Page 2 of 2 FirstFirst 12
Results 21 to 38 of 38

Thread: AI Expansion

  1. #21

    Default Re: AI Expansion

    Part 2: New Baseline

    Strat file changes

    I have personal preferences with regard to the game's starting position:

    --lower settlement level e.g city to large town
    --lower starting population
    --more pre-placed buildings
    --starting garrisons reflecting settlements
    --slightly lower starting armies
    --slightly weaker rebel garrisons except in a few places like Prague, Antioch, Antwerp etc
    --starting villages replaced with an actual settlement usually a castle
    --change some towns to castles

    and as a lot of these changes slow down the AI expansion i wanted to show the effect of certain changes on the pure vanilla setup first then make these changes so i have a clear new baseline for future tweaks. All the changes are strat file changes to the settlements and starting armies.

    Before these changes the AI was managing to take in the range of 150-160 regions by turn 12 whereas after these changes it was down around 140. Some reasons for this:

    1) replacing the empty villages of york, dublin, durazzo, zagreb etc with castles that have to be sieged
    2) smaller starting settlement size and population reduces faction income
    3) adding bowyer and stable to the garrison quarters i'd already added to the starting AI castles (this slows the AI slightly in the early turns but makes playing more interesting when you have the first tier of units from the start)

    Also the changes led to some AI glitches which will be the subject of the next post.

    Recruitment Changes

    Secondly, as mentioned before, the expansion of specific factions can be improved by tailoring their recruitment to produce stronger armies. As a prelude to that i changed the recruitment in the building file to give me a standardized recruitment pattern for each faction e.g castles were set to produce units in proportion 4 infantry, 2 missiles and 2 cavalry. The individual units changed with upgrades but the proportions remained constant. I set each faction to have the same pattern so i could compare their expansion before tweaking things to make each faction more individual.

    So the wooden castles with pre-placed military buildings the factions start with might have a production pattern of:

    1 x Mailed Knights
    1 x Hobilar
    2 x Peasant Archers
    2 x Levy Spearmen
    2 x Peasants

    with replenishment set to four turns per unit.

    The turk AI equivalent:

    1 x Turkomans
    1 x Turkish Horse Archers
    2 x Peasant Archers
    2 x Turkish Javelinmen
    2 x Peasants

    etc.

    With the new recruitment added in the baseline was slightly lower around 138 regions captured.

    So the next step is to try to bring it back up to the 150s again.

    +++

    Next post, England and Venice.
    Last edited by tupodawg999; January 26, 2010 at 05:22 AM.

  2. #22

    Default Re: AI Expansion

    England and Venice

    The AI expansion can be effected in unexpected ways as anything that can effect the game's auto-resolve calcs can change how the AI moves and that can throw up glitchs.

    England

    With my previous baseline England were gaining 7-9 regions per six tests i.e they were gaining 0-2 regions per test. After my strat file and recruitment changes that dropped to 0-1 regions per six tests i.e in most tests they got none.

    So i start as egypt in the vanilla game and watched the english AI for the first few turns and then did the same in my mod to try and spot what was happening. The problem is the AI has a pathing problem from Nottingham to Caernarvon and my changes had changed the AI's sequence of attack.

    In the original setup the english AI targeted Caernarvon from London and York from Nottingham - sometimes they succeeded sometimes not but it was fine. After i changed the starting settlements and garrisons around however the sequence of initial english AI moves ended up targeting Caernarvon from Nottingham thereby triggering the pathing problem...

    the AI usually does this in two steps, firstly it moves the army out of the city to the tile to the south-west and then the next turn the army moves off to attack, except in cases where they get stuck at that point (usually if it's > 1 but < 2 turns movement away) when the AI army just sits outside the city indefinitely.

    There are multiple ways to try and get around this.

    1) I tend to move all the starting armies inside starting settlements except where a faction has spare generals so i could move some out again to be closer to the cities i want them to attack. The problem with this method is if the army attacks and retreats they often get stuck again after the retreat.

    2) Another method is simply to mess around with starting garrisons until you make the AI change it's movement sequence in a way that gets round the problem. For example adding more units to the Caerarvon garrison for some reason made the AI attack York more strongly so they took York more often and attacked Caernarvon from York (previously there were weaker attacks against York plus the stuck Nottingham army which meant the english AI ended up taking neither).

    3) Try and edit the map to clear the pathing problem. This takes too much work usually.

    In this case the simplest solution is to take advantage of AI pathing seemingly always working when < 1 turns movement away. By moving Caernarvon one tile to the right and Nottingham one tile to the left an AI captain army of just infantry is just within one turns movement of both York and Caerarvon when standing on the tile to the SW of Nottingham. Another advantage of this solution is it should continue to work regardless of how many other changes i make to the starting position in future.



    Modding Details

    1) Go to expansiontest/data/world/maps/base
    2) Open up map_regions.tga
    3) Zoom to the releavant regions. The black dots represent the settlements. Move Caernarvon one square to the right and Nottingham one square to the left.
    4) Delete map.rwn



    5) Go to expansiontest/data/world/maps/campaign/imperial_campaign
    6) Open descr_strat.text
    7) Find the garrison for Caernarvon and increase the x co-ordinate by one
    8) Find the garrison for Nottingham and decrease the x co-ordinate by one

    Effect

    I'll test together with the Venice changes


    Venice

    Tests on the previous baseline had venice gaining 7-9 regions per six tests i.e they'd usually get Zagreb plus sometimes one other region. After the changes for part 2 they were gaining 0-2 regions per six tests i.e they took Zagreb sometimes but nothing else. This was due to changing Zagreb from a village to a wooden castle forcing a siege and the attacking Venice army no longer being strong enough to win the battle most of the time. However watching the early Venice moves i also noticed a few other things.

    Initial setup - Venice has a general in each starting town plus a spare general with an army near Zagreb. What happens is this outside army splits up with the general leaving the army. Then the general goes back to Venice while his old army marchs up and down aimlessly. Meanwhile the garrison from Venice targets Zagreb and moves out led by a captain to attack it. Thirdly the army in Ragusa moves outside and then gets stuck targeting Durazzo. You can tell it's stuck because the army starts to move when Durazzo is captured by someone else.

    Changing Zagreb from a village to a castle made the army from Venice too weak to win an assault most of the time. This was easily fixed by removing the army from the outside general and adding a couple of units to the Venice garrison. This saved the Venice AI a little useless upkeep money and after the change the outside general moved to Venice as before but the Venice army was now strong enough to win the assault on Zagreb more often.

    Ragusa fix - looking at the map the road from Ragusa to Durazzo takes a detour around some coastal mountains. Roads in the game will only form along orthogonal paths i.e a path of tiles that join left-right and up-down and not diagonally. The tile SW of Ragusa is sea so instead of the usual spot the AI army from Ragusa moves out to the tile directly west of Ragusa. Editing the map to take away the coastal corner of the mountain block made the road follow the coast and what this means is - when the Venice AI builds roads - Durazzo is within one turns movement of the Venice army outside Ragusa. So as soon as the Venice AI builds roads in Ragusa province the Ragusa army becomes unstuck.

    This means the Venice AI should occasionally attack Durazzo early on as well.



    Modding Details

    1) Go to expansiontest/data/world/maps/base
    2) Open up map_ground_types.tga
    3) Zoom to the releavant area of the map. Four pixels in this file map onto one tile in the game but the critical pixel that determines what the ground type is for the tile in game is the one with both odd co-ordinates i.e 343, 191. There is a set of high mountains pixels (pink) and we need to replace pixel 343, 191 with some other ground type. It can be anything other than mountains or high mountains. I picked the beige color that specifies hills.
    4) Delete map.rwn



    Effect

    In the last set of tests before the new baseline England took 6 regions over six tests and Venice took 9. After the strat file changes that went down to 1 and 2 respectively. With the changes described above it went back to 7 and 9 again. This should have added 10+ to my new baseline of 140 bringing it back to 150 ready for some more factional tweaks but instead it went up to 180 - which was a surprise.

    I'd tweaked the recruitment changes a little between tests and fixed some errors but nothing that would appear enough to make such a big difference. As i didn't do it step by step i'm not entirely sure why it suddenly went so well so the next post will backtrack on the changes to see if there's a clue.

    Regardless - 180 is new highpoint and marked improvement over vanilla's 102.

    +++

    Next post, Mystery Improvement
    Last edited by tupodawg999; January 27, 2010 at 04:54 AM.

  3. #23

    Default Re: AI Expansion

    Mystery Improvement

    The reason for going through this is it highlights a few useful points.

    To recap, before my strat file and recruitment changes my baseline was around 150-160. After the strat file changes it dropped to around 140. This wasn't surprising as replacing empty village settlements and some of the town settlements with castles was bound to slow the AI. On top of that the changes caused the England and Venice glitches described in the previous post. Between them those two things explained the drop. After fixing the two glitches i expected the baseline to go to just below the original 160 - because of more castles than the original - but instead got a massively improved 180. The question is why.

    I'd made three changes:

    1) Changed the descr_settlement_mechanics.xml file to give a minimum population for upgrading wooden castle to castles.
    2) Given all buildings that had the same minimum settlement requirement the same construction cost and time in export_descr_units.txt i.e everything buildable at the "town" level had the same construction time and cost, everything at the large_town level ditto etc.
    3) Recruitment changes in export_descr_units.txt.

    I removed both the two changed files from the mod folder so things were back to the way they were apart from the map edits made to unglitch England and Venice mentioned in the previous post. Retesting gave a result of 162. As well as improving the performance of England and Venice the map edits had also improved the performance of the France AI. They went from capturing 0-1 regions per test before the map edits to capturing around 2-4 per test.

    Throughout the whole process so far the French AI had been poor but i hadn't got around to looking for its problems yet, assuming one or more of their important early armies consistently got stuck. The map edits for Venice and England seem to have fixed whatever the problem was. This isn't unusal with map changes. Whenever you make an edit you have to delete map.rwn so the game regenerates it. That process must involve reading all these map files and creating some kind of data array in the map.rwn that gets used for path-finding among other things. Many times in the past i've made map changes in one part of the map that caused or fixed pathing problems on the other side of the map. The key point is to not worry about it too much except at the end as every fix you make can be unfixed by a later change and vice versa.

    So a big part of the mystery improvement was a sudden dramatic improvement in the French expansion caused (i will assume) by a pathing error getting fixed (for now).

    Settlement Mechanics File

    Another change i'd made but didn't mention as i didn't think it would be relevant was to the descr_settlement_mechanics.xml file. This file contains minimum population requirements to upgrade settlements. The original code had no requirements for motte and bailey castles to upgrade to wooden castles and from there to castle. The first minimum requirement was on fortresses:

    <population_levels>
    <!-- city -->
    <level name="village" base="400" upgrade="800" min="400" max="1500"/>
    <level name="town" base="800" upgrade="2000" min="400" max="3500"/>
    <level name="large_town" base="2000" upgrade="6000" min="400" max="9000"/>
    <level name="city" base="6000" upgrade="12000" min="400" max="18000"/>
    <level name="large_city" base="12000" upgrade="24000" min="400" max="36000"/>
    <level name="huge_city" base="24000" min="400" max="72000"/>
    <!-- castle -->
    <level name="moot_and_bailey" base="400" upgrade="0" min="400" max="1500"/>
    <level name="wooden_castle" base="400" upgrade="0" min="400" max="3500"/>
    <level name="castle" base="1500" upgrade="4500" min="400" max="9000"/>
    <level name="fortress" base="4500" upgrade="9000" min="400" max="13500"/>
    <level name="citadel" base="9000" upgrade="18000" min="400" max="18000"/>
    </population_levels>
    I changed it so there was a minimum population of 2000 to upgrade from a wooden castle to a castle.

    <population_levels>
    <!-- city -->
    <level name="village" base="400" upgrade="800" min="400" max="1500"/>
    <level name="town" base="800" upgrade="2000" min="400" max="3500"/>
    <level name="large_town" base="2000" upgrade="6000" min="400" max="9000"/>
    <level name="city" base="6000" upgrade="12000" min="400" max="18000"/>
    <level name="large_city" base="12000" upgrade="24000" min="400" max="36000"/>
    <level name="huge_city" base="24000" min="400" max="72000"/>
    <!-- castle -->
    <level name="moot_and_bailey" base="400" upgrade="800" min="400" max="1500"/>
    <level name="wooden_castle" base="800" upgrade="2000" min="400" max="3500"/>
    <level name="castle" base="2000" upgrade="4500" min="400" max="9000"/>
    <level name="fortress" base="4500" upgrade="9000" min="400" max="13500"/>
    <level name="citadel" base="9000" upgrade="18000" min="400" max="18000"/>
    </population_levels>
    I'd changed the starting castles for the factions to be wooden castles with a pop of 1600 as part of my strat file changes. The reason this turned out to be important than it appeared is illustrated by the screenshots.

    The first image shows what the AI has available to build in one of the starting wooden castles with the upgrade requirement in place. Four options one of which is a road. If the AI randomly picked what it was going to build and built one building after the other there would be a very high chance of roads being built within 10 tens.




    The second image shows what the AI's building options are without the upgrade requirement. The settlement pop is 1600 but there is no requirement for a minimum of 2000 so the castle upgrade is displayed. In theory there doesn't appear to be much difference as there are now 5 options which if the AI chooses randomly would slightly reduce the average time it took for the AI to build roads. Except the AI doesn't choose randomly when there is a settlement upgrade available. It always seems to pick that if it has the cash.






    So the third image shows the actual difference between the two cases plus n, where n is the number of turns it takes to build the castle. As the AI always seems to build the upgrade first then the true comparison is between the first set of options and this set i.e 9 options, most of which take longer to build than the four choices in the original image plus the n turns it took to build the castle. So basically the difference between having the upgrade requirement and not having it is the difference between the AI being highly likely to build roads within 10 turns (if it has the money) and being extremely unlikely to build roads within 10 turns. As movement costs are so important this change turned out to be significant to the AI expansion.

    (This is on the assumption that the AI factions are all set to the default "balanced smith" setting in the strat file.)



    So this seemingly unimportant change turned out to be worth around 2 extra captured regions per test which is surprisingly significant. This brought the baseline from c162 up to around 174 explaining another significant chunk of the mystery improvement.


    Building Construction Time

    I'd changed all the buildings to have the same cost and construction time per settlement level i.e all the buildings with a village minimum i'd set to 2/600, town level buildings also 2/600, large town to 3/1200, city level to 4/2400.

    The reason for this was after the automated testing i'd look to see what the england AI had built and noticed they'd almost never built the mines - which i always build first. I set the costs and times all the same in case the AI took that into account.

    This change on its own did improve the baseline a little - around +1 settlement per test - i assume through the slight reduction in the average cost of early upgrading of captured rebel regions so they produce better units sooner.

    Recruitment Changes

    Finally the recruitment changes. These also had a very small improving effect which brought the baseline up to the new total of around 180. The changes reduce the total amount of units that can be recruited rapidly while controlling the proprtions to maintain average quality. This both reduces and increases the amount of autocalc points being created so it wasn't surprising to me there wasn't an effect in the short term. Longer term there should hopefully be a benefit from the AI not running out of money by spamming units but that isn't a problem in the first few turns.


    Conclusion

    That explains the sudden improvement after the previous changes and illustrates how all sorts of edits can effect AI expansion.

    +++

    Next post, modding for the AI, Rebels.
    Last edited by tupodawg999; January 27, 2010 at 05:11 AM.

  4. #24

    Default Re: AI Expansion

    Modding for the AI: Rebels

    (The "Modding for the AI" set of posts wil not be directly about improving the AI performance but with the indirect consequences of some of those AI improving changes.)

    In post 6 (brigands, pirates and revolts) i suggested that weakening rebels helped the AI and that meant reducing initial settlement garrisons and also limiting the units that can spawn randomly as brigands to only the weaker units. This works but also helps the player. My aim is to try and reduce the AI's handicaps but if that leads to a helping the player also then i want to add back the handicap but in a way that makes it player only. So this post describes some methods of doing that using script.

    Increasing Garrisons

    I set the standard garrison in the strat file to be four average units except in certain buffer regions where it's double. For the player however i add some extra to the regions the player is likely to reach before the AI for each faction. So for egypt it might be Dongola, Acre and Jerusalem whereas Scotland might be Dublin and Edinburgh.

    Example code

    Code:
     
    ;;;;;;;;;;;;;;;;;;;;;;;;
    ; -- Scotland
    ;;;;;;;;;;;;;;;;;;;;;;;;
    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    and I_LocalFaction scotland
     
     
    create_unit Edinburgh, Spear Militia, num 2, exp 3
    create_unit Edinburgh, Town Militia, num 2, exp 3
    create_unit Edinburgh, Peasant Archers, num 2, exp 3
     
    create_unit Dublin, Galloglaich, num 2, exp 3
    create_unit Dublin, Irish Kerns, num 4, exp 3
     
    terminate_monitor
    end_monitor

    Random Starting Headache

    In many cases however the nearest rebel regions for a particular faction are shared with AI factions so increasing the garrison hinders the AI equally e.g if the player was France and the garrison of Metz was greatly increased it would hinder HRE also. So instead of or as well as increasing garrisons in some settlements we can add some random player headaches.

    The first step is to add a random element so it's not the same every game. There's probably better ways of doing it (and there definitely is if using Kingdoms) but what i do in 1.2 is:

    Code:
    declare_counter random_headache
     
    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    and RandomPercent > 20
     
    set_counter random_headache 1
     
    terminate_monitor
    end_monitor
     
     
    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    and I_CompareCounter random_headache = 1
    and RandomPercent > 25
     
    set_counter random_headache 2
     
    terminate_monitor
    end_monitor
     
    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    and I_CompareCounter random_headache = 2
    and RandomPercent > 33
     
    set_counter random_headache 3
     
    terminate_monitor
    end_monitor
     
    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    and I_CompareCounter random_headache = 3
    and RandomPercent > 50
     
    set_counter random_headache 4
     
    terminate_monitor
    end_monitor
    If i calculated right at the beginning of each game the random_headache counter should get a value from 0 to 4 with a roughly 20% chance of each. Then you use this value to spawn some rebel armies around the player.

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;
    ; -- Scotland
    ;;;;;;;;;;;;;;;;;;;;;;;;
    monitor_event FactionTurnStart FactionIsLocal
    and I_TurnNumber = 0
    and I_LocalFaction scotland
     
     
    if I_CompareCounter random_headache == 2
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 104, y 170,
    unit Highlanders exp 3 armour 0 weapon_lvl 0
    unit Highlanders exp 0 armour 0 weapon_lvl 0
    unit Highlanders exp 0 armour 0 weapon_lvl 0
    unit Highland Rabble exp 0 armour 0 weapon_lvl 0
    unit Highland Rabble exp 0 armour 0 weapon_lvl 0
    end
     
    end_if
     
     
    if I_CompareCounter random_headache == 3
     
    spawn_army
    faction slave
    character Primus, general, age 30, x 100, y 184,
    unit Norse Swordsmen exp 6 armour 0 weapon_lvl 0
    unit Viking Raiders exp 3 armour 0 weapon_lvl 0
    unit Viking Raiders exp 3 armour 0 weapon_lvl 0
    end
     
    end_if
     
    if I_CompareCounter random_headache == 4
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 92, y 168,
    unit Galloglaich exp 3 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    end
     
    end_if
     
    terminate_monitor
    end_monitor
    If random_headache gets set to 0 or 1 then there's no spawn but if it's 2, 3 and 4 then the player would get a highland army or viking raid in Inverness or an Irish force guarding the land-bridge to Dublin.

    Scotland has a couple of rebel regions which only the player is likely to attack before the AI i.e Dublin and Edinburgh so in this case i only had 3 spawned armies rather than the maximum 5. For a faction like HRE where most of the surrounding regions are shared with other factions i'd set a sizable headache army to spawn with all 5 of the random_headache values.

    Edgy Rebels

    The above scripts can be used to compensate for making the initial rebel garrisons slightly weaker but i also want something to compensate for making the brigand spawns weaker as that will effect the whole game. I want it to be player only. I also don't want it everywhere as i want to make particular regions stand out.

    The first set of additional scripted rebels will be in edgy regions where these are regions on the edge of the map or regions well known for rebellion. I'll give these regions scripts that randomly spawn a rebel force if the player holds the settlement.

    Example:

    Code:
    monitor_event SettlementTurnStart SettlementIsLocal
    and SettlementName Inverness
    and RandomPercent > 95
    ;and not I_LocalFaction scotland
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 96, y 178,
    unit Highlanders exp 3 armour 0 weapon_lvl 0
    unit Highlanders exp 0 armour 0 weapon_lvl 0
    unit Highlanders exp 0 armour 0 weapon_lvl 0
    unit Highland Rabble exp 0 armour 0 weapon_lvl 0
    unit Highland Rabble exp 0 armour 0 weapon_lvl 0
    end
     
    end_monitor
    This very simply checks to see if the player holds Inverness and if so gives a 5% chance of spawning a rebel army. On the vanilla map i'd have something like this for Inverness, Dublin, Caernarvon, Oslo, Stockholm, Riga, Arguin, Timbuctoo, Dongola, Jedda. I'd probably leave the eastern and north-eastern edges because the mongols and timurids do a similar job.

    As well as these edge regions i'd have something similar on a few particular regions like Bern, Prague, Adana etc.

    You can vary it somewhat for example i don't like rebel swiss pikemen spawning early on so i could add a turn number condition for Bern:

    Code:
    monitor_event SettlementTurnStart SettlementIsLocal
    and SettlementName Bern
    and I_TurnNumber > 100
    and RandomPercent > 95
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 129, y 122,
    unit Halberd Militia exp 3 armour 0 weapon_lvl 0
    unit Halberd Militia exp 0 armour 0 weapon_lvl 0
    unit Halberd Militia exp 0 armour 0 weapon_lvl 0
    unit Swiss Pikemen exp 0 armour 0 weapon_lvl 0
    unit Swiss Pikemen exp 0 armour 0 weapon_lvl 0
    unit Swiss Pikemen exp 0 armour 0 weapon_lvl 0
    unit Swiss Pikemen exp 0 armour 0 weapon_lvl 0
    unit Crossbow Militia exp 0 armour 0 weapon_lvl 0
    unit Crossbow Militia exp 0 armour 0 weapon_lvl 0
    end
     
    end_monitor
    Another idea would to have revolts that built up and subsided. So we declare a counter e.g irish_rebellion and then have three monitors. One triggers when the counter is 0, increments the counter to 1 and spawns a small army. The second triggers when the counter is 1, increments it to 2 and spawns a medium army. The third (actually the first in the actual script file) triggers when the counter is set to 2, sets it back to 0, and then spawns a large army.

    Code:
    declare_counter irish_rebellion
     
    monitor_event SettlementTurnStart SettlementIsLocal
    and SettlementName Dublin
    and I_CompareCounter irish_rebellion = 2
    and RandomPercent > 95
     
    set_counter irish_rebellion 0
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 88, y 163,
    unit Galloglaich exp 3 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 3 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    end
     
    end_monitor
     
    monitor_event SettlementTurnStart SettlementIsLocal
    and SettlementName Dublin
    and I_CompareCounter irish_rebellion = 1
    and RandomPercent > 95
     
    set_counter irish_rebellion 2
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 89, y 162,
    unit Galloglaich exp 3 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    end
     
    end_monitor
     
    monitor_event SettlementTurnStart SettlementIsLocal
    and SettlementName Dublin
    and I_CompareCounter irish_rebellion = 0
    and RandomPercent > 95
     
    set_counter irish_rebellion 1
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 88, y 162,
    unit Galloglaich exp 3 armour 0 weapon_lvl 0
    unit Galloglaich exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    unit Irish Kerns exp 0 armour 0 weapon_lvl 0
    end
     
    end_monitor

    Capital Region Revolts

    Lastly i want scripted rebels in the main capital city regions. These will have two scripts each, one if the original faction holds the settlement and one if it's someone else. The scripts will trigger based on city happiness. So for example if Scotland holds Edinburgh there's a 50% chance of rebels spawning if the happy face is red. Any other faction there's a 50% chance of rebels spawning if the face is blue or red.

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; -- Capital region revolts
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
    monitor_event SettlementTurnStart SettlementIsLocal
    and SettlementName Edinburgh
    and I_LocalFaction scotland
    and SettlementLoyaltyLevel <= loyalty_rioting
    and RandomPercent > 50
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 104, y 174,
    unit Spear Militia exp 3 armour 0 weapon_lvl 0
    unit Town Militia exp 0 armour 0 weapon_lvl 0
    unit Town Militia exp 0 armour 0 weapon_lvl 0
    unit Peasants exp 0 armour 0 weapon_lvl 0
    unit Peasants exp 0 armour 0 weapon_lvl 0
    unit Highlanders exp 0 armour 0 weapon_lvl 0
    unit Highland Rabble exp 0 armour 0 weapon_lvl 0
    unit Highland Rabble exp 0 armour 0 weapon_lvl 0
    end
    end_monitor
     
    monitor_event SettlementTurnStart SettlementIsLocal
    and SettlementName Edinburgh
    and not I_LocalFaction scotland
    and SettlementLoyaltyLevel <= loyalty_disillusioned
    and RandomPercent > 50
     
    spawn_army 
    faction slave
    character Primus, general, age 30, x 104, y 174,
    unit Spear Militia exp 3 armour 0 weapon_lvl 0
    unit Town Militia exp 0 armour 0 weapon_lvl 0
    unit Town Militia exp 0 armour 0 weapon_lvl 0
    unit Peasants exp 0 armour 0 weapon_lvl 0
    unit Peasants exp 0 armour 0 weapon_lvl 0
    unit Highlanders exp 0 armour 0 weapon_lvl 0
    unit Highland Rabble exp 0 armour 0 weapon_lvl 0
    unit Highland Rabble exp 0 armour 0 weapon_lvl 0
    end
     
    end_monitor
    For the player these scripts should more than make up for weakening the random brigands but without effecting the AI much if at all.

    +++

    Next post, money.
    Last edited by tupodawg999; January 27, 2010 at 05:20 AM.

  5. #25

    Default Re: AI Expansion

    Modding for the AI (Missions, Money Shocks and Upkeep)

    The AI doesn't deal with unit upkeep very well. In particular it tends to spam units and bankrupt itself, especially on VH. One of the aims of my recruitment changes is to ration the total number of units the AI can build and a second strand is to try and change the upkeep so the player doesn't have an advantage.

    Generals and Princesses

    In vanilla family general wages are 200 plus 250 upkeep for the bodyguard. Princesses are 250. For a small faction this is a very big proportion of their total costs leading to potential early bankruptcy. For example Portugal has three generals and two princesses at start for a total of 3 x 450 + 2 x 250 = 1850 fl. I reduce the wages, bodyguard upkeep and princess wage to 100 each.

    You do this by opening descr_character.txt and editing the wage base line:

    Code:
     
    type named character
    actions moving_normal, moving_quickmarch, garrison, assault, attack, besiege, entrench, ambush, diplomacy, bribe, exchange, building_fort, building_watchtower
    wage_base 100
    starting_action_points 120
    and

    Code:
     
    type princess
    actions moving_normal, diplomacy, bribe, marry
    wage_base 100
    starting_action_points 180
    To reduce the bodyguard's upkeep you open export_descr_units.txt and find the stat_cost line for the each of the bodyguard units and edit the third number:

    Code:
     
    stat_cost 1, 820, 100, 120, 95, 820, 1, 200
    Mission Shocks

    When the player gets a council mission to take a settlement the reward can sometimes be four of the best units currently available e.g knights. The problem with this is knights have an upkeep of 250 each so the "reward" suddenly gives an extra upkeep cost of 1000 fl. This is too much especially at the start of the game imo. The easiset way to deal with this sort of problem is to just give the AI lots of money in script but i like to try and make the AI work as well as possible first before using that as a final tweak.

    One way to solve the problem is to simply remove those mission rewards from descr_missions.txt. The various different rewards are described like:

    Code:
    payback_list council_major_unit
    {
     reward
     {
      best_buildable_unit 1200 4
     }
    }
    So you can search for the "council_major_unit" payback and find entries like:

    Code:
     
    paybacks
    {
    random 0.5 payback_id council_major_income
    payback_id council_major_unit
    }
    What this does is give a 50/50 chance of getting the council_major_income reward or the unit one. If you change it to:

    Code:
     
    paybacks
    {
    payback_id council_major_income
    }
    Then the reward becomes just cash.

    The other option, which is what i did is reduce the upkeep of the best units. My reasoning was:

    1) The elite feudal units are fun - the more knights the better imo.
    2) It sort of makes sense for their upkeep to be less than other units because they're the feudal elite and the economic system is designed around supporting them.
    3) It will generally help the AI getting into bankruptcy problems from spamming too many units.

    So i reduced the upkeep of knights, siphais, tukomans, arab cavalry, mameluks etc to 100 each. Now if the AI gets the four best units reward it will only be 400 fl.

    Modding for the AI (Free Upkeep)

    The game has a neat feature where certain units get free upkeep in settlements. This simulates a feudal military which has people tending their lands and costing nothing who can be called up quickly in time of attack. In earlier modding attempts i extended the system to castles as well. However the AI doesn't use the system. As mentioned in previous posts the AI often leaves just a general in its settlements so what the free_upkeep system does when i play is give me circa four free units per settlement which adds up to a massive advantage over the AI of maybe 400-600 fl per settlement. So despite liking the system i decided to remove free_upkeep from my mod and instead reduce the upkeep of units across the board.

    To remove free_upkeep you open export_descr_buildings.txt in your mod folder and search for the lines that say "free_upkeep" and put a semi-colon in front:

    Code:
     
    ;free_upkeep bonus 2
    I then repeated what i did for bodyguards above and went through the units reducing the third number in their stat_cost line:

    Code:
     
    stat_cost 1, 820, 100, 120, 95, 820, 1, 200
    The upshot of these changes is so far both the AI and player has plenty of money. I'm planning to compensate for this change by adding a player-only script at some point where every general outside their terriotory costs a lot of cash each turn.

    +++

    Next post, unit stats
    Last edited by tupodawg999; February 03, 2010 at 02:40 PM.

  6. #26

    Default Re: AI Expansion

    Unit Stats

    Unit stats have a direct effect on the AI's expansion and little things can be significant. The AI expansion will mostly be via autocalc battles with other AI factions so in game terms each unit can be seen as an amount of autocalc points and combined with the recruitment system gives a rate of production of autocalc points. I don't think anyone knows the actual autocalc formula so i use number of soldiers times the melee attack strength to give me a rough value to compare between different units and different factions. You can see how adding or subtracting a couple of points from a unit type that makes up a lot of an AI faction's starting armies could dramtically change it's initial autocalc strength.

    In terms of the vanilla stats the most noticeable things are related to animation issues. In the tactical battles the melee attack is only part of the story - there's also how the animations are set up for each soldier type. Two-handed axemen for example had/have an animation problem and to attempt to compensate for this in the tactical battles the game gave two-handed axe units a very high melee attack value. Similarly the middle-eastern peasants have daggers with a fast attack animation so they were given a lower melee attack value than other peasants to compensate. The animations are irrelevant in the autocalc battles but the melee attack values still apply. Poland expands well in vanilla partly because of the high attack they get from their early woodsmen unit. The Turks don't expand well for many reasons but one small part is their peasant unit is worth 1/4 of a western peasant unit.

    1) Any change to the unit stats of early units can have a big impact on AI expansion.
    2) You can add strong starting units to help an AI faction early on
    3) Increasing starting strength doesn't always help as it can change the settlements the AI chooses to attack showing up pathing errors.

    Anyway i wanted to change the unit stats to the system i prefer. As my changes reduce the average strength of the units - through reductions in two-handed attack and cavalry swapping some attack for charge etc - i expect this to reduce my baseline again.

    nb My modding preferences leading to the AI expanding worse than before is why i started thinking about how to optimize the expansion to compensate.

    So previous baseline 180. New baseline after my unit stat changes back down to 162. This was expected for as well as a reduction in early strength especially for the 2H axe factions the changes to start strength caused a few factions to glitch as usual.

    However instead of tweaking the factions to get it back up again i want to look briefly at Campaign AI.

    +++

    Next post Campaign AI
    Last edited by tupodawg999; February 03, 2010 at 02:42 PM.

  7. #27

    Default Re: AI Expansion

    Campaign AI

    I won't go into the whole of the campaign AI i just want to illustrate some points that relate to early expansion against the rebels.

    The campaign AI is in descr_campaign_ai_db.xml and the part we are interested in are the invade decisions relating to the "slave" faction (which is the rebels) as the target in both the "default" and the "catholic" set of AI decisions. The vanilla file has four decision entries and the AI drops out of the file when it finds a decision that fits the circumstances specified. The four entries are:

    Code:
     
    <decision_entry>
    <!--
    special case the slaves faction - there are all sorts of things we don't want to do with the slaves
    -->
    <min_entry target_faction="slave"/>
    <max_entry turn_number="30" target_faction="slave"/>
    <faction_attitude invade="invade_immediate" invade_priority="1200"/>
    </decision_entry>
     
    
    <decision_entry>
    <!--
    special case the slaves faction - there are all sorts of things we don't want to do with the slaves
    if we've more than twice his frontline strength, then >>> invade immediate
    -->
    <min_entry target_faction="slave" frontline_balance="2.0"/>
    <max_entry target_faction="slave"/>
    <faction_attitude invade="invade_immediate" invade_priority="850"/>
    </decision_entry>
     
    <decision_entry>
    <!--
    special case the slaves faction - there are all sorts of things we don't want to do with the slaves
    if we're superior on the frontline, then >>> invade buildup
    -->
    <min_entry target_faction="slave" frontline_balance="1.0"/>
    <max_entry target_faction="slave"/>
    <faction_attitude invade="invade_buildup" invade_priority="850"/>
    </decision_entry>
     
    <decision_entry>
    <!--
    special case the slaves faction - there are all sorts of things we don't want to do with the slaves
    -->
    <min_entry target_faction="slave"/>
    <max_entry target_faction="slave"/>
    <faction_attitude invade="invade_opportunistic" invade_priority="850"/>
    </decision_entry>
    The first is the most critical. What it says is for the first 30 turns each AI faction should attack the slave faction using "invade immediate" with a priority of 1200. After 30 turns the game would bypass this entry and select one of the three below. The first of the three says to invade_immediate with a priority of 850 if the faction outnumbers the rebels by 2:1 on the frontline. If the ratio of strength is less than that but higher than 1: 1 then invade_buildup with a priority of 850. If below that then invade_opportunistic with a priority of 850.

    The problem with this is the blanket 30 turns given in the first entry. What can happen is, for example, one AI faction has many rebel regions to its east and attacks them. To the west of the faction is another AI faction which has no rebel regions nearby. The second faction attacks the first faction because its the best target but the first faction doesn't defend itself properly because it's too busy attacking the rebels to its east.

    The second problem is the conditions on the other entries relating to comparisons of frontline strength as i'm not convinced the game can calculate it accurately for the slave faction with its regions scattered all over the map. Invade_immediate sets the AI to attack straight away with its available forces and many times in the early game you'll see the AI attack a rebel region with weaker forces and end up retreating over and over.

    So some experiments (baseline 162 regions):

    1) I ran three tests where i replaced the four entires with just invade_immediate or just invade_buildup or just opportunistic, all three with a priority of 850. All three were worse than with immediate at 1200.
    2) Replacing the four entries with one entry specifying invade_buildup in all cases with a priority of 1200 gave 172 regions.
    3) Replacing the four entries with one entry specifying invade_opportunistic in all cases with a priority of 1200 gave 176 regions.

    Invade_immediate led the AI to attack faster but less successfully whereas opportunistic was initially slower but more effective leading to greater success.

    The invade priority influences how much of a faction's force is given to attack each faction they're at war with. Having just one decision entry for the slave faction meant the AI factions would always be paying a lot of attention to the slave faction even when they were at war with other factions. This led to the final version where there are two invade decisions relating to the slave faction.

    Code:
     
    <decision_entry>
    <!--
    special case the slaves faction - there are all sorts of things we don't want to do with the slaves
    -->
    <min_entry target_faction="slave"/>
    <max_entry target_faction="slave" num_enemies="0"/>
    <faction_attitude invade="invade_opportunistic" invade_priority="1200"/>
    </decision_entry>
     
    <decision_entry>
    <!--
    special case the slaves faction - there are all sorts of things we don't want to do with the slaves
    -->
    <min_entry target_faction="slave"/>
    <max_entry target_faction="slave"/>
    <faction_attitude invade="invade_opportunistic" invade_priority="600"/>
    </decision_entry>
    The first entry sets the AI to attack the slave faction with invade_opportunistic and a priority of 1200 if they're not at war with anyone else (num_enemies="0"). If the AI faction is at war with another faction or factions as well then the first entry won't apply and the decision will fall through to the second also sets invade to invade_opportunistic but with a priority of only 600 so the faction (hopefully) doesn't over-focus on rebels and ignore other threats.

    It will need further testing over longer test runs but going from 162 regions to 176 looks like a major improvement and shows at least the potential for optimizing the campaign AI for dealing with the rebs with fairly minimal effort.

    Also while editing this file i changed:

    Code:
     
    <use_cheat_overrides bool="false"/>
    from true to false. This is the value that sets the AI to specifically attack the player. It won't apply so early in the game anyway but it's worth getting rid of it as it makes the AI behave stupidly and as we've already shown there's better ways of improving the AI's performance.

  8. #28

    Default Re: AI Expansion

    Any chance you could upload a version of your map with the extra settlements?

  9. #29
    Gorrrrrn's Avatar Citizen
    Join Date
    Jan 2007
    Location
    here
    Posts
    5,546

    Default Re: AI Expansion

    re Mission Shocks
    http://www.twcenter.net/forums/showt...51#post6709051

    As far as I'm aware the AI factions don't get missions as such.

    --

    re settlement levels I'd recommend starting with a minimum level of towns and no villages - the latter are a pain in public order terms.
    ie their population isn't big enough to allow for public order buildings, and being captured usually causes a population drop.
    the AI doesn't keep a big enough garrison to maintain order, and sooner or later, the place rebels, the population drops and the settlement remains a village.
    and so on and so on ...

  10. #30
    irishron's Avatar Cura Palatii
    Join Date
    Feb 2005
    Location
    Cirith Ungol
    Posts
    47,023

    Default Re: AI Expansion

    I naven't gotten into the mechanics, but in my mod the ai will grow villages. In fact, I sieged one that was a village by the time I got there was a large town so it can be done.

    We are using BBB 4 and XAI if that helps.

  11. #31
    Methoz's Avatar Senator
    Join Date
    Jul 2005
    Location
    Bohemia (Czech: Čechy; German: Böhmen) (CZE)
    Posts
    1,281

    Default Re: AI Expansion

    can downlaod any file for new mod?
    TotalWarForum.cz
    Česko-Slovenské fórum o hrách ze série Total War

  12. #32

    Default Re: AI Expansion

    Very interesant thread, I would know how modd the power of the loyalists, who sometimes push the conqueror out from the city.
    Thanks

  13. #33
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: AI Expansion

    Moved this thread here.

    Pretty interesting read.
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  14. #34
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: AI Expansion

    I already read this thread about 2-3 years, but couldn't realize it's wisdom for that time.

    Well, that's a very interesting and illustrative example of AI improvement whith such a small changes. And also an argument of how disbalanced original game is.

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  15. #35
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: AI Expansion

    One more old hint (I suppose scince Rome I) - in descr_strat if you set different faction_creator for settlement then faction it owns at start of the campaign seems that faction set as faction_creator will try to capture this settlement. Need more tests but first drafts says it's true.

    So we can set principal targets for factions this way.

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  16. #36
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: AI Expansion

    Similar research form Nikolai1962 here https://forums.totalwar.org/vb/showt...-Game-AI-stuff

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  17. #37
    Jadli's Avatar The Fallen God
    Gaming Emeritus

    Join Date
    Dec 2013
    Location
    Czech Republic
    Posts
    8,528

    Default Re: AI Expansion

    Nice work! Wanted to rep but repped some other ppl recently

  18. #38

    Default Re: AI Expansion

    Chcem sa opýtať, aké vplyvy má to, ktoré regióny sú napadnuté konkrétnou AI frakciou? Alebo ako by mal vyzerať rozširujúci skript, ak chcem, aby sa frakcia AI zaujímala o útok na konkrétny región?

Page 2 of 2 FirstFirst 12

Posting Permissions

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