Hi, I saw your message and popped to look at the script. My feedback (mind that I did not test these code snippets, thetr may be typos inside)
A general feedback: have consistent tabbing for every code blocks, it makes it more readable and help prevent missing end_if and such.
First monitor, you are testing the same conditions every time (isbattlesiege and battleplayerarmyisattacker) but you already test them in the monitor declaration, I think this is redundant and would just do:
Code:
monitor_conditions I_BattleStarted
and I_BattleIsSiegeBattle
and ! I_BattlePlayerArmyIsAttacker
and I_CompareCounter sally_siege_fix = 0
battle_wait 1
set_counter sally_siege_fix 1
label_location 0, -850, south_side
label_location 0, 850, north_side
label_location -850, 0, west_side
label_location 850, 0, east_side
if I_UnitDistanceFromLine a1u1 west_side east_side > 200
log -siege_script- Army South
set_counter defence_south 1
end_if
if I_UnitDistanceFromLine a1u1 west_side east_side < -200
log -siege_script- Army North
set_counter defence_north 1
end_if
if I_UnitDistanceFromLine a1u1 south_side north_side > 200
log -siege_script- Army East
set_counter defence_east 1
end_if
if I_UnitDistanceFromLine a1u1 south_side north_side < -200
log -siege_script- Army West
set_counter defence_west 1
end_if
Then the bit about testing distance:
- nesting ifs would prevent unecessary tests (but this is so ugly!)
- too much logging, just use log_counter after the distance has been tested
Code:
if I_CompareCounter defence_south = 1
;a2u1
if I_CompareCounter player_unit_count > 0
if I_UnitDistanceFromLine a2u1 west_side east_side < 400
set_counter a2u1_start_distance 40
if I_UnitDistanceFromLine a2u1 west_side east_side < 380
set_counter a2u1_start_distance 38
if I_UnitDistanceFromLine a2u1 west_side east_side < 360
set_counter a2u1_start_distance 36
if I_UnitDistanceFromLine a2u1 west_side east_side < 340
set_counter a2u1_start_distance 34
if I_UnitDistanceFromLine a2u1 west_side east_side < 320
set_counter a2u1_start_distance 32
if I_UnitDistanceFromLine a2u1 west_side east_side < 300
set_counter a2u1_start_distance 30
if I_UnitDistanceFromLine a2u1 west_side east_side < 280
set_counter a2u1_start_distance 28
if I_UnitDistanceFromLine a2u1 west_side east_side < 260
set_counter a2u1_start_distance 26
if I_UnitDistanceFromLine a2u1 west_side east_side < 240
set_counter a2u1_start_distance 24
if I_UnitDistanceFromLine a2u1 west_side east_side < 220
set_counter a2u1_start_distance 22
if I_UnitDistanceFromLine a2u1 west_side east_side < 200
set_counter a2u1_start_distance 20
if I_UnitDistanceFromLine a2u1 west_side east_side < 180
set_counter a2u1_start_distance 18
if I_UnitDistanceFromLine a2u1 west_side east_side < 160
set_counter a2u1_start_distance 16
if I_UnitDistanceFromLine a2u1 west_side east_side < 140
set_counter a2u1_start_distance 14
if I_UnitDistanceFromLine a2u1 west_side east_side < 120
set_counter a2u1_start_distance 12
if I_UnitDistanceFromLine a2u1 west_side east_side < 100
set_counter a2u1_start_distance 10
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
end_if
log_counter a2u1_start_distance
end_if
Same thing about nesting can be reused at different places, also extracting code from nested ifs to execute just after can make is more readable, and easier to refactor (I admire you for making such a script in a language that is so limited...)
Instead of:
Code:
if I_CompareCounter a2u8_start_distance 110;unit needs to change the distance in the axis perpendicular to the gates
unit_set_morale a2u8 routing
set_counter a2u8_routed 1
battle_wait 0.1
log -siege_script- PlayerUnit a2u8 set_morale routing 110
end_if
if I_CompareCounter a2u8_start_distance 130
set_counter a2u8_routed 1
unit_set_morale a2u8 routing
battle_wait 0.1
log -siege_script- PlayerUnit a2u8 set_morale routing 130
end_if
; etc ...
I would try this kind of coding
Code:
if I_CompareCounter a2u8_start_distance 110;unit needs to change the distance in the axis perpendicular to the gates
set_counter DO_IT 1
if I_CompareCounter a2u8_start_distance 130
set_counter DO_IT 1
; all the rest of the nesting here, enjoy ...
end_if
end_if
if I_CompareCounter DO_IT == 1
unit_set_morale a2u8 routing
set_counter a2u8_routed 1
battle_wait 0.1
log_counter a2u8_routed
set_counter DO_IT 0
end_if
; etc ...
About the third part of the script and the 20 monitors you wanted to merge:
Code:
monitor_event BattlePlayerUnitRouts TrueCondition
and BattlePlayerUnitOnWalls
and I_CompareCounter siege_script_end = 0
and I_CompareCounter sally_siege_fix = 1
if I_IsUnitRouting a2u1
and I_CompareCounter a2u1_on_walls = 0
unit_set_morale a2u1 firm
unit_unset_morale a2u1
set_counter a2u1_on_walls 1
log -siege_script- Unit a2u1 Unrouted on walls +
end_if
if I_IsUnitRouting a2u2
and I_CompareCounter a2u2_on_walls = 0
unit_set_morale a2u2 firm
unit_unset_morale a2u2
set_counter a2u2_on_walls 1
log -siege_script- Unit a2u2 Unrouted on walls +
end_if
if I_IsUnitRouting a2u3
and I_CompareCounter a2u3_on_walls = 0
unit_set_morale a2u3 firm
unit_unset_morale a2u3
set_counter a2u3_on_walls 1
log -siege_script- Unit a2u3 Unrouted on walls +
end_if
; same logic repeated here for all units
; could also be nested but I'm not sure there would be much to gain here...
end_monitor