Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Siege Defending Script

  1. #1

    Default Siege Defending Script

    Guys, I wrote this script, it makes routing units that sally out of the settlement in the first phase of the siege, when the siege engines are advancing. It makes it impossible or at least very risky to attack the ram and towers. It means that the sieges will become much more sophisticated and difficult as the enemy will use all the siege equipment. Up to now it was enough to attack the engines, leaving one ladder and AI was lost, crowding all the units to climb a ladder.

    1.Here is the file for campaign version. (updated 28 July 2023)

    To install it, just COPY EVERYTHING from the file above and REPLACE THE WHOLE BAI script in the

    ...\Medieval II Total War\mods\SSHIP_098\data\world\maps\campaign\imperial_campaign\campaign_script.txt

    In detail- replace everything starting with this:

    ;==================================================================
    ;------- G5 BAI STUFF
    ;==================================================================

    ....
    And finishing with this:


    ....
    set_counter a2u18_distance 0
    set_counter a2u19_distance 0
    set_counter a2u20_distance 0
    ; suspend_unscripted_advice false
    end_monitor
    Doing this you will replace the Germanicus script with the same one but including some counters declaration and of course my script.

    It should work with whatever version of SSHIP you have. If somebody wants to install it for custom battles I can prepare also files for it.

    I tested it already a lot in custom battles and a little in campaign.. I wonder what will be your opinion, does it work in campaigns in many situations, especially when ai have reinforcements? Do you find it worthy to implement, or unnecessary ?

    I posted a new version July 28 2023- some improvements for the settlements with just wood palisade. Its tested on the separate computer with a fresh install of MTW2 + SSHIP, also in Titanium and SS6.4. It should work in whatever mod that uses G5.
    Last edited by Macaras; July 28, 2023 at 01:42 PM. Reason: Updated Version

  2. #2

    Default Re: Siege Defending Script

    Perfect Macaras, i will try in my sicilian campaign! And tell you my opinion
    THE MORE YOU SWEAT NOW,
    THE LESS YOU BLEED IN BATTLE!!!



    Sign the petition to remove hardcoded limits for M2TW

  3. #3

    Default Re: Siege Defending Script

    Does it work on AI sallying out too for the player's battering ram? It's a minor problem that at least on smaller settlements, usually one AI unit sallies out right before player's ram is closing in on the gates, which leads to not needing to use the ram at all to storm the gate. I suspect it's caused by the AI not being able to take into account the rest of the player's troops, which wait outside of the range of AI archers / towers. I guess a house rule solution would be to march some / all of the troops closer to the gate, but it's a bit hard not to spare them of the arrow rain whilst waiting for the ram to do its job. If a script could force the AI not to sally out at all in those situations, all the better.

    Defending a siege battle on the other hand is lots of fun when having to think about troop placement with AI siege towers and ladders in mind. Perhaps the AI uses more of them when they have larger armies or the player has larger settlements? So far in 115+ turns the Danes have only used one ram, one siege tower and one set of ladders simultaneously when sieging my wooden castles / wooden walls.

  4. #4

    Default

    Thank you j.a. luna! if you are interested I also posted the custom battle version in the first post.

    Quote Originally Posted by vovery View Post
    Does it work on AI sallying out too for the player's battering ram? It's a minor problem that at least on smaller settlements, usually one AI unit sallies out right before player's ram is closing in on the gates, which leads to not needing to use the ram at all to storm the gate. I suspect it's caused by the AI not being able to take into account the rest of the player's troops, which wait outside of the range of AI archers / towers. I guess a house rule solution would be to march some / all of the troops closer to the gate, but it's a bit hard not to spare them of the arrow rain whilst waiting for the ram to do its job. If a script could force the AI not to sally out at all in those situations, all the better.

    Defending a siege battle on the other hand is lots of fun when having to think about troop placement with AI siege towers and ladders in mind. Perhaps the AI uses more of them when they have larger armies or the player has larger settlements? So far in 115+ turns the Danes have only used one ram, one siege tower and one set of ladders simultaneously when sieging my wooden castles / wooden walls.
    Vovery, I think this is already a G5 way of making AI smarter and if you think about this - its the best tactics against human. AI can either wait until the gates is broken and the attacker has a nice open gates to run into it, or sally out just in the right moment when the gates are about to be reached by the ram. The second option leaves the ram in the middle of the gate which forces units to enter very slowly, easier to defend. This is an improvement, not a bug.
    Regarding the second question, true- ai uses more engines in the bigger armies.
    Last edited by Maximinus Thrax; July 04, 2023 at 09:34 AM. Reason: posts merged

  5. #5

    Default Re: Siege Defending Script

    Quote Originally Posted by Macaras View Post
    Vovery, I think this is already a G5 way of making AI smarter and if you think about this - its the best tactics against human. AI can either wait until the gates is broken and the attacker has a nice open gates to run into it, or sally out just in the right moment when the gates are about to be reached by the ram. The second option leaves the ram in the middle of the gate which forces units to enter very slowly, easier to defend. This is an improvement, not a bug.
    Regarding the second question, true- ai uses more engines in the bigger armies.
    Perhaps you're right. I haven't tested it thoroughly so can't say for sure, but I have a slight memory that the AI doesn't sally out if you have more units closer to the ram. I should test it to confirm. The ram isn't blocking the gate that much though, as right when the gates open, the player can order the ram unit to drop it, and attack the sallying unit. Then order some more troops to attack too, and one troop to move the ram out of the way. Though now that I think of it, the AI archer towers still have the opportunity to work even when the battle is ongoing at the gate with doors open. What I was thinking was that they would have a little bit more time to do so, if the ram had to break through the gates, and only then the AI would sally forth to block the player from entering through the broken gate. And yea, definitely not a bug, just a minor problem in my opinion

    Can't wait to defend sieges by bigger armies too in later gameplay! Siege defending against a bigger and stronger force feels the hardest to estimate if you'll actually win the battle or not, and on some of them I've already been on the verge of survival even though Norway and Denmark don't have that big armies yet at 115+ turns. Really get the feel of desperation kicking in, and also the joy when the tide of battle turns in favour of yourself. Siege attacks don't often produce the same situation, as you get to mostly choose your moment of sieging the enemy settlement in a favourable time.

  6. #6

    Default Re: Siege Defending Script

    Hi Macaras here my opinion with 3 sieges with the new system...Usually when I go out to attack the siege engines like towers or battering ram, the enemy army will attack me and protect their siege engines very well, but the problem remains that once I have entered my castle with my cavalry, the The enemy chooses a single siege engine (for example some stairs) and simply puts them up and all the infantry starts to crowd up to climb them, so I only have to defend a section and concentrate my forces, the battering ram and the towers leave it aside ... I'll give you some images so you can see them (tga file).


    NEW SIEGES.rar


    I suppose that I have copied my files correctly, please check it, I will also give you that file.


    campaign_script.rar
    THE MORE YOU SWEAT NOW,
    THE LESS YOU BLEED IN BATTLE!!!



    Sign the petition to remove hardcoded limits for M2TW

  7. #7

    Default Re: Siege Defending Script

    Thanks for your feedback ! It means that the script didn't even trigger, otherwise the difference will be obvious. The defender units should rout once leave the castle.. Could you upload a log as well ? What settlement is this that you defend? Did enemy have 2 or more missile units ?

  8. #8

    Default Re: Siege Defending Script

    Quote Originally Posted by Macaras View Post
    Thanks for your feedback ! It means that the script didn't even trigger, otherwise the difference will be obvious. The defender units should rout once leave the castle.. Could you upload a log as well ? What settlement is this that you defend? Did enemy have 2 or more missile units ?
    The sieges was in 2 settlements, in Ancona against Venetians and Tarabulus against Fatimids, i guess that both enemies had not missile units, only infantry and cavalry... But I attacked the siege engines with my bodyguard and general, is it necessary for the enemy to have at least 2 missile units? what is the reason? If this works, would even my general or bodyguard flee / go on the run?
    THE MORE YOU SWEAT NOW,
    THE LESS YOU BLEED IN BATTLE!!!



    Sign the petition to remove hardcoded limits for M2TW

  9. #9

    Default Re: Siege Defending Script

    Quote Originally Posted by j.a.luna View Post
    The sieges was in 2 settlements, in Ancona against Venetians and Tarabulus against Fatimids, i guess that both enemies had not missile units, only infantry and cavalry... But I attacked the siege engines with my bodyguard and general, is it necessary for the enemy to have at least 2 missile units? what is the reason? If this works, would even my general or bodyguard flee / go on the run?
    Yes, it is necessary (right now it is the condition for the script to start), I thought it threatens more the sallying out units. Without missile units they will not rout. I have no problem with changing it though, and make the units flee regardless missile or not. For the second question - the general will flee as well.

    I was playing testing it and found already two mistakes, I will try upload a new version of the script tonight. I will also remove the condition for the missile units..

    New version available (07 of July) - I removed few bugs, let's see now how it works -> look the first post in this thread.
    Last edited by Macaras; July 07, 2023 at 11:40 AM.

  10. #10

    Default Re: Siege Defending Script

    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
    Last edited by Belovèse; July 07, 2023 at 01:53 PM.
    Belovèse's Toolbox: export text files to spreadsheet, detailed unit stats
    Stainless Steel Historical Improvement Project (SSHIP) team member.
    Mini-mods: diplomacy and relation/reputation - detailled unit stats

  11. #11

    Default Re: Siege Defending Script

    Thank you for looking into it! I have some comments and questions though:

    1.
    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
    Just wanted to make sure the other monitors will never trigger in different situations than player defending the siege. I set the counter sally_siege_fix = 0 to 0 when the script is finishing, and I was not sure about timing, sometimes things happen 'in the meantime'. Does 'and' parts also consume more processor timing ?

    2.
    nesting ifs would prevent unecessary tests (but this is so ugly!)
    True, I will change it maybe as the las thing, will it really give me much time saved? Actually I was thinking, for example for 10 units it gives 10 x15 - 150 if, seems a lot to gain!

    3. But this way of coding (below) will give me double number of 'if' ?

    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 ...
    4. Regarding the last point :

    About the third part of the script and the 20 monitors you wanted to merge
    I tried to do it, but it somehow confuses the engine? One units routes and before the end the monitor some other is routing, since the first was on the wall, the other is also unrouted - again, things that happen 'in the meantime'. I will test it more though..

    Belo, do you know btw if there is some investigation on how much really the monitors, 'ifs' and 'ands' take processor time? For example what does it meant - 20 monitors more, is it visible for the player?
    Last edited by Macaras; July 07, 2023 at 03:02 PM.

  12. #12

    Default Re: Siege Defending Script

    Also you can use event counters to reuse bits of codes without duplicating it manually:
    Code:
    ; this monitor is used to call reusable snippets of codes, of pseudo-functions
    monitor_event EventCounter TrueCondition
    	; pseudo-function : unset army 2 morale
    	if I_EventCounter unsetMoraleArmy2 == 1
    		if I_CompareCounter player_unit_count > 0
    			unit_unset_morale a2u1
    			if I_CompareCounter player_unit_count > 1
    				unit_unset_morale a2u2
    				if I_CompareCounter player_unit_count > 2
    					unit_unset_morale a2u3
    					if I_CompareCounter player_unit_count > 3
    						unit_unset_morale a2u4
    						if I_CompareCounter player_unit_count > 4
    							unit_unset_morale a2u5
    							if I_CompareCounter player_unit_count > 5
    								unit_unset_morale a2u6
    								if I_CompareCounter player_unit_count > 6
    									unit_unset_morale a2u7
    									if I_CompareCounter player_unit_count > 7
    										unit_unset_morale a2u8
    										if I_CompareCounter player_unit_count > 8
    											unit_unset_morale a2u9
    											if I_CompareCounter player_unit_count > 9
    												unit_unset_morale a2u10
    												if I_CompareCounter player_unit_count > 10
    													unit_unset_morale a2u11
    													if I_CompareCounter player_unit_count > 11
    														unit_unset_morale a2u12
    														if I_CompareCounter player_unit_count > 12
    															unit_unset_morale a2u13
    															if I_CompareCounter player_unit_count > 13
    																unit_unset_morale a2u14
    																if I_CompareCounter player_unit_count > 14
    																	unit_unset_morale a2u15
    																	if I_CompareCounter player_unit_count > 15
    																		unit_unset_morale a2u16
    																		if I_CompareCounter player_unit_count > 16
    																			unit_unset_morale a2u17
    																			if I_CompareCounter player_unit_count > 17
    																				unit_unset_morale a2u18
    																				if I_CompareCounter player_unit_count > 18
    																					unit_unset_morale a2u19
    																					if I_CompareCounter player_unit_count > 19
    																						unit_unset_morale a2u20
    																					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
    					end_if
    				end_if
    			end_if
    		end_if
    	; needs to flip back the counter to 0 so pseudo-function can be called again
    	set_event_counter unsetMoraleArmy2 0
    	; pseudo-function: reset counters
    	; use it at start and end of your script --- Belo
    	if I_EventCounter siegeScriptCleanCounters == 1
    		set_counter siege_script_end 0
    		set_counter sally_siege_fix 0 
    		
    		set_counter defence_east 0
    		set_counter defence_west 0
    		set_counter defence_south 0
    		set_counter defence_north 0
    		
    		set_counter a2u1_on_walls 0 
    		set_counter a2u2_on_walls 0 
    		set_counter a2u3_on_walls 0 
    		set_counter a2u4_on_walls 0
    		set_counter a2u5_on_walls 0
    		set_counter a2u6_on_walls 0
    		set_counter a2u7_on_walls 0
    		set_counter a2u8_on_walls 0
    		set_counter a2u9_on_walls 0
    		set_counter a2u10_on_walls 0
    		set_counter a2u11_on_walls 0
    		set_counter a2u12_on_walls 0
    		set_counter a2u13_on_walls 0
    		set_counter a2u14_on_walls 0
    		set_counter a2u15_on_walls 0
    		set_counter a2u16_on_walls 0
    		set_counter a2u17_on_walls 0
    		set_counter a2u18_on_walls 0
    		set_counter a2u19_on_walls 0
    		set_counter a2u20_on_walls 0
    		
    		set_counter a2u1_routed 0
    		set_counter a2u2_routed 0 
    		set_counter a2u3_routed 0
    		set_counter a2u4_routed 0
    		set_counter a2u5_routed 0
    		set_counter a2u6_routed 0
    		set_counter a2u7_routed 0
    		set_counter a2u8_routed 0
    		set_counter a2u9_routed 0
    		set_counter a2u10_routed 0
    		set_counter a2u11_routed 0
    		set_counter a2u12_routed 0
    		set_counter a2u13_routed 0
    		set_counter a2u14_routed 0
    		set_counter a2u15_routed 0
    		set_counter a2u16_routed 0
    		set_counter a2u17_routed 0
    		set_counter a2u18_routed 0
    		set_counter a2u19_routed 0
    		set_counter a2u20_routed 0
    		
    		set_counter a2u1_start_distance 0
    		set_counter a2u2_start_distance 0
    		set_counter a2u3_start_distance 0
    		set_counter a2u4_start_distance 0
    		set_counter a2u5_start_distance 0
    		set_counter a2u6_start_distance 0
    		set_counter a2u7_start_distance 0
    		set_counter a2u8_start_distance 0
    		set_counter a2u9_start_distance 0
    		set_counter a2u10_start_distance 0
    		set_counter a2u11_start_distance 0
    		set_counter a2u12_start_distance 0
    		set_counter a2u13_start_distance 0
    		set_counter a2u14_start_distance 0
    		set_counter a2u15_start_distance 0
    		set_counter a2u16_start_distance 0
    		set_counter a2u17_start_distance 0
    		set_counter a2u18_start_distance 0
    		set_counter a2u19_start_distance 0
    		set_counter a2u20_start_distance 0
    		log -siege_script- siege_fix counters cleaned
    		set_event_counter siegeScriptCleanCounters 0
    	end_if
    end_monitor
    
    ; --- 3 Monitors to check when to finish the script
    
    monitor_event BattleGatesAttackedByEnemyEngine TrueCondition
    and I_BattleIsSiegeBattle
    and ! I_BattlePlayerArmyIsAttacker
    and I_CompareCounter sally_siege_fix = 1
    and I_CompareCounter siege_script_end = 0
    	set_counter siege_script_end 1
    	; set event counter to 1 to call pseudo-function
    	set_event_counter unsetMoraleArmy2 1
    	log -siege_script- all units morale released - gate attacked
    end_monitor
    
    ; Walls captured triggers with both sides capturing them.
    monitor_event BattleWallsCaptured TrueCondition
    and I_BattleIsSiegeBattle
    and ! I_BattlePlayerArmyIsAttacker
    and I_CompareCounter sally_siege_fix = 1
    and I_CompareCounter siege_script_end = 1
    	set_counter siege_script_end 1
    	; set event counter to 1 to call pseudo-function
    	set_event_counter unsetMoraleArmy2 1
    	log -siege_script- all units morale released - walls captured
    end_monitor
    
    ;;;; Trigger when siege engine docks the wall, wait because it takes a while for the unit to climb the ladder --------------
    
    monitor_event BattleSiegeEngineDocksWall TrueCondition
    and I_CompareCounter sally_siege_fix = 1
    and I_BattleIsSiegeBattle
    and ! I_BattlePlayerArmyIsAttacker
    	battle_wait 40
    	log -siege_script- Enemy_on_Walls =1 BattleSiegeEngineDocksWall set_counter siege_script_end 1
    	set_counter siege_script_end 1
    	; set event counter to 1 to call pseudo-function
    	set_event_counter unsetMoraleArmy2 1
    	log -siege_script- all units morale released - engine docks wall
    end_monitor
    
    ;;;; Trigger when walls are breached by an engine  --------------
    
    monitor_event BattleWallsBreachedByEngine TrueCondition
    and I_BattleIsSiegeBattle
    and ! I_BattlePlayerArmyIsAttacker
    and I_CompareCounter sally_siege_fix = 1
    and I_CompareCounter siege_script_end = 0
    	log -siege_script- BattleWallsBreachedByEngine set_counter siege_script_end 1
    	set_counter siege_script_end 1
    	; set event counter to 1 to call pseudo-function
    	set_event_counter unsetMoraleArmy2 1
    	log -siege_script- all units morale released - engine docks wall
    end_monitor
    
    ; ------ Two special conditions for the fort level 0
    monitor_event BattlePlayerUnitRouts TrueCondition
    and I_CompareCounter sally_siege_fix = 1
    and I_CompareCounter siege_script_end = 0
    and I_BattleSettlementFortificationLevel = 0
    	battle_wait 25
    	set_counter siege_script_end 1
    	log -siege_script- Unit Unrouts, fort level 0, the siege_fix_script finished
    	; set event counter to 1 to call pseudo-function
    	set_event_counter unsetMoraleArmy2 1
    end_monitor
    
    monitor_event BattlePlayerUnitEngaged TrueCondition
    and I_BattleIsSiegeBattle
    and ! I_BattlePlayerArmyIsAttacker
    and BattleIsMeleeAttack
    and I_CompareCounter sally_siege_fix = 1
    and I_CompareCounter siege_script_end = 0
    and I_BattleSettlementFortificationLevel = 0
    	log -siege_script- BattlePlayerUnitEngaged, fort level 0, the siege_fix_script will finish in 25
    	battle_wait 25
    	set_counter siege_script_end 1
    ; set event counter to 1 to call pseudo-function
    	set_event_counter unsetMoraleArmy2 1
    end_monitor
    Belovèse's Toolbox: export text files to spreadsheet, detailed unit stats
    Stainless Steel Historical Improvement Project (SSHIP) team member.
    Mini-mods: diplomacy and relation/reputation - detailled unit stats

  13. #13

    Default Re: Siege Defending Script

    Quote Originally Posted by Macaras View Post
    Thank you for looking into it! I have some comments and questions though:

    1.
    Just wanted to make sure the other monitors will never trigger in different situations than player defending the siege. I set the counter sally_siege_fix = 0 to 0 when the script is finishing, and I was not sure about timing, sometimes things happen 'in the meantime'. Does 'and' parts also consume more processor timing ?
    I don't think "and" are that expensive (even if small things can add up fast), it is more about code readability and easy of refactoring: if you decide to change the conditions a bit, you'll have to adjust them in 5 places instead of one. So more potential mistakes.

    2.
    True, I will change it maybe as the las thing, will it really give me much time saved? I was thinking, if its 10 units, it gives me 10 'if' saved, is it worth to nest it?
    Again small things can add up, but I have no first-hand data on the time it takes really.

    3. But this way of coding (below) will give me double number of 'if' ?
    Just one "if" more, but this is again more about readability and ease of reworking the code if needed. In this case one single "if" is a worthy sacrifice to me

    4. Regarding the last point :



    I tried to do it, but it somehow confuses the engine? One units routes and before the end the monitor some other is routing, since the first was on the wall, the other is also unrouted - again, things that happen 'in the meantime'. I will test it more though..

    Belo, do you know btw if there is some investigation on how much really the monitors, 'ifs' and 'ands' take processor time? For example what does it meant - 20 monitors more, is it visible for the player?
    here is a discussion about monitors and ifs https://www.twcenter.net/forums/show...faction_emerge

    about the 20 monitor merge: if it doesn't work, then it doesn't work I'll dig a bit more on the conditions you use.
    Belovèse's Toolbox: export text files to spreadsheet, detailed unit stats
    Stainless Steel Historical Improvement Project (SSHIP) team member.
    Mini-mods: diplomacy and relation/reputation - detailled unit stats

  14. #14

    Default Re: Siege Defending Script

    Thanks, I have to do some homework and learn some of this stuff!

  15. #15

    Default Re: Siege Defending Script

    Hi guys, I made a new version yesterday, fixed a little bug that prevented the script to even start on other installations then mine.
    I tested it and I implemented the script in Titanium and SS6.4 (both have Germanicus BAI) just in the way as is described in the first post, and it works.
    Just to want to invite again whoever wants to play siege defences without the opportunity to sally out and stop the siege engines to try it. I think it's much more fun now and the exploit is not possible !!
    Last edited by Macaras; July 15, 2023 at 06:46 PM.

  16. #16

    Default Re: Siege Defending Script

    But is there any easy way to replace all that script (g5 bai) after copying all the text of your new script? I do it from my notepad but since the script is so long I ask if there is any shortcut... as soon as you explain it to me I will replace it
    THE MORE YOU SWEAT NOW,
    THE LESS YOU BLEED IN BATTLE!!!



    Sign the petition to remove hardcoded limits for M2TW

  17. #17

    Default Re: Siege Defending Script

    Quote Originally Posted by j.a.luna View Post
    But is there any easy way to replace all that script (g5 bai) after copying all the text of your new script? I do it from my notepad but since the script is so long I ask if there is any shortcut... as soon as you explain it to me I will replace it
    Ok, J.a.luna:

    1. Select all from my file and 'copy'
    2. In campaign_script just left click in the beginning of BAI and hold shift, scroll down to the end and left-click holding shift. This will select all that part and then 'paste'.

    I am not sure if its the explanation you asked for.. I know it means scrolling down some thousands of lines. The problem is that I don't know which version you have, if you send me the campaign_script you have I can do it for you. You can also try to download the same campaign_script from here - that will contain this script already. Try to just replace your file with this one - if there are no ctd's you should be all set.

  18. #18

    Default Re: Siege Defending Script

    Quote Originally Posted by Macaras View Post
    Ok, J.a.luna:

    1. Select all from my file and 'copy'
    2. In campaign_script just left click in the beginning of BAI and hold shift, scroll down to the end and left-click holding shift. This will select all that part and then 'paste'.

    I am not sure if its the explanation you asked for.. I know it means scrolling down some thousands of lines. The problem is that I don't know which version you have, if you send me the campaign_script you have I can do it for you. You can also try to download the same campaign_script from here - that will contain this script already. Try to just replace your file with this one - if there are no ctd's you should be all set.
    Perfect Macaras i will download your file and paste in my files, it is faster, thanks!
    THE MORE YOU SWEAT NOW,
    THE LESS YOU BLEED IN BATTLE!!!



    Sign the petition to remove hardcoded limits for M2TW

  19. #19

    Default Re: Siege Defending Script

    Macaras your script It doesn't work as it should and I downloaded and overwrote your file... here a save with one epic battle against HRE, tell me if it go well please, but for me any unit routing when they sally out walls...

    here is my save


    2.rar
    THE MORE YOU SWEAT NOW,
    THE LESS YOU BLEED IN BATTLE!!!



    Sign the petition to remove hardcoded limits for M2TW

  20. #20

    Default Re: Siege Defending Script

    I just tried your save and indeed the script doesn't start. It seems though that you have a different campaign_script file then mine..
    Can you upload your file exactly from this location ...\Medieval II Total War\mods\SSHIP_098\data\world\maps\campaign\imperial_campaign\campaign_script.txt ?
    When you downloaded the file did you overwrite exactly in this location ?
    Or maybe what happened is that you continue the same campaign - so it always uses the old version of the script..

    If you start a new campaign with Rum and allow Byzantines to siege your cities? That happens in few first turns, you can see there if the script works..
    Last edited by Macaras; July 20, 2023 at 01:40 PM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •