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.