HOW TO: Make AI Repair Critical Systems

Started by Ascertes, September 17, 2016, 11:14:25 PM

Previous topic - Next topic
September 17, 2016, 11:14:25 PM Last Edit: September 22, 2016, 12:20:05 PM by Ascertes
NOTE: I will be adding to this tutorial as I discover more about this topic. I will keep a tally in this header as to when I last updated it.

Last update: 9/22/16, 3:19pm EST


If you've ever played a space map before, you know that you can repair some of the critical systems should they be destroyed or damaged. Shields, Auto Turret mainframes, etc. are all susceptible to damage in space battles and essential to victory. Keeping these in tip-top shape is a first priority for any team.

...Except the AI don't do it. In singleplayer, you have the comfort of knowing that once the shields or defense mainframes are down, you don't have to worry about those anymore. This can be very disappointing however to those of us that want a bit more of a challenge. Today, I bring you that opportunity for your maps.

Step by Step Guide:
To get the AI to repair the critical systems should they be destroyed or damaged, do the following:
1. Add this line to your ABC_ass, or ctf, whatever your game mode is:
function ScriptPostLoad()
    SetupObjectives()
   
    SetupShields()
    SetupDestroyables()
    SetupTurrets()

    AddAIGoal(REP, "Deathmatch", 100)
    AddAIGoal(CIS, "Deathmatch", 100)
    --AddAIGoal(REP, "Conquest", 100)
    --AddAIGoal(CIS, "Conquest", 100)

DisableSmallMapMiniMap()
end


The commented-out lines are what you need to add.

2. That's it.
3. You're done.
4. Congratulations.
5. Go forth and make smarter AI!

...But wait, there's more!
The AI by default will repair anything with the "armedbuilding" ClassLabel. Shield Generators are not "armedbuildings" by default. Change their ClassLabel to it for the AI to repair it, or you'll be waiting around forever! Also, add this line to the Shield Generator ODF:
RespawnTime = "999999"
Otherwise, the shield generator will regenerate on its own. But maybe you want it to do that?  :shrug:



There are somethings in the game of course that are labelled as "armedbuilding" that you don't want the AI to repair (turrets, exterior systems, the ship itself, even...) For anything with the "armedbuilding" ClassLabel you don't want the AI repairing, add this line to that object's ODF file:
AINoRepair = "1"

AI Repair Frequency
I also want to note some things about the above code. If the AI are repairing stuff too often, or not enough, change their goal values.

The formula for this as follows:
So, in this case Conquest and Deathmatch are both set to values of 100. If the AI are repairing stuff too quickly, lower the value of the Conquest goal, or raise the one for Deathmatch. Really, it looks like this if we set the value of Conquest to 90 instead of 100:

90/(100 + 90). AKA, the percentage of 90 out of 190, which is the total amount of "goal points." Please be advised that the "goal points" must be equal for both teams. So if one team's "goal points" are 190, the other team's must be as well.

There's also another part in the LUA that can cause problems with getting the AI to repair properly. Go to your ABC_cmn LUA and look for this line:
SetAIVehicleNotifyRadius(100)
For whatever reason, vehicles interfere with the AI's desire to repair stuff. If you're working with a normal Capital Ship interior, changing the value to 60-80 is about what you'll be looking for to balance the AI correctly. (Personally I use 75, but you'll want to adjust it for your own projects.)


NOTE: Only AI with the UnitType "pilot" will repair things. So don't expect any old AI with a fusion cutter to repair stuff.

Ta-da!
Okay, this is the actual end of the Tutorial. Enjoy  :P

CREDITS:
Everyone who helped me figure this out:
1. Oceans14
2. Marth8880
3. thelegend
4. Samee3
5. AnthonyBF2
6. AQT
"Birth, pain, fear, death; the cycle of existence." -Dread Master Calphayus.

SWBF1 Maps: Tatooine: Mos Anek, Kashyyyk: Village, Naboo: Province, Tatooine: Gulch.

SWBF2 Maps: Space Carida.


Quote from: Ltin on September 18, 2016, 08:02:51 AM
Hey that's pretty cool!
:moo:

I thought it was rather cool myself, too. I always wondered why they never repaired stuff in space, but now I know  :XD:

I plan to have this feature included in my new map as well :)
"Birth, pain, fear, death; the cycle of existence." -Dread Master Calphayus.

SWBF1 Maps: Tatooine: Mos Anek, Kashyyyk: Village, Naboo: Province, Tatooine: Gulch.

SWBF2 Maps: Space Carida.

Wow, I didn't think you could get the AI to do that! Awesome!

Quote from: Commander Awesome on September 18, 2016, 09:47:52 PM
Wow, I didn't think you could get the AI to do that! Awesome!

Yeah! I noticed in the campaign missions the AI would repair the mainframes so I set out to figure out why they did it there but not in the regular modes. Think this opens a new door to improving the AI. :)
"Birth, pain, fear, death; the cycle of existence." -Dread Master Calphayus.

SWBF1 Maps: Tatooine: Mos Anek, Kashyyyk: Village, Naboo: Province, Tatooine: Gulch.

SWBF2 Maps: Space Carida.