Building an AI
Tutorial for Gen
|
|
Original Author: Calamity_Jones
####Part 3####
Before you open worldbuilder, you'll need to make sure you've set up your AIData.INI file. This file lives in INI/Default and consists of three main chunks:
The first defines some basic constants used by the AI. Ignore these, you can fiddle if you want, but I don't advise it.
The Next is the skillset section where the generals powers used by each side are defined. The bog standard America one looks like this:
For each of your factions you need to make one of these, make sure you don't give the AI more sciences than it can possibly purchase during the game. The different sets are... different sets that the AI uses. You define which it uses in scripts.
The last chunk is the bit which tells the AI what buildings to build and where. The bog standard USA one is:
Simply copy and pop in your buildings. You don't have to fill every "slot" and if you do, you can make more. Just be careful about locations. Also, don't worry about having things in the list which aren't part of that faction. Again, this file on its own will not do anything. You must specifically tell the AI to try to build something with scripts. Of course, if you try to tell it to build something that it can't, then it won't. In my Only War AI the factions only have a handful of buildings, but the AIData list has all sorts of GLA crap listed, just in case I wanted to add more buildings.
If you've got that ready, it's time to add some more basic bits. Let's start with the "###_Base Building" folder. (Which requires your AIData.INI fie :p)
Here's the first one: (Actions in Team/AI and Skirmish Only/Build)
TYPE: [nsAD][ENH]
NAME: "###_Build Initial"
Obviously in yours, you will choose a building instead of what I have in square brackets. Choose buildings that DO NOT HAVE PREREQUISITES (e.g. power plant and barracks) as the AI will run this script instantly, and if you happen to supply more than one builder at start, or have a builder than builds exceedingly fast, the AI will assign that builder to any buildings still waiting. The second construction unit is built using this script too, except you have not made the team that is referred to, hence question marks (you'll see these whenever a script has faults... [???]). Ignore them for now. Mine for Only War looks like this: (The last line is added to make the AI garrison the troops it starts with (Only War starts the player with a builder and a squad of basic Troops) as they're not much use otherwise.)
Now, depending on how complicated your prerequisite system is, you might have quite a few scripts in here. The next one should be the next BASIC building that the player can build once the initial buildings have been constructed.
Script two: (Conditions in Player/Owns and actions in Skirmish Only/Build)
TYPE: [nsAD][ENH]
NAME: "###_Build Initial Warfactory"
Basically starts building once the AI has met the conditions, again, it doesn't matter what you set as conditions here, whether the AI can build it or not is determined by prerequisites in the buildings INI. By splitting them like this, the AI won't give up trying to build something it can't. You can keep adding these things until you have enough scripts for your AI to build a basic base. For example, if you need power to build a refinery, then a refinery to build a tank factory, that's 3 scripts you'll need.
Now, you want to start altering what the AI builds depending on the difficulty level. The reason I said specifically use the first few scripts for basic buildings is that the AI needs to build these structures to be able to play. Everything else is optional, such as defence, advanced buildings, extra barracks/factories.
Speaking of defence:
TYPE: [nsAD][E]
NAME: "###_E_Build Initial Defences"
TYPE: [nsAD][N]
NAME: "###_N_Build Initial Defences"
TYPE: [nsAD][H]
NAME: "###_H_Build Initial Defences"
As you can tell, this makes the AI build better defence as the difficulty increases. Of course, you can add as many as you want, and add different types. Make sure that your AI isn't trying to build too many things simultaneously, it's a good idea to make sure that your conditions won't result in the AI trying to build, say, extra power, turrets and a war fac at the same time. You want to control the order of construction to make sure the AI doesn't accidentally run out of power too. If you think it will run out, add another power plant to the first building script. (That's why mine for Only War has the AI make 2 power plants). With the Hard one, you can make it build the power in the "###_H_Build Initial Defences" script as it'll probably be the one testing its energy grid.
####Part 3####
Before you open worldbuilder, you'll need to make sure you've set up your AIData.INI file. This file lives in INI/Default and consists of three main chunks:
The first defines some basic constants used by the AI. Ignore these, you can fiddle if you want, but I don't advise it.
The Next is the skillset section where the generals powers used by each side are defined. The bog standard America one looks like this:
Code |
|
For each of your factions you need to make one of these, make sure you don't give the AI more sciences than it can possibly purchase during the game. The different sets are... different sets that the AI uses. You define which it uses in scripts.
The last chunk is the bit which tells the AI what buildings to build and where. The bog standard USA one is:
Code |
|
Simply copy and pop in your buildings. You don't have to fill every "slot" and if you do, you can make more. Just be careful about locations. Also, don't worry about having things in the list which aren't part of that faction. Again, this file on its own will not do anything. You must specifically tell the AI to try to build something with scripts. Of course, if you try to tell it to build something that it can't, then it won't. In my Only War AI the factions only have a handful of buildings, but the AIData list has all sorts of GLA crap listed, just in case I wanted to add more buildings.
If you've got that ready, it's time to add some more basic bits. Let's start with the "###_Base Building" folder. (Which requires your AIData.INI fie :p)
Here's the first one: (Actions in Team/AI and Skirmish Only/Build)
TYPE: [nsAD][ENH]
NAME: "###_Build Initial"
Code |
|
Obviously in yours, you will choose a building instead of what I have in square brackets. Choose buildings that DO NOT HAVE PREREQUISITES (e.g. power plant and barracks) as the AI will run this script instantly, and if you happen to supply more than one builder at start, or have a builder than builds exceedingly fast, the AI will assign that builder to any buildings still waiting. The second construction unit is built using this script too, except you have not made the team that is referred to, hence question marks (you'll see these whenever a script has faults... [???]). Ignore them for now. Mine for Only War looks like this: (The last line is added to make the AI garrison the troops it starts with (Only War starts the player with a builder and a squad of basic Troops) as they're not much use otherwise.)
Code |
|
Now, depending on how complicated your prerequisite system is, you might have quite a few scripts in here. The next one should be the next BASIC building that the player can build once the initial buildings have been constructed.
Script two: (Conditions in Player/Owns and actions in Skirmish Only/Build)
TYPE: [nsAD][ENH]
NAME: "###_Build Initial Warfactory"
Code |
|
Basically starts building once the AI has met the conditions, again, it doesn't matter what you set as conditions here, whether the AI can build it or not is determined by prerequisites in the buildings INI. By splitting them like this, the AI won't give up trying to build something it can't. You can keep adding these things until you have enough scripts for your AI to build a basic base. For example, if you need power to build a refinery, then a refinery to build a tank factory, that's 3 scripts you'll need.
Now, you want to start altering what the AI builds depending on the difficulty level. The reason I said specifically use the first few scripts for basic buildings is that the AI needs to build these structures to be able to play. Everything else is optional, such as defence, advanced buildings, extra barracks/factories.
Speaking of defence:
TYPE: [nsAD][E]
NAME: "###_E_Build Initial Defences"
Code |
|
TYPE: [nsAD][N]
NAME: "###_N_Build Initial Defences"
Code |
|
TYPE: [nsAD][H]
NAME: "###_H_Build Initial Defences"
Code |
|
As you can tell, this makes the AI build better defence as the difficulty increases. Of course, you can add as many as you want, and add different types. Make sure that your AI isn't trying to build too many things simultaneously, it's a good idea to make sure that your conditions won't result in the AI trying to build, say, extra power, turrets and a war fac at the same time. You want to control the order of construction to make sure the AI doesn't accidentally run out of power too. If you think it will run out, add another power plant to the first building script. (That's why mine for Only War has the AI make 2 power plants). With the Hard one, you can make it build the power in the "###_H_Build Initial Defences" script as it'll probably be the one testing its energy grid.