Code:
declare_counter UExp
declare_counter UWepArm
declare_counter PT
These are used later in the script and i will explain them at that point. Basically they control the variety and number of units that can spawn.
Code:
;Unique Counters per Settlement
declare_counter Belfalas_Siege
declare_counter Anorien_Siege
...
These counters will determine if a settlement is under siege or not. If set to 1 or higher they are being or have been sieged recently. Any time you declare a counter it is set to 0. You will note that in that list some settlements are missing. KK selected the settlements he felt required assistance.
Code:
declare_counter Belfalas_Defense
declare_counter Anorien_Defense
declare_counter Bree_Defense
...
These counters will determine a settlements defense level. 11, 12, 21 or 22. It is better explained later on.
Code:
declare_counter Belfalas_Local
declare_counter Anorien_Local
declare_counter Bree_Local
...
These counters determine whether the settlement is player owned or AI owned. This garrison script spawns units for both AI vs AI and Player vs AI, but uses a somewhat different system for both. These counters help determine how to spawn the units.
Code:
monitor_event FactionTurnStart FactionIsLocal
and I_TurnNumber < 1
set_counter UExp 1
set_counter UWepArm 1
terminate_monitor
end_monitor
This is the first monitor of the script and merely sets the Exp and Armor levels of units for the first turn (i originally wrote the script to include experience and armor upgrades).
Code:
monitor_event SettlementTurnStart SettlementIsLocal
and SettlementName Belfalas
set_counter Belfalas_Local 1
end_monitor
repeated for each settlement AND,
monitor_event SettlementTurnEnd SettlementIsLocal
and SettlementName Belfalas
set_counter Belfalas_Local 1
end_monitor
These monitors, one for each settlement, check if the settlement is the players on his/her turn start and turn end, if so, set the counter to 1.
Code:
monitor_event SettlementTurnStart not SettlementIsLocal
and SettlementName Belfalas
set_counter Belfalas_Local 0
end_monitor
repeated for each settlement ANS,
monitor_event SettlementTurnEnd not SettlementIsLocal
and SettlementName Belfalas
set_counter Belfalas_Local 0
end_monitor
These monitors do the same except on the AI's turn and checks if it is belonged to the AI.
NOTE: A settlement could in fact change control multiple times during a turn. You may own it on your turn, but faction2 may take it from you on his and faction3 may take it from them on his turn. These monitors merely ensure that who ever owns it on THIS current turn is the one who owns it. The counters are updated at the start and the end of every factions turn!
Code:
monitor_event PreFactionTurnStart FactionIsLocal
inc_counter Belfalas_Siege -1
inc_counter Anorien_Siege -1
...
inc_counter Westfold_Siege -1
set_counter PT 0
end_monitor
This monitor decreases the siege counter every turn by 1. When a settlement is besieged and the script spawns units it sets the siege counter to 10. Units will only spawn if the siege counter is below 0. Meaning units can only spawn once ever 10 turns for this settlment.
This monitor also sets PT to 0. (PT means nothing, i simply couldnt think of a word to describe what it does at the time). PT is the counter that determines the number of times to 'repeat' the spawn. I explain it later...
Code:
monitor_event PreFactionTurnStart FactionIsLocal
generate_random_counter random_exp 1 2
if I_EventCounter random_exp = 1
set_counter UExp 1
end_if
if I_EventCounter random_exp = 2
set_counter UExp 2
end_if
end_monitor
monitor_event PreFactionTurnStart FactionIsLocal
generate_random_counter random_armwep 1 2
if I_EventCounter random_armwep = 1
set_counter UWepArm 1
end_if
if I_EventCounter random_armwep = 2
set_counter UWepArm 2
end_if
end_monitor
These 2 monitors set the random 'variety' you can expect to see in spawns.
generate_random_counter random_exp 1 2
this command generates a random counter (you name it what u want, i named it random_exp and random_armwep as it randomly gives a value to the UExp and UWepArm counters). the values
1 2 is what is being randomized. Its either a 1 or a 2. You could set it to
1 10 and the value will be a random number between 1 and 10. For purposes of this script we only require a 1 or a 2.
Code:
monitor_event FactionTurnStart FactionIsLocal
if I_CompareCounter UExp = 1
and I_CompareCounter UWepArm = 1
set_counter Belfalas_Defense 11
set_counter Anorien_Defense 11
...
This monitor and its IF statements take the random variety counters and determine a settlements defense level for the turn. Every turn the defense level is ranomized in this way. Hence the defence levels of 11, 12, 21 and 22. When i wrote this script for Stainless steel each settlement had 1-6 (11, 12, 13, 14, 15, 16, 21, 22, 23... etc up to 66) for an extremely wide variety of spawns. These defense values are better explained further down.
Code:
;For Player vs AI
monitor_event ScrollOpened ScrollOpened siege_scroll
generate_random_counter random_variety 1 100
if I_EventCounter random_variety < 6
set_counter PT 0
end_if
...
This monitor is for when the player sieges and AI faction. It ultimately sets the PT counter. Which i explained earlier is the counter that determines how many times to repeat the spawn. Which will make more sense later.
Code:
;For AI vs AI
monitor_event PreFactionTurnStart not FactionIsLocal
generate_random_counter random_variety_AI 1 100
if I_EventCounter random_variety_AI < 1
set_counter PT 0
end_if
...
Same as above but this is for the AI vs AI sieges.
Now we get into the beef of the script. This is where it all comes together and our garrison script comes to life. All done in just a few monitors. I will explain this line by line.
This is the first monitor:
monitor_event ButtonPressed ButtonPressed siege_maintain_button
This part of the script will only fire when the player selects to maintain the siege. Assualting the walls immidiatly will result in fewer spawns. It simulates the local settlement able to muster up the locals to help defend.
if I_SettlementUnderSiege Anorien
This checks which settlement is in question. There is an IF statement for each settlement.
and I_SettlementOwner Anorien = sicily
This condition ensures that the settlement in question is controlled by the correct faction (else you can end up with silver surfers being spawned if the faction doesnt have access to the units). IF a unit is available to EVERY faction, you dont need to declare this.
and I_CompareCounter Anorien_Siege < 1
As stated before, the siege counter will allow/stop a spawn. Only if the counter is below 1 (0 or below) will the spawn occur. Once the spawn occurs it is set to 10 and slowly decreases 1 per turn. It takes turns (2 and a half yrs for 4tpy) for a settlment to again muster the locals into a garrison force.
and I_CompareCounter Anorien_Local = 0
This counter ensures that the settlement is not the players.
Code:
while I_CompareCounter PT < 1
The rest of this IF statement is enclosed in a
WHILE statement. While the PT counter is less then 1 it will continue to spawn units. The rest of this IF statment also contains additional IF statements inside it. You can write IF statements inside IF statements. As long as u keep track of it.
if I_CompareCounter Anorien_Defense = 11
create_unit Anorien, Gondor Spearmen, num 1, exp 0, arm 0, wep 0
create_unit Anorien, Gondor Archers, num 1, exp 0, arm 0, wep 0
create_unit Anorien, Gondor Trebuchet, num 1, exp 0, arm 0, wep 0
create_unit Anorien, Gondor Infantry, num 1, exp 0, arm 0, wep 0
create_unit Anorien, Dismounted Kofm, num 1, exp 0, arm 0, wep 0
inc_counter PT 1
set_counter Anorien_Siege 10
end_if
There is an if statement like this for each of the defense counters we set earlier. 11, 12, 21 and 22. This is suppose to be the variety of the units. But if you look at the script, you will notice they are all the same for each settlement and each defense level. So its pointless. Either remove a unit from each level and add numbers or experience etc to create the variety it is suppose to.
11 - is suppose to spawn the least resistance. So i would recommend just one unit with no experience.
12 - is suppose to be adequate defense. I would recommend 2 units with no experience.
21 - is suppose to be moderate. I would recommend 3 units with no experience.
22 - is suppose to be elite. I would recommend 3 units WITH some experience.
Keep in mind you also have the
PT while statement, which doubles, even triples the units spawned. So the above example could likely spawn 15 units! If you use my recommendations you get a variety to the units that spawn. They arnt alwys the same. (you could get from 1 unit with no exp up to 12 units with some exp) If you look at my garrison script for Stainless Steel (
my sig) you would notice that i have included DATES into the script. Actual events. That determine roughly at what year certain units and thier equipment (
such as gothic armor) become available and then spawns them in the script based on those values. That way you dont get a late era unit spawning on turn 3 for example.
In this part of the script we also increase the PT counter by one. Up until it equals one which is when the spawn stops. We also set the siege counter to 10 for this settlement. No spawns can occur for atleast 10 turns. This could be changed to 20, or 30 or 40 or whatever. 40 would represent 10 yrs in TATW at 4tpy.
The next monitor:
monitor_event ButtonPressed ButtonPressed siege_assault_button
Is exactly the same as the above one, except it fires when you select siege and assault the settlement. You will note, the only difference here is what the siege counter is set to, its half that if you maintined the siege. This is to represent the town being able to respawn again in a short time. Ideally, this monitor should spawn LESS units then if you maintained the siege, so once again, the 'variety' i spoke of should be re evaluated.
The final monitor spawns units for AI vs AI. It does not take into consideration a faction maintaining the siege or assaulting. If an AI faction assaults immediatly, then no units will spawn for the AI faction. Hence in the script there are 2 open areas to complete, siege units 3 and 4.