The following sections will assume you already have a map ready to go, with a pre-build enemy base.
If you haven't already created a
#include "base_army.cfg"
#include "base_army_orderers.cfg"
#include "base_army_plans.cfg"
These three files contain the default configurations of an AI base. They are pretty basic, but they'll work for us for now. We can modify them later.
Next we need to tell the script to create the AI base for the mission. This is typically done in the initial start objective for the AI team. The Action scope would look like this:
CreateObjectType("objective_start_AI", "Objective")
{
Condition("TRUE");
Action()
{
AddBase("[base name]", "army")
{
Region("[region name]");
Orientation(180);
}
AssignBaseConstructors("[base name]")
{
Tag("[tag name]");
}
AssignBaseUnits("[base name]")
{
Tag("[tag name]");
}
}
}
The [base name] is the script identifier of the base and can be anything you wish. Where it says "army" is which base config to use, in which "army" is the default we included earlier. The [region name] is the location on the map the base considers home. If it buys new buildings, it will use center of this region as a reference point for placement. If no region is given, then it will assume the start region set in the studio, and if that isn't given, then the AI will fail, crashing the game!
Orientation
is the compass angle the base faces. While buildings can only face the four cardinal directions, more precise angles will be reflected in exact cell placements, such as for towers. If an orientation isn't specified, it will default towards the center of the map. The number increases the angle in a clockwise fashion. The four cardinals are as follows:
0
- North
90
- East
180
- South
270
- West
If you just have one AI base, put all buildings and units that should be a part of that base into one tag, and use that tag name for both the above [tag name]. If you have multiple AI bases, you would have another set of specifications just like the one above, in the same action scope, but designate the correct tags and name for the other base. Enemy units placed far away from the main base typically aren't included in the base tag, but can be.
Finally, you'll need to add one more .cfg file to your mission folder. Make a new text file and call it "
#include "recruit_types.cfg"
The
CreateRecruitType("[recruit name]")
{
Type("army.unit.grunt", 1);
}
The above recruit type just contains one grunt. So if an attack script called for this recruit type, it would just be sending out one grunt. The number can be changed to anything, but it's a good idea to not have the number exceed the amount of the unit being built in the orderers config. The units are specified by type name (you can view the type name of all objects in the studio by clicking the "type names" button in the Objects menu). You can list as many unit types as you want in one recruit type, just add more lines. For example:
CreateRecruitType("[recruit name]")
{
Type("army.unit.machinegunner", 3);
Type("army.unit.bazooka", 2);
Type("army.unit.mortar", 1);
}