How to automatically garrison liberated prisoners after a siege ? [code]

Users who are viewing this thread


Hello all,

I would like to implement a small feature in my mod : automatically garrison the prisoners of a taken castle (by the player) in the garrison. The idea would be to make that after the screen which shows the prisoners taken in the enemy troop and the prisoners freed in the castle regarding the player's party (troops and prisoners) = all the troops not included by the player in his army would be included in the castle garrison after this screen.

I tried some code variation (module system) but never managed to do this (the prisoners always vanish in thin air between this screen and the return to the worldmap). Is that possible, and are there any piece of code I should use to do it ?
This feature would be really useful as my mod put a large number of castle and towns.

If anybody can help, thank you !
@Douw if the party really gets wiped after the window closes, then the easiest method would be to just intervene right BEFORE the prisoner window opens (it's gonna be some kind of after-battle menu).
In that menu hook into the consequence block of the "Continue..." button, and just make a copy of player party, then make a copy of party with defeated troops, then set some kind of switch, that there is work to do. (e.g. "$check_for_troops_to_garrison" and assign 1 to it)
Then after you take prisoners and close the window, you will end up either in menu or on the world map.
For world map, you can catch getting there with ti_on_switch_to_map simple trigger.
For menu, just enter the appropriate menu.
And there do:
if $check_for_troops_to_garrison is 1, then:
compare your copy of player party with actual player party, note which troops were added to it and which were removed.
Then compare that result with your copy of defeated troops party. The changes are zero-sum, so comparing 2 "before" parties with 1 "after" party will always allow you to recreate the other "after" party. Create it, and then just add it as garrison to the town.
And don't forget to set the $check_for_troops_to_garrison back to zero!
Last edited:
As to how to compare parties, here's how I'd do it:
1. Make a party that is a sum of parties "before". Let's call it a sum-party.
2. Loop through player's current party's stacks. For each stack:
2.1. check troop ID
2.2. check number of ":wounded"
2.3. remove this number from sum-party with party_remove_members_wounded_first
2.4. check number of ":troops" in stack, val_sub ":troops", ":wounded"
2.5 remove these troops from sum-party with party_remove_members
3. Repeat same process for prisoners, except you don't even have to check wounded (always 0).
4. Now whatever's left in sum-party is identical to the temp-party that you wanted. Add all troops from sum-party to garrison of $current_town
thank you for these indications ; (i have just seen your messages right now) , i'll try to do something about this !
Top Bottom