Adding a New Unit to the AI

Tutorial for Generals Gen

Avatar of Mastermind

Mastermind

Category: Code
Level: Beginner
Created: Saturday May 1, 2010 - 14:35
Updated: Saturday May 1, 2010 - 14:38
Views: 2192
Summary: How to add a new unit to the Generals AI
Rating
  • Staff-
  • Members-
  • Average-

0 votes

For this scenario, we will assume that we want to add a new unit to America, the Patriot Tank.


What is in a Team?

The AI in Generals uses its units by the use of Teams. A "Team" in WorldBuilder is basically one or more units that have been assigned specific behaviour.
This behaviour is, of course, defined by faction scripts.


Let's get started. Run WorldBuilder.

Go to Edit > Player List. In the new window, locate the "Add Skirmish Players" button and click it.
Click "OK" and go to Edit > Scripts. Find the "Import Scripts" button, and import the SkirmishScripts.scb file (usually located in your "Command and Conquer Generals\Data\Scripts\" directory).

After a few seconds you will possibly see that the three fction folders have a queston mark next to them.
This means that the scripts cannot find an item - don't worry though, it's only hte waypoints, trigger areas and civilian buildings that it can't find.

Now that you have imported the scripts (the teams import with the scripts), click "OK" and go to Edit > Edit Teams.

Click "Skirmish America" and you'll se a big list of teams.
User image

This is where the AI gets all the team data from. Here is a list of things that the Teams Editor defines:
  • Build Conditions.
  • OnCreate Behaviour (what the team is supposed to do once it is created).
  • Magnitude of teams (which unit(s), and how many of them).
  • Build Priority (sets whether this team is to be built before any others are not).
  • OnDestroyed Behaviour (what the team is supposed to do when it is destroyed. The percentage value next to it defines when it should consider itself "destroyed").
  • Generic Scripts (you cna attach any scripts here, the mostused ones are the Apply Priorities and Attack Hunt).


Now, to add the Patriot Tank to the USA AI, we need to choose specific teams.

Note the "D" followed by a numver and then another letter in the team's name.

The "D" stands for "Defcon". The defcon counter is governed by death counters. It determines when and how much bonus cash it will receive, and also which teams to build.
It rotates from 1 to 5 and back again infinitely depending on the battle.
(Look at the "USA Defcon Conditions - Easy Normal or Hard" folders).

The number next to the "D" in the team's name determines the defcon's value. Thenext letter (can be either an E, M or H) stands for difficulty settings Easy, Medium or Hard.

Since we want to make the USA use the Patriot Tank early, we will choose higher defcon teams to add our Patriot Tank to - otherwise the AI will only build it later on in the game, and not at the start.

Fr now, double click "USA D5H Tank Rush". Stay with me now while you wait for your brain to make sense of it.
User image

1) The Team's name, the "D5H" is discussed above.
2) How many instances of this team can exist simultaneously.
3) The Owner, which is defined by the players in the Player List.
4) Mainly used for map missions, this sets where the team is initially, waypoints must be chosen.
5) The Build Condition. The "USA Build D5H Tank Rush" is a simple script which sets a flag to "True" when its conditions are true, and our team is built when that flag is "True".
6) Execute the actions in the "Actions if true" tab in the Scripts editor - will get to that later.
7) Build priority. 1000 is pretty high, so this will be built first of all - if one or more teams have the same priority and build conditions, then they will be built randomly.
8) Increase this team's priority if they succeed in their orders (OnCreate, will get to that).
9) Build for this many frames. After that, start executing your initial orders. Note that the Skirmish AI does not recognise this - the AIData.ini handles that. This is only for singleplayer.
10) Value by which the team's priority will be decreased if they fail with their orders, so they won't be built again.
11) The unit list. Any units cna go there, they do not necessarily have to be in a specific faction.
12) Automatically build reinforcement teams, defined in the Reinforcement tab. This function reinforces the team on a unit only basis... it doesn't replace the entire team. It also has the nasty havit of robbing units from one team that has the AIRecruitable box checked, causing that team to be broken.
13) This team can be recruited from another team when the "Recruit a team" script command is used.
14) This team can only be created once, will never be rebuilt even if the build conditions allow that.


Now, the Reinforcement tab is mostly used on map missions. The only "interesting" ones at this time are the other two: Behaviour and Generic.

Behaviour first:
User image

1) "USA Attack Sequence Center" is a sequential script that tells this team to follow the "Center" path in the map and attack any enemies there.
2) Execute this script when you see an enemy. The sight distance is defined in the object INI "VisionRange" line.
3) Execute this script when you see no enemies.
4) Execute this script when the team has been destroyed. The box with the percentage next to it defines when a team should consider itself "destroyed".
5) Execute this script when you are idle.
6) Execute this script when this team has lost a unit.
7 and 8) These seem to have been disabled.
9) Sets the attitude of the team. "Aggressive" is often the most effective. NOTE: If the team is to load into a transport DO NOT set it to Aggressive. They won't load.
10) Focus fire. Pretty obvious, I think.


Now, let's move on to Generic:
User image

Note: The number of scripts you can add will change when you add them.

1) USA Attack Hunt makes the team attack enemy targets along the way, when they follow the "Center" path of the map as defined by the OnCreate behaviour.
2) USA Base Invaded Hunt will make this team retreat to their base if it is attacked, to defend it.
3) USA Apply Tank Priority will make this team use the Tank Priority as defined in the scripts.


Now that you know more about the teams tabs, lets get back to our original scenario.

Go back to the "Identity" tab, and in the Unit List, (below AmericaVehicleHumvee), add the Patriot Tank (or your new unit) and set both the maximum and minimum numbers to 1.


Now set its priority to 9000 for this scenario.

Note that the build condition of our team (USA Build D5H Tank Rush) states that the AI's enemy must have less than or equal to four rocket guys, and less than or equal to 3 units of type "Anti Air" (look at the script itself in the Script Editor).

If you just want the AI to build those units now so that you can see it, take those above states conditions off the build condition. (The USA Build D5H Tank Rush script is located in "SkirmishAmerica\Build Conditions - Hard").

Fire up the game and see if it works. (playing on Brutal difficulty level of course).

Note that the more teams you add the unit to, the higher is the chance of that unit being built. If you have started the game and played a bit, yet the AI did not build it, try adding it to more teams.

Also note that the new unit must be in the faction's building CommandSet somewhere, else the AI won't "find" it. For example, if you take off the ChinaTankGattling from the Chinese War Factory, the AI will no longer build the Gattling Tank. So the AI needs both the CommandSet and CommandButton entries.

That's it, you're done.

Credits

Original tutorial made by the SDI Team.

Return to top