Author Topic: Source code of Restoration  (Read 4658 times)

0 Members and 1 Guest are viewing this topic.

rubik

  • Squire
  • *
    • View Profile
  • Faction: Vaegir
Source code of Restoration
« on: July 02, 2009, 08:46:20 AM »
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:
Quote
  # 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,
":original_faction", ":cur_troop", slot_troop_original_faction),
        (neg|faction_slot_eq,
":original_faction", slot_faction_state, sfs_active),
        (store_troop_faction,
":faction_no", ":cur_troop"),
        (neq,
":faction_no", ":original_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, ":original_king", ":original_faction", fac_kingdom_1),
        (val_add,
":original_king", "trp_kingdom_1_lord"),
        (faction_set_slot,
":original_faction", slot_faction_leader, ":original_king"),
       
        (call_script,
"script_change_troop_faction", ":cur_troop", ":original_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,
":original_faction_2", ":cur_troop_2", slot_troop_original_faction),
          (store_troop_faction,
":faction_no_2", ":cur_troop_2"),
          (eq,
":original_faction_2", ":original_faction"),
          (neq,
":faction_no_2", ":original_faction"),
          (troop_set_slot,
":cur_troop_2", slot_troop_change_to_faction, ":original_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:
Quote
  # 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,
":original_faction", "$g_notification_menu_var1", slot_troop_original_faction),
      (faction_get_slot,
":original_king", ":original_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,
":original_faction"),
      (str_store_troop_name, s14,
":original_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,
":original_faction", "fac_kingdom_1", kingdoms_end), #Excluding player kingdom
       
(set_game_menu_tableau_mesh, "tableau_faction_note_mesh_for_menu", ":original_faction", pos0),
      (else_try),
        (set_game_menu_tableau_mesh,
"tableau_faction_note_mesh_banner", ":original_faction", pos0),
      (try_end),
      ],
    [
      (
"continue",[],"Continue...",
        [
          (troop_get_slot,
":original_faction", "$g_notification_menu_var1", slot_troop_original_faction),
         
## start peace
         
(try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
            (neq,
":cur_kingdom", ":original_faction"),
            (neq,
":cur_kingdom", "$g_notification_menu_var2"),
            (call_script,
"script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":original_faction", 0),
          (try_end),
         
## start war
         
(call_script, "script_diplomacy_start_war_between_kingdoms", "$g_notification_menu_var2", ":original_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:
« Last Edit: July 02, 2009, 08:54:15 AM by rubik »

NaglFaar

  • Baron
  • *
    • View Profile
  • Faction: Nord
  • MP nick: NaglFaar
  • WBM&BNW
Re: Source code of Restoration
« Reply #1 on: July 02, 2009, 08:54:14 AM »
Great feature.
That's all I can say.

I'll try it out.
Mæli þarft eða þegi


the thread is in Alpha stages and when all the ideas have been put together and implemented the taleworlds post shall be completed.

SPD_Phoenix

  • Master Knight
  • *
    • View Profile
  • Faction: Neutral
Re: Source code of Restoration
« Reply #2 on: July 02, 2009, 10:43:03 AM »
Cool feature.

I'll put it in my mini mod.

bjorne.

  • Sergeant Knight
  • *
  • I'm a nerd... deal with it..
    • View Profile
    • Age of Blackpowder - Realm of Revolution
  • Faction: Swadian
Re: Source code of Restoration
« Reply #3 on: July 02, 2009, 12:48:03 PM »
Very nice indeed. I wonder if this would fit into my mod.

Lumos

  • Probably Not a Help Desk
  • Moderator
  • *
  • Mens INsana in corpore sano
    • Steam - lumosx
    • YouTube - LumosX
    • View Profile
  • Faction: Nord
  • WBWF&SNWM&BVC
Re: Source code of Restoration
« Reply #4 on: July 02, 2009, 04:31:28 PM »
Awesome! Just what I needed! except the fix for the colors, though...