[WIP] Dynamic Settlements

Users who are viewing this thread

Dynamic Settlements

[size=24pt]WIP​

Download:
Dynamic Settlements Alpha 1.1

Features:
- Build new villages, castles & towns
- upgrade village to town
- downgrade town to village
- Building new villages will reduce prosperity and population of the center building it. Reduction depending on original prosperity
- new village prosperity depends on prosperity of center building it, and will always be slightly lower.
- centers upgraded to a town will lose some prosperity and start with relatively low population.
- village scenes will be set according to their terrain location. Desert scenes for desert villages! Snow scenes in snow terrain!

Screenshots: (all adjustments to the settlements is done live ingame)


It will be fairly easy to implement and use:
- it works with the existing constants: towns_begin, towns_end, etc. So any new settlement is immediately active and functional.
- This also means amazing performance, as it doesn't add any triggers. The scripts only run once, when a settlement is changed or built.
- It just requires to call one of the following scripts, with the parameter (-1, if player is building; ":center_no" if the AI is building it)
Code:
script_build_village
script_upgrade_to_town
script_downgrade_to_village
script_build_castle
script_build_town
Run (call_script, "script_build_village", "p_town_2), and town 2 will have a new village in it's vicinity, assigned to the owned of town_2.

Why this is WIP:

- Can only be used via cheats
- AI currently doesn't use this, though player can built/upgrade AI fiefs in cheat mode.
- doesn't include delayed building, yet.
- Fixed: parties attached to a cloned center don't get properly reassigned, yet.
- the terrain code doesn't work for castles and towns yet. So towns&castles get random scenes.
- Fixed: Scenes dont have working walkers and lots of  player troops spawn in the scenes.
- Fixed: new towns don't have garrison yet. Makes it easy to lose.

How does it work:
The game uses constants towns_begin, towns_end, villages_begin, villages_end, castles_begin, castles_end, as well as the slot_party_type, to determine, which settlement is which.
The problem with freely upgrading, building new upgrading fiefs used to be, the lack of continuous ranges.

Imagine this scenario, where each letter stands for a settlement in the parties_list (e=empty, t=town, c=castle, v=village),
eeeeeeeeeettttttttccccccccccvvvvvvvvvvvvvvvvvvvveeeeeeeeee
When building a new town, you take the e fief to the left of the leftmost t, assign it as a town and set towns_begin -1
When building a new village, you take the e fief to the right of the rightmost v, assign it as a village and set villages_end +1. Easy stuff
However, when you upgrade a village to town, you remove a v fief from the middle and suddenly villages_begin, villages_end is not continously filled with villages. This is where the scripts come in. They take the last active village, clone it onto the v fief, that is getting moved to the towns range and suddenly you have continous ranges again! Sweet stuff.

Below is the current code used. Code has not been updated to Alpha 1
Code:
towns_begin = "$g_towns_begin"
villages_begin = "$g_villages_begin"
towns_end = "$g_towns_end"
castles_begin = towns_end
castles_end = villages_begin
villages_end   = "$g_villages_end"
Code:
## F&B 
  ("kingdom_100","Ghost",0, 0.9, [], []),
  
  ("kingdoms_end","{!}kingdoms_end", 0, 0,[], []),
Code:
### Place new fiefs before town_1 ##################
  ("fief_1","Sargoth",  icon_town_nord_sargoth|pf_town, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(-17.6, 79.7),[], 170),
  ("fief_2","Sargoth",  icon_town_nord_sargoth|pf_town, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(-17.6, 79.7),[], 170),
  ("fief_3","Sargoth",  icon_town_nord_sargoth|pf_town, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(-17.6, 79.7),[], 170), 

  ("town_1","Sargoth",  icon_town_nord_sargoth|pf_town, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(-17.6, 79.7),[], 170),

##### And place new fiefs below the last village ####################
 ("village_110","Rushdigh",  icon_village_c|pf_village, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(38, -104),[], 40),

  ("fief_101","Sargoth",  icon_town_nord_sargoth|pf_town, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(-17.6, 79.7),[], 170),
  ("fief_102","Sargoth",  icon_town_nord_sargoth|pf_town, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(-17.6, 79.7),[], 170),
  ("fief_103","Sargoth",  icon_town_nord_sargoth|pf_town, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(-17.6, 79.7),[], 170),
  ("fief_104","Sargoth",  icon_town_nord_sargoth|pf_town, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(-17.6, 79.7),[], 170),
Code:
#F&B extra we go for 60 towns 100 castles 250 villages
  ["town_23_seneschal", "{!}Town 23 Seneschal", "{!}Town 23 Seneschal", tf_hero|tf_randomize_face|tf_is_merchant, 0,reserved,  fac_neutral,                                                                    [                 itm_ar_rho_tun_vest                       ,itm_bo_rho_t2_highlander                                                                                                                                                 ],def_attrib|level(2),wp(20),knows_common,rhodok_man_face_middle_1,rhodok_man_face_older_2],
  ["town_24_seneschal", "{!}Town 24 Seneschal", "{!}Town 24 Seneschal", tf_hero|tf_randomize_face|tf_is_merchant, 0,reserved,  fac_neutral,                                                                    [                 itm_ar_swa_tun_tabard                     ,itm_bo_swa_t2_hose                                                                                                                                                     ],def_attrib|level(2),wp(20),knows_common,swadian_man_face_middle_1,swadian_man_face_older_2],
 ################## .............. ####################################
#F&B extra
  ["castle_49_seneschal", "{!}Castle 49 Seneschal", "{!}Castle 49 Seneschal", tf_hero|tf_is_merchant, 0,reserved,  fac_neutral,                                                                          [                 itm_ar_rho_tun_vest_a                     ,itm_bo_rho_t2_highlander                                                                                                                                                 ],def_attrib|level(2),wp(20),knows_common,rhodok_man_face_middle_3,rhodok_man_face_older_4], #Jamiche Castle, Rhodok, Utrehd's Castle Pack 0.32
  ["castle_50_seneschal", "{!}Castle 50 Seneschal", "{!}Castle 50 Seneschal", tf_hero|tf_is_merchant, 0,reserved,  fac_neutral,                                                                         [                 itm_ar_nor_tun_green                      ,itm_bo_nor_t2_shoes                                                                                                                                                    ],def_attrib|level(2),wp(20),knows_common,nord_man_face_middle_3,nord_man_face_older_4], #Alburq Castle, Nord, El Arte de la Guerre 1.71, corrected by Smarmellows

######################.......................................#######################

  ["town_23_arena_master", "Tournament Master","{!}Tournament Master",tf_hero|tf_randomize_face|tf_guarantee_boots|tf_guarantee_armor, scn_town_3_arena|entry(52),reserved,   fac_commoners,                                           [                                 itm_ar_rho_t3_aketon_a      ,itm_bo_rho_t3_highlander                                                                                                                                                 ],def_attrib|level(22),wp(20),knows_common,rhodok_man_face_middle_1,rhodok_man_face_older_2], #Veluca, Rhodok
  ["town_24_arena_master", "Tournament Master","{!}Tournament Master",tf_hero|tf_randomize_face|tf_guarantee_boots|tf_guarantee_armor, scn_town_4_arena|entry(52),reserved,   fac_commoners,                                           [                 itm_ar_swa_tun_tabard                     ,itm_bo_swa_t2_hose                                                                                                                                                     ],def_attrib|level(22),wp(20),knows_common,swadian_man_face_middle_1,swadian_man_face_older_2], #Suno, Swadia

###########.........................................#################################
 ["town_23_crook","Town 23 Crook","Town 23 Crook",tf_hero,                0,0, fac_neutral,                                                                                           [                 itm_ar_rho_shi_capegreen                    ,itm_bo_rho_t1_bear                                                                                                                                                     ],def_attrib|level(2),wp(20),knows_inventory_management_10,rhodok_man_face_middle_1,rhodok_man_face_older_2],
  ["town_24_crook","Town 24 Crook","Town 24 Crook",tf_hero,                0,0, fac_neutral,                                                                                           [                 itm_ar_swa_shi_linen                      ,itm_bo_swa_t1_sandal                                                                                                                                                   ],def_attrib|level(5),wp(20),knows_inventory_management_10,swadian_man_face_middle_1,swadian_man_face_older_2],

 ####################........................##########################
["town_23_armorer","Armorer",  "{!}Armorer",  tf_hero|tf_randomize_face|          tf_is_merchant, 0, 0, fac_commoners,                                                                             [                 itm_ar_rho_tun_vest                       ,itm_bo_rho_t2_highlander                                                                                                                                                 ],def_attrib|level(2),wp(20),knows_inventory_management_10,rhodok_man_face_young_1,rhodok_man_face_older_2],
  ["town_24_armorer","Armorer",  "{!}Armorer",  tf_hero|tf_randomize_face|          tf_is_merchant, 0, 0, fac_commoners,                                                                             [                 itm_ar_swa_tun_tabard                     ,itm_bo_swa_t2_hose                                                                                                                                                     ],def_attrib|level(5),wp(20),knows_inventory_management_10,swadian_man_face_young_1,swadian_man_face_older_4],

 #########################...........................#########################
["town_23_weaponsmith", "Weaponsmith","{!}Weaponsmith",tf_hero|tf_randomize_face|          tf_is_merchant, 0, 0, fac_commoners,                                                                        [                 itm_ar_rho_mer_highlandergreen                  ,itm_bo_rho_t2_highlander                                                                                                                                                 ],def_attrib|level(5),wp(20),knows_inventory_management_10,rhodok_man_face_young_1,rhodok_man_face_older_4],
  ["town_24_weaponsmith", "Weaponsmith","{!}Weaponsmith",tf_hero|tf_randomize_face|          tf_is_merchant, 0, 0, fac_commoners,                                                                        [                 itm_ar_swa_shi_linen                      ,itm_bo_swa_t1_sandal                                                                                                                                                   ],def_attrib|level(5),wp(20),knows_inventory_management_10,swadian_man_face_young_2,swadian_man_face_older_3],

################.............................####################################
["town_23_tavernkeeper", "Tavern_Keeper","{!}Tavern_Keeper",tf_hero|tf_randomize_face|tf_female, scn_town_3_tavern|entry(9),0,   fac_commoners,                                                                [                 itm_dress_rhodok_common_a                   ,itm_bo_rho_t1_bear                                                                                                                                                     ],def_attrib|level(2),wp(20),knows_common,rhodok_woman_face_young_1,rhodok_woman_face_older_2],
  ["town_24_tavernkeeper", "Tavern_Keeper","{!}Tavern_Keeper",tf_hero|tf_randomize_face,           scn_town_4_tavern|entry(9),0,   fac_commoners,                                                                [                 itm_ar_swa_shi_linen                      ,itm_bo_swa_t1_sandal                                                                                                                                                   ],def_attrib|level(2),wp(20),knows_common,swadian_man_face_young_2,swadian_man_face_older_3],

 #############............................................########################
["town_23_merchant","Merchant","{!}Merchant",tf_female|tf_hero|tf_randomize_face|tf_is_merchant, scn_town_3_store|entry(9),0, fac_commoners,                                                                    [                 itm_dress_rhodok_common_b                   ,itm_bo_rho_t1_bear                       ,itm_he_rho_lad_common_a                                                                                                                  ],def_attrib|level(2),wp(20),knows_inventory_management_10,rhodok_woman_face_young_1,rhodok_woman_face_older_3],
  ["town_24_merchant", "Merchant","{!}Merchant",          tf_hero|tf_randomize_face|tf_is_merchant, scn_town_4_store|entry(9),0, fac_commoners,                                                                    [                 itm_ar_swa_mer_outfit                     ,itm_bo_swa_t2_hose                                                                                                                                                     ],def_attrib|level(2),wp(20),knows_inventory_management_10,swadian_man_face_young_1,swadian_man_face_older_3],

##############........................#############################
["town_23_horse_merchant","Horse Merchant","{!}Town 23 Horse Merchant",tf_hero|tf_randomize_face|tf_is_merchant,              0, 0, fac_commoners,                                                                [                 itm_ar_pla_mer_leatherapron                   ,itm_bo_rho_t1_bear                                                                                                                                                     ],def_attrib|level(5),wp(20),knows_inventory_management_10,rhodok_man_face_middle_1,rhodok_man_face_older_2],
  ["town_24_horse_merchant","Horse Merchant","{!}Town 24 Horse Merchant",tf_hero|tf_randomize_face|tf_is_merchant,              0, 0, fac_commoners,                                                                [                 itm_ar_pla_mer_leatherapron                   ,itm_bo_swa_t1_sandal                                                                                                                                                   ],def_attrib|level(5),wp(20),knows_inventory_management_10,swadian_man_face_middle_1,swadian_man_face_older_2],

#############...................................#################################
["town_23_mayor", "Guild_Master", "{!}Guild_Master", tf_hero|tf_randomize_face, 0,reserved,  fac_neutral,                                                                                    [                 itm_ar_rho_tun_vest                       ,itm_bo_rho_t2_highlander                                                                                                                                                 ],def_attrib|level(2),wp(20),knows_common,rhodok_man_face_middle_3,rhodok_man_face_older_4],
  ["town_24_mayor", "Guild_Master", "{!}Guild_Master", tf_hero|tf_randomize_face, 0,reserved,  fac_neutral,                                                                                    [                 itm_ar_swa_tun_tabard                     ,itm_bo_swa_t2_hose                                                                                                                                                     ],def_attrib|level(2),wp(20),knows_common,swadian_man_face_middle_1,swadian_man_face_older_4],

#############...........................######################
["village_111_elder","Village_Elder", "{!}village_11_elder",tf_hero|tf_randomize_face|tf_is_merchant, 0,0, fac_commoners,                                                                           [                 itm_ar_khe_tun_furcoat_a                    ,itm_bo_khe_t2_boots                                                                                                                                                    ],def_attrib|level(2),wp(20),knows_inventory_management_10,khergit_man_face_old_1,khergit_man_face_older_2], #Dusturil
  ["village_112_elder","Village_Elder", "{!}village_11_elder",tf_hero|tf_randomize_face|tf_is_merchant, 0,0, fac_commoners,                                                                           [                 itm_ar_pla_pri_robe                       ,itm_bo_pla_t1_priest                     ,itm_he_rho_t1_common_a                                                                                                                   ],def_attrib|level(2),wp(20),knows_inventory_management_10,rhodok_man_face_old_3,rhodok_man_face_older_4], #Emer

#############..........................############################
["town_23_master_craftsman", "{!}Town 3 Craftsman", "{!}Town 3 Craftsman", tf_hero|tf_is_merchant, 0,reserved,  fac_neutral,                                                                         [                 itm_ar_rho_tun_vest                       ,itm_bo_rho_t2_highlander                                                                                                                                                 ],def_attrib|level(2),wp(20),knows_common,rhodok_man_face_young_1], ##Floris: Joseph Louis Lagrange
  ["town_24_master_craftsman", "{!}Town 4 Craftsman", "{!}Town 4 Craftsman", tf_hero|tf_is_merchant, 0,reserved,  fac_neutral,                                                                         [                 itm_ar_pla_mer_leatherapron                   ,itm_bo_swa_t1_sandal                                                                                                                                                   ],def_attrib|level(2),wp(20),knows_common,swadian_man_face_older_1], ##Floris: Alfred Hitchcock
  
##########.............................###################
Code:
("game_start",
    [

    #F&B begin assigning global variables. IMPORTANT! This needs to be at the very start.
    (assign, "$g_towns_begin", "p_town_1"),
    (assign, "$g_towns_end", "p_castle_1"),
    (assign, "$g_villages_begin", "p_village_1"),
    (assign, "$g_villages_end", "p_fief_101"),
    #F&B end 
######## ...........Put below code anywhere in script_game_start ................###############
   #F&B begin disable the empty settlement
    (try_for_range, ":center_no", "p_fief_1", "p_town_1"),
      (call_script, "script_give_center_to_faction_aux", ":center_no", "fac_kingdom_100"),
      (disable_party, ":center_no"),
      (party_set_note_available, ":center_no", 0),
    (try_end),
    (try_for_range, ":center_no", "p_fief_101", "p_salt_mine"),
      (call_script, "script_give_center_to_faction_aux", ":center_no", "fac_kingdom_100"),
      (disable_party, ":center_no"),
      (party_set_note_available, ":center_no", 0),
    (try_end),
    (faction_set_slot, "fac_kingdom_100", slot_faction_state, sfs_inactive), #make kingdom 100 inactive
    (faction_set_note_available, "fac_kingdom_100", 0),
    #F&B end

Code:
############# place this above town_leave
   #F&B begin Dynamic World cheats 
    ("cheat_downgrade_to_village",
    [
      (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
      (eq, "$cheat_mode", 1),
      ],
      "Downgrade to village",
      [
      (call_script, "script_downgrade_to_village", "$g_encountered_party"),
      (change_screen_return),
      ]),
    ("cheat_build_village",
      [
      (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
      (eq, "$cheat_mode", 1),
      ],
      "Build new village",
      [
      (try_begin),
          (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
          (eq, ":town_lord", "trp_player"),
          (call_script, "script_build_village", -1),
      (else_try),
          (call_script, "script_build_village", "$g_encountered_party"),    
      (try_end),
      (change_screen_return),
      ]),
     ("cheat_build_castle",
      [
      (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
      (eq, "$cheat_mode", 1),
      ],
      "Build new Castle",
      [
      (try_begin),
          (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
          (eq, ":town_lord", "trp_player"),
          (call_script, "script_build_village", -1),
      (else_try),
          (call_script, "script_build_castle", "$g_encountered_party"),    
      (try_end),
      (change_screen_return),
      ]), 
    ("cheat_rename",
      [     
      (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord), 
      (this_or_next|eq, ":town_lord", "trp_player"),  
      (eq, "$cheat_mode", 1),
      ],
      "Rename fief",
      [
      (start_presentation, "prsnt_name_fief"),
      ]),
    #F&B end Dynamic World Cheats  

      ("town_leave",[],"Leave...",
##########..................... Add the code between #F&B begin and F&B end to the cheat menu ##############
("camp_cheat",
       [(ge, "$cheat_mode", 1)
        ], "CHEAT MENU!",
       [(jump_to_menu, "mnu_camp_cheat"),
        ],
       ),
      #F&B begin
      ("fb_cheat",
       [(ge, "$cheat_mode", 1)
      ], "Dynamic World Cheats",
      [(jump_to_menu, "mnu_fb_cheat"),
       ],
      ),
      #F&B end
      ("resume_travelling",[],"Resume travelling.",
##################..............Place this somewhere in game_menus###############
  #F&B begin Dynamic World Cheat Menu
  ("fb_cheat",0,
  "Behold the wonders of infinite power and use it wisely",
  "none",
  [
   ],
  [
  ("fb_cheat_build_village",[], "Build new village here",
    [ 
    (call_script, "script_build_village", -1),
    (change_screen_return),
     ]
  ),
  
  ("fb_cheat_build_castle",[], "Build new castle here",
    [
    (call_script, "script_build_castle", -1),
    (change_screen_return),
    ]
  ),
  
  ("fb_cheat_build_town",[], "Build new town here",
    [
    (call_script, "script_build_town", -1),
    (change_screen_return),
    ]
  ),
  ("fb_cheat_camp",[],"{!}Camp for 1 year at 50x speed",
       [
         (assign,"$g_camp_mode", 1),
         (assign, "$g_infinite_camping", 1),
         (assign, "$g_player_icon_state", pis_camping),
         (rest_for_hours_interactive, 24 * 365, 50), #1 year rest while not attackable with 50x speed
         (change_screen_return),
        ]
       ),
  ("fb_cheat_return",[], "Return",
    [
    (jump_to_menu, "mnu_camp"),
    ]
  ),
  ]
  ),
  #F&B end Dynamic World Cheat Menu

Credits:
- everyone who was involved in the Floris mod and any of the OSP's it includes
- Q&A Thread members. Notable mention: kalarhan
 
The other code part is just adding more troops, etc.
But this is, where the magic happens.

(call_script, "script_clone_party", "p_village_1", "p_fief_150"),
and you got yourself a free fief adjacent to the castles range, which you can assign as an additional castle, while retaining the village with all its properties


  #F&B begin Dynamic World

  # "script_build_village"
  # Description. Builds a new village and binds it to nearby center. Prosperity is dependent on center building it, but will be lower.
  # Input: ":eek:rig_center"
  # Output: none
  ("build_village",
  [
      (store_script_param_1, ":eek:rig_center"),
      (assign, ":new_village", villages_end),  #New village has to always be last used village +1.
      (try_begin),
          (gt, ":eek:rig_center", 0),      # 1= AI built, else player built
          (party_get_slot, ":town_lord", ":eek:rig_center", slot_town_lord),
          (party_relocate_near_party, ":new_village", ":eek:rig_center", 5),
          (store_faction_of_party, ":faction", ":eek:rig_center"),
          (call_script, "script_give_center_to_faction", ":new_village", ":faction"),
          (party_get_slot, ":prosperity", ":eek:rig_center", slot_town_prosperity),
          (party_get_slot, ":eek:rig_center_pop", ":eek:rig_center", slot_center_population),
          (store_random_in_range, ":reduction", 25000, 50000),
          (val_div, ":reduction", ":prosperity"),      #looses more pop the poorer orig center is. Avg prosperity should be 70. 50000/70=3,5k pop lost
          (val_sub, ":eek:rig_center_pop", ":reduction"),
          (party_set_slot, ":eek:rig_center", slot_center_population, ":eek:rig_center_pop"),
          (val_sub, ":prosperity", 10),
          (party_set_slot, ":eek:rig_center", slot_town_prosperity, ":prosperity"),  #slightly reduce prosperity of town
          (val_sub, ":prosperity", 10),      #Prosperity for new village. Will be 20 points lower than town's prosperity     
      (else_try),
          (party_relocate_near_party, ":new_village", "p_main_party", 0),
          (assign, ":town_lord", "trp_player"),
          (store_random_in_range, ":prosperity", 20, 50),
          (assign, ":faction, "fac_player_faction"),
                                                  #F&B Fix need to give it to player faction?                       
      (try_end),
      (enable_party, ":new_village"),
     
      (assign, ":end_cond", village_elders_end),
      (try_for_range, ":new_elder", village_elders_begin, ":end_cond"),
          (neg|troop_slot_eq, ":new_elder", slot_trp_is_active, 1),
          (party_set_slot, ":new_village", slot_town_elder, ":new_elder"),
          (troop_set_slot, ":new_elder", slot_trp_is_active, 1),
          (assign, ":end_cond", ":new_elder"),             
      (try_end),
      (party_set_slot,":new_village", slot_village_raided_by, -1),
      (party_set_flags, ":new_village", pf_is_static, 1),
      (party_set_flags, ":new_village", pf_always_visible, 1),
      (party_set_flags, ":new_village", pf_hide_defenders, -1),
      (party_set_flags, ":new_village", pf_label_large, 0),
      (party_set_flags, ":new_village", pf_label_small, 1),
      (party_set_slot, ":new_village", slot_town_prosperity, ":prosperity"),
      (party_set_slot, ":new_village", slot_center_last_spotted_enemy, -1),
      (party_set_slot, ":new_village", slot_center_is_besieged_by, -1),
      (party_set_slot, ":new_village", slot_center_last_taken_by_troop, -1),     
      (party_set_slot, ":new_village", slot_party_type, spt_village),
      (call_script, "script_give_center_to_faction", ":faction", ":new_village"),
      (call_script, "script_start_give_center_to_lord", ":new_village",  ":town_lord", 0),
      (call_script, "script_bind_village", ":new_village"),
   
      (call_script, "script_set_village_scene", ":new_village"),
      (call_script, "script_start_refresh_village_defenders", ":new_village"),
      (call_script, "script_start_refresh_village_defenders", ":new_village"),
      (call_script, "script_start_refresh_village_defenders", ":new_village"),
      (call_script, "script_start_refresh_village_defenders", ":new_village"),                       
      (val_add, ":new_village", 1),        #Move villages_end 1 down, since we now have an additional village
      (assign, "$g_villages_end", ":new_village"),       
     
  ]),
  # "script_downgrade_to_village"
  # Description: This downgrades existing settlement to village. Similar to script_build_village, but I think it's easier to split them up. Assumption: We downgrade from town to village, otherwise this will bug
  # Input: ":eek:rig_center"  the center, which is getting downgraded to a village
  # Output: none
  ("downgrade_to_village",       
  [ 
      (store_script_param_1, ":downgraded_center"),
      (assign, ":center_to_keep", towns_begin),
     
      (assign, ":new_village", villages_end),
      (party_get_slot, ":town_lord_downgraded", ":downgraded_center", slot_town_lord),
      (party_get_slot, ":prosperity", ":downgraded_center", slot_town_prosperity),
      (val_add, ":prosperity", 10),
      (assign, ":end_cond", village_elders_end),
      (try_for_range, ":new_elder", "trp_village_1_elder", ":end_cond"),
          (neg|troop_slot_eq, ":new_elder", slot_trp_is_active, 1),
          (party_set_slot, ":new_village", slot_town_elder, ":new_elder"),
          (troop_set_slot, ":new_elder", slot_trp_is_active, 1),
          (assign, ":end_cond", ":new_elder"),              #break once we found ourselves a new village_elder
      (try_end),
      (party_relocate_near_party, ":new_village", ":downgraded_center", 0),
      (str_clear, s1),
      (str_store_party_name, s1, ":downgraded_center"),   
      (party_set_name, ":new_village", s1),
      (str_clear, s1),
     
      (party_set_slot, ":new_village", slot_village_raided_by, -1),     
      (party_set_flags, ":new_village", pf_is_static, 1),
      (party_set_flags, ":new_village", pf_always_visible, 1),
      (party_set_flags, ":new_village", pf_hide_defenders, -1),
      (party_set_flags, ":new_village", pf_label_large, 0),
      (party_set_flags, ":new_village", pf_label_small, 1),
      (party_set_note_available, ":new_village", 1),
      (enable_party, ":new_village"),
      (party_set_slot, ":new_village", slot_town_prosperity, ":prosperity"),
      (party_set_slot, ":new_village", slot_party_type, spt_village),
      (store_faction_of_party, ":faction", ":downgraded_center"),
      (call_script, "script_give_center_to_faction", ":new_village", ":faction"),
      (call_script, "script_give_center_to_lord", ":new_village", ":town_lord_downgraded", 0),
      (call_script, "script_set_village_scene", ":new_village"),  #F&B Fix need to also run script to get village_walkers working
      (call_script, "script_start_refresh_village_defenders", ":new_village"),
      (call_script, "script_start_refresh_village_defenders", ":new_village"),
      (call_script, "script_start_refresh_village_defenders", ":new_village"),
      (call_script, "script_start_refresh_village_defenders", ":new_village"), 
      (try_for_range, ":walker_no", 0, num_town_walkers),
          (call_script, "script_center_set_walker_to_type", ":new_village", ":walker_no", walkert_default),
      (try_end), 
      (call_script, "script_bind_village", ":new_village"),
                                                   
        #### We now have the village with all relevant information in place and just need to deal with the previous fief.
      (try_begin),   
          (eq, ":downgraded_center", towns_begin),      #for this case, :downgraded_center=:center_to_keep
          (try_for_range, reg1, 0, 1000),              #clear all slots from old town
            (party_set_slot, ":downgraded_center", reg1, 0),
          (try_end),
      (else_try),    #downgraded town isn't first town. We need to swap first town with downgraded town, then disable first town, so the cloned town is still enabled, but on place of downgraded town and move towns_begin one down 
          (party_get_slot, ":town_lord_to_keep", ":center_to_keep", slot_town_lord),
          (store_faction_of_party, ":faction", ":center_to_keep"),
                                           
          ###First we get all important information from :downgraded_center and transfer it to the village fief, then we clone information from :center_to_keep onto :downgraded_fief     
          # here we copy all relevant town information from :center_to_keep onto the now free :downgraded_center
          (try_for_range, reg1, 0, 1000), # slot_town_trade_good_productions_begin
            (party_set_slot, ":downgraded_center", reg1, 0),    #safety measure. Clear all slots of the center we keep using, before filling it with new information, in case the other center doesn't overwrite all. So we cannot end up with old information
            (party_get_slot, reg0, ":center_to_keep", reg1),
            (neq, reg0, 0),
            (party_set_slot, ":downgraded_center", reg1, reg0), #store information in the other town
            (party_set_slot, ":center_to_keep", reg1, 0),      #clear all slots from the town, before disabling it completely 
          (try_end),
          (party_get_position, pos1, ":center_to_keep"),
          (party_set_position, ":downgraded_center", pos1),
          (str_clear, s1),
          (str_store_party_name, s1, ":center_to_keep"),
          (party_set_name, ":downgraded_center", s1),
          (str_clear, s1),
          (party_get_icon, ":icon_to_keep", ":center_to_keep"),
          (party_set_icon, ":downgraded_center", ":icon_to_keep"),
          (assign, "$g_move_heroes", 1),
          (call_script, "script_party_add_party", ":downgraded_center", ":center_to_keep"),
          (assign, "$g_move_heroes", 0),
          (party_set_slot, ":downgraded_center", slot_party_type, spt_town),
          (party_set_flags, ":downgraded_center", pf_is_static, 1),
          (party_set_flags, ":downgraded_center", pf_always_visible, 1),
          (party_set_flags, ":downgraded_center", pf_hide_defenders, 1),
          (party_set_flags, ":downgraded_center", pf_label_large, 1),
          (party_set_slot, ":downgraded_center", slot_party_type, spt_town),
         
          (call_script, "script_give_center_to_faction", ":downgraded_center", ":faction"),              #F&B check. This could potentially overwrite slot values, that we want to keep
          (call_script, "script_give_center_to_lord", ":downgraded_center", ":town_lord_to_keep", 0),  #F&B Fix make it transfer garrison from old to new town   
         
      (try_end),
      (party_clear, ":center_to_keep"),
      (call_script, "script_give_center_to_faction", ":center_to_keep", "fac_kingdom_100"),
      (disable_party, ":center_to_keep"),
      (party_set_note_available, ":center_to_keep", 0),
      (val_add, "$g_villages_end", 1),  #Take into account the additional village for the villages range   
      (val_add, "$g_towns_begin", 1),  #Take into account the disabled town
  ]),

  # "script_upgrade_to_town"
  # Description: Upgrade a village to a town. This code assigns all the proper slots, troops, icons, owner.
  # Important naming convention: :upgraded_center is the fief, which gets upgraded to a town. This means, we copy all relevant information of this upgraded_center onto an empty town, the new_town
  # Once this information is copied, all information from the last active village, :center_to_keep, will be saved in :upgraded_center and :center_to_keep will be disabled.
  # This allows us to change the number of active towns, villages & castles, while keeping the settlements between the constants _begin, _end.
  # Input: party_id of village getting upgraded
  # Output: none
  ("upgrade_to_town",
  [
      (store_script_param_1, ":upgraded_center"),
      (assign, ":center_to_keep", villages_end),
      (val_sub, ":center_to_keep", 1),    #this is the last active village, which we will need to clone onto upgraded village, before disabling it.
      (assign, ":new_town", towns_begin),
      (val_sub, ":new_town", 1),          #this will be our new town settlement.  #F&B Fix! Need to make safety check, that there will be an unused party, that can be set as town. Otherwise ****s gonna hit the fan HAAAARD!
      (party_get_slot, ":town_lord_upgraded", ":upgraded_center", slot_town_lord),
      (party_get_slot, ":prosperity", ":upgraded_center", slot_town_prosperity),
      (val_sub, ":prosperity", 20),      #Reduce prosperity after upgrading
      (party_set_slot, ":new_town", slot_town_prosperity, ":prosperity"),
      (store_random_in_range, ":new_pop", 5000, 7500),
      (party_set_slot, ":new_town", slot_center_population, ":new_pop"),     
    # (store_faction_of_party, ":faction", ":upgraded_center"),
      (call_script, "script_set_town_scene", ":new_town"),    #Here we set scenes and all troops
      (party_relocate_near_party, ":new_town", ":upgraded_center", 0),
      (str_clear, s1),
      (str_store_party_name, s1, ":upgraded_center"),   
      (party_set_name, ":new_town", s1),
      (str_clear, s1),
      #F&B check. maybe need to set faction as well?
      (store_faction_of_party, ":faction", ":upgraded_center"),
      (call_script, "script_give_center_to_faction", ":faction", ":new_town"),
      (call_script, "script_give_center_to_lord", ":new_town", ":town_lord_upgraded", 0),  #F&B Check include a garrison? We don't want to upgrade to town and then lose it instantly. Maybe include grace period?
      (party_set_slot, ":new_town", slot_party_type, spt_town),
      (party_set_flags, ":new_town", pf_is_static, 1),
      (party_set_flags, ":new_town", pf_always_visible, 1),
      (party_set_flags, ":new_town", pf_hide_defenders),
      (party_set_flags, ":new_town", pf_label_large, 1),
      (party_set_note_available, ":new_town", 1),
      (enable_party, ":new_town"),     
      ###### Town information is set above. Now we need to clone :center_to_keep onto :upgraded_center
      (try_begin),   
          (eq, ":upgraded_center", ":center_to_keep"),      #for this case, :upgraded_center=:center_to_keep, so we don't need it anymore, as it turned into town.
          (try_for_range, reg1, 0, 1000),              #clear all slots from old town
            (party_set_slot, ":upgraded_center", reg1, 0),
          (try_end),
      (else_try),   
          (party_get_slot, ":town_lord_to_keep", ":center_to_keep", slot_town_lord), 
          (store_faction_of_party, ":faction", ":center_to_keep"),
                 
          # here we copy all relevant village information from :center_to_keep onto the now free :upgraded_center
          (try_for_range, reg1, 0, 1000), # slot_town_trade_good_productions_begin
            (party_set_slot, ":upgraded_center", reg1, 0),    #safety measure. Clear all slots of the center we keep using, before filling it with new information, in case the other center doesn't overwrite all. So we cannot end up with old information
            (party_get_slot, reg0, ":center_to_keep", reg1),
            (neq, reg0, 0),
            (party_set_slot, ":upgraded_center", reg1, reg0), #store information in the other village
            (party_set_slot, ":center_to_keep", reg1, 0),      #clear all slots from the village, before disabling it completely 
          (try_end),
          (party_get_position, pos1, ":center_to_keep"),
          (party_set_position, ":upgraded_center", pos1),
          (str_clear, s1),
          (str_store_party_name, s1, ":center_to_keep"),
          (party_set_name, ":upgraded_center", s1),
          (str_clear, s1),
          (party_get_icon, ":icon_to_keep", ":center_to_keep"),
          (party_set_icon, ":upgraded_center", ":icon_to_keep"),
          (party_set_slot, ":upgraded_center", slot_party_type, spt_village),
         
          (assign, "$g_move_heroes", 1),
          (call_script, "script_party_add_party", ":upgraded_center", ":center_to_keep"),
          (assign, "$g_move_heroes", 0),
          (call_script, "script_give_center_to_faction", ":faction", ":upgraded_center"),
          (call_script, "script_give_center_to_lord", ":upgraded_center", ":town_lord_to_keep", 0),  #F&B Fix make it transfer garrison from old to new town       
      (try_end),
      (call_script, "script_bind_village", -1),  #Rebind all villages, since we got a new town
     
      (party_set_slot, ":upgraded_center", slot_party_type, spt_village),
      (party_clear, ":center_to_keep"),
      (call_script, "script_give_center_to_faction", "fac_kingdom_100", ":center_to_keep"),
      (disable_party, ":center_to_keep"),
      (party_set_note_available, ":center_to_keep", 0),
      (val_sub, "$g_towns_begin", 1),
      (val_sub, "$g_towns_end", 1),
  ]),

  # "script_clone_party"
  # Description: This copies ALL information from one settlement onto a new settlement. Warning: Any information from target center will be overwritten
  # Input: param_1: Original Center; param_2: Target Center
  # Output: none
  ("clone_party",
  [
   
      (store_script_param_1, ":eek:rig_center"),
      (store_script_param_2, ":target_center"),
      (party_get_slot, ":eek:rig_town_lord", ":eek:rig_center", slot_town_lord),
      (store_faction_of_party, ":eek:rig_faction", ":eek:rig_center"),
      (try_for_range, reg1, 0, 1000),
        (party_set_slot, ":target_center", reg1, 0),
        (party_get_slot, reg0, ":eek:rig_center", reg1),
        (neq, reg0, 0),
        (party_set_slot, ":target_center", reg1, reg0),
        (party_set_slot, ":eek:rig_center", reg1, 0),
      (try_end),
      (party_get_position, pos1, ":eek:rig_center"),
      (party_set_position, ":target_center", pos1),
      (str_clear, s1),
      (str_store_party_name, s1, ":eek:rig_center"),
      (party_set_name, ":target_center", s1),
      (str_clear, s1),
      (party_get_icon, ":eek:rig_icon", ":eek:rig_center"),
      (party_set_icon, ":target_center", ":eek:rig_icon"),
      (assign, "$g_move_heroes", 1),
      (call_script, "script_party_add_party", ":target_center", ":eek:rig_center"),
      (assign, "$g_move_heroes", 0),
      (call_script, "script_give_center_to_faction", ":eek:rig_faction", ":target_center"),
      (call_script, "script_give_center_to_lord", ":target_center", ":eek:rig_town_lord", 0),  #F&B Fix make it transfer garrison from old to new town       
      (try_begin), #F&B Check. If we run out of fiefs, we might have to shift both castles and villages around to get to an empty fief. This assumes, we have empty fiefs both before towns and after villages. Should be mostly true.
          (party_slot_eq, ":target_center", slot_party_type, spt_town),
          (val_sub, "$g_towns_begin", 1),      #Adjust settlement range
      (else_try),
          (party_slot_eq, ":target_center", slot_party_type, spt_village),
          (val_add, "$g_villages_end", 1),      #Adjust settlement range
      (try_end),
  ]),
  # "script_build_castle"
  # Description: Builds a new castle. This is a bit more complex. Before castle_begin constants are all the castles.
  # After castles_end are the villages. Idea is to clone first village onto a new village located at last village +1.
  # That way we get an empty fief adjacent to the castle range. Only then create new castle onto first village party.
  # Input: party_id of center building the castle. Input Center, if AI builds. For player building castle, leave empty.
  # Output: none
  ("build_castle",
  [
      (store_script_param_1, ":initiating_center"),
      (assign, ":new_center", villages_begin),
      (call_script, "script_clone_party", villages_begin, villages_end),
      (val_add, "$g_villages_begin", 1),    #former 1st village will be used as a castle now       
      (try_begin),
          (ge, ":initiating_center", 1),
          (party_relocate_near_party, ":new_center", ":initiating_center", :cool:,
          (store_faction_of_party, ":faction", ":initiating_center"),
          (party_get_slot, ":town_lord", ":initiating_center", slot_town_lord),
      (else_try),
          (party_relocate_near_party, ":new_center", "p_main_party", 0),
          (assign, ":faction", "fac_player_faction"),
          (assign, ":town_lord", "p_main_party"),
      (try_end),
      (store_random_in_range, ":prosperity", 25, 45),
      (party_set_slot, ":new_center", slot_town_prosperity, ":prosperity"),
      (party_set_flags, ":new_center", pf_is_static, 1),
      (party_set_flags, ":new_center", pf_always_visible, 1),
      (party_set_flags, ":new_center", pf_show_faction, 1),
      (party_set_flags, ":new_center", pf_label_large, 0),
      (party_set_flags, ":new_center", pf_label_medium, 1),
      (party_set_flags, ":new_center", pf_hide_defenders),
      (party_set_note_available, ":new_center", 1),
      (enable_party, ":new_center"),
      #(call_script, "script_give_center_to_faction", ":faction", ":new_center"),  #F&B bug hunting. Is it unneccesariy
      (call_script, "script_give_center_to_lord", ":new_center", ":town_lord", 0),  #F&B Check include a garrison? We don't want to upgrade to town and then lose it instantly. Maybe include grace period?
      (call_script, "script_set_castle_scene", ":new_center"),   
      (call_script, "script_bind_village", -1),
  ]),
  # "script_build_town"
  # Description: Builds a new town.
  # Input: party_id of center building a town. Input Center, if AI builds. For player building town leave empty.
  # Output: none
  ("build_town",
  [
      (store_script_param_1, ":initiating_center"),
      (assign, ":new_center", towns_begin),
      (val_sub, ":new_center", 1),    #F&B Fix! Need to make safety check, that there will be an unused party, that can be set as town. Otherwise ****s gonna hit the fan HAAAARD!
      (try_begin),
          (ge, ":initiating_center", 1),
          (party_relocate_near_party, ":new_center", ":initiating_center", :cool:,
          (store_faction_of_party, ":faction", ":initiating_center"),
          (party_get_slot, ":town_lord", ":initiating_center", slot_town_lord),
      (else_try),
          (party_relocate_near_party, ":new_center", "p_main_party", 0),
          (assign, ":faction", "fac_player_faction"),
          (assign, ":town_lord", "p_main_party"),
      (try_end),
      (party_set_slot, ":new_center", slot_party_type, spt_town),
      (party_set_flags, ":new_center", pf_is_static, 1),
      (party_set_flags, ":new_center", pf_always_visible, 1),
      (party_set_flags, ":new_center", pf_hide_defenders),
      (party_set_flags, ":new_center", pf_label_large, 1),
      (party_set_note_available, ":new_center", 1),
      (enable_party, ":new_center"),     
      (store_random_in_range, ":new_pop", 5000, 10000),
      (party_set_slot, ":new_center", slot_center_population, ":new_pop"),
    # (call_script, "script_give_center_to_faction", ":faction", ":new_center"),
      (call_script, "script_give_center_to_lord", ":new_center", ":town_lord", 0),  #F&B Check include a garrison? We don't want to upgrade to town and then lose it instantly. Maybe include grace period?
      (call_script, "script_set_town_scene", ":new_center"),   
      (call_script, "script_bind_village", -1),
  ]),
  # "script_set_village_scene"
  # Description: Here we set the village icon and scene depending on it's location.
  # Input: party_id of village
  # Output: none
  ("set_village_scene",
  [
    (store_script_param_1, ":center_no"),
    (party_get_current_terrain, ":terrain", ":center_no"),
    (try_begin),
        (eq, ":terrain", 4), #snow terrain
        (party_set_icon, ":center_no", "icon_village_snow_a"),
        (store_random_in_range, ":exterior_scene_no", "scn_village_78", "scn_village_91"),
        (store_sub, ":eek:ffset", ":exterior_scene_no", "scn_village_78"),
        (store_add, ":exterior_scene_no", "scn_village_78", ":eek:ffset"),
        (party_set_slot,":center_no", slot_castle_exterior, ":exterior_scene_no"),         
    (else_try),
        (eq, ":terrain", 5), # desert terrain
        (party_set_icon, ":center_no", "icon_village_c"),
        (store_random_in_range, ":exterior_scene_no", "scn_village_91", "scn_village_110"), #could be scn_village_110 +1
        (store_sub, ":eek:ffset", ":exterior_scene_no", "scn_village_91"),
        (store_add, ":exterior_scene_no", "scn_village_91", ":eek:ffset"),
        (party_set_slot,":center_no", slot_castle_exterior, ":exterior_scene_no"), 
    (else_try),      # all other terrain
        (party_set_icon, ":center_no", "icon_village_a"),
        (store_random_in_range, ":exterior_scene_no", "scn_village_1", "scn_village_78"),
        (store_sub, ":eek:ffset", ":exterior_scene_no", "scn_village_1"),
        (store_add, ":exterior_scene_no", "scn_village_1", ":eek:ffset"),
        (party_set_slot,":center_no", slot_castle_exterior, ":exterior_scene_no"),       
    (try_end),
    (try_for_range, ":walker_no", 0, num_town_walkers),
          (call_script, "script_center_set_walker_to_type", ":center_no", ":walker_no", walkert_default),
      (try_end), 
  ]),



    ("set_castle_scene",
      [
        (store_script_param_1, ":new_castle"),
        (store_random_in_range, ":castle_no", "p_castle_1", "p_village_1"),
        (store_sub, ":eek:ffset", ":castle_no", "p_castle_1"),
        (assign, ":eek:ffset_orig", ":eek:ffset"),
        (val_mul, ":eek:ffset", 3),    #F&B Check no idea, why this mul by 3 is used.
        (store_add, ":exterior_scene_no", "scn_castle_1_exterior", ":eek:ffset"),
        (party_set_slot,":new_castle", slot_castle_exterior, ":exterior_scene_no"),
        (store_add, ":interior_scene_no", "scn_castle_1_interior", ":eek:ffset"),
        (party_set_slot,":new_castle", slot_town_castle, ":interior_scene_no"),
        (store_add, ":interior_scene_no", "scn_castle_1_prison", ":eek:ffset"),
        (party_set_slot,":new_castle", slot_town_prison, ":interior_scene_no"),
        (party_set_slot,":new_castle", slot_town_reinforcement_party_template, "pt_center_reinforcements"),
        (party_set_slot,":new_castle", slot_party_type, spt_castle),
        (party_set_slot,":new_castle", slot_center_is_besieged_by, -1),
        (store_random_in_range, ":rand_castle_icon", "icon_castle_derchios", "icon_castle_weyyah"),
        (party_set_icon, ":new_castle", ":rand_castle_icon"),
              # Check, whether castle needs to be sieged with belfry
        (try_begin),
            (this_or_next|eq, ":eek:ffset_orig", 0),
            (this_or_next|eq, ":eek:ffset_orig", 1),
            (this_or_next|eq, ":eek:ffset_orig", 3),
            (this_or_next|eq, ":eek:ffset_orig", 6),
            (this_or_next|eq, ":eek:ffset_orig", 7),
            (this_or_next|eq, ":eek:ffset_orig", :cool:,
            (this_or_next|eq, ":eek:ffset_orig", 10),
            (this_or_next|eq, ":eek:ffset_orig", 12),
            (this_or_next|eq, ":eek:ffset_orig", 20),
            (this_or_next|eq, ":eek:ffset_orig", 24),
            (this_or_next|eq, ":eek:ffset_orig", 33),
            (this_or_next|eq, ":eek:ffset_orig", 34),
            (this_or_next|eq, ":eek:ffset_orig", 37),
            (this_or_next|eq, ":eek:ffset_orig", 39),
            (this_or_next|eq, ":eek:ffset_orig", 40),
            (this_or_next|eq, ":eek:ffset_orig", 41),
            (eq, ":eek:ffset_orig", 42),
            (party_set_slot, ":new_castle", slot_center_siege_with_belfry, 1), 
        (try_end),

      ]),

    # "script_set_town_scene"
    # Description: Here we set the scenes for a new town. Might make this terrain based, as for vilages, later on.
    # Input: party_id of town
    # Output: none
    ("set_town_scene",
    [
      (store_script_param_1, ":town_no"),
      ######## Here we assign all troops required for a town
      (assign, ":end_cond", mayors_end),
     
      (try_for_range, ":free_mayor", mayors_begin, ":end_cond"),
        (troop_slot_eq, ":free_mayor", slot_trp_is_active, 0),        # Since we assign all troops at the same time, if mayor 25 is unused, all other 25th troops should be unused as well. Should be always true. So realistically, setting trp_is_active for other troops is not required, however, just do it for safety. Though we never check for it, yet.
        (store_sub, ":eek:ffset", ":free_mayor", mayors_begin),
        (store_add, ":cur_object_no", "trp_town_1_mayor", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_elder, ":cur_object_no"),
        (troop_set_slot, ":cur_object_no", slot_trp_is_active, 1),
        (store_add, ":cur_object_no", "trp_town_1_tavernkeeper", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_tavernkeeper, ":cur_object_no"),
        (troop_set_slot, ":cur_object_no", slot_trp_is_active, 1),
        (store_add, ":cur_object_no", "trp_town_1_weaponsmith", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_weaponsmith, ":cur_object_no"),
        (troop_set_slot, ":cur_object_no", slot_trp_is_active, 1),
      # (try_begin),
      #  (eq, "$cheat_mode", 1),
        # (eq, "$cheat_mode", 1),
      #  (eq, 1, 1), 
      #  (assign, reg20, ":town_no"),
      #  (assign, reg21, ":cur_object_no"),

      #  (str_store_party_name, s20, reg20),
      #  (str_store_troop_name, s21, reg21),

        #  (display_message, "@Weaponsmith: {reg21} | {s21} | Town: {reg20} | {s20}"),
        #(try_end),

        (store_add, ":cur_object_no", "trp_town_1_armorer", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_armorer, ":cur_object_no"),
        (troop_set_slot, ":cur_object_no", slot_trp_is_active, 1),
        (store_add, ":cur_object_no", "trp_town_1_merchant", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_merchant, ":cur_object_no"),
        (troop_set_slot, ":cur_object_no", slot_trp_is_active, 1),
        (store_add, ":cur_object_no", "trp_town_1_horse_merchant", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_horse_merchant, ":cur_object_no"),
        (troop_set_slot, ":cur_object_no", slot_trp_is_active, 1),
        (store_add, ":cur_object_no", "scn_town_1_center", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_center, ":cur_object_no"),    #F&B Check Can we use this multiple times?
        (assign, ":end_cond", ":free_mayor"),  #break
      (try_end),
      ######## Here we assign all scenes required for a town
    # (try_for_range, ":random_town", _begin, _end),
        (store_random_in_range, ":eek:ffset", 1, 22),  #22 towns, picks random scenes for now. Gonna improve later on
       
        (store_add, ":cur_object_no", "scn_town_1_center", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_center, ":cur_object_no"),
        (store_add, ":cur_object_no", "scn_town_1_castle", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_castle, ":cur_object_no"),
        (store_add, ":cur_object_no", "scn_town_1_prison", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_prison, ":cur_object_no"),
        (store_add, ":cur_object_no", "scn_town_1_walls", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_walls, ":cur_object_no"),
        (store_add, ":cur_object_no", "scn_town_1_tavern", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_tavern, ":cur_object_no"),
        (store_add, ":cur_object_no", "scn_town_1_store", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_store, ":cur_object_no"),
        (store_add, ":cur_object_no", "scn_town_1_arena", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_arena, ":cur_object_no"),
        (store_add, ":cur_object_no", "scn_town_1_alley", ":eek:ffset"),
        (party_set_slot,":town_no", slot_town_alley, ":cur_object_no"),
      #(try_end),
        (party_set_slot,":town_no", slot_town_reinforcement_party_template, "pt_center_reinforcements"), 
        #Check, whether town needs to be besieged with belfry
        (try_begin),              #F&B check. If we messed up, we are off by 1
          (this_or_next|eq, ":eek:ffset", 12),
          (eq, ":eek:ffset", 15),
          (party_set_slot, ":town_no", slot_center_siege_with_belfry, 1),
        (try_end),
        (try_for_range, ":walker_no", 0, num_town_walkers),
          (call_script, "script_center_set_walker_to_type", ":town_no", ":walker_no", walkert_default),
        (try_end),
    ]),
   
      # "script_bind_village"
      # Description: Find new market town for village. If there is an input parameter, if will bind that village to nearest town. Without input parameter, all villages will be rebound. o_O this is gonna suck.
      # Input: party_id of village
      # Output: none
      ("bind_village",
      [
      (store_script_param_1, ":cur_village"),
      (try_begin),
          (ge, ":cur_village", 1),    #if
          (assign, ":min_dist", 999999),
          (assign, ":min_dist_town", -1),
          (try_for_range, ":cur_town", towns_begin, towns_end),
            (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_town"),
            (lt, ":cur_dist", ":min_dist"),
            (assign, ":min_dist", ":cur_dist"),
            (assign, ":min_dist_town", ":cur_town"),
          (try_end),
          (party_set_slot, ":cur_village", slot_village_bound_center, ":min_dist_town"),
          (store_faction_of_party, ":town_faction", ":min_dist_town"),
          (call_script, "script_give_center_to_faction_aux", ":cur_village", ":town_faction"),
      (else_try),  ##### Due to town up and downgrading, we may need to rebind all villages.
       
          # First reset slot_village_bound_center, otherwise the code after won't reassign properly.
        (try_for_range, ":center_no", villages_begin, villages_end),
            (party_set_slot, ":center_no", slot_village_bound_center, 0),
        (try_end),
        #pass 1: Give one village to each castle          #F&B Check
        #this is temporary. We want to get rid of bound villages and make them seperate.
        (try_for_range, ":cur_center", castles_begin, castles_end),
          (assign, ":min_dist", 999999),
          (assign, ":min_dist_village", -1),
          (try_for_range, ":cur_village", villages_begin, villages_end),
            (neg|party_slot_ge, ":cur_village", slot_village_bound_center, 1), #skip villages which are already bound.
            (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_center"),
            (lt, ":cur_dist", ":min_dist"),
            (assign, ":min_dist", ":cur_dist"),
            (assign, ":min_dist_village", ":cur_village"),
          (try_end),
          (party_set_slot, ":min_dist_village", slot_village_bound_center, ":cur_center"),
          (store_faction_of_party, ":town_faction", ":cur_center"),
          (call_script, "script_give_center_to_faction_aux", ":min_dist_village", ":town_faction"),
        (try_end),
     
     
      #pass 2: Give other villages to closest town.
        (try_for_range, ":cur_village", villages_begin, villages_end),
          (neg|party_slot_ge, ":cur_village", slot_village_bound_center, 1), #skip villages which are already bound.
          (assign, ":min_dist", 999999),
          (assign, ":min_dist_town", -1),
          (try_for_range, ":cur_town", towns_begin, towns_end),
            (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_town"),
            (lt, ":cur_dist", ":min_dist"),
            (assign, ":min_dist", ":cur_dist"),
            (assign, ":min_dist_town", ":cur_town"),
          (try_end),
          (party_set_slot, ":cur_village", slot_village_bound_center, ":min_dist_town"),
          (store_faction_of_party, ":town_faction", ":min_dist_town"),
          (call_script, "script_give_center_to_faction_aux", ":cur_village", ":town_faction"),
        (try_end),
      (try_end),
               
      ]),

      # F&B end Dynamic World
 
use dynamic lists to point at the village and towns, so that you can walk through the list instead of using start and stop variables that have holes and out of order changes.  Hmm where was the dynamic list thread?
from    https://forums.taleworlds.com/index.php/topic,341079.0.html    the_Dragon modified from Lumos
That should make this easier for you.

  I like the idea.

 
gsanders said:
use dynamic lists to point at the village and towns, so that you can walk through the list instead of using start and stop variables that have holes and out of order changes.  Hmm where was the dynamic list thread?
from    https://forums.taleworlds.com/index.php/topic,341079.0.html    the_Dragon modified from Lumos
That should make this easier for you.

  I like the idea.
Something, something WSE arrays/dictionaries. Ye, idea is rly cool.
 
Adjusting the MS to use dynamic lists instead of constants is doable, but easy to mess up.
It requires replacing every reference of town-, castle-, village-, walled_center-, center- begin/end with corresponding list scripts.
These constants are used, dunno, 750 (?) times in the MS, with various commands:
(try_for_range); (store_random_in_range);(is_between)(val_sub);
The current Dynamic Settlement scripts are designed to automatically handle the fief range adjustment, so as not require such a major change to the MS.
 
Code:
############# place this above town_leave
   #F&B begin Dynamic World cheats 
    ("cheat_downgrade_to_village",
    [
      (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
      (eq, "$cheat_mode", 1),
      ],
      "Downgrade to village",
      [
      (call_script, "script_downgrade_to_village", "$g_encountered_party"),
      (change_screen_return),
      ]),
    ("cheat_build_village",
      [
      (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
      (eq, "$cheat_mode", 1),
      ],
      "Build new village",
      [
      (try_begin),
          (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
          (eq, ":town_lord", "trp_player"),
          (call_script, "script_build_village", -1),
      (else_try),
          (call_script, "script_build_village", "$g_encountered_party"),    
      (try_end),
      (change_screen_return),
      ]),
     ("cheat_build_castle",
      [
      (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
      (eq, "$cheat_mode", 1),
      ],
      "Build new Castle",
      [
      (try_begin),
          (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
          (eq, ":town_lord", "trp_player"),
          (call_script, "script_build_village", -1),
      (else_try),
          (call_script, "script_build_castle", "$g_encountered_party"),    
      (try_end),
      (change_screen_return),
      ]), 
    ("cheat_rename",
      [     
      (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord), 
      (this_or_next|eq, ":town_lord", "trp_player"),  
      (eq, "$cheat_mode", 1),
      ],
      "Rename fief",
      [
      (start_presentation, "prsnt_name_fief"),
      ]),
    #F&B end Dynamic World Cheats  

      ("town_leave",[],"Leave...",
##########..................... Add the code between #F&B begin and F&B end to the cheat menu ##############
("camp_cheat",
       [(ge, "$cheat_mode", 1)
        ], "CHEAT MENU!",
       [(jump_to_menu, "mnu_camp_cheat"),
        ],
       ),
      #F&B begin
      ("fb_cheat",
       [(ge, "$cheat_mode", 1)
      ], "Dynamic World Cheats",
      [(jump_to_menu, "mnu_fb_cheat"),
       ],
      ),
      #F&B end
      ("resume_travelling",[],"Resume travelling.",
##################..............Place this somewhere in game_menus###############
  #F&B begin Dynamic World Cheat Menu
  ("fb_cheat",0,
  "Behold the wonders of infinite power and use it wisely",
  "none",
  [
   ],
  [
  ("fb_cheat_build_village",[], "Build new village here",
    [ 
    (call_script, "script_build_village", -1),
    (change_screen_return),
     ]
  ),
  
  ("fb_cheat_build_castle",[], "Build new castle here",
    [
    (call_script, "script_build_castle", -1),
    (change_screen_return),
    ]
  ),
  
  ("fb_cheat_build_town",[], "Build new town here",
    [
    (call_script, "script_build_town", -1),
    (change_screen_return),
    ]
  ),
  ("fb_cheat_camp",[],"{!}Camp for 1 year at 50x speed",
       [
         (assign,"$g_camp_mode", 1),
         (assign, "$g_infinite_camping", 1),
         (assign, "$g_player_icon_state", pis_camping),
         (rest_for_hours_interactive, 24 * 365, 50), #1 year rest while not attackable with 50x speed
         (change_screen_return),
        ]
       ),
  ("fb_cheat_return",[], "Return",
    [
    (jump_to_menu, "mnu_camp"),
    ]
  ]
  ),
  #F&B end Dynamic World Cheat Menu

There is an error in the following code.
 
What kind of error?
The menu code is split into three parts, there are further instructions in the lines with lots of #################################.

In any case, I could see two problems:
Either you are copying more than the stuff between #F&B begin and #F&B end,
or you don't have the rename presentation. In that case, just remove the following lines:
Code:
("cheat_rename",
      [     
      (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
      (this_or_next|eq, ":town_lord", "trp_player"), 
      (eq, "$cheat_mode", 1),
      ],
      "Rename fief",
      [
      (start_presentation, "prsnt_name_fief"),
      ]),
 
Syntax Error.It was not clear which line and the problem is still not resolved.Line end 15252.I'm looking, but I do not know where the punctuation is wrong.

kXv6zD.jpg



 
Can you post line 15252?

is it possible, you copied one of these two lines by accident? They will give Syntax errors
      ("town_leave",[],"Leave...",
  ("resume_travelling",[],"Resume travelling.",

   
 
I did not copy.I thought it was a mistake.

Code:
  ("fb_cheat_return",[], "Return",
    [
    (jump_to_menu, "mnu_camp"),
    ]
    ),
  ]
  ),

I deleted the punctuation marks, so.  '']  ),''



 
I'm unable to replicate that error .
The code itself compiles fine.
All of the punctuation is required.
It's a separate menu, so it needs to be placed outside existing menus. Safest place would be at the very end right above the last "]"
Code:
#F&B begin Dynamic World Cheat Menu
  ("fb_cheat",0,
  "Behold the wonders of infinite power and use it wisely",
  "none",
  [
   ],
  [
  ("fb_cheat_build_village",[], "Build new village here",
    [ 
    (call_script, "script_build_village", -1),
    (change_screen_return),
     ]
  ),
  
  ("fb_cheat_build_castle",[], "Build new castle here",
    [
    (call_script, "script_build_castle", -1),
    (change_screen_return),
    ]
  ),
  
  ("fb_cheat_build_town",[], "Build new town here",
    [
    (call_script, "script_build_town", -1),
    (change_screen_return),
    ]
  ),
  ("fb_cheat_camp",[],"{!}Camp for 1 year at 50x speed",
       [
         (assign,"$g_camp_mode", 1),
         (assign, "$g_infinite_camping", 1),
         (assign, "$g_player_icon_state", pis_camping),
         (rest_for_hours_interactive, 24 * 365, 50), #1 year rest while not attackable with 50x speed
         (change_screen_return),
        ]
       ),
  ("fb_cheat_return",[], "Return",
    [
    (jump_to_menu, "mnu_camp"),
    ]
  ),
  ]
  ),
  #F&B end Dynamic World Cheat Menu

Edit:
Things fixed for next release:
-Functioning walkers in villages&towns,
-No more player clones in scenes
-Walled centers will have an initial garrison
 
No, that error  shouldn't occur. It's possible, those scripts are from Diplomacy and therefor not present in Native.  I'll have to check that, though I intend to release a test version first.

It should be possible to fix the error by replacing those script names:
script_start_give_center_to_lord with script_give_center_to_lord
script_start_refresh_village_defenders with script_refresh_village_defenders



Naus said:
It is normal to give the following kinds of errors.

ZOd8yV.jpg
 
I solved that error, I came up with this error, added the variables but it was not resolved.  :facepalm: :mrgreen:

lbEzEb.jpg
 
Back
Top Bottom