Results 1 to 12 of 12

Thread: Campaign AI Recruitment in Rome II

  1. #1
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Campaign AI Recruitment in Rome II

    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:
    Spoiler Alert, click show to read: 



    3. Creating a new entry

    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
    Last edited by Litharion; October 31, 2014 at 11:27 PM. Reason: added How to make melee units recruitable for Sparta

  2. #2
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: Campaign AI Recruitment in Rome II

    Part 6 how to create new Army Configkeys (requires Startpos editing) added.

    Can be used for more diverse and faction specific AI armies

  3. #3

    Default Re: Campaign AI Recruitment in Rome II

    Litharion: last few days i struggled a lot with the AI recruitment decisions, especially for rebellion units. From what i observed, it seems like AI checks the unit quality rating but in the opposite way - for AI, quality = weight, so lower is the number, more units of that type AI will recruit.

  4. #4
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: Campaign AI Recruitment in Rome II

    so you mean that the AI recruits lower quality units if they are a Rebel faction ?

    The baseline I know is the higher the unit quality the more likely will the AI choose to recruit that unit instead of other units within the same category. The only other things that may affect the AI's choice are lack of money and the lack of better units.

  5. #5
    Magnar's Avatar Artifex
    Join Date
    Jul 2013
    Location
    The last place you look
    Posts
    4,370

    Default Re: Campaign AI Recruitment in Rome II

    The unit qualities are not relative to the category.

    The template shows the max number of units in each category then the qualities are compared to the unit costs to determine which units to recruit.

    You'll notice that the sum of the template unit ratios is greater that 20 (a full stack) and the quality values will determine which to recruit before hitting the template limit.

  6. #6
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: Campaign AI Recruitment in Rome II

    Quote Originally Posted by Magnar View Post
    The template shows the max number of units in each category then the qualities are compared to the unit costs to determine which units to recruit.
    You'll notice that the sum of the template unit ratios is greater that 20 (a full stack) and the quality values will determine which to recruit before hitting the template limit.
    are you sure about that ? As the so called template limit seems to be a soft limit, the AI is free to recruit more than the template limit of any unit category.
    E.g. a new template with 5 spear and 5 missile unit categories will still produce a full stack army close to 50% spear and 50% missile units. So there is no fixed limit to hit.

    Quote Originally Posted by Magnar View Post
    The unit qualities are not relative to the category.
    I have to agree, but it wonīt matter. If all missile units only have a quality of "100" compared to "10.000" for the spear units. The quality will only determine the unit within the category and probably the sequence of recruitment. In the end the army will still consist of 10 spear and 10 missile units.

    From my point of view the best way to balance the quality values is within a category combined with more stringent army ratios.

  7. #7

    Default Re: Campaign AI Recruitment in Rome II

    All i experienced was that AI was recruiting ranged units only, when ranged units had 1 set in the cdir_military_generator_template_ratios in appropriate category for that faction. I did dozen of campaign runs, always with the same results, where AI's army for that particular faction had stacks of 75% ranged units (usually, melee unit as commander, and 8 javelinmen or similar). AI was definitely not out of money, as that faction being client, gave me gifts every now and then typically at least 6000..

    Now, when i reduced numbers for melee and spears from 20/10 to 12/6, while ranged kept at 1, suddenly AI stopped that behavior and recruited melee infantry.


    Completely another issue was how AI selected rebel units. Rebel armies most likely use default template, yet while rebelion units everywhere else were approximately ok, those in Italy and Sicily, were prominently composed of ranged units only. I even tried to give melee units in ranged class, but with no effect. reducing their cost while increasing quality had no effect. Things changed with opposite approach, where i reduced the quality to the level those ranged units had.. AI selected those units immediately.

  8. #8
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: Campaign AI Recruitment in Rome II

    Quote Originally Posted by JaM View Post
    Now, when i reduced numbers for melee and spears from 20/10 to 12/6, while ranged kept at 1, suddenly AI stopped that behavior and recruited melee infantry.
    Maybe the total number was a bit too high for the respective template. I think you can achieve reasonable good results with template ratios based around a total of 20. At least all my template ratios are based around the number.

    Quote Originally Posted by JaM View Post
    Completely another issue was how AI selected rebel units. Rebel armies most likely use default template, yet while rebelion units everywhere else were approximately ok, those in Italy and Sicily, were prominently composed of ranged units only. I even tried to give melee units in ranged class, but with no effect. reducing their cost while increasing quality had no effect. Things changed with opposite approach, where i reduced the quality to the level those ranged units had.. AI selected those units immediately.
    Interesting maybe the rebel factions work differently then. You can circumvent problems like this by balancing the quality of all your units within a category. E.g. weakest missile unit = 100, weakest melee unit = 100 or a number close to 100. As the unit quality values are only important for AI recruitment they donīt have to represent the actual strength of a unit.

  9. #9
    Junaidi83 de Bodemloze's Avatar Dont Mess With Me
    Join Date
    Feb 2011
    Location
    Indonesia
    Posts
    2,616

    Default Re: Campaign AI Recruitment in Rome II

    Ah great tutorial deserve +rep, remember me back on shogun 2
    Modding is like accursed wine, you try a sip and you ended empty the whole glass
    Under Proud Patronage of Shankbot de Bodemloze

  10. #10

    Default Re: Campaign AI Recruitment in Rome II

    Hi Litharion!
    Can u add tutorial about adding new mercenary units to campaign?
    thx.

  11. #11

    Default Re: Campaign AI Recruitment in Rome II

    Is there any way to get the AI to recruit anything other than full stacks? I tried changing the ratios, but still only get full stacks in game.

  12. #12
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: Campaign AI Recruitment in Rome II

    Quote Originally Posted by CIaagent11 View Post
    Is there any way to get the AI to recruit anything other than full stacks? I tried changing the ratios, but still only get full stacks in game.
    not as far as I know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •