Leonion

Advanced Soldier Management in Exchange Screens

Feb 19th, 2018
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   ("initialize_exchange_screen_extensions",
  2.     [
  3.     (store_script_param, ":troop_id", 1),
  4.  
  5.     (try_begin), #MASS PRISONER TRANSFER AFTER BATTLE
  6.         (key_is_down, key_left_control), (key_is_down, key_a),
  7.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 10),
  8.         (party_get_num_prisoner_stacks, ":num_prisoner_stacks","p_temp_party"),
  9.         (assign, ":stop_stack", -1),
  10.         (assign, ":stop_no", -1),
  11.         (try_for_range, ":stack_no", 0, ":num_prisoner_stacks"),
  12.             (eq, ":stop_stack", -1),
  13.             (party_get_free_prisoners_capacity, ":player_prisoner_capacity", "p_main_party"),
  14.             (party_prisoner_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  15.             (party_prisoner_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  16.             (try_begin),
  17.                 (ge, ":player_prisoner_capacity", ":stack_size"),
  18.                 (party_add_prisoners, "p_main_party", ":stack_troop", ":stack_size"),
  19.             (else_try),
  20.                 (party_add_prisoners, "p_main_party", ":stack_troop", ":player_prisoner_capacity"),
  21.                 (assign, ":stop_stack", ":stack_no"),
  22.                 (assign, ":stop_no", ":player_prisoner_capacity"),
  23.             (try_end),
  24.         (try_end),
  25.         (try_begin),
  26.             (neq, ":stop_stack", -1),
  27.             (store_add, ":stop_stack_plus_one", ":stop_stack", 1),
  28.         (else_try),
  29.             (assign, ":stop_stack_plus_one", ":num_prisoner_stacks"),
  30.         (try_end),
  31.         (try_for_range_backwards, ":stack_no", 0, ":stop_stack_plus_one"),
  32.             (party_prisoner_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  33.             (party_prisoner_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  34.             (try_begin),
  35.                 (neq, ":stop_no", -1),
  36.                 (eq, ":stack_no", ":stop_stack"),
  37.                 (party_remove_prisoners, "p_temp_party", ":stack_troop", ":stop_no"),
  38.             (else_try),
  39.                 (party_remove_prisoners, "p_temp_party", ":stack_troop", ":stack_size"),
  40.             (try_end),
  41.         (try_end),
  42.     (try_end),
  43.     #++++++++++++++++++++++++++++++++++++++++++++++++ MASS TRANSFER OF RESCUED PRISONERS AFTER BATTLE
  44.     (try_begin),
  45.         (key_is_down, key_left_control), (key_is_down, key_s),
  46.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 10),
  47.         (party_get_num_companion_stacks, ":num_companion_stacks","p_temp_party"),
  48.         (assign, ":stop_stack", -1),
  49.         (assign, ":stop_no", -1),
  50.         (try_for_range, ":stack_no", 0, ":num_companion_stacks"),
  51.             (eq, ":stop_stack", -1),
  52.             (party_get_free_companions_capacity, ":player_companion_capacity", "p_main_party"),
  53.             (party_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  54.             (party_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  55.             (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":stack_no"),
  56.             (try_begin),
  57.                 (ge, ":player_companion_capacity", ":stack_size"),
  58.                 (party_add_members, "p_main_party", ":stack_troop", ":stack_size"),
  59.                 (party_wound_members, "p_main_party", ":stack_troop", ":stack_no_wounded"),
  60.             (else_try),
  61.                 (party_add_members, "p_main_party", ":stack_troop", ":player_companion_capacity"),
  62.                 (assign, ":stop_stack", ":stack_no"),
  63.                 (assign, ":stop_no", ":player_companion_capacity"),
  64.                 (val_add, ":stack_no_wounded", ":player_companion_capacity"),
  65.                 (store_sub, ":excess", ":stack_no_wounded", ":stack_size"), #party_remove_members first removes healthy members, so we need to find whether any sick members get transfered
  66.                 (val_max, ":excess", 0),
  67.                 (party_wound_members, "p_main_party", ":stack_troop", ":excess"),
  68.             (try_end),
  69.         (try_end),
  70.         (try_begin),
  71.             (neq, ":stop_stack", -1),
  72.             (store_add, ":stop_stack_plus_one", ":stop_stack", 1),
  73.         (else_try),
  74.             (assign, ":stop_stack_plus_one", ":num_companion_stacks"),
  75.         (try_end),
  76.         (try_for_range_backwards, ":stack_no", 0, ":stop_stack_plus_one"),
  77.             (party_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  78.             (party_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  79.             (try_begin),
  80.                 (neq, ":stop_no", -1),
  81.                 (eq, ":stack_no", ":stop_stack"),
  82.                 (party_remove_members, "p_temp_party", ":stack_troop", ":stop_no"),
  83.             (else_try),
  84.                 (party_remove_members, "p_temp_party", ":stack_troop", ":stack_size"),
  85.             (try_end),
  86.         (try_end),
  87.     (try_end),
  88.     #++++++++++++++++++++++++++++++++++++++++++++++++ SORTING GARRISONS
  89.     (try_begin), #ARROW UP
  90.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 12),
  91.         (troop_slot_eq, "trp_globals_troop", slot_last_requested_troop, ":troop_id"),
  92.         (key_is_down, key_up),
  93.         (party_clear, "p_temp_party"),
  94.         (call_script, "script_party_add_party_companions", "p_temp_party", "$current_town"),
  95.         (party_get_num_companion_stacks, ":num_stacks","$current_town"),
  96.         (assign, ":key_stack", -1),
  97.         (try_for_range, ":stack_no", 0, ":num_stacks"),
  98.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  99.             (try_begin),
  100.                 (eq, ":stack_troop", ":troop_id"),
  101.                 (neq, ":stack_no", 0), #key_up can't be used with stack 0
  102.                 (assign, ":key_stack", ":stack_no"),
  103.             (try_end),
  104.         (try_end),
  105.         (neq, ":key_stack", -1),
  106.         (try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
  107.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  108.             (party_stack_get_size, ":stack_size","$current_town",":stack_no"),
  109.             (party_remove_members, "$current_town", ":stack_troop", ":stack_size"),
  110.         (try_end),
  111.         (store_sub, ":key_stack_minus_one", ":key_stack", 1),
  112.         (store_add, ":key_stack_plus_one", ":key_stack", 1),
  113.         (try_for_range, ":stack_no", 0, ":key_stack_minus_one"),
  114.             (party_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  115.             (party_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  116.             (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":stack_no"),
  117.             (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  118.             (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  119.         (try_end),
  120.         (party_stack_get_troop_id, ":stack_troop","p_temp_party",":key_stack"),
  121.         (party_stack_get_size, ":stack_size","p_temp_party",":key_stack"),
  122.         (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":key_stack"),
  123.         (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  124.         (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  125.         (assign, ":first_party_member_was_wounded", 0), #we're trying to understand if the first party member that got transferred by the player (action that launches the script) was wounded
  126.         (try_begin),
  127.             (ge, ":stack_no_wounded", 1),
  128.             (assign, ":first_party_member_was_wounded", 1),
  129.         (try_end),
  130.         (party_get_num_companion_stacks, ":num_stacks_in_main_party","p_main_party"),
  131.         (try_for_range, ":stack_in_main_party", 0, ":num_stacks_in_main_party"),
  132.             (party_stack_get_troop_id, ":stack_troop_in_main_party","p_main_party",":stack_in_main_party"),
  133.             (eq, ":stack_troop_in_main_party", ":troop_id"),
  134.             (party_stack_get_size, ":stack_size_in_main_party","p_main_party",":stack_in_main_party"),
  135.             (party_stack_get_num_wounded, ":stack_no_wounded_in_main_party","p_main_party",":stack_in_main_party"),
  136.             (try_begin),
  137.                 (eq, ":first_party_member_was_wounded", 1), #restoring the balance in main party
  138.                 (gt, ":stack_size_in_main_party", ":stack_no_wounded_in_main_party"),
  139.                 (store_sub, ":stack_size_in_main_party_minus_1" ,":stack_size_in_main_party", 1),
  140.                 (store_sub, ":stack_no_wounded_in_main_party_minus_2" ,":stack_no_wounded_in_main_party", 2),
  141.                 (party_remove_members, "p_main_party", ":troop_id", ":stack_size_in_main_party_minus_1"),
  142.                 (party_add_members, "p_main_party", ":troop_id", ":stack_size_in_main_party_minus_1"),
  143.                 (party_wound_members, "p_main_party", ":stack_troop_in_main_party", ":stack_no_wounded_in_main_party_minus_2"),
  144.             (else_try),
  145.                 (eq, ":stack_no_wounded_in_main_party", ":stack_size_in_main_party"), #the only case when we will remove a sick member, but add (unless it's corrected) a healthy one
  146.                 (assign, ":first_party_member_was_wounded", 1),
  147.             (try_end), 
  148.         (try_end),
  149.         (party_stack_get_troop_id, ":stack_troop","p_temp_party",":key_stack_minus_one"),
  150.         (party_stack_get_size, ":stack_size","p_temp_party",":key_stack_minus_one"),
  151.         (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":key_stack_minus_one"),
  152.         (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  153.         (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  154.         (try_for_range, ":stack_no", ":key_stack_plus_one", ":num_stacks"),
  155.             (party_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  156.             (party_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  157.             (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":stack_no"),
  158.             (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  159.             (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  160.         (try_end),
  161.         (party_remove_members, "p_main_party", ":troop_id", 1),
  162.         (party_add_members, "$current_town", ":troop_id", 1),
  163.         (try_begin),
  164.             (eq, ":first_party_member_was_wounded", 1), #restoring the balance in town
  165.             (party_wound_members, "$current_town", ":troop_id", 1),
  166.         (try_end),
  167.     (try_end),
  168.    
  169.     (try_begin), #ARROW DOWN
  170.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 12),
  171.         (troop_slot_eq, "trp_globals_troop", slot_last_requested_troop, ":troop_id"),
  172.         (key_is_down, key_down),
  173.         (party_clear, "p_temp_party"),
  174.         (call_script, "script_party_add_party_companions", "p_temp_party", "$current_town"),
  175.         (party_get_num_companion_stacks, ":num_stacks","$current_town"),
  176.         (store_sub, ":num_stacks_minus_one", ":num_stacks", 1),
  177.         (assign, ":key_stack", -1),
  178.         (try_for_range, ":stack_no", 0, ":num_stacks"),
  179.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  180.             (try_begin),
  181.                 (eq, ":stack_troop", ":troop_id"),
  182.                 (neq, ":stack_no", ":num_stacks_minus_one"), #key_down can't be used with last stack
  183.                 (assign, ":key_stack", ":stack_no"),
  184.             (try_end),
  185.         (try_end),
  186.         (neq, ":key_stack", -1),
  187.         (try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
  188.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  189.             (party_stack_get_size, ":stack_size","$current_town",":stack_no"),
  190.             (party_remove_members, "$current_town", ":stack_troop", ":stack_size"),
  191.         (try_end),
  192.         (store_add, ":key_stack_plus_one", ":key_stack", 1),
  193.         (store_add, ":key_stack_plus_two", ":key_stack", 2),
  194.         (try_for_range, ":stack_no", 0, ":key_stack"),
  195.             (party_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  196.             (party_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  197.             (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":stack_no"),
  198.             (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  199.             (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  200.         (try_end),
  201.         (party_stack_get_troop_id, ":stack_troop","p_temp_party",":key_stack_plus_one"),
  202.         (party_stack_get_size, ":stack_size","p_temp_party",":key_stack_plus_one"),
  203.         (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":key_stack_plus_one"),
  204.         (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  205.         (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  206.         (party_stack_get_troop_id, ":stack_troop","p_temp_party",":key_stack"),
  207.         (party_stack_get_size, ":stack_size","p_temp_party",":key_stack"),
  208.         (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":key_stack"),
  209.         (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  210.         (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  211.         (assign, ":first_party_member_was_wounded", 0), #we're trying to understand if the first party member that got transferred by the player (action that launches the script) was wounded
  212.         (try_begin),
  213.             (ge, ":stack_no_wounded", 1),
  214.             (assign, ":first_party_member_was_wounded", 1),
  215.         (try_end),
  216.         (party_get_num_companion_stacks, ":num_stacks_in_main_party","p_main_party"),
  217.         (try_for_range, ":stack_in_main_party", 0, ":num_stacks_in_main_party"),
  218.             (party_stack_get_troop_id, ":stack_troop_in_main_party","p_main_party",":stack_in_main_party"),
  219.             (eq, ":stack_troop_in_main_party", ":troop_id"),
  220.             (party_stack_get_size, ":stack_size_in_main_party","p_main_party",":stack_in_main_party"),
  221.             (party_stack_get_num_wounded, ":stack_no_wounded_in_main_party","p_main_party",":stack_in_main_party"),
  222.             (try_begin),
  223.                 (eq, ":first_party_member_was_wounded", 1), #restoring the balance in main party
  224.                 (gt, ":stack_size_in_main_party", ":stack_no_wounded_in_main_party"),
  225.                 (store_sub, ":stack_size_in_main_party_minus_1" ,":stack_size_in_main_party", 1),
  226.                 (store_sub, ":stack_no_wounded_in_main_party_minus_2" ,":stack_no_wounded_in_main_party", 2),
  227.                 (party_remove_members, "p_main_party", ":troop_id", ":stack_size_in_main_party_minus_1"),
  228.                 (party_add_members, "p_main_party", ":troop_id", ":stack_size_in_main_party_minus_1"),
  229.                 (party_wound_members, "p_main_party", ":stack_troop_in_main_party", ":stack_no_wounded_in_main_party_minus_2"),
  230.             (else_try),
  231.                 (eq, ":stack_no_wounded_in_main_party", ":stack_size_in_main_party"), #the only case when we will remove a sick member, but add (unless it's corrected) a healthy one
  232.                 (assign, ":first_party_member_was_wounded", 1),
  233.             (try_end), 
  234.         (try_end),
  235.         (try_for_range, ":stack_no", ":key_stack_plus_two", ":num_stacks"),
  236.             (party_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  237.             (party_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  238.             (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":stack_no"),
  239.             (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  240.             (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  241.         (try_end),
  242.         (party_remove_members, "p_main_party", ":troop_id", 1),
  243.         (party_add_members, "$current_town", ":troop_id", 1),
  244.         (try_begin),
  245.             (eq, ":first_party_member_was_wounded", 1),
  246.             (party_wound_members, "$current_town", ":troop_id", 1),
  247.         (try_end),
  248.     (try_end),
  249.    
  250.     (try_begin), #PAGE UP
  251.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 12),
  252.         (troop_slot_eq, "trp_globals_troop", slot_last_requested_troop, ":troop_id"),
  253.         (key_is_down, key_page_up),
  254.         (party_clear, "p_temp_party"),
  255.         (call_script, "script_party_add_party_companions", "p_temp_party", "$current_town"),
  256.         (party_get_num_companion_stacks, ":num_stacks","$current_town"),
  257.         (assign, ":key_stack", -1),
  258.         (try_for_range, ":stack_no", 0, ":num_stacks"),
  259.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  260.             (try_begin),
  261.                 (eq, ":stack_troop", ":troop_id"),
  262.                 (neq, ":stack_no", 0), #key_page_up can't be used with stack 0
  263.                 (assign, ":key_stack", ":stack_no"),
  264.             (try_end),
  265.         (try_end),
  266.         (neq, ":key_stack", -1),
  267.         (try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
  268.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  269.             (party_stack_get_size, ":stack_size","$current_town",":stack_no"),
  270.             (party_remove_members, "$current_town", ":stack_troop", ":stack_size"),
  271.         (try_end),
  272.         (party_stack_get_troop_id, ":stack_troop","p_temp_party",":key_stack"),
  273.         (party_stack_get_size, ":stack_size","p_temp_party",":key_stack"),
  274.         (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":key_stack"),
  275.         (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  276.         (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  277.         (assign, ":first_party_member_was_wounded", 0), #we're trying to understand if the first party member that got transferred by the player (action that launches the script) was wounded
  278.         (try_begin),
  279.             (ge, ":stack_no_wounded", 1),
  280.             (assign, ":first_party_member_was_wounded", 1),
  281.         (try_end),
  282.         (party_get_num_companion_stacks, ":num_stacks_in_main_party","p_main_party"),
  283.         (try_for_range, ":stack_in_main_party", 0, ":num_stacks_in_main_party"),
  284.             (party_stack_get_troop_id, ":stack_troop_in_main_party","p_main_party",":stack_in_main_party"),
  285.             (eq, ":stack_troop_in_main_party", ":troop_id"),
  286.             (party_stack_get_size, ":stack_size_in_main_party","p_main_party",":stack_in_main_party"),
  287.             (party_stack_get_num_wounded, ":stack_no_wounded_in_main_party","p_main_party",":stack_in_main_party"),
  288.             (try_begin),
  289.                 (eq, ":first_party_member_was_wounded", 1), #restoring the balance in main party
  290.                 (gt, ":stack_size_in_main_party", ":stack_no_wounded_in_main_party"),
  291.                 (store_sub, ":stack_size_in_main_party_minus_1" ,":stack_size_in_main_party", 1),
  292.                 (store_sub, ":stack_no_wounded_in_main_party_minus_2" ,":stack_no_wounded_in_main_party", 2),
  293.                 (party_remove_members, "p_main_party", ":troop_id", ":stack_size_in_main_party_minus_1"),
  294.                 (party_add_members, "p_main_party", ":troop_id", ":stack_size_in_main_party_minus_1"),
  295.                 (party_wound_members, "p_main_party", ":stack_troop_in_main_party", ":stack_no_wounded_in_main_party_minus_2"),
  296.             (else_try),
  297.                 (eq, ":stack_no_wounded_in_main_party", ":stack_size_in_main_party"), #the only case when we will remove a sick member, but add (unless it's corrected) a healthy one
  298.                 (assign, ":first_party_member_was_wounded", 1),
  299.             (try_end), 
  300.         (try_end),
  301.         (try_for_range, ":stack_no", 0, ":num_stacks"),
  302.             (neq, ":stack_no", ":key_stack"),
  303.             (party_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  304.             (party_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  305.             (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":stack_no"),
  306.             (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  307.             (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  308.         (try_end),
  309.         (party_remove_members, "p_main_party", ":troop_id", 1),
  310.         (party_add_members, "$current_town", ":troop_id", 1),
  311.         (try_begin),
  312.             (eq, ":first_party_member_was_wounded", 1),
  313.             (party_wound_members, "$current_town", ":troop_id", 1),
  314.         (try_end),
  315.     (try_end),
  316.    
  317.     (try_begin), #PAGE DOWN
  318.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 12),
  319.         (troop_slot_eq, "trp_globals_troop", slot_last_requested_troop, ":troop_id"),
  320.         (key_is_down, key_page_down),
  321.         (party_clear, "p_temp_party"),
  322.         (call_script, "script_party_add_party_companions", "p_temp_party", "$current_town"),
  323.         (party_get_num_companion_stacks, ":num_stacks","$current_town"),
  324.         (store_sub, ":num_stacks_minus_one", ":num_stacks", 1),
  325.         (assign, ":key_stack", -1),
  326.         (try_for_range, ":stack_no", 0, ":num_stacks"),
  327.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  328.             (try_begin),
  329.                 (eq, ":stack_troop", ":troop_id"),
  330.                 (neq, ":stack_no", ":num_stacks_minus_one"), #key_down can't be used with last stack
  331.                 (assign, ":key_stack", ":stack_no"),
  332.             (try_end),
  333.         (try_end),
  334.         (neq, ":key_stack", -1),
  335.         (try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
  336.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  337.             (party_stack_get_size, ":stack_size","$current_town",":stack_no"),
  338.             (party_remove_members, "$current_town", ":stack_troop", ":stack_size"),
  339.         (try_end),
  340.         (try_for_range, ":stack_no", 0, ":num_stacks"),
  341.             (neq, ":stack_no", ":key_stack"),
  342.             (party_stack_get_troop_id, ":stack_troop","p_temp_party",":stack_no"),
  343.             (party_stack_get_size, ":stack_size","p_temp_party",":stack_no"),
  344.             (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":stack_no"),
  345.             (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  346.             (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  347.         (try_end),
  348.         (party_stack_get_troop_id, ":stack_troop","p_temp_party",":key_stack"),
  349.         (party_stack_get_size, ":stack_size","p_temp_party",":key_stack"),
  350.         (party_stack_get_num_wounded, ":stack_no_wounded","p_temp_party",":key_stack"),
  351.         (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  352.         (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  353.         (assign, ":first_party_member_was_wounded", 0), #we're trying to understand if the first party member that got transferred by the player (action that launches the script) was wounded
  354.         (try_begin),
  355.             (ge, ":stack_no_wounded", 1),
  356.             (assign, ":first_party_member_was_wounded", 1),
  357.         (try_end),
  358.         (party_get_num_companion_stacks, ":num_stacks_in_main_party","p_main_party"),
  359.         (try_for_range, ":stack_in_main_party", 0, ":num_stacks_in_main_party"),
  360.             (party_stack_get_troop_id, ":stack_troop_in_main_party","p_main_party",":stack_in_main_party"),
  361.             (eq, ":stack_troop_in_main_party", ":troop_id"),
  362.             (party_stack_get_size, ":stack_size_in_main_party","p_main_party",":stack_in_main_party"),
  363.             (party_stack_get_num_wounded, ":stack_no_wounded_in_main_party","p_main_party",":stack_in_main_party"),
  364.             (try_begin),
  365.                 (eq, ":first_party_member_was_wounded", 1), #restoring the balance in main party
  366.                 (gt, ":stack_size_in_main_party", ":stack_no_wounded_in_main_party"),
  367.                 (store_sub, ":stack_size_in_main_party_minus_1" ,":stack_size_in_main_party", 1),
  368.                 (store_sub, ":stack_no_wounded_in_main_party_minus_2" ,":stack_no_wounded_in_main_party", 2),
  369.                 (party_remove_members, "p_main_party", ":troop_id", ":stack_size_in_main_party_minus_1"),
  370.                 (party_add_members, "p_main_party", ":troop_id", ":stack_size_in_main_party_minus_1"),
  371.                 (party_wound_members, "p_main_party", ":stack_troop_in_main_party", ":stack_no_wounded_in_main_party_minus_2"),
  372.             (else_try),
  373.                 (eq, ":stack_no_wounded_in_main_party", ":stack_size_in_main_party"), #the only case when we will remove a sick member, but add (unless it's corrected) a healthy one
  374.                 (assign, ":first_party_member_was_wounded", 1),
  375.             (try_end), 
  376.         (try_end),
  377.         (party_remove_members, "p_main_party", ":troop_id", 1),
  378.         (party_add_members, "$current_town", ":troop_id", 1),
  379.         (try_begin),
  380.             (eq, ":first_party_member_was_wounded", 1),
  381.             (party_wound_members, "$current_town", ":troop_id", 1),
  382.         (try_end),
  383.     (try_end),
  384.     #++++++++++++++++++++++++++++++++++++++++++++++++ MASSIVE TRANSFERS TO/FROM GARRISON
  385.     (try_begin), #TROOPS FROM GARRISON TO PLAYER'S PARTY
  386.         (key_is_down, key_right_control), (key_is_down, key_right),
  387.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 12),
  388.         (party_get_num_companion_stacks, ":num_companion_stacks","$current_town"),
  389.         (assign, ":stop_stack", -1),
  390.         (assign, ":stop_no", -1),
  391.         (try_for_range, ":stack_no", 0, ":num_companion_stacks"),
  392.             (eq, ":stop_stack", -1),
  393.             (party_get_free_companions_capacity, ":player_companion_capacity", "p_main_party"),
  394.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  395.             (party_stack_get_size, ":stack_size","$current_town",":stack_no"),
  396.             (party_stack_get_num_wounded, ":stack_no_wounded","$current_town",":stack_no"),
  397.             (try_begin),
  398.                 (ge, ":player_companion_capacity", ":stack_size"),
  399.                 (party_add_members, "p_main_party", ":stack_troop", ":stack_size"),
  400.                 (party_wound_members, "p_main_party", ":stack_troop", ":stack_no_wounded"),
  401.             (else_try),
  402.                 (party_add_members, "p_main_party", ":stack_troop", ":player_companion_capacity"),
  403.                 (assign, ":stop_stack", ":stack_no"),
  404.                 (assign, ":stop_no", ":player_companion_capacity"),
  405.                 (val_add, ":stack_no_wounded", ":player_companion_capacity"),
  406.                 (store_sub, ":excess", ":stack_no_wounded", ":stack_size"), #party_remove_members first removes healthy members, so we need to find whether any sick members get transfered
  407.                 (val_max, ":excess", 0),
  408.                 (party_wound_members, "p_main_party", ":stack_troop", ":excess"),
  409.             (try_end),
  410.         (try_end),
  411.         (try_begin),
  412.             (neq, ":stop_stack", -1),
  413.             (store_add, ":stop_stack_plus_one", ":stop_stack", 1),
  414.         (else_try),
  415.             (assign, ":stop_stack_plus_one", ":num_companion_stacks"),
  416.         (try_end),
  417.         (try_for_range_backwards, ":stack_no", 0, ":stop_stack_plus_one"),
  418.             (party_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  419.             (party_stack_get_size, ":stack_size","$current_town",":stack_no"),
  420.             (try_begin),
  421.                 (neq, ":stop_no", -1),
  422.                 (eq, ":stack_no", ":stop_stack"),
  423.                 (party_remove_members, "$current_town", ":stack_troop", ":stop_no"),
  424.             (else_try),
  425.                 (party_remove_members, "$current_town", ":stack_troop", ":stack_size"),
  426.             (try_end),
  427.         (try_end),
  428.     (try_end),
  429.    
  430.     (try_begin), #TROOPS FROM PLAYER'S PARTY TO GARRISON
  431.         (key_is_down, key_right_control), (key_is_down, key_left),
  432.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 12),
  433.         (party_get_num_companion_stacks, ":num_companion_stacks","p_main_party"),
  434.         (try_for_range, ":stack_no", 0, ":num_companion_stacks"),
  435.             (party_stack_get_troop_id, ":stack_troop","p_main_party",":stack_no"),
  436.             (neg|troop_is_hero, ":stack_troop"),
  437.             (party_stack_get_size, ":stack_size","p_main_party",":stack_no"),
  438.             (party_stack_get_num_wounded, ":stack_no_wounded","p_main_party",":stack_no"),
  439.             (party_add_members, "$current_town", ":stack_troop", ":stack_size"),
  440.             (party_wound_members, "$current_town", ":stack_troop", ":stack_no_wounded"),
  441.         (try_end),
  442.         (try_for_range_backwards, ":stack_no", 0, ":num_companion_stacks"),
  443.             (party_stack_get_troop_id, ":stack_troop","p_main_party",":stack_no"),
  444.             (neg|troop_is_hero, ":stack_troop"),
  445.             (party_stack_get_size, ":stack_size","p_main_party",":stack_no"),
  446.             (party_remove_members, "p_main_party", ":stack_troop", ":stack_size"),
  447.         (try_end),
  448.     (try_end),
  449.    
  450.     (try_begin), #PRISONERS FROM GARRISON TO PLAYER'S PARTY
  451.         (key_is_down, key_left_control), (key_is_down, key_a),
  452.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 12),
  453.         (party_get_num_prisoner_stacks, ":num_prisoner_stacks","$current_town"),
  454.         (assign, ":stop_stack", -1),
  455.         (assign, ":stop_no", -1),
  456.         (try_for_range, ":stack_no", 0, ":num_prisoner_stacks"),
  457.             (eq, ":stop_stack", -1),
  458.             (party_get_free_prisoners_capacity, ":player_prisoner_capacity", "p_main_party"),
  459.             (party_prisoner_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  460.             (neg|troop_is_hero, ":stack_troop"),
  461.             (party_prisoner_stack_get_size, ":stack_size","$current_town",":stack_no"),
  462.             (try_begin),
  463.                 (ge, ":player_prisoner_capacity", ":stack_size"),
  464.                 (party_add_prisoners, "p_main_party", ":stack_troop", ":stack_size"),
  465.             (else_try),
  466.                 (party_add_prisoners, "p_main_party", ":stack_troop", ":player_prisoner_capacity"),
  467.                 (assign, ":stop_stack", ":stack_no"),
  468.                 (assign, ":stop_no", ":player_prisoner_capacity"),
  469.             (try_end),
  470.         (try_end),
  471.         (try_begin),
  472.             (neq, ":stop_stack", -1),
  473.             (store_add, ":stop_stack_plus_one", ":stop_stack", 1),
  474.         (else_try),
  475.             (assign, ":stop_stack_plus_one", ":num_prisoner_stacks"),
  476.         (try_end),
  477.         (try_for_range_backwards, ":stack_no", 0, ":stop_stack_plus_one"),
  478.             (party_prisoner_stack_get_troop_id, ":stack_troop","$current_town",":stack_no"),
  479.             (neg|troop_is_hero, ":stack_troop"),
  480.             (party_prisoner_stack_get_size, ":stack_size","$current_town",":stack_no"),
  481.             (try_begin),
  482.                 (neq, ":stop_no", -1),
  483.                 (eq, ":stack_no", ":stop_stack"),
  484.                 (party_remove_prisoners, "$current_town", ":stack_troop", ":stop_no"),
  485.             (else_try),
  486.                 (party_remove_prisoners, "$current_town", ":stack_troop", ":stack_size"),
  487.             (try_end),
  488.         (try_end),
  489.     (try_end),
  490.    
  491.     (try_begin), #PRISONERS FROM PLAYER'S PARTY TO GARRISON
  492.         (key_is_down, key_left_control), (key_is_down, key_d),
  493.         (troop_slot_eq, "trp_globals_troop", slot_adv_transfer_mode, 12),
  494.         (party_get_num_prisoner_stacks, ":num_prisoner_stacks","p_main_party"),
  495.         (try_for_range, ":stack_no", 0, ":num_prisoner_stacks"),
  496.             (party_prisoner_stack_get_troop_id, ":stack_troop","p_main_party",":stack_no"),
  497.             (neg|troop_is_hero, ":stack_troop"),
  498.             (party_prisoner_stack_get_size, ":stack_size","p_main_party",":stack_no"),
  499.             (party_add_prisoners, "$current_town", ":stack_troop", ":stack_size"),
  500.         (try_end),
  501.         (try_for_range_backwards, ":stack_no", 0, ":num_prisoner_stacks"),
  502.             (party_prisoner_stack_get_troop_id, ":stack_troop","p_main_party",":stack_no"),
  503.             (neg|troop_is_hero, ":stack_troop"),
  504.             (party_prisoner_stack_get_size, ":stack_size","p_main_party",":stack_no"),
  505.             (party_remove_prisoners, "p_main_party", ":stack_troop", ":stack_size"),
  506.         (try_end),
  507.     (try_end),
  508.     ]
  509.   ),
RAW Paste Data