EDIT 2019/03/11:
Full list of (personally) known AI GTA plan sets
http://www.twcenter.net/forums/showt...1#post15093711
EDIT 2016/10/27:
A word of warning, this tutorial is merely left here to explain the basics behind battle scripting. The finalized version of the script is included in the 'Skynet AI' resource in the world/maps/campaign/imperial_campaign add_into_campaign_script text file.
That script is the finalized version and was implemented directly into the campaign as the campaign rather than custom battles were viewed as most important. It was in my opinion the best way to implement things as the script is automatically executed that way (via the campaign script). Some people get confused as to what to do with the click on the advisor method, even if that way works for custom & campaign battles.
OP (2015ish):
First an explanation, I by no means suggest this is the only way or the best way this script was designed with several principles in mind. Further it does everything in a relatively efficient fashion, in my opinion of course. According to our feedback it lacks any major issues like battle CTD's and so on due to its design premise which is based around as few monitors as possible with the maximum effect. Note that you want as few monitors as possible, so as to lessen the load on the CPU/frame rates as well as the chance of a crash related to scripts.
I am very interested in people trying to improve upon this current design.
1) That it would be a custom/campaign battle script activated via advisor.
2) That it could alternatively be implemented into a campaign based script. Doing this would involve two steps, one naming your script at the bottom of the descr_strat. This is the current implementation in the dev build of EBII.
3) That it would execute repetitively through every battle rather than terminate.
Creating a campaign based script is simple, you just write this at the bottom of your descr_strat located in your mod/data/world/maps/campaign/imperial_campiagn
Code:
script
campaign_script.txt
Then create a text file named campaign_script in your mod/data/world/maps/campaign/imperial_campiagn
This will execute your script upon starting or continuing a new campaign.
You will have to paste the full script (located in the second post), into the campaign_script you just created. If you are modding a pre existing mod though with 'script' and 'end_script' already existing in the campaign script make sure you remove those two lines (located at the top and very bottom respectively).
For some history on the script, several difficulties born from pre-existing engine limitations and quirks (which are in fact sensible), made this script (the campaign script version as it is different from a background script version) a very drawn out creation lasting about 3-4 months of iterations and testing to iron out several different things. For example, thanks to Gigantus I was able to allow trace logs to become readable and avoid the point of no return in regards to text editors.
The advantage of a campaign script version is that it will be automatic and always activate in any battle, even sally out battles. On the other hand, it will not activate in custom battles.
The advisor based script will activate in custom battles, as well as the campaign battles with the exception of sally out battles unless it was previously activated during the script game state, note that the scripting game state is refreshed every time you close the game.
Activation via a trigger based advisor script must be written into the export_descr_advice file. (if you do not go the campaign script route)
Code:
;------------------------------------------
AdviceThread BackgroundScriptThread
GameArea Battle
Item Background_Script_Text_01
Uninhibitable
Verbosity 0
Priority 6
Threshold 1
MaxRepeats 0
RepeatInterval 1
Attitude Excited
Presentation Default
Title Background_Script_Title
On_display scripts\show_me\background_script.txt
Text Background_Script_Text1
A MaxRepeats of 0 means an infinite amount. It is activated via the On_Display command rather than Script.
This would be Script, which means you have to use the Show Me How button to activate it rather than activation via simply clicking the advisor portrait.
Code:
;------------------------------------------
AdviceThread BackgroundScriptThread
GameArea Battle
Item Background_Script_Text_01
Uninhibitable
Verbosity 0
Priority 6
Threshold 1
MaxRepeats 0
RepeatInterval 1
Attitude Excited
Presentation Default
Title Background_Script_Title
Script scripts\show_me\background_script.txt
Text Background_Script_Text1
There are triggers required within this file that cause this advice thread to fire.
This is a simple trigger, with a WhenToTest line which tells the exe when to fire the command, and a superflous condition of 'I_InBattle'. This could according to Gigantus be further supplemented.
Code:
;------------------------------------------
Trigger background_script_trigger_1
WhenToTest BattleDeploymentPhaseCommenced
Condition I_InBattle
AdviceThread BackgroundScriptThread 1
Using the Condition line as TrueCondition could according to a test run by Gigantus make the script fire automatically without intervention/clicking the portrait by the player. Note that I have not tested this myself as I instead moved the battle script to the campaign script where it is automatically executed by the descr_strat + campaign script. (The descr_strat must have a reference to the script so that a campaign based script fires).
Code:
;------------------------------------------
Trigger background_script_trigger_1
WhenToTest BattleDeploymentPhaseCommenced
Condition TrueCondition
AdviceThread BackgroundScriptThread 1
Using it inside of a campaign script does give a couple of theoretical advantanges, namely you can use event counters/randomly generated counters which in turn set other counters which are then used by the battle script. This may sound terribly complicated but it is a simple idea.
The foundations of battle scripting are ways to trigger/code the script itself and then unit/group labels and other related commands. Once these are written in you can start to script anything you so desire. (you can without unit/group labels but it is rather useful to have them)
script (lower case intentional) this is your basic command which leds the exe know the file contains a script. There is also an end_script command which terminates the script and lets the exe know that is the end of the script.
So far our code looks like this.
This part appears in some of the historical battle scripts, I included it just because there did not seem to be any adverse effect. It seems to say say execute the script while the battle deployment is not finished.
Code:
script
while ! I_BattleStarted
end_while
A similar command rears its head at the bottom of the script.
Code:
while I_InBattle
end_while
end_script
So to be clear, this is what the script looks like at the moment.
Code:
script ; Start of our script
while ! I_BattleStarted
end_while
while I_InBattle
end_while
end_script ; End of our script
Now we have some initial and somewhat unnecessary stuff to add, just to let ourselves know 'yay our script works!' and so on. However there is one part worth noting/explaining the 'restart_timer'. This is a basic command which restarts a timer. A timer is a way of tracking how much time passed in the game. There are different types of timers as well, one for the strat and one for the battle.
Code:
;;;;*************************************************************************************************
;;;; Initialize Battle
;;;;*************************************************************************************************
log always EBII Battle Scripts
log always Activated
restart_timer deployment_timer
I try to declare my counters at the very top of the script because it keeps things organized and as far as I can see there is no untoward effect. Logically, there should not be either as the time a timer is declared until it is used is a non issue.
Of course these counters are all named and have a purpose specifically for my own script, so if you don't need them in your own (removing them immediately would be something only advanced modders should do by the way, otherwise it will mess up your script if you use mine as as base), you can remove these.
Code:
;;;;*************************************************************************************************
;;;; Counters
;;;;*************************************************************************************************
declare_counter deploy_check
declare_counter start_battle
declare_counter FaW_and_S
declare_counter Release_Labels
declare_counter End_Labels
declare_counter AI_GRP
declare_counter AI_HTC
declare_counter AI_reinforcements
declare_timer deployment_timer
declare_timer AI_reinforcements_timer
;suspend_unscripted_advice true
What this first line means here is that we are monitoring the timer we just declared called the 'deployment_timer'. The logic token > means if the timer is more than 101 milliseconds and we are in battle but the deployment phase has not ended restart the deployment timer and set those specific counters to 0.
Note I only make those counters get set to 0 so that they clear up any previous battle related settings in those counters. This may make more sense once we progress further through the tutorial with more of the script appearing but in essence, what happens is certain counters get incremented/set to numbers higher than 0 after a battle is finished, so we must 'clear' these up for a new battle.
Code:
monitor_conditions I_TimerElapsed deployment_timer > 101
and I_InBattle
and not I_BattleStarted
restart_timer deployment_timer
set_counter AI_GRP 0
set_counter AI_reinforcements 0
end_monitor
This condition is meant to be reliant on the first condition which controls whether the timer is restarted or not. It is meant to do two things, 1) Clear any of the previous labels 2) reset the help the AI captain vs player family members script 3) set the deploy check to 1.
Code:
monitor_conditions I_TimerElapsed deployment_timer < 101
and I_InBattle
prepare_for_battle
set_counter AI_HTC 0
set_counter deploy_check 1
end_monitor
Once the deploy check is fired, this means the rest of the scripts start to fire.
To explain this logic, the first monitor checks if whether the deployment phase has ended or not, the second monitor is a safeguard to prevent future CTD's in regards to unit labels.
This code is the second monitor. Note the most important command here is the 'prepare_for_battle' which clears the external unit labels. There are two types of labels, 1) internal unit labels and 2) external unit labels. We will get into that soon as well.
Code:
monitor_conditions I_TimerElapsed deployment_timer < 101
and I_InBattle
prepare_for_battle
set_counter AI_HTC 0
set_counter deploy_check 1
end_monitor
This code here is what tells the script, 'yes we are in battle and it has started with the deployment phase ended'.
Code:
monitor_conditions I_CompareCounter deploy_check = 1
and I_BattleStarted
set_counter start_battle 1
end_monitor
So the counter for 'start_battle' is now set to 1, which means this monitor can now fire if the battle is started.
Here we can see several new and important functions, I apologize for the length of this monitor and the numerous topics we might get into but to start explaining, here is the foundation of a battle script (other than starting one which executes repeatedly).
1) An internal unit label, all internal unit labels start with three things.
The first 0, the second 0, and the third 0.
The first 0 is a reference to the 'team/alliance' number. 0 is generally considered the enemy alliance number, whereas 1 is the player (note! this scheme changes when there is a second reinforcing AI army *third as well no doubt but I have never been able to test that or have reason to).
What this means is that if you label an internally named unit with an external label. (extracted the bolded external unit label so I could explain), then it may have its AI automatically turned off unless the command 'release_unit 0 0 0 MAu1' is used as well. Normally, as the players units do not have an AI in the first place except when directly placed under the AI by the player, this does not matter.
However it will matter if you have an AI reinforcing army. Hence you have to remember to release all the units or suffer grave consequences with a mostly unresponsive/defensive AI.
Next, we have the ability to name 'groups' of units. Naming a unit group repeatedly would be redundant, hence I just went and named them all at once. (also note that unit group commands still work doing it this way even if the external/internal unit labels do not exist because there are not enough units in the battle to cover them all).
This issue of internal/external unit labels is a non fatal issue by the way, and is simply reported in the log. I suppose it doesn't crash as some of CA's coders for historical battles may have encountered the issue as well. In any case, it is what allows us to definitively label all units/unit groups in any battle.
Code:
label_unit 0 0 0 MAu1
Code:
monitor_conditions I_CompareCounter start_battle = 1
and I_BattleStarted
set_counter Release_Labels 1
set_counter FaW_and_S 1
if I_CompareCounter Release_Labels = 1
set_counter start_battle 0
end_if
;;;;*************************************************************************************************
;;;; Create Labels
;;;;*************************************************************************************************
; *********************************************************************************************
; Main Army Unit Labels
; *********************************************************************************************
label_unit 0 0 0 MAu1
label_unit 0 0 1 MAu2
label_unit 0 0 2 MAu3
label_unit 0 0 3 MAu4
label_unit 0 0 4 MAu5
label_unit 0 0 5 MAu6
label_unit 0 0 6 MAu7
label_unit 0 0 7 MAu8
label_unit 0 0 8 MAu9
label_unit 0 0 9 MAu10
label_unit 0 0 10 MAu11
label_unit 0 0 11 MAu12
label_unit 0 0 12 MAu13
label_unit 0 0 13 MAu14
label_unit 0 0 14 MAu15
label_unit 0 0 15 MAu16
label_unit 0 0 16 MAu17
label_unit 0 0 17 MAu18
label_unit 0 0 18 MAu19
label_unit 0 0 19 MAu20
label_unit 0 0 20 MAu21
label_unit 0 0 21 MAu22
label_unit 0 0 22 MAu23
label_unit 0 0 23 MAu24
label_unit 0 0 24 MAu25
label_unit 0 0 25 MAu26
label_unit 0 0 26 MAu27
label_unit 0 0 27 MAu28
label_unit 0 0 28 MAu29
label_unit 0 0 29 MAu30
label_unit 0 0 30 MAu31
label_unit 0 0 31 MAu32
label_unit 0 0 32 MAu33
label_unit 0 0 33 MAu34
label_unit 0 0 34 MAu35
label_unit 0 0 35 MAu36
label_unit 0 0 36 MAu37
label_unit 0 0 37 MAu38
label_unit 0 0 38 MAu39
label_unit 0 0 39 MAu40
; *********************************************************************************************
; Allied Unit Labels
; *********************************************************************************************
label_unit 1 0 0 Eu1
label_unit 1 0 1 Eu2
label_unit 1 0 2 Eu3
label_unit 1 0 3 Eu4
label_unit 1 0 4 Eu5
label_unit 1 0 5 Eu6
label_unit 1 0 6 Eu7
label_unit 1 0 7 Eu8
label_unit 1 0 8 Eu9
label_unit 1 0 9 Eu10
label_unit 1 0 10 Eu11
label_unit 1 0 11 Eu12
label_unit 1 0 12 Eu13
label_unit 1 0 13 Eu14
label_unit 1 0 14 Eu15
label_unit 1 0 15 Eu16
label_unit 1 0 16 Eu17
label_unit 1 0 17 Eu18
label_unit 1 0 18 Eu19
label_unit 1 0 19 Eu20
label_unit 1 0 20 Eu21
label_unit 1 0 21 Eu22
label_unit 1 0 22 Eu23
label_unit 1 0 23 Eu24
label_unit 1 0 24 Eu25
label_unit 1 0 25 Eu26
label_unit 1 0 26 Eu27
label_unit 1 0 27 Eu28
label_unit 1 0 28 Eu29
label_unit 1 0 29 Eu30
label_unit 1 0 30 Eu31
label_unit 1 0 31 Eu32
label_unit 1 0 32 Eu33
label_unit 1 0 33 Eu34
label_unit 1 0 34 Eu35
label_unit 1 0 35 Eu36
label_unit 1 0 36 Eu37
label_unit 1 0 37 Eu38
label_unit 1 0 38 Eu39
label_unit 1 0 39 Eu40
; *********************************************************************************************
; Group Labels
; *********************************************************************************************
define_unit_group Allies MAu1 MAu2 MAu3 MAu4 MAu5 MAu6 MAu7 MAu8 MAu9 MAu10 MAu11 MAu12 MAu13 MAu14 MAu15 MAu16 MAu17 MAu18 MAu19 MAu20 MAu21 MAu22 MAu23 MAu24 MAu25 MAu26 MAu27 MAu28 MAu29 MAu30 MAu31 MAu32 MAu33 MAu34 MAu35 MAu36 MAu37 MAu38 MAu39 MAu40
define_unit_group Enemy Eu1 Eu2 Eu3 Eu4 Eu5 Eu6 Eu7 Eu8 Eu9 Eu10 Eu11 Eu12 Eu13 Eu14 Eu15 Eu16 Eu17 Eu18 Eu19 Eu20 Eu21 Eu22 Eu23 Eu24 Eu25 Eu26 Eu27 Eu28 Eu29 Eu30 Eu31 Eu32 Eu33 Eu34 Eu35 Eu36 Eu37 Eu38 Eu39 Eu40
end_monitor
Next we have the fire at will commands applied directly after the units are labeled. Again this may throw out an error about a certain unit not being defined internally/externally but it doesn't matter here either.
What it does is set the fire at will mode on automatically for player units, whereas vanilla had it off by default for the player. And in my opinion the AI as well, unfortunately the reloading bug is compounded by this default off decision by the AI/game. It should have been on by default which may have meant the reloading bug we often see with precursor units would have been less prevalent. I do have eventual plans one day to try to address it once again but at preliminary tests scripting doesn't seem to be helpful in fixing this either.
Code:
monitor_conditions I_CompareCounter FaW_and_S > 0
and I_BattleStarted
set_counter End_Labels 1
; *********************************************************************************************
; FaW - Active
; *********************************************************************************************
; *********************************************************************************************
; FaW - Player
; *********************************************************************************************
unit_set_fire_at_will_mode MAu1 on
unit_set_fire_at_will_mode MAu2 on
unit_set_fire_at_will_mode MAu3 on
unit_set_fire_at_will_mode MAu4 on
unit_set_fire_at_will_mode MAu5 on
unit_set_fire_at_will_mode MAu6 on
unit_set_fire_at_will_mode MAu7 on
unit_set_fire_at_will_mode MAu8 on
unit_set_fire_at_will_mode MAu9 on
unit_set_fire_at_will_mode MAu10 on
unit_set_fire_at_will_mode MAu11 on
unit_set_fire_at_will_mode MAu12 on
unit_set_fire_at_will_mode MAu13 on
unit_set_fire_at_will_mode MAu14 on
unit_set_fire_at_will_mode MAu15 on
unit_set_fire_at_will_mode MAu16 on
unit_set_fire_at_will_mode MAu17 on
unit_set_fire_at_will_mode MAu18 on
unit_set_fire_at_will_mode MAu19 on
unit_set_fire_at_will_mode MAu20 on
unit_set_fire_at_will_mode MAu21 on
unit_set_fire_at_will_mode MAu22 on
unit_set_fire_at_will_mode MAu23 on
unit_set_fire_at_will_mode MAu24 on
unit_set_fire_at_will_mode MAu25 on
unit_set_fire_at_will_mode MAu26 on
unit_set_fire_at_will_mode MAu27 on
unit_set_fire_at_will_mode MAu28 on
unit_set_fire_at_will_mode MAu29 on
unit_set_fire_at_will_mode MAu30 on
unit_set_fire_at_will_mode MAu31 on
unit_set_fire_at_will_mode MAu32 on
unit_set_fire_at_will_mode MAu33 on
unit_set_fire_at_will_mode MAu34 on
unit_set_fire_at_will_mode MAu35 on
unit_set_fire_at_will_mode MAu36 on
unit_set_fire_at_will_mode MAu37 on
unit_set_fire_at_will_mode MAu38 on
unit_set_fire_at_will_mode MAu39 on
unit_set_fire_at_will_mode MAu40 on
; *********************************************************************************************
; FaW - AI
; *********************************************************************************************
unit_set_fire_at_will_mode Eu1 on
unit_set_fire_at_will_mode Eu2 on
unit_set_fire_at_will_mode Eu3 on
unit_set_fire_at_will_mode Eu4 on
unit_set_fire_at_will_mode Eu5 on
unit_set_fire_at_will_mode Eu6 on
unit_set_fire_at_will_mode Eu7 on
unit_set_fire_at_will_mode Eu8 on
unit_set_fire_at_will_mode Eu9 on
unit_set_fire_at_will_mode Eu10 on
unit_set_fire_at_will_mode Eu11 on
unit_set_fire_at_will_mode Eu12 on
unit_set_fire_at_will_mode Eu13 on
unit_set_fire_at_will_mode Eu14 on
unit_set_fire_at_will_mode Eu15 on
unit_set_fire_at_will_mode Eu16 on
unit_set_fire_at_will_mode Eu17 on
unit_set_fire_at_will_mode Eu18 on
unit_set_fire_at_will_mode Eu19 on
unit_set_fire_at_will_mode Eu20 on
unit_set_fire_at_will_mode Eu21 on
unit_set_fire_at_will_mode Eu22 on
unit_set_fire_at_will_mode Eu23 on
unit_set_fire_at_will_mode Eu24 on
unit_set_fire_at_will_mode Eu25 on
unit_set_fire_at_will_mode Eu26 on
unit_set_fire_at_will_mode Eu27 on
unit_set_fire_at_will_mode Eu28 on
unit_set_fire_at_will_mode Eu29 on
unit_set_fire_at_will_mode Eu30 on
unit_set_fire_at_will_mode Eu31 on
unit_set_fire_at_will_mode Eu32 on
unit_set_fire_at_will_mode Eu33 on
unit_set_fire_at_will_mode Eu34 on
unit_set_fire_at_will_mode Eu35 on
unit_set_fire_at_will_mode Eu36 on
unit_set_fire_at_will_mode Eu37 on
unit_set_fire_at_will_mode Eu38 on
unit_set_fire_at_will_mode Eu39 on
unit_set_fire_at_will_mode Eu40 on
; *********************************************************************************************
; Skirmish Mode - Active
; *********************************************************************************************
unit_set_skirmish_mode Eu1 on
unit_set_skirmish_mode Eu2 on
unit_set_skirmish_mode Eu3 on
unit_set_skirmish_mode Eu4 on
unit_set_skirmish_mode Eu5 on
unit_set_skirmish_mode Eu6 on
unit_set_skirmish_mode Eu7 on
unit_set_skirmish_mode Eu8 on
unit_set_skirmish_mode Eu9 on
unit_set_skirmish_mode Eu10 on
unit_set_skirmish_mode Eu11 on
unit_set_skirmish_mode Eu12 on
unit_set_skirmish_mode Eu13 on
unit_set_skirmish_mode Eu14 on
unit_set_skirmish_mode Eu15 on
unit_set_skirmish_mode Eu16 on
unit_set_skirmish_mode Eu17 on
unit_set_skirmish_mode Eu18 on
unit_set_skirmish_mode Eu19 on
unit_set_skirmish_mode Eu20 on
unit_set_skirmish_mode Eu21 on
unit_set_skirmish_mode Eu22 on
unit_set_skirmish_mode Eu23 on
unit_set_skirmish_mode Eu24 on
unit_set_skirmish_mode Eu25 on
unit_set_skirmish_mode Eu26 on
unit_set_skirmish_mode Eu27 on
unit_set_skirmish_mode Eu28 on
unit_set_skirmish_mode Eu29 on
unit_set_skirmish_mode Eu30 on
unit_set_skirmish_mode Eu31 on
unit_set_skirmish_mode Eu32 on
unit_set_skirmish_mode Eu33 on
unit_set_skirmish_mode Eu34 on
unit_set_skirmish_mode Eu35 on
unit_set_skirmish_mode Eu36 on
unit_set_skirmish_mode Eu37 on
unit_set_skirmish_mode Eu38 on
unit_set_skirmish_mode Eu39 on
unit_set_skirmish_mode Eu40 on
end_monitor
Next we have the 'release' back to the AI control for the units as stated before, this is necessary or you will see the AI in a stasis in certain battles.
Code:
monitor_conditions I_CompareCounter Release_Labels > 0
and I_BattleStarted
;Must release Main Army, internal army label is recalibrated upon arrival of AI reinforcements causing 1 (previously the main AI army) to become 0 and 1 to become the secondary AI army.
release_unit MAu1
release_unit MAu2
release_unit MAu3
release_unit MAu4
release_unit MAu5
release_unit MAu6
release_unit MAu7
release_unit MAu8
release_unit MAu9
release_unit MAu10
release_unit MAu11
release_unit MAu12
release_unit MAu13
release_unit MAu14
release_unit MAu15
release_unit MAu16
release_unit MAu17
release_unit MAu18
release_unit MAu19
release_unit MAu20
release_unit MAu21
release_unit MAu22
release_unit MAu23
release_unit MAu24
release_unit MAu25
release_unit MAu26
release_unit MAu27
release_unit MAu28
release_unit MAu29
release_unit MAu30
release_unit MAu31
release_unit MAu32
release_unit MAu33
release_unit MAu34
release_unit MAu35
release_unit MAu36
release_unit MAu37
release_unit MAu38
release_unit MAu39
release_unit MAu40
release_unit Eu1
release_unit Eu2
release_unit Eu3
release_unit Eu4
release_unit Eu5
release_unit Eu6
release_unit Eu7
release_unit Eu8
release_unit Eu9
release_unit Eu10
release_unit Eu11
release_unit Eu12
release_unit Eu13
release_unit Eu14
release_unit Eu15
release_unit Eu16
release_unit Eu17
release_unit Eu18
release_unit Eu19
release_unit Eu20
release_unit Eu21
release_unit Eu22
release_unit Eu23
release_unit Eu24
release_unit Eu25
release_unit Eu26
release_unit Eu27
release_unit Eu28
release_unit Eu29
release_unit Eu30
release_unit Eu31
release_unit Eu32
release_unit Eu33
release_unit Eu34
release_unit Eu35
release_unit Eu36
release_unit Eu37
release_unit Eu38
release_unit Eu39
release_unit Eu40
end_monitor
Then we have 'cleanup' for all these counters.
Code:
monitor_conditions I_CompareCounter End_Labels = 1
and I_BattleStarted
set_counter Release_Labels 0
if I_CompareCounter Release_Labels = 0
set_counter FaW_and_S 0
set_counter End_Labels 0
set_counter deploy_check 0
end_if
end_monitor
This is a nearly finished idea based around ordering the AI armies to do a specific task defend until a reinforcement based timer completes upon the condition that it has not lost a certain percentage of units. Although these monitors have not been shown yet, I am just explaining the concept behind an event monitor for reinforcements.
According to player feedback it does work to an extent, but as usual I am trying to perfect it.
Code:
; *********************************************************************************************
; Initialize Battle Plans & Monitors
; *********************************************************************************************
; *********************************************************************************************
; Shared Reinforcements Monitor
; *********************************************************************************************
monitor_event BattleReinforcementsArrive
;AI Reinforcements
inc_counter AI_reinforcements 1
if I_CompareCounter AI_reinforcements = 1
restart_timer AI_reinforcements_timer
end_if
end_monitor
Here we can see the AI Reinforcements functions based on the timer (again revolving around the principle of a 'restart_timer' command and comparisons to counters). Note that ai_gta_add_objective may likely require a direct AI related label for the internal unit. However internal EBII testing indicated that some users have problems with this command for some reason causing their game to crash. In any case I included it regardless as it doesn't have a negative side effect and there are future plans for including such a thing if possible.
Code:
; *********************************************************************************************
; AI Reinforcements Defend Plan
; *********************************************************************************************
monitor_conditions I_CompareCounter AI_reinforcements > 0
and I_BattlePlayerAllianceOddsInFavour > 1
and I_TimerElapsed AI_reinforcements_timer < 90000
;AI Units from Army 1 Battle Objective
ai_gta_add_objective 0 DEFEND_LINE 999
;AI Army 1 Battle Objective
ai_gta_plan_set 0 DEFEND_FEATURE
;AI Units from Army 2 Battle Objective
ai_gta_add_objective 1 DEFEND_LINE 999
;AI Army 2 Battle Objective
ai_gta_plan_set 1 DEFEND_FEATURE
end_monitor
; *********************************************************************************************
; AI Reinforcements Attack Plan
; *********************************************************************************************
monitor_conditions I_CompareCounter AI_reinforcements > 0
and not I_BattlePlayerArmyIsAttacker
and I_TimerElapsed AI_reinforcements_timer > 90000
;AI Units from Army 1 Battle Objective
ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
;AI Army 1 Battle Objective
ai_gta_plan_set 0 ATTACK_ALL
;AI Units from Army 2 Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Army 2 Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
Next we have this part, it monitors certain AI units. Namely the general unit, if the general is under attack the entire army switches into an attack state regardless of its previous AI based orders. (often players including myself would exploit the poor defensive AI by killing off its general in several repetitive cavalry charges during which the AI wouldn't react very well if at all). Further there is an army based one that kicks the AI into gear if under fire/being attacked in some way or another, this is to limit another player exploit we all used at one point or another firing at the uncaring enemy with our archers.
Code:
; *********************************************************************************************
; AI Unit Monitors & AI Reactions
; *********************************************************************************************
monitor_conditions I_PercentageUnitKilled Eu1 > 5
and I_BattleStarted
and not I_BattleIsSiegeBattle
inc_counter AI_GRP 1
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
monitor_conditions I_PercentageOfArmyKilled 1 0 > 3
and I_BattleStarted
and I_BattlePlayerArmyIsAttacker
and not I_BattleIsSiegeBattle
inc_counter AI_GRP 1
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
Here is the help the captain script, which revolves around two principles 1) the CAI often sends large captain stacks around without a FM to help it, and inadvertedly attacks the player with such a stack, an overwhelming majority voted for the AI led captain stacks to receive a buff in regards to morale if attacked or attacking a player army led by a family member. Hence this script.
Code:
monitor_conditions I_BattlePlayerArmyNumberOfAttribute general_unit > 0
and I_BattleEnemyArmyNumberOfAttribute general_unit = 0
and I_InBattle
; *********************************************************************************************
; Help The Captain - AI (35% chance of an experienced captain)
; *********************************************************************************************
unit_set_experience Eu1 3
unit_set_experience Eu2 3
unit_set_experience Eu3 3
unit_set_experience Eu4 3
unit_set_experience Eu5 3
unit_set_experience Eu6 3
unit_set_experience Eu7 3
unit_set_experience Eu8 3
unit_set_experience Eu9 3
unit_set_experience Eu10 3
unit_set_experience Eu11 3
unit_set_experience Eu12 3
unit_set_experience Eu13 3
unit_set_experience Eu14 3
unit_set_experience Eu15 3
unit_set_experience Eu16 3
unit_set_experience Eu17 3
unit_set_experience Eu18 3
unit_set_experience Eu19 3
unit_set_experience Eu20 3
unit_set_experience Eu21 3
unit_set_experience Eu22 3
unit_set_experience Eu23 3
unit_set_experience Eu24 3
unit_set_experience Eu25 3
unit_set_experience Eu26 3
unit_set_experience Eu27 3
unit_set_experience Eu28 3
unit_set_experience Eu29 3
unit_set_experience Eu30 3
unit_set_experience Eu31 3
unit_set_experience Eu32 3
unit_set_experience Eu33 3
unit_set_experience Eu34 3
unit_set_experience Eu35 3
unit_set_experience Eu36 3
unit_set_experience Eu37 3
unit_set_experience Eu38 3
unit_set_experience Eu39 3
unit_set_experience Eu40 3
;AI Reinforcements/Main Army get set to the internal label 0 which was previously the players when reinforced
;AI Reinforcing Army = MA = 0, AI Reinforcing Army 2 = (E) = 1, Player Army = 2 when there are two reinforcing AI armies
;Internal Labels are counted from 0 onwards
;No Random Help The Captain Conditions as this would be an important army/battle if two reinforcements
if I_CompareCounter AI_Reinforcements > 0
unit_set_experience MAu1 3
unit_set_experience MAu2 3
unit_set_experience MAu3 3
unit_set_experience MAu4 3
unit_set_experience MAu5 3
unit_set_experience MAu6 3
unit_set_experience MAu7 3
unit_set_experience MAu8 3
unit_set_experience MAu9 3
unit_set_experience MAu10 3
unit_set_experience MAu11 3
unit_set_experience MAu12 3
unit_set_experience MAu13 3
unit_set_experience MAu14 3
unit_set_experience MAu15 3
unit_set_experience MAu16 3
unit_set_experience MAu17 3
unit_set_experience MAu18 3
unit_set_experience MAu19 3
unit_set_experience MAu20 3
unit_set_experience MAu21 3
unit_set_experience MAu22 3
unit_set_experience MAu23 3
unit_set_experience MAu24 3
unit_set_experience MAu25 3
unit_set_experience MAu26 3
unit_set_experience MAu27 3
unit_set_experience MAu28 3
unit_set_experience MAu29 3
unit_set_experience MAu30 3
unit_set_experience MAu31 3
unit_set_experience MAu32 3
unit_set_experience MAu33 3
unit_set_experience MAu34 3
unit_set_experience MAu35 3
unit_set_experience MAu36 3
unit_set_experience MAu37 3
unit_set_experience MAu38 3
unit_set_experience MAu39 3
unit_set_experience MAu40 3
unit_set_experience Eu1 3
unit_set_experience Eu2 3
unit_set_experience Eu3 3
unit_set_experience Eu4 3
unit_set_experience Eu5 3
unit_set_experience Eu6 3
unit_set_experience Eu7 3
unit_set_experience Eu8 3
unit_set_experience Eu9 3
unit_set_experience Eu10 3
unit_set_experience Eu11 3
unit_set_experience Eu12 3
unit_set_experience Eu13 3
unit_set_experience Eu14 3
unit_set_experience Eu15 3
unit_set_experience Eu16 3
unit_set_experience Eu17 3
unit_set_experience Eu18 3
unit_set_experience Eu19 3
unit_set_experience Eu20 3
unit_set_experience Eu21 3
unit_set_experience Eu22 3
unit_set_experience Eu23 3
unit_set_experience Eu24 3
unit_set_experience Eu25 3
unit_set_experience Eu26 3
unit_set_experience Eu27 3
unit_set_experience Eu28 3
unit_set_experience Eu29 3
unit_set_experience Eu30 3
unit_set_experience Eu31 3
unit_set_experience Eu32 3
unit_set_experience Eu33 3
unit_set_experience Eu34 3
unit_set_experience Eu35 3
unit_set_experience Eu36 3
unit_set_experience Eu37 3
unit_set_experience Eu38 3
unit_set_experience Eu39 3
unit_set_experience Eu40 3
end_if
end_monitor
Next we have a couple scripts meant to force certain behaviors that should always happen to happen. As the AI has been known to refuse to attack when it attacked you etc. As you can see some of them are also counter dependant and based around certain conditions, this is because in battle scripting you must exclude certain behaviours and make sure they are not overwritten in any way by previous commands.
Code:
; *********************************************************************************************
; Normal Attack Plan
; *********************************************************************************************
monitor_conditions I_CompareCounter AI_reinforcements = 0
and I_ConflictType Normal
and I_InBattle
and not I_BattlePlayerArmyIsAttacker
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
; *********************************************************************************************
; Normal Defend Plan
; Recurring counters fire above 0
; *********************************************************************************************
monitor_conditions I_CompareCounter AI_reinforcements = 0
and I_ConflictType Normal
and I_InBattle
and not I_BattleAiAttacking
and I_BattlePlayerArmyIsAttacker
if I_CompareCounter AI_GRP = 0
;AI Units Battle Objective Main Army
ai_gta_add_objective 1 DEFEND_LINE 999
;AI Alliance Battle Objective Main Army
ai_gta_plan_set 1 DEFEND_FEATURE
end_if
if I_CompareCounter AI_GRP > 0
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_if
end_monitor
; *********************************************************************************************
; Assault Crossing
; *********************************************************************************************
monitor_conditions I_BattleIsRiverBattle
and I_InBattle
and not I_BattlePlayerArmyIsAttacker
;AI Units Battle Objective
ai_gta_add_objective 1 ASSAULT_CROSSING 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
; *********************************************************************************************
; Assault Settlement
; *********************************************************************************************
monitor_conditions I_BattleIsSiegeBattle
and I_InBattle
and not I_BattlePlayerArmyIsAttacker
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_SETTLEMENT
end_monitor
; *********************************************************************************************
; Sally Out
; *********************************************************************************************
monitor_conditions I_BattleIsSallyOutBattle
and I_InBattle
and not I_BattlePlayerArmyIsAttacker
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
Hopefully this tutorial clarified at least a couple of things for you, if you still have any questions feel free to ask!
I'll include a quick/final summary here.
1) A way of executing a battle script is necessary, you should either write your script into export_descr_advice or a campaign_script (or whatever name you prefer).
2) Your script must be able to execute repetatively in more than one battle to prevent issues with a second battle not starting or crashing due to a lack of the prepare_for_battle implemented in your script.
3) Your script must contain valid commands, everything is parsed, use the docudemons for ideas on scripting conditions and or commands/events. You can use excel viewer (free software provided by microsoft) if you do not have excel to view them.
Lastly here is what the final script looks like.
Code:
; *********************************************************************************************
; EBII Battle Scripts
; 27/1/2015
; z3n
; *********************************************************************************************
script
while ! I_BattleStarted
end_while
;;;;*************************************************************************************************
;;;; Initialize Battle
;;;;*************************************************************************************************
log always EBII Battle Scripts
log always Activated
restart_timer deployment_timer
;generate_random_counter AI_RHTC 1 100 (event counter only works in the campaign script)
;;;;*************************************************************************************************
;;;; Counters
;;;;*************************************************************************************************
declare_counter deploy_check
declare_counter start_battle
declare_counter FaW_and_S
declare_counter Release_Labels
declare_counter End_Labels
declare_counter AI_GRP
declare_counter AI_HTC
declare_counter AI_reinforcements
declare_timer deployment_timer
declare_timer AI_reinforcements_timer
;suspend_unscripted_advice true
monitor_conditions I_TimerElapsed deployment_timer > 101
and I_InBattle
and not I_BattleStarted
restart_timer deployment_timer
set_counter AI_GRP 0
set_counter AI_reinforcements 0
end_monitor
monitor_conditions I_TimerElapsed deployment_timer < 101
and I_InBattle
prepare_for_battle
set_counter AI_HTC 0
set_counter deploy_check 1
end_monitor
monitor_conditions I_CompareCounter deploy_check = 1
and I_BattleStarted
set_counter start_battle 1
end_monitor
monitor_conditions I_CompareCounter start_battle = 1
and I_BattleStarted
set_counter Release_Labels 1
set_counter FaW_and_S 1
if I_CompareCounter Release_Labels = 1
set_counter start_battle 0
end_if
;;;;*************************************************************************************************
;;;; Create Labels
;;;;*************************************************************************************************
; *********************************************************************************************
; Main Army Unit Labels
; *********************************************************************************************
label_unit 0 0 0 MAu1
label_unit 0 0 1 MAu2
label_unit 0 0 2 MAu3
label_unit 0 0 3 MAu4
label_unit 0 0 4 MAu5
label_unit 0 0 5 MAu6
label_unit 0 0 6 MAu7
label_unit 0 0 7 MAu8
label_unit 0 0 8 MAu9
label_unit 0 0 9 MAu10
label_unit 0 0 10 MAu11
label_unit 0 0 11 MAu12
label_unit 0 0 12 MAu13
label_unit 0 0 13 MAu14
label_unit 0 0 14 MAu15
label_unit 0 0 15 MAu16
label_unit 0 0 16 MAu17
label_unit 0 0 17 MAu18
label_unit 0 0 18 MAu19
label_unit 0 0 19 MAu20
label_unit 0 0 20 MAu21
label_unit 0 0 21 MAu22
label_unit 0 0 22 MAu23
label_unit 0 0 23 MAu24
label_unit 0 0 24 MAu25
label_unit 0 0 25 MAu26
label_unit 0 0 26 MAu27
label_unit 0 0 27 MAu28
label_unit 0 0 28 MAu29
label_unit 0 0 29 MAu30
label_unit 0 0 30 MAu31
label_unit 0 0 31 MAu32
label_unit 0 0 32 MAu33
label_unit 0 0 33 MAu34
label_unit 0 0 34 MAu35
label_unit 0 0 35 MAu36
label_unit 0 0 36 MAu37
label_unit 0 0 37 MAu38
label_unit 0 0 38 MAu39
label_unit 0 0 39 MAu40
; *********************************************************************************************
; Allied Unit Labels
; *********************************************************************************************
label_unit 1 0 0 Eu1
label_unit 1 0 1 Eu2
label_unit 1 0 2 Eu3
label_unit 1 0 3 Eu4
label_unit 1 0 4 Eu5
label_unit 1 0 5 Eu6
label_unit 1 0 6 Eu7
label_unit 1 0 7 Eu8
label_unit 1 0 8 Eu9
label_unit 1 0 9 Eu10
label_unit 1 0 10 Eu11
label_unit 1 0 11 Eu12
label_unit 1 0 12 Eu13
label_unit 1 0 13 Eu14
label_unit 1 0 14 Eu15
label_unit 1 0 15 Eu16
label_unit 1 0 16 Eu17
label_unit 1 0 17 Eu18
label_unit 1 0 18 Eu19
label_unit 1 0 19 Eu20
label_unit 1 0 20 Eu21
label_unit 1 0 21 Eu22
label_unit 1 0 22 Eu23
label_unit 1 0 23 Eu24
label_unit 1 0 24 Eu25
label_unit 1 0 25 Eu26
label_unit 1 0 26 Eu27
label_unit 1 0 27 Eu28
label_unit 1 0 28 Eu29
label_unit 1 0 29 Eu30
label_unit 1 0 30 Eu31
label_unit 1 0 31 Eu32
label_unit 1 0 32 Eu33
label_unit 1 0 33 Eu34
label_unit 1 0 34 Eu35
label_unit 1 0 35 Eu36
label_unit 1 0 36 Eu37
label_unit 1 0 37 Eu38
label_unit 1 0 38 Eu39
label_unit 1 0 39 Eu40
; *********************************************************************************************
; Group Labels
; *********************************************************************************************
define_unit_group Allies MAu1 MAu2 MAu3 MAu4 MAu5 MAu6 MAu7 MAu8 MAu9 MAu10 MAu11 MAu12 MAu13 MAu14 MAu15 MAu16 MAu17 MAu18 MAu19 MAu20 MAu21 MAu22 MAu23 MAu24 MAu25 MAu26 MAu27 MAu28 MAu29 MAu30 MAu31 MAu32 MAu33 MAu34 MAu35 MAu36 MAu37 MAu38 MAu39 MAu40
define_unit_group Enemy Eu1 Eu2 Eu3 Eu4 Eu5 Eu6 Eu7 Eu8 Eu9 Eu10 Eu11 Eu12 Eu13 Eu14 Eu15 Eu16 Eu17 Eu18 Eu19 Eu20 Eu21 Eu22 Eu23 Eu24 Eu25 Eu26 Eu27 Eu28 Eu29 Eu30 Eu31 Eu32 Eu33 Eu34 Eu35 Eu36 Eu37 Eu38 Eu39 Eu40
end_monitor
monitor_conditions I_CompareCounter FaW_and_S > 0
and I_BattleStarted
set_counter End_Labels 1
; *********************************************************************************************
; FaW - Active
; *********************************************************************************************
; *********************************************************************************************
; FaW - Player
; *********************************************************************************************
unit_set_fire_at_will_mode MAu1 on
unit_set_fire_at_will_mode MAu2 on
unit_set_fire_at_will_mode MAu3 on
unit_set_fire_at_will_mode MAu4 on
unit_set_fire_at_will_mode MAu5 on
unit_set_fire_at_will_mode MAu6 on
unit_set_fire_at_will_mode MAu7 on
unit_set_fire_at_will_mode MAu8 on
unit_set_fire_at_will_mode MAu9 on
unit_set_fire_at_will_mode MAu10 on
unit_set_fire_at_will_mode MAu11 on
unit_set_fire_at_will_mode MAu12 on
unit_set_fire_at_will_mode MAu13 on
unit_set_fire_at_will_mode MAu14 on
unit_set_fire_at_will_mode MAu15 on
unit_set_fire_at_will_mode MAu16 on
unit_set_fire_at_will_mode MAu17 on
unit_set_fire_at_will_mode MAu18 on
unit_set_fire_at_will_mode MAu19 on
unit_set_fire_at_will_mode MAu20 on
unit_set_fire_at_will_mode MAu21 on
unit_set_fire_at_will_mode MAu22 on
unit_set_fire_at_will_mode MAu23 on
unit_set_fire_at_will_mode MAu24 on
unit_set_fire_at_will_mode MAu25 on
unit_set_fire_at_will_mode MAu26 on
unit_set_fire_at_will_mode MAu27 on
unit_set_fire_at_will_mode MAu28 on
unit_set_fire_at_will_mode MAu29 on
unit_set_fire_at_will_mode MAu30 on
unit_set_fire_at_will_mode MAu31 on
unit_set_fire_at_will_mode MAu32 on
unit_set_fire_at_will_mode MAu33 on
unit_set_fire_at_will_mode MAu34 on
unit_set_fire_at_will_mode MAu35 on
unit_set_fire_at_will_mode MAu36 on
unit_set_fire_at_will_mode MAu37 on
unit_set_fire_at_will_mode MAu38 on
unit_set_fire_at_will_mode MAu39 on
unit_set_fire_at_will_mode MAu40 on
; *********************************************************************************************
; FaW - AI
; *********************************************************************************************
unit_set_fire_at_will_mode Eu1 on
unit_set_fire_at_will_mode Eu2 on
unit_set_fire_at_will_mode Eu3 on
unit_set_fire_at_will_mode Eu4 on
unit_set_fire_at_will_mode Eu5 on
unit_set_fire_at_will_mode Eu6 on
unit_set_fire_at_will_mode Eu7 on
unit_set_fire_at_will_mode Eu8 on
unit_set_fire_at_will_mode Eu9 on
unit_set_fire_at_will_mode Eu10 on
unit_set_fire_at_will_mode Eu11 on
unit_set_fire_at_will_mode Eu12 on
unit_set_fire_at_will_mode Eu13 on
unit_set_fire_at_will_mode Eu14 on
unit_set_fire_at_will_mode Eu15 on
unit_set_fire_at_will_mode Eu16 on
unit_set_fire_at_will_mode Eu17 on
unit_set_fire_at_will_mode Eu18 on
unit_set_fire_at_will_mode Eu19 on
unit_set_fire_at_will_mode Eu20 on
unit_set_fire_at_will_mode Eu21 on
unit_set_fire_at_will_mode Eu22 on
unit_set_fire_at_will_mode Eu23 on
unit_set_fire_at_will_mode Eu24 on
unit_set_fire_at_will_mode Eu25 on
unit_set_fire_at_will_mode Eu26 on
unit_set_fire_at_will_mode Eu27 on
unit_set_fire_at_will_mode Eu28 on
unit_set_fire_at_will_mode Eu29 on
unit_set_fire_at_will_mode Eu30 on
unit_set_fire_at_will_mode Eu31 on
unit_set_fire_at_will_mode Eu32 on
unit_set_fire_at_will_mode Eu33 on
unit_set_fire_at_will_mode Eu34 on
unit_set_fire_at_will_mode Eu35 on
unit_set_fire_at_will_mode Eu36 on
unit_set_fire_at_will_mode Eu37 on
unit_set_fire_at_will_mode Eu38 on
unit_set_fire_at_will_mode Eu39 on
unit_set_fire_at_will_mode Eu40 on
; *********************************************************************************************
; Skirmish Mode - Active
; *********************************************************************************************
unit_set_skirmish_mode Eu1 on
unit_set_skirmish_mode Eu2 on
unit_set_skirmish_mode Eu3 on
unit_set_skirmish_mode Eu4 on
unit_set_skirmish_mode Eu5 on
unit_set_skirmish_mode Eu6 on
unit_set_skirmish_mode Eu7 on
unit_set_skirmish_mode Eu8 on
unit_set_skirmish_mode Eu9 on
unit_set_skirmish_mode Eu10 on
unit_set_skirmish_mode Eu11 on
unit_set_skirmish_mode Eu12 on
unit_set_skirmish_mode Eu13 on
unit_set_skirmish_mode Eu14 on
unit_set_skirmish_mode Eu15 on
unit_set_skirmish_mode Eu16 on
unit_set_skirmish_mode Eu17 on
unit_set_skirmish_mode Eu18 on
unit_set_skirmish_mode Eu19 on
unit_set_skirmish_mode Eu20 on
unit_set_skirmish_mode Eu21 on
unit_set_skirmish_mode Eu22 on
unit_set_skirmish_mode Eu23 on
unit_set_skirmish_mode Eu24 on
unit_set_skirmish_mode Eu25 on
unit_set_skirmish_mode Eu26 on
unit_set_skirmish_mode Eu27 on
unit_set_skirmish_mode Eu28 on
unit_set_skirmish_mode Eu29 on
unit_set_skirmish_mode Eu30 on
unit_set_skirmish_mode Eu31 on
unit_set_skirmish_mode Eu32 on
unit_set_skirmish_mode Eu33 on
unit_set_skirmish_mode Eu34 on
unit_set_skirmish_mode Eu35 on
unit_set_skirmish_mode Eu36 on
unit_set_skirmish_mode Eu37 on
unit_set_skirmish_mode Eu38 on
unit_set_skirmish_mode Eu39 on
unit_set_skirmish_mode Eu40 on
end_monitor
monitor_conditions I_CompareCounter Release_Labels > 0
and I_BattleStarted
;Must release Main Army, internal army label is recalibrated upon arrival of AI reinforcements causing 1 (previously the main AI army) to become 0 and 1 to become the secondary AI army.
release_unit MAu1
release_unit MAu2
release_unit MAu3
release_unit MAu4
release_unit MAu5
release_unit MAu6
release_unit MAu7
release_unit MAu8
release_unit MAu9
release_unit MAu10
release_unit MAu11
release_unit MAu12
release_unit MAu13
release_unit MAu14
release_unit MAu15
release_unit MAu16
release_unit MAu17
release_unit MAu18
release_unit MAu19
release_unit MAu20
release_unit MAu21
release_unit MAu22
release_unit MAu23
release_unit MAu24
release_unit MAu25
release_unit MAu26
release_unit MAu27
release_unit MAu28
release_unit MAu29
release_unit MAu30
release_unit MAu31
release_unit MAu32
release_unit MAu33
release_unit MAu34
release_unit MAu35
release_unit MAu36
release_unit MAu37
release_unit MAu38
release_unit MAu39
release_unit MAu40
release_unit Eu1
release_unit Eu2
release_unit Eu3
release_unit Eu4
release_unit Eu5
release_unit Eu6
release_unit Eu7
release_unit Eu8
release_unit Eu9
release_unit Eu10
release_unit Eu11
release_unit Eu12
release_unit Eu13
release_unit Eu14
release_unit Eu15
release_unit Eu16
release_unit Eu17
release_unit Eu18
release_unit Eu19
release_unit Eu20
release_unit Eu21
release_unit Eu22
release_unit Eu23
release_unit Eu24
release_unit Eu25
release_unit Eu26
release_unit Eu27
release_unit Eu28
release_unit Eu29
release_unit Eu30
release_unit Eu31
release_unit Eu32
release_unit Eu33
release_unit Eu34
release_unit Eu35
release_unit Eu36
release_unit Eu37
release_unit Eu38
release_unit Eu39
release_unit Eu40
end_monitor
monitor_conditions I_CompareCounter End_Labels = 1
and I_BattleStarted
set_counter Release_Labels 0
if I_CompareCounter Release_Labels = 0
set_counter FaW_and_S 0
set_counter End_Labels 0
set_counter deploy_check 0
end_if
end_monitor
; *********************************************************************************************
; Initialize Battle Plans & Monitors
; *********************************************************************************************
; *********************************************************************************************
; Shared Reinforcements Monitor
; *********************************************************************************************
monitor_event BattleReinforcementsArrive
;AI Reinforcements
inc_counter AI_reinforcements 1
if I_CompareCounter AI_reinforcements = 1
restart_timer AI_reinforcements_timer
end_if
end_monitor
; *********************************************************************************************
; AI Reinforcements Defend Plan
; *********************************************************************************************
monitor_conditions I_CompareCounter AI_reinforcements > 0
and I_BattlePlayerAllianceOddsInFavour > 1
and I_TimerElapsed AI_reinforcements_timer < 90000
;AI Units from Army 1 Battle Objective
ai_gta_add_objective 0 DEFEND_LINE 999
;AI Army 1 Battle Objective
ai_gta_plan_set 0 DEFEND_FEATURE
;AI Units from Army 2 Battle Objective
ai_gta_add_objective 1 DEFEND_LINE 999
;AI Army 2 Battle Objective
ai_gta_plan_set 1 DEFEND_FEATURE
end_monitor
; *********************************************************************************************
; AI Reinforcements Attack Plan
; *********************************************************************************************
monitor_conditions I_CompareCounter AI_reinforcements > 0
and not I_BattlePlayerArmyIsAttacker
and I_TimerElapsed AI_reinforcements_timer > 90000
;AI Units from Army 1 Battle Objective
ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
;AI Army 1 Battle Objective
ai_gta_plan_set 0 ATTACK_ALL
;AI Units from Army 2 Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Army 2 Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
; *********************************************************************************************
; AI Unit Monitors & AI Reactions
; *********************************************************************************************
monitor_conditions I_PercentageUnitKilled Eu1 > 5
and I_BattleStarted
and not I_BattleIsSiegeBattle
inc_counter AI_GRP 1
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
monitor_conditions I_PercentageOfArmyKilled 1 0 > 3
and I_BattleStarted
and I_BattlePlayerArmyIsAttacker
and not I_BattleIsSiegeBattle
inc_counter AI_GRP 1
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
; *********************************************************************************************
; Unit Group Orders - Disabled
; *********************************************************************************************
;monitor_conditions I_InBattle
;and I_ConflictType Normal
;and I_BattleEnemyArmyNumberOfClassAndCategory missile cavalry > 9
;and I_PercentageOfArmyKilled 1 0 >= 5
;unit_group_set_morale Enemy routing
;end_monitor
monitor_conditions I_BattlePlayerArmyNumberOfAttribute general_unit > 0
and I_BattleEnemyArmyNumberOfAttribute general_unit = 0
and I_InBattle
; *********************************************************************************************
; Help The Captain - AI (35% chance of an experienced captain)
; *********************************************************************************************
unit_set_experience Eu1 3
unit_set_experience Eu2 3
unit_set_experience Eu3 3
unit_set_experience Eu4 3
unit_set_experience Eu5 3
unit_set_experience Eu6 3
unit_set_experience Eu7 3
unit_set_experience Eu8 3
unit_set_experience Eu9 3
unit_set_experience Eu10 3
unit_set_experience Eu11 3
unit_set_experience Eu12 3
unit_set_experience Eu13 3
unit_set_experience Eu14 3
unit_set_experience Eu15 3
unit_set_experience Eu16 3
unit_set_experience Eu17 3
unit_set_experience Eu18 3
unit_set_experience Eu19 3
unit_set_experience Eu20 3
unit_set_experience Eu21 3
unit_set_experience Eu22 3
unit_set_experience Eu23 3
unit_set_experience Eu24 3
unit_set_experience Eu25 3
unit_set_experience Eu26 3
unit_set_experience Eu27 3
unit_set_experience Eu28 3
unit_set_experience Eu29 3
unit_set_experience Eu30 3
unit_set_experience Eu31 3
unit_set_experience Eu32 3
unit_set_experience Eu33 3
unit_set_experience Eu34 3
unit_set_experience Eu35 3
unit_set_experience Eu36 3
unit_set_experience Eu37 3
unit_set_experience Eu38 3
unit_set_experience Eu39 3
unit_set_experience Eu40 3
;AI Reinforcements/Main Army get set to the internal label 0 which was previously the players when reinforced
;AI Reinforcing Army = MA = 0, AI Reinforcing Army 2 = (E) = 1, Player Army = 2 when there are two reinforcing AI armies
;Internal Labels are counted from 0 onwards
;No Random Help The Captain Conditions as this would be an important army/battle if two reinforcements
if I_CompareCounter AI_Reinforcements > 0
unit_set_experience MAu1 3
unit_set_experience MAu2 3
unit_set_experience MAu3 3
unit_set_experience MAu4 3
unit_set_experience MAu5 3
unit_set_experience MAu6 3
unit_set_experience MAu7 3
unit_set_experience MAu8 3
unit_set_experience MAu9 3
unit_set_experience MAu10 3
unit_set_experience MAu11 3
unit_set_experience MAu12 3
unit_set_experience MAu13 3
unit_set_experience MAu14 3
unit_set_experience MAu15 3
unit_set_experience MAu16 3
unit_set_experience MAu17 3
unit_set_experience MAu18 3
unit_set_experience MAu19 3
unit_set_experience MAu20 3
unit_set_experience MAu21 3
unit_set_experience MAu22 3
unit_set_experience MAu23 3
unit_set_experience MAu24 3
unit_set_experience MAu25 3
unit_set_experience MAu26 3
unit_set_experience MAu27 3
unit_set_experience MAu28 3
unit_set_experience MAu29 3
unit_set_experience MAu30 3
unit_set_experience MAu31 3
unit_set_experience MAu32 3
unit_set_experience MAu33 3
unit_set_experience MAu34 3
unit_set_experience MAu35 3
unit_set_experience MAu36 3
unit_set_experience MAu37 3
unit_set_experience MAu38 3
unit_set_experience MAu39 3
unit_set_experience MAu40 3
unit_set_experience Eu1 3
unit_set_experience Eu2 3
unit_set_experience Eu3 3
unit_set_experience Eu4 3
unit_set_experience Eu5 3
unit_set_experience Eu6 3
unit_set_experience Eu7 3
unit_set_experience Eu8 3
unit_set_experience Eu9 3
unit_set_experience Eu10 3
unit_set_experience Eu11 3
unit_set_experience Eu12 3
unit_set_experience Eu13 3
unit_set_experience Eu14 3
unit_set_experience Eu15 3
unit_set_experience Eu16 3
unit_set_experience Eu17 3
unit_set_experience Eu18 3
unit_set_experience Eu19 3
unit_set_experience Eu20 3
unit_set_experience Eu21 3
unit_set_experience Eu22 3
unit_set_experience Eu23 3
unit_set_experience Eu24 3
unit_set_experience Eu25 3
unit_set_experience Eu26 3
unit_set_experience Eu27 3
unit_set_experience Eu28 3
unit_set_experience Eu29 3
unit_set_experience Eu30 3
unit_set_experience Eu31 3
unit_set_experience Eu32 3
unit_set_experience Eu33 3
unit_set_experience Eu34 3
unit_set_experience Eu35 3
unit_set_experience Eu36 3
unit_set_experience Eu37 3
unit_set_experience Eu38 3
unit_set_experience Eu39 3
unit_set_experience Eu40 3
end_if
end_monitor
;Test Order - Player Allies Only
; unit_group_order_relative_move_formed Allies 0 200
; I_UnitGroupInRangeOfUnitGroup
; I_PercentageUnitGroupKilled
; *********************************************************************************************
; Normal Attack Plan
; *********************************************************************************************
monitor_conditions I_CompareCounter AI_reinforcements = 0
and I_ConflictType Normal
and I_InBattle
and not I_BattlePlayerArmyIsAttacker
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
; *********************************************************************************************
; Normal Defend Plan
; Recurring counters fire above 0
; *********************************************************************************************
monitor_conditions I_CompareCounter AI_reinforcements = 0
and I_ConflictType Normal
and I_InBattle
and not I_BattleAiAttacking
and I_BattlePlayerArmyIsAttacker
if I_CompareCounter AI_GRP = 0
;AI Units Battle Objective Main Army
ai_gta_add_objective 1 DEFEND_LINE 999
;AI Alliance Battle Objective Main Army
ai_gta_plan_set 1 DEFEND_FEATURE
end_if
if I_CompareCounter AI_GRP > 0
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_if
end_monitor
; *********************************************************************************************
; Assault Crossing
; *********************************************************************************************
monitor_conditions I_BattleIsRiverBattle
and I_InBattle
and not I_BattlePlayerArmyIsAttacker
;AI Units Battle Objective
ai_gta_add_objective 1 ASSAULT_CROSSING 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
; *********************************************************************************************
; Assault Settlement
; *********************************************************************************************
monitor_conditions I_BattleIsSiegeBattle
and I_InBattle
and not I_BattlePlayerArmyIsAttacker
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_SETTLEMENT
end_monitor
; *********************************************************************************************
; Sally Out
; *********************************************************************************************
monitor_conditions I_BattleIsSallyOutBattle
and I_InBattle
and not I_BattlePlayerArmyIsAttacker
;AI Units Battle Objective
ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
;AI Alliance Battle Objective
ai_gta_plan_set 1 ATTACK_ALL
end_monitor
while I_InBattle
end_while
end_script