Source code of Restoration

rubik

Squire
Best answers
0
About restoration: defeated faction can be restored once a lord of this faction get a town or castle after he switch to other factions. All lords of this faction include the king will come back, the defeated faction is restored.

Source code:

Paste the following into module_simple_triggers.py:
  # restoration begin
  # Note: make sure there is a comma in the entry behind this one
 
(24,
    [
      (try_for_range,
":cur_troop", kingdom_heroes_begin, kingdom_heroes_end),
        (troop_slot_eq,
":cur_troop", slot_troop_occupation, slto_kingdom_hero),
        (troop_get_slot,
":eek:riginal_faction", ":cur_troop", slot_troop_original_faction),
        (neg|faction_slot_eq,
":eek:riginal_faction", slot_faction_state, sfs_active),
        (store_troop_faction,
":faction_no", ":cur_troop"),
        (neq,
":faction_no", ":eek:riginal_faction"),
       
        (assign,
":num_walled_centers", 0),
        (try_for_range,
":walled_center", walled_centers_begin, walled_centers_end),
          (party_slot_eq,
":walled_center", slot_town_lord, ":cur_troop"),
          (val_add,
":num_walled_centers", 1),
        (try_end),
        (gt,
":num_walled_centers", 0), ## has a walled center
       
       
(store_sub, ":eek:riginal_king", ":eek:riginal_faction", fac_kingdom_1),
        (val_add,
":eek:riginal_king", "trp_kingdom_1_lord"),
        (faction_set_slot,
":eek:riginal_faction", slot_faction_leader, ":eek:riginal_king"),
       
        (call_script,
"script_change_troop_faction", ":cur_troop", ":eek:riginal_faction"),
        (try_for_range,
":cur_troop_2", kingdom_heroes_begin, kingdom_heroes_end),
          (troop_slot_eq,
":cur_troop_2", slot_troop_occupation, slto_kingdom_hero),
          (neg|is_between,
":cur_troop_2", pretenders_begin, pretenders_end),
          (neq,
":cur_troop_2", ":cur_troop"),
          (troop_get_slot,
":eek:riginal_faction_2", ":cur_troop_2", slot_troop_original_faction),
          (store_troop_faction,
":faction_no_2", ":cur_troop_2"),
          (eq,
":eek:riginal_faction_2", ":eek:riginal_faction"),
          (neq,
":faction_no_2", ":eek:riginal_faction"),
          (troop_set_slot,
":cur_troop_2", slot_troop_change_to_faction, ":eek:riginal_faction"),
        (try_end),
        (call_script,
"script_add_notification_menu", "mnu_notification_kingdom_restoration", ":cur_troop", ":faction_no"),
      (try_end),
    ]),
 
## restoration end
The following into module_game_menus.py:
  # restoration begin
 
(
   
"notification_kingdom_restoration",0,
   
"Restoration^^{s11} of {s13} gets a fief from {s12}, {s13} is restored! All lords of {s13} include {s14} will come back to {s13} later.",
   
"none",
    [
      (troop_get_slot,
":eek:riginal_faction", "$g_notification_menu_var1", slot_troop_original_faction),
      (faction_get_slot,
":eek:riginal_king", ":eek:riginal_faction", slot_faction_leader),
      (str_store_troop_name, s11,
"$g_notification_menu_var1"),
      (str_store_faction_name, s12,
"$g_notification_menu_var2"),
      (str_store_faction_name, s13,
":eek:riginal_faction"),
      (str_store_troop_name, s14,
":eek:riginal_king"),
     
      (set_fixed_point_multiplier,
100),
      (position_set_x, pos0,
65),
      (position_set_y, pos0,
30),
      (position_set_z, pos0,
170),
      (try_begin),
        (is_between,
":eek:riginal_faction", "fac_kingdom_1", kingdoms_end), #Excluding player kingdom
       
(set_game_menu_tableau_mesh, "tableau_faction_note_mesh_for_menu", ":eek:riginal_faction", pos0),
      (else_try),
        (set_game_menu_tableau_mesh,
"tableau_faction_note_mesh_banner", ":eek:riginal_faction", pos0),
      (try_end),
      ],
    [
      (
"continue",[],"Continue...",
        [
          (troop_get_slot,
":eek:riginal_faction", "$g_notification_menu_var1", slot_troop_original_faction),
         
## start peace
         
(try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
            (neq,
":cur_kingdom", ":eek:riginal_faction"),
            (neq,
":cur_kingdom", "$g_notification_menu_var2"),
            (call_script,
"script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":eek:riginal_faction", 0),
          (try_end),
         
## start war
         
(call_script, "script_diplomacy_start_war_between_kingdoms", "$g_notification_menu_var2", ":eek:riginal_faction", 1),
          (call_script,
"script_update_all_notes"),
          (change_screen_return),
        ]),
    ]
  ),
 
## restoration end
At last, there is a BUG in the Module System of native. We need to fix it, otherwise restorations will not work normally.

It's here in module_simple_triggers.py.
        .......................
        #checking if the party is away from his original faction parties
        (assign, ":end_cond", kingdom_heroes_end),
        (try_for_range, ":enemy_troop_no", kingdom_heroes_begin, ":end_cond"),
          ## bugfix - must not include himself
        (neq, ":enemy_troop_no", ":troop_no"),
        ## bugfix
          (troop_get_slot, ":enemy_party_no", ":enemy_troop_no", slot_troop_leaded_party),
          (gt, ":enemy_party_no", 0),
          (store_faction_of_party, ":enemy_faction_no", ":enemy_party_no"),
          (eq, ":enemy_faction_no", ":faction_no"),
          (store_distance_to_party_from_party, ":dist", ":party_no", ":enemy_party_no"),
          (lt, ":dist", 4),
          (assign, ":end_cond", 0),
        (try_end),
        .......................

Screenshot:
 

Lumos

Section Moderator
M&BWBWF&SNWVC
Best answers
0
Awesome! Just what I needed! except the fix for the colors, though...
 
Top