Hello future modders and modders
Since I was unhappy with armies build by AI factions, I created the Better AI Recruitment mod for Rome II late February 2014.
This tutorial will help to understand the current system and how to modify it, the tutorial will be separated into different parts, from basic changes to advanced changes meant for complete overhauls of the current system.
English is not my native language and I have never done a tutorial before. I hope the tutorial is understandable. Feel free to ask questions if you are unable to understand certain parts.
Tools we need:
PFM
Introduction: How the System works: cdir table connections
Part 1 basics: Table overview (requires PFM )
Part 2 basic modding: How to change AI army compositions (requires Part 1)
Part 3 basic modding: How to change unit qualities (requires Part 1 and 2)
Part 4 extended modding: How to add new unit groups (requires Part 1 to 3)
Part 5 extended modding: How to add additional army templates (requires Part 1-3)
Part 6 advanced modding: How to add a new Configkey (requires Part 1 to 3 and Part 5)
How the System works: cdir table connections
db tables are marked green
Config_key:
Every AI faction has a Config_key assigned to it in the startpos
Compressed_Data -> World -> Faction Array -> Faction Array - "Number" -> Faction, row 17
Faction Array ID
You can find all Config_keys used in the game in the cdir_military_generator_configs_table
template_key:
The Config_key itself is not responsible for the AI army composition. This is defined with a template_key connected to the faction (Config_key) in
cdir_military_generator_template_priorities_table. This way the game recognized to which Faction (Config_key) the actual army composition
(template_key) belongs. You can find all template_keys here cdir_military_generator_templates_table.
template_ratio:
After the template_key is assigned to a Faction (Config_key), each template gets a set of different Group_keys assigned to it.
Group_keys are used to differentiate between different unit types like spearmen or Elephants. Only if a Group_key is assigned to a template,
the faction using the template will be able to recruit that unit type (group_key).
The cdir_military_generator_template_ratios_table is consequently the most important one for changing AI army compositions.
unit_group_key:
Every unit located in the main_unit_table is linked to a Group_key in cdir_military_generator_unit_qualities_table.
A list of all group_keys can be found in the Group_key ist cdir_military_generator_unit_groups_table.
Config_key -> Template_key -> Template_ratios -> Unit_Group_key -> Main_Unit
Part 1 basics: Table overview
Part 1 basics: Table overview
First we take a quick look at the most important tables for basic changes, like decreasing AI missile unit or artillery recruitment. Most changes we do in that area work as table fragments.
tables you need:
cdir_military_generator_unit_qualities_tables
cdir_military_generator_template_ratios_tables
notes: the cdir_unit_balances_tables seem not to work with Rome II, at least I am unable to see any effect.
cdir_military_generator_unit_qualities_tables vanilla:
Spoiler Alert, click show to read:
keys:
Spoiler Alert, click show to read:
group_key: This key determinants to which unit type group the unit belongs. All group keys can be found in the cdir_military_generator_unit_groups_tables, we will take a closer look at the table in Part 4.
unit_key: Unit key, pretty simply the unit from the main unit table.
quality: The Quality values determinants how the AI evaluates certain unit types. The higher the quality the more will the AI prefer to build the unit instead of other units with the same group key.
cdir_military_generator_template_ratios_tables vanilla:
Spoiler Alert, click show to read:
keys:
Spoiler Alert, click show to read:
template_key: This key determinants to which template the the value belongs. All vanilla templates can be found in the cdir_military_generator_templates_tables. We will take a closer look at the table in part 5
unit_group: This key determinants which unit groups will be recruited by the template assigned before. The AI will always prefer units with a higher quality.
ratio: The Ratio determinants how many units of a certain unit group will be recruited by the faction. The Higher the ratio the more units of that group will be recruited by the AI. You can set values from 1 to 99999.
Part 2 basic modding: How to change AI army compositions
table you need:
cdir_military_generator_template_ratios_tables - table fragment
a.) lowering missile unit recruitment
At first we choose something we dislike about AI armies and then simply change that. For the tutorial I will decrease missile_unit recruitment and will make Egyptian Archers more likely being recruited by the Egyptians than other Skirmishers.
We start creating a new table: We donīt need the full table to decrease missile unit ratios. A table fragment will do. We copy all values with the default_land_missile_unit group key into the newly created table.
Now we lower the ratios for all of them to the value we see fits the template. For the tutorial I have changed the ratio to 2 for all templates.
Spoiler Alert, click show to read:
AI armies will now use less missile units generally.
b.) Make swordsmen recruitable for Sparta
We also can use the table to add unit group_keys to templates which donīt use them. Sparta for example has no group_key for melee units in the cdir_military_generator_template_ratios_table.
If we want the Spartan AI to recruit swordsmen, we have to add the group key to their template ratio.
Example:
Spoiler Alert, click show to read:
Part 3 basic modding: How to change unit qualities
As we have learned all ratios are connected to unit groups like default_land_infantry_missile. The AI will recruit the units available to it in the group with the highest quality value.
In vanilla Egyptian Javelinemen have a higher rating than Archers to change that we can either lower the Javelinmen quality or raise the Archer quality or combine both.
table you need:
cdir_military_generator_unit_qualities_tables - table fragment
Spoiler Alert, click show to read:
Spoiler Alert, click show to read:
Vanilla:
Default_land_infantry_missile Egy_Archers 500
Default_land_infantry_missile Egy_Javelinmen 534
Changed:
Default_land_infantry_missile Egy_Archers 550
Default_land_infantry_missile Egy_Javelinmen 400
The AI will now recruit Egyptian Archers more often than Javelinmen.
Part 4 extended modding: How to add new unit groups keys
A Very powerful way to change and differentiate AI army recruitment is the addition of new cdir recruitment unit group_keys. This is done in the cdir_military_generator_unit_groups_tables.
For the tutorial we will create an new unit group called "land_War_Dogs" and assign it to every Dog unit in the base game. Further more we have to add the unit group to the cdir_military_generator_unit_qualities_tables and cdir_military_generator_template_ratios_tables, if we want the AI to recruit our custom group.
tables you need:
cai_construction_system_categories - table fragment
cdir_military_generator_unit_groups_tables - table fragment
cdir_military_generator_template_ratios_tables - table fragment
cdir_military_generator_unit_qualities_tables - full table!
1. Adding new Unit Groups:
At first we simply add our new group_key : "land_War_Dogs" to a cdir_military_generator_unit_groups_tables
Spoiler Alert, click show to read:
Now we let the cai_construction table know that a new military group key exists by adding those values to a cai_construction_system_categories. The AI now knows in order to get the land_War_Dog unit, I have to construct a building belonging to the cai_military_land_group for example barracks.
Example:
Spoiler Alert, click show to read:
cai_category_military_land_War_Dogs - custom key - The first key only matters if we have a building type especially for our Dogs. You can customize the name.
cai_military_land_group - set key from cai_construction_system_category_group
land_War_Dogs - Key we added to a cdir_military_generator_unit_groups_tables - table fragment
2. Adding the Group key to the cdir_military_generator_unit_qualities_table - full table!
To change vanilla unit_group_keys we have to add the full cdir_military_generator_unit_qualities_table to our pack and change the group_key for our Dogs from default_land_infantry_melee to land_War_Dogs.
Table fragments will not work properly as far as I can tell.
Spoiler Alert, click show to read:
3. Adding the Group key to the cdir_military_generator_template_ratios_table
The new values are now set to be used by our basic tables. Now we make our new cdir unit type recruitable by the AI.
- cdir_military_generator_template_ratios_tables - table fragment
We now create a new table fragment and add the new group key with a ratio we like to the template we want to able to recruit War_Dogs for example Roman_land.
Example:
Spoiler Alert, click show to read:
Part 5 extended modding: how to create additional army templates
Currently all factions use the same Default_Naval templates and generally only one army template per Config_key. This part will explain how we can add more than 1 template to a given Config_key. Instead of only using one army setup the AI has then the choice to create different army compositions. This powerful method was fully integrated into DeI 0.9. We will create different army templates for Parthia. The new template will use infantry as base. (note a general unit on the campaign map will only use one template at a time, this means you can create different army setups for the same faction)
In the end we will change the vanilla template to a cavalry only one. This way the AI is able to create specialized and varied armies.
tables needed:
cdir_military_generator_template_priorities_tables - table fragment
cdir_military_generator_template_ratios_tables - table fragment
cdir_military_generator_templates_tables - table fragment
1. Creating a new template entry - cdir_military_generator_templates_table - table fragment
At first we create a new entry in the cdir_military_generator_templates_table. We can customize the name. I will name it "Parthia_infantry"
Spoiler Alert, click show to read:
2. Assigning the template to a Config_key - cdir_military_generator_template_ratios_tables - table fragment
Now we assign the new template to a Config_key found in the cdir_military_generator_configs_table. We will take closer look at the keys in the last part of the tutorial.
The Config_key for the parthian faction is Parthia. The template key has to be the new one we created Parthia_infantry. The Ratio value can be set to increase the frequency of the newly created template.
The higher the value the more will the AI prefer using the template. The default value is 1.
Example:
Spoiler Alert, click show to read:
3. Adding Unit_groups to the new template - cdir_military_generator_template_priorities_tables - table fragment
The last thing we need to do is to add the unit groups the new template should use. We can be as creative as we want or be strictly historical . Again Unit Groups can be found in the cdir_military_generator_unit_groups_table.
Example:
Spoiler Alert, click show to read:
Parthia is now able to recruit a new army setup. To finalize the the variation we could change the parthian vanilla template to a cavalry only one.
This would require the full table as we have to delete all infantry entries for the vanilla parthian template.
Example:
Spoiler Alert, click show to read:
Part 6 advanced modding: How to add a new Configkey
1. add the Startpos
add the Startpos to your newly created mod pack with Add -> File. The Main Campaign Startpos is usually located here ....\Total War Rome II\data\campaigns\main_rome
Spoiler Alert, click show to read:
2. Go to Compressed_Data -> Campaign_Env -> Campaign_Model -> World -> Faction Array XX -> Faction -> The entry we are looking for is located in row 17
This entry is referenced by cdir_military_generator_configs_tables.
Startpos entry
Spoiler Alert, click show to read:
DB entry:
3. Creating a new entrySpoiler Alert, click show to read:
To create a new entry we have to set it up in the cdir_military_generator_configs_tables and change the value in the startpos.
If you take a look through the Confikkeys you will notice that only 41 keys are used for all factions in the game (including CiG, EE, HatG) many faction share the same key.
For example Athens and Syracuse. We will split up both factions and create Syracuse as a new Configkey (Syracuse Faction Array is 26 in vanilla 2.0).
New Startpos entry
Spoiler Alert, click show to read:
New DB entry
Spoiler Alert, click show to read:
4. Add Army Templates
The new Configkey now needs army templates already explained under 5. All new entries can be added as table fragments.
p.s. Donīt forget do add a naval template to the new Configkey as well.
With the tutorial I want to say thank you to the great community here at twc