Garrison Script - one monitor per settlement for all factions & AIvsAI & AivsPl & PlvsAI
Hi, I want to share with you my latest success.
Following the 'good practice' to keep number of monitors at minimum in campaign_script I was able to create Garrison Script with one monitor per Settlement.
And one particular settlement monitor (GeneralAssaultsResidence) is able to :
.
handle creating faction specific troops for all factions.
distinguish scenarios for :
AI attacking AI (medium garrison), garrison size = settlement size -1 but minimum 1
AI attacking Player (small garrison), garrison size = settlement size -2 but minimum 1
Player attacking AI (large garrison), garrison size = settlement size
so AI is in favor against player.
Above garrison sizes are of course example ones, coould be different.
More info & guides about garrison scripts & GeneralAssaultsResidence event : herehereherehere
Here it goes :
Code:
monitor_event GeneralAssaultsResidence IsTargetRegionOneOf Venice_Province
and I_SettlementUnderSiege Venice
and I_CompareCounter Venice_LastSiegeMobilizationTurnsCount > 12 ;---- it's settlement 'recovery' counter, one garrison per 12 turns
if I_SettlementOwner Venice = denmark ;--- Defender is denmark, defender is AI or Player, we don't know yet ---
; #### Here goes 'common part' of scenarios : AI vs AI/Player & Player vs AI
create_unit Venice, Spear Militia, num 1, exp 2, arm 0, wep 0
create_unit Venice, Spear Militia, num 1, exp 2, arm 0, wep 0
create_unit Venice, Spear Militia, num 1, exp 2, arm 0, wep 0
console_command add_money denmark, -891 ;-- troops created so charge some money from treasury ....
log always ### Garrison Script: Sieged Settlement: Venice[L5_LargeCity] : denmark : Creating (891) [3]:Spear Militia,Spear Militia,Spear Militia,
if not I_LocalFaction denmark
;#### Here we know that the DEFENDER IS NOT the player (not Local) !!! ####
;#### So we create additional unit for AI defender
create_unit Venice, Crossbow Militia, num 1, exp 1, arm 0, wep 0
console_command add_money denmark, -368
log always ### Garrison Script: Sieged Settlement: Venice[L5_LargeCity] : denmark : Creating (368) [1]:Crossbow Militia,
if I_CompareCounter ai_ec_id = 0
;#### Here we know that the ATTACKER IS the PLAYER (Local) ####
;#### ai_ec_id - Stainless Steel / SSHIP counter set on PreFactionTurnStart, 'early' in the script,
;#### ai_ec_id ::: 0=Local player, 1=rebels, 2=venice etc
;#### So -> AI is attacked by the player -> create additional unit(s)
create_unit Venice, Crossbow Militia, num 1, exp 1, arm 0, wep 0
console_command add_money denmark, -368
log always ### Garrison Script: Sieged Settlement: Venice[L5_LargeCity] : denmark : Creating (368) [1]:Crossbow Militia,
end_if
end_if
end_if
if I_SettlementOwner Venice = jerusalem
; --- handling raising troops for next faction, goes similar, troops specific to 'jerusalem' can be inserted ...
; --- .....
end_if
; --- and so on for rest of the factions
;--- resetting the settlement siege mobilization - recovery counter
set_counter Venice_LastSiegeMobilizationTurnsCount 0
end_monitor
;--- monitors for rest settlements, schema is the same
monitor_event GeneralAssaultsResidence IsTargetRegionOneOf Palermo_Province
;--- ......
end_monitor
;--- we need to increment the [settlement]_LastSiegeMobilizationTurnsCount counters once per turn
;--- my way:
monitor_event PreFactionTurnStart FactionType slave
inc_counter Venice_LastSiegeMobilizationTurnsCount 1
inc_counter Palermo_LastSiegeMobilizationTurnsCount 1
inc_counter Bari_LastSiegeMobilizationTurnsCount 1
;--- ... all settlement siege mobilization couters
end_if
Everything - out of the blue, unexpectedly - works as designed !!
So ex.: for Venice (lev 5 Large City) :
AI attacking AI -> garrison 4,
player attacking AI -> garrison 5,
AI attacking player -> garrison 3
Finally, as a proof of concept (POC ) here goes my log :
Ribel, Vrhbosna, Skadar -> it's AI sieging AI. (garrison = settlm. -1)
Valencia -> it's me (Local) sieging AI (settl. level 4, garrison size = 4).
Zaragoza -> AI sieging me (level 4, two units added) (garrison = settlement size -2).
Re: Garrison Script - one monitor per settlement for all factions & AIvsAI & AivsPl & PlvsAI
If I understand you right you have solved the problem with too bad defended settlements? In the case of being attacked, the AI created units additionally to the existing ones to defend the settlement better. If I understand the script right there is no need for each settlement of Venice to create a monitor event but for the faction only (I mean it is sufficient to have one monitor event for each faction)? What will happen if Venice has no sufficient funds for creating that units?
I appreciate your script very much! It is very interesting.
Last edited by Granatenwerfer; November 24, 2016 at 06:33 AM.
Re: Garrison Script - one monitor per settlement for all factions & AIvsAI & AivsPl & PlvsAI
monitor_event GeneralAssaultsResidence IsTargetRegionOneOf Venice_Province
...
; Faction 'switch' and unit creation per each faction for Venice settlement
; per scenario AI vs AI , AI vs Player , Player vs AI
end_monitor
monitor_event GeneralAssaultsResidence IsTargetRegionOneOf Rome_Province
....
; Faction 'switch' and unit creation per each faction for Rome settlement
; per scenario AI vs AI , AI vs Player , Player vs AI
end_monitor
.... and so goes for each settlement. So with ~ 200 monitors only we can handle garrison creations for all settlements.
If I understand you right you have solved the problem with too bad defended settlements?
Problem in general is solved for a long time (TATW & 1648 & DLV & Hispania & .... & many developers Garrison Scripts ex Gigantus , Withwnar , TNZ etc. ).
What I've manage to do is to create solution: one monitor per one settlement for: all 3 scenarios AI/Player vs AI/Player and all factions included.
I've just 'compiled' or extended existing solutions that I've found.
See guides : here hereherehere
> What will happen if Venice has no sufficient funds for creating that units? Garrison will be created, money treasury is just a side effect.
Last edited by tmodelsk; November 24, 2016 at 07:39 AM.
Re: Garrison Script - one monitor per settlement for all factions & AIvsAI & AivsPl & PlvsAI
Nice stuff! So basically you have a base garrison addition at attack, an further increase if the defender is the AI and an final increase if the attacker is the player.
But I don't think the monitor will fire or else you are handling the declaring and setting of this counter somewhere else. I am assuming that at a SettlementTurnStart event you automatically increase the counter and set it to zero at the end of the above script?
Not everyone is aware how the ai_ec_id counter is created in SSHIP - best to give an example, too.
Tip: put script stuff into code tags (the # sign in advanced edit mode), it allows for proper formatting:
Code:
monitor_event GeneralAssaultsResidence IsTargetRegionOneOf Venice_Province
and I_SettlementUnderSiege Venice
and I_CompareCounter Venice_LastSiegeMobilizationTurnsCount > 12 ;---- it's settlement 'recovery' counter, one garrison per 12 turns
if I_SettlementOwner Venice = denmark ;--- Defender is denmark, defender is AI or Player, we don't know yet ---
; #### Here goes 'generic' scenario, for all AI vs AI/Player & Player vs AI
create_unit Venice, Spear Militia, num 1, exp 2, arm 0, wep 0
create_unit Venice, Spear Militia, num 1, exp 2, arm 0, wep 0
create_unit Venice, Spear Militia, num 1, exp 2, arm 0, wep 0
console_command add_money denmark, -891 ;-- troops created so charge some money from treasury ....
log always ### Garrison Script: Sieged Settlement: Venice[L5_LargeCity] : denmark : Creating (891) [3]:Spear Militia,Spear Militia,Spear Militia,
if not I_LocalFaction denmark
;#### Here we know that the DEFENDER IS NOT the player (not Local) !!! ####
create_unit Venice, Crossbow Militia, num 1, exp 1, arm 0, wep 0
console_command add_money denmark, -368
log always ### Garrison Script: Sieged Settlement: Venice[L5_LargeCity] : denmark : Creating (368) [1]:Crossbow Militia,
if I_CompareCounter ai_ec_id = 0
;#### Here we know that the ATTACKER IS the PLAYER (Local) ####
;#### ai_ec_id - Stainless Steel / SSHIP counter set on PreFactionTurnStart, 'early' in the script, 0 means current flow is for player - local.
create_unit Venice, Crossbow Militia, num 1, exp 1, arm 0, wep 0
console_command add_money denmark, -368
log always ### Garrison Script: Sieged Settlement: Venice[L5_LargeCity] : denmark : Creating (368) [1]:Crossbow Militia,
end_if
end_if
end_if
if I_SettlementOwner Venice = jerusalem
; handling raising troops for next faction
; .....
; and so on for rest of the factions
end_monitor
With repetitive stuff like this it's always good to reference GED's replicator tool - without it this will test the resolve of any modder.
Last edited by Gigantus; November 24, 2016 at 10:52 AM.
Re: Garrison Script - one monitor per settlement for all factions & AIvsAI & AivsPl & PlvsAI
Originally Posted by Gigantus
Nice stuff! So basically you have a base garrison addition at attack, an further increase if the defender is the AI and an final increase if the attacker is the player.
Exactly that is the algorithm.
Thanks for corrections & tips, I've updated main post to be more useful & readable for everybody.
Of course [settlement]_LastSiegeMobilizationTurnsCount counter is set to 0 at the end of settlement monitor,
and incremented once per turn (I've updated my code).
Re: Garrison Script - one monitor per settlement for all factions & AIvsAI & AivsPl & PlvsAI
Originally Posted by OPASEH
This not work if AI made will make a sortie and if attacking the army near the city. Garrison settlement will help this army without garrison units.
Well, if so then the AI has some units more to defend itself against the attacking human player. In my games the AI has no chances at all. Hence it is not wrong that the AI gets some reinforcement. This script is much better than the bad programmed AI by CA.
Re: Garrison Script - one monitor per settlement for all factions & AIvsAI & AivsPl & PlvsAI
This is a showcase of technical solution. Nothing more, nothing less.
My intention was to create a good performance solution (keep monitors number at minimum) that allows a lot of options (scenarios) in subject of garrison raising by script.
It's not intended to solve all in-game problems.
It has props and cons, there are scenarios good to use it and bad to use it.
Using it I've already created a "Garrison Mod" for Stainless Steel Historical Improvements Project (SSHIP).
If you're interested, read it, there are some considerations & scenarios that above solution is handling with success.