Croaxleigh
3rd Mar 09, 8:31 AM
Skill Level: Novice
Prerequisites: None
AI Series:
Part 0 - Understanding the AI
Part I - Coming Soon
= = = = = = = = = = = = = = =
INTRODUCTION
= = = = = = = = = = = = = = =
Since the beginning of time (or at least the ship date of Dawn of War 2), players have been frustrated by a seemingly simple AI. "Please!" they would cry. "Please, someone save us with a mighty AI mod that will deliver us from Orkz that stay in their base and 'Nids who just cap points all day!"
And lo, there came a messenger from Relic who spake thusly: "We might look into it."
Undaunted and unsatisfied with that answer, it fell to the modding community to take matters into their own hands.
= = = = = = = = = = = = = = =
PURPOSE OF THIS TUTORIAL
= = = = = = = = = = = = = = =
This tutorial isn't designed to teach you how to edit the game AI, but is instead merely a step toward understanding how the AI works in the first place (and why sometimes it doesn't seem to work at all.) It's my intention to write additional tutorials in this series which will teach more about editing the AI to make it stronger, faster, and able to do nasty things to your units if you're not paying attention. You've got to crawl before you can walk, however, and before you can crawl you've got to learn to flip over. This tutorial isn't even that stage... it's more like lifting your head up on your own and realizing that there's a whole big world around you.
What can I say... I used to be a Child Psychology major, so I'm good with developmental similes.
= = = = = = = = = = = = = = =
STRUCTURE OF THE AI
= = = = = = = = = = = = = = =
The AI of Dawn of War 2 is made up of a bunch of aptly-named .ai files, not to be confused with the files with the same extension which are made by Adobe Illustrator. These files can be opened up using Notepad, WordPad, or any other plain text editor... I'd recommend Notepad or any editor that you're sure isn't going to do strange things to the file information, as that can lead to lots of things not working.
These little .ai files are written in the same format as any of the other .lua or .scar files that you'll find in the Dawn of War 2 archive files... you've got a lot of functions, definitions, and conditional statements that will help the computer-controlled players to know what to do. All of the AI files are located in the DATA/simulation/AI folder (and it's subfolders.)
= = = = = = = = = = = = = = =
STRUCTURE OF THE AI FOLDER
= = = = = = = = = = = = = = =
There are several files located directly in the AI folder which outline the basic strategies for purchasing units, upgrades, defenses, and the like. You'll also see files with fancy names like strategy_buildorder and strategy_military. Don't get too excited... all of these files are essentially just the "basic" rules that are imported by the race-specific files you'll find in the subfolders.
Speaking of the subfolders, there are 4 of them. Personality, Tactics, Targets, and Util. Tactics contains 2 files which are used to help determine things like whether a squad is being shot at and figuring out whether an ability should be used. Targets contains a single file to help the AI determine which players it should be shooting at. While both of these items seem very useful, it is the Personality and Util subfolders that deserve a little more attention at the moment.
Personality is where all of the race-specific AI information is kept, including information for each of the difficulty levels and build orders that the AI can choose from. There are 4 files named base_<difficulty>, with the <difficulty> part of course representing a different difficulty level, as well as a file named buildorder_conditions_lib in the main Personality folder. Much like the files in the main AI directory, these files are just your baseline rules for difficulty and build orders; each of the race subfolders (there are 5 of them, one for each of the core races as well as the IG) contains files that will import from them which are the ones that are most directly used. Editing the files in Personality will make changes to the overall rules which can be overridden by the race-specific rules, while editing the race-specific files will actually set the rules that override the base ruleset (but will only be applied to that one race, obviously.)
Util is the other important folder that you'll find, since it is where you'll actually set some of how the AI "thinks" and which data is and isn't available to it. Some of the files won't be immediately useful to beginning AI coders, while some files such as lua_consts (which lets you set the references for units which are used by the AI, an especially useful thing since not all of the units are listed in the lua_consts file to begin with... which is why you never see the AI build some units) will help you to fine-tune exactly which units, abilities, and similar bits of the game the AI can access.
= = = = = = = = = = = = = = =
MODIFYING THE AI
= = = = = = = = = = = = = = =
Modifying the AI is technically a simple matter, since all that you have to do is make changes to the file and save it. Unfortunately, it's written in .lua/SCAR and is therefore rather easy to mess up unless you know what you're doing. Get the wrong context or try to use a bit of data that hasn't been defined yet and you're going to end up with SCAR errors that will kill the unit AI. Hence the reason for doing the background info first and then getting in to build order editing and such later... you need to understand at least a little of how things are structured before you just jump in and start editing things around.
If you think that you're ready to try your hand at editing the AI on your own, however, here are a few things that you should be sure to do:
- Make a backup copy of the file before you edit it. Open the file in Notepad, select File>Save As..., select "All Files" from the drop-down menu beneath the file name, then save the file as <filename>.ai.bak (with <filename> obviously being the original name of the file.) Once the backup has been saved, close it and reopen the original.
- Always make sure that you select "All Files" before saving AI files if using Save As..., since otherwise Notepad will save it as a .txt file.
- Be very careful with syntax. It's recommended that you study some of the existing AI files before you make any edits, since it can be very easy to make a typo or use the wrong syntax and kill the AI completely with a simple keystroke.
= = = = = = = = = = = = = = =
SO WHY'S THE AI SO DUMB?
= = = = = = = = = = = = = = =
The AI chooses a build order randomly from those which are defined, in theory giving way to more variety in matches. Unfortunately, some of these build orders are "free for all" orders which don't have anything in them at all. The AI picks units and upgrades at random, and if it can't make them it'll choose something else until it finds something that it can. This leads to mass-production of small-cost units and no real direction for what the AI should do. The buildorder_lib files acknowledge that this isn't optimal but that it was intended to add variety... unfortunately, there are 2 different build orders which feature this sort of free form structure (either with nothing or with very little) so at least half the time (statistically) the AI is going to be completely on its own without any idea of what to do.
= = = = = = = = = = = = = = =
INTERESTING FACTOID
= = = = = = = = = = = = = = =
Hidden within one of the AI files is instructions for specific DoW2 units... the Servitor, Bonesinger, Enginseer, Grot, and Genesplicer. Though it's been known for a while that the original builds of DoW2 contained base building with engineer units, it's interesting to see which units those actually were.
= = = = = = = = = = = = = = =
COMING SOON...
= = = = = = = = = = = = = = =
I'm actually planning on doing a few AI tutorials that will walk folks through things like making some units more likely to be built, controlling unit spam, and creating custom build orders that the AI can choose from. They'll be starting simple and getting a bit more complex, so hopefully be the time I finish 3 or 4 of them people who aren't comfortable enough with their abilities to root around in the AI will at least feel like tweaking it a bit to make it more to their liking.
Prerequisites: None
AI Series:
Part 0 - Understanding the AI
Part I - Coming Soon
= = = = = = = = = = = = = = =
INTRODUCTION
= = = = = = = = = = = = = = =
Since the beginning of time (or at least the ship date of Dawn of War 2), players have been frustrated by a seemingly simple AI. "Please!" they would cry. "Please, someone save us with a mighty AI mod that will deliver us from Orkz that stay in their base and 'Nids who just cap points all day!"
And lo, there came a messenger from Relic who spake thusly: "We might look into it."
Undaunted and unsatisfied with that answer, it fell to the modding community to take matters into their own hands.
= = = = = = = = = = = = = = =
PURPOSE OF THIS TUTORIAL
= = = = = = = = = = = = = = =
This tutorial isn't designed to teach you how to edit the game AI, but is instead merely a step toward understanding how the AI works in the first place (and why sometimes it doesn't seem to work at all.) It's my intention to write additional tutorials in this series which will teach more about editing the AI to make it stronger, faster, and able to do nasty things to your units if you're not paying attention. You've got to crawl before you can walk, however, and before you can crawl you've got to learn to flip over. This tutorial isn't even that stage... it's more like lifting your head up on your own and realizing that there's a whole big world around you.
What can I say... I used to be a Child Psychology major, so I'm good with developmental similes.
= = = = = = = = = = = = = = =
STRUCTURE OF THE AI
= = = = = = = = = = = = = = =
The AI of Dawn of War 2 is made up of a bunch of aptly-named .ai files, not to be confused with the files with the same extension which are made by Adobe Illustrator. These files can be opened up using Notepad, WordPad, or any other plain text editor... I'd recommend Notepad or any editor that you're sure isn't going to do strange things to the file information, as that can lead to lots of things not working.
These little .ai files are written in the same format as any of the other .lua or .scar files that you'll find in the Dawn of War 2 archive files... you've got a lot of functions, definitions, and conditional statements that will help the computer-controlled players to know what to do. All of the AI files are located in the DATA/simulation/AI folder (and it's subfolders.)
= = = = = = = = = = = = = = =
STRUCTURE OF THE AI FOLDER
= = = = = = = = = = = = = = =
There are several files located directly in the AI folder which outline the basic strategies for purchasing units, upgrades, defenses, and the like. You'll also see files with fancy names like strategy_buildorder and strategy_military. Don't get too excited... all of these files are essentially just the "basic" rules that are imported by the race-specific files you'll find in the subfolders.
Speaking of the subfolders, there are 4 of them. Personality, Tactics, Targets, and Util. Tactics contains 2 files which are used to help determine things like whether a squad is being shot at and figuring out whether an ability should be used. Targets contains a single file to help the AI determine which players it should be shooting at. While both of these items seem very useful, it is the Personality and Util subfolders that deserve a little more attention at the moment.
Personality is where all of the race-specific AI information is kept, including information for each of the difficulty levels and build orders that the AI can choose from. There are 4 files named base_<difficulty>, with the <difficulty> part of course representing a different difficulty level, as well as a file named buildorder_conditions_lib in the main Personality folder. Much like the files in the main AI directory, these files are just your baseline rules for difficulty and build orders; each of the race subfolders (there are 5 of them, one for each of the core races as well as the IG) contains files that will import from them which are the ones that are most directly used. Editing the files in Personality will make changes to the overall rules which can be overridden by the race-specific rules, while editing the race-specific files will actually set the rules that override the base ruleset (but will only be applied to that one race, obviously.)
Util is the other important folder that you'll find, since it is where you'll actually set some of how the AI "thinks" and which data is and isn't available to it. Some of the files won't be immediately useful to beginning AI coders, while some files such as lua_consts (which lets you set the references for units which are used by the AI, an especially useful thing since not all of the units are listed in the lua_consts file to begin with... which is why you never see the AI build some units) will help you to fine-tune exactly which units, abilities, and similar bits of the game the AI can access.
= = = = = = = = = = = = = = =
MODIFYING THE AI
= = = = = = = = = = = = = = =
Modifying the AI is technically a simple matter, since all that you have to do is make changes to the file and save it. Unfortunately, it's written in .lua/SCAR and is therefore rather easy to mess up unless you know what you're doing. Get the wrong context or try to use a bit of data that hasn't been defined yet and you're going to end up with SCAR errors that will kill the unit AI. Hence the reason for doing the background info first and then getting in to build order editing and such later... you need to understand at least a little of how things are structured before you just jump in and start editing things around.
If you think that you're ready to try your hand at editing the AI on your own, however, here are a few things that you should be sure to do:
- Make a backup copy of the file before you edit it. Open the file in Notepad, select File>Save As..., select "All Files" from the drop-down menu beneath the file name, then save the file as <filename>.ai.bak (with <filename> obviously being the original name of the file.) Once the backup has been saved, close it and reopen the original.
- Always make sure that you select "All Files" before saving AI files if using Save As..., since otherwise Notepad will save it as a .txt file.
- Be very careful with syntax. It's recommended that you study some of the existing AI files before you make any edits, since it can be very easy to make a typo or use the wrong syntax and kill the AI completely with a simple keystroke.
= = = = = = = = = = = = = = =
SO WHY'S THE AI SO DUMB?
= = = = = = = = = = = = = = =
The AI chooses a build order randomly from those which are defined, in theory giving way to more variety in matches. Unfortunately, some of these build orders are "free for all" orders which don't have anything in them at all. The AI picks units and upgrades at random, and if it can't make them it'll choose something else until it finds something that it can. This leads to mass-production of small-cost units and no real direction for what the AI should do. The buildorder_lib files acknowledge that this isn't optimal but that it was intended to add variety... unfortunately, there are 2 different build orders which feature this sort of free form structure (either with nothing or with very little) so at least half the time (statistically) the AI is going to be completely on its own without any idea of what to do.
= = = = = = = = = = = = = = =
INTERESTING FACTOID
= = = = = = = = = = = = = = =
Hidden within one of the AI files is instructions for specific DoW2 units... the Servitor, Bonesinger, Enginseer, Grot, and Genesplicer. Though it's been known for a while that the original builds of DoW2 contained base building with engineer units, it's interesting to see which units those actually were.
= = = = = = = = = = = = = = =
COMING SOON...
= = = = = = = = = = = = = = =
I'm actually planning on doing a few AI tutorials that will walk folks through things like making some units more likely to be built, controlling unit spam, and creating custom build orders that the AI can choose from. They'll be starting simple and getting a bit more complex, so hopefully be the time I finish 3 or 4 of them people who aren't comfortable enough with their abilities to root around in the AI will at least feel like tweaking it a bit to make it more to their liking.