Building an AI
Tutorial for Gen
|
|
Original Author: Calamity_Jones
Right. Leave this folder and run off to "###_Setup" And add these scripts: (The actions are in Player/AI)
TYPE: [nsAD][E]
NAME: "###_E_Build Times"
TYPE: [nsAD][N]
NAME: "###_N_Build Times"
TYPE: [nsAD][H]
NAME: "###_H_Build Times"
This simply tells the AI how often to build a team of units.
Now things get a bit tedious... You'll need to define what every unit you use in the game is, in order to make priorities. Start by making a [nsAD][ENH] script called "###_Define Object Types". Then add an action like: "'Tanks' : add 'TANK NAME'" which is under Scripting/ObjectTypeList. The list is Tanks, and the object is your tank. Continue to define types and add objects for each faction that are of that type. Part of mine looks like this:
Once you've finished this script you need to OK the scripts window to update the map. (If you don't, the script editor will not know your object types exist... Also, you should probably save.) Then re-open the scripts window and add a script like this:
TYPE: [nsAD][ENH]
NAME: "###_Define Priorities_Generic"
The action is in AttackPrioritySet/CreateSet (Modify a sets priority for a single unit type) For yours, name the set "###_Generic" and set your different types in order of their importance... i.e. what you want your AI to want to attack more. You can set things to the same value if you want. You could even set everything to the same value.
You can also define priority sets for different unit types, or specific units. It's cleaner to do this in a separate script. If you have rocket soldiers and machine gun soldiers for example, make one script called "###_Define Priorities_Machine Gun Soldier" and another called "###_Define Priorities_Rocket Soldier" with the sets named accordingly. Then, set tanks to have higher priorities than soldiers for the rocket guy, and vice versa for the Machine Gun guy... simple!
Now for the next script, a simple affair: (Action under Player/Build)
TYPE: [nsAD][ENH]
NAME: "###_Enable Building"
Add another script like this: (Action under Scripting/Flags)
TYPE: [nsAD][ENH]
NAME: "###_Set Flags Initial"
This script defines a bunch of really important flags that the AI uses to define what's going on. (Refer to my other tutorial). The infantry and vehicle building ones are called when a team starts building to tell the AI that its factory is busy. The crippled one is called when the AI cannot win the game. Enemy crippled is to tell the Ai to finish off an opponent. Enemy in my base is... well... obvious.. :p
Finally, add: (Action under Scripting/Counters)
TYPE: [nsAD][ENH]
NAME: "###_Set Counters Initial"
The names of these are short for "###_Teams Lost_Overall"... "###_Teams Lost_Centre_Tanks" etc... The main attack routes defined by waypoint paths are Centre (Spelt Center ingame due to silly American spelling :dry: ), Backdoor and Flank. These scripts set up counters that count how many teams that have been dispatched down these routes have died, and the overall number of teams lost. (Which is used back in our master counters! You'll see how everything links together in very complicated and subtle ways. This is what's so damn difficult about making an AI. There's no clear lines between parts, everything is linked together...)
Okay, we're done setting things up. Now we're gonna see what's going on in the world. Go to "###_World Status" and add this script: (Player/Destroyed for the condition and Scripting/Flags for the action)
TYPE: [nsAD][ENH]
NAME: "###_I Am Crippled"
This as you might guess, checks to see if the player can build anything. If it can't, it's fucked.
Next, add these scripts: (condition in Player/Area and actions in Scripting/Flags and Scripting/Script)
TYPE: [nsAD][ENH]
NAME: "###_Base Invaded False"
and
TYPE: [nsAD][ENH]
NAME: "###_Base Invaded True"
As you might guess, these two scripts work together like a switch, checking to see if the AI is in danger or not. The reason that the switch is split into two separate scripts rather than using the false action is that if the enemy sends units into the AI's base and the script is set to say the base is invaded with any value of units, a single rifleman could walk in who costs say 200 and cause the AI to gather it's army at it's base for defence. Even if base guards and defence could easily dispatch a single soldier. So, it only calls a state of emergency if there's a lot of stuff inside the base. Later we'll see some other scripts that reset this switch once the threat is removed.
Oh, for the love of god, click "OK" on the scripts window and save your map from the file menu. Clicking cancel removes any changes to scripts, and if you just close your map it WILL NOT PROMPT YOU TO SAVE if you have only made scripting changes.
Right. Leave this folder and run off to "###_Setup" And add these scripts: (The actions are in Player/AI)
TYPE: [nsAD][E]
NAME: "###_E_Build Times"
Code |
|
TYPE: [nsAD][N]
NAME: "###_N_Build Times"
Code |
|
TYPE: [nsAD][H]
NAME: "###_H_Build Times"
Code |
|
This simply tells the AI how often to build a team of units.
Now things get a bit tedious... You'll need to define what every unit you use in the game is, in order to make priorities. Start by making a [nsAD][ENH] script called "###_Define Object Types". Then add an action like: "'Tanks' : add 'TANK NAME'" which is under Scripting/ObjectTypeList. The list is Tanks, and the object is your tank. Continue to define types and add objects for each faction that are of that type. Part of mine looks like this:
Code |
|
Once you've finished this script you need to OK the scripts window to update the map. (If you don't, the script editor will not know your object types exist... Also, you should probably save.) Then re-open the scripts window and add a script like this:
TYPE: [nsAD][ENH]
NAME: "###_Define Priorities_Generic"
Code |
|
The action is in AttackPrioritySet/CreateSet (Modify a sets priority for a single unit type) For yours, name the set "###_Generic" and set your different types in order of their importance... i.e. what you want your AI to want to attack more. You can set things to the same value if you want. You could even set everything to the same value.
You can also define priority sets for different unit types, or specific units. It's cleaner to do this in a separate script. If you have rocket soldiers and machine gun soldiers for example, make one script called "###_Define Priorities_Machine Gun Soldier" and another called "###_Define Priorities_Rocket Soldier" with the sets named accordingly. Then, set tanks to have higher priorities than soldiers for the rocket guy, and vice versa for the Machine Gun guy... simple!
Now for the next script, a simple affair: (Action under Player/Build)
TYPE: [nsAD][ENH]
NAME: "###_Enable Building"
Code |
|
Add another script like this: (Action under Scripting/Flags)
TYPE: [nsAD][ENH]
NAME: "###_Set Flags Initial"
Code |
|
This script defines a bunch of really important flags that the AI uses to define what's going on. (Refer to my other tutorial). The infantry and vehicle building ones are called when a team starts building to tell the AI that its factory is busy. The crippled one is called when the AI cannot win the game. Enemy crippled is to tell the Ai to finish off an opponent. Enemy in my base is... well... obvious.. :p
Finally, add: (Action under Scripting/Counters)
TYPE: [nsAD][ENH]
NAME: "###_Set Counters Initial"
Code |
|
The names of these are short for "###_Teams Lost_Overall"... "###_Teams Lost_Centre_Tanks" etc... The main attack routes defined by waypoint paths are Centre (Spelt Center ingame due to silly American spelling :dry: ), Backdoor and Flank. These scripts set up counters that count how many teams that have been dispatched down these routes have died, and the overall number of teams lost. (Which is used back in our master counters! You'll see how everything links together in very complicated and subtle ways. This is what's so damn difficult about making an AI. There's no clear lines between parts, everything is linked together...)
Okay, we're done setting things up. Now we're gonna see what's going on in the world. Go to "###_World Status" and add this script: (Player/Destroyed for the condition and Scripting/Flags for the action)
TYPE: [nsAD][ENH]
NAME: "###_I Am Crippled"
Code |
|
This as you might guess, checks to see if the player can build anything. If it can't, it's fucked.
Next, add these scripts: (condition in Player/Area and actions in Scripting/Flags and Scripting/Script)
TYPE: [nsAD][ENH]
NAME: "###_Base Invaded False"
Code |
|
and
TYPE: [nsAD][ENH]
NAME: "###_Base Invaded True"
Code |
|
As you might guess, these two scripts work together like a switch, checking to see if the AI is in danger or not. The reason that the switch is split into two separate scripts rather than using the false action is that if the enemy sends units into the AI's base and the script is set to say the base is invaded with any value of units, a single rifleman could walk in who costs say 200 and cause the AI to gather it's army at it's base for defence. Even if base guards and defence could easily dispatch a single soldier. So, it only calls a state of emergency if there's a lot of stuff inside the base. Later we'll see some other scripts that reset this switch once the threat is removed.
Oh, for the love of god, click "OK" on the scripts window and save your map from the file menu. Clicking cancel removes any changes to scripts, and if you just close your map it WILL NOT PROMPT YOU TO SAVE if you have only made scripting changes.