Ramaraunt1

Untitled

Jan 16th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 MB | None | 0 0
  1. # -*- coding: cp1254 -*-
  2. from header_common import *
  3. from header_operations import *
  4. from module_constants import *
  5. from module_constants import *
  6. from header_parties import *
  7. from header_skills import *
  8. from header_mission_templates import *
  9. from header_items import *
  10. from header_triggers import *
  11. from header_terrain_types import *
  12. from header_music import *
  13. from header_map_icons import *
  14. from ID_animations import *
  15. ##diplomacy start+
  16. from module_factions import dplmc_factions_begin, dplmc_factions_end, dplmc_non_generic_factions_begin
  17. ##diplomacy end+
  18.  
  19. ##diplomacy begin
  20. ##jrider reports
  21. from header_presentations import tf_left_align
  22. #### Autoloot improved by rubik begin
  23. from module_items import *
  24.  
  25. ## deprecated due to 1.165 operations
  26. # ibf_item_type_mask = 0x000000ff
  27.  
  28. # def set_item_difficulty():
  29. # item_difficulty = []
  30. # for i_item in xrange(len(items)):
  31. # item_difficulty.append((item_set_slot, i_item, dplmc_slot_item_difficulty, get_difficulty(items[i_item][6])))
  32. # return item_difficulty[:]
  33.  
  34. # def set_item_base_score():
  35. # item_base_score = []
  36. # for i_item in xrange(len(items)):
  37. # if items[i_item][3] & ibf_item_type_mask == itp_type_two_handed_wpn and items[i_item][3] & itp_two_handed == 0:
  38. # item_base_score.append((item_set_slot, i_item, dplmc_slot_two_handed_one_handed, 1))
  39. # type = items[i_item][3] & ibf_item_type_mask
  40. # if type >= itp_type_head_armor and type <= itp_type_hand_armor:
  41. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_head_armor, get_head_armor(items[i_item][6])))
  42. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_body_armor, get_body_armor(items[i_item][6])))
  43. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_leg_armor, get_leg_armor(items[i_item][6])))
  44. # elif type >= itp_type_one_handed_wpn and type <= itp_type_thrown and type != itp_type_shield:
  45. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_thrust_damage, get_thrust_damage(items[i_item][6])))
  46. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_swing_damage, get_swing_damage(items[i_item][6])))
  47. # elif type == itp_type_horse:
  48. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_horse_speed, get_missile_speed(items[i_item][6])))
  49. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_horse_armor, get_body_armor(items[i_item][6])))
  50. # elif type == itp_type_shield:
  51. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_shield_size, get_weapon_length(items[i_item][6])))
  52. # item_base_score.append((item_set_slot, i_item, dplmc_slot_item_shield_armor, get_body_armor(items[i_item][6])))
  53. # return item_base_score[:]
  54. # #### Autoloot improved by rubik end
  55.  
  56. ##diplomacy end
  57.  
  58. ####################################################################################################################
  59. # scripts is a list of script records.
  60. # Each script record contns the following two fields:
  61. # 1) Script id: The prefix "script_" will be inserted when referencing scripts.
  62. # 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
  63. ####################################################################################################################
  64.  
  65. def keys_array():
  66. keys_list = []
  67. for key_no in xrange(len(keys)):
  68. keys_list.append((troop_set_slot, "trp_temp_array_a", key_no, keys[key_no]))
  69. keys_list.append((troop_set_slot, "trp_temp_array_b", key_no, str_key_0+key_no))
  70. return keys_list[:]
  71.  
  72. scripts = [
  73.  
  74.  
  75. #script_game_start:
  76. # This script is called when a new game is started
  77. # INPUT: none
  78. ("game_start",
  79. [
  80. (faction_set_slot, "fac_player_supporters_faction", slot_faction_state, sfs_inactive),
  81.  
  82. (assign, "$g_player_luck", 200),
  83. (troop_set_slot, "trp_player", slot_troop_occupation, slto_kingdom_hero),
  84. (store_random_in_range, ":starting_training_ground", training_grounds_begin, training_grounds_end),
  85. (party_relocate_near_party, "p_main_party", ":starting_training_ground", 3),
  86. (str_store_troop_name, s5, "trp_player"),
  87. (party_set_name, "p_main_party", s5),
  88. (call_script, "script_update_party_creation_random_limits"),
  89. (assign, "$g_player_party_icon", -1),
  90.  
  91. #Warband changes begin -- set this early
  92. (try_for_range, ":npc", 0, kingdom_ladies_end),
  93. (this_or_next|eq, ":npc", "trp_player"),
  94. (is_between, ":npc", active_npcs_begin, kingdom_ladies_end),
  95. (troop_set_slot, ":npc", slot_troop_father, -1),
  96. (troop_set_slot, ":npc", slot_troop_mother, -1),
  97. (troop_set_slot, ":npc", slot_troop_guardian, -1),
  98. (troop_set_slot, ":npc", slot_troop_spouse, -1),
  99. (troop_set_slot, ":npc", slot_troop_betrothed, -1),
  100. (troop_set_slot, ":npc", slot_troop_prisoner_of_party, -1),
  101. (troop_set_slot, ":npc", slot_lady_last_suitor, -1),
  102. (troop_set_slot, ":npc", slot_troop_stance_on_faction_issue, -1),
  103.  
  104. (store_random_in_range, ":decision_seed", 0, 10000),
  105. (troop_set_slot, ":npc", slot_troop_set_decision_seed, ":decision_seed"), #currently not used
  106. (troop_set_slot, ":npc", slot_troop_temp_decision_seed, ":decision_seed"), #currently not used, holds for at least 24 hours
  107. (try_end),
  108.  
  109. (assign, "$g_lord_long_term_count", 0),
  110. ##diplomacy start+ Clear faction leader/marshall, since 0 is the player
  111. (try_for_range, ":faction_no", 0, dplmc_factions_end),
  112. (neq, ":faction_no", "fac_player_faction"),
  113. (neq, ":faction_no", "fac_player_supporters_faction"),
  114. (faction_set_slot, ":faction_no", slot_faction_leader, -1),
  115. (faction_set_slot, ":faction_no", slot_faction_marshall, -1),
  116. (try_end),
  117. ##diplomacy end+
  118.  
  119. (call_script, "script_initialize_banner_info"),
  120. (call_script, "script_initialize_item_info"),
  121. (call_script, "script_initialize_aristocracy"),
  122. (call_script, "script_initialize_npcs"),
  123. (assign, "$disable_npc_complaints", 0),
  124. #NPC companion changes end
  125.  
  126. # Setting random feast time
  127. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  128. (store_random_in_range, ":last_feast_time", 0, 312), #240 + 72
  129. (val_mul, ":last_feast_time", -1),
  130. (faction_set_slot, ":faction_no", slot_faction_last_feast_start_time, ":last_feast_time"),
  131. (try_end),
  132.  
  133. # Setting the random town sequence:
  134. (store_sub, ":num_towns", towns_end, towns_begin),
  135. (assign, ":num_iterations", ":num_towns"),
  136. (try_for_range, ":cur_town_no", 0, ":num_towns"),
  137. (troop_set_slot, "trp_random_town_sequence", ":cur_town_no", -1),
  138. (try_end),
  139. (assign, ":cur_town_no", 0),
  140. (try_for_range, ":unused", 0, ":num_iterations"),
  141. (store_random_in_range, ":random_no", 0, ":num_towns"),
  142. (assign, ":is_unique", 1),
  143. (try_for_range, ":cur_town_no_2", 0, ":num_towns"),
  144. (troop_slot_eq, "trp_random_town_sequence", ":cur_town_no_2", ":random_no"),
  145. (assign, ":is_unique", 0),
  146. (try_end),
  147. (try_begin),
  148. (eq, ":is_unique", 1),
  149. (troop_set_slot, "trp_random_town_sequence", ":cur_town_no", ":random_no"),
  150. (val_add, ":cur_town_no", 1),
  151. (else_try),
  152. (val_add, ":num_iterations", 1),
  153. (try_end),
  154. (try_end),
  155.  
  156. # Cultures:
  157. (faction_set_slot, "fac_culture_1", slot_faction_tier_1_troop, "trp_swadian_recruit"),
  158. (faction_set_slot, "fac_culture_1", slot_faction_tier_2_troop, "trp_swadian_militia"),
  159. (faction_set_slot, "fac_culture_1", slot_faction_tier_3_troop, "trp_swadian_footman"),
  160. (faction_set_slot, "fac_culture_1", slot_faction_tier_4_troop, "trp_swadian_infantry"),
  161. (faction_set_slot, "fac_culture_1", slot_faction_tier_5_troop, "trp_swadian_knight"),
  162.  
  163. (faction_set_slot, "fac_culture_2", slot_faction_tier_1_troop, "trp_vaegir_recruit"),
  164. (faction_set_slot, "fac_culture_2", slot_faction_tier_2_troop, "trp_vaegir_footman"),
  165. (faction_set_slot, "fac_culture_2", slot_faction_tier_3_troop, "trp_vaegir_veteran"),
  166. (faction_set_slot, "fac_culture_2", slot_faction_tier_4_troop, "trp_vaegir_infantry"),
  167. (faction_set_slot, "fac_culture_2", slot_faction_tier_5_troop, "trp_vaegir_knight"),
  168.  
  169. (faction_set_slot, "fac_culture_3", slot_faction_tier_1_troop, "trp_khergit_tribesman"),
  170. (faction_set_slot, "fac_culture_3", slot_faction_tier_2_troop, "trp_khergit_skirmisher"),
  171. (faction_set_slot, "fac_culture_3", slot_faction_tier_3_troop, "trp_khergit_horseman"),
  172. (faction_set_slot, "fac_culture_3", slot_faction_tier_4_troop, "trp_khergit_horse_archer"),
  173. (faction_set_slot, "fac_culture_3", slot_faction_tier_5_troop, "trp_khergit_veteran_horse_archer"),
  174.  
  175. (faction_set_slot, "fac_culture_4", slot_faction_tier_1_troop, "trp_nord_recruit"),
  176. (faction_set_slot, "fac_culture_4", slot_faction_tier_2_troop, "trp_nord_footman"),
  177. (faction_set_slot, "fac_culture_4", slot_faction_tier_3_troop, "trp_nord_trained_footman"),
  178. (faction_set_slot, "fac_culture_4", slot_faction_tier_4_troop, "trp_nord_warrior"),
  179. (faction_set_slot, "fac_culture_4", slot_faction_tier_5_troop, "trp_nord_veteran"),
  180.  
  181. (faction_set_slot, "fac_culture_5", slot_faction_tier_1_troop, "trp_rhodok_tribesman"),
  182. (faction_set_slot, "fac_culture_5", slot_faction_tier_2_troop, "trp_rhodok_spearman"),
  183. (faction_set_slot, "fac_culture_5", slot_faction_tier_3_troop, "trp_rhodok_trained_spearman"),
  184. (faction_set_slot, "fac_culture_5", slot_faction_tier_4_troop, "trp_rhodok_veteran_spearman"),
  185. (faction_set_slot, "fac_culture_5", slot_faction_tier_5_troop, "trp_rhodok_sergeant"),
  186.  
  187. (faction_set_slot, "fac_culture_6", slot_faction_tier_1_troop, "trp_sarranid_recruit"),
  188. (faction_set_slot, "fac_culture_6", slot_faction_tier_2_troop, "trp_sarranid_footman"),
  189. (faction_set_slot, "fac_culture_6", slot_faction_tier_3_troop, "trp_sarranid_archer"),
  190. (faction_set_slot, "fac_culture_6", slot_faction_tier_4_troop, "trp_sarranid_horseman"),
  191. (faction_set_slot, "fac_culture_6", slot_faction_tier_5_troop, "trp_sarranid_mamluke"),
  192.  
  193. (faction_set_slot, "fac_culture_1", slot_faction_town_walker_male_troop, "trp_town_walker_1"),
  194. (faction_set_slot, "fac_culture_1", slot_faction_town_walker_female_troop, "trp_town_walker_2"),
  195. (faction_set_slot, "fac_culture_1", slot_faction_village_walker_male_troop, "trp_village_walker_1"),
  196. (faction_set_slot, "fac_culture_1", slot_faction_village_walker_female_troop, "trp_village_walker_2"),
  197. (faction_set_slot, "fac_culture_1", slot_faction_town_spy_male_troop, "trp_spy_walker_1"),
  198. (faction_set_slot, "fac_culture_1", slot_faction_town_spy_female_troop, "trp_spy_walker_2"),
  199.  
  200. (faction_set_slot, "fac_culture_2", slot_faction_town_walker_male_troop, "trp_town_walker_1"),
  201. (faction_set_slot, "fac_culture_2", slot_faction_town_walker_female_troop, "trp_town_walker_2"),
  202. (faction_set_slot, "fac_culture_2", slot_faction_village_walker_male_troop, "trp_village_walker_1"),
  203. (faction_set_slot, "fac_culture_2", slot_faction_village_walker_female_troop, "trp_village_walker_2"),
  204. (faction_set_slot, "fac_culture_2", slot_faction_town_spy_male_troop, "trp_spy_walker_1"),
  205. (faction_set_slot, "fac_culture_2", slot_faction_town_spy_female_troop, "trp_spy_walker_2"),
  206.  
  207. (faction_set_slot, "fac_culture_3", slot_faction_town_walker_male_troop, "trp_khergit_townsman"),
  208. (faction_set_slot, "fac_culture_3", slot_faction_town_walker_female_troop, "trp_khergit_townswoman"),
  209. (faction_set_slot, "fac_culture_3", slot_faction_village_walker_male_troop, "trp_khergit_townsman"),
  210. (faction_set_slot, "fac_culture_3", slot_faction_village_walker_female_troop, "trp_khergit_townswoman"),
  211. (faction_set_slot, "fac_culture_3", slot_faction_town_spy_male_troop, "trp_spy_walker_1"),
  212. (faction_set_slot, "fac_culture_3", slot_faction_town_spy_female_troop, "trp_spy_walker_2"),
  213.  
  214. (faction_set_slot, "fac_culture_4", slot_faction_town_walker_male_troop, "trp_town_walker_1"),
  215. (faction_set_slot, "fac_culture_4", slot_faction_town_walker_female_troop, "trp_town_walker_2"),
  216. (faction_set_slot, "fac_culture_4", slot_faction_village_walker_male_troop, "trp_village_walker_1"),
  217. (faction_set_slot, "fac_culture_4", slot_faction_village_walker_female_troop, "trp_village_walker_2"),
  218. (faction_set_slot, "fac_culture_4", slot_faction_town_spy_male_troop, "trp_spy_walker_1"),
  219. (faction_set_slot, "fac_culture_4", slot_faction_town_spy_female_troop, "trp_spy_walker_2"),
  220.  
  221. (faction_set_slot, "fac_culture_5", slot_faction_town_walker_male_troop, "trp_town_walker_1"),
  222. (faction_set_slot, "fac_culture_5", slot_faction_town_walker_female_troop, "trp_town_walker_2"),
  223. (faction_set_slot, "fac_culture_5", slot_faction_village_walker_male_troop, "trp_village_walker_1"),
  224. (faction_set_slot, "fac_culture_5", slot_faction_village_walker_female_troop, "trp_village_walker_2"),
  225. (faction_set_slot, "fac_culture_5", slot_faction_town_spy_male_troop, "trp_spy_walker_1"),
  226. (faction_set_slot, "fac_culture_5", slot_faction_town_spy_female_troop, "trp_spy_walker_2"),
  227.  
  228. (faction_set_slot, "fac_culture_6", slot_faction_town_walker_male_troop, "trp_sarranid_townsman"),
  229. (faction_set_slot, "fac_culture_6", slot_faction_town_walker_female_troop, "trp_sarranid_townswoman"),
  230. (faction_set_slot, "fac_culture_6", slot_faction_village_walker_male_troop, "trp_sarranid_townsman"),
  231. (faction_set_slot, "fac_culture_6", slot_faction_village_walker_female_troop, "trp_sarranid_townswoman"),
  232. (faction_set_slot, "fac_culture_6", slot_faction_town_spy_male_troop, "trp_spy_walker_1"),
  233. (faction_set_slot, "fac_culture_6", slot_faction_town_spy_female_troop, "trp_spy_walker_2"),
  234.  
  235. (try_begin),
  236. (eq, "$cheat_mode", 1),
  237. (assign, reg3, "$cheat_mode"),
  238. (display_message, "@{!}DEBUG : Completed faction troop assignments, cheat mode: {reg3}"),
  239. (try_end),
  240.  
  241. # Factions:
  242. (faction_set_slot, "fac_kingdom_1", slot_faction_culture, "fac_culture_1"),
  243. (faction_set_slot, "fac_kingdom_1", slot_faction_leader, "trp_kingdom_1_lord"),
  244. (troop_set_slot, "trp_kingdom_1_lord", slot_troop_renown, 1200),
  245.  
  246. (faction_set_slot, "fac_kingdom_2", slot_faction_culture, "fac_culture_2"),
  247. (faction_set_slot, "fac_kingdom_2", slot_faction_leader, "trp_kingdom_2_lord"),
  248. (troop_set_slot, "trp_kingdom_2_lord", slot_troop_renown, 1200),
  249.  
  250. (faction_set_slot, "fac_kingdom_3", slot_faction_culture, "fac_culture_3"),
  251. (faction_set_slot, "fac_kingdom_3", slot_faction_leader, "trp_kingdom_3_lord"),
  252. (troop_set_slot, "trp_kingdom_3_lord", slot_troop_renown, 1200),
  253.  
  254. (faction_set_slot, "fac_kingdom_4", slot_faction_culture, "fac_culture_4"),
  255. (faction_set_slot, "fac_kingdom_4", slot_faction_leader, "trp_kingdom_4_lord"),
  256. (troop_set_slot, "trp_kingdom_4_lord", slot_troop_renown, 1200),
  257.  
  258. (faction_set_slot, "fac_kingdom_5", slot_faction_culture, "fac_culture_5"),
  259. (faction_set_slot, "fac_kingdom_5", slot_faction_leader, "trp_kingdom_5_lord"),
  260. (troop_set_slot, "trp_kingdom_5_lord", slot_troop_renown, 1200),
  261.  
  262. (faction_set_slot, "fac_kingdom_6", slot_faction_culture, "fac_culture_6"),
  263. (faction_set_slot, "fac_kingdom_6", slot_faction_leader, "trp_kingdom_6_lord"),
  264. (troop_set_slot, "trp_kingdom_6_lord", slot_troop_renown, 1200),
  265.  
  266. (assign, ":player_faction_culture", "fac_culture_1"),
  267. (faction_set_slot, "fac_player_supporters_faction", slot_faction_culture, ":player_faction_culture"),
  268. (faction_set_slot, "fac_player_faction", slot_faction_culture, ":player_faction_culture"),
  269.  
  270. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  271. (faction_set_slot, ":faction_no", slot_faction_marshall, -1),
  272. (try_end),
  273. (faction_set_slot, "fac_player_supporters_faction", slot_faction_marshall, "trp_player"),
  274. (call_script, "script_initialize_faction_troop_types"),
  275. ##diplomacy begin
  276. (call_script, "script_dplmc_init_domestic_policy"),
  277. ##diplomacy end
  278.  
  279.  
  280. # Towns:
  281. (try_for_range, ":item_no", trade_goods_begin, trade_goods_end),
  282. (store_sub, ":offset", ":item_no", trade_goods_begin),
  283. (val_add, ":offset", slot_town_trade_good_prices_begin),
  284. (try_for_range, ":center_no", centers_begin, centers_end),
  285. (party_set_slot, ":center_no", ":offset", average_price_factor), #1000
  286. (try_end),
  287. (try_end),
  288.  
  289. (call_script, "script_initialize_trade_routes"),
  290. (call_script, "script_initialize_town_arena_info"),
  291. #start some tournaments
  292. (try_for_range, ":town_no", towns_begin, towns_end),
  293. (store_random_in_range, ":rand", 0, 100),
  294. (lt, ":rand", 20),
  295. (store_random_in_range, ":random_days", 12, 15),
  296. (party_set_slot, ":town_no", slot_town_has_tournament, ":random_days"),
  297. (try_end),
  298.  
  299. #village products -- at some point we might make it so that the villages supply raw materials to towns, and the towns produce manufactured goods
  300. #village products designate the raw materials produced in the vicinity
  301. #right now, just doing a test for grain produced in the swadian heartland
  302.  
  303.  
  304. # fill_village_bound_centers
  305. #pass 1: Give one village to each castle
  306. (try_for_range, ":cur_center", castles_begin, castles_end),
  307. (assign, ":min_dist", 999999),
  308. (assign, ":min_dist_village", -1),
  309. (try_for_range, ":cur_village", villages_begin, villages_end),
  310. (neg|party_slot_ge, ":cur_village", slot_village_bound_center, 1), #skip villages which are already bound.
  311. (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_center"),
  312. (lt, ":cur_dist", ":min_dist"),
  313. (assign, ":min_dist", ":cur_dist"),
  314. (assign, ":min_dist_village", ":cur_village"),
  315. (try_end),
  316. (party_set_slot, ":min_dist_village", slot_village_bound_center, ":cur_center"),
  317. (store_faction_of_party, ":town_faction", ":cur_center"),
  318. (call_script, "script_give_center_to_faction_aux", ":min_dist_village", ":town_faction"),
  319. (try_end),
  320.  
  321.  
  322. #pass 2: Give other villages to closest town.
  323. (try_for_range, ":cur_village", villages_begin, villages_end),
  324. (neg|party_slot_ge, ":cur_village", slot_village_bound_center, 1), #skip villages which are already bound.
  325. (assign, ":min_dist", 999999),
  326. (assign, ":min_dist_town", -1),
  327. (try_for_range, ":cur_town", towns_begin, towns_end),
  328. (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_town"),
  329. (lt, ":cur_dist", ":min_dist"),
  330. (assign, ":min_dist", ":cur_dist"),
  331. (assign, ":min_dist_town", ":cur_town"),
  332. (try_end),
  333. (party_set_slot, ":cur_village", slot_village_bound_center, ":min_dist_town"),
  334. (store_faction_of_party, ":town_faction", ":min_dist_town"),
  335. (call_script, "script_give_center_to_faction_aux", ":cur_village", ":town_faction"),
  336. (try_end),
  337.  
  338.  
  339. # Towns (loop)
  340. (try_for_range, ":town_no", towns_begin, towns_end),
  341. (store_sub, ":offset", ":town_no", towns_begin),
  342. (party_set_slot,":town_no", slot_party_type, spt_town),
  343. #(store_add, ":cur_object_no", "trp_town_1_seneschal", ":offset"),
  344. #(party_set_slot,":town_no", slot_town_seneschal, ":cur_object_no"),
  345. (store_add, ":cur_object_no", "scn_town_1_center", ":offset"),
  346. (party_set_slot,":town_no", slot_town_center, ":cur_object_no"),
  347. (store_add, ":cur_object_no", "scn_town_1_castle", ":offset"),
  348. (party_set_slot,":town_no", slot_town_castle, ":cur_object_no"),
  349. (store_add, ":cur_object_no", "scn_town_1_prison", ":offset"),
  350. (party_set_slot,":town_no", slot_town_prison, ":cur_object_no"),
  351. (store_add, ":cur_object_no", "scn_town_1_walls", ":offset"),
  352. (party_set_slot,":town_no", slot_town_walls, ":cur_object_no"),
  353. (store_add, ":cur_object_no", "scn_town_1_tavern", ":offset"),
  354. (party_set_slot,":town_no", slot_town_tavern, ":cur_object_no"),
  355. (store_add, ":cur_object_no", "scn_town_1_store", ":offset"),
  356. (party_set_slot,":town_no", slot_town_store, ":cur_object_no"),
  357. (store_add, ":cur_object_no", "scn_town_1_arena", ":offset"),
  358. (party_set_slot,":town_no", slot_town_arena, ":cur_object_no"),
  359. (store_add, ":cur_object_no", "scn_town_1_alley", ":offset"),
  360. (party_set_slot,":town_no", slot_town_alley, ":cur_object_no"),
  361. (store_add, ":cur_object_no", "trp_town_1_mayor", ":offset"),
  362. (party_set_slot,":town_no", slot_town_elder, ":cur_object_no"),
  363. (store_add, ":cur_object_no", "trp_town_1_tavernkeeper", ":offset"),
  364. (party_set_slot,":town_no", slot_town_tavernkeeper, ":cur_object_no"),
  365. (store_add, ":cur_object_no", "trp_town_1_weaponsmith", ":offset"),
  366. (party_set_slot,":town_no", slot_town_weaponsmith, ":cur_object_no"),
  367. (store_add, ":cur_object_no", "trp_town_1_armorer", ":offset"),
  368. (party_set_slot,":town_no", slot_town_armorer, ":cur_object_no"),
  369. (store_add, ":cur_object_no", "trp_town_1_merchant", ":offset"),
  370. (party_set_slot,":town_no", slot_town_merchant, ":cur_object_no"),
  371. (store_add, ":cur_object_no", "trp_town_1_horse_merchant", ":offset"),
  372. (party_set_slot,":town_no", slot_town_horse_merchant, ":cur_object_no"),
  373. (store_add, ":cur_object_no", "scn_town_1_center", ":offset"),
  374. (party_set_slot,":town_no", slot_town_center, ":cur_object_no"),
  375. # (party_set_slot,":town_no", slot_town_reinforcement_party_template, "pt_center_reinforcements"),
  376. (try_end),
  377.  
  378. # Castles
  379. (try_for_range, ":castle_no", castles_begin, castles_end),
  380. (store_sub, ":offset", ":castle_no", castles_begin),
  381. (val_mul, ":offset", 3),
  382.  
  383. (store_add, ":exterior_scene_no", "scn_castle_1_exterior", ":offset"),
  384. (party_set_slot,":castle_no", slot_castle_exterior, ":exterior_scene_no"),
  385. (store_add, ":interior_scene_no", "scn_castle_1_interior", ":offset"),
  386. (party_set_slot,":castle_no", slot_town_castle, ":interior_scene_no"),
  387. (store_add, ":interior_scene_no", "scn_castle_1_prison", ":offset"),
  388. (party_set_slot,":castle_no", slot_town_prison, ":interior_scene_no"),
  389.  
  390. # (party_set_slot,":castle_no", slot_town_reinforcement_party_template, "pt_center_reinforcements"),
  391. (party_set_slot,":castle_no", slot_party_type, spt_castle),
  392. (party_set_slot,":castle_no", slot_center_is_besieged_by, -1),
  393. (try_end),
  394.  
  395. # Set which castles need to be attacked with siege towers.
  396. (party_set_slot,"p_town_13", slot_center_siege_with_belfry, 1),
  397. (party_set_slot,"p_town_16", slot_center_siege_with_belfry, 1),
  398.  
  399. (party_set_slot,"p_castle_1", slot_center_siege_with_belfry, 1),
  400. (party_set_slot,"p_castle_2", slot_center_siege_with_belfry, 1),
  401. (party_set_slot,"p_castle_4", slot_center_siege_with_belfry, 1),
  402. (party_set_slot,"p_castle_7", slot_center_siege_with_belfry, 1),
  403. (party_set_slot,"p_castle_8", slot_center_siege_with_belfry, 1),
  404. (party_set_slot,"p_castle_9", slot_center_siege_with_belfry, 1),
  405. (party_set_slot,"p_castle_11", slot_center_siege_with_belfry, 1),
  406. (party_set_slot,"p_castle_13", slot_center_siege_with_belfry, 1),
  407. (party_set_slot,"p_castle_21", slot_center_siege_with_belfry, 1),
  408. (party_set_slot,"p_castle_25", slot_center_siege_with_belfry, 1),
  409. (party_set_slot,"p_castle_34", slot_center_siege_with_belfry, 1),
  410. (party_set_slot,"p_castle_35", slot_center_siege_with_belfry, 1),
  411. (party_set_slot,"p_castle_38", slot_center_siege_with_belfry, 1),
  412. (party_set_slot,"p_castle_40", slot_center_siege_with_belfry, 1),
  413. (party_set_slot,"p_castle_41", slot_center_siege_with_belfry, 1),
  414. (party_set_slot,"p_castle_42", slot_center_siege_with_belfry, 1),
  415. (party_set_slot,"p_castle_43", slot_center_siege_with_belfry, 1),
  416.  
  417. # Villages characters
  418. (try_for_range, ":village_no", villages_begin, villages_end),
  419. (store_sub, ":offset", ":village_no", villages_begin),
  420.  
  421. (store_add, ":exterior_scene_no", "scn_village_1", ":offset"),
  422. (party_set_slot,":village_no", slot_castle_exterior, ":exterior_scene_no"),
  423.  
  424. (store_add, ":store_troop_no", "trp_village_1_elder", ":offset"),
  425. (party_set_slot,":village_no", slot_town_elder, ":store_troop_no"),
  426.  
  427. (party_set_slot,":village_no", slot_party_type, spt_village),
  428. (party_set_slot,":village_no", slot_village_raided_by, -1),
  429.  
  430. (call_script, "script_refresh_village_defenders", ":village_no"),
  431. (call_script, "script_refresh_village_defenders", ":village_no"),
  432. (call_script, "script_refresh_village_defenders", ":village_no"),
  433. (call_script, "script_refresh_village_defenders", ":village_no"),
  434. (try_end),
  435.  
  436. (try_for_range, ":center_no", centers_begin, centers_end),
  437. (party_set_slot, ":center_no", slot_center_last_spotted_enemy, -1),
  438. (party_set_slot, ":center_no", slot_center_is_besieged_by, -1),
  439. (party_set_slot, ":center_no", slot_center_last_taken_by_troop, -1),
  440. ##diplomacy start+ Set the home slots for town merchants, elders, etc. for reverse-lookup
  441. (try_for_range, ":offset", dplmc_slot_town_merchants_begin, dplmc_slot_town_merchants_end),
  442. (party_get_slot, ":npc", ":center_no", ":offset"),
  443. (gt, ":npc", 0),
  444. (neg|troop_slot_ge, ":npc", slot_troop_home, 1),#If the startup script wasn't altered by another mod, we don't have to worry about this condition.
  445. (troop_set_slot, ":npc", slot_troop_home, ":center_no"),
  446. (try_end),
  447. ##diplomacy end+
  448. (try_end),
  449.  
  450. # Troops:
  451.  
  452. # Assign banners and renown.
  453. # We assume there are enough banners for all kingdom heroes.
  454.  
  455. #faction banners
  456. (faction_set_slot, "fac_kingdom_1", slot_faction_banner, "mesh_banner_kingdom_f"),
  457. (faction_set_slot, "fac_kingdom_2", slot_faction_banner, "mesh_banner_kingdom_b"),
  458. (faction_set_slot, "fac_kingdom_3", slot_faction_banner, "mesh_banner_kingdom_c"),
  459. (faction_set_slot, "fac_kingdom_4", slot_faction_banner, "mesh_banner_kingdom_a"),
  460. (faction_set_slot, "fac_kingdom_5", slot_faction_banner, "mesh_banner_kingdom_d"),
  461. (faction_set_slot, "fac_kingdom_6", slot_faction_banner, "mesh_banner_kingdom_e"),
  462.  
  463. (try_for_range, ":cur_faction", npc_kingdoms_begin, npc_kingdoms_end),
  464. (faction_get_slot, ":cur_faction_king", ":cur_faction", slot_faction_leader),
  465. (faction_get_slot, ":cur_faction_banner", ":cur_faction", slot_faction_banner),
  466. (val_sub, ":cur_faction_banner", banner_meshes_begin),
  467. (val_add, ":cur_faction_banner", banner_scene_props_begin),
  468. (troop_set_slot, ":cur_faction_king", slot_troop_banner_scene_prop, ":cur_faction_banner"),
  469. (try_end),
  470. (assign, ":num_khergit_lords_assigned", 0),
  471. (assign, ":num_sarranid_lords_assigned", 0),
  472. (assign, ":num_other_lords_assigned", 0),
  473.  
  474. (try_for_range, ":kingdom_hero", active_npcs_begin, active_npcs_end),
  475. (this_or_next|troop_slot_eq, ":kingdom_hero", slot_troop_occupation, slto_kingdom_hero),
  476. (troop_slot_eq, ":kingdom_hero", slot_troop_occupation, slto_inactive_pretender),
  477.  
  478. (store_troop_faction, ":kingdom_hero_faction", ":kingdom_hero"),
  479. (neg|faction_slot_eq, ":kingdom_hero_faction", slot_faction_leader, ":kingdom_hero"),
  480. (try_begin),
  481. (eq, ":kingdom_hero_faction", "fac_kingdom_3"), #Khergit Khanate
  482. (store_add, ":kingdom_3_banners_begin", banner_scene_props_begin, khergit_banners_begin_offset),
  483. (store_add, ":banner_id", ":kingdom_3_banners_begin", ":num_khergit_lords_assigned"),
  484. (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":banner_id"),
  485. (val_add, ":num_khergit_lords_assigned", 1),
  486. (else_try),
  487. (eq, ":kingdom_hero_faction", "fac_kingdom_6"), #Sarranid Sultanate
  488. (store_add, ":kingdom_6_banners_begin", banner_scene_props_begin, sarranid_banners_begin_offset),
  489. (store_add, ":banner_id", ":kingdom_6_banners_begin", ":num_sarranid_lords_assigned"),
  490. (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":banner_id"),
  491. (val_add, ":num_sarranid_lords_assigned", 1),
  492. (else_try),
  493. (assign, ":hero_offset", ":num_other_lords_assigned"),
  494. (try_begin),
  495. (gt, ":hero_offset", khergit_banners_begin_offset),#Do not add khergit banners to other lords
  496. (val_add, ":hero_offset", khergit_banners_end_offset),
  497. (val_sub, ":hero_offset", khergit_banners_begin_offset),
  498. (try_end),
  499. (try_begin),
  500. (gt, ":hero_offset", sarranid_banners_begin_offset),#Do not add sarranid banners to other lords
  501. (val_add, ":hero_offset", sarranid_banners_end_offset),
  502. (val_sub, ":hero_offset", sarranid_banners_begin_offset),
  503. (try_end),
  504. (store_add, ":banner_id", banner_scene_props_begin, ":hero_offset"),
  505. (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":banner_id"),
  506. (val_add, ":num_other_lords_assigned", 1),
  507. (try_end),
  508. (try_begin),
  509. (this_or_next|lt, ":banner_id", banner_scene_props_begin),
  510. (gt, ":banner_id", banner_scene_props_end_minus_one),
  511. (display_message, "@{!}ERROR: Not enough banners for heroes!"),
  512. (try_end),
  513.  
  514. (store_character_level, ":level", ":kingdom_hero"),
  515. (store_mul, ":renown", ":level", ":level"),
  516. (val_div, ":renown", 4), #for top lord, is about 400
  517.  
  518. (troop_get_slot, ":age", ":kingdom_hero", slot_troop_age),
  519. (store_mul, ":age_addition", ":age", ":age"),
  520. (val_div, ":age_addition", 8), #for top lord, is about 400
  521. (val_add, ":renown", ":age_addition"),
  522.  
  523. (try_begin),
  524. (faction_slot_eq, ":kingdom_hero_faction", slot_faction_leader, ":kingdom_hero"),
  525. (store_random_in_range, ":random_renown", 250, 400),
  526. (else_try),
  527. (store_random_in_range, ":random_renown", 0, 100),
  528. (try_end),
  529. (val_add, ":renown", ":random_renown"),
  530.  
  531. (troop_set_slot, ":kingdom_hero", slot_troop_renown, ":renown"),
  532. (try_end),
  533.  
  534. (try_for_range, ":troop_no", "trp_player", "trp_merchants_end"),
  535. (add_troop_note_tableau_mesh, ":troop_no", "tableau_troop_note_mesh"),
  536. (try_end),
  537.  
  538. (try_for_range, ":center_no", centers_begin, centers_end),
  539. (add_party_note_tableau_mesh, ":center_no", "tableau_center_note_mesh"),
  540. (try_end),
  541.  
  542. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  543. (is_between, ":faction_no", "fac_kingdom_1", kingdoms_end), #Excluding player kingdom
  544. (add_faction_note_tableau_mesh, ":faction_no", "tableau_faction_note_mesh"),
  545. (else_try),
  546. (add_faction_note_tableau_mesh, ":faction_no", "tableau_faction_note_mesh_banner"),
  547. (try_end),
  548.  
  549. #Give centers to factions first, to ensure more equal distributions
  550. (call_script, "script_give_center_to_faction_aux", "p_town_1", "fac_kingdom_4"),
  551. (call_script, "script_give_center_to_faction_aux", "p_town_2", "fac_kingdom_4"),
  552. (call_script, "script_give_center_to_faction_aux", "p_town_3", "fac_kingdom_5"),
  553. (call_script, "script_give_center_to_faction_aux", "p_town_4", "fac_kingdom_1"),
  554. (call_script, "script_give_center_to_faction_aux", "p_town_5", "fac_kingdom_5"),
  555. (call_script, "script_give_center_to_faction_aux", "p_town_6", "fac_kingdom_1"),
  556. (call_script, "script_give_center_to_faction_aux", "p_town_7", "fac_kingdom_1"),
  557. (call_script, "script_give_center_to_faction_aux", "p_town_8", "fac_kingdom_2"),
  558. (call_script, "script_give_center_to_faction_aux", "p_town_9", "fac_kingdom_2"),
  559. (call_script, "script_give_center_to_faction_aux", "p_town_10", "fac_kingdom_3"),
  560. (call_script, "script_give_center_to_faction_aux", "p_town_11", "fac_kingdom_2"),
  561. (call_script, "script_give_center_to_faction_aux", "p_town_12", "fac_kingdom_4"),
  562. (call_script, "script_give_center_to_faction_aux", "p_town_13", "fac_kingdom_2"),
  563. (call_script, "script_give_center_to_faction_aux", "p_town_14", "fac_kingdom_3"),
  564. (call_script, "script_give_center_to_faction_aux", "p_town_15", "fac_kingdom_5"),
  565. (call_script, "script_give_center_to_faction_aux", "p_town_16", "fac_kingdom_1"),
  566. (call_script, "script_give_center_to_faction_aux", "p_town_17", "fac_kingdom_3"),
  567. (call_script, "script_give_center_to_faction_aux", "p_town_18", "fac_kingdom_3"),
  568. (call_script, "script_give_center_to_faction_aux", "p_town_19", "fac_kingdom_6"),
  569. (call_script, "script_give_center_to_faction_aux", "p_town_20", "fac_kingdom_6"),
  570. (call_script, "script_give_center_to_faction_aux", "p_town_21", "fac_kingdom_6"),
  571. (call_script, "script_give_center_to_faction_aux", "p_town_22", "fac_kingdom_6"),
  572.  
  573. (call_script, "script_give_center_to_faction_aux", "p_castle_1", "fac_kingdom_5"),
  574. (call_script, "script_give_center_to_faction_aux", "p_castle_2", "fac_kingdom_3"),
  575. (call_script, "script_give_center_to_faction_aux", "p_castle_3", "fac_kingdom_2"),
  576. (call_script, "script_give_center_to_faction_aux", "p_castle_4", "fac_kingdom_2"),
  577. (call_script, "script_give_center_to_faction_aux", "p_castle_5", "fac_kingdom_4"),
  578. (call_script, "script_give_center_to_faction_aux", "p_castle_6", "fac_kingdom_1"),
  579. (call_script, "script_give_center_to_faction_aux", "p_castle_7", "fac_kingdom_3"),
  580. (call_script, "script_give_center_to_faction_aux", "p_castle_8", "fac_kingdom_2"),
  581. (call_script, "script_give_center_to_faction_aux", "p_castle_9", "fac_kingdom_5"),
  582. (call_script, "script_give_center_to_faction_aux", "p_castle_10", "fac_kingdom_4"),
  583. (call_script, "script_give_center_to_faction_aux", "p_castle_11", "fac_kingdom_4"),
  584.  
  585. (call_script, "script_give_center_to_faction_aux", "p_castle_12", "fac_kingdom_4"),
  586. (call_script, "script_give_center_to_faction_aux", "p_castle_13", "fac_kingdom_1"),
  587. (call_script, "script_give_center_to_faction_aux", "p_castle_14", "fac_kingdom_5"),
  588. (call_script, "script_give_center_to_faction_aux", "p_castle_15", "fac_kingdom_5"),
  589. (call_script, "script_give_center_to_faction_aux", "p_castle_16", "fac_kingdom_5"),
  590. (call_script, "script_give_center_to_faction_aux", "p_castle_17", "fac_kingdom_3"),
  591. (call_script, "script_give_center_to_faction_aux", "p_castle_18", "fac_kingdom_2"),
  592. (call_script, "script_give_center_to_faction_aux", "p_castle_19", "fac_kingdom_2"),
  593. (call_script, "script_give_center_to_faction_aux", "p_castle_20", "fac_kingdom_1"),
  594.  
  595. (call_script, "script_give_center_to_faction_aux", "p_castle_21", "fac_kingdom_5"),
  596. (call_script, "script_give_center_to_faction_aux", "p_castle_22", "fac_kingdom_3"),
  597. (call_script, "script_give_center_to_faction_aux", "p_castle_23", "fac_kingdom_1"),
  598. (call_script, "script_give_center_to_faction_aux", "p_castle_24", "fac_kingdom_1"),
  599.  
  600. (call_script, "script_give_center_to_faction_aux", "p_castle_25", "fac_kingdom_1"),
  601. (call_script, "script_give_center_to_faction_aux", "p_castle_26", "fac_kingdom_1"),
  602. (call_script, "script_give_center_to_faction_aux", "p_castle_27", "fac_kingdom_1"),
  603. (call_script, "script_give_center_to_faction_aux", "p_castle_28", "fac_kingdom_5"),
  604.  
  605. (call_script, "script_give_center_to_faction_aux", "p_castle_29", "fac_kingdom_2"),
  606. (call_script, "script_give_center_to_faction_aux", "p_castle_30", "fac_kingdom_3"),
  607. (call_script, "script_give_center_to_faction_aux", "p_castle_31", "fac_kingdom_1"),
  608.  
  609. (call_script, "script_give_center_to_faction_aux", "p_castle_32", "fac_kingdom_4"),
  610. (call_script, "script_give_center_to_faction_aux", "p_castle_33", "fac_kingdom_5"),
  611. (call_script, "script_give_center_to_faction_aux", "p_castle_34", "fac_kingdom_4"),
  612. (call_script, "script_give_center_to_faction_aux", "p_castle_35", "fac_kingdom_1"),
  613.  
  614. (call_script, "script_give_center_to_faction_aux", "p_castle_36", "fac_kingdom_4"),
  615. (call_script, "script_give_center_to_faction_aux", "p_castle_37", "fac_kingdom_2"),
  616. (call_script, "script_give_center_to_faction_aux", "p_castle_38", "fac_kingdom_3"),
  617. (call_script, "script_give_center_to_faction_aux", "p_castle_39", "fac_kingdom_2"),
  618. (call_script, "script_give_center_to_faction_aux", "p_castle_40", "fac_kingdom_3"),
  619.  
  620. (call_script, "script_give_center_to_faction_aux", "p_castle_41", "fac_kingdom_6"),
  621. (call_script, "script_give_center_to_faction_aux", "p_castle_42", "fac_kingdom_6"),
  622. (call_script, "script_give_center_to_faction_aux", "p_castle_43", "fac_kingdom_6"),
  623. (call_script, "script_give_center_to_faction_aux", "p_castle_44", "fac_kingdom_6"),
  624. (call_script, "script_give_center_to_faction_aux", "p_castle_45", "fac_kingdom_6"),
  625. (call_script, "script_give_center_to_faction_aux", "p_castle_46", "fac_kingdom_6"),
  626. (call_script, "script_give_center_to_faction_aux", "p_castle_47", "fac_kingdom_6"),
  627. (call_script, "script_give_center_to_faction_aux", "p_castle_48", "fac_kingdom_6"),
  628.  
  629.  
  630. #Now give towns to great lords
  631. ##diplomacy+ notes added, otherwise unchanged
  632. (call_script, "script_give_center_to_lord", "p_town_1", "trp_kingdom_4_lord", 0),# Sargoth - King Ragnar
  633. (call_script, "script_give_center_to_lord", "p_town_2", "trp_knight_4_1", 0),#Tihr - Jarl Aedin
  634. (call_script, "script_give_center_to_lord", "p_town_3", "trp_knight_5_1", 0),#Veluca - Count Matheas
  635. (call_script, "script_give_center_to_lord", "p_town_4", "trp_knight_1_1", 0),#Suno - Count Klargus
  636. (call_script, "script_give_center_to_lord", "p_town_5", "trp_kingdom_5_lord", 0),# Jelkala - King Graveth
  637. (call_script, "script_give_center_to_lord", "p_town_6", "trp_kingdom_1_lord", 0),# Praven - King Harlaus
  638. (call_script, "script_give_center_to_lord", "p_town_7", "trp_knight_1_2", 0),#Uxkhal - Count Delinard
  639.  
  640. (call_script, "script_give_center_to_lord", "p_town_8", "trp_kingdom_2_lord", 0),# Reyvadin - King Yaroglek
  641. (call_script, "script_give_center_to_lord", "p_town_9", "trp_knight_2_1", 0),#Khudan -Boyar Vuldrat
  642. (call_script, "script_give_center_to_lord", "p_town_10", "trp_kingdom_3_lord", 0),# Tulga - Sanjar Khan
  643. (call_script, "script_give_center_to_lord", "p_town_11", "trp_knight_2_2", 0),#Curaw - Boyar Naldera
  644. (call_script, "script_give_center_to_lord", "p_town_12", "trp_knight_4_2", 0),#Wercheg - Jarl Irya
  645. (call_script, "script_give_center_to_lord", "p_town_13", "trp_knight_2_3", 0),#Rivacheg - Boyar Meriga
  646. (call_script, "script_give_center_to_lord", "p_town_14", "trp_knight_3_1", 0),#Halmar -Alagur Noyan
  647.  
  648. (call_script, "script_give_center_to_lord", "p_town_15", "trp_knight_5_2", 0),#Yalen -Count Gutlans
  649. (call_script, "script_give_center_to_lord", "p_town_16", "trp_knight_1_4", 0),#Dhirim - Count Clais #changed from 1_3 (Count Harringoth)
  650. (call_script, "script_give_center_to_lord", "p_town_17", "trp_knight_3_2", 0),#Ichamur - Tonju Noyan
  651. (call_script, "script_give_center_to_lord", "p_town_18", "trp_knight_3_3", 0),#Narra - Belir Noyan
  652.  
  653. (call_script, "script_give_center_to_lord", "p_town_19", "trp_kingdom_6_lord", 0),#Shariz - Sultan Hakim
  654. (call_script, "script_give_center_to_lord", "p_town_20", "trp_knight_6_1", 0),#Durquba - Emir Uqais
  655. (call_script, "script_give_center_to_lord", "p_town_21", "trp_knight_6_2", 0),#Ahmerrad - Emir Hamezan
  656. (call_script, "script_give_center_to_lord", "p_town_22", "trp_knight_6_3", 0),#Bariyye - Emir Atis
  657. ##diplomacy end+
  658.  
  659. # Give family castles to certain nobles.
  660. (call_script, "script_give_center_to_lord", "p_castle_29", "trp_knight_2_10", 0), #Nelag_Castle
  661. (call_script, "script_give_center_to_lord", "p_castle_30", "trp_knight_3_4", 0), #Asugan_Castle
  662. (call_script, "script_give_center_to_lord", "p_castle_35", "trp_knight_1_3", 0), #Haringoth_Castle
  663. ##diplomacy start+
  664. (call_script, "script_give_center_to_lord", "p_castle_33", "trp_knight_5_11", 0), #Etrosq Castle -- why wasn't this being done already?
  665. #Add home centers for claimants
  666. (troop_set_slot, "trp_kingdom_1_pretender", slot_troop_home, "p_town_4"),#Lady Isolle - Suno
  667. (troop_set_slot, "trp_kingdom_2_pretender", slot_troop_home, "p_town_11"),#Prince Valdym - Curaw
  668. (troop_set_slot, "trp_kingdom_3_pretender", slot_troop_home, "p_town_18"),#Dustum Khan - Narra
  669. (troop_set_slot, "trp_kingdom_4_pretender", slot_troop_home, "p_town_12"),#Lethwin Far-Seeker - Wercheg
  670. (troop_set_slot, "trp_kingdom_5_pretender", slot_troop_home, "p_town_3"),#Lord Kastor - Veluca
  671. (troop_set_slot, "trp_kingdom_6_pretender", slot_troop_home, "p_town_20"),#Arwa the Pearled One - Durquba
  672. #add ancestral fiefs to home slots (mods not using standard NPCs should remove this)
  673. (troop_set_slot, "trp_knight_2_10", slot_troop_home, "p_castle_29"), #Nelag_Castle
  674. (troop_set_slot, "trp_knight_3_4", slot_troop_home, "p_castle_30"), #Asugan_Castle
  675. (troop_set_slot, "trp_knight_1_3", slot_troop_home, "p_castle_35"), #Haringoth_Castle
  676. (troop_set_slot, "trp_knight_5_11", slot_troop_home, "p_castle_33"), #Etrosq_Castle
  677. #Also the primary six towns:
  678. (troop_set_slot, "trp_kingdom_1_lord", slot_troop_home, "p_town_6"),#King Harlaus to Praven
  679. (troop_set_slot, "trp_kingdom_2_lord", slot_troop_home, "p_town_8"),#King Yaroglek to Reyvadin
  680. (troop_set_slot, "trp_kingdom_3_lord", slot_troop_home, "p_town_10"),#Sanjar Khan to Tulga
  681. (troop_set_slot, "trp_kingdom_4_lord", slot_troop_home, "p_town_1"),#King Ragnar to Sargoth
  682. (troop_set_slot, "trp_kingdom_5_lord", slot_troop_home, "p_town_5"),#King Graveth to Jelkala
  683. (troop_set_slot, "trp_kingdom_6_lord", slot_troop_home, "p_town_19"),#Sultan Hakim to Shariz
  684. ##Also set home slots for starting quest merchants (merchant of praven, merchant of reyvadin, etc.)
  685. (try_for_range, ":npc", kings_begin, kings_end),
  686. (troop_get_slot, ":center_no", ":npc", slot_troop_home),
  687. (val_sub, ":npc", kings_begin),
  688. (val_add, ":npc", startup_merchants_begin),
  689. (is_between, ":npc", startup_merchants_begin, startup_merchants_end),#Right now there's a startup merchant for each faction. Verify this hasn't unexpectedly changed.
  690. (neg|troop_slot_ge, ":npc", slot_troop_home, 1),#Verify that the home slot is not already set
  691. (troop_set_slot, ":npc", slot_troop_home, ":center_no"),
  692. (try_end),
  693. ##diplomacy end+
  694.  
  695. (call_script, "script_assign_lords_to_empty_centers"),
  696.  
  697. #set original factions
  698. (try_for_range, ":center_no", centers_begin, centers_end),
  699. (store_faction_of_party, ":original_faction", ":center_no"),
  700. (faction_get_slot, ":culture", ":original_faction", slot_faction_culture),
  701. (party_set_slot, ":center_no", slot_center_culture, ":culture"),
  702. (party_set_slot, ":center_no", slot_center_original_faction, ":original_faction"),
  703. (party_set_slot, ":center_no", slot_center_ex_faction, ":original_faction"),
  704. ##diplomacy start+ set additional slots
  705. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  706.  
  707. (try_begin),
  708. (eq, ":town_lord", "trp_player"),
  709. #Use trp_kingdom_heroes_including_player_begin instead of trp_player as a workaround for
  710. #old saved games (since uninitialized memory is 0).
  711. (party_set_slot, ":center_no", dplmc_slot_center_ex_lord, "trp_kingdom_heroes_including_player_begin"),
  712. (troop_slot_eq, "trp_player", slot_troop_home, ":center_no"),
  713. (neg|party_slot_ge, ":center_no", dplmc_slot_center_original_lord, 1),
  714. (party_set_slot, ":center_no", dplmc_slot_center_original_lord, "trp_kingdom_heroes_including_player_begin"),
  715. (else_try),
  716. (party_set_slot, ":center_no", dplmc_slot_center_ex_lord, ":town_lord"),
  717. (ge, ":town_lord", 0),
  718. (troop_slot_eq, ":town_lord", slot_troop_home, ":center_no"),
  719. (neg|party_slot_ge, ":center_no", dplmc_slot_center_original_lord, 1),
  720. (party_set_slot, ":center_no", dplmc_slot_center_original_lord, ":town_lord"),
  721. (try_end),
  722. ##diplomacy end+
  723. (try_end),
  724.  
  725. #set territorial disputes/outstanding border issues
  726. (party_set_slot, "p_castle_10", slot_center_ex_faction, "fac_kingdom_2"), #vaegirs claim nord-held alburq
  727. (party_set_slot, "p_castle_13", slot_center_ex_faction, "fac_kingdom_4"), #nords claim swadian-held kelredan
  728. (party_set_slot, "p_castle_15", slot_center_ex_faction, "fac_kingdom_1"), #swadians claim rhodok-held ergelon
  729. (party_set_slot, "p_castle_46", slot_center_ex_faction, "fac_kingdom_5"), #rhodoks claim sarranid-held weyyah
  730. (party_set_slot, "p_castle_40", slot_center_ex_faction, "fac_kingdom_6"), #sarranids claim khergit-held uhhun
  731. (party_set_slot, "p_town_11", slot_center_ex_faction, "fac_kingdom_3"), #Khergits claim vaegir-held curaw
  732.  
  733. #Swadians, being in the middle, will have additional claims on two of their neighhbors
  734. (party_set_slot, "p_castle_15", slot_center_ex_faction, "fac_kingdom_1"), #swadians claim vaegir-held tilbault
  735. (party_set_slot, "p_castle_22", slot_center_ex_faction, "fac_kingdom_1"), #swadians claim khergit-held unuzdaq
  736.  
  737. (call_script, "script_update_village_market_towns"),
  738.  
  739. ##diplomacy start+
  740. #(1) Assign plausible ancestral homes to some of the lords (not all of them) who didn't have
  741. #one set before. Among other things, this is used for a sense of possessiveness.
  742. #(2) Assign last-transfer-times to the contested centers.
  743. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  744. (try_begin),
  745. #Assign last-transfer-times to the contested centers.
  746. (party_get_slot, ":original_faction", ":center_no", slot_center_original_faction),
  747. (neg|party_slot_eq, ":center_no", slot_center_ex_faction, ":original_faction"),
  748. (store_random_in_range, ":transfer_time", 1, 181),#some time in the last 180 days (the length of a short game)
  749. (val_mul, ":transfer_time", -24),
  750. (party_set_slot, ":center_no", dplmc_slot_center_last_transfer_time, ":transfer_time"),
  751. (else_try),
  752. #For non-contested centers, possibly set the lord's home slot. Note that because
  753. #we're iterating in order, lords will get set to towns they own before they get
  754. #set to cities.
  755. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  756. (ge, ":town_lord", 1),#only NPCs
  757. (neg|party_slot_ge, ":center_no", dplmc_slot_center_original_lord, 1),#If there is an original owner who is dispossessed, such as a claimant
  758. (neg|troop_slot_ge, ":town_lord", slot_troop_home, 1),
  759. (troop_set_slot, ":town_lord", slot_troop_home, ":center_no"),
  760. (try_end),
  761. (try_end),
  762.  
  763. # (try_for_range, ":troop_id", heroes_begin, heroes_end),
  764. # (try_end),
  765. #
  766. #etc.
  767. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  768. #If the original owner of the lord is set, don't apply this
  769. (neg|party_slot_ge, ":center_no", dplmc_slot_center_original_lord, 1),
  770. #Don't apply this to contested centers.
  771. (party_get_slot, ":original_faction", ":center_no", slot_center_original_faction),
  772. (party_slot_eq, ":center_no", slot_center_ex_faction, ":original_faction"),
  773. #If the owner already has his "home" slot set, don't overwrite it
  774. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  775. (neg|troop_slot_ge, ":town_lord", slot_troop_home, 1),
  776. #No objections, so go ahead
  777. (troop_set_slot, ":town_lord", slot_troop_home, ":center_no"),
  778. (try_end),
  779. ##diplomacy end+
  780.  
  781. #this should come after assignment of territorial grievances
  782. (try_for_range, ":unused", 0, 70),
  783. (try_begin),
  784. (eq, "$cheat_mode", 1),
  785. (display_message, "@{!}DEBUG -- initial war/peace check begins"),
  786. (try_end),
  787. (call_script, "script_randomly_start_war_peace_new", 0),
  788. (try_end),
  789.  
  790.  
  791. #Initialize walkers
  792. (try_for_range, ":center_no", centers_begin, centers_end),
  793. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  794. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  795. (try_for_range, ":walker_no", 0, num_town_walkers),
  796. (call_script, "script_center_set_walker_to_type", ":center_no", ":walker_no", walkert_default),
  797. (try_end),
  798. (try_end),
  799.  
  800.  
  801. #This needs to be after market towns
  802. (call_script, "script_initialize_economic_information"),
  803.  
  804. (try_for_range, ":village_no", villages_begin, villages_end),
  805. (call_script, "script_refresh_village_merchant_inventory", ":village_no"),
  806. (try_end),
  807.  
  808. (try_for_range, ":troop_id", original_kingdom_heroes_begin, active_npcs_end),
  809. (try_begin),
  810. (store_troop_faction, ":faction_id", ":troop_id"),
  811. (is_between, ":faction_id", kingdoms_begin, kingdoms_end),
  812. (troop_set_slot, ":troop_id", slot_troop_original_faction, ":faction_id"),
  813. (try_begin),
  814. (is_between, ":troop_id", pretenders_begin, pretenders_end),
  815. (faction_set_slot, ":faction_id", slot_faction_has_rebellion_chance, 1),
  816. (try_end),
  817. (try_end),
  818. (assign, ":initial_wealth", 6000),
  819. (try_begin),
  820. (store_troop_faction, ":faction", ":troop_id"),
  821. (faction_slot_eq, ":faction", slot_faction_leader, ":troop_id"),
  822. (assign, ":initial_wealth", 20000),
  823. (try_end),
  824. (troop_set_slot, ":troop_id", slot_troop_wealth, ":initial_wealth"),
  825. (try_end),
  826.  
  827. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),#add town garrisons
  828. #Add initial center wealth
  829. (assign, ":initial_wealth", 2000),
  830. (try_begin),
  831. (is_between, ":center_no", towns_begin, towns_end),
  832. (val_mul, ":initial_wealth", 2),
  833. (try_end),
  834. (party_set_slot, ":center_no", slot_town_wealth, ":initial_wealth"),
  835.  
  836. (assign, ":garrison_strength", 15),
  837. (try_begin),
  838. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  839. (assign, ":garrison_strength", 40),
  840. (try_end),
  841. (try_for_range, ":unused", 0, ":garrison_strength"),
  842. (call_script, "script_cf_reinforce_party", ":center_no"),
  843. (try_end),
  844. ## ADD some XP initially
  845. (store_div, ":xp_rounds", ":garrison_strength", 5),
  846. (val_add, ":xp_rounds", 2),
  847.  
  848. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  849.  
  850. (try_begin), #hard
  851. (eq, ":reduce_campaign_ai", 0),
  852. (assign, ":xp_addition_for_centers", 7500),
  853. (else_try), #moderate
  854. (eq, ":reduce_campaign_ai", 1),
  855. (assign, ":xp_addition_for_centers", 5000),
  856. (else_try), #easy
  857. (eq, ":reduce_campaign_ai", 2),
  858. (assign, ":xp_addition_for_centers", 2500),
  859. (try_end),
  860.  
  861. (try_for_range, ":unused", 0, ":xp_rounds"),
  862. (party_upgrade_with_xp, ":center_no", ":xp_addition_for_centers", 0),
  863. (try_end),
  864.  
  865. #Fill town food stores upto half the limit
  866. (call_script, "script_center_get_food_store_limit", ":center_no"),
  867. (assign, ":food_store_limit", reg0),
  868. (val_div, ":food_store_limit", 2),
  869. (party_set_slot, ":center_no", slot_party_food_store, ":food_store_limit"),
  870.  
  871. #create lord parties
  872. (party_get_slot, ":center_lord", ":center_no", slot_town_lord),
  873. (ge, ":center_lord", 1),
  874. (troop_slot_eq, ":center_lord", slot_troop_leaded_party, 0),
  875. (assign, "$g_there_is_no_avaliable_centers", 0),
  876. (call_script, "script_create_kingdom_hero_party", ":center_lord", ":center_no"),
  877. (assign, ":lords_party", "$pout_party"),
  878. (party_attach_to_party, ":lords_party", ":center_no"),
  879. (party_set_slot, ":center_no", slot_town_player_odds, 1000),
  880. (try_end),
  881.  
  882. #More pre-Warband family structures removed here
  883.  
  884. #Warband changes begin - set companions relations
  885. (try_for_range, ":companion", companions_begin, companions_end),
  886. (try_for_range, ":other_companion", companions_begin, companions_end),
  887. (neq, ":other_companion", ":companion"),
  888. (neg|troop_slot_eq, ":companion", slot_troop_personalityclash_object, ":other_companion"),
  889. (neg|troop_slot_eq, ":companion", slot_troop_personalityclash2_object, ":other_companion"),
  890. (call_script, "script_troop_change_relation_with_troop", ":companion", ":other_companion", 7), #companions have a starting relation of 14, unless they are rivals
  891. (try_end),
  892. (try_end),
  893.  
  894. #Warband changes continue - sets relations in the same faction
  895. (try_for_range, ":lord", original_kingdom_heroes_begin, active_npcs_end),
  896. (troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  897. (troop_get_slot, ":lord_faction", ":lord", slot_troop_original_faction),
  898.  
  899. (try_for_range, ":other_hero", original_kingdom_heroes_begin, active_npcs_end),
  900. (this_or_next|troop_slot_eq, ":other_hero", slot_troop_occupation, slto_kingdom_hero),
  901. (troop_slot_eq, ":other_hero", slot_troop_occupation, slto_inactive_pretender),
  902. (troop_get_slot, ":other_hero_faction", ":other_hero", slot_troop_original_faction),
  903. (eq, ":other_hero_faction", ":lord_faction"),
  904. (call_script, "script_troop_get_family_relation_to_troop", ":lord", ":other_hero"),
  905. (call_script, "script_troop_change_relation_with_troop", ":lord", ":other_hero", reg0),
  906.  
  907. (store_random_in_range, ":random", 0, 11), #this will be scored twice between two kingdom heroes, so starting relation will average 10. Between lords and pretenders it will average 7.5
  908. (call_script, "script_troop_change_relation_with_troop", ":lord", ":other_hero", ":random"),
  909. (try_end),
  910. (try_end),
  911.  
  912. ##diplomacy start+
  913. ##Initialize town "last caravan arrived" times randomly
  914. (try_for_range, ":cur_town", towns_begin, towns_end),
  915. (try_for_range, ":cur_slot", dplmc_slot_town_trade_route_last_arrivals_begin, dplmc_slot_town_trade_route_last_arrivals_end),
  916. (party_slot_eq, ":cur_town", ":cur_slot", 0),
  917. (store_random_in_range, ":last_arrived", 1, (24 * 7 * 5) + 1),#some time in the last five weeks
  918. (val_mul, ":last_arrived", -1),
  919. (party_get_slot, ":prosperity_factor", ":cur_town", slot_town_prosperity),#modify plus or minus 40% based on prosperity
  920. (val_clamp, ":prosperity_factor", 0, 101),
  921. (val_add, ":prosperity_factor", 75),
  922. (val_mul, ":last_arrived", 125),
  923. (val_div, ":last_arrived", ":prosperity_factor"),#last arrival some time in the last five weeks, plus or minus 40%
  924. (party_set_slot, ":cur_town", ":cur_slot", ":last_arrived"),
  925. (try_end),
  926. (try_end),
  927. (try_for_range, ":cur_village", villages_begin, villages_end),
  928. (party_get_slot, ":prosperity_factor", ":cur_town", slot_town_prosperity),#modify plus or minus 40% based on prosperity
  929. (val_clamp, ":prosperity_factor", 0, 101),
  930. (val_add, ":prosperity_factor", 75),#average 125, min 75, max 175
  931. (store_random_in_range, ":last_arrived", 1, (24 * 7) + 1),
  932. (val_mul, ":last_arrived", -1),#some time in the last 7 days, plus or minus 40%
  933. (val_mul, ":last_arrived", 125),
  934. (val_div, ":last_arrived", ":prosperity_factor"),
  935. (party_set_slot, ":cur_village", dplmc_slot_village_trade_last_returned_from_market, ":last_arrived"),
  936. (store_random_in_range, ":last_arrived", 1, (24 * 7) + 1),
  937. (val_mul, ":last_arrived", -1),#some time in the last 7 days
  938. (val_mul, ":last_arrived", 125),
  939. (val_div, ":last_arrived", ":prosperity_factor"),
  940. (party_set_slot, ":cur_village", dplmc_slot_village_trade_last_arrived_to_market, ":last_arrived"),
  941. (try_end),
  942. ##diplomacy end+
  943.  
  944. #do about 5 years' worth of political history (assuming 3 random checks a day)
  945. (try_for_range, ":unused", 0, 5000),
  946. (call_script, "script_cf_random_political_event"),
  947. (try_end),
  948. (assign, "$total_random_quarrel_changes", 0),
  949. (assign, "$total_relation_adds", 0),
  950. (assign, "$total_relation_subs", 0),
  951.  
  952. (try_for_range, ":kingdom", kingdoms_begin, kingdoms_end),
  953. (call_script, "script_evaluate_realm_stability", ":kingdom"),
  954. (try_end),
  955. #Warband changes end
  956.  
  957. (try_begin),
  958. (eq, "$cheat_mode", 1),
  959. (assign, reg3, "$cheat_mode"),
  960. (display_message, "@{!}DEBUG : Completed political events, cheat mode: {reg3}"),
  961. (try_end),
  962.  
  963. #assign love interests to unmarried male lords
  964. (try_for_range, ":cur_troop", lords_begin, lords_end),
  965. (troop_slot_eq, ":cur_troop", slot_troop_spouse, -1),
  966. ##diplomacy start+ Also bypass this for characters that start with manually-assigned fiancees
  967. (troop_slot_eq, ":cur_troop", slot_troop_betrothed, -1),
  968. ##diplomacy end+
  969. (neg|is_between, ":cur_troop", kings_begin, kings_end),
  970. (neg|is_between, ":cur_troop", pretenders_begin, pretenders_end),
  971.  
  972. (call_script, "script_assign_troop_love_interests", ":cur_troop"),
  973. (try_end),
  974.  
  975. (store_random_in_range, "$romantic_attraction_seed", 0, 5),
  976.  
  977. (try_begin),
  978. (eq, "$cheat_mode", 1),
  979. (assign, reg3, "$romantic_attraction_seed"),
  980. (display_message, "@{!}DEBUG : Assigned love interests. Attraction seed: {reg3}"),
  981. (try_end),
  982.  
  983. #we need to spawn more bandits in warband, because map is bigger.
  984. #(try_for_range, ":unused", 0, 7),
  985. # (call_script, "script_spawn_bandits"),
  986. #(try_end),
  987.  
  988. #(set_spawn_radius, 50),
  989. #(try_for_range, ":unused", 0, 25),
  990. # (spawn_around_party, "p_main_party", "pt_looters"),
  991. #(try_end),
  992.  
  993. (try_for_range, ":unused", 0, 10),
  994. (call_script, "script_spawn_bandits"),
  995. (try_end),
  996.  
  997. #we are adding looter parties around each village with 1/5 probability.
  998. (set_spawn_radius, 5),
  999. (try_for_range, ":cur_village", villages_begin, villages_end),
  1000. (store_random_in_range, ":random_value", 0, 5),
  1001. (eq, ":random_value", 0),
  1002. (spawn_around_party, ":cur_village", "pt_looters"),
  1003. (try_end),
  1004.  
  1005. (call_script, "script_update_mercenary_units_of_towns"),
  1006. (call_script, "script_update_companion_candidates_in_taverns"),
  1007. (call_script, "script_update_ransom_brokers"),
  1008. (call_script, "script_update_tavern_travellers"),
  1009. (call_script, "script_update_tavern_minstrels"),
  1010. (call_script, "script_update_booksellers"),
  1011.  
  1012. (try_for_range, ":village_no", villages_begin, villages_end),
  1013. (call_script, "script_update_volunteer_troops_in_village", ":village_no"),
  1014. (try_end),
  1015.  
  1016. (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
  1017. (call_script, "script_update_faction_notes", ":cur_kingdom"),
  1018. (store_random_in_range, ":random_no", -60, 0),
  1019. ##diplomacy start+
  1020. #The above is a random time in the last 60 hours, but that's probably a mistake.
  1021. #Change to a time within the last 60 days.
  1022. (val_mul, ":random_no", 24),
  1023. ##diplomacy end+
  1024. (faction_set_slot, ":faction_no", slot_faction_last_offensive_concluded, ":random_no"),
  1025. (try_end),
  1026.  
  1027. (try_for_range, ":cur_troop", original_kingdom_heroes_begin, active_npcs_end),
  1028. (call_script, "script_update_troop_notes", ":cur_troop"),
  1029. (try_end),
  1030.  
  1031. (try_for_range, ":cur_center", centers_begin, centers_end),
  1032. ##diplomacy start+
  1033. (party_get_slot, ":original_faction", ":center_no", slot_center_original_faction),
  1034. (try_begin),
  1035. #Assign plausible last-transfer-times to the contested centers based
  1036. #on the "last offensive concluded" slot of the controlling faction.
  1037. (is_between, ":original_faction", kingdoms_begin, kingdoms_end),
  1038. (neg|party_slot_eq, ":center_no", slot_center_ex_faction, ":original_faction"),
  1039. (faction_get_slot, reg0, ":original_faction", slot_faction_last_offensive_concluded),
  1040. (party_set_slot, ":center_no", dplmc_slot_center_last_transfer_time, reg0),
  1041. (try_end),
  1042. ##diplomacy end+
  1043. (call_script, "script_update_center_notes", ":cur_center"),
  1044. (try_end),
  1045.  
  1046. (call_script, "script_update_troop_notes", "trp_player"),
  1047.  
  1048. #Place kingdom ladies
  1049. (try_for_range, ":troop_id", kingdom_ladies_begin, kingdom_ladies_end),
  1050. (call_script, "script_get_kingdom_lady_social_determinants", ":troop_id"),
  1051. (troop_set_slot, ":troop_id", slot_troop_cur_center, reg1),
  1052. ##diplomacy start+
  1053. #Set their original faction.
  1054. (ge, reg0, 0),
  1055. (troop_get_slot, ":original_faction", reg0, slot_troop_original_faction),
  1056. (troop_set_slot, ":troop_id", slot_troop_original_faction, ":original_faction"),
  1057. ##diplomacy end+
  1058. (try_end),
  1059.  
  1060. ##diplomacy start+
  1061. ##Set initial relations between kingdom ladies and their relatives.
  1062. ##Do *not* initialize their relations with anyone they aren't related to:
  1063. ##that is used for courtship.
  1064. ## The purpose of this initialization is so if a kingdom lady gets promoted,
  1065. ##her relations aren't a featureless slate. Also, it would be interesting to
  1066. ##further develop the idea of ladies as pursuing agendas even if they aren't
  1067. ##leading warbands, which would benefit from giving them relations with other
  1068. ##people.
  1069. (try_for_range, ":lady", kingdom_ladies_begin, kingdom_ladies_end),
  1070. (troop_slot_eq, ":lady", slot_troop_occupation, slto_kingdom_lady),
  1071. (troop_get_slot, ":lady_faction", ":lady", slot_troop_original_faction),
  1072.  
  1073. (try_for_range, ":other_hero", heroes_begin, heroes_end),
  1074. (this_or_next|troop_slot_eq, ":other_hero", slot_troop_occupation, slto_kingdom_lady),
  1075. (this_or_next|troop_slot_eq, ":other_hero", slot_troop_occupation, slto_kingdom_hero),
  1076. (troop_slot_eq, ":other_hero", slot_troop_occupation, slto_inactive_pretender),
  1077. (troop_slot_eq, ":other_hero", slot_troop_original_faction, ":lady_faction"),
  1078.  
  1079. (neq, ":other_hero", ":lady"),
  1080. (try_begin),
  1081. (this_or_next|troop_slot_eq, ":lady", slot_troop_spouse, ":other_hero"),
  1082. (troop_slot_eq, ":other_hero", slot_troop_spouse, ":lady"),
  1083. (store_random_in_range, reg0, 0, 11),
  1084. (else_try),
  1085. (call_script, "script_troop_get_family_relation_to_troop", ":lady", ":other_hero"),
  1086. (try_end),
  1087. (call_script, "script_troop_change_relation_with_troop", ":lady", ":other_hero", reg0),
  1088.  
  1089. #This relation change only applies between kingdom ladies.
  1090. (troop_slot_eq, ":other_hero", slot_troop_occupation, slto_kingdom_lady),
  1091. (is_between, ":other_hero", kingdom_ladies_begin, kingdom_ladies_end),
  1092.  
  1093. (store_random_in_range, ":random", 0, 11),
  1094. (call_script, "script_troop_change_relation_with_troop", ":lady", ":other_hero", ":random"),
  1095. (try_end),
  1096. (try_end),
  1097. ##diplomacy end+
  1098.  
  1099.  
  1100. (try_begin),
  1101. (eq, "$cheat_mode", 1),
  1102. (assign, reg3, "$cheat_mode"),
  1103. (display_message, "@{!}DEBUG : Located kingdom ladies, cheat mode: {reg3}"),
  1104. (try_end),
  1105.  
  1106. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  1107. (call_script, "script_faction_recalculate_strength", ":faction_no"),
  1108. (try_end),
  1109.  
  1110. (faction_set_slot, "fac_kingdom_1", slot_faction_adjective, "str_kingdom_1_adjective"),
  1111. (faction_set_slot, "fac_kingdom_2", slot_faction_adjective, "str_kingdom_2_adjective"),
  1112. (faction_set_slot, "fac_kingdom_3", slot_faction_adjective, "str_kingdom_3_adjective"),
  1113. (faction_set_slot, "fac_kingdom_4", slot_faction_adjective, "str_kingdom_4_adjective"),
  1114. (faction_set_slot, "fac_kingdom_5", slot_faction_adjective, "str_kingdom_5_adjective"),
  1115. (faction_set_slot, "fac_kingdom_6", slot_faction_adjective, "str_kingdom_6_adjective"),
  1116.  
  1117. ## (assign, "$players_kingdom", "fac_kingdom_1"),
  1118. ## (call_script, "script_give_center_to_lord", "p_town_7", "trp_player", 0),
  1119. ## (call_script, "script_give_center_to_lord", "p_town_16", "trp_player", 0),
  1120. #### (call_script, "script_give_center_to_lord", "p_castle_10", "trp_player", 0),
  1121. ## (assign, "$g_castle_requested_by_player", "p_castle_10"),
  1122. (call_script, "script_get_player_party_morale_values"),
  1123. (party_set_morale, "p_main_party", reg0),
  1124.  
  1125. (troop_set_note_available, "trp_player", 1),
  1126.  
  1127. (try_for_range, ":troop_no", kings_begin, kings_end),
  1128. (troop_set_note_available, ":troop_no", 1),
  1129. (try_end),
  1130.  
  1131. (try_for_range, ":troop_no", lords_begin, lords_end),
  1132. (troop_set_note_available, ":troop_no", 1),
  1133. (try_end),
  1134.  
  1135. (try_for_range, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  1136. (troop_set_note_available, ":troop_no", 1),
  1137. (try_end),
  1138. (troop_set_note_available, "trp_knight_1_1_wife", 0),
  1139.  
  1140. (try_for_range, ":troop_no", pretenders_begin, pretenders_end),
  1141. (troop_set_note_available, ":troop_no", 1),
  1142. (try_end),
  1143.  
  1144. #Lady and companion notes become available as you meet/recruit them
  1145.  
  1146. (try_for_range, ":faction_no", npc_kingdoms_begin, npc_kingdoms_end),
  1147. (faction_set_note_available, ":faction_no", 1),
  1148. (try_end),
  1149. (faction_set_note_available, "fac_neutral", 0),
  1150.  
  1151. (try_for_range, ":party_no", centers_begin, centers_end),
  1152. (party_set_note_available, ":party_no", 1),
  1153. (try_end),
  1154.  
  1155. ##diplomacy start+
  1156. #Perform initialization for autoloot / autosell.
  1157. (call_script, "script_dplmc_initialize_autoloot", 1),#argument "1" forces this to make changes
  1158. #Set the version number (this slot on this troop should never be used for anything else)
  1159. #The lowest 7 bits of the slot are a verification code. They should always be equal to 68,
  1160. # unless there is no version number set. The rest of the slot is the version number.
  1161. (troop_set_slot, "trp_dplmc_chamberlain", dplmc_slot_troop_affiliated, (DPLMC_CURRENT_VERSION_CODE * 128) + DPLMC_VERSION_LOW_7_BITS),#Version number 1
  1162. ##diplomacy end+
  1163.  
  1164. #SB : default parameters for post-battle continuation
  1165. (call_script, "script_setup_camera_keys"),
  1166. (assign, "$g_dplmc_cam_default", camera_keyboard),
  1167. (assign, "$g_dplmc_player_disguise", disguise_pilgrim),
  1168. (assign, "$g_dplmc_charge_when_dead", 1),
  1169.  
  1170. #SB : training ground slots
  1171. (try_for_range, ":npc", training_ground_trainers_begin, training_ground_trainers_end),
  1172. #init trainer vars
  1173. (troop_set_slot, ":npc", slot_troop_trainer_met, 0),
  1174. (troop_set_slot, ":npc", slot_troop_trainer_waiting_for_result, 0),
  1175. (troop_set_slot, ":npc", slot_troop_trainer_training_fight_won, 0),
  1176. (troop_set_slot, ":npc", slot_troop_trainer_num_opponents_to_beat, 3),
  1177. (troop_set_slot, ":npc", slot_troop_trainer_training_system_explained, 0),
  1178. (troop_set_slot, ":npc", slot_troop_trainer_opponent_troop, fighters_begin),
  1179. (troop_set_slot, ":npc", slot_troop_trainer_training_difficulty, 0),
  1180.  
  1181. (store_sub, ":offset", ":npc", training_ground_trainers_begin),
  1182. #init grounds vars
  1183. (store_add, ":grounds", ":offset", training_grounds_begin),
  1184. (store_add, ":scene", ":offset", "scn_training_ground_ranged_melee_1"),
  1185. (party_set_slot, ":grounds", slot_grounds_melee, ":scene"),
  1186. (store_add, ":scene", ":offset", "scn_training_ground_horse_track_1"),
  1187. (party_set_slot, ":grounds", slot_grounds_track, ":scene"),
  1188. (party_set_slot, ":grounds", slot_grounds_trainer, ":npc"),
  1189. (party_set_slot, ":grounds", slot_grounds_count, 0),
  1190. (troop_set_slot, ":npc", slot_troop_cur_center, ":grounds"),
  1191. (try_end),
  1192. ]),
  1193.  
  1194. #script_game_get_use_string
  1195. # This script is called from the game engine for getting using information text
  1196. # INPUT: used_scene_prop_id
  1197. # OUTPUT: s0
  1198. ("game_get_use_string",
  1199. [
  1200. (store_script_param, ":instance_id", 1),
  1201.  
  1202. (prop_instance_get_scene_prop_kind, ":scene_prop_id", ":instance_id"),
  1203.  
  1204. (try_begin),
  1205. (this_or_next|eq, ":scene_prop_id", "spr_winch_b"),
  1206. (eq, ":scene_prop_id", "spr_winch"),
  1207. (assign, ":effected_object", "spr_portcullis"),
  1208. (else_try),
  1209. (this_or_next|eq, ":scene_prop_id", "spr_door_destructible"),
  1210. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_door_b"),
  1211. (this_or_next|eq, ":scene_prop_id", "spr_castle_e_sally_door_a"),
  1212. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_sally_door_a"),
  1213. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_left"),
  1214. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_right"),
  1215. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_left"),
  1216. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_right"),
  1217. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_door_a"),
  1218. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_6m"),
  1219. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_8m"),
  1220. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_10m"),
  1221. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_12m"),
  1222. (eq, ":scene_prop_id", "spr_siege_ladder_move_14m"),
  1223. (assign, ":effected_object", ":scene_prop_id"),
  1224. (try_end),
  1225.  
  1226. (scene_prop_get_slot, ":item_situation", ":instance_id", scene_prop_open_or_close_slot),
  1227.  
  1228. (try_begin), #opening/closing portcullis
  1229. (eq, ":effected_object", "spr_portcullis"),
  1230.  
  1231. (try_begin),
  1232. (eq, ":item_situation", 0),
  1233. (str_store_string, s0, "str_open_gate"),
  1234. (else_try),
  1235. (str_store_string, s0, "str_close_gate"),
  1236. (try_end),
  1237. #INVASION MODE START
  1238. (else_try),
  1239. #(display_message, "@could it be?"),
  1240. (eq, ":scene_prop_id", "spr_multiplayer_coop_item_drop"),
  1241. #(display_message, "@one of those!"),
  1242. (str_store_string, s0, "str_coop_open_chest"),
  1243. (multiplayer_get_my_player, ":player_no"),
  1244. (try_for_range, ":cur_slot", slot_player_coop_opened_chests_begin, slot_player_coop_opened_chests_end),
  1245. (player_get_slot, ":cur_instance", ":player_no", ":cur_slot"),
  1246. (try_begin),
  1247. (eq, ":cur_instance", ":instance_id"),
  1248. (neg|is_presentation_active, "prsnt_coop_assign_drop_to_group_member"),
  1249. (str_store_string, s0, "str_coop_already_opened"),
  1250. (try_end),
  1251. (try_end),
  1252. #INVASION MODE END
  1253. (else_try), #opening/closing door
  1254. (this_or_next|eq, ":effected_object", "spr_door_destructible"),
  1255. (this_or_next|eq, ":effected_object", "spr_castle_f_door_b"),
  1256. (this_or_next|eq, ":effected_object", "spr_castle_e_sally_door_a"),
  1257. (this_or_next|eq, ":effected_object", "spr_castle_f_sally_door_a"),
  1258. (this_or_next|eq, ":effected_object", "spr_earth_sally_gate_left"),
  1259. (this_or_next|eq, ":effected_object", "spr_earth_sally_gate_right"),
  1260. (this_or_next|eq, ":effected_object", "spr_viking_keep_destroy_sally_door_left"),
  1261. (this_or_next|eq, ":effected_object", "spr_viking_keep_destroy_sally_door_right"),
  1262. (eq, ":effected_object", "spr_castle_f_door_a"),
  1263.  
  1264. (try_begin),
  1265. (eq, ":item_situation", 0),
  1266. (str_store_string, s0, "str_open_door"),
  1267. (else_try),
  1268. (str_store_string, s0, "str_close_door"),
  1269. (try_end),
  1270. (else_try), #raising/dropping ladder
  1271. (try_begin),
  1272. (eq, ":item_situation", 0),
  1273. (str_store_string, s0, "str_raise_ladder"),
  1274. (else_try),
  1275. (str_store_string, s0, "str_drop_ladder"),
  1276. (try_end),
  1277. (try_end),
  1278. ]),
  1279.  
  1280. #script_game_quick_start
  1281. # This script is called from the game engine for initializing the global variables for tutorial, multiplayer and custom battle modes.
  1282. # INPUT:
  1283. # none
  1284. # OUTPUT:
  1285. # none
  1286. ("game_quick_start",
  1287. [
  1288. #for quick battle mode
  1289. (assign, "$g_is_quick_battle", 0),
  1290. (assign, "$g_quick_battle_game_type", 0),
  1291. (assign, "$g_quick_battle_troop", quick_battle_troops_begin),
  1292. (assign, "$g_quick_battle_map", quick_battle_scenes_begin),
  1293. (assign, "$g_quick_battle_team_1_faction", "fac_kingdom_1"),
  1294. (assign, "$g_quick_battle_team_2_faction", "fac_kingdom_2"),
  1295. (assign, "$g_quick_battle_army_1_size", 25),
  1296. (assign, "$g_quick_battle_army_2_size", 25),
  1297.  
  1298. (faction_set_slot, "fac_outlaws", slot_faction_quick_battle_tier_1_infantry, "trp_mountain_bandit"),
  1299. (faction_set_slot, "fac_outlaws", slot_faction_quick_battle_tier_2_infantry, "trp_sea_raider"),
  1300. (faction_set_slot, "fac_outlaws", slot_faction_quick_battle_tier_1_archer, "trp_forest_bandit"),
  1301. (faction_set_slot, "fac_outlaws", slot_faction_quick_battle_tier_2_archer, "trp_taiga_bandit"),
  1302. (faction_set_slot, "fac_outlaws", slot_faction_quick_battle_tier_1_cavalry, "trp_steppe_bandit"),
  1303. (faction_set_slot, "fac_outlaws", slot_faction_quick_battle_tier_2_cavalry, "trp_desert_bandit"),
  1304. (faction_set_slot, "fac_kingdom_1", slot_faction_quick_battle_tier_1_infantry, "trp_swadian_footman"),
  1305. (faction_set_slot, "fac_kingdom_1", slot_faction_quick_battle_tier_2_infantry, "trp_swadian_infantry"),
  1306. (faction_set_slot, "fac_kingdom_1", slot_faction_quick_battle_tier_1_archer, "trp_swadian_skirmisher"),
  1307. (faction_set_slot, "fac_kingdom_1", slot_faction_quick_battle_tier_2_archer, "trp_swadian_crossbowman"),
  1308. (faction_set_slot, "fac_kingdom_1", slot_faction_quick_battle_tier_1_cavalry, "trp_swadian_man_at_arms"),
  1309. (faction_set_slot, "fac_kingdom_1", slot_faction_quick_battle_tier_2_cavalry, "trp_swadian_knight"),
  1310. (faction_set_slot, "fac_kingdom_2", slot_faction_quick_battle_tier_1_infantry, "trp_vaegir_footman"),
  1311. (faction_set_slot, "fac_kingdom_2", slot_faction_quick_battle_tier_2_infantry, "trp_vaegir_infantry"),
  1312. (faction_set_slot, "fac_kingdom_2", slot_faction_quick_battle_tier_1_archer, "trp_vaegir_skirmisher"),
  1313. (faction_set_slot, "fac_kingdom_2", slot_faction_quick_battle_tier_2_archer, "trp_vaegir_archer"),
  1314. (faction_set_slot, "fac_kingdom_2", slot_faction_quick_battle_tier_1_cavalry, "trp_vaegir_horseman"),
  1315. (faction_set_slot, "fac_kingdom_2", slot_faction_quick_battle_tier_2_cavalry, "trp_vaegir_knight"),
  1316. (faction_set_slot, "fac_kingdom_3", slot_faction_quick_battle_tier_1_infantry, "trp_khergit_dismounted_lancer_multiplayer_ai"),
  1317. (faction_set_slot, "fac_kingdom_3", slot_faction_quick_battle_tier_2_infantry, "trp_khergit_dismounted_lancer_multiplayer_ai"),
  1318. (faction_set_slot, "fac_kingdom_3", slot_faction_quick_battle_tier_1_archer, "trp_khergit_horse_archer"),
  1319. (faction_set_slot, "fac_kingdom_3", slot_faction_quick_battle_tier_2_archer, "trp_khergit_veteran_horse_archer"),
  1320. (faction_set_slot, "fac_kingdom_3", slot_faction_quick_battle_tier_1_cavalry, "trp_khergit_lancer"),
  1321. (faction_set_slot, "fac_kingdom_3", slot_faction_quick_battle_tier_2_cavalry, "trp_khergit_lancer"),
  1322. (faction_set_slot, "fac_kingdom_4", slot_faction_quick_battle_tier_1_infantry, "trp_nord_warrior"),
  1323. (faction_set_slot, "fac_kingdom_4", slot_faction_quick_battle_tier_2_infantry, "trp_nord_champion"),
  1324. (faction_set_slot, "fac_kingdom_4", slot_faction_quick_battle_tier_1_archer, "trp_nord_archer"),
  1325. (faction_set_slot, "fac_kingdom_4", slot_faction_quick_battle_tier_2_archer, "trp_nord_veteran_archer"),
  1326. (faction_set_slot, "fac_kingdom_4", slot_faction_quick_battle_tier_1_cavalry, "trp_nord_scout_multiplayer_ai"),
  1327. (faction_set_slot, "fac_kingdom_4", slot_faction_quick_battle_tier_2_cavalry, "trp_nord_scout_multiplayer_ai"),
  1328. (faction_set_slot, "fac_kingdom_5", slot_faction_quick_battle_tier_1_infantry, "trp_rhodok_veteran_spearman"),
  1329. (faction_set_slot, "fac_kingdom_5", slot_faction_quick_battle_tier_2_infantry, "trp_rhodok_sergeant"),
  1330. (faction_set_slot, "fac_kingdom_5", slot_faction_quick_battle_tier_1_archer, "trp_rhodok_crossbowman"),
  1331. (faction_set_slot, "fac_kingdom_5", slot_faction_quick_battle_tier_2_archer, "trp_rhodok_veteran_crossbowman"),
  1332. (faction_set_slot, "fac_kingdom_5", slot_faction_quick_battle_tier_1_cavalry, "trp_rhodok_scout_multiplayer_ai"),
  1333. (faction_set_slot, "fac_kingdom_5", slot_faction_quick_battle_tier_2_cavalry, "trp_rhodok_scout_multiplayer_ai"),
  1334. (faction_set_slot, "fac_kingdom_6", slot_faction_quick_battle_tier_1_infantry, "trp_sarranid_veteran_footman"),
  1335. (faction_set_slot, "fac_kingdom_6", slot_faction_quick_battle_tier_2_infantry, "trp_sarranid_infantry"),
  1336. (faction_set_slot, "fac_kingdom_6", slot_faction_quick_battle_tier_1_archer, "trp_sarranid_skirmisher"),
  1337. (faction_set_slot, "fac_kingdom_6", slot_faction_quick_battle_tier_2_archer, "trp_sarranid_archer"),
  1338. (faction_set_slot, "fac_kingdom_6", slot_faction_quick_battle_tier_1_cavalry, "trp_sarranid_horseman"),
  1339. (faction_set_slot, "fac_kingdom_6", slot_faction_quick_battle_tier_2_cavalry, "trp_sarranid_mamluke"),
  1340.  
  1341. #for multiplayer mode
  1342. (assign, "$g_multiplayer_selected_map", multiplayer_scenes_begin),
  1343. (assign, "$g_multiplayer_respawn_period", 5),
  1344. (assign, "$g_multiplayer_round_max_seconds", 300),
  1345. (assign, "$g_multiplayer_game_max_minutes", 30),
  1346. (assign, "$g_multiplayer_game_max_points", 300),
  1347.  
  1348. (server_get_renaming_server_allowed, "$g_multiplayer_renaming_server_allowed"),
  1349. (server_get_changing_game_type_allowed, "$g_multiplayer_changing_game_type_allowed"),
  1350. (assign, "$g_multiplayer_point_gained_from_flags", 100),
  1351. (assign, "$g_multiplayer_point_gained_from_capturing_flag", 5),
  1352. (assign, "$g_multiplayer_game_type", 0),
  1353. (assign, "$g_multiplayer_team_1_faction", "fac_kingdom_1"),
  1354. (assign, "$g_multiplayer_team_2_faction", "fac_kingdom_2"),
  1355. (assign, "$g_multiplayer_next_team_1_faction", "$g_multiplayer_team_1_faction"),
  1356. (assign, "$g_multiplayer_next_team_2_faction", "$g_multiplayer_team_2_faction"),
  1357. (assign, "$g_multiplayer_num_bots_team_1", 0),
  1358. (assign, "$g_multiplayer_num_bots_team_2", 0),
  1359. (assign, "$g_multiplayer_number_of_respawn_count", 0),
  1360. (assign, "$g_multiplayer_num_bots_voteable", 50),
  1361. (assign, "$g_multiplayer_max_num_bots", 101),
  1362. (assign, "$g_multiplayer_factions_voteable", 1),
  1363. (assign, "$g_multiplayer_maps_voteable", 1),
  1364. (assign, "$g_multiplayer_kick_voteable", 1),
  1365. (assign, "$g_multiplayer_ban_voteable", 1),
  1366. (assign, "$g_multiplayer_valid_vote_ratio", 51), #more than 50 percent
  1367. (assign, "$g_multiplayer_auto_team_balance_limit", 3), #auto balance when difference is more than 2
  1368. (assign, "$g_multiplayer_player_respawn_as_bot", 1),
  1369. (assign, "$g_multiplayer_stats_chart_opened_manually", 0),
  1370. (assign, "$g_multiplayer_mission_end_screen", 0),
  1371. (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
  1372. (assign, "$g_multiplayer_welcome_message_shown", 0),
  1373. (assign, "$g_multiplayer_allow_player_banners", 1),
  1374. (assign, "$g_multiplayer_force_default_armor", 1),
  1375. (assign, "$g_multiplayer_disallow_ranged_weapons", 0),
  1376.  
  1377. (assign, "$g_multiplayer_initial_gold_multiplier", 100),
  1378. (assign, "$g_multiplayer_battle_earnings_multiplier", 100),
  1379. (assign, "$g_multiplayer_round_earnings_multiplier", 100),
  1380.  
  1381. #faction banners
  1382. (faction_set_slot, "fac_kingdom_1", slot_faction_banner, "mesh_banner_kingdom_f"),
  1383. (faction_set_slot, "fac_kingdom_2", slot_faction_banner, "mesh_banner_kingdom_b"),
  1384. (faction_set_slot, "fac_kingdom_3", slot_faction_banner, "mesh_banner_kingdom_c"),
  1385. (faction_set_slot, "fac_kingdom_4", slot_faction_banner, "mesh_banner_kingdom_a"),
  1386. (faction_set_slot, "fac_kingdom_5", slot_faction_banner, "mesh_banner_kingdom_d"),
  1387. (faction_set_slot, "fac_kingdom_6", slot_faction_banner, "mesh_banner_kingdom_e"),
  1388.  
  1389. (try_for_range, ":cur_item", all_items_begin, all_items_end),
  1390. (try_for_range, ":cur_faction", npc_kingdoms_begin, npc_kingdoms_end),
  1391. (store_sub, ":faction_index", ":cur_faction", npc_kingdoms_begin),
  1392. (val_add, ":faction_index", slot_item_multiplayer_faction_price_multipliers_begin),
  1393. (item_set_slot, ":cur_item", ":faction_index", 100), #100 is the default price multiplier
  1394. (try_end),
  1395. (try_end),
  1396. (store_sub, ":swadian_price_slot", "fac_kingdom_1", npc_kingdoms_begin),
  1397. (val_add, ":swadian_price_slot", slot_item_multiplayer_faction_price_multipliers_begin),
  1398. (store_sub, ":vaegir_price_slot", "fac_kingdom_2", npc_kingdoms_begin),
  1399. (val_add, ":vaegir_price_slot", slot_item_multiplayer_faction_price_multipliers_begin),
  1400. (store_sub, ":khergit_price_slot", "fac_kingdom_3", npc_kingdoms_begin),
  1401. (val_add, ":khergit_price_slot", slot_item_multiplayer_faction_price_multipliers_begin),
  1402. (store_sub, ":nord_price_slot", "fac_kingdom_4", npc_kingdoms_begin),
  1403. (val_add, ":nord_price_slot", slot_item_multiplayer_faction_price_multipliers_begin),
  1404. (store_sub, ":rhodok_price_slot", "fac_kingdom_5", npc_kingdoms_begin),
  1405. (val_add, ":rhodok_price_slot", slot_item_multiplayer_faction_price_multipliers_begin),
  1406. (store_sub, ":sarranid_price_slot", "fac_kingdom_6", npc_kingdoms_begin),
  1407. (val_add, ":sarranid_price_slot", slot_item_multiplayer_faction_price_multipliers_begin),
  1408.  
  1409. (item_set_slot, "itm_awlpike", ":swadian_price_slot", 80),
  1410. (item_set_slot, "itm_awlpike_long", ":swadian_price_slot", 90),
  1411. (item_set_slot, "itm_sword_medieval_a", ":swadian_price_slot", 80),
  1412. (item_set_slot, "itm_sword_medieval_b", ":swadian_price_slot", 80),
  1413. (item_set_slot, "itm_sword_medieval_b_small", ":swadian_price_slot", 80),
  1414. (item_set_slot, "itm_sword_medieval_c", ":swadian_price_slot", 80),
  1415. (item_set_slot, "itm_sword_medieval_c_small", ":swadian_price_slot", 80),
  1416. (item_set_slot, "itm_leather_boots", ":swadian_price_slot", 90),
  1417. (item_set_slot, "itm_mail_chausses", ":swadian_price_slot", 80),
  1418. (item_set_slot, "itm_splinted_greaves", ":swadian_price_slot", 80),
  1419. (item_set_slot, "itm_plate_boots", ":swadian_price_slot", 80),
  1420. (item_set_slot, "itm_courser", ":swadian_price_slot", 90),
  1421. (item_set_slot, "itm_hunter", ":swadian_price_slot", 75),
  1422. (item_set_slot, "itm_norman_helmet", ":swadian_price_slot", 75),
  1423. (item_set_slot, "itm_helmet_with_neckguard", ":swadian_price_slot", 75),
  1424. (item_set_slot, "itm_red_gambeson", ":swadian_price_slot", 75),
  1425. (item_set_slot, "itm_darts", ":swadian_price_slot", 50),
  1426. (item_set_slot, "itm_war_darts", ":swadian_price_slot", 50),
  1427. (item_set_slot, "itm_tab_shield_heater_d", ":swadian_price_slot", 80),
  1428. (item_set_slot, "itm_brigandine_red", ":swadian_price_slot", 75),
  1429. (item_set_slot, "itm_bastard_sword_b", ":swadian_price_slot", 65),
  1430. (item_set_slot, "itm_bastard_sword_a", ":swadian_price_slot", 85),
  1431.  
  1432. (item_set_slot, "itm_steppe_horse", ":khergit_price_slot", 120),
  1433. (item_set_slot, "itm_courser", ":khergit_price_slot", 80),
  1434. (item_set_slot, "itm_hunter", ":khergit_price_slot", 80),
  1435. (item_set_slot, "itm_warhorse_steppe", ":khergit_price_slot", 120),
  1436. (item_set_slot, "itm_one_handed_war_axe_a", ":khergit_price_slot", 300),
  1437. (item_set_slot, "itm_tribal_warrior_outfit", ":khergit_price_slot", 140),
  1438.  
  1439. (item_set_slot, "itm_leather_gloves", ":sarranid_price_slot", 50),
  1440. (item_set_slot, "itm_short_bow", ":sarranid_price_slot", 50),
  1441. (item_set_slot, "itm_barbed_arrows", ":sarranid_price_slot", 80),
  1442. (item_set_slot, "itm_jarid", ":sarranid_price_slot", 85),
  1443. (item_set_slot, "itm_javelin", ":sarranid_price_slot", 85),
  1444.  
  1445. (item_set_slot, "itm_lamellar_vest", ":vaegir_price_slot", 130),
  1446. (item_set_slot, "itm_awlpike", ":vaegir_price_slot", 150),
  1447. (item_set_slot, "itm_scimitar", ":vaegir_price_slot", 130),
  1448. (item_set_slot, "itm_scimitar_b", ":vaegir_price_slot", 150),
  1449. (item_set_slot, "itm_tab_shield_kite_a", ":vaegir_price_slot", 120),
  1450. (item_set_slot, "itm_tab_shield_kite_b", ":vaegir_price_slot", 120),
  1451. (item_set_slot, "itm_tab_shield_kite_c", ":vaegir_price_slot", 120),
  1452. (item_set_slot, "itm_tab_shield_kite_d", ":vaegir_price_slot", 120),
  1453. (item_set_slot, "itm_javelin", ":vaegir_price_slot", 120),
  1454.  
  1455. #arrows
  1456. (item_set_slot, "itm_arrows", slot_item_multiplayer_item_class, multi_item_class_type_arrow),
  1457. (item_set_slot, "itm_barbed_arrows", slot_item_multiplayer_item_class, multi_item_class_type_arrow),
  1458. (item_set_slot, "itm_bodkin_arrows", slot_item_multiplayer_item_class, multi_item_class_type_arrow),
  1459. (item_set_slot, "itm_khergit_arrows", slot_item_multiplayer_item_class, multi_item_class_type_arrow),
  1460. #bolts
  1461. (item_set_slot, "itm_bolts", slot_item_multiplayer_item_class, multi_item_class_type_bolt),
  1462. (item_set_slot, "itm_steel_bolts", slot_item_multiplayer_item_class, multi_item_class_type_bolt),
  1463. #bows
  1464. (item_set_slot, "itm_crossbow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1465. (item_set_slot, "itm_heavy_crossbow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1466. (item_set_slot, "itm_sniper_crossbow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1467. (item_set_slot, "itm_nomad_bow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1468. (item_set_slot, "itm_khergit_bow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1469. (item_set_slot, "itm_strong_bow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1470. (item_set_slot, "itm_war_bow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1471. (item_set_slot, "itm_short_bow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1472. (item_set_slot, "itm_long_bow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1473. (item_set_slot, "itm_light_crossbow", slot_item_multiplayer_item_class, multi_item_class_type_bow),
  1474. #swords
  1475. (item_set_slot, "itm_sword_medieval_a", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1476. (item_set_slot, "itm_sword_medieval_b", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1477. (item_set_slot, "itm_sword_medieval_b_small", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1478. (item_set_slot, "itm_sword_medieval_c", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1479. (item_set_slot, "itm_sword_medieval_c_small", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1480. (item_set_slot, "itm_scimitar", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1481. (item_set_slot, "itm_scimitar_b", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1482. (item_set_slot, "itm_dagger", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1483. (item_set_slot, "itm_sword_khergit_1", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1484. (item_set_slot, "itm_sword_khergit_2", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1485. (item_set_slot, "itm_sword_khergit_3", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1486. (item_set_slot, "itm_sword_khergit_4", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1487. (item_set_slot, "itm_sword_viking_1", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1488. (item_set_slot, "itm_sword_viking_2", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1489. (item_set_slot, "itm_sword_viking_2_small", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1490. (item_set_slot, "itm_sword_viking_3", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1491. (item_set_slot, "itm_sword_viking_3_small", slot_item_multiplayer_item_class, multi_item_class_type_sword),
  1492. (item_set_slot, "itm_bastard_sword_a", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_sword),
  1493. (item_set_slot, "itm_bastard_sword_b", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_sword),
  1494. (item_set_slot, "itm_sword_two_handed_a", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_sword),
  1495. (item_set_slot, "itm_sword_two_handed_b", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_sword),
  1496. (item_set_slot, "itm_arabian_sword_a", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_sword),
  1497. (item_set_slot, "itm_arabian_sword_b", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_sword),
  1498. (item_set_slot, "itm_sarranid_cavalry_sword", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_sword),
  1499. (item_set_slot, "itm_arabian_sword_d", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_sword),
  1500.  
  1501. #axe
  1502. (item_set_slot, "itm_axe", slot_item_multiplayer_item_class, multi_item_class_type_axe),
  1503. (item_set_slot, "itm_battle_axe", slot_item_multiplayer_item_class, multi_item_class_type_axe),
  1504. (item_set_slot, "itm_one_handed_war_axe_a", slot_item_multiplayer_item_class, multi_item_class_type_axe),
  1505. (item_set_slot, "itm_one_handed_war_axe_b", slot_item_multiplayer_item_class, multi_item_class_type_axe),
  1506. (item_set_slot, "itm_one_handed_battle_axe_a", slot_item_multiplayer_item_class, multi_item_class_type_axe),
  1507. (item_set_slot, "itm_one_handed_battle_axe_b", slot_item_multiplayer_item_class, multi_item_class_type_axe),
  1508. (item_set_slot, "itm_one_handed_battle_axe_c", slot_item_multiplayer_item_class, multi_item_class_type_axe),
  1509.  
  1510. (item_set_slot, "itm_two_handed_axe", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1511. (item_set_slot, "itm_two_handed_battle_axe_2", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1512. (item_set_slot, "itm_shortened_voulge", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1513. (item_set_slot, "itm_bardiche", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1514. (item_set_slot, "itm_great_axe", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1515. (item_set_slot, "itm_great_bardiche", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1516. (item_set_slot, "itm_long_axe", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1517. (item_set_slot, "itm_long_axe_b", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1518. (item_set_slot, "itm_long_axe_c", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1519. (item_set_slot, "itm_voulge", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1520. (item_set_slot, "itm_long_bardiche", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1521. (item_set_slot, "itm_great_long_bardiche", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1522.  
  1523. #blunt
  1524. (item_set_slot, "itm_mace_1", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1525. (item_set_slot, "itm_mace_2", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1526. (item_set_slot, "itm_mace_3", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1527. (item_set_slot, "itm_mace_4", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1528. (item_set_slot, "itm_long_spiked_club", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1529. (item_set_slot, "itm_long_hafted_spiked_mace", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1530.  
  1531. (item_set_slot, "itm_maul", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1532. (item_set_slot, "itm_sledgehammer", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1533. (item_set_slot, "itm_warhammer", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1534. (item_set_slot, "itm_morningstar", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1535. #picks
  1536. (item_set_slot, "itm_military_sickle_a", slot_item_multiplayer_item_class, multi_item_class_type_war_picks),
  1537. (item_set_slot, "itm_fighting_pick", slot_item_multiplayer_item_class, multi_item_class_type_war_picks),
  1538. (item_set_slot, "itm_military_pick", slot_item_multiplayer_item_class, multi_item_class_type_war_picks),
  1539. (item_set_slot, "itm_club_with_spike_head", slot_item_multiplayer_item_class, multi_item_class_type_war_picks),
  1540.  
  1541. #Cleavers
  1542. (item_set_slot, "itm_falchion", slot_item_multiplayer_item_class, multi_item_class_type_cleavers),
  1543. (item_set_slot, "itm_military_cleaver_b", slot_item_multiplayer_item_class, multi_item_class_type_cleavers),
  1544. (item_set_slot, "itm_military_cleaver_c", slot_item_multiplayer_item_class, multi_item_class_type_cleavers),
  1545. (item_set_slot, "itm_two_handed_cleaver", slot_item_multiplayer_item_class, multi_item_class_type_cleavers),
  1546. (item_set_slot, "itm_hafted_blade_a", slot_item_multiplayer_item_class, multi_item_class_type_cleavers),
  1547. (item_set_slot, "itm_hafted_blade_b", slot_item_multiplayer_item_class, multi_item_class_type_cleavers),
  1548. (item_set_slot, "itm_shortened_military_scythe", slot_item_multiplayer_item_class, multi_item_class_type_cleavers),
  1549.  
  1550. (item_set_slot, "itm_sarranid_mace_1", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1551. (item_set_slot, "itm_sarranid_axe_a", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1552. (item_set_slot, "itm_sarranid_axe_b", slot_item_multiplayer_item_class, multi_item_class_type_blunt),
  1553. (item_set_slot, "itm_sarranid_two_handed_axe_a", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1554. (item_set_slot, "itm_sarranid_two_handed_axe_b", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1555. (item_set_slot, "itm_sarranid_two_handed_mace_1", slot_item_multiplayer_item_class, multi_item_class_type_two_handed_axe),
  1556. (item_set_slot, "itm_bamboo_spear", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1557.  
  1558.  
  1559.  
  1560. #spears
  1561. (item_set_slot, "itm_double_sided_lance", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1562. (item_set_slot, "itm_glaive", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1563. (item_set_slot, "itm_poleaxe", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1564. (item_set_slot, "itm_polehammer", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1565. (item_set_slot, "itm_staff", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1566. (item_set_slot, "itm_quarter_staff", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1567. (item_set_slot, "itm_iron_staff", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1568.  
  1569. (item_set_slot, "itm_shortened_spear", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1570. (item_set_slot, "itm_spear", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1571. (item_set_slot, "itm_war_spear", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1572. (item_set_slot, "itm_military_scythe", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1573. (item_set_slot, "itm_pike", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1574. (item_set_slot, "itm_ashwood_pike", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1575. (item_set_slot, "itm_awlpike", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1576. (item_set_slot, "itm_awlpike_long", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1577. #lance
  1578. (item_set_slot, "itm_light_lance", slot_item_multiplayer_item_class, multi_item_class_type_lance),
  1579. (item_set_slot, "itm_lance", slot_item_multiplayer_item_class, multi_item_class_type_lance),
  1580. (item_set_slot, "itm_heavy_lance", slot_item_multiplayer_item_class, multi_item_class_type_lance),
  1581. (item_set_slot, "itm_great_lance", slot_item_multiplayer_item_class, multi_item_class_type_lance),
  1582. #shields
  1583.  
  1584. (item_set_slot, "itm_tab_shield_round_a", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1585. (item_set_slot, "itm_tab_shield_round_b", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1586. (item_set_slot, "itm_tab_shield_round_c", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1587. (item_set_slot, "itm_tab_shield_round_d", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1588. (item_set_slot, "itm_tab_shield_round_e", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1589. (item_set_slot, "itm_tab_shield_kite_a", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1590. (item_set_slot, "itm_tab_shield_kite_b", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1591. (item_set_slot, "itm_tab_shield_kite_c", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1592. (item_set_slot, "itm_tab_shield_kite_d", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1593. (item_set_slot, "itm_tab_shield_kite_cav_a", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1594. (item_set_slot, "itm_tab_shield_kite_cav_b", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1595. (item_set_slot, "itm_tab_shield_heater_a", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1596. (item_set_slot, "itm_tab_shield_heater_b", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1597. (item_set_slot, "itm_tab_shield_heater_c", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1598. (item_set_slot, "itm_tab_shield_heater_d", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1599. (item_set_slot, "itm_tab_shield_heater_cav_a", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1600. (item_set_slot, "itm_tab_shield_heater_cav_b", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1601. (item_set_slot, "itm_tab_shield_pavise_a", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1602. (item_set_slot, "itm_tab_shield_pavise_b", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1603. (item_set_slot, "itm_tab_shield_pavise_c", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1604. (item_set_slot, "itm_tab_shield_pavise_d", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1605. (item_set_slot, "itm_tab_shield_small_round_a", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1606. (item_set_slot, "itm_tab_shield_small_round_b", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1607. (item_set_slot, "itm_tab_shield_small_round_c", slot_item_multiplayer_item_class, multi_item_class_type_small_shield),
  1608. (item_set_slot, "itm_spear", slot_item_multiplayer_item_class, multi_item_class_type_spear),
  1609. #throwing
  1610. (item_set_slot, "itm_darts", slot_item_multiplayer_item_class, multi_item_class_type_throwing),
  1611. (item_set_slot, "itm_war_darts", slot_item_multiplayer_item_class, multi_item_class_type_throwing),
  1612. (item_set_slot, "itm_javelin", slot_item_multiplayer_item_class, multi_item_class_type_throwing),
  1613. (item_set_slot, "itm_jarid", slot_item_multiplayer_item_class, multi_item_class_type_throwing),
  1614. (item_set_slot, "itm_throwing_spears", slot_item_multiplayer_item_class, multi_item_class_type_throwing),
  1615.  
  1616. (item_set_slot, "itm_throwing_axes", slot_item_multiplayer_item_class, multi_item_class_type_throwing_axe),
  1617. (item_set_slot, "itm_light_throwing_axes", slot_item_multiplayer_item_class, multi_item_class_type_throwing_axe),
  1618. (item_set_slot, "itm_heavy_throwing_axes", slot_item_multiplayer_item_class, multi_item_class_type_throwing_axe),
  1619. #armors
  1620. (item_set_slot, "itm_red_shirt", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1621. (item_set_slot, "itm_red_tunic", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1622. (item_set_slot, "itm_aketon_green", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1623. (item_set_slot, "itm_padded_cloth", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1624. (item_set_slot, "itm_red_gambeson", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1625. (item_set_slot, "itm_leather_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1626. (item_set_slot, "itm_haubergeon", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1627. (item_set_slot, "itm_coat_of_plates_red", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1628. (item_set_slot, "itm_brigandine_red", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1629. (item_set_slot, "itm_mail_with_surcoat", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1630. (item_set_slot, "itm_linen_tunic", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1631. (item_set_slot, "itm_leather_vest", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1632. (item_set_slot, "itm_leather_jerkin", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1633. (item_set_slot, "itm_studded_leather_coat", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1634. (item_set_slot, "itm_lamellar_vest", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1635. (item_set_slot, "itm_lamellar_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1636. (item_set_slot, "itm_coarse_tunic", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1637. (item_set_slot, "itm_tribal_warrior_outfit", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1638. (item_set_slot, "itm_khergit_guard_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1639. (item_set_slot, "itm_blue_tunic", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1640. (item_set_slot, "itm_mail_hauberk", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1641. (item_set_slot, "itm_mail_shirt", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1642. (item_set_slot, "itm_byrnie", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1643. (item_set_slot, "itm_lamellar_vest_khergit", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1644. (item_set_slot, "itm_steppe_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1645.  
  1646.  
  1647. (item_set_slot, "itm_banded_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1648. (item_set_slot, "itm_cuir_bouilli", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1649. (item_set_slot, "itm_scale_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1650.  
  1651. (item_set_slot, "itm_padded_leather", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1652. (item_set_slot, "itm_green_tunic", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1653. (item_set_slot, "itm_tunic_with_green_cape", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1654. (item_set_slot, "itm_aketon_green", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1655. (item_set_slot, "itm_ragged_outfit", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1656. (item_set_slot, "itm_surcoat_over_mail", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1657.  
  1658. (item_set_slot, "itm_sarranid_elite_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1659. (item_set_slot, "itm_skirmisher_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1660. (item_set_slot, "itm_archers_vest", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1661. (item_set_slot, "itm_sarranid_leather_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1662. (item_set_slot, "itm_sarranid_cloth_robe", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1663. (item_set_slot, "itm_sarranid_mail_shirt", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1664. (item_set_slot, "itm_sarranid_cavalry_robe", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1665. (item_set_slot, "itm_arabian_armor_b", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1666. (item_set_slot, "itm_mamluke_mail", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1667. (item_set_slot, "itm_khergit_elite_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1668. (item_set_slot, "itm_vaegir_elite_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1669. (item_set_slot, "itm_khergit_armor", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675. #boots
  1676. (item_set_slot, "itm_hide_boots", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1677. (item_set_slot, "itm_ankle_boots", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1678. (item_set_slot, "itm_nomad_boots", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1679. (item_set_slot, "itm_leather_boots", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1680. (item_set_slot, "itm_splinted_leather_greaves", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1681. (item_set_slot, "itm_mail_chausses", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1682. (item_set_slot, "itm_splinted_leather_greaves", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1683. (item_set_slot, "itm_splinted_greaves", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1684. (item_set_slot, "itm_mail_boots", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1685. (item_set_slot, "itm_iron_greaves", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1686. (item_set_slot, "itm_sarranid_boots_b", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1687. (item_set_slot, "itm_sarranid_boots_c", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1688. (item_set_slot, "itm_sarranid_boots_d", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1689. (item_set_slot, "itm_plate_boots", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1690. (item_set_slot, "itm_khergit_leather_boots", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1691. (item_set_slot, "itm_khergit_guard_boots", slot_item_multiplayer_item_class, multi_item_class_type_light_foot),
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700. #helmets
  1701.  
  1702.  
  1703. (item_set_slot, "itm_leather_steppe_cap_a", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1704. (item_set_slot, "itm_leather_steppe_cap_b", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1705. (item_set_slot, "itm_steppe_cap", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1706. (item_set_slot, "itm_khergit_war_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1707. (item_set_slot, "itm_khergit_guard_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1708.  
  1709.  
  1710.  
  1711. (item_set_slot, "itm_arming_cap", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1712. (item_set_slot, "itm_padded_coif", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1713. (item_set_slot, "itm_mail_coif", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1714. (item_set_slot, "itm_footman_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1715. (item_set_slot, "itm_norman_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1716. (item_set_slot, "itm_kettle_hat", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1717. (item_set_slot, "itm_helmet_with_neckguard", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1718.  
  1719. (item_set_slot, "itm_bascinet_2", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1720. (item_set_slot, "itm_bascinet_3", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1721.  
  1722.  
  1723.  
  1724. (item_set_slot, "itm_flat_topped_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1725. (item_set_slot, "itm_guard_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1726. (item_set_slot, "itm_full_helm", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1727. (item_set_slot, "itm_great_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1728. (item_set_slot, "itm_nomad_cap_b", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1729. (item_set_slot, "itm_skullcap", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1730. (item_set_slot, "itm_leather_cap", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1731.  
  1732. (item_set_slot, "itm_spiked_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1733. # (item_set_slot, "itm_nasal_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1734. (item_set_slot, "itm_nordic_archer_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1735. (item_set_slot, "itm_nordic_veteran_archer_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1736. (item_set_slot, "itm_nordic_footman_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1737. (item_set_slot, "itm_nordic_fighter_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1738. (item_set_slot, "itm_nordic_huscarl_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1739. (item_set_slot, "itm_nordic_warlord_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1740.  
  1741. (item_set_slot, "itm_sarranid_helmet1", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1742. (item_set_slot, "itm_sarranid_horseman_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1743. (item_set_slot, "itm_sarranid_felt_hat", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1744. (item_set_slot, "itm_sarranid_veiled_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1745. (item_set_slot, "itm_turban", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1746. (item_set_slot, "itm_desert_turban", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1747. (item_set_slot, "itm_sarranid_warrior_cap", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1748. (item_set_slot, "itm_sarranid_mail_coif", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1749.  
  1750. (item_set_slot, "itm_vaegir_fur_cap", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1751. (item_set_slot, "itm_vaegir_fur_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1752. (item_set_slot, "itm_vaegir_spiked_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1753. (item_set_slot, "itm_vaegir_lamellar_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1754. (item_set_slot, "itm_vaegir_noble_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1755. (item_set_slot, "itm_vaegir_war_helmet", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1756. (item_set_slot, "itm_vaegir_mask", slot_item_multiplayer_item_class, multi_item_class_type_light_helm),
  1757.  
  1758.  
  1759. #gloves
  1760. (item_set_slot, "itm_leather_gloves", slot_item_multiplayer_item_class, multi_item_class_type_glove),
  1761. (item_set_slot, "itm_mail_mittens", slot_item_multiplayer_item_class, multi_item_class_type_glove),
  1762. (item_set_slot, "itm_scale_gauntlets", slot_item_multiplayer_item_class, multi_item_class_type_glove),
  1763. (item_set_slot, "itm_lamellar_gauntlets", slot_item_multiplayer_item_class, multi_item_class_type_glove),
  1764. (item_set_slot, "itm_gauntlets", slot_item_multiplayer_item_class, multi_item_class_type_glove),
  1765.  
  1766. #horses
  1767. (item_set_slot, "itm_saddle_horse", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1768. (item_set_slot, "itm_hunter", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1769. (item_set_slot, "itm_courser", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1770. (item_set_slot, "itm_hunter", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1771. (item_set_slot, "itm_warhorse", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1772. (item_set_slot, "itm_charger", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1773. (item_set_slot, "itm_steppe_horse", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1774. (item_set_slot, "itm_arabian_horse_a", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1775. (item_set_slot, "itm_arabian_horse_b", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1776. (item_set_slot, "itm_warhorse_steppe", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1777. (item_set_slot, "itm_warhorse_sarranid", slot_item_multiplayer_item_class, multi_item_class_type_horse),
  1778.  
  1779.  
  1780. #1-Swadian Warriors
  1781. #1a-Swadian Crossbowman
  1782. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bolts", "trp_swadian_crossbowman_multiplayer"),
  1783. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steel_bolts", "trp_swadian_crossbowman_multiplayer"),
  1784. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_crossbow", "trp_swadian_crossbowman_multiplayer"),
  1785. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_crossbow", "trp_swadian_crossbowman_multiplayer"),
  1786. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sniper_crossbow", "trp_swadian_crossbowman_multiplayer"),
  1787. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_a", "trp_swadian_crossbowman_multiplayer"),
  1788. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b", "trp_swadian_crossbowman_multiplayer"),
  1789. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b_small", "trp_swadian_crossbowman_multiplayer"),
  1790. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_a", "trp_swadian_crossbowman_multiplayer"),
  1791. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_b", "trp_swadian_crossbowman_multiplayer"),
  1792. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_c", "trp_swadian_crossbowman_multiplayer"),
  1793.  
  1794. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_red_shirt", "trp_swadian_crossbowman_multiplayer"),
  1795. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_padded_cloth", "trp_swadian_crossbowman_multiplayer"),
  1796. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_armor", "trp_swadian_crossbowman_multiplayer"),
  1797. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_haubergeon", "trp_swadian_crossbowman_multiplayer"),
  1798. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ankle_boots", "trp_swadian_crossbowman_multiplayer"),
  1799. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_swadian_crossbowman_multiplayer"),
  1800. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_chausses", "trp_swadian_crossbowman_multiplayer"),
  1801. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_swadian_crossbowman_multiplayer"),
  1802.  
  1803. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arming_cap", "trp_swadian_crossbowman_multiplayer"),
  1804. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_norman_helmet", "trp_swadian_crossbowman_multiplayer"),
  1805. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_helmet_with_neckguard", "trp_swadian_crossbowman_multiplayer"),
  1806. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_flat_topped_helmet", "trp_swadian_crossbowman_multiplayer"),
  1807. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_guard_helmet", "trp_swadian_crossbowman_multiplayer"),
  1808.  
  1809. #1b-Swadian Infantry
  1810. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_awlpike", "trp_swadian_infantry_multiplayer"),
  1811. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_awlpike_long", "trp_swadian_infantry_multiplayer"),
  1812. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_a", "trp_swadian_infantry_multiplayer"),
  1813. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b", "trp_swadian_infantry_multiplayer"),
  1814. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b_small", "trp_swadian_infantry_multiplayer"),
  1815. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_c", "trp_swadian_infantry_multiplayer"),
  1816. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_c_small", "trp_swadian_infantry_multiplayer"),
  1817. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bastard_sword_a", "trp_swadian_infantry_multiplayer"),
  1818. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bastard_sword_b", "trp_swadian_infantry_multiplayer"),
  1819. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_two_handed_a", "trp_swadian_infantry_multiplayer"),
  1820. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_two_handed_b", "trp_swadian_infantry_multiplayer"),
  1821. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_darts", "trp_swadian_infantry_multiplayer"),
  1822. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_darts", "trp_swadian_infantry_multiplayer"),
  1823. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_a", "trp_swadian_infantry_multiplayer"),
  1824. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_b", "trp_swadian_infantry_multiplayer"),
  1825. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_c", "trp_swadian_infantry_multiplayer"),
  1826. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_d", "trp_swadian_infantry_multiplayer"),
  1827. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_red_tunic", "trp_swadian_infantry_multiplayer"),
  1828. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_red_gambeson", "trp_swadian_infantry_multiplayer"),
  1829. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_armor", "trp_swadian_infantry_multiplayer"),
  1830. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_haubergeon", "trp_swadian_infantry_multiplayer"),
  1831. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_brigandine_red", "trp_swadian_infantry_multiplayer"),
  1832. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ankle_boots", "trp_swadian_infantry_multiplayer"),
  1833. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_swadian_infantry_multiplayer"),
  1834. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_chausses", "trp_swadian_infantry_multiplayer"),
  1835. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_swadian_infantry_multiplayer"),
  1836. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arming_cap", "trp_swadian_infantry_multiplayer"),
  1837. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_norman_helmet", "trp_swadian_infantry_multiplayer"),
  1838. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_helmet_with_neckguard", "trp_swadian_infantry_multiplayer"),
  1839. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_flat_topped_helmet", "trp_swadian_infantry_multiplayer"),
  1840. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_guard_helmet", "trp_swadian_infantry_multiplayer"),
  1841. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_great_helmet", "trp_swadian_infantry_multiplayer"),
  1842. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_swadian_infantry_multiplayer"),
  1843. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_swadian_infantry_multiplayer"),
  1844. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_swadian_infantry_multiplayer"),
  1845. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_gauntlets", "trp_swadian_infantry_multiplayer"),
  1846.  
  1847. #1c-Swadian Man At Arms
  1848. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_darts", "trp_swadian_man_at_arms_multiplayer"),
  1849. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_darts", "trp_swadian_man_at_arms_multiplayer"),
  1850. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lance", "trp_swadian_man_at_arms_multiplayer"),
  1851. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_lance", "trp_swadian_man_at_arms_multiplayer"),
  1852. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_great_lance", "trp_swadian_man_at_arms_multiplayer"),
  1853. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_a", "trp_swadian_man_at_arms_multiplayer"),
  1854. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b", "trp_swadian_man_at_arms_multiplayer"),
  1855. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b_small", "trp_swadian_man_at_arms_multiplayer"),
  1856. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_c", "trp_swadian_man_at_arms_multiplayer"),
  1857. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_c_small", "trp_swadian_man_at_arms_multiplayer"),
  1858. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bastard_sword_a", "trp_swadian_man_at_arms_multiplayer"),
  1859. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bastard_sword_b", "trp_swadian_man_at_arms_multiplayer"),
  1860. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_a", "trp_swadian_man_at_arms_multiplayer"),
  1861. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_b", "trp_swadian_man_at_arms_multiplayer"),
  1862. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_c", "trp_swadian_man_at_arms_multiplayer"),
  1863. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_d", "trp_swadian_man_at_arms_multiplayer"),
  1864. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_red_tunic", "trp_swadian_man_at_arms_multiplayer"),
  1865. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_padded_cloth", "trp_swadian_man_at_arms_multiplayer"),
  1866. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_armor", "trp_swadian_man_at_arms_multiplayer"),
  1867. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_with_surcoat", "trp_swadian_man_at_arms_multiplayer"),
  1868. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_coat_of_plates_red", "trp_swadian_man_at_arms_multiplayer"),
  1869. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ankle_boots", "trp_swadian_man_at_arms_multiplayer"),
  1870. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_swadian_man_at_arms_multiplayer"),
  1871. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_chausses", "trp_swadian_man_at_arms_multiplayer"),
  1872. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_swadian_man_at_arms_multiplayer"),
  1873. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_plate_boots", "trp_swadian_man_at_arms_multiplayer"),
  1874.  
  1875. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arming_cap", "trp_swadian_man_at_arms_multiplayer"),
  1876. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_norman_helmet", "trp_swadian_man_at_arms_multiplayer"),
  1877. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_helmet_with_neckguard", "trp_swadian_man_at_arms_multiplayer"),
  1878. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_flat_topped_helmet", "trp_swadian_man_at_arms_multiplayer"),
  1879. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_guard_helmet", "trp_swadian_man_at_arms_multiplayer"),
  1880. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_great_helmet", "trp_swadian_man_at_arms_multiplayer"),
  1881. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_swadian_man_at_arms_multiplayer"),
  1882. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_swadian_man_at_arms_multiplayer"),
  1883. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_swadian_man_at_arms_multiplayer"),
  1884. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_gauntlets", "trp_swadian_man_at_arms_multiplayer"),
  1885. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_saddle_horse", "trp_swadian_man_at_arms_multiplayer"),
  1886. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_courser", "trp_swadian_man_at_arms_multiplayer"),
  1887. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hunter", "trp_swadian_man_at_arms_multiplayer"),
  1888. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_warhorse", "trp_swadian_man_at_arms_multiplayer"),
  1889. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_charger", "trp_swadian_man_at_arms_multiplayer"),
  1890.  
  1891. # #1d-Swadian Mounted Crossbowman
  1892. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bolts", "trp_swadian_mounted_crossbowman_multiplayer"),
  1893. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_light_crossbow", "trp_swadian_mounted_crossbowman_multiplayer"),
  1894. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_crossbow", "trp_swadian_mounted_crossbowman_multiplayer"),
  1895. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_crossbow", "trp_swadian_mounted_crossbowman_multiplayer"),
  1896. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_cav_a", "trp_swadian_mounted_crossbowman_multiplayer"),
  1897. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_cav_b", "trp_swadian_mounted_crossbowman_multiplayer"),
  1898. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bastard_sword_a", "trp_swadian_mounted_crossbowman_multiplayer"),
  1899. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_red_shirt", "trp_swadian_mounted_crossbowman_multiplayer"),
  1900. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_padded_cloth", "trp_swadian_mounted_crossbowman_multiplayer"),
  1901. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_armor", "trp_swadian_mounted_crossbowman_multiplayer"),
  1902. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_with_surcoat", "trp_swadian_mounted_crossbowman_multiplayer"),
  1903. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_coat_of_plates_red", "trp_swadian_mounted_crossbowman_multiplayer"),
  1904. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hide_boots", "trp_swadian_mounted_crossbowman_multiplayer"),
  1905. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arming_cap", "trp_swadian_mounted_crossbowman_multiplayer"),
  1906. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_norman_helmet", "trp_swadian_mounted_crossbowman_multiplayer"),
  1907. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_helmet_with_neckguard", "trp_swadian_mounted_crossbowman_multiplayer"),
  1908. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_flat_topped_helmet", "trp_swadian_mounted_crossbowman_multiplayer"),
  1909. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_guard_helmet", "trp_swadian_mounted_crossbowman_multiplayer"),
  1910. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_swadian_mounted_crossbowman_multiplayer"),
  1911. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_saddle_horse", "trp_swadian_mounted_crossbowman_multiplayer"),
  1912. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_courser", "trp_swadian_mounted_crossbowman_multiplayer"),
  1913. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hunter", "trp_swadian_mounted_crossbowman_multiplayer"),
  1914.  
  1915. #2-Vaegir Warriors
  1916. #2a-Vaegir Archer
  1917. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arrows", "trp_vaegir_archer_multiplayer"),
  1918. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_barbed_arrows", "trp_vaegir_archer_multiplayer"),
  1919. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_1", "trp_vaegir_archer_multiplayer"),
  1920. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_2", "trp_vaegir_archer_multiplayer"),
  1921. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_falchion", "trp_vaegir_archer_multiplayer"),
  1922. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_bow", "trp_vaegir_archer_multiplayer"),
  1923. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_bow", "trp_vaegir_archer_multiplayer"),
  1924. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_strong_bow", "trp_vaegir_archer_multiplayer"),
  1925. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_bow", "trp_vaegir_archer_multiplayer"),
  1926. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_linen_tunic", "trp_vaegir_archer_multiplayer"),
  1927. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_jerkin", "trp_vaegir_archer_multiplayer"),
  1928. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_vest", "trp_vaegir_archer_multiplayer"),
  1929. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_vest", "trp_vaegir_archer_multiplayer"),
  1930. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hide_boots", "trp_vaegir_archer_multiplayer"),
  1931. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_boots", "trp_vaegir_archer_multiplayer"),
  1932. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_vaegir_archer_multiplayer"),
  1933. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_cap", "trp_vaegir_archer_multiplayer"),
  1934. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_fur_cap", "trp_vaegir_archer_multiplayer"),
  1935. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_fur_helmet", "trp_vaegir_archer_multiplayer"),
  1936. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_spiked_helmet", "trp_vaegir_archer_multiplayer"),
  1937. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_lamellar_helmet", "trp_vaegir_archer_multiplayer"),
  1938.  
  1939. #2b-Vaegir Spearman
  1940. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_spear", "trp_vaegir_spearman_multiplayer"),
  1941. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_spear", "trp_vaegir_spearman_multiplayer"),
  1942. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_awlpike", "trp_vaegir_spearman_multiplayer"),
  1943. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_a", "trp_vaegir_spearman_multiplayer"),
  1944. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_b", "trp_vaegir_spearman_multiplayer"),
  1945. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_c", "trp_vaegir_spearman_multiplayer"),
  1946. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_d", "trp_vaegir_spearman_multiplayer"),
  1947. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_1", "trp_vaegir_spearman_multiplayer"),
  1948. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_2", "trp_vaegir_spearman_multiplayer"),
  1949. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_3", "trp_vaegir_spearman_multiplayer"),
  1950. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_4", "trp_vaegir_spearman_multiplayer"),
  1951. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_long_hafted_spiked_mace", "trp_vaegir_spearman_multiplayer"),
  1952. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_long_spiked_club", "trp_vaegir_spearman_multiplayer"),
  1953. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scimitar", "trp_vaegir_spearman_multiplayer"),
  1954. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scimitar_b", "trp_vaegir_spearman_multiplayer"),
  1955. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bardiche", "trp_vaegir_spearman_multiplayer"),
  1956. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_great_bardiche", "trp_vaegir_spearman_multiplayer"),
  1957. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_long_bardiche", "trp_vaegir_spearman_multiplayer"),
  1958. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_great_long_bardiche", "trp_vaegir_spearman_multiplayer"),
  1959. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_vaegir_spearman_multiplayer"),
  1960. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_linen_tunic", "trp_vaegir_spearman_multiplayer"),
  1961. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_jerkin", "trp_vaegir_spearman_multiplayer"),
  1962. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_vest", "trp_vaegir_spearman_multiplayer"),
  1963. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_vest", "trp_vaegir_spearman_multiplayer"),
  1964. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_armor", "trp_vaegir_spearman_multiplayer"),
  1965. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_elite_armor", "trp_vaegir_spearman_multiplayer"),
  1966. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hide_boots", "trp_vaegir_spearman_multiplayer"),
  1967. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_boots", "trp_vaegir_spearman_multiplayer"),
  1968. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_vaegir_spearman_multiplayer"),
  1969. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_vaegir_spearman_multiplayer"),
  1970. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_spiked_helmet", "trp_vaegir_spearman_multiplayer"),
  1971. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_fur_cap", "trp_vaegir_spearman_multiplayer"),
  1972. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_fur_helmet", "trp_vaegir_spearman_multiplayer"),
  1973. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_spiked_helmet", "trp_vaegir_spearman_multiplayer"),
  1974. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_lamellar_helmet", "trp_vaegir_spearman_multiplayer"),
  1975. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_noble_helmet", "trp_vaegir_spearman_multiplayer"),
  1976. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_war_helmet", "trp_vaegir_spearman_multiplayer"),
  1977. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nasal_helmet", "trp_vaegir_spearman_multiplayer"),
  1978. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_vaegir_spearman_multiplayer"),
  1979. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_vaegir_spearman_multiplayer"),
  1980. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_vaegir_spearman_multiplayer"),
  1981.  
  1982. #2c-Vaegir Horseman
  1983. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_darts", "trp_vaegir_horseman_multiplayer"),
  1984. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_darts", "trp_vaegir_horseman_multiplayer"),
  1985. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bardiche", "trp_vaegir_horseman_multiplayer"),
  1986. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_great_bardiche", "trp_vaegir_horseman_multiplayer"),
  1987. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scimitar", "trp_vaegir_horseman_multiplayer"),
  1988. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scimitar_b", "trp_vaegir_horseman_multiplayer"),
  1989. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lance", "trp_vaegir_horseman_multiplayer"),
  1990. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_lance", "trp_vaegir_horseman_multiplayer"),
  1991. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_cav_a", "trp_vaegir_horseman_multiplayer"),
  1992. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_cav_b", "trp_vaegir_horseman_multiplayer"),
  1993. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_c", "trp_vaegir_horseman_multiplayer"),
  1994. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_d", "trp_vaegir_horseman_multiplayer"),
  1995. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_linen_tunic", "trp_vaegir_horseman_multiplayer"),
  1996. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_vest", "trp_vaegir_horseman_multiplayer"),
  1997. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_vest", "trp_vaegir_horseman_multiplayer"),
  1998. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_studded_leather_coat", "trp_vaegir_horseman_multiplayer"),
  1999. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_armor", "trp_vaegir_horseman_multiplayer"),
  2000. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_elite_armor", "trp_vaegir_horseman_multiplayer"),
  2001. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hide_boots", "trp_vaegir_horseman_multiplayer"),
  2002. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_boots", "trp_vaegir_horseman_multiplayer"),
  2003. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_vaegir_horseman_multiplayer"),
  2004. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_vaegir_horseman_multiplayer"),
  2005. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_plate_boots", "trp_vaegir_horseman_multiplayer"),
  2006. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_spiked_helmet", "trp_vaegir_horseman_multiplayer"),
  2007. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nasal_helmet", "trp_vaegir_horseman_multiplayer"),
  2008. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_fur_cap", "trp_vaegir_horseman_multiplayer"),
  2009. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_fur_helmet", "trp_vaegir_horseman_multiplayer"),
  2010. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_spiked_helmet", "trp_vaegir_horseman_multiplayer"),
  2011. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_lamellar_helmet", "trp_vaegir_horseman_multiplayer"),
  2012. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_noble_helmet", "trp_vaegir_horseman_multiplayer"),
  2013. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_war_helmet", "trp_vaegir_horseman_multiplayer"),
  2014. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_vaegir_mask", "trp_vaegir_horseman_multiplayer"),
  2015. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_vaegir_horseman_multiplayer"),
  2016. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_vaegir_horseman_multiplayer"),
  2017. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_vaegir_horseman_multiplayer"),
  2018. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_saddle_horse", "trp_vaegir_horseman_multiplayer"),
  2019. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_courser", "trp_vaegir_horseman_multiplayer"),
  2020. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hunter", "trp_vaegir_horseman_multiplayer"),
  2021. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_warhorse_steppe", "trp_vaegir_horseman_multiplayer"),
  2022.  
  2023. #3-Khergit Warriors
  2024. #3a-Khergit Veteran Horse Archer
  2025. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_1", "trp_khergit_veteran_horse_archer_multiplayer"),
  2026. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_2", "trp_khergit_veteran_horse_archer_multiplayer"),
  2027. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_3", "trp_khergit_veteran_horse_archer_multiplayer"),
  2028. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_4", "trp_khergit_veteran_horse_archer_multiplayer"),
  2029. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_bow", "trp_khergit_veteran_horse_archer_multiplayer"),
  2030. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_bow", "trp_khergit_veteran_horse_archer_multiplayer"),
  2031. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_strong_bow", "trp_khergit_veteran_horse_archer_multiplayer"),
  2032. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arrows", "trp_khergit_veteran_horse_archer_multiplayer"),
  2033. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_arrows", "trp_khergit_veteran_horse_archer_multiplayer"),
  2034. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_steppe_cap_a", "trp_khergit_veteran_horse_archer_multiplayer"),
  2035. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_cap_b", "trp_khergit_veteran_horse_archer_multiplayer"),
  2036. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_steppe_cap_b", "trp_khergit_veteran_horse_archer_multiplayer"),
  2037. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steppe_cap", "trp_khergit_veteran_horse_archer_multiplayer"),
  2038. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_armor", "trp_khergit_veteran_horse_archer_multiplayer"),
  2039. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steppe_armor", "trp_khergit_veteran_horse_archer_multiplayer"),
  2040. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tribal_warrior_outfit", "trp_khergit_veteran_horse_archer_multiplayer"),
  2041. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_vest_khergit", "trp_khergit_veteran_horse_archer_multiplayer"),
  2042. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hide_boots", "trp_khergit_veteran_horse_archer_multiplayer"),
  2043. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_boots", "trp_khergit_veteran_horse_archer_multiplayer"),
  2044. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_leather_boots", "trp_khergit_veteran_horse_archer_multiplayer"),
  2045. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_khergit_veteran_horse_archer_multiplayer"),
  2046. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_khergit_veteran_horse_archer_multiplayer"),
  2047. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steppe_horse", "trp_khergit_veteran_horse_archer_multiplayer"),
  2048. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_khergit_veteran_horse_archer_multiplayer"),
  2049. #3a-Khergit Dismounted Lancer
  2050. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_khergit_infantry_multiplayer"),
  2051. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_jarid", "trp_khergit_infantry_multiplayer"),
  2052. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_1", "trp_khergit_infantry_multiplayer"),
  2053. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_2", "trp_khergit_infantry_multiplayer"),
  2054. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_3", "trp_khergit_infantry_multiplayer"),
  2055. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_4", "trp_khergit_infantry_multiplayer"),
  2056. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_a", "trp_khergit_infantry_multiplayer"),
  2057. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_b", "trp_khergit_infantry_multiplayer"),
  2058. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_c", "trp_khergit_infantry_multiplayer"),
  2059. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_round_b", "trp_khergit_infantry_multiplayer"),
  2060. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_round_c", "trp_khergit_infantry_multiplayer"),
  2061. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_spear", "trp_khergit_infantry_multiplayer"),
  2062. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hafted_blade_a", "trp_khergit_infantry_multiplayer"),
  2063. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hafted_blade_b", "trp_khergit_infantry_multiplayer"),
  2064. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_1", "trp_khergit_infantry_multiplayer"),
  2065. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_2", "trp_khergit_infantry_multiplayer"),
  2066. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_3", "trp_khergit_infantry_multiplayer"),
  2067. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_cap_b", "trp_khergit_infantry_multiplayer"),
  2068. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_steppe_cap_b", "trp_khergit_infantry_multiplayer"),
  2069. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steppe_cap", "trp_khergit_infantry_multiplayer"),
  2070. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_war_helmet", "trp_khergit_infantry_multiplayer"),
  2071. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_guard_helmet", "trp_khergit_infantry_multiplayer"),
  2072. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steppe_armor", "trp_khergit_infantry_multiplayer"),
  2073. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tribal_warrior_outfit", "trp_khergit_infantry_multiplayer"),
  2074. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_armor", "trp_khergit_infantry_multiplayer"),
  2075. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_elite_armor", "trp_khergit_infantry_multiplayer"),
  2076. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hide_boots", "trp_khergit_infantry_multiplayer"),
  2077. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_boots", "trp_khergit_infantry_multiplayer"),
  2078. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_leather_boots", "trp_khergit_infantry_multiplayer"),
  2079. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_khergit_infantry_multiplayer"),
  2080. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_khergit_infantry_multiplayer"),
  2081. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_khergit_infantry_multiplayer"),
  2082. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_khergit_infantry_multiplayer"),
  2083. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_khergit_infantry_multiplayer"),
  2084. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_gauntlets", "trp_khergit_infantry_multiplayer"),
  2085. #3a-Khergit Lancer
  2086. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_khergit_lancer_multiplayer"),
  2087. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_1", "trp_khergit_lancer_multiplayer"),
  2088. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_2", "trp_khergit_lancer_multiplayer"),
  2089. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_3", "trp_khergit_lancer_multiplayer"),
  2090. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_khergit_4", "trp_khergit_lancer_multiplayer"),
  2091. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_a", "trp_khergit_lancer_multiplayer"),
  2092. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_b", "trp_khergit_lancer_multiplayer"),
  2093. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_c", "trp_khergit_lancer_multiplayer"),
  2094. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lance", "trp_khergit_lancer_multiplayer"),
  2095. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_lance", "trp_khergit_lancer_multiplayer"),
  2096. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hafted_blade_a", "trp_khergit_lancer_multiplayer"),
  2097. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hafted_blade_b", "trp_khergit_lancer_multiplayer"),
  2098. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_one_handed_war_axe_a", "trp_khergit_lancer_multiplayer"),
  2099. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_steppe_cap_a", "trp_khergit_lancer_multiplayer"),
  2100. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_cap_b", "trp_khergit_lancer_multiplayer"),
  2101. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_steppe_cap_b", "trp_khergit_lancer_multiplayer"),
  2102. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steppe_cap", "trp_khergit_lancer_multiplayer"),
  2103. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_war_helmet", "trp_khergit_lancer_multiplayer"),
  2104. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_armor", "trp_khergit_lancer_multiplayer"),
  2105. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steppe_armor", "trp_khergit_lancer_multiplayer"),
  2106. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tribal_warrior_outfit", "trp_khergit_lancer_multiplayer"),
  2107. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_armor", "trp_khergit_lancer_multiplayer"),
  2108. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hide_boots", "trp_khergit_lancer_multiplayer"),
  2109. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_boots", "trp_khergit_lancer_multiplayer"),
  2110. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_khergit_leather_boots", "trp_khergit_lancer_multiplayer"),
  2111. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_khergit_lancer_multiplayer"),
  2112. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_khergit_lancer_multiplayer"),
  2113. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_khergit_lancer_multiplayer"),
  2114. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_khergit_lancer_multiplayer"),
  2115. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_khergit_lancer_multiplayer"),
  2116. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lamellar_gauntlets", "trp_khergit_lancer_multiplayer"),
  2117. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steppe_horse", "trp_khergit_lancer_multiplayer"),
  2118. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_courser", "trp_khergit_lancer_multiplayer"),
  2119. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hunter", "trp_khergit_lancer_multiplayer"),
  2120. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_warhorse_steppe", "trp_khergit_lancer_multiplayer"),
  2121.  
  2122. #Nord Warriors
  2123.  
  2124. #4c-Nord Archer
  2125. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arrows", "trp_nord_archer_multiplayer"),
  2126. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_barbed_arrows", "trp_nord_archer_multiplayer"),
  2127. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bodkin_arrows", "trp_nord_archer_multiplayer"),
  2128. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_1", "trp_nord_archer_multiplayer"),
  2129. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_2", "trp_nord_archer_multiplayer"),
  2130. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_2_small", "trp_nord_archer_multiplayer"),
  2131. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_3", "trp_nord_archer_multiplayer"),
  2132. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_3_small", "trp_nord_archer_multiplayer"),
  2133. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_one_handed_war_axe_a", "trp_nord_archer_multiplayer"),
  2134. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_one_handed_war_axe_b", "trp_nord_archer_multiplayer"),
  2135. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_two_handed_axe", "trp_nord_archer_multiplayer"),
  2136. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_short_bow", "trp_nord_archer_multiplayer"),
  2137. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_long_bow", "trp_nord_archer_multiplayer"),
  2138. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_blue_tunic", "trp_nord_archer_multiplayer"),
  2139. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_jerkin", "trp_nord_archer_multiplayer"),
  2140. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_byrnie", "trp_nord_archer_multiplayer"),
  2141. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_nord_archer_multiplayer"),
  2142. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_nord_archer_multiplayer"),
  2143. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_chausses", "trp_nord_archer_multiplayer"),
  2144. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_boots", "trp_nord_archer_multiplayer"),
  2145. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_archer_helmet", "trp_nord_archer_multiplayer"),
  2146. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_veteran_archer_helmet", "trp_nord_archer_multiplayer"),
  2147. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_footman_helmet", "trp_nord_archer_multiplayer"),
  2148. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_fighter_helmet", "trp_nord_archer_multiplayer"),
  2149.  
  2150. #4a-Nord Veteran
  2151. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_darts", "trp_nord_veteran_multiplayer"),
  2152. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_darts", "trp_nord_veteran_multiplayer"),
  2153. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_nord_veteran_multiplayer"),
  2154. # (call_script, "script_multiplayer_set_item_available_for_troop", "itm_throwing_spears", "trp_nord_veteran_multiplayer"),
  2155. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_1", "trp_nord_veteran_multiplayer"),
  2156. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_2", "trp_nord_veteran_multiplayer"),
  2157. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_2_small", "trp_nord_veteran_multiplayer"),
  2158. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_3", "trp_nord_veteran_multiplayer"),
  2159. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_3_small", "trp_nord_veteran_multiplayer"),
  2160. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_one_handed_war_axe_a", "trp_nord_veteran_multiplayer"),
  2161. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_one_handed_war_axe_b", "trp_nord_veteran_multiplayer"),
  2162. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_one_handed_battle_axe_a", "trp_nord_veteran_multiplayer"),
  2163. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_one_handed_battle_axe_b", "trp_nord_veteran_multiplayer"),
  2164. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_one_handed_battle_axe_c", "trp_nord_veteran_multiplayer"),
  2165. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_two_handed_axe", "trp_nord_veteran_multiplayer"),
  2166. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_two_handed_battle_axe_2", "trp_nord_veteran_multiplayer"),
  2167. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_great_axe", "trp_nord_veteran_multiplayer"),
  2168. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_long_axe", "trp_nord_veteran_multiplayer"),
  2169. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_long_axe_b", "trp_nord_veteran_multiplayer"),
  2170. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_long_axe_c", "trp_nord_veteran_multiplayer"),
  2171. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_spear", "trp_nord_veteran_multiplayer"),
  2172. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_spear", "trp_nord_veteran_multiplayer"),
  2173.  
  2174. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_round_a", "trp_nord_veteran_multiplayer"),
  2175. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_round_b", "trp_nord_veteran_multiplayer"),
  2176. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_round_c", "trp_nord_veteran_multiplayer"),
  2177. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_round_d", "trp_nord_veteran_multiplayer"),
  2178. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_round_e", "trp_nord_veteran_multiplayer"),
  2179. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_light_throwing_axes", "trp_nord_veteran_multiplayer"),
  2180. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_throwing_axes", "trp_nord_veteran_multiplayer"),
  2181. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_throwing_axes", "trp_nord_veteran_multiplayer"),
  2182. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_veteran_archer_helmet", "trp_nord_veteran_multiplayer"),
  2183. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_footman_helmet", "trp_nord_veteran_multiplayer"),
  2184. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_fighter_helmet", "trp_nord_veteran_multiplayer"),
  2185. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_huscarl_helmet", "trp_nord_veteran_multiplayer"),
  2186. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_warlord_helmet", "trp_nord_veteran_multiplayer"),
  2187.  
  2188. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_blue_tunic", "trp_nord_veteran_multiplayer"),
  2189. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_jerkin", "trp_nord_veteran_multiplayer"),
  2190. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_shirt", "trp_nord_veteran_multiplayer"),
  2191. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_hauberk", "trp_nord_veteran_multiplayer"),
  2192. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_banded_armor", "trp_nord_veteran_multiplayer"),
  2193. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_nord_veteran_multiplayer"),
  2194. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_nord_veteran_multiplayer"),
  2195. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_chausses", "trp_nord_veteran_multiplayer"),
  2196. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_boots", "trp_nord_veteran_multiplayer"),
  2197. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_nord_veteran_multiplayer"),
  2198. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_nord_veteran_multiplayer"),
  2199. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_nord_veteran_multiplayer"),
  2200.  
  2201. #4b-Nord Scout
  2202. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_darts", "trp_nord_scout_multiplayer"),
  2203. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_darts", "trp_nord_scout_multiplayer"),
  2204. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_nord_scout_multiplayer"),
  2205. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_throwing_spears", "trp_nord_scout_multiplayer"),
  2206. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_light_throwing_axes", "trp_nord_scout_multiplayer"),
  2207. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_throwing_axes", "trp_nord_scout_multiplayer"),
  2208. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_1", "trp_nord_scout_multiplayer"),
  2209. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_2", "trp_nord_scout_multiplayer"),
  2210. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_viking_3", "trp_nord_scout_multiplayer"),
  2211. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_two_handed_axe", "trp_nord_scout_multiplayer"),
  2212. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_two_handed_battle_axe_2", "trp_nord_scout_multiplayer"),
  2213. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_shortened_voulge", "trp_nord_scout_multiplayer"),
  2214.  
  2215. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_spear", "trp_nord_scout_multiplayer"),
  2216. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_spear", "trp_nord_scout_multiplayer"),
  2217. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_light_lance", "trp_nord_scout_multiplayer"),
  2218. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lance", "trp_nord_scout_multiplayer"),
  2219. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_a", "trp_nord_scout_multiplayer"),
  2220. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_b", "trp_nord_scout_multiplayer"),
  2221. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_c", "trp_nord_scout_multiplayer"),
  2222. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_archer_helmet", "trp_nord_scout_multiplayer"),
  2223. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_veteran_archer_helmet", "trp_nord_scout_multiplayer"),
  2224. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_footman_helmet", "trp_nord_scout_multiplayer"),
  2225. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_fighter_helmet", "trp_nord_scout_multiplayer"),
  2226. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nordic_huscarl_helmet", "trp_nord_scout_multiplayer"),
  2227.  
  2228.  
  2229. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_blue_tunic", "trp_nord_scout_multiplayer"),
  2230. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_jerkin", "trp_nord_scout_multiplayer"),
  2231. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_shirt", "trp_nord_scout_multiplayer"),
  2232. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_hauberk", "trp_nord_scout_multiplayer"),
  2233. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_nord_scout_multiplayer"),
  2234. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_leather_greaves", "trp_nord_scout_multiplayer"),
  2235. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_chausses", "trp_nord_scout_multiplayer"),
  2236. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_boots", "trp_nord_scout_multiplayer"),
  2237. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_nord_scout_multiplayer"),
  2238. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_nord_scout_multiplayer"),
  2239. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_nord_scout_multiplayer"),
  2240. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_saddle_horse", "trp_nord_scout_multiplayer"),
  2241. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_courser", "trp_nord_scout_multiplayer"),
  2242. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hunter", "trp_nord_scout_multiplayer"),
  2243.  
  2244.  
  2245. #5-Rhodok Warriors
  2246. #5a-Rhodok Veteran Crossbowman
  2247. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_crossbow", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2248. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_crossbow", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2249. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sniper_crossbow", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2250. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bolts", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2251. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_steel_bolts", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2252. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_fighting_pick", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2253. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_military_pick", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2254. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_club_with_spike_head", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2255. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_maul", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2256. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sledgehammer", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2257. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_a", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2258. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2259. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b_small", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2260. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_pavise_a", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2261. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_pavise_b", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2262. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_pavise_c", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2263. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_pavise_d", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2264. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_cap", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2265. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_padded_coif", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2266. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_footman_helmet", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2267. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_kettle_hat", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2268. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tunic_with_green_cape", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2269. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_aketon_green", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2270. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_armor", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2271. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ankle_boots", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2272. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2273. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2274. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_rhodok_veteran_crossbowman_multiplayer"),
  2275.  
  2276. #5b-Rhodok Sergeant
  2277. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_darts", "trp_rhodok_sergeant_multiplayer"),
  2278. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_darts", "trp_rhodok_sergeant_multiplayer"),
  2279. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_rhodok_sergeant_multiplayer"),
  2280. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_fighting_pick", "trp_rhodok_sergeant_multiplayer"),
  2281. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_military_pick", "trp_rhodok_sergeant_multiplayer"),
  2282. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_morningstar", "trp_rhodok_sergeant_multiplayer"),
  2283. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_club_with_spike_head", "trp_rhodok_sergeant_multiplayer"),
  2284. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_military_cleaver_b", "trp_rhodok_sergeant_multiplayer"),
  2285. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_military_cleaver_c", "trp_rhodok_sergeant_multiplayer"),
  2286. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_two_handed_cleaver", "trp_rhodok_sergeant_multiplayer"),
  2287. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_military_sickle_a", "trp_rhodok_sergeant_multiplayer"),
  2288. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_maul", "trp_rhodok_sergeant_multiplayer"),
  2289. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sledgehammer", "trp_rhodok_sergeant_multiplayer"),
  2290. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_warhammer", "trp_rhodok_sergeant_multiplayer"),
  2291. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_spear", "trp_rhodok_sergeant_multiplayer"),
  2292. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_pike", "trp_rhodok_sergeant_multiplayer"),
  2293. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ashwood_pike", "trp_rhodok_sergeant_multiplayer"),
  2294. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_spear", "trp_rhodok_sergeant_multiplayer"),
  2295. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_glaive", "trp_rhodok_sergeant_multiplayer"),
  2296. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_pavise_a", "trp_rhodok_sergeant_multiplayer"),
  2297. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_pavise_b", "trp_rhodok_sergeant_multiplayer"),
  2298. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_pavise_c", "trp_rhodok_sergeant_multiplayer"),
  2299. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_pavise_d", "trp_rhodok_sergeant_multiplayer"),
  2300. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_cap", "trp_rhodok_sergeant_multiplayer"),
  2301. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_padded_coif", "trp_rhodok_sergeant_multiplayer"),
  2302. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_footman_helmet", "trp_rhodok_sergeant_multiplayer"),
  2303. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_kettle_hat", "trp_rhodok_sergeant_multiplayer"),
  2304. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bascinet_2", "trp_rhodok_sergeant_multiplayer"),
  2305. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_full_helm", "trp_rhodok_sergeant_multiplayer"),
  2306. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_green_tunic", "trp_rhodok_sergeant_multiplayer"),
  2307. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_aketon_green", "trp_rhodok_sergeant_multiplayer"),
  2308. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ragged_outfit", "trp_rhodok_sergeant_multiplayer"),
  2309. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_armor", "trp_rhodok_sergeant_multiplayer"),
  2310. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_surcoat_over_mail", "trp_rhodok_sergeant_multiplayer"),
  2311. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ankle_boots", "trp_rhodok_sergeant_multiplayer"),
  2312. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_rhodok_sergeant_multiplayer"),
  2313. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_rhodok_sergeant_multiplayer"),
  2314. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_iron_greaves", "trp_rhodok_sergeant_multiplayer"),
  2315. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_rhodok_sergeant_multiplayer"),
  2316. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_rhodok_sergeant_multiplayer"),
  2317. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_rhodok_sergeant_multiplayer"),
  2318. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_gauntlets", "trp_rhodok_sergeant_multiplayer"),
  2319.  
  2320. #5c-Rhodok Horseman
  2321. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_darts", "trp_rhodok_horseman_multiplayer"),
  2322. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_war_darts", "trp_rhodok_horseman_multiplayer"),
  2323. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_rhodok_horseman_multiplayer"),
  2324. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_a", "trp_rhodok_horseman_multiplayer"),
  2325. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_b", "trp_rhodok_horseman_multiplayer"),
  2326. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sword_medieval_c", "trp_rhodok_horseman_multiplayer"),
  2327. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_fighting_pick", "trp_rhodok_horseman_multiplayer"),
  2328. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_military_pick", "trp_rhodok_horseman_multiplayer"),
  2329. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_morningstar", "trp_rhodok_horseman_multiplayer"),
  2330. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_military_cleaver_b", "trp_rhodok_horseman_multiplayer"),
  2331. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_military_cleaver_c", "trp_rhodok_horseman_multiplayer"),
  2332. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_two_handed_cleaver", "trp_rhodok_horseman_multiplayer"),
  2333. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_shortened_military_scythe", "trp_rhodok_horseman_multiplayer"),
  2334. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_light_lance", "trp_rhodok_horseman_multiplayer"),
  2335. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lance", "trp_rhodok_horseman_multiplayer"),
  2336. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_lance", "trp_rhodok_horseman_multiplayer"),
  2337. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_cav_a", "trp_rhodok_horseman_multiplayer"),
  2338. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_heater_cav_b", "trp_rhodok_horseman_multiplayer"),
  2339. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_padded_coif", "trp_rhodok_horseman_multiplayer"),
  2340. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_footman_helmet", "trp_rhodok_horseman_multiplayer"),
  2341. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_kettle_hat", "trp_rhodok_horseman_multiplayer"),
  2342. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bascinet_3", "trp_rhodok_horseman_multiplayer"),
  2343. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_green_tunic", "trp_rhodok_horseman_multiplayer"),
  2344. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_aketon_green", "trp_rhodok_horseman_multiplayer"),
  2345. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ragged_outfit", "trp_rhodok_horseman_multiplayer"),
  2346. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_armor", "trp_rhodok_horseman_multiplayer"),
  2347. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_surcoat_over_mail", "trp_rhodok_horseman_multiplayer"),
  2348. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_ankle_boots", "trp_rhodok_horseman_multiplayer"),
  2349. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_boots", "trp_rhodok_horseman_multiplayer"),
  2350. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_splinted_greaves", "trp_rhodok_horseman_multiplayer"),
  2351. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_plate_boots", "trp_rhodok_horseman_multiplayer"),
  2352. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_rhodok_horseman_multiplayer"),
  2353. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_rhodok_horseman_multiplayer"),
  2354. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_rhodok_horseman_multiplayer"),
  2355. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_gauntlets", "trp_rhodok_horseman_multiplayer"),
  2356. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_saddle_horse", "trp_rhodok_horseman_multiplayer"),
  2357. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_courser", "trp_rhodok_horseman_multiplayer"),
  2358. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_hunter", "trp_rhodok_horseman_multiplayer"),
  2359. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_warhorse", "trp_rhodok_horseman_multiplayer"),
  2360.  
  2361.  
  2362.  
  2363. #6-Sarranid Warriors
  2364. #5a-Sarranid archer
  2365. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_cloth_robe", "trp_sarranid_archer_multiplayer"),
  2366. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_skirmisher_armor", "trp_sarranid_archer_multiplayer"),
  2367. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_archers_vest", "trp_sarranid_archer_multiplayer"),
  2368. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_armor_b", "trp_sarranid_archer_multiplayer"),
  2369. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_felt_hat", "trp_sarranid_archer_multiplayer"),
  2370. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_turban", "trp_sarranid_archer_multiplayer"),
  2371. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_desert_turban", "trp_sarranid_archer_multiplayer"),
  2372. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_mail_coif", "trp_sarranid_archer_multiplayer"),
  2373. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_horseman_helmet", "trp_sarranid_archer_multiplayer"),
  2374. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_warrior_cap", "trp_sarranid_archer_multiplayer"),
  2375. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_boots_b", "trp_sarranid_archer_multiplayer"),
  2376. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_boots_c", "trp_sarranid_archer_multiplayer"),
  2377.  
  2378. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_short_bow", "trp_sarranid_archer_multiplayer"),
  2379. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_nomad_bow", "trp_sarranid_archer_multiplayer"),
  2380. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arrows", "trp_sarranid_archer_multiplayer"),
  2381. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_barbed_arrows", "trp_sarranid_archer_multiplayer"),
  2382. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scimitar", "trp_sarranid_archer_multiplayer"),
  2383. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mace_1", "trp_sarranid_archer_multiplayer"),
  2384. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_sword_a", "trp_sarranid_archer_multiplayer"),
  2385. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_sword_b", "trp_sarranid_archer_multiplayer"),
  2386.  
  2387. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_sarranid_archer_multiplayer"),
  2388.  
  2389.  
  2390.  
  2391. #Sarranid footman
  2392. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_cloth_robe", "trp_sarranid_footman_multiplayer"),
  2393. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_skirmisher_armor", "trp_sarranid_footman_multiplayer"),
  2394. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_archers_vest", "trp_sarranid_footman_multiplayer"),
  2395. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_leather_armor", "trp_sarranid_footman_multiplayer"),
  2396. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_armor_b", "trp_sarranid_footman_multiplayer"),
  2397.  
  2398. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_elite_armor", "trp_sarranid_footman_multiplayer"),
  2399. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_felt_hat", "trp_sarranid_footman_multiplayer"),
  2400. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_turban", "trp_sarranid_footman_multiplayer"),
  2401. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_desert_turban", "trp_sarranid_footman_multiplayer"),
  2402. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_mail_coif", "trp_sarranid_footman_multiplayer"),
  2403. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_warrior_cap", "trp_sarranid_footman_multiplayer"),
  2404. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_veiled_helmet", "trp_sarranid_footman_multiplayer"),
  2405. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_boots_b", "trp_sarranid_footman_multiplayer"),
  2406. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_boots_c", "trp_sarranid_footman_multiplayer"),
  2407. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_boots_d", "trp_sarranid_footman_multiplayer"),
  2408.  
  2409. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_sword_a", "trp_sarranid_footman_multiplayer"),
  2410. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_sword_b", "trp_sarranid_footman_multiplayer"),
  2411. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_sword_d", "trp_sarranid_footman_multiplayer"),
  2412.  
  2413. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_mace_1", "trp_sarranid_footman_multiplayer"),
  2414. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_axe_a", "trp_sarranid_footman_multiplayer"),
  2415. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_axe_b", "trp_sarranid_footman_multiplayer"),
  2416. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_two_handed_axe_a", "trp_sarranid_footman_multiplayer"),
  2417. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_two_handed_axe_b", "trp_sarranid_footman_multiplayer"),
  2418. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_two_handed_mace_1", "trp_sarranid_footman_multiplayer"),
  2419. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_bamboo_spear", "trp_sarranid_footman_multiplayer"),
  2420.  
  2421. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_spear", "trp_sarranid_footman_multiplayer"),
  2422. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_jarid", "trp_sarranid_footman_multiplayer"),
  2423. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_sarranid_footman_multiplayer"),
  2424.  
  2425. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_a", "trp_sarranid_footman_multiplayer"),
  2426. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_b", "trp_sarranid_footman_multiplayer"),
  2427. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_c", "trp_sarranid_footman_multiplayer"),
  2428. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_kite_d", "trp_sarranid_footman_multiplayer"),
  2429.  
  2430. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_sarranid_footman_multiplayer"),
  2431. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_sarranid_footman_multiplayer"),
  2432. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_sarranid_footman_multiplayer"),
  2433.  
  2434.  
  2435.  
  2436.  
  2437. #Sarranid mamluke
  2438. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_cloth_robe", "trp_sarranid_mamluke_multiplayer"),
  2439. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_skirmisher_armor", "trp_sarranid_mamluke_multiplayer"),
  2440. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_archers_vest", "trp_sarranid_mamluke_multiplayer"),
  2441. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_mail_shirt", "trp_sarranid_mamluke_multiplayer"),
  2442. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_cavalry_robe", "trp_sarranid_mamluke_multiplayer"),
  2443. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mamluke_mail", "trp_sarranid_mamluke_multiplayer"),
  2444. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_elite_armor", "trp_sarranid_mamluke_multiplayer"),
  2445.  
  2446.  
  2447. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_turban", "trp_sarranid_mamluke_multiplayer"),
  2448. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_desert_turban", "trp_sarranid_mamluke_multiplayer"),
  2449. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_horseman_helmet", "trp_sarranid_mamluke_multiplayer"),
  2450. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_mail_coif", "trp_sarranid_mamluke_multiplayer"),
  2451. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_veiled_helmet", "trp_sarranid_mamluke_multiplayer"),
  2452. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_boots_b", "trp_sarranid_mamluke_multiplayer"),
  2453. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_boots_c", "trp_sarranid_mamluke_multiplayer"),
  2454. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_boots_d", "trp_sarranid_mamluke_multiplayer"),
  2455.  
  2456. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_sword_a", "trp_sarranid_mamluke_multiplayer"),
  2457. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_sword_b", "trp_sarranid_mamluke_multiplayer"),
  2458. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_cavalry_sword", "trp_sarranid_mamluke_multiplayer"),
  2459. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_sword_d", "trp_sarranid_mamluke_multiplayer"),
  2460. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_mace_1", "trp_sarranid_mamluke_multiplayer"),
  2461. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_axe_a", "trp_sarranid_mamluke_multiplayer"),
  2462. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_axe_b", "trp_sarranid_mamluke_multiplayer"),
  2463. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_sarranid_two_handed_axe_a", "trp_sarranid_mamluke_multiplayer"),
  2464.  
  2465. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_lance", "trp_sarranid_mamluke_multiplayer"),
  2466. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_heavy_lance", "trp_sarranid_mamluke_multiplayer"),
  2467.  
  2468. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_jarid", "trp_sarranid_mamluke_multiplayer"),
  2469. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_javelin", "trp_sarranid_mamluke_multiplayer"),
  2470.  
  2471. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_a", "trp_sarranid_mamluke_multiplayer"),
  2472. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_b", "trp_sarranid_mamluke_multiplayer"),
  2473. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_tab_shield_small_round_c", "trp_sarranid_mamluke_multiplayer"),
  2474.  
  2475. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_saddle_horse", "trp_sarranid_mamluke_multiplayer"),
  2476. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_horse_a", "trp_sarranid_mamluke_multiplayer"),
  2477. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_arabian_horse_b", "trp_sarranid_mamluke_multiplayer"),
  2478. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_warhorse_sarranid", "trp_sarranid_mamluke_multiplayer"),
  2479.  
  2480. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_leather_gloves", "trp_sarranid_mamluke_multiplayer"),
  2481. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_mail_mittens", "trp_sarranid_mamluke_multiplayer"),
  2482. (call_script, "script_multiplayer_set_item_available_for_troop", "itm_scale_gauntlets", "trp_sarranid_mamluke_multiplayer"),
  2483.  
  2484.  
  2485. ]),
  2486.  
  2487. #script_get_army_size_from_slider_value
  2488. # INPUT: arg1 = slider_value
  2489. # OUTPUT: reg0 = army_size
  2490. ("get_army_size_from_slider_value",
  2491. [
  2492. (store_script_param, ":slider_value", 1),
  2493. (assign, ":army_size", ":slider_value"),
  2494. (try_begin),
  2495. (gt, ":slider_value", 25),
  2496. (store_sub, ":adder_value", ":slider_value", 25),
  2497. (val_add, ":army_size", ":adder_value"),
  2498. (try_begin),
  2499. (gt, ":slider_value", 50),
  2500. (store_sub, ":adder_value", ":slider_value", 50),
  2501. (val_mul, ":adder_value", 3),
  2502. (val_add, ":army_size", ":adder_value"),
  2503. (try_end),
  2504. (try_end),
  2505. (assign, reg0, ":army_size"),
  2506. ]),
  2507.  
  2508. #script_spawn_quick_battle_army
  2509. # INPUT: arg1 = initial_entry_point, arg2 = faction_no, arg3 = infantry_ratio, arg4 = archers_ratio, arg5 = cavalry_ratio, arg6 = divide_archer_entry_points, arg7 = player_team
  2510. # OUTPUT: none
  2511. ("spawn_quick_battle_army",
  2512. [
  2513. (store_script_param, ":cur_entry_point", 1),
  2514. (store_script_param, ":faction_no", 2),
  2515. (store_script_param, ":infantry_ratio", 3),
  2516. (store_script_param, ":archers_ratio", 4),
  2517. (store_script_param, ":cavalry_ratio", 5),
  2518. (store_script_param, ":divide_archer_entry_points", 6),
  2519. (store_script_param, ":player_team", 7),
  2520.  
  2521. (try_begin),
  2522. (eq, ":player_team", 1),
  2523. (call_script, "script_get_army_size_from_slider_value", "$g_quick_battle_army_1_size"),
  2524. (assign, ":army_size", reg0),
  2525. (set_player_troop, "$g_quick_battle_troop"),
  2526. (set_visitor, ":cur_entry_point", "$g_quick_battle_troop"),
  2527. (try_begin),
  2528. (eq, ":cur_entry_point", 0),
  2529. (try_begin),
  2530. (is_between, ":faction_no", npc_kingdoms_begin, npc_kingdoms_end),
  2531. (faction_get_slot, "$g_quick_battle_team_0_banner", ":faction_no", slot_faction_banner),
  2532. (else_try),
  2533. (assign, "$g_quick_battle_team_0_banner", "mesh_banners_default_b"),
  2534. (try_end),
  2535. (else_try),
  2536. (try_begin),
  2537. (is_between, ":faction_no", npc_kingdoms_begin, npc_kingdoms_end),
  2538. (faction_get_slot, "$g_quick_battle_team_1_banner", ":faction_no", slot_faction_banner),
  2539. (else_try),
  2540. (assign, "$g_quick_battle_team_1_banner", "mesh_banners_default_b"),
  2541. (try_end),
  2542. (try_end),
  2543. (val_add, ":cur_entry_point", 1),
  2544.  
  2545. (else_try),
  2546. (call_script, "script_get_army_size_from_slider_value", "$g_quick_battle_army_2_size"),
  2547. (assign, ":army_size", reg0),
  2548. (try_begin),
  2549. (eq, ":cur_entry_point", 0),
  2550. (assign, "$g_quick_battle_team_0_banner", "mesh_banners_default_a"),
  2551. (else_try),
  2552. (assign, "$g_quick_battle_team_1_banner", "mesh_banners_default_a"),
  2553. (try_end),
  2554. (val_add, ":cur_entry_point", 1),
  2555. (try_end),
  2556.  
  2557. (store_mul, ":num_infantry", ":infantry_ratio", ":army_size"),
  2558. (val_div, ":num_infantry", 100),
  2559. (store_mul, ":num_archers", ":archers_ratio", ":army_size"),
  2560. (val_div, ":num_archers", 100),
  2561. (store_mul, ":num_cavalry", ":cavalry_ratio", ":army_size"),
  2562. (val_div, ":num_cavalry", 100),
  2563.  
  2564. (try_begin),
  2565. (store_add, ":num_total", ":num_infantry", ":num_archers"),
  2566. (val_add, ":num_total", ":num_cavalry"),
  2567. (neq, ":num_total", ":army_size"),
  2568. (store_sub, ":leftover", ":army_size", ":num_total"),
  2569. (try_begin),
  2570. (gt, ":infantry_ratio", ":archers_ratio"),
  2571. (gt, ":infantry_ratio", ":cavalry_ratio"),
  2572. (val_add, ":num_infantry", ":leftover"),
  2573. (else_try),
  2574. (gt, ":archers_ratio", ":cavalry_ratio"),
  2575. (val_add, ":num_archers", ":leftover"),
  2576. (else_try),
  2577. (val_add, ":num_cavalry", ":leftover"),
  2578. (try_end),
  2579. (try_end),
  2580.  
  2581. (store_mul, ":rand_min", ":num_infantry", 15),
  2582. (val_div, ":rand_min", 100),
  2583. (store_mul, ":rand_max", ":num_infantry", 45),
  2584. (val_div, ":rand_max", 100),
  2585. (store_random_in_range, ":num_tier_2_infantry", ":rand_min", ":rand_max"),
  2586. (store_sub, ":num_tier_1_infantry", ":num_infantry", ":num_tier_2_infantry"),
  2587. (store_mul, ":rand_min", ":num_archers", 15),
  2588. (val_div, ":rand_min", 100),
  2589. (store_mul, ":rand_max", ":num_archers", 45),
  2590. (val_div, ":rand_max", 100),
  2591. (store_random_in_range, ":num_tier_2_archers", ":rand_min", ":rand_max"),
  2592. (store_sub, ":num_tier_1_archers", ":num_archers", ":num_tier_2_archers"),
  2593. (store_mul, ":rand_min", ":num_cavalry", 15),
  2594. (val_div, ":rand_min", 100),
  2595. (store_mul, ":rand_max", ":num_cavalry", 45),
  2596. (val_div, ":rand_max", 100),
  2597. (store_random_in_range, ":num_tier_2_cavalry", ":rand_min", ":rand_max"),
  2598. (store_sub, ":num_tier_1_cavalry", ":num_cavalry", ":num_tier_2_cavalry"),
  2599.  
  2600. (faction_get_slot, ":cur_troop", ":faction_no", slot_faction_quick_battle_tier_2_infantry),
  2601. (set_visitors, ":cur_entry_point", ":cur_troop", ":num_tier_2_infantry"),
  2602. (val_add, ":cur_entry_point", 1),
  2603. (faction_get_slot, ":cur_troop", ":faction_no", slot_faction_quick_battle_tier_1_infantry),
  2604. (set_visitors, ":cur_entry_point", ":cur_troop", ":num_tier_1_infantry"),
  2605. (val_add, ":cur_entry_point", 1),
  2606. (faction_get_slot, ":cur_troop", ":faction_no", slot_faction_quick_battle_tier_2_cavalry),
  2607. (set_visitors, ":cur_entry_point", ":cur_troop", ":num_tier_2_cavalry"),
  2608. (val_add, ":cur_entry_point", 1),
  2609. (faction_get_slot, ":cur_troop", ":faction_no", slot_faction_quick_battle_tier_1_cavalry),
  2610. (set_visitors, ":cur_entry_point", ":cur_troop", ":num_tier_1_cavalry"),
  2611. (val_add, ":cur_entry_point", 1),
  2612.  
  2613. (try_begin),
  2614. (eq, ":divide_archer_entry_points", 0),
  2615. (faction_get_slot, ":cur_troop", ":faction_no", slot_faction_quick_battle_tier_2_archer),
  2616. (set_visitors, ":cur_entry_point", ":cur_troop", ":num_tier_2_archers"),
  2617. (val_add, ":cur_entry_point", 1),
  2618. (faction_get_slot, ":cur_troop", ":faction_no", slot_faction_quick_battle_tier_1_archer),
  2619. (set_visitors, ":cur_entry_point", ":cur_troop", ":num_tier_1_archers"),
  2620. (val_add, ":cur_entry_point", 1),
  2621. (else_try),
  2622. (assign, ":cur_entry_point", 40), #archer positions begin point
  2623. (store_div, ":num_tier_1_archers_ceil_8", ":num_tier_1_archers", 8),
  2624. (val_mul, ":num_tier_1_archers_ceil_8", 8),
  2625. (try_begin),
  2626. (neq, ":num_tier_1_archers_ceil_8", ":num_tier_1_archers"),
  2627. (val_div, ":num_tier_1_archers_ceil_8", 8),
  2628. (val_add, ":num_tier_1_archers_ceil_8", 1),
  2629. (val_mul, ":num_tier_1_archers_ceil_8", 8),
  2630. (try_end),
  2631. (store_div, ":num_tier_2_archers_ceil_8", ":num_tier_2_archers", 8),
  2632. (val_mul, ":num_tier_2_archers_ceil_8", 8),
  2633. (try_begin),
  2634. (neq, ":num_tier_2_archers_ceil_8", ":num_tier_2_archers"),
  2635. (val_div, ":num_tier_2_archers_ceil_8", 8),
  2636. (val_add, ":num_tier_2_archers_ceil_8", 1),
  2637. (val_mul, ":num_tier_2_archers_ceil_8", 8),
  2638. (try_end),
  2639. (store_add, ":num_archers_ceil_8", ":num_tier_1_archers_ceil_8", ":num_tier_2_archers_ceil_8"),
  2640. (store_div, ":num_archers_per_entry_point", ":num_archers_ceil_8", 8),
  2641. (assign, ":left_tier_1_archers", ":num_tier_1_archers"),
  2642. (assign, ":left_tier_2_archers", ":num_tier_2_archers"),
  2643. (assign, ":end_cond", 1000),
  2644. (try_for_range, ":unused", 0, ":end_cond"),
  2645. (try_begin),
  2646. (gt, ":left_tier_2_archers", 0),
  2647. (assign, ":used_tier_2_archers", ":num_archers_per_entry_point"),
  2648. (val_min, ":used_tier_2_archers", ":left_tier_2_archers"),
  2649. (faction_get_slot, ":cur_troop", ":faction_no", slot_faction_quick_battle_tier_2_archer),
  2650. (set_visitors, ":cur_entry_point", ":cur_troop", ":used_tier_2_archers"),
  2651. (val_add, ":cur_entry_point", 1),
  2652. (val_sub, ":left_tier_2_archers", ":used_tier_2_archers"),
  2653. (else_try),
  2654. (gt, ":left_tier_1_archers", 0),
  2655. (assign, ":used_tier_1_archers", ":num_archers_per_entry_point"),
  2656. (val_min, ":used_tier_1_archers", ":left_tier_1_archers"),
  2657. (faction_get_slot, ":cur_troop", ":faction_no", slot_faction_quick_battle_tier_1_archer),
  2658. (set_visitors, ":cur_entry_point", ":cur_troop", ":used_tier_1_archers"),
  2659. (val_add, ":cur_entry_point", 1),
  2660. (val_sub, ":left_tier_1_archers", ":used_tier_1_archers"),
  2661. (else_try),
  2662. (assign, ":end_cond", 0),
  2663. (try_end),
  2664. (try_end),
  2665. (try_end),
  2666. ]),
  2667.  
  2668. ("player_arrived",
  2669. [
  2670. # (assign, ":player_faction_culture", "fac_culture_1"),
  2671. #SB : align start faction culture
  2672. (party_relocate_near_party, "p_main_party", "$g_starting_town", 2),
  2673. (party_get_slot, ":player_faction_culture", "$g_starting_town", slot_center_culture),
  2674. (faction_set_slot, "fac_player_supporters_faction", slot_faction_culture, ":player_faction_culture"),
  2675. (faction_set_slot, "fac_player_faction", slot_faction_culture, ":player_faction_culture"),
  2676. (party_set_morale, "p_main_party", 100),
  2677. ]),
  2678.  
  2679.  
  2680. #script_game_set_multiplayer_mission_end
  2681. # This script is called from the game engine when a multiplayer map is ended in clients (not in server).
  2682. # INPUT:
  2683. # none
  2684. # OUTPUT:
  2685. # none
  2686. ("game_set_multiplayer_mission_end",
  2687. [
  2688. (assign, "$g_multiplayer_mission_end_screen", 1),
  2689. ]),
  2690. #script_game_enable_cheat_menu
  2691. # This script is called from the game engine when user enters "cheatmenu from command console (ctrl+~).
  2692. # INPUT:
  2693. # none
  2694. # OUTPUT:
  2695. # none
  2696. ("game_enable_cheat_menu",
  2697. [
  2698. (store_script_param, ":input", 1),
  2699. (try_begin),
  2700. (eq, ":input", 0),
  2701. (assign, "$cheat_mode", 0),
  2702. (else_try),
  2703. (eq, ":input", 1),
  2704. (assign, "$cheat_mode", 1),
  2705. #SB : flavour text
  2706. (call_script, "script_objectionable_action", tmt_honest, "str_stop_cheating"),
  2707. (try_end),
  2708. (try_begin),
  2709. (neg|is_presentation_active, "prsnt_modify_slots"),
  2710. # (assign, "$g_talk_troop", ":input"),
  2711. (assign, "$g_presentation_state", 0),
  2712. (assign, "$g_presentation_input", rename_companion),
  2713. (start_presentation, "prsnt_modify_slots"),
  2714. (try_end),
  2715. ]),
  2716.  
  2717. #script_game_get_console_command
  2718. # This script is called from the game engine when a console command is entered from the dedicated server.
  2719. # INPUT: anything
  2720. # OUTPUT: s0 = result text
  2721. ("game_get_console_command",
  2722. [
  2723. (store_script_param, ":input", 1),
  2724. (store_script_param, ":val1", 2),
  2725. (try_begin),
  2726. #getting val2 for some commands
  2727. (eq, ":input", 2),
  2728. (store_script_param, ":val2", 3),
  2729. (end_try),
  2730. (try_begin),
  2731. (eq, ":input", 1),
  2732. (assign, reg0, ":val1"),
  2733. (try_begin),
  2734. (eq, ":val1", 1),
  2735. (assign, reg1, "$g_multiplayer_num_bots_team_1"),
  2736. (str_store_string, s0, "str_team_reg0_bot_count_is_reg1"),
  2737. (else_try),
  2738. (eq, ":val1", 2),
  2739. (assign, reg1, "$g_multiplayer_num_bots_team_2"),
  2740. (str_store_string, s0, "str_team_reg0_bot_count_is_reg1"),
  2741. (else_try),
  2742. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2743. (try_end),
  2744. (else_try),
  2745. (eq, ":input", 2),
  2746. (assign, reg0, ":val1"),
  2747. (assign, reg1, ":val2"),
  2748. (try_begin),
  2749. (eq, ":val1", 1),
  2750. (ge, ":val2", 0),
  2751. (assign, "$g_multiplayer_num_bots_team_1", ":val2"),
  2752. (str_store_string, s0, "str_team_reg0_bot_count_is_reg1"),
  2753. (else_try),
  2754. (eq, ":val1", 2),
  2755. (ge, ":val2", 0),
  2756. (assign, "$g_multiplayer_num_bots_team_2", ":val2"),
  2757. (str_store_string, s0, "str_team_reg0_bot_count_is_reg1"),
  2758. (else_try),
  2759. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2760. (try_end),
  2761. (else_try),
  2762. (eq, ":input", 3),
  2763. (assign, reg0, "$g_multiplayer_round_max_seconds"),
  2764. (str_store_string, s0, "str_maximum_seconds_for_round_is_reg0"),
  2765. (else_try),
  2766. (eq, ":input", 4),
  2767. (assign, reg0, ":val1"),
  2768. (try_begin),
  2769. (is_between, ":val1", multiplayer_round_max_seconds_min, multiplayer_round_max_seconds_max),
  2770. (assign, "$g_multiplayer_round_max_seconds", ":val1"),
  2771. (str_store_string, s0, "str_maximum_seconds_for_round_is_reg0"),
  2772. (get_max_players, ":num_players"),
  2773. (try_for_range, ":cur_player", 1, ":num_players"),
  2774. (player_is_active, ":cur_player"),
  2775. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_round_max_seconds, ":val1"),
  2776. (try_end),
  2777. (else_try),
  2778. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2779. (try_end),
  2780. (else_try),
  2781. (eq, ":input", 5),
  2782. (assign, reg0, "$g_multiplayer_respawn_period"),
  2783. (str_store_string, s0, "str_respawn_period_is_reg0_seconds"),
  2784. (else_try),
  2785. (eq, ":input", 6),
  2786. (assign, reg0, ":val1"),
  2787. (try_begin),
  2788. (is_between, ":val1", multiplayer_respawn_period_min, multiplayer_respawn_period_max),
  2789. (assign, "$g_multiplayer_respawn_period", ":val1"),
  2790. (str_store_string, s0, "str_respawn_period_is_reg0_seconds"),
  2791. (else_try),
  2792. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2793. (try_end),
  2794. (else_try),
  2795. (eq, ":input", 7),
  2796. (assign, reg0, "$g_multiplayer_num_bots_voteable"),
  2797. (str_store_string, s0, "str_bots_upper_limit_for_votes_is_reg0"),
  2798. (else_try),
  2799. (eq, ":input", 8),
  2800. (try_begin),
  2801. (is_between, ":val1", 0, 51),
  2802. (assign, "$g_multiplayer_num_bots_voteable", ":val1"),
  2803. (store_add, "$g_multiplayer_max_num_bots", ":val1", 1),
  2804. (assign, reg0, "$g_multiplayer_num_bots_voteable"),
  2805. (str_store_string, s0, "str_bots_upper_limit_for_votes_is_reg0"),
  2806. (get_max_players, ":num_players"),
  2807. (try_for_range, ":cur_player", 1, ":num_players"),
  2808. (player_is_active, ":cur_player"),
  2809. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_num_bots_voteable, ":val1"),
  2810. (try_end),
  2811. (else_try),
  2812. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2813. (try_end),
  2814. (else_try),
  2815. (eq, ":input", 9),
  2816. (try_begin),
  2817. (eq, "$g_multiplayer_maps_voteable", 1),
  2818. (str_store_string, s0, "str_map_is_voteable"),
  2819. (else_try),
  2820. (str_store_string, s0, "str_map_is_not_voteable"),
  2821. (try_end),
  2822. (else_try),
  2823. (eq, ":input", 10),
  2824. (try_begin),
  2825. (is_between, ":val1", 0, 2),
  2826. (assign, "$g_multiplayer_maps_voteable", ":val1"),
  2827. (try_begin),
  2828. (eq, ":val1", 1),
  2829. (str_store_string, s0, "str_map_is_voteable"),
  2830. (else_try),
  2831. (str_store_string, s0, "str_map_is_not_voteable"),
  2832. (try_end),
  2833. (get_max_players, ":num_players"),
  2834. (try_for_range, ":cur_player", 1, ":num_players"),
  2835. (player_is_active, ":cur_player"),
  2836. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_maps_voteable, ":val1"),
  2837. (try_end),
  2838. (else_try),
  2839. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2840. (try_end),
  2841. (else_try),
  2842. (eq, ":input", 11),
  2843. (try_begin),
  2844. (eq, "$g_multiplayer_factions_voteable", 1),
  2845. (str_store_string, s0, "str_factions_are_voteable"),
  2846. (else_try),
  2847. (str_store_string, s0, "str_factions_are_not_voteable"),
  2848. (try_end),
  2849. (else_try),
  2850. (eq, ":input", 12),
  2851. (try_begin),
  2852. (is_between, ":val1", 0, 2),
  2853. (assign, "$g_multiplayer_factions_voteable", ":val1"),
  2854. (try_begin),
  2855. (eq, ":val1", 1),
  2856. (str_store_string, s0, "str_factions_are_voteable"),
  2857. (else_try),
  2858. (str_store_string, s0, "str_factions_are_not_voteable"),
  2859. (try_end),
  2860. (get_max_players, ":num_players"),
  2861. (try_for_range, ":cur_player", 1, ":num_players"),
  2862. (player_is_active, ":cur_player"),
  2863. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_factions_voteable, ":val1"),
  2864. (try_end),
  2865. (else_try),
  2866. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2867. (try_end),
  2868. (else_try),
  2869. (eq, ":input", 13),
  2870. (try_begin),
  2871. (eq, "$g_multiplayer_player_respawn_as_bot", 1),
  2872. (str_store_string, s0, "str_players_respawn_as_bot"),
  2873. (else_try),
  2874. (str_store_string, s0, "str_players_do_not_respawn_as_bot"),
  2875. (try_end),
  2876. (else_try),
  2877. (eq, ":input", 14),
  2878. (try_begin),
  2879. (is_between, ":val1", 0, 2),
  2880. (assign, "$g_multiplayer_player_respawn_as_bot", ":val1"),
  2881. (try_begin),
  2882. (eq, ":val1", 1),
  2883. (str_store_string, s0, "str_players_respawn_as_bot"),
  2884. (else_try),
  2885. (str_store_string, s0, "str_players_do_not_respawn_as_bot"),
  2886. (try_end),
  2887. (get_max_players, ":num_players"),
  2888. (try_for_range, ":cur_player", 1, ":num_players"),
  2889. (player_is_active, ":cur_player"),
  2890. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_player_respawn_as_bot, ":val1"),
  2891. (try_end),
  2892. (else_try),
  2893. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2894. (try_end),
  2895. (else_try),
  2896. (eq, ":input", 15),
  2897. (try_begin),
  2898. (eq, "$g_multiplayer_kick_voteable", 1),
  2899. (str_store_string, s0, "str_kicking_a_player_is_voteable"),
  2900. (else_try),
  2901. (str_store_string, s0, "str_kicking_a_player_is_not_voteable"),
  2902. (try_end),
  2903. (else_try),
  2904. (eq, ":input", 16),
  2905. (try_begin),
  2906. (is_between, ":val1", 0, 2),
  2907. (assign, "$g_multiplayer_kick_voteable", ":val1"),
  2908. (try_begin),
  2909. (eq, ":val1", 1),
  2910. (str_store_string, s0, "str_kicking_a_player_is_voteable"),
  2911. (else_try),
  2912. (str_store_string, s0, "str_kicking_a_player_is_not_voteable"),
  2913. (try_end),
  2914. (get_max_players, ":num_players"),
  2915. (try_for_range, ":cur_player", 1, ":num_players"),
  2916. (player_is_active, ":cur_player"),
  2917. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_kick_voteable, ":val1"),
  2918. (try_end),
  2919. (else_try),
  2920. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2921. (try_end),
  2922. (else_try),
  2923. (eq, ":input", 17),
  2924. (try_begin),
  2925. (eq, "$g_multiplayer_ban_voteable", 1),
  2926. (str_store_string, s0, "str_banning_a_player_is_voteable"),
  2927. (else_try),
  2928. (str_store_string, s0, "str_banning_a_player_is_not_voteable"),
  2929. (try_end),
  2930. (else_try),
  2931. (eq, ":input", 18),
  2932. (try_begin),
  2933. (is_between, ":val1", 0, 2),
  2934. (assign, "$g_multiplayer_ban_voteable", ":val1"),
  2935. (try_begin),
  2936. (eq, ":val1", 1),
  2937. (str_store_string, s0, "str_banning_a_player_is_voteable"),
  2938. (else_try),
  2939. (str_store_string, s0, "str_banning_a_player_is_not_voteable"),
  2940. (try_end),
  2941. (get_max_players, ":num_players"),
  2942. (try_for_range, ":cur_player", 1, ":num_players"),
  2943. (player_is_active, ":cur_player"),
  2944. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_ban_voteable, ":val1"),
  2945. (try_end),
  2946. (else_try),
  2947. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2948. (try_end),
  2949. (else_try),
  2950. (eq, ":input", 19),
  2951. (assign, reg0, "$g_multiplayer_valid_vote_ratio"),
  2952. (str_store_string, s0, "str_percentage_of_yes_votes_required_for_a_poll_to_get_accepted_is_reg0"),
  2953. (else_try),
  2954. (eq, ":input", 20),
  2955. (try_begin),
  2956. (is_between, ":val1", 50, 101),
  2957. (assign, "$g_multiplayer_valid_vote_ratio", ":val1"),
  2958. (assign, reg0, ":val1"),
  2959. (str_store_string, s0, "str_percentage_of_yes_votes_required_for_a_poll_to_get_accepted_is_reg0"),
  2960. (else_try),
  2961. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2962. (try_end),
  2963. (else_try),
  2964. (eq, ":input", 21),
  2965. (assign, reg0, "$g_multiplayer_auto_team_balance_limit"),
  2966. (str_store_string, s0, "str_auto_team_balance_threshold_is_reg0"),
  2967. (else_try),
  2968. (eq, ":input", 22),
  2969. (try_begin),
  2970. (is_between, ":val1", 2, 7),
  2971. (assign, "$g_multiplayer_auto_team_balance_limit", ":val1"),
  2972. (assign, reg0, "$g_multiplayer_auto_team_balance_limit"),
  2973. (str_store_string, s0, "str_auto_team_balance_threshold_is_reg0"),
  2974. (get_max_players, ":num_players"),
  2975. (try_for_range, ":cur_player", 1, ":num_players"),
  2976. (player_is_active, ":cur_player"),
  2977. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_auto_team_balance_limit, ":val1"),
  2978. (try_end),
  2979. (else_try),
  2980. (ge, ":val1", 7),
  2981. (assign, "$g_multiplayer_auto_team_balance_limit", 1000),
  2982. (assign, reg0, "$g_multiplayer_auto_team_balance_limit"),
  2983. (str_store_string, s0, "str_auto_team_balance_threshold_is_reg0"),
  2984. (get_max_players, ":num_players"),
  2985. (try_for_range, ":cur_player", 1, ":num_players"),
  2986. (player_is_active, ":cur_player"),
  2987. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_auto_team_balance_limit, ":val1"),
  2988. (try_end),
  2989. (else_try),
  2990. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  2991. (try_end),
  2992. (else_try),
  2993. (eq, ":input", 23),
  2994. (assign, reg0, "$g_multiplayer_initial_gold_multiplier"),
  2995. (str_store_string, s0, "str_starting_gold_ratio_is_reg0"),
  2996. (else_try),
  2997. (eq, ":input", 24),
  2998. (try_begin),
  2999. (is_between, ":val1", 0, 1001),
  3000. (assign, "$g_multiplayer_initial_gold_multiplier", ":val1"),
  3001. (assign, reg0, "$g_multiplayer_initial_gold_multiplier"),
  3002. (str_store_string, s0, "str_starting_gold_ratio_is_reg0"),
  3003. (else_try),
  3004. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3005. (try_end),
  3006. (else_try),
  3007. (eq, ":input", 25),
  3008. (assign, reg0, "$g_multiplayer_battle_earnings_multiplier"),
  3009. (str_store_string, s0, "str_combat_gold_bonus_ratio_is_reg0"),
  3010. (else_try),
  3011. (eq, ":input", 26),
  3012. (try_begin),
  3013. (is_between, ":val1", 0, 1001),
  3014. (assign, "$g_multiplayer_battle_earnings_multiplier", ":val1"),
  3015. (assign, reg0, "$g_multiplayer_battle_earnings_multiplier"),
  3016. (str_store_string, s0, "str_combat_gold_bonus_ratio_is_reg0"),
  3017. (else_try),
  3018. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3019. (try_end),
  3020. (else_try),
  3021. (eq, ":input", 27),
  3022. (assign, reg0, "$g_multiplayer_round_earnings_multiplier"),
  3023. (str_store_string, s0, "str_round_gold_bonus_ratio_is_reg0"),
  3024. (else_try),
  3025. (eq, ":input", 28),
  3026. (try_begin),
  3027. (is_between, ":val1", 0, 1001),
  3028. (assign, "$g_multiplayer_round_earnings_multiplier", ":val1"),
  3029. (assign, reg0, "$g_multiplayer_round_earnings_multiplier"),
  3030. (str_store_string, s0, "str_round_gold_bonus_ratio_is_reg0"),
  3031. (else_try),
  3032. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3033. (try_end),
  3034. (else_try),
  3035. (eq, ":input", 29),
  3036. (try_begin),
  3037. (eq, "$g_multiplayer_allow_player_banners", 1),
  3038. (str_store_string, s0, "str_player_banners_are_allowed"),
  3039. (else_try),
  3040. (str_store_string, s0, "str_player_banners_are_not_allowed"),
  3041. (try_end),
  3042. (else_try),
  3043. (eq, ":input", 30),
  3044. (try_begin),
  3045. (is_between, ":val1", 0, 2),
  3046. (assign, "$g_multiplayer_allow_player_banners", ":val1"),
  3047. (try_begin),
  3048. (eq, ":val1", 1),
  3049. (str_store_string, s0, "str_player_banners_are_allowed"),
  3050. (else_try),
  3051. (str_store_string, s0, "str_player_banners_are_not_allowed"),
  3052. (try_end),
  3053. (else_try),
  3054. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3055. (try_end),
  3056. (else_try),
  3057. (eq, ":input", 31),
  3058. (try_begin),
  3059. (eq, "$g_multiplayer_force_default_armor", 1),
  3060. (str_store_string, s0, "str_default_armor_is_forced"),
  3061. (else_try),
  3062. (str_store_string, s0, "str_default_armor_is_not_forced"),
  3063. (try_end),
  3064. (else_try),
  3065. (eq, ":input", 32),
  3066. (try_begin),
  3067. (is_between, ":val1", 0, 2),
  3068. (assign, "$g_multiplayer_force_default_armor", ":val1"),
  3069. (try_begin),
  3070. (eq, ":val1", 1),
  3071. (str_store_string, s0, "str_default_armor_is_forced"),
  3072. (else_try),
  3073. (str_store_string, s0, "str_default_armor_is_not_forced"),
  3074. (try_end),
  3075. (else_try),
  3076. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3077. (try_end),
  3078. (else_try),
  3079. (eq, ":input", 33),
  3080. (assign, reg0, "$g_multiplayer_point_gained_from_flags"),
  3081. (str_store_string, s0, "str_point_gained_from_flags_is_reg0"),
  3082. (else_try),
  3083. (eq, ":input", 34),
  3084. (try_begin),
  3085. (is_between, ":val1", 25, 401),
  3086. (assign, "$g_multiplayer_point_gained_from_flags", ":val1"),
  3087. (assign, reg0, "$g_multiplayer_point_gained_from_flags"),
  3088. (str_store_string, s0, "str_point_gained_from_flags_is_reg0"),
  3089. (else_try),
  3090. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3091. (try_end),
  3092. (else_try),
  3093. (eq, ":input", 35),
  3094. (assign, reg0, "$g_multiplayer_point_gained_from_capturing_flag"),
  3095. (str_store_string, s0, "str_point_gained_from_capturing_flag_is_reg0"),
  3096. (else_try),
  3097. (eq, ":input", 36),
  3098. (try_begin),
  3099. (is_between, ":val1", 0, 11),
  3100. (assign, "$g_multiplayer_point_gained_from_capturing_flag", ":val1"),
  3101. (assign, reg0, "$g_multiplayer_point_gained_from_capturing_flag"),
  3102. (str_store_string, s0, "str_point_gained_from_capturing_flag_is_reg0"),
  3103. (else_try),
  3104. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3105. (try_end),
  3106. (else_try),
  3107. (eq, ":input", 37),
  3108. (assign, reg0, "$g_multiplayer_game_max_minutes"),
  3109. (str_store_string, s0, "str_map_time_limit_is_reg0"),
  3110. (else_try),
  3111. (eq, ":input", 38),
  3112. (try_begin),
  3113. (is_between, ":val1", 5, 121),
  3114. (assign, "$g_multiplayer_game_max_minutes", ":val1"),
  3115. (assign, reg0, "$g_multiplayer_game_max_minutes"),
  3116. (str_store_string, s0, "str_map_time_limit_is_reg0"),
  3117. (else_try),
  3118. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3119. (try_end),
  3120. (else_try),
  3121. (eq, ":input", 39),
  3122. (assign, reg0, "$g_multiplayer_game_max_points"),
  3123. (str_store_string, s0, "str_team_points_limit_is_reg0"),
  3124. (else_try),
  3125. (eq, ":input", 40),
  3126. (try_begin),
  3127. (is_between, ":val1", 3, 1001),
  3128. (assign, "$g_multiplayer_game_max_points", ":val1"),
  3129. (assign, reg0, "$g_multiplayer_game_max_points"),
  3130. (str_store_string, s0, "str_team_points_limit_is_reg0"),
  3131. (else_try),
  3132. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3133. (try_end),
  3134. (else_try),
  3135. (eq, ":input", 41),
  3136. (assign, reg0, "$g_multiplayer_number_of_respawn_count"),
  3137. (try_begin),
  3138. (eq, reg0, 0),
  3139. (str_store_string, s1, "str_unlimited"),
  3140. (else_try),
  3141. (str_store_string, s1, "str_reg0"),
  3142. (try_end),
  3143. (str_store_string, s0, "str_defender_spawn_count_limit_is_s1"),
  3144. (else_try),
  3145. (eq, ":input", 42),
  3146. (try_begin),
  3147. (is_between, ":val1", 0, 6),
  3148. (assign, "$g_multiplayer_number_of_respawn_count", ":val1"),
  3149. (assign, reg0, "$g_multiplayer_number_of_respawn_count"),
  3150. (try_begin),
  3151. (eq, reg0, 0),
  3152. (str_store_string, s1, "str_unlimited"),
  3153. (else_try),
  3154. (str_store_string, s1, "str_reg0"),
  3155. (try_end),
  3156. (str_store_string, s0, "str_defender_spawn_count_limit_is_s1"),
  3157. (get_max_players, ":num_players"),
  3158. (try_for_range, ":cur_player", 1, ":num_players"),
  3159. (player_is_active, ":cur_player"),
  3160. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_respawn_count, ":val1"),
  3161. (try_end),
  3162. (else_try),
  3163. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3164. (try_end),
  3165. (else_try),
  3166. (eq, ":input", 43),
  3167. (try_begin),
  3168. (eq, "$g_multiplayer_disallow_ranged_weapons", 1),
  3169. (str_store_string, s0, "str_ranged_weapons_are_disallowed"),
  3170. (else_try),
  3171. (str_store_string, s0, "str_ranged_weapons_are_allowed"),
  3172. (try_end),
  3173. (else_try),
  3174. (eq, ":input", 44),
  3175. (try_begin),
  3176. (is_between, ":val1", 0, 2),
  3177. (assign, "$g_multiplayer_disallow_ranged_weapons", ":val1"),
  3178. (try_begin),
  3179. (eq, ":val1", 1),
  3180. (str_store_string, s0, "str_ranged_weapons_are_disallowed"),
  3181. (else_try),
  3182. (str_store_string, s0, "str_ranged_weapons_are_allowed"),
  3183. (try_end),
  3184. (else_try),
  3185. (str_store_string, s0, "str_input_is_not_correct_for_the_command_type_help_for_more_information"),
  3186. (try_end),
  3187. (else_try),
  3188. (str_store_string, s0, "@{!}DEBUG : SYSTEM ERROR!"),
  3189. (try_end),
  3190. ]),
  3191.  
  3192.  
  3193. # script_game_event_party_encounter:
  3194. # This script is called from the game engine whenever player party encounters another party or a battle on the world map
  3195. # INPUT:
  3196. # param1: encountered_party
  3197. # param2: second encountered_party (if this was a battle
  3198. ("game_event_party_encounter",
  3199. [
  3200. (store_script_param_1, "$g_encountered_party"),
  3201. (store_script_param_2, "$g_encountered_party_2"),# encountered_party2 is set when we come across a battle or siege, otherwise it's a negative value
  3202. # (store_encountered_party, "$g_encountered_party"),
  3203. # (store_encountered_party2,"$g_encountered_party_2"), # encountered_party2 is set when we come across a battle or siege, otherwise it's a minus value
  3204. (store_faction_of_party, "$g_encountered_party_faction","$g_encountered_party"),
  3205. (store_relation, "$g_encountered_party_relation", "$g_encountered_party_faction", "fac_player_faction"),
  3206.  
  3207. (party_get_slot, "$g_encountered_party_type", "$g_encountered_party", slot_party_type),
  3208. (party_get_template_id,"$g_encountered_party_template","$g_encountered_party"),
  3209. # (try_begin),
  3210. # (gt, "$g_encountered_party_2", 0),
  3211. # (store_faction_of_party, "$g_encountered_party_2_faction","$g_encountered_party_2"),
  3212. # (store_relation, "$g_encountered_party_2_relation", "$g_encountered_party_2_faction", "fac_player_faction"),
  3213. # (party_get_template_id,"$g_encountered_party_2_template","$g_encountered_party_2"),
  3214. # (else_try),
  3215. # (assign, "$g_encountered_party_2_faction",-1),
  3216. # (assign, "$g_encountered_party_2_relation", 0),
  3217. # (assign,"$g_encountered_party_2_template", -1),
  3218. # (try_end),
  3219.  
  3220. #NPC companion changes begin
  3221. (call_script, "script_party_count_fit_regulars", "p_main_party"),
  3222. (assign, "$playerparty_prebattle_regulars", reg0),
  3223.  
  3224. # (try_begin),
  3225. # (assign, "$player_party__regulars", 0),
  3226. # (call_script, "script_party_count_fit_regulars", "p_main_party"),
  3227. # (gt, reg0, 0),
  3228. # (assign, "$player_party_contains_regulars", 1),
  3229. # (try_end),
  3230. #NPC companion changes end
  3231.  
  3232.  
  3233. (assign, "$g_last_rest_center", -1),
  3234. (assign, "$talk_context", 0),
  3235. (assign, "$g_player_surrenders",0),
  3236. (assign, "$g_enemy_surrenders",0),
  3237. (assign, "$g_leave_encounter",0),
  3238. (assign, "$g_engaged_enemy", 0),
  3239. # (assign,"$waiting_for_arena_fight_result", 0),
  3240. # (assign,"$arena_bet_amount",0),
  3241. # (assign,"$g_player_raiding_village",0),
  3242. (try_begin),
  3243. (neg|is_between, "$g_encountered_party", centers_begin, centers_end),
  3244. (rest_for_hours, 0), #stop waiting
  3245. (assign, "$g_infinite_camping", 0),
  3246. (try_end),
  3247. # (assign, "$g_permitted_to_center",0),
  3248. #SB : do cheat here before other menus are accessed
  3249. (try_begin),
  3250. (eq, "$new_encounter", 2),
  3251. (jump_to_menu, "mnu_party_cheat"),
  3252. (else_try),
  3253. (assign, "$new_encounter", 1), #check this in the menu.
  3254. (try_begin),
  3255. (lt, "$g_encountered_party_2",0), #Normal encounter. Not battle or siege.
  3256. (try_begin),
  3257. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
  3258. (jump_to_menu, "mnu_castle_outside"),
  3259. (else_try),
  3260. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_castle),
  3261. (jump_to_menu, "mnu_castle_outside"),
  3262. (else_try),
  3263. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_ship),
  3264. (jump_to_menu, "mnu_ship_reembark"),
  3265. (else_try),
  3266. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_village),
  3267. (jump_to_menu, "mnu_village"),
  3268. (else_try),
  3269. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_cattle_herd),
  3270. (jump_to_menu, "mnu_cattle_herd"),
  3271. (else_try),
  3272. (is_between, "$g_encountered_party", training_grounds_begin, training_grounds_end),
  3273. (jump_to_menu, "mnu_training_ground"),
  3274. (else_try),
  3275. (party_get_template_id, ":template", "$g_encountered_party"), #SB : is_between range
  3276. (is_between, ":template", "pt_steppe_bandit_lair", "pt_bandit_lair_templates_end"),
  3277. (assign, "$loot_screen_shown", 0),
  3278. (jump_to_menu, "mnu_bandit_lair"),
  3279. (else_try),
  3280. (eq, "$g_encountered_party", "p_zendar"),
  3281. (jump_to_menu, "mnu_zendar"),
  3282. (else_try),
  3283. (eq, "$g_encountered_party", "p_salt_mine"),
  3284. (jump_to_menu, "mnu_salt_mine"),
  3285. (else_try),
  3286. (eq, "$g_encountered_party", "p_four_ways_inn"),
  3287. (jump_to_menu, "mnu_four_ways_inn"),
  3288. (else_try),
  3289. (eq, "$g_encountered_party", "p_test_scene"),
  3290. (jump_to_menu, "mnu_test_scene"),
  3291. (else_try),
  3292. (eq, "$g_encountered_party", "p_battlefields"),
  3293. (jump_to_menu, "mnu_battlefields"),
  3294. (else_try),
  3295. (eq, "$g_encountered_party", "p_training_ground"),
  3296. (jump_to_menu, "mnu_tutorial"),
  3297. (else_try),
  3298. (eq, "$g_encountered_party", "p_camp_bandits"),
  3299. (jump_to_menu, "mnu_camp"),
  3300. (else_try),
  3301. (jump_to_menu, "mnu_simple_encounter"),
  3302. (try_end),
  3303. (else_try), #Battle or siege
  3304. (try_begin),
  3305. (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
  3306. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_castle),
  3307. (try_begin),
  3308. (eq, "$auto_enter_town", "$g_encountered_party"),
  3309. (jump_to_menu, "mnu_town"),
  3310. (else_try),
  3311. (eq, "$auto_besiege_town", "$g_encountered_party"),
  3312. (jump_to_menu, "mnu_besiegers_camp_with_allies"),
  3313. (else_try),
  3314. (jump_to_menu, "mnu_join_siege_outside"),
  3315. (try_end),
  3316. (else_try),
  3317. (jump_to_menu, "mnu_pre_join"),
  3318. (try_end),
  3319. (try_end),
  3320. (try_end),
  3321. (assign,"$auto_enter_town",0),
  3322. (assign,"$auto_besiege_town",0),
  3323. ]),
  3324.  
  3325. #script_game_event_simulate_battle:
  3326. # This script is called whenever the game simulates the battle between two parties on the map.
  3327. # INPUT:
  3328. # param1: Defender Party
  3329. # param2: Attacker Party
  3330. ("game_event_simulate_battle",
  3331. [
  3332. (store_script_param_1, ":root_defender_party"),
  3333. (store_script_param_2, ":root_attacker_party"),
  3334.  
  3335. (assign, "$marshall_defeated_in_battle", -1),
  3336.  
  3337. (store_current_hours, ":hours"),
  3338.  
  3339. ##diplomacy start+ Get campaign AI, used below
  3340. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  3341. ##diplomacy end+
  3342.  
  3343. (try_for_parties, ":party"),
  3344. (party_get_battle_opponent, ":opponent", ":party"),
  3345. (gt, ":opponent", 0),
  3346. (party_set_slot, ":party", slot_party_last_in_combat, ":hours"),
  3347. (try_end),
  3348.  
  3349. (assign, ":trigger_result", 1),
  3350. (try_begin),
  3351. (ge, ":root_defender_party", 0),
  3352. (ge, ":root_attacker_party", 0),
  3353. (party_is_active, ":root_defender_party"),
  3354. (party_is_active, ":root_attacker_party"),
  3355. (store_faction_of_party, ":defender_faction", ":root_defender_party"),
  3356. (store_faction_of_party, ":attacker_faction", ":root_attacker_party"),
  3357. #(neq, ":defender_faction", "fac_player_faction"),
  3358. #(neq, ":attacker_faction", "fac_player_faction"),
  3359. (store_relation, ":reln", ":defender_faction", ":attacker_faction"),
  3360. (lt, ":reln", 0),
  3361. (assign, ":trigger_result", 0),
  3362.  
  3363. (try_begin),
  3364. (this_or_next|eq, "$g_battle_simulation_cancel_for_party", ":root_defender_party"),
  3365. (eq, "$g_battle_simulation_cancel_for_party", ":root_attacker_party"),
  3366. (assign, "$g_battle_simulation_cancel_for_party", -1),
  3367. (assign, "$auto_enter_town", "$g_battle_simulation_auto_enter_town_after_battle"),
  3368. (assign, ":trigger_result", 1),
  3369. (else_try),
  3370. (try_begin),
  3371. (this_or_next|party_slot_eq, ":root_defender_party", slot_party_retreat_flag, 1),
  3372. (party_slot_eq, ":root_attacker_party", slot_party_retreat_flag, 1),
  3373. (assign, ":trigger_result", 1), #End battle!
  3374. (try_end),
  3375. (party_set_slot, ":root_attacker_party", slot_party_retreat_flag, 0),
  3376.  
  3377. #(assign, ":cancel_attack", 0),
  3378.  
  3379. (party_collect_attachments_to_party, ":root_defender_party", "p_collective_ally"),
  3380. (party_collect_attachments_to_party, ":root_attacker_party", "p_collective_enemy"),
  3381.  
  3382. ##diplomacy start+
  3383. (assign, ":terrain_code", dplmc_terrain_code_none),#defined in header_terrain.py
  3384. (try_begin),
  3385. (eq, "$g_dplmc_terrain_advantage", DPLMC_TERRAIN_ADVANTAGE_ENABLE),
  3386. (call_script, "script_dplmc_get_terrain_code_for_battle", ":root_attacker_party", ":root_defender_party"),
  3387. (assign, ":terrain_code", reg0),
  3388. #
  3389. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_collective_ally", ":terrain_code", 0, 1),
  3390. (assign, ":defender_strength", reg0),
  3391. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_collective_enemy", ":terrain_code", 0, 1),
  3392. (assign, ":attacker_strength", reg0),
  3393. (else_try),
  3394. (call_script, "script_party_calculate_strength", "p_collective_ally", 0),
  3395. (assign, ":defender_strength", reg0),
  3396. #(call_script, "script_party_count_fit_for_battle", "p_collective_enemy"),
  3397. (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
  3398. (assign, ":attacker_strength", reg0),
  3399. (try_end),
  3400. ##diplomacy end+
  3401.  
  3402. (store_div, ":defender_strength", ":defender_strength", 20),
  3403. (val_min, ":defender_strength", 50),
  3404. (val_max, ":defender_strength", 1),
  3405. (store_div, ":attacker_strength", ":attacker_strength", 20),
  3406. (val_min, ":attacker_strength", 50),
  3407. (val_add, ":attacker_strength", 1),
  3408. (try_begin),
  3409. #For sieges increase attacker casualties and reduce defender casualties.
  3410. (this_or_next|party_slot_eq, ":root_defender_party", slot_party_type, spt_castle),
  3411. (party_slot_eq, ":root_defender_party", slot_party_type, spt_town),
  3412. (val_mul, ":defender_strength", 123), #it was 1.5 in old version, now it is only 1.23
  3413. (val_div, ":defender_strength", 100),
  3414.  
  3415. (val_mul, ":attacker_strength", 100), #it was 0.5 in old version, now it is only 1 / 1.23
  3416. (val_div, ":attacker_strength", 123),
  3417. (try_end),
  3418.  
  3419. ##diplomacy begin
  3420. (assign, ":defender_percent", 100),
  3421. (try_begin),
  3422. (faction_get_slot, ":serfdom", ":defender_faction", dplmc_slot_faction_serfdom),
  3423. (neq, ":serfdom", 0),
  3424. (val_mul, ":serfdom", -2),
  3425. (val_add, ":defender_percent", ":serfdom"),
  3426. (try_end),
  3427. (try_begin),
  3428. (faction_get_slot, ":quality", ":defender_faction", dplmc_slot_faction_quality),
  3429. (neq, ":quality", 0),
  3430. (val_mul, ":quality", 4),
  3431. (val_add, ":defender_percent", ":quality"),
  3432. (try_end),
  3433. (val_mul, ":defender_strength", ":defender_percent"),
  3434. (val_div, ":defender_strength", 100),
  3435.  
  3436. (assign, ":attacker_percent", 100),
  3437. (try_begin),
  3438. (faction_get_slot, ":serfdom", ":attacker_faction", dplmc_slot_faction_serfdom),
  3439. (neq, ":serfdom", 0),
  3440. (val_mul, ":serfdom", -2),
  3441. (val_add, ":attacker_percent", ":serfdom"),
  3442. (try_end),
  3443. (try_begin),
  3444. (faction_get_slot, ":quality", ":attacker_faction", dplmc_slot_faction_quality),
  3445. (neq, ":quality", 0),
  3446. (val_mul, ":quality", 4),
  3447. (val_add, ":attacker_percent", ":quality"),
  3448. (try_end),
  3449. (val_mul, ":attacker_strength", ":attacker_percent"),
  3450. (val_div, ":attacker_strength", 100),
  3451. ##diplomacy end
  3452.  
  3453. (call_script, "script_party_count_fit_for_battle", "p_collective_ally", 0),
  3454. (assign, ":old_defender_strength", reg0),
  3455.  
  3456. (try_begin),
  3457. (neg|is_currently_night), #Don't fight at night
  3458. (inflict_casualties_to_party_group, ":root_attacker_party", ":defender_strength", "p_temp_casualties"),
  3459. (party_collect_attachments_to_party, ":root_attacker_party", "p_collective_enemy"),
  3460. (try_end),
  3461. (call_script, "script_party_count_fit_for_battle", "p_collective_enemy", 0),
  3462. (assign, ":new_attacker_strength", reg0),
  3463.  
  3464. (try_begin),
  3465. (gt, ":new_attacker_strength", 0),
  3466. (neg|is_currently_night), #Don't fight at night
  3467. (inflict_casualties_to_party_group, ":root_defender_party", ":attacker_strength", "p_temp_casualties"),
  3468. (party_collect_attachments_to_party, ":root_defender_party", "p_collective_ally"),
  3469. (try_end),
  3470. (call_script, "script_party_count_fit_for_battle", "p_collective_ally", 0),
  3471. (assign, ":new_defender_strength", reg0),
  3472.  
  3473. (try_begin),
  3474. (this_or_next|eq, ":new_attacker_strength", 0),
  3475. (eq, ":new_defender_strength", 0),
  3476. # Battle concluded! determine winner
  3477.  
  3478. (assign, ":do_not_end_battle", 0),
  3479. (try_begin),
  3480. (neg|troop_is_wounded, "trp_player"),
  3481. (eq, ":new_defender_strength", 0),
  3482. (eq, "$auto_enter_town", "$g_encountered_party"),
  3483. (eq, ":old_defender_strength", ":new_defender_strength"),
  3484. (assign, ":do_not_end_battle", 1),
  3485. (try_end),
  3486. (eq, ":do_not_end_battle", 0),
  3487.  
  3488. (try_begin),
  3489. (eq, ":new_attacker_strength", 0),
  3490. (eq, ":new_defender_strength", 0),
  3491. (assign, ":root_winner_party", -1),
  3492. (assign, ":root_defeated_party", -1),
  3493. (assign, ":collective_casualties", -1),
  3494. (else_try),
  3495. (eq, ":new_attacker_strength", 0),
  3496. (assign, ":root_winner_party", ":root_defender_party"),
  3497. (assign, ":root_defeated_party", ":root_attacker_party"),
  3498. (assign, ":collective_casualties", "p_collective_enemy"),
  3499. (else_try),
  3500. (assign, ":root_winner_party", ":root_attacker_party"),
  3501. (assign, ":root_defeated_party", ":root_defender_party"),
  3502. (assign, ":collective_casualties", "p_collective_ally"),
  3503. (try_end),
  3504. ##diplomacy begin
  3505. (try_begin),
  3506. (gt, ":root_defeated_party", -1),
  3507. # Recruiter kit begin
  3508. # This little fella just shows a message when a recruiter is defeated.
  3509.  
  3510. (assign, ":minimum_distance", 1000000),
  3511. (try_for_range, ":center", centers_begin, centers_end),
  3512. (store_distance_to_party_from_party, ":dist", ":root_defeated_party", ":center"),
  3513. (try_begin),
  3514. (lt, ":dist", ":minimum_distance"),
  3515. (assign, ":minimum_distance", ":dist"),
  3516. (assign, ":nearest_center", ":center"),
  3517. (try_end),
  3518. (try_end),
  3519.  
  3520. (str_clear, s10),
  3521. (try_begin),
  3522. (gt, ":nearest_center", 0),
  3523. (str_store_party_name, s10, ":nearest_center"),
  3524. (str_store_string, s10, "@ near {s10}"),
  3525. (try_end),
  3526.  
  3527. #SB : reformat loop
  3528. (party_get_slot, ":type", ":root_defeated_party", slot_party_type),
  3529. (try_begin),
  3530. (eq, ":type", dplmc_spt_recruiter),
  3531. (party_get_slot, reg10, ":root_defeated_party", dplmc_slot_party_recruiter_needed_recruits),
  3532. (party_get_slot, ":party_origin", ":root_defeated_party", dplmc_slot_party_recruiter_origin),
  3533. (str_store_party_name_link, s13, ":party_origin"),
  3534. (display_log_message, "@Your recruiter who was commissioned to recruit {reg10} recruits to {s13} has been defeated{s10}!", message_defeated),
  3535. (else_try),
  3536. (eq,":type", dplmc_spt_gift_caravan),
  3537. (party_get_slot, ":target_troop", ":root_defeated_party", slot_party_orders_object),
  3538. (party_get_slot, ":target_party", ":root_defeated_party", slot_party_ai_object),
  3539. (try_begin),
  3540. (gt, ":target_troop", 0),
  3541. (str_store_troop_name, s13, ":target_troop"),
  3542. (else_try),
  3543. (str_store_party_name, s13, ":target_party"),
  3544. (end_try),
  3545. (party_get_slot, ":gift", ":root_defeated_party", dplmc_slot_party_mission_diplomacy),
  3546. (str_store_item_name, s12, ":gift"),
  3547. #SB : defeated -> looted
  3548. (display_log_message, "@Your caravan sending {s12} to {s13} has been looted{s10}!", message_defeated),
  3549. (else_try),
  3550. (eq, ":type", spt_messenger),
  3551. (party_get_slot, ":target_party", ":root_defeated_party", slot_party_orders_object),
  3552. (party_stack_get_troop_id, ":party_leader", ":target_party", 0),
  3553. (str_store_troop_name, s13, ":party_leader"),
  3554. #SB : defeated -> intercepted
  3555. (display_log_message, "@Your messenger on the way to {s13} has been ambushed{s10}!", message_defeated),
  3556. (else_try),
  3557. (eq, ":type", spt_patrol),
  3558. (party_slot_eq, ":root_defeated_party", dplmc_slot_party_mission_diplomacy, "trp_player"),
  3559. (party_get_slot, ":target_party", ":root_defeated_party", slot_party_ai_object),
  3560. (str_store_party_name, s13, ":target_party"),
  3561. (display_log_message, "@Your soldiers patrolling {s13} have been defeated{s10}!", message_defeated),
  3562. (else_try),
  3563. (eq, ":type", spt_scout),
  3564. (store_faction_of_party, ":party_faction", ":root_defeated_party"),
  3565. (eq, ":party_faction", "$players_kingdom"),
  3566. (party_get_slot, ":target_party", ":root_defeated_party", slot_party_orders_object),
  3567. (str_store_party_name, s13, ":target_party"),
  3568. (display_log_message, "@A scout trying to gather information about {s13} has been slain{s10}!", message_defeated),
  3569. (else_try), #SB : reinforcements
  3570. (eq, ":type", spt_reinforcement),
  3571. (store_faction_of_party, ":party_faction", ":root_defeated_party"),
  3572. (eq, ":party_faction", "$players_kingdom"), #show only if relevant
  3573. (party_get_slot, ":home_village", ":root_defeated_party", slot_party_home_center),
  3574. (party_get_slot, ":target_party", ":home_village", slot_village_bound_center),
  3575. (str_store_party_name_link, s12, ":home_village"),
  3576. (str_store_party_name_link, s13, ":target_party"),
  3577. (display_log_message, "@Reinforcements from {s12} intended for {s13} have been intercepted{s10}!", message_defeated),
  3578. (try_end),
  3579. (try_end),
  3580. ##diplomacy end
  3581.  
  3582. (try_begin),
  3583. (ge, ":root_winner_party", 0),
  3584. (call_script, "script_get_nonempty_party_in_group", ":root_winner_party"),
  3585. (assign, ":nonempty_winner_party", reg0),
  3586. (store_faction_of_party, ":faction_receiving_prisoners", ":nonempty_winner_party"),
  3587. (store_faction_of_party, ":defeated_faction", ":root_defeated_party"),
  3588. (else_try),
  3589. (assign, ":nonempty_winner_party", -1),
  3590. (try_end),
  3591.  
  3592. (try_begin),
  3593. (ge, ":collective_casualties", 0),
  3594. (party_get_num_companion_stacks, ":num_stacks", ":collective_casualties"),
  3595. (else_try),
  3596. (assign, ":num_stacks", 0),
  3597. (try_end),
  3598.  
  3599. #SB : set up primary color here
  3600. (faction_get_color, ":faction_color", ":faction_receiving_prisoners"),
  3601. #depending on war status we can enforce either message_positive or message_negative
  3602. (try_for_range, ":troop_iterator", 0, ":num_stacks"),
  3603. (party_stack_get_troop_id, ":cur_troop_id", ":collective_casualties", ":troop_iterator"),
  3604. (troop_is_hero, ":cur_troop_id"),
  3605.  
  3606. (try_begin),
  3607. #abort quest if troop loses a battle during rest time
  3608. (check_quest_active, "qst_lend_surgeon"),
  3609. (quest_slot_eq, "qst_lend_surgeon", slot_quest_giver_troop, ":cur_troop_id"),
  3610. (call_script, "script_abort_quest", "qst_lend_surgeon", 0),
  3611. (try_end),
  3612.  
  3613. (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
  3614.  
  3615. (troop_set_slot, ":cur_troop_id", slot_troop_leaded_party, -1),
  3616.  
  3617. (store_random_in_range, ":rand", 0, 100),
  3618. (str_store_troop_name_link, s1, ":cur_troop_id"),
  3619. (str_store_faction_name_link, s2, ":faction_receiving_prisoners"),
  3620. (store_troop_faction, ":defeated_troop_faction", ":cur_troop_id"),
  3621. (str_store_faction_name_link, s3, ":defeated_troop_faction"),
  3622. #SB : colorize
  3623. (faction_get_color, ":color", ":defeated_troop_faction"),
  3624. (try_begin),
  3625. (ge, ":rand", hero_escape_after_defeat_chance),
  3626. (party_stack_get_troop_id, ":leader_troop_id", ":nonempty_winner_party", 0),
  3627. ##diplomacy start+ kingdom ladies might lead kingdom parties
  3628. (this_or_next|is_between,":leader_troop_id", kingdom_ladies_begin, kingdom_ladies_end),
  3629. (is_between, ":leader_troop_id", active_npcs_begin, active_npcs_end),
  3630.  
  3631. (this_or_next|troop_slot_eq, ":leader_troop_id", slot_troop_occupation, slto_kingdom_hero),
  3632. ##diplomacy end+
  3633. (is_between, ":leader_troop_id", active_npcs_begin, active_npcs_end), #disable non-kingdom parties capturing enemy lords
  3634. (party_add_prisoners, ":nonempty_winner_party", ":cur_troop_id", 1),
  3635. (gt, reg0, 0),
  3636. #(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 1),
  3637. (troop_set_slot, ":cur_troop_id", slot_troop_prisoner_of_party, ":nonempty_winner_party"),
  3638.  
  3639. (display_log_message, "str_hero_taken_prisoner", ":color"),
  3640.  
  3641. (try_begin),
  3642. (call_script, "script_cf_prisoner_offered_parole", ":cur_troop_id"),
  3643.  
  3644. (try_begin),
  3645. (eq, "$cheat_mode", 1),
  3646. (display_message, "@{!}DEBUG : Prisoner granted parole"),
  3647. (try_end),
  3648.  
  3649. (call_script, "script_troop_change_relation_with_troop", ":leader_troop_id", ":cur_troop_id", 3),
  3650. (val_add, "$total_battle_enemy_changes", 3),
  3651. (else_try),
  3652. (try_begin),
  3653. (eq, "$cheat_mode", 1),
  3654. (display_message, "@{!}DEBUG : Prisoner not offered parole"),
  3655. (try_end),
  3656.  
  3657. (call_script, "script_troop_change_relation_with_troop", ":leader_troop_id", ":cur_troop_id", -5),
  3658. (val_add, "$total_battle_enemy_changes", -5),
  3659. (try_end),
  3660.  
  3661. (store_faction_of_party, ":capturer_faction", ":nonempty_winner_party"),
  3662. (call_script, "script_update_troop_location_notes_prisoned", ":cur_troop_id", ":capturer_faction"),
  3663. (else_try),
  3664. (display_message,"@{s1} of {s3} was defeated in battle but managed to escape.", ":color"),
  3665. (try_end),
  3666.  
  3667. (try_begin),
  3668. (store_troop_faction, ":cur_troop_faction", ":cur_troop_id"),
  3669. (is_between, ":cur_troop_faction", kingdoms_begin, kingdoms_end),
  3670. (faction_slot_eq, ":cur_troop_faction", slot_faction_marshall, ":cur_troop_id"),
  3671. (is_between, ":cur_troop_faction", kingdoms_begin, kingdoms_end),
  3672. (assign, "$marshall_defeated_in_battle", ":cur_troop_id"),
  3673. #Marshall is defeated, refresh ai.
  3674. (assign, "$g_recalculate_ais", 1),
  3675. (try_end),
  3676.  
  3677. ##diplomacy begin
  3678. (try_begin),
  3679. (call_script, "script_dplmc_is_affiliated_family_member", ":cur_troop_id"),
  3680. (eq, reg0, 1),
  3681. ##diplomacy start+ skip relationship decay for defeat when the player himself is imprisoned or wounded
  3682. (eq, "$g_player_is_captive", 0),
  3683. (neg|troop_slot_ge, "trp_player", slot_troop_prisoner_of_party, 1),
  3684. (neg|troop_is_wounded, "trp_player"),
  3685. ##diplomacy end+
  3686. (assign, ":mitigating_factors", 0),
  3687. (try_begin),
  3688. #Being at war with the troop's faction is a mitigating factor, unless the player leads his faction.
  3689. (store_relation, reg0, "$players_kingdom", ":cur_troop_faction"),
  3690. (lt, reg0, 0),
  3691. (neq, "$players_kingdom", "fac_player_supporters_faction"),
  3692. (neg|faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  3693. (assign, ":mitigating_factors", 1),
  3694. (try_end),
  3695.  
  3696. (try_for_range, ":family_member", lords_begin, kingdom_ladies_end),
  3697. ##diplomacy start+
  3698. #The dead, exiled, and retired don't participate in this
  3699. (neg|troop_slot_ge, ":family_member", slot_troop_occupation, slto_retirement),
  3700. #Members of factions at war with the defeated affiliate's faction don't have
  3701. #any relation loss either: it would be nonsensical for them to be willing to
  3702. #battle him themselves, but become enraged at his defeat.
  3703. (store_troop_faction, ":family_member_faction", ":family_member"),
  3704. (store_relation, reg0, ":family_member_faction", ":cur_troop_faction"),
  3705. (this_or_next|eq, ":family_member_faction", ":cur_troop_faction"),
  3706. (ge, reg0, 0),
  3707. ##(call_script, "script_troop_get_family_relation_to_troop", ":family_member", "$g_player_affiliated_troop"),
  3708. (call_script, "script_dplmc_is_affiliated_family_member", ":family_member"),
  3709. (gt, reg0, 0),
  3710. (assign, reg0, -2),
  3711. (try_begin),
  3712. (eq, ":reduce_campaign_ai", 0),#hard: -1
  3713. (assign, reg0, -1),
  3714. (else_try),
  3715. (eq, ":reduce_campaign_ai", 1),#medium: -1 or 0
  3716. (store_random_in_range, reg0, -1, 1),
  3717. (else_try),
  3718. (eq, ":reduce_campaign_ai", 2),#easy: 0
  3719. (assign, reg0, 0),
  3720. (try_end),
  3721. (val_add, reg0, ":mitigating_factors"),
  3722. (lt, reg0, 0),
  3723. (call_script, "script_change_player_relation_with_troop", ":family_member", reg0),
  3724. ##diplomacy end+
  3725. (try_end),
  3726. (try_end),
  3727. ##diplomacy end
  3728. (try_end),
  3729.  
  3730. (try_begin),
  3731. (ge, ":collective_casualties", 0),
  3732. (party_get_num_prisoner_stacks, ":num_stacks", ":collective_casualties"),
  3733. (else_try),
  3734. (assign, ":num_stacks", 0),
  3735. (try_end),
  3736. (try_for_range, ":troop_iterator", 0, ":num_stacks"),
  3737. (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":collective_casualties", ":troop_iterator"),
  3738. (troop_is_hero, ":cur_troop_id"),
  3739. (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
  3740. (store_troop_faction, ":cur_troop_faction", ":cur_troop_id"),
  3741. (str_store_troop_name_link, s1, ":cur_troop_id"),
  3742. (str_store_faction_name_link, s2, ":faction_receiving_prisoners"),
  3743. (str_store_faction_name_link, s3, ":cur_troop_faction"),
  3744. #SB : colorize, use previously set up primary color
  3745. (display_log_message, "str_hero_freed", ":faction_color"),
  3746. (try_end),
  3747.  
  3748. (try_begin),
  3749. (ge, ":collective_casualties", 0),
  3750. (party_clear, "p_temp_party"),
  3751. (assign, "$g_move_heroes", 0), #heroes are already processed above. Skip them here.
  3752. (call_script, "script_party_add_party_prisoners", "p_temp_party", ":collective_casualties"),
  3753. (call_script, "script_party_prisoners_add_party_companions", "p_temp_party", ":collective_casualties"),
  3754. (distribute_party_among_party_group, "p_temp_party", ":root_winner_party"),
  3755.  
  3756. (call_script, "script_battle_political_consequences", ":root_defeated_party", ":root_winner_party"),
  3757.  
  3758. (call_script, "script_clear_party_group", ":root_defeated_party"),
  3759. (try_end),
  3760. (assign, ":trigger_result", 1), #End battle!
  3761.  
  3762. #Center captured
  3763. (try_begin),
  3764. (ge, ":collective_casualties", 0),
  3765. (party_get_slot, ":cur_party_type", ":root_defeated_party", slot_party_type),
  3766. (this_or_next|eq, ":cur_party_type", spt_town),
  3767. (eq, ":cur_party_type", spt_castle),
  3768.  
  3769. (assign, "$g_recalculate_ais", 1),
  3770.  
  3771. (store_faction_of_party, ":winner_faction", ":root_winner_party"),
  3772. (store_faction_of_party, ":defeated_faction", ":root_defeated_party"),
  3773.  
  3774. (str_store_party_name, s1, ":root_defeated_party"),
  3775. (str_store_faction_name, s2, ":winner_faction"),
  3776. (str_store_faction_name, s3, ":defeated_faction"),
  3777. ## CC
  3778. (faction_get_color, ":faction_color", ":winner_faction"),
  3779. (display_log_message, "str_center_captured", ":faction_color"),
  3780. ## CC
  3781.  
  3782. (store_current_hours, ":hours"),
  3783. (faction_set_slot, ":winner_faction", slot_faction_ai_last_decisive_event, ":hours"),
  3784.  
  3785. (try_begin),
  3786. (eq, "$g_encountered_party", ":root_defeated_party"),
  3787. (call_script, "script_add_log_entry", logent_player_participated_in_siege, "trp_player", "$g_encountered_party", 0, "$g_encountered_party_faction"),
  3788. (try_end),
  3789.  
  3790. (try_begin),
  3791. (party_get_num_companion_stacks, ":num_stacks", ":root_winner_party"),
  3792. (gt, ":num_stacks", 0),
  3793. (party_stack_get_troop_id, ":leader_troop_no", ":root_winner_party", 0),
  3794. ##diplomacy start+ support for promoted kingdom ladies
  3795. (is_between, ":leader_troop_no", heroes_begin, heroes_end),#<- dplmc+ added
  3796. (this_or_next|troop_slot_eq, ":leader_troop_no", slot_troop_occupation, slto_kingdom_hero),#<- dplmc+ addded
  3797. (is_between, ":leader_troop_no", active_npcs_begin, active_npcs_end),
  3798. ##diplomacy end+
  3799. (party_set_slot, ":root_defeated_party", slot_center_last_taken_by_troop, ":leader_troop_no"),
  3800. (else_try),
  3801. (party_set_slot, ":root_defeated_party", slot_center_last_taken_by_troop, -1),
  3802. (try_end),
  3803.  
  3804. (call_script, "script_lift_siege", ":root_defeated_party", 0),
  3805. (call_script, "script_spawn_looters", ":root_defeated_party", 5), #SB : spawn some looters
  3806. (store_faction_of_party, ":fortress_faction", ":root_defeated_party"),
  3807. (try_begin),
  3808. (is_between, ":root_defeated_party", towns_begin, towns_end),
  3809. (assign, ":damage", 40),
  3810. (else_try),
  3811. (assign, ":damage", 20),
  3812. (try_end),
  3813. (call_script, "script_faction_inflict_war_damage_on_faction", ":winner_faction", ":fortress_faction", ":damage"),
  3814.  
  3815. (call_script, "script_give_center_to_faction", ":root_defeated_party", ":winner_faction"),
  3816. (try_begin),
  3817. ##diplomacy start+ Handle player is co-ruler of faction
  3818. (assign, ":is_defeated_faction_coruler", 0),
  3819. (try_begin),
  3820. ##zerilius changes begin
  3821. (eq, ":defeated_faction", "$players_kingdom"),
  3822. # (eq, ":is_defeated_faction_coruler", "$players_kingdom"),
  3823. ##zerilius changes end
  3824. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  3825. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  3826. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  3827. (assign, ":is_defeated_faction_coruler", 1),
  3828. (try_end),
  3829. (this_or_next|eq, ":is_defeated_faction_coruler", 1),
  3830. ##diplomacy end+
  3831. (eq, ":defeated_faction", "fac_player_supporters_faction"),
  3832. (call_script, "script_add_notification_menu", "mnu_notification_center_lost", ":root_defeated_party", ":winner_faction"),
  3833. (try_end),
  3834.  
  3835. (party_get_num_attached_parties, ":num_attached_parties", ":root_attacker_party"),
  3836. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  3837. (party_get_attached_party_with_rank, ":attached_party", ":root_attacker_party", ":attached_party_rank"),
  3838.  
  3839. (party_get_num_companion_stacks, ":num_stacks", ":attached_party"),
  3840. (assign, ":total_size", 0),
  3841. (try_for_range, ":i_stack", 0, ":num_stacks"),
  3842. (party_stack_get_size, ":stack_size", ":attached_party", ":i_stack"),
  3843. (val_add, ":total_size", ":stack_size"),
  3844. (try_end),
  3845.  
  3846. (try_begin),
  3847. (ge, ":total_size", 10),
  3848.  
  3849. (assign, ":stacks_added", 0),
  3850. (assign, ":last_random_stack", -1),
  3851.  
  3852. (assign, ":end_condition", 10),
  3853. (try_for_range, ":unused", 0, ":end_condition"),
  3854. (store_random_in_range, ":random_stack", 1, ":num_stacks"),
  3855. (party_stack_get_troop_id, ":random_stack_troop", ":attached_party", ":random_stack"),
  3856. (party_stack_get_size, ":stack_size", ":attached_party", ":random_stack"),
  3857. (ge, ":stack_size", 4),
  3858. (neq, ":random_stack", ":last_random_stack"),
  3859.  
  3860. (store_mul, ":total_size_mul_2", ":total_size", 2),
  3861. (assign, ":percentage", ":total_size_mul_2"),
  3862. (val_min, ":percentage", 100),
  3863.  
  3864. (val_mul, ":stack_size", ":percentage"),
  3865. (val_div, ":stack_size", 100),
  3866.  
  3867. (party_stack_get_troop_id, ":party_leader", ":attached_party", 0),
  3868.  
  3869. (try_begin),
  3870. ##diplomacy start+ add lady personality
  3871. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_conventional),
  3872. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_otherworldly),
  3873. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_adventurous),
  3874. ##diplomacy end+
  3875. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_goodnatured),
  3876. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_upstanding),
  3877. (troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_martial),
  3878. (assign, reg2, 0),
  3879. (store_random_in_range, ":random_percentage", 40, 50), #average 45%
  3880. (else_try),
  3881. ##diplomacy start+ add lady personality
  3882. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_ambitious),
  3883. ##diplmoacy end+
  3884. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_quarrelsome),
  3885. (troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_cunning),
  3886. (assign, reg2, 1),
  3887. (store_random_in_range, ":random_percentage", 30, 40), #average 35%
  3888. (else_try),
  3889. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_selfrighteous),
  3890. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_roguish),
  3891. (troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_debauched),
  3892. (assign, reg2, 2),
  3893. (store_random_in_range, ":random_percentage", 20, 30), #average 25%
  3894. (else_try),
  3895. ##diplomacy start+ add lady personality
  3896. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_moralist),
  3897. ##diplomacy end+
  3898. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_benefactor),
  3899. (troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_custodian),
  3900. (assign, reg2, 3),
  3901. (store_random_in_range, ":random_percentage", 50, 60), #average 55%
  3902. (try_end),
  3903.  
  3904. (val_min, ":random_percentage", 100),
  3905. (val_mul, ":stack_size", ":random_percentage"),
  3906. (val_div, ":stack_size", 100),
  3907.  
  3908. (party_add_members, ":root_defender_party", ":random_stack_troop", ":stack_size"),
  3909. (party_remove_members, ":attached_party", ":random_stack_troop", ":stack_size"),
  3910.  
  3911. (val_add, ":stacks_added", 1),
  3912. (assign, ":last_random_stack", ":random_stack"),
  3913.  
  3914. (try_begin),
  3915. #if troops from three different stack is already added then break
  3916. (eq, ":stacks_added", 3),
  3917. (assign, ":end_condition", 0),
  3918. (try_end),
  3919. (try_end),
  3920. (try_end),
  3921. (try_end),
  3922.  
  3923. #Reduce prosperity of the center by 5
  3924. (try_begin),
  3925. (neg|is_between, ":root_defeated_party", castles_begin, castles_end),
  3926. (call_script, "script_change_center_prosperity", ":root_defeated_party", -5),
  3927. (val_add, "$newglob_total_prosperity_from_townloot", -5),
  3928. (try_end),
  3929. (call_script, "script_order_best_besieger_party_to_guard_center", ":root_defeated_party", ":winner_faction"),
  3930. (call_script, "script_cf_reinforce_party", ":root_defeated_party"),
  3931. (call_script, "script_cf_reinforce_party", ":root_defeated_party"),
  3932. (try_end),
  3933. (try_end),
  3934.  
  3935. #ADD XP
  3936. (try_begin),
  3937. (party_slot_eq, ":root_attacker_party", slot_party_type, spt_kingdom_hero_party),
  3938.  
  3939. (assign, ":xp_gained_attacker", 200),
  3940. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  3941. (store_faction_of_party, ":root_attacker_party_faction", ":root_attacker_party"),
  3942. (try_begin),
  3943. (this_or_next|eq, ":root_attacker_party", "p_main_party"),
  3944. (this_or_next|eq, ":root_attacker_party_faction", "fac_player_supporters_faction"),
  3945. (eq, ":root_attacker_party_faction", "$players_kingdom"),
  3946. #same
  3947. (else_try),
  3948. (eq, ":reduce_campaign_ai", 0), #hard (1.5x)
  3949. (val_mul, ":xp_gained_attacker", 3),
  3950. (val_div, ":xp_gained_attacker", 2),
  3951. (else_try),
  3952. (eq, ":reduce_campaign_ai", 1), #moderate (1.0x)
  3953. #same
  3954. (else_try),
  3955. (eq, ":reduce_campaign_ai", 2), #easy (0.5x)
  3956. (val_div, ":xp_gained_attacker", 2),
  3957. (try_end),
  3958.  
  3959. (gt, ":new_attacker_strength", 0),
  3960. (call_script, "script_upgrade_hero_party", ":root_attacker_party", ":xp_gained_attacker"),
  3961. (try_end),
  3962. (try_begin),
  3963. (party_slot_eq, ":root_defender_party", slot_party_type, spt_kingdom_hero_party),
  3964.  
  3965. (assign, ":xp_gained_defender", 200),
  3966. (store_faction_of_party, ":root_defender_party_faction", ":root_defender_party"),
  3967. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  3968. (try_begin),
  3969. (this_or_next|eq, ":root_defender_party", "p_main_party"),
  3970. (this_or_next|eq, ":root_defender_party_faction", "fac_player_supporters_faction"),
  3971. (eq, ":root_defender_party_faction", "$players_kingdom"),
  3972. #same
  3973. (else_try),
  3974. (eq, ":reduce_campaign_ai", 0), #hard (1.5x)
  3975. (val_mul, ":xp_gained_defender", 3),
  3976. (val_div, ":xp_gained_defender", 2),
  3977. (else_try),
  3978. (eq, ":reduce_campaign_ai", 1), #moderate (1.0x)
  3979. #same
  3980. (else_try),
  3981. (eq, ":reduce_campaign_ai", 2), #easy (0.5x)
  3982. (val_div, ":xp_gained_defender", 2),
  3983. (try_end),
  3984.  
  3985. (gt, ":new_defender_strength", 0),
  3986. (call_script, "script_upgrade_hero_party", ":root_defender_party", ":xp_gained_defender"),
  3987. (try_end),
  3988.  
  3989. (try_begin),
  3990. #ozan - do not randomly end battles aganist towns or castles.
  3991. (neg|party_slot_eq, ":root_defender_party", slot_party_type, spt_castle), #added by ozan
  3992. (neg|party_slot_eq, ":root_defender_party", slot_party_type, spt_town), #added by ozan
  3993. #end ozan
  3994.  
  3995. (party_get_slot, ":attacker_root_strength", ":root_attacker_party", slot_party_cached_strength),
  3996. (party_get_slot, ":attacker_nearby_friend_strength", ":root_attacker_party", slot_party_nearby_friend_strength),
  3997. (party_get_slot, ":strength_of_attacker_followers", ":root_attacker_party", slot_party_follower_strength),
  3998. (store_add, ":total_attacker_strength", ":attacker_root_strength", ":attacker_nearby_friend_strength"),
  3999. (val_add, ":total_attacker_strength", ":strength_of_attacker_followers"),
  4000.  
  4001. (party_get_slot, ":defender_root_strength", ":root_defender_party", slot_party_cached_strength),
  4002. (party_get_slot, ":defender_nearby_friend_strength", ":root_defender_party", slot_party_nearby_friend_strength),
  4003. (party_get_slot, ":strength_of_defender_followers", ":root_defender_party", slot_party_follower_strength),
  4004. (store_add, ":total_defender_strength", ":defender_root_strength", ":defender_nearby_friend_strength"),
  4005. (val_add, ":total_attacker_strength", ":strength_of_defender_followers"),
  4006.  
  4007. #Players can make save loads and change history because these random values are not determined from random_slots of troops
  4008. (store_random_in_range, ":random_num", 0, 100),
  4009.  
  4010. (try_begin),
  4011. (lt, ":random_num", 10),
  4012. (assign, ":trigger_result", 1), #End battle!
  4013. (try_end),
  4014. (else_try),
  4015. (party_get_slot, ":attacker_root_strength", ":root_attacker_party", slot_party_cached_strength),
  4016. (party_get_slot, ":attacker_nearby_friend_strength", ":root_attacker_party", slot_party_nearby_friend_strength),
  4017. (party_get_slot, ":strength_of_followers", ":root_attacker_party", slot_party_follower_strength),
  4018. (store_add, ":total_attacker_strength", ":attacker_root_strength", ":attacker_nearby_friend_strength"),
  4019. (val_add, ":total_attacker_strength", ":strength_of_followers"),
  4020.  
  4021. (party_get_slot, ":defender_root_strength", ":root_defender_party", slot_party_cached_strength),
  4022. (party_get_slot, ":defender_nearby_friend_strength", ":root_defender_party", slot_party_nearby_friend_strength),
  4023. (store_add, ":total_defender_strength", ":defender_root_strength", ":defender_nearby_friend_strength"),
  4024.  
  4025. (val_mul, ":total_defender_strength", 13), #multiply defender strength with 1.3
  4026. (val_div, ":total_defender_strength", 10),
  4027.  
  4028. (gt, ":total_defender_strength", ":total_attacker_strength"),
  4029. (gt, ":total_defender_strength", 3),
  4030.  
  4031. #Players can make save loads and change history because these random values are not determined from random_slots of troops
  4032. (store_random_in_range, ":random_num", 0, 100),
  4033.  
  4034. (try_begin),
  4035. (lt, ":random_num", 15), #15% is a bit higher than 10% (which is open area escape probability)
  4036. (assign, ":trigger_result", 1), #End battle!
  4037.  
  4038. (assign, "$g_recalculate_ais", 1), #added new
  4039.  
  4040. (try_begin),
  4041. (eq, "$cheat_mode", 1),
  4042. (display_message, "@{!}DEBUG : Siege attackers are running away"),
  4043. (try_end),
  4044. (try_end),
  4045. (try_end),
  4046. (try_end),
  4047. (try_end),
  4048. (set_trigger_result, ":trigger_result"),
  4049. ]),
  4050.  
  4051. #script_game_event_battle_end:
  4052. # This script is called whenever the game ends the battle between two parties on the map.
  4053. # INPUT:
  4054. # param1: Defender Party
  4055. # param2: Attacker Party
  4056. ("game_event_battle_end",
  4057. [
  4058. ## (store_script_param_1, ":root_defender_party"),
  4059. ## (store_script_param_2, ":root_attacker_party"),
  4060.  
  4061. #Fixing deleted heroes
  4062. ##diplomacy start+ kingdom ladies may also potentially lead parties
  4063. (try_for_range, ":cur_troop", heroes_begin, heroes_end),#<- changed active_npcs to heroes
  4064. #diplomacy end+
  4065. (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  4066. (troop_get_slot, ":cur_party", ":cur_troop", slot_troop_leaded_party),
  4067. (troop_get_slot, ":cur_prisoner_of_party", ":cur_troop", slot_troop_prisoner_of_party),
  4068. (try_begin),
  4069. (ge, ":cur_party", 0),
  4070. (assign, ":continue", 0),
  4071. (try_begin),
  4072. (neg|party_is_active, ":cur_party"),
  4073. (assign, ":continue", 1),
  4074. (else_try),
  4075. (party_count_companions_of_type, ":amount", ":cur_party", ":cur_troop"),
  4076. (le, ":amount", 0),
  4077. (assign, ":continue", 1),
  4078. (try_end),
  4079. (eq, ":continue", 1),
  4080. (try_begin),
  4081. (eq, "$cheat_mode", 1),
  4082. (str_store_troop_name, s1, ":cur_troop"),
  4083. (display_message, "@{!}DEBUG: {s1} no longer leads a party."),
  4084. (try_end),
  4085.  
  4086. (troop_set_slot, ":cur_troop", slot_troop_leaded_party, -1),
  4087. #(str_store_troop_name, s5, ":cur_troop"),
  4088. #(display_message, "@{!}DEBUG : {s5}'s troop_leaded_party set to -1"),
  4089. (try_end),
  4090. (try_begin),
  4091. (ge, ":cur_prisoner_of_party", 0),
  4092. (assign, ":continue", 0),
  4093. (try_begin),
  4094. (neg|party_is_active, ":cur_prisoner_of_party"),
  4095. (assign, ":continue", 1),
  4096. (else_try),
  4097. (party_count_prisoners_of_type, ":amount", ":cur_prisoner_of_party", ":cur_troop"),
  4098. (le, ":amount", 0),
  4099. (assign, ":continue", 1),
  4100. (try_end),
  4101. (eq, ":continue", 1),
  4102. (try_begin),
  4103. (eq, "$cheat_mode", 1),
  4104. (str_store_troop_name, s1, ":cur_troop"),
  4105. (display_message, "@{!}DEBUG: {s1} is no longer a prisoner."),
  4106. (try_end),
  4107. (call_script, "script_remove_troop_from_prison", ":cur_troop"),
  4108. #searching player
  4109. (try_begin),
  4110. (party_count_prisoners_of_type, ":amount", "p_main_party", ":cur_troop"),
  4111. (gt, ":amount", 0),
  4112. (troop_set_slot, ":cur_troop", slot_troop_prisoner_of_party, "p_main_party"),
  4113. (assign, ":continue", 0),
  4114. (try_begin),
  4115. (eq, "$cheat_mode", 1),
  4116. (str_store_troop_name, s1, ":cur_troop"),
  4117. (display_message, "@{!}DEBUG: {s1} is now a prisoner of player."),
  4118. (try_end),
  4119. (try_end),
  4120. (eq, ":continue", 1),
  4121. ##diplomacy start+
  4122. #Add increased information for affiliates.
  4123. (call_script, "script_dplmc_store_troop_is_eligible_for_affiliate_messages", ":cur_troop"),
  4124. (assign, ":is_affiliated", reg0),
  4125. ##diplomacy end+
  4126. #searching kingdom heroes
  4127. ##diplomacy start+ support for promoted kingdom ladies
  4128. (try_for_range, ":cur_troop_2", heroes_begin, heroes_end),#<-- changed active_npcs to heroes
  4129. ##diplomacy end+
  4130. (troop_slot_eq, ":cur_troop_2", slot_troop_occupation, slto_kingdom_hero),
  4131. (eq, ":continue", 1),
  4132. (troop_get_slot, ":cur_prisoner_of_party_2", ":cur_troop_2", slot_troop_leaded_party),
  4133. (party_is_active, ":cur_prisoner_of_party_2"),
  4134. (party_count_prisoners_of_type, ":amount", ":cur_prisoner_of_party_2", ":cur_troop"),
  4135. (gt, ":amount", 0),
  4136. (troop_set_slot, ":cur_troop", slot_troop_prisoner_of_party, ":cur_prisoner_of_party_2"),
  4137. (assign, ":continue", 0),
  4138. (try_begin),
  4139. ##diplomacy start+ Show for affiliates
  4140. (ge, ":is_affiliated", 1),
  4141. (str_store_troop_name, s1, ":cur_troop"),
  4142. (str_store_party_name, s2, ":cur_prisoner_of_party_2"),
  4143. (display_message, "@{s1} is now a prisoner of {s2}."),
  4144. (else_try),
  4145. ##diplomacy end+
  4146. (eq, "$cheat_mode", 1),
  4147. (str_store_troop_name, s1, ":cur_troop"),
  4148. (str_store_party_name, s2, ":cur_prisoner_of_party_2"),
  4149. (display_message, "@{!}DEBUG: {s1} is now a prisoner of {s2}."),
  4150. (try_end),
  4151. (try_end),
  4152. #searching walled centers
  4153. (try_for_range, ":cur_prisoner_of_party_2", walled_centers_begin, walled_centers_end),
  4154. (eq, ":continue", 1),
  4155. (party_count_prisoners_of_type, ":amount", ":cur_prisoner_of_party_2", ":cur_troop"),
  4156. (gt, ":amount", 0),
  4157. (troop_set_slot, ":cur_troop", slot_troop_prisoner_of_party, ":cur_prisoner_of_party_2"),
  4158. (assign, ":continue", 0),
  4159. (try_begin),
  4160. ##diplomacy start+ Show for affiliates
  4161. (ge, ":is_affiliated", 1),
  4162. (str_store_troop_name, s1, ":cur_troop"),
  4163. (str_store_party_name, s2, ":cur_prisoner_of_party_2"),
  4164. (display_message, "@{s1} is now a prisoner of {s2}."),
  4165. (else_try),
  4166. ##diplomacy end+
  4167. (eq, "$cheat_mode", 1),
  4168. (str_store_troop_name, s1, ":cur_troop"),
  4169. (str_store_party_name, s2, ":cur_prisoner_of_party_2"),
  4170. (display_message, "@{!}DEBUG: {s1} is now a prisoner of {s2}."),
  4171. (try_end),
  4172. (try_end),
  4173. (try_end),
  4174. (try_end),
  4175. ]),
  4176.  
  4177. #script_order_best_besieger_party_to_guard_center:
  4178. # INPUT:
  4179. # param1: defeated_center, param2: winner_faction
  4180. # OUTPUT:
  4181. # none
  4182. ("order_best_besieger_party_to_guard_center",
  4183. [
  4184. (store_script_param, ":defeated_center", 1),
  4185. (store_script_param, ":winner_faction", 2),
  4186. (assign, ":best_party", -1),
  4187. (assign, ":best_party_strength", 0),
  4188. ##diplomacy start+ support for promoted kingdom ladies
  4189. (try_for_range, ":kingdom_hero", heroes_begin, heroes_end),#<- changed to heroes
  4190. (this_or_next|troop_slot_eq, ":kingdom_hero", slot_troop_occupation, slto_kingdom_hero),
  4191. (is_between, ":kingdom_hero", active_npcs_begin, active_npcs_end),
  4192. ##diplomacy end+
  4193. (troop_get_slot, ":kingdom_hero_party", ":kingdom_hero", slot_troop_leaded_party),
  4194. (gt, ":kingdom_hero_party", 0),
  4195. (party_is_active, ":kingdom_hero_party"),
  4196. (store_faction_of_party, ":kingdom_hero_party_faction", ":kingdom_hero_party"),
  4197. (eq, ":winner_faction", ":kingdom_hero_party_faction"),
  4198. (store_distance_to_party_from_party, ":dist", ":kingdom_hero_party", ":defeated_center"),
  4199. (lt, ":dist", 5),
  4200. #If marshall has captured the castle, then do not leave him behind.
  4201. (neg|faction_slot_eq, ":winner_faction", slot_faction_marshall, ":kingdom_hero"),
  4202. (assign, ":has_besiege_ai", 0),
  4203. (try_begin),
  4204. (party_slot_eq, ":kingdom_hero_party", slot_party_ai_state, spai_besieging_center),
  4205. (party_slot_eq, ":kingdom_hero_party", slot_party_ai_object, ":defeated_center"),
  4206. (assign, ":has_besiege_ai", 1),
  4207. (else_try),
  4208. (party_slot_eq, ":kingdom_hero_party", slot_party_ai_state, spai_accompanying_army),
  4209. (party_get_slot, ":kingdom_hero_party_commander_party", ":kingdom_hero_party", slot_party_ai_object),
  4210. (party_slot_eq, ":kingdom_hero_party_commander_party", slot_party_ai_state, spai_besieging_center),
  4211. (party_slot_eq, ":kingdom_hero_party_commander_party", slot_party_ai_object, ":defeated_center"),
  4212. (assign, ":has_besiege_ai", 1),
  4213. (try_end),
  4214. (eq, ":has_besiege_ai", 1),
  4215. (party_get_slot, ":kingdom_hero_party_strength", ":kingdom_hero_party", slot_party_cached_strength),#recently calculated
  4216. (gt, ":kingdom_hero_party_strength", ":best_party_strength"),
  4217. (assign, ":best_party_strength", ":kingdom_hero_party_strength"),
  4218. (assign, ":best_party", ":kingdom_hero_party"),
  4219. (try_end),
  4220. (try_begin),
  4221. (gt, ":best_party", 0),
  4222. (call_script, "script_party_set_ai_state", ":best_party", spai_holding_center, ":defeated_center"),
  4223. #(party_set_slot, ":best_party", slot_party_commander_party, -1),
  4224. (party_set_flags, ":best_party", pf_default_behavior, 1),
  4225. (try_end),
  4226. ]),
  4227.  
  4228. #script_game_get_item_buy_price_factor:
  4229. # This script is called from the game engine for calculating the buying price of any item.
  4230. # INPUT:
  4231. # param1: item_kind_id
  4232. # OUTPUT:
  4233. # trigger_result and reg0 = price_factor
  4234. ("game_get_item_buy_price_factor",
  4235. [
  4236. (store_script_param_1, ":item_kind_id"),
  4237. (assign, ":price_factor", 100),
  4238.  
  4239. (call_script, "script_get_trade_penalty", ":item_kind_id"),
  4240. (assign, ":trade_penalty", reg0),
  4241.  
  4242. (try_begin),
  4243. (is_between, "$g_encountered_party", centers_begin, centers_end),
  4244. (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  4245. (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
  4246. (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
  4247. (party_get_slot, ":price_factor", "$g_encountered_party", ":item_slot_no"),
  4248.  
  4249. #new
  4250. #(try_begin),
  4251. # (is_between, "$g_encountered_party", villages_begin, villages_end),
  4252. # (party_get_slot, ":market_town", "$g_encountered_party", slot_village_market_town),
  4253. # (party_get_slot, ":price_in_market_town", ":market_town", ":item_slot_no"),
  4254. # (val_max, ":price_factor", ":price_in_market_town"),
  4255. #(try_end),
  4256.  
  4257. #For villages, the good will be sold no cheaper than in the market town
  4258. #This represents the absence of a permanent market -- ie, the peasants retain goods to sell on their journeys to town, and are not about to do giveaway deals with passing adventurers
  4259.  
  4260.  
  4261. (val_mul, ":price_factor", 100), #normalize price factor to range 0..100
  4262. (val_div, ":price_factor", average_price_factor),
  4263. (try_end),
  4264.  
  4265. (store_add, ":penalty_factor", 100, ":trade_penalty"),
  4266.  
  4267. (val_mul, ":price_factor", ":penalty_factor"),
  4268. (val_div, ":price_factor", 100),
  4269.  
  4270. (assign, reg0, ":price_factor"),
  4271. (set_trigger_result, reg0),
  4272. ]),
  4273.  
  4274. #script_game_get_item_sell_price_factor:
  4275. # This script is called from the game engine for calculating the selling price of any item.
  4276. # INPUT:
  4277. # param1: item_kind_id
  4278. # OUTPUT:
  4279. # trigger_result and reg0 = price_factor
  4280. ("game_get_item_sell_price_factor",
  4281. [
  4282. (store_script_param_1, ":item_kind_id"),
  4283. (assign, ":price_factor", 100),
  4284.  
  4285. (call_script, "script_get_trade_penalty", ":item_kind_id"),
  4286. (assign, ":trade_penalty", reg0),
  4287.  
  4288. (try_begin),
  4289. (is_between, "$g_encountered_party", centers_begin, centers_end),
  4290. (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  4291. (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
  4292. (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
  4293. (party_get_slot, ":price_factor", "$g_encountered_party", ":item_slot_no"),
  4294. (val_mul, ":price_factor", 100),#normalize price factor to range 0..100
  4295. (val_div, ":price_factor", average_price_factor),
  4296. (else_try),
  4297. #increase trade penalty while selling weapons, armor, and horses
  4298. (val_mul, ":trade_penalty", 4),
  4299. (try_end),
  4300.  
  4301. ##diplomacy start+
  4302. #If economic changes are enabled, use a lesser trade penalty when selling
  4303. #to the correct merchant in town.
  4304. (try_begin),
  4305. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  4306. (is_between, "$g_encountered_party", towns_begin, towns_end),
  4307. (gt, "$g_talk_troop", "trp_player"),
  4308. (try_begin),
  4309. #Selling weapons to the weaponsmith
  4310. (party_slot_eq, "$g_encountered_party", slot_town_weaponsmith, "$g_talk_troop"),
  4311. (this_or_next|is_between, ":item_kind_id", weapons_begin, weapons_end),
  4312. (this_or_next|is_between, ":item_kind_id", shields_begin, shields_end),
  4313. (is_between, ":item_kind_id", ranged_weapons_begin, ranged_weapons_end),
  4314. (val_mul, ":trade_penalty", 9),
  4315. (val_div, ":trade_penalty", 10),
  4316. (else_try),
  4317. #Selling armor to the armorer
  4318. (party_slot_eq, "$g_encountered_party", slot_town_armorer, "$g_talk_troop"),
  4319. (is_between, ":item_kind_id", armors_begin, armors_end),
  4320. (val_mul, ":trade_penalty", 9),
  4321. (val_div, ":trade_penalty", 10),
  4322. (else_try),
  4323. #Selling horses to the horse merchant
  4324. (party_slot_eq, "$g_encountered_party", slot_town_horse_merchant, "$g_talk_troop"),
  4325. (is_between, ":item_kind_id", horses_begin, horses_end),
  4326. (val_mul, ":trade_penalty", 9),
  4327. (val_div, ":trade_penalty", 10),
  4328. (try_end),
  4329. (try_end),
  4330.  
  4331. #If economic changes are enabled, increase food prices in a town under siege.
  4332. (try_begin),
  4333. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  4334. (is_between, "$g_encountered_party", centers_begin, centers_end),
  4335. #Check selling food
  4336. (is_between, ":item_kind_id", food_begin, food_end),
  4337. #Check at a town or castle under siege for at least 48 hours
  4338. (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
  4339. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_castle),
  4340. (party_slot_eq, "$g_encountered_party", slot_village_state, svs_under_siege),
  4341.  
  4342. (party_slot_ge, "$g_encountered_party", slot_center_is_besieged_by, 1),
  4343. (party_get_slot, ":siege_start", "$g_encountered_party", slot_center_siege_begin_hours),
  4344. (store_current_hours, ":cur_hours"),
  4345. (store_sub, reg0, ":cur_hours", ":siege_start"),
  4346. (ge, reg0, 48),
  4347. #Check last caravan or village trading party arrival (default to eight weeks ago)
  4348. (store_sub, ":last_arrival", ":cur_hours", 8 * 7 * 24),
  4349. (val_min, ":last_arrival", ":siege_start"),
  4350. (try_for_range, ":village_no", villages_begin, villages_end),
  4351. (party_slot_eq, ":village_no", slot_village_market_town, "$g_encountered_party"),
  4352. (party_get_slot, reg0, ":village_no", dplmc_slot_village_trade_last_arrived_to_market),
  4353. (val_min, reg0, ":cur_hours"),
  4354. (val_max, ":last_arrival", reg0),
  4355. (try_end),
  4356. (try_for_range, ":slot_no", dplmc_slot_town_trade_route_last_arrivals_begin, dplmc_slot_town_trade_route_last_arrivals_end),
  4357. #Not all of these slots correspond to towns, but that doesn't
  4358. #matter since their arrival times won't update after the start
  4359. #of the game.
  4360. (party_get_slot, reg0, "$g_encountered_party", ":slot_no"),
  4361. (val_min, reg0, ":cur_hours"),
  4362. (val_max, ":last_arrival", reg0),
  4363. (try_end),
  4364. ##Increase food prices by 10% for every 3 days the siege has been going on,
  4365. #or a minimum of 5%.
  4366. #TODO: Make use of the last caravan arrival time.
  4367. (store_sub, ":hours_since", ":cur_hours", ":siege_start"),
  4368. (store_mul, ":siege_percent", ":hours_since", 10),
  4369. (val_add, ":siege_percent", (3 * 24) // 2),
  4370. (val_div, ":siege_percent", 3 * 24),
  4371. (val_max, ":siege_percent", 5),
  4372. (val_add, ":siege_percent", 100),
  4373. (val_mul, ":price_factor", ":siege_percent"),
  4374. (val_add, ":price_factor", 50),
  4375. (val_div, ":price_factor", 100),
  4376. (try_end),
  4377. ##diplomacy end+
  4378.  
  4379. (store_add, ":penalty_divisor", 100, ":trade_penalty"),
  4380.  
  4381. (val_mul, ":price_factor", 100),
  4382. ##diplomacy start+
  4383. (try_begin),
  4384. (gt, ":penalty_divisor", 0),
  4385. (store_div, reg0, ":penalty_divisor", 2),
  4386. (val_add, ":price_factor", reg0),#round correctly
  4387. (try_end),
  4388. ##diplomacy end+
  4389. (val_div, ":price_factor", ":penalty_divisor"),
  4390.  
  4391. (assign, reg0, ":price_factor"),
  4392. (set_trigger_result, reg0),
  4393. ]),
  4394.  
  4395. # script_get_trade_penalty
  4396. #
  4397. # Input:
  4398. # param1: troop_id,
  4399. # Output: reg0
  4400.  
  4401. ("get_trade_penalty",
  4402. [
  4403. ##diplomacy start+
  4404. ##Changed to fall back to parameterized version
  4405. ##NEW:
  4406. (store_script_param_1, ":item_kind_id"),
  4407. (call_script, "script_dplmc_get_trade_penalty", ":item_kind_id", "$g_encountered_party", "trp_player", "$g_talk_troop"),
  4408.  
  4409. ##OLD:
  4410. # (store_script_param_1, ":item_kind_id"),
  4411. #
  4412. # (assign, ":penalty",0),
  4413. #
  4414. # (party_get_skill_level, ":trade_skill", "p_main_party", skl_trade),
  4415. # (try_begin),
  4416. # (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  4417. # (assign, ":penalty",15), #reduced slightly
  4418. # (store_mul, ":skill_bonus", ":trade_skill", 1),
  4419. # (val_sub, ":penalty", ":skill_bonus"),
  4420. # (else_try),
  4421. # (assign, ":penalty",100),
  4422. # (store_mul, ":skill_bonus", ":trade_skill", 5),
  4423. # (val_sub, ":penalty", ":skill_bonus"),
  4424. # (try_end),
  4425. #
  4426. # ##diplomacy start+
  4427. # (assign, ":penalty_multiplier", average_price_factor),#<-- replaced 1000 with average_price_factor
  4428. # ##diplomacy end+
  4429. ### # Apply penalty if player is hostile to merchants faction
  4430. ### (store_relation, ":merchants_reln", "fac_merchants", "fac_player_supporters_faction"),
  4431. ### (try_begin),
  4432. ### (lt, ":merchants_reln", 0),
  4433. ### (store_sub, ":merchants_reln_dif", 10, ":merchants_reln"),
  4434. ### (store_mul, ":merchants_relation_penalty", ":merchants_reln_dif", 20),
  4435. ### (val_add, ":penalty_multiplier", ":merchants_relation_penalty"),
  4436. ### (try_end),
  4437. #
  4438. # # Apply penalty if player is on bad terms with the town
  4439. # (try_begin),
  4440. # (is_between, "$g_encountered_party", centers_begin, centers_end),
  4441. # (party_get_slot, ":center_relation", "$g_encountered_party", slot_center_player_relation),
  4442. # (store_mul, ":center_relation_penalty", ":center_relation", -3),
  4443. # (val_add, ":penalty_multiplier", ":center_relation_penalty"),
  4444. # (try_begin),
  4445. # (lt, ":center_relation", 0),
  4446. # (store_sub, ":center_penalty_multiplier", 100, ":center_relation"),
  4447. # (val_mul, ":penalty_multiplier", ":center_penalty_multiplier"),
  4448. # (val_div, ":penalty_multiplier", 100),
  4449. # (try_end),
  4450. # (try_end),
  4451. #
  4452. # # Apply penalty if player is on bad terms with the merchant (not currently used)
  4453. # (call_script, "script_troop_get_player_relation", "$g_talk_troop"),
  4454. # (assign, ":troop_reln", reg0),
  4455. # #(troop_get_slot, ":troop_reln", "$g_talk_troop", slot_troop_player_relation),
  4456. # (try_begin),
  4457. # (lt, ":troop_reln", 0),
  4458. # (store_sub, ":troop_reln_dif", 0, ":troop_reln"),
  4459. # (store_mul, ":troop_relation_penalty", ":troop_reln_dif", 20),
  4460. # (val_add, ":penalty_multiplier", ":troop_relation_penalty"),
  4461. # (try_end),
  4462. #
  4463. #
  4464. # (try_begin),
  4465. # (is_between, "$g_encountered_party", villages_begin, villages_end),
  4466. # (val_mul, ":penalty", 2),
  4467. # (try_end),
  4468. #
  4469. # (try_begin),
  4470. # (is_between, "$g_encountered_party", centers_begin, centers_end),
  4471. # #Double trade penalty if no local production or consumption
  4472. # (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  4473. # ##diplomacy start+
  4474. # #OPTIONAL CHANGE: Do not apply this to food
  4475. # (this_or_next|lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  4476. # (neg|is_between, ":item_kind_id", food_begin, food_end),
  4477. # ##diplomacy end+
  4478. # (call_script, "script_center_get_production", "$g_encountered_party", ":item_kind_id"),
  4479. # (eq, reg0, 0),
  4480. # (call_script, "script_center_get_consumption", "$g_encountered_party", ":item_kind_id"),
  4481. # (eq, reg0, 0),
  4482. # (val_mul, ":penalty", 2),
  4483. # (try_end),
  4484. #
  4485. # (val_mul, ":penalty", ":penalty_multiplier"),
  4486. # ##diplomacy start+
  4487. # (val_add, ":penalty", average_price_factor // 2),#round in the correct direction (we don't need to worry about penalty < 0)
  4488. # (val_div, ":penalty", average_price_factor),#replace the hardcoded constant 1000 with average_price_factor
  4489. # ##diplomacy end+
  4490. # (val_max, ":penalty", 1),
  4491. # (assign, reg0, ":penalty"),
  4492. ]),
  4493.  
  4494. #script_game_event_buy_item:
  4495. # This script is called from the game engine when player buys an item.
  4496. # INPUT:
  4497. # param1: item_kind_id
  4498. ("game_event_buy_item",
  4499. [
  4500. (store_script_param_1, ":item_kind_id"),
  4501. (store_script_param_2, ":reclaim_mode"),
  4502. (try_begin),
  4503. (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  4504. (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
  4505. (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
  4506. (party_get_slot, ":multiplier", "$g_encountered_party", ":item_slot_no"),
  4507. (try_begin),
  4508. (eq, ":reclaim_mode", 0),
  4509. (val_add, ":multiplier", 20),
  4510. (else_try),
  4511. (val_add, ":multiplier", 30),
  4512. (try_end),
  4513.  
  4514. (store_item_value, ":item_value", ":item_kind_id"),
  4515. (try_begin),
  4516. (ge, ":item_value", 100),
  4517. (store_sub, ":item_value_sub_100", ":item_value", 100),
  4518. (store_div, ":item_value_sub_100_div_8", ":item_value_sub_100", 8),
  4519. (val_add, ":multiplier", ":item_value_sub_100_div_8"),
  4520. (try_end),
  4521. (val_min, ":multiplier", maximum_price_factor),
  4522.  
  4523. (party_set_slot, "$g_encountered_party", ":item_slot_no", ":multiplier"),
  4524. (try_end),
  4525. ]),
  4526.  
  4527. #script_game_event_sell_item:
  4528. # This script is called from the game engine when player sells an item.
  4529. # INPUT:
  4530. # param1: item_kind_id
  4531. ("game_event_sell_item",
  4532. [
  4533. (store_script_param_1, ":item_kind_id"),
  4534. (store_script_param_2, ":return_mode"),
  4535. (try_begin),
  4536. (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  4537. (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
  4538. (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
  4539. (party_get_slot, ":multiplier", "$g_encountered_party", ":item_slot_no"),
  4540. (try_begin),
  4541. (eq, ":return_mode", 0),
  4542. (val_sub, ":multiplier", 30),
  4543. (else_try),
  4544. (val_sub, ":multiplier", 20),
  4545. (try_end),
  4546.  
  4547. (store_item_value, ":item_value", ":item_kind_id"),
  4548. (try_begin),
  4549. (ge, ":item_value", 100),
  4550. (store_sub, ":item_value_sub_100", ":item_value", 100),
  4551. (store_div, ":item_value_sub_100_div_8", ":item_value_sub_100", 8),
  4552. (val_sub, ":multiplier", ":item_value_sub_100_div_8"),
  4553. (try_end),
  4554. (val_max, ":multiplier", minimum_price_factor),
  4555.  
  4556. (party_set_slot, "$g_encountered_party", ":item_slot_no", ":multiplier"),
  4557. (try_end),
  4558. ]),
  4559.  
  4560. #script_start_wedding_cutscene
  4561. # INPUT: arg1 = groom_troop, arg2 = bride_troop
  4562. # OUTPUT: none
  4563. ("start_wedding_cutscene",
  4564. [
  4565. (store_script_param, "$g_wedding_groom_troop", 1),
  4566. (store_script_param, "$g_wedding_bride_troop", 2),
  4567. ##diplomacy start+
  4568. (assign, ":save_reg0", reg0),
  4569. (assign, ":save_reg1", reg1),
  4570.  
  4571.  
  4572. #To prevent a ridiculous cutscene, reverse genders if the bride is male.
  4573. (call_script, "script_dplmc_store_is_female_troop_1_troop_2", "$g_wedding_groom_troop", "$g_wedding_bride_troop"),
  4574. (assign, ":groom_is_woman", reg0),
  4575. (assign, ":bride_is_woman", reg1),
  4576.  
  4577. (try_begin),
  4578. (eq, ":bride_is_woman", 0),
  4579. (neq, ":groom_is_woman", 0),#Don't bother reversing if both are male
  4580. (assign, reg0, "$g_wedding_bride_troop"),
  4581. (assign, "$g_wedding_bride_troop", "$g_wedding_groom_troop"),
  4582. (assign, "$g_wedding_groom_troop", reg0),
  4583. (else_try),
  4584. #If it's a same-sex wedding, put the player in the role of the groom.
  4585. (eq, ":bride_is_woman", ":groom_is_woman"),
  4586. (eq, "$g_wedding_bride_troop", "trp_player"),
  4587. (assign, "$g_wedding_bride_troop", "$g_wedding_groom_troop"),
  4588. (assign, "$g_wedding_groom_troop", "trp_player"),
  4589. (try_end),
  4590. #diplomacy end+
  4591. (assign, "$g_wedding_bishop_troop", "trp_temporary_minister"),
  4592. (try_begin),
  4593. (is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
  4594. (neg|faction_slot_eq, "$players_kingdom", slot_faction_leader, "$g_wedding_groom_troop"),
  4595. (neg|faction_slot_eq, "$players_kingdom", slot_faction_leader, "$g_wedding_bride_troop"),
  4596. (faction_get_slot, ":players_king", "$players_kingdom", slot_faction_leader),
  4597. ##diplomacy start+
  4598. (neq, ":players_king", "$g_wedding_bride_troop"),#necessary now that marrying monarchs can occur
  4599. (neq, ":players_king", "$g_wedding_groom_troop"),
  4600. #Changed the gender requirement (used to be required male)
  4601. #(troop_get_type, ":troop_type", ":players_king"),
  4602. #(eq, ":troop_type", 0), #male
  4603. (call_script, "script_dplmc_store_troop_is_female", ":players_king"),
  4604. (this_or_next|eq, reg0, 0),
  4605. (this_or_next|eq, ":groom_is_woman", ":bride_is_woman"),
  4606. (ge, "$g_disable_condescending_comments", 2),
  4607. (neq, ":players_king", "$g_wedding_bride_troop"),
  4608. (neg|troop_slot_eq, "$g_wedding_bride_troop", slot_troop_father, ":players_king"),
  4609. (neg|troop_slot_eq, "$g_wedding_bride_troop", slot_troop_mother, ":players_king"),
  4610. ##diplomacy end+
  4611. (neq, ":players_king", "$g_wedding_groom_troop"),
  4612. (assign, "$g_wedding_bishop_troop", ":players_king"),
  4613. (else_try),
  4614. (eq, "$players_kingdom", "fac_player_supporters_faction"),
  4615. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  4616. (gt, "$g_player_minister", 0),
  4617. ##diplomacy start+
  4618. #(troop_get_type, ":troop_type", "$g_player_minister"),
  4619. #(eq, ":troop_type", 0), #male
  4620. (call_script, "script_dplmc_store_troop_is_female", "$g_player_minister"),
  4621. (this_or_next|eq, reg0, 0),
  4622. (this_or_next|eq, ":groom_is_woman", ":bride_is_woman"),
  4623. (ge, "$g_disable_condescending_comments", 2),
  4624. ##diplomacy end+
  4625. (neq, "$g_player_minister", "$g_wedding_groom_troop"),
  4626. (assign, "$g_wedding_bishop_troop", "$g_player_minister"),
  4627. (try_end),
  4628.  
  4629. (assign, "$g_wedding_brides_dad_troop", "trp_temporary_minister"),
  4630. (try_begin),
  4631. (neq, "$g_wedding_bride_troop", "trp_player"),
  4632. (try_begin),
  4633. (troop_get_slot, ":father", "$g_wedding_bride_troop", slot_troop_father),
  4634. (gt, ":father", 0),
  4635. ##diplomacy start+
  4636. (neg|troop_slot_ge, ":father", slot_troop_occupation, slto_retirement),
  4637. #(troop_get_type, ":troop_type", ":father"), #just to make sure #<- dplmc+ replaced
  4638. (call_script, "script_dplmc_store_troop_is_female", ":father"),
  4639. (this_or_next|eq, ":bride_is_woman", 0),
  4640. (eq, reg0, 0), #male
  4641. ##diplomacy end+
  4642. (neq, ":father", "$g_wedding_groom_troop"), #this might be 0 due to an error
  4643. (neq, ":father", "$g_wedding_bishop_troop"),
  4644. (assign, "$g_wedding_brides_dad_troop", ":father"),
  4645. (else_try),
  4646. (troop_get_slot, ":guardian", "$g_wedding_bride_troop", slot_troop_guardian),
  4647. (gt, ":guardian", 0),
  4648. ##diplomacy start+
  4649. (neg|troop_slot_ge, ":guardian", slot_troop_occupation, slto_retirement),
  4650. #(troop_get_type, ":troop_type", ":guardian"), #just to make sure #<- dplmc+ replaced
  4651. (call_script, "script_dplmc_store_troop_is_female", ":guardian"),
  4652. (this_or_next|eq, ":bride_is_woman", 0),
  4653. (eq, reg0, 0), #male
  4654. (call_script, "script_dplmc_store_troop_is_female", ":guardian"),
  4655. ##diplomacy end+
  4656. (neq, ":guardian", "$g_wedding_groom_troop"), #this might be 0 due to an error
  4657. (neq, ":guardian", "$g_wedding_bishop_troop"),
  4658. (assign, "$g_wedding_brides_dad_troop", ":guardian"),
  4659. ##diplomacy start+
  4660. #mother might be appropriate
  4661. (else_try),
  4662. (troop_get_slot, ":mother", "$g_wedding_bride_troop", slot_troop_mother),
  4663. (gt, ":mother", 0),
  4664. (neg|troop_slot_ge, ":mother", slot_troop_occupation, slto_retirement),
  4665.  
  4666. (neq, ":mother", "$g_wedding_groom_troop"),
  4667. (neq, ":mother", "$g_wedding_bride_troop"),
  4668. (neq, ":mother", "$g_wedding_bishop_troop"),
  4669.  
  4670. (assign, "$g_wedding_brides_dad_troop", ":mother"),
  4671. #we can get here, since male players can marry female lords
  4672. (else_try),
  4673. (is_between, "$g_wedding_bride_troop", companions_begin, companions_end),
  4674. (troop_get_slot, ":cur_npc", "$g_wedding_bride_troop", slot_troop_personalitymatch_object),
  4675. (ge, ":cur_npc", heroes_begin),
  4676. (troop_slot_ge, ":cur_npc", slot_troop_met, 1),
  4677. (neg|troop_slot_ge, ":cur_npc", slot_troop_occupation, slto_retirement),
  4678. (this_or_next|troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_kingdom_hero),
  4679. (this_or_next|troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_player_companion),
  4680. (this_or_next|troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_kingdom_seneschal),
  4681. (troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_kingdom_lady),
  4682.  
  4683. (neg|troop_slot_ge, ":cur_npc", slot_troop_occupation, slto_retirement),
  4684. (neq, ":cur_npc", "$g_wedding_groom_troop"),
  4685. (neq, ":cur_npc", "$g_wedding_bride_troop"),
  4686. (neq, ":cur_npc", "$g_wedding_bishop_troop"),
  4687.  
  4688. (this_or_next|neg|troop_slot_ge, ":cur_npc", slot_lord_reputation_type, lrep_roguish),
  4689. (this_or_next|troop_slot_ge, ":cur_npc", slot_lord_reputation_type, lrep_conventional),
  4690.  
  4691. (assign, "$g_wedding_brides_dad_troop", ":cur_npc"),
  4692. (else_try),
  4693. #any other companion or lord that is favorable
  4694. (assign, ":best_score", 0),#must be at least positive
  4695. (try_for_range, ":cur_npc", heroes_begin, heroes_end),
  4696. (neq, ":cur_npc", "$g_wedding_groom_troop"),
  4697. (neq, ":cur_npc", "$g_wedding_bride_troop"),
  4698. (neq, ":cur_npc", "$g_wedding_bishop_troop"),
  4699. (neq, ":cur_npc", "trp_knight_1_1_wife"),
  4700. (neq, ":cur_npc", "trp_kingdom_heroes_including_player_begin"),
  4701.  
  4702. (neg|troop_slot_ge, ":cur_npc", slot_troop_occupation, slto_retirement),
  4703.  
  4704. (call_script, "script_troop_get_relation_with_troop", ":cur_npc", "$g_wedding_bride_troop"),
  4705. (assign, ":relation", reg0),
  4706. #(call_script, "script_troop_get_family_relation_to_troop", ":cur_npc", "$g_wedding_bride_troop"),
  4707. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":cur_npc", "$g_wedding_bride_troop"),
  4708. (assign, ":family_relation", reg0),
  4709.  
  4710. (store_add, ":score", ":relation", ":family_relation"),
  4711.  
  4712. (gt, ":score", ":best_score"),#score better than current best
  4713. (assign, ":best_score", ":score"),
  4714. (assign, "$g_wedding_brides_dad_troop", ":cur_npc"),
  4715. (try_end),
  4716. ##diplomacy end+
  4717. (try_end),
  4718. (else_try),
  4719. (try_for_range, ":cur_companion", companions_begin, companions_end),
  4720. (this_or_next|troop_slot_eq, ":cur_companion", slot_troop_occupation, slto_player_companion),
  4721. (troop_slot_eq, ":cur_companion", slot_troop_occupation, slto_kingdom_hero),
  4722. ##diplomacy start+
  4723. #(troop_get_type, ":troop_type", ":cur_companion"), #just to make sure
  4724. #(eq, ":troop_type", 0), #male
  4725. (call_script, "script_dplmc_store_troop_is_female", ":cur_companion"),
  4726. (this_or_next|eq, reg0, 0),
  4727. (eq, ":bride_is_woman", 0),
  4728. ##diplomacy end+
  4729. (neq, ":cur_companion", "$g_wedding_groom_troop"),
  4730. (neq, ":cur_companion", "$g_wedding_bishop_troop"),
  4731. (assign, "$g_wedding_brides_dad_troop", ":cur_companion"),
  4732. (try_end),
  4733. ##diplomacy start+ try again with female companions if no male companions available
  4734. (eq, "$g_wedding_brides_dad_troop", "trp_temporary_minister"),
  4735. (try_for_range, ":cur_companion", companions_begin, companions_end),
  4736. (this_or_next|troop_slot_eq, ":cur_companion", slot_troop_occupation, slto_player_companion),
  4737. (troop_slot_eq, ":cur_companion", slot_troop_occupation, slto_kingdom_hero),
  4738. (neq, ":cur_companion", "$g_wedding_groom_troop"),
  4739. (neq, ":cur_companion", "$g_wedding_bishop_troop"),
  4740. (assign, "$g_wedding_brides_dad_troop", ":cur_companion"),
  4741. (try_end),
  4742. #try again with all lords if no female companions available
  4743. (eq, "$g_wedding_brides_dad_troop", "trp_temporary_minister"),
  4744. (assign, ":best_score", -100),#best score
  4745. (try_for_range, ":cur_npc", heroes_begin, heroes_end),
  4746. (neg|troop_slot_eq, ":cur_npc", slot_troop_met, 0),
  4747.  
  4748. (this_or_next|troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_kingdom_seneschal),
  4749. (this_or_next|troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_player_companion),
  4750. (this_or_next|troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_kingdom_lady),
  4751. (troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_kingdom_hero),
  4752.  
  4753. (neq, ":cur_npc", "$g_wedding_groom_troop"),
  4754. (neq, ":cur_npc", "$g_wedding_bishop_troop"),
  4755. (neq, ":cur_npc", "trp_knight_1_1_wife"),
  4756. (neq, ":cur_npc", "trp_kingdom_heroes_including_player_begin"),
  4757.  
  4758. (call_script, "script_troop_get_player_relation", ":cur_npc"),
  4759. (assign, ":score", reg0),
  4760. (ge, ":score", 0),
  4761. (call_script, "script_dplmc_is_affiliated_family_member", ":cur_npc"),
  4762. (this_or_next|ge, ":score", 20),
  4763. (ge, reg0, 1),
  4764. (gt, ":score", ":best_score"),
  4765. (assign, ":best_score", ":score"),
  4766. (assign, "$g_wedding_brides_dad_troop", ":cur_npc"),
  4767. (try_end),
  4768. ##diplomacy end+
  4769. (try_end),
  4770.  
  4771. (modify_visitors_at_site,"scn_wedding"),
  4772. (reset_visitors,0),
  4773. (set_visitor, 0, "$g_wedding_groom_troop"),
  4774. (set_visitor, 1, "$g_wedding_bride_troop"),
  4775. (set_visitor, 2, "$g_wedding_brides_dad_troop"),
  4776. (set_visitor, 3, "$g_wedding_bishop_troop"),
  4777. (assign, ":num_visitors", 4),
  4778. (assign, ":num_male_visitors", 0),
  4779. ##diplomacy start+
  4780. (store_troop_faction, ":groom_faction", "$g_wedding_groom_troop"),
  4781. (store_troop_faction, ":bride_faction", "$g_wedding_bride_troop"),
  4782. ##diplomacy end+
  4783. (try_for_range, ":cur_npc", active_npcs_begin, kingdom_ladies_end),
  4784. (lt, ":num_visitors", 32),
  4785. (neq, ":cur_npc", "$g_wedding_groom_troop"),
  4786. (neq, ":cur_npc", "$g_wedding_bride_troop"),
  4787. (neq, ":cur_npc", "$g_wedding_brides_dad_troop"),
  4788. (neq, ":cur_npc", "$g_wedding_bishop_troop"),
  4789. (store_troop_faction, ":npc_faction", ":cur_npc"),
  4790. ##diplomacy start+
  4791. #(is_between, ":npc_faction", kingdoms_begin, kingdoms_end),
  4792. #(eq, ":npc_faction", "$players_kingdom"),
  4793. (this_or_next|eq, ":groom_faction", ":npc_faction"),
  4794. (eq, ":bride_faction", ":npc_faction"),
  4795. ##diplomacy end+
  4796. (this_or_next|troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_player_companion),
  4797. (this_or_next|troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_kingdom_hero),
  4798. (troop_slot_eq, ":cur_npc", slot_troop_occupation, slto_kingdom_lady),
  4799. ##diplomacy start+
  4800. #(troop_get_type, ":troop_type", ":cur_npc"),
  4801. (call_script, "script_dplmc_store_troop_is_female", ":cur_npc"),
  4802. (assign, ":troop_type", reg0),
  4803. ##diplomacy end+
  4804. (assign, ":continue_adding", 1),
  4805. (try_begin),
  4806. (eq, ":troop_type", 0),
  4807. (assign, ":continue_adding", 0),
  4808. (lt, ":num_male_visitors", 16), #limit number of male visitors
  4809. (assign, ":continue_adding", 1),
  4810. (val_add, ":num_male_visitors", 1),
  4811. (try_end),
  4812. (eq, ":continue_adding", 1),
  4813. (set_visitor, ":num_visitors", ":cur_npc"),
  4814. (val_add, ":num_visitors", 1),
  4815. (try_end),
  4816. ##diplomacy start+
  4817. (assign, reg0, ":save_reg0"),
  4818. (assign, reg1, ":save_reg1"),
  4819. ##diplomacy end+
  4820. (set_jump_mission,"mt_wedding"),
  4821. (jump_to_scene,"scn_wedding"),
  4822. (change_screen_mission),
  4823. ]),
  4824.  
  4825.  
  4826. # script_game_get_troop_wage
  4827. # This script is called from the game engine for calculating troop wages.
  4828. # Input:
  4829. # param1: troop_id, param2: party-id
  4830. # Output: reg0: weekly wage
  4831.  
  4832. ("game_get_troop_wage",
  4833. [
  4834. (store_script_param_1, ":troop_id"),
  4835. (store_script_param_2, ":unused"), #party id
  4836.  
  4837. (assign,":wage", 0),
  4838. (try_begin),
  4839. (this_or_next|eq, ":troop_id", "trp_player"),
  4840. (eq, ":troop_id", "trp_kidnapped_girl"),
  4841. (else_try),
  4842. (is_between, ":troop_id", pretenders_begin, pretenders_end),
  4843. ##diplomacy start+
  4844. (else_try),
  4845. #Temporarily joined lords and ladies don't require wages.
  4846. (is_between, ":troop_id", heroes_begin, heroes_end),
  4847. (this_or_next|troop_slot_eq, ":troop_id", slot_troop_playerparty_history,dplmc_pp_history_lord_rejoined),
  4848. (this_or_next|troop_slot_eq, ":troop_id", slot_troop_occupation, slto_kingdom_hero),
  4849. (troop_slot_eq, ":troop_id",slot_troop_occupation, slto_kingdom_lady),
  4850. ##diplomacy end+
  4851. (else_try),
  4852. (store_character_level, ":troop_level", ":troop_id"),
  4853. (assign, ":wage", ":troop_level"),
  4854. (val_add, ":wage", 3),
  4855. (val_mul, ":wage", ":wage"),
  4856. (val_div, ":wage", 25),
  4857. (try_end),
  4858.  
  4859. (try_begin), #mounted troops cost 65% more than the normal cost
  4860. (neg|is_between, ":troop_id", companions_begin, companions_end),
  4861. (troop_is_mounted, ":troop_id"),
  4862. (val_mul, ":wage", 5),
  4863. (val_div, ":wage", 3),
  4864. (try_end),
  4865.  
  4866. (try_begin), #mercenaries cost %50 more than the normal cost
  4867. (is_between, ":troop_id", mercenary_troops_begin, mercenary_troops_end),
  4868. (val_mul, ":wage", 3),
  4869. (val_div, ":wage", 2),
  4870. (try_end),
  4871.  
  4872. (try_begin),
  4873. (is_between, ":troop_id", companions_begin, companions_end),
  4874. (val_mul, ":wage", 2),
  4875. (try_end),
  4876.  
  4877. (store_skill_level, ":leadership_level", "skl_leadership", "trp_player"),
  4878. (store_mul, ":leadership_bonus", 5, ":leadership_level"),
  4879. (store_sub, ":leadership_factor", 100, ":leadership_bonus"),
  4880. (val_mul, ":wage", ":leadership_factor"), #wage = wage * (100 - 5*leadership)/100
  4881. (val_div, ":wage", 100),
  4882.  
  4883. (try_begin),
  4884. (neq, ":troop_id", "trp_player"),
  4885. (neq, ":troop_id", "trp_kidnapped_girl"),
  4886. (neg|is_between, ":troop_id", pretenders_begin, pretenders_end),
  4887. ##diplomacy start+ For temporarily rejoined lords, and temporarily joined ladies
  4888. (neg|troop_slot_eq, ":troop_id", slot_troop_playerparty_history,dplmc_pp_history_lord_rejoined),
  4889. (neg|troop_slot_eq, ":troop_id", slot_troop_occupation, slto_kingdom_hero),
  4890. (neg|is_between, ":troop_id", kingdom_ladies_begin, kingdom_ladies_end),
  4891. ##diplomacy end+
  4892. (val_max, ":wage", 1),
  4893. (try_end),
  4894.  
  4895. (assign, reg0, ":wage"),
  4896. (set_trigger_result, reg0),
  4897. ]),
  4898.  
  4899. # script_game_get_total_wage
  4900. # This script is called from the game engine for calculating total wage of the player party which is shown at the party window.
  4901. # Input: none
  4902. # Output: reg0: weekly wage
  4903.  
  4904. ("game_get_total_wage",
  4905. [
  4906. (assign, ":total_wage", 0),
  4907. (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  4908. (try_for_range, ":i_stack", 0, ":num_stacks"),
  4909. (party_stack_get_troop_id, ":stack_troop", "p_main_party", ":i_stack"),
  4910. (party_stack_get_size, ":stack_size", "p_main_party", ":i_stack"),
  4911. (call_script, "script_game_get_troop_wage", ":stack_troop", 0),
  4912. (val_mul, reg0, ":stack_size"),
  4913. (val_add, ":total_wage", reg0),
  4914. (try_end),
  4915. ##diplomacy start+
  4916. #If the player leads a kingdom, take into account centralization.
  4917. (faction_get_slot, ":centralization", "$players_kingdom", dplmc_slot_faction_centralization),
  4918. (try_begin),
  4919. (neq, ":centralization", 0),
  4920.  
  4921. (assign, reg0, 0),
  4922. (try_begin),
  4923. (is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
  4924. (faction_get_slot, ":faction_leader", "$players_kingdom", slot_faction_leader),
  4925. (ge, ":faction_leader", 0),
  4926. (this_or_next|eq, ":faction_leader", "trp_player"),
  4927. (this_or_next|troop_slot_eq, ":faction_leader", slot_troop_spouse, "trp_player"),
  4928. (troop_slot_eq, "trp_player", slot_troop_spouse, reg0),
  4929. (assign, reg0, 1),
  4930. (try_end),
  4931.  
  4932. (this_or_next|eq, reg0, 1),
  4933. (eq, "$players_kingdom", "fac_player_supporters_faction"),
  4934. (faction_slot_eq, "$players_kingdom", slot_faction_state, sfs_active),
  4935.  
  4936. #Apply centralization, but limit it for nascent kingdoms
  4937. (val_clamp, ":centralization", -3, 4),
  4938. (faction_get_slot, ":policy_limit", "$players_kingdom", slot_faction_num_towns),
  4939. (faction_get_slot, reg0, "$players_kingdom", slot_faction_num_castles),
  4940. (val_add, ":policy_limit", reg0),
  4941.  
  4942. (val_max, ":policy_limit", 0),
  4943. (val_min, ":centralization", ":policy_limit"),
  4944. (val_mul, ":policy_limit", -1),
  4945. (val_max, ":centralization", ":policy_limit"),
  4946.  
  4947. #Now reg0 is going to be the result again
  4948. (store_mul, reg0, ":centralization", -5),
  4949. (val_add, reg0, 100),
  4950. (val_mul, reg0, ":total_wage"),
  4951. (val_add, reg0, 50),#rounding
  4952. (val_div, reg0, 100),
  4953. (try_end),
  4954. ##diplomacy end+
  4955. (assign, reg0, ":total_wage"),
  4956. (set_trigger_result, reg0),
  4957. ]),
  4958.  
  4959. # script_game_get_join_cost
  4960. # This script is called from the game engine for calculating troop join cost.
  4961. # Input:
  4962. # param1: troop_id,
  4963. # Output: reg0: weekly wage
  4964.  
  4965. ("game_get_join_cost",
  4966. [
  4967. (store_script_param_1, ":troop_id"),
  4968.  
  4969. (assign,":join_cost", 0),
  4970. (try_begin),
  4971. (troop_is_hero, ":troop_id"),
  4972. (else_try),
  4973. (store_character_level, ":troop_level", ":troop_id"),
  4974. (store_add, ":join_cost", ":troop_level", 5),
  4975. (val_mul, ":join_cost", ":join_cost"),
  4976. (val_add, ":join_cost", 40),
  4977. (val_div, ":join_cost", 5),
  4978. (try_begin), #mounted troops cost %100 more than the normal cost
  4979. (troop_is_mounted, ":troop_id"),
  4980. (val_mul, ":join_cost", 2),
  4981. (try_end),
  4982. (try_end),
  4983. (assign, reg0, ":join_cost"),
  4984. (set_trigger_result, reg0),
  4985. ]),
  4986.  
  4987. # script_game_get_upgrade_xp
  4988. # This script is called from game engine for calculating needed troop upgrade exp
  4989. # Input:
  4990. # param1: troop_id,
  4991. # Output: reg0 = needed exp for upgrade
  4992. ("game_get_upgrade_xp",
  4993. [
  4994. (store_script_param_1, ":troop_id"),
  4995.  
  4996. (assign, ":needed_upgrade_xp", 0),
  4997. #formula : int needed_upgrade_xp = 2 * (30 + 0.006f * level_boundaries[troops[troop_id].level + 3]);
  4998. (store_character_level, ":troop_level", ":troop_id"),
  4999. (store_add, ":needed_upgrade_xp", ":troop_level", 3),
  5000. (get_level_boundary, reg0, ":needed_upgrade_xp"),
  5001. (val_mul, reg0, 6),
  5002. (val_div, reg0, 1000),
  5003. (val_add, reg0, 30),
  5004.  
  5005. (try_begin), #SB : merge range
  5006. (is_between, ":troop_id", bandits_begin, bandits_end),
  5007. (val_mul, reg0, 2),
  5008. (try_end),
  5009.  
  5010. (set_trigger_result, reg0),
  5011. ]),
  5012.  
  5013. # script_game_get_upgrade_cost
  5014. # This script is called from game engine for calculating needed troop upgrade exp
  5015. # Input:
  5016. # param1: troop_id,
  5017. # Output: reg0 = needed cost for upgrade
  5018. ("game_get_upgrade_cost",
  5019. [
  5020. (store_script_param_1, ":troop_id"),
  5021.  
  5022. (store_character_level, ":troop_level", ":troop_id"),
  5023.  
  5024. (try_begin),
  5025. (is_between, ":troop_level", 0, 6),
  5026. (assign, reg0, 10),
  5027. (else_try),
  5028. (is_between, ":troop_level", 6, 11),
  5029. (assign, reg0, 20),
  5030. (else_try),
  5031. (is_between, ":troop_level", 11, 16),
  5032. (assign, reg0, 40),
  5033. (else_try),
  5034. (is_between, ":troop_level", 16, 21),
  5035. (assign, reg0, 80),
  5036. (else_try),
  5037. (is_between, ":troop_level", 21, 26),
  5038. (assign, reg0, 120),
  5039. (else_try),
  5040. (is_between, ":troop_level", 26, 31),
  5041. (assign, reg0, 160),
  5042. (else_try),
  5043. (assign, reg0, 200),
  5044. (try_end),
  5045.  
  5046. (set_trigger_result, reg0),
  5047. ]),
  5048.  
  5049. # script_game_get_prisoner_price
  5050. # This script is called from the game engine for calculating prisoner price
  5051. # Input:
  5052. # param1: troop_id,
  5053. # Output: reg0
  5054. ("game_get_prisoner_price",
  5055. [
  5056. (store_script_param_1, ":troop_id"),
  5057.  
  5058. (try_begin), #SB : regular prices for constable selling
  5059. (this_or_next|eq, "$g_talk_troop", "$g_player_constable"),
  5060. (is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
  5061. (store_character_level, ":troop_level", ":troop_id"),
  5062. (store_add, ":ransom_amount", ":troop_level", 10),
  5063. # (val_add, ":ransom_amount", 10),
  5064. (val_mul, ":ransom_amount", ":ransom_amount"),
  5065. (val_div, ":ransom_amount", 6),
  5066. (else_try),
  5067. (assign, ":ransom_amount", 50),
  5068. (try_end),
  5069.  
  5070. (assign, reg0, ":ransom_amount"),
  5071.  
  5072. (set_trigger_result, reg0),
  5073. ]),
  5074.  
  5075.  
  5076. # script_game_check_prisoner_can_be_sold
  5077. # This script is called from the game engine for checking if a given troop can be sold.
  5078. # Input:
  5079. # param1: troop_id,
  5080. # Output: reg0: 1= can be sold; 0= cannot be sold.
  5081.  
  5082. ("game_check_prisoner_can_be_sold",
  5083. [
  5084. (store_script_param_1, ":troop_id"),
  5085. (assign, reg0, 0),
  5086. (try_begin),
  5087. (neg|troop_is_hero, ":troop_id"),
  5088. (try_begin),
  5089. (check_quest_active, "qst_hunt_down_fugitive"),
  5090. (eq, ":troop_id", "trp_fugitive"), #SB : can't sell quest troops
  5091. (assign, reg0, 0),
  5092. (else_try),
  5093. (check_quest_active, "qst_hunt_down_fugitive"),
  5094. (this_or_next|eq, ":troop_id", "trp_spy"),
  5095. (eq, ":troop_id", "trp_spy_partner"),
  5096. (assign, reg0, 0),
  5097. (else_try),
  5098. (assign, reg0, 1),
  5099. (try_end),
  5100. (try_end),
  5101. (set_trigger_result, reg0),
  5102. ]),
  5103.  
  5104. # script_game_get_morale_of_troops_from_faction
  5105. # This script is called from the game engine
  5106. # Input:
  5107. # param1: faction_no,
  5108. # Output: reg0: extra morale x 100
  5109.  
  5110. ("game_get_morale_of_troops_from_faction",
  5111. [
  5112. (store_script_param_1, ":troop_no"),
  5113.  
  5114. (store_troop_faction, ":faction_no", ":troop_no"),
  5115.  
  5116. (try_begin),
  5117. (is_between, ":faction_no", npc_kingdoms_begin, npc_kingdoms_end),
  5118.  
  5119. (faction_get_slot, reg0, ":faction_no", slot_faction_morale_of_player_troops),
  5120.  
  5121. #(assign, reg1, ":faction_no"),
  5122. #(assign, reg2, ":troop_no"),
  5123. #(assign, reg3, reg0),
  5124. #(display_message, "@extra morale for troop {reg2} of faction {reg1} is {reg3}"),
  5125. (else_try),
  5126. (assign, reg0, 0),
  5127. (try_end),
  5128. ##diplomacy start+
  5129. #If there is no current morale penalty, then there will be a minor morale bonus
  5130. #if the player has his own faction and his culture matches the source kingdom.
  5131. (try_begin),
  5132. (eq, reg0, 0),
  5133. (is_between,"$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  5134. (eq, "$g_player_culture", ":faction_no"),
  5135. #xxx TODO: pick a number less arbitrarily
  5136. (assign, reg0, 100),
  5137. (try_end),
  5138. ##diplomacy end+
  5139. (val_div, reg0, 100),
  5140.  
  5141. (party_get_morale, reg1, "p_main_party"),
  5142.  
  5143. (val_add, reg0, reg1),
  5144.  
  5145. (set_trigger_result, reg0),
  5146. ]),
  5147.  
  5148. #script_game_event_detect_party:
  5149. # This script is called from the game engine when player party inspects another party.
  5150. # INPUT:
  5151. # param1: Party-id
  5152. ("game_event_detect_party",
  5153. [
  5154. (store_script_param_1, ":party_id"),
  5155. (try_begin),
  5156. (party_slot_eq, ":party_id", slot_party_type, spt_kingdom_hero_party),
  5157. (party_stack_get_troop_id, ":leader", ":party_id", 0),
  5158. ##diplomacy start+ support for promoted kingdom ladies
  5159. (is_between, ":leader", heroes_begin, heroes_end),
  5160. (this_or_next|troop_slot_eq, ":leader", slot_troop_occupation, slto_kingdom_hero),
  5161. ##diplomacy end+
  5162. (is_between, ":leader", active_npcs_begin, active_npcs_end),
  5163. (call_script, "script_update_troop_location_notes", ":leader", 0),
  5164. (else_try),
  5165. (is_between, ":party_id", walled_centers_begin, walled_centers_end),
  5166. (party_get_num_attached_parties, ":num_attached_parties", ":party_id"),
  5167. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  5168. (party_get_attached_party_with_rank, ":attached_party", ":party_id", ":attached_party_rank"),
  5169. (party_stack_get_troop_id, ":leader", ":attached_party", 0),
  5170. ##diplomacy start+ support for promoted kingdom ladies
  5171. (is_between, ":leader", heroes_begin, heroes_end),
  5172. (this_or_next|troop_slot_eq, ":leader", slot_troop_occupation, slto_kingdom_hero),
  5173. ##diplomacy end+
  5174. (is_between, ":leader", active_npcs_begin, active_npcs_end),
  5175. (call_script, "script_update_troop_location_notes", ":leader", 0),
  5176. (try_end),
  5177. (try_end),
  5178. ]),
  5179.  
  5180. #script_game_event_undetect_party:
  5181. # This script is called from the game engine when player party inspects another party.
  5182. # INPUT:
  5183. # param1: Party-id
  5184. ("game_event_undetect_party",
  5185. [
  5186. (store_script_param_1, ":party_id"),
  5187. (try_begin),
  5188. (party_slot_eq, ":party_id", slot_party_type, spt_kingdom_hero_party),
  5189. (party_stack_get_troop_id, ":leader", ":party_id", 0),
  5190. ##diplomacy start+ support for promoted kingdom ladies
  5191. (is_between, ":leader", heroes_begin, heroes_end),
  5192. (this_or_next|troop_slot_eq, ":leader", slot_troop_occupation, slto_kingdom_hero),
  5193. ##diplomacy end+
  5194. (is_between, ":leader", active_npcs_begin, active_npcs_end),
  5195. (call_script, "script_update_troop_location_notes", ":leader", 0),
  5196. (try_end),
  5197. ]),
  5198.  
  5199. #script_game_get_statistics_line:
  5200. # This script is called from the game engine when statistics page is opened.
  5201. # INPUT:
  5202. # param1: line_no
  5203. ("game_get_statistics_line",
  5204. [
  5205. (store_script_param_1, ":line_no"),
  5206. (try_begin),
  5207. (eq, ":line_no", 0),
  5208. (get_player_agent_kill_count, reg1),
  5209. (str_store_string, s1, "str_number_of_troops_killed_reg1"),
  5210. (set_result_string, s1),
  5211. (else_try),
  5212. (eq, ":line_no", 1),
  5213. (get_player_agent_kill_count, reg1, 1),
  5214. (str_store_string, s1, "str_number_of_troops_wounded_reg1"),
  5215. (set_result_string, s1),
  5216. (else_try),
  5217. (eq, ":line_no", 2),
  5218. (get_player_agent_own_troop_kill_count, reg1),
  5219. (str_store_string, s1, "str_number_of_own_troops_killed_reg1"),
  5220. (set_result_string, s1),
  5221. (else_try),
  5222. (eq, ":line_no", 3),
  5223. (get_player_agent_own_troop_kill_count, reg1, 1),
  5224. (str_store_string, s1, "str_number_of_own_troops_wounded_reg1"),
  5225. (set_result_string, s1),
  5226. (try_end),
  5227. ]),
  5228.  
  5229. #script_game_get_date_text:
  5230. # This script is called from the game engine when the date needs to be displayed.
  5231. # INPUT: arg1 = number of days passed since the beginning of the game
  5232. # OUTPUT: result string = date
  5233. ("game_get_date_text",
  5234. [
  5235. (store_script_param_2, ":num_hours"),
  5236. (store_div, ":num_days", ":num_hours", 24),
  5237. (store_add, ":cur_day", ":num_days", 23),
  5238. (assign, ":cur_month", 3),
  5239. (assign, ":cur_year", 1257),
  5240. (assign, ":try_range", 99999),
  5241. (try_for_range, ":unused", 0, ":try_range"),
  5242. (try_begin),
  5243. (this_or_next|eq, ":cur_month", 1),
  5244. (this_or_next|eq, ":cur_month", 3),
  5245. (this_or_next|eq, ":cur_month", 5),
  5246. (this_or_next|eq, ":cur_month", 7),
  5247. (this_or_next|eq, ":cur_month", 8),
  5248. (this_or_next|eq, ":cur_month", 10),
  5249. (eq, ":cur_month", 12),
  5250. (assign, ":month_day_limit", 31),
  5251. (else_try),
  5252. (this_or_next|eq, ":cur_month", 4),
  5253. (this_or_next|eq, ":cur_month", 6),
  5254. (this_or_next|eq, ":cur_month", 9),
  5255. (eq, ":cur_month", 11),
  5256. (assign, ":month_day_limit", 30),
  5257. (else_try),
  5258. (try_begin),
  5259. (store_div, ":cur_year_div_4", ":cur_year", 4),
  5260. (val_mul, ":cur_year_div_4", 4),
  5261. (eq, ":cur_year_div_4", ":cur_year"),
  5262. (assign, ":month_day_limit", 29),
  5263. (else_try),
  5264. (assign, ":month_day_limit", 28),
  5265. (try_end),
  5266. (try_end),
  5267. (try_begin),
  5268. (gt, ":cur_day", ":month_day_limit"),
  5269. (val_sub, ":cur_day", ":month_day_limit"),
  5270. (val_add, ":cur_month", 1),
  5271. (try_begin),
  5272. (gt, ":cur_month", 12),
  5273. (val_sub, ":cur_month", 12),
  5274. (val_add, ":cur_year", 1),
  5275. (try_end),
  5276. (else_try),
  5277. (assign, ":try_range", 0),
  5278. (try_end),
  5279. (try_end),
  5280. (assign, reg1, ":cur_day"),
  5281. (assign, reg2, ":cur_year"),
  5282. (try_begin),
  5283. (eq, ":cur_month", 1),
  5284. (str_store_string, s1, "str_january_reg1_reg2"),
  5285. (else_try),
  5286. (eq, ":cur_month", 2),
  5287. (str_store_string, s1, "str_february_reg1_reg2"),
  5288. (else_try),
  5289. (eq, ":cur_month", 3),
  5290. (str_store_string, s1, "str_march_reg1_reg2"),
  5291. (else_try),
  5292. (eq, ":cur_month", 4),
  5293. (str_store_string, s1, "str_april_reg1_reg2"),
  5294. (else_try),
  5295. (eq, ":cur_month", 5),
  5296. (str_store_string, s1, "str_may_reg1_reg2"),
  5297. (else_try),
  5298. (eq, ":cur_month", 6),
  5299. (str_store_string, s1, "str_june_reg1_reg2"),
  5300. (else_try),
  5301. (eq, ":cur_month", 7),
  5302. (str_store_string, s1, "str_july_reg1_reg2"),
  5303. (else_try),
  5304. (eq, ":cur_month", 8),
  5305. (str_store_string, s1, "str_august_reg1_reg2"),
  5306. (else_try),
  5307. (eq, ":cur_month", 9),
  5308. (str_store_string, s1, "str_september_reg1_reg2"),
  5309. (else_try),
  5310. (eq, ":cur_month", 10),
  5311. (str_store_string, s1, "str_october_reg1_reg2"),
  5312. (else_try),
  5313. (eq, ":cur_month", 11),
  5314. (str_store_string, s1, "str_november_reg1_reg2"),
  5315. (else_try),
  5316. (eq, ":cur_month", 12),
  5317. (str_store_string, s1, "str_december_reg1_reg2"),
  5318. (try_end),
  5319. (set_result_string, s1),
  5320. ]),
  5321.  
  5322. #script_game_get_money_text:
  5323. # This script is called from the game engine when an amount of money needs to be displayed.
  5324. # INPUT: arg1 = amount in units
  5325. # OUTPUT: result string = money in text
  5326. ("game_get_money_text",
  5327. [
  5328. (store_script_param_1, ":amount"),
  5329. (try_begin),
  5330. (eq, ":amount", 1),
  5331. (str_store_string, s1, "str_1_denar"),
  5332. (else_try),
  5333. (assign, reg1, ":amount"),
  5334. (str_store_string, s1, "str_reg1_denars"),
  5335. (try_end),
  5336. (set_result_string, s1),
  5337. ]),
  5338.  
  5339. #script_game_get_party_companion_limit:
  5340. # This script is called from the game engine when the companion limit is needed for a party.
  5341. # INPUT: arg1 = none
  5342. # OUTPUT: reg0 = companion_limit
  5343. ("game_get_party_companion_limit",
  5344. [
  5345. (assign, ":troop_no", "trp_player"),
  5346.  
  5347. (assign, ":limit", 30),
  5348. (store_skill_level, ":skill", "skl_leadership", ":troop_no"),
  5349. (store_attribute_level, ":charisma", ":troop_no", ca_charisma),
  5350. (val_mul, ":skill", 5),
  5351. (val_add, ":limit", ":skill"),
  5352. (val_add, ":limit", ":charisma"),
  5353.  
  5354. #SB : possibly inherit half of spouse's renown
  5355. (troop_get_slot, ":troop_renown", ":troop_no", slot_troop_renown),
  5356. (store_div, ":renown_bonus", ":troop_renown", 25),
  5357. (val_add, ":limit", ":renown_bonus"),
  5358.  
  5359. #SB : add non-standard size modifiers here
  5360. (try_begin),
  5361. (eq, ":troop_no", "trp_player"),
  5362. (is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
  5363. (try_begin),
  5364. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  5365. (store_mul, ":king_bonus", "$player_right_to_rule", 5),
  5366. (val_clamp, ":king_bonus", dplmc_marshal_party_bonus, dplmc_monarch_party_bonus + 1), #to match marshal amount
  5367. (val_add, ":limit", ":king_bonus"),
  5368. (try_end),
  5369. (try_begin),
  5370. (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
  5371. (val_add, ":limit", dplmc_marshal_party_bonus),
  5372. (try_end),
  5373. #party takes additional 20 limit per each castle its party leader owns
  5374. (try_for_range, ":cur_center", castles_begin, castles_end),
  5375. (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
  5376. (val_add, ":limit", dplmc_castle_party_bonus),
  5377. (try_end),
  5378.  
  5379. ##diplomacy begin
  5380. (assign, ":percent", 100),
  5381. (assign, ":policy_min", -3),
  5382. (assign, ":policy_max", 4),
  5383.  
  5384. (try_begin),
  5385. (this_or_next|eq, "$players_kingdom", "fac_player_supporters_faction"),
  5386. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  5387. (faction_get_slot, ":policy_max", "$players_kingdom", slot_faction_num_towns),
  5388. (faction_get_slot, reg0, "$players_kingdom", slot_faction_num_castles),
  5389. (val_add, ":policy_max", reg0),
  5390. (val_clamp, ":policy_max", 0, 4),#0, 1, 2, 3
  5391. (store_mul, ":policy_min", ":policy_max", -1),
  5392. (val_add, ":policy_max", 1),#one greater than the maximum
  5393. (try_end),
  5394. ##diplomacy end+
  5395.  
  5396. (try_begin),
  5397. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  5398. # (val_add, ":limit", "$player_right_to_rule"),
  5399. (try_begin),
  5400. (faction_get_slot, ":centralization", "$players_kingdom", dplmc_slot_faction_centralization),
  5401. (neq, ":centralization", 0),
  5402. (val_clamp, ":centralization", ":policy_min", ":policy_max"),
  5403. (val_mul, ":centralization", 10),
  5404. (val_add, ":percent", ":centralization"),
  5405. (try_end),
  5406.  
  5407. (else_try),
  5408. (try_begin),
  5409. (faction_get_slot, ":centralization", "$players_kingdom", dplmc_slot_faction_centralization),
  5410. (neq, ":centralization", 0),
  5411. (val_clamp, ":centralization", ":policy_min", ":policy_max"),
  5412. (val_mul, ":centralization", -3),
  5413. (val_add, ":percent", ":centralization"),
  5414. (try_end),
  5415. (try_begin),
  5416. (faction_get_slot, ":aristocracy", "$players_kingdom", dplmc_slot_faction_aristocracy),
  5417. (neq, ":aristocracy", 0),
  5418. (val_clamp, ":aristocracy", ":policy_min", ":policy_max"),
  5419. (val_mul, ":aristocracy", 3),
  5420. (val_add, ":percent", ":aristocracy"),
  5421. (try_end),
  5422. (try_begin),
  5423. (faction_get_slot, ":quality", "$players_kingdom", dplmc_slot_faction_quality),
  5424. (neq, ":quality", 0),
  5425. (val_clamp, ":quality", ":policy_min", ":policy_max"),
  5426. (val_mul, ":quality", -4),
  5427. (val_add, ":percent", ":quality"),
  5428. (try_end),
  5429. (try_end),
  5430.  
  5431. (try_begin),
  5432. (faction_get_slot, ":serfdom", "$players_kingdom", dplmc_slot_faction_serfdom),
  5433. (neq, ":serfdom", 0),
  5434. (val_clamp, ":serfdom", ":policy_min", ":policy_max"),
  5435. (val_mul, ":serfdom", 2),
  5436. (val_add, ":percent", ":serfdom"),
  5437. (try_end),
  5438.  
  5439. (val_mul, ":limit", ":percent"),
  5440. ##nested diplomacy start+ Round correctly
  5441. (val_add, ":limit", 50),
  5442. ##nested diplomacy end+
  5443. (val_div, ":limit", 100),
  5444. ##diplomacy end
  5445. (try_end),
  5446.  
  5447. (assign, reg0, ":limit"),
  5448. (set_trigger_result, reg0),
  5449. ]),
  5450.  
  5451.  
  5452. #script_game_reset_player_party_name:
  5453. # This script is called from the game engine when the player name is changed.
  5454. # INPUT: none
  5455. # OUTPUT: none
  5456. ("game_reset_player_party_name",
  5457. [(str_store_troop_name, s5, "trp_player"),
  5458. (party_set_name, "p_main_party", s5),
  5459. ]),
  5460.  
  5461. #script_game_get_troop_note
  5462. # This script is called from the game engine when the notes of a troop is needed.
  5463. # INPUT: arg1 = troop_no, arg2 = note_index
  5464. # OUTPUT: s0 = note
  5465. ("game_get_troop_note",
  5466. [
  5467. (store_script_param_1, ":troop_no"),
  5468. (store_script_param_2, ":note_index"),
  5469. (set_trigger_result, 0),
  5470.  
  5471. (str_store_troop_name, s54, ":troop_no"),
  5472. (try_begin),
  5473. (eq, ":troop_no", "trp_player"),
  5474. (this_or_next|eq, "$player_has_homage", 1),
  5475. (eq, "$players_kingdom", "fac_player_supporters_faction"),
  5476. (assign, ":troop_faction", "$players_kingdom"),
  5477. (else_try),
  5478. (store_troop_faction, ":troop_faction", ":troop_no"),
  5479. (try_end),
  5480. (str_clear, s49),
  5481.  
  5482. #Family notes
  5483. (try_begin),
  5484. ##diplomacy start+ add support for displaying relations with kings and claimants
  5485. #(this_or_next|is_between, ":troop_no", lords_begin, kingdom_ladies_end),
  5486. #(eq, ":troop_no", "trp_player"),
  5487. #(neg|is_between, ":troop_no", pretenders_begin, pretenders_end),
  5488.  
  5489. (this_or_next|eq, ":troop_no", "trp_player"),
  5490. (this_or_next|is_between, ":troop_no", lords_begin, kingdom_ladies_end),#includes pretenders
  5491. (is_between, ":troop_no", kings_begin, kings_end),
  5492.  
  5493. ##The following would only show relations for kings and claimants if they are married.
  5494. #(this_or_next|troop_slot_ge, ":troop_no", slot_troop_spouse, 0),
  5495. # (neg|is_between, ":troop_no", pretenders_begin, pretenders_end),
  5496. #(this_or_next|troop_slot_ge, ":troop_no", slot_troop_spouse, 0),
  5497. # (neg|is_between, ":troop_no", kings_begin, kings_end),
  5498.  
  5499. ##diplomacy end+
  5500. (assign, ":num_relations", 0),
  5501.  
  5502. (try_begin),
  5503. (call_script, "script_troop_get_family_relation_to_troop", "trp_player", ":troop_no"),
  5504. (gt, reg0, 0),
  5505. (val_add, ":num_relations", 1),
  5506. (try_end),
  5507. ##diplomacy start+
  5508. #(try_for_range, ":aristocrat", lords_begin, kingdom_ladies_end),
  5509. #Display relations with kings and claimants
  5510. (try_for_range, ":aristocrat", heroes_begin, heroes_end),
  5511. (this_or_next|is_between, ":aristocrat", lords_begin, kingdom_ladies_end),#includes pretenders
  5512. (is_between, ":aristocrat", kings_begin, kings_end),
  5513. ##diplomacy end+
  5514. (call_script, "script_troop_get_family_relation_to_troop", ":aristocrat", ":troop_no"),
  5515. (gt, reg0, 0),
  5516. (val_add, ":num_relations", 1),
  5517. (try_end),
  5518. (try_begin),
  5519. (gt, ":num_relations", 0),
  5520. (try_begin),
  5521. (eq, ":troop_no", "trp_player"),
  5522. (str_store_string, s49, "str__family_"),
  5523. (else_try),
  5524. (troop_get_slot, reg1, ":troop_no", slot_troop_age),
  5525. (str_store_string, s49, "str__age_reg1_family_"),
  5526. (try_end),
  5527. (try_begin),
  5528. (call_script, "script_troop_get_family_relation_to_troop", "trp_player", ":troop_no"),
  5529. (gt, reg0, 0),
  5530. (str_store_troop_name_link, s12, "trp_player"),
  5531. (val_sub, ":num_relations", 1),
  5532. (try_begin),
  5533. (eq, ":num_relations", 0),
  5534. (str_store_string, s49, "str_s49_s12_s11_end"),
  5535. (else_try),
  5536. (str_store_string, s49, "str_s49_s12_s11"),
  5537. (try_end),
  5538. (try_end),
  5539. ##diplomacy start+
  5540. #(try_for_range, ":aristocrat", lords_begin, kingdom_ladies_end),
  5541. #Display relations with kings and claimants
  5542. (try_for_range, ":aristocrat", heroes_begin, heroes_end),
  5543. (this_or_next|is_between, ":aristocrat", lords_begin, kingdom_ladies_end),#includes pretenders
  5544. (is_between, ":aristocrat", kings_begin, kings_end),
  5545. ##diplomacy end+
  5546. (call_script, "script_troop_get_family_relation_to_troop", ":aristocrat", ":troop_no"),
  5547. (gt, reg0, 0),
  5548. (try_begin),
  5549. (neg|is_between, ":aristocrat", kingdom_ladies_begin, kingdom_ladies_end),
  5550. (eq, "$cheat_mode", 1),
  5551. (str_store_troop_name_link, s12, ":aristocrat"),
  5552. (call_script, "script_troop_get_relation_with_troop", ":aristocrat", ":troop_no"),
  5553. (str_store_string, s49, "str_s49_s12_s11_rel_reg0"),
  5554. (else_try),
  5555. (str_store_troop_name_link, s12, ":aristocrat"),
  5556. (val_sub, ":num_relations", 1),
  5557. (try_begin),
  5558. (eq, ":num_relations", 0),
  5559. (str_store_string, s49, "str_s49_s12_s11_end"),
  5560. (else_try),
  5561. (str_store_string, s49, "str_s49_s12_s11"),
  5562. (try_end),
  5563. (try_end),
  5564. (try_end),
  5565. (try_end),
  5566. (try_end),
  5567.  
  5568. (try_begin),
  5569. (neq, ":troop_no", "trp_player"),
  5570. (neg|is_between, ":troop_faction", kingdoms_begin, kingdoms_end),
  5571. (neg|is_between, ":troop_no", companions_begin, companions_end),
  5572. (neg|is_between, ":troop_no", pretenders_begin, pretenders_end),
  5573.  
  5574. (try_begin),
  5575. (eq, ":note_index", 0),
  5576. (str_store_string, s0, "str_s54_has_left_the_realm"),
  5577. ##diplomacy start+
  5578. #Check for "deceased" instead
  5579. (try_begin),
  5580. (troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_dead),
  5581. (str_store_string, s0, "str_s54_is_deceased"),
  5582. (try_end),
  5583. ##diplomacy end+
  5584. (set_trigger_result, 1),
  5585. (else_try),
  5586. (str_clear, s0),
  5587. (this_or_next|eq, ":note_index", 1),
  5588. (eq, ":note_index", 2),
  5589. (set_trigger_result, 1),
  5590. (try_end),
  5591.  
  5592. (else_try),
  5593. (is_between, ":troop_no", companions_begin, companions_end),
  5594. (neg|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  5595. (eq, ":note_index", 0),
  5596. (set_trigger_result, 1),
  5597. (str_clear, s0),
  5598. (assign, ":companion", ":troop_no"),
  5599. (str_store_troop_name, s4, ":companion"),
  5600. (try_begin),
  5601. # (troop_get_slot, ":days_left", ":companion", slot_troop_days_on_mission),
  5602.  
  5603. (this_or_next|main_party_has_troop, ":companion"),
  5604. (this_or_next|troop_slot_ge, ":companion", slot_troop_current_mission, 1),
  5605. (eq, "$g_player_minister", ":companion"),
  5606. #SB : replace the call
  5607. (call_script, "script_companion_get_mission_string", ":companion"),
  5608.  
  5609. # (try_begin),
  5610. # (troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_kingsupport),
  5611. # (str_store_string, s8, "str_gathering_support"),
  5612. # (try_begin),
  5613. # (eq, ":days_left", 1),
  5614. # (str_store_string, s5, "str_expected_back_imminently"),
  5615. # (else_try),
  5616. # (assign, reg3, ":days_left"),
  5617. # (str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
  5618. # (try_end),
  5619. # (else_try),
  5620. # (troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_gather_intel),
  5621. # (troop_get_slot, ":town_with_contacts", ":companion", slot_troop_town_with_contacts),
  5622. # (str_store_party_name, s11, ":town_with_contacts"),
  5623.  
  5624. # (str_store_string, s8, "str_gathering_intelligence"),
  5625. # (try_begin),
  5626. # (eq, ":days_left", 1),
  5627. # (str_store_string, s5, "str_expected_back_imminently"),
  5628. # (else_try),
  5629. # (assign, reg3, ":days_left"),
  5630. # (str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
  5631. # (try_end),
  5632. # (else_try),
  5633.  
  5634. # (troop_slot_ge, ":companion", slot_troop_current_mission, npc_mission_peace_request),
  5635. # (neg|troop_slot_ge, ":companion", slot_troop_current_mission, npc_mission_rejoin_when_possible), #SB : replace hard constant 8
  5636.  
  5637. # (troop_get_slot, ":faction", ":companion", slot_troop_mission_object),
  5638. # (str_store_faction_name, s9, ":faction"),
  5639. # (str_store_string, s8, "str_diplomatic_embassy_to_s9"),
  5640. # (try_begin),
  5641. # (eq, ":days_left", 1),
  5642. # (str_store_string, s5, "str_expected_back_imminently"),
  5643. # (else_try),
  5644. # (assign, reg3, ":days_left"),
  5645. # (str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
  5646. # (try_end),
  5647. # (else_try),
  5648. # (eq, ":companion", "$g_player_minister"),
  5649. # (str_store_string, s8, "str_serving_as_minister"),
  5650. # (str_store_party_name, s9, "$g_player_court"),
  5651. # (is_between, "$g_player_court", centers_begin, centers_end),
  5652. # (str_store_string, s5, "str_in_your_court_at_s9"),
  5653. # (else_try),
  5654. # (eq, ":companion", "$g_player_minister"),
  5655. # (str_store_string, s8, "str_serving_as_minister"),
  5656. # (str_store_string, s5, "str_awaiting_the_capture_of_a_fortress_which_can_serve_as_your_court"),
  5657. # (else_try),
  5658. # (main_party_has_troop, ":companion"),
  5659. # (str_store_string, s8, "str_under_arms"),
  5660. # (str_store_string, s5, "str_in_your_party"),
  5661. # (try_end),
  5662.  
  5663. # (str_store_string, s0, "str_s4_s8_s5"),
  5664. ##diplomacy start+
  5665. #Check for explicit "exiled" and "dead" settings
  5666. (else_try),
  5667. (troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_dead),
  5668. (str_store_string, s0, "str_s54_is_deceased"),
  5669. (else_try),
  5670. (troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_exile),
  5671. (str_store_string, s0, "str_s54_has_left_the_realm"),
  5672. ##diplomacy end+
  5673. (else_try),
  5674. (str_store_string, s0, "str_whereabouts_unknown"),
  5675. (try_end),
  5676.  
  5677.  
  5678. (else_try),
  5679. (is_between, ":troop_no", pretenders_begin, pretenders_end),
  5680. (neg|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  5681. (neq, ":troop_no", "$supported_pretender"),
  5682.  
  5683.  
  5684. (troop_get_slot, ":orig_faction", ":troop_no", slot_troop_original_faction),
  5685. (try_begin),
  5686. (faction_slot_eq, ":orig_faction", slot_faction_state, sfs_active),
  5687. (faction_slot_eq, ":orig_faction", slot_faction_has_rebellion_chance, 1),
  5688. (try_begin),
  5689. (eq, ":note_index", 0),
  5690. (str_store_faction_name_link, s56, ":orig_faction"),
  5691. ##diplomacy start+ xxx Removed third argument (was it doing anything?)
  5692. #(str_store_string, s0, "@{s54} is a claimant to the throne of {s56}.", 0),
  5693. (str_store_string, s0, "@{s54} is a claimant to the throne of {s56}."),
  5694. ##diplomacy end+
  5695. (set_trigger_result, 1),
  5696. (try_end),
  5697. (else_try),
  5698. (try_begin),
  5699. (str_clear, s0),
  5700. (this_or_next|eq, ":note_index", 0),
  5701. (this_or_next|eq, ":note_index", 1),
  5702. (eq, ":note_index", 2),
  5703. (set_trigger_result, 1),
  5704. (try_end),
  5705. (try_end),
  5706.  
  5707. (else_try),
  5708. (try_begin),
  5709. (eq, ":note_index", 0),
  5710. (faction_get_slot, ":faction_leader", ":troop_faction", slot_faction_leader),
  5711. (str_store_troop_name_link, s55, ":faction_leader"),
  5712. (str_store_faction_name_link, s56, ":troop_faction"),
  5713. (assign, ":troop_is_player_faction", 0),
  5714. (assign, ":troop_is_faction_leader", 0),
  5715. (try_begin),
  5716. (eq, ":troop_faction", "fac_player_faction"),
  5717. (assign, ":troop_is_player_faction", 1),
  5718. (else_try),
  5719. (eq, ":faction_leader", ":troop_no"),
  5720. (assign, ":troop_is_faction_leader", 1),
  5721. (try_end),
  5722. #SB: add marshal check
  5723. (try_begin),
  5724. (faction_slot_eq, ":troop_faction", slot_faction_marshall, ":troop_no"),
  5725. (assign, ":troop_is_marshal", 1),
  5726. (else_try),
  5727. (assign, ":troop_is_marshal", 0),
  5728. (try_end),
  5729. (assign, ":num_centers", 0),
  5730. (str_store_string, s58, "@nowhere"),
  5731. (try_for_range_backwards, ":cur_center", centers_begin, centers_end),
  5732. (party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
  5733. (try_begin),
  5734. (eq, ":num_centers", 0),
  5735. (str_store_party_name_link, s58, ":cur_center"),
  5736. (else_try),
  5737. (eq, ":num_centers", 1),
  5738. (str_store_party_name_link, s57, ":cur_center"),
  5739. (str_store_string, s58, "@{s57} and {s58}"),
  5740. (else_try),
  5741. (str_store_party_name_link, s57, ":cur_center"),
  5742. (str_store_string, s58, "@{!}{s57}, {s58}"),
  5743. (try_end),
  5744. (val_add, ":num_centers", 1),
  5745. (try_end),
  5746. ##diplomacy start+ use script for gender
  5747. #(troop_get_type, reg3, ":troop_no"),
  5748. (call_script, "script_dplmc_store_troop_is_female_reg", ":troop_no", 3),
  5749. #(assign, reg3, reg0),
  5750. ##diplomacy end+
  5751.  
  5752.  
  5753. (str_clear, s59),
  5754. (try_begin),
  5755. (call_script, "script_troop_get_player_relation", ":troop_no"),
  5756. (assign, ":relation", reg0),
  5757. (store_add, ":normalized_relation", ":relation", 100),
  5758. (val_add, ":normalized_relation", 5),
  5759. (store_div, ":str_offset", ":normalized_relation", 10),
  5760. (val_clamp, ":str_offset", 0, 20),
  5761. (store_add, ":str_id", "str_relation_mnus_100_ns", ":str_offset"),
  5762. (neq, ":str_id", "str_relation_plus_0_ns"),
  5763. (str_store_string, s60, "@{reg3?She:He}"),
  5764. (str_store_string, s59, ":str_id"),
  5765. (str_store_string, s59, "@{!}^{s59}"),
  5766. (try_end),
  5767. #lord recruitment changes begin
  5768. #This sends a bunch of political information to s47.
  5769.  
  5770. #refresh registers
  5771. (assign, reg9, ":num_centers"),
  5772. ##diplomacy start+ use script for gender
  5773. #(troop_get_type, reg3, ":troop_no"),
  5774. (call_script, "script_dplmc_store_troop_is_female_reg", ":troop_no", 3),
  5775. ##diplomacy end+
  5776.  
  5777. #SB : rearrange registers a bit
  5778. (assign, reg4, ":troop_is_faction_leader"),
  5779. (assign, reg5, ":troop_is_marshal"),
  5780. (assign, reg6, ":troop_is_player_faction"),
  5781.  
  5782. #SB : TODO, add rounding based on personal relation/time last met?
  5783. (troop_get_slot, reg15, ":troop_no", slot_troop_renown),
  5784. (troop_get_slot, reg16, ":troop_no", slot_troop_controversy),
  5785. #SB : actually use this wealth in string
  5786. (troop_get_slot, reg17, ":troop_no", slot_troop_wealth), #DEBUGS
  5787. ##diplomacy start+ xxx remove third argument (was it doing anything?)
  5788. #(str_store_string, s0, "str_lord_info_string", 0),
  5789. (str_store_string, s0, "str_lord_info_string"),
  5790. ##diplomacy end+
  5791. #lord recruitment changes end
  5792. (add_troop_note_tableau_mesh, ":troop_no", "tableau_troop_note_mesh"),
  5793. (set_trigger_result, 1),
  5794. (try_end),
  5795. (try_end),
  5796. ]),
  5797.  
  5798. #script_game_get_center_note
  5799. # This script is called from the game engine when the notes of a center is needed.
  5800. # INPUT: arg1 = center_no, arg2 = note_index
  5801. # OUTPUT: s0 = note
  5802. ("game_get_center_note",
  5803. [
  5804. (store_script_param_1, ":center_no"),
  5805. (store_script_param_2, ":note_index"),
  5806.  
  5807. (set_trigger_result, 0),
  5808. (try_begin),
  5809. (eq, ":note_index", 0),
  5810. (party_get_slot, ":lord_troop", ":center_no", slot_town_lord),
  5811. (try_begin),
  5812. (ge, ":lord_troop", 0),
  5813. (store_troop_faction, ":lord_faction", ":lord_troop"),
  5814. (str_store_troop_name_link, s1, ":lord_troop"),
  5815. (try_begin),
  5816. (eq, ":lord_troop", "trp_player"),
  5817. (gt, "$players_kingdom", 0),
  5818. (str_store_faction_name_link, s2, "$players_kingdom"),
  5819. (else_try),
  5820. (str_store_faction_name_link, s2, ":lord_faction"),
  5821. (try_end),
  5822. (str_store_party_name, s50, ":center_no"),
  5823. (try_begin),
  5824. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  5825. (str_store_string, s51, "@The town of {s50}"),
  5826. (else_try),
  5827. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  5828. (party_get_slot, ":bound_center", ":center_no", slot_village_bound_center),
  5829. (str_store_party_name_link, s52, ":bound_center"),
  5830. (str_store_string, s51, "@The village of {s50} near {s52}"),
  5831. (else_try),
  5832. (str_store_string, s51, "@{!}{s50}"),
  5833. (try_end),
  5834. ##diplomacy start+ Show when the city is the home of a lord or is a court
  5835. (assign, ":bound_center", reg0),#Save reg0 to avoid having it randomly change
  5836. (try_begin),
  5837. (eq, "$g_player_court", ":center_no"),
  5838.  
  5839. (store_and, reg1, "$players_kingdom_name_set", rename_center), #SB : specify capitals
  5840. (str_store_string, s2, "@{s51} belongs to {s1} of {s2}, and is {reg1?your capital:where you make your court}.^"),
  5841. (else_try),
  5842. (neq, ":lord_troop", "trp_player"),
  5843. (neg|is_between, ":center_no", villages_begin, villages_end),
  5844. (call_script, "script_lord_get_home_center", ":lord_troop"),
  5845. (eq, reg0, ":center_no"),
  5846. (call_script, "script_dplmc_get_troop_standing_in_faction", ":lord_troop", ":lord_faction"),
  5847. (try_begin),
  5848. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  5849. (call_script, "script_dplmc_store_troop_is_female", ":lord_troop"),
  5850. (str_store_string, s2, "@{s51} belongs to {s1} of {s2}, and is where {reg0?she:he} makes {reg0?her:his} court.^"),
  5851. (else_try),
  5852. (call_script, "script_dplmc_store_troop_is_female", ":lord_troop"),
  5853. (str_store_string, s2, "@{s51} belongs to {s1} of {s2}, and is where {reg0?she:he} makes {reg0?her:his} home.^"),
  5854. (try_end),
  5855. (else_try),#Fall through to normal behavior
  5856. ##diplomacy end+
  5857. (str_store_string, s2, "@{s51} belongs to {s1} of {s2}.^"),
  5858. ##diplomacy start+
  5859. (try_end),
  5860. (assign, reg0, ":bound_center"),#Revert reg0 to avoid having it randomly change
  5861. ##diplomacy end+
  5862. (else_try),
  5863. (str_clear, s2),
  5864. ##diplomacy start+ Don't hide notes for centers with no lords.
  5865. (store_faction_of_party, ":lord_faction", ":center_no"),
  5866. (str_store_string, s1, "str_noone"),
  5867. (try_begin),
  5868. (ge, ":lord_faction", 1),
  5869. (str_store_faction_name_link, s2, ":lord_faction"),
  5870. (else_try),
  5871. (str_store_string, s2, "str_noone"),
  5872. (try_end),
  5873. (str_store_party_name, s50, ":center_no"),
  5874. (try_begin),
  5875. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  5876. (str_store_string, s51, "@The town of {s50}"),
  5877. (else_try),
  5878. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  5879. (party_get_slot, ":bound_center", ":center_no", slot_village_bound_center),
  5880. (str_store_party_name_link, s52, ":bound_center"),
  5881. (str_store_string, s51, "@The village of {s50} near {s52}"),
  5882. (else_try),
  5883. (str_store_string, s51, "@{!}{s50}"),
  5884. (try_end),
  5885. (try_begin),
  5886. (is_between, ":lord_faction", kingdoms_begin, kingdoms_end),
  5887. (faction_slot_eq, ":lord_faction", slot_faction_state, sfs_active),
  5888. (str_store_string, s2, "@{s51} belongs to {s2} but has not yet been granted to a lord.^"),
  5889. (else_try),
  5890. (str_store_string, s2, "@{s51} belongs to {s2}.^"),
  5891. (try_end),
  5892. ##diplomacy end+
  5893. (try_end),
  5894. (try_begin),
  5895. (is_between, ":center_no", villages_begin, villages_end),
  5896. ##diplomacy start+ Show market town if it differs from the bound center
  5897. (party_get_slot, ":market_center", ":center_no", slot_village_market_town),
  5898. (try_begin),
  5899. (is_between, ":market_center", centers_begin, centers_end),
  5900. (neq, ":market_center", ":center_no"),
  5901. (neg|party_slot_eq, ":center_no", slot_village_bound_center, ":market_center"),
  5902. (str_store_party_name_link, s8, ":market_center"),
  5903. (str_store_string, s2, "@{s2}Its market town is {s8}.^"),
  5904. (try_end),
  5905. ##diplomacy end+
  5906. (else_try),
  5907. (assign, ":num_villages", 0),
  5908. (try_for_range_backwards, ":village_no", villages_begin, villages_end),
  5909. (party_slot_eq, ":village_no", slot_village_bound_center, ":center_no"),
  5910. (try_begin),
  5911. (eq, ":num_villages", 0),
  5912. (str_store_party_name_link, s8, ":village_no"),
  5913. (else_try),
  5914. (eq, ":num_villages", 1),
  5915. (str_store_party_name_link, s7, ":village_no"),
  5916. (str_store_string, s8, "@{s7} and {s8}"),
  5917. (else_try),
  5918. (str_store_party_name_link, s7, ":village_no"),
  5919. (str_store_string, s8, "@{!}{s7}, {s8}"),
  5920. (try_end),
  5921. (val_add, ":num_villages", 1),
  5922. (try_end),
  5923. (try_begin),
  5924. (eq, ":num_villages", 0),
  5925. (str_store_string, s2, "@{s2}It has no villages.^"),
  5926. (else_try),
  5927. (store_sub, reg0, ":num_villages", 1),
  5928. (str_store_string, s2, "@{s2}{reg0?Its villages are:Its village is} {s8}.^"),
  5929. (try_end),
  5930. (try_end),
  5931. (call_script, "script_get_prosperity_text_to_s50", ":center_no"),
  5932. #(party_get_slot, reg7, ":center_no", slot_town_prosperity),
  5933. (str_store_string, s0, "@{s2}Its prosperity is: {s50}", 0),
  5934.  
  5935. (set_trigger_result, 1),
  5936. (try_end),
  5937. ]),
  5938.  
  5939. #script_game_get_faction_note
  5940. # This script is called from the game engine when the notes of a faction is needed.
  5941. # INPUT: arg1 = faction_no, arg2 = note_index
  5942. # OUTPUT: s0 = note
  5943. ("game_get_faction_note",
  5944. [
  5945. (store_script_param_1, ":faction_no"),
  5946. (store_script_param_2, ":note_index"),
  5947. (set_trigger_result, 0),
  5948.  
  5949. ## (try_begin),
  5950. ## (eq, 2, 1),
  5951. ## (str_store_faction_name, s14, ":faction_no"),
  5952. ## (assign, reg4, "$temp"),
  5953. ## (display_message, "str_updating_faction_notes_for_s14_temp_=_reg4"),
  5954. ## (try_end),
  5955.  
  5956. (try_begin),
  5957. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  5958. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  5959. #conditions end
  5960. (try_begin),
  5961. (eq, ":note_index", 0),
  5962. (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  5963. (str_store_faction_name, s5, ":faction_no"),
  5964. ##diplomacy start+
  5965. ##OLD:
  5966. #(str_store_troop_name_link, s6, ":faction_leader"),
  5967. ##NEW:
  5968. (try_begin),
  5969. (lt, ":faction_leader", 0),
  5970. #(le, ":faction_leader", 0),
  5971. #(this_or_next|lt, ":faction_leader", 0),
  5972. # (neg|is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  5973. (str_store_string, s6, "str_noone"),
  5974. (else_try),
  5975. (eq, ":faction_leader", "trp_kingdom_heroes_including_player_begin"),
  5976. (assign, ":faction_leader", "trp_player"),
  5977. (str_store_troop_name_link, s6, ":faction_leader"),
  5978. (else_try),
  5979. (str_store_troop_name_link, s6, ":faction_leader"),
  5980. (try_end),
  5981. ##diplomacy end+
  5982. (assign, ":num_centers", 0),
  5983. (str_store_string, s8, "@nowhere"),
  5984. (try_for_range_backwards, ":cur_center", centers_begin, centers_end),
  5985. (store_faction_of_party, ":center_faction", ":cur_center"),
  5986. (eq, ":center_faction", ":faction_no"),
  5987. (try_begin),
  5988. (eq, ":num_centers", 0),
  5989. (str_store_party_name_link, s8, ":cur_center"),
  5990. (else_try),
  5991. (eq, ":num_centers", 1),
  5992. (str_store_party_name_link, s7, ":cur_center"),
  5993. (str_store_string, s8, "@{s7} and {s8}"),
  5994. (else_try),
  5995. (str_store_party_name_link, s7, ":cur_center"),
  5996. (str_store_string, s8, "@{!}{s7}, {s8}"),
  5997. (try_end),
  5998. (val_add, ":num_centers", 1),
  5999. (try_end),
  6000. (assign, ":num_members", 0),
  6001. (str_store_string, s10, "@noone"),
  6002. ##diplomacy start+ support for promoted kingdom ladies
  6003. (try_for_range_backwards, ":loop_var", "trp_kingdom_heroes_including_player_begin", heroes_end),#<- changed active_npcs_end to heroes_end
  6004. ##diplomacy end+
  6005. (assign, ":cur_troop", ":loop_var"),
  6006. (try_begin),
  6007. (eq, ":loop_var", "trp_kingdom_heroes_including_player_begin"),
  6008. (assign, ":cur_troop", "trp_player"),
  6009. (assign, ":troop_faction", "$players_kingdom"),
  6010. (else_try),
  6011. (store_troop_faction, ":troop_faction", ":cur_troop"),
  6012. (try_end),
  6013. (eq, ":troop_faction", ":faction_no"),
  6014. (neq, ":cur_troop", ":faction_leader"),
  6015. (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  6016. (try_begin),
  6017. (eq, ":num_members", 0),
  6018. (str_store_troop_name_link, s10, ":cur_troop"),
  6019. (else_try),
  6020. (eq, ":num_members", 1),
  6021. (str_store_troop_name_link, s9, ":cur_troop"),
  6022. (str_store_string, s10, "@{s9} and {s10}"),
  6023. (else_try),
  6024. (str_store_troop_name_link, s9, ":cur_troop"),
  6025. (str_store_string, s10, "@{!}{s9}, {s10}"),
  6026. (try_end),
  6027. (val_add, ":num_members", 1),
  6028. (try_end),
  6029.  
  6030. #wars
  6031. (str_store_string, s12, "@noone"),
  6032. # (assign, ":num_enemies", 0),
  6033. # (try_for_range_backwards, ":cur_faction", kingdoms_begin, kingdoms_end),
  6034. # (faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
  6035. # (store_relation, ":cur_relation", ":cur_faction", ":faction_no"),
  6036. # (lt, ":cur_relation", 0),
  6037. # (try_begin),
  6038. # (eq, ":num_enemies", 0),
  6039. # (str_store_faction_name_link, s12, ":cur_faction"),
  6040. # (else_try),
  6041. # (eq, ":num_enemies", 1),
  6042. # (str_store_faction_name_link, s11, ":cur_faction"),
  6043. # (str_store_string, s12, "@the {s11} and the {s12}"),
  6044. # (else_try),
  6045. # (str_store_faction_name_link, s11, ":cur_faction"),
  6046. # (str_store_string, s12, "@the {s11}, the {s12}"),
  6047. # (try_end),
  6048. # (val_add, ":num_enemies", 1),
  6049. # (try_end),
  6050.  
  6051.  
  6052. ##SB : add domestic policy as overview
  6053. (str_clear, s21),
  6054. (str_clear, s20),
  6055. (try_begin),
  6056. (eq, ":faction_no", "$players_kingdom"),
  6057. (str_store_string, s20, "@Domestic policy: ^^"),
  6058. (call_script, "script_display_policy_string_to_reg", ":faction_no", 0, 1),
  6059. (try_end),
  6060. (str_store_string, s21, "str_foreign_relations__"),
  6061.  
  6062. #other foreign relations
  6063. (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  6064. (faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
  6065. (neq, ":faction_no", ":cur_faction"),
  6066. (str_store_faction_name_link, s14, ":cur_faction"),
  6067. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":faction_no", ":cur_faction"),
  6068. (assign, ":diplomatic_status", reg0),
  6069. (assign, ":duration_of_status", reg1),
  6070.  
  6071. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":cur_faction", ":faction_no"),
  6072. (assign, ":reverse_diplomatic_status", reg0),
  6073. (try_begin),
  6074. (eq, ":diplomatic_status", -2),
  6075. (str_store_string, s21, "str_s21__the_s5_is_at_war_with_the_s14"),
  6076. (store_add, ":slot_war_damage_inflicted", ":cur_faction", slot_faction_war_damage_inflicted_on_factions_begin),
  6077. (val_sub, ":slot_war_damage_inflicted", kingdoms_begin),
  6078. (faction_get_slot, ":war_damage_inflicted", ":faction_no", ":slot_war_damage_inflicted"),
  6079. (store_mul, ":war_damage_inflicted_x_2", ":war_damage_inflicted", 2),
  6080.  
  6081. (store_add, ":slot_war_damage_suffered", ":faction_no", slot_faction_war_damage_inflicted_on_factions_begin),
  6082. (val_sub, ":slot_war_damage_suffered", kingdoms_begin),
  6083. (faction_get_slot, ":war_damage_suffered", ":cur_faction", ":slot_war_damage_suffered"),
  6084. (store_mul, ":war_damage_suffered_x_2", ":war_damage_suffered", 2),
  6085.  
  6086.  
  6087. (assign, ":war_cause", 0),
  6088. (assign, ":attacker", 0),
  6089. (try_for_range, ":log_entry", 0, "$num_log_entries"),
  6090. (troop_get_slot, ":type", "trp_log_array_entry_type", ":log_entry"),
  6091. (is_between, ":type", logent_faction_declares_war_out_of_personal_enmity, logent_war_declaration_types_end),
  6092. (troop_get_slot, ":actor", "trp_log_array_actor", ":log_entry"),
  6093. (troop_get_slot, ":object", "trp_log_array_faction_object", ":log_entry"),
  6094.  
  6095. (try_begin),
  6096. (eq, ":actor", ":cur_faction"),
  6097. (eq, ":object", ":faction_no"),
  6098. (assign, ":war_cause", ":type"),
  6099. (assign, ":attacker", ":actor"),
  6100. (else_try),
  6101. (eq, ":actor", ":faction_no"),
  6102. (eq, ":object", ":cur_faction"),
  6103. (assign, ":war_cause", ":type"),
  6104. (assign, ":attacker", ":actor"),
  6105. (try_end),
  6106. (try_end),
  6107.  
  6108. #bug fix! backing up s8 to somewhere else
  6109. (str_store_string, s25, s8),
  6110. (try_begin),
  6111. (gt, ":war_cause", 0),
  6112. (str_store_faction_name, s8, ":attacker"),
  6113. (try_begin),
  6114. (eq, ":war_cause", logent_faction_declares_war_out_of_personal_enmity),
  6115. (str_store_string, s21, "str_s21_the_s8_declared_war_out_of_personal_enmity"),
  6116. (else_try),
  6117. (eq, ":war_cause", logent_faction_declares_war_to_respond_to_provocation),
  6118. (str_store_string, s21, "str_s21_the_s8_declared_war_in_response_to_border_provocations"),
  6119. (else_try),
  6120. (eq, ":war_cause", logent_faction_declares_war_to_curb_power),
  6121. (str_store_string, s21, "str_s21_the_s8_declared_war_to_curb_the_other_realms_power"),
  6122. (else_try),
  6123. (eq, ":war_cause", logent_faction_declares_war_to_regain_territory),
  6124. (str_store_string, s21, "str_s21_the_s8_declared_war_to_regain_lost_territory"),
  6125. ##diplomacy begin
  6126. (else_try),
  6127. (eq, ":war_cause", logent_faction_declares_war_to_fulfil_pact),
  6128. (str_store_string, s21, "str_dplmc_s21_the_s8_declared_war_to_fulfil_pact"),
  6129. ##diplomacy end
  6130. (else_try),
  6131. (eq, ":war_cause", logent_player_faction_declares_war),
  6132. (neq, ":attacker", "fac_player_supporters_faction"),
  6133. (str_store_string, s21, "str_s21_the_s8_declared_war_as_part_of_a_bid_to_conquer_all_calradia"),
  6134. (try_end),
  6135. (try_end),
  6136. #bug fix! restoring the back up to s8
  6137. (str_store_string, s8, s25),
  6138.  
  6139. (try_begin),
  6140. (gt, ":war_damage_inflicted", ":war_damage_suffered_x_2"),
  6141. (str_store_string, s21, "str_s21_the_s5_has_had_the_upper_hand_in_the_fighting"),
  6142. (else_try),
  6143. (gt, ":war_damage_suffered", ":war_damage_inflicted_x_2"),
  6144. (str_store_string, s21, "str_s21_the_s5_has_gotten_the_worst_of_the_fighting"),
  6145. (else_try),
  6146. (gt, ":war_damage_inflicted", 100),
  6147. (gt, ":war_damage_inflicted", 100),
  6148. (str_store_string, s21, "str_s21_the_fighting_has_gone_on_for_some_time_and_the_war_may_end_soon_with_a_truce"),
  6149. (else_try),
  6150. (str_store_string, s21, "str_s21_the_fighting_has_begun_relatively_recently_and_the_war_may_continue_for_some_time"),
  6151. (try_end),
  6152. (try_begin),
  6153. (eq, "$cheat_mode", 1),
  6154. (assign, reg4, ":war_damage_inflicted"),
  6155. (assign, reg5, ":war_damage_suffered"),
  6156. (str_store_string, s21, "str_s21_reg4reg5"),
  6157. (try_end),
  6158. (else_try),
  6159. (eq, ":diplomatic_status", 1),
  6160. (str_clear, s18),
  6161. (try_begin),
  6162. (neq, ":reverse_diplomatic_status", 1),
  6163. (str_store_string, s18, "str__however_the_truce_is_no_longer_binding_on_the_s14"),
  6164. (try_end),
  6165. (assign, reg1, ":duration_of_status"),
  6166. ##diplomacy begin
  6167. (try_begin),
  6168. ##nested diplomacy start+ Use named variables for truce lengths
  6169. #(is_between, ":duration_of_status", 1, 21),
  6170. (is_between, ":duration_of_status", dplmc_treaty_truce_days_expire + 1, dplmc_treaty_truce_days_initial + 1),
  6171. ##nested diplomacy end+
  6172. ##diplomacy end
  6173. (str_store_string, s21, "str_s21__the_s5_is_bound_by_truce_not_to_attack_the_s14s18_the_truce_will_expire_in_reg1_days"),
  6174. ##diplomacy begin
  6175. ##nested diplomacy start+ Use named variables for truce lengths
  6176. (else_try),
  6177. #(is_between, ":duration_of_status", 21, 41),
  6178. #(val_sub, reg1, 20),
  6179. (is_between, ":duration_of_status", dplmc_treaty_trade_days_expire + 1, dplmc_treaty_trade_days_initial + 1),
  6180. (val_sub, reg1, dplmc_treaty_trade_days_expire),
  6181. (str_store_string, s21, "str_dplmc_s21__the_s5_is_bound_by_trade_not_to_attack_the_s14s18_it_will_expire_in_reg1_days"),
  6182. (else_try),
  6183. #(is_between, ":duration_of_status", 41, 61),
  6184. #(val_sub, reg1, 40),
  6185. (is_between, ":duration_of_status", dplmc_treaty_defense_days_expire + 1, dplmc_treaty_defense_days_initial + 1),
  6186. (val_sub, reg1, dplmc_treaty_defense_days_expire),
  6187. (str_store_string, s21, "str_dplmc_s21__the_s5_is_bound_by_defensive_not_to_attack_the_s14s18_it_will_expire_in_reg1_days"),
  6188. (else_try),
  6189. #(is_between, ":duration_of_status", 61, 81),
  6190. #(val_sub, reg1, 60),
  6191. (is_between, ":duration_of_status", dplmc_treaty_alliance_days_expire + 1, dplmc_treaty_alliance_days_initial + 1),
  6192. (val_sub, reg1, dplmc_treaty_alliance_days_expire),
  6193. (str_store_string, s21, "str_dplmc_s21__the_s5_is_bound_by_alliance_not_to_attack_the_s14s18_it_will_expire_in_reg1_days"),
  6194. (try_end),
  6195. ##nested diplomacy end+ (Use named variables for truce lengths)
  6196. ##diplomacy end
  6197. (else_try),
  6198. (eq, ":diplomatic_status", -1),
  6199. (str_store_string, s21, "str_s21__the_s5_has_recently_suffered_provocation_by_subjects_of_the_s14_and_there_is_a_risk_of_war"),
  6200. (else_try),
  6201. (eq, ":diplomatic_status", 0),
  6202. (str_store_string, s21, "str_s21__the_s5_has_no_outstanding_issues_with_the_s14"),
  6203. (try_end),
  6204. (try_begin),
  6205. (eq, ":reverse_diplomatic_status", -1),
  6206. (str_store_string, s21, "str_s21_the_s14_was_recently_provoked_by_subjects_of_the_s5_and_there_is_a_risk_of_war_"),
  6207. (try_end),
  6208. (try_begin),
  6209. (eq, "$cheat_mode", 1),
  6210. (call_script, "script_npc_decision_checklist_peace_or_war", ":faction_no", ":cur_faction", -1),
  6211. (str_store_string, s21, "@{!}DEBUG : {s21}.^CHEAT MODE ASSESSMENT: {s14}^"),
  6212. (try_end),
  6213. (try_end),
  6214. (str_store_string, s0, "str_the_s5_is_ruled_by_s6_it_occupies_s8_its_vassals_are_s10__s21", 0),
  6215. (set_trigger_result, 1),
  6216. (try_end),
  6217. (else_try),
  6218. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  6219. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_defeated),
  6220. (try_begin),
  6221. (eq, ":note_index", 0),
  6222. (str_store_faction_name, s5, ":faction_no"),
  6223. (str_store_string, s0, "@{s5} has been defeated!", 0),
  6224. (set_trigger_result, 1),
  6225. (else_try),
  6226. (eq, ":note_index", 1),
  6227. (str_clear, s0),
  6228. (set_trigger_result, 1),
  6229. (try_end),
  6230. (else_try),
  6231. (try_begin),
  6232. (this_or_next|eq, ":note_index", 0),
  6233. (eq, ":note_index", 1),
  6234. (str_clear, s0),
  6235. (set_trigger_result, 1),
  6236. (try_end),
  6237. (try_end),
  6238. ]),
  6239.  
  6240. #script_game_get_quest_note
  6241. # This script is called from the game engine when the notes of a quest is needed.
  6242. # INPUT: arg1 = quest_no, arg2 = note_index
  6243. # OUTPUT: s0 = note
  6244. ("game_get_quest_note",
  6245. [
  6246. ## (store_script_param_1, ":quest_no"),
  6247. ## (store_script_param_2, ":note_index"),
  6248. (set_trigger_result, 0), # set it to 1 if this script is wanted to be used rather than static notes
  6249. #SB: TODO set up progress for pretender quests and other long-winding series
  6250. ]),
  6251.  
  6252. #script_game_get_info_page_note
  6253. # This script is called from the game engine when the notes of a info_page is needed.
  6254. # INPUT: arg1 = info_page_no, arg2 = note_index
  6255. # OUTPUT: s0 = note
  6256. ("game_get_info_page_note",
  6257. [
  6258. ## (store_script_param_1, ":info_page_no"),
  6259. ## (store_script_param_2, ":note_index"),
  6260. (set_trigger_result, 0), # set it to 1 if this script is wanted to be used rather than static notes
  6261. #SB: TODO use actual settings for camera, ai_changes etc
  6262. ]),
  6263.  
  6264. #script_game_get_scene_name
  6265. # This script is called from the game engine when a name for the scene is needed.
  6266. # INPUT: arg1 = scene_no
  6267. # OUTPUT: s0 = name
  6268. ("game_get_scene_name",
  6269. [
  6270. (store_script_param, ":scene_no", 1),
  6271. (try_begin),
  6272. (is_between, ":scene_no", multiplayer_scenes_begin, multiplayer_scenes_end),
  6273. (store_sub, ":string_id", ":scene_no", multiplayer_scenes_begin),
  6274. (val_add, ":string_id", multiplayer_scene_names_begin),
  6275. (str_store_string, s0, ":string_id"),
  6276. (try_end),
  6277. ]),
  6278.  
  6279. #script_game_get_mission_template_name
  6280. # This script is called from the game engine when a name for the mission template is needed.
  6281. # INPUT: arg1 = mission_template_no
  6282. # OUTPUT: s0 = name
  6283. ("game_get_mission_template_name",
  6284. [
  6285. (store_script_param, ":mission_template_no", 1),
  6286. (call_script, "script_multiplayer_get_mission_template_game_type", ":mission_template_no"),
  6287. (assign, ":game_type", reg0),
  6288. (try_begin),
  6289. (is_between, ":game_type", 0, multiplayer_num_game_types),
  6290. (store_add, ":string_id", ":game_type", multiplayer_game_type_names_begin),
  6291. (str_store_string, s0, ":string_id"),
  6292. (try_end),
  6293. ]),
  6294.  
  6295. #script_add_kill_death_counts
  6296. # INPUT: arg1 = killer_agent_no, arg2 = dead_agent_no
  6297. # OUTPUT: none
  6298. ("add_kill_death_counts",
  6299. [
  6300. (store_script_param, ":killer_agent_no", 1),
  6301. (store_script_param, ":dead_agent_no", 2),
  6302.  
  6303. (try_begin),
  6304. (ge, ":killer_agent_no", 0),
  6305. (agent_get_team, ":killer_agent_team", ":killer_agent_no"),
  6306. (else_try),
  6307. (assign, ":killer_agent_team", -1),
  6308. (try_end),
  6309.  
  6310. (try_begin),
  6311. (ge, ":dead_agent_no", 0),
  6312. (agent_get_team, ":dead_agent_team", ":dead_agent_no"),
  6313. (else_try),
  6314. (assign, ":dead_agent_team", -1),
  6315. (try_end),
  6316.  
  6317. #adjusting kill counts of players/bots
  6318. (try_begin),
  6319. (try_begin),
  6320. (ge, ":killer_agent_no", 0),
  6321. (ge, ":dead_agent_no", 0),
  6322. (agent_is_human, ":killer_agent_no"),
  6323. (agent_is_human, ":dead_agent_no"),
  6324. (neq, ":killer_agent_no", ":dead_agent_no"),
  6325.  
  6326. (this_or_next|neq, ":killer_agent_team", ":dead_agent_team"),
  6327. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
  6328. (eq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
  6329.  
  6330. (agent_get_player_id, ":killer_agent_player", ":killer_agent_no"),
  6331. (try_begin),
  6332. (agent_is_non_player, ":killer_agent_no"), #if killer agent is bot then increase bot kill counts of killer agent's team by one.
  6333. (agent_get_team, ":killer_agent_team", ":killer_agent_no"),
  6334. (team_get_bot_kill_count, ":killer_agent_team_bot_kill_count", ":killer_agent_team"),
  6335. (val_add, ":killer_agent_team_bot_kill_count", 1),
  6336. (team_set_bot_kill_count, ":killer_agent_team", ":killer_agent_team_bot_kill_count"),
  6337. (else_try), #if killer agent is not bot then increase kill counts of killer agent's player by one.
  6338. (player_is_active, ":killer_agent_player"),
  6339. (player_get_kill_count, ":killer_agent_player_kill_count", ":killer_agent_player"),
  6340. (val_add, ":killer_agent_player_kill_count", 1),
  6341. (player_set_kill_count, ":killer_agent_player", ":killer_agent_player_kill_count"),
  6342. (try_end),
  6343. (try_end),
  6344.  
  6345. (try_begin),
  6346. (ge, ":dead_agent_no", 0),
  6347. (agent_is_human, ":dead_agent_no"),
  6348. (try_begin),
  6349. (agent_is_non_player, ":dead_agent_no"), #if dead agent is bot then increase bot kill counts of dead agent's team by one.
  6350. (agent_get_team, ":dead_agent_team", ":dead_agent_no"),
  6351. (team_get_bot_death_count, ":dead_agent_team_bot_death_count", ":dead_agent_team"),
  6352. (val_add, ":dead_agent_team_bot_death_count", 1),
  6353. (team_set_bot_death_count, ":dead_agent_team", ":dead_agent_team_bot_death_count"),
  6354. (else_try), #if dead agent is not bot then increase death counts of dead agent's player by one.
  6355. (agent_get_player_id, ":dead_agent_player", ":dead_agent_no"),
  6356. (player_is_active, ":dead_agent_player"),
  6357. (player_get_death_count, ":dead_agent_player_death_count", ":dead_agent_player"),
  6358. (val_add, ":dead_agent_player_death_count", 1),
  6359. (player_set_death_count, ":dead_agent_player", ":dead_agent_player_death_count"),
  6360. (try_end),
  6361.  
  6362. (try_begin),
  6363. (assign, ":continue", 0),
  6364.  
  6365. (try_begin),
  6366. (this_or_next|lt, ":killer_agent_no", 0), #if he killed himself (1a(team change) or 1b(self kill)) then decrease kill counts of killer player by one.
  6367. (eq, ":killer_agent_no", ":dead_agent_no"),
  6368. (assign, ":continue", 1),
  6369. (try_end),
  6370.  
  6371. (try_begin),
  6372. (eq, ":killer_agent_team", ":dead_agent_team"), #if he killed a teammate and game mod is not deathmatch then decrease kill counts of killer player by one.
  6373. (neq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
  6374. (neq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
  6375. (assign, ":continue", 1),
  6376. (try_end),
  6377.  
  6378. (eq, ":continue", 1),
  6379.  
  6380. (try_begin),
  6381. (ge, ":killer_agent_no", 0),
  6382. (assign, ":responsible_agent", ":killer_agent_no"),
  6383. (else_try),
  6384. (assign, ":responsible_agent", ":dead_agent_no"),
  6385. (try_end),
  6386.  
  6387. (try_begin),
  6388. (ge, ":responsible_agent", 0),
  6389. (neg|agent_is_non_player, ":responsible_agent"),
  6390. (agent_get_player_id, ":responsible_player", ":responsible_agent"),
  6391. (ge, ":responsible_player", 0),
  6392. (player_get_kill_count, ":dead_agent_player_kill_count", ":responsible_player"),
  6393. (val_add, ":dead_agent_player_kill_count", -1),
  6394. (player_set_kill_count, ":responsible_player", ":dead_agent_player_kill_count"),
  6395. (try_end),
  6396. (try_end),
  6397. (try_end),
  6398. (try_end),
  6399. ]),
  6400.  
  6401. #script_warn_player_about_auto_team_balance
  6402. # INPUT: none
  6403. # OUTPUT: none
  6404. ("warn_player_about_auto_team_balance",
  6405. [
  6406. (assign, "$g_multiplayer_message_type", multiplayer_message_type_auto_team_balance_next),
  6407. (start_presentation, "prsnt_multiplayer_message_2"),
  6408. ]),
  6409.  
  6410. #script_check_team_balance
  6411. # INPUT: none
  6412. # OUTPUT: none
  6413. ("check_team_balance",
  6414. [
  6415. (try_begin),
  6416. (multiplayer_is_server),
  6417.  
  6418. (assign, ":number_of_players_at_team_1", 0),
  6419. (assign, ":number_of_players_at_team_2", 0),
  6420. (get_max_players, ":num_players"),
  6421. (try_for_range, ":cur_player", 0, ":num_players"),
  6422. (player_is_active, ":cur_player"),
  6423. (player_get_team_no, ":player_team", ":cur_player"),
  6424. (try_begin),
  6425. (eq, ":player_team", 0),
  6426. (val_add, ":number_of_players_at_team_1", 1),
  6427. (else_try),
  6428. (eq, ":player_team", 1),
  6429. (val_add, ":number_of_players_at_team_2", 1),
  6430. (try_end),
  6431. (try_end),
  6432.  
  6433. (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
  6434. (assign, ":number_of_players_will_be_moved", 0),
  6435. (try_begin),
  6436. (try_begin),
  6437. (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
  6438. (le, ":difference_of_number_of_players", ":checked_value"),
  6439. (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", -2),
  6440. (assign, ":team_with_more_players", 1),
  6441. (assign, ":team_with_less_players", 0),
  6442. (else_try),
  6443. (ge, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
  6444. (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", 2),
  6445. (assign, ":team_with_more_players", 0),
  6446. (assign, ":team_with_less_players", 1),
  6447. (try_end),
  6448. (try_end),
  6449. #team balance checks are done
  6450. (try_begin),
  6451. (gt, ":number_of_players_will_be_moved", 0),
  6452. (try_begin),
  6453. (eq, "$g_team_balance_next_round", 1), #if warning is given
  6454.  
  6455. #auto team balance starts
  6456. (try_for_range, ":unused", 0, ":number_of_players_will_be_moved"),
  6457. (assign, ":max_player_join_time", 0),
  6458. (assign, ":latest_joined_player_no", -1),
  6459. (get_max_players, ":num_players"),
  6460. (try_for_range, ":player_no", 0, ":num_players"),
  6461. (player_is_active, ":player_no"),
  6462. (player_get_team_no, ":player_team", ":player_no"),
  6463. (eq, ":player_team", ":team_with_more_players"),
  6464. (player_get_slot, ":player_join_time", ":player_no", slot_player_join_time),
  6465. (try_begin),
  6466. (gt, ":player_join_time", ":max_player_join_time"),
  6467. (assign, ":max_player_join_time", ":player_join_time"),
  6468. (assign, ":latest_joined_player_no", ":player_no"),
  6469. (try_end),
  6470. (try_end),
  6471. (try_begin),
  6472. (ge, ":latest_joined_player_no", 0),
  6473. (try_begin),
  6474. #if player is living add +1 to his kill count because he will get -1 because of team change while living.
  6475. (player_get_agent_id, ":latest_joined_agent_id", ":latest_joined_player_no"),
  6476. (ge, ":latest_joined_agent_id", 0),
  6477. (agent_is_alive, ":latest_joined_agent_id"),
  6478.  
  6479. (player_get_kill_count, ":player_kill_count", ":latest_joined_player_no"), #adding 1 to his kill count, because he will lose 1 undeserved kill count for dying during team change
  6480. (val_add, ":player_kill_count", 1),
  6481. (player_set_kill_count, ":latest_joined_player_no", ":player_kill_count"),
  6482.  
  6483. (player_get_death_count, ":player_death_count", ":latest_joined_player_no"), #subtracting 1 to his death count, because he will gain 1 undeserved death count for dying during team change
  6484. (val_sub, ":player_death_count", 1),
  6485. (player_set_death_count, ":latest_joined_player_no", ":player_death_count"),
  6486.  
  6487. (player_get_score, ":player_score", ":latest_joined_player_no"), #adding 1 to his score count, because he will lose 1 undeserved score for dying during team change
  6488. (val_add, ":player_score", 1),
  6489. (player_set_score, ":latest_joined_player_no", ":player_score"),
  6490.  
  6491. (try_for_range, ":player_no", 1, ":num_players"), #0 is server so starting from 1
  6492. (player_is_active, ":player_no"),
  6493. (multiplayer_send_4_int_to_player, ":player_no", multiplayer_event_set_player_score_kill_death, ":latest_joined_player_no", ":player_score", ":player_kill_count", ":player_death_count"),
  6494. (try_end),
  6495.  
  6496. (player_get_value_of_original_items, ":old_items_value", ":latest_joined_player_no"),
  6497. (player_get_gold, ":player_gold", ":latest_joined_player_no"),
  6498. (val_add, ":player_gold", ":old_items_value"),
  6499. (player_set_gold, ":latest_joined_player_no", ":player_gold", multi_max_gold_that_can_be_stored),
  6500. (end_try),
  6501.  
  6502. (player_set_troop_id, ":latest_joined_player_no", -1),
  6503. (player_set_team_no, ":latest_joined_player_no", ":team_with_less_players"),
  6504. (multiplayer_send_message_to_player, ":latest_joined_player_no", multiplayer_event_force_start_team_selection),
  6505. (try_end),
  6506. (try_end),
  6507.  
  6508. #for only server itself-----------------------------------------------------------------------------------------------
  6509. (call_script, "script_show_multiplayer_message", multiplayer_message_type_auto_team_balance_done, 0), #0 is useless here
  6510. #for only server itself-----------------------------------------------------------------------------------------------
  6511. (get_max_players, ":num_players"),
  6512. (try_for_range, ":player_no", 1, ":num_players"),
  6513. (player_is_active, ":player_no"),
  6514. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_auto_team_balance_done),
  6515. (try_end),
  6516. (assign, "$g_team_balance_next_round", 0),
  6517. #auto team balance done
  6518. (else_try),
  6519. #tutorial message (next round there will be auto team balance)
  6520. (assign, "$g_team_balance_next_round", 1),
  6521.  
  6522. #for only server itself-----------------------------------------------------------------------------------------------
  6523. (call_script, "script_show_multiplayer_message", multiplayer_message_type_auto_team_balance_next, 0), #0 is useless here
  6524. #for only server itself-----------------------------------------------------------------------------------------------
  6525. (get_max_players, ":num_players"),
  6526. (try_for_range, ":player_no", 1, ":num_players"),
  6527. (player_is_active, ":player_no"),
  6528. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_auto_team_balance_next),
  6529. (try_end),
  6530. (try_end),
  6531. (else_try),
  6532. (assign, "$g_team_balance_next_round", 0),
  6533. (try_end),
  6534. (try_end),
  6535. ]),
  6536.  
  6537. #script_check_creating_ladder_dust_effect
  6538. # INPUT: arg1 = instance_id, arg2 = remaining_time
  6539. # OUTPUT: none
  6540. ("check_creating_ladder_dust_effect",
  6541. [
  6542. (store_trigger_param_1, ":instance_id"),
  6543. (store_trigger_param_2, ":remaining_time"),
  6544.  
  6545. (try_begin),
  6546. (lt, ":remaining_time", 15), #less then 0.15 seconds
  6547. (gt, ":remaining_time", 3), #more than 0.03 seconds
  6548.  
  6549. (scene_prop_get_slot, ":smoke_effect_done", ":instance_id", scene_prop_smoke_effect_done),
  6550. (scene_prop_get_slot, ":opened_or_closed", ":instance_id", scene_prop_open_or_close_slot),
  6551.  
  6552. (try_begin),
  6553. (eq, ":smoke_effect_done", 0),
  6554. (eq, ":opened_or_closed", 0),
  6555.  
  6556. (prop_instance_get_position, pos0, ":instance_id"),
  6557.  
  6558. (assign, ":smallest_dist", -1),
  6559. (try_for_range, ":entry_point_no", multi_entry_points_for_usable_items_start, multi_entry_points_for_usable_items_end),
  6560. (entry_point_get_position, pos1, ":entry_point_no"),
  6561. (get_sq_distance_between_positions, ":dist", pos0, pos1),
  6562. (this_or_next|eq, ":smallest_dist", -1),
  6563. (lt, ":dist", ":smallest_dist"),
  6564. (assign, ":smallest_dist", ":dist"),
  6565. (assign, ":nearest_entry_point", ":entry_point_no"),
  6566. (try_end),
  6567.  
  6568. (try_begin),
  6569. (set_fixed_point_multiplier, 100),
  6570.  
  6571. (ge, ":smallest_dist", 0),
  6572. (lt, ":smallest_dist", 22500), #max 15m distance
  6573.  
  6574. (entry_point_get_position, pos1, ":nearest_entry_point"),
  6575. (position_rotate_x, pos1, -90),
  6576.  
  6577. (prop_instance_get_scene_prop_kind, ":scene_prop_kind", ":instance_id"),
  6578. (try_begin),
  6579. (eq, ":scene_prop_kind", "spr_siege_ladder_move_6m"),
  6580. (init_position, pos2),
  6581. (position_set_z, pos2, 300),
  6582. (position_transform_position_to_parent, pos3, pos1, pos2),
  6583. (particle_system_burst, "psys_ladder_dust_6m", pos3, 100),
  6584. (particle_system_burst, "psys_ladder_straw_6m", pos3, 100),
  6585. (else_try),
  6586. (eq, ":scene_prop_kind", "spr_siege_ladder_move_8m"),
  6587. (init_position, pos2),
  6588. (position_set_z, pos2, 400),
  6589. (position_transform_position_to_parent, pos3, pos1, pos2),
  6590. (particle_system_burst, "psys_ladder_dust_8m", pos3, 100),
  6591. (particle_system_burst, "psys_ladder_straw_8m", pos3, 100),
  6592. (else_try),
  6593. (eq, ":scene_prop_kind", "spr_siege_ladder_move_10m"),
  6594. (init_position, pos2),
  6595. (position_set_z, pos2, 500),
  6596. (position_transform_position_to_parent, pos3, pos1, pos2),
  6597. (particle_system_burst, "psys_ladder_dust_10m", pos3, 100),
  6598. (particle_system_burst, "psys_ladder_straw_10m", pos3, 100),
  6599. (else_try),
  6600. (eq, ":scene_prop_kind", "spr_siege_ladder_move_12m"),
  6601. (init_position, pos2),
  6602. (position_set_z, pos2, 600),
  6603. (position_transform_position_to_parent, pos3, pos1, pos2),
  6604. (particle_system_burst, "psys_ladder_dust_12m", pos3, 100),
  6605. (particle_system_burst, "psys_ladder_straw_12m", pos3, 100),
  6606. (else_try),
  6607. (eq, ":scene_prop_kind", "spr_siege_ladder_move_14m"),
  6608. (init_position, pos2),
  6609. (position_set_z, pos2, 700),
  6610. (position_transform_position_to_parent, pos3, pos1, pos2),
  6611. (particle_system_burst, "psys_ladder_dust_14m", pos3, 100),
  6612. (particle_system_burst, "psys_ladder_straw_14m", pos3, 100),
  6613. (try_end),
  6614.  
  6615. (scene_prop_set_slot, ":instance_id", scene_prop_smoke_effect_done, 1),
  6616. (try_end),
  6617. (try_end),
  6618. (try_end),
  6619. ]),
  6620.  
  6621. #script_money_management_after_agent_death
  6622. # INPUT: arg1 = killer_agent_no, arg2 = dead_agent_no
  6623. # OUTPUT: none
  6624. ("money_management_after_agent_death",
  6625. [
  6626. (store_script_param, ":killer_agent_no", 1),
  6627. (store_script_param, ":dead_agent_no", 2),
  6628.  
  6629. (assign, ":dead_agent_player_id", -1),
  6630.  
  6631. (try_begin),
  6632. (multiplayer_is_server),
  6633. (ge, ":killer_agent_no", 0),
  6634. (ge, ":dead_agent_no", 0),
  6635. (agent_is_human, ":dead_agent_no"), #if dead agent is not horse
  6636. (agent_is_human, ":killer_agent_no"), #if killer agent is not horse
  6637. (agent_get_team, ":killer_agent_team", ":killer_agent_no"),
  6638. (agent_get_team, ":dead_agent_team", ":dead_agent_no"),
  6639.  
  6640. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
  6641. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
  6642. (neq, ":killer_agent_team", ":dead_agent_team"), #if these agents are enemies
  6643.  
  6644. (neq, ":dead_agent_no", ":killer_agent_no"), #if agents are different, do not remove it is needed because in deathmatch mod, self killing passes here because of this or next.
  6645.  
  6646. (try_begin),
  6647. (neg|agent_is_non_player, ":dead_agent_no"),
  6648. (agent_get_player_id, ":dead_player_no", ":dead_agent_no"),
  6649. (player_get_slot, ":dead_agent_equipment_value", ":dead_player_no", slot_player_total_equipment_value),
  6650. (else_try),
  6651. (assign, ":dead_agent_equipment_value", 0),
  6652. (try_end),
  6653.  
  6654. (assign, ":dead_agent_team_human_players_count", 0),
  6655. (get_max_players, ":num_players"),
  6656. (try_for_range, ":player_no", 0, ":num_players"),
  6657. (player_is_active, ":player_no"),
  6658. (player_get_team_no, ":player_team", ":player_no"),
  6659. (eq, ":player_team", ":dead_agent_team"),
  6660. (val_add, ":dead_agent_team_human_players_count", 1),
  6661. (try_end),
  6662.  
  6663. (try_for_range, ":player_no", 0, ":num_players"),
  6664. (player_is_active, ":player_no"),
  6665.  
  6666. (try_begin),
  6667. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  6668. (eq, "$g_multiplayer_game_type", multiplayer_game_type_destroy),
  6669. (assign, ":one_spawn_per_round_game_type", 1),
  6670. (else_try),
  6671. (assign, ":one_spawn_per_round_game_type", 0),
  6672. (try_end),
  6673.  
  6674. (this_or_next|eq, ":one_spawn_per_round_game_type", 0),
  6675. (this_or_next|player_slot_eq, ":player_no", slot_player_spawned_this_round, 0),
  6676. (player_slot_eq, ":player_no", slot_player_spawned_this_round, 1),
  6677.  
  6678. (player_get_agent_id, ":agent_no", ":player_no"),
  6679. (try_begin),
  6680. (eq, ":agent_no", ":dead_agent_no"), #if this agent is dead agent then get share from total loot. (20% of total equipment value)
  6681. (player_get_gold, ":player_gold", ":player_no"),
  6682.  
  6683. (assign, ":dead_agent_player_id", ":player_no"),
  6684.  
  6685. #dead agent loot share (32%-48%-64%, norm : 48%)
  6686. (store_mul, ":share_of_dead_agent", ":dead_agent_equipment_value", multi_dead_agent_loot_percentage_share),
  6687. (val_div, ":share_of_dead_agent", 100),
  6688. (val_mul, ":share_of_dead_agent", "$g_multiplayer_battle_earnings_multiplier"),
  6689. (val_div, ":share_of_dead_agent", 100),
  6690. (try_begin),
  6691. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch), #(4/3x) share if current mod is deathmatch
  6692. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_duel), #(4/3x) share if current mod is duel
  6693. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch), #(4/3x) share if current mod is team_deathmatch
  6694. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag), #(4/3x) share if current mod is capture the flag
  6695. (eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters), #(4/3x) share if current mod is headquarters
  6696. (val_mul, ":share_of_dead_agent", 4),
  6697. (val_div, ":share_of_dead_agent", 3),
  6698. (val_add, ":player_gold", ":share_of_dead_agent"),
  6699. (else_try),
  6700. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle), #(2/3x) share if current mod is battle
  6701. (eq, "$g_multiplayer_game_type", multiplayer_game_type_destroy), #(2/3x) share if current mod is fight and destroy
  6702. (val_mul, ":share_of_dead_agent", 2),
  6703. (val_div, ":share_of_dead_agent", 3),
  6704. (val_add, ":player_gold", ":share_of_dead_agent"),
  6705. (else_try),
  6706. (val_add, ":player_gold", ":share_of_dead_agent"), #(3/3x) share if current mod is siege
  6707. (try_end),
  6708. (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
  6709. (else_try),
  6710. (eq, ":agent_no", ":killer_agent_no"), #if this agent is killer agent then get share from total loot. (10% of total equipment value)
  6711. (player_get_gold, ":player_gold", ":player_no"),
  6712.  
  6713. #killer agent standart money (100-150-200, norm : 150)
  6714. (assign, ":killer_agent_standard_money_addition", multi_killer_agent_standard_money_add),
  6715. (val_mul, ":killer_agent_standard_money_addition", "$g_multiplayer_battle_earnings_multiplier"),
  6716. (val_div, ":killer_agent_standard_money_addition", 100),
  6717. (try_begin),
  6718. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch), #(4/3x) share if current mod is deathmatch
  6719. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_duel), #(4/3x) share if current mod is duel
  6720. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch), #(4/3x) share if current mod is team_deathmatch
  6721. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag), #(4/3x) share if current mod is capture the flag
  6722. (eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters), #(4/3x) share if current mod is headquarters
  6723. (val_mul, ":killer_agent_standard_money_addition", 4),
  6724. (val_div, ":killer_agent_standard_money_addition", 3),
  6725. (val_add, ":player_gold", ":killer_agent_standard_money_addition"),
  6726. (else_try),
  6727. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle), #(2/3x) share if current mod is battle
  6728. (eq, "$g_multiplayer_game_type", multiplayer_game_type_destroy), #(2/3x) share if current mod is fight and destroy
  6729. (val_mul, ":killer_agent_standard_money_addition", 2),
  6730. (val_div, ":killer_agent_standard_money_addition", 3),
  6731. (val_add, ":player_gold", ":killer_agent_standard_money_addition"),
  6732. (else_try),
  6733. (val_add, ":player_gold", ":killer_agent_standard_money_addition"), #(3/3x) share if current mod is siege
  6734. (try_end),
  6735.  
  6736. #killer agent loot share (8%-12%-16%, norm : 12%)
  6737. (store_mul, ":share_of_killer_agent", ":dead_agent_equipment_value", multi_killer_agent_loot_percentage_share),
  6738. (val_div, ":share_of_killer_agent", 100),
  6739. (val_mul, ":share_of_killer_agent", "$g_multiplayer_battle_earnings_multiplier"),
  6740. (val_div, ":share_of_killer_agent", 100),
  6741. (try_begin),
  6742. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch), #(4/3x) share if current mod is deathmatch
  6743. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_duel), #(4/3x) share if current mod is duel
  6744. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch), #(4/3x) share if current mod is team_deathmatch
  6745. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag), #(4/3x) share if current mod is capture the flag
  6746. (eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters), #(4/3x) share if current mod is headquarters
  6747. (val_mul, ":share_of_killer_agent", 4),
  6748. (val_div, ":share_of_killer_agent", 3),
  6749. (val_add, ":player_gold", ":share_of_killer_agent"),
  6750. (else_try),
  6751. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle), #(2/3x) share if current mod is battle
  6752. (eq, "$g_multiplayer_game_type", multiplayer_game_type_destroy), #(2/3x) share if current mod is fight and destroy
  6753. (val_mul, ":share_of_killer_agent", 2),
  6754. (val_div, ":share_of_killer_agent", 3),
  6755. (val_add, ":player_gold", ":share_of_killer_agent"),
  6756. (else_try),
  6757. (val_add, ":player_gold", ":share_of_killer_agent"), #(3/3x) share if current mod is siege
  6758. (try_end),
  6759. (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
  6760. (try_end),
  6761. (try_end),
  6762. (try_end),
  6763.  
  6764. #(below lines added new at 25.11.09 after Armagan decided new money system)
  6765. (try_begin),
  6766. (multiplayer_is_server),
  6767. (neq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  6768. (neq, "$g_multiplayer_game_type", multiplayer_game_type_destroy),
  6769.  
  6770. (ge, ":dead_agent_no", 0),
  6771. (agent_is_human, ":dead_agent_no"), #if dead agent is not horse
  6772. (agent_get_player_id, ":dead_agent_player_id", ":dead_agent_no"),
  6773. (ge, ":dead_agent_player_id", 0),
  6774.  
  6775. (player_get_gold, ":player_gold", ":dead_agent_player_id"),
  6776. (try_begin),
  6777. (store_mul, ":minimum_gold", "$g_multiplayer_initial_gold_multiplier", 10),
  6778. (lt, ":player_gold", ":minimum_gold"),
  6779. (assign, ":player_gold", ":minimum_gold"),
  6780. (try_end),
  6781. (player_set_gold, ":dead_agent_player_id", ":player_gold"),
  6782. (try_end),
  6783. #new money system addition end
  6784. ]),
  6785.  
  6786. ("initialize_aristocracy",
  6787. [
  6788. #LORD OCCUPATIONS, BLOOD RELATIONSHIPS, RENOWN AND REPUTATIONS
  6789.  
  6790. #King ages
  6791. (try_for_range, ":cur_troop", kings_begin, kings_end),
  6792. (troop_set_slot, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  6793. (store_random_in_range, ":age", 50, 60),
  6794. (troop_set_slot, ":cur_troop", slot_troop_age, ":age"),
  6795. ##diplomacy start+
  6796. #(eq, ":cur_troop", "trp_kingdom_5_lord"),#<-- There was no reason for this to be in the loop, so moved it out.
  6797. #(troop_set_slot, ":cur_troop", slot_troop_age, 47),
  6798. (try_end),
  6799. (troop_set_slot, "trp_kingdom_5_lord", slot_troop_age, 47),#<-- Moved from above
  6800. ##diplomacy end+
  6801.  
  6802. #The first thing - family structure
  6803. #lords 1 to 8 are patriarchs with one live-at-home son and one daughter. They come from one of six possible ancestors, thus making it likely that there will be two sets of siblings
  6804. #lords 9 to 12 are unmarried landowners with sisters
  6805. #lords 13 to 20 are sons who still live in their fathers' houses
  6806. #For the sake of simplicity, we can assume that all male aristocrats in prior generations either married commoners or procured their brides from the Old Country, thus discounting intermarriage
  6807.  
  6808. (try_for_range, ":cur_troop", kingdom_ladies_begin, kingdom_ladies_end),
  6809. (troop_set_slot, ":cur_troop", slot_troop_occupation, slto_kingdom_lady),
  6810. (try_end),
  6811.  
  6812. (assign, ":cur_lady", "trp_kingdom_1_lady_1"),
  6813.  
  6814. (try_for_range, ":cur_troop", lords_begin, lords_end),
  6815. (troop_set_slot, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  6816.  
  6817. (store_random_in_range, ":father_age_at_birth", 23, 26),
  6818. # (store_random_in_range, ":mother_age_at_birth", 19, 22),
  6819.  
  6820. (try_begin),
  6821. (is_between, ":cur_troop", "trp_knight_1_1", "trp_knight_2_1"),
  6822. (store_sub, ":npc_seed", ":cur_troop", "trp_knight_1_1"),
  6823. (assign, ":ancestor_seed", 1),
  6824.  
  6825. (else_try),
  6826. (is_between, ":cur_troop", "trp_knight_2_1", "trp_knight_3_1"),
  6827. (store_sub, ":npc_seed", ":cur_troop", "trp_knight_2_1"),
  6828. (assign, ":ancestor_seed", 7),
  6829.  
  6830. (else_try),
  6831. (is_between, ":cur_troop", "trp_knight_3_1", "trp_knight_4_1"),
  6832. (store_sub, ":npc_seed", ":cur_troop", "trp_knight_3_1"),
  6833. (assign, ":ancestor_seed", 13),
  6834.  
  6835. (else_try),
  6836. (is_between, ":cur_troop", "trp_knight_4_1", "trp_knight_5_1"),
  6837. (store_sub, ":npc_seed", ":cur_troop", "trp_knight_4_1"),
  6838. (assign, ":ancestor_seed", 19),
  6839.  
  6840. (else_try),
  6841. (is_between, ":cur_troop", "trp_knight_5_1", "trp_knight_6_1"),
  6842. (store_sub, ":npc_seed", ":cur_troop", "trp_knight_5_1"),
  6843. (assign, ":ancestor_seed", 25),
  6844.  
  6845. (else_try),
  6846. (is_between, ":cur_troop", "trp_knight_6_1", "trp_kingdom_1_pretender"),
  6847. (store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
  6848. (assign, ":ancestor_seed", 31),
  6849.  
  6850. (try_end),
  6851.  
  6852.  
  6853. (try_begin),
  6854. (lt, ":npc_seed", 8), #NPC seed is the order in the faction
  6855. ##diplomacy start+ do not overwrite reputation if it was already set explicitly
  6856. (troop_get_slot, ":reputation", ":cur_troop", slot_lord_reputation_type),
  6857. (try_begin),
  6858. (lt, ":reputation", 1),
  6859. #Original behavior:
  6860. (assign, ":reputation", ":npc_seed"),
  6861. (try_end),
  6862. ##diplomacy end+
  6863. (store_random_in_range, ":age", 45, 64),
  6864.  
  6865. ##diplomacy start+ only set father if not already set
  6866. (try_begin),#<- dplmc+ added
  6867. (troop_slot_eq, ":cur_troop", slot_troop_father, -1),#<- dplmc+ added
  6868. (store_random_in_range, ":father", 0, 6), #six possible fathers
  6869. (val_add, ":father", ":ancestor_seed"),
  6870. (troop_set_slot, ":cur_troop", slot_troop_father, ":father"),
  6871. (try_end),#<- dplmc+ added
  6872. ##diplomacy end+
  6873.  
  6874. #wife
  6875. ##diplomacy start+ do not rebind an already-set wife
  6876. (try_begin),
  6877. (troop_slot_eq, ":cur_troop", slot_troop_spouse, -1),
  6878. #There may be a better solution, but to avoid oddities disable automatic spouses if there is a gender mismatch.
  6879. #Mods that add additional races may want to tweak this (for example if some races shouldn't intermarry).
  6880. (call_script, "script_dplmc_store_is_female_troop_1_troop_2", ":cur_troop", ":cur_lady"),
  6881. #Types are stored to reg0 and reg1.
  6882. (neq, reg0, reg1),#lord and lady aren't both female or both non-female
  6883. (val_mul, reg0, reg1),
  6884. (eq, reg0, 0),#at least one of lord or lady is non-female
  6885. ##diplomacy end+
  6886. (troop_set_slot, ":cur_troop", slot_troop_spouse, ":cur_lady"),
  6887. (troop_set_slot, ":cur_lady", slot_troop_spouse, ":cur_troop"),
  6888. (store_random_in_range, ":wife_reputation", 20, 26),
  6889. (try_begin),
  6890. (eq, ":wife_reputation", 20),
  6891. (assign, ":wife_reputation", lrep_conventional),
  6892. (try_end),
  6893. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, ":wife_reputation"),
  6894.  
  6895.  
  6896. (call_script, "script_init_troop_age", ":cur_lady", 49),
  6897. (call_script, "script_add_lady_items", ":cur_lady"),
  6898.  
  6899. (val_add, ":cur_lady", 1),
  6900. ##diplomacy start+
  6901. (try_end),
  6902. ##diplomacy end+
  6903.  
  6904. #daughter
  6905. ##diplomacy start+
  6906. (try_begin),
  6907. ##diplomacy end+
  6908. (troop_set_slot, ":cur_lady", slot_troop_father, ":cur_troop"),
  6909. (store_sub, ":mother", ":cur_lady", 1),
  6910. (call_script, "script_init_troop_age", ":cur_lady", 19),
  6911. ##diplomacy start+
  6912. #fix native bug (daughters are their own mothers)
  6913. # Note: this bug was fixed in native version 1.158
  6914. #(troop_set_slot, ":cur_lady", slot_troop_mother, ":cur_lady"),
  6915. (troop_set_slot, ":cur_lady", slot_troop_mother, ":mother"),
  6916. (try_begin),
  6917. #swap father and mother slots if the lord was female (do nothing if both were female)
  6918. (call_script, "script_dplmc_store_is_female_troop_1_troop_2", ":cur_troop", ":mother"),
  6919. (neq, reg0, 0),#:cur_troop is female
  6920. (eq, reg1, 0),#:mother is not female
  6921. (troop_set_slot, ":cur_lady", slot_troop_mother, ":cur_troop"),
  6922. (troop_set_slot, ":cur_lady", slot_troop_father, ":mother"),
  6923. (try_end),
  6924. ##diplomacy end+
  6925. (store_random_in_range, ":lady_reputation", lrep_conventional, 34), #33% chance of father-derived
  6926. (try_begin),
  6927. (le, ":lady_reputation", 25),
  6928. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, ":lady_reputation"),
  6929. (else_try),
  6930. (eq, ":lady_reputation", 26),
  6931. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_conventional),
  6932. (else_try),
  6933. (eq, ":lady_reputation", 27),
  6934. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_moralist),
  6935. (else_try),
  6936. (assign, ":guardian_reputation", ":reputation"),
  6937. (try_begin),
  6938. (this_or_next|eq, ":guardian_reputation", lrep_martial),
  6939. (eq, ":guardian_reputation", 0),
  6940. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_conventional),
  6941. (else_try),
  6942. (eq, ":guardian_reputation", lrep_quarrelsome),
  6943. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_otherworldly),
  6944. (else_try),
  6945. (eq, ":guardian_reputation", lrep_selfrighteous),
  6946. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_ambitious),
  6947. (else_try),
  6948. (eq, ":guardian_reputation", lrep_cunning),
  6949. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_adventurous),
  6950. (else_try),
  6951. (eq, ":guardian_reputation", lrep_goodnatured),
  6952. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_adventurous),
  6953. (else_try),
  6954. (eq, ":guardian_reputation", lrep_debauched),
  6955. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_ambitious),
  6956. (else_try),
  6957. (eq, ":guardian_reputation", lrep_upstanding),
  6958. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_moralist),
  6959. (try_end),
  6960. (try_end),
  6961.  
  6962. (call_script, "script_add_lady_items", ":cur_lady"),
  6963. (val_add, ":cur_lady", 1),
  6964. ##diplomacy start+
  6965. (try_end),
  6966. ##diplomacy end+
  6967. #high renown
  6968.  
  6969. (else_try), #Older unmarried lords
  6970. (is_between, ":npc_seed", 8, 12),
  6971.  
  6972. (store_random_in_range, ":age", 25, 36),
  6973. ##diplomacy start+ do not overwrite reputation if it was already set explicitly
  6974. (troop_get_slot, ":reputation", ":cur_troop", slot_lord_reputation_type),
  6975. (try_begin),
  6976. (lt, ":reputation", 1),
  6977. #Original behavior:
  6978. (store_random_in_range, ":reputation", 0, 8),
  6979. (try_end),
  6980. ##diplomacy end+
  6981.  
  6982. (store_random_in_range, ":sister_reputation", 20, 26),
  6983. (try_begin),
  6984. (eq, ":sister_reputation", 20),
  6985. (assign, ":sister_reputation", lrep_conventional),
  6986. (try_end),
  6987. (troop_set_slot, ":cur_lady", slot_lord_reputation_type, ":sister_reputation"),
  6988.  
  6989. (troop_set_slot, ":cur_lady", slot_troop_guardian, ":cur_troop"),
  6990. ##diplomacy start+
  6991. #Initialize parents
  6992. (try_begin),
  6993. (troop_slot_eq, ":cur_troop", slot_troop_father, -1),
  6994. (store_mul, ":new_index", ":cur_troop", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),#defined in module_constants.py
  6995. (val_add, ":new_index", DPLMC_VIRTUAL_RELATIVE_FATHER_OFFSET),#defined in module_constants.py
  6996. (troop_set_slot, ":cur_troop", slot_troop_father, ":new_index"),
  6997. (troop_slot_eq, ":cur_lady", slot_troop_father, -1),
  6998. (troop_set_slot, ":cur_lady", slot_troop_father, ":new_index"),
  6999. (try_end),
  7000. (try_begin),
  7001. (troop_slot_eq, ":cur_troop", slot_troop_mother, -1),
  7002. (store_mul, ":new_index", ":cur_troop", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),#defined in module_constants.py
  7003. (val_add, ":new_index", DPLMC_VIRTUAL_RELATIVE_MOTHER_OFFSET),#defined in module_constants.py
  7004. (troop_set_slot, ":cur_troop", slot_troop_mother, ":new_index"),
  7005. (troop_slot_eq, ":cur_lady", slot_troop_mother, -1),
  7006. (troop_set_slot, ":cur_lady", slot_troop_mother, ":new_index"),
  7007. (try_end),
  7008. ##diplomacy end+
  7009.  
  7010. (call_script, "script_init_troop_age", ":cur_lady", 21),
  7011. (call_script, "script_add_lady_items", ":cur_lady"),
  7012.  
  7013. (val_add, ":cur_lady", 1),
  7014.  
  7015. (else_try), #Younger unmarried lords
  7016. #age is father's minus 20 to 25
  7017. (store_sub, ":father", ":cur_troop", 12),
  7018. ##diplomacy start+
  7019. #Some submods don't pay attention to this aspect of the troop list, and
  7020. #so initialization produces absurd or impossible results. Prevent such
  7021. #things from appearing in the game.
  7022. (try_begin),
  7023. #"father" can be father or mother
  7024. #(troop_get_type, ":parent_type", ":father"),
  7025. (try_begin),
  7026. #(eq, ":parent_type", tf_female),
  7027. (call_script, "script_cf_dplmc_troop_is_female", ":father"),
  7028. (assign, ":parent_slot", slot_troop_mother),
  7029. (assign, ":other_parent_slot", slot_troop_father),
  7030. (else_try),
  7031. (assign, ":parent_slot", slot_troop_father),
  7032. (assign, ":other_parent_slot", slot_troop_mother),
  7033. (try_end),
  7034.  
  7035. (troop_slot_eq, ":cur_troop", ":parent_slot", -1),
  7036. (store_add, ":logical_minimum_age", ":father_age_at_birth", 16),
  7037. (troop_slot_ge, ":father", slot_troop_age, ":logical_minimum_age"),
  7038. #Passed test
  7039. (troop_set_slot, ":cur_troop", ":parent_slot", ":father"),
  7040. #Set mother if not already specified
  7041. (try_begin),
  7042. (troop_slot_eq, ":cur_troop", ":other_parent_slot", -1),
  7043. (troop_get_slot, ":mother", ":father", slot_troop_spouse),
  7044. (troop_set_slot, ":cur_troop", ":other_parent_slot", ":mother"),
  7045. (try_end),
  7046.  
  7047. (troop_get_slot, ":father_age", ":father", slot_troop_age),
  7048. (store_sub, ":age", ":father_age", ":father_age_at_birth"),
  7049.  
  7050. (troop_get_slot, ":reputation", ":cur_troop", slot_lord_reputation_type),
  7051. (try_begin),
  7052. #Don't change reputation if it already has been set
  7053. (lt, ":reputation", 1),
  7054. #50% chance of having father's rep
  7055. (store_random_in_range, ":reputation", 0, 16),
  7056.  
  7057. (gt, ":reputation", 7),
  7058. (troop_get_slot, ":reputation", ":father", slot_lord_reputation_type),
  7059. (try_end),
  7060. (else_try),
  7061. #Average age is [45,63] minus [23,25], so [22, 38]
  7062. (store_random_in_range, ":age", 22, 39),
  7063. (troop_get_slot, ":reputation", ":cur_troop", slot_lord_reputation_type),
  7064. #Don't change reputation if it already has been set
  7065. (lt, ":reputation", 1),
  7066. (store_random_in_range, ":reputation", 0, 8),
  7067. (try_end),
  7068. #diplomacy end+
  7069. (try_end),
  7070.  
  7071. (try_begin),
  7072. (eq, ":reputation", 0),
  7073. (assign, ":reputation", 1),
  7074. (try_end),
  7075.  
  7076. (troop_set_slot, ":cur_troop", slot_lord_reputation_type, ":reputation"),
  7077.  
  7078. (call_script, "script_init_troop_age", ":cur_troop", ":age"),
  7079. (try_end),
  7080.  
  7081. (try_begin),
  7082. (eq, "$cheat_mode", 1),
  7083. (assign, reg3, "$cheat_mode"),
  7084. (display_message, "@{!}DEBUG -- Assigned lord reputation and relations"),
  7085.  
  7086. # (display_message, "str_assigned_lord_reputation_and_relations_cheat_mode_reg3"), #This string can be removed
  7087. (try_end),
  7088.  
  7089. (try_for_range, ":cur_troop", pretenders_begin, pretenders_end),
  7090. (troop_set_slot, ":cur_troop", slot_troop_occupation, slto_inactive_pretender),
  7091. (store_random_in_range, ":age", 25, 30),
  7092. (troop_set_slot, ":cur_troop", slot_troop_age, ":age"),
  7093. (eq, ":cur_troop", "trp_kingdom_5_pretender"),
  7094. (troop_set_slot, ":cur_troop", slot_troop_age, 45),
  7095. (try_end),
  7096. ]),
  7097.  
  7098.  
  7099.  
  7100.  
  7101.  
  7102. ("initialize_trade_routes",
  7103. [
  7104. #SARGOTH - 10 routes
  7105. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_2"), #Sargoth - Tihr
  7106. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_4"), #Sargoth - Suno
  7107. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_12"), #Sargoth - Wercheg
  7108. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_11"), #Sargoth - Curaw
  7109. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_8"), #Sargoth - Reyvadin
  7110. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_13"), #Sargoth - Rivacheg
  7111. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_7"), #Sargoth - Uxkhal
  7112. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_9"), #Sargoth - Khudan
  7113. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_6"), #Sargoth - Praven
  7114. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_15"), #Sargoth - Yalen
  7115. (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_16"), #Sargoth - Dhirim
  7116.  
  7117. #TIHR- 8 Routes
  7118. (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_4"), #Tihr- Suno
  7119. (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_6"), #Tihr - Praven
  7120. (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_7"), #Tihr - Uxkhal
  7121. (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_15"), #Tihr - Yalen
  7122. (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_12"), #Tihr - Wercheg
  7123. (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_8"), #Tihr - Reyvadin
  7124. (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_11"), #Tihr - Curaw
  7125. (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_16"), #Thir - Dhirim
  7126.  
  7127. #VELUCA - 8 Routes
  7128. (call_script, "script_set_trade_route_between_centers", "p_town_3", "p_town_7"), #Veluca- Uxkhal
  7129. (call_script, "script_set_trade_route_between_centers", "p_town_3", "p_town_5"), #Veluca - Jelkala
  7130. (call_script, "script_set_trade_route_between_centers", "p_town_3", "p_town_15"), #Veluca - Yalen
  7131. (call_script, "script_set_trade_route_between_centers", "p_town_3", "p_town_16"), #Veluca - Dhirim
  7132. (call_script, "script_set_trade_route_between_centers", "p_town_3", "p_town_14"), #Veluca - Halmar
  7133. (call_script, "script_set_trade_route_between_centers", "p_town_3", "p_town_4"), #Veluca - Suno
  7134. (call_script, "script_set_trade_route_between_centers", "p_town_3", "p_town_19"), #Veluca - Shariz
  7135. (call_script, "script_set_trade_route_between_centers", "p_town_3", "p_town_6"), #Veluca - Praven
  7136.  
  7137. #SUNO - 11 routes
  7138. #Sargoth, Tihr, Veluca
  7139. (call_script, "script_set_trade_route_between_centers", "p_town_4", "p_town_12"), #Suno - Wercheg
  7140. (call_script, "script_set_trade_route_between_centers", "p_town_4", "p_town_8"), #Suno - Reyvadin
  7141. (call_script, "script_set_trade_route_between_centers", "p_town_4", "p_town_11"), #Suno - Curaw
  7142. (call_script, "script_set_trade_route_between_centers", "p_town_4", "p_town_6"), #Suno - Praven
  7143. (call_script, "script_set_trade_route_between_centers", "p_town_4", "p_town_7"), #Suno - Uxkhal
  7144. (call_script, "script_set_trade_route_between_centers", "p_town_4", "p_town_16"), #Suno - Dhirim
  7145. (call_script, "script_set_trade_route_between_centers", "p_town_4", "p_town_5"), #Suno - Jelkala
  7146. (call_script, "script_set_trade_route_between_centers", "p_town_4", "p_town_15"), #Suno - Yalen
  7147.  
  7148. #JELKALA - 6 ROUTES
  7149. #Veluca, Suno
  7150. (call_script, "script_set_trade_route_between_centers", "p_town_5", "p_town_15"), #Jelkala - Yalen
  7151. (call_script, "script_set_trade_route_between_centers", "p_town_5", "p_town_6"), #Jelkala - Praven
  7152. (call_script, "script_set_trade_route_between_centers", "p_town_5", "p_town_7"), #Jelkala - Uxkhal
  7153. (call_script, "script_set_trade_route_between_centers", "p_town_5", "p_town_19"), #Jelkala - Shariz
  7154.  
  7155. #PRAVEN - 7 ROUTES
  7156. #Tihr, Veluca, Suno, Jelkala
  7157. (call_script, "script_set_trade_route_between_centers", "p_town_6", "p_town_7"), #Praven - Uxkhal
  7158. (call_script, "script_set_trade_route_between_centers", "p_town_6", "p_town_15"), #Praven - Yalen
  7159. (call_script, "script_set_trade_route_between_centers", "p_town_6", "p_town_16"), #Praven - Dhirim
  7160.  
  7161. #UXKHAL - 9 Routes
  7162. #Sargoth, Tihr, Suno, Jelkala, Praven
  7163. (call_script, "script_set_trade_route_between_centers", "p_town_7", "p_town_15"), #Yalen
  7164. (call_script, "script_set_trade_route_between_centers", "p_town_7", "p_town_16"), #Dhirim
  7165. (call_script, "script_set_trade_route_between_centers", "p_town_7", "p_town_19"), #Shariz
  7166. (call_script, "script_set_trade_route_between_centers", "p_town_7", "p_town_14"), #Halmar
  7167.  
  7168. #REYVADIN - 9 Routes
  7169. #Suno, Sargoth
  7170. (call_script, "script_set_trade_route_between_centers", "p_town_8", "p_town_9"), #Khudan
  7171. (call_script, "script_set_trade_route_between_centers", "p_town_8", "p_town_11"), #Curaw
  7172. (call_script, "script_set_trade_route_between_centers", "p_town_8", "p_town_12"), #Wercheg
  7173. (call_script, "script_set_trade_route_between_centers", "p_town_8", "p_town_13"), #Rivacheg
  7174. (call_script, "script_set_trade_route_between_centers", "p_town_8", "p_town_16"), #Dhirim
  7175. (call_script, "script_set_trade_route_between_centers", "p_town_8", "p_town_18"), #Narra
  7176. (call_script, "script_set_trade_route_between_centers", "p_town_8", "p_town_17"), #Ichamur
  7177.  
  7178. #KHUDAN - 9 Routes
  7179. #Sargoth, Reyvadin
  7180. (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_11"), #Curaw
  7181. (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_13"), #Rivacheg
  7182. (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_12"), #Wercheg
  7183. (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_17"), #Ichamur
  7184. (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_10"), #Tulga
  7185. (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_16"), #Dhirim
  7186. (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_18"), #Narra
  7187.  
  7188. #TULGA - 7 Routes
  7189. #Khudan
  7190. (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_17"), #Ichamur
  7191. (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_18"), #Narra
  7192. (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_22"), #Bariyye
  7193. (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_21"), #Ahmerrad
  7194. (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_14"), #Halmar
  7195. (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_20"), #Durquba
  7196.  
  7197. #CURAW - 9 Routes
  7198. #Khudan, Reyvadin, Sargoth, Suno
  7199. (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_12"), #Wercheg
  7200. (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_13"), #Rivacheg
  7201. (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_14"), #Halmar
  7202. (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_16"), #Dhirim
  7203. (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_17"), #Ichamur
  7204.  
  7205. #WERCHEG - 7 Routes
  7206. #Sargoth, Suno, Reyvadin, Khudan, Curaw, Tihr
  7207. (call_script, "script_set_trade_route_between_centers", "p_town_12", "p_town_13"), #Rivacheg
  7208.  
  7209. #RIVACHEG - 6 Routes
  7210. #Sargoth, Reyvadin, Khudan, Curaw, Wercheg
  7211. (call_script, "script_set_trade_route_between_centers", "p_town_13", "p_town_17"), #Ichamur
  7212.  
  7213. #HALMAR- 11 Routes
  7214. #Veluca, Uxkhal, Tulga, Curaw
  7215. (call_script, "script_set_trade_route_between_centers", "p_town_14", "p_town_17"), #Ichamur
  7216. (call_script, "script_set_trade_route_between_centers", "p_town_14", "p_town_18"), #Narra
  7217. (call_script, "script_set_trade_route_between_centers", "p_town_14", "p_town_21"), #Ahmerrad
  7218. (call_script, "script_set_trade_route_between_centers", "p_town_14", "p_town_22"), #Bariyye
  7219. (call_script, "script_set_trade_route_between_centers", "p_town_14", "p_town_20"), #Durquba
  7220. (call_script, "script_set_trade_route_between_centers", "p_town_14", "p_town_19"), #Shariz
  7221. (call_script, "script_set_trade_route_between_centers", "p_town_14", "p_town_16"), #Dhirim
  7222.  
  7223. #YALEN - 7 Routes
  7224. #Sargoth, Tihr, Veluca, Suno, Jelkala, Praven, Uxkhal
  7225.  
  7226. #DHIRIM - 13 Routes
  7227. #Sargoth, Thir, Veluca, Suno, Praven, Uxkhal, Reyvadin, Khudan, Curaw, Halmar
  7228. (call_script, "script_set_trade_route_between_centers", "p_town_16", "p_town_18"), #Narra
  7229. (call_script, "script_set_trade_route_between_centers", "p_town_16", "p_town_20"), #Durquba
  7230. (call_script, "script_set_trade_route_between_centers", "p_town_16", "p_town_19"), #Shariz
  7231.  
  7232. #ICHAMUR - 7 Routes
  7233. #Reyvadin, Khudan, Tulga, Curaw, Rivacheg, Halmar
  7234. (call_script, "script_set_trade_route_between_centers", "p_town_17", "p_town_18"), #Narra
  7235.  
  7236. #NARRA - 9 Routes
  7237. #Reyvadin, Khudan, Tulga, Halmar, Dhirim, Ichamur
  7238. (call_script, "script_set_trade_route_between_centers", "p_town_18", "p_town_20"), #Durquba
  7239. (call_script, "script_set_trade_route_between_centers", "p_town_18", "p_town_21"), #Ahmerrad
  7240. (call_script, "script_set_trade_route_between_centers", "p_town_18", "p_town_22"), #Bariyye
  7241.  
  7242. #SHARIZ - 8 Routes
  7243. #Veluca, Jelkala, Uxkhal, Halmar, Dhirim
  7244. (call_script, "script_set_trade_route_between_centers", "p_town_19", "p_town_20"), #Durquba
  7245. (call_script, "script_set_trade_route_between_centers", "p_town_19", "p_town_21"), #Ahmerrad
  7246. (call_script, "script_set_trade_route_between_centers", "p_town_19", "p_town_22"), #Bariyye
  7247.  
  7248. #DURQUBA - 7 Routes
  7249. #Tulga, Halmar, Dhirim, Narra, Shariz
  7250. (call_script, "script_set_trade_route_between_centers", "p_town_20", "p_town_21"), #Ahmerrad
  7251. (call_script, "script_set_trade_route_between_centers", "p_town_20", "p_town_22"), #Bariyye
  7252.  
  7253. #AHMERRAD - 6 Routes
  7254. #Tulga, Halmar, Narra, Shariz, Durquba
  7255. (call_script, "script_set_trade_route_between_centers", "p_town_21", "p_town_22"), #Bariyye
  7256.  
  7257. #BARIYYE - 6 Routes
  7258. #Tulga, Halmar, Narra, Shariz, Durquba, Ahmerrad
  7259. ]),
  7260.  
  7261.  
  7262.  
  7263. ("initialize_faction_troop_types",
  7264. [
  7265.  
  7266. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  7267. (faction_get_slot, ":culture", ":faction_no", slot_faction_culture),
  7268.  
  7269. (faction_get_slot, ":troop", ":culture", slot_faction_tier_1_troop),
  7270. (faction_set_slot, ":faction_no", slot_faction_tier_1_troop, ":troop"),
  7271. (faction_get_slot, ":troop", ":culture", slot_faction_tier_2_troop),
  7272. (faction_set_slot, ":faction_no", slot_faction_tier_2_troop, ":troop"),
  7273. (faction_get_slot, ":troop", ":culture", slot_faction_tier_3_troop),
  7274. (faction_set_slot, ":faction_no", slot_faction_tier_3_troop, ":troop"),
  7275. (faction_get_slot, ":troop", ":culture", slot_faction_tier_4_troop),
  7276. (faction_set_slot, ":faction_no", slot_faction_tier_4_troop, ":troop"),
  7277. (faction_get_slot, ":troop", ":culture", slot_faction_tier_5_troop),
  7278. (faction_set_slot, ":faction_no", slot_faction_tier_5_troop, ":troop"),
  7279.  
  7280. (try_begin),
  7281. (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_1"),
  7282.  
  7283. (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_swadian_deserter"),
  7284. (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_swadian_sergeant"),
  7285. (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_swadian_messenger"),
  7286. (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_swadian_prison_guard"),
  7287. (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_swadian_castle_guard"),
  7288. (faction_set_slot, ":faction_no", slot_faction_reinforcements_a, "pt_kingdom_1_reinforcements_a"),
  7289. (faction_set_slot, ":faction_no", slot_faction_reinforcements_b, "pt_kingdom_1_reinforcements_b"),
  7290. (faction_set_slot, ":faction_no", slot_faction_reinforcements_c, "pt_kingdom_1_reinforcements_c"),
  7291. (else_try),
  7292. (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_2"),
  7293.  
  7294. (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_vaegir_deserter"),
  7295. (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_vaegir_guard"),
  7296. (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_vaegir_messenger"),
  7297. (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_vaegir_prison_guard"),
  7298. (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_vaegir_castle_guard"),
  7299. (faction_set_slot, ":faction_no", slot_faction_reinforcements_a, "pt_kingdom_2_reinforcements_a"),
  7300. (faction_set_slot, ":faction_no", slot_faction_reinforcements_b, "pt_kingdom_2_reinforcements_b"),
  7301. (faction_set_slot, ":faction_no", slot_faction_reinforcements_c, "pt_kingdom_2_reinforcements_c"),
  7302. (else_try),
  7303. (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_3"),
  7304.  
  7305. (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_khergit_deserter"),
  7306. (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_khergit_horseman"),
  7307. (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_khergit_messenger"),
  7308. (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_khergit_prison_guard"),
  7309. (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_khergit_castle_guard"),
  7310. (faction_set_slot, ":faction_no", slot_faction_reinforcements_a, "pt_kingdom_3_reinforcements_a"),
  7311. (faction_set_slot, ":faction_no", slot_faction_reinforcements_b, "pt_kingdom_3_reinforcements_b"),
  7312. (faction_set_slot, ":faction_no", slot_faction_reinforcements_c, "pt_kingdom_3_reinforcements_c"),
  7313. (else_try),
  7314. (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_4"),
  7315.  
  7316. (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_nord_deserter"),
  7317. (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_nord_warrior"),
  7318. (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_nord_messenger"),
  7319. (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_nord_prison_guard"),
  7320. (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_nord_castle_guard"),
  7321. (faction_set_slot, ":faction_no", slot_faction_reinforcements_a, "pt_kingdom_4_reinforcements_a"),
  7322. (faction_set_slot, ":faction_no", slot_faction_reinforcements_b, "pt_kingdom_4_reinforcements_b"),
  7323. (faction_set_slot, ":faction_no", slot_faction_reinforcements_c, "pt_kingdom_4_reinforcements_c"),
  7324. (else_try),
  7325. (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_5"),
  7326.  
  7327. (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_rhodok_deserter"),
  7328. (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_rhodok_veteran_spearman"),
  7329. (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_rhodok_messenger"),
  7330. (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_rhodok_prison_guard"),
  7331. (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_rhodok_castle_guard"),
  7332. (faction_set_slot, ":faction_no", slot_faction_reinforcements_a, "pt_kingdom_5_reinforcements_a"),
  7333. (faction_set_slot, ":faction_no", slot_faction_reinforcements_b, "pt_kingdom_5_reinforcements_b"),
  7334. (faction_set_slot, ":faction_no", slot_faction_reinforcements_c, "pt_kingdom_5_reinforcements_c"),
  7335. (else_try),
  7336. (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_6"),
  7337.  
  7338. (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_sarranid_deserter"),
  7339. (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_sarranid_castle_guard"),
  7340. (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_sarranid_messenger"),
  7341. (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_sarranid_prison_guard"),
  7342. (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_sarranid_castle_guard"),
  7343. (faction_set_slot, ":faction_no", slot_faction_reinforcements_a, "pt_kingdom_6_reinforcements_a"),
  7344. (faction_set_slot, ":faction_no", slot_faction_reinforcements_b, "pt_kingdom_6_reinforcements_b"),
  7345. (faction_set_slot, ":faction_no", slot_faction_reinforcements_c, "pt_kingdom_6_reinforcements_c"),
  7346. (try_end),
  7347. (try_end),
  7348. ]),
  7349.  
  7350. ("initialize_item_info",
  7351. [
  7352. # Setting food bonuses - these have been changed to incentivize using historical rations. Bread is the most cost-efficient
  7353. #Staples
  7354. (item_set_slot, "itm_bread", slot_item_food_bonus, 8), #brought up from 4
  7355. (item_set_slot, "itm_grain", slot_item_food_bonus, 2), #new - can be boiled as porridge
  7356.  
  7357. #Fat sources - preserved
  7358. (item_set_slot, "itm_smoked_fish", slot_item_food_bonus, 4),
  7359. (item_set_slot, "itm_dried_meat", slot_item_food_bonus, 5),
  7360. (item_set_slot, "itm_cheese", slot_item_food_bonus, 5),
  7361. (item_set_slot, "itm_sausages", slot_item_food_bonus, 5),
  7362. (item_set_slot, "itm_butter", slot_item_food_bonus, 4), #brought down from 8
  7363.  
  7364. #Fat sources - perishable
  7365. (item_set_slot, "itm_chicken", slot_item_food_bonus, 8), #brought up from 7
  7366. (item_set_slot, "itm_cattle_meat", slot_item_food_bonus, 7), #brought down from 7
  7367. (item_set_slot, "itm_pork", slot_item_food_bonus, 6), #brought down from 6
  7368.  
  7369. #Produce
  7370. (item_set_slot, "itm_raw_olives", slot_item_food_bonus, 1),
  7371. (item_set_slot, "itm_cabbages", slot_item_food_bonus, 2),
  7372. (item_set_slot, "itm_raw_grapes", slot_item_food_bonus, 3),
  7373. (item_set_slot, "itm_apples", slot_item_food_bonus, 4), #brought down from 5
  7374.  
  7375. #Sweet items
  7376. (item_set_slot, "itm_raw_date_fruit", slot_item_food_bonus, 4), #brought down from 8
  7377. (item_set_slot, "itm_honey", slot_item_food_bonus, 6), #brought down from 12
  7378.  
  7379. (item_set_slot, "itm_wine", slot_item_food_bonus, 5),
  7380. (item_set_slot, "itm_ale", slot_item_food_bonus, 4),
  7381.  
  7382. #Item economic settings
  7383. (item_set_slot, "itm_grain", slot_item_urban_demand, 20),
  7384. (item_set_slot, "itm_grain", slot_item_rural_demand, 20),
  7385. (item_set_slot, "itm_grain", slot_item_desert_demand, 20),
  7386. (item_set_slot, "itm_grain", slot_item_production_slot, slot_center_acres_grain),
  7387. (item_set_slot, "itm_grain", slot_item_production_string, "str_acres_grain"),
  7388. (item_set_slot, "itm_grain", slot_item_base_price, 30),
  7389.  
  7390. (item_set_slot, "itm_bread", slot_item_urban_demand, 30),
  7391. (item_set_slot, "itm_bread", slot_item_rural_demand, 30),
  7392. (item_set_slot, "itm_bread", slot_item_desert_demand, 30),
  7393. (item_set_slot, "itm_bread", slot_item_production_slot, slot_center_mills),
  7394. (item_set_slot, "itm_bread", slot_item_production_string, "str_mills"),
  7395. (item_set_slot, "itm_bread", slot_item_primary_raw_material, "itm_grain"),
  7396. (item_set_slot, "itm_bread", slot_item_input_number, 6),
  7397. (item_set_slot, "itm_bread", slot_item_output_per_run, 6),
  7398. (item_set_slot, "itm_bread", slot_item_overhead_per_run, 30),
  7399. (item_set_slot, "itm_bread", slot_item_base_price, 50),
  7400. (item_set_slot, "itm_bread", slot_item_enterprise_building_cost, 1500),
  7401.  
  7402. (item_set_slot, "itm_ale", slot_item_urban_demand, 10),
  7403. (item_set_slot, "itm_ale", slot_item_rural_demand, 15),
  7404. (item_set_slot, "itm_ale", slot_item_desert_demand, 0),
  7405. (item_set_slot, "itm_ale", slot_item_production_slot, slot_center_breweries),
  7406. (item_set_slot, "itm_ale", slot_item_production_string, "str_breweries"),
  7407. (item_set_slot, "itm_ale", slot_item_base_price, 120),
  7408. (item_set_slot, "itm_ale", slot_item_primary_raw_material, "itm_grain"),
  7409. (item_set_slot, "itm_ale", slot_item_input_number, 1),
  7410. (item_set_slot, "itm_ale", slot_item_output_per_run, 2),
  7411. (item_set_slot, "itm_ale", slot_item_overhead_per_run, 50),
  7412. (item_set_slot, "itm_ale", slot_item_base_price, 120),
  7413. (item_set_slot, "itm_ale", slot_item_enterprise_building_cost, 2500),
  7414.  
  7415. (item_set_slot, "itm_wine", slot_item_urban_demand, 15),
  7416. (item_set_slot, "itm_wine", slot_item_rural_demand, 10),
  7417. (item_set_slot, "itm_wine", slot_item_desert_demand, 25),
  7418. (item_set_slot, "itm_wine", slot_item_production_slot, slot_center_wine_presses),
  7419. (item_set_slot, "itm_wine", slot_item_production_string, "str_presses"),
  7420. (item_set_slot, "itm_wine", slot_item_primary_raw_material, "itm_raw_grapes"),
  7421. (item_set_slot, "itm_wine", slot_item_input_number, 4),
  7422. (item_set_slot, "itm_wine", slot_item_output_per_run, 2),
  7423. (item_set_slot, "itm_wine", slot_item_overhead_per_run, 60),
  7424. (item_set_slot, "itm_wine", slot_item_base_price, 220),
  7425. (item_set_slot, "itm_wine", slot_item_enterprise_building_cost, 5000),
  7426.  
  7427. (item_set_slot, "itm_raw_grapes", slot_item_urban_demand, 0),
  7428. (item_set_slot, "itm_raw_grapes", slot_item_rural_demand, 0),
  7429. (item_set_slot, "itm_raw_grapes", slot_item_desert_demand, 0),
  7430. (item_set_slot, "itm_raw_grapes", slot_item_production_slot, slot_center_acres_vineyard),
  7431. (item_set_slot, "itm_raw_grapes", slot_item_production_string, "str_acres_orchard"),
  7432. (item_set_slot, "itm_raw_grapes", slot_item_is_raw_material_only_for, "itm_wine"),
  7433. (item_set_slot, "itm_raw_grapes", slot_item_base_price, 75),
  7434.  
  7435. (item_set_slot, "itm_apples", slot_item_urban_demand, 4),
  7436. (item_set_slot, "itm_apples", slot_item_rural_demand, 4),
  7437. (item_set_slot, "itm_apples", slot_item_desert_demand, 0),
  7438. (item_set_slot, "itm_apples", slot_item_production_slot, slot_center_acres_vineyard),
  7439. (item_set_slot, "itm_apples", slot_item_production_string, "str_acres_orchard"),
  7440. (item_set_slot, "itm_apples", slot_item_base_price, 44),
  7441.  
  7442. (item_set_slot, "itm_smoked_fish", slot_item_urban_demand, 16),
  7443. (item_set_slot, "itm_smoked_fish", slot_item_rural_demand, 16),
  7444. (item_set_slot, "itm_smoked_fish", slot_item_desert_demand, 16),
  7445. (item_set_slot, "itm_smoked_fish", slot_item_production_slot, slot_center_fishing_fleet),
  7446. (item_set_slot, "itm_smoked_fish", slot_item_production_string, "str_boats"),
  7447.  
  7448. (item_set_slot, "itm_salt", slot_item_urban_demand, 5),
  7449. (item_set_slot, "itm_salt", slot_item_rural_demand, 3),
  7450. (item_set_slot, "itm_salt", slot_item_desert_demand, -1),
  7451. (item_set_slot, "itm_salt", slot_item_production_slot, slot_center_salt_pans),
  7452. (item_set_slot, "itm_salt", slot_item_production_string, "str_pans"),
  7453.  
  7454. (item_set_slot, "itm_dried_meat", slot_item_urban_demand, 20),
  7455. (item_set_slot, "itm_dried_meat", slot_item_rural_demand, 5),
  7456. (item_set_slot, "itm_dried_meat", slot_item_desert_demand, -1),
  7457. (item_set_slot, "itm_dried_meat", slot_item_production_slot, slot_center_head_cattle),
  7458. (item_set_slot, "itm_dried_meat", slot_item_production_string, "str_head_cattle"),
  7459.  
  7460. (item_set_slot, "itm_cattle_meat", slot_item_urban_demand, 12),
  7461. (item_set_slot, "itm_cattle_meat", slot_item_rural_demand, 3),
  7462. (item_set_slot, "itm_cattle_meat", slot_item_desert_demand, -1),
  7463. (item_set_slot, "itm_cattle_meat", slot_item_production_slot, slot_center_head_cattle),
  7464. (item_set_slot, "itm_cattle_meat", slot_item_production_string, "str_head_cattle"),
  7465.  
  7466. (item_set_slot, "itm_cheese", slot_item_urban_demand, 10),
  7467. (item_set_slot, "itm_cheese", slot_item_rural_demand, 10),
  7468. (item_set_slot, "itm_cheese", slot_item_desert_demand, 10),
  7469. (item_set_slot, "itm_cheese", slot_item_production_slot, slot_center_head_cattle),
  7470. (item_set_slot, "itm_cheese", slot_item_production_string, "str_head_cattle"),
  7471.  
  7472. (item_set_slot, "itm_butter", slot_item_urban_demand, 2),
  7473. (item_set_slot, "itm_butter", slot_item_rural_demand, 2),
  7474. (item_set_slot, "itm_butter", slot_item_desert_demand, 2),
  7475. (item_set_slot, "itm_butter", slot_item_production_slot, slot_center_head_cattle),
  7476. (item_set_slot, "itm_butter", slot_item_production_string, "str_head_cattle"),
  7477.  
  7478. (item_set_slot, "itm_leatherwork", slot_item_urban_demand, 10),
  7479. (item_set_slot, "itm_leatherwork", slot_item_rural_demand, 10),
  7480. (item_set_slot, "itm_leatherwork", slot_item_desert_demand, 10),
  7481. (item_set_slot, "itm_leatherwork", slot_item_production_slot, slot_center_tanneries),
  7482. (item_set_slot, "itm_leatherwork", slot_item_production_string, "str_tanneries"),
  7483. (item_set_slot, "itm_leatherwork", slot_item_primary_raw_material, "itm_raw_leather"),
  7484. (item_set_slot, "itm_leatherwork", slot_item_input_number, 3),
  7485. (item_set_slot, "itm_leatherwork", slot_item_output_per_run, 3),
  7486. (item_set_slot, "itm_leatherwork", slot_item_overhead_per_run, 50),
  7487. (item_set_slot, "itm_leatherwork", slot_item_base_price, 220),
  7488. (item_set_slot, "itm_leatherwork", slot_item_enterprise_building_cost, 8000),
  7489.  
  7490. (item_set_slot, "itm_raw_leather", slot_item_urban_demand, 0),
  7491. (item_set_slot, "itm_raw_leather", slot_item_rural_demand, 0),
  7492. (item_set_slot, "itm_raw_leather", slot_item_desert_demand, 0),
  7493. (item_set_slot, "itm_raw_leather", slot_item_production_slot, slot_center_head_cattle),
  7494. (item_set_slot, "itm_raw_leather", slot_item_production_string, "str_head_cattle"),
  7495. (item_set_slot, "itm_raw_leather", slot_item_is_raw_material_only_for, "itm_leatherwork"),
  7496. (item_set_slot, "itm_raw_leather", slot_item_base_price, 120),
  7497.  
  7498. (item_set_slot, "itm_sausages", slot_item_urban_demand, 12),
  7499. (item_set_slot, "itm_sausages", slot_item_rural_demand, 3),
  7500. (item_set_slot, "itm_sausages", slot_item_desert_demand, -1),
  7501. (item_set_slot, "itm_sausages", slot_item_production_slot, slot_center_head_sheep),
  7502. (item_set_slot, "itm_sausages", slot_item_production_string, "str_head_sheep"),
  7503.  
  7504. (item_set_slot, "itm_wool", slot_item_urban_demand, 0),
  7505. (item_set_slot, "itm_wool", slot_item_rural_demand, 0),
  7506. (item_set_slot, "itm_wool", slot_item_desert_demand, 0),
  7507. (item_set_slot, "itm_wool", slot_item_production_slot, slot_center_head_sheep),
  7508. (item_set_slot, "itm_wool", slot_item_production_string, "str_head_sheep"),
  7509. (item_set_slot, "itm_wool", slot_item_is_raw_material_only_for, "itm_wool_cloth"),
  7510. (item_set_slot, "itm_wool", slot_item_base_price,130),
  7511.  
  7512. (item_set_slot, "itm_wool_cloth", slot_item_urban_demand, 15),
  7513. (item_set_slot, "itm_wool_cloth", slot_item_rural_demand, 20),
  7514. (item_set_slot, "itm_wool_cloth", slot_item_desert_demand, 5),
  7515. (item_set_slot, "itm_wool_cloth", slot_item_production_slot, slot_center_wool_looms),
  7516. (item_set_slot, "itm_wool_cloth", slot_item_production_string, "str_looms"),
  7517. (item_set_slot, "itm_wool_cloth", slot_item_primary_raw_material, "itm_wool"),
  7518. (item_set_slot, "itm_wool_cloth", slot_item_input_number, 2),
  7519. (item_set_slot, "itm_wool_cloth", slot_item_output_per_run, 2),
  7520. (item_set_slot, "itm_wool_cloth", slot_item_overhead_per_run, 120),
  7521. (item_set_slot, "itm_wool_cloth", slot_item_base_price, 250),
  7522. (item_set_slot, "itm_wool_cloth", slot_item_enterprise_building_cost, 6000),
  7523.  
  7524. (item_set_slot, "itm_raw_flax", slot_item_urban_demand, 0),
  7525. (item_set_slot, "itm_raw_flax", slot_item_rural_demand, 0),
  7526. (item_set_slot, "itm_raw_flax", slot_item_desert_demand, 0),
  7527. (item_set_slot, "itm_raw_flax", slot_item_production_slot, slot_center_acres_flax),
  7528. (item_set_slot, "itm_raw_flax", slot_item_production_string, "str_acres_flax"),
  7529. (item_set_slot, "itm_raw_flax", slot_item_is_raw_material_only_for, "itm_linen"),
  7530. (item_set_slot, "itm_raw_flax", slot_item_base_price, 150),
  7531.  
  7532. (item_set_slot, "itm_linen", slot_item_urban_demand, 7),
  7533. (item_set_slot, "itm_linen", slot_item_rural_demand, 3),
  7534. (item_set_slot, "itm_linen", slot_item_desert_demand, 15),
  7535. (item_set_slot, "itm_linen", slot_item_production_slot, slot_center_linen_looms),
  7536. (item_set_slot, "itm_linen", slot_item_production_string, "str_looms"),
  7537. (item_set_slot, "itm_linen", slot_item_primary_raw_material, "itm_raw_flax"),
  7538. (item_set_slot, "itm_linen", slot_item_input_number, 2),
  7539. (item_set_slot, "itm_linen", slot_item_output_per_run, 2),
  7540. (item_set_slot, "itm_linen", slot_item_overhead_per_run, 120),
  7541. (item_set_slot, "itm_linen", slot_item_base_price, 250),
  7542. (item_set_slot, "itm_linen", slot_item_enterprise_building_cost, 6000),
  7543.  
  7544. (item_set_slot, "itm_iron", slot_item_urban_demand, 0),
  7545. (item_set_slot, "itm_iron", slot_item_rural_demand, 0),
  7546. (item_set_slot, "itm_iron", slot_item_desert_demand, 0),
  7547. (item_set_slot, "itm_iron", slot_item_production_slot, slot_center_iron_deposits),
  7548. (item_set_slot, "itm_iron", slot_item_production_string, "str_deposits"),
  7549. (item_set_slot, "itm_iron", slot_item_is_raw_material_only_for, "itm_tools"),
  7550. (item_set_slot, "itm_iron", slot_item_base_price, 264),
  7551.  
  7552. (item_set_slot, "itm_tools", slot_item_urban_demand, 7),
  7553. (item_set_slot, "itm_tools", slot_item_rural_demand, 7),
  7554. (item_set_slot, "itm_tools", slot_item_desert_demand, 7),
  7555. (item_set_slot, "itm_tools", slot_item_production_slot, slot_center_smithies),
  7556. (item_set_slot, "itm_tools", slot_item_production_string, "str_smithies"),
  7557. (item_set_slot, "itm_tools", slot_item_primary_raw_material, "itm_iron"),
  7558. (item_set_slot, "itm_tools", slot_item_input_number, 2),
  7559. (item_set_slot, "itm_tools", slot_item_output_per_run, 2),
  7560. (item_set_slot, "itm_tools", slot_item_overhead_per_run, 60),
  7561. (item_set_slot, "itm_tools", slot_item_base_price, 410),
  7562. (item_set_slot, "itm_tools", slot_item_enterprise_building_cost, 3500),
  7563.  
  7564. (item_set_slot, "itm_pottery", slot_item_urban_demand, 15),
  7565. (item_set_slot, "itm_pottery", slot_item_rural_demand, 5),
  7566. (item_set_slot, "itm_pottery", slot_item_desert_demand, -1),
  7567. (item_set_slot, "itm_pottery", slot_item_production_slot, slot_center_pottery_kilns),
  7568. (item_set_slot, "itm_pottery", slot_item_production_string, "str_kilns"),
  7569.  
  7570. (item_set_slot, "itm_oil", slot_item_urban_demand, 10),
  7571. (item_set_slot, "itm_oil", slot_item_rural_demand, 5),
  7572. (item_set_slot, "itm_oil", slot_item_desert_demand, -1),
  7573. (item_set_slot, "itm_oil", slot_item_production_slot, slot_center_olive_presses),
  7574. (item_set_slot, "itm_oil", slot_item_production_string, "str_presses"),
  7575. (item_set_slot, "itm_oil", slot_item_primary_raw_material, "itm_raw_olives"),
  7576. (item_set_slot, "itm_oil", slot_item_input_number, 6),
  7577. (item_set_slot, "itm_oil", slot_item_output_per_run, 2),
  7578. (item_set_slot, "itm_oil", slot_item_overhead_per_run, 80),
  7579. (item_set_slot, "itm_oil", slot_item_base_price, 450),
  7580. (item_set_slot, "itm_oil", slot_item_enterprise_building_cost, 4500),
  7581.  
  7582. (item_set_slot, "itm_raw_olives", slot_item_urban_demand, 0),
  7583. (item_set_slot, "itm_raw_olives", slot_item_rural_demand, 0),
  7584. (item_set_slot, "itm_raw_olives", slot_item_desert_demand, 0),
  7585. (item_set_slot, "itm_raw_olives", slot_item_production_slot, slot_center_acres_olives),
  7586. (item_set_slot, "itm_raw_olives", slot_item_production_string, "str_olive_groves"),
  7587. (item_set_slot, "itm_raw_olives", slot_item_is_raw_material_only_for, "itm_oil"),
  7588. (item_set_slot, "itm_raw_olives", slot_item_base_price, 100),
  7589.  
  7590. (item_set_slot, "itm_velvet", slot_item_urban_demand, 5),
  7591. (item_set_slot, "itm_velvet", slot_item_rural_demand, 0),
  7592. (item_set_slot, "itm_velvet", slot_item_desert_demand, -1),
  7593. (item_set_slot, "itm_velvet", slot_item_production_slot, slot_center_silk_looms),
  7594. (item_set_slot, "itm_velvet", slot_item_production_string, "str_looms"),
  7595. (item_set_slot, "itm_velvet", slot_item_primary_raw_material, "itm_raw_silk"),
  7596. (item_set_slot, "itm_velvet", slot_item_input_number, 2),
  7597. (item_set_slot, "itm_velvet", slot_item_output_per_run, 2),
  7598. (item_set_slot, "itm_velvet", slot_item_overhead_per_run, 160),
  7599. (item_set_slot, "itm_velvet", slot_item_base_price, 1025),
  7600. (item_set_slot, "itm_velvet", slot_item_secondary_raw_material, "itm_raw_dyes"),
  7601. (item_set_slot, "itm_velvet", slot_item_enterprise_building_cost, 10000),
  7602.  
  7603. (item_set_slot, "itm_raw_silk", slot_item_urban_demand, 0),
  7604. (item_set_slot, "itm_raw_silk", slot_item_rural_demand, 0),
  7605. (item_set_slot, "itm_raw_silk", slot_item_production_slot, slot_center_silk_farms),
  7606. (item_set_slot, "itm_raw_silk", slot_item_production_string, "str_mulberry_groves"),
  7607. (item_set_slot, "itm_raw_silk", slot_item_is_raw_material_only_for, "itm_velvet"),
  7608. (item_set_slot, "itm_raw_silk", slot_item_base_price, 600),
  7609.  
  7610. (item_set_slot, "itm_raw_dyes", slot_item_urban_demand, 3),
  7611. (item_set_slot, "itm_raw_dyes", slot_item_rural_demand, 0),
  7612. (item_set_slot, "itm_raw_dyes", slot_item_desert_demand, -1),
  7613. (item_set_slot, "itm_raw_dyes", slot_item_production_string, "str_caravans"),
  7614. (item_set_slot, "itm_raw_dyes", slot_item_base_price, 200),
  7615.  
  7616. (item_set_slot, "itm_spice", slot_item_urban_demand, 5),
  7617. (item_set_slot, "itm_spice", slot_item_rural_demand, 0),
  7618. (item_set_slot, "itm_spice", slot_item_desert_demand, 5),
  7619. (item_set_slot, "itm_spice", slot_item_production_string, "str_caravans"),
  7620.  
  7621. (item_set_slot, "itm_furs", slot_item_urban_demand, 5),
  7622. (item_set_slot, "itm_furs", slot_item_rural_demand, 0),
  7623. (item_set_slot, "itm_furs", slot_item_desert_demand, -1),
  7624. (item_set_slot, "itm_furs", slot_item_production_slot, slot_center_fur_traps),
  7625. (item_set_slot, "itm_furs", slot_item_production_string, "str_traps"),
  7626.  
  7627. (item_set_slot, "itm_honey", slot_item_urban_demand, 12),
  7628. (item_set_slot, "itm_honey", slot_item_rural_demand, 3),
  7629. (item_set_slot, "itm_honey", slot_item_desert_demand, -1),
  7630. (item_set_slot, "itm_honey", slot_item_production_slot, slot_center_apiaries),
  7631. (item_set_slot, "itm_honey", slot_item_production_string, "str_hives"),
  7632.  
  7633. (item_set_slot, "itm_cabbages", slot_item_urban_demand, 7),
  7634. (item_set_slot, "itm_cabbages", slot_item_rural_demand, 7),
  7635. (item_set_slot, "itm_cabbages", slot_item_desert_demand, 7),
  7636. (item_set_slot, "itm_cabbages", slot_item_production_slot, slot_center_household_gardens),
  7637. (item_set_slot, "itm_cabbages", slot_item_production_string, "str_gardens"),
  7638.  
  7639. (item_set_slot, "itm_raw_date_fruit", slot_item_urban_demand, 7),
  7640. (item_set_slot, "itm_raw_date_fruit", slot_item_rural_demand, 7),
  7641. (item_set_slot, "itm_raw_date_fruit", slot_item_desert_demand, 7),
  7642. (item_set_slot, "itm_raw_date_fruit", slot_item_production_slot, slot_center_household_gardens),
  7643. (item_set_slot, "itm_raw_date_fruit", slot_item_production_string, "str_acres_oasis"),
  7644.  
  7645. (item_set_slot, "itm_chicken", slot_item_urban_demand, 40),
  7646. (item_set_slot, "itm_chicken", slot_item_rural_demand, 10),
  7647. (item_set_slot, "itm_chicken", slot_item_desert_demand, -1),
  7648.  
  7649. (item_set_slot, "itm_pork", slot_item_urban_demand, 40),
  7650. (item_set_slot, "itm_pork", slot_item_rural_demand, 10),
  7651. (item_set_slot, "itm_pork", slot_item_desert_demand, -1),
  7652.  
  7653. # Setting book intelligence requirements
  7654. (item_set_slot, "itm_book_tactics", slot_item_intelligence_requirement, 9),
  7655. (item_set_slot, "itm_book_persuasion", slot_item_intelligence_requirement, 8),
  7656. (item_set_slot, "itm_book_leadership", slot_item_intelligence_requirement, 7),
  7657. (item_set_slot, "itm_book_intelligence", slot_item_intelligence_requirement, 10),
  7658. (item_set_slot, "itm_book_trade", slot_item_intelligence_requirement, 11),
  7659. (item_set_slot, "itm_book_weapon_mastery", slot_item_intelligence_requirement, 9),
  7660. (item_set_slot, "itm_book_engineering", slot_item_intelligence_requirement, 12),
  7661.  
  7662. (item_set_slot, "itm_book_wound_treatment_reference", slot_item_intelligence_requirement, 10),
  7663. (item_set_slot, "itm_book_training_reference", slot_item_intelligence_requirement, 10),
  7664. (item_set_slot, "itm_book_surgery_reference", slot_item_intelligence_requirement, 10),
  7665. ]),
  7666.  
  7667.  
  7668. ("initialize_town_arena_info",
  7669. [
  7670. (try_for_range, ":town_no", towns_begin, towns_end),
  7671. (party_set_slot, ":town_no", slot_town_tournament_max_teams, 4),
  7672. (party_set_slot, ":town_no", slot_town_tournament_max_team_size, 8),
  7673. (try_end),
  7674. (party_set_slot, "p_town_6", slot_town_tournament_max_team_size, 2),
  7675.  
  7676. (party_set_slot,"p_town_1", slot_town_arena_melee_1_num_teams, 2),
  7677. (party_set_slot,"p_town_1", slot_town_arena_melee_1_team_size, 1),
  7678. (party_set_slot,"p_town_1", slot_town_arena_melee_2_num_teams, 4),
  7679. (party_set_slot,"p_town_1", slot_town_arena_melee_2_team_size, 1),
  7680. (party_set_slot,"p_town_1", slot_town_arena_melee_3_num_teams, 4),
  7681. (party_set_slot,"p_town_1", slot_town_arena_melee_3_team_size, 1),
  7682.  
  7683. (party_set_slot,"p_town_2", slot_town_arena_melee_1_num_teams, 4),
  7684. (party_set_slot,"p_town_2", slot_town_arena_melee_1_team_size, 4),
  7685. (party_set_slot,"p_town_2", slot_town_arena_melee_2_num_teams, 4),
  7686. (party_set_slot,"p_town_2", slot_town_arena_melee_2_team_size, 6),
  7687. (party_set_slot,"p_town_2", slot_town_arena_melee_3_num_teams, 4),
  7688. (party_set_slot,"p_town_2", slot_town_arena_melee_3_team_size, 8),
  7689.  
  7690. (party_set_slot,"p_town_3", slot_town_arena_melee_1_num_teams, 2),
  7691. (party_set_slot,"p_town_3", slot_town_arena_melee_1_team_size, 8),
  7692. (party_set_slot,"p_town_3", slot_town_arena_melee_2_num_teams, 2),
  7693. (party_set_slot,"p_town_3", slot_town_arena_melee_2_team_size, 8),
  7694. (party_set_slot,"p_town_3", slot_town_arena_melee_3_num_teams, 2),
  7695. (party_set_slot,"p_town_3", slot_town_arena_melee_3_team_size, 8),
  7696.  
  7697. (party_set_slot,"p_town_4", slot_town_arena_melee_1_num_teams, 2),
  7698. (party_set_slot,"p_town_4", slot_town_arena_melee_1_team_size, 8),
  7699. (party_set_slot,"p_town_4", slot_town_arena_melee_2_num_teams, 3),
  7700. (party_set_slot,"p_town_4", slot_town_arena_melee_2_team_size, 8),
  7701. (party_set_slot,"p_town_4", slot_town_arena_melee_3_num_teams, 2),
  7702. (party_set_slot,"p_town_4", slot_town_arena_melee_3_team_size, 5),
  7703.  
  7704. (party_set_slot,"p_town_5", slot_town_arena_melee_1_num_teams, 2),
  7705. (party_set_slot,"p_town_5", slot_town_arena_melee_1_team_size, 3),
  7706. (party_set_slot,"p_town_5", slot_town_arena_melee_2_num_teams, 2),
  7707. (party_set_slot,"p_town_5", slot_town_arena_melee_2_team_size, 5),
  7708. (party_set_slot,"p_town_5", slot_town_arena_melee_3_num_teams, 2),
  7709. (party_set_slot,"p_town_5", slot_town_arena_melee_3_team_size, 8),
  7710.  
  7711. (party_set_slot,"p_town_6", slot_town_arena_melee_1_num_teams, 2),
  7712. (party_set_slot,"p_town_6", slot_town_arena_melee_1_team_size, 4),
  7713. (party_set_slot,"p_town_6", slot_town_arena_melee_2_num_teams, 3),
  7714. (party_set_slot,"p_town_6", slot_town_arena_melee_2_team_size, 4),
  7715. (party_set_slot,"p_town_6", slot_town_arena_melee_3_num_teams, 3),
  7716. (party_set_slot,"p_town_6", slot_town_arena_melee_3_team_size, 6),
  7717.  
  7718. (party_set_slot,"p_town_7", slot_town_arena_melee_1_num_teams, 4),
  7719. (party_set_slot,"p_town_7", slot_town_arena_melee_1_team_size, 4),
  7720. (party_set_slot,"p_town_7", slot_town_arena_melee_2_num_teams, 4),
  7721. (party_set_slot,"p_town_7", slot_town_arena_melee_2_team_size, 6),
  7722. (party_set_slot,"p_town_7", slot_town_arena_melee_3_num_teams, 4),
  7723. (party_set_slot,"p_town_7", slot_town_arena_melee_3_team_size, 8),
  7724.  
  7725. (party_set_slot,"p_town_8", slot_town_arena_melee_1_num_teams, 3),
  7726. (party_set_slot,"p_town_8", slot_town_arena_melee_1_team_size, 1),
  7727. (party_set_slot,"p_town_8", slot_town_arena_melee_2_num_teams, 3),
  7728. (party_set_slot,"p_town_8", slot_town_arena_melee_2_team_size, 3),
  7729. (party_set_slot,"p_town_8", slot_town_arena_melee_3_num_teams, 3),
  7730. (party_set_slot,"p_town_8", slot_town_arena_melee_3_team_size, 7),
  7731.  
  7732. (party_set_slot,"p_town_9", slot_town_arena_melee_1_num_teams, 2),
  7733. (party_set_slot,"p_town_9", slot_town_arena_melee_1_team_size, 2),
  7734. (party_set_slot,"p_town_9", slot_town_arena_melee_2_num_teams, 2),
  7735. (party_set_slot,"p_town_9", slot_town_arena_melee_2_team_size, 5),
  7736. (party_set_slot,"p_town_9", slot_town_arena_melee_3_num_teams, 2),
  7737. (party_set_slot,"p_town_9", slot_town_arena_melee_3_team_size, 8),
  7738.  
  7739. (party_set_slot,"p_town_10", slot_town_arena_melee_1_num_teams, 2),
  7740. (party_set_slot,"p_town_10", slot_town_arena_melee_1_team_size, 3),
  7741. (party_set_slot,"p_town_10", slot_town_arena_melee_2_num_teams, 2),
  7742. (party_set_slot,"p_town_10", slot_town_arena_melee_2_team_size, 5),
  7743. (party_set_slot,"p_town_10", slot_town_arena_melee_3_num_teams, 2),
  7744. (party_set_slot,"p_town_10", slot_town_arena_melee_3_team_size, 8),
  7745.  
  7746. (party_set_slot,"p_town_11", slot_town_arena_melee_1_num_teams, 2),
  7747. (party_set_slot,"p_town_11", slot_town_arena_melee_1_team_size, 8),
  7748. (party_set_slot,"p_town_11", slot_town_arena_melee_2_num_teams, 3),
  7749. (party_set_slot,"p_town_11", slot_town_arena_melee_2_team_size, 4),
  7750. (party_set_slot,"p_town_11", slot_town_arena_melee_3_num_teams, 3),
  7751. (party_set_slot,"p_town_11", slot_town_arena_melee_3_team_size, 6),
  7752.  
  7753. (party_set_slot,"p_town_12", slot_town_arena_melee_1_num_teams, 3),
  7754. (party_set_slot,"p_town_12", slot_town_arena_melee_1_team_size, 8),
  7755. (party_set_slot,"p_town_12", slot_town_arena_melee_2_num_teams, 4),
  7756. (party_set_slot,"p_town_12", slot_town_arena_melee_2_team_size, 6),
  7757. (party_set_slot,"p_town_12", slot_town_arena_melee_3_num_teams, 4),
  7758. (party_set_slot,"p_town_12", slot_town_arena_melee_3_team_size, 5),
  7759.  
  7760. (party_set_slot,"p_town_13", slot_town_arena_melee_1_num_teams, 2),
  7761. (party_set_slot,"p_town_13", slot_town_arena_melee_1_team_size, 8),
  7762. (party_set_slot,"p_town_13", slot_town_arena_melee_2_num_teams, 4),
  7763. (party_set_slot,"p_town_13", slot_town_arena_melee_2_team_size, 5),
  7764. (party_set_slot,"p_town_13", slot_town_arena_melee_3_num_teams, 4),
  7765. (party_set_slot,"p_town_13", slot_town_arena_melee_3_team_size, 7),
  7766.  
  7767. (party_set_slot,"p_town_14", slot_town_arena_melee_1_num_teams, 2),
  7768. (party_set_slot,"p_town_14", slot_town_arena_melee_1_team_size, 4),
  7769. (party_set_slot,"p_town_14", slot_town_arena_melee_2_num_teams, 2),
  7770. (party_set_slot,"p_town_14", slot_town_arena_melee_2_team_size, 5),
  7771. (party_set_slot,"p_town_14", slot_town_arena_melee_3_num_teams, 2),
  7772. (party_set_slot,"p_town_14", slot_town_arena_melee_3_team_size, 6),
  7773.  
  7774. (party_set_slot,"p_town_15", slot_town_arena_melee_1_num_teams, 2),
  7775. (party_set_slot,"p_town_15", slot_town_arena_melee_1_team_size, 8),
  7776. (party_set_slot,"p_town_15", slot_town_arena_melee_2_num_teams, 3),
  7777. (party_set_slot,"p_town_15", slot_town_arena_melee_2_team_size, 4),
  7778. (party_set_slot,"p_town_15", slot_town_arena_melee_3_num_teams, 3),
  7779. (party_set_slot,"p_town_15", slot_town_arena_melee_3_team_size, 6),
  7780.  
  7781. (party_set_slot,"p_town_16", slot_town_arena_melee_1_num_teams, 3),
  7782. (party_set_slot,"p_town_16", slot_town_arena_melee_1_team_size, 8),
  7783. (party_set_slot,"p_town_16", slot_town_arena_melee_2_num_teams, 4),
  7784. (party_set_slot,"p_town_16", slot_town_arena_melee_2_team_size, 6),
  7785. (party_set_slot,"p_town_16", slot_town_arena_melee_3_num_teams, 4),
  7786. (party_set_slot,"p_town_16", slot_town_arena_melee_3_team_size, 5),
  7787.  
  7788. (party_set_slot,"p_town_17", slot_town_arena_melee_1_num_teams, 2),
  7789. (party_set_slot,"p_town_17", slot_town_arena_melee_1_team_size, 8),
  7790. (party_set_slot,"p_town_17", slot_town_arena_melee_2_num_teams, 4),
  7791. (party_set_slot,"p_town_17", slot_town_arena_melee_2_team_size, 5),
  7792. (party_set_slot,"p_town_17", slot_town_arena_melee_3_num_teams, 4),
  7793. (party_set_slot,"p_town_17", slot_town_arena_melee_3_team_size, 7),
  7794.  
  7795. (party_set_slot,"p_town_18", slot_town_arena_melee_1_num_teams, 2),
  7796. (party_set_slot,"p_town_18", slot_town_arena_melee_1_team_size, 4),
  7797. (party_set_slot,"p_town_18", slot_town_arena_melee_2_num_teams, 2),
  7798. (party_set_slot,"p_town_18", slot_town_arena_melee_2_team_size, 5),
  7799. (party_set_slot,"p_town_18", slot_town_arena_melee_3_num_teams, 2),
  7800. (party_set_slot,"p_town_18", slot_town_arena_melee_3_team_size, 6),
  7801.  
  7802. (party_set_slot,"p_town_19", slot_town_arena_melee_1_num_teams, 2),
  7803. (party_set_slot,"p_town_19", slot_town_arena_melee_1_team_size, 8),
  7804. (party_set_slot,"p_town_19", slot_town_arena_melee_2_num_teams, 4),
  7805. (party_set_slot,"p_town_19", slot_town_arena_melee_2_team_size, 4),
  7806. (party_set_slot,"p_town_19", slot_town_arena_melee_3_num_teams, 4),
  7807. (party_set_slot,"p_town_19", slot_town_arena_melee_3_team_size, 6),
  7808.  
  7809. (party_set_slot,"p_town_20", slot_town_arena_melee_1_num_teams, 4),
  7810. (party_set_slot,"p_town_20", slot_town_arena_melee_1_team_size, 2),
  7811. (party_set_slot,"p_town_20", slot_town_arena_melee_2_num_teams, 4),
  7812. (party_set_slot,"p_town_20", slot_town_arena_melee_2_team_size, 4),
  7813. (party_set_slot,"p_town_20", slot_town_arena_melee_3_num_teams, 4),
  7814. (party_set_slot,"p_town_20", slot_town_arena_melee_3_team_size, 6),
  7815.  
  7816. (party_set_slot,"p_town_21", slot_town_arena_melee_1_num_teams, 3),
  7817. (party_set_slot,"p_town_21", slot_town_arena_melee_1_team_size, 3),
  7818. (party_set_slot,"p_town_21", slot_town_arena_melee_2_num_teams, 2),
  7819. (party_set_slot,"p_town_21", slot_town_arena_melee_2_team_size, 6),
  7820. (party_set_slot,"p_town_21", slot_town_arena_melee_3_num_teams, 2),
  7821. (party_set_slot,"p_town_21", slot_town_arena_melee_3_team_size, 8),
  7822.  
  7823. (party_set_slot,"p_town_22", slot_town_arena_melee_1_num_teams, 4),
  7824. (party_set_slot,"p_town_22", slot_town_arena_melee_1_team_size, 3),
  7825. (party_set_slot,"p_town_22", slot_town_arena_melee_2_num_teams, 3),
  7826. (party_set_slot,"p_town_22", slot_town_arena_melee_2_team_size, 4),
  7827. (party_set_slot,"p_town_22", slot_town_arena_melee_3_num_teams, 2),
  7828. (party_set_slot,"p_town_22", slot_town_arena_melee_3_team_size, 6),
  7829. ]),
  7830.  
  7831. ("initialize_banner_info",
  7832. [
  7833. #Banners
  7834. (try_for_range, ":cur_troop", active_npcs_begin, kingdom_ladies_end),
  7835. (troop_set_slot, ":cur_troop", slot_troop_custom_banner_flag_type, -1),
  7836. (troop_set_slot, ":cur_troop", slot_troop_custom_banner_map_flag_type, -1),
  7837. (try_end),
  7838. (troop_set_slot, "trp_player", slot_troop_custom_banner_flag_type, -1),
  7839. (troop_set_slot, "trp_player", slot_troop_custom_banner_map_flag_type, -1),
  7840. (store_random_in_range, "$g_election_date", 0, 45), #setting a random election date
  7841. #Assigning global constant
  7842. #(call_script, "script_store_average_center_value_per_faction"),
  7843.  
  7844. (troop_set_slot, "trp_player", slot_troop_custom_banner_bg_color_1, 0xFFFFFFFF),
  7845. (troop_set_slot, "trp_player", slot_troop_custom_banner_bg_color_2, 0xFFFFFFFF),
  7846. (troop_set_slot, "trp_player", slot_troop_custom_banner_charge_color_1, 0xFFFFFFFF),
  7847. (troop_set_slot, "trp_player", slot_troop_custom_banner_charge_color_2, 0xFFFFFFFF),
  7848. (troop_set_slot, "trp_player", slot_troop_custom_banner_charge_color_3, 0xFFFFFFFF),
  7849. (troop_set_slot, "trp_player", slot_troop_custom_banner_charge_color_4, 0xFFFFFFFF),
  7850.  
  7851. #Setting background colors for banners
  7852. (troop_set_slot, "trp_banner_background_color_array", 0, 0xFF8f4531),
  7853. (troop_set_slot, "trp_banner_background_color_array", 1, 0xFFd9d7d1),
  7854. (troop_set_slot, "trp_banner_background_color_array", 2, 0xFF373736),
  7855. (troop_set_slot, "trp_banner_background_color_array", 3, 0xFFa48b28),
  7856. (troop_set_slot, "trp_banner_background_color_array", 4, 0xFF497735),
  7857. (troop_set_slot, "trp_banner_background_color_array", 5, 0xFF82362d),
  7858. (troop_set_slot, "trp_banner_background_color_array", 6, 0xFF793329),
  7859. (troop_set_slot, "trp_banner_background_color_array", 7, 0xFF262521),
  7860. (troop_set_slot, "trp_banner_background_color_array", 8, 0xFFd9dad1),
  7861. (troop_set_slot, "trp_banner_background_color_array", 9, 0xFF524563),
  7862. (troop_set_slot, "trp_banner_background_color_array", 10, 0xFF91312c),
  7863. (troop_set_slot, "trp_banner_background_color_array", 11, 0xFFafa231),
  7864. (troop_set_slot, "trp_banner_background_color_array", 12, 0xFF706d3c),
  7865. (troop_set_slot, "trp_banner_background_color_array", 13, 0xFFd6d3ce),
  7866. (troop_set_slot, "trp_banner_background_color_array", 14, 0xFF521c08),
  7867. (troop_set_slot, "trp_banner_background_color_array", 15, 0xFF394584),
  7868. (troop_set_slot, "trp_banner_background_color_array", 16, 0xFF42662e),
  7869. (troop_set_slot, "trp_banner_background_color_array", 17, 0xFFdfded6),
  7870. (troop_set_slot, "trp_banner_background_color_array", 18, 0xFF292724),
  7871. (troop_set_slot, "trp_banner_background_color_array", 19, 0xFF58611b),
  7872. (troop_set_slot, "trp_banner_background_color_array", 20, 0xFF313a67),
  7873. (troop_set_slot, "trp_banner_background_color_array", 21, 0xFF9c924a),
  7874. (troop_set_slot, "trp_banner_background_color_array", 22, 0xFF998b39),
  7875. (troop_set_slot, "trp_banner_background_color_array", 23, 0xFF365168),
  7876. (troop_set_slot, "trp_banner_background_color_array", 24, 0xFFd6d3ce),
  7877. (troop_set_slot, "trp_banner_background_color_array", 25, 0xFF94a642),
  7878. (troop_set_slot, "trp_banner_background_color_array", 26, 0xFF944131),
  7879. (troop_set_slot, "trp_banner_background_color_array", 27, 0xFF893b34),
  7880. (troop_set_slot, "trp_banner_background_color_array", 28, 0xFF425510),
  7881. (troop_set_slot, "trp_banner_background_color_array", 29, 0xFF94452e),
  7882. (troop_set_slot, "trp_banner_background_color_array", 30, 0xFF475a94),
  7883. (troop_set_slot, "trp_banner_background_color_array", 31, 0xFFd1b231),
  7884. (troop_set_slot, "trp_banner_background_color_array", 32, 0xFFe1e2df),
  7885. (troop_set_slot, "trp_banner_background_color_array", 33, 0xFF997c1e),
  7886. (troop_set_slot, "trp_banner_background_color_array", 34, 0xFFc6b74d),
  7887. (troop_set_slot, "trp_banner_background_color_array", 35, 0xFFad9a18),
  7888. (troop_set_slot, "trp_banner_background_color_array", 36, 0xFF212421),
  7889. (troop_set_slot, "trp_banner_background_color_array", 37, 0xFF8c2021),
  7890. (troop_set_slot, "trp_banner_background_color_array", 38, 0xFF4d7136),
  7891. (troop_set_slot, "trp_banner_background_color_array", 39, 0xFF395d84),
  7892. (troop_set_slot, "trp_banner_background_color_array", 40, 0xFF527539),
  7893. (troop_set_slot, "trp_banner_background_color_array", 41, 0xFF9c3c39),
  7894. (troop_set_slot, "trp_banner_background_color_array", 42, 0xFF42518c),
  7895. (troop_set_slot, "trp_banner_background_color_array", 43, 0xFFa46a2c),
  7896. (troop_set_slot, "trp_banner_background_color_array", 44, 0xFF9f5141),
  7897. (troop_set_slot, "trp_banner_background_color_array", 45, 0xFF2c6189),
  7898. (troop_set_slot, "trp_banner_background_color_array", 46, 0xFF556421),
  7899. (troop_set_slot, "trp_banner_background_color_array", 47, 0xFF9d621e),
  7900. (troop_set_slot, "trp_banner_background_color_array", 48, 0xFFdeded6),
  7901. (troop_set_slot, "trp_banner_background_color_array", 49, 0xFF6e4891),
  7902. (troop_set_slot, "trp_banner_background_color_array", 50, 0xFF865a29),
  7903. (troop_set_slot, "trp_banner_background_color_array", 51, 0xFFdedfd9),
  7904. (troop_set_slot, "trp_banner_background_color_array", 52, 0xFF524273),
  7905. (troop_set_slot, "trp_banner_background_color_array", 53, 0xFF8c3821),
  7906. (troop_set_slot, "trp_banner_background_color_array", 54, 0xFFd1cec6),
  7907. (troop_set_slot, "trp_banner_background_color_array", 55, 0xFF313031),
  7908. (troop_set_slot, "trp_banner_background_color_array", 56, 0xFF47620d),
  7909. (troop_set_slot, "trp_banner_background_color_array", 57, 0xFF6b4139),
  7910. (troop_set_slot, "trp_banner_background_color_array", 58, 0xFFd6d7d6),
  7911. (troop_set_slot, "trp_banner_background_color_array", 59, 0xFF2e2f2c),
  7912. (troop_set_slot, "trp_banner_background_color_array", 60, 0xFF604283),
  7913. (troop_set_slot, "trp_banner_background_color_array", 61, 0xFF395584),
  7914. (troop_set_slot, "trp_banner_background_color_array", 62, 0xFF313031),
  7915. (troop_set_slot, "trp_banner_background_color_array", 63, 0xFF7e3f2e),
  7916. (troop_set_slot, "trp_banner_background_color_array", 64, 0xFF343434),
  7917. (troop_set_slot, "trp_banner_background_color_array", 65, 0xFF3c496b),
  7918. (troop_set_slot, "trp_banner_background_color_array", 66, 0xFFd9d8d1),
  7919. (troop_set_slot, "trp_banner_background_color_array", 67, 0xFF99823c),
  7920. (troop_set_slot, "trp_banner_background_color_array", 68, 0xFF9f822e),
  7921. (troop_set_slot, "trp_banner_background_color_array", 69, 0xFF393839),
  7922. (troop_set_slot, "trp_banner_background_color_array", 70, 0xFFa54931),
  7923. (troop_set_slot, "trp_banner_background_color_array", 71, 0xFFdfdcd6),
  7924. (troop_set_slot, "trp_banner_background_color_array", 72, 0xFF9f4a36),
  7925. (troop_set_slot, "trp_banner_background_color_array", 73, 0xFF8c7521),
  7926. (troop_set_slot, "trp_banner_background_color_array", 74, 0xFF9f4631),
  7927. (troop_set_slot, "trp_banner_background_color_array", 75, 0xFF793324),
  7928. (troop_set_slot, "trp_banner_background_color_array", 76, 0xFF395076),
  7929. (troop_set_slot, "trp_banner_background_color_array", 77, 0xFF2c2b2c),
  7930. (troop_set_slot, "trp_banner_background_color_array", 78, 0xFF657121),
  7931. (troop_set_slot, "trp_banner_background_color_array", 79, 0xFF7e3121),
  7932. (troop_set_slot, "trp_banner_background_color_array", 80, 0xFF76512e),
  7933. (troop_set_slot, "trp_banner_background_color_array", 81, 0xFFe7e3de),
  7934. (troop_set_slot, "trp_banner_background_color_array", 82, 0xFF947921),
  7935. (troop_set_slot, "trp_banner_background_color_array", 83, 0xFF4d7b7c),
  7936. (troop_set_slot, "trp_banner_background_color_array", 84, 0xFF343331),
  7937. (troop_set_slot, "trp_banner_background_color_array", 85, 0xFFa74d36),
  7938. (troop_set_slot, "trp_banner_background_color_array", 86, 0xFFe7e3de),
  7939. (troop_set_slot, "trp_banner_background_color_array", 87, 0xFFd6d8ce),
  7940. (troop_set_slot, "trp_banner_background_color_array", 88, 0xFF3e4d67),
  7941. (troop_set_slot, "trp_banner_background_color_array", 89, 0xFF9f842e),
  7942. (troop_set_slot, "trp_banner_background_color_array", 90, 0xFF4d6994),
  7943. (troop_set_slot, "trp_banner_background_color_array", 91, 0xFF4a6118),
  7944. (troop_set_slot, "trp_banner_background_color_array", 92, 0xFF943c29),
  7945. (troop_set_slot, "trp_banner_background_color_array", 93, 0xFF394479),
  7946. (troop_set_slot, "trp_banner_background_color_array", 94, 0xFF343331),
  7947. (troop_set_slot, "trp_banner_background_color_array", 95, 0xFF3f4d5d),
  7948. (troop_set_slot, "trp_banner_background_color_array", 96, 0xFF4a6489),
  7949. (troop_set_slot, "trp_banner_background_color_array", 97, 0xFF313031),
  7950. (troop_set_slot, "trp_banner_background_color_array", 98, 0xFFd6d7ce),
  7951. (troop_set_slot, "trp_banner_background_color_array", 99, 0xFFc69e00),
  7952. (troop_set_slot, "trp_banner_background_color_array", 100, 0xFF638e52),
  7953. (troop_set_slot, "trp_banner_background_color_array", 101, 0xFFdcdbd3),
  7954. (troop_set_slot, "trp_banner_background_color_array", 102, 0xFFdbdcd3),
  7955. (troop_set_slot, "trp_banner_background_color_array", 103, 0xFF843831),
  7956. (troop_set_slot, "trp_banner_background_color_array", 104, 0xFFcecfc6),
  7957. (troop_set_slot, "trp_banner_background_color_array", 105, 0xFFc39d31),
  7958. (troop_set_slot, "trp_banner_background_color_array", 106, 0xFFcbb670),
  7959. (troop_set_slot, "trp_banner_background_color_array", 107, 0xFF394a18),
  7960. (troop_set_slot, "trp_banner_background_color_array", 108, 0xFF372708),
  7961. (troop_set_slot, "trp_banner_background_color_array", 109, 0xFF9a6810),
  7962. (troop_set_slot, "trp_banner_background_color_array", 110, 0xFFb27910),
  7963. (troop_set_slot, "trp_banner_background_color_array", 111, 0xFF8c8621),
  7964. (troop_set_slot, "trp_banner_background_color_array", 112, 0xFF975a03),
  7965. (troop_set_slot, "trp_banner_background_color_array", 113, 0xFF2c2924),
  7966. (troop_set_slot, "trp_banner_background_color_array", 114, 0xFFaa962c),
  7967. (troop_set_slot, "trp_banner_background_color_array", 115, 0xFFa2822e),
  7968. (troop_set_slot, "trp_banner_background_color_array", 116, 0xFF7b8a8c),
  7969. (troop_set_slot, "trp_banner_background_color_array", 117, 0xFF3c0908),
  7970. (troop_set_slot, "trp_banner_background_color_array", 118, 0xFFFF00FF),
  7971. (troop_set_slot, "trp_banner_background_color_array", 119, 0xFF671e14),
  7972. (troop_set_slot, "trp_banner_background_color_array", 120, 0xFF103042),
  7973. (troop_set_slot, "trp_banner_background_color_array", 121, 0xFF4a4500),
  7974. (troop_set_slot, "trp_banner_background_color_array", 122, 0xFF703324),
  7975. (troop_set_slot, "trp_banner_background_color_array", 123, 0xFF24293c),
  7976. (troop_set_slot, "trp_banner_background_color_array", 124, 0xFF5d6966),
  7977. (troop_set_slot, "trp_banner_background_color_array", 125, 0xFFbd9631),
  7978. (troop_set_slot, "trp_banner_background_color_array", 126, 0xFFc6b26b),
  7979. (troop_set_slot, "trp_banner_background_color_array", 127, 0xFF394918),
  7980.  
  7981. #Default banners
  7982. (troop_set_slot, "trp_banner_background_color_array", 128, 0xFF212221),
  7983. (troop_set_slot, "trp_banner_background_color_array", 129, 0xFF212221),
  7984. (troop_set_slot, "trp_banner_background_color_array", 130, 0xFF2E3B10),
  7985. (troop_set_slot, "trp_banner_background_color_array", 131, 0xFF425D7B),
  7986. (troop_set_slot, "trp_banner_background_color_array", 132, 0xFF394608),
  7987. ]),
  7988.  
  7989.  
  7990. ("initialize_economic_information",
  7991. [
  7992. #All towns produce tools, pottery, and wool cloth for sale in countryside
  7993. (try_for_range, ":town_no", towns_begin, towns_end),
  7994. (store_random_in_range, ":random_average_20_variation_10", 10, 31), #10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 or 30
  7995. (party_set_slot, ":town_no", slot_center_wool_looms, ":random_average_20_variation_10"),
  7996.  
  7997. (store_random_in_range, ":random_average_2_variation_1", 1, 4), #1,2 or 3
  7998. (party_set_slot, ":town_no", slot_center_breweries, ":random_average_2_variation_1"),
  7999.  
  8000. (store_random_in_range, ":random_average_5_variation_3", 3, 9), #2,3,4,5,6,7 or 8
  8001. (party_set_slot, ":town_no", slot_center_pottery_kilns, ":random_average_5_variation_3"),
  8002.  
  8003. (store_random_in_range, ":random_average_15_variation_9", 6, 25), #6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 or 24
  8004. (party_set_slot, ":town_no", slot_center_smithies, ":random_average_15_variation_9"),
  8005.  
  8006. (store_random_in_range, ":random_average_5_variation_3", 3, 9), #2,3,4,5,6,7 or 8
  8007. (party_set_slot, ":town_no", slot_center_mills, ":random_average_5_variation_3"),
  8008.  
  8009. (store_random_in_range, ":random_average_2_variation_1", 1, 4), #1,2 or 3
  8010. (party_set_slot, ":town_no", slot_center_tanneries, ":random_average_2_variation_1"),
  8011.  
  8012. (store_random_in_range, ":random_average_1_variation_1", 0, 3), #0,1 or 2
  8013. (party_set_slot, ":town_no", slot_center_wine_presses, ":random_average_1_variation_1"),
  8014.  
  8015. (store_random_in_range, ":random_average_2_variation_1", 1, 4), #1,2 or 3
  8016. (party_set_slot, ":town_no", slot_center_olive_presses, ":random_average_2_variation_1"),
  8017.  
  8018. (store_random_in_range, ":random_average_1000_variation_1000", 0, 2001), #0..2000
  8019. (party_set_slot, ":town_no", slot_center_acres_grain, ":random_average_1000_variation_1000"), #0..2000
  8020.  
  8021. (store_random_in_range, ":random_average_1000_variation_1000", 0, 2001), #0..2000
  8022. (party_set_slot, ":town_no", slot_center_acres_vineyard, ":random_average_1000_variation_1000"), #0..2000
  8023. (try_end),
  8024.  
  8025. #Sargoth (linen, wine)
  8026. (party_set_slot, "p_town_1", slot_center_linen_looms, 15),
  8027. (party_set_slot, "p_town_1", slot_center_wine_presses, 4),
  8028.  
  8029. #Tihr (salt, smoked fish, linen)
  8030. (party_set_slot, "p_town_2", slot_center_salt_pans, 3),
  8031. (party_set_slot, "p_town_2", slot_center_fishing_fleet, 25),
  8032. (party_set_slot, "p_town_2", slot_center_linen_looms, 15),
  8033.  
  8034. #Veluca (wine, velvet)
  8035. (party_set_slot, "p_town_3", slot_center_wine_presses, 10),
  8036. (party_set_slot, "p_town_3", slot_center_silk_looms, 12),
  8037.  
  8038. #Suno (velvet, oil)
  8039. (party_set_slot, "p_town_4", slot_center_silk_looms, 12),
  8040. (party_set_slot, "p_town_4", slot_center_olive_presses, 15),
  8041.  
  8042. #Jelkala (velvet, smoked fish)
  8043. (party_set_slot, "p_town_5", slot_center_silk_looms, 24),
  8044. (party_set_slot, "p_town_5", slot_center_fishing_fleet, 30),
  8045.  
  8046. #Praven (ale, leatherwork, smoked fish)
  8047. (party_set_slot, "p_town_6", slot_center_breweries, 10),
  8048. (party_set_slot, "p_town_6", slot_center_tanneries, 4),
  8049. (party_set_slot, "p_town_6", slot_center_fishing_fleet, 10),
  8050.  
  8051. #Uxkhal (bread, leatherwork, oil)
  8052. (party_set_slot, "p_town_7", slot_center_mills, 15),
  8053. (party_set_slot, "p_town_7", slot_center_tanneries, 4),
  8054. (party_set_slot, "p_town_7", slot_center_olive_presses, 5),
  8055.  
  8056. #Reyvadin (tools, wool cloth, wine)
  8057. (party_set_slot, "p_town_8", slot_center_smithies, 25),
  8058. (party_set_slot, "p_town_8", slot_center_wool_looms, 35),
  8059. (party_set_slot, "p_town_8", slot_center_wine_presses, 4),
  8060.  
  8061. #Khudan (tools, leatherwork, smoked fish)
  8062. (party_set_slot, "p_town_9", slot_center_smithies, 18),
  8063. (party_set_slot, "p_town_9", slot_center_tanneries, 3),
  8064. (party_set_slot, "p_town_9", slot_center_fishing_fleet, 5),
  8065.  
  8066. #Tulga (salt, spice)
  8067. (party_set_slot, "p_town_10", slot_center_salt_pans, 2),
  8068. #also produces 100 spice
  8069.  
  8070. #Curaw (tools, iron, smoked fish)
  8071. (party_set_slot, "p_town_11", slot_center_smithies, 19),
  8072. (party_set_slot, "p_town_11", slot_center_iron_deposits, 10),
  8073. (party_set_slot, "p_town_11", slot_center_fishing_fleet, 10),
  8074.  
  8075. #Wercheg (salt, smoked fish)
  8076. (party_set_slot, "p_town_12", slot_center_salt_pans, 3),
  8077. (party_set_slot, "p_town_12", slot_center_fishing_fleet, 25),
  8078.  
  8079. #Rivacheg (wool cloth, leatherwork, smoked fish)
  8080. (party_set_slot, "p_town_13", slot_center_wool_looms, 30),
  8081. (party_set_slot, "p_town_13", slot_center_tanneries, 5),
  8082. (party_set_slot, "p_town_13", slot_center_fishing_fleet, 20),
  8083.  
  8084. #Halmar (leatherwork, pottery)
  8085. (party_set_slot, "p_town_14", slot_center_tanneries, 3),
  8086. (party_set_slot, "p_town_14", slot_center_pottery_kilns, 18),
  8087.  
  8088. #Yalen (tools, wine, oil, smoked fish)
  8089. (party_set_slot, "p_town_15", slot_center_smithies, 20),
  8090. (party_set_slot, "p_town_15", slot_center_wine_presses, 6),
  8091. (party_set_slot, "p_town_15", slot_center_olive_presses, 5),
  8092. (party_set_slot, "p_town_15", slot_center_fishing_fleet, 25),
  8093.  
  8094. #Dhirim (tools, leatherwork)
  8095. (party_set_slot, "p_town_16", slot_center_smithies, 30),
  8096. (party_set_slot, "p_town_16", slot_center_tanneries, 4),
  8097.  
  8098. #Ichamur (wool cloth, spice)
  8099. (party_set_slot, "p_town_17", slot_center_wool_looms, 40),
  8100. #also produces 50 spice
  8101.  
  8102. #Narra (wool cloth, oil)
  8103. (party_set_slot, "p_town_18", slot_center_wool_looms, 35),
  8104. (party_set_slot, "p_town_18", slot_center_olive_presses, 10),
  8105.  
  8106. #Shariz (leatherwork, smoked fish, oil)
  8107. (party_set_slot, "p_town_19", slot_center_tanneries, 5),
  8108. (party_set_slot, "p_town_19", slot_center_breweries, 0), #no alcohol (ale) in arabic region
  8109. (party_set_slot, "p_town_19", slot_center_wine_presses, 0), #no alcohol (wine) in arabic region
  8110. (party_set_slot, "p_town_19", slot_center_fishing_fleet, 5),
  8111. (party_set_slot, "p_town_19", slot_center_olive_presses, 5),
  8112. #also produces 50 spice
  8113.  
  8114. #Darquba (linen, pottery, oil)
  8115. (party_set_slot, "p_town_20", slot_center_breweries, 0), #no alcohol (ale) in arabic region
  8116. (party_set_slot, "p_town_20", slot_center_wine_presses, 0), #no alcohol (wine) in arabic region
  8117. (party_set_slot, "p_town_20", slot_center_linen_looms, 15),
  8118. (party_set_slot, "p_town_20", slot_center_pottery_kilns, 12),
  8119. (party_set_slot, "p_town_19", slot_center_olive_presses, 3),
  8120.  
  8121. #Ahmerrad (pottery, salt)
  8122. (party_set_slot, "p_town_21", slot_center_breweries, 0), #no alcohol (ale) in arabic region
  8123. (party_set_slot, "p_town_21", slot_center_wine_presses, 0), #no alcohol (wine) in arabic region
  8124. (party_set_slot, "p_town_21", slot_center_pottery_kilns, 24),
  8125. (party_set_slot, "p_town_21", slot_center_salt_pans, 1),
  8126.  
  8127. #Bariyye (salt, pottery, spice)
  8128. (party_set_slot, "p_town_22", slot_center_breweries, 0), #no alcohol (ale) in arabic region
  8129. (party_set_slot, "p_town_22", slot_center_wine_presses, 0), #no alcohol (wine) in arabic region
  8130. (party_set_slot, "p_town_22", slot_center_pottery_kilns, 12),
  8131. (party_set_slot, "p_town_22", slot_center_salt_pans, 2),
  8132. #also produces 50 spice
  8133.  
  8134. (try_for_range, ":village_no", villages_begin, villages_end),
  8135. (try_begin),
  8136. ##diplomacy start+ Replace the explicit "is desert" list with a terrain check.
  8137. ##This is less brittle to map changes.
  8138. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),#In Diplomacy this is true at the start of the module, but the player could re-initialize economic stats during the game with cheat codes, or derived mods could change the default.
  8139. (party_get_current_terrain, ":village_is_at_desert", ":village_no"),#Will be changed to either 0 or 1
  8140. (this_or_next|eq, ":village_is_at_desert", rt_desert),
  8141. (eq, ":village_is_at_desert", rt_desert_forest),#If false, will fall through and be assigned to 0 below
  8142. (assign, ":village_is_at_desert", 1),
  8143. (else_try),
  8144. (lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW), #Fall back to old behavior
  8145. ##diplomacy end+
  8146. (this_or_next|eq, ":village_no", "p_village_93"), #mazigh
  8147. (this_or_next|eq, ":village_no", "p_village_94"), #sekhtem
  8148. (this_or_next|eq, ":village_no", "p_village_95"), #qalyut
  8149. (this_or_next|eq, ":village_no", "p_village_96"), #tilimsal
  8150. (this_or_next|eq, ":village_no", "p_village_97"), #shibal zumr
  8151. (this_or_next|eq, ":village_no", "p_village_102"), #tamnuh
  8152. (this_or_next|eq, ":village_no", "p_village_109"), #habba
  8153. (this_or_next|eq, ":village_no", "p_village_98"), #mawiti
  8154. (this_or_next|eq, ":village_no", "p_village_103"), #mijayet
  8155. (this_or_next|eq, ":village_no", "p_village_105"), #aab
  8156. (this_or_next|eq, ":village_no", "p_village_99"), #fishara
  8157. (this_or_next|eq, ":village_no", "p_village_100"), #iqbayl
  8158. (this_or_next|eq, ":village_no", "p_village_107"), #unriya
  8159. (this_or_next|eq, ":village_no", "p_village_101"), #uzgha
  8160. (this_or_next|eq, ":village_no", "p_village_104"), #tazjunat
  8161. (this_or_next|eq, ":village_no", "p_village_110"), #rushdigh
  8162. (this_or_next|eq, ":village_no", "p_village_108"), #mit nun
  8163. (eq, ":village_no", "p_village_92"), #dhibbain
  8164.  
  8165. (assign, ":village_is_at_desert", 1),
  8166. (else_try),
  8167. (assign, ":village_is_at_desert", 0),
  8168. (try_end),
  8169.  
  8170. (store_random_in_range, ":random_cattle", 20, 100),
  8171. (try_begin),
  8172. (eq, ":village_is_at_desert", 1),
  8173. (val_div, ":random_cattle", 5),
  8174. (try_end),
  8175. (party_set_slot, ":village_no", slot_center_head_cattle, ":random_cattle"), #average : 50, min : 25, max : 75
  8176.  
  8177. (store_random_in_range, ":random_sheep", 40, 200),
  8178. (try_begin),
  8179. (eq, ":village_is_at_desert", 1),
  8180. (val_div, ":random_sheep", 5),
  8181. (try_end),
  8182. (party_set_slot, ":village_no", slot_center_head_sheep, ":random_sheep"), #average : 100, min : 50, max : 150
  8183.  
  8184. #grain production
  8185. (store_random_in_range, ":random_value_between_0_and_40000", 0, 40000),
  8186. (store_random_in_range, ":random_value_between_0_and_average_20000", 0, ":random_value_between_0_and_40000"),
  8187. (try_begin),
  8188. (eq, ":village_is_at_desert", 1),
  8189. (val_div, ":random_value_between_0_and_average_20000", 5),
  8190. (try_end),
  8191. (party_set_slot, ":village_no", slot_center_acres_grain, ":random_value_between_0_and_average_20000"), #average : 10000, min : 0, max : 40000
  8192.  
  8193. #grape production
  8194. (store_random_in_range, ":random_value_between_0_and_2000", 0, 2000),
  8195. (store_random_in_range, ":random_value_between_0_and_average_1000", 0, ":random_value_between_0_and_2000"),
  8196. (try_begin),
  8197. (eq, ":village_is_at_desert", 1),
  8198. (val_div, ":random_value_between_0_and_average_1000", 5),
  8199. (try_end),
  8200. (party_set_slot, ":village_no", slot_center_acres_vineyard, ":random_value_between_0_and_average_1000"), #average : 500, min : 0, max : 2000
  8201.  
  8202. #olive production
  8203. (store_random_in_range, ":random_value_between_0_and_2000", 0, 2000),
  8204. (store_random_in_range, ":random_value_between_0_and_average_1000", 0, ":random_value_between_0_and_2000"),
  8205. (try_begin),
  8206. (eq, ":village_is_at_desert", 1),
  8207. (val_div, ":random_value_between_0_and_average_1000", 5),
  8208. (try_end),
  8209. (party_set_slot, ":village_no", slot_center_acres_olives, ":random_value_between_0_and_average_1000"), #average : 500, min : 0, max : 2000
  8210.  
  8211. #honey production
  8212. (store_random_in_range, ":random_value_between_0_and_3", 0, 3),
  8213. (try_begin),
  8214. (eq, ":village_is_at_desert", 1),
  8215. (assign, ":random_value_between_0_and_3", 0), #at desert regions no honey production
  8216. (try_end),
  8217. (party_set_slot, ":village_no", slot_center_apiaries, ":random_value_between_0_and_3"),
  8218.  
  8219. #cabbage and fruit production
  8220. (store_random_in_range, ":random_value_between_0_and_5", 0, 5),
  8221. (try_begin),
  8222. (eq, ":village_is_at_desert", 1),
  8223. (assign, ":random_value_between_0_and_5", 0), #at desert regions no cabbage and fruit production
  8224. (try_end),
  8225. (party_set_slot, ":village_no", slot_center_household_gardens, ":random_value_between_0_and_5"),
  8226.  
  8227. #bread production
  8228. (store_random_in_range, ":random_value_between_0_and_3", 0, 3),
  8229. (party_set_slot, ":village_no", slot_center_mills, ":random_value_between_0_and_3"),
  8230.  
  8231. #pottery production
  8232. (store_random_in_range, ":random_value_between_0_and_5", 0, 5),
  8233. (try_begin),
  8234. (eq, ":village_is_at_desert", 1),
  8235. (val_mul, ":random_value_between_0_and_5", 5), #at desert regions pottery production 4x more than normal (totally 5x)
  8236. (try_end),
  8237. (party_set_slot, ":village_no", slot_center_pottery_kilns, ":random_value_between_0_and_5"),
  8238.  
  8239. #Sargoth (village productions : Ambean, Fearichen and Fenada)
  8240. (try_begin),
  8241. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_1"),
  8242. (party_set_slot, ":village_no", slot_center_acres_flax, 4000),
  8243. (party_set_slot, ":village_no", slot_center_acres_vineyard, 8000),
  8244.  
  8245. #Tihr (village productions : Kulum, Haen and Aldelen)
  8246. (else_try),
  8247. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_2"),
  8248. (party_set_slot, ":village_no", slot_center_acres_vineyard, 8000),
  8249. (party_set_slot, ":village_no", slot_center_household_gardens, 10),
  8250.  
  8251. #Veluca (village productions : Emer, Fedner, Chaeza and Sarimish)
  8252. (else_try),
  8253. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_3"),
  8254. (party_set_slot, ":village_no", slot_center_acres_vineyard, 6000),
  8255. (party_set_slot, ":village_no", slot_center_acres_olives, 6000),
  8256.  
  8257. #Suno (village productions : Ruluns and Lyindah)
  8258. (else_try),
  8259. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_4"),
  8260. (party_set_slot, ":village_no", slot_center_fur_traps, 2),
  8261. (party_set_slot, ":village_no", slot_center_acres_olives, 8000),
  8262.  
  8263. #Jelkala (village productions : Buvran, Ruldi and Chelez)
  8264. (else_try),
  8265. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_5"),
  8266. (party_set_slot, ":village_no", slot_center_silk_farms, 1500),
  8267. (party_set_slot, ":village_no", slot_center_kirmiz_farms, 1500),
  8268.  
  8269. #Praven (village productions : Azgad, Veidar, Elberl and Gisim)
  8270. (else_try),
  8271. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_6"),
  8272. (party_set_slot, ":village_no", slot_center_acres_flax, 4000),
  8273. (party_set_slot, ":village_no", slot_center_breweries, 4),
  8274.  
  8275. #Uxkhal (village productions : Nomar, Ibiran and Tahlberl)
  8276. (else_try),
  8277. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_7"),
  8278. (party_set_slot, ":village_no", slot_center_fur_traps, 1),
  8279. (party_set_slot, ":village_no", slot_center_acres_olives, 8000),
  8280. (party_set_slot, ":village_no", slot_center_apiaries, 8),
  8281.  
  8282. #Reyvadin (village productions : Ulburban and Ayyike)
  8283. (else_try),
  8284. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_8"),
  8285. (party_set_slot, ":village_no", slot_center_fur_traps, 2),
  8286. (party_set_slot, ":village_no", slot_center_head_cattle, 100),
  8287. (party_set_slot, ":village_no", slot_center_iron_deposits, 6),
  8288.  
  8289. #Khudan (village productions : Uslum, Shulus and Tismirr)
  8290. (else_try),
  8291. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_9"),
  8292. (party_set_slot, ":village_no", slot_center_fur_traps, 2),
  8293. (party_set_slot, ":village_no", slot_center_acres_olives, 4000),
  8294.  
  8295. #Tulga (village productions : Dusturil and Dashbigha)
  8296. (else_try),
  8297. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_10"),
  8298. (party_set_slot, ":village_no", slot_center_head_sheep, 150),
  8299. (party_set_slot, ":village_no", slot_center_salt_pans, 1),
  8300. (party_set_slot, ":village_no", slot_center_fur_traps, 1),
  8301. (party_set_slot, ":village_no", slot_center_apiaries, 8),
  8302.  
  8303. #Curaw (village productions : Bazeck and Rebache)
  8304. (else_try),
  8305. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_11"),
  8306. (party_set_slot, ":village_no", slot_center_iron_deposits, 6),
  8307. (party_set_slot, ":village_no", slot_center_fur_traps, 2),
  8308.  
  8309. #Wercheg (village productions : Ruvar and Odasan)
  8310. (else_try),
  8311. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_12"),
  8312. (party_set_slot, ":village_no", slot_center_acres_vineyard, 8000),
  8313. (party_set_slot, ":village_no", slot_center_household_gardens, 10),
  8314. (party_set_slot, ":village_no", slot_center_salt_pans, 1),
  8315.  
  8316. #Rivacheg (village productions : Shapeshte, Vezin and Fisdnar)
  8317. (else_try),
  8318. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_13"),
  8319. (party_set_slot, ":village_no", slot_center_fur_traps, 2),
  8320. (party_set_slot, ":village_no", slot_center_head_cattle, 100),
  8321. (party_set_slot, ":village_no", slot_center_silk_farms, 1500),
  8322.  
  8323. #Halmar (village productions : Peshmi)
  8324. (else_try),
  8325. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_14"),
  8326. (party_set_slot, ":village_no", slot_center_acres_grain, 40000),
  8327. (party_set_slot, ":village_no", slot_center_mills, 5),
  8328.  
  8329. #Yalen (village productions : Ilvia, Glunmar, Epeshe and Istiniar)
  8330. (else_try),
  8331. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_15"),
  8332. (party_set_slot, ":village_no", slot_center_acres_vineyard, 8000),
  8333. (party_set_slot, ":village_no", slot_center_acres_olives, 8000),
  8334. (party_set_slot, ":village_no", slot_center_household_gardens, 10),
  8335.  
  8336. #Dhirim (village productions : Burglen, Amere, Ushkuru, Tshibtin and Yalibe)
  8337. (else_try),
  8338. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_16"),
  8339. (party_set_slot, ":village_no", slot_center_acres_grain, 40000),
  8340. (party_set_slot, ":village_no", slot_center_iron_deposits, 3),
  8341. (party_set_slot, ":village_no", slot_center_mills, 5),
  8342.  
  8343. #Ichamur (village productions : Ada Kulun and Drigh Aban)
  8344. (else_try),
  8345. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_17"),
  8346. (party_set_slot, ":village_no", slot_center_acres_grain, 20000),
  8347. (party_set_slot, ":village_no", slot_center_fur_traps, 1),
  8348.  
  8349. #Narra (village productions : Zagush and Kedelke)
  8350. (else_try),
  8351. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_18"),
  8352. (party_set_slot, ":village_no", slot_center_acres_grain, 20000),
  8353. (party_set_slot, ":village_no", slot_center_iron_deposits, 3),
  8354. (party_set_slot, ":village_no", slot_center_apiaries, 8),
  8355. (party_set_slot, ":village_no", slot_center_acres_flax, 4000),
  8356.  
  8357. #Shariz (village productions : Ayn Assuadi, Dhibbain, Qalyut, Tilimsal and Rushdigh)
  8358. (else_try),
  8359. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_19"),
  8360. (party_set_slot, ":village_no", slot_center_acres_grain, 6000), #low grain (partially desert)
  8361. (party_set_slot, ":village_no", slot_center_acres_flax, 2000),
  8362. (party_set_slot, ":village_no", slot_center_acres_olives, 3000),
  8363. (party_set_slot, ":village_no", slot_center_acres_dates, 5000),
  8364.  
  8365. #Durquba (village productions : Tamnuh and Sekhtem)
  8366. (else_try),
  8367. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_20"),
  8368. (party_set_slot, ":village_no", slot_center_acres_grain, 3000), #low grain (heavy desert)
  8369. (party_set_slot, ":village_no", slot_center_acres_dates, 10000),
  8370. (party_set_slot, ":village_no", slot_center_salt_pans, 1),
  8371.  
  8372. #Ahmerrad (village productions : Mawiti, Uzgha and Mijayet)
  8373. (else_try),
  8374. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_21"),
  8375. (party_set_slot, ":village_no", slot_center_acres_grain, 3000), #low grain (heavy desert)
  8376. (party_set_slot, ":village_no", slot_center_acres_dates, 5000),
  8377. (party_set_slot, ":village_no", slot_center_kirmiz_farms, 1500),
  8378.  
  8379. #Bariyye (village productions : Fishara and Iqbayl)
  8380. (else_try),
  8381. (party_slot_eq, ":village_no", slot_village_market_town, "p_town_22"),
  8382. (party_set_slot, ":village_no", slot_center_acres_grain, 2000), #low grain (heavy desert)
  8383. (party_set_slot, ":village_no", slot_center_acres_flax, 2000),
  8384. (party_set_slot, ":village_no", slot_center_acres_dates, 10000),
  8385. (party_set_slot, ":village_no", slot_center_salt_pans, 1),
  8386. (party_set_slot, ":village_no", slot_center_kirmiz_farms, 1500),
  8387.  
  8388. (try_end),
  8389. (try_end),
  8390.  
  8391. #determining village productions which are bounded by castle by nearby village productions which are bounded by a town.
  8392. (try_for_range, ":village_no", villages_begin, villages_end),
  8393. (party_get_slot, ":bound_center", ":village_no", slot_village_bound_center),
  8394. (is_between, ":bound_center", castles_begin, castles_end),
  8395.  
  8396. (try_for_range, ":cur_production_source", slot_production_sources_begin, slot_production_sources_end),
  8397.  
  8398. (assign, ":total_averaged_production", 0),
  8399. (try_for_range, ":effected_village_no", villages_begin, villages_end),
  8400. (party_get_slot, ":bound_center", ":effected_village_no", slot_village_bound_center),
  8401. (is_between, ":bound_center", towns_begin, towns_end),
  8402.  
  8403. (store_distance_to_party_from_party, ":dist", ":village_no", ":effected_village_no"),
  8404. (le, ":dist", 72),
  8405.  
  8406. (party_get_slot, ":production", ":village_no", ":cur_production_source"),
  8407.  
  8408. (store_add, ":dist_plus_24", ":dist", 24),
  8409. (store_mul, ":production_mul_12", ":production", 12),
  8410. (store_div, ":averaged_production", ":production_mul_12", ":dist_plus_24"), #if close (12/24=1/2) else (12/96=1/8)
  8411. (val_div, ":averaged_production", 2), #if close (1/4) else (1/16)
  8412. (val_add, ":total_averaged_production", ":averaged_production"),
  8413. (try_end),
  8414.  
  8415. (party_set_slot, ":village_no", ":cur_production_source", ":total_averaged_production"),
  8416. (try_end),
  8417. (try_end),
  8418.  
  8419. #Ocean and river villages, new map
  8420. (party_set_slot, "p_village_1", slot_center_fishing_fleet, 15), #Yaragar
  8421. (party_set_slot, "p_village_3", slot_center_fishing_fleet, 15), #Azgad
  8422. (party_set_slot, "p_village_5", slot_center_fishing_fleet, 15), #Kulum
  8423.  
  8424. (party_set_slot, "p_village_8", slot_center_fishing_fleet, 15), #Haen
  8425. (party_set_slot, "p_village_9", slot_center_fishing_fleet, 15), #Buvran
  8426.  
  8427. (party_set_slot, "p_village_20", slot_center_fishing_fleet, 15), #Uslum
  8428. (party_set_slot, "p_village_21", slot_center_fishing_fleet, 15), #Bazeck
  8429. (party_set_slot, "p_village_23", slot_center_fishing_fleet, 15), #Ilvia
  8430. (party_set_slot, "p_village_27", slot_center_fishing_fleet, 15), #Glunmar
  8431.  
  8432. (party_set_slot, "p_village_30", slot_center_fishing_fleet, 20), #Ruvar
  8433. (party_set_slot, "p_village_31", slot_center_fishing_fleet, 15), #Ambean
  8434. (party_set_slot, "p_village_35", slot_center_fishing_fleet, 15), #Feacharin
  8435.  
  8436. (party_set_slot, "p_village_47", slot_center_fishing_fleet, 15), #Epeshe
  8437. (party_set_slot, "p_village_49", slot_center_fishing_fleet, 15), #Tismirr
  8438.  
  8439. (party_set_slot, "p_village_51", slot_center_fishing_fleet, 15), #Jelbegi
  8440. (party_set_slot, "p_village_56", slot_center_fishing_fleet, 15), #Fenada
  8441.  
  8442. (party_set_slot, "p_village_66", slot_center_fishing_fleet, 15), #Fisdnar
  8443. (party_set_slot, "p_village_68", slot_center_fishing_fleet, 15), #Ibdeles
  8444. (party_set_slot, "p_village_69", slot_center_fishing_fleet, 15), #Kwynn
  8445.  
  8446. (party_set_slot, "p_village_77", slot_center_fishing_fleet, 25), #Rizi - Estuary
  8447. (party_set_slot, "p_village_79", slot_center_fishing_fleet, 15), #Istiniar
  8448.  
  8449. (party_set_slot, "p_village_81", slot_center_fishing_fleet, 15), #Odasan
  8450. (party_set_slot, "p_village_85", slot_center_fishing_fleet, 15), #Ismirala
  8451. (party_set_slot, "p_village_87", slot_center_fishing_fleet, 15), #Udiniad
  8452.  
  8453. (party_set_slot, "p_village_90", slot_center_fishing_fleet, 15), #Jamiche
  8454.  
  8455. #Initialize pastureland
  8456. (try_for_range, ":center", centers_begin, centers_end),
  8457. (party_get_slot, ":head_cattle", ":center", slot_center_head_cattle),
  8458. (party_get_slot, ":head_sheep", ":center", slot_center_head_sheep),
  8459. (store_mul, ":num_acres", ":head_cattle", 4),
  8460. (val_add, ":num_acres", ":head_sheep"),
  8461. (val_add, ":num_acres", ":head_sheep"),
  8462. (val_mul, ":num_acres", 6),
  8463. (val_div, ":num_acres", 5),
  8464.  
  8465. (store_random_in_range, ":random", 60, 150),
  8466. (val_mul, ":num_acres", ":random"),
  8467. (val_div, ":num_acres", 100),
  8468.  
  8469. (party_set_slot, ":center", slot_center_acres_pasture, ":num_acres"),
  8470. (try_end),
  8471.  
  8472. #Initialize prices based on production, etc
  8473. (try_for_range, ":unused", 0, 3), #15 cycles = 45 days. For a village with -20 production, this should lead to approximate +1000, modified
  8474. (call_script, "script_update_trade_good_prices"), #changes prices based on production
  8475. (try_end),
  8476.  
  8477. #Initialize prosperity based on final prices
  8478. (try_for_range, ":center_no", centers_begin, centers_end),
  8479. (neg|is_between, ":center_no", castles_begin, castles_end),
  8480. (store_random_in_range, ":random_prosperity_adder", -10, 10),
  8481. (call_script, "script_get_center_ideal_prosperity", ":center_no"),
  8482. (assign, ":prosperity", reg0),
  8483. (val_add, ":prosperity", ":random_prosperity_adder"),
  8484. (val_clamp, ":prosperity", 0, 100),
  8485. (party_set_slot, ":center_no", slot_town_prosperity, ":prosperity"),
  8486. (try_end),
  8487.  
  8488. (call_script, "script_calculate_castle_prosperities_by_using_its_villages"),
  8489. ]),
  8490.  
  8491. #script_initialize_all_scene_prop_slots
  8492. # INPUT: arg1 = scene_prop_no
  8493. # OUTPUT: none
  8494. ("initialize_all_scene_prop_slots",
  8495. [
  8496. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_6m"),
  8497. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_8m"),
  8498. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_10m"),
  8499. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_12m"),
  8500. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_14m"),
  8501. (call_script, "script_initialize_scene_prop_slots", "spr_castle_e_sally_door_a"),
  8502. (call_script, "script_initialize_scene_prop_slots", "spr_castle_f_sally_door_a"),
  8503. (call_script, "script_initialize_scene_prop_slots", "spr_earth_sally_gate_left"),
  8504. (call_script, "script_initialize_scene_prop_slots", "spr_earth_sally_gate_right"),
  8505. (call_script, "script_initialize_scene_prop_slots", "spr_viking_keep_destroy_sally_door_left"),
  8506. (call_script, "script_initialize_scene_prop_slots", "spr_viking_keep_destroy_sally_door_right"),
  8507. (call_script, "script_initialize_scene_prop_slots", "spr_castle_f_door_a"),
  8508. (call_script, "script_initialize_scene_prop_slots", "spr_belfry_a"),
  8509. (call_script, "script_initialize_scene_prop_slots", "spr_belfry_b"),
  8510. (call_script, "script_initialize_scene_prop_slots", "spr_winch_b"),
  8511. ]),
  8512.  
  8513. #script_initialize_scene_prop_slots
  8514. # INPUT: arg1 = scene_prop_no
  8515. # OUTPUT: none
  8516. ("initialize_scene_prop_slots",
  8517. [
  8518. (store_script_param, ":scene_prop_no", 1),
  8519.  
  8520. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", ":scene_prop_no"),
  8521. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  8522. (scene_prop_get_instance, ":cur_instance_id", ":scene_prop_no", ":cur_instance"),
  8523. (try_for_range, ":cur_slot", 0, scene_prop_slots_end),
  8524. (scene_prop_set_slot, ":cur_instance_id", ":cur_slot", 0),
  8525. (try_end),
  8526. (try_end),
  8527. ]),
  8528.  
  8529. #script_use_item
  8530. # INPUT: arg1 = agent_id, arg2 = instance_id
  8531. # OUTPUT: none
  8532. ("use_item",
  8533. [
  8534. (store_script_param, ":instance_id", 1),
  8535. (store_script_param, ":user_id", 2),
  8536.  
  8537. (try_begin),
  8538. (game_in_multiplayer_mode),
  8539. (prop_instance_get_scene_prop_kind, ":scene_prop_id", ":instance_id"),
  8540. (eq, ":scene_prop_id", "spr_winch_b"),
  8541.  
  8542. (multiplayer_get_my_player, ":my_player_no"),
  8543.  
  8544. (this_or_next|gt, ":my_player_no", 0),
  8545. (neg|multiplayer_is_dedicated_server),
  8546.  
  8547. (ge, ":my_player_no", 0),
  8548. (player_get_agent_id, ":my_agent_id", ":my_player_no"),
  8549. (ge, ":my_agent_id", 0),
  8550. (agent_is_active, ":my_agent_id"),
  8551. (agent_get_team, ":my_team_no", ":my_agent_id"),
  8552. (eq, ":my_team_no", 0),
  8553.  
  8554. (scene_prop_get_slot, ":opened_or_closed", ":instance_id", scene_prop_open_or_close_slot),
  8555. (ge, ":user_id", 0),
  8556. (agent_is_active, ":user_id"),
  8557. (agent_get_player_id, ":user_player", ":user_id"),
  8558. (str_store_player_username, s7, ":user_player"),
  8559.  
  8560. (try_begin),
  8561. (eq, ":opened_or_closed", 0),
  8562. (display_message, "@{s7} opened the gate"),
  8563. (else_try),
  8564. (display_message, "@{s7} closed the gate"),
  8565. (try_end),
  8566. (try_end),
  8567.  
  8568. (prop_instance_get_scene_prop_kind, ":scene_prop_id", ":instance_id"),
  8569.  
  8570. (try_begin),
  8571. (this_or_next|eq, ":scene_prop_id", "spr_winch_b"),
  8572. (eq, ":scene_prop_id", "spr_winch"),
  8573. (assign, ":effected_object", "spr_portcullis"),
  8574. (else_try),
  8575. (this_or_next|eq, ":scene_prop_id", "spr_door_destructible"),
  8576. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_door_b"),
  8577. (this_or_next|eq, ":scene_prop_id", "spr_castle_e_sally_door_a"),
  8578. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_sally_door_a"),
  8579. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_left"),
  8580. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_right"),
  8581. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_left"),
  8582. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_right"),
  8583. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_door_a"),
  8584. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_6m"),
  8585. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_8m"),
  8586. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_10m"),
  8587. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_12m"),
  8588. (eq, ":scene_prop_id", "spr_siege_ladder_move_14m"),
  8589. (assign, ":effected_object", ":scene_prop_id"),
  8590. (try_end),
  8591.  
  8592. (assign, ":smallest_dist", -1),
  8593. (prop_instance_get_position, pos0, ":instance_id"),
  8594. (scene_prop_get_num_instances, ":num_instances_of_effected_object", ":effected_object"),
  8595. (try_for_range, ":cur_instance", 0, ":num_instances_of_effected_object"),
  8596. (scene_prop_get_instance, ":cur_instance_id", ":effected_object", ":cur_instance"),
  8597. (prop_instance_get_position, pos1, ":cur_instance_id"),
  8598. (get_sq_distance_between_positions, ":dist", pos0, pos1),
  8599. (this_or_next|eq, ":smallest_dist", -1),
  8600. (lt, ":dist", ":smallest_dist"),
  8601. (assign, ":smallest_dist", ":dist"),
  8602. (assign, ":effected_object_instance_id", ":cur_instance_id"),
  8603. (try_end),
  8604.  
  8605. (try_begin),
  8606. (ge, ":instance_id", 0),
  8607. (ge, ":smallest_dist", 0),
  8608.  
  8609. (try_begin),
  8610. (eq, ":effected_object", "spr_portcullis"),
  8611. (scene_prop_get_slot, ":opened_or_closed", ":instance_id", scene_prop_open_or_close_slot),
  8612.  
  8613. (try_begin),
  8614. (eq, ":opened_or_closed", 0), #open gate
  8615.  
  8616. (scene_prop_enable_after_time, ":instance_id", 400), #4 seconds
  8617. (try_begin),
  8618. (this_or_next|multiplayer_is_server),
  8619. (neg|game_in_multiplayer_mode),
  8620. (prop_instance_get_position, pos0, ":effected_object_instance_id"),
  8621. (position_move_z, pos0, 375),
  8622. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 400),
  8623. (try_end),
  8624. (scene_prop_set_slot, ":instance_id", scene_prop_open_or_close_slot, 1),
  8625.  
  8626. (try_begin),
  8627. (eq, ":scene_prop_id", "spr_winch_b"),
  8628. (this_or_next|multiplayer_is_server),
  8629. (neg|game_in_multiplayer_mode),
  8630. (prop_instance_get_position, pos1, ":instance_id"),
  8631. (prop_instance_rotate_to_position, ":instance_id", pos1, 400, 72000),
  8632. (try_end),
  8633. (else_try), #close gate
  8634. (scene_prop_enable_after_time, ":instance_id", 400), #4 seconds
  8635. (try_begin),
  8636. (this_or_next|multiplayer_is_server),
  8637. (neg|game_in_multiplayer_mode),
  8638. (prop_instance_get_position, pos0, ":effected_object_instance_id"),
  8639. (position_move_z, pos0, -375),
  8640. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 400),
  8641. (try_end),
  8642. (scene_prop_set_slot, ":instance_id", scene_prop_open_or_close_slot, 0),
  8643.  
  8644. (try_begin),
  8645. (eq, ":scene_prop_id", "spr_winch_b"),
  8646. (this_or_next|multiplayer_is_server),
  8647. (neg|game_in_multiplayer_mode),
  8648. (prop_instance_get_position, pos1, ":instance_id"),
  8649. (prop_instance_rotate_to_position, ":instance_id", pos1, 400, -72000),
  8650. (try_end),
  8651. (try_end),
  8652. (else_try),
  8653. (this_or_next|eq, ":effected_object", "spr_siege_ladder_move_6m"),
  8654. (this_or_next|eq, ":effected_object", "spr_siege_ladder_move_8m"),
  8655. (this_or_next|eq, ":effected_object", "spr_siege_ladder_move_10m"),
  8656. (this_or_next|eq, ":effected_object", "spr_siege_ladder_move_12m"),
  8657. (eq, ":effected_object", "spr_siege_ladder_move_14m"),
  8658.  
  8659. (try_begin),
  8660. (eq, ":effected_object", "spr_siege_ladder_move_6m"),
  8661. (assign, ":animation_time_drop", 120),
  8662. (assign, ":animation_time_elevate", 240),
  8663. (else_try),
  8664. (eq, ":effected_object", "spr_siege_ladder_move_8m"),
  8665. (assign, ":animation_time_drop", 140),
  8666. (assign, ":animation_time_elevate", 280),
  8667. (else_try),
  8668. (eq, ":effected_object", "spr_siege_ladder_move_10m"),
  8669. (assign, ":animation_time_drop", 160),
  8670. (assign, ":animation_time_elevate", 320),
  8671. (else_try),
  8672. (eq, ":effected_object", "spr_siege_ladder_move_12m"),
  8673. (assign, ":animation_time_drop", 190),
  8674. (assign, ":animation_time_elevate", 360),
  8675. (else_try),
  8676. (eq, ":effected_object", "spr_siege_ladder_move_14m"),
  8677. (assign, ":animation_time_drop", 230),
  8678. (assign, ":animation_time_elevate", 400),
  8679. (try_end),
  8680.  
  8681. (scene_prop_get_slot, ":opened_or_closed", ":instance_id", scene_prop_open_or_close_slot),
  8682.  
  8683. (try_begin),
  8684. (scene_prop_enable_after_time, ":effected_object_instance_id", ":animation_time_elevate"), #3 seconds in average
  8685. (eq, ":opened_or_closed", 0), #ladder at ground
  8686. (prop_instance_get_starting_position, pos0, ":effected_object_instance_id"),
  8687. (prop_instance_enable_physics, ":effected_object_instance_id", 0),
  8688. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 300),
  8689. (scene_prop_set_slot, ":effected_object_instance_id", scene_prop_open_or_close_slot, 1),
  8690. (else_try), #ladder at wall
  8691. (scene_prop_enable_after_time, ":effected_object_instance_id", ":animation_time_drop"), #1.5 seconds in average
  8692. (prop_instance_get_position, pos0, ":instance_id"),
  8693.  
  8694. (assign, ":smallest_dist", -1),
  8695. (try_for_range, ":entry_point_no", multi_entry_points_for_usable_items_start, multi_entry_points_for_usable_items_end),
  8696. (entry_point_get_position, pos1, ":entry_point_no"),
  8697. (get_sq_distance_between_positions, ":dist", pos0, pos1),
  8698. (this_or_next|eq, ":smallest_dist", -1),
  8699. (lt, ":dist", ":smallest_dist"),
  8700. (assign, ":smallest_dist", ":dist"),
  8701. (assign, ":nearest_entry_point", ":entry_point_no"),
  8702. (try_end),
  8703.  
  8704. (try_begin),
  8705. (ge, ":smallest_dist", 0),
  8706. (lt, ":smallest_dist", 22500), #max 15m distance
  8707. (entry_point_get_position, pos1, ":nearest_entry_point"),
  8708. (position_rotate_x, pos1, -90),
  8709. (scene_prop_set_slot, ":effected_object_instance_id", scene_prop_smoke_effect_done, 0),
  8710. (prop_instance_enable_physics, ":effected_object_instance_id", 0),
  8711. (prop_instance_animate_to_position, ":effected_object_instance_id", pos1, 130),
  8712. (try_end),
  8713.  
  8714. (scene_prop_set_slot, ":effected_object_instance_id", scene_prop_open_or_close_slot, 0),
  8715. (try_end),
  8716. (else_try),
  8717. (this_or_next|eq, ":effected_object", "spr_door_destructible"),
  8718. (this_or_next|eq, ":effected_object", "spr_castle_f_door_b"),
  8719. (this_or_next|eq, ":scene_prop_id", "spr_castle_e_sally_door_a"),
  8720. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_sally_door_a"),
  8721. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_left"),
  8722. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_right"),
  8723. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_left"),
  8724. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_right"),
  8725. (eq, ":scene_prop_id", "spr_castle_f_door_a"),
  8726.  
  8727. (assign, ":effected_object_instance_id", ":instance_id"),
  8728. (scene_prop_get_slot, ":opened_or_closed", ":effected_object_instance_id", scene_prop_open_or_close_slot),
  8729.  
  8730. (try_begin),
  8731. (eq, ":opened_or_closed", 0),
  8732.  
  8733. (prop_instance_get_starting_position, pos0, ":effected_object_instance_id"),
  8734.  
  8735. (scene_prop_enable_after_time, ":effected_object_instance_id", 100),
  8736.  
  8737. (try_begin),
  8738. (neg|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_left"),
  8739. (neg|eq, ":scene_prop_id", "spr_earth_sally_gate_left"),
  8740.  
  8741. (position_rotate_z, pos0, -85),
  8742. (else_try),
  8743. (position_rotate_z, pos0, 85),
  8744. (try_end),
  8745.  
  8746. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 100),
  8747.  
  8748. (scene_prop_set_slot, ":effected_object_instance_id", scene_prop_open_or_close_slot, 1),
  8749. (else_try),
  8750. (prop_instance_get_starting_position, pos0, ":effected_object_instance_id"),
  8751.  
  8752. (scene_prop_enable_after_time, ":effected_object_instance_id", 100),
  8753.  
  8754. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 100),
  8755.  
  8756. (scene_prop_set_slot, ":effected_object_instance_id", scene_prop_open_or_close_slot, 0),
  8757. (try_end),
  8758. (try_end),
  8759. (try_end),
  8760. ]),
  8761.  
  8762. #script_determine_team_flags
  8763. # INPUT: none
  8764. # OUTPUT: none
  8765. ("determine_team_flags",
  8766. [
  8767. (store_script_param, ":team_no", 1),
  8768.  
  8769. (try_begin),
  8770. (eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  8771.  
  8772. (try_begin),
  8773. (eq, ":team_no", 0),
  8774.  
  8775. (team_get_faction, ":team_faction_no", 0),
  8776. (try_begin),
  8777. (eq, ":team_faction_no", "fac_kingdom_1"),
  8778. (assign, "$team_1_flag_scene_prop", "spr_ctf_flag_kingdom_1"),
  8779. (else_try),
  8780. (eq, ":team_faction_no", "fac_kingdom_2"),
  8781. (assign, "$team_1_flag_scene_prop", "spr_ctf_flag_kingdom_2"),
  8782. (else_try),
  8783. (eq, ":team_faction_no", "fac_kingdom_3"),
  8784. (assign, "$team_1_flag_scene_prop", "spr_ctf_flag_kingdom_3"),
  8785. (else_try),
  8786. (eq, ":team_faction_no", "fac_kingdom_4"),
  8787. (assign, "$team_1_flag_scene_prop", "spr_ctf_flag_kingdom_4"),
  8788. (else_try),
  8789. (eq, ":team_faction_no", "fac_kingdom_5"),
  8790. (assign, "$team_1_flag_scene_prop", "spr_ctf_flag_kingdom_5"),
  8791. (else_try),
  8792. (eq, ":team_faction_no", "fac_kingdom_6"),
  8793. (assign, "$team_1_flag_scene_prop", "spr_ctf_flag_kingdom_6"),
  8794. (try_end),
  8795. (else_try),
  8796. (team_get_faction, ":team_faction_no", 1),
  8797. (try_begin),
  8798. (eq, ":team_faction_no", "fac_kingdom_1"),
  8799. (assign, "$team_2_flag_scene_prop", "spr_ctf_flag_kingdom_1"),
  8800. (else_try),
  8801. (eq, ":team_faction_no", "fac_kingdom_2"),
  8802. (assign, "$team_2_flag_scene_prop", "spr_ctf_flag_kingdom_2"),
  8803. (else_try),
  8804. (eq, ":team_faction_no", "fac_kingdom_3"),
  8805. (assign, "$team_2_flag_scene_prop", "spr_ctf_flag_kingdom_3"),
  8806. (else_try),
  8807. (eq, ":team_faction_no", "fac_kingdom_4"),
  8808. (assign, "$team_2_flag_scene_prop", "spr_ctf_flag_kingdom_4"),
  8809. (else_try),
  8810. (eq, ":team_faction_no", "fac_kingdom_5"),
  8811. (assign, "$team_2_flag_scene_prop", "spr_ctf_flag_kingdom_5"),
  8812. (else_try),
  8813. (eq, ":team_faction_no", "fac_kingdom_6"),
  8814. (assign, "$team_2_flag_scene_prop", "spr_ctf_flag_kingdom_6"),
  8815. (try_end),
  8816.  
  8817. (try_begin),
  8818. (eq, "$team_1_flag_scene_prop", "$team_2_flag_scene_prop"),
  8819. (assign, "$team_2_flag_scene_prop", "spr_ctf_flag_kingdom_7"),
  8820. (try_end),
  8821. (try_end),
  8822. (else_try),
  8823. (try_begin),
  8824. (eq, ":team_no", 0),
  8825.  
  8826. (team_get_faction, ":team_faction_no", 0),
  8827. (try_begin),
  8828. (eq, ":team_faction_no", "fac_kingdom_1"),
  8829. (assign, "$team_1_flag_scene_prop", "spr_headquarters_flag_swadian"),
  8830. (else_try),
  8831. (eq, ":team_faction_no", "fac_kingdom_2"),
  8832. (assign, "$team_1_flag_scene_prop", "spr_headquarters_flag_vaegir"),
  8833. (else_try),
  8834. (eq, ":team_faction_no", "fac_kingdom_3"),
  8835. (assign, "$team_1_flag_scene_prop", "spr_headquarters_flag_khergit"),
  8836. (else_try),
  8837. (eq, ":team_faction_no", "fac_kingdom_4"),
  8838. (assign, "$team_1_flag_scene_prop", "spr_headquarters_flag_nord"),
  8839. (else_try),
  8840. (eq, ":team_faction_no", "fac_kingdom_5"),
  8841. (assign, "$team_1_flag_scene_prop", "spr_headquarters_flag_rhodok"),
  8842. (else_try),
  8843. (eq, ":team_faction_no", "fac_kingdom_6"),
  8844. (assign, "$team_1_flag_scene_prop", "spr_headquarters_flag_sarranid"),
  8845. (try_end),
  8846. (else_try),
  8847. (team_get_faction, ":team_faction_no", 1),
  8848. (try_begin),
  8849. (eq, ":team_faction_no", "fac_kingdom_1"),
  8850. (assign, "$team_2_flag_scene_prop", "spr_headquarters_flag_swadian"),
  8851. (else_try),
  8852. (eq, ":team_faction_no", "fac_kingdom_2"),
  8853. (assign, "$team_2_flag_scene_prop", "spr_headquarters_flag_vaegir"),
  8854. (else_try),
  8855. (eq, ":team_faction_no", "fac_kingdom_3"),
  8856. (assign, "$team_2_flag_scene_prop", "spr_headquarters_flag_khergit"),
  8857. (else_try),
  8858. (eq, ":team_faction_no", "fac_kingdom_4"),
  8859. (assign, "$team_2_flag_scene_prop", "spr_headquarters_flag_nord"),
  8860. (else_try),
  8861. (eq, ":team_faction_no", "fac_kingdom_5"),
  8862. (assign, "$team_2_flag_scene_prop", "spr_headquarters_flag_rhodok"),
  8863. (else_try),
  8864. (eq, ":team_faction_no", "fac_kingdom_6"),
  8865. (assign, "$team_2_flag_scene_prop", "spr_headquarters_flag_sarranid"),
  8866. (try_end),
  8867.  
  8868. (try_begin),
  8869. (eq, "$team_1_flag_scene_prop", "$team_2_flag_scene_prop"),
  8870. (assign, "$team_2_flag_scene_prop", "spr_headquarters_flag_rebel"),
  8871. (try_end),
  8872. (try_end),
  8873. (try_end),
  8874. ]),
  8875.  
  8876.  
  8877. #script_calculate_flag_move_time
  8878. # INPUT: arg1 = number_of_total_agents_around_flag, arg2 = dist_between_flag_and_its_pole
  8879. # OUTPUT: reg0 = flag move time
  8880. ("calculate_flag_move_time",
  8881. [
  8882. (store_script_param, ":number_of_total_agents_around_flag", 1),
  8883. (store_script_param, ":dist_between_flag_and_its_target", 2),
  8884.  
  8885. (try_begin), #(if no one is around flag it again moves to its current owner situation but 5 times slower than normal)
  8886. (eq, ":number_of_total_agents_around_flag", 0),
  8887. (store_mul, reg0, ":dist_between_flag_and_its_target", 2500),#5.00 * 1.00 * (500 stable) = 2000
  8888. (else_try),
  8889. (eq, ":number_of_total_agents_around_flag", 1),
  8890. (store_mul, reg0, ":dist_between_flag_and_its_target", 500), #1.00 * (500 stable) = 500
  8891. (else_try),
  8892. (eq, ":number_of_total_agents_around_flag", 2),
  8893. (store_mul, reg0, ":dist_between_flag_and_its_target", 300), #0.60(0.60) * (500 stable) = 300
  8894. (else_try),
  8895. (eq, ":number_of_total_agents_around_flag", 3),
  8896. (store_mul, reg0, ":dist_between_flag_and_its_target", 195), #0.39(0.60 * 0.65) * (500 stable) = 195
  8897. (else_try),
  8898. (eq, ":number_of_total_agents_around_flag", 4),
  8899. (store_mul, reg0, ":dist_between_flag_and_its_target", 137), #0.273(0.60 * 0.65 * 0.70) * (500 stable) = 136.5 >rounding> 137
  8900. (else_try),
  8901. (eq, ":number_of_total_agents_around_flag", 5),
  8902. (store_mul, reg0, ":dist_between_flag_and_its_target", 102), #0.20475(0.60 * 0.65 * 0.70 * 0.75) * (500 stable) = 102.375 >rounding> 102
  8903. (else_try),
  8904. (eq, ":number_of_total_agents_around_flag", 6),
  8905. (store_mul, reg0, ":dist_between_flag_and_its_target", 82), #0.1638(0.60 * 0.65 * 0.70 * 0.75 * 0.80) * (500 stable) = 81.9 >rounding> 82
  8906. (else_try),
  8907. (eq, ":number_of_total_agents_around_flag", 7),
  8908. (store_mul, reg0, ":dist_between_flag_and_its_target", 66), #0.13104(0.60 * 0.65 * 0.70 * 0.75 * 0.80 * 0.85) * (500 stable) = 65.52 >rounding> 66
  8909. (else_try),
  8910. (eq, ":number_of_total_agents_around_flag", 8),
  8911. (store_mul, reg0, ":dist_between_flag_and_its_target", 59), #0.117936(0.60 * 0.65 * 0.70 * 0.75 * 0.80 * 0.85 * 0.90) * (500 stable) = 58.968 >rounding> 59
  8912. (else_try),
  8913. (store_mul, reg0, ":dist_between_flag_and_its_target", 56), #0.1120392(0.60 * 0.65 * 0.70 * 0.75 * 0.80 * 0.85 * 0.90 * 0.95) * (500 stable) = 56.0196 >rounding> 56
  8914. (try_end),
  8915.  
  8916. (assign, ":number_of_players", 0),
  8917. (get_max_players, ":num_players"),
  8918. (try_for_range, ":cur_player", 0, ":num_players"),
  8919. (player_is_active, ":cur_player"),
  8920. (val_add, ":number_of_players", 1),
  8921. (try_end),
  8922.  
  8923. (try_begin),
  8924. (lt, ":number_of_players", 10),
  8925. (val_mul, reg0, 50),
  8926. (else_try),
  8927. (lt, ":number_of_players", 35),
  8928. (store_sub, ":number_of_players_multipication", 35, ":number_of_players"),
  8929. (val_mul, ":number_of_players_multipication", 2),
  8930. (store_sub, ":number_of_players_multipication", 100, ":number_of_players_multipication"),
  8931. (val_mul, reg0, ":number_of_players_multipication"),
  8932. (else_try),
  8933. (val_mul, reg0, 100),
  8934. (try_end),
  8935.  
  8936. (try_begin),
  8937. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  8938. (val_mul, reg0, 2),
  8939. (try_end),
  8940.  
  8941. (val_div, reg0, 10000), #100x for number of players around flag, 100x for number of players in game
  8942. ]),
  8943.  
  8944. #script_move_death_mode_flags_down
  8945. # INPUT: none
  8946. # OUTPUT: none
  8947. ("move_death_mode_flags_down",
  8948. [
  8949. (try_begin),
  8950. (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
  8951. (prop_instance_get_position, pos0, ":pole_1_id"),
  8952. (position_move_z, pos0, -2000),
  8953. (prop_instance_set_position, ":pole_1_id", pos0),
  8954. (try_end),
  8955.  
  8956. (try_begin),
  8957. (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
  8958. (prop_instance_get_position, pos1, ":pole_2_id"),
  8959. (position_move_z, pos1, -2000),
  8960. (prop_instance_set_position, ":pole_2_id", pos1),
  8961. (try_end),
  8962.  
  8963. (try_begin),
  8964. (scene_prop_get_instance, ":pole_1_id", "spr_headquarters_pole_code_only", 0),
  8965. (prop_instance_get_position, pos0, ":pole_1_id"),
  8966. (scene_prop_get_instance, ":flag_1_id", "$team_1_flag_scene_prop", 0),
  8967. (prop_instance_stop_animating, ":flag_1_id"),
  8968. (position_move_z, pos0, multi_headquarters_flag_initial_height),
  8969. (prop_instance_set_position, ":flag_1_id", pos0),
  8970. (try_end),
  8971.  
  8972. (try_begin),
  8973. (scene_prop_get_instance, ":pole_2_id", "spr_headquarters_pole_code_only", 1),
  8974. (prop_instance_get_position, pos1, ":pole_2_id"),
  8975. (scene_prop_get_instance, ":flag_2_id", "$team_2_flag_scene_prop", 0),
  8976. (prop_instance_stop_animating, ":flag_2_id"),
  8977. (position_move_z, pos1, multi_headquarters_flag_initial_height),
  8978. (prop_instance_set_position, ":flag_2_id", pos1),
  8979. (try_end),
  8980. ]),
  8981.  
  8982. #script_move_flag
  8983. # INPUT: arg1 = shown_flag_id, arg2 = move time in seconds, pos0 = target position
  8984. # OUTPUT: none
  8985. ("move_flag",
  8986. [
  8987. (store_script_param, ":shown_flag_id", 1),
  8988. (store_script_param, ":shown_flag_move_time", 2),
  8989.  
  8990. (try_begin),
  8991. (multiplayer_is_server), #added after auto-animating
  8992.  
  8993. (try_begin),
  8994. (eq, ":shown_flag_move_time", 0), #stop
  8995. (prop_instance_stop_animating, ":shown_flag_id"),
  8996. (else_try),
  8997. (prop_instance_animate_to_position, ":shown_flag_id", pos0, ":shown_flag_move_time"),
  8998. (try_end),
  8999. (try_end),
  9000. ]),
  9001.  
  9002. #script_move_headquarters_flags
  9003. # INPUT: arg1 = current_owner, arg2 = number_of_agents_around_flag_team_1, arg3 = number_of_agents_around_flag_team_2
  9004. # OUTPUT: none
  9005. ("move_headquarters_flags",
  9006. [
  9007. (store_script_param, ":flag_no", 1),
  9008. (store_script_param, ":number_of_agents_around_flag_team_1", 2),
  9009. (store_script_param, ":number_of_agents_around_flag_team_2", 3),
  9010.  
  9011. (store_add, ":cur_flag_slot", multi_data_flag_owner_begin, ":flag_no"),
  9012. (troop_get_slot, ":current_owner", "trp_multiplayer_data", ":cur_flag_slot"),
  9013.  
  9014. (scene_prop_get_num_instances, ":num_instances", "spr_headquarters_flag_gray_code_only"),
  9015. (try_begin),
  9016. (assign, ":visibility", 0),
  9017. (lt, ":flag_no", ":num_instances"),
  9018. (scene_prop_get_instance, ":flag_id", "spr_headquarters_flag_gray_code_only", ":flag_no"),
  9019. (scene_prop_get_visibility, ":visibility", ":flag_id"),
  9020. (try_end),
  9021.  
  9022. (try_begin),
  9023. (eq, ":visibility", 1),
  9024. (assign, ":shown_flag", 0),
  9025. (assign, ":shown_flag_id", ":flag_id"),
  9026. (else_try),
  9027. (scene_prop_get_num_instances, ":num_instances", "$team_1_flag_scene_prop"),
  9028. (try_begin),
  9029. (assign, ":visibility", 0),
  9030. (lt, ":flag_no", ":num_instances"),
  9031. (scene_prop_get_instance, ":flag_id", "$team_1_flag_scene_prop", ":flag_no"),
  9032. (scene_prop_get_visibility, ":visibility", ":flag_id"),
  9033. (try_end),
  9034.  
  9035. #(scene_prop_get_instance, ":flag_id", "$team_1_flag_scene_prop", ":flag_no"),
  9036. #(scene_prop_get_visibility, ":visibility", ":flag_id"),
  9037. (try_begin),
  9038. (eq, ":visibility", 1),
  9039. (assign, ":shown_flag", 1),
  9040. (assign, ":shown_flag_id", ":flag_id"),
  9041. (else_try),
  9042. (scene_prop_get_num_instances, ":num_instances", "$team_2_flag_scene_prop"),
  9043. (try_begin),
  9044. (assign, ":visibility", 0),
  9045. (lt, ":flag_no", ":num_instances"),
  9046. (scene_prop_get_instance, ":flag_id", "$team_2_flag_scene_prop", ":flag_no"),
  9047. (scene_prop_get_visibility, ":visibility", ":flag_id"),
  9048. (try_end),
  9049.  
  9050. #(scene_prop_get_instance, ":flag_id", "$team_2_flag_scene_prop", ":flag_no"),
  9051. #(scene_prop_get_visibility, ":visibility", ":flag_id"),
  9052. (try_begin),
  9053. (eq, ":visibility", 1),
  9054. (assign, ":shown_flag", 2),
  9055. (assign, ":shown_flag_id", ":flag_id"),
  9056. (try_end),
  9057. (try_end),
  9058. (try_end),
  9059.  
  9060. (try_begin),
  9061. (scene_prop_get_instance, ":pole_id", "spr_headquarters_pole_code_only", ":flag_no"),
  9062. (try_end),
  9063.  
  9064. (try_begin),
  9065. (eq, ":shown_flag", ":current_owner"), #situation 1 : (current owner is equal shown flag)
  9066. (try_begin),
  9067. (ge, ":number_of_agents_around_flag_team_1", 1),
  9068. (ge, ":number_of_agents_around_flag_team_2", 1),
  9069. (assign, ":flag_movement", 0), #0:stop
  9070. (else_try),
  9071. (eq, ":number_of_agents_around_flag_team_1", 0),
  9072. (eq, ":number_of_agents_around_flag_team_2", 0),
  9073. (assign, ":flag_movement", 1), #1:rise (slow)
  9074. (else_try),
  9075. (try_begin),
  9076. (ge, ":number_of_agents_around_flag_team_1", 1),
  9077. (eq, ":number_of_agents_around_flag_team_2", 0),
  9078. (eq, ":current_owner", 1),
  9079. (assign, ":flag_movement", 1), #1:rise (fast)
  9080. (else_try),
  9081. (eq, ":number_of_agents_around_flag_team_1", 0),
  9082. (ge, ":number_of_agents_around_flag_team_2", 1),
  9083. (eq, ":current_owner", 2),
  9084. (assign, ":flag_movement", 1), #1:rise (fast)
  9085. (else_try),
  9086. (assign, ":flag_movement", -1), #-1:drop (fast)
  9087. (try_end),
  9088. (try_end),
  9089. (else_try), #situation 2 : (current owner is different than shown flag)
  9090. (try_begin),
  9091. (ge, ":number_of_agents_around_flag_team_1", 1),
  9092. (ge, ":number_of_agents_around_flag_team_2", 1),
  9093. (assign, ":flag_movement", 0), #0:stop
  9094. (else_try),
  9095. (eq, ":number_of_agents_around_flag_team_1", 0),
  9096. (eq, ":number_of_agents_around_flag_team_2", 0),
  9097. (assign, ":flag_movement", -1), #-1:drop (slow)
  9098. (else_try),
  9099. (try_begin),
  9100. (ge, ":number_of_agents_around_flag_team_1", 1),
  9101. (eq, ":number_of_agents_around_flag_team_2", 0),
  9102. (try_begin),
  9103. (eq, ":shown_flag", 1),
  9104. (assign, ":flag_movement", 1), #1:rise (fast)
  9105. (else_try),
  9106. (neq, ":current_owner", 1),
  9107. (assign, ":flag_movement", -1), #-1:drop (fast)
  9108. (try_end),
  9109. (else_try),
  9110. (eq, ":number_of_agents_around_flag_team_1", 0),
  9111. (ge, ":number_of_agents_around_flag_team_2", 1),
  9112. (try_begin),
  9113. (eq, ":shown_flag", 2),
  9114. (assign, ":flag_movement", 1), #1:rise (fast)
  9115. (else_try),
  9116. (neq, ":current_owner", 2),
  9117. (assign, ":flag_movement", -1), #-1:drop (fast)
  9118. (try_end),
  9119. (try_end),
  9120. (try_end),
  9121. (try_end),
  9122.  
  9123. (store_add, ":number_of_total_agents_around_flag", ":number_of_agents_around_flag_team_1", ":number_of_agents_around_flag_team_2"),
  9124.  
  9125. (try_begin),
  9126. (eq, ":flag_movement", 0),
  9127. (assign, reg0, 0),
  9128. (else_try),
  9129. (eq, ":flag_movement", 1),
  9130. (prop_instance_get_position, pos1, ":shown_flag_id"),
  9131. (prop_instance_get_position, pos0, ":pole_id"),
  9132. (position_move_z, pos0, multi_headquarters_pole_height),
  9133. (get_distance_between_positions, ":dist_between_flag_and_its_target", pos0, pos1),
  9134. (call_script, "script_calculate_flag_move_time", ":number_of_total_agents_around_flag", ":dist_between_flag_and_its_target"),
  9135. (else_try),
  9136. (eq, ":flag_movement", -1),
  9137. (prop_instance_get_position, pos1, ":shown_flag_id"),
  9138. (prop_instance_get_position, pos0, ":pole_id"),
  9139. (get_distance_between_positions, ":dist_between_flag_and_its_target", pos0, pos1),
  9140. (call_script, "script_calculate_flag_move_time", ":number_of_total_agents_around_flag", ":dist_between_flag_and_its_target"),
  9141. (try_end),
  9142.  
  9143. (call_script, "script_move_flag", ":shown_flag_id", reg0), #pos0 : target position
  9144. ]),
  9145.  
  9146. #script_set_num_agents_around_flag
  9147. # INPUT: arg1 = flag_no, arg2 = owner_code
  9148. # OUTPUT: none
  9149. ("set_num_agents_around_flag",
  9150. [
  9151. (store_script_param, ":flag_no", 1),
  9152. (store_script_param, ":current_owner_code", 2),
  9153.  
  9154. (store_div, ":number_of_agents_around_flag_team_1", ":current_owner_code", 100),
  9155. (store_mod, ":number_of_agents_around_flag_team_2", ":current_owner_code", 100),
  9156.  
  9157. (store_add, ":cur_flag_owner_counts_slot", multi_data_flag_players_around_begin, ":flag_no"),
  9158. (troop_set_slot, "trp_multiplayer_data", ":cur_flag_owner_counts_slot", ":current_owner_code"),
  9159.  
  9160. (call_script, "script_move_headquarters_flags", ":flag_no", ":number_of_agents_around_flag_team_1", ":number_of_agents_around_flag_team_2"),
  9161. ]),
  9162.  
  9163. #script_change_flag_owner
  9164. # INPUT: arg1 = flag_no, arg2 = owner_code
  9165. # OUTPUT: none
  9166. ("change_flag_owner",
  9167. [
  9168. (store_script_param, ":flag_no", 1),
  9169. (store_script_param, ":owner_code", 2),
  9170.  
  9171. (try_begin),
  9172. (lt, ":owner_code", 0),
  9173. (val_add, ":owner_code", 1),
  9174. (val_mul, ":owner_code", -1),
  9175. (try_end),
  9176.  
  9177. (store_div, ":owner_team_no", ":owner_code", 100),
  9178. (store_mod, ":shown_flag_no", ":owner_code", 100),
  9179.  
  9180. (store_add, ":cur_flag_slot", multi_data_flag_owner_begin, ":flag_no"),
  9181. (troop_get_slot, ":older_owner_team_no", "trp_multiplayer_data", ":cur_flag_slot"),
  9182.  
  9183. (store_add, ":cur_flag_slot", multi_data_flag_owner_begin, ":flag_no"),
  9184. (troop_set_slot, "trp_multiplayer_data", ":cur_flag_slot", ":owner_team_no"),
  9185.  
  9186. #senchronizing flag positions
  9187. (try_begin),
  9188. #(this_or_next|eq, ":initial_flags", 0), #moved after auto-animating
  9189. (multiplayer_is_server),
  9190.  
  9191. (scene_prop_get_instance, ":pole_id", "spr_headquarters_pole_code_only", ":flag_no"),
  9192. (try_begin),
  9193. (eq, ":owner_team_no", 0), #if new owner team is 0 then flags are at bottom
  9194. (neq, ":older_owner_team_no", -1), #clients
  9195. (assign, ":continue", 1),
  9196. (try_begin),
  9197. (multiplayer_is_server),
  9198. (eq, "$g_placing_initial_flags", 1),
  9199. (assign, ":continue", 0),
  9200. (try_end),
  9201. (eq, ":continue", 1),
  9202. (prop_instance_get_position, pos0, ":pole_id"),
  9203. (position_move_z, pos0, multi_headquarters_distance_to_change_flag),
  9204. (else_try),
  9205. (prop_instance_get_position, pos0, ":pole_id"), #if new owner team is not 0 then flags are at top
  9206. (position_move_z, pos0, multi_headquarters_pole_height),
  9207. (try_end),
  9208.  
  9209. (scene_prop_get_instance, ":flag_id", "$team_1_flag_scene_prop", ":flag_no"),
  9210. (prop_instance_stop_animating, ":flag_id"),
  9211. (prop_instance_set_position, ":flag_id", pos0),
  9212.  
  9213. (scene_prop_get_instance, ":flag_id", "$team_2_flag_scene_prop", ":flag_no"),
  9214. (prop_instance_stop_animating, ":flag_id"),
  9215. (prop_instance_set_position, ":flag_id", pos0),
  9216.  
  9217. (scene_prop_get_instance, ":flag_id", "spr_headquarters_flag_gray_code_only", ":flag_no"),
  9218. (prop_instance_stop_animating, ":flag_id"),
  9219. (prop_instance_set_position, ":flag_id", pos0),
  9220. (try_end),
  9221.  
  9222. #setting visibilities of flags
  9223. (try_begin),
  9224. (eq, ":shown_flag_no", 0),
  9225. (scene_prop_get_instance, ":flag_id", "$team_1_flag_scene_prop", ":flag_no"),
  9226. (scene_prop_set_visibility, ":flag_id", 0),
  9227. (scene_prop_get_instance, ":flag_id", "$team_2_flag_scene_prop", ":flag_no"),
  9228. (scene_prop_set_visibility, ":flag_id", 0),
  9229. (scene_prop_get_instance, ":flag_id", "spr_headquarters_flag_gray_code_only", ":flag_no"),
  9230. (scene_prop_set_visibility, ":flag_id", 1),
  9231. (else_try),
  9232. (eq, ":shown_flag_no", 1),
  9233. (scene_prop_get_instance, ":flag_id", "$team_1_flag_scene_prop", ":flag_no"),
  9234. (scene_prop_set_visibility, ":flag_id", 1),
  9235. (scene_prop_get_instance, ":flag_id", "$team_2_flag_scene_prop", ":flag_no"),
  9236. (scene_prop_set_visibility, ":flag_id", 0),
  9237. (scene_prop_get_instance, ":flag_id", "spr_headquarters_flag_gray_code_only", ":flag_no"),
  9238. (scene_prop_set_visibility, ":flag_id", 0),
  9239. (else_try),
  9240. (eq, ":shown_flag_no", 2),
  9241. (scene_prop_get_instance, ":flag_id", "$team_1_flag_scene_prop", ":flag_no"),
  9242. (scene_prop_set_visibility, ":flag_id", 0),
  9243. (scene_prop_get_instance, ":flag_id", "$team_2_flag_scene_prop", ":flag_no"),
  9244. (scene_prop_set_visibility, ":flag_id", 1),
  9245. (scene_prop_get_instance, ":flag_id", "spr_headquarters_flag_gray_code_only", ":flag_no"),
  9246. (scene_prop_set_visibility, ":flag_id", 0),
  9247. (try_end),
  9248.  
  9249. #other
  9250. (store_add, ":cur_flag_players_around_slot", multi_data_flag_players_around_begin, ":flag_no"),
  9251. (troop_get_slot, ":players_around_code", "trp_multiplayer_data", ":cur_flag_players_around_slot"),
  9252.  
  9253. (store_div, ":number_of_agents_around_flag_team_1", ":players_around_code", 100),
  9254. (store_mod, ":number_of_agents_around_flag_team_2", ":players_around_code", 100),
  9255.  
  9256. (call_script, "script_move_headquarters_flags", ":flag_no", ":number_of_agents_around_flag_team_1", ":number_of_agents_around_flag_team_2"),
  9257. ]),
  9258.  
  9259. #script_move_object_to_nearest_entry_point
  9260. # INPUT: none
  9261. # OUTPUT: none
  9262. ("move_object_to_nearest_entry_point",
  9263. [
  9264. (store_script_param, ":scene_prop_no", 1),
  9265.  
  9266. (scene_prop_get_num_instances, ":num_instances", ":scene_prop_no"),
  9267.  
  9268. (try_for_range, ":instance_no", 0, ":num_instances"),
  9269. (scene_prop_get_instance, ":instance_id", ":scene_prop_no", ":instance_no"),
  9270. (prop_instance_get_position, pos0, ":instance_id"),
  9271.  
  9272. (assign, ":smallest_dist", -1),
  9273. (try_for_range, ":entry_point_no", multi_entry_points_for_usable_items_start, multi_entry_points_for_usable_items_end),
  9274. (entry_point_get_position, pos1, ":entry_point_no"),
  9275. (get_sq_distance_between_positions, ":dist", pos0, pos1),
  9276. (this_or_next|eq, ":smallest_dist", -1),
  9277. (lt, ":dist", ":smallest_dist"),
  9278. (assign, ":smallest_dist", ":dist"),
  9279. (assign, ":nearest_entry_point", ":entry_point_no"),
  9280. (try_end),
  9281.  
  9282. (try_begin),
  9283. (ge, ":smallest_dist", 0),
  9284. (lt, ":smallest_dist", 22500), #max 15m distance
  9285. (entry_point_get_position, pos1, ":nearest_entry_point"),
  9286. (position_rotate_x, pos1, -90),
  9287. (prop_instance_animate_to_position, ":instance_id", pos1, 1),
  9288. (try_end),
  9289. (try_end),
  9290. ]),
  9291.  
  9292.  
  9293. #script_multiplayer_server_on_agent_spawn_common
  9294. # INPUT: arg1 = agent_no
  9295. # OUTPUT: none
  9296. ("multiplayer_server_on_agent_spawn_common",
  9297. [
  9298. (store_script_param, ":agent_no", 1),
  9299. (agent_set_slot, ":agent_no", slot_agent_in_duel_with, -1),
  9300. (try_begin),
  9301. (agent_is_non_player, ":agent_no"),
  9302. (assign, "$g_multiplayer_ready_for_spawning_agent", 1),
  9303. (try_end),
  9304. ]),
  9305.  
  9306. #script_multiplayer_server_player_joined_common
  9307. # INPUT: arg1 = player_no
  9308. # OUTPUT: none
  9309. ("multiplayer_server_player_joined_common",
  9310. [
  9311. (store_script_param, ":player_no", 1),
  9312. (try_begin),
  9313. (this_or_next|player_is_active, ":player_no"),
  9314. (eq, ":player_no", 0),
  9315. (call_script, "script_multiplayer_init_player_slots", ":player_no"),
  9316. (store_mission_timer_a, ":player_join_time"),
  9317. (player_set_slot, ":player_no", slot_player_join_time, ":player_join_time"),
  9318. (player_set_slot, ":player_no", slot_player_first_spawn, 1),
  9319. #fight and destroy only
  9320. (player_set_slot, ":player_no", slot_player_damage_given_to_target_1, 0),
  9321. (player_set_slot, ":player_no", slot_player_damage_given_to_target_2, 0),
  9322. #fight and destroy only end
  9323. (try_begin),
  9324. (multiplayer_is_server),
  9325. (assign, ":initial_gold", multi_initial_gold_value),
  9326. (val_mul, ":initial_gold", "$g_multiplayer_initial_gold_multiplier"),
  9327. (val_div, ":initial_gold", 100),
  9328. (player_set_gold, ":player_no", ":initial_gold"),
  9329. (call_script, "script_multiplayer_send_initial_information", ":player_no"),
  9330. (try_end),
  9331. (try_end),
  9332. ]),
  9333.  
  9334. #script_multiplayer_server_before_mission_start_common
  9335. # INPUT: none
  9336. # OUTPUT: none
  9337. ("multiplayer_server_before_mission_start_common",
  9338. [
  9339. (try_begin),
  9340. (scene_allows_mounted_units),
  9341. (assign, "$g_horses_are_avaliable", 1),
  9342. (else_try),
  9343. (assign, "$g_horses_are_avaliable", 0),
  9344. (try_end),
  9345. (scene_set_day_time, 15),
  9346. (assign, "$g_multiplayer_mission_end_screen", 0),
  9347.  
  9348. (get_max_players, ":num_players"),
  9349. (try_for_range, ":player_no", 0, ":num_players"),
  9350. (player_is_active, ":player_no"),
  9351. (call_script, "script_multiplayer_init_player_slots", ":player_no"),
  9352. (assign, ":initial_gold", multi_initial_gold_value),
  9353. (val_mul, ":initial_gold", "$g_multiplayer_initial_gold_multiplier"),
  9354. (val_div, ":initial_gold", 100),
  9355. (player_set_gold, ":player_no", ":initial_gold"),
  9356. (player_set_slot, ":player_no", slot_player_first_spawn, 1), #not required in siege, bt, fd
  9357. (try_end),
  9358. ]),
  9359.  
  9360. #script_multiplayer_server_on_agent_killed_or_wounded_common
  9361. # INPUT: arg1 = dead_agent_no, arg2 = killer_agent_no
  9362. # OUTPUT: none
  9363. ("multiplayer_server_on_agent_killed_or_wounded_common",
  9364. [
  9365. (store_script_param, ":dead_agent_no", 1),
  9366. (store_script_param, ":killer_agent_no", 2),
  9367.  
  9368. (call_script, "script_multiplayer_event_agent_killed_or_wounded", ":dead_agent_no", ":killer_agent_no"),
  9369. #adding 1 score points to agent which kills enemy agent at server
  9370. (try_begin),
  9371. (multiplayer_is_server),
  9372. (try_begin), #killing myself because of some reason (friend hit, fall, team change)
  9373. (lt, ":killer_agent_no", 0),
  9374. (ge, ":dead_agent_no", 0),
  9375. (neg|agent_is_non_player, ":dead_agent_no"),
  9376. (agent_get_player_id, ":dead_agent_player_id", ":dead_agent_no"),
  9377. (player_is_active, ":dead_agent_player_id"),
  9378. (player_get_score, ":dead_agent_player_score", ":dead_agent_player_id"),
  9379. (val_add, ":dead_agent_player_score", -1),
  9380. (player_set_score, ":dead_agent_player_id", ":dead_agent_player_score"),
  9381. (else_try), #killing teammate
  9382. (ge, ":killer_agent_no", 0),
  9383. (ge, ":dead_agent_no", 0),
  9384. (agent_get_team, ":killer_team_no", ":killer_agent_no"),
  9385. (agent_get_team, ":dead_team_no", ":dead_agent_no"),
  9386. (eq, ":killer_team_no", ":dead_team_no"),
  9387. (neg|agent_is_non_player, ":killer_agent_no"),
  9388. (agent_get_player_id, ":killer_agent_player_id", ":killer_agent_no"),
  9389. (player_is_active, ":killer_agent_player_id"),
  9390. (player_get_score, ":killer_agent_player_score", ":killer_agent_player_id"),
  9391. (val_add, ":killer_agent_player_score", -1),
  9392. (player_set_score, ":killer_agent_player_id", ":killer_agent_player_score"),
  9393. #(player_get_kill_count, ":killer_agent_player_kill_count", ":killer_agent_player_id"),
  9394. #(val_add, ":killer_agent_player_kill_count", -2),
  9395. #(player_set_kill_count, ":killer_agent_player_id", ":killer_agent_player_kill_count"),
  9396. (else_try), #killing enemy
  9397. (ge, ":killer_agent_no", 0),
  9398. (ge, ":dead_agent_no", 0),
  9399. (agent_is_human, ":dead_agent_no"),
  9400. (agent_is_human, ":killer_agent_no"),
  9401. (try_begin),
  9402. (eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  9403. (try_begin),
  9404. (eq, "$g_battle_death_mode_started", 1),
  9405. (neq, ":dead_agent_no", ":killer_agent_no"),
  9406. (call_script, "script_calculate_new_death_waiting_time_at_death_mod"),
  9407. (try_end),
  9408. (try_end),
  9409. (try_begin),
  9410. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  9411. (eq, "$g_multiplayer_game_type", multiplayer_game_type_destroy),
  9412. (agent_get_player_id, ":dead_player_no", ":dead_agent_no"),
  9413. (try_begin),
  9414. (ge, ":dead_player_no", 0),
  9415. (player_is_active, ":dead_player_no"),
  9416. (neg|agent_is_non_player, ":dead_agent_no"),
  9417. (try_for_agents, ":cur_agent"),
  9418. (agent_is_non_player, ":cur_agent"),
  9419. (agent_is_human, ":cur_agent"),
  9420. (agent_is_alive, ":cur_agent"),
  9421. (agent_get_group, ":agent_group", ":cur_agent"),
  9422. (try_begin),
  9423. (eq, ":dead_player_no", ":agent_group"),
  9424. (agent_set_group, ":cur_agent", -1),
  9425. (try_end),
  9426. (try_end),
  9427. (try_end),
  9428. (try_end),
  9429. (neg|agent_is_non_player, ":killer_agent_no"),
  9430. (agent_get_player_id, ":killer_agent_player_id", ":killer_agent_no"),
  9431. (player_is_active, ":killer_agent_player_id"),
  9432. (player_get_score, ":killer_agent_player_score", ":killer_agent_player_id"),
  9433. (agent_get_team, ":killer_agent_team", ":killer_agent_no"),
  9434. (agent_get_team, ":dead_agent_team", ":dead_agent_no"),
  9435. (try_begin),
  9436. (neq, ":killer_agent_team", ":dead_agent_team"),
  9437. (val_add, ":killer_agent_player_score", 1),
  9438. (else_try),
  9439. (val_add, ":killer_agent_player_score", -1),
  9440. (try_end),
  9441. (player_set_score, ":killer_agent_player_id", ":killer_agent_player_score"),
  9442. (try_end),
  9443. (try_end),
  9444.  
  9445. (call_script, "script_add_kill_death_counts", ":killer_agent_no", ":dead_agent_no"),
  9446. #money management
  9447. (call_script, "script_money_management_after_agent_death", ":killer_agent_no", ":dead_agent_no"),
  9448. ]),
  9449.  
  9450. #script_multiplayer_close_gate_if_it_is_open
  9451. # INPUT: none
  9452. # OUTPUT: none
  9453. ("multiplayer_close_gate_if_it_is_open",
  9454. [
  9455. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_winch_b"),
  9456. (try_for_range, ":cur_prop_instance", 0, ":num_instances_of_scene_prop"),
  9457. (scene_prop_get_instance, ":prop_instance_id", "spr_winch_b", ":cur_prop_instance"),
  9458. (scene_prop_slot_eq, ":prop_instance_id", scene_prop_open_or_close_slot, 1),
  9459. (scene_prop_get_instance, ":effected_object_instance_id", "spr_portcullis", ":cur_prop_instance"),
  9460. (prop_instance_get_starting_position, pos0, ":effected_object_instance_id"),
  9461. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 1),
  9462. (try_end),
  9463. ]),
  9464.  
  9465. #script_multiplayer_move_moveable_objects_initial_positions
  9466. # INPUT: none
  9467. # OUTPUT: none
  9468. ("multiplayer_move_moveable_objects_initial_positions",
  9469. [
  9470. (call_script, "script_move_object_to_nearest_entry_point", "spr_siege_ladder_move_6m"),
  9471. (call_script, "script_move_object_to_nearest_entry_point", "spr_siege_ladder_move_8m"),
  9472. (call_script, "script_move_object_to_nearest_entry_point", "spr_siege_ladder_move_10m"),
  9473. (call_script, "script_move_object_to_nearest_entry_point", "spr_siege_ladder_move_12m"),
  9474. (call_script, "script_move_object_to_nearest_entry_point", "spr_siege_ladder_move_14m"),
  9475. ]),
  9476.  
  9477. #script_move_belfries_to_their_first_entry_point
  9478. # INPUT: none
  9479. # OUTPUT: none
  9480. ("move_belfries_to_their_first_entry_point",
  9481. [
  9482. (store_script_param, ":belfry_body_scene_prop", 1),
  9483.  
  9484. (set_fixed_point_multiplier, 100),
  9485. (scene_prop_get_num_instances, ":num_belfries", ":belfry_body_scene_prop"),
  9486.  
  9487. (try_for_range, ":belfry_no", 0, ":num_belfries"),
  9488. #belfry
  9489. (scene_prop_get_instance, ":belfry_scene_prop_id", ":belfry_body_scene_prop", ":belfry_no"),
  9490. (prop_instance_get_position, pos0, ":belfry_scene_prop_id"),
  9491.  
  9492. (try_begin),
  9493. (eq, ":belfry_body_scene_prop", "spr_belfry_a"),
  9494. #belfry platform_a
  9495. (scene_prop_get_instance, ":belfry_platform_a_scene_prop_id", "spr_belfry_platform_a", ":belfry_no"),
  9496. #belfry platform_b
  9497. (scene_prop_get_instance, ":belfry_platform_b_scene_prop_id", "spr_belfry_platform_b", ":belfry_no"),
  9498. (else_try),
  9499. #belfry platform_a
  9500. (scene_prop_get_instance, ":belfry_platform_a_scene_prop_id", "spr_belfry_b_platform_a", ":belfry_no"),
  9501. (try_end),
  9502.  
  9503. #belfry wheel_1
  9504. (store_mul, ":wheel_no", ":belfry_no", 3),
  9505. (try_begin),
  9506. (eq, ":belfry_body_scene_prop", "spr_belfry_b"),
  9507. (scene_prop_get_num_instances, ":number_of_belfry_a", "spr_belfry_a"),
  9508. (store_mul, ":number_of_belfry_a_wheels", ":number_of_belfry_a", 3),
  9509. (val_add, ":wheel_no", ":number_of_belfry_a_wheels"),
  9510. (try_end),
  9511. (scene_prop_get_instance, ":belfry_wheel_1_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
  9512. #belfry wheel_2
  9513. (val_add, ":wheel_no", 1),
  9514. (scene_prop_get_instance, ":belfry_wheel_2_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
  9515. #belfry wheel_3
  9516. (val_add, ":wheel_no", 1),
  9517. (scene_prop_get_instance, ":belfry_wheel_3_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
  9518.  
  9519. (store_add, ":belfry_first_entry_point_id", 11, ":belfry_no"), #belfry entry points are 110..119 and 120..129 and 130..139
  9520. (try_begin),
  9521. (eq, ":belfry_body_scene_prop", "spr_belfry_b"),
  9522. (scene_prop_get_num_instances, ":number_of_belfry_a", "spr_belfry_a"),
  9523. (val_add, ":belfry_first_entry_point_id", ":number_of_belfry_a"),
  9524. (try_end),
  9525. (val_mul, ":belfry_first_entry_point_id", 10),
  9526. (entry_point_get_position, pos1, ":belfry_first_entry_point_id"),
  9527.  
  9528. #this code block is taken from module_mission_templates.py (multiplayer_server_check_belfry_movement)
  9529. #up down rotation of belfry's next entry point
  9530. (init_position, pos9),
  9531. (position_set_y, pos9, -500), #go 5.0 meters back
  9532. (position_set_x, pos9, -300), #go 3.0 meters left
  9533. (position_transform_position_to_parent, pos10, pos1, pos9),
  9534. (position_get_distance_to_terrain, ":height_to_terrain_1", pos10), #learn distance between 5 meters back of entry point(pos10) and ground level at left part of belfry
  9535.  
  9536. (init_position, pos9),
  9537. (position_set_y, pos9, -500), #go 5.0 meters back
  9538. (position_set_x, pos9, 300), #go 3.0 meters right
  9539. (position_transform_position_to_parent, pos10, pos1, pos9),
  9540. (position_get_distance_to_terrain, ":height_to_terrain_2", pos10), #learn distance between 5 meters back of entry point(pos10) and ground level at right part of belfry
  9541.  
  9542. (store_add, ":height_to_terrain", ":height_to_terrain_1", ":height_to_terrain_2"),
  9543. (val_mul, ":height_to_terrain", 100), #because of fixed point multiplier
  9544.  
  9545. (store_div, ":rotate_angle_of_next_entry_point", ":height_to_terrain", 24), #if there is 1 meters of distance (100cm) then next target position will rotate by 2 degrees. #ac sonra
  9546. (init_position, pos20),
  9547. (position_rotate_x_floating, pos20, ":rotate_angle_of_next_entry_point"),
  9548. (position_transform_position_to_parent, pos23, pos1, pos20),
  9549.  
  9550. #right left rotation of belfry's next entry point
  9551. (init_position, pos9),
  9552. (position_set_x, pos9, -300), #go 3.0 meters left
  9553. (position_transform_position_to_parent, pos10, pos1, pos9), #applying 3.0 meters in -x to position of next entry point target, final result is in pos10
  9554. (position_get_distance_to_terrain, ":height_to_terrain_at_left", pos10), #learn distance between 3.0 meters left of entry point(pos10) and ground level
  9555. (init_position, pos9),
  9556. (position_set_x, pos9, 300), #go 3.0 meters left
  9557. (position_transform_position_to_parent, pos10, pos1, pos9), #applying 3.0 meters in x to position of next entry point target, final result is in pos10
  9558. (position_get_distance_to_terrain, ":height_to_terrain_at_right", pos10), #learn distance between 3.0 meters right of entry point(pos10) and ground level
  9559. (store_sub, ":height_to_terrain_1", ":height_to_terrain_at_left", ":height_to_terrain_at_right"),
  9560.  
  9561. (init_position, pos9),
  9562. (position_set_x, pos9, -300), #go 3.0 meters left
  9563. (position_set_y, pos9, -500), #go 5.0 meters forward
  9564. (position_transform_position_to_parent, pos10, pos1, pos9), #applying 3.0 meters in -x to position of next entry point target, final result is in pos10
  9565. (position_get_distance_to_terrain, ":height_to_terrain_at_left", pos10), #learn distance between 3.0 meters left of entry point(pos10) and ground level
  9566. (init_position, pos9),
  9567. (position_set_x, pos9, 300), #go 3.0 meters left
  9568. (position_set_y, pos9, -500), #go 5.0 meters forward
  9569. (position_transform_position_to_parent, pos10, pos1, pos9), #applying 3.0 meters in x to position of next entry point target, final result is in pos10
  9570. (position_get_distance_to_terrain, ":height_to_terrain_at_right", pos10), #learn distance between 3.0 meters right of entry point(pos10) and ground level
  9571. (store_sub, ":height_to_terrain_2", ":height_to_terrain_at_left", ":height_to_terrain_at_right"),
  9572.  
  9573. (store_add, ":height_to_terrain", ":height_to_terrain_1", ":height_to_terrain_2"),
  9574. (val_mul, ":height_to_terrain", 100), #100 is because of fixed_point_multiplier
  9575. (store_div, ":rotate_angle_of_next_entry_point", ":height_to_terrain", 24), #if there is 1 meters of distance (100cm) then next target position will rotate by 25 degrees.
  9576. (val_mul, ":rotate_angle_of_next_entry_point", -1),
  9577.  
  9578. (init_position, pos20),
  9579. (position_rotate_y_floating, pos20, ":rotate_angle_of_next_entry_point"),
  9580. (position_transform_position_to_parent, pos22, pos23, pos20),
  9581.  
  9582. (copy_position, pos1, pos22),
  9583. #end of code block
  9584.  
  9585. #belfry
  9586. (prop_instance_stop_animating, ":belfry_scene_prop_id"),
  9587. (prop_instance_set_position, ":belfry_scene_prop_id", pos1),
  9588.  
  9589. #belfry platforms
  9590. (try_begin),
  9591. (eq, ":belfry_body_scene_prop", "spr_belfry_a"),
  9592.  
  9593. #belfry platform_a
  9594. (prop_instance_get_position, pos6, ":belfry_platform_a_scene_prop_id"),
  9595. (position_transform_position_to_local, pos7, pos0, pos6),
  9596. (position_transform_position_to_parent, pos8, pos1, pos7),
  9597. (try_begin),
  9598. (neg|scene_prop_slot_eq, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 0),
  9599.  
  9600. (init_position, pos20),
  9601. (position_rotate_x, pos20, 90),
  9602. (position_transform_position_to_parent, pos8, pos8, pos20),
  9603. (try_end),
  9604. (prop_instance_stop_animating, ":belfry_platform_a_scene_prop_id"),
  9605. (prop_instance_set_position, ":belfry_platform_a_scene_prop_id", pos8),
  9606. #belfry platform_b
  9607. (prop_instance_get_position, pos6, ":belfry_platform_b_scene_prop_id"),
  9608. (position_transform_position_to_local, pos7, pos0, pos6),
  9609. (position_transform_position_to_parent, pos8, pos1, pos7),
  9610. (prop_instance_stop_animating, ":belfry_platform_b_scene_prop_id"),
  9611. (prop_instance_set_position, ":belfry_platform_b_scene_prop_id", pos8),
  9612. (else_try),
  9613. #belfry platform_a
  9614. (prop_instance_get_position, pos6, ":belfry_platform_a_scene_prop_id"),
  9615. (position_transform_position_to_local, pos7, pos0, pos6),
  9616. (position_transform_position_to_parent, pos8, pos1, pos7),
  9617. (try_begin),
  9618. (neg|scene_prop_slot_eq, ":belfry_scene_prop_id", scene_prop_belfry_platform_moved, 0),
  9619.  
  9620. (init_position, pos20),
  9621. (position_rotate_x, pos20, 50),
  9622. (position_transform_position_to_parent, pos8, pos8, pos20),
  9623. (try_end),
  9624. (prop_instance_stop_animating, ":belfry_platform_a_scene_prop_id"),
  9625. (prop_instance_set_position, ":belfry_platform_a_scene_prop_id", pos8),
  9626. (try_end),
  9627.  
  9628. #belfry wheel_1
  9629. (store_mul, ":wheel_no", ":belfry_no", 3),
  9630. (try_begin),
  9631. (eq, ":belfry_body_scene_prop", "spr_belfry_b"),
  9632. (scene_prop_get_num_instances, ":number_of_belfry_a", "spr_belfry_a"),
  9633. (store_mul, ":number_of_belfry_a_wheels", ":number_of_belfry_a", 3),
  9634. (val_add, ":wheel_no", ":number_of_belfry_a_wheels"),
  9635. (try_end),
  9636. (prop_instance_get_position, pos6, ":belfry_wheel_1_scene_prop_id"),
  9637. (position_transform_position_to_local, pos7, pos0, pos6),
  9638. (position_transform_position_to_parent, pos8, pos1, pos7),
  9639. (prop_instance_stop_animating, ":belfry_wheel_1_scene_prop_id"),
  9640. (prop_instance_set_position, ":belfry_wheel_1_scene_prop_id", pos8),
  9641. #belfry wheel_2
  9642. (prop_instance_get_position, pos6, ":belfry_wheel_2_scene_prop_id"),
  9643. (position_transform_position_to_local, pos7, pos0, pos6),
  9644. (position_transform_position_to_parent, pos8, pos1, pos7),
  9645. (prop_instance_stop_animating, ":belfry_wheel_2_scene_prop_id"),
  9646. (prop_instance_set_position, ":belfry_wheel_2_scene_prop_id", pos8),
  9647. #belfry wheel_3
  9648. (prop_instance_get_position, pos6, ":belfry_wheel_3_scene_prop_id"),
  9649. (position_transform_position_to_local, pos7, pos0, pos6),
  9650. (position_transform_position_to_parent, pos8, pos1, pos7),
  9651. (prop_instance_stop_animating, ":belfry_wheel_3_scene_prop_id"),
  9652. (prop_instance_set_position, ":belfry_wheel_3_scene_prop_id", pos8),
  9653. (try_end),
  9654. ]),
  9655.  
  9656. #script_team_set_score
  9657. # INPUT: arg1 = team_no, arg2 = score
  9658. # OUTPUT: none
  9659. ("team_set_score",
  9660. [
  9661. (store_script_param, ":team_no", 1),
  9662. (store_script_param, ":score", 2),
  9663.  
  9664. (team_set_score, ":team_no", ":score"),
  9665. ]),
  9666.  
  9667. #script_player_set_score
  9668. # INPUT: arg1 = player_no, arg2 = score
  9669. # OUTPUT: none
  9670. ("player_set_score",
  9671. [
  9672. (store_script_param, ":player_no", 1),
  9673. (store_script_param, ":score", 2),
  9674.  
  9675. (player_set_score, ":player_no", ":score"),
  9676. ]),
  9677.  
  9678. #script_player_set_kill_count
  9679. # INPUT: arg1 = player_no, arg2 = score
  9680. # OUTPUT: none
  9681. ("player_set_kill_count",
  9682. [
  9683. (store_script_param, ":player_no", 1),
  9684. (store_script_param, ":score", 2),
  9685.  
  9686. (player_set_kill_count, ":player_no", ":score"),
  9687. ]),
  9688.  
  9689. #script_player_set_death_count
  9690. # INPUT: arg1 = player_no, arg2 = score
  9691. # OUTPUT: none
  9692. ("player_set_death_count",
  9693. [
  9694. (store_script_param, ":player_no", 1),
  9695. (store_script_param, ":score", 2),
  9696.  
  9697. (player_set_death_count, ":player_no", ":score"),
  9698. ]),
  9699.  
  9700. #script_set_attached_scene_prop
  9701. # INPUT: arg1 = agent_id, arg2 = flag_id
  9702. # OUTPUT: none
  9703. ("set_attached_scene_prop",
  9704. [
  9705. (store_script_param, ":agent_id", 1),
  9706. (store_script_param, ":flag_id", 2),
  9707.  
  9708. (try_begin), #if current mod is capture the flag and attached scene prop is flag then change flag situation of flag owner team.
  9709. (scene_prop_get_instance, ":red_flag_id", "spr_tutorial_flag_red", 0),
  9710. (scene_prop_get_instance, ":blue_flag_id", "spr_tutorial_flag_blue", 0),
  9711. (assign, ":flag_owner_team", -1),
  9712. (try_begin),
  9713. (ge, ":red_flag_id", 0),
  9714. (eq, ":flag_id", ":red_flag_id"),
  9715. (assign, ":flag_owner_team", 0),
  9716. (else_try),
  9717. (ge, ":blue_flag_id", 0),
  9718. (eq, ":flag_id", ":blue_flag_id"),
  9719. (assign, ":flag_owner_team", 1),
  9720. (try_end),
  9721. (ge, ":flag_owner_team", 0),
  9722. (team_set_slot, ":flag_owner_team", slot_team_flag_situation, 1), #1-stolen flag
  9723. (try_end),
  9724.  
  9725. (agent_set_attached_scene_prop, ":agent_id", ":flag_id"),
  9726. (agent_set_attached_scene_prop_x, ":agent_id", 20),
  9727. (agent_set_attached_scene_prop_z, ":agent_id", 50),
  9728. ]),
  9729.  
  9730. #script_set_team_flag_situation
  9731. # INPUT: arg1 = team_no, arg2 = score
  9732. # OUTPUT: none
  9733. ("set_team_flag_situation",
  9734. [
  9735. (store_script_param, ":team_no", 1),
  9736. (store_script_param, ":flag_situation", 2),
  9737.  
  9738. (team_set_slot, ":team_no", slot_team_flag_situation, ":flag_situation"),
  9739. ]),
  9740.  
  9741. #script_start_death_mode
  9742. # INPUT: none
  9743. # OUTPUT: none
  9744. ("start_death_mode",
  9745. [
  9746. (assign, "$g_multiplayer_message_type", multiplayer_message_type_start_death_mode),
  9747. (start_presentation, "prsnt_multiplayer_message_1"),
  9748. ]),
  9749.  
  9750. #script_calculate_new_death_waiting_time_at_death_mod
  9751. # INPUT: none
  9752. # OUTPUT: none
  9753. ("calculate_new_death_waiting_time_at_death_mod",
  9754. [
  9755. (assign, ":num_living_players", 0), #count number of living players to find out death wait time
  9756. (try_begin),
  9757. (try_for_agents, ":agent_no"),
  9758. (agent_is_human, ":agent_no"),
  9759. (agent_is_alive, ":agent_no"),
  9760. (val_add, ":num_living_players", 1),
  9761. (try_end),
  9762. (try_end),
  9763.  
  9764. (val_add, ":num_living_players", multiplayer_battle_formula_value_a),
  9765. (set_fixed_point_multiplier, 100),
  9766. (store_mul, ":num_living_players", ":num_living_players", 100),
  9767. (store_sqrt, ":sqrt_num_living_players", ":num_living_players"),
  9768. (store_div, "$g_battle_waiting_seconds", multiplayer_battle_formula_value_b, ":sqrt_num_living_players"),
  9769. (store_mission_timer_a, "$g_death_mode_part_1_start_time"),
  9770. ]),
  9771.  
  9772. #script_calculate_number_of_targets_destroyed
  9773. # INPUT: none
  9774. # OUTPUT: none
  9775.  
  9776. ("calculate_number_of_targets_destroyed",
  9777. [
  9778. (assign, "$g_number_of_targets_destroyed", 0),
  9779. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_catapult_destructible"),
  9780. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9781. (scene_prop_get_instance, ":cur_instance_id", "spr_catapult_destructible", ":cur_instance"),
  9782. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9783. (prop_instance_get_position, pos1, ":cur_instance_id"),
  9784. (get_sq_distance_between_positions_in_meters, ":dist", pos0, pos1),
  9785. (gt, ":dist", 2), #this can be 0 or 1 too.
  9786. (val_add, "$g_number_of_targets_destroyed", 1),
  9787. (try_end),
  9788.  
  9789. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_trebuchet_destructible"),
  9790. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9791. (scene_prop_get_instance, ":cur_instance_id", "spr_trebuchet_destructible", ":cur_instance"),
  9792. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9793. (prop_instance_get_position, pos1, ":cur_instance_id"),
  9794. (get_sq_distance_between_positions_in_meters, ":dist", pos0, pos1),
  9795. (gt, ":dist", 2), #this can be 0 or 1 too.
  9796. (val_add, "$g_number_of_targets_destroyed", 1),
  9797. (try_end),
  9798. ]),
  9799.  
  9800. #script_initialize_objects
  9801. # INPUT: none
  9802. # OUTPUT: none
  9803. ("initialize_objects",
  9804. [
  9805. (assign, ":number_of_players", 0),
  9806. (get_max_players, ":num_players"),
  9807. (try_for_range, ":player_no", 0, ":num_players"),
  9808. (player_is_active, ":player_no"),
  9809. (val_add, ":number_of_players", 1),
  9810. (try_end),
  9811.  
  9812. #1 player = (Sqrt(1) - 1) * 200 + 1200 = 1200, 1800 (minimum)
  9813. #4 player = (Sqrt(4) - 1) * 200 + 1200 = 1400, 2100
  9814. #9 player = (Sqrt(9) - 1) * 200 + 1200 = 1600, 2400
  9815. #16 player = (Sqrt(16) - 1) * 200 + 1200 = 1800, 2700 (general used)
  9816. #25 player = (Sqrt(25) - 1) * 200 + 1200 = 2000, 3000 (average)
  9817. #36 player = (Sqrt(36) - 1) * 200 + 1200 = 2200, 3300
  9818. #49 player = (Sqrt(49) - 1) * 200 + 1200 = 2400, 3600
  9819. #64 player = (Sqrt(49) - 1) * 200 + 1200 = 2600, 3900
  9820.  
  9821. (set_fixed_point_multiplier, 100),
  9822. (val_mul, ":number_of_players", 100),
  9823. (store_sqrt, ":number_of_players", ":number_of_players"),
  9824. (val_sub, ":number_of_players", 100),
  9825. (val_max, ":number_of_players", 0),
  9826. (store_mul, ":effect_of_number_of_players", ":number_of_players", 2),
  9827. (store_add, ":health_catapult", multi_minimum_target_health, ":effect_of_number_of_players"),
  9828. (store_mul, ":health_trebuchet", ":health_catapult", 15), #trebuchet's health is 1.5x of catapult's
  9829. (val_div, ":health_trebuchet", 10),
  9830. (store_mul, ":health_sally_door", ":health_catapult", 18), #sally door's health is 1.8x of catapult's
  9831. (val_div, ":health_sally_door", 10),
  9832. (store_mul, ":health_sally_door_double", ":health_sally_door", 2),
  9833.  
  9834. (assign, "$g_number_of_targets_destroyed", 0),
  9835.  
  9836. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_catapult_destructible"),
  9837. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9838. (scene_prop_get_instance, ":cur_instance_id", "spr_catapult_destructible", ":cur_instance"),
  9839. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9840. (prop_instance_stop_animating, ":cur_instance_id"),
  9841. (prop_instance_set_position, ":cur_instance_id", pos0),
  9842. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9843. (scene_prop_set_hit_points, ":cur_instance_id", ":health_catapult"),
  9844. (try_end),
  9845.  
  9846. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_trebuchet_destructible"),
  9847. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9848. (scene_prop_get_instance, ":cur_instance_id", "spr_trebuchet_destructible", ":cur_instance"),
  9849. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9850. (prop_instance_stop_animating, ":cur_instance_id"),
  9851. (prop_instance_set_position, ":cur_instance_id", pos0),
  9852. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9853. (scene_prop_set_hit_points, ":cur_instance_id", ":health_trebuchet"),
  9854. (try_end),
  9855.  
  9856. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_castle_e_sally_door_a"),
  9857. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9858. (scene_prop_get_instance, ":cur_instance_id", "spr_castle_e_sally_door_a", ":cur_instance"),
  9859. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9860. (prop_instance_stop_animating, ":cur_instance_id"),
  9861. (prop_instance_set_position, ":cur_instance_id", pos0),
  9862. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9863. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door"),
  9864. (try_end),
  9865.  
  9866. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_castle_f_sally_door_a"),
  9867. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9868. (scene_prop_get_instance, ":cur_instance_id", "spr_castle_f_sally_door_a", ":cur_instance"),
  9869. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9870. (prop_instance_stop_animating, ":cur_instance_id"),
  9871. (prop_instance_set_position, ":cur_instance_id", pos0),
  9872. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9873. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door"),
  9874. (try_end),
  9875.  
  9876. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_earth_sally_gate_left"),
  9877. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9878. (scene_prop_get_instance, ":cur_instance_id", "spr_earth_sally_gate_left", ":cur_instance"),
  9879. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9880. (prop_instance_stop_animating, ":cur_instance_id"),
  9881. (prop_instance_set_position, ":cur_instance_id", pos0),
  9882. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9883. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door_double"),
  9884. (try_end),
  9885.  
  9886. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_earth_sally_gate_right"),
  9887. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9888. (scene_prop_get_instance, ":cur_instance_id", "spr_earth_sally_gate_right", ":cur_instance"),
  9889. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9890. (prop_instance_stop_animating, ":cur_instance_id"),
  9891. (prop_instance_set_position, ":cur_instance_id", pos0),
  9892. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9893. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door_double"),
  9894. (try_end),
  9895.  
  9896. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_viking_keep_destroy_sally_door_left"),
  9897. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9898. (scene_prop_get_instance, ":cur_instance_id", "spr_viking_keep_destroy_sally_door_left", ":cur_instance"),
  9899. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9900. (prop_instance_stop_animating, ":cur_instance_id"),
  9901. (prop_instance_set_position, ":cur_instance_id", pos0),
  9902. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9903. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door"),
  9904. (try_end),
  9905.  
  9906. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_viking_keep_destroy_sally_door_right"),
  9907. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9908. (scene_prop_get_instance, ":cur_instance_id", "spr_viking_keep_destroy_sally_door_right", ":cur_instance"),
  9909. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9910. (prop_instance_stop_animating, ":cur_instance_id"),
  9911. (prop_instance_set_position, ":cur_instance_id", pos0),
  9912. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9913. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door"),
  9914. (try_end),
  9915.  
  9916. (store_div, ":health_sally_door_div_3", ":health_sally_door", 3),
  9917.  
  9918. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_castle_f_door_a"),
  9919. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9920. (scene_prop_get_instance, ":cur_instance_id", "spr_castle_f_door_a", ":cur_instance"),
  9921. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9922. (prop_instance_stop_animating, ":cur_instance_id"),
  9923. (prop_instance_set_position, ":cur_instance_id", pos0),
  9924. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9925. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door_div_3"),
  9926. (try_end),
  9927.  
  9928. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_castle_f_door_b"),
  9929. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9930. (scene_prop_get_instance, ":cur_instance_id", "spr_castle_f_door_b", ":cur_instance"),
  9931. (prop_instance_get_starting_position, pos0, ":cur_instance_id"),
  9932. (prop_instance_stop_animating, ":cur_instance_id"),
  9933. (prop_instance_set_position, ":cur_instance_id", pos0),
  9934. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9935. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door_div_3"),
  9936. (try_end),
  9937. ]),
  9938.  
  9939. #script_initialize_objects_clients
  9940. # INPUT: none
  9941. # OUTPUT: none
  9942. ("initialize_objects_clients",
  9943. [
  9944. (assign, ":number_of_players", 0),
  9945. (get_max_players, ":num_players"),
  9946. (try_for_range, ":player_no", 0, ":num_players"),
  9947. (player_is_active, ":player_no"),
  9948. (val_add, ":number_of_players", 1),
  9949. (try_end),
  9950.  
  9951. #1 player = (Sqrt(1) - 1) * 200 + 1200 = 1200, 1800 (minimum)
  9952. #4 player = (Sqrt(4) - 1) * 200 + 1200 = 1400, 2100
  9953. #9 player = (Sqrt(9) - 1) * 200 + 1200 = 1600, 2400
  9954. #16 player = (Sqrt(16) - 1) * 200 + 1200 = 1800, 2700 (general used)
  9955. #25 player = (Sqrt(25) - 1) * 200 + 1200 = 2000, 3000 (average)
  9956. #36 player = (Sqrt(36) - 1) * 200 + 1200 = 2200, 3300
  9957. #49 player = (Sqrt(49) - 1) * 200 + 1200 = 2400, 3600
  9958. #64 player = (Sqrt(49) - 1) * 200 + 1200 = 2600, 3900
  9959.  
  9960. (set_fixed_point_multiplier, 100),
  9961. (val_mul, ":number_of_players", 100),
  9962. (store_sqrt, ":number_of_players", ":number_of_players"),
  9963. (val_sub, ":number_of_players", 100),
  9964. (val_max, ":number_of_players", 0),
  9965. (store_mul, ":effect_of_number_of_players", ":number_of_players", 2),
  9966. (store_add, ":health_catapult", multi_minimum_target_health, ":effect_of_number_of_players"),
  9967. (store_mul, ":health_trebuchet", ":health_catapult", 15), #trebuchet's health is 1.5x of catapult's
  9968. (val_div, ":health_trebuchet", 10),
  9969. (store_mul, ":health_sally_door", ":health_catapult", 18), #trebuchet's health is 1.8x of trebuchet's
  9970. (val_div, ":health_sally_door", 10),
  9971. (store_mul, ":health_sally_door_double", ":health_sally_door", 2),
  9972.  
  9973. (assign, "$g_number_of_targets_destroyed", 0),
  9974.  
  9975. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_catapult_destructible"),
  9976. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9977. (scene_prop_get_instance, ":cur_instance_id", "spr_catapult_destructible", ":cur_instance"),
  9978. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9979. (scene_prop_set_hit_points, ":cur_instance_id", ":health_catapult"),
  9980. (try_end),
  9981.  
  9982. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_trebuchet_destructible"),
  9983. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9984. (scene_prop_get_instance, ":cur_instance_id", "spr_trebuchet_destructible", ":cur_instance"),
  9985. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9986. (scene_prop_set_hit_points, ":cur_instance_id", ":health_trebuchet"),
  9987. (try_end),
  9988.  
  9989. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_castle_e_sally_door_a"),
  9990. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9991. (scene_prop_get_instance, ":cur_instance_id", "spr_castle_e_sally_door_a", ":cur_instance"),
  9992. (prop_instance_enable_physics, ":cur_instance_id", 1),
  9993. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door"),
  9994. (try_end),
  9995.  
  9996. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_castle_f_sally_door_a"),
  9997. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  9998. (scene_prop_get_instance, ":cur_instance_id", "spr_castle_f_sally_door_a", ":cur_instance"),
  9999. (prop_instance_enable_physics, ":cur_instance_id", 1),
  10000. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door"),
  10001. (try_end),
  10002.  
  10003. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_earth_sally_gate_left"),
  10004. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  10005. (scene_prop_get_instance, ":cur_instance_id", "spr_earth_sally_gate_left", ":cur_instance"),
  10006. (prop_instance_enable_physics, ":cur_instance_id", 1),
  10007. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door_double"),
  10008. (try_end),
  10009.  
  10010. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_earth_sally_gate_right"),
  10011. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  10012. (scene_prop_get_instance, ":cur_instance_id", "spr_earth_sally_gate_right", ":cur_instance"),
  10013. (prop_instance_enable_physics, ":cur_instance_id", 1),
  10014. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door_double"),
  10015. (try_end),
  10016.  
  10017. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_viking_keep_destroy_sally_door_left"),
  10018. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  10019. (scene_prop_get_instance, ":cur_instance_id", "spr_viking_keep_destroy_sally_door_left", ":cur_instance"),
  10020. (prop_instance_enable_physics, ":cur_instance_id", 1),
  10021. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door"),
  10022. (try_end),
  10023.  
  10024. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_viking_keep_destroy_sally_door_right"),
  10025. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  10026. (scene_prop_get_instance, ":cur_instance_id", "spr_viking_keep_destroy_sally_door_right", ":cur_instance"),
  10027. (prop_instance_enable_physics, ":cur_instance_id", 1),
  10028. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door"),
  10029. (try_end),
  10030.  
  10031. (store_div, ":health_sally_door_div_3", ":health_sally_door", 3),
  10032.  
  10033. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_castle_f_door_a"),
  10034. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  10035. (scene_prop_get_instance, ":cur_instance_id", "spr_castle_f_door_a", ":cur_instance"),
  10036. (prop_instance_enable_physics, ":cur_instance_id", 1),
  10037. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door_div_3"),
  10038. (try_end),
  10039.  
  10040. (scene_prop_get_num_instances, ":num_instances_of_scene_prop", "spr_castle_f_door_b"),
  10041. (try_for_range, ":cur_instance", 0, ":num_instances_of_scene_prop"),
  10042. (scene_prop_get_instance, ":cur_instance_id", "spr_castle_f_door_b", ":cur_instance"),
  10043. (prop_instance_enable_physics, ":cur_instance_id", 1),
  10044. (scene_prop_set_hit_points, ":cur_instance_id", ":health_sally_door_div_3"),
  10045. (try_end),
  10046. ]),
  10047.  
  10048. #script_show_multiplayer_message
  10049. # INPUT: arg1 = multiplayer_message_type
  10050. # OUTPUT: none
  10051. ("show_multiplayer_message",
  10052. [
  10053. (store_script_param, ":multiplayer_message_type", 1),
  10054. (store_script_param, ":value", 2),
  10055.  
  10056. (assign, "$g_multiplayer_message_type", ":multiplayer_message_type"),
  10057.  
  10058. (try_begin),
  10059. (eq, ":multiplayer_message_type", multiplayer_message_type_round_result_in_battle_mode),
  10060. (assign, "$g_multiplayer_message_value_1", ":value"),
  10061. (start_presentation, "prsnt_multiplayer_message_1"),
  10062.  
  10063. (try_begin), #end of round in clients
  10064. (neg|multiplayer_is_server),
  10065. (assign, "$g_battle_death_mode_started", 0),
  10066. (try_end),
  10067. (else_try),
  10068. (eq, ":multiplayer_message_type", multiplayer_message_type_auto_team_balance_done),
  10069. (assign, "$g_multiplayer_message_value_1", ":value"),
  10070. (start_presentation, "prsnt_multiplayer_message_2"),
  10071. (assign, "$g_team_balance_next_round", 0),
  10072. (else_try),
  10073. (eq, ":multiplayer_message_type", multiplayer_message_type_auto_team_balance_next),
  10074. (assign, "$g_team_balance_next_round", 1),
  10075. (call_script, "script_warn_player_about_auto_team_balance"),
  10076. (else_try),
  10077. (eq, ":multiplayer_message_type", multiplayer_message_type_auto_team_balance_no_need),
  10078. (assign, "$g_team_balance_next_round", 0),
  10079. (else_try),
  10080. (eq, ":multiplayer_message_type", multiplayer_message_type_capture_the_flag_score),
  10081. (assign, "$g_multiplayer_message_value_1", ":value"),
  10082. (start_presentation, "prsnt_multiplayer_message_1"),
  10083. (else_try),
  10084. (eq, ":multiplayer_message_type", multiplayer_message_type_flag_returned_home),
  10085. (assign, "$g_multiplayer_message_value_1", ":value"),
  10086. (start_presentation, "prsnt_multiplayer_message_1"),
  10087. (else_try),
  10088. (eq, ":multiplayer_message_type", multiplayer_message_type_capture_the_flag_stole),
  10089. (assign, "$g_multiplayer_message_value_1", ":value"),
  10090. (start_presentation, "prsnt_multiplayer_message_1"),
  10091. (else_try),
  10092. (eq, ":multiplayer_message_type", multiplayer_message_type_poll_result),
  10093. (assign, "$g_multiplayer_message_value_3", ":value"),
  10094. (start_presentation, "prsnt_multiplayer_message_3"),
  10095. (else_try),
  10096. (eq, ":multiplayer_message_type", multiplayer_message_type_flag_neutralized),
  10097. (assign, "$g_multiplayer_message_value_1", ":value"),
  10098. (start_presentation, "prsnt_multiplayer_message_1"),
  10099. (else_try),
  10100. (eq, ":multiplayer_message_type", multiplayer_message_type_flag_captured),
  10101. (assign, "$g_multiplayer_message_value_1", ":value"),
  10102. (start_presentation, "prsnt_multiplayer_message_1"),
  10103. (else_try),
  10104. (eq, ":multiplayer_message_type", multiplayer_message_type_flag_is_pulling),
  10105. (assign, "$g_multiplayer_message_value_1", ":value"),
  10106. (start_presentation, "prsnt_multiplayer_message_1"),
  10107. (else_try),
  10108. (eq, ":multiplayer_message_type", multiplayer_message_type_round_draw),
  10109. (start_presentation, "prsnt_multiplayer_message_1"),
  10110. (else_try),
  10111. (eq, ":multiplayer_message_type", multiplayer_message_type_target_destroyed),
  10112.  
  10113. (try_begin), #destroy score (condition : a target destroyed)
  10114. (eq, "$g_defender_team", 0),
  10115. (assign, ":attacker_team_no", 1),
  10116. (else_try),
  10117. (assign, ":attacker_team_no", 0),
  10118. (try_end),
  10119.  
  10120. (team_get_score, ":team_score", ":attacker_team_no"),
  10121. (val_add, ":team_score", 1),
  10122. (call_script, "script_team_set_score", ":attacker_team_no", ":team_score"), #destroy score end
  10123.  
  10124. (assign, "$g_multiplayer_message_value_1", ":value"),
  10125. (start_presentation, "prsnt_multiplayer_message_1"),
  10126. (else_try),
  10127. (eq, ":multiplayer_message_type", multiplayer_message_type_defenders_saved_n_targets),
  10128. (assign, "$g_multiplayer_message_value_1", ":value"),
  10129. (start_presentation, "prsnt_multiplayer_message_1"),
  10130. (else_try),
  10131. (eq, ":multiplayer_message_type", multiplayer_message_type_attackers_won_the_round),
  10132. (try_begin),
  10133. (eq, "$g_defender_team", 0),
  10134. (assign, "$g_multiplayer_message_value_1", 1),
  10135. (else_try),
  10136. (assign, "$g_multiplayer_message_value_1", 0),
  10137. (try_end),
  10138. (start_presentation, "prsnt_multiplayer_message_1"),
  10139. (try_end),
  10140. ]),
  10141.  
  10142. #script_get_headquarters_scores
  10143. # INPUT: none
  10144. # OUTPUT: reg0 = team_1_num_flags, reg1 = team_2_num_flags
  10145. ("get_headquarters_scores",
  10146. [
  10147. (assign, ":team_1_num_flags", 0),
  10148. (assign, ":team_2_num_flags", 0),
  10149. (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
  10150. (store_add, ":cur_flag_owner_slot", multi_data_flag_owner_begin, ":flag_no"),
  10151. (troop_get_slot, ":cur_flag_owner", "trp_multiplayer_data", ":cur_flag_owner_slot"),
  10152. (neq, ":cur_flag_owner", 0),
  10153. (try_begin),
  10154. (eq, ":cur_flag_owner", 1),
  10155. (val_add, ":team_1_num_flags", 1),
  10156. (else_try),
  10157. (val_add, ":team_2_num_flags", 1),
  10158. (try_end),
  10159. (try_end),
  10160. (assign, reg0, ":team_1_num_flags"),
  10161. (assign, reg1, ":team_2_num_flags"),
  10162. ]),
  10163.  
  10164.  
  10165. #script_draw_this_round
  10166. # INPUT: arg1 = value
  10167. ("draw_this_round",
  10168. [
  10169. (store_script_param, ":value", 1),
  10170. (try_begin),
  10171. (eq, ":value", -9), #destroy mod round end
  10172. (assign, "$g_round_ended", 1),
  10173. (store_mission_timer_a, "$g_round_finish_time"),
  10174. #(assign, "$g_multiplayer_message_value_1", -1),
  10175. #(assign, "$g_multiplayer_message_type", multiplayer_message_type_round_draw),
  10176. #(start_presentation, "prsnt_multiplayer_message_1"),
  10177. (else_try),
  10178. (eq, ":value", -1), #draw
  10179. (assign, "$g_round_ended", 1),
  10180. (store_mission_timer_a, "$g_round_finish_time"),
  10181. (assign, "$g_multiplayer_message_value_1", -1),
  10182. (assign, "$g_multiplayer_message_type", multiplayer_message_type_round_draw),
  10183. (start_presentation, "prsnt_multiplayer_message_1"),
  10184. (else_try),
  10185. (eq, ":value", 0), #defender wins
  10186. #THIS_IS_OUR_LAND achievement
  10187. (try_begin),
  10188. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  10189. (multiplayer_get_my_player, ":my_player_no"),
  10190. (is_between, ":my_player_no", 0, multiplayer_max_possible_player_id),
  10191. (player_get_agent_id, ":my_player_agent", ":my_player_no"),
  10192. (ge, ":my_player_agent", 0),
  10193. (agent_is_alive, ":my_player_agent"),
  10194. (agent_get_team, ":my_player_agent_team_no", ":my_player_agent"),
  10195. (eq, ":my_player_agent_team_no", 0), #defender
  10196. (unlock_achievement, ACHIEVEMENT_THIS_IS_OUR_LAND),
  10197. (try_end),
  10198. #THIS_IS_OUR_LAND achievement end
  10199. (assign, "$g_round_ended", 1),
  10200. (store_mission_timer_a, "$g_round_finish_time"),
  10201.  
  10202. (team_get_faction, ":faction_of_winner_team", 0),
  10203. (team_get_score, ":team_1_score", 0),
  10204. (val_add, ":team_1_score", 1),
  10205. (team_set_score, 0, ":team_1_score"),
  10206. (assign, "$g_winner_team", 0),
  10207. (str_store_faction_name, s1, ":faction_of_winner_team"),
  10208.  
  10209. (assign, "$g_multiplayer_message_value_1", ":value"),
  10210. (try_begin),
  10211. (neq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  10212. (neq, "$g_multiplayer_game_type", multiplayer_game_type_destroy),
  10213. (assign, "$g_multiplayer_message_type", multiplayer_message_type_round_result_in_siege_mode),
  10214. (else_try),
  10215. (assign, "$g_multiplayer_message_type", multiplayer_message_type_round_result_in_battle_mode),
  10216. (try_end),
  10217. (start_presentation, "prsnt_multiplayer_message_1"),
  10218. (else_try),
  10219. (eq, ":value", 1), #attacker wins
  10220. (assign, "$g_round_ended", 1),
  10221. (store_mission_timer_a, "$g_round_finish_time"),
  10222.  
  10223. (team_get_faction, ":faction_of_winner_team", 1),
  10224. (team_get_score, ":team_2_score", 1),
  10225. (val_add, ":team_2_score", 1),
  10226. (team_set_score, 1, ":team_2_score"),
  10227. (assign, "$g_winner_team", 1),
  10228. (str_store_faction_name, s1, ":faction_of_winner_team"),
  10229.  
  10230. (assign, "$g_multiplayer_message_value_1", ":value"),
  10231. (try_begin),
  10232. (neq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  10233. (neq, "$g_multiplayer_game_type", multiplayer_game_type_destroy),
  10234. (assign, "$g_multiplayer_message_type", multiplayer_message_type_round_result_in_siege_mode),
  10235. (else_try),
  10236. (assign, "$g_multiplayer_message_type", multiplayer_message_type_round_result_in_battle_mode),
  10237. (try_end),
  10238. (start_presentation, "prsnt_multiplayer_message_1"),
  10239. (try_end),
  10240. #LAST_MAN_STANDING achievement
  10241. (try_begin),
  10242. (is_between, ":value", 0, 2), #defender or attacker wins
  10243. (try_begin),
  10244. (eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  10245. (multiplayer_get_my_player, ":my_player_no"),
  10246. (is_between, ":my_player_no", 0, multiplayer_max_possible_player_id),
  10247. (player_get_agent_id, ":my_player_agent", ":my_player_no"),
  10248. (ge, ":my_player_agent", 0),
  10249. (agent_is_alive, ":my_player_agent"),
  10250. (agent_get_team, ":my_player_agent_team_no", ":my_player_agent"),
  10251. (eq, ":my_player_agent_team_no", ":value"), #winner team
  10252. (unlock_achievement, ACHIEVEMENT_LAST_MAN_STANDING),
  10253. (try_end),
  10254. (try_end),
  10255. #LAST_MAN_STANDING achievement end
  10256. ]),
  10257.  
  10258. #script_check_achievement_last_man_standing
  10259. #INPUT: arg1 = value
  10260. ("check_achievement_last_man_standing",
  10261. [
  10262. #LAST_MAN_STANDING achievement
  10263. (try_begin),
  10264. (store_script_param, ":value", 1),
  10265. (is_between, ":value", 0, 2), #defender or attacker wins
  10266. (try_begin),
  10267. (eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  10268. (multiplayer_get_my_player, ":my_player_no"),
  10269. (is_between, ":my_player_no", 0, multiplayer_max_possible_player_id),
  10270. (player_get_agent_id, ":my_player_agent", ":my_player_no"),
  10271. (ge, ":my_player_agent", 0),
  10272. (agent_is_alive, ":my_player_agent"),
  10273. (agent_get_team, ":my_player_agent_team_no", ":my_player_agent"),
  10274. (eq, ":my_player_agent_team_no", ":value"), #winner team
  10275. (unlock_achievement, ACHIEVEMENT_LAST_MAN_STANDING),
  10276. (try_end),
  10277. (try_end),
  10278. #LAST_MAN_STANDING achievement end
  10279. ]),
  10280.  
  10281. #script_find_most_suitable_bot_to_control
  10282. # INPUT: arg1 = value
  10283. ("find_most_suitable_bot_to_control",
  10284. [
  10285. (set_fixed_point_multiplier, 100),
  10286. (store_script_param, ":player_no", 1),
  10287. (player_get_team_no, ":player_team", ":player_no"),
  10288.  
  10289. (player_get_slot, ":x_coor", ":player_no", slot_player_death_pos_x),
  10290. (player_get_slot, ":y_coor", ":player_no", slot_player_death_pos_y),
  10291. (player_get_slot, ":z_coor", ":player_no", slot_player_death_pos_z),
  10292.  
  10293. (init_position, pos0),
  10294. (position_set_x, pos0, ":x_coor"),
  10295. (position_set_y, pos0, ":y_coor"),
  10296. (position_set_z, pos0, ":z_coor"),
  10297.  
  10298. (assign, ":most_suitable_bot", -1),
  10299. (assign, ":max_bot_score", -1),
  10300.  
  10301. (try_for_agents, ":cur_agent"),
  10302. (agent_is_alive, ":cur_agent"),
  10303. (agent_is_human, ":cur_agent"),
  10304. (agent_is_non_player, ":cur_agent"),
  10305. (agent_get_team ,":cur_team", ":cur_agent"),
  10306. (eq, ":cur_team", ":player_team"),
  10307. (agent_get_position, pos1, ":cur_agent"),
  10308.  
  10309. #getting score for distance of agent to death point (0..3000)
  10310. (get_distance_between_positions_in_meters, ":dist", pos0, pos1),
  10311.  
  10312. (try_begin),
  10313. (lt, ":dist", 500),
  10314. (store_sub, ":bot_score", 500, ":dist"),
  10315. (else_try),
  10316. (assign, ":bot_score", 0),
  10317. (try_end),
  10318. (val_mul, ":bot_score", 6),
  10319.  
  10320. #getting score for distance of agent to enemy & friend agents (0..300 x agents)
  10321. (try_for_agents, ":cur_agent_2"),
  10322. (agent_is_alive, ":cur_agent_2"),
  10323. (agent_is_human, ":cur_agent_2"),
  10324. (neq, ":cur_agent", ":cur_agent_2"),
  10325. (agent_get_team ,":cur_team_2", ":cur_agent_2"),
  10326. (try_begin),
  10327. (neq, ":cur_team_2", ":player_team"),
  10328. (agent_get_position, pos1, ":cur_agent_2"),
  10329. (get_distance_between_positions, ":dist_2", pos0, pos1),
  10330. (try_begin),
  10331. (lt, ":dist_2", 300),
  10332. (assign, ":enemy_near_score", ":dist_2"),
  10333. (else_try),
  10334. (assign, ":enemy_near_score", 300),
  10335. (try_end),
  10336. (val_add, ":bot_score", ":enemy_near_score"),
  10337. (else_try),
  10338. (agent_get_position, pos1, ":cur_agent_2"),
  10339. (get_distance_between_positions, ":dist_2", pos0, pos1),
  10340. (try_begin),
  10341. (lt, ":dist_2", 300),
  10342. (assign, ":friend_near_score", 300, ":dist_2"),
  10343. (else_try),
  10344. (assign, ":friend_near_score", 0),
  10345. (try_end),
  10346. (val_add, ":bot_score", ":friend_near_score"),
  10347. (try_end),
  10348. (try_end),
  10349.  
  10350. #getting score for health (0..200)
  10351. (store_agent_hit_points, ":agent_hit_points", ":cur_agent"),
  10352. (val_mul, ":agent_hit_points", 2),
  10353. (val_add, ":bot_score", ":agent_hit_points"),
  10354.  
  10355. (ge, ":bot_score", ":max_bot_score"),
  10356. (assign, ":max_bot_score", ":bot_score"),
  10357. (assign, ":most_suitable_bot", ":cur_agent"),
  10358. (try_end),
  10359.  
  10360. (assign, reg0, ":most_suitable_bot"),
  10361. ]),
  10362.  
  10363. #script_game_receive_url_response
  10364. #response format should be like this:
  10365. # [a number or a string]|[another number or a string]|[yet another number or a string] ...
  10366. # here is an example response:
  10367. # 12|Player|100|another string|142|323542|34454|yet another string
  10368. # INPUT: arg1 = num_integers, arg2 = num_strings
  10369. # reg0, reg1, reg2, ... up to 128 registers contain the integer values
  10370. # s0, s1, s2, ... up to 128 strings contain the string values
  10371. ("game_receive_url_response",
  10372. [
  10373. #here is an example usage
  10374. ## (store_script_param, ":num_integers", 1),
  10375. ## (store_script_param, ":num_strings", 2),
  10376. ## (try_begin),
  10377. ## (gt, ":num_integers", 4),
  10378. ## (display_message, "@{reg0}, {reg1}, {reg2}, {reg3}, {reg4}"),
  10379. ## (try_end),
  10380. ## (try_begin),
  10381. ## (gt, ":num_strings", 4),
  10382. ## (display_message, "@{s0}, {s1}, {s2}, {s3}, {s4}"),
  10383. ## (try_end),
  10384. ]),
  10385.  
  10386. ("game_get_cheat_mode",
  10387. [
  10388. (assign, reg0, "$cheat_mode"),
  10389. ]),
  10390.  
  10391. #script_game_receive_network_message
  10392. # This script is called from the game engine when a new network message is received.
  10393. # INPUT: arg1 = player_no, arg2 = event_type, arg3 = value, arg4 = value_2, arg5 = value_3, arg6 = value_4
  10394. ("game_receive_network_message",
  10395. [
  10396. (store_script_param, ":player_no", 1),
  10397. (store_script_param, ":event_type", 2),
  10398. (try_begin),
  10399. ###############
  10400. #SERVER EVENTS#
  10401. ###############
  10402. (eq, ":event_type", multiplayer_event_set_item_selection),
  10403. (store_script_param, ":slot_no", 3),
  10404. (store_script_param, ":value", 4),
  10405. (try_begin),
  10406. #valid slot check
  10407. (is_between, ":slot_no", slot_player_selected_item_indices_begin, slot_player_selected_item_indices_end),
  10408. #valid item check
  10409. (assign, ":valid_item", 0),
  10410. (try_begin),
  10411. (eq, ":value", -1),
  10412. (assign, ":valid_item", 1),
  10413. (else_try),
  10414. (ge, ":value", 0),
  10415. (player_get_troop_id, ":player_troop_no", ":player_no"),
  10416. (is_between, ":player_troop_no", multiplayer_troops_begin, multiplayer_troops_end),
  10417. (store_sub, ":troop_index", ":player_troop_no", multiplayer_troops_begin),
  10418. (val_add, ":troop_index", slot_item_multiplayer_availability_linked_list_begin),
  10419. (item_get_slot, ":prev_next_item_ids", ":value", ":troop_index"),
  10420. (gt, ":prev_next_item_ids", 0), #0 if the item is not valid for the multiplayer mode
  10421. (assign, ":valid_item", 1),
  10422. (try_begin),
  10423. (neq, "$g_horses_are_avaliable", 1),
  10424. (item_get_slot, ":item_class", ":value", slot_item_multiplayer_item_class),
  10425. (is_between, ":item_class", multi_item_class_type_horses_begin, multi_item_class_type_horses_end),
  10426. (assign, ":valid_item", 0),
  10427. (try_end),
  10428. (try_begin),
  10429. (eq, "$g_multiplayer_disallow_ranged_weapons", 1),
  10430. (item_get_slot, ":item_class", ":value", slot_item_multiplayer_item_class),
  10431. (is_between, ":item_class", multi_item_class_type_ranged_weapons_begin, multi_item_class_type_ranged_weapons_end),
  10432. (assign, ":valid_item", 0),
  10433. (try_end),
  10434. (try_end),
  10435. (eq, ":valid_item", 1),
  10436. #condition checks are done
  10437. (player_set_slot, ":player_no", ":slot_no", ":value"),
  10438. (try_end),
  10439. (else_try),
  10440. (eq, ":event_type", multiplayer_event_set_bot_selection),
  10441. (store_script_param, ":slot_no", 3),
  10442. (store_script_param, ":value", 4),
  10443. (try_begin),
  10444. #condition check
  10445. (is_between, ":slot_no", slot_player_bot_type_1_wanted, slot_player_bot_type_4_wanted + 1),
  10446. (is_between, ":value", 0, 2),
  10447. #condition checks are done
  10448. (player_set_slot, ":player_no", ":slot_no", ":value"),
  10449. (try_end),
  10450. (else_try),
  10451. (eq, ":event_type", multiplayer_event_change_team_no),
  10452. (store_script_param, ":value", 3),
  10453. (try_begin),
  10454. #validity check
  10455. (player_get_team_no, ":player_team", ":player_no"),
  10456. (neq, ":player_team", ":value"),
  10457.  
  10458. #condition checks are done
  10459. (try_begin),
  10460. #check if available
  10461. (call_script, "script_cf_multiplayer_team_is_available", ":player_no", ":value"),
  10462. #reset troop_id to -1
  10463. (player_set_troop_id, ":player_no", -1),
  10464. (player_set_team_no, ":player_no", ":value"),
  10465. (try_begin),
  10466. (neq, ":value", multi_team_spectator),
  10467. (neq, ":value", multi_team_unassigned),
  10468.  
  10469. (store_mission_timer_a, ":player_last_team_select_time"),
  10470. (player_set_slot, ":player_no", slot_player_last_team_select_time, ":player_last_team_select_time"),
  10471.  
  10472. (multiplayer_send_message_to_player, ":player_no", multiplayer_event_return_confirmation),
  10473. (try_end),
  10474. (else_try),
  10475. #reject request
  10476. (multiplayer_send_message_to_player, ":player_no", multiplayer_event_return_rejection),
  10477. (try_end),
  10478. (try_end),
  10479. (else_try),
  10480. (eq, ":event_type", multiplayer_event_change_troop_id),
  10481. (store_script_param, ":value", 3),
  10482. #troop-faction validity check
  10483. (try_begin),
  10484. (eq, ":value", -1),
  10485. (player_set_troop_id, ":player_no", -1),
  10486. (else_try),
  10487. (is_between, ":value", multiplayer_troops_begin, multiplayer_troops_end),
  10488. (player_get_team_no, ":player_team", ":player_no"),
  10489. (is_between, ":player_team", 0, multi_team_spectator),
  10490. (team_get_faction, ":team_faction", ":player_team"),
  10491. (store_troop_faction, ":new_troop_faction", ":value"),
  10492. (eq, ":new_troop_faction", ":team_faction"),
  10493. (player_set_troop_id, ":player_no", ":value"),
  10494. (call_script, "script_multiplayer_clear_player_selected_items", ":player_no"),
  10495. (try_end),
  10496. (else_try),
  10497. (eq, ":event_type", multiplayer_event_admin_start_map),
  10498. (store_script_param, ":value", 3),
  10499. (store_script_param, ":value_2", 4),
  10500. (try_begin),
  10501. #validity check
  10502. (player_is_admin, ":player_no"),
  10503. (is_between, ":value", multiplayer_scenes_begin, multiplayer_scenes_end),
  10504. (is_between, ":value_2", 0, multiplayer_num_game_types),
  10505. (server_get_changing_game_type_allowed, "$g_multiplayer_changing_game_type_allowed"),
  10506. (this_or_next|eq, "$g_multiplayer_changing_game_type_allowed", 1),
  10507. (eq, "$g_multiplayer_game_type", ":value_2"),
  10508. (call_script, "script_multiplayer_fill_map_game_types", ":value_2"),
  10509. (assign, ":num_maps", reg0),
  10510. (assign, ":is_valid", 0),
  10511. (store_add, ":end_cond", multi_data_maps_for_game_type_begin, ":num_maps"),
  10512. (try_for_range, ":i_map", multi_data_maps_for_game_type_begin, ":end_cond"),
  10513. (troop_slot_eq, "trp_multiplayer_data", ":i_map", ":value"),
  10514. (assign, ":is_valid", 1),
  10515. (assign, ":end_cond", 0),
  10516. (try_end),
  10517. (eq, ":is_valid", 1),
  10518. #condition checks are done
  10519. (assign, "$g_multiplayer_game_type", ":value_2"),
  10520. (assign, "$g_multiplayer_selected_map", ":value"),
  10521. (team_set_faction, 0, "$g_multiplayer_next_team_1_faction"),
  10522. (team_set_faction, 1, "$g_multiplayer_next_team_2_faction"),
  10523. (call_script, "script_game_multiplayer_get_game_type_mission_template", "$g_multiplayer_game_type"),
  10524. (start_multiplayer_mission, reg0, "$g_multiplayer_selected_map", 1),
  10525. (try_end),
  10526. (else_try),
  10527. (eq, ":event_type", multiplayer_event_admin_set_max_num_players),
  10528. (store_script_param, ":value", 3),
  10529. (try_begin),
  10530. #validity check
  10531. (player_is_admin, ":player_no"),
  10532. (is_between, ":value", 2, 201),
  10533. #condition checks are done
  10534. (server_set_max_num_players, ":value"),
  10535. (try_end),
  10536. (else_try),
  10537. (eq, ":event_type", multiplayer_event_admin_set_num_bots_in_team),
  10538. (store_script_param, ":value", 3),
  10539. (store_script_param, ":value_2", 4),
  10540. (try_begin),
  10541. #validity check
  10542. (player_is_admin, ":player_no"),
  10543. (is_between, ":value", 1, 3),
  10544. (is_between, ":value_2", 0, "$g_multiplayer_max_num_bots"),
  10545. #condition checks are done
  10546. (try_begin),
  10547. (eq, ":value", 1),
  10548. (assign, "$g_multiplayer_num_bots_team_1", ":value_2"),
  10549. (else_try),
  10550. (assign, "$g_multiplayer_num_bots_team_2", ":value_2"),
  10551. (try_end),
  10552. (get_max_players, ":num_players"),
  10553. (try_for_range, ":cur_player", 1, ":num_players"),
  10554. (player_is_active, ":cur_player"),
  10555. (multiplayer_send_2_int_to_player, ":cur_player", multiplayer_event_return_num_bots_in_team, ":value", ":value_2"),
  10556. (try_end),
  10557. (try_end),
  10558. (else_try),
  10559. (eq, ":event_type", multiplayer_event_admin_set_anti_cheat),
  10560. (store_script_param, ":value", 3),
  10561. (try_begin),
  10562. #validity check
  10563. (player_is_admin, ":player_no"),
  10564. (is_between, ":value", 0, 2),
  10565. #condition checks are done
  10566. (server_set_anti_cheat, ":value"),
  10567. (try_end),
  10568. (else_try),
  10569. (eq, ":event_type", multiplayer_event_admin_set_friendly_fire),
  10570. (store_script_param, ":value", 3),
  10571. (try_begin),
  10572. #validity check
  10573. (player_is_admin, ":player_no"),
  10574. (is_between, ":value", 0, 2),
  10575. #condition checks are done
  10576. (server_set_friendly_fire, ":value"),
  10577. (try_end),
  10578. (else_try),
  10579. (eq, ":event_type", multiplayer_event_admin_set_melee_friendly_fire),
  10580. (store_script_param, ":value", 3),
  10581. (try_begin),
  10582. #validity check
  10583. (player_is_admin, ":player_no"),
  10584. (is_between, ":value", 0, 2),
  10585. #condition checks are done
  10586. (server_set_melee_friendly_fire, ":value"),
  10587. (try_end),
  10588. (else_try),
  10589. (eq, ":event_type", multiplayer_event_admin_set_friendly_fire_damage_self_ratio),
  10590. (store_script_param, ":value", 3),
  10591. (try_begin),
  10592. #validity check
  10593. (player_is_admin, ":player_no"),
  10594. (is_between, ":value", 0, 101),
  10595. #condition checks are done
  10596. (server_set_friendly_fire_damage_self_ratio, ":value"),
  10597. (try_end),
  10598. (else_try),
  10599. (eq, ":event_type", multiplayer_event_admin_set_friendly_fire_damage_friend_ratio),
  10600. (store_script_param, ":value", 3),
  10601. (try_begin),
  10602. #validity check
  10603. (player_is_admin, ":player_no"),
  10604. (is_between, ":value", 0, 101),
  10605. #condition checks are done
  10606. (server_set_friendly_fire_damage_friend_ratio, ":value"),
  10607. (try_end),
  10608. (else_try),
  10609. (eq, ":event_type", multiplayer_event_admin_set_ghost_mode),
  10610. (store_script_param, ":value", 3),
  10611. (try_begin),
  10612. #validity check
  10613. (player_is_admin, ":player_no"),
  10614. (is_between, ":value", 0, 4),
  10615. #condition checks are done
  10616. (server_set_ghost_mode, ":value"),
  10617. (try_end),
  10618. (else_try),
  10619. (eq, ":event_type", multiplayer_event_admin_set_control_block_dir),
  10620. (store_script_param, ":value", 3),
  10621. (try_begin),
  10622. #validity check
  10623. (player_is_admin, ":player_no"),
  10624. (is_between, ":value", 0, 2),
  10625. #condition checks are done
  10626. (server_set_control_block_dir, ":value"),
  10627. (try_end),
  10628. (else_try),
  10629. (eq, ":event_type", multiplayer_event_admin_set_combat_speed),
  10630. (store_script_param, ":value", 3),
  10631. (try_begin),
  10632. #validity check
  10633. (player_is_admin, ":player_no"),
  10634. (is_between, ":value", 0, 5),
  10635. #condition checks are done
  10636. (server_set_combat_speed, ":value"),
  10637. (try_end),
  10638. (else_try),
  10639. (eq, ":event_type", multiplayer_event_admin_set_respawn_count),
  10640. (store_script_param, ":value", 3),
  10641. #validity check
  10642. (player_is_admin, ":player_no"),
  10643. (is_between, ":value", 0, 6),
  10644. #condition checks are done
  10645. (assign, "$g_multiplayer_number_of_respawn_count", ":value"),
  10646. (get_max_players, ":num_players"),
  10647. (try_for_range, ":cur_player", 1, ":num_players"),
  10648. (player_is_active, ":cur_player"),
  10649. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_respawn_count, ":value"),
  10650. (try_end),
  10651. (else_try),
  10652. (eq, ":event_type", multiplayer_event_admin_set_add_to_servers_list),
  10653. (store_script_param, ":value", 3),
  10654. (try_begin),
  10655. #validity check
  10656. (player_is_admin, ":player_no"),
  10657. #condition checks are done
  10658. (server_set_add_to_game_servers_list, ":value"),
  10659. (try_end),
  10660. (else_try),
  10661. (eq, ":event_type", multiplayer_event_admin_set_respawn_period),
  10662. (store_script_param, ":value", 3),
  10663. (try_begin),
  10664. #validity check
  10665. (player_is_admin, ":player_no"),
  10666. (is_between, ":value", 3, 31),
  10667. #condition checks are done
  10668. (assign, "$g_multiplayer_respawn_period", ":value"),
  10669. (get_max_players, ":num_players"),
  10670. (try_for_range, ":cur_player", 1, ":num_players"),
  10671. (player_is_active, ":cur_player"),
  10672. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_respawn_period, ":value"),
  10673. (try_end),
  10674. (try_end),
  10675. (else_try),
  10676. (eq, ":event_type", multiplayer_event_admin_set_game_max_minutes),
  10677. (store_script_param, ":value", 3),
  10678. (try_begin),
  10679. #validity check
  10680. (player_is_admin, ":player_no"),
  10681. (is_between, ":value", 5, 121),
  10682. #condition checks are done
  10683. (assign, "$g_multiplayer_game_max_minutes", ":value"),
  10684. (try_end),
  10685. (else_try),
  10686. (eq, ":event_type", multiplayer_event_admin_set_round_max_seconds),
  10687. (store_script_param, ":value", 3),
  10688. (try_begin),
  10689. #validity check
  10690. (player_is_admin, ":player_no"),
  10691. (is_between, ":value", 60, 901),
  10692. #condition checks are done
  10693. (assign, "$g_multiplayer_round_max_seconds", ":value"),
  10694. (get_max_players, ":num_players"),
  10695. (try_for_range, ":cur_player", 1, ":num_players"),
  10696. (player_is_active, ":cur_player"),
  10697. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_round_max_seconds, ":value"),
  10698. (try_end),
  10699. (try_end),
  10700. (else_try),
  10701. (eq, ":event_type", multiplayer_event_admin_set_player_respawn_as_bot),
  10702. (store_script_param, ":value", 3),
  10703. (try_begin),
  10704. #validity check
  10705. (player_is_admin, ":player_no"),
  10706. (is_between, ":value", 0, 2),
  10707. #condition checks are done
  10708. (assign, "$g_multiplayer_player_respawn_as_bot", ":value"),
  10709. (get_max_players, ":num_players"),
  10710. (try_for_range, ":cur_player", 1, ":num_players"),
  10711. (player_is_active, ":cur_player"),
  10712. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_player_respawn_as_bot, ":value"),
  10713. (try_end),
  10714. (try_end),
  10715. (else_try),
  10716. (eq, ":event_type", multiplayer_event_admin_set_game_max_points),
  10717. (store_script_param, ":value", 3),
  10718. (try_begin),
  10719. #validity check
  10720. (player_is_admin, ":player_no"),
  10721. (is_between, ":value", 3, 1001),
  10722. #condition checks are done
  10723. (assign, "$g_multiplayer_game_max_points", ":value"),
  10724. (try_end),
  10725. (else_try),
  10726. (eq, ":event_type", multiplayer_event_admin_set_point_gained_from_flags),
  10727. (store_script_param, ":value", 3),
  10728. (try_begin),
  10729. #validity check
  10730. (player_is_admin, ":player_no"),
  10731. (is_between, ":value", 25, 401),
  10732. #condition checks are done
  10733. (assign, "$g_multiplayer_point_gained_from_flags", ":value"),
  10734. (try_end),
  10735. (else_try),
  10736. (eq, ":event_type", multiplayer_event_admin_set_point_gained_from_capturing_flag),
  10737. (store_script_param, ":value", 3),
  10738. (try_begin),
  10739. #validity check
  10740. (player_is_admin, ":player_no"),
  10741. (is_between, ":value", 0, 11),
  10742. #condition checks are done
  10743. (assign, "$g_multiplayer_point_gained_from_capturing_flag", ":value"),
  10744. (try_end),
  10745. (else_try),
  10746. (eq, ":event_type", multiplayer_event_admin_set_initial_gold_multiplier),
  10747. (store_script_param, ":value", 3),
  10748. (try_begin),
  10749. #validity check
  10750. (player_is_admin, ":player_no"),
  10751. (is_between, ":value", 0, 1001),
  10752. #condition checks are done
  10753. (assign, "$g_multiplayer_initial_gold_multiplier", ":value"),
  10754. (try_end),
  10755. (else_try),
  10756. (eq, ":event_type", multiplayer_event_admin_set_battle_earnings_multiplier),
  10757. (store_script_param, ":value", 3),
  10758. (try_begin),
  10759. #validity check
  10760. (player_is_admin, ":player_no"),
  10761. (is_between, ":value", 0, 1001),
  10762. #condition checks are done
  10763. (assign, "$g_multiplayer_battle_earnings_multiplier", ":value"),
  10764. (try_end),
  10765. (else_try),
  10766. (eq, ":event_type", multiplayer_event_admin_set_round_earnings_multiplier),
  10767. (store_script_param, ":value", 3),
  10768. (try_begin),
  10769. #validity check
  10770. (player_is_admin, ":player_no"),
  10771. (is_between, ":value", 0, 1001),
  10772. #condition checks are done
  10773. (assign, "$g_multiplayer_round_earnings_multiplier", ":value"),
  10774. (try_end),
  10775. (else_try),
  10776. (eq, ":event_type", multiplayer_event_admin_set_server_name),
  10777. (try_begin),
  10778. #validity check
  10779. (player_is_admin, ":player_no"),
  10780. (server_get_renaming_server_allowed, "$g_multiplayer_renaming_server_allowed"),
  10781. (eq, "$g_multiplayer_renaming_server_allowed", 1),
  10782. #condition checks are done
  10783. (server_set_name, s0), #validity is checked inside this function
  10784. (try_end),
  10785. (else_try),
  10786. (eq, ":event_type", multiplayer_event_admin_set_game_password),
  10787. (try_begin),
  10788. #validity check
  10789. (player_is_admin, ":player_no"),
  10790. #condition checks are done
  10791. (server_set_password, s0), #validity is checked inside this function
  10792. (try_end),
  10793. (else_try),
  10794. (eq, ":event_type", multiplayer_event_admin_set_welcome_message),
  10795. (try_begin),
  10796. #validity check
  10797. (player_is_admin, ":player_no"),
  10798. #condition checks are done
  10799. (server_set_welcome_message, s0), #validity is checked inside this function
  10800. (try_end),
  10801. (else_try),
  10802. (eq, ":event_type", multiplayer_event_admin_set_team_faction),
  10803. (store_script_param, ":value", 3),
  10804. (store_script_param, ":value_2", 4),
  10805. (try_begin),
  10806. #validity check
  10807. (player_is_admin, ":player_no"),
  10808. (is_between, ":value", 1, 3),
  10809. (is_between, ":value_2", npc_kingdoms_begin, npc_kingdoms_end),
  10810. ## (assign, ":is_valid", 0),
  10811. ## (try_begin),
  10812. ## (eq, ":value", 1),
  10813. ## (neq, ":value_2", "$g_multiplayer_next_team_2_faction"),
  10814. ## (assign, ":is_valid", 1),
  10815. ## (else_try),
  10816. ## (neq, ":value_2", "$g_multiplayer_next_team_1_faction"),
  10817. ## (assign, ":is_valid", 1),
  10818. ## (try_end),
  10819. ## (eq, ":is_valid", 1),
  10820. #condition checks are done
  10821. (try_begin),
  10822. (eq, ":value", 1),
  10823. (assign, "$g_multiplayer_next_team_1_faction", ":value_2"),
  10824. (else_try),
  10825. (assign, "$g_multiplayer_next_team_2_faction", ":value_2"),
  10826. (try_end),
  10827. (try_end),
  10828. (else_try),
  10829. (eq, ":event_type", multiplayer_event_open_game_rules),
  10830. (try_begin),
  10831. #no validity check
  10832. (server_get_max_num_players, ":max_num_players"),
  10833. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_max_num_players, ":max_num_players"),
  10834. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_next_team_faction, 1, "$g_multiplayer_next_team_1_faction"),
  10835. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_next_team_faction, 2, "$g_multiplayer_next_team_2_faction"),
  10836. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_num_bots_in_team, 1, "$g_multiplayer_num_bots_team_1"),
  10837. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_num_bots_in_team, 2, "$g_multiplayer_num_bots_team_2"),
  10838. (server_get_anti_cheat, ":server_anti_cheat"),
  10839. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_anti_cheat, ":server_anti_cheat"),
  10840. (server_get_friendly_fire, ":server_friendly_fire"),
  10841. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_friendly_fire, ":server_friendly_fire"),
  10842. (server_get_melee_friendly_fire, ":server_melee_friendly_fire"),
  10843. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_melee_friendly_fire, ":server_melee_friendly_fire"),
  10844. (server_get_friendly_fire_damage_self_ratio, ":friendly_fire_damage_self_ratio"),
  10845. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_friendly_fire_damage_self_ratio, ":friendly_fire_damage_self_ratio"),
  10846. (server_get_friendly_fire_damage_friend_ratio, ":friendly_fire_damage_friend_ratio"),
  10847. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_friendly_fire_damage_friend_ratio, ":friendly_fire_damage_friend_ratio"),
  10848. (server_get_ghost_mode, ":server_ghost_mode"),
  10849. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_ghost_mode, ":server_ghost_mode"),
  10850. (server_get_control_block_dir, ":server_control_block_dir"),
  10851. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_control_block_dir, ":server_control_block_dir"),
  10852. (server_get_combat_speed, ":server_combat_speed"),
  10853. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_combat_speed, ":server_combat_speed"),
  10854. (server_get_add_to_game_servers_list, ":server_add_to_servers_list"),
  10855. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_add_to_servers_list, ":server_add_to_servers_list"),
  10856. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_respawn_period, "$g_multiplayer_respawn_period"),
  10857. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_game_max_minutes, "$g_multiplayer_game_max_minutes"),
  10858. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_round_max_seconds, "$g_multiplayer_round_max_seconds"),
  10859. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_player_respawn_as_bot, "$g_multiplayer_player_respawn_as_bot"),
  10860. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_game_max_points, "$g_multiplayer_game_max_points"),
  10861. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_point_gained_from_flags, "$g_multiplayer_point_gained_from_flags"),
  10862. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_point_gained_from_capturing_flag, "$g_multiplayer_point_gained_from_capturing_flag"),
  10863. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_initial_gold_multiplier, "$g_multiplayer_initial_gold_multiplier"),
  10864. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_battle_earnings_multiplier, "$g_multiplayer_battle_earnings_multiplier"),
  10865. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_round_earnings_multiplier, "$g_multiplayer_round_earnings_multiplier"),
  10866. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_valid_vote_ratio, "$g_multiplayer_valid_vote_ratio"),
  10867. (str_store_server_name, s0),
  10868. (multiplayer_send_string_to_player, ":player_no", multiplayer_event_return_server_name, s0),
  10869. (multiplayer_send_message_to_player, ":player_no", multiplayer_event_return_open_game_rules),
  10870. (try_end),
  10871. (else_try),
  10872. (eq, ":event_type", multiplayer_event_open_admin_panel),
  10873. (try_begin),
  10874. #validity check
  10875. (player_is_admin, ":player_no"),
  10876. #condition checks are done
  10877. (server_get_renaming_server_allowed, "$g_multiplayer_renaming_server_allowed"),
  10878. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_renaming_server_allowed, "$g_multiplayer_renaming_server_allowed"),
  10879. (server_get_changing_game_type_allowed, "$g_multiplayer_changing_game_type_allowed"),
  10880. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_changing_game_type_allowed, "$g_multiplayer_changing_game_type_allowed"),
  10881. (server_get_max_num_players, ":max_num_players"),
  10882. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_max_num_players, ":max_num_players"),
  10883. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_next_team_faction, 1, "$g_multiplayer_next_team_1_faction"),
  10884. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_next_team_faction, 2, "$g_multiplayer_next_team_2_faction"),
  10885. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_num_bots_in_team, 1, "$g_multiplayer_num_bots_team_1"),
  10886. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_num_bots_in_team, 2, "$g_multiplayer_num_bots_team_2"),
  10887. (server_get_anti_cheat, ":server_anti_cheat"),
  10888. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_anti_cheat, ":server_anti_cheat"),
  10889. (server_get_friendly_fire, ":server_friendly_fire"),
  10890. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_friendly_fire, ":server_friendly_fire"),
  10891. (server_get_melee_friendly_fire, ":server_melee_friendly_fire"),
  10892. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_melee_friendly_fire, ":server_melee_friendly_fire"),
  10893. (server_get_friendly_fire_damage_self_ratio, ":friendly_fire_damage_self_ratio"),
  10894. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_friendly_fire_damage_self_ratio, ":friendly_fire_damage_self_ratio"),
  10895. (server_get_friendly_fire_damage_friend_ratio, ":friendly_fire_damage_friend_ratio"),
  10896. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_friendly_fire_damage_friend_ratio, ":friendly_fire_damage_friend_ratio"),
  10897. (server_get_ghost_mode, ":server_ghost_mode"),
  10898. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_ghost_mode, ":server_ghost_mode"),
  10899. (server_get_control_block_dir, ":server_control_block_dir"),
  10900. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_control_block_dir, ":server_control_block_dir"),
  10901. (server_get_combat_speed, ":server_combat_speed"),
  10902. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_combat_speed, ":server_combat_speed"),
  10903. (server_get_add_to_game_servers_list, ":server_add_to_servers_list"),
  10904. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_add_to_servers_list, ":server_add_to_servers_list"),
  10905. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_respawn_period, "$g_multiplayer_respawn_period"),
  10906. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_game_max_minutes, "$g_multiplayer_game_max_minutes"),
  10907. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_round_max_seconds, "$g_multiplayer_round_max_seconds"),
  10908. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_player_respawn_as_bot, "$g_multiplayer_player_respawn_as_bot"),
  10909. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_game_max_points, "$g_multiplayer_game_max_points"),
  10910. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_point_gained_from_flags, "$g_multiplayer_point_gained_from_flags"),
  10911. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_point_gained_from_capturing_flag, "$g_multiplayer_point_gained_from_capturing_flag"),
  10912. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_initial_gold_multiplier, "$g_multiplayer_initial_gold_multiplier"),
  10913. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_battle_earnings_multiplier, "$g_multiplayer_battle_earnings_multiplier"),
  10914. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_round_earnings_multiplier, "$g_multiplayer_round_earnings_multiplier"),
  10915. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_valid_vote_ratio, "$g_multiplayer_valid_vote_ratio"),
  10916. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_max_num_bots, "$g_multiplayer_max_num_bots"),
  10917. (str_store_server_name, s0),
  10918. (multiplayer_send_string_to_player, ":player_no", multiplayer_event_return_server_name, s0),
  10919. (str_store_server_password, s0),
  10920. (multiplayer_send_string_to_player, ":player_no", multiplayer_event_return_game_password, s0),
  10921. (try_end),
  10922. (else_try),
  10923. (eq, ":event_type", multiplayer_event_start_new_poll),
  10924. (try_begin),
  10925. (store_script_param, ":value", 3),
  10926. (store_script_param, ":value_2", 4),
  10927. #validity check
  10928. (eq, "$g_multiplayer_poll_running", 0),
  10929. (store_mission_timer_a, ":mission_timer"),
  10930. (player_get_slot, ":poll_disable_time", ":player_no", slot_player_poll_disabled_until_time),
  10931. (ge, ":mission_timer", ":poll_disable_time"),
  10932. (assign, ":continue", 0),
  10933. (try_begin),
  10934. (eq, ":value", 1), # kicking a player
  10935. (try_begin),
  10936. (eq, "$g_multiplayer_kick_voteable", 1),
  10937. (player_is_active, ":value_2"),
  10938. (assign, ":continue", 1),
  10939. (try_end),
  10940. (else_try),
  10941. (eq, ":value", 2), # banning a player
  10942. (try_begin),
  10943. (eq, "$g_multiplayer_ban_voteable", 1),
  10944. (player_is_active, ":value_2"),
  10945. (save_ban_info_of_player, ":value_2"),
  10946. (assign, ":continue", 1),
  10947. (try_end),
  10948. (else_try), # vote for map
  10949. (eq, ":value", 0),
  10950. (try_begin),
  10951. (eq, "$g_multiplayer_maps_voteable", 1),
  10952. (call_script, "script_multiplayer_fill_map_game_types", "$g_multiplayer_game_type"),
  10953. (assign, ":num_maps", reg0),
  10954. (try_for_range, ":i_map", 0, ":num_maps"),
  10955. (store_add, ":map_slot", ":i_map", multi_data_maps_for_game_type_begin),
  10956. (troop_slot_eq, "trp_multiplayer_data", ":map_slot", ":value_2"),
  10957. (assign, ":continue", 1),
  10958. (assign, ":num_maps", 0), #break
  10959. (try_end),
  10960. (try_end),
  10961. (else_try),
  10962. (eq, ":value", 3), #vote for map and factions
  10963. (try_begin),
  10964. (eq, "$g_multiplayer_factions_voteable", 1),
  10965. (store_script_param, ":value_3", 5),
  10966. (store_script_param, ":value_4", 6),
  10967. (call_script, "script_multiplayer_fill_map_game_types", "$g_multiplayer_game_type"),
  10968. (assign, ":num_maps", reg0),
  10969. (try_for_range, ":i_map", 0, ":num_maps"),
  10970. (store_add, ":map_slot", ":i_map", multi_data_maps_for_game_type_begin),
  10971. (troop_slot_eq, "trp_multiplayer_data", ":map_slot", ":value_2"),
  10972. (assign, ":continue", 1),
  10973. (assign, ":num_maps", 0), #break
  10974. (try_end),
  10975. (try_begin),
  10976. (eq, ":continue", 1),
  10977. (this_or_next|neg|is_between, ":value_3", npc_kingdoms_begin, npc_kingdoms_end),
  10978. (this_or_next|neg|is_between, ":value_4", npc_kingdoms_begin, npc_kingdoms_end),
  10979. (eq, ":value_3", ":value_4"),
  10980. (assign, ":continue", 0),
  10981. (try_end),
  10982. (try_end),
  10983. (else_try),
  10984. (eq, ":value", 4), #vote for number of bots
  10985. (store_script_param, ":value_3", 5),
  10986. (store_add, ":upper_limit", "$g_multiplayer_num_bots_voteable", 1),
  10987. (is_between, ":value_2", 0, ":upper_limit"),
  10988. (is_between, ":value_3", 0, ":upper_limit"),
  10989. (assign, ":continue", 1),
  10990. (try_end),
  10991. (eq, ":continue", 1),
  10992. #condition checks are done
  10993. (str_store_player_username, s0, ":player_no"),
  10994. (try_begin),
  10995. (eq, ":value", 1), #kicking a player
  10996. (str_store_player_username, s1, ":value_2"),
  10997. (server_add_message_to_log, "str_poll_kick_player_s1_by_s0"),
  10998. (else_try),
  10999. (eq, ":value", 2), #banning a player
  11000. (str_store_player_username, s1, ":value_2"),
  11001. (server_add_message_to_log, "str_poll_ban_player_s1_by_s0"),
  11002. (else_try),
  11003. (eq, ":value", 0), #vote for map
  11004. (store_sub, ":string_index", ":value_2", multiplayer_scenes_begin),
  11005. (val_add, ":string_index", multiplayer_scene_names_begin),
  11006. (str_store_string, s1, ":string_index"),
  11007. (server_add_message_to_log, "str_poll_change_map_to_s1_by_s0"),
  11008. (else_try),
  11009. (eq, ":value", 3), #vote for map and factions
  11010. (store_sub, ":string_index", ":value_2", multiplayer_scenes_begin),
  11011. (val_add, ":string_index", multiplayer_scene_names_begin),
  11012. (str_store_string, s1, ":string_index"),
  11013. (str_store_faction_name, s2, ":value_3"),
  11014. (str_store_faction_name, s3, ":value_4"),
  11015. (server_add_message_to_log, "str_poll_change_map_to_s1_and_factions_to_s2_and_s3_by_s0"),
  11016. (else_try),
  11017. (eq, ":value", 4), #vote for number of bots
  11018. (assign, reg0, ":value_2"),
  11019. (assign, reg1, ":value_3"),
  11020. (server_add_message_to_log, "str_poll_change_number_of_bots_to_reg0_and_reg1_by_s0"),
  11021. (try_end),
  11022. (assign, "$g_multiplayer_poll_running", 1),
  11023. (assign, "$g_multiplayer_poll_ended", 0),
  11024. (assign, "$g_multiplayer_poll_num_sent", 0),
  11025. (assign, "$g_multiplayer_poll_yes_count", 0),
  11026. (assign, "$g_multiplayer_poll_no_count", 0),
  11027. (assign, "$g_multiplayer_poll_to_show", ":value"),
  11028. (assign, "$g_multiplayer_poll_value_to_show", ":value_2"),
  11029. (try_begin),
  11030. (eq, ":value", 3),
  11031. (assign, "$g_multiplayer_poll_value_2_to_show", ":value_3"),
  11032. (assign, "$g_multiplayer_poll_value_3_to_show", ":value_4"),
  11033. (else_try),
  11034. (eq, ":value", 4),
  11035. (assign, "$g_multiplayer_poll_value_2_to_show", ":value_3"),
  11036. (assign, "$g_multiplayer_poll_value_3_to_show", -1),
  11037. (else_try),
  11038. (assign, "$g_multiplayer_poll_value_2_to_show", -1),
  11039. (assign, "$g_multiplayer_poll_value_3_to_show", -1),
  11040. (try_end),
  11041. (store_add, ":poll_disable_until", ":mission_timer", multiplayer_poll_disable_period),
  11042. (player_set_slot, ":player_no", slot_player_poll_disabled_until_time, ":poll_disable_until"),
  11043. (store_add, "$g_multiplayer_poll_end_time", ":mission_timer", 60),
  11044. (get_max_players, ":num_players"),
  11045. (try_for_range, ":cur_player", 0, ":num_players"),
  11046. (player_is_active, ":cur_player"),
  11047. (player_set_slot, ":cur_player", slot_player_can_answer_poll, 1),
  11048. (val_add, "$g_multiplayer_poll_num_sent", 1),
  11049. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_ask_for_poll, "$g_multiplayer_poll_to_show", "$g_multiplayer_poll_value_to_show", "$g_multiplayer_poll_value_2_to_show", "$g_multiplayer_poll_value_3_to_show"),
  11050. (try_end),
  11051. (try_end),
  11052. (else_try),
  11053. (eq, ":event_type", multiplayer_event_answer_to_poll),
  11054. (try_begin),
  11055. (store_script_param, ":value", 3),
  11056. #validity check
  11057. (eq, "$g_multiplayer_poll_running", 1),
  11058. (is_between, ":value", 0, 2),
  11059. (player_slot_eq, ":player_no", slot_player_can_answer_poll, 1),
  11060. #condition checks are done
  11061. (player_set_slot, ":player_no", slot_player_can_answer_poll, 0),
  11062. (try_begin),
  11063. (eq, ":value", 0),
  11064. (val_add, "$g_multiplayer_poll_no_count", 1),
  11065. (else_try),
  11066. (eq, ":value", 1),
  11067. (val_add, "$g_multiplayer_poll_yes_count", 1),
  11068. (try_end),
  11069. (try_end),
  11070. (else_try),
  11071. (eq, ":event_type", multiplayer_event_admin_kick_player),
  11072. (try_begin),
  11073. (store_script_param, ":value", 3),
  11074. #validity check
  11075. (player_is_admin, ":player_no"),
  11076. (player_is_active, ":value"),
  11077. #condition checks are done
  11078. (kick_player, ":value"),
  11079. (try_end),
  11080. (else_try),
  11081. (eq, ":event_type", multiplayer_event_admin_ban_player),
  11082. (try_begin),
  11083. (store_script_param, ":value", 3),
  11084. #validity check
  11085. (player_is_admin, ":player_no"),
  11086. (player_is_active, ":value"),
  11087. #condition checks are done
  11088. (ban_player, ":value", 0, ":player_no"),
  11089. (try_end),
  11090. (else_try),
  11091. (eq, ":event_type", multiplayer_event_admin_set_valid_vote_ratio),
  11092. (try_begin),
  11093. (store_script_param, ":value", 3),
  11094. #validity check
  11095. (player_is_admin, ":player_no"),
  11096. (is_between, ":value", 50, 101),
  11097. #condition checks are done
  11098. (assign, "$g_multiplayer_valid_vote_ratio", ":value"),
  11099. (try_end),
  11100. (else_try),
  11101. (eq, ":event_type", multiplayer_event_admin_set_auto_team_balance_limit),
  11102. (try_begin),
  11103. (store_script_param, ":value", 3),
  11104. #validity check
  11105. (player_is_admin, ":player_no"),
  11106. (this_or_next|is_between, ":value", 2, 7),
  11107. (eq, ":value", 1000),
  11108. #condition checks are done
  11109. (assign, "$g_multiplayer_auto_team_balance_limit", ":value"),
  11110. (get_max_players, ":num_players"),
  11111. (try_for_range, ":cur_player", 1, ":num_players"),
  11112. (player_is_active, ":cur_player"),
  11113. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_auto_team_balance_limit, ":value"),
  11114. (try_end),
  11115. (try_end),
  11116. (else_try),
  11117. (eq, ":event_type", multiplayer_event_admin_set_num_bots_voteable),
  11118. (try_begin),
  11119. (store_script_param, ":value", 3),
  11120. #validity check
  11121. (player_is_admin, ":player_no"),
  11122. (is_between, ":value", 0, 51),
  11123. (is_between, ":value", 0, "$g_multiplayer_max_num_bots"),
  11124. #condition checks are done
  11125. (assign, "$g_multiplayer_num_bots_voteable", ":value"),
  11126. (get_max_players, ":num_players"),
  11127. (try_for_range, ":cur_player", 1, ":num_players"),
  11128. (player_is_active, ":cur_player"),
  11129. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_num_bots_voteable, ":value"),
  11130. (try_end),
  11131. (try_end),
  11132. (else_try),
  11133. (eq, ":event_type", multiplayer_event_admin_set_factions_voteable),
  11134. (try_begin),
  11135. (store_script_param, ":value", 3),
  11136. #validity check
  11137. (player_is_admin, ":player_no"),
  11138. (is_between, ":value", 0, 2),
  11139. #condition checks are done
  11140. (assign, "$g_multiplayer_factions_voteable", ":value"),
  11141. (get_max_players, ":num_players"),
  11142. (try_for_range, ":cur_player", 1, ":num_players"),
  11143. (player_is_active, ":cur_player"),
  11144. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_factions_voteable, ":value"),
  11145. (try_end),
  11146. (try_end),
  11147. (else_try),
  11148. (eq, ":event_type", multiplayer_event_admin_set_maps_voteable),
  11149. (try_begin),
  11150. (store_script_param, ":value", 3),
  11151. #validity check
  11152. (player_is_admin, ":player_no"),
  11153. (is_between, ":value", 0, 2),
  11154. #condition checks are done
  11155. (assign, "$g_multiplayer_maps_voteable", ":value"),
  11156. (get_max_players, ":num_players"),
  11157. (try_for_range, ":cur_player", 1, ":num_players"),
  11158. (player_is_active, ":cur_player"),
  11159. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_maps_voteable, ":value"),
  11160. (try_end),
  11161. (try_end),
  11162. (else_try),
  11163. (eq, ":event_type", multiplayer_event_admin_set_kick_voteable),
  11164. (try_begin),
  11165. (store_script_param, ":value", 3),
  11166. #validity check
  11167. (player_is_admin, ":player_no"),
  11168. (is_between, ":value", 0, 2),
  11169. #condition checks are done
  11170. (assign, "$g_multiplayer_kick_voteable", ":value"),
  11171. (get_max_players, ":num_players"),
  11172. (try_for_range, ":cur_player", 1, ":num_players"),
  11173. (player_is_active, ":cur_player"),
  11174. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_kick_voteable, ":value"),
  11175. (try_end),
  11176. (try_end),
  11177. (else_try),
  11178. (eq, ":event_type", multiplayer_event_admin_set_ban_voteable),
  11179. (try_begin),
  11180. (store_script_param, ":value", 3),
  11181. #validity check
  11182. (player_is_admin, ":player_no"),
  11183. (is_between, ":value", 0, 2),
  11184. #condition checks are done
  11185. (assign, "$g_multiplayer_ban_voteable", ":value"),
  11186. (get_max_players, ":num_players"),
  11187. (try_for_range, ":cur_player", 1, ":num_players"),
  11188. (player_is_active, ":cur_player"),
  11189. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_return_ban_voteable, ":value"),
  11190. (try_end),
  11191. (try_end),
  11192. (else_try),
  11193. (eq, ":event_type", multiplayer_event_admin_set_allow_player_banners),
  11194. (try_begin),
  11195. (store_script_param, ":value", 3),
  11196. #validity check
  11197. (player_is_admin, ":player_no"),
  11198. (is_between, ":value", 0, 2),
  11199. #condition checks are done
  11200. (assign, "$g_multiplayer_allow_player_banners", ":value"),
  11201. (try_end),
  11202. (else_try),
  11203. (eq, ":event_type", multiplayer_event_admin_set_force_default_armor),
  11204. (try_begin),
  11205. (store_script_param, ":value", 3),
  11206. #validity check
  11207. (player_is_admin, ":player_no"),
  11208. (is_between, ":value", 0, 2),
  11209. #condition checks are done
  11210. (assign, "$g_multiplayer_force_default_armor", ":value"),
  11211. (try_end),
  11212. (else_try),
  11213. (eq, ":event_type", multiplayer_event_offer_duel),
  11214. (try_begin),
  11215. (store_script_param, ":value", 3),
  11216. #validity check
  11217. (eq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
  11218. (agent_is_active, ":value"),
  11219. (agent_is_alive, ":value"),
  11220. (agent_is_human, ":value"),
  11221. (player_get_agent_id, ":player_agent_no", ":player_no"),
  11222. (agent_is_active, ":player_agent_no"),
  11223. (agent_is_alive, ":player_agent_no"),
  11224. (agent_get_position, pos0, ":player_agent_no"),
  11225. (agent_get_position, pos1, ":value"),
  11226. (get_sq_distance_between_positions_in_meters, ":agent_dist_sq", pos0, pos1),
  11227. (le, ":agent_dist_sq", 49),
  11228. #allow duelists to receive new offers
  11229. (this_or_next|agent_check_offer_from_agent, ":player_agent_no", ":value"),
  11230. (agent_slot_eq, ":player_agent_no", slot_agent_in_duel_with, -1),
  11231. (neg|agent_slot_eq, ":player_agent_no", slot_agent_in_duel_with, ":value"), #don't allow spamming duel offers during countdown
  11232. #condition checks are done
  11233. (try_begin),
  11234. #accepting a duel
  11235. (agent_check_offer_from_agent, ":player_agent_no", ":value"),
  11236. (call_script, "script_multiplayer_accept_duel", ":player_agent_no", ":value"),
  11237. (else_try),
  11238. #sending a duel request
  11239. (assign, ":display_notification", 1),
  11240. (try_begin),
  11241. (agent_check_offer_from_agent, ":value", ":player_agent_no"),
  11242. (assign, ":display_notification", 0),
  11243. (try_end),
  11244. (agent_add_offer_with_timeout, ":value", ":player_agent_no", 10000), #10 second timeout
  11245. (agent_get_player_id, ":value_player", ":value"),
  11246. (try_begin),
  11247. (player_is_active, ":value_player"), #might be AI
  11248. (try_begin),
  11249. (eq, ":display_notification", 1),
  11250. (multiplayer_send_int_to_player, ":value_player", multiplayer_event_show_duel_request, ":player_agent_no"),
  11251. (try_end),
  11252. (else_try),
  11253. (call_script, "script_multiplayer_accept_duel", ":value", ":player_agent_no"),
  11254. (try_end),
  11255. (try_end),
  11256. (try_end),
  11257. (else_try),
  11258. (eq, ":event_type", multiplayer_event_admin_set_disallow_ranged_weapons),
  11259. (try_begin),
  11260. (store_script_param, ":value", 3),
  11261. #validity check
  11262. (player_is_admin, ":player_no"),
  11263. (is_between, ":value", 0, 2),
  11264. #condition checks are done
  11265. (assign, "$g_multiplayer_disallow_ranged_weapons", ":value"),
  11266. (try_end),
  11267. (else_try),
  11268. ###############
  11269. #CLIENT EVENTS#
  11270. ###############
  11271. (neg|multiplayer_is_dedicated_server),
  11272. (try_begin),
  11273. (eq, ":event_type", multiplayer_event_return_renaming_server_allowed),
  11274. (store_script_param, ":value", 3),
  11275. (assign, "$g_multiplayer_renaming_server_allowed", ":value"),
  11276. (else_try),
  11277. (eq, ":event_type", multiplayer_event_return_changing_game_type_allowed),
  11278. (store_script_param, ":value", 3),
  11279. (assign, "$g_multiplayer_changing_game_type_allowed", ":value"),
  11280. (else_try),
  11281. (eq, ":event_type", multiplayer_event_return_max_num_players),
  11282. (store_script_param, ":value", 3),
  11283. (server_set_max_num_players, ":value"),
  11284. (else_try),
  11285. (eq, ":event_type", multiplayer_event_return_next_team_faction),
  11286. (store_script_param, ":value", 3),
  11287. (store_script_param, ":value_2", 4),
  11288. (try_begin),
  11289. (eq, ":value", 1),
  11290. (assign, "$g_multiplayer_next_team_1_faction", ":value_2"),
  11291. (else_try),
  11292. (assign, "$g_multiplayer_next_team_2_faction", ":value_2"),
  11293. (try_end),
  11294. (else_try),
  11295. (eq, ":event_type", multiplayer_event_return_num_bots_in_team),
  11296. (store_script_param, ":value", 3),
  11297. (store_script_param, ":value_2", 4),
  11298. (try_begin),
  11299. (eq, ":value", 1),
  11300. (assign, "$g_multiplayer_num_bots_team_1", ":value_2"),
  11301. (else_try),
  11302. (assign, "$g_multiplayer_num_bots_team_2", ":value_2"),
  11303. (try_end),
  11304. (else_try),
  11305. (eq, ":event_type", multiplayer_event_return_anti_cheat),
  11306. (store_script_param, ":value", 3),
  11307. (server_set_anti_cheat, ":value"),
  11308. (else_try),
  11309. (eq, ":event_type", multiplayer_event_return_friendly_fire),
  11310. (store_script_param, ":value", 3),
  11311. (server_set_friendly_fire, ":value"),
  11312. (else_try),
  11313. (eq, ":event_type", multiplayer_event_return_melee_friendly_fire),
  11314. (store_script_param, ":value", 3),
  11315. (server_set_melee_friendly_fire, ":value"),
  11316. (else_try),
  11317. (eq, ":event_type", multiplayer_event_return_friendly_fire_damage_self_ratio),
  11318. (store_script_param, ":value", 3),
  11319. (server_set_friendly_fire_damage_self_ratio, ":value"),
  11320. (else_try),
  11321. (eq, ":event_type", multiplayer_event_return_friendly_fire_damage_friend_ratio),
  11322. (store_script_param, ":value", 3),
  11323. (server_set_friendly_fire_damage_friend_ratio, ":value"),
  11324. (else_try),
  11325. (eq, ":event_type", multiplayer_event_return_ghost_mode),
  11326. (store_script_param, ":value", 3),
  11327. (server_set_ghost_mode, ":value"),
  11328. (else_try),
  11329. (eq, ":event_type", multiplayer_event_return_control_block_dir),
  11330. (store_script_param, ":value", 3),
  11331. (server_set_control_block_dir, ":value"),
  11332. (else_try),
  11333. (eq, ":event_type", multiplayer_event_return_add_to_servers_list),
  11334. (store_script_param, ":value", 3),
  11335. (server_set_add_to_game_servers_list, ":value"),
  11336. (else_try),
  11337. (eq, ":event_type", multiplayer_event_return_respawn_period),
  11338. (store_script_param, ":value", 3),
  11339. (assign, "$g_multiplayer_respawn_period", ":value"),
  11340. (else_try),
  11341. (eq, ":event_type", multiplayer_event_return_game_max_minutes),
  11342. (store_script_param, ":value", 3),
  11343. (assign, "$g_multiplayer_game_max_minutes", ":value"),
  11344. (else_try),
  11345. (eq, ":event_type", multiplayer_event_return_round_max_seconds),
  11346. (store_script_param, ":value", 3),
  11347. (assign, "$g_multiplayer_round_max_seconds", ":value"),
  11348. (else_try),
  11349. (eq, ":event_type", multiplayer_event_return_player_respawn_as_bot),
  11350. (store_script_param, ":value", 3),
  11351. (assign, "$g_multiplayer_player_respawn_as_bot", ":value"),
  11352. (else_try),
  11353. (eq, ":event_type", multiplayer_event_return_game_max_points),
  11354. (store_script_param, ":value", 3),
  11355. (assign, "$g_multiplayer_game_max_points", ":value"),
  11356. (else_try),
  11357. (eq, ":event_type", multiplayer_event_return_point_gained_from_flags),
  11358. (store_script_param, ":value", 3),
  11359. (assign, "$g_multiplayer_point_gained_from_flags", ":value"),
  11360. (else_try),
  11361. (eq, ":event_type", multiplayer_event_return_point_gained_from_capturing_flag),
  11362. (store_script_param, ":value", 3),
  11363. (assign, "$g_multiplayer_point_gained_from_capturing_flag", ":value"),
  11364. (else_try),
  11365. (eq, ":event_type", multiplayer_event_return_initial_gold_multiplier),
  11366. (store_script_param, ":value", 3),
  11367. (assign, "$g_multiplayer_initial_gold_multiplier", ":value"),
  11368. (else_try),
  11369. (eq, ":event_type", multiplayer_event_return_battle_earnings_multiplier),
  11370. (store_script_param, ":value", 3),
  11371. (assign, "$g_multiplayer_battle_earnings_multiplier", ":value"),
  11372. (else_try),
  11373. (eq, ":event_type", multiplayer_event_return_round_earnings_multiplier),
  11374. (store_script_param, ":value", 3),
  11375. (assign, "$g_multiplayer_round_earnings_multiplier", ":value"),
  11376. (else_try),
  11377. (eq, ":event_type", multiplayer_event_return_respawn_count),
  11378. (store_script_param, ":value", 3),
  11379. (assign, "$g_multiplayer_number_of_respawn_count", ":value"),
  11380. (else_try),
  11381. (eq, ":event_type", multiplayer_event_return_server_name),
  11382. (server_set_name, s0),
  11383. (else_try),
  11384. (eq, ":event_type", multiplayer_event_return_game_password),
  11385. (server_set_password, s0),
  11386. #this is the last option in admin panel, so start the presentation
  11387. (start_presentation, "prsnt_game_multiplayer_admin_panel"),
  11388. (else_try),
  11389. (eq, ":event_type", multiplayer_event_return_open_game_rules),
  11390. #this is the last message for game rules, so start the presentation
  11391. (assign, "$g_multiplayer_show_server_rules", 1),
  11392. (start_presentation, "prsnt_multiplayer_welcome_message"),
  11393. (else_try),
  11394. (eq, ":event_type", multiplayer_event_return_game_type),
  11395. (store_script_param, ":value", 3),
  11396. (assign, "$g_multiplayer_game_type", ":value"),
  11397. (else_try),
  11398. (eq, ":event_type", multiplayer_event_return_valid_vote_ratio),
  11399. (store_script_param, ":value", 3),
  11400. (assign, "$g_multiplayer_valid_vote_ratio", ":value"),
  11401. (else_try),
  11402. (eq, ":event_type", multiplayer_event_return_max_num_bots),
  11403. (store_script_param, ":value", 3),
  11404. (assign, "$g_multiplayer_max_num_bots", ":value"),
  11405. (else_try),
  11406. (eq, ":event_type", multiplayer_event_return_server_mission_timer_while_player_joined),
  11407. (store_script_param, ":value", 3),
  11408. (assign, "$server_mission_timer_while_player_joined", ":value"),
  11409. (else_try),
  11410. (eq, ":event_type", multiplayer_event_return_auto_team_balance_limit),
  11411. (store_script_param, ":value", 3),
  11412. (assign, "$g_multiplayer_auto_team_balance_limit", ":value"),
  11413. (else_try),
  11414. (eq, ":event_type", multiplayer_event_return_num_bots_voteable),
  11415. (store_script_param, ":value", 3),
  11416. (assign, "$g_multiplayer_num_bots_voteable", ":value"),
  11417. (else_try),
  11418. (eq, ":event_type", multiplayer_event_return_factions_voteable),
  11419. (store_script_param, ":value", 3),
  11420. (assign, "$g_multiplayer_factions_voteable", ":value"),
  11421. (else_try),
  11422. (eq, ":event_type", multiplayer_event_return_maps_voteable),
  11423. (store_script_param, ":value", 3),
  11424. (assign, "$g_multiplayer_maps_voteable", ":value"),
  11425. (else_try),
  11426. (eq, ":event_type", multiplayer_event_return_kick_voteable),
  11427. (store_script_param, ":value", 3),
  11428. (assign, "$g_multiplayer_kick_voteable", ":value"),
  11429. (else_try),
  11430. (eq, ":event_type", multiplayer_event_return_ban_voteable),
  11431. (store_script_param, ":value", 3),
  11432. (assign, "$g_multiplayer_ban_voteable", ":value"),
  11433. (else_try),
  11434. (eq, ":event_type", multiplayer_event_return_allow_player_banners),
  11435. (store_script_param, ":value", 3),
  11436. (assign, "$g_multiplayer_allow_player_banners", ":value"),
  11437. (else_try),
  11438. (eq, ":event_type", multiplayer_event_return_force_default_armor),
  11439. (store_script_param, ":value", 3),
  11440. (assign, "$g_multiplayer_force_default_armor", ":value"),
  11441. (else_try),
  11442. (eq, ":event_type", multiplayer_event_return_disallow_ranged_weapons),
  11443. (store_script_param, ":value", 3),
  11444. (assign, "$g_multiplayer_disallow_ranged_weapons", ":value"),
  11445. (else_try),
  11446. (eq, ":event_type", multiplayer_event_return_confirmation),
  11447. (assign, "$g_confirmation_result", 1),
  11448. (else_try),
  11449. (eq, ":event_type", multiplayer_event_return_rejection),
  11450. (assign, "$g_confirmation_result", -1),
  11451. (else_try),
  11452. (eq, ":event_type", multiplayer_event_show_multiplayer_message),
  11453. (store_script_param, ":value", 3),
  11454. (store_script_param, ":value_2", 4),
  11455. (call_script, "script_show_multiplayer_message", ":value", ":value_2"),
  11456. (else_try),
  11457. (eq, ":event_type", multiplayer_event_draw_this_round),
  11458. (store_script_param, ":value", 3),
  11459. (call_script, "script_draw_this_round", ":value"),
  11460. (else_try),
  11461. (eq, ":event_type", multiplayer_event_set_attached_scene_prop),
  11462. (store_script_param, ":value", 3),
  11463. (store_script_param, ":value_2", 4),
  11464. (call_script, "script_set_attached_scene_prop", ":value", ":value_2"),
  11465. (try_begin),
  11466. (eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  11467. (try_begin),
  11468. (neq, ":value_2", -1),
  11469. (agent_set_horse_speed_factor, ":value", 75),
  11470. (else_try),
  11471. (agent_set_horse_speed_factor, ":value", 100),
  11472. (try_end),
  11473. (try_end),
  11474. (else_try),
  11475. (eq, ":event_type", multiplayer_event_set_team_flag_situation),
  11476. (store_script_param, ":value", 3),
  11477. (store_script_param, ":value_2", 4),
  11478. (call_script, "script_set_team_flag_situation", ":value", ":value_2"),
  11479. (else_try),
  11480. (eq, ":event_type", multiplayer_event_set_team_score),
  11481. (store_script_param, ":value", 3),
  11482. (store_script_param, ":value_2", 4),
  11483. (call_script, "script_team_set_score", ":value", ":value_2"),
  11484. (else_try),
  11485. (eq, ":event_type", multiplayer_event_set_player_score_kill_death),
  11486. (store_script_param, ":value", 3),
  11487. (store_script_param, ":value_2", 4),
  11488. (store_script_param, ":value_3", 5),
  11489. (store_script_param, ":value_4", 6),
  11490. (call_script, "script_player_set_score", ":value", ":value_2"),
  11491. (call_script, "script_player_set_kill_count", ":value", ":value_3"),
  11492. (call_script, "script_player_set_death_count", ":value", ":value_4"),
  11493. (else_try),
  11494. (eq, ":event_type", multiplayer_event_set_num_agents_around_flag),
  11495. (store_script_param, ":flag_no", 3),
  11496. (store_script_param, ":current_owner_code", 4),
  11497. (call_script, "script_set_num_agents_around_flag", ":flag_no", ":current_owner_code"),
  11498. (else_try),
  11499. (eq, ":event_type", multiplayer_event_ask_for_poll),
  11500. (store_script_param, ":value", 3),
  11501. (store_script_param, ":value_2", 4),
  11502. (store_script_param, ":value_3", 5),
  11503. (store_script_param, ":value_4", 6),
  11504. (assign, ":continue_to_poll", 0),
  11505. (try_begin),
  11506. (this_or_next|eq, ":value", 1),
  11507. (eq, ":value", 2),
  11508. (player_is_active, ":value_2"), #might go offline before here
  11509. (assign, ":continue_to_poll", 1),
  11510. (else_try),
  11511. (assign, ":continue_to_poll", 1),
  11512. (try_end),
  11513. (try_begin),
  11514. (eq, ":continue_to_poll", 1),
  11515. (assign, "$g_multiplayer_poll_to_show", ":value"),
  11516. (assign, "$g_multiplayer_poll_value_to_show", ":value_2"),
  11517. (assign, "$g_multiplayer_poll_value_2_to_show", ":value_3"),
  11518. (assign, "$g_multiplayer_poll_value_3_to_show", ":value_4"),
  11519. (store_mission_timer_a, ":mission_timer"),
  11520. (store_add, "$g_multiplayer_poll_client_end_time", ":mission_timer", 60),
  11521. (start_presentation, "prsnt_multiplayer_poll"),
  11522. (try_end),
  11523. (else_try),
  11524. (eq, ":event_type", multiplayer_event_change_flag_owner),
  11525. (store_script_param, ":flag_no", 3),
  11526. (store_script_param, ":owner_code", 4),
  11527. (call_script, "script_change_flag_owner", ":flag_no", ":owner_code"),
  11528. (else_try),
  11529. (eq, ":event_type", multiplayer_event_use_item),
  11530. (store_script_param, ":value", 3),
  11531. (store_script_param, ":value_2", 4),
  11532. (call_script, "script_use_item", ":value", ":value_2"),
  11533. (else_try),
  11534. (eq, ":event_type", multiplayer_event_set_scene_prop_open_or_close),
  11535. (store_script_param, ":instance_id", 3),
  11536.  
  11537. (scene_prop_set_slot, ":instance_id", scene_prop_open_or_close_slot, 1),
  11538.  
  11539. (prop_instance_get_scene_prop_kind, ":scene_prop_id", ":instance_id"),
  11540.  
  11541. (try_begin),
  11542. (eq, ":scene_prop_id", "spr_winch_b"),
  11543. (assign, ":effected_object", "spr_portcullis"),
  11544. (else_try),
  11545. (this_or_next|eq, ":scene_prop_id", "spr_castle_e_sally_door_a"),
  11546. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_sally_door_a"),
  11547. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_left"),
  11548. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_right"),
  11549. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_left"),
  11550. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_right"),
  11551. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_door_a"),
  11552. (this_or_next|eq, ":scene_prop_id", "spr_door_destructible"),
  11553. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_door_b"),
  11554. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_6m"),
  11555. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_8m"),
  11556. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_10m"),
  11557. (this_or_next|eq, ":scene_prop_id", "spr_siege_ladder_move_12m"),
  11558. (eq, ":scene_prop_id", "spr_siege_ladder_move_14m"),
  11559. (assign, ":effected_object", ":scene_prop_id"),
  11560. (try_end),
  11561.  
  11562. (try_begin),
  11563. (eq, ":effected_object", "spr_portcullis"),
  11564.  
  11565. (assign, ":smallest_dist", -1),
  11566. (prop_instance_get_position, pos0, ":instance_id"),
  11567. (scene_prop_get_num_instances, ":num_instances_of_effected_object", ":effected_object"),
  11568. (try_for_range, ":cur_instance", 0, ":num_instances_of_effected_object"),
  11569. (scene_prop_get_instance, ":cur_instance_id", ":effected_object", ":cur_instance"),
  11570. (prop_instance_get_position, pos1, ":cur_instance_id"),
  11571. (get_sq_distance_between_positions, ":dist", pos0, pos1),
  11572. (this_or_next|eq, ":smallest_dist", -1),
  11573. (lt, ":dist", ":smallest_dist"),
  11574. (assign, ":smallest_dist", ":dist"),
  11575. (assign, ":effected_object_instance_id", ":cur_instance_id"),
  11576. (try_end),
  11577.  
  11578. (ge, ":smallest_dist", 0),
  11579. (prop_instance_is_animating, ":is_animating", ":effected_object_instance_id"),
  11580. (eq, ":is_animating", 0),
  11581.  
  11582. (prop_instance_get_starting_position, pos0, ":effected_object_instance_id"),
  11583. (position_move_z, pos0, 375),
  11584. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 1),
  11585. (else_try),
  11586. (this_or_next|eq, ":scene_prop_id", "spr_castle_e_sally_door_a"),
  11587. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_sally_door_a"),
  11588. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_left"),
  11589. (this_or_next|eq, ":scene_prop_id", "spr_earth_sally_gate_right"),
  11590. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_left"),
  11591. (this_or_next|eq, ":scene_prop_id", "spr_viking_keep_destroy_sally_door_right"),
  11592. (this_or_next|eq, ":scene_prop_id", "spr_castle_f_door_a"),
  11593. (this_or_next|eq, ":scene_prop_id", "spr_door_destructible"),
  11594. (eq, ":scene_prop_id", "spr_castle_f_door_b"),
  11595. (assign, ":effected_object_instance_id", ":instance_id"),
  11596. (prop_instance_get_starting_position, pos0, ":effected_object_instance_id"),
  11597. (position_rotate_z, pos0, -80),
  11598. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 1),
  11599. (else_try),
  11600. (assign, ":effected_object_instance_id", ":instance_id"),
  11601. (prop_instance_is_animating, ":is_animating", ":effected_object_instance_id"),
  11602. (eq, ":is_animating", 0),
  11603. (prop_instance_get_starting_position, pos0, ":effected_object_instance_id"),
  11604. (prop_instance_animate_to_position, ":effected_object_instance_id", pos0, 1),
  11605. (try_end),
  11606. (else_try),
  11607. (eq, ":event_type", multiplayer_event_set_round_start_time),
  11608. (store_script_param, ":value", 3),
  11609.  
  11610. (try_begin),
  11611. (neq, ":value", -9999),
  11612. (assign, "$g_round_start_time", ":value"),
  11613. (else_try),
  11614. (store_mission_timer_a, "$g_round_start_time"),
  11615.  
  11616. #if round start time is assigning to current time (so new round is starting) then also initialize moveable object slots too.
  11617. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_6m"),
  11618. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_8m"),
  11619. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_10m"),
  11620. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_12m"),
  11621. (call_script, "script_initialize_scene_prop_slots", "spr_siege_ladder_move_14m"),
  11622. (call_script, "script_initialize_scene_prop_slots", "spr_winch_b"),
  11623. (try_end),
  11624. (else_try),
  11625. (eq, ":event_type", multiplayer_event_force_start_team_selection),
  11626. (try_begin),
  11627. (is_presentation_active, "prsnt_multiplayer_item_select"),
  11628. (assign, "$g_close_equipment_selection", 1),
  11629. (try_end),
  11630. (start_presentation, "prsnt_multiplayer_troop_select"),
  11631. (else_try),
  11632. (eq, ":event_type", multiplayer_event_start_death_mode),
  11633. (assign, "$g_battle_death_mode_started", 2),
  11634. (start_presentation, "prsnt_multiplayer_flag_projection_display_bt"),
  11635. (call_script, "script_start_death_mode"),
  11636. (else_try),
  11637. (eq, ":event_type", multiplayer_event_return_player_respawn_spent),
  11638. (store_script_param, ":value", 3),
  11639. (try_begin),
  11640. (gt, "$g_my_spawn_count", 0),
  11641. (store_add, "$g_my_spawn_count", "$g_my_spawn_count", ":value"),
  11642. (else_try),
  11643. (assign, "$g_my_spawn_count", ":value"),
  11644. (try_end),
  11645. (else_try),
  11646. (eq, ":event_type", multiplayer_event_show_duel_request),
  11647. (store_script_param, ":value", 3),
  11648. (try_begin),
  11649. (agent_is_active, ":value"),
  11650. (agent_get_player_id, ":value_player_no", ":value"),
  11651. (try_begin),
  11652. (player_is_active, ":value_player_no"),
  11653. (str_store_player_username, s0, ":value_player_no"),
  11654. (else_try),
  11655. (str_store_agent_name, s0, ":value"),
  11656. (try_end),
  11657. (display_message, "str_s0_offers_a_duel_with_you"),
  11658. (try_begin),
  11659. (get_player_agent_no, ":player_agent"),
  11660. (agent_is_active, ":player_agent"),
  11661. (agent_add_offer_with_timeout, ":player_agent", ":value", 10000), #10 second timeout
  11662. (try_end),
  11663. (try_end),
  11664. (else_try),
  11665. (eq, ":event_type", multiplayer_event_start_duel),
  11666. (store_script_param, ":value", 3),
  11667. (store_mission_timer_a, ":mission_timer"),
  11668. (try_begin),
  11669. (agent_is_active, ":value"),
  11670. (get_player_agent_no, ":player_agent"),
  11671. (agent_is_active, ":player_agent"),
  11672. (agent_get_player_id, ":value_player_no", ":value"),
  11673. (try_begin),
  11674. (player_is_active, ":value_player_no"),
  11675. (str_store_player_username, s0, ":value_player_no"),
  11676. (else_try),
  11677. (str_store_agent_name, s0, ":value"),
  11678. (try_end),
  11679. (display_message, "str_a_duel_between_you_and_s0_will_start_in_3_seconds"),
  11680. (assign, "$g_multiplayer_duel_start_time", ":mission_timer"),
  11681. (start_presentation, "prsnt_multiplayer_duel_start_counter"),
  11682. (agent_set_slot, ":player_agent", slot_agent_in_duel_with, ":value"),
  11683. (agent_set_slot, ":value", slot_agent_in_duel_with, ":player_agent"),
  11684. (agent_set_slot, ":player_agent", slot_agent_duel_start_time, ":mission_timer"),
  11685. (agent_set_slot, ":value", slot_agent_duel_start_time, ":mission_timer"),
  11686. (agent_clear_relations_with_agents, ":player_agent"),
  11687. (agent_clear_relations_with_agents, ":value"),
  11688. ## (agent_add_relation_with_agent, ":player_agent", ":value", -1),
  11689. (try_end),
  11690. (else_try),
  11691. (eq, ":event_type", multiplayer_event_cancel_duel),
  11692. (store_script_param, ":value", 3),
  11693. (try_begin),
  11694. (agent_is_active, ":value"),
  11695. (agent_get_player_id, ":value_player_no", ":value"),
  11696. (try_begin),
  11697. (player_is_active, ":value_player_no"),
  11698. (str_store_player_username, s0, ":value_player_no"),
  11699. (else_try),
  11700. (str_store_agent_name, s0, ":value"),
  11701. (try_end),
  11702. (display_message, "str_your_duel_with_s0_is_cancelled"),
  11703. (try_end),
  11704. (try_begin),
  11705. (get_player_agent_no, ":player_agent"),
  11706. (agent_is_active, ":player_agent"),
  11707. (agent_set_slot, ":player_agent", slot_agent_in_duel_with, -1),
  11708. (agent_clear_relations_with_agents, ":player_agent"),
  11709. (try_end),
  11710. (else_try),
  11711. (eq, ":event_type", multiplayer_event_show_server_message),
  11712. (display_message, "str_server_s0", 0xFFFF6666),
  11713. (try_end),
  11714. (try_end),
  11715. ]),
  11716.  
  11717. # script_cf_multiplayer_evaluate_poll
  11718. # Input: none
  11719. # Output: none (can fail)
  11720. ("cf_multiplayer_evaluate_poll",
  11721. [
  11722. (assign, ":result", 0),
  11723. (assign, "$g_multiplayer_poll_ended", 1),
  11724. (store_add, ":total_votes", "$g_multiplayer_poll_yes_count", "$g_multiplayer_poll_no_count"),
  11725. (store_sub, ":abstain_votes", "$g_multiplayer_poll_num_sent", ":total_votes"),
  11726. (store_mul, ":nos_from_abstains", 3, ":abstain_votes"),
  11727. (val_div, ":nos_from_abstains", 10), #30% of abstains are counted as no
  11728. (val_add, ":total_votes", ":nos_from_abstains"),
  11729. (val_max, ":total_votes", 1), #if someone votes and only 1-3 abstain occurs?
  11730. (store_mul, ":vote_ratio", 100, "$g_multiplayer_poll_yes_count"),
  11731. (val_div, ":vote_ratio", ":total_votes"),
  11732. (try_begin),
  11733. (ge, ":vote_ratio", "$g_multiplayer_valid_vote_ratio"),
  11734. (assign, ":result", 1),
  11735. (try_begin),
  11736. (eq, "$g_multiplayer_poll_to_show", 1), #kick player
  11737. (try_begin),
  11738. (player_is_active, "$g_multiplayer_poll_value_to_show"),
  11739. (kick_player, "$g_multiplayer_poll_value_to_show"),
  11740. (try_end),
  11741. (else_try),
  11742. (eq, "$g_multiplayer_poll_to_show", 2), #ban player
  11743. (ban_player_using_saved_ban_info), #already loaded at the beginning of the poll
  11744. (else_try),
  11745. (eq, "$g_multiplayer_poll_to_show", 3), #change map with factions
  11746. (team_set_faction, 0, "$g_multiplayer_poll_value_2_to_show"),
  11747. (team_set_faction, 1, "$g_multiplayer_poll_value_3_to_show"),
  11748. (else_try),
  11749. (eq, "$g_multiplayer_poll_to_show", 4), #change number of bots
  11750. (assign, "$g_multiplayer_num_bots_team_1", "$g_multiplayer_poll_value_to_show"),
  11751. (assign, "$g_multiplayer_num_bots_team_2", "$g_multiplayer_poll_value_2_to_show"),
  11752. (get_max_players, ":num_players"),
  11753. (try_for_range, ":cur_player", 1, ":num_players"),
  11754. (player_is_active, ":cur_player"),
  11755. (multiplayer_send_2_int_to_player, ":cur_player", multiplayer_event_return_num_bots_in_team, 1, "$g_multiplayer_num_bots_team_1"),
  11756. (multiplayer_send_2_int_to_player, ":cur_player", multiplayer_event_return_num_bots_in_team, 2, "$g_multiplayer_num_bots_team_2"),
  11757. (try_end),
  11758. (try_end),
  11759. (else_try),
  11760. (assign, "$g_multiplayer_poll_running", 0), #end immediately if poll fails. but end after some time if poll succeeds (apply the results first)
  11761. (try_end),
  11762. (get_max_players, ":num_players"),
  11763. #for only server itself-----------------------------------------------------------------------------------------------
  11764. (call_script, "script_show_multiplayer_message", multiplayer_message_type_poll_result, ":result"), #0 is useless here
  11765. #for only server itself-----------------------------------------------------------------------------------------------
  11766. (try_for_range, ":cur_player", 1, ":num_players"),
  11767. (player_is_active, ":cur_player"),
  11768. (multiplayer_send_2_int_to_player, ":cur_player", multiplayer_event_show_multiplayer_message, multiplayer_message_type_poll_result, ":result"),
  11769. (try_end),
  11770. (eq, ":result", 1),
  11771. ]),
  11772.  
  11773. # script_multiplayer_accept_duel
  11774. # Input: arg1 = agent_no, arg2 = agent_no_offerer
  11775. # Output: none
  11776. ("multiplayer_accept_duel",
  11777. [
  11778. (store_script_param, ":agent_no", 1),
  11779. (store_script_param, ":agent_no_offerer", 2),
  11780. (try_begin),
  11781. (agent_slot_ge, ":agent_no", slot_agent_in_duel_with, 0),
  11782. (agent_get_slot, ":ex_duelist", ":agent_no", slot_agent_in_duel_with),
  11783. (agent_is_active, ":ex_duelist"),
  11784. (agent_clear_relations_with_agents, ":ex_duelist"),
  11785. (agent_set_slot, ":ex_duelist", slot_agent_in_duel_with, -1),
  11786. (agent_get_player_id, ":player_no", ":ex_duelist"),
  11787. (try_begin),
  11788. (player_is_active, ":player_no"), #might be AI
  11789. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_cancel_duel, ":agent_no"),
  11790. (else_try),
  11791. (agent_force_rethink, ":ex_duelist"),
  11792. (try_end),
  11793. (try_end),
  11794. (try_begin),
  11795. (agent_slot_ge, ":agent_no_offerer", slot_agent_in_duel_with, 0),
  11796. (agent_get_slot, ":ex_duelist", ":agent_no_offerer", slot_agent_in_duel_with),
  11797. (agent_is_active, ":ex_duelist"),
  11798. (agent_clear_relations_with_agents, ":ex_duelist"),
  11799. (agent_set_slot, ":ex_duelist", slot_agent_in_duel_with, -1),
  11800. (try_begin),
  11801. (player_is_active, ":player_no"), #might be AI
  11802. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_cancel_duel, ":agent_no_offerer"),
  11803. (else_try),
  11804. (agent_force_rethink, ":ex_duelist"),
  11805. (try_end),
  11806. (try_end),
  11807. (agent_set_slot, ":agent_no", slot_agent_in_duel_with, ":agent_no_offerer"),
  11808. (agent_set_slot, ":agent_no_offerer", slot_agent_in_duel_with, ":agent_no"),
  11809. (agent_clear_relations_with_agents, ":agent_no"),
  11810. (agent_clear_relations_with_agents, ":agent_no_offerer"),
  11811. ## (agent_add_relation_with_agent, ":agent_no", ":agent_no_offerer", -1),
  11812. ## (agent_add_relation_with_agent, ":agent_no_offerer", ":agent_no", -1),
  11813. (agent_get_player_id, ":player_no", ":agent_no"),
  11814. (store_mission_timer_a, ":mission_timer"),
  11815. (try_begin),
  11816. (player_is_active, ":player_no"), #might be AI
  11817. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_start_duel, ":agent_no_offerer"),
  11818. (else_try),
  11819. (agent_force_rethink, ":agent_no"),
  11820. (try_end),
  11821. (agent_set_slot, ":agent_no", slot_agent_duel_start_time, ":mission_timer"),
  11822. (agent_get_player_id, ":agent_no_offerer_player", ":agent_no_offerer"),
  11823. (try_begin),
  11824. (player_is_active, ":agent_no_offerer_player"), #might be AI
  11825. (multiplayer_send_int_to_player, ":agent_no_offerer_player", multiplayer_event_start_duel, ":agent_no"),
  11826. (else_try),
  11827. (agent_force_rethink, ":agent_no_offerer"),
  11828. (try_end),
  11829. (agent_set_slot, ":agent_no_offerer", slot_agent_duel_start_time, ":mission_timer"),
  11830. ]),
  11831.  
  11832. # script_game_get_multiplayer_server_option_for_mission_template
  11833. # Input: arg1 = mission_template_id, arg2 = option_index
  11834. # Output: trigger_result = 1 for option available, 0 for not available
  11835. # reg0 = option_value
  11836. ("game_get_multiplayer_server_option_for_mission_template",
  11837. [
  11838. (store_script_param, ":mission_template_id", 1),
  11839. (store_script_param, ":option_index", 2),
  11840. (try_begin),
  11841. (eq, ":option_index", 0),
  11842. (assign, reg0, "$g_multiplayer_team_1_faction"),
  11843. (set_trigger_result, 1),
  11844. (else_try),
  11845. (eq, ":option_index", 1),
  11846. (assign, reg0, "$g_multiplayer_team_2_faction"),
  11847. (set_trigger_result, 1),
  11848. (else_try),
  11849. (eq, ":option_index", 2),
  11850. (assign, reg0, "$g_multiplayer_num_bots_team_1"),
  11851. (set_trigger_result, 1),
  11852. (else_try),
  11853. (eq, ":option_index", 3),
  11854. (assign, reg0, "$g_multiplayer_num_bots_team_2"),
  11855. (set_trigger_result, 1),
  11856. (else_try),
  11857. (eq, ":option_index", 4),
  11858. (server_get_friendly_fire, reg0),
  11859. (set_trigger_result, 1),
  11860. (else_try),
  11861. (eq, ":option_index", 5),
  11862. (server_get_melee_friendly_fire, reg0),
  11863. (set_trigger_result, 1),
  11864. (else_try),
  11865. (eq, ":option_index", 6),
  11866. (server_get_friendly_fire_damage_self_ratio, reg0),
  11867. (set_trigger_result, 1),
  11868. (else_try),
  11869. (eq, ":option_index", 7),
  11870. (server_get_friendly_fire_damage_friend_ratio, reg0),
  11871. (set_trigger_result, 1),
  11872. (else_try),
  11873. (eq, ":option_index", 8),
  11874. (server_get_ghost_mode, reg0),
  11875. (set_trigger_result, 1),
  11876. (else_try),
  11877. (eq, ":option_index", 9),
  11878. (server_get_control_block_dir, reg0),
  11879. (set_trigger_result, 1),
  11880. (else_try),
  11881. (eq, ":option_index", 10),
  11882. (server_get_combat_speed, reg0),
  11883. (set_trigger_result, 1),
  11884. (else_try),
  11885. (try_begin),
  11886. (eq, ":mission_template_id", "mt_multiplayer_hq"),
  11887. (val_add, ":option_index", 1), #max game time
  11888. (try_end),
  11889. (eq, ":option_index", 11),
  11890. (assign, reg0, "$g_multiplayer_game_max_minutes"),
  11891. (set_trigger_result, 1),
  11892. (else_try),
  11893. (try_begin),
  11894. (neq, ":mission_template_id", "mt_multiplayer_bt"),
  11895. (neq, ":mission_template_id", "mt_multiplayer_fd"),
  11896. (neq, ":mission_template_id", "mt_multiplayer_sg"),
  11897. (val_add, ":option_index", 1), #max round time
  11898. (try_end),
  11899. (eq, ":option_index", 12),
  11900. (assign, reg0, "$g_multiplayer_round_max_seconds"),
  11901. (set_trigger_result, 1),
  11902. (else_try),
  11903. (try_begin),
  11904. (neq, ":mission_template_id", "mt_multiplayer_bt"),
  11905. (neq, ":mission_template_id", "mt_multiplayer_fd"),
  11906. (val_add, ":option_index", 1), #respawn as bot
  11907. (try_end),
  11908. (eq, ":option_index", 13),
  11909. (assign, reg0, "$g_multiplayer_player_respawn_as_bot"),
  11910. (set_trigger_result, 1),
  11911. (else_try),
  11912. (try_begin),
  11913. (neq, ":mission_template_id", "mt_multiplayer_sg"),
  11914. (val_add, ":option_index", 1), #respawn limit
  11915. (try_end),
  11916. (eq, ":option_index", 14),
  11917. (assign, reg0, "$g_multiplayer_number_of_respawn_count"),
  11918. (set_trigger_result, 1),
  11919. (else_try),
  11920. (eq, ":option_index", 15),
  11921. (assign, reg0, "$g_multiplayer_game_max_points"),
  11922. (set_trigger_result, 1),
  11923. (else_try),
  11924. (try_begin),
  11925. (neq, ":mission_template_id", "mt_multiplayer_hq"),
  11926. (val_add, ":option_index", 1), #point gained from flags
  11927. (try_end),
  11928. (eq, ":option_index", 16),
  11929. (assign, reg0, "$g_multiplayer_point_gained_from_flags"),
  11930. (set_trigger_result, 1),
  11931. (else_try),
  11932. (try_begin),
  11933. (neq, ":mission_template_id", "mt_multiplayer_cf"),
  11934. (val_add, ":option_index", 1), #point gained from capturing flag
  11935. (try_end),
  11936. (eq, ":option_index", 17),
  11937. (assign, reg0, "$g_multiplayer_point_gained_from_capturing_flag"),
  11938. (set_trigger_result, 1),
  11939. (else_try),
  11940. (eq, ":option_index", 18),
  11941. (assign, reg0, "$g_multiplayer_respawn_period"),
  11942. (set_trigger_result, 1),
  11943. (else_try),
  11944. (eq, ":option_index", 19),
  11945. (assign, reg0, "$g_multiplayer_initial_gold_multiplier"),
  11946. (set_trigger_result, 1),
  11947. (else_try),
  11948. (eq, ":option_index", 20),
  11949. (assign, reg0, "$g_multiplayer_battle_earnings_multiplier"),
  11950. (set_trigger_result, 1),
  11951. (else_try),
  11952. (try_begin),
  11953. (neq, ":mission_template_id", "mt_multiplayer_bt"),
  11954. (neq, ":mission_template_id", "mt_multiplayer_fd"),
  11955. (neq, ":mission_template_id", "mt_multiplayer_sg"),
  11956. (val_add, ":option_index", 1),
  11957. (try_end),
  11958. (eq, ":option_index", 21),
  11959. (assign, reg0, "$g_multiplayer_round_earnings_multiplier"),
  11960. (set_trigger_result, 1),
  11961. (try_end),
  11962. ]),
  11963.  
  11964. # script_game_multiplayer_server_option_for_mission_template_to_string
  11965. # Input: arg1 = mission_template_id, arg2 = option_index, arg3 = option_value
  11966. # Output: s0 = option_text
  11967. ("game_multiplayer_server_option_for_mission_template_to_string",
  11968. [
  11969. (store_script_param, ":mission_template_id", 1),
  11970. (store_script_param, ":option_index", 2),
  11971. (store_script_param, ":option_value", 3),
  11972. (str_clear, s0),
  11973. (try_begin),
  11974. (eq, ":option_index", 0),
  11975. (assign, reg1, 1),
  11976. (str_store_string, s0, "str_team_reg1_faction"),
  11977. (str_store_faction_name, s1, ":option_value"),
  11978. (str_store_string, s0, "str_s0_s1"),
  11979. (else_try),
  11980. (eq, ":option_index", 1),
  11981. (assign, reg1, 2),
  11982. (str_store_string, s0, "str_team_reg1_faction"),
  11983. (str_store_faction_name, s1, ":option_value"),
  11984. (str_store_string, s0, "str_s0_s1"),
  11985. (else_try),
  11986. (eq, ":option_index", 2),
  11987. (assign, reg1, 1),
  11988. (str_store_string, s0, "str_number_of_bots_in_team_reg1"),
  11989. (assign, reg0, ":option_value"),
  11990. (str_store_string, s0, "str_s0_reg0"),
  11991. (else_try),
  11992. (eq, ":option_index", 3),
  11993. (assign, reg1, 2),
  11994. (str_store_string, s0, "str_number_of_bots_in_team_reg1"),
  11995. (assign, reg0, ":option_value"),
  11996. (str_store_string, s0, "str_s0_reg0"),
  11997. (else_try),
  11998. (eq, ":option_index", 4),
  11999. (str_store_string, s0, "str_allow_friendly_fire"),
  12000. (try_begin),
  12001. (eq, ":option_value", 0),
  12002. (str_store_string, s1, "str_no_wo_dot"),
  12003. (else_try),
  12004. (str_store_string, s1, "str_yes_wo_dot"),
  12005. (try_end),
  12006. (str_store_string, s0, "str_s0_s1"),
  12007. (else_try),
  12008. (eq, ":option_index", 5),
  12009. (str_store_string, s0, "str_allow_melee_friendly_fire"),
  12010. (try_begin),
  12011. (eq, ":option_value", 0),
  12012. (str_store_string, s1, "str_no_wo_dot"),
  12013. (else_try),
  12014. (str_store_string, s1, "str_yes_wo_dot"),
  12015. (try_end),
  12016. (str_store_string, s0, "str_s0_s1"),
  12017. (else_try),
  12018. (eq, ":option_index", 6),
  12019. (str_store_string, s0, "str_friendly_fire_damage_self_ratio"),
  12020. (assign, reg0, ":option_value"),
  12021. (str_store_string, s0, "str_s0_reg0"),
  12022. (else_try),
  12023. (eq, ":option_index", 7),
  12024. (str_store_string, s0, "str_friendly_fire_damage_friend_ratio"),
  12025. (assign, reg0, ":option_value"),
  12026. (str_store_string, s0, "str_s0_reg0"),
  12027. (else_try),
  12028. (eq, ":option_index", 8),
  12029. (str_store_string, s0, "str_spectator_camera"),
  12030. (try_begin),
  12031. (eq, ":option_value", 0),
  12032. (str_store_string, s1, "str_free"),
  12033. (else_try),
  12034. (eq, ":option_value", 1),
  12035. (str_store_string, s1, "str_stick_to_any_player"),
  12036. (else_try),
  12037. (eq, ":option_value", 2),
  12038. (str_store_string, s1, "str_stick_to_team_members"),
  12039. (else_try),
  12040. (str_store_string, s1, "str_stick_to_team_members_view"),
  12041. (try_end),
  12042. (str_store_string, s0, "str_s0_s1"),
  12043. (else_try),
  12044. (eq, ":option_index", 9),
  12045. (str_store_string, s0, "str_control_block_direction"),
  12046. (try_begin),
  12047. (eq, ":option_value", 0),
  12048. (str_store_string, s1, "str_automatic"),
  12049. (else_try),
  12050. (str_store_string, s1, "str_by_mouse_movement"),
  12051. (try_end),
  12052. (str_store_string, s0, "str_s0_s1"),
  12053. (else_try),
  12054. (eq, ":option_index", 10),
  12055. (str_store_string, s0, "str_combat_speed"),
  12056. (try_begin),
  12057. (eq, ":option_value", 0),
  12058. (str_store_string, s1, "str_combat_speed_0"),
  12059. (else_try),
  12060. (eq, ":option_value", 1),
  12061. (str_store_string, s1, "str_combat_speed_1"),
  12062. (else_try),
  12063. (eq, ":option_value", 2),
  12064. (str_store_string, s1, "str_combat_speed_2"),
  12065. (else_try),
  12066. (eq, ":option_value", 3),
  12067. (str_store_string, s1, "str_combat_speed_3"),
  12068. (else_try),
  12069. (str_store_string, s1, "str_combat_speed_4"),
  12070. (try_end),
  12071. (str_store_string, s0, "str_s0_s1"),
  12072. (else_try),
  12073. (try_begin),
  12074. (eq, ":mission_template_id", "mt_multiplayer_hq"),
  12075. (val_add, ":option_index", 1), #max game time
  12076. (try_end),
  12077. (eq, ":option_index", 11),
  12078. (str_store_string, s0, "str_map_time_limit"),
  12079. (assign, reg0, ":option_value"),
  12080. (str_store_string, s0, "str_s0_reg0"),
  12081. (else_try),
  12082. (try_begin),
  12083. (neq, ":mission_template_id", "mt_multiplayer_bt"),
  12084. (neq, ":mission_template_id", "mt_multiplayer_fd"),
  12085. (neq, ":mission_template_id", "mt_multiplayer_sg"),
  12086. (val_add, ":option_index", 1), #max round time
  12087. (try_end),
  12088. (eq, ":option_index", 12),
  12089. (str_store_string, s0, "str_round_time_limit"),
  12090. (assign, reg0, ":option_value"),
  12091. (str_store_string, s0, "str_s0_reg0"),
  12092. (else_try),
  12093. (try_begin),
  12094. (neq, ":mission_template_id", "mt_multiplayer_bt"),
  12095. (neq, ":mission_template_id", "mt_multiplayer_fd"),
  12096. (val_add, ":option_index", 1), #respawn as bot
  12097. (try_end),
  12098. (eq, ":option_index", 13),
  12099. (str_store_string, s0, "str_players_take_control_of_a_bot_after_death"),
  12100. (try_begin),
  12101. (eq, ":option_value", 0),
  12102. (str_store_string, s1, "str_no_wo_dot"),
  12103. (else_try),
  12104. (str_store_string, s1, "str_yes_wo_dot"),
  12105. (try_end),
  12106. (str_store_string, s0, "str_s0_s1"),
  12107. (else_try),
  12108. (try_begin),
  12109. (neq, ":mission_template_id", "mt_multiplayer_sg"),
  12110. (val_add, ":option_index", 1), #respawn limit
  12111. (try_end),
  12112. (eq, ":option_index", 14),
  12113. (str_store_string, s0, "str_defender_spawn_count_limit"),
  12114. (try_begin),
  12115. (eq, ":option_value", 0),
  12116. (str_store_string, s1, "str_unlimited"),
  12117. (else_try),
  12118. (assign, reg1, ":option_value"),
  12119. (str_store_string, s1, "str_reg1"),
  12120. (try_end),
  12121. (str_store_string, s0, "str_s0_s1"),
  12122. (else_try),
  12123. (eq, ":option_index", 15),
  12124. (str_store_string, s0, "str_team_points_limit"),
  12125. (assign, reg0, ":option_value"),
  12126. (str_store_string, s0, "str_s0_reg0"),
  12127. (else_try),
  12128. (try_begin),
  12129. (neq, ":mission_template_id", "mt_multiplayer_hq"),
  12130. (val_add, ":option_index", 1), #point gained from flags
  12131. (try_end),
  12132. (eq, ":option_index", 16),
  12133. (str_store_string, s0, "str_point_gained_from_flags"),
  12134. (assign, reg0, ":option_value"),
  12135. (str_store_string, s0, "str_s0_reg0"),
  12136. (else_try),
  12137. (try_begin),
  12138. (neq, ":mission_template_id", "mt_multiplayer_cf"),
  12139. (val_add, ":option_index", 1), #point gained from capturing flag
  12140. (try_end),
  12141. (eq, ":option_index", 17),
  12142. (str_store_string, s0, "str_point_gained_from_capturing_flag"),
  12143. (assign, reg0, ":option_value"),
  12144. (str_store_string, s0, "str_s0_reg0"),
  12145. (else_try),
  12146. (eq, ":option_index", 18),
  12147. (str_store_string, s0, "str_respawn_period"),
  12148. (assign, reg0, ":option_value"),
  12149. (str_store_string, s0, "str_s0_reg0"),
  12150. (else_try),
  12151. (eq, ":option_index", 19),
  12152. (str_store_string, s0, "str_initial_gold_multiplier"),
  12153. (assign, reg0, ":option_value"),
  12154. (str_store_string, s0, "str_s0_reg0"),
  12155. (else_try),
  12156. (eq, ":option_index", 20),
  12157. (str_store_string, s0, "str_battle_earnings_multiplier"),
  12158. (assign, reg0, ":option_value"),
  12159. (str_store_string, s0, "str_s0_reg0"),
  12160. (else_try),
  12161. (try_begin),
  12162. (neq, ":mission_template_id", "mt_multiplayer_bt"),
  12163. (neq, ":mission_template_id", "mt_multiplayer_fd"),
  12164. (neq, ":mission_template_id", "mt_multiplayer_sg"),
  12165. (val_add, ":option_index", 1),
  12166. (try_end),
  12167. (eq, ":option_index", 21),
  12168. (str_store_string, s0, "str_round_earnings_multiplier"),
  12169. (assign, reg0, ":option_value"),
  12170. (str_store_string, s0, "str_s0_reg0"),
  12171. (try_end),
  12172. ]),
  12173.  
  12174. # script_cf_multiplayer_team_is_available
  12175. # Input: arg1 = player_no, arg2 = team_no
  12176. # Output: none, true or false
  12177. ("cf_multiplayer_team_is_available",
  12178. [
  12179. (store_script_param, ":player_no", 1),
  12180. (store_script_param, ":team_no", 2),
  12181. (assign, ":continue_change_team", 1),
  12182. (try_begin),
  12183. (neq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
  12184. (neq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
  12185. (is_between, ":team_no", 0, multi_team_spectator),
  12186. (neg|teams_are_enemies, ":team_no", ":team_no"), #checking if it is a deathmatch or not
  12187. (assign, ":continue_change_team", 0),
  12188. #counting number of players for team balance checks
  12189. (assign, ":number_of_players_at_team_1", 0),
  12190. (assign, ":number_of_players_at_team_2", 0),
  12191. (get_max_players, ":num_players"),
  12192. (try_for_range, ":cur_player", 0, ":num_players"),
  12193. (player_is_active, ":cur_player"),
  12194. (neq, ":cur_player", ":player_no"),
  12195. (player_get_team_no, ":player_team", ":cur_player"),
  12196. (try_begin),
  12197. (eq, ":player_team", 0),
  12198. (val_add, ":number_of_players_at_team_1", 1),
  12199. (else_try),
  12200. (eq, ":player_team", 1),
  12201. (val_add, ":number_of_players_at_team_2", 1),
  12202. (try_end),
  12203. (try_end),
  12204. (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
  12205.  
  12206. (try_begin),
  12207. (ge, ":difference_of_number_of_players", 0),
  12208. (val_add, ":difference_of_number_of_players", 1),
  12209. (else_try),
  12210. (val_add, ":difference_of_number_of_players", -1),
  12211. (try_end),
  12212.  
  12213. (try_begin),
  12214. (eq, ":team_no", 0),
  12215. (lt, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
  12216. (assign, ":continue_change_team", 1),
  12217. (else_try),
  12218. (eq, ":team_no", 1),
  12219. (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
  12220. (gt, ":difference_of_number_of_players", ":checked_value"),
  12221. (assign, ":continue_change_team", 1),
  12222. (try_end),
  12223. (try_end),
  12224. (eq, ":continue_change_team", 1),
  12225. ]),
  12226.  
  12227. # script_find_number_of_agents_constant
  12228. # Input: none
  12229. # Output: reg0 = 100xconstant (100..500)
  12230. ("find_number_of_agents_constant",
  12231. [
  12232. (assign, ":num_dead_or_alive_agents", 0),
  12233.  
  12234. (try_for_agents, ":cur_agent"),
  12235. (agent_is_human, ":cur_agent"),
  12236. (val_add, ":num_dead_or_alive_agents", 1),
  12237. (try_end),
  12238.  
  12239. (try_begin),
  12240. (le, ":num_dead_or_alive_agents", 2), #2
  12241. (assign, reg0, 100),
  12242. (else_try),
  12243. (le, ":num_dead_or_alive_agents", 4), #2+2
  12244. (assign, reg0, 140),
  12245. (else_try),
  12246. (le, ":num_dead_or_alive_agents", 7), #2+2+3
  12247. (assign, reg0, 180),
  12248. (else_try),
  12249. (le, ":num_dead_or_alive_agents", 11), #2+2+3+4
  12250. (assign, reg0, 220),
  12251. (else_try),
  12252. (le, ":num_dead_or_alive_agents", 17), #2+2+3+4+6
  12253. (assign, reg0, 260),
  12254. (else_try),
  12255. (le, ":num_dead_or_alive_agents", 25), #2+2+3+4+6+8
  12256. (assign, reg0, 300),
  12257. (else_try),
  12258. (le, ":num_dead_or_alive_agents", 36), #2+2+3+4+6+8+11
  12259. (assign, reg0, 340),
  12260. (else_try),
  12261. (le, ":num_dead_or_alive_agents", 50), #2+2+3+4+6+8+11+14
  12262. (assign, reg0, 380),
  12263. (else_try),
  12264. (le, ":num_dead_or_alive_agents", 68), #2+2+3+4+6+8+11+14+18
  12265. (assign, reg0, 420),
  12266. (else_try),
  12267. (le, ":num_dead_or_alive_agents", 91), #2+2+3+4+6+8+11+14+18+23
  12268. (assign, reg0, 460),
  12269. (else_try),
  12270. (assign, reg0, 500),
  12271. (try_end),
  12272. ]),
  12273.  
  12274. # script_game_multiplayer_event_duel_offered
  12275. # Input: arg1 = agent_no
  12276. # Output: none
  12277. ("game_multiplayer_event_duel_offered",
  12278. [
  12279. (store_script_param, ":agent_no", 1),
  12280. (get_player_agent_no, ":player_agent_no"),
  12281. (try_begin),
  12282. (agent_is_active, ":player_agent_no"),
  12283. (this_or_next|agent_slot_eq, ":player_agent_no", slot_agent_in_duel_with, -1),
  12284. (agent_check_offer_from_agent, ":player_agent_no", ":agent_no"),
  12285. (neg|agent_slot_eq, ":player_agent_no", slot_agent_in_duel_with, ":agent_no"), #don't allow spamming duel offers during countdown
  12286. (multiplayer_send_int_to_server, multiplayer_event_offer_duel, ":agent_no"),
  12287. (agent_get_player_id, ":player_no", ":agent_no"),
  12288. (try_begin),
  12289. (player_is_active, ":player_no"),
  12290. (str_store_player_username, s0, ":player_no"),
  12291. (else_try),
  12292. (str_store_agent_name, s0, ":agent_no"),
  12293. (try_end),
  12294. (display_message, "str_a_duel_request_is_sent_to_s0"),
  12295. (try_end),
  12296. ]),
  12297.  
  12298. # script_game_get_multiplayer_game_type_enum
  12299. # Input: none
  12300. # Output: reg0:first type, reg1:type count
  12301. ("game_get_multiplayer_game_type_enum",
  12302. [
  12303. (assign, reg0, multiplayer_game_type_deathmatch),
  12304. (assign, reg1, multiplayer_num_game_types),
  12305. ]),
  12306.  
  12307. # script_game_multiplayer_get_game_type_mission_template
  12308. # Input: arg1 = game_type
  12309. # Output: mission_template
  12310. ("game_multiplayer_get_game_type_mission_template",
  12311. [
  12312. (assign, ":selected_mt", -1),
  12313. (store_script_param, ":game_type", 1),
  12314. (try_begin),
  12315. (eq, ":game_type", multiplayer_game_type_deathmatch),
  12316. (assign, ":selected_mt", "mt_multiplayer_dm"),
  12317. (else_try),
  12318. (eq, ":game_type", multiplayer_game_type_team_deathmatch),
  12319. (assign, ":selected_mt", "mt_multiplayer_tdm"),
  12320. (else_try),
  12321. (eq, ":game_type", multiplayer_game_type_battle),
  12322. (assign, ":selected_mt", "mt_multiplayer_bt"),
  12323. (else_try),
  12324. (eq, ":game_type", multiplayer_game_type_destroy),
  12325. (assign, ":selected_mt", "mt_multiplayer_fd"),
  12326. (else_try),
  12327. (eq, ":game_type", multiplayer_game_type_capture_the_flag),
  12328. (assign, ":selected_mt", "mt_multiplayer_cf"),
  12329. (else_try),
  12330. (eq, ":game_type", multiplayer_game_type_headquarters),
  12331. (assign, ":selected_mt", "mt_multiplayer_hq"),
  12332. (else_try),
  12333. (eq, ":game_type", multiplayer_game_type_siege),
  12334. (assign, ":selected_mt", "mt_multiplayer_sg"),
  12335. (else_try),
  12336. (eq, ":game_type", multiplayer_game_type_duel),
  12337. (assign, ":selected_mt", "mt_multiplayer_duel"),
  12338. (try_end),
  12339. (assign, reg0, ":selected_mt"),
  12340. ]),
  12341.  
  12342. # script_multiplayer_get_mission_template_game_type
  12343. # Input: arg1 = mission_template_no
  12344. # Output: game_type
  12345. ("multiplayer_get_mission_template_game_type",
  12346. [
  12347. (store_script_param, ":mission_template_no", 1),
  12348. (assign, ":game_type", -1),
  12349. (try_begin),
  12350. (eq, ":mission_template_no", "mt_multiplayer_dm"),
  12351. (assign, ":game_type", multiplayer_game_type_deathmatch),
  12352. (else_try),
  12353. (eq, ":mission_template_no", "mt_multiplayer_tdm"),
  12354. (assign, ":game_type", multiplayer_game_type_team_deathmatch),
  12355. (else_try),
  12356. (eq, ":mission_template_no", "mt_multiplayer_bt"),
  12357. (assign, ":game_type", multiplayer_game_type_battle),
  12358. (else_try),
  12359. (eq, ":mission_template_no", "mt_multiplayer_fd"),
  12360. (assign, ":game_type", multiplayer_game_type_destroy),
  12361. (else_try),
  12362. (eq, ":mission_template_no", "mt_multiplayer_cf"),
  12363. (assign, ":game_type", multiplayer_game_type_capture_the_flag),
  12364. (else_try),
  12365. (eq, ":mission_template_no", "mt_multiplayer_hq"),
  12366. (assign, ":game_type", multiplayer_game_type_headquarters),
  12367. (else_try),
  12368. (eq, ":mission_template_no", "mt_multiplayer_sg"),
  12369. (assign, ":game_type", multiplayer_game_type_siege),
  12370. (else_try),
  12371. (eq, ":mission_template_no", "mt_multiplayer_duel"),
  12372. (assign, ":game_type", multiplayer_game_type_duel),
  12373. (try_end),
  12374. (assign, reg0, ":game_type"),
  12375. ]),
  12376.  
  12377.  
  12378. # script_multiplayer_fill_available_factions_combo_button
  12379. # Input: arg1 = overlay_id, arg2 = selected_faction_no, arg3 = opposite_team_selected_faction_no
  12380. # Output: none
  12381. ("multiplayer_fill_available_factions_combo_button",
  12382. [
  12383. (store_script_param, ":overlay_id", 1),
  12384. (store_script_param, ":selected_faction_no", 2),
  12385. ## (store_script_param, ":opposite_team_selected_faction_no", 3),
  12386. ## (try_for_range, ":cur_faction", "fac_kingdom_1", "fac_kingdoms_end"),
  12387. ## (try_begin),
  12388. ## (eq, ":opposite_team_selected_faction_no", ":cur_faction"),
  12389. ## (try_begin),
  12390. ## (gt, ":selected_faction_no", ":opposite_team_selected_faction_no"),
  12391. ## (val_sub, ":selected_faction_no", 1),
  12392. ## (try_end),
  12393. ## (else_try),
  12394. ## (str_store_faction_name, s0, ":cur_faction"),
  12395. ## (overlay_add_item, ":overlay_id", s0),
  12396. ## (try_end),
  12397. ## (try_end),
  12398. ## (val_sub, ":selected_faction_no", "fac_kingdom_1"),
  12399. ## (overlay_set_val, ":overlay_id", ":selected_faction_no"),
  12400. (try_for_range, ":cur_faction", npc_kingdoms_begin, npc_kingdoms_end),
  12401. (str_store_faction_name, s0, ":cur_faction"),
  12402. (overlay_add_item, ":overlay_id", s0),
  12403. (try_end),
  12404. (val_sub, ":selected_faction_no", "fac_kingdom_1"),
  12405. (overlay_set_val, ":overlay_id", ":selected_faction_no"),
  12406. ]),
  12407.  
  12408.  
  12409. # script_multiplayer_get_troop_class
  12410. # Input: arg1 = troop_no
  12411. # Output: reg0: troop_class
  12412. ("multiplayer_get_troop_class",
  12413. [
  12414. (store_script_param_1, ":troop_no"),
  12415. (assign, ":troop_class", multi_troop_class_other),
  12416. (try_begin),
  12417. (this_or_next|eq, ":troop_no", "trp_vaegir_archer_multiplayer"),
  12418. (this_or_next|eq, ":troop_no", "trp_nord_archer_multiplayer"),
  12419. (eq, ":troop_no", "trp_sarranid_archer_multiplayer"),
  12420. (assign, ":troop_class", multi_troop_class_archer),
  12421. (else_try),
  12422. (this_or_next|eq, ":troop_no", "trp_swadian_man_at_arms_multiplayer"),
  12423. (this_or_next|eq, ":troop_no", "trp_nord_scout_multiplayer"),
  12424. (this_or_next|eq, ":troop_no", "trp_rhodok_horseman_multiplayer"),
  12425. (this_or_next|eq, ":troop_no", "trp_sarranid_mamluke_multiplayer"),
  12426. (eq, ":troop_no", "trp_vaegir_horseman_multiplayer"),
  12427. (assign, ":troop_class", multi_troop_class_cavalry),
  12428. (else_try),
  12429. (eq, ":troop_no", "trp_khergit_veteran_horse_archer_multiplayer"),
  12430. (assign, ":troop_class", multi_troop_class_mounted_archer),
  12431. # (else_try),
  12432. # (eq, ":troop_no", "trp_swadian_mounted_crossbowman_multiplayer"),
  12433. # (assign, ":troop_class", multi_troop_class_mounted_crossbowman),
  12434. (else_try),
  12435. (this_or_next|eq, ":troop_no", "trp_swadian_crossbowman_multiplayer"),
  12436. (eq, ":troop_no", "trp_rhodok_veteran_crossbowman_multiplayer"),
  12437. (assign, ":troop_class", multi_troop_class_crossbowman),
  12438. (else_try),
  12439. (this_or_next|eq, ":troop_no", "trp_swadian_infantry_multiplayer"),
  12440. (this_or_next|eq, ":troop_no", "trp_sarranid_footman_multiplayer"),
  12441. (eq, ":troop_no", "trp_nord_veteran_multiplayer"),
  12442. (assign, ":troop_class", multi_troop_class_infantry),
  12443. (else_try),
  12444. (eq, ":troop_no", "trp_vaegir_spearman_multiplayer"),
  12445. (assign, ":troop_class", multi_troop_class_spearman),
  12446. (try_end),
  12447. (assign, reg0, ":troop_class"),
  12448. ]),
  12449.  
  12450. #script_multiplayer_clear_player_selected_items
  12451. # Input: arg1 = player_no
  12452. # Output: none
  12453. ("multiplayer_clear_player_selected_items",
  12454. [
  12455. (store_script_param, ":player_no", 1),
  12456. (try_for_range, ":slot_no", slot_player_selected_item_indices_begin, slot_player_selected_item_indices_end),
  12457. (player_set_slot, ":player_no", ":slot_no", -1),
  12458. (try_end),
  12459. ]),
  12460.  
  12461.  
  12462. #script_multiplayer_init_player_slots
  12463. # Input: arg1 = player_no
  12464. # Output: none
  12465. ("multiplayer_init_player_slots",
  12466. [
  12467. (store_script_param, ":player_no", 1),
  12468. (call_script, "script_multiplayer_clear_player_selected_items", ":player_no"),
  12469. (player_set_slot, ":player_no", slot_player_spawned_this_round, 0),
  12470. (player_set_slot, ":player_no", slot_player_last_rounds_used_item_earnings, 0),
  12471. (player_set_slot, ":player_no", slot_player_poll_disabled_until_time, 0),
  12472.  
  12473. (player_set_slot, ":player_no", slot_player_bot_type_1_wanted, 0),
  12474. (player_set_slot, ":player_no", slot_player_bot_type_2_wanted, 0),
  12475. (player_set_slot, ":player_no", slot_player_bot_type_3_wanted, 0),
  12476. (player_set_slot, ":player_no", slot_player_bot_type_4_wanted, 0),
  12477. ]),
  12478.  
  12479. #script_multiplayer_initialize_belfry_wheel_rotations
  12480. # Input: none
  12481. # Output: none
  12482. ("multiplayer_initialize_belfry_wheel_rotations",
  12483. [
  12484. ## (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_a"),
  12485. ## (try_for_range, ":belfry_no", 0, ":num_belfries"),
  12486. ## (store_mul, ":wheel_no", ":belfry_no", 3),
  12487. ## (scene_prop_get_instance, ":belfry_wheel_1_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
  12488. ## (prop_instance_initialize_rotation_angles, ":belfry_wheel_1_scene_prop_id"),
  12489. ## #belfry wheel_2
  12490. ## (val_add, ":wheel_no", 1),
  12491. ## (scene_prop_get_instance, ":belfry_wheel_2_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
  12492. ## (prop_instance_initialize_rotation_angles, ":belfry_wheel_2_scene_prop_id"),
  12493. ## #belfry wheel_3
  12494. ## (val_add, ":wheel_no", 1),
  12495. ## (scene_prop_get_instance, ":belfry_wheel_3_scene_prop_id", "spr_belfry_wheel", ":wheel_no"),
  12496. ## (prop_instance_initialize_rotation_angles, ":belfry_wheel_3_scene_prop_id"),
  12497. ## (try_end),
  12498. ##
  12499. ## (scene_prop_get_num_instances, ":num_belfries_a", "spr_belfry_a"),
  12500. ##
  12501. ## (scene_prop_get_num_instances, ":num_belfries", "spr_belfry_b"),
  12502. ## (try_for_range, ":belfry_no", 0, ":num_belfries"),
  12503. ## (store_add, ":wheel_no_plus_num_belfries_a", ":wheel_no", ":num_belfries_a"),
  12504. ## (store_mul, ":wheel_no_plus_num_belfries_a", ":belfry_no", 3),
  12505. ## (scene_prop_get_instance, ":belfry_wheel_1_scene_prop_id", "spr_belfry_wheel", ":wheel_no_plus_num_belfries_a"),
  12506. ## (prop_instance_initialize_rotation_angles, ":belfry_wheel_1_scene_prop_id"),
  12507. ## #belfry wheel_2
  12508. ## (val_add, ":wheel_no_plus_num_belfries_a", 1),
  12509. ## (scene_prop_get_instance, ":belfry_wheel_2_scene_prop_id", "spr_belfry_wheel", ":wheel_no_plus_num_belfries_a"),
  12510. ## (prop_instance_initialize_rotation_angles, ":belfry_wheel_2_scene_prop_id"),
  12511. ## #belfry wheel_3
  12512. ## (val_add, ":wheel_no_plus_num_belfries_a", 1),
  12513. ## (scene_prop_get_instance, ":belfry_wheel_3_scene_prop_id", "spr_belfry_wheel", ":wheel_no_plus_num_belfries_a"),
  12514. ## (prop_instance_initialize_rotation_angles, ":belfry_wheel_3_scene_prop_id"),
  12515. ## (try_end),
  12516.  
  12517. (scene_prop_get_num_instances, ":num_wheel", "spr_belfry_wheel"),
  12518. (try_for_range, ":wheel_no", 0, ":num_wheel"),
  12519. (scene_prop_get_instance, ":wheel_id", "spr_belfry_wheel", ":wheel_no"),
  12520. (prop_instance_initialize_rotation_angles, ":wheel_id"),
  12521. (try_end),
  12522.  
  12523. (scene_prop_get_num_instances, ":num_winch", "spr_winch"),
  12524. (try_for_range, ":winch_no", 0, ":num_winch"),
  12525. (scene_prop_get_instance, ":winch_id", "spr_winch", ":winch_no"),
  12526. (prop_instance_initialize_rotation_angles, ":winch_id"),
  12527. (try_end),
  12528.  
  12529. (scene_prop_get_num_instances, ":num_winch_b", "spr_winch_b"),
  12530. (try_for_range, ":winch_b_no", 0, ":num_winch_b"),
  12531. (scene_prop_get_instance, ":winch_b_id", "spr_winch_b", ":winch_b_no"),
  12532. (prop_instance_initialize_rotation_angles, ":winch_b_id"),
  12533. (try_end),
  12534. ]),
  12535.  
  12536. #script_send_open_close_information_of_object
  12537. # Input: arg1 = mission_object_id
  12538. # Output: none
  12539. ("send_open_close_information_of_object",
  12540. [
  12541. (store_script_param, ":player_no", 1),
  12542. (store_script_param, ":scene_prop_no", 2),
  12543.  
  12544. (scene_prop_get_num_instances, ":num_instances", ":scene_prop_no"),
  12545.  
  12546. (try_for_range, ":instance_no", 0, ":num_instances"),
  12547. (scene_prop_get_instance, ":instance_id", ":scene_prop_no", ":instance_no"),
  12548. (scene_prop_get_slot, ":opened_or_closed", ":instance_id", scene_prop_open_or_close_slot),
  12549. (try_begin),
  12550. (eq, ":opened_or_closed", 1),
  12551. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_set_scene_prop_open_or_close, ":instance_id"),
  12552. (try_end),
  12553. (try_end),
  12554. ]),
  12555.  
  12556. #script_multiplayer_send_initial_information
  12557. # Input: arg1 = player_no
  12558. # Output: none
  12559. ("multiplayer_send_initial_information",
  12560. [
  12561. (store_script_param, ":player_no", 1),
  12562.  
  12563. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_num_bots_in_team, 1, "$g_multiplayer_num_bots_team_1"),
  12564. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_return_num_bots_in_team, 2, "$g_multiplayer_num_bots_team_2"),
  12565. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_auto_team_balance_limit, "$g_multiplayer_auto_team_balance_limit"),
  12566. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_num_bots_voteable, "$g_multiplayer_num_bots_voteable"),
  12567. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_factions_voteable, "$g_multiplayer_factions_voteable"),
  12568. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_maps_voteable, "$g_multiplayer_maps_voteable"),
  12569. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_kick_voteable, "$g_multiplayer_kick_voteable"),
  12570. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_ban_voteable, "$g_multiplayer_ban_voteable"),
  12571. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_allow_player_banners, "$g_multiplayer_allow_player_banners"),
  12572. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_force_default_armor, "$g_multiplayer_force_default_armor"),
  12573. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_disallow_ranged_weapons, "$g_multiplayer_disallow_ranged_weapons"),
  12574. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_respawn_period, "$g_multiplayer_respawn_period"),
  12575. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_round_max_seconds, "$g_multiplayer_round_max_seconds"),
  12576. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_game_type, "$g_multiplayer_game_type"),
  12577. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_player_respawn_as_bot, "$g_multiplayer_player_respawn_as_bot"),
  12578.  
  12579. (store_mission_timer_a, ":mission_timer"),
  12580. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_server_mission_timer_while_player_joined, ":mission_timer"),
  12581.  
  12582. (try_begin),
  12583. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  12584. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_return_respawn_count, "$g_multiplayer_number_of_respawn_count"),
  12585. (try_end),
  12586.  
  12587. (try_for_agents, ":cur_agent"), #send if any agent is carrying any scene object
  12588. (agent_is_human, ":cur_agent"),
  12589. (agent_get_attached_scene_prop, ":attached_scene_prop", ":cur_agent"),
  12590. (ge, ":attached_scene_prop", 0),
  12591. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_attached_scene_prop, ":cur_agent", ":attached_scene_prop"),
  12592. (try_end),
  12593.  
  12594. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_siege_ladder_move_6m"),
  12595. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_siege_ladder_move_8m"),
  12596. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_siege_ladder_move_10m"),
  12597. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_siege_ladder_move_12m"),
  12598. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_siege_ladder_move_14m"),
  12599. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_winch_b"),
  12600. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_castle_e_sally_door_a"),
  12601. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_castle_f_sally_door_a"),
  12602. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_earth_sally_gate_left"),
  12603. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_earth_sally_gate_right"),
  12604. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_viking_keep_destroy_sally_door_left"),
  12605. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_viking_keep_destroy_sally_door_right"),
  12606. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_castle_f_door_a"),
  12607. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_door_destructible"),
  12608. (call_script, "script_send_open_close_information_of_object", ":player_no", "spr_castle_f_door_b"),
  12609.  
  12610. (try_begin),
  12611. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  12612. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_destroy),
  12613. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  12614.  
  12615. (store_mission_timer_a, ":current_time"),
  12616. (val_sub, ":current_time", "$g_round_start_time"),
  12617. (val_mul, ":current_time", -1),
  12618.  
  12619. (multiplayer_send_int_to_player, ":player_no", multiplayer_event_set_round_start_time, ":current_time"),
  12620. (else_try),
  12621. (eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  12622. #if game type is capture the flag send current flag situations to each player.
  12623. (team_get_slot, ":flag_situation_team_1", 0, slot_team_flag_situation),
  12624. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_team_flag_situation, 0, ":flag_situation_team_1"),
  12625. (team_get_slot, ":flag_situation_team_2", 1, slot_team_flag_situation),
  12626. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_team_flag_situation, 1, ":flag_situation_team_2"),
  12627. (else_try),
  12628. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters),
  12629. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  12630. #if game type is headquarters send number of agents placed around each pole's around to player.
  12631. (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
  12632. (assign, ":number_of_agents_around_flag_team_1", 0),
  12633. (assign, ":number_of_agents_around_flag_team_2", 0),
  12634.  
  12635. (scene_prop_get_instance, ":pole_id", "spr_headquarters_pole_code_only", ":flag_no"),
  12636. (prop_instance_get_position, pos0, ":pole_id"), #pos0 holds pole position.
  12637.  
  12638. (try_for_agents, ":cur_agent"),
  12639. (agent_is_human, ":cur_agent"),
  12640. (agent_is_alive, ":cur_agent"),
  12641. (neg|agent_is_non_player, ":cur_agent"),
  12642. (agent_get_team, ":cur_agent_team", ":cur_agent"),
  12643. (agent_get_position, pos1, ":cur_agent"), #pos1 holds agent's position.
  12644. (get_sq_distance_between_positions, ":squared_dist", pos0, pos1),
  12645. (get_sq_distance_between_position_heights, ":squared_height_dist", pos0, pos1),
  12646. (val_add, ":squared_dist", ":squared_height_dist"),
  12647. (lt, ":squared_dist", multi_headquarters_max_distance_sq_to_raise_flags),
  12648. (try_begin),
  12649. (eq, ":cur_agent_team", 0),
  12650. (val_add, ":number_of_agents_around_flag_team_1", 1),
  12651. (else_try),
  12652. (eq, ":cur_agent_team", 1),
  12653. (val_add, ":number_of_agents_around_flag_team_2", 1),
  12654. (try_end),
  12655. (try_end),
  12656.  
  12657. (store_mul, ":current_owner_code", ":number_of_agents_around_flag_team_1", 100),
  12658. (val_add, ":current_owner_code", ":number_of_agents_around_flag_team_2"),
  12659. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_num_agents_around_flag, ":flag_no", ":current_owner_code"),
  12660. (try_end),
  12661.  
  12662. #if game type is headquarters send owners of each pole to player.
  12663. (assign, "$g_placing_initial_flags", 1),
  12664. (try_for_range, ":cur_flag", 0, "$g_number_of_flags"),
  12665. (store_add, ":cur_flag_slot", multi_data_flag_owner_begin, ":cur_flag"),
  12666. (troop_get_slot, ":cur_flag_owner", "trp_multiplayer_data", ":cur_flag_slot"),
  12667. (store_mul, ":cur_flag_owner_code", ":cur_flag_owner", 100),
  12668. (val_add, ":cur_flag_owner_code", ":cur_flag_owner"),
  12669. (val_add, ":cur_flag_owner_code", 1),
  12670. (val_mul, ":cur_flag_owner_code", -1),
  12671. (multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_change_flag_owner, ":cur_flag", ":cur_flag_owner_code"),
  12672. (try_end),
  12673. (assign, "$g_placing_initial_flags", 0),
  12674. (try_end),
  12675.  
  12676. #(multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_set_day_time, "$g_round_day_time"),
  12677. ]),
  12678.  
  12679. #script_multiplayer_remove_headquarters_flags
  12680. # Input: none
  12681. # Output: none
  12682. ("multiplayer_remove_headquarters_flags",
  12683. [
  12684. (store_add, ":end_cond", "spr_headquarters_flag_gray", 1),
  12685. (try_for_range, ":headquarters_flag_no", "spr_headquarters_flag_red", ":end_cond"),
  12686. (replace_scene_props, ":headquarters_flag_no", "spr_empty"),
  12687. (try_end),
  12688. ]),
  12689.  
  12690. #script_multiplayer_remove_destroy_mod_targets
  12691. # Input: none
  12692. # Output: none
  12693. ("multiplayer_remove_destroy_mod_targets",
  12694. [
  12695. (replace_scene_props, "spr_catapult_destructible", "spr_empty"),
  12696. (replace_scene_props, "spr_trebuchet_destructible", "spr_empty"),
  12697. ]),
  12698.  
  12699. #script_multiplayer_init_mission_variables
  12700. ("multiplayer_init_mission_variables",
  12701. [
  12702. (assign, "$g_multiplayer_team_1_first_spawn", 1),
  12703. (assign, "$g_multiplayer_team_2_first_spawn", 1),
  12704. (assign, "$g_multiplayer_poll_running", 0),
  12705. ## (assign, "$g_multiplayer_show_poll_when_suitable", 0),
  12706. (assign, "$g_waiting_for_confirmation_to_terminate", 0),
  12707. (assign, "$g_confirmation_result", 0),
  12708. (assign, "$g_team_balance_next_round", 0),
  12709. (team_get_faction, "$g_multiplayer_team_1_faction", 0),
  12710. (team_get_faction, "$g_multiplayer_team_2_faction", 1),
  12711. (assign, "$g_multiplayer_next_team_1_faction", "$g_multiplayer_team_1_faction"),
  12712. (assign, "$g_multiplayer_next_team_2_faction", "$g_multiplayer_team_2_faction"),
  12713.  
  12714. (assign, "$g_multiplayer_bot_type_1_wanted", 0),
  12715. (assign, "$g_multiplayer_bot_type_2_wanted", 0),
  12716. (assign, "$g_multiplayer_bot_type_3_wanted", 0),
  12717. (assign, "$g_multiplayer_bot_type_4_wanted", 0),
  12718.  
  12719. (call_script, "script_music_set_situation_with_culture", mtf_sit_multiplayer_fight),
  12720. ]),
  12721.  
  12722. #script_multiplayer_event_mission_end
  12723. # Input: none
  12724. # Output: none
  12725. ("multiplayer_event_mission_end",
  12726. [
  12727. #EVERY_BREATH_YOU_TAKE achievement
  12728. (try_begin),
  12729. (multiplayer_get_my_player, ":my_player_no"),
  12730. (is_between, ":my_player_no", 0, multiplayer_max_possible_player_id),
  12731. (player_get_kill_count, ":kill_count", ":my_player_no"),
  12732. (player_get_death_count, ":death_count", ":my_player_no"),
  12733. (gt, ":kill_count", ":death_count"),
  12734. (unlock_achievement, ACHIEVEMENT_EVERY_BREATH_YOU_TAKE),
  12735. (try_end),
  12736. #EVERY_BREATH_YOU_TAKE achievement end
  12737. ]),
  12738.  
  12739.  
  12740. #script_multiplayer_event_agent_killed_or_wounded
  12741. # Input: arg1 = dead_agent_no, arg2 = killer_agent_no
  12742. # Output: none
  12743. ("multiplayer_event_agent_killed_or_wounded",
  12744. [
  12745. (store_script_param, ":dead_agent_no", 1),
  12746. (store_script_param, ":killer_agent_no", 2),
  12747.  
  12748. (multiplayer_get_my_player, ":my_player_no"),
  12749. (try_begin),
  12750. (is_between, ":my_player_no", 0, multiplayer_max_possible_player_id),
  12751. (player_get_agent_id, ":my_player_agent", ":my_player_no"),
  12752. (ge, ":my_player_agent", 0),
  12753. (try_begin),
  12754. (eq, ":my_player_agent", ":dead_agent_no"),
  12755. (store_mission_timer_a, "$g_multiplayer_respawn_start_time"),
  12756. (try_end),
  12757. (try_begin),
  12758. (eq, ":my_player_agent", ":killer_agent_no"),
  12759. (neq, ":my_player_agent", ":dead_agent_no"),
  12760. (agent_is_human, ":dead_agent_no"),
  12761. (agent_is_alive, ":my_player_agent"),
  12762. (neg|agent_is_ally, ":dead_agent_no"),
  12763. (agent_get_horse, ":my_horse_agent", ":my_player_agent"),
  12764. (agent_get_wielded_item, ":my_wielded_item", ":my_player_agent", 0),
  12765. (assign, ":my_item_class", -1),
  12766. (try_begin),
  12767. (ge, ":my_wielded_item", 0),
  12768. (item_get_slot, ":my_item_class", ":my_wielded_item", slot_item_multiplayer_item_class),
  12769. (try_end),
  12770. #SPOIL_THE_CHARGE achievement
  12771. (try_begin),
  12772. (lt, ":my_horse_agent", 0),
  12773. (agent_get_horse, ":dead_agent_horse_agent", ":dead_agent_no"),
  12774. (ge, ":dead_agent_horse_agent", 0),
  12775. (get_achievement_stat, ":achievement_stat", ACHIEVEMENT_SPOIL_THE_CHARGE, 0),
  12776. (lt, ":achievement_stat", 50),
  12777. (val_add, ":achievement_stat", 1),
  12778. (set_achievement_stat, ACHIEVEMENT_SPOIL_THE_CHARGE, 0, ":achievement_stat"),
  12779. (ge, ":achievement_stat", 50),
  12780. (unlock_achievement, ACHIEVEMENT_SPOIL_THE_CHARGE),
  12781. (try_end),
  12782. #SPOIL_THE_CHARGE achievement end
  12783. #HARASSING_HORSEMAN achievement
  12784. (try_begin),
  12785. (ge, ":my_horse_agent", 0),
  12786. (this_or_next|eq, ":my_item_class", multi_item_class_type_bow),
  12787. (this_or_next|eq, ":my_item_class", multi_item_class_type_crossbow),
  12788. (this_or_next|eq, ":my_item_class", multi_item_class_type_throwing),
  12789. (eq, ":my_item_class", multi_item_class_type_throwing_axe),
  12790. (get_achievement_stat, ":achievement_stat", ACHIEVEMENT_HARASSING_HORSEMAN, 0),
  12791. (lt, ":achievement_stat", 100),
  12792. (val_add, ":achievement_stat", 1),
  12793. (set_achievement_stat, ACHIEVEMENT_HARASSING_HORSEMAN, 0, ":achievement_stat"),
  12794. (ge, ":achievement_stat", 100),
  12795. (unlock_achievement, ACHIEVEMENT_HARASSING_HORSEMAN),
  12796. (try_end),
  12797. #HARASSING_HORSEMAN achievement end
  12798. #THROWING_STAR achievement
  12799. (try_begin),
  12800. (this_or_next|eq, ":my_item_class", multi_item_class_type_throwing),
  12801. (eq, ":my_item_class", multi_item_class_type_throwing_axe),
  12802. (get_achievement_stat, ":achievement_stat", ACHIEVEMENT_THROWING_STAR, 0),
  12803. (lt, ":achievement_stat", 25),
  12804. (val_add, ":achievement_stat", 1),
  12805. (set_achievement_stat, ACHIEVEMENT_THROWING_STAR, 0, ":achievement_stat"),
  12806. (ge, ":achievement_stat", 25),
  12807. (unlock_achievement, ACHIEVEMENT_THROWING_STAR),
  12808. (try_end),
  12809. #THROWING_STAR achievement end
  12810. #SHISH_KEBAB achievement
  12811. (try_begin),
  12812. (ge, ":my_horse_agent", 0),
  12813. (eq, ":my_item_class", multi_item_class_type_lance),
  12814. (get_achievement_stat, ":achievement_stat", ACHIEVEMENT_SHISH_KEBAB, 0),
  12815. (lt, ":achievement_stat", 25),
  12816. (val_add, ":achievement_stat", 1),
  12817. (set_achievement_stat, ACHIEVEMENT_SHISH_KEBAB, 0, ":achievement_stat"),
  12818. (ge, ":achievement_stat", 25),
  12819. (unlock_achievement, ACHIEVEMENT_SHISH_KEBAB),
  12820. (try_end),
  12821. #SHISH_KEBAB achievement end
  12822. #CHOPPY_CHOP_CHOP achievement
  12823. (try_begin),
  12824. (this_or_next|eq, ":my_item_class", multi_item_class_type_sword),
  12825. (this_or_next|eq, ":my_item_class", multi_item_class_type_axe),
  12826. (this_or_next|eq, ":my_item_class", multi_item_class_type_cleavers),
  12827. (this_or_next|eq, ":my_item_class", multi_item_class_type_two_handed_sword),
  12828. (this_or_next|eq, ":my_item_class", multi_item_class_type_two_handed_axe),
  12829. (this_or_next|eq, ":my_wielded_item", "itm_sarranid_axe_a"), #sarranid item exception
  12830. (eq, ":my_wielded_item", "itm_sarranid_axe_b"), #sarranid item exception
  12831. (neq, ":my_wielded_item", "itm_sarranid_two_handed_mace_1"), #sarranid item exception
  12832. (get_achievement_stat, ":achievement_stat", ACHIEVEMENT_CHOPPY_CHOP_CHOP, 0),
  12833. (lt, ":achievement_stat", 50),
  12834. (val_add, ":achievement_stat", 1),
  12835. (set_achievement_stat, ACHIEVEMENT_CHOPPY_CHOP_CHOP, 0, ":achievement_stat"),
  12836. (ge, ":achievement_stat", 50),
  12837. (unlock_achievement, ACHIEVEMENT_CHOPPY_CHOP_CHOP),
  12838. (try_end),
  12839. #CHOPPY_CHOP_CHOP achievement end
  12840. #MACE_IN_YER_FACE achievement
  12841. (try_begin),
  12842. (this_or_next|eq, ":my_item_class", multi_item_class_type_blunt),
  12843. (eq, ":my_wielded_item", "itm_sarranid_two_handed_mace_1"), #sarranid item exception
  12844. (neq, ":my_wielded_item", "itm_sarranid_axe_b"), #sarranid item exception
  12845. (neq, ":my_wielded_item", "itm_sarranid_axe_a"), #sarranid item exception
  12846. (get_achievement_stat, ":achievement_stat", ACHIEVEMENT_MACE_IN_YER_FACE, 0),
  12847. (lt, ":achievement_stat", 25),
  12848. (val_add, ":achievement_stat", 1),
  12849. (set_achievement_stat, ACHIEVEMENT_MACE_IN_YER_FACE, 0, ":achievement_stat"),
  12850. (ge, ":achievement_stat", 25),
  12851. (unlock_achievement, ACHIEVEMENT_MACE_IN_YER_FACE),
  12852. (try_end),
  12853. #MACE_IN_YER_FACE achievement end
  12854. #THE_HUSCARL achievement
  12855. (try_begin),
  12856. (eq, ":my_item_class", multi_item_class_type_throwing_axe),
  12857. (get_achievement_stat, ":achievement_stat", ACHIEVEMENT_THE_HUSCARL, 0),
  12858. (lt, ":achievement_stat", 50),
  12859. (val_add, ":achievement_stat", 1),
  12860. (set_achievement_stat, ACHIEVEMENT_THE_HUSCARL, 0, ":achievement_stat"),
  12861. (ge, ":achievement_stat", 50),
  12862. (unlock_achievement, ACHIEVEMENT_THE_HUSCARL),
  12863. (try_end),
  12864. #THE_HUSCARL achievement end
  12865. (try_end),
  12866. (try_end),
  12867.  
  12868. (try_begin),
  12869. (is_between, ":my_player_no", 0, multiplayer_max_possible_player_id),
  12870. (player_get_agent_id, ":player_agent", ":my_player_no"),
  12871. (eq, ":dead_agent_no", ":player_agent"),
  12872.  
  12873. (assign, ":show_respawn_counter", 0),
  12874. (try_begin),
  12875. #TODO: add other game types with no respawns here
  12876. (neq, "$g_multiplayer_game_type", multiplayer_game_type_battle),
  12877. (neq, "$g_multiplayer_game_type", multiplayer_game_type_destroy),
  12878. (assign, ":show_respawn_counter", 1),
  12879. (else_try),
  12880. (eq, "$g_multiplayer_player_respawn_as_bot", 1),
  12881. (player_get_team_no, ":my_player_team", ":my_player_no"),
  12882. (assign, ":is_found", 0),
  12883. (try_for_agents, ":cur_agent"),
  12884. (eq, ":is_found", 0),
  12885. (agent_is_alive, ":cur_agent"),
  12886. (agent_is_human, ":cur_agent"),
  12887. (agent_is_non_player, ":cur_agent"),
  12888. (agent_get_team ,":cur_team", ":cur_agent"),
  12889. (eq, ":cur_team", ":my_player_team"),
  12890. (assign, ":is_found", 1),
  12891. (try_end),
  12892. (eq, ":is_found", 1),
  12893. (assign, ":show_respawn_counter", 1),
  12894. (try_end),
  12895.  
  12896. (try_begin),
  12897. #(player_get_slot, ":spawn_count", ":player_no", slot_player_spawn_count),
  12898. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  12899. (gt, "$g_multiplayer_number_of_respawn_count", 0),
  12900.  
  12901. (ge, "$g_my_spawn_count", "$g_multiplayer_number_of_respawn_count"),
  12902.  
  12903. (multiplayer_get_my_player, ":my_player_no"),
  12904. (player_get_team_no, ":my_player_team", ":my_player_no"),
  12905.  
  12906. (this_or_next|eq, ":my_player_team", 0),
  12907. (ge, "$g_my_spawn_count", 999),
  12908.  
  12909. (assign, "$g_show_no_more_respawns_remained", 1),
  12910. (else_try),
  12911. (assign, "$g_show_no_more_respawns_remained", 0),
  12912. (try_end),
  12913.  
  12914. (eq, ":show_respawn_counter", 1),
  12915.  
  12916. (start_presentation, "prsnt_multiplayer_respawn_time_counter"),
  12917. (try_end),
  12918. ]),
  12919.  
  12920. #script_multiplayer_get_item_value_for_troop
  12921. # Input: arg1 = item_no, arg2 = troop_no
  12922. # Output: reg0: item_value
  12923. ("multiplayer_get_item_value_for_troop",
  12924. [
  12925. (store_script_param, ":item_no", 1),
  12926. (store_script_param, ":troop_no", 2),
  12927. (try_begin),
  12928. (call_script, "script_cf_multiplayer_is_item_default_for_troop", ":item_no", ":troop_no"),
  12929. (assign, ":item_value", 0),
  12930. (else_try),
  12931. (store_item_value, ":item_value", ":item_no"),
  12932. (store_troop_faction, ":faction_no", ":troop_no"),
  12933. (store_sub, ":faction_slot", ":faction_no", npc_kingdoms_begin),
  12934. (val_add, ":faction_slot", slot_item_multiplayer_faction_price_multipliers_begin),
  12935. (item_get_slot, ":price_multiplier", ":item_no", ":faction_slot"),
  12936. (val_mul, ":item_value", ":price_multiplier"),
  12937. (val_div, ":item_value", 100),
  12938. (try_end),
  12939. (assign, reg0, ":item_value"),
  12940. ]),
  12941.  
  12942. #script_multiplayer_get_previous_item_for_item_and_troop
  12943. # Input: arg1 = item_no, arg2 = troop_no
  12944. # Output: reg0: previous_item_no (-1 if it is the root item, 0 if the item is invalid)
  12945. ("multiplayer_get_previous_item_for_item_and_troop",
  12946. [
  12947. (store_script_param, ":item_no", 1),
  12948. (store_script_param, ":troop_no", 2),
  12949. (item_get_slot, ":item_class", ":item_no", slot_item_multiplayer_item_class),
  12950. (call_script, "script_multiplayer_get_item_value_for_troop", ":item_no", ":troop_no"),
  12951. (assign, ":item_value", reg0),
  12952. (store_sub, ":troop_index", ":troop_no", multiplayer_troops_begin),
  12953. (val_add, ":troop_index", slot_item_multiplayer_availability_linked_list_begin),
  12954. (assign, ":max_item_no", -1),
  12955. (assign, ":max_item_value", -1),
  12956. (try_for_range, ":i_item", all_items_begin, all_items_end),
  12957. (item_slot_eq, ":i_item", slot_item_multiplayer_item_class, ":item_class"),
  12958. (item_slot_ge, ":i_item", ":troop_index", 1),
  12959. (call_script, "script_multiplayer_get_item_value_for_troop", ":i_item", ":troop_no"),
  12960. (assign, ":i_item_value", reg0),
  12961. (try_begin),
  12962. (eq, ":i_item_value", 0),
  12963. (eq, ":max_item_value", 0),
  12964. #choose between 2 default items
  12965. (store_item_value, ":i_item_real_value", ":i_item"),
  12966. (store_item_value, ":max_item_real_value", ":max_item_no"),
  12967. (try_begin),
  12968. (gt, ":i_item_real_value", ":max_item_real_value"),
  12969. (assign, ":max_item_value", ":i_item_value"),
  12970. (assign, ":max_item_no", ":i_item"),
  12971. (try_end),
  12972. (else_try),
  12973. (gt, ":i_item_value", ":max_item_value"),
  12974. (lt, ":i_item_value", ":item_value"),
  12975. (assign, ":max_item_value", ":i_item_value"),
  12976. (assign, ":max_item_no", ":i_item"),
  12977. (try_end),
  12978. (try_end),
  12979. (try_begin),
  12980. (eq, ":max_item_no", -1),
  12981. (assign, ":item_upper_class", -1),
  12982. (try_begin),
  12983. (is_between, ":item_class", multi_item_class_type_melee_weapons_begin, multi_item_class_type_melee_weapons_end),
  12984. (assign, ":item_upper_class", 0),
  12985. (else_try),
  12986. (is_between, ":item_class", multi_item_class_type_shields_begin, multi_item_class_type_shields_end),
  12987. (assign, ":item_upper_class", 1),
  12988. (else_try),
  12989. (eq, ":item_class", multi_item_class_type_bow),
  12990. (assign, ":item_upper_class", 2),
  12991. (else_try),
  12992. (eq, ":item_class", multi_item_class_type_crossbow),
  12993. (assign, ":item_upper_class", 3),
  12994. (else_try),
  12995. (eq, ":item_class", multi_item_class_type_arrow),
  12996. (assign, ":item_upper_class", 4),
  12997. (else_try),
  12998. (eq, ":item_class", multi_item_class_type_bolt),
  12999. (assign, ":item_upper_class", 5),
  13000. (else_try),
  13001. (eq, ":item_class", multi_item_class_type_throwing),
  13002. (assign, ":item_upper_class", 6),
  13003. (else_try),
  13004. (is_between, ":item_class", multi_item_class_type_heads_begin, multi_item_class_type_heads_end),
  13005. (assign, ":item_upper_class", 7),
  13006. (else_try),
  13007. (is_between, ":item_class", multi_item_class_type_bodies_begin, multi_item_class_type_bodies_end),
  13008. (assign, ":item_upper_class", 8),
  13009. (else_try),
  13010. (is_between, ":item_class", multi_item_class_type_feet_begin, multi_item_class_type_feet_end),
  13011. (assign, ":item_upper_class", 9),
  13012. (else_try),
  13013. (is_between, ":item_class", multi_item_class_type_gloves_begin, multi_item_class_type_gloves_end),
  13014. (assign, ":item_upper_class", 10),
  13015. (else_try),
  13016. (is_between, ":item_class", multi_item_class_type_horses_begin, multi_item_class_type_horses_end),
  13017. (assign, ":item_upper_class", 11),
  13018. (try_end),
  13019. (neq, ":item_upper_class", 0),
  13020. #search for the default item for non-weapon classes (only 1 slot is easy to fill)
  13021. (assign, ":end_cond", all_items_end),
  13022. (try_for_range, ":i_item", all_items_begin, ":end_cond"),
  13023. (item_slot_ge, ":i_item", ":troop_index", 1),
  13024. (item_get_slot, ":i_item_class", ":i_item", slot_item_multiplayer_item_class),
  13025. (try_begin),
  13026. (is_between, ":i_item_class", multi_item_class_type_melee_weapons_begin, multi_item_class_type_melee_weapons_end),
  13027. (assign, ":i_item_upper_class", 0),
  13028. (else_try),
  13029. (is_between, ":i_item_class", multi_item_class_type_shields_begin, multi_item_class_type_shields_end),
  13030. (assign, ":i_item_upper_class", 1),
  13031. (else_try),
  13032. (eq, ":i_item_class", multi_item_class_type_bow),
  13033. (assign, ":i_item_upper_class", 2),
  13034. (else_try),
  13035. (eq, ":i_item_class", multi_item_class_type_crossbow),
  13036. (assign, ":i_item_upper_class", 3),
  13037. (else_try),
  13038. (eq, ":i_item_class", multi_item_class_type_arrow),
  13039. (assign, ":i_item_upper_class", 4),
  13040. (else_try),
  13041. (eq, ":i_item_class", multi_item_class_type_bolt),
  13042. (assign, ":i_item_upper_class", 5),
  13043. (else_try),
  13044. (eq, ":i_item_class", multi_item_class_type_throwing),
  13045. (assign, ":i_item_upper_class", 6),
  13046. (else_try),
  13047. (is_between, ":i_item_class", multi_item_class_type_heads_begin, multi_item_class_type_heads_end),
  13048. (assign, ":i_item_upper_class", 7),
  13049. (else_try),
  13050. (is_between, ":i_item_class", multi_item_class_type_bodies_begin, multi_item_class_type_bodies_end),
  13051. (assign, ":i_item_upper_class", 8),
  13052. (else_try),
  13053. (is_between, ":i_item_class", multi_item_class_type_feet_begin, multi_item_class_type_feet_end),
  13054. (assign, ":i_item_upper_class", 9),
  13055. (else_try),
  13056. (is_between, ":i_item_class", multi_item_class_type_gloves_begin, multi_item_class_type_gloves_end),
  13057. (assign, ":i_item_upper_class", 10),
  13058. (else_try),
  13059. (is_between, ":i_item_class", multi_item_class_type_horses_begin, multi_item_class_type_horses_end),
  13060. (assign, ":i_item_upper_class", 11),
  13061. (try_end),
  13062. (eq, ":i_item_upper_class", ":item_upper_class"),
  13063. (call_script, "script_cf_multiplayer_is_item_default_for_troop", ":i_item", ":troop_no"),
  13064. (assign, ":max_item_no", ":i_item"),
  13065. (assign, ":end_cond", 0), #break
  13066. (try_end),
  13067. (try_end),
  13068. (assign, reg0, ":max_item_no"),
  13069. ]),
  13070.  
  13071. #script_cf_multiplayer_is_item_default_for_troop
  13072. # Input: arg1 = item_no, arg2 = troop_no
  13073. # Output: reg0: total_cost
  13074. ("cf_multiplayer_is_item_default_for_troop",
  13075. [
  13076. (store_script_param, ":item_no", 1),
  13077. (store_script_param, ":troop_no", 2),
  13078. (assign, ":default_item", 0),
  13079. (try_begin),
  13080. (neg|is_between, ":item_no", horses_begin, horses_end),
  13081. (neq, ":item_no", "itm_warhorse_sarranid"),
  13082. (neq, ":item_no", "itm_warhorse_steppe"),
  13083.  
  13084. (troop_get_inventory_capacity, ":end_cond", ":troop_no"), #troop no can come -1 here error occured at friday
  13085. (try_for_range, ":i_slot", 0, ":end_cond"),
  13086. (troop_get_inventory_slot, ":default_item_id", ":troop_no", ":i_slot"),
  13087. (eq, ":item_no", ":default_item_id"),
  13088. (assign, ":default_item", 1),
  13089. (assign, ":end_cond", 0), #break
  13090. (try_end),
  13091. (try_end),
  13092. (eq, ":default_item", 1),
  13093. ]),
  13094.  
  13095. #script_multiplayer_calculate_cur_selected_items_cost
  13096. # Input: arg1 = player_no
  13097. # Output: reg0: total_cost
  13098. ("multiplayer_calculate_cur_selected_items_cost",
  13099. [
  13100. (store_script_param, ":player_no", 1),
  13101. (store_script_param, ":calculation_type", 2), #0 for normal calculation
  13102. (assign, ":total_cost", 0),
  13103. (player_get_troop_id, ":troop_no", ":player_no"),
  13104.  
  13105. (try_begin),
  13106. (eq, ":calculation_type", 0),
  13107. (assign, ":begin_cond", slot_player_cur_selected_item_indices_begin),
  13108. (assign, ":end_cond", slot_player_cur_selected_item_indices_end),
  13109. (else_try),
  13110. (assign, ":begin_cond", slot_player_selected_item_indices_begin),
  13111. (assign, ":end_cond", slot_player_selected_item_indices_end),
  13112. (try_end),
  13113.  
  13114. (try_for_range, ":i_item", ":begin_cond", ":end_cond"),
  13115. (player_get_slot, ":item_id", ":player_no", ":i_item"),
  13116. (ge, ":item_id", 0), #might be -1 for horses etc.
  13117. (call_script, "script_multiplayer_get_item_value_for_troop", ":item_id", ":troop_no"),
  13118. (val_add, ":total_cost", reg0),
  13119. (try_end),
  13120. (assign, reg0, ":total_cost"),
  13121. ]),
  13122.  
  13123. #script_multiplayer_set_item_available_for_troop
  13124. # Input: arg1 = item_no, arg2 = troop_no
  13125. # Output: none
  13126. ("multiplayer_set_item_available_for_troop",
  13127. [
  13128. (store_script_param, ":item_no", 1),
  13129. (store_script_param, ":troop_no", 2),
  13130. (store_sub, ":item_troop_slot", ":troop_no", multiplayer_troops_begin),
  13131. (val_add, ":item_troop_slot", slot_item_multiplayer_availability_linked_list_begin),
  13132. (item_set_slot, ":item_no", ":item_troop_slot", 1),
  13133. ]),
  13134.  
  13135. #script_multiplayer_send_item_selections
  13136. # Input: none
  13137. # Output: none
  13138. ("multiplayer_send_item_selections",
  13139. [
  13140. (multiplayer_get_my_player, ":my_player_no"),
  13141. (try_for_range, ":i_item", slot_player_selected_item_indices_begin, slot_player_selected_item_indices_end),
  13142. (player_get_slot, ":item_id", ":my_player_no", ":i_item"),
  13143. (multiplayer_send_2_int_to_server, multiplayer_event_set_item_selection, ":i_item", ":item_id"),
  13144. (try_end),
  13145. ]),
  13146.  
  13147. #script_multiplayer_set_default_item_selections_for_troop
  13148. # Input: arg1 = troop_no
  13149. # Output: none
  13150. ("multiplayer_set_default_item_selections_for_troop",
  13151. [
  13152. (store_script_param, ":troop_no", 1),
  13153. (multiplayer_get_my_player, ":my_player_no"),
  13154. (call_script, "script_multiplayer_clear_player_selected_items", ":my_player_no"),
  13155. (assign, ":cur_weapon_slot", 0),
  13156. (troop_get_inventory_capacity, ":inv_cap", ":troop_no"),
  13157. (try_for_range, ":i_slot", 0, ":inv_cap"),
  13158. (troop_get_inventory_slot, ":item_id", ":troop_no", ":i_slot"),
  13159. (ge, ":item_id", 0),
  13160. (item_get_slot, ":item_class", ":item_id", slot_item_multiplayer_item_class),
  13161. (try_begin),
  13162. (is_between, ":item_class", multi_item_class_type_weapons_begin, multi_item_class_type_weapons_end),
  13163. (this_or_next|eq, "$g_multiplayer_disallow_ranged_weapons", 0),
  13164. (neg|is_between, ":item_class", multi_item_class_type_ranged_weapons_begin, multi_item_class_type_ranged_weapons_end),
  13165. (store_add, ":selected_item_slot", slot_player_selected_item_indices_begin, ":cur_weapon_slot"),
  13166. (player_set_slot, ":my_player_no", ":selected_item_slot", ":item_id"),
  13167. (val_add, ":cur_weapon_slot", 1),
  13168. (else_try),
  13169. (is_between, ":item_class", multi_item_class_type_heads_begin, multi_item_class_type_heads_end),
  13170. (store_add, ":selected_item_slot", slot_player_selected_item_indices_begin, 4),
  13171. (player_set_slot, ":my_player_no", ":selected_item_slot", ":item_id"),
  13172. (else_try),
  13173. (is_between, ":item_class", multi_item_class_type_bodies_begin, multi_item_class_type_bodies_end),
  13174. (store_add, ":selected_item_slot", slot_player_selected_item_indices_begin, 5),
  13175. (player_set_slot, ":my_player_no", ":selected_item_slot", ":item_id"),
  13176. (else_try),
  13177. (is_between, ":item_class", multi_item_class_type_feet_begin, multi_item_class_type_feet_end),
  13178. (store_add, ":selected_item_slot", slot_player_selected_item_indices_begin, 6),
  13179. (player_set_slot, ":my_player_no", ":selected_item_slot", ":item_id"),
  13180. (else_try),
  13181. (is_between, ":item_class", multi_item_class_type_gloves_begin, multi_item_class_type_gloves_end),
  13182. (store_add, ":selected_item_slot", slot_player_selected_item_indices_begin, 7),
  13183. (player_set_slot, ":my_player_no", ":selected_item_slot", ":item_id"),
  13184. (else_try),
  13185. (is_between, ":item_class", multi_item_class_type_horses_begin, multi_item_class_type_horses_end),
  13186. (eq, "$g_horses_are_avaliable", 1),
  13187. (store_add, ":selected_item_slot", slot_player_selected_item_indices_begin, 8),
  13188. (player_set_slot, ":my_player_no", ":selected_item_slot", ":item_id"),
  13189. (try_end),
  13190. (try_end),
  13191. ]),
  13192.  
  13193. #script_multiplayer_display_available_items_for_troop_and_item_classes
  13194. # Input: arg1 = troop_no, arg2 = item_classes_begin, arg3 = item_classes_end, arg4 = pos_x_begin, arg5 = pos_y_begin
  13195. # Output: none
  13196. ("multiplayer_display_available_items_for_troop_and_item_classes",
  13197. [
  13198. (store_script_param, ":troop_no", 1),
  13199. (store_script_param, ":item_classes_begin", 2),
  13200. (store_script_param, ":item_classes_end", 3),
  13201. (store_script_param, ":pos_x_begin", 4),
  13202. (store_script_param, ":pos_y_begin", 5),
  13203.  
  13204. (assign, ":x_adder", 100),
  13205. (try_begin),
  13206. (gt, ":pos_x_begin", 500),
  13207. (assign, ":x_adder", -100),
  13208. (try_end),
  13209.  
  13210. (store_sub, ":item_troop_slot", ":troop_no", multiplayer_troops_begin),
  13211. (val_add, ":item_troop_slot", slot_item_multiplayer_availability_linked_list_begin),
  13212.  
  13213. (try_for_range, ":cur_slot", multi_data_item_button_indices_begin, multi_data_item_button_indices_end),
  13214. (troop_set_slot, "trp_multiplayer_data", ":cur_slot", -1),
  13215. (try_end),
  13216.  
  13217. (assign, ":num_available_items", 0),
  13218.  
  13219. (try_for_range, ":item_no", all_items_begin, all_items_end),
  13220. (item_get_slot, ":item_class", ":item_no", slot_item_multiplayer_item_class),
  13221. (is_between, ":item_class", ":item_classes_begin", ":item_classes_end"),
  13222. (this_or_next|eq, "$g_multiplayer_disallow_ranged_weapons", 0),
  13223. (neg|is_between, ":item_class", multi_item_class_type_ranged_weapons_begin, multi_item_class_type_ranged_weapons_end),
  13224. (item_slot_ge, ":item_no", ":item_troop_slot", 1),
  13225. (store_add, ":cur_slot_index", ":num_available_items", multi_data_item_button_indices_begin),
  13226. #using the result array for item_ids
  13227. (troop_set_slot, "trp_multiplayer_data", ":cur_slot_index", ":item_no"),
  13228. (val_add, ":num_available_items", 1),
  13229. (try_end),
  13230.  
  13231. #sorting
  13232. (store_add, ":item_slots_end", ":num_available_items", multi_data_item_button_indices_begin),
  13233. (store_sub, ":item_slots_end_minus_one", ":item_slots_end", 1),
  13234. (try_for_range, ":cur_slot", multi_data_item_button_indices_begin, ":item_slots_end_minus_one"),
  13235. (store_add, ":cur_slot_2_begin", ":cur_slot", 1),
  13236. (try_for_range, ":cur_slot_2", ":cur_slot_2_begin", ":item_slots_end"),
  13237. (troop_get_slot, ":item_1", "trp_multiplayer_data", ":cur_slot"),
  13238. (troop_get_slot, ":item_2", "trp_multiplayer_data", ":cur_slot_2"),
  13239. (call_script, "script_multiplayer_get_item_value_for_troop", ":item_1", ":troop_no"),
  13240. (assign, ":item_1_point", reg0),
  13241. (call_script, "script_multiplayer_get_item_value_for_troop", ":item_2", ":troop_no"),
  13242. (assign, ":item_2_point", reg0),
  13243. (item_get_slot, ":item_1_class", ":item_1", slot_item_multiplayer_item_class),
  13244. (item_get_slot, ":item_2_class", ":item_2", slot_item_multiplayer_item_class),
  13245. (val_mul, ":item_1_class", 1000000), #assuming maximum item price is 1000000
  13246. (val_mul, ":item_2_class", 1000000), #assuming maximum item price is 1000000
  13247. (val_add, ":item_1_point", ":item_1_class"),
  13248. (val_add, ":item_2_point", ":item_2_class"),
  13249. (lt, ":item_2_point", ":item_1_point"),
  13250. (troop_set_slot, "trp_multiplayer_data", ":cur_slot", ":item_2"),
  13251. (troop_set_slot, "trp_multiplayer_data", ":cur_slot_2", ":item_1"),
  13252. (try_end),
  13253. (try_end),
  13254.  
  13255. (troop_get_slot, ":last_item_no", "trp_multiplayer_data", multi_data_item_button_indices_begin),
  13256. (assign, ":num_item_classes", 0),
  13257. (try_begin),
  13258. (ge, ":last_item_no", 0),
  13259. (item_get_slot, ":last_item_class", ":last_item_no", slot_item_multiplayer_item_class),
  13260.  
  13261. (try_for_range, ":cur_slot", multi_data_item_button_indices_begin, ":item_slots_end"),
  13262. (troop_get_slot, ":item_no", "trp_multiplayer_data", ":cur_slot"),
  13263. (item_get_slot, ":item_class", ":item_no", slot_item_multiplayer_item_class),
  13264. (neq, ":item_class", ":last_item_class"),
  13265. (val_add, ":num_item_classes", 1),
  13266. (assign, ":last_item_class", ":item_class"),
  13267. (try_end),
  13268.  
  13269. (try_begin),
  13270. (store_mul, ":required_y", ":num_item_classes", 100),
  13271. (gt, ":required_y", ":pos_y_begin"),
  13272. (store_sub, ":dif", ":required_y", ":pos_y_begin"),
  13273. (val_div, ":dif", 100),
  13274. (val_add, ":dif", 1),
  13275. (val_mul, ":dif", 100),
  13276. (val_add, ":pos_y_begin", ":dif"),
  13277. (try_end),
  13278.  
  13279. (item_get_slot, ":last_item_class", ":last_item_no", slot_item_multiplayer_item_class),
  13280. (try_end),
  13281. (assign, ":cur_x", ":pos_x_begin"),
  13282. (assign, ":cur_y", ":pos_y_begin"),
  13283. (try_for_range, ":cur_slot", multi_data_item_button_indices_begin, ":item_slots_end"),
  13284. (troop_get_slot, ":item_no", "trp_multiplayer_data", ":cur_slot"),
  13285. (item_get_slot, ":item_class", ":item_no", slot_item_multiplayer_item_class),
  13286. (try_begin),
  13287. (neq, ":item_class", ":last_item_class"),
  13288. (val_sub, ":cur_y", 100),
  13289. (assign, ":cur_x", ":pos_x_begin"),
  13290. (assign, ":last_item_class", ":item_class"),
  13291. (try_end),
  13292. (create_image_button_overlay, ":cur_obj", "mesh_mp_inventory_choose", "mesh_mp_inventory_choose"),
  13293. (position_set_x, pos1, 800),
  13294. (position_set_y, pos1, 800),
  13295. (overlay_set_size, ":cur_obj", pos1),
  13296. (position_set_x, pos1, ":cur_x"),
  13297. (position_set_y, pos1, ":cur_y"),
  13298. (overlay_set_position, ":cur_obj", pos1),
  13299. (create_mesh_overlay_with_item_id, reg0, ":item_no"),
  13300. (store_add, ":item_x", ":cur_x", 50),
  13301. (store_add, ":item_y", ":cur_y", 50),
  13302. (position_set_x, pos1, ":item_x"),
  13303. (position_set_y, pos1, ":item_y"),
  13304. (overlay_set_position, reg0, pos1),
  13305. (val_add, ":cur_x", ":x_adder"),
  13306. (try_end),
  13307. ]),
  13308.  
  13309. # script_multiplayer_fill_map_game_types
  13310. # Input: game_type
  13311. # Output: num_maps
  13312. ("multiplayer_fill_map_game_types",
  13313. [
  13314. (store_script_param, ":game_type", 1),
  13315. (try_for_range, ":i_multi", multi_data_maps_for_game_type_begin, multi_data_maps_for_game_type_end),
  13316. (troop_set_slot, "trp_multiplayer_data", ":i_multi", -1),
  13317. (try_end),
  13318. (assign, ":num_maps", 0),
  13319. (try_begin),
  13320. (this_or_next|eq, ":game_type", multiplayer_game_type_deathmatch),
  13321. (this_or_next|eq, ":game_type", multiplayer_game_type_duel),
  13322. (eq, ":game_type", multiplayer_game_type_team_deathmatch),
  13323. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin, "scn_multi_scene_1"),
  13324. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 1, "scn_multi_scene_2"),
  13325. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 2, "scn_multi_scene_4"),
  13326. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 3, "scn_multi_scene_7"),
  13327. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 4, "scn_multi_scene_9"),
  13328. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 5, "scn_multi_scene_11"),
  13329. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 6, "scn_multi_scene_12"),
  13330. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 7, "scn_multi_scene_14"),
  13331. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 8, "scn_multi_scene_17"),
  13332. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 9, "scn_multi_scene_18"),
  13333. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 10, "scn_multi_scene_19"),
  13334. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 11, "scn_multi_scene_20"),
  13335. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 12, "scn_random_multi_plain_medium"),
  13336. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 13, "scn_random_multi_plain_large"),
  13337. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 14, "scn_random_multi_steppe_medium"),
  13338. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 15, "scn_random_multi_steppe_large"),
  13339. (assign, ":num_maps", 16),
  13340. (else_try),
  13341. (eq, ":game_type", multiplayer_game_type_battle),
  13342. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin, "scn_multi_scene_1"),
  13343. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 1, "scn_multi_scene_2"),
  13344. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 2, "scn_multi_scene_4"),
  13345. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 3, "scn_multi_scene_7"),
  13346. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 4, "scn_multi_scene_9"),
  13347. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 5, "scn_multi_scene_11"),
  13348. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 6, "scn_multi_scene_12"),
  13349. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 7, "scn_multi_scene_14"),
  13350. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 8, "scn_multi_scene_17"),
  13351. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 9, "scn_multi_scene_18"),
  13352. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 10, "scn_multi_scene_19"),
  13353. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 11, "scn_multi_scene_20"),
  13354. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 12, "scn_random_multi_plain_medium"),
  13355. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 13, "scn_random_multi_plain_large"),
  13356. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 14, "scn_random_multi_steppe_medium"),
  13357. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 15, "scn_random_multi_steppe_large"),
  13358. (assign, ":num_maps", 16),
  13359. (else_try),
  13360. (eq, ":game_type", multiplayer_game_type_destroy),
  13361. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin, "scn_multi_scene_1"),
  13362. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 1, "scn_multi_scene_2"),
  13363. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 2, "scn_multi_scene_4"),
  13364. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 3, "scn_multi_scene_7"),
  13365. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 4, "scn_multi_scene_9"),
  13366. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 5, "scn_multi_scene_12"),
  13367. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 6, "scn_multi_scene_14"),
  13368. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 7, "scn_multi_scene_19"),
  13369. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 8, "scn_multi_scene_20"),
  13370. (assign, ":num_maps", 9),
  13371. (else_try),
  13372. (eq, ":game_type", multiplayer_game_type_capture_the_flag),
  13373. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin, "scn_multi_scene_1"),
  13374. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 1, "scn_multi_scene_2"),
  13375. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 2, "scn_multi_scene_4"),
  13376. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 3, "scn_multi_scene_7"),
  13377. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 4, "scn_multi_scene_9"),
  13378. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 5, "scn_multi_scene_11"),
  13379. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 6, "scn_multi_scene_12"),
  13380. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 7, "scn_multi_scene_14"),
  13381. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 8, "scn_multi_scene_17"),
  13382. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 9, "scn_multi_scene_18"),
  13383. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 10, "scn_multi_scene_19"),
  13384. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 11, "scn_multi_scene_20"),
  13385. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 12, "scn_random_multi_plain_medium"),
  13386. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 13, "scn_random_multi_plain_large"),
  13387. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 14, "scn_random_multi_steppe_medium"),
  13388. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 15, "scn_random_multi_steppe_large"),
  13389. (assign, ":num_maps", 16),
  13390. (else_try),
  13391. (eq, ":game_type", multiplayer_game_type_headquarters),
  13392. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin, "scn_multi_scene_1"),
  13393. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 1, "scn_multi_scene_2"),
  13394. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 2, "scn_multi_scene_4"),
  13395. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 3, "scn_multi_scene_7"),
  13396. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 4, "scn_multi_scene_9"),
  13397. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 5, "scn_multi_scene_11"),
  13398. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 6, "scn_multi_scene_12"),
  13399. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 7, "scn_multi_scene_14"),
  13400. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 8, "scn_multi_scene_17"),
  13401. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 9, "scn_multi_scene_18"),
  13402. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 10, "scn_multi_scene_19"),
  13403. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 11, "scn_multi_scene_20"),
  13404. (assign, ":num_maps", 12),
  13405. (else_try),
  13406. (eq, ":game_type", multiplayer_game_type_siege),
  13407. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin, "scn_multi_scene_3"),
  13408. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 1, "scn_multi_scene_8"),
  13409. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 2, "scn_multi_scene_10"),
  13410. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 3, "scn_multi_scene_13"),
  13411. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 4, "scn_multi_scene_15"),
  13412. (troop_set_slot, "trp_multiplayer_data", multi_data_maps_for_game_type_begin + 5, "scn_multi_scene_16"),
  13413. (assign, ":num_maps", 6),
  13414. (try_end),
  13415. (assign, reg0, ":num_maps"),
  13416. ]),
  13417.  
  13418.  
  13419. # script_multiplayer_count_players_bots
  13420. # Input: none
  13421. # Output: none
  13422. ("multiplayer_count_players_bots",
  13423. [
  13424. (get_max_players, ":num_players"),
  13425. (try_for_range, ":cur_player", 0, ":num_players"),
  13426. (player_is_active, ":cur_player"),
  13427. (player_set_slot, ":cur_player", slot_player_last_bot_count, 0),
  13428. (try_end),
  13429.  
  13430. (try_for_agents, ":cur_agent"),
  13431. (agent_is_human, ":cur_agent"),
  13432. (agent_is_alive, ":cur_agent"),
  13433. (agent_get_player_id, ":agent_player", ":cur_agent"),
  13434. (lt, ":agent_player", 0), #not a player
  13435. (agent_get_group, ":agent_group", ":cur_agent"),
  13436. (player_is_active, ":agent_group"),
  13437. (player_get_slot, ":bot_count", ":agent_group", slot_player_last_bot_count),
  13438. (val_add, ":bot_count", 1),
  13439. (player_set_slot, ":agent_group", slot_player_last_bot_count, ":bot_count"),
  13440. (try_end),
  13441. ]),
  13442.  
  13443. # script_multiplayer_find_player_leader_for_bot
  13444. # Input: arg1 = team_no
  13445. # Output: reg0 = player_no
  13446. ("multiplayer_find_player_leader_for_bot",
  13447. [
  13448. (store_script_param, ":team_no", 1),
  13449. (store_script_param, ":look_only_actives", 2),
  13450.  
  13451. (team_get_faction, ":team_faction", ":team_no"),
  13452. (assign, ":num_ai_troops", 0),
  13453. (try_for_range, ":cur_ai_troop", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
  13454. (store_troop_faction, ":ai_troop_faction", ":cur_ai_troop"),
  13455. (eq, ":ai_troop_faction", ":team_faction"),
  13456. (val_add, ":num_ai_troops", 1),
  13457. (try_end),
  13458.  
  13459. (call_script, "script_multiplayer_count_players_bots"),
  13460.  
  13461. (assign, ":team_player_count", 0),
  13462.  
  13463. (get_max_players, ":num_players"),
  13464. (try_for_range, ":cur_player", 0, ":num_players"),
  13465. (assign, ":continue", 0),
  13466. (player_is_active, ":cur_player"),
  13467. (try_begin),
  13468. (eq, ":look_only_actives", 0),
  13469. (assign, ":continue", 1),
  13470. (else_try),
  13471. (neq, ":look_only_actives", 0),
  13472. (player_get_agent_id, ":cur_agent", ":cur_player"),
  13473. (ge, ":cur_agent", 0),
  13474. (agent_is_alive, ":cur_agent"),
  13475. (assign, ":continue", 1),
  13476. (try_end),
  13477.  
  13478. (eq, ":continue", 1),
  13479.  
  13480. (player_get_team_no, ":player_team", ":cur_player"),
  13481. (eq, ":team_no", ":player_team"),
  13482. (val_add, ":team_player_count", 1),
  13483. (try_end),
  13484. (assign, ":result_leader", -1),
  13485. (try_begin),
  13486. (gt, ":team_player_count", 0),
  13487. (assign, ":total_bot_count", "$g_multiplayer_num_bots_team_1"),
  13488. (try_begin),
  13489. (eq, ":team_no", 1),
  13490. (assign, ":total_bot_count", "$g_multiplayer_num_bots_team_2"),
  13491. (try_end),
  13492. (store_div, ":num_bots_for_each_player", ":total_bot_count", ":team_player_count"),
  13493. (store_mul, ":check_remainder", ":num_bots_for_each_player", ":team_player_count"),
  13494. (try_begin),
  13495. (lt, ":check_remainder", ":total_bot_count"),
  13496. (val_add, ":num_bots_for_each_player", 1),
  13497. (try_end),
  13498.  
  13499. (assign, ":total_bot_req", 0),
  13500. (try_for_range, ":cur_player", 0, ":num_players"),
  13501. (player_is_active, ":cur_player"),
  13502.  
  13503. (player_get_agent_id, ":cur_agent", ":cur_player"),
  13504. (ge, ":cur_agent", 0),
  13505. (agent_is_alive, ":cur_agent"),
  13506.  
  13507. (player_get_team_no, ":player_team", ":cur_player"),
  13508. (eq, ":team_no", ":player_team"),
  13509. (assign, ":ai_wanted", 0),
  13510. (store_add, ":end_cond", slot_player_bot_type_1_wanted, ":num_ai_troops"),
  13511. (try_for_range, ":bot_type_wanted_slot", slot_player_bot_type_1_wanted, ":end_cond"),
  13512. (player_slot_ge, ":cur_player", ":bot_type_wanted_slot", 1),
  13513. (assign, ":ai_wanted", 1),
  13514. (assign, ":end_cond", 0), #break
  13515. (try_end),
  13516. (eq, ":ai_wanted", 1),
  13517. (player_get_slot, ":player_bot_count", ":cur_player", slot_player_last_bot_count),
  13518. (lt, ":player_bot_count", ":num_bots_for_each_player"),
  13519. (val_add, ":total_bot_req", ":num_bots_for_each_player"),
  13520. (val_sub, ":total_bot_req", ":player_bot_count"),
  13521. (try_end),
  13522. (gt, ":total_bot_req", 0),
  13523.  
  13524. (store_random_in_range, ":random_bot", 0, ":total_bot_req"),
  13525. (try_for_range, ":cur_player", 0, ":num_players"),
  13526. (player_is_active, ":cur_player"),
  13527.  
  13528. (player_get_agent_id, ":cur_agent", ":cur_player"),
  13529. (ge, ":cur_agent", 0),
  13530. (agent_is_alive, ":cur_agent"),
  13531.  
  13532. (player_get_team_no, ":player_team", ":cur_player"),
  13533. (eq, ":team_no", ":player_team"),
  13534. (assign, ":ai_wanted", 0),
  13535. (store_add, ":end_cond", slot_player_bot_type_1_wanted, ":num_ai_troops"),
  13536. (try_for_range, ":bot_type_wanted_slot", slot_player_bot_type_1_wanted, ":end_cond"),
  13537. (player_slot_ge, ":cur_player", ":bot_type_wanted_slot", 1),
  13538. (assign, ":ai_wanted", 1),
  13539. (assign, ":end_cond", 0), #break
  13540. (try_end),
  13541. (eq, ":ai_wanted", 1),
  13542. (player_get_slot, ":player_bot_count", ":cur_player", slot_player_last_bot_count),
  13543. (lt, ":player_bot_count", ":num_bots_for_each_player"),
  13544. (val_sub, ":random_bot", ":num_bots_for_each_player"),
  13545. (val_add, ":random_bot", ":player_bot_count"),
  13546. (lt, ":random_bot", 0),
  13547. (assign, ":result_leader", ":cur_player"),
  13548. (assign, ":num_players", 0), #break
  13549. (try_end),
  13550. (try_end),
  13551. (assign, reg0, ":result_leader"),
  13552. ]),
  13553.  
  13554. # script_multiplayer_find_bot_troop_and_group_for_spawn
  13555. # Input: arg1 = team_no
  13556. # Output: reg0 = troop_id, reg1 = group_id
  13557. ("multiplayer_find_bot_troop_and_group_for_spawn",
  13558. [
  13559. (store_script_param, ":team_no", 1),
  13560. (store_script_param, ":look_only_actives", 2),
  13561.  
  13562. (call_script, "script_multiplayer_find_player_leader_for_bot", ":team_no", ":look_only_actives"),
  13563. (assign, ":leader_player", reg0),
  13564.  
  13565. (assign, ":available_troops_in_faction", 0),
  13566. (assign, ":available_troops_to_spawn", 0),
  13567. (team_get_faction, ":team_faction_no", ":team_no"),
  13568.  
  13569. (try_for_range, ":troop_no", multiplayer_ai_troops_begin, multiplayer_ai_troops_end),
  13570. (store_troop_faction, ":troop_faction", ":troop_no"),
  13571. (eq, ":troop_faction", ":team_faction_no"),
  13572. (store_add, ":wanted_slot", slot_player_bot_type_1_wanted, ":available_troops_in_faction"),
  13573. (val_add, ":available_troops_in_faction", 1),
  13574. (try_begin),
  13575. (this_or_next|lt, ":leader_player", 0),
  13576. (player_slot_ge, ":leader_player", ":wanted_slot", 1),
  13577. (val_add, ":available_troops_to_spawn", 1),
  13578. (try_end),
  13579. (try_end),
  13580.  
  13581. (assign, ":available_troops_in_faction", 0),
  13582.  
  13583. (store_random_in_range, ":random_troop_index", 0, ":available_troops_to_spawn"),
  13584. (assign, ":end_cond", multiplayer_ai_troops_end),
  13585. (try_for_range, ":troop_no", multiplayer_ai_troops_begin, ":end_cond"),
  13586. (store_troop_faction, ":troop_faction", ":troop_no"),
  13587. (eq, ":troop_faction", ":team_faction_no"),
  13588. (store_add, ":wanted_slot", slot_player_bot_type_1_wanted, ":available_troops_in_faction"),
  13589. (val_add, ":available_troops_in_faction", 1),
  13590. (this_or_next|lt, ":leader_player", 0),
  13591. (player_slot_ge, ":leader_player", ":wanted_slot", 1),
  13592. (val_sub, ":random_troop_index", 1),
  13593. (lt, ":random_troop_index", 0),
  13594. (assign, ":end_cond", 0),
  13595. (assign, ":selected_troop", ":troop_no"),
  13596. (try_end),
  13597. (assign, reg0, ":selected_troop"),
  13598. (assign, reg1, ":leader_player"),
  13599. ]),
  13600.  
  13601. # script_multiplayer_change_leader_of_bot
  13602. # Input: arg1 = agent_no
  13603. # Output: none
  13604. ("multiplayer_change_leader_of_bot",
  13605. [
  13606. (store_script_param, ":agent_no", 1),
  13607. (agent_get_team, ":team_no", ":agent_no"),
  13608. (call_script, "script_multiplayer_find_player_leader_for_bot", ":team_no", 1),
  13609. (assign, ":leader_player", reg0),
  13610. (agent_set_group, ":agent_no", ":leader_player"),
  13611. ]),
  13612.  
  13613. ("multiplayer_find_spawn_point",
  13614. [
  13615. (store_script_param, ":team_no", 1),
  13616. (store_script_param, ":examine_all_spawn_points", 2), #0-dm, 1-tdm, 2-cf, 3-hq, 4-sg
  13617. (store_script_param, ":is_horseman", 3), #0:no, 1:yes, -1:do not care
  13618.  
  13619. (set_fixed_point_multiplier, 100),
  13620.  
  13621. (assign, ":flags", 0),
  13622.  
  13623. (try_begin),
  13624. (eq, ":examine_all_spawn_points", 1),
  13625. (val_or, ":flags", spf_examine_all_spawn_points),
  13626. (try_end),
  13627.  
  13628. (try_begin),
  13629. (eq, ":is_horseman", 1),
  13630. (val_or, ":flags", spf_is_horseman),
  13631. (try_end),
  13632.  
  13633. (try_begin),
  13634. (eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
  13635. (eq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
  13636. (val_or, ":flags", spf_all_teams_are_enemy),
  13637. (val_or, ":flags", spf_try_to_spawn_close_to_at_least_one_enemy),
  13638. (else_try),
  13639. (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
  13640. (val_or, ":flags", spf_try_to_spawn_close_to_at_least_one_enemy),
  13641. (else_try),
  13642. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13643. (val_or, ":flags", spf_team_1_spawn_far_from_entry_66), #team 1 agents will not spawn 70 meters around of entry 0
  13644. (val_or, ":flags", spf_team_0_walkers_spawn_at_high_points),
  13645. (val_or, ":flags", spf_team_0_spawn_near_entry_66),
  13646. (val_or, ":flags", spf_care_agent_to_agent_distances_less),
  13647. (else_try),
  13648. (eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  13649. (val_or, ":flags", spf_team_1_spawn_far_from_entry_0), #team 1 agents will not spawn 70 meters around of entry 0
  13650. (val_or, ":flags", spf_team_0_spawn_far_from_entry_32), #team 0 agents will not spawn 70 meters around of entry 32
  13651. (val_or, ":flags", spf_try_to_spawn_close_to_at_least_one_enemy),
  13652. (else_try),
  13653. (eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters),
  13654. (assign, ":assigned_flag_count", 0),
  13655.  
  13656. (store_sub, ":maximum_moved_flag_distance", multi_headquarters_pole_height, 50), #900 - 50 = 850
  13657. (store_mul, ":maximum_moved_flag_distance_sq", ":maximum_moved_flag_distance", ":maximum_moved_flag_distance"),
  13658. (val_div, ":maximum_moved_flag_distance_sq", 100), #dividing 100, because fixed point multiplier is 100 and it is included twice, look above line.
  13659.  
  13660. (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
  13661. (store_add, ":cur_flag_owner_slot", multi_data_flag_owner_begin, ":flag_no"),
  13662. (troop_get_slot, ":cur_flag_owner", "trp_multiplayer_data", ":cur_flag_owner_slot"),
  13663.  
  13664. (scene_prop_get_instance, ":pole_id", "spr_headquarters_pole_code_only", ":flag_no"),
  13665. (prop_instance_get_position, pos0, ":pole_id"),
  13666.  
  13667. (try_begin),
  13668. (eq, ":cur_flag_owner", 1),
  13669. (scene_prop_get_instance, ":flag_of_team_1", "$team_1_flag_scene_prop", ":flag_no"),
  13670.  
  13671. (prop_instance_get_position, pos1, ":flag_of_team_1"),
  13672. (get_sq_distance_between_positions, ":flag_height_sq", pos0, pos1),
  13673. (ge, ":flag_height_sq", ":maximum_moved_flag_distance_sq"),
  13674.  
  13675. (set_spawn_effector_scene_prop_id, ":assigned_flag_count", ":flag_of_team_1"),
  13676. (val_add, ":assigned_flag_count", 1),
  13677. (else_try),
  13678. (eq, ":cur_flag_owner", 2),
  13679. (scene_prop_get_instance, ":flag_of_team_2", "$team_2_flag_scene_prop", ":flag_no"),
  13680.  
  13681. (prop_instance_get_position, pos1, ":flag_of_team_2"),
  13682. (get_sq_distance_between_positions, ":flag_height_sq", pos0, pos1),
  13683. (ge, ":flag_height_sq", ":maximum_moved_flag_distance_sq"),
  13684.  
  13685. (set_spawn_effector_scene_prop_id, ":assigned_flag_count", ":flag_of_team_2"),
  13686. (val_add, ":assigned_flag_count", 1),
  13687. (try_end),
  13688. (try_end),
  13689. (set_spawn_effector_scene_prop_id, ":assigned_flag_count", -1),
  13690. (try_end),
  13691.  
  13692. (multiplayer_find_spawn_point, reg0, ":team_no", ":flags"),
  13693. ]),
  13694.  
  13695. # script_multiplayer_find_spawn_point_2
  13696. # Input: arg1 = team_no, arg2 = examine_all_spawn_points, arg3 = is_horseman
  13697. # Output: reg0 = entry_point_no
  13698. ("multiplayer_find_spawn_point_2",
  13699. [
  13700. (store_script_param, ":team_no", 1),
  13701. (store_script_param, ":examine_all_spawn_points", 2), #0-dm, 1-tdm, 2-cf, 3-hq, 4-sg
  13702. (store_script_param, ":is_horseman", 3), #0:no, 1:yes, -1:do not care
  13703.  
  13704. (assign, ":best_entry_point_score", -10000000),
  13705. (assign, ":best_entry_point", 0),
  13706.  
  13707. (assign, ":num_operations", 0),
  13708.  
  13709. (assign, ":num_human_agents_div_3_plus_one", 0),
  13710. (try_begin), #counting number of agents
  13711. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  13712. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters),
  13713. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13714. (try_for_agents, ":i_agent"),
  13715. (agent_is_alive, ":i_agent"),
  13716. (agent_is_human, ":i_agent"),
  13717. (val_add, ":num_human_agents_div_3_plus_one", 1),
  13718. (try_end),
  13719. (try_end),
  13720.  
  13721. (assign, ":num_human_agents_plus_one", ":num_human_agents_div_3_plus_one"),
  13722.  
  13723. (try_begin),
  13724. (le, ":num_human_agents_plus_one", 4),
  13725. (assign, ":random_number_upper_limit", 2), #this is not typo-mistake this should be 2 too, not 1.
  13726. (else_try),
  13727. (le, ":num_human_agents_plus_one", 8),
  13728. (assign, ":random_number_upper_limit", 2),
  13729. (else_try),
  13730. (le, ":num_human_agents_plus_one", 16),
  13731. (assign, ":random_number_upper_limit", 3),
  13732. (else_try),
  13733. (le, ":num_human_agents_plus_one", 24),
  13734. (assign, ":random_number_upper_limit", 4),
  13735. (else_try),
  13736. (le, ":num_human_agents_plus_one", 32),
  13737. (assign, ":random_number_upper_limit", 5),
  13738. (else_try),
  13739. (le, ":num_human_agents_plus_one", 40),
  13740. (assign, ":random_number_upper_limit", 6),
  13741. (else_try),
  13742. (assign, ":random_number_upper_limit", 7),
  13743. (try_end),
  13744.  
  13745. (val_div, ":num_human_agents_div_3_plus_one", 3),
  13746. (val_add, ":num_human_agents_div_3_plus_one", 1),
  13747. (store_mul, ":negative_num_human_agents_div_3_plus_one", ":num_human_agents_div_3_plus_one", -1),
  13748.  
  13749. (try_begin),
  13750. (eq, ":examine_all_spawn_points", 1),
  13751. (assign, ":random_number_upper_limit", 1),
  13752. (try_end),
  13753.  
  13754. (try_begin), #counting number of our flags and enemy flags
  13755. (eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters),
  13756. (assign, ":our_flag_count", 0),
  13757. (assign, ":enemy_flag_count", 0),
  13758. (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
  13759. (store_add, ":cur_flag_owner_slot", multi_data_flag_owner_begin, ":flag_no"),
  13760. (troop_get_slot, ":cur_flag_owner", "trp_multiplayer_data", ":cur_flag_owner_slot"),
  13761. (neq, ":cur_flag_owner", 0),
  13762. (val_sub, ":cur_flag_owner", 1),
  13763. (try_begin),
  13764. (eq, ":cur_flag_owner", ":team_no"),
  13765. (val_add, ":our_flag_count", 1),
  13766. (else_try),
  13767. (val_add, ":enemy_flag_count", 1),
  13768. (try_end),
  13769. (try_end),
  13770. (try_end),
  13771.  
  13772. (assign, ":first_agent", 0),
  13773. (try_begin), #first spawned agents will be spawned at their base points in tdm, cf and hq mods.
  13774. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
  13775. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  13776. (eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters),
  13777. (try_begin),
  13778. (eq, ":team_no", 0),
  13779. (eq, "$g_multiplayer_team_1_first_spawn", 1),
  13780. (assign, ":first_agent", 1),
  13781. (assign, "$g_multiplayer_team_1_first_spawn", 0),
  13782. (else_try),
  13783. (eq, ":team_no", 1),
  13784. (eq, "$g_multiplayer_team_2_first_spawn", 1),
  13785. (assign, ":first_agent", 1),
  13786. (assign, "$g_multiplayer_team_2_first_spawn", 0),
  13787. (try_end),
  13788. (try_end),
  13789.  
  13790. (try_begin),
  13791. (eq, ":first_agent", 1),
  13792. (store_mul, ":best_entry_point", ":team_no", multi_num_valid_entry_points_div_2),
  13793. (else_try),
  13794. (try_for_range, ":i_entry_point", 0, multi_num_valid_entry_points),
  13795. (assign, ":minimum_enemy_distance", 3000),
  13796. (assign, ":second_minimum_enemy_distance", 3000),
  13797.  
  13798. (assign, ":entry_point_score", 0),
  13799. (store_random_in_range, ":random_value", 0, ":random_number_upper_limit"), #in average it is 5
  13800. (eq, ":random_value", 0),
  13801. (entry_point_get_position, pos0, ":i_entry_point"), #pos0 holds current entry point position
  13802. (try_for_agents, ":i_agent"),
  13803. (agent_is_alive, ":i_agent"),
  13804. (agent_is_human, ":i_agent"),
  13805. (agent_get_team, ":agent_team", ":i_agent"),
  13806. (try_begin),
  13807. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
  13808. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  13809. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters),
  13810. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13811. (try_begin),
  13812. (teams_are_enemies, ":team_no", ":agent_team"),
  13813. (assign, ":multiplier", -2),
  13814. (else_try),
  13815. (assign, ":multiplier", 1),
  13816. (try_end),
  13817. (else_try),
  13818. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
  13819. (eq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
  13820. (assign, ":multiplier", -1),
  13821. (try_end),
  13822. (agent_get_position, pos1, ":i_agent"),
  13823. (get_distance_between_positions_in_meters, ":distance", pos0, pos1),
  13824. (val_add, ":num_operations", 1),
  13825. (try_begin),
  13826. (try_begin), #find closest enemy soldiers
  13827. (lt, ":multiplier", 0),
  13828. (try_begin),
  13829. (lt, ":distance", ":minimum_enemy_distance"),
  13830. (assign, ":second_minimum_enemy_distance", ":minimum_enemy_distance"),
  13831. (assign, ":minimum_enemy_distance", ":distance"),
  13832. (else_try),
  13833. (lt, ":distance", ":second_minimum_enemy_distance"),
  13834. (assign, ":second_minimum_enemy_distance", ":distance"),
  13835. (try_end),
  13836. (try_end),
  13837.  
  13838. (lt, ":distance", 100),
  13839. (try_begin), #do not spawn over or too near to another agent (limit is 2 meters, squared 4 meters)
  13840. (lt, ":distance", 3),
  13841. (try_begin),
  13842. (this_or_next|eq, ":examine_all_spawn_points", 0),
  13843. (this_or_next|lt, ":multiplier", 0), #new added 20.08.08
  13844. (neq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13845. (try_begin),
  13846. (lt, ":distance", 1),
  13847. (assign, ":dist_point", -1000000), #never place
  13848. (else_try),
  13849. (lt, ":distance", 2),
  13850. (try_begin),
  13851. (lt, ":multiplier", 0),
  13852. (assign, ":dist_point", -20000),
  13853. (else_try),
  13854. (assign, ":dist_point", -2000), #can place, friend and distance is between 1-2 meters
  13855. (try_end),
  13856. (else_try),
  13857. (try_begin),
  13858. (lt, ":multiplier", 0),
  13859. (assign, ":dist_point", -10000),
  13860. (else_try),
  13861. (assign, ":dist_point", -1000), #can place, friend and distance is between 2-3 meters
  13862. (try_end),
  13863. (try_end),
  13864. (else_try),
  13865. #if examinining all spawn points and mod is siege only. This happens in new round start placings.
  13866. (try_begin),
  13867. (lt, ":distance", 1),
  13868. (assign, ":dist_point", -20000), #very hard to place distance is < 1 meter
  13869. (else_try),
  13870. (lt, ":distance", 2),
  13871. (assign, ":dist_point", -2000),
  13872. (else_try),
  13873. (assign, ":dist_point", -1000), #can place, distance is between 2-3 meters
  13874. (try_end),
  13875. (try_end),
  13876.  
  13877. (val_mul, ":dist_point", ":num_human_agents_div_3_plus_one"),
  13878. (else_try),
  13879. (assign, ":dist_point", 0),
  13880. (this_or_next|neq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13881. (this_or_next|lt, ":multiplier", 0),
  13882. (eq, ":team_no", 1), #only attackers are effected by positive enemy & friend distance at siege mod, defenders only get negative score effect a bit
  13883.  
  13884. (try_begin), #in siege give no positive or negative score to > 40m distance. (6400 = 10000 - 3600(60 * 60))
  13885. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13886.  
  13887. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch), #new added after moving below part to above
  13888. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_duel), #new added after moving below part to above
  13889. (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch), #new added after moving below part to above
  13890.  
  13891. (store_sub, ":dist_point", multiplayer_spawn_min_enemy_dist_limit, ":distance"), #up to 40 meters give (positive(if friend) or negative(if enemy)) points
  13892. (val_max, ":dist_point", 0),
  13893. (val_mul, ":dist_point", ":dist_point"),
  13894. (else_try),
  13895. (store_mul, ":one_and_half_limit", multiplayer_spawn_min_enemy_dist_limit, 3),
  13896. (val_div, ":one_and_half_limit", 2),
  13897. (store_sub, ":dist_point", ":one_and_half_limit", ":distance"), #up to 60 meters give (positive(if friend) or negative(if enemy)) points
  13898. (val_mul, ":dist_point", ":dist_point"),
  13899. (try_end),
  13900.  
  13901. (val_mul, ":dist_point", ":multiplier"),
  13902. (try_end),
  13903. (val_add, ":entry_point_score", ":dist_point"),
  13904. (try_end),
  13905. (try_end),
  13906.  
  13907. (try_begin),
  13908. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13909. (store_mul, ":max_enabled_agent_distance_score", 1000, ":num_human_agents_div_3_plus_one"),
  13910. (ge, ":entry_point_score", ":max_enabled_agent_distance_score"),
  13911. (assign, ":entry_point_score", ":max_enabled_agent_distance_score"),
  13912. (try_end),
  13913.  
  13914. (try_begin),
  13915. (neq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13916.  
  13917. #(assign, ":minimum_enemy_dist_score", 0), #close also these with displays
  13918. #(assign, ":second_minimum_enemy_dist_score", 0), #close also these with displays
  13919. #(assign, reg2, ":minimum_enemy_distance"), #close also these with displays
  13920. #(assign, reg3, ":second_minimum_enemy_distance"), #close also these with displays
  13921.  
  13922. (try_begin), #if minimum enemy dist score is greater than 40(multiplayer_spawn_above_opt_enemy_dist_point) meters then give negative score
  13923. (lt, ":minimum_enemy_distance", 3000),
  13924. (try_begin),
  13925. (gt, ":minimum_enemy_distance", multiplayer_spawn_above_opt_enemy_dist_point),
  13926. (val_sub, ":minimum_enemy_distance", multiplayer_spawn_above_opt_enemy_dist_point),
  13927. (store_mul, ":minimum_enemy_dist_score", ":minimum_enemy_distance", -50),
  13928. (val_mul, ":minimum_enemy_dist_score", ":num_human_agents_div_3_plus_one"),
  13929. (val_add, ":entry_point_score", ":minimum_enemy_dist_score"),
  13930. (try_end),
  13931. (try_end),
  13932.  
  13933. (try_begin), #if second minimum enemy dist score is greater than 40(multiplayer_spawn_above_opt_enemy_dist_point) meters then give negative score
  13934. (lt, ":second_minimum_enemy_distance", 3000), #3000 x 3000
  13935. (try_begin),
  13936. (gt, ":second_minimum_enemy_distance", multiplayer_spawn_above_opt_enemy_dist_point),
  13937. (val_sub, ":second_minimum_enemy_distance", multiplayer_spawn_above_opt_enemy_dist_point),
  13938. (store_mul, ":second_minimum_enemy_dist_score", ":second_minimum_enemy_distance", -50),
  13939. (val_mul, ":second_minimum_enemy_dist_score", ":num_human_agents_div_3_plus_one"),
  13940. (val_add, ":entry_point_score", ":second_minimum_enemy_dist_score"),
  13941. (try_end),
  13942. (try_end),
  13943.  
  13944. #(assign, reg0, ":minimum_enemy_dist_score"), #close also above assignment lines with these displays
  13945. #(assign, reg1, ":second_minimum_enemy_dist_score"), #close also above assignment lines with these displays
  13946. #(display_message, "@{!}minimum enemy distance : {reg2}, score : {reg0}"), #close also above assignment lines with these displays
  13947. #(display_message, "@{!}second minimum enemy distance : {reg3}, score : {reg1}"), #close also above assignment lines with these displays
  13948. (try_end),
  13949.  
  13950. (try_begin), #giving positive points for "distance of entry point position to ground" while searching for entry point for defender team
  13951. (neq, ":is_horseman", -1), #if being horseman or rider is not (not important)
  13952.  
  13953. #additional score to entry points which has distance to ground value of > 0 meters
  13954. (position_get_distance_to_terrain, ":height_to_terrain", pos0),
  13955. (val_max, ":height_to_terrain", 0),
  13956. (val_min, ":height_to_terrain", 300),
  13957. (ge, ":height_to_terrain", 40),
  13958.  
  13959. (store_mul, ":height_to_terrain_score", ":height_to_terrain", ":num_human_agents_div_3_plus_one"), #it was 8
  13960.  
  13961. (try_begin),
  13962. (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
  13963. (val_mul, ":height_to_terrain_score", 16),
  13964. (else_try),
  13965. (val_mul, ":height_to_terrain_score", 4),
  13966. (try_end),
  13967.  
  13968. (try_begin),
  13969. (eq, ":is_horseman", 0),
  13970. (try_begin),
  13971. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege), #but only in siege mod, defender infantries will get positive points for spawning in high places.
  13972. (eq, ":team_no", 0),
  13973. (val_add, ":entry_point_score", ":height_to_terrain_score"),
  13974. (try_end),
  13975. (else_try),
  13976. (val_mul, ":height_to_terrain_score", 5),
  13977. (val_sub, ":entry_point_score", ":height_to_terrain_score"),
  13978. (try_end),
  13979. (try_end),
  13980.  
  13981. (try_begin), #additional random entry point score at deathmatch, teamdethmatch, capture the flag and siege
  13982. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13983. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
  13984. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
  13985. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  13986. (eq, "$g_multiplayer_game_type", multiplayer_game_type_team_deathmatch),
  13987. (try_begin),
  13988. (neq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  13989. (store_random_in_range, ":random_value", 0, 400),
  13990.  
  13991. (try_begin),
  13992. (eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  13993. (val_mul, ":random_value", 5),
  13994. (try_end),
  13995. (else_try),
  13996. (eq, ":team_no", 1),
  13997. (store_random_in_range, ":random_value", 0, 600), #siege-attacker
  13998. (else_try),
  13999. (store_random_in_range, ":random_value", 0, 200), #siege-defender
  14000. (try_end),
  14001. (val_mul, ":random_value", ":num_human_agents_div_3_plus_one"),
  14002. (val_add, ":entry_point_score", ":random_value"),
  14003. (try_end),
  14004.  
  14005. (try_begin),
  14006. (this_or_next|eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  14007. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  14008.  
  14009. (try_begin),
  14010. (eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  14011. (try_begin),
  14012. (eq, ":team_no", 0),
  14013. (entry_point_get_position, pos1, multi_base_point_team_1), #our base is at pos1
  14014. (entry_point_get_position, pos2, multi_base_point_team_2), #enemy base is at pos2
  14015. (else_try),
  14016. (entry_point_get_position, pos1, multi_base_point_team_2), #our base is at pos2
  14017. (entry_point_get_position, pos2, multi_base_point_team_1), #enemy base is at pos1
  14018. (try_end),
  14019. (else_try),
  14020. (try_begin), #siege
  14021. (eq, ":team_no", 0),
  14022. (entry_point_get_position, pos1, multi_siege_flag_point), #our base is at pos1 (it was multi_initial_spawn_point_team_1 changed at v622)
  14023. (entry_point_get_position, pos2, multi_initial_spawn_point_team_2), #enemy base is at pos2
  14024. (else_try),
  14025. (entry_point_get_position, pos1, multi_initial_spawn_point_team_2), #our base is at pos2
  14026. (entry_point_get_position, pos2, multi_siege_flag_point), #enemy base is at pos1 (it was multi_initial_spawn_point_team_1 changed at v622)
  14027. (try_end),
  14028. (try_end),
  14029.  
  14030. (try_begin),
  14031. (eq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  14032. (position_get_z, ":pos0_z", pos0),
  14033. (position_set_z, pos1, ":pos0_z"), #make z of our base same with entry point position z
  14034. (position_set_z, pos2, ":pos0_z"), #make z of enemy base same with entry point position z
  14035. (try_end),
  14036.  
  14037. (get_sq_distance_between_positions_in_meters, ":sq_dist_to_our_base", pos0, pos1),
  14038. (get_sq_distance_between_positions_in_meters, ":sq_dist_to_enemy_base", pos0, pos2),
  14039. (get_distance_between_positions_in_meters, ":dist_to_enemy_base", pos0, pos2),
  14040.  
  14041. #give positive points if this entry point is near to our base.
  14042. (assign, ":dist_to_our_base_point", 0),
  14043. (try_begin), #capture the flag (points for being near to base)
  14044. (eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  14045.  
  14046. (get_distance_between_positions_in_meters, ":dist_to_our_base", pos0, pos1),
  14047. (lt, ":dist_to_our_base", 100),
  14048. (store_sub, ":dist_to_our_base_point", 100, ":dist_to_our_base"),
  14049.  
  14050. (try_begin), #assign all 75-100's to 75
  14051. (gt, ":dist_to_our_base_point", 75),
  14052. (assign, ":dist_to_our_base_point", 75),
  14053. (try_end),
  14054.  
  14055. (val_mul, ":dist_to_our_base_point", 50), #0..5000 (increase is linear)
  14056.  
  14057. (val_mul, ":dist_to_our_base_point", ":num_human_agents_div_3_plus_one"),
  14058. (else_try), #siege (points for being near to base)
  14059. (lt, ":sq_dist_to_our_base", 10000), #in siege give entry points score until 100m distance is reached
  14060. (try_begin),
  14061. (eq, ":team_no", 0),
  14062. (try_begin),
  14063. (lt, ":sq_dist_to_our_base", 2500), #if distance is < 50m in siege give all highest point possible
  14064. (assign, ":sq_dist_to_our_base", 0),
  14065. (else_try),
  14066. (val_sub, ":sq_dist_to_our_base", 2500),
  14067. (val_mul, ":sq_dist_to_our_base", 2),
  14068. (try_end),
  14069. (try_end),
  14070.  
  14071. (store_sub, ":dist_to_our_base_point", 10000, ":sq_dist_to_our_base"),
  14072.  
  14073. #can be (10000 - (10000 - 2500) * 2) = -5000 (for only defenders) so we are adding this loss.
  14074. (val_add, ":dist_to_our_base_point", 5000), #so score getting from being near to base changes between 0 to 15000
  14075.  
  14076. (try_begin),
  14077. (eq, ":team_no", 0),
  14078. (else_try), #in siege mod for attackers being near to base entry point has 45 times less importance
  14079. (val_div, ":dist_to_our_base_point", 45),
  14080. (try_end),
  14081. (val_mul, ":dist_to_our_base_point", ":num_human_agents_div_3_plus_one"),
  14082. (try_end),
  14083.  
  14084. (val_add, ":entry_point_score", ":dist_to_our_base_point"),
  14085.  
  14086.  
  14087. #give negative points if this entry point is near to enemy base.
  14088. (assign, ":dist_to_enemy_base_point", 0),
  14089. (try_begin), #capture the flag
  14090. (eq, "$g_multiplayer_game_type", multiplayer_game_type_capture_the_flag),
  14091.  
  14092. (lt, ":dist_to_enemy_base", 150),
  14093. (store_sub, ":dist_to_enemy_base_point", 150, ":dist_to_enemy_base"),
  14094.  
  14095. (try_begin), #assign 150 to 150 + (150 - 50) * 2 = 350, assign 100 to 100 + (100 - 50) * 2 = 200
  14096. (gt, ":dist_to_enemy_base_point", 50),
  14097. (store_sub, ":dist_to_enemy_base_point_minus_50", ":dist_to_enemy_base_point", 50),
  14098. (val_mul, ":dist_to_enemy_base_point_minus_50", 2),
  14099. (val_add, ":dist_to_enemy_base_point", ":dist_to_enemy_base_point_minus_50"),
  14100. (try_end),
  14101.  
  14102. (val_mul, ":dist_to_enemy_base_point", -50), #-7500(with extras 350 * 50 = -17500)..0 (increase is linear)
  14103.  
  14104. (val_mul, ":dist_to_enemy_base_point", ":num_human_agents_div_3_plus_one"),
  14105. (else_try),
  14106. (this_or_next|neq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  14107. (eq, ":team_no", 1),
  14108.  
  14109. (assign, ":dist_to_enemy_base_point", 0),
  14110.  
  14111. (try_begin),
  14112. (neq, "$g_multiplayer_game_type", multiplayer_game_type_siege),
  14113.  
  14114. (try_begin),
  14115. (lt, ":sq_dist_to_enemy_base", 10000),
  14116. (store_sub, ":dist_to_enemy_base_point", 10000, ":sq_dist_to_enemy_base"),
  14117. (val_div, ":dist_to_enemy_base_point", 4),
  14118. (val_mul, ":dist_to_enemy_base_point", ":negative_num_human_agents_div_3_plus_one"),
  14119. (try_end),
  14120. (else_try),
  14121. (val_max, ":dist_to_enemy_base", 60), #<60 meters has all most negative score
  14122.  
  14123. (try_begin),
  14124. (eq, ":is_horseman", 1),
  14125. (assign, ":optimal_distance", 120),
  14126. (else_try),
  14127. (assign, ":optimal_distance", 80),
  14128. (try_end),
  14129.  
  14130. (try_begin),
  14131. (le, ":dist_to_enemy_base", ":optimal_distance"),
  14132. (store_sub, ":dist_to_enemy_base_point", ":optimal_distance", ":dist_to_enemy_base"),
  14133. (val_mul, ":dist_to_enemy_base_point", 180), #-3600 max
  14134. (else_try),
  14135. (store_sub, ":dist_to_enemy_base_point", ":dist_to_enemy_base", ":optimal_distance"),
  14136. (val_mul, ":dist_to_enemy_base_point", 30), #-unlimited max but lower slope
  14137. (try_end),
  14138.  
  14139. (val_sub, ":dist_to_enemy_base_point", 600),
  14140. (val_max, ":dist_to_enemy_base_point", 0),
  14141.  
  14142. (val_mul, ":dist_to_enemy_base_point", ":negative_num_human_agents_div_3_plus_one"),
  14143. (try_end),
  14144. (try_end),
  14145.  
  14146. (val_add, ":entry_point_score", ":dist_to_enemy_base_point"),
  14147. (else_try),
  14148. (eq, "$g_multiplayer_game_type", multiplayer_game_type_headquarters),
  14149.  
  14150. (try_for_range, ":flag_no", 0, "$g_number_of_flags"),
  14151. (store_add, ":cur_flag_owner_slot", multi_data_flag_owner_begin, ":flag_no"),
  14152. (troop_get_slot, ":cur_flag_owner", "trp_multiplayer_data", ":cur_flag_owner_slot"),
  14153. (neq, ":cur_flag_owner", 0),
  14154. (val_sub, ":cur_flag_owner", 1),
  14155.  
  14156. (scene_prop_get_instance, ":pole_id", "spr_headquarters_pole_code_only", ":flag_no"),
  14157. (prop_instance_get_position, pos1, ":pole_id"), #pos1 holds pole position.
  14158.  
  14159. (get_sq_distance_between_positions_in_meters, ":sq_dist_to_cur_pole", pos0, pos1),
  14160. (lt, ":sq_dist_to_cur_pole", 6400),
  14161.  
  14162. (try_begin),
  14163. (eq, ":cur_flag_owner", ":team_no"),
  14164. (store_sub, ":dist_to_flag_point", 6400, ":sq_dist_to_cur_pole"), #up to 80 meters give positive points if entry point is near our base
  14165. (val_mul, ":dist_to_flag_point", 2),
  14166. (val_div, ":dist_to_flag_point", ":our_flag_count"),
  14167. (val_mul, ":dist_to_flag_point", ":num_human_agents_div_3_plus_one"),
  14168. (else_try),
  14169. (store_sub, ":dist_to_flag_point", 6400, ":sq_dist_to_cur_pole"), #up to 80 meters give negative points if entry point is near enemy base
  14170. (val_mul, ":dist_to_flag_point", 2),
  14171. (val_div, ":dist_to_flag_point", ":enemy_flag_count"),
  14172. (val_mul, ":dist_to_flag_point", ":negative_num_human_agents_div_3_plus_one"),
  14173. (try_end),
  14174. (val_add, ":entry_point_score", ":dist_to_flag_point"),
  14175. (try_end),
  14176. (try_end),
  14177.  
  14178. #(assign, reg1, ":i_entry_point"),
  14179. #(assign, reg2, ":entry_point_score"),
  14180. #(display_message, "@{!}entry_no : {reg1} , entry_score : {reg2}"),
  14181.  
  14182. (gt, ":entry_point_score", ":best_entry_point_score"),
  14183. (assign, ":best_entry_point_score", ":entry_point_score"),
  14184. (assign, ":best_entry_point", ":i_entry_point"),
  14185. (try_end),
  14186.  
  14187. #(assign, reg0, ":best_entry_point"),
  14188. #(assign, reg1, ":best_entry_point_score"),
  14189. #(assign, reg2, ":num_operations"),
  14190. #(assign, reg7, ":is_horseman"),
  14191. #(display_message, "@{!},is horse:{reg7}, best entry:{reg0}, best entry score:{reg1}, num_operations:{reg2}"),
  14192. (try_end),
  14193. (assign, reg0, ":best_entry_point"),
  14194. ]),
  14195.  
  14196. #script_multiplayer_buy_agent_equipment
  14197. # Input: arg1 = player_no
  14198. # Output: none
  14199. ("multiplayer_buy_agent_equipment",
  14200. [
  14201. (store_script_param, ":player_no", 1),
  14202. (player_get_troop_id, ":player_troop", ":player_no"),
  14203. (player_get_gold, ":player_gold", ":player_no"),
  14204. (player_get_slot, ":added_gold", ":player_no", slot_player_last_rounds_used_item_earnings),
  14205. (player_set_slot, ":player_no", slot_player_last_rounds_used_item_earnings, 0),
  14206. (val_add, ":player_gold", ":added_gold"),
  14207. (assign, ":armor_bought", 0),
  14208.  
  14209. #moving original values to temp slots
  14210. (try_for_range, ":i_item", slot_player_selected_item_indices_begin, slot_player_selected_item_indices_end),
  14211. (player_get_slot, ":selected_item_index", ":player_no", ":i_item"),
  14212. (store_sub, ":i_cur_selected_item", ":i_item", slot_player_selected_item_indices_begin),
  14213. (try_begin),
  14214. (player_item_slot_is_picked_up, ":player_no", ":i_cur_selected_item"),
  14215. (assign, ":selected_item_index", -1),
  14216. (try_end),
  14217. (val_add, ":i_cur_selected_item", slot_player_cur_selected_item_indices_begin),
  14218. (player_set_slot, ":player_no", ":i_cur_selected_item", ":selected_item_index"),
  14219. (try_end),
  14220. (assign, ":end_cond", 1000),
  14221. (try_for_range, ":unused", 0, ":end_cond"),
  14222. (call_script, "script_multiplayer_calculate_cur_selected_items_cost", ":player_no", 0),
  14223. (assign, ":total_cost", reg0),
  14224. (try_begin),
  14225. (gt, ":total_cost", ":player_gold"),
  14226. #downgrade one of the selected items
  14227. #first normalize the prices
  14228. #then prioritize some of the weapon classes for specific troop classes
  14229. (call_script, "script_multiplayer_get_troop_class", ":player_troop"),
  14230. (assign, ":player_troop_class", reg0),
  14231.  
  14232. (assign, ":max_cost_value", 0),
  14233. (assign, ":max_cost_value_index", -1),
  14234. (try_for_range, ":i_item", slot_player_cur_selected_item_indices_begin, slot_player_cur_selected_item_indices_end),
  14235. (player_get_slot, ":item_id", ":player_no", ":i_item"),
  14236. (ge, ":item_id", 0), #might be -1 for horses etc.
  14237. (call_script, "script_multiplayer_get_item_value_for_troop", ":item_id", ":player_troop"),
  14238. (assign, ":item_value", reg0),
  14239. (store_sub, ":item_type", ":i_item", slot_player_cur_selected_item_indices_begin),
  14240. (try_begin), #items
  14241. (this_or_next|eq, ":item_type", 0),
  14242. (this_or_next|eq, ":item_type", 1),
  14243. (this_or_next|eq, ":item_type", 2),
  14244. (eq, ":item_type", 3),
  14245. (val_mul, ":item_value", 5),
  14246. (else_try), #head
  14247. (eq, ":item_type", 4),
  14248. (val_mul, ":item_value", 4),
  14249. (else_try), #body
  14250. (eq, ":item_type", 5),
  14251. (val_mul, ":item_value", 2),
  14252. (else_try), #foot
  14253. (eq, ":item_type", 6),
  14254. (val_mul, ":item_value", 8),
  14255. (else_try), #gloves
  14256. (eq, ":item_type", 7),
  14257. (val_mul, ":item_value", 8),
  14258. (else_try), #horse
  14259. #base value (most expensive)
  14260. (try_end),
  14261. (item_get_slot, ":item_class", ":item_id", slot_item_multiplayer_item_class),
  14262. (try_begin),
  14263. (eq, ":player_troop_class", multi_troop_class_infantry),
  14264. (this_or_next|eq, ":item_class", multi_item_class_type_sword),
  14265. (this_or_next|eq, ":item_class", multi_item_class_type_axe),
  14266. (this_or_next|eq, ":item_class", multi_item_class_type_blunt),
  14267. (this_or_next|eq, ":item_class", multi_item_class_type_war_picks),
  14268. (this_or_next|eq, ":item_class", multi_item_class_type_two_handed_sword),
  14269. (this_or_next|eq, ":item_class", multi_item_class_type_small_shield),
  14270. (eq, ":item_class", multi_item_class_type_two_handed_axe),
  14271. (val_div, ":item_value", 2),
  14272. (else_try),
  14273. (eq, ":player_troop_class", multi_troop_class_spearman),
  14274. (this_or_next|eq, ":item_class", multi_item_class_type_spear),
  14275. (eq, ":item_class", multi_item_class_type_large_shield),
  14276. (val_div, ":item_value", 2),
  14277. (else_try),
  14278. (eq, ":player_troop_class", multi_troop_class_cavalry),
  14279. (this_or_next|eq, ":item_class", multi_item_class_type_lance),
  14280. (this_or_next|eq, ":item_class", multi_item_class_type_sword),
  14281. (eq, ":item_class", multi_item_class_type_horse),
  14282. (val_div, ":item_value", 2),
  14283. (else_try),
  14284. (eq, ":player_troop_class", multi_troop_class_archer),
  14285. (this_or_next|eq, ":item_class", multi_item_class_type_bow),
  14286. (eq, ":item_class", multi_item_class_type_arrow),
  14287. (val_div, ":item_value", 2),
  14288. (else_try),
  14289. (eq, ":player_troop_class", multi_troop_class_crossbowman),
  14290. (this_or_next|eq, ":item_class", multi_item_class_type_crossbow),
  14291. (eq, ":item_class", multi_item_class_type_bolt),
  14292. (val_div, ":item_value", 2),
  14293. (else_try),
  14294. (eq, ":player_troop_class", multi_troop_class_mounted_archer),
  14295. (this_or_next|eq, ":item_class", multi_item_class_type_bow),
  14296. (this_or_next|eq, ":item_class", multi_item_class_type_arrow),
  14297. (eq, ":item_class", multi_item_class_type_horse),
  14298. (val_div, ":item_value", 2),
  14299. (else_try),
  14300. (eq, ":player_troop_class", multi_troop_class_mounted_crossbowman),
  14301. (this_or_next|eq, ":item_class", multi_item_class_type_crossbow),
  14302. (this_or_next|eq, ":item_class", multi_item_class_type_bolt),
  14303. (eq, ":item_class", multi_item_class_type_horse),
  14304. (val_div, ":item_value", 2),
  14305. (try_end),
  14306.  
  14307. (try_begin),
  14308. (gt, ":item_value", ":max_cost_value"),
  14309. (assign, ":max_cost_value", ":item_value"),
  14310. (assign, ":max_cost_value_index", ":i_item"),
  14311. (try_end),
  14312. (try_end),
  14313.  
  14314. #max_cost_value and max_cost_value_index will definitely be valid
  14315. #unless no items are left (therefore some items must cost 0 gold)
  14316. (player_get_slot, ":item_id", ":player_no", ":max_cost_value_index"),
  14317. (call_script, "script_multiplayer_get_previous_item_for_item_and_troop", ":item_id", ":player_troop"),
  14318. (assign, ":item_id", reg0),
  14319. (player_set_slot, ":player_no", ":max_cost_value_index", ":item_id"),
  14320. (else_try),
  14321. (assign, ":end_cond", 0),
  14322. (val_sub, ":player_gold", ":total_cost"),
  14323. (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
  14324. (try_for_range, ":i_item", slot_player_cur_selected_item_indices_begin, slot_player_cur_selected_item_indices_end),
  14325. (player_get_slot, ":item_id", ":player_no", ":i_item"),
  14326. #checking if different class default item replace is needed for weapons
  14327. (try_begin),
  14328. (ge, ":item_id", 0),
  14329. #then do nothing
  14330. (else_try),
  14331. (store_sub, ":base_index_slot", ":i_item", slot_player_cur_selected_item_indices_begin),
  14332. (store_add, ":selected_item_index_slot", ":base_index_slot", slot_player_selected_item_indices_begin),
  14333. (player_get_slot, ":selected_item_index", ":player_no", ":selected_item_index_slot"),
  14334. (this_or_next|eq, ":selected_item_index", -1),
  14335. (player_item_slot_is_picked_up, ":player_no", ":base_index_slot"),
  14336. #then do nothing
  14337. (else_try),
  14338. #an item class without a default value is -1, then find a default weapon
  14339. (item_get_slot, ":item_class", ":selected_item_index", slot_item_multiplayer_item_class),
  14340. (is_between, ":item_class", multi_item_class_type_weapons_begin, multi_item_class_type_weapons_end),
  14341. (assign, ":dc_replaced_item", -1),
  14342. (try_for_range, ":i_dc_item_class", multi_item_class_type_melee_weapons_begin, multi_item_class_type_melee_weapons_end),
  14343. (lt, ":dc_replaced_item", 0),
  14344. (assign, ":dc_item_class_used", 0),
  14345. (try_for_range, ":i_dc_item", slot_player_cur_selected_item_indices_begin, slot_player_cur_selected_item_indices_end),
  14346. (player_get_slot, ":dc_cur_item", ":player_no", ":i_dc_item"),
  14347. (ge, ":dc_cur_item", 0),
  14348. (item_get_slot, ":dc_item_class", ":dc_cur_item", slot_item_multiplayer_item_class),
  14349. (eq, ":dc_item_class", ":i_dc_item_class"),
  14350. (assign, ":dc_item_class_used", 1),
  14351. (try_end),
  14352. (eq, ":dc_item_class_used", 0),
  14353. (assign, ":dc_end_cond", all_items_end),
  14354. (try_for_range, ":i_dc_new_item", all_items_begin, ":dc_end_cond"),
  14355. (item_slot_eq, ":i_dc_new_item", slot_item_multiplayer_item_class, ":i_dc_item_class"),
  14356. (call_script, "script_cf_multiplayer_is_item_default_for_troop", ":i_dc_new_item", ":player_troop"),
  14357. (assign, ":dc_end_cond", 0), #break
  14358. (assign, ":dc_replaced_item", ":i_dc_new_item"),
  14359. (try_end),
  14360. (try_end),
  14361. (ge, ":dc_replaced_item", 0),
  14362. (player_set_slot, ":player_no", ":i_item", ":dc_replaced_item"),
  14363. (assign, ":item_id", ":dc_replaced_item"),
  14364. (try_end),
  14365.  
  14366. #finally, add the item to agent
  14367. (try_begin),
  14368. (ge, ":item_id", 0), #might be -1 for horses etc.
  14369. (store_sub, ":item_slot", ":i_item", slot_player_cur_selected_item_indices_begin),
  14370. (player_add_spawn_item, ":player_no", ":item_slot", ":item_id"),
  14371. (try_begin),
  14372. (eq, ":item_slot", ek_body), #ek_body is the slot for armor
  14373. (assign, ":armor_bought", 1),
  14374. (try_end),
  14375. (try_end),
  14376. (try_end),
  14377.  
  14378. (player_set_slot, ":player_no", slot_player_total_equipment_value, ":total_cost"),
  14379. (try_end),
  14380. (try_end),
  14381. (try_begin),
  14382. (eq, ":armor_bought", 0),
  14383. (eq, "$g_multiplayer_force_default_armor", 1),
  14384. (assign, ":end_cond", all_items_end),
  14385. (try_for_range, ":i_new_item", all_items_begin, ":end_cond"),
  14386. (this_or_next|item_slot_eq, ":i_new_item", slot_item_multiplayer_item_class, multi_item_class_type_light_armor),
  14387. (this_or_next|item_slot_eq, ":i_new_item", slot_item_multiplayer_item_class, multi_item_class_type_medium_armor),
  14388. (item_slot_eq, ":i_new_item", slot_item_multiplayer_item_class, multi_item_class_type_heavy_armor),
  14389. (call_script, "script_cf_multiplayer_is_item_default_for_troop", ":i_new_item", ":player_troop"),
  14390. (assign, ":end_cond", 0), #break
  14391. (player_add_spawn_item, ":player_no", ek_body, ":i_new_item"), #ek_body is the slot for armor
  14392. (try_end),
  14393. (try_end),
  14394. ]),
  14395.  
  14396. # script_party_get_ideal_size @used for NPC parties.
  14397. # Input: arg1 = party_no
  14398. # Output: reg0: ideal size
  14399. ("party_get_ideal_size",
  14400. [
  14401. (store_script_param_1, ":party_no"),
  14402.  
  14403. #default limit is 30 for any party
  14404. (assign, ":limit", 30),
  14405.  
  14406. (try_begin),
  14407. (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_hero_party),
  14408. (party_stack_get_troop_id, ":party_leader", ":party_no", 0),
  14409. (store_faction_of_party, ":faction_id", ":party_no"),
  14410.  
  14411. #default limit is 10 for kingdom lords
  14412. (assign, ":limit", 10),
  14413.  
  14414. #each (leadership level) gives 5 to limit
  14415. (store_skill_level, ":skill", "skl_leadership", ":party_leader"),
  14416. (store_attribute_level, ":charisma", ":party_leader", ca_charisma),
  14417. (val_mul, ":skill", 5),
  14418. (val_add, ":limit", ":skill"),
  14419.  
  14420. #each (charisma level) gives 1 to limit
  14421. (val_add, ":limit", ":charisma"),
  14422.  
  14423. #each (25 renown) gives 1 to limit
  14424. (troop_get_slot, ":troop_renown", ":party_leader", slot_troop_renown),
  14425. (store_div, ":renown_bonus", ":troop_renown", 25),
  14426. (val_add, ":limit", ":renown_bonus"),
  14427.  
  14428. ##diplomacy begin
  14429. (assign, ":percent", 100),
  14430. ##diplomacy end
  14431.  
  14432. ##diplomacy start+
  14433. #Limit effects of policies for nascent kingdoms.
  14434. (assign, ":policy_min", -3),
  14435. (assign, ":policy_max", 4),#one greater than the maximum
  14436.  
  14437. (try_begin),
  14438. (this_or_next|eq, ":faction_id", "fac_player_supporters_faction"),
  14439. (faction_slot_eq, ":faction_id", slot_faction_leader, "trp_player"),
  14440. (faction_get_slot, ":policy_max", ":faction_id", slot_faction_num_towns),
  14441. (faction_get_slot, reg0, ":faction_id", slot_faction_num_castles),
  14442. (val_add, ":policy_max", reg0),
  14443. (val_clamp, ":policy_max", 0, 4),#0, 1, 2, 3
  14444. (store_mul, ":policy_min", ":policy_max", -1),
  14445. (val_add, ":policy_max", 1),#one greater than the maximum
  14446. (try_end),
  14447. ##diplomacy end+
  14448.  
  14449. (try_begin),
  14450. (faction_slot_eq, ":faction_id", slot_faction_leader, ":party_leader"),
  14451. (val_add, ":limit", dplmc_monarch_party_bonus),
  14452. ##diplomacy begin
  14453. (try_begin),
  14454. (faction_get_slot, ":centralization", ":faction_id", dplmc_slot_faction_centralization),
  14455. (neq, ":centralization", 0),
  14456. ##diplomacy start+ Apply constraint
  14457. (val_clamp, ":centralization", ":policy_min", ":policy_max"),
  14458. ##diplomacy end+
  14459. (val_mul, ":centralization", 10),
  14460. (val_add, ":percent", ":centralization"),
  14461. (try_end),
  14462.  
  14463. (else_try),
  14464. (try_begin),
  14465. (faction_get_slot, ":centralization", ":faction_id", dplmc_slot_faction_centralization),
  14466. (neq, ":centralization", 0),
  14467. ##diplomacy start+ Apply constraint
  14468. (val_clamp, ":centralization", ":policy_min", ":policy_max"),
  14469. ##diplomacy end+
  14470. (val_mul, ":centralization", -3),
  14471. (val_add, ":percent", ":centralization"),
  14472. (try_end),
  14473. (try_begin),
  14474. (faction_get_slot, ":aristocraty", ":faction_id", dplmc_slot_faction_aristocracy),
  14475. (neq, ":aristocraty", 0),
  14476. ##diplomacy start+ Apply constraint
  14477. (val_clamp, ":aristocraty", ":policy_min", ":policy_max"),
  14478. ##diplomacy end+
  14479. (val_mul, ":aristocraty", 3),
  14480. (val_add, ":percent", ":aristocraty"),
  14481. (try_end),
  14482. (try_begin),
  14483. (faction_get_slot, ":quality", ":faction_id", dplmc_slot_faction_quality),
  14484. (neq, ":quality", 0),
  14485. ##diplomacy start+ Apply constraint
  14486. (val_clamp, ":quality", ":policy_min", ":policy_max"),
  14487. ##diplomacy end+
  14488. (val_mul, ":quality", -4),
  14489. (val_add, ":percent", ":quality"),
  14490. (try_end),
  14491. ##diplomacy end
  14492. (try_end),
  14493.  
  14494. ##diplomacy begin
  14495. (try_begin),
  14496. (faction_get_slot, ":serfdom", ":faction_id", dplmc_slot_faction_serfdom),
  14497. (neq, ":serfdom", 0),
  14498. ##diplomacy start+ Apply constraint
  14499. (val_clamp, ":serfdom", ":policy_min", ":policy_max"),
  14500. ##diplomacy end+
  14501. (val_mul, ":serfdom", 2), #SB : description says 1, this used to be 3
  14502. (val_add, ":percent", ":serfdom"),
  14503. (try_end),
  14504.  
  14505. (val_mul, ":limit", ":percent"),
  14506. ##nested diplomacy start+ Round correctly
  14507. (val_add, ":limit", 50),
  14508. ##nested diplomacy end+
  14509. (val_div, ":limit", 100),
  14510. ##diplomacy end
  14511.  
  14512. (try_begin),
  14513. (faction_slot_eq, ":faction_id", slot_faction_marshall, ":party_leader"),
  14514. (val_add, ":limit", dplmc_marshal_party_bonus),
  14515. (try_end),
  14516.  
  14517. #party takes additional 20 limit per each castle its party leader owns
  14518. (try_for_range, ":cur_center", castles_begin, castles_end),
  14519. (party_slot_eq, ":cur_center", slot_town_lord, ":party_leader"),
  14520. (val_add, ":limit", dplmc_castle_party_bonus),
  14521. (try_end),
  14522. ##diplomacy start+
  14523. ##Extend this script so it will also work with garrisons
  14524. (else_try),
  14525. (party_slot_eq, ":party_no", slot_party_type, spt_town),
  14526. (assign, ":limit", 380),#average starting town garrison size
  14527. (else_try),
  14528. (this_or_next|is_between, ":party_no", walled_centers_begin, walled_centers_end),
  14529. (party_slot_eq, ":party_no", slot_party_type, spt_castle),
  14530. (assign, ":limit", 142),#average starting castle garrison size
  14531. #(store_faction_of_party, ":faction_id", ":party_no"),
  14532. ##diplomacy end+
  14533. (try_end),
  14534.  
  14535. #if player has level of 0 then ideal limit will be exactly same, if player has level of 80 then ideal limit will be multiplied by 2 ((80 + 80) / 80)
  14536. #below code will increase limits a little as the game progresses and player gains level
  14537. (store_character_level, ":level", "trp_player"),
  14538. (val_min, ":level", 80),
  14539. (store_add, ":level_factor", 80, ":level"),
  14540. (val_mul, ":limit", ":level_factor"),
  14541. (val_div, ":limit", 80),
  14542. (assign, reg0, ":limit"),
  14543. ]),
  14544.  
  14545.  
  14546. #script_game_get_party_prisoner_limit:
  14547. # This script is called from the game engine when the prisoner limit is needed for a party.
  14548. # INPUT: arg1 = party_no
  14549. # OUTPUT: reg0 = prisoner_limit
  14550. ("game_get_party_prisoner_limit",
  14551. [
  14552. # (store_script_param_1, ":party_no"),
  14553. (assign, ":troop_no", "trp_player"),
  14554.  
  14555. (assign, ":limit", 0),
  14556. (store_skill_level, ":skill", "skl_prisoner_management", ":troop_no"),
  14557. (store_mul, ":limit", ":skill", 5),
  14558. (try_begin), #SB : override with diplomacy_var2
  14559. (eq, "$diplomacy_var", DPLMC_CURRENT_VERSION_CODE),
  14560. (assign, ":limit", "$diplomacy_var2"),
  14561. (try_end),
  14562. (assign, reg0, ":limit"),
  14563. (set_trigger_result, reg0),
  14564. ]),
  14565.  
  14566. #script_game_get_item_extra_text:
  14567. # This script is called from the game engine when an item's properties are displayed.
  14568. # INPUT: arg1 = item_no, arg2 = extra_text_id (this can be between 0-7 (7 included)), arg3 = item_modifier
  14569. # OUTPUT: result_string = item extra text, trigger_result = text color (0 for default)
  14570. ("game_get_item_extra_text",
  14571. [
  14572. (store_script_param, ":item_no", 1),
  14573. (store_script_param, ":extra_text_id", 2),
  14574. (store_script_param, ":item_modifier", 3),
  14575. (try_begin),
  14576. (is_between, ":item_no", food_begin, food_end),
  14577. (try_begin),
  14578. (eq, ":extra_text_id", 0),
  14579. (assign, ":continue", 1),
  14580. (try_begin),
  14581. (this_or_next|eq, ":item_no", "itm_cattle_meat"),
  14582. (this_or_next|eq, ":item_no", "itm_pork"),
  14583. (eq, ":item_no", "itm_chicken"),
  14584.  
  14585. (eq, ":item_modifier", imod_rotten),
  14586. (assign, ":continue", 0),
  14587. (try_end),
  14588. (eq, ":continue", 1),
  14589. (item_get_slot, ":food_bonus", ":item_no", slot_item_food_bonus),
  14590. (assign, reg1, ":food_bonus"),
  14591. (set_result_string, "@+{reg1} to party morale"),
  14592. (set_trigger_result, 0x4444FF),
  14593. (else_try),
  14594. (eq, ":extra_text_id", 1),
  14595. (assign, ":quest_no", -1), #no quest selected
  14596. (try_begin),
  14597. (check_quest_active, "qst_deliver_wine"),
  14598. (quest_slot_eq, "qst_deliver_wine", slot_quest_target_item, ":item_no"),
  14599. (assign, ":quest_no", "qst_deliver_wine"),
  14600. (quest_get_slot, ":quest_target_center", ":quest_no", slot_quest_target_center),
  14601. (try_end),
  14602.  
  14603. (try_begin), #prioritize town missions
  14604. (eq, ":quest_no", -1),
  14605. (check_quest_active, "qst_deliver_grain"),
  14606. (quest_slot_eq, "qst_deliver_grain", slot_quest_target_item, ":item_no"),
  14607. (assign, ":quest_no", "qst_deliver_grain"),
  14608. (quest_get_slot, ":quest_target_center", ":quest_no", slot_quest_giver_center),
  14609. (try_end),
  14610. (neq, ":item_modifier", imod_rotten),
  14611. (neq, ":quest_no", -1),
  14612. (quest_get_slot, reg5, ":quest_no", slot_quest_target_amount),
  14613. #probably do a x/n items counter here or something
  14614. (str_store_party_name, s5, ":quest_target_center"),
  14615. (set_result_string, "@Deliver {reg5} units to {s5}"),
  14616. (set_trigger_result, message_alert),
  14617. (try_end),
  14618. (else_try),
  14619. (is_between, ":item_no", readable_books_begin, readable_books_end),
  14620. (try_begin),
  14621. (eq, ":extra_text_id", 0),
  14622. (item_get_slot, reg1, ":item_no", slot_item_intelligence_requirement),
  14623. (set_result_string, "@Requires {reg1} intelligence to read"),
  14624. (set_trigger_result, 0xFFEEDD),
  14625. (else_try),
  14626. (eq, ":extra_text_id", 1),
  14627. (item_get_slot, ":progress", ":item_no", slot_item_book_reading_progress),
  14628. (val_div, ":progress", 10),
  14629. (assign, reg1, ":progress"),
  14630. (set_result_string, "@Reading Progress: {reg1}%"),
  14631. (set_trigger_result, 0xFFEEDD),
  14632. (try_end),
  14633. (else_try),
  14634. (is_between, ":item_no", reference_books_begin, reference_books_end),
  14635. (try_begin),
  14636. (eq, ":extra_text_id", 0),
  14637. (try_begin),
  14638. (eq, ":item_no", "itm_book_wound_treatment_reference"),
  14639. (str_store_string, s1, "@wound treament"),
  14640. (else_try),
  14641. (eq, ":item_no", "itm_book_training_reference"),
  14642. (str_store_string, s1, "@trainer"),
  14643. (else_try),
  14644. (eq, ":item_no", "itm_book_surgery_reference"),
  14645. (str_store_string, s1, "@surgery"),
  14646. (try_end),
  14647. (set_result_string, "@+1 to {s1} while in inventory"),
  14648. (set_trigger_result, 0xFFEEDD),
  14649. (try_end),
  14650. (else_try),
  14651.  
  14652. # sb : debug
  14653. (try_begin),
  14654. (ge, "$cheat_mode", 1),
  14655. (eq, ":extra_text_id", 4),
  14656. (call_script, "script_dplmc_get_item_value_with_imod", ":item_no", ":item_modifier"),
  14657. (assign, ":value", reg0),
  14658. (call_script, "script_dplmc_get_item_score_with_imod", ":item_no", ":item_modifier"),
  14659. (store_div, reg1, ":value", 100),
  14660. (set_result_string, "@item score:{reg0}, value:{reg1}"),
  14661. (set_trigger_result, 0x0DDEEE),
  14662. (try_end),
  14663.  
  14664. (try_begin), #SB : display this block when in item pool mode
  14665. (eq, ":extra_text_id", 2),
  14666. (eq, "$pool_troop", "trp_temp_troop"), #new exit code resets condition
  14667. (this_or_next|eq, "$lord_selected", "trp_player"),
  14668. (is_between, "$lord_selected", companions_begin, companions_end),
  14669. (call_script, "script_item_get_type_aux", ":item_no"),
  14670. (assign, ":meta_type", reg0),
  14671. (gt, ":meta_type", meta_itp_mask), #has a valid meta-type
  14672. (assign, ":string", "str_empty_string"),
  14673. (try_begin), #doesn't need it, Native item type already shows
  14674. # (eq, ":meta_type", dplmc_itp_morningstar),
  14675. # (assign, ":string", "str_dplmc_hero_wpn_slot_two_handed_one_handed"),
  14676. # (else_try),
  14677. (eq, ":meta_type", dplmc_itp_lance),
  14678. (assign, ":string", "str_dplmc_hero_wpn_slot_lance"),
  14679. (else_try),
  14680. (eq, ":meta_type", dplmc_itp_pike),
  14681. (assign, ":string", "str_dplmc_hero_wpn_slot_pikes"),
  14682. (else_try),
  14683. (eq, ":meta_type", dplmc_itp_halberd),
  14684. (assign, ":string", "str_dplmc_hero_wpn_slot_halberd"),
  14685. (try_end),
  14686. (gt, ":string", "str_empty_string"), #could use directly
  14687. (set_result_string, ":string"),
  14688. (set_trigger_result, 0xDDEEFF),
  14689. (try_end),
  14690. (try_end),
  14691.  
  14692. ]),
  14693.  
  14694. #script_game_on_disembark:
  14695. # This script is called from the game engine when the player reaches the shore with a ship.
  14696. # INPUT: pos0 = disembark position
  14697. # OUTPUT: none
  14698. ("game_on_disembark",
  14699. [(jump_to_menu, "mnu_disembark"),
  14700. ]),
  14701.  
  14702.  
  14703. #script_game_context_menu_get_buttons:
  14704. # This script is called from the game engine when the player clicks the right mouse button over a party on the map.
  14705. # INPUT: arg1 = party_no
  14706. # OUTPUT: none, fills the menu buttons
  14707. ("game_context_menu_get_buttons",
  14708. [
  14709. (store_script_param, ":party_no", 1),
  14710. (try_begin),
  14711. (neq, ":party_no", "p_main_party"),
  14712. (context_menu_add_item, "@Move here", cmenu_move),
  14713. (try_end),
  14714.  
  14715. (try_begin),
  14716. (is_between, ":party_no", centers_begin, centers_end),
  14717. (context_menu_add_item, "@View notes", cmenu_notes),
  14718. (else_try),
  14719. (party_get_num_companion_stacks, ":num_stacks", ":party_no"),
  14720. (gt, ":num_stacks", 0),
  14721. (party_stack_get_troop_id, ":troop_no", ":party_no", 0),
  14722. ##diplomacy start+ support for promoted kingdom ladies
  14723. (is_between, ":troop_no", heroes_begin, heroes_end),
  14724. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  14725. ##diplomacy end+
  14726. (is_between, ":troop_no", active_npcs_begin, active_npcs_end),
  14727. (context_menu_add_item, "@View notes", cmenu_notes), #move this to same slot
  14728. (try_end),
  14729.  
  14730. (try_begin),
  14731. (neq, ":party_no", "p_main_party"),
  14732. (store_faction_of_party, ":party_faction", ":party_no"),
  14733.  
  14734. (this_or_next|eq, ":party_faction", "$players_kingdom"),
  14735. (this_or_next|eq, ":party_faction", "fac_player_supporters_faction"),
  14736. (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_caravan),
  14737.  
  14738. (neg|is_between, ":party_no", centers_begin, centers_end),
  14739.  
  14740. (context_menu_add_item, "@Accompany", cmenu_follow),
  14741. (try_end),
  14742.  
  14743. #SB : debug cheats
  14744. (try_begin),
  14745. (ge, "$cheat_mode", 1),
  14746. (try_begin),
  14747. (neq, ":party_no", "p_main_party"),
  14748. (context_menu_add_item, "@Attach", cmenu_attach),
  14749. # (context_menu_add_item, "@Reinforce", cmenu_reinforce),
  14750. (context_menu_add_item, "@Inspect", cmenu_encounter),
  14751. # (context_menu_add_item, "@Exchange", cmenu_exchange),
  14752. (try_end),
  14753. (try_begin),
  14754. (party_get_num_attached_parties, ":num_attached", ":party_no"),
  14755. (gt, ":num_attached", 0),
  14756. (try_begin),
  14757. (eq, ":party_no", "p_main_party"),
  14758. (party_get_attached_party_with_rank, ":attached_party", "p_main_party", 0),
  14759. (str_store_party_name, s1, ":attached_party"),
  14760. (set_fixed_point_multiplier, 1000),
  14761. (party_get_position, pos1, ":party_no"),
  14762. (position_get_x, reg1, pos1),
  14763. (position_get_y, reg2, pos1),
  14764. (context_menu_add_item, "@Detach {s1} at {reg1},{reg2}", cmenu_attach),
  14765. (try_end),
  14766. (context_menu_add_item, "@Detach All", cmenu_detach),
  14767. (try_end),
  14768.  
  14769. (try_begin),
  14770. (party_get_battle_opponent, ":other_party", ":party_no"),
  14771. (party_is_active, ":other_party"),
  14772. (context_menu_add_item, "@Win Battle", cmenu_winbattle),
  14773. (context_menu_add_item, "@Lose Battle", cmenu_losebattle),
  14774. # (else_try),
  14775. # (context_menu_add_item, "@Wound All", cmenu_wound),
  14776. # (context_menu_add_item, "@Heal All", cmenu_heal),
  14777. (try_end),
  14778.  
  14779. # (try_begin),
  14780. # (is_between, ":party_no", centers_begin, centers_end),
  14781. # (context_menu_add_item, "@Spawn Bandits", cmenu_spawnbandit),
  14782. # (try_end),
  14783. (try_end),
  14784. ]),
  14785.  
  14786. #script_game_event_context_menu_button_clicked:
  14787. # This script is called from the game engine when the player clicks on a button at the right mouse menu.
  14788. # INPUT: arg1 = party_no, arg2 = button_value
  14789. # OUTPUT: none
  14790. ("game_event_context_menu_button_clicked",
  14791. [(store_script_param, ":party_no", 1),
  14792. (store_script_param, ":button_value", 2),
  14793. (try_begin),
  14794. (eq, ":button_value", cmenu_notes),
  14795. #SB : unify this under a single constant
  14796. (try_begin),
  14797. (is_between, ":party_no", centers_begin, centers_end),
  14798. (change_screen_notes, 3, ":party_no"),
  14799. (else_try),
  14800. (party_stack_get_troop_id, ":troop_no", ":party_no", 0),
  14801. (change_screen_notes, 1, ":troop_no"),
  14802. (try_end),
  14803. (else_try), #SB : lots of cheats
  14804. (eq, ":button_value", cmenu_attach),
  14805. (try_begin),
  14806. (neq, ":party_no", "p_main_party"),
  14807. (party_set_next_battle_simulation_time, ":party_no", -1),
  14808. (party_leave_cur_battle, ":party_no"),
  14809. (party_set_flags, ":party_no", pf_is_static, 0),
  14810. (party_attach_to_party, ":party_no", "p_main_party"),
  14811. (else_try),
  14812. (party_get_attached_party_with_rank, ":attached_party", "p_main_party", 0),
  14813. (party_get_position, pos1, "p_main_party"),
  14814. (party_detach, ":attached_party"),
  14815. (party_set_position, ":attached_party", pos1),
  14816. (try_begin),
  14817. (is_between, ":attached_party", centers_begin, centers_end),
  14818. (party_set_flags, ":attached_party", pf_is_static, 1),
  14819. (try_end),
  14820. (try_end),
  14821. (else_try),
  14822. (eq, ":button_value", cmenu_detach),
  14823. (party_get_num_attached_parties, ":num_stacks", ":party_no"),
  14824. (try_for_range_backwards, ":stacks", 0, ":num_stacks"),
  14825. (party_get_attached_party_with_rank, ":attached_party", ":party_no", ":stacks"),
  14826. (party_detach, ":attached_party"),
  14827. (party_set_ai_behavior, ":attached_party", ai_bhvr_hold),
  14828. (party_set_flags, ":attached_party", pf_default_behavior, 1),
  14829. (party_relocate_near_party, ":attached_party", ":party_no", 3),
  14830. (try_begin),
  14831. (is_between, ":attached_party", centers_begin, centers_end),
  14832. (party_set_flags, ":attached_party", pf_is_static, 1),
  14833. (try_end),
  14834. (try_end),
  14835. (else_try),
  14836. (eq, ":button_value", cmenu_encounter),
  14837. (assign, "$new_encounter", 2), #this lets us branch to a different menu
  14838. (start_encounter, ":party_no"),
  14839. # (set_encountered_party, ":party_no"),
  14840. # (assign, "$g_encountered_party", ":party_no"),
  14841. # (change_screen_exchange_with_party, ":party_no"),
  14842. # (jump_to_menu, "mnu_auto_return"),
  14843. # (else_try),
  14844. # (eq, ":button_value", cmenu_encounter),
  14845. # (start_encounter, ":party_no"),
  14846. # (else_try),
  14847. # (eq, ":button_value", cmenu_spawnbandit),
  14848. # (set_spawn_radius, 25),
  14849. # (try_for_range, ":unused", 0, 10),
  14850. # (store_random_in_range, ":party_template", bandit_party_templates_begin, bandit_party_templates_end),
  14851. # (spawn_around_party, ":party_no", ":party_template"),
  14852. # (try_end),
  14853. #(call_script, "script_update_bandit_pressure"),
  14854. (else_try), #too lazy to invoke magical commands, screw around with composition
  14855. (eq, ":button_value", cmenu_losebattle),
  14856. (call_script, "script_party_wound_all_members", ":party_no"),
  14857. (party_set_next_battle_simulation_time, ":party_no", -1),
  14858. (else_try), #winning is half the battle
  14859. (eq, ":button_value", cmenu_winbattle),
  14860. (party_get_battle_opponent, ":other_party", ":party_no"),
  14861. (call_script, "script_party_wound_all_members", ":other_party"),
  14862. (party_set_next_battle_simulation_time, ":party_no", 0),
  14863. ## Moved the following to a menu instead
  14864. # (else_try), #refill or double-up
  14865. # (eq, ":button_value", cmenu_reinforce),
  14866. # (store_faction_of_party, ":faction_no", ":party_no"),
  14867. # (try_begin), #
  14868. # (is_between, ":party_no", villages_begin, villages_end),
  14869. # (party_add_template, ":party_no", "pt_village_defenders"),
  14870. # (else_try),
  14871. # (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  14872. # (call_script, "script_cf_reinforce_party", ":party_no"),
  14873. # (else_try),
  14874. # (eq, ":faction_no", "fac_deserters"),
  14875. # (party_stack_get_troop_id, ":troop_id", ":party_no", 0),
  14876. # (store_faction_of_troop, ":faction_no", ":troop_id"),
  14877. # (store_random_in_range, ":slot_no", slot_faction_reinforcements_a, slot_faction_num_armies),
  14878. # (faction_get_slot, ":party_template", ":faction_no", ":slot_no"),
  14879. # (party_add_template, ":party_no", ":party_template"),
  14880. # (else_try),
  14881. # # (this_or_next|eq, ":faction_no", "fac_outlaws"),
  14882. # # (is_between, ":faction_no", bandit_factions_begin, bandit_factions_end),
  14883. # (party_get_template_id, ":party_template", ":party_no"),
  14884. # (party_add_template, ":party_no", ":party_template"),
  14885. # (try_end),
  14886. # (else_try),
  14887. # (eq, ":button_value", cmenu_wound),
  14888. # (call_script, "script_party_wound_all_members", ":party_no"),
  14889. # (else_try),
  14890. # (eq, ":button_value", cmenu_heal),
  14891. # # (heal_party, ":party_no"), #this does NOT work, any calls will only affect the main party
  14892. # (try_begin),
  14893. # (eq, ":party_no", "p_main_party"),
  14894. # (heal_party, "p_main_party"),
  14895. # (else_try),
  14896. # (call_script, "script_party_heal_all_members_aux", ":party_no"),
  14897. # (try_end),
  14898. (try_end),
  14899. ]),
  14900.  
  14901. #script_game_get_skill_modifier_for_troop
  14902. # This script is called from the game engine when a skill's modifiers are needed
  14903. # INPUT: arg1 = troop_no, arg2 = skill_no
  14904. # OUTPUT: trigger_result = modifier_value
  14905. ("game_get_skill_modifier_for_troop",
  14906. [(store_script_param, ":troop_no", 1),
  14907. (store_script_param, ":skill_no", 2),
  14908. (assign, ":modifier_value", 0),
  14909. (try_begin),
  14910. (eq, ":skill_no", "skl_wound_treatment"),
  14911. (call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_wound_treatment_reference"),
  14912. (gt, reg0, 0),
  14913. (val_add, ":modifier_value", 1),
  14914. (else_try),
  14915. (eq, ":skill_no", "skl_trainer"),
  14916. (call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_training_reference"),
  14917. (gt, reg0, 0),
  14918. (val_add, ":modifier_value", 1),
  14919. (else_try),
  14920. (eq, ":skill_no", "skl_surgery"),
  14921. (call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_surgery_reference"),
  14922. (gt, reg0, 0),
  14923. (val_add, ":modifier_value", 1),
  14924. (try_end),
  14925. (set_trigger_result, ":modifier_value"),
  14926. ]),
  14927.  
  14928. # Note to modders: Uncomment these if you'd like to use the following.
  14929.  
  14930. ## #script_game_check_party_sees_party
  14931. ## # This script is called from the game engine when a party is inside the range of another party
  14932. ## # INPUT: arg1 = party_no_seer, arg2 = party_no_seen
  14933. ## # OUTPUT: trigger_result = true or false (1 = true, 0 = false)
  14934. ## ("game_check_party_sees_party",
  14935. ## [
  14936. ## (store_script_param, ":party_no_seer", 1),
  14937. ## (store_script_param, ":party_no_seen", 2),
  14938. ## (set_trigger_result, 1),
  14939. ## ]),
  14940. ##
  14941.  
  14942. ##diplomacy start+
  14943. #Enable script_game_check_party_sees_party to prevent compassionate lords from
  14944. #attacking villagers and merchant caravans.
  14945.  
  14946. #script_game_check_party_sees_party
  14947. # This script is called from the game engine when a party is inside the range of another party
  14948. # INPUT: arg1 = party_no_seer, arg2 = party_no_seen
  14949. # OUTPUT: trigger_result = true or false (1 = true, 0 = false)
  14950. ("game_check_party_sees_party",
  14951. [
  14952. (store_script_param_1, ":party_no_seer"),
  14953. (store_script_param_2, ":party_no_seen"),
  14954.  
  14955. (assign, ":trigger_result", 1),
  14956. (assign, ":save_reg0", reg0),
  14957.  
  14958. #Lords who dislike raiding caravans should not attack village_farmer or kingdom_caravan
  14959. #parties. Achieve this by stopping them from seeing them.
  14960. (try_begin),
  14961. (gt, ":party_no_seer", spawn_points_end),
  14962. (gt, ":party_no_seen", spawn_points_end),
  14963.  
  14964. #Only apply this when the "seer" is a kingdom hero party
  14965. (party_slot_eq, ":party_no_seer", slot_party_type, spt_kingdom_hero_party),
  14966.  
  14967. #Only needed if the seen party is of a hostile faction
  14968. (call_script, "script_get_relation_between_parties", ":party_no_seer", ":party_no_seen"),
  14969. (lt, reg0, 0),
  14970.  
  14971. #Only apply this when the seen party is a merchant caravan or villagers
  14972. #(party_get_template_id, ":template", ":party_no_seen"),
  14973. (this_or_next|party_slot_eq, ":party_no_seen", slot_party_type, spt_kingdom_caravan),
  14974. (this_or_next|party_slot_eq,":party_no_seen", slot_party_type, dplmc_spt_gift_caravan),#custom diplomacy caravan
  14975. (party_slot_eq, ":party_no_seen", slot_party_type, spt_village_farmer),
  14976.  
  14977. #Never apply this when the seen party is engaging in hostile actions
  14978. (party_get_battle_opponent, reg0, ":party_no_seen"),
  14979. (lt, reg0, 0),
  14980. (neg|party_slot_eq, ":party_no_seen", slot_party_ai_state, spai_besieging_center),
  14981. (neg|party_slot_eq, ":party_no_seen", slot_party_ai_state, spai_raiding_around_center),
  14982. (neg|party_slot_eq, ":party_no_seen", slot_party_ai_state, spai_engaging_army),
  14983. (neg|party_slot_eq, ":party_no_seen", slot_party_ai_state, spai_accompanying_army),
  14984. (neg|party_slot_eq, ":party_no_seen", slot_party_ai_state, spai_screening_army),
  14985.  
  14986.  
  14987. #Only apply this when the leader is tmt_humanitarian, lrep_benefactor, or lrep_moralist
  14988. (party_get_num_companion_stacks, ":num_stacks", ":party_no_seer"),
  14989. (ge, ":num_stacks", 1),
  14990. (party_stack_get_troop_id, ":leader", ":party_no_seer", 0),
  14991. (ge, ":leader", 1),
  14992. (troop_is_hero, ":leader"),
  14993. (call_script, "script_dplmc_get_troop_morality_value", ":leader", tmt_humanitarian),
  14994. (ge, reg0, 0),# (never apply for leaders who like raiding caravans and attacking villagers)
  14995. (this_or_next|ge, reg0, 1),
  14996. (this_or_next|troop_slot_eq, ":leader", slot_lord_reputation_type, lrep_benefactor),
  14997. (troop_slot_eq, ":leader", slot_lord_reputation_type, lrep_moralist),
  14998. (assign, ":trigger_result", 0),
  14999. (try_end),
  15000.  
  15001. (assign, reg0, ":save_reg0"),
  15002. (set_trigger_result, ":trigger_result"),
  15003. ]),
  15004. ##diplomacy end+
  15005.  
  15006. ## #script_game_check_party_sees_party
  15007. ## # This script is called from the game engine when a party is inside the range of another party
  15008. ## # INPUT: arg1 = party_no_seer, arg2 = party_no_seen
  15009. ## # OUTPUT: trigger_result = true or false (1 = true, 0 = false)
  15010. ## ("game_check_party_sees_party",
  15011. ## [
  15012. ## (store_script_param, ":party_no_seer", 1),
  15013. ## (store_script_param, ":party_no_seen", 2),
  15014. ## (set_trigger_result, 1),
  15015. ## ]),
  15016. ##diplomacy begin
  15017. #script_game_get_party_speed_multiplier
  15018. # This script is called from the game engine when a skill's modifiers are needed
  15019. # INPUT: arg1 = party_no
  15020. # OUTPUT: trigger_result = multiplier (scaled by 100, meaning that giving 100 as the trigger result does not change the party speed)
  15021. ("game_get_party_speed_multiplier",
  15022. [
  15023. (store_script_param_1, ":party_no"),
  15024.  
  15025. (assign,":speed_multiplier",100),
  15026.  
  15027. (try_begin),
  15028. (this_or_next|eq,":party_no","p_main_party"),
  15029. (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_hero_party),
  15030. (party_get_skill_level, ":pathfinding_skill", ":party_no", skl_pathfinding),
  15031. (val_mul,":pathfinding_skill",3),
  15032. (val_add,":speed_multiplier",":pathfinding_skill"),
  15033. (try_end),
  15034.  
  15035. (try_begin),
  15036. (eq,":party_no","p_main_party"),
  15037. (eq,"$g_move_fast", 1),
  15038. (val_mul,":speed_multiplier",2),
  15039. (try_end),
  15040.  
  15041. (val_max, ":speed_multiplier", 0),
  15042. (set_trigger_result, ":speed_multiplier"),
  15043. ]),
  15044. ##diplomacy end
  15045.  
  15046. # script_npc_get_troop_wage
  15047. # This script is called from module system to calculate troop wages for npc parties.
  15048. # Input:
  15049. # param1: troop_id
  15050. # Output: reg0: weekly wage
  15051.  
  15052. ("npc_get_troop_wage",
  15053. [
  15054. (store_script_param_1, ":troop_id"),
  15055. (assign,":wage", 0),
  15056. (try_begin),
  15057. (troop_is_hero, ":troop_id"),
  15058. (else_try),
  15059. (store_character_level, ":wage", ":troop_id"),
  15060. (val_mul, ":wage", ":wage"),
  15061. (val_add, ":wage", 50),
  15062. (val_div, ":wage", 30),
  15063. (troop_is_mounted, ":troop_id"),
  15064. (val_mul, ":wage", 5),
  15065. (val_div, ":wage", 4),
  15066. (try_end),
  15067. (assign, reg0, ":wage"),
  15068. ]),
  15069.  
  15070. #script_setup_talk_info
  15071. # INPUT: $g_talk_troop, $g_talk_troop_relation
  15072. ("setup_talk_info",
  15073. [
  15074. # ##diplomacy start+ Ensure $character_gender is set correctly (it should have been set during character creation)
  15075. # (try_begin),
  15076. # (call_script, "script_cf_dplmc_troop_is_female", "trp_player"),
  15077. # (assign, "$character_gender", tf_female),
  15078. # (else_try),
  15079. # (assign, "$character_gender", tf_male),
  15080. # (try_end),
  15081. # ##diplomacy end+
  15082. #SB : redo order
  15083. (talk_info_set_relation_bar, "$g_talk_troop_relation"),
  15084. (str_store_troop_name, s61, "$g_talk_troop"),
  15085. # (str_store_string, s61, "@{!} {s61}"),
  15086. (assign, reg1, "$g_talk_troop_relation"),
  15087. # (str_store_string, s62, "str_relation_reg1"),
  15088. (talk_info_set_line, 0, "@{!} {s61}"),
  15089. (talk_info_set_line, 1, "str_relation_reg1"),
  15090. (call_script, "script_describe_relation_to_s63", "$g_talk_troop_relation"),
  15091. (talk_info_set_line, 3, s63),
  15092. ]),
  15093.  
  15094. #NPC companion changes begin
  15095. #script_setup_talk_info_companions
  15096. ("setup_talk_info_companions",
  15097. [
  15098. ##diplomacy start+ Ensure $character_gender is set correctly (it should have been set during character creation)
  15099. (try_begin),
  15100. (call_script, "script_cf_dplmc_troop_is_female", "trp_player"),
  15101. (assign, "$character_gender", 1),
  15102. (else_try),
  15103. (assign, "$character_gender", 0),
  15104. (try_end),
  15105. ##diplomacy end+
  15106. (call_script, "script_dplmc_npc_morale", "$g_talk_troop", 1), #SB : number + bar string in s63
  15107. (assign, ":troop_morale", reg0),
  15108. (talk_info_set_relation_bar, ":troop_morale"),
  15109. (talk_info_set_line, 3, s63),
  15110.  
  15111. (str_store_troop_name, s61, "$g_talk_troop"),
  15112. (talk_info_set_line, 0, s61),
  15113. # (str_store_string, s61, "@{!} {s61}"),
  15114. (assign, reg1, ":troop_morale"),
  15115. (str_store_string, s62, "str_morale_reg1"),
  15116. (talk_info_set_line, 1, s62),
  15117. ]),
  15118. #NPC companion changes end
  15119.  
  15120. #script_update_party_creation_random_limits
  15121. # INPUT: none
  15122. ("update_party_creation_random_limits",
  15123. [
  15124. (store_character_level, ":player_level", "trp_player"),
  15125. (store_mul, ":upper_limit", ":player_level", 3),
  15126. (val_add, ":upper_limit", 25),
  15127. (val_min, ":upper_limit", 100),
  15128. (set_party_creation_random_limits, 0, ":upper_limit"),
  15129. (assign, reg0, ":upper_limit"),
  15130. ]),
  15131.  
  15132. #script_set_trade_route_between_centers
  15133. # INPUT:
  15134. # param1: center_no_1
  15135. # param1: center_no_2
  15136. ("set_trade_route_between_centers",
  15137. [(store_script_param, ":center_no_1", 1),
  15138. (store_script_param, ":center_no_2", 2),
  15139. (assign, ":center_1_added", 0),
  15140. (assign, ":center_2_added", 0),
  15141. (try_for_range, ":cur_slot", slot_town_trade_routes_begin, slot_town_trade_routes_end),
  15142. (try_begin),
  15143. (eq, ":center_1_added", 0),
  15144. (party_slot_eq, ":center_no_1", ":cur_slot", 0),
  15145. (party_set_slot, ":center_no_1", ":cur_slot", ":center_no_2"),
  15146. (assign, ":center_1_added", 1),
  15147. (try_end),
  15148. (try_begin),
  15149. (eq, ":center_2_added", 0),
  15150. (party_slot_eq, ":center_no_2", ":cur_slot", 0),
  15151. (party_set_slot, ":center_no_2", ":cur_slot", ":center_no_1"),
  15152. (assign, ":center_2_added", 1),
  15153. (try_end),
  15154. (try_end),
  15155. (try_begin),
  15156. (eq, ":center_1_added", 0),
  15157. (str_store_party_name, s1, ":center_no_1"),
  15158. (display_message, "@{!}DEBUG -- ERROR: More than 15 trade routes are given for {s1}."),
  15159. (try_end),
  15160. (try_begin),
  15161. (eq, ":center_2_added", 0),
  15162. (str_store_party_name, s1, ":center_no_2"),
  15163. (display_message, "@{!}DEBUG -- ERROR: More than 15 trade routes are given for {s1}."),
  15164. (try_end),
  15165. ]),
  15166.  
  15167. #script_center_change_trade_good_production
  15168. # INPUT:
  15169. # param1: center_no
  15170. # param2: item_id
  15171. # param3: production_rate (should be between -100 (for net consumption) and 100 (for net production)
  15172. # param4: randomness (between 0-100)
  15173. #("center_change_trade_good_production",
  15174. # [
  15175. # (display_message, "@CHANGING"),
  15176. # (store_script_param, ":center_no", 1),
  15177. # (store_script_param, ":item_no", 2),
  15178. # (store_script_param, ":production_rate", 3),
  15179. # (store_script_param, ":randomness", 4),
  15180. # (store_random_in_range, ":random_num", 0, ":randomness"),
  15181. # (store_random_in_range, ":random_sign", 0, 2),
  15182. # (try_begin),
  15183. # (eq, ":random_sign", 0),
  15184. # (val_add, ":production_rate", ":random_num"),
  15185. # (else_try),
  15186. # (val_sub, ":production_rate", ":random_num"),
  15187. # (try_end),
  15188. # (val_sub, ":item_no", trade_goods_begin),
  15189. # (val_add, ":item_no", slot_town_trade_good_productions_begin),
  15190. #
  15191. # (party_get_slot, ":old_production_rate", ":center_no", ":item_no"),
  15192. # (val_add, ":production_rate", ":old_production_rate"),
  15193. # (party_set_slot, ":center_no", ":item_no", ":production_rate"),
  15194. # ]),
  15195.  
  15196.  
  15197.  
  15198.  
  15199. ("average_trade_good_prices", #Called from start
  15200. [
  15201.  
  15202. #This should be done by route rather than distance
  15203. (store_sub, ":item_to_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  15204.  
  15205. (try_for_range, ":center_no", towns_begin, towns_end),
  15206. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  15207. (is_between, ":center_no", villages_begin, villages_end),
  15208.  
  15209. (try_for_range, ":other_center", centers_begin, centers_end),
  15210. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  15211. (is_between, ":center_no", villages_begin, villages_end),
  15212.  
  15213. (neq, ":other_center", ":center_no"),
  15214. (store_distance_to_party_from_party, ":cur_distance", ":center_no", ":other_center"),
  15215. (lt, ":cur_distance", 50), #Reduced from 110
  15216. (store_sub, ":dist_factor", 50, ":cur_distance"),
  15217.  
  15218. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  15219. (store_add, ":cur_good_slot", ":cur_good", ":item_to_slot"),
  15220. (party_get_slot, ":center_price", ":center_no", ":cur_good_slot"),
  15221. (party_get_slot, ":other_center_price", ":other_center", ":cur_good_slot"),
  15222. (store_sub, ":price_dif", ":center_price", ":other_center_price"),
  15223.  
  15224. (assign, ":price_dif_change", ":price_dif"),
  15225.  
  15226. (val_mul ,":price_dif_change", ":dist_factor"),
  15227. (val_div ,":price_dif_change", 1000), #Maximum of 1/20 per center
  15228. (val_add, ":other_center_price", ":price_dif_change"),
  15229. (party_set_slot, ":other_center", ":cur_good_slot", ":other_center_price"),
  15230.  
  15231. (val_sub, ":center_price", ":price_dif_change"),
  15232. (party_set_slot, ":center_no", ":cur_good_slot", ":center_price"),
  15233. (try_end),
  15234. (try_end),
  15235. (try_end),
  15236. ]),
  15237.  
  15238. ("average_trade_good_prices_2", #Called from start
  15239. [
  15240.  
  15241. #This should be done by route rather than distance
  15242. (store_sub, ":item_to_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  15243.  
  15244. (try_for_range, ":center_no", towns_begin, towns_end),
  15245. (try_for_range, ":other_center", centers_begin, centers_end),
  15246. (this_or_next|is_between, ":other_center", towns_begin, towns_end),
  15247. (is_between, ":other_center", villages_begin, villages_end),
  15248.  
  15249. (this_or_next|party_slot_eq, ":other_center", slot_village_market_town, ":center_no"),
  15250. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_1, ":other_center"),
  15251. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_2, ":other_center"),
  15252. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_3, ":other_center"),
  15253. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_4, ":other_center"),
  15254. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_5, ":other_center"),
  15255. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_6, ":other_center"),
  15256. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_7, ":other_center"),
  15257. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_8, ":other_center"),
  15258. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_9, ":other_center"),
  15259. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_10, ":other_center"),
  15260. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_11, ":other_center"),
  15261. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_12, ":other_center"),
  15262. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_13, ":other_center"),
  15263. (this_or_next|party_slot_eq, ":center_no", slot_town_trade_route_14, ":other_center"),
  15264. (party_slot_eq, ":center_no", slot_town_trade_route_15, ":other_center"),
  15265.  
  15266. # (neq, ":other_center", ":center_no"),
  15267. # (store_distance_to_party_from_party, ":cur_distance", ":center_no", ":other_center"),
  15268. # (lt, ":cur_distance", 50), #Reduced from 110
  15269. # (store_sub, ":dist_factor", 50, ":cur_distance"),
  15270.  
  15271. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  15272. (store_add, ":cur_good_slot", ":cur_good", ":item_to_slot"),
  15273. (party_get_slot, ":center_price", ":center_no", ":cur_good_slot"),
  15274. (party_get_slot, ":other_center_price", ":other_center", ":cur_good_slot"),
  15275. (store_sub, ":price_dif", ":center_price", ":other_center_price"),
  15276.  
  15277. (store_div, ":price_dif_change", ":price_dif", 5), #this is done twice, reduced from 4
  15278. # (assign, ":price_dif_change", ":price_dif"),
  15279.  
  15280. # (val_mul ,":price_dif_change", ":dist_factor"),
  15281. # (val_div ,":price_dif_change", 500), #Maximum of 1/10 per center
  15282. (val_add, ":other_center_price", ":price_dif_change"),
  15283. (party_set_slot, ":other_center", ":cur_good_slot", ":other_center_price"),
  15284.  
  15285. (val_sub, ":center_price", ":price_dif_change"),
  15286. (party_set_slot, ":center_no", ":cur_good_slot", ":center_price"),
  15287.  
  15288. (try_end),
  15289. (try_end),
  15290. (try_end),
  15291. ]),
  15292.  
  15293.  
  15294.  
  15295. #script_average_trade_good_productions
  15296. # INPUT: none (called only from game start?)
  15297. #This is currently deprecated, as I was going to try to fine-tune production
  15298. ("average_trade_good_productions",
  15299. [
  15300. (store_sub, ":item_to_slot", slot_town_trade_good_productions_begin, trade_goods_begin),
  15301. (try_for_range, ":center_no", towns_begin, towns_end),
  15302. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  15303. (is_between, ":center_no", villages_begin, villages_end),
  15304. (try_for_range, ":other_center", centers_begin, centers_end),
  15305. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  15306. (is_between, ":center_no", villages_begin, villages_end),
  15307. (neq, ":other_center", ":center_no"),
  15308. (store_distance_to_party_from_party, ":cur_distance", ":center_no", ":other_center"),
  15309. (lt, ":cur_distance", 110),
  15310. (store_sub, ":dist_factor", 110, ":cur_distance"),
  15311. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  15312. (store_add, ":cur_good_slot", ":cur_good", ":item_to_slot"),
  15313. (party_get_slot, ":center_production", ":center_no", ":cur_good_slot"),
  15314. (party_get_slot, ":other_center_production", ":other_center", ":cur_good_slot"),
  15315. (store_sub, ":prod_dif", ":center_production", ":other_center_production"),
  15316. (gt, ":prod_dif", 0),
  15317. (store_mul, ":prod_dif_change", ":prod_dif", 1),
  15318. ## (try_begin),
  15319. ## (is_between, ":center_no", towns_begin, towns_end),
  15320. ## (is_between, ":other_center", towns_begin, towns_end),
  15321. ## (val_mul, ":cur_distance", 2),
  15322. ## (try_end),
  15323. (val_mul ,":prod_dif_change", ":dist_factor"),
  15324. (val_div ,":prod_dif_change", 110),
  15325. (val_add, ":other_center_production", ":prod_dif_change"),
  15326. (party_set_slot, ":other_center", ":cur_good_slot", ":other_center_production"),
  15327. (try_end),
  15328. (try_end),
  15329. (try_end),
  15330. ]),
  15331.  
  15332. #script_normalize_trade_good_productions
  15333. #Adjusts productions according to the amount of the item produced
  15334. # INPUT: none
  15335. # This currently deprecated, as I was going to try to fine-tune productions
  15336. ("normalize_trade_good_productions",
  15337. [
  15338. (store_sub, ":item_to_slot", slot_town_trade_good_productions_begin, trade_goods_begin),
  15339. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  15340. (assign, ":total_production", 0),
  15341. (assign, ":num_centers", 0),
  15342. (store_add, ":cur_good_slot", ":cur_good", ":item_to_slot"),
  15343. (try_for_range, ":center_no", centers_begin, centers_end),
  15344. (val_add, ":num_centers", 1),
  15345. (try_begin),
  15346. (is_between, ":center_no", towns_begin, towns_end), #each town is weighted as 5 villages...
  15347. (val_add, ":num_centers", 4),
  15348. (try_end),
  15349. (party_get_slot, ":center_production", ":center_no", ":cur_good_slot"),
  15350. (val_add, ":total_production", ":center_production"),
  15351. (try_end),
  15352. (store_div, ":new_production_difference", ":total_production", ":num_centers"),
  15353. (neq, ":new_production_difference", 0),
  15354. (try_for_range, ":center_no", centers_begin, centers_end),
  15355. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  15356. (is_between, ":center_no", villages_begin, villages_end),
  15357. (party_get_slot, ":center_production", ":center_no", ":cur_good_slot"),
  15358. (val_sub, ":center_production", ":new_production_difference"),
  15359. (party_set_slot, ":center_no", ":cur_good_slot", ":center_production"),
  15360. (try_end),
  15361. (try_end),
  15362. ]),
  15363.  
  15364. #script_update_trade_good_prices
  15365. # INPUT: none
  15366. ("update_trade_good_prices",
  15367. [
  15368. (try_for_range, ":center_no", centers_begin, centers_end),
  15369. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  15370. (is_between, ":center_no", villages_begin, villages_end),
  15371. (call_script, "script_update_trade_good_price_for_party", ":center_no"),
  15372. (try_end),
  15373.  
  15374. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  15375. (assign, ":total_price", 0),
  15376. (assign, ":total_constants", 0),
  15377.  
  15378. (try_for_range, ":center_no", centers_begin, centers_end),
  15379. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  15380. (is_between, ":center_no", villages_begin, villages_end),
  15381.  
  15382. (store_sub, ":cur_good_price_slot", ":cur_good", trade_goods_begin),
  15383. (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
  15384. (party_get_slot, ":cur_price", ":center_no", ":cur_good_price_slot"),
  15385.  
  15386. (try_begin),
  15387. (is_between, ":center_no", towns_begin, towns_end),
  15388. (assign, ":constant", 5),
  15389. (else_try),
  15390. (assign, ":constant", 1),
  15391. (try_end),
  15392.  
  15393. (val_mul, ":cur_price", ":constant"),
  15394.  
  15395. (val_add, ":total_price", ":cur_price"),
  15396. (val_add, ":total_constants", ":constant"),
  15397. (try_end),
  15398.  
  15399. (try_for_range, ":center_no", centers_begin, centers_end),
  15400. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  15401. (is_between, ":center_no", villages_begin, villages_end),
  15402.  
  15403. (store_sub, ":cur_good_price_slot", ":cur_good", trade_goods_begin),
  15404. (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
  15405. (party_get_slot, ":cur_price", ":center_no", ":cur_good_price_slot"),
  15406.  
  15407. (val_mul, ":cur_price", 1000),
  15408. (val_mul, ":cur_price", ":total_constants"),
  15409. (val_div, ":cur_price", ":total_price"),
  15410.  
  15411. (val_clamp, ":cur_price", minimum_price_factor, maximum_price_factor),
  15412. (party_set_slot, ":center_no", ":cur_good_price_slot", ":cur_price"),
  15413. (try_end),
  15414. (try_end),
  15415. ]),
  15416.  
  15417. #script_update_trade_good_price_for_party
  15418. # INPUT: arg1 = party_no
  15419. #Called once every 72 hours
  15420. ("update_trade_good_price_for_party",
  15421. [
  15422. (store_script_param, ":center_no", 1),
  15423. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  15424. (store_sub, ":cur_good_price_slot", ":cur_good", trade_goods_begin),
  15425. (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
  15426. (party_get_slot, ":cur_price", ":center_no", ":cur_good_price_slot"),
  15427.  
  15428. (call_script, "script_center_get_production", ":center_no", ":cur_good"),
  15429. (assign, ":production", reg0),
  15430.  
  15431. (call_script, "script_center_get_consumption", ":center_no", ":cur_good"),
  15432. (assign, ":consumption", reg0),
  15433.  
  15434. #OZANDEBUG
  15435. #(assign, reg1, ":production"),
  15436. #(assign, reg2, ":consumption"),
  15437. #(str_store_party_name, s1, ":center_no"),
  15438. #(str_store_item_name, s2, ":cur_good"),
  15439.  
  15440. (val_sub, ":production", ":consumption"),
  15441.  
  15442. #Change average production x 2(1+random(2)) (was average 4, random(8)) for excess demand
  15443. (try_begin),
  15444. #supply is greater than demand
  15445. (gt, ":production", 0),
  15446. (store_mul, ":change_factor", ":production", 1), #price will be decreased by his factor
  15447. (store_random_in_range, ":random_change", 0, ":change_factor"),
  15448. (val_add, ":random_change", ":change_factor"),
  15449. (val_add, ":random_change", ":change_factor"),
  15450.  
  15451. #simulation starts
  15452. (store_sub, ":final_price", ":cur_price", ":random_change"),
  15453. (val_clamp, ":final_price", minimum_price_factor, maximum_price_factor),
  15454. (try_begin), #Excess of supply decelerates over time, as low price reduces output
  15455. #if expected final price is 100 then it will multiply random_change by 0.308x ((100+300)/(1300) = 400/1300).
  15456. (lt, ":final_price", 1000),
  15457. (store_add, ":final_price_plus_300", ":final_price", 300),
  15458. (val_mul, ":random_change", ":final_price_plus_300"),
  15459. (val_div, ":random_change", 1300),
  15460. (try_end),
  15461. (val_sub, ":cur_price", ":random_change"),
  15462. (else_try),
  15463. (lt, ":production", 0),
  15464. (store_sub, ":change_factor", 0, ":production"), #price will be increased by his factor
  15465. (val_mul, ":change_factor", 1),
  15466. (store_random_in_range, ":random_change", 0, ":change_factor"),
  15467. (val_add, ":random_change", ":change_factor"),
  15468. (val_add, ":random_change", ":change_factor"),
  15469. (val_add, ":cur_price", ":random_change"),
  15470. (try_end),
  15471.  
  15472. #Move price towards average by 3%...
  15473. #Equilibrium is 33 cycles, or 100 days
  15474. #Change per cycle is Production x 4
  15475. #Thus, max differential = -5 x 4 x 33 = -660 for -5
  15476. (try_begin),
  15477. (is_between, ":center_no", villages_begin, villages_end),
  15478. (store_sub, ":price_difference", ":cur_price", average_price_factor),
  15479. (val_mul, ":price_difference", 96),
  15480. (val_div, ":price_difference", 100),
  15481. (store_add, ":new_price", average_price_factor, ":price_difference"),
  15482. (else_try),
  15483. (store_sub, ":price_difference", ":cur_price", average_price_factor),
  15484. (val_mul, ":price_difference", 96),
  15485. (val_div, ":price_difference", 100),
  15486. (store_add, ":new_price", average_price_factor, ":price_difference"),
  15487. (try_end),
  15488.  
  15489. #Price of manufactured goods drift towards primary raw material
  15490. (try_begin),
  15491. (item_get_slot, ":raw_material", ":cur_good", slot_item_primary_raw_material),
  15492. (neq, ":raw_material", 0),
  15493. (store_sub, ":raw_material_price_slot", ":raw_material", trade_goods_begin),
  15494. (val_add, ":raw_material_price_slot", slot_town_trade_good_prices_begin),
  15495.  
  15496. (party_get_slot, ":total_raw_material_price", ":center_no", ":raw_material_price_slot"),
  15497. (val_mul, ":total_raw_material_price", 3),
  15498. (assign, ":number_of_centers", 3),
  15499.  
  15500. (try_for_range, ":village_no", villages_begin, villages_end),
  15501. (party_slot_eq, ":village_no", slot_village_bound_center, ":center_no"),
  15502. (party_get_slot, ":raw_material_price", ":village_no", ":raw_material_price_slot"),
  15503. (val_add, ":total_raw_material_price", ":raw_material_price"),
  15504. (val_add, ":number_of_centers", 1),
  15505. (try_end),
  15506.  
  15507. (store_div, ":average_raw_material_price", ":total_raw_material_price", ":number_of_centers"),
  15508.  
  15509. (gt, ":average_raw_material_price", ":new_price"),
  15510. (store_sub, ":raw_material_boost", ":average_raw_material_price", ":new_price"),
  15511. (val_div, ":raw_material_boost", 10),
  15512. (val_add, ":new_price", ":raw_material_boost"),
  15513. (try_end),
  15514.  
  15515. (val_clamp, ":new_price", minimum_price_factor, maximum_price_factor),
  15516. (party_set_slot, ":center_no", ":cur_good_price_slot", ":new_price"),
  15517.  
  15518. #(assign, reg3, ":new_price"),
  15519. #(str_store_item_name, s2, ":cur_good"),
  15520. #(display_log_message, "@DEBUG : {s1}-{s2}, prod:{reg1}, cons:{reg2}, price:{reg3}"),
  15521. (try_end),
  15522. ]),
  15523.  
  15524. ("center_get_production",
  15525. [
  15526. #Actually, this could be reset somewhat to yield supply and demand as raw numbers
  15527. #Demand could be set values for rural and urban
  15528. #Supply could be based on capital goods -- head of cattle, head of sheep, fish ponds, fishing fleets, acres of grain fields, olive orchards, olive presses, wine presses, mills, smithies, salt pans, potters' kilns, etc
  15529. #Prosperity would increase both demand and supply
  15530. (store_script_param_1, ":center_no"),
  15531. (store_script_param_2, ":cur_good"),
  15532.  
  15533. (assign, ":base_production", 0),
  15534.  
  15535. #Grain products
  15536. (try_begin),
  15537. (eq, ":cur_good", "itm_bread"), #Demand = 3000 across Calradia
  15538. (party_get_slot, ":base_production", ":center_no", slot_center_mills),
  15539. (val_mul, ":base_production", 20), #one mills per village, five mills per town = 160 mills
  15540. (else_try),
  15541. (eq, ":cur_good", "itm_grain"), #Demand = 3200+, 1600 to mills, 1500 on its own, extra to breweries
  15542. (party_get_slot, ":base_production", ":center_no", slot_center_acres_grain),
  15543. (val_div, ":base_production", 125), #10000 acres is the average across Calradia, extra in Swadia, less in snows and steppes, a bit from towns
  15544. (else_try),
  15545. (eq, ":cur_good", "itm_ale"), #
  15546. (party_get_slot, ":base_production", ":center_no", slot_center_breweries),
  15547. (val_mul, ":base_production", 25),
  15548.  
  15549. (else_try),
  15550. (eq, ":cur_good", "itm_smoked_fish"), #Demand = 20
  15551. (party_get_slot, ":base_production", ":center_no", slot_center_fishing_fleet),
  15552. (val_mul, ":base_production", 4), #was originally 5
  15553. (else_try),
  15554. (eq, ":cur_good", "itm_salt"),
  15555. (party_get_slot, ":base_production", ":center_no", slot_center_salt_pans),
  15556. (val_mul, ":base_production", 35),
  15557.  
  15558. #Cattle products
  15559. (else_try),
  15560. (eq, ":cur_good", "itm_cattle_meat"), #Demand = 5
  15561. (party_get_slot, ":base_production", ":center_no", slot_center_head_cattle),
  15562. (val_div, ":base_production", 4), #was 9
  15563. (else_try),
  15564. (eq, ":cur_good", "itm_dried_meat"), #Demand = 15
  15565. (party_get_slot, ":base_production", ":center_no", slot_center_head_cattle),
  15566. (val_div, ":base_production", 2), #was 3
  15567. (else_try),
  15568. (eq, ":cur_good", "itm_cheese"), #Demand = 10
  15569. (party_get_slot, ":base_production", ":center_no", slot_center_head_cattle),
  15570. (party_get_slot, ":sheep_addition", ":center_no", slot_center_head_sheep),
  15571. (val_div, ":sheep_addition", 2),
  15572. (val_add, ":base_production", ":sheep_addition"),
  15573. (party_get_slot, ":gardens", ":center_no", slot_center_household_gardens),
  15574. (val_mul, ":base_production", ":gardens"),
  15575. (val_div, ":base_production", 10),
  15576. (else_try),
  15577. (eq, ":cur_good", "itm_butter"), #Demand = 2
  15578. (party_get_slot, ":base_production", ":center_no", slot_center_head_cattle),
  15579. (party_get_slot, ":gardens", ":center_no", slot_center_household_gardens),
  15580. (val_mul, ":base_production", ":gardens"),
  15581. (val_div, ":base_production", 15),
  15582.  
  15583. (else_try),
  15584. (eq, ":cur_good", "itm_raw_leather"), #Demand = ??
  15585. (party_get_slot, ":base_production", ":center_no", slot_center_head_cattle),
  15586. (val_div, ":base_production", 6),
  15587. (party_get_slot, ":sheep_addition", ":center_no", slot_center_head_sheep),
  15588. (val_div, ":sheep_addition", 12),
  15589. (val_add, ":base_production", ":sheep_addition"),
  15590.  
  15591. (else_try),
  15592. (eq, ":cur_good", "itm_leatherwork"), #Demand = ??
  15593. (party_get_slot, ":base_production", ":center_no", slot_center_tanneries),
  15594. (val_mul, ":base_production", 20),
  15595.  
  15596. (else_try),
  15597. (eq, ":cur_good", "itm_honey"), #Demand = 5
  15598. (party_get_slot, ":base_production", ":center_no", slot_center_apiaries),
  15599. (val_mul, ":base_production", 6),
  15600. (else_try),
  15601. (eq, ":cur_good", "itm_cabbages"), #Demand = 7
  15602. (party_get_slot, ":base_production", ":center_no", slot_center_household_gardens),
  15603. (val_mul, ":base_production", 10),
  15604. (else_try),
  15605. (eq, ":cur_good", "itm_apples"), #Demand = 7
  15606. (party_get_slot, ":base_production", ":center_no", slot_center_household_gardens),
  15607. (val_mul, ":base_production", 10),
  15608.  
  15609. #Sheep products
  15610. (else_try),
  15611. (eq, ":cur_good", "itm_sausages"), #Demand = 5
  15612. (party_get_slot, ":base_production", ":center_no", slot_center_head_sheep), #average of 90 sheep
  15613. (val_div, ":base_production", 15),
  15614. (else_try),
  15615. (eq, ":cur_good", "itm_wool"), #(Demand = 0, but 15 averaged out perhaps)
  15616. (party_get_slot, ":base_production", ":center_no", slot_center_head_sheep), #average of 90 sheep
  15617. (val_div, ":base_production", 5),
  15618. (else_try),
  15619. (eq, ":cur_good", "itm_wool_cloth"), #(Demand = 1500 across Calradia)
  15620. (party_get_slot, ":base_production", ":center_no", slot_center_wool_looms),
  15621. (val_mul, ":base_production", 5), #300 across Calradia
  15622.  
  15623. (else_try),
  15624. (this_or_next|eq, ":cur_good", "itm_pork"),
  15625. (eq, ":cur_good", "itm_chicken"),
  15626. (try_begin),
  15627. (is_between, ":center_no", villages_begin, villages_end),
  15628. (assign, ":base_production", 30),
  15629. (else_try),
  15630. (assign, ":base_production", 0),
  15631. (try_end),
  15632.  
  15633. (else_try),
  15634. (eq, ":cur_good", "itm_iron"), #Demand = 5, one supplies three smithies
  15635. (party_get_slot, ":base_production", ":center_no", slot_center_iron_deposits),
  15636. (val_mul, ":base_production", 10),
  15637. (else_try),
  15638. (eq, ":cur_good", "itm_tools"), #Demand = 560 across Calradia
  15639. (party_get_slot, ":base_production", ":center_no", slot_center_smithies),
  15640. (val_mul, ":base_production", 3),
  15641.  
  15642. #Other artisanal goods
  15643. (else_try),
  15644. (eq, ":cur_good", "itm_pottery"), #560 is total demand
  15645. (party_get_slot, ":base_production", ":center_no", slot_center_pottery_kilns),
  15646. (val_mul, ":base_production", 5),
  15647.  
  15648. (else_try),
  15649. (eq, ":cur_good", "itm_raw_grapes"),
  15650. (party_get_slot, ":base_production", ":center_no", slot_center_acres_vineyard),
  15651. (val_div, ":base_production", 100),
  15652. (else_try),
  15653. (eq, ":cur_good", "itm_wine"),
  15654. (party_get_slot, ":base_production", ":center_no", slot_center_wine_presses),
  15655. (val_mul, ":base_production", 25),
  15656. (else_try),
  15657. (eq, ":cur_good", "itm_raw_olives"),
  15658. (party_get_slot, ":base_production", ":center_no", slot_center_acres_olives),
  15659. (val_div, ":base_production", 150),
  15660. (else_try),
  15661. (eq, ":cur_good", "itm_oil"),
  15662. (party_get_slot, ":base_production", ":center_no", slot_center_olive_presses),
  15663. (val_mul, ":base_production", 12),
  15664.  
  15665. #Flax and linen
  15666. (else_try),
  15667. (eq, ":cur_good", "itm_linen"),
  15668. (party_get_slot, ":base_production", ":center_no", slot_center_linen_looms),
  15669. (val_mul, ":base_production", 5),
  15670. (else_try),
  15671. (eq, ":cur_good", "itm_raw_flax"),
  15672. (party_get_slot, ":base_production", ":center_no", slot_center_acres_flax),
  15673. (val_div, ":base_production", 80),
  15674. (else_try),
  15675. (eq, ":cur_good", "itm_velvet"),
  15676. (party_get_slot, ":base_production", ":center_no", slot_center_silk_looms),
  15677. (val_mul, ":base_production", 5),
  15678. (else_try),
  15679. (eq, ":cur_good", "itm_raw_silk"),
  15680. (party_get_slot, ":base_production", ":center_no", slot_center_silk_farms),
  15681. (val_div, ":base_production", 20),
  15682. (else_try),
  15683. (eq, ":cur_good", "itm_raw_dyes"),
  15684. (party_get_slot, ":base_production", ":center_no", slot_center_kirmiz_farms),
  15685. (val_div, ":base_production", 20),
  15686. (else_try),
  15687. (eq, ":cur_good", "itm_raw_date_fruit"),
  15688. (party_get_slot, ":base_production", ":center_no", slot_center_acres_dates),
  15689. (val_div, ":base_production", 120),
  15690. (else_try),
  15691. (eq, ":cur_good", "itm_furs"), #Demand = 90 across Calradia
  15692. (party_get_slot, ":base_production", ":center_no", slot_center_fur_traps),
  15693. (val_mul, ":base_production", 25),
  15694. (else_try),
  15695. (eq, ":cur_good", "itm_spice"),
  15696. (try_begin),
  15697. (eq, ":center_no", "p_town_10"), #Tulga
  15698. (assign, ":base_production", 100),
  15699. (else_try),
  15700. (eq, ":center_no", "p_town_17"), #Ichamur
  15701. (assign, ":base_production", 50),
  15702. (else_try),
  15703. (eq, ":center_no", "p_town_19"), #Shariz
  15704. (assign, ":base_production", 50),
  15705. (else_try),
  15706. (eq, ":center_no", "p_town_22"), #Bariyye
  15707. (assign, ":base_production", 50),
  15708. (else_try),
  15709. (this_or_next|eq, ":center_no", "p_village_11"), #Dusturil (village of Tulga)
  15710. (eq, ":center_no", "p_village_25"), #Dashbigha (village of Tulga)
  15711. (assign, ":base_production", 50),
  15712. (else_try),
  15713. (this_or_next|eq, ":center_no", "p_village_37"), #Ada Kulun (village of Ichlamur)
  15714. (this_or_next|eq, ":center_no", "p_village_42"), #Dirigh Aban (village of Ichlamur)
  15715. (this_or_next|eq, ":center_no", "p_village_99"), #Fishara (village of Bariyye)
  15716. (eq, ":center_no", "p_village_100"), #Iqbayl (village of Bariyye)
  15717. (assign, ":base_production", 25),
  15718. (try_end),
  15719. (try_end),
  15720.  
  15721. #Modify production by other goods
  15722. (assign, ":modified_production", ":base_production"),
  15723. (try_begin),
  15724. (eq, ":cur_good", "itm_bread"),
  15725. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_grain", ":base_production", 1),
  15726. (assign, ":modified_production", reg0),
  15727. (else_try),
  15728. (eq, ":cur_good", "itm_ale"),
  15729. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_grain", ":base_production", 2),
  15730. (assign, ":modified_production", reg0),
  15731. (else_try),
  15732. (eq, ":cur_good", "itm_dried_meat"),
  15733. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_salt", ":base_production", 2),
  15734. (assign, ":modified_production", reg0),
  15735. (else_try),
  15736. (eq, ":cur_good", "itm_smoked_fish"),
  15737. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_salt", ":base_production", 2),
  15738. (assign, ":modified_production", reg0),
  15739. (else_try),
  15740. (eq, ":cur_good", "itm_tools"),
  15741. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_iron", ":base_production", 1),
  15742. (assign, ":modified_production", reg0),
  15743. (else_try),
  15744. (eq, ":cur_good", "itm_wool_cloth"),
  15745. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_wool", ":base_production", 1),
  15746. (assign, ":modified_production", reg0),
  15747. (else_try),
  15748. (eq, ":cur_good", "itm_wine"),
  15749. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_raw_grapes", ":base_production", 1),
  15750. (assign, ":modified_production", reg0),
  15751. (else_try),
  15752. (eq, ":cur_good", "itm_oil"),
  15753. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_raw_olives", ":base_production", 1),
  15754. (assign, ":modified_production", reg0),
  15755. (else_try),
  15756. (eq, ":cur_good", "itm_velvet"),
  15757. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_raw_silk", ":base_production", 1),
  15758. (assign, ":initially_modified_production", reg0),
  15759.  
  15760. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_raw_dyes", ":initially_modified_production", 2),
  15761. (assign, ":modified_production", reg0),
  15762. (else_try),
  15763. (eq, ":cur_good", "itm_leatherwork"),
  15764. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_raw_leather", ":base_production", 1),
  15765. (assign, ":modified_production", reg0),
  15766. (else_try),
  15767. (eq, ":cur_good", "itm_linen"),
  15768. (call_script, "script_good_price_affects_good_production", ":center_no", "itm_raw_flax", ":base_production", 1),
  15769. (assign, ":modified_production", reg0),
  15770. (try_end),
  15771.  
  15772.  
  15773. (assign, ":base_production_modded_by_raw_materials", ":modified_production"), #this is just logged for the report screen
  15774.  
  15775. #Increase both positive and negative production by the center's prosperity
  15776. #Richer towns have more people and consume more, but also produce more
  15777. (try_begin),
  15778. (party_get_slot, ":prosperity_plus_75", ":center_no", slot_town_prosperity),
  15779. (val_add, ":prosperity_plus_75", 75),
  15780. (val_mul, ":modified_production", ":prosperity_plus_75"),
  15781. (val_div, ":modified_production", 125),
  15782. (try_end),
  15783.  
  15784. (try_begin),
  15785. (this_or_next|party_slot_eq, ":center_no", slot_village_state, svs_being_raided),
  15786. (this_or_next|party_slot_eq, ":center_no", slot_village_state, svs_deserted), #SB : deserted village
  15787. (party_slot_eq, ":center_no", slot_village_state, svs_looted),
  15788. (assign, ":modified_production", 0),
  15789. (try_end),
  15790.  
  15791. (assign, reg0, ":modified_production"), #modded by prosperity
  15792. (assign, reg1, ":base_production_modded_by_raw_materials"),
  15793. (assign, reg2, ":base_production"),
  15794.  
  15795. ]),
  15796.  
  15797. ("center_get_consumption",
  15798. [
  15799. (store_script_param_1, ":center_no"),
  15800. (store_script_param_2, ":cur_good"),
  15801.  
  15802. (assign, ":consumer_consumption", 0),
  15803. (try_begin),
  15804. ##diplomacy start+ To determine if a center should be counted as a desert center or not,
  15805. #instead of using a fixed range (which is brittle to map changes) check if the terrain
  15806. #at the center is rt_desert or rt_desert_forest.
  15807. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  15808. (is_between, ":center_no", centers_begin, centers_end),
  15809. (party_get_current_terrain, reg0, ":center_no"),
  15810. (this_or_next|eq, reg0, rt_desert),
  15811. (eq, reg0, rt_desert_forest),
  15812. (item_slot_ge, ":cur_good", slot_item_desert_demand, 0), #Otherwise use rural or urban
  15813. (item_get_slot, ":consumer_consumption", ":cur_good", slot_item_desert_demand),
  15814. (else_try),
  15815. (lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  15816. #If economic changes are disabled, use the Native desert-check logic.
  15817. ##diplomacy end+
  15818. (this_or_next|is_between, ":center_no", "p_town_19", "p_castle_1"),
  15819. (ge, ":center_no", "p_village_91"),
  15820. (item_slot_ge, ":cur_good", slot_item_desert_demand, 0), #Otherwise use rural or urban
  15821. (item_get_slot, ":consumer_consumption", ":cur_good", slot_item_desert_demand),
  15822. (else_try),
  15823. (is_between, ":center_no", villages_begin, villages_end),
  15824. (item_get_slot, ":consumer_consumption", ":cur_good", slot_item_rural_demand),
  15825. (else_try),
  15826. (is_between, ":center_no", towns_begin, towns_end),
  15827. (item_get_slot, ":consumer_consumption", ":cur_good", slot_item_urban_demand),
  15828. (try_end),
  15829.  
  15830.  
  15831. (assign, ":raw_material_consumption", 0),
  15832. (try_begin),
  15833. (eq, ":cur_good", "itm_grain"),
  15834. (party_get_slot, ":grain_for_bread", ":center_no", slot_center_mills),
  15835. (val_mul, ":grain_for_bread", 20),
  15836.  
  15837. (party_get_slot, ":grain_for_ale", ":center_no", slot_center_breweries),
  15838. (val_mul, ":grain_for_ale", 5),
  15839.  
  15840. (store_add, ":raw_material_consumption", ":grain_for_bread", ":grain_for_ale"),
  15841.  
  15842. (else_try),
  15843. (eq, ":cur_good", "itm_iron"),
  15844. (party_get_slot, ":raw_material_consumption", ":center_no", slot_center_smithies),
  15845. (val_mul, ":raw_material_consumption", 3),
  15846.  
  15847. (else_try),
  15848. (eq, ":cur_good", "itm_wool"),
  15849. (party_get_slot, ":raw_material_consumption", ":center_no", slot_center_wool_looms),
  15850. (val_mul, ":raw_material_consumption", 5),
  15851.  
  15852. (else_try),
  15853. (eq, ":cur_good", "itm_raw_flax"),
  15854. (party_get_slot, ":raw_material_consumption", ":center_no", slot_center_linen_looms),
  15855. (val_mul, ":raw_material_consumption", 5),
  15856.  
  15857. (else_try),
  15858. (eq, ":cur_good", "itm_raw_leather"),
  15859. (party_get_slot, ":raw_material_consumption", ":center_no", slot_center_tanneries),
  15860. (val_mul, ":raw_material_consumption", 20),
  15861.  
  15862. (else_try),
  15863. (eq, ":cur_good", "itm_raw_grapes"),
  15864. (party_get_slot, ":raw_material_consumption", ":center_no", slot_center_wine_presses),
  15865. (val_mul, ":raw_material_consumption", 30),
  15866.  
  15867. (else_try),
  15868. (eq, ":cur_good", "itm_raw_olives"),
  15869. (party_get_slot, ":raw_material_consumption", ":center_no", slot_center_olive_presses),
  15870. (val_mul, ":raw_material_consumption", 12),
  15871.  
  15872.  
  15873. (else_try),
  15874. (eq, ":cur_good", "itm_raw_dyes"),
  15875. (party_get_slot, ":raw_material_consumption", ":center_no", slot_center_silk_looms),
  15876. (val_mul, ":raw_material_consumption", 1),
  15877. (else_try),
  15878. (eq, ":cur_good", "itm_raw_silk"),
  15879. (party_get_slot, ":raw_material_consumption", ":center_no", slot_center_silk_looms),
  15880. (val_mul, ":raw_material_consumption", 5),
  15881.  
  15882.  
  15883. (else_try),
  15884. (eq, ":cur_good", "itm_salt"),
  15885. (party_get_slot, ":salt_for_beef", ":center_no", slot_center_head_cattle),
  15886. (val_div, ":salt_for_beef", 10),
  15887.  
  15888. (party_get_slot, ":salt_for_fish", ":center_no", slot_center_fishing_fleet),
  15889. (val_div, ":salt_for_fish", 5),
  15890.  
  15891. (store_add, ":raw_material_consumption", ":salt_for_beef", ":salt_for_fish"),
  15892. (try_end),
  15893.  
  15894. (try_begin), #Reduce consumption of raw materials if their cost is high
  15895. (gt, ":raw_material_consumption", 0),
  15896. (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  15897. (store_add, ":cur_good_price_slot", ":cur_good", ":item_to_price_slot"),
  15898. (party_get_slot, ":cur_center_price", ":center_no", ":cur_good_price_slot"),
  15899. ##diplomacy start+
  15900. (gt, ":cur_center_price", average_price_factor),#replace the hardcoded constant 1000 with average_price_factor
  15901. (val_mul, ":raw_material_consumption", average_price_factor),#again replace the hardcoded constant 1000 with average_price_factor
  15902. ##diplomacy end+
  15903. (val_div, ":raw_material_consumption", ":cur_center_price"),
  15904. (try_end),
  15905.  
  15906.  
  15907.  
  15908. (store_add, ":modified_consumption", ":consumer_consumption", ":raw_material_consumption"),
  15909. (try_begin),
  15910. (party_get_slot, ":prosperity_plus_75", ":center_no", slot_town_prosperity),
  15911. (val_add, ":prosperity_plus_75", 75),
  15912. (val_mul, ":modified_consumption", ":prosperity_plus_75"),
  15913. (val_div, ":modified_consumption", 125),
  15914. (try_end),
  15915.  
  15916.  
  15917. (assign, reg0, ":modified_consumption"), #modded by prosperity
  15918. (assign, reg1, ":raw_material_consumption"),
  15919. (assign, reg2, ":consumer_consumption"),
  15920. ]),
  15921.  
  15922. #script_get_enterprise_name
  15923. # INPUT: arg1 = item_no
  15924. # Output: reg0: production string
  15925. ("get_enterprise_name",
  15926. [
  15927. (store_script_param_1, ":item_produced"),
  15928. (assign, ":enterprise_name", "str_bread_site"),
  15929. (try_begin),
  15930. (eq, ":item_produced", "itm_bread"),
  15931. (assign, ":enterprise_name", "str_bread_site"),
  15932. (else_try),
  15933. (eq, ":item_produced", "itm_ale"),
  15934. (assign, ":enterprise_name", "str_ale_site"),
  15935. (else_try),
  15936. (eq, ":item_produced", "itm_oil"),
  15937. (assign, ":enterprise_name", "str_oil_site"),
  15938. (else_try),
  15939. (eq, ":item_produced", "itm_wine"),
  15940. (assign, ":enterprise_name", "str_wine_site"),
  15941. (else_try),
  15942. (eq, ":item_produced", "itm_leatherwork"),
  15943. (assign, ":enterprise_name", "str_leather_site"),
  15944. (else_try),
  15945. (eq, ":item_produced", "itm_wool_cloth"),
  15946. (assign, ":enterprise_name", "str_wool_cloth_site"),
  15947. (else_try),
  15948. (eq, ":item_produced", "itm_linen"),
  15949. (assign, ":enterprise_name", "str_linen_site"),
  15950. (else_try),
  15951. (eq, ":item_produced", "itm_velvet"),
  15952. (assign, ":enterprise_name", "str_velvet_site"),
  15953. (else_try),
  15954. (eq, ":item_produced", "itm_tools"),
  15955. (assign, ":enterprise_name", "str_tool_site"),
  15956. (try_end),
  15957. (assign, reg0, ":enterprise_name"),
  15958. ]),
  15959.  
  15960. #script_do_merchant_town_trade
  15961. # INPUT: arg1 = party_no (of the merchant), arg2 = center_no
  15962. ##diplomacy start+
  15963. # If optional economic changes are enabled, the benefits are applied to both
  15964. # the town of origin and the destination, instead of just the latter.
  15965. ##diplomacy end+
  15966. ("do_merchant_town_trade",
  15967. [
  15968. (store_script_param_1, ":party_no"),
  15969. (store_script_param_2, ":center_no"),
  15970.  
  15971. (party_get_slot, ":origin", ":party_no", slot_party_last_traded_center),
  15972.  
  15973. (try_begin),
  15974. (eq, "$cheat_mode", 2),
  15975. (str_store_party_name, s4, ":center_no"),
  15976. (str_store_party_name, s5, ":origin"),
  15977. (display_message, "@{!}DEBUG -- Caravan trades in {s4}, originally from {s5}"),
  15978. (try_end),
  15979.  
  15980. (call_script, "script_add_log_entry", logent_party_traded, ":party_no", ":origin", ":center_no", -1),
  15981.  
  15982. (call_script, "script_do_party_center_trade", ":party_no", ":center_no", 4), #it was first 10 then increased 20 then increased 30, now I decrease it to back 6. Because otherwise prices do not differiate much. Trade become useless in game.
  15983.  
  15984. (assign, ":total_change", reg0),
  15985. #Adding the earnings to the wealth (maximum changed price is the earning)
  15986. (val_div, ":total_change", 2),
  15987. (str_store_party_name, s1, ":party_no"),
  15988. (str_store_party_name, s2, ":center_no"),
  15989. (assign, reg1, ":total_change"),
  15990.  
  15991. #Adding tariffs to the town
  15992. (party_get_slot, ":accumulated_tariffs", ":center_no", slot_center_accumulated_tariffs),
  15993. (party_get_slot, ":prosperity", ":center_no", slot_town_prosperity),
  15994.  
  15995. (assign, ":tariffs_generated", ":total_change"),
  15996. (val_mul, ":tariffs_generated", ":prosperity"),
  15997. ##diplomacy start+
  15998. #Move the next two lines further down to reduce rounding error
  15999. #(val_div, ":tariffs_generated", 100),
  16000. #(val_div, ":tariffs_generated", 10), #10 for caravans, 20 for villages
  16001.  
  16002. #Re-wrote the "diplomacy" section here for greater clarity.
  16003. (assign, ":percent", 100),
  16004. (try_begin), # trade agreement
  16005. (store_faction_of_party, ":party_faction", ":party_no"),
  16006. (store_faction_of_party, ":center_faction", ":center_no"),
  16007.  
  16008. (store_add, ":truce_slot", ":party_faction", slot_faction_truce_days_with_factions_begin),
  16009. (val_sub, ":truce_slot", kingdoms_begin),
  16010. (faction_get_slot, ":truce_days", ":center_faction", ":truce_slot"),
  16011. ##nested diplomacy start+ replace "20" with a named constant
  16012. #(gt, ":truce_days", 20),
  16013. (gt, ":truce_days", dplmc_treaty_trade_days_expire),
  16014. ##nested diplomacy end+
  16015. (val_add, ":percent", 30),
  16016. (try_end),
  16017.  
  16018. #If economic changes are enabled, divide the tariffs between the source and destination.
  16019. (assign, ":origin_tariffs_generated", 0),#we will need this variable later, if it is set
  16020. (try_begin),
  16021. #Economic changes must be enabled
  16022. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  16023. #verify the origin is a real town or village and not a placeholder value
  16024. (ge, ":origin", 0),
  16025. (this_or_next|is_between, ":origin", towns_begin, towns_end),
  16026. (this_or_next|is_between, ":origin", villages_begin, villages_end),
  16027. (this_or_next|party_slot_eq, ":origin", slot_party_type, spt_town),
  16028. (party_slot_eq, ":origin", slot_party_type, spt_village),
  16029. #give half the tariffs to the origin
  16030. (ge, ":tariffs_generated", 0),
  16031. (party_get_slot, ":origin_accumulated_tariffs", ":origin", slot_center_accumulated_tariffs),
  16032. (store_div, ":origin_tariffs_generated", ":tariffs_generated", 2),
  16033. (val_sub, ":tariffs_generated", ":origin_tariffs_generated"),
  16034. #apply plutocracy/aristocracy modifier, and any modifier from a trade treaty
  16035. (store_faction_of_party, ":origin_faction", ":center_no"),
  16036. (faction_get_slot, ":aristocracy", ":origin_faction", dplmc_slot_faction_aristocracy),
  16037. (val_mul, ":aristocracy", -5),
  16038. (store_add, ":origin_percent", ":percent", ":aristocracy"),
  16039. (val_mul, ":origin_tariffs_generated", ":origin_percent"),
  16040. (val_add, ":origin_tariffs_generated", 50),#for rounding
  16041. (val_div, ":origin_tariffs_generated", 100),
  16042. #apply the delayed division from before (leaving the steps separated for clarity)
  16043. (val_add, ":origin_tariffs_generated", 50),
  16044. (val_div, ":origin_tariffs_generated", 100),#adjust for having been multiplied by prosperity
  16045. (val_add, ":tariffs_generated", 5),
  16046. (val_div, ":tariffs_generated", 10), #10 for caravans, 20 for villages
  16047. #now we have the final value of origin_tariffs_generated
  16048. (val_add, ":origin_accumulated_tariffs", ":origin_tariffs_generated"),
  16049. (party_set_slot, ":origin", slot_center_accumulated_tariffs, ":origin_accumulated_tariffs"),
  16050. #print economic debug message if enabled
  16051. (ge, "$cheat_mode", 3),
  16052. (assign, reg4, ":origin_tariffs_generated"),
  16053. (str_store_party_name, s4, ":origin"),
  16054. (assign, reg5, ":origin_accumulated_tariffs"),
  16055. (display_message, "@{!}New tariffs at {s4} = {reg4}, total = {reg5}"),
  16056. (try_end),
  16057.  
  16058. #For this town: apply the faction plutocracy/aristocracy modifier
  16059. (faction_get_slot, ":aristocracy", ":center_faction", dplmc_slot_faction_aristocracy),
  16060. (val_mul, ":aristocracy", -5),
  16061. (val_add, ":percent", ":aristocracy"),
  16062. (val_mul, ":tariffs_generated", ":percent"),
  16063. (val_add, ":tariffs_generated", 50),
  16064. (val_div, ":tariffs_generated", 100),
  16065. #apply the delayed division from before (leaving the steps separated for clarity)
  16066. (val_add, ":tariffs_generated", 50),
  16067. (val_div, ":tariffs_generated", 100),#adjust for having been multiplied by prosperity
  16068. (val_add, ":tariffs_generated", 5),
  16069. (val_div, ":tariffs_generated", 10), #10 for caravans, 20 for villages
  16070. ##diplomacy end+
  16071. (val_add, ":accumulated_tariffs", ":tariffs_generated"),
  16072.  
  16073. (try_begin),
  16074. (ge, "$cheat_mode", 3),
  16075. (assign, reg4, ":tariffs_generated"),
  16076. (str_store_party_name, s4, ":center_no"),
  16077. (assign, reg5, ":accumulated_tariffs"),
  16078. (display_message, "@{!}New tariffs at {s4} = {reg4}, total = {reg5}"),
  16079. (try_end),
  16080.  
  16081. (party_set_slot, ":center_no", slot_center_accumulated_tariffs, ":accumulated_tariffs"),
  16082. ##diplomacy start+
  16083. #If economic changes are enabled, 50% chance that the origin rather than
  16084. #the destination will receive the chance for prosperity increase.
  16085. (assign, ":benefit_center", ":center_no"),
  16086. (try_begin),
  16087. #Economic changes must be enabled
  16088. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  16089. #verify the origin is a real town or village and not a placeholder value
  16090. (ge, ":origin", 0),
  16091. (this_or_next|is_between, ":origin", towns_begin, towns_end),
  16092. (this_or_next|is_between, ":origin", villages_begin, villages_end),
  16093. (this_or_next|party_slot_eq, ":origin", slot_party_type, spt_town),
  16094. (party_slot_eq, ":origin", slot_party_type, spt_village),
  16095. (ge, ":tariffs_generated", 0),
  16096. #50% chance
  16097. (store_random_in_range, ":rand", 0, 64),
  16098. (lt, ":rand", 32),
  16099. (assign, ":benefit_center", ":origin"),
  16100. (try_end),
  16101. ##diplomacy end+
  16102. #Adding 1 to center prosperity with 18% for each caravan in that center
  16103. (try_begin),
  16104. (store_random_in_range, ":rand", 0, 80),
  16105. ##diplomacy start+ in next line, changed center_no to benefit_center
  16106. (call_script, "script_center_get_goods_availability", ":benefit_center"),
  16107. ##diplomacy end+
  16108. (assign, ":hardship_index", reg0),
  16109. (gt, ":rand", ":hardship_index"),
  16110. (try_begin),
  16111. (store_random_in_range, ":rand", 0, 100),
  16112. (gt, ":rand", 82),
  16113. ##diplomacy start+ in next line, changed center_no to benefit_center
  16114. (call_script, "script_change_center_prosperity", ":benefit_center", 1),
  16115. ##diplomacy end+
  16116. (val_add, "$newglob_total_prosperity_from_caravan_trade", 1),
  16117. (try_end),
  16118. (try_end),
  16119. ]),
  16120.  
  16121. #script_party_calculate_regular_strength:
  16122. # INPUT:
  16123. # param1: Party-id
  16124. ("party_calculate_regular_strength",
  16125. [
  16126. (store_script_param_1, ":party"), #Party_id
  16127.  
  16128. (assign, reg0,0),
  16129. (party_get_num_companion_stacks, ":num_stacks",":party"),
  16130. (try_for_range, ":i_stack", 0, ":num_stacks"),
  16131. (party_stack_get_troop_id, ":stack_troop", ":party", ":i_stack"),
  16132. (neg|troop_is_hero, ":stack_troop"),
  16133. (store_character_level, ":stack_strength", ":stack_troop"),
  16134. (val_add, ":stack_strength", 12),
  16135. (val_mul, ":stack_strength", ":stack_strength"),
  16136. (val_div, ":stack_strength", 100),
  16137. (party_stack_get_size, ":stack_size",":party",":i_stack"),
  16138. (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
  16139. (val_sub, ":stack_size", ":num_wounded"),
  16140. (val_mul, ":stack_strength", ":stack_size"),
  16141. (val_add,reg0, ":stack_strength"),
  16142. (try_end),
  16143. ]),
  16144.  
  16145.  
  16146.  
  16147.  
  16148. #script_party_calculate_strength:
  16149. # INPUT: arg1 = party_id, arg2 = exclude leader
  16150. # OUTPUT: reg0 = strength
  16151.  
  16152. ("party_calculate_strength",
  16153. [
  16154. (store_script_param_1, ":party"), #Party_id
  16155. (store_script_param_2, ":exclude_leader"), #Party_id
  16156.  
  16157. (assign, reg0,0),
  16158. (party_get_num_companion_stacks, ":num_stacks", ":party"),
  16159. (assign, ":first_stack", 0),
  16160. (try_begin),
  16161. (neq, ":exclude_leader", 0),
  16162. (assign, ":first_stack", 1),
  16163. (try_end),
  16164. (try_for_range, ":i_stack", ":first_stack", ":num_stacks"),
  16165. (party_stack_get_troop_id, ":stack_troop",":party", ":i_stack"),
  16166. (store_character_level, ":stack_strength", ":stack_troop"),
  16167. (val_add, ":stack_strength", 4), #new was 12 (patch 1.125)
  16168. (val_mul, ":stack_strength", ":stack_strength"),
  16169. (val_mul, ":stack_strength", 2), #new (patch 1.125)
  16170. (val_div, ":stack_strength", 100),
  16171. (val_max, ":stack_strength", 1), #new (patch 1.125)
  16172. (try_begin),
  16173. (neg|troop_is_hero, ":stack_troop"),
  16174. (party_stack_get_size, ":stack_size",":party",":i_stack"),
  16175. (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
  16176. (val_sub, ":stack_size", ":num_wounded"),
  16177. (val_mul, ":stack_strength", ":stack_size"),
  16178. (else_try),
  16179. (troop_is_wounded, ":stack_troop"), #hero & wounded
  16180. (assign, ":stack_strength", 0),
  16181. (try_end),
  16182. (val_add, reg0, ":stack_strength"),
  16183. (try_end),
  16184. (party_set_slot, ":party", slot_party_cached_strength, reg0),
  16185. ]),
  16186.  
  16187.  
  16188. #script_loot_player_items:
  16189. # INPUT: arg1 = enemy_party_no
  16190. # Output: none
  16191. ("loot_player_items",
  16192. [
  16193. (store_script_param, ":enemy_party_no", 1),
  16194. ##diplomacy start+ some enemy lords will not loot the personal equipment of a player who surrendered
  16195. (assign, ":save_reg0", reg0),
  16196. (assign, ":extra_gold", 0),
  16197. #I am not sure if this is historical or not, but it gives the player a reason to
  16198. #surrender (rather than fight to the end) even before permanent attribute loss is
  16199. #a possibility (or even if it is disabled outright).
  16200. #
  16201. #This also adds another layer of interaction, and makes different lords feel
  16202. #different from each other.
  16203. #
  16204. #Other changes:
  16205. # Enemy lords will receive gold they loot from the player,
  16206. # Books will not be looted from the player (it turns out a bug was responsible for this being possible)
  16207. # The enemy leader's looting skill will affect the amount of gold lootable.
  16208. (assign, ":merciful", 0),
  16209. (assign, ":party_leader", -1),
  16210. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  16211. (try_begin),
  16212. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),#only use this if it is explicitly enabled
  16213. #Possibility the player's personal equipment will be untouched if he surrendered
  16214. (ge, "$g_player_surrenders", 1),
  16215. (gt, ":enemy_party_no", 0),
  16216. (party_stack_get_troop_id, ":party_leader", ":enemy_party_no", 0),
  16217. #(party_slot_eq, ":enemy_party_no", slot_party_type, spt_kingdom_hero_party),
  16218. (ge, ":party_leader", walkers_end),
  16219. (troop_is_hero, ":party_leader"),
  16220. (call_script, "script_troop_get_player_relation", ":party_leader"),
  16221. (assign, ":relation", reg0),
  16222. (assign, ":probability_modifier", 0),
  16223. (try_begin),
  16224. #Upstanding lords are inclined to honor deals in general, and will automatically
  16225. #do so with honorable lords they do not extremely dislike. However, this does not
  16226. #extend to commoners.
  16227. (troop_slot_ge, "trp_player", slot_troop_banner_scene_prop, 1),# the player has a coat of arms
  16228. (troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_upstanding),
  16229. (val_max, ":probability_modifier", 10),#set to +10 unless already higher
  16230. #They will automatically honor deals with the honorable, if they do not
  16231. #excessively dislike them.
  16232. (ge, "$player_honor", 1),
  16233. (val_add, reg0, 10),
  16234. (val_clamp, reg0, 11, 21),
  16235. (val_max, ":probability_modifier", reg0),#set somewhere from +11 to +20 unless already higher
  16236. (ge, ":relation", -10),
  16237. (assign, ":merciful", 1),
  16238. (else_try),
  16239. #Martial lords are inclined to honor deals with lords who likewise follow the rules of war,
  16240. #and will do so as long as they are neutral or friendly towards them. This does not extend
  16241. #to commoners.
  16242. (troop_slot_ge, "trp_player", slot_troop_banner_scene_prop, 1),# the player has a coat of arms
  16243. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_moralist),
  16244. (troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_martial),
  16245. (ge, "$player_honor", 1),
  16246. (assign, reg0, "$player_honor"),
  16247. (val_clamp, reg0, 1, 6),
  16248. (val_max, ":probability_modifier", reg0),#set somewhere from +1 to +5 unless already higher
  16249. (ge, ":relation", 0),
  16250. (assign, ":merciful", 1),
  16251. (else_try),
  16252. #Good-natured lords are inclined to honor deals with everyone, commoner or not.
  16253. #They will do so automatically unless they particularly dislike someone.
  16254. #This also goes for Moralist ladies if they someone end up accepting your surrender.
  16255. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_goodnatured),
  16256. (troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_moralist),
  16257. (val_max, ":probability_modifier", 21),#set to +20 unless already higher
  16258. (ge, ":relation", -10),
  16259. (assign, ":merciful", 1),
  16260. (else_try),
  16261. #Honest lords are inclined honor deals with everyone, commoner or not.
  16262. #They will do so automatically unless they particularly dislike someone.
  16263. (call_script, "script_dplmc_get_troop_morality_value", ":party_leader", tmt_honest),
  16264. (assign, ":honest_val", reg0),
  16265. (ge, ":honest_val", 1),
  16266. (store_add, reg0, ":honest_val", 14),
  16267. (val_max, ":probability_modifier", reg0),#set to (14 + honesty ) unless already higher
  16268. (ge, "$player_honor", 1),
  16269. (val_mul, reg0, -1),
  16270. (ge, ":relation", reg0),
  16271. (assign, ":merciful", 1),
  16272. (else_try),
  16273. (try_begin),
  16274. #Penalty instead of bonus for vicious lord personalities, unless they are
  16275. #explicitly set as honest. (None are by default.)
  16276. (lt, ":honest_val", 1),#Must either be negative or not given
  16277. (this_or_next|lt, ":honest_val", 0),
  16278. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_debauched),
  16279. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_selfrighteous),
  16280. (this_or_next|troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_cunning),
  16281. (troop_slot_eq, ":party_leader", slot_lord_reputation_type, lrep_quarrelsome),
  16282. (val_min, ":probability_modifier", -10),#set to -10 unless already lower
  16283. (try_end),
  16284. #Now store into reg0 the percent chance of mercy
  16285. (try_begin),
  16286. (le, ":reduce_campaign_ai", 0),#Hard: base chance 25% + relation
  16287. (store_add, reg0, ":relation", 25),
  16288. (else_try),
  16289. (eq, ":reduce_campaign_ai", 1),#Medium: base chance 50% + relation
  16290. (store_add, reg0, ":relation", 50),
  16291. (else_try),
  16292. (ge, ":reduce_campaign_ai", 2),#Easy: base chance 75% + relation
  16293. (store_add, reg0, ":relation", 75),
  16294. (try_end),
  16295. (val_add, reg0, ":probability_modifier"),#modify the chance based on the captor's personality
  16296. (val_max, reg0, ":probability_modifier"),#at least this much of a chance
  16297. (val_max, reg0, 5),#at least a 5% chance
  16298. (store_random_in_range, ":probability_modifier", 1, 101),
  16299. (lt, reg0, ":probability_modifier"),
  16300. (assign, ":merciful", 1),
  16301. (try_end),
  16302. (else_try),
  16303. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),#only use this if it is explicitly enabled
  16304. #Surrendered to a non-hero party
  16305. (gt, ":enemy_party_no", 0),
  16306. (ge, "$g_player_surrenders", 1),
  16307. (store_random_in_range, reg0, 1, 101),
  16308. (this_or_next|lt, reg0, 25),#Hard: 25% chance
  16309. (ge, ":reduce_campaign_ai", 1),
  16310. (this_or_next|lt, reg0, 50),#Medium: 50% chance
  16311. (ge, ":reduce_campaign_ai", 2),
  16312. (lt, reg0, 75),#Easy: 75% chance
  16313. (assign, ":merciful", 1),
  16314. (try_end),
  16315. (try_begin),
  16316. (ge, "$cheat_mode", 1),
  16317. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),#don't display when nonapplicable
  16318. (assign, ":save_reg1", reg1),
  16319. (assign, reg0, "$g_player_surrenders"),
  16320. (assign, reg1, ":merciful"),
  16321. (display_message, "@{!} DEBUG loot_player_items: g_player_surrenders = {reg0}, merciful = {reg1}"),
  16322. (assign, reg1, ":save_reg1"),
  16323. (try_end),
  16324. ##diplomacy end+
  16325. (troop_get_inventory_capacity, ":inv_cap", "trp_player"),
  16326. (try_for_range, ":i_slot", 0, ":inv_cap"),
  16327. (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),
  16328. (ge, ":item_id", 0),
  16329. ##diplomacy start+ looting changes
  16330. (neg|is_between, ":item_id", books_begin, books_end),#shouldn't be necessary, but just in case
  16331. (assign, ":randomness", 0),#properly initialize variables
  16332. ##diplomacy end+
  16333. (troop_get_inventory_slot_modifier, ":item_modifier", "trp_player", ":i_slot"),
  16334. (try_begin),
  16335. (is_between, ":item_id", trade_goods_begin, trade_goods_end),
  16336. (assign, ":randomness", 20),
  16337. (else_try),
  16338. (this_or_next|is_between, ":item_id", horses_begin, horses_end),
  16339. (this_or_next|eq, ":item_id", "itm_warhorse_sarranid"),
  16340. (eq, ":item_id", "itm_warhorse_steppe"),
  16341. (assign, ":randomness", 15),
  16342. (else_try),
  16343. (this_or_next|is_between, ":item_id", weapons_begin, weapons_end),
  16344. (is_between, ":item_id", ranged_weapons_begin, ranged_weapons_end),
  16345. (assign, ":randomness", 5),
  16346. (else_try),
  16347. (this_or_next|is_between, ":item_id", armors_begin, armors_end),
  16348. (this_or_next|eq, ":item_id", "itm_plate_boots"), #added to the end because of not breaking the save games
  16349. (is_between, ":item_id", shields_begin, shields_end),
  16350. (assign, ":randomness", 5),
  16351. (try_end),
  16352. (store_random_in_range, ":random_no", 0, 100),
  16353. (lt, ":random_no", ":randomness"),
  16354. ##diplomacy start+ changes
  16355. (try_begin),
  16356. #If this option is enabled, personal items may be spared, and instead
  16357. #sligthly more gold is taken (but not as much as the thing's worth).
  16358. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  16359. (ge, ":merciful", 1),
  16360. (is_between, ":i_slot", ek_item_0, dplmc_ek_alt_items_end),
  16361. (assign, ":random_no", 101),
  16362. #(store_item_value, reg0, ":item_id"),#don't bother with imods #don't bother with the rest of this
  16363. #(val_div, reg0, 2),
  16364. #(ge, reg0, 1),
  16365. #(val_add, ":extra_gold", reg0),##disable, as it defeats the point!
  16366. (try_end),
  16367. (lt, ":random_no", ":randomness"),
  16368. ##diplomacy end+
  16369. (troop_remove_item, "trp_player", ":item_id"),
  16370.  
  16371. (try_begin),
  16372. (gt, ":enemy_party_no", 0),
  16373. (party_get_slot, ":cur_loot_slot", ":enemy_party_no", slot_party_next_looted_item_slot),
  16374. (val_add, ":cur_loot_slot", slot_party_looted_item_1),
  16375. (party_set_slot, ":enemy_party_no", ":cur_loot_slot", ":item_id"),
  16376. (val_sub, ":cur_loot_slot", slot_party_looted_item_1),
  16377. (val_add, ":cur_loot_slot", slot_party_looted_item_1_modifier),
  16378. (party_set_slot, ":enemy_party_no", ":cur_loot_slot", ":item_modifier"),
  16379. (val_sub, ":cur_loot_slot", slot_party_looted_item_1_modifier),
  16380. (val_add, ":cur_loot_slot", 1),
  16381. (val_mod, ":cur_loot_slot", num_party_loot_slots),
  16382. (party_set_slot, ":enemy_party_no", slot_party_next_looted_item_slot, ":cur_loot_slot"),
  16383. (try_end),
  16384. (try_end),
  16385. (store_troop_gold, ":cur_gold", "trp_player"),
  16386. (store_div, ":max_lost", ":cur_gold", 5),
  16387. (store_div, ":min_lost", ":cur_gold", 10),
  16388. (store_random_in_range, ":lost_gold", ":min_lost", ":max_lost"),
  16389. ##diplomacy start+
  16390. (try_begin),
  16391. #This does nothing unless the option is enabled.
  16392. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),
  16393. #add extra gold from enemy's looting skill
  16394. (gt, ":enemy_party_no", 0),
  16395. (party_get_skill_level, reg0, ":enemy_party_no", "skl_looting"),
  16396. (val_clamp, reg0, 0, 11),#allow range +0 to +10
  16397. (val_add, reg0, 10),
  16398. (val_mul, ":lost_gold", reg0),
  16399. (val_div, ":lost_gold", 10),
  16400. #Add any gold from items not looted.
  16401. (val_add, ":lost_gold", ":extra_gold"),
  16402. #gold looted can't exceed player's actual gold
  16403. (val_min, ":lost_gold", ":cur_gold"),
  16404. (val_max, ":lost_gold", 0),
  16405. (try_end),
  16406. #diplomacy end+
  16407. (troop_remove_gold, "trp_player", ":lost_gold"),
  16408. ##diplomacy start+
  16409. (try_begin),
  16410. #add looted gold to the enemy, if he's a valid hero
  16411. (is_between, ":party_leader", heroes_begin, heroes_end),
  16412. (troop_is_hero, ":party_leader"),
  16413. (neq, ":party_leader", "trp_player"),
  16414. (neq, ":party_leader", "trp_kingdom_heroes_including_player_begin"),
  16415. (ge, ":lost_gold", 1),
  16416. #(call_script, "script_troop_add_gold", ":party_leader", ":lost_gold"),#add looted gold to enemy
  16417. (troop_get_slot, reg0, ":party_leader", slot_troop_wealth),
  16418. (val_add, reg0, ":lost_gold"),
  16419. (val_max, reg0, 0),
  16420. (troop_set_slot, ":party_leader", slot_troop_wealth, reg0),#add looted gold to enemy
  16421. (try_end),
  16422. (assign, reg0, ":save_reg0"),#revert register
  16423. ##diplomacy end+
  16424. ]),
  16425.  
  16426.  
  16427. #script_party_calculate_loot:
  16428. # INPUT:
  16429. # param1: Party-id
  16430. # Returns num looted items in reg0
  16431. ("party_calculate_loot",
  16432. [
  16433. (store_script_param_1, ":enemy_party"), #Enemy Party_id
  16434.  
  16435. (call_script, "script_calculate_main_party_shares"),
  16436. (assign, ":num_player_party_shares", reg0),
  16437.  
  16438. (try_for_range, ":i_loot", 0, num_party_loot_slots),
  16439. (store_add, ":cur_loot_slot", ":i_loot", slot_party_looted_item_1),
  16440. (party_get_slot, ":item_no", "$g_enemy_party", ":cur_loot_slot"),
  16441. (gt, ":item_no", 0),
  16442. (party_set_slot, "$g_enemy_party", ":cur_loot_slot", 0),
  16443. (val_sub, ":cur_loot_slot", slot_party_looted_item_1),
  16444. (val_add, ":cur_loot_slot", slot_party_looted_item_1_modifier),
  16445. (party_get_slot, ":item_modifier", "$g_enemy_party", ":cur_loot_slot"),
  16446. (troop_add_item, "trp_temp_troop", ":item_no", ":item_modifier"),
  16447. (try_end),
  16448. (party_set_slot, "$g_enemy_party", slot_party_next_looted_item_slot, 0),
  16449.  
  16450. (assign, ":num_looted_items",0),
  16451. (try_begin),
  16452. (this_or_next|party_slot_eq, "$g_enemy_party", slot_party_type, spt_kingdom_caravan),
  16453. (this_or_next|party_slot_eq, "$g_enemy_party", slot_party_type, spt_bandit_lair),
  16454. (party_slot_eq, "$g_enemy_party", slot_party_type, spt_village_farmer),
  16455. (store_mul, ":plunder_amount", player_loot_share, 30),
  16456. (val_mul, ":plunder_amount", "$g_strength_contribution_of_player"),
  16457. (val_div, ":plunder_amount", 100),
  16458. (val_div, ":plunder_amount", ":num_player_party_shares"),
  16459. (try_begin),
  16460. (party_slot_eq, "$g_enemy_party", slot_party_type, spt_kingdom_caravan),
  16461. (reset_item_probabilities, 100),
  16462. (assign, ":range_min", trade_goods_begin),
  16463. (assign, ":range_max", trade_goods_end),
  16464. (else_try),
  16465. (party_slot_eq, "$g_enemy_party", slot_party_type, spt_bandit_lair),
  16466. (val_div, ":plunder_amount", 2),
  16467. (reset_item_probabilities, 1),
  16468. (assign, ":range_min", food_begin),
  16469. (assign, ":range_max", food_end),
  16470. (else_try),
  16471. (val_div, ":plunder_amount", 5),
  16472. (reset_item_probabilities, 1),
  16473. (assign, ":range_min", food_begin),
  16474. (assign, ":range_max", food_end),
  16475. (try_end),
  16476. (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  16477. (try_for_range, ":cur_goods", ":range_min", ":range_max"),
  16478. (try_begin),
  16479. (neg|party_slot_eq, "$g_enemy_party", slot_party_type, spt_bandit_lair),
  16480. (store_add, ":cur_price_slot", ":cur_goods", ":item_to_price_slot"),
  16481. (party_get_slot, ":cur_price", "$g_enemy_party", ":cur_price_slot"),
  16482. (else_try),
  16483. (assign, ":cur_price", maximum_price_factor),
  16484. (val_add, ":cur_price", average_price_factor),
  16485. (val_div, ":cur_price", 3),
  16486. (try_end),
  16487.  
  16488. (assign, ":cur_probability", 100),
  16489. (val_mul, ":cur_probability", average_price_factor),
  16490. (val_div, ":cur_probability", ":cur_price"),
  16491. (assign, reg0, ":cur_probability"),
  16492. (set_item_probability_in_merchandise, ":cur_goods", ":cur_probability"),
  16493. (try_end),
  16494. (troop_add_merchandise, "trp_temp_troop", itp_type_goods, ":plunder_amount"),
  16495. (val_add, ":num_looted_items", ":plunder_amount"),
  16496. (try_end),
  16497.  
  16498. #Now loot the defeated party
  16499. (store_mul, ":loot_probability", player_loot_share, 3),
  16500. (val_mul, ":loot_probability", "$g_strength_contribution_of_player"),
  16501. (party_get_skill_level, ":player_party_looting", "p_main_party", "skl_looting"),
  16502. (val_add, ":player_party_looting", 10),
  16503. (val_mul, ":loot_probability", ":player_party_looting"),
  16504. (val_div, ":loot_probability", 10),
  16505. (val_div, ":loot_probability", ":num_player_party_shares"),
  16506.  
  16507. (party_get_num_companion_stacks, ":num_stacks",":enemy_party"),
  16508. (try_for_range, ":i_stack", 0, ":num_stacks"),
  16509. (party_stack_get_troop_id, ":stack_troop",":enemy_party",":i_stack"),
  16510. (neg|troop_is_hero, ":stack_troop"),
  16511. (party_stack_get_size, ":stack_size",":enemy_party",":i_stack"),
  16512. (try_for_range, ":unused", 0, ":stack_size"),
  16513. (troop_loot_troop, "trp_temp_troop", ":stack_troop", ":loot_probability"),
  16514. (try_end),
  16515. (try_end),
  16516.  
  16517. #(troop_get_inventory_capacity, ":inv_cap", "trp_temp_troop"),
  16518. #(try_for_range, ":i_slot", 0, ":inv_cap"),
  16519. # (troop_get_inventory_slot, ":item_id", "trp_temp_troop", ":i_slot"),
  16520. # (is_between, ":item_id", horses_begin, horses_end),
  16521. # (troop_set_inventory_slot, "trp_temp_troop", ":i_slot", -1),
  16522. #(try_end),
  16523.  
  16524. (troop_get_inventory_capacity, ":inv_cap", "trp_temp_troop"),
  16525. (try_for_range, ":i_slot", 0, ":inv_cap"),
  16526. (troop_get_inventory_slot, ":item_id", "trp_temp_troop", ":i_slot"),
  16527. (ge, ":item_id", 0),
  16528. (val_add, ":num_looted_items", 1),
  16529. (try_end),
  16530.  
  16531. (assign, reg0, ":num_looted_items"),
  16532. ]),
  16533.  
  16534. #script_calculate_main_party_shares:
  16535. # INPUT:
  16536. # Returns number of player party shares in reg0
  16537. ("calculate_main_party_shares",
  16538. [
  16539. (assign, ":num_player_party_shares", player_loot_share),
  16540. # Add shares for player's party
  16541. (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  16542. (try_for_range, ":i_stack", 1, ":num_stacks"),
  16543. (party_stack_get_troop_id, ":stack_troop", "p_main_party", ":i_stack"),
  16544. (try_begin),
  16545. (neg|troop_is_hero, ":stack_troop"),
  16546. (party_stack_get_size, ":stack_size","p_main_party",":i_stack"),
  16547. (val_add, ":num_player_party_shares", ":stack_size"),
  16548. (else_try),
  16549. (val_add, ":num_player_party_shares", hero_loot_share),
  16550. (try_end),
  16551. (try_end),
  16552.  
  16553. (assign, reg0, ":num_player_party_shares"),
  16554. ]),
  16555.  
  16556. #script_party_give_xp_and_gold:
  16557. # INPUT:
  16558. # param1: destroyed Party-id
  16559. # calculates and gives player paty's share of gold and xp.
  16560.  
  16561. ("party_give_xp_and_gold",
  16562. [
  16563. (store_script_param_1, ":enemy_party"), #Party_id
  16564.  
  16565. (call_script, "script_calculate_main_party_shares"),
  16566. (assign, ":num_player_party_shares", reg0),
  16567.  
  16568. (assign, ":total_gain", 0),
  16569. (party_get_num_companion_stacks, ":num_stacks",":enemy_party"),
  16570. (try_for_range, ":i_stack", 0, ":num_stacks"),
  16571. (party_stack_get_troop_id, ":stack_troop",":enemy_party",":i_stack"),
  16572. (neg|troop_is_hero, ":stack_troop"),
  16573. (party_stack_get_size, ":stack_size",":enemy_party",":i_stack"),
  16574. (store_character_level, ":level", ":stack_troop"),
  16575. (store_add, ":gain", ":level", 10),
  16576. (val_mul, ":gain", ":gain"),
  16577. (val_div, ":gain", 10),
  16578. (store_mul, ":stack_gain", ":gain", ":stack_size"),
  16579. (val_add, ":total_gain", ":stack_gain"),
  16580. (try_end),
  16581.  
  16582. (val_mul, ":total_gain", "$g_strength_contribution_of_player"),
  16583. (val_div, ":total_gain", 100),
  16584.  
  16585. (val_min, ":total_gain", 40000), #eliminate negative results
  16586.  
  16587. (assign, ":player_party_xp_gain", ":total_gain"),
  16588.  
  16589. (store_random_in_range, ":r", 50, 100),
  16590. (val_mul, ":player_party_xp_gain", ":r"),
  16591. (val_div, ":player_party_xp_gain", 100),
  16592.  
  16593. (party_add_xp, "p_main_party", ":player_party_xp_gain"),
  16594.  
  16595. (store_mul, ":player_gold_gain", ":total_gain", player_loot_share),
  16596. (val_min, ":player_gold_gain", 60000), #eliminate negative results
  16597. (store_random_in_range, ":r", 50, 100),
  16598. (val_mul, ":player_gold_gain", ":r"),
  16599. (val_div, ":player_gold_gain", 100),
  16600. (val_div, ":player_gold_gain", ":num_player_party_shares"),
  16601.  
  16602. #add gold now
  16603. (party_get_num_companion_stacks, ":num_stacks","p_main_party"),
  16604. (try_for_range, ":i_stack", 0, ":num_stacks"),
  16605. (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
  16606. (try_begin),
  16607. (troop_is_hero, ":stack_troop"),
  16608. (call_script, "script_troop_add_gold", ":stack_troop", ":player_gold_gain"),
  16609. (try_end),
  16610. (try_end),
  16611. ]),
  16612.  
  16613.  
  16614. #script_setup_troop_meeting:
  16615. # INPUT:
  16616. # param1: troop_id with which meeting will be made.
  16617. # param2: troop_dna (optional)
  16618.  
  16619. ("setup_troop_meeting",
  16620. [
  16621. (store_script_param_1, ":meeting_troop"),
  16622. (store_script_param_2, ":troop_dna"),
  16623. (call_script, "script_get_meeting_scene"),
  16624. (assign, ":meeting_scene", reg0),
  16625. (modify_visitors_at_site,":meeting_scene"),
  16626. (reset_visitors),
  16627. (set_visitor,0,"trp_player"),
  16628. (try_begin),
  16629. (gt, ":troop_dna", -1),
  16630. (set_visitor,17,":meeting_troop",":troop_dna"),
  16631. (else_try),
  16632. (set_visitor,17,":meeting_troop"),
  16633. (try_end),
  16634. (set_jump_mission,"mt_conversation_encounter"),
  16635. (jump_to_scene,":meeting_scene"),
  16636. (change_screen_map_conversation, ":meeting_troop"),
  16637. ]),
  16638.  
  16639. #script_setup_party_meeting:
  16640. # INPUT:
  16641. # param1: Party-id with which meeting will be made.
  16642.  
  16643. ("setup_party_meeting",
  16644. [
  16645. (store_script_param_1, ":meeting_party"),
  16646. (try_begin),
  16647. (lt, "$g_encountered_party_relation", 0), #hostile
  16648. # (call_script, "script_music_set_situation_with_culture", mtf_sit_encounter_hostile),
  16649. (try_end),
  16650. (call_script, "script_get_meeting_scene"), (assign, ":meeting_scene", reg0),
  16651. (modify_visitors_at_site,":meeting_scene"),(reset_visitors),
  16652. (set_visitor,0,"trp_player"),
  16653. (party_stack_get_troop_id, ":meeting_troop",":meeting_party",0),
  16654. (party_stack_get_troop_dna,":troop_dna",":meeting_party",0),
  16655. (set_visitor,17,":meeting_troop",":troop_dna"),
  16656. (set_jump_mission,"mt_conversation_encounter"),
  16657. (jump_to_scene,":meeting_scene"),
  16658. (change_screen_map_conversation, ":meeting_troop"),
  16659. ]),
  16660.  
  16661. #script_get_meeting_scene:
  16662. # INPUT: none
  16663. # OUTPUT: reg0 contain suitable scene_no
  16664.  
  16665. ("get_meeting_scene",
  16666. [
  16667. (party_get_current_terrain, ":terrain_type", "p_main_party"),
  16668. (assign, ":scene_to_use", "scn_random_scene"),
  16669. (try_begin),
  16670. (eq, ":terrain_type", rt_steppe),
  16671. (assign, ":scene_to_use", "scn_meeting_scene_steppe"),
  16672. (else_try),
  16673. (eq, ":terrain_type", rt_plain),
  16674. (assign, ":scene_to_use", "scn_meeting_scene_plain"),
  16675. (else_try),
  16676. (eq, ":terrain_type", rt_snow),
  16677. (assign, ":scene_to_use", "scn_meeting_scene_snow"),
  16678. (else_try),
  16679. (eq, ":terrain_type", rt_desert),
  16680. (assign, ":scene_to_use", "scn_meeting_scene_desert"),
  16681. (else_try),
  16682. (eq, ":terrain_type", rt_steppe_forest),
  16683. (assign, ":scene_to_use", "scn_meeting_scene_steppe"),
  16684. (else_try),
  16685. (eq, ":terrain_type", rt_forest),
  16686. (assign, ":scene_to_use", "scn_meeting_scene_plain"),
  16687. (else_try),
  16688. (eq, ":terrain_type", rt_snow_forest),
  16689. (assign, ":scene_to_use", "scn_meeting_scene_snow"),
  16690. (else_try),
  16691. (eq, ":terrain_type", rt_desert_forest),
  16692. (assign, ":scene_to_use", "scn_meeting_scene_desert"),
  16693. (else_try),
  16694. (assign, ":scene_to_use", "scn_meeting_scene_plain"),
  16695. (try_end),
  16696. (assign, reg0, ":scene_to_use"),
  16697. ]),
  16698.  
  16699. #script_party_remove_all_companions:
  16700. # INPUT:
  16701. # param1: Party-id from which companions will be removed.
  16702. # "$g_move_heroes" : controls if heroes will also be removed.
  16703.  
  16704. ("party_remove_all_companions",
  16705. [
  16706. (store_script_param_1, ":party"), #Source Party_id
  16707. (party_get_num_companion_stacks, ":num_companion_stacks",":party"),
  16708. (try_for_range_backwards, ":stack_no", 0, ":num_companion_stacks"),
  16709. (party_stack_get_troop_id, ":stack_troop",":party",":stack_no"),
  16710.  
  16711. (party_stack_get_size, ":stack_size", ":party", ":stack_no"),
  16712.  
  16713. (try_begin),
  16714. ##diplomacy start+
  16715. #To avoid problems with temporarily-rejoined promoted companions and ladies
  16716. #suddenly forgetting that they're lords, check this.
  16717. #If the troop is a companion or a kingdom lady...
  16718. (this_or_next|is_between, ":stack_troop", companions_begin, companions_end),
  16719. (is_between, ":stack_troop", kingdom_ladies_begin, kingdom_ladies_end),
  16720. #...but has since become a lord
  16721. (this_or_next|troop_slot_eq, ":stack_troop", slot_troop_playerparty_history, dplmc_pp_history_granted_fief),
  16722. (this_or_next|troop_slot_eq, ":stack_troop", slot_troop_playerparty_history, dplmc_pp_history_lord_rejoined),
  16723. (troop_slot_eq, ":stack_troop", slot_troop_occupation, slto_kingdom_hero),
  16724. #...and the troop would be removed
  16725. (this_or_next|eq, "$g_move_heroes", 1),
  16726. (eq, ":party", "p_main_party"),
  16727. #Then set up the troop as if it was a lord that was just defeated but escaped
  16728. (troop_set_slot, ":stack_troop", slot_troop_occupation, slto_kingdom_hero),
  16729. (troop_set_slot, ":stack_troop", slot_troop_leaded_party, -1),
  16730. (troop_set_slot, ":stack_troop", slot_troop_prisoner_of_party, -1),
  16731. (troop_set_slot, ":stack_troop", slot_troop_cur_center, -1),
  16732. (party_remove_members, ":party", ":stack_troop", ":stack_size"),
  16733. #Fall through to standard behavior:
  16734. (else_try),
  16735. ##diplomacy end+
  16736. (troop_is_hero, ":stack_troop"),
  16737. (neg|is_between, ":stack_troop", pretenders_begin, pretenders_end),
  16738. #SB : insert fix for wife as companion, do not let her get imprisoned because dialogues aren't fun to debug
  16739. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, ":stack_troop"),
  16740. (neq, ":stack_troop", "trp_player"),
  16741. (eq, "$g_prison_heroes", 1),
  16742. (eq, ":party", "p_main_party"),
  16743. (store_random_in_range, ":succeed_escaping", 0, 2),
  16744. (neq, ":succeed_escaping", 0), #50% chance companion stays with us.
  16745. (troop_set_health, ":stack_troop", 100), #heal before leaving
  16746. (store_faction_of_party, ":enemy_faction", "$g_enemy_party"),
  16747. (assign, ":minimum_distance", 99999),
  16748. (assign, ":prison_center", -1),
  16749. (try_for_range, ":center", walled_centers_begin, walled_centers_end),
  16750. (store_faction_of_party, ":center_faction", ":center"),
  16751. (eq, ":center_faction", ":enemy_faction"),
  16752. (store_distance_to_party_from_party, ":dist", ":center", "p_main_party"),
  16753. (lt, ":dist", ":minimum_distance"),
  16754. (assign, ":minimum_distance", ":dist"),
  16755. (assign, ":prison_center", ":center"),
  16756. (try_end),
  16757. (assign, reg1, ":prison_center"),
  16758. #(display_message, "@{!}DEBUG : prison center is {reg1}"),
  16759. (try_begin),
  16760. (ge, ":prison_center", 0),
  16761. (store_random_in_range, ":succeed_escaping", 0, 4),
  16762. (neq, ":succeed_escaping", 0), #25% chance companion escapes to a tavern.
  16763. (party_add_prisoners, ":prison_center", ":stack_troop", ":stack_size"),
  16764. (troop_set_slot, ":stack_troop", slot_troop_prisoner_of_party, ":prison_center"),
  16765. (troop_set_slot, ":stack_troop", slot_troop_playerparty_history, pp_history_scattered),
  16766. (troop_set_slot, ":stack_troop", slot_troop_turned_down_twice, 0),
  16767. (troop_set_slot, ":stack_troop", slot_troop_occupation, 0),
  16768. (party_remove_members, ":party", ":stack_troop", ":stack_size"),
  16769. (try_begin),
  16770. (eq, "$cheat_mode", 1),
  16771. (str_store_party_name, s1, ":prison_center"),
  16772. (display_message, "str_your_hero_prisoned_at_s1"),
  16773. (try_end),
  16774. (else_try),
  16775. #bandits or deserters won and captured companion. So place it randomly in a town's tavern.
  16776. (assign, ":end_condition", 1000),
  16777. (try_for_range, ":unused", 0, ":end_condition"),
  16778. (store_random_in_range, ":town_no", towns_begin, towns_end),
  16779. ##diplomacy start+
  16780. #OLD (NATIVE) VERSION:
  16781. #(neg|troop_slot_eq, ":stack_troop", slot_troop_home, ":town_no"),
  16782. #(neg|troop_slot_eq, ":stack_troop", slot_troop_first_encountered, ":town_no"),
  16783. #
  16784. #NEW (DIPLOMACY+) VERSION:
  16785. #If the player owns the town, the companion is no longer in "never return" mode.
  16786. (party_get_slot, ":town_lord", ":town_no", slot_town_lord),
  16787. (this_or_next|eq, ":town_lord", "trp_player"),
  16788. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, ":town_lord"),
  16789. (neg|troop_slot_eq, ":stack_troop", slot_troop_home, ":town_no"),
  16790. (this_or_next|eq, ":town_lord", "trp_player"),
  16791. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, ":town_lord"),
  16792. (neg|troop_slot_eq, ":stack_troop", slot_troop_first_encountered, ":town_no"),
  16793. ##diplomacy end+
  16794. (assign, ":end_condition", -1),
  16795. (try_end),
  16796. (troop_set_slot, ":stack_troop", slot_troop_cur_center, ":town_no"),
  16797. (troop_set_slot, ":stack_troop", slot_troop_playerparty_history, pp_history_scattered),
  16798. (troop_set_slot, ":stack_troop", slot_troop_turned_down_twice, 0),
  16799. (troop_set_slot, ":stack_troop", slot_troop_occupation, 0),
  16800. (party_remove_members, ":party", ":stack_troop", ":stack_size"),
  16801. (try_begin),
  16802. (eq, "$cheat_mode", 1),
  16803. (str_store_troop_name, 4, ":stack_troop"),
  16804. (str_store_party_name, 5, ":town_no"),
  16805. (display_message, "@{!}{s4} is sent to {s5} after defeat"),
  16806. (try_end),
  16807. (try_end),
  16808. (else_try),
  16809. (this_or_next|neg|troop_is_hero, ":stack_troop"),
  16810. (eq, "$g_move_heroes", 1),
  16811. (party_remove_members, ":party", ":stack_troop", ":stack_size"),
  16812. (try_end),
  16813. (try_end),
  16814. ]),
  16815.  
  16816. #script_party_remove_all_prisoners:
  16817. # INPUT:
  16818. # param1: Party-id from which prisoners will be removed.
  16819. # "$g_move_heroes" : controls if heroes will also be removed.
  16820.  
  16821. ("party_remove_all_prisoners",
  16822. [
  16823. (store_script_param_1, ":party"), #Source Party_id
  16824. (party_get_num_prisoner_stacks, ":num_prisoner_stacks",":party"),
  16825. (try_for_range_backwards, ":stack_no", 0, ":num_prisoner_stacks"),
  16826. (party_prisoner_stack_get_troop_id, ":stack_troop",":party",":stack_no"),
  16827. (this_or_next|neg|troop_is_hero, ":stack_troop"),
  16828. (eq, "$g_move_heroes", 1),
  16829. (party_prisoner_stack_get_size, ":stack_size",":party",":stack_no"),
  16830. (party_remove_prisoners, ":party", ":stack_troop", ":stack_size"),
  16831. (try_end),
  16832. ]),
  16833.  
  16834. #script_party_add_party_companions:
  16835. # INPUT:
  16836. # param1: Party-id to add the second part
  16837. # param2: Party-id which will be added to the first one.
  16838. # "$g_move_heroes" : controls if heroes will also be added.
  16839.  
  16840. ("party_add_party_companions",
  16841. [
  16842. (store_script_param_1, ":target_party"), #Target Party_id
  16843. (store_script_param_2, ":source_party"), #Source Party_id
  16844. (party_get_num_companion_stacks, ":num_stacks",":source_party"),
  16845. (try_for_range, ":stack_no", 0, ":num_stacks"),
  16846. (party_stack_get_troop_id, ":stack_troop",":source_party",":stack_no"),
  16847. (this_or_next|neg|troop_is_hero, ":stack_troop"),
  16848. (eq, "$g_move_heroes", 1),
  16849. (party_stack_get_size, ":stack_size",":source_party",":stack_no"),
  16850. (party_add_members, ":target_party", ":stack_troop", ":stack_size"),
  16851. (party_stack_get_num_wounded, ":num_wounded", ":source_party", ":stack_no"),
  16852. (party_wound_members, ":target_party", ":stack_troop", ":num_wounded"),
  16853. (try_end),
  16854. ]),
  16855.  
  16856. #script_party_add_party_prisoners:
  16857. # INPUT:
  16858. # param1: Party-id to add the second party
  16859. # param2: Party-id which will be added to the first one.
  16860. # "$g_move_heroes" : controls if heroes will also be added.
  16861.  
  16862. ("party_add_party_prisoners",
  16863. [
  16864. (store_script_param_1, ":target_party"), #Target Party_id
  16865. (store_script_param_2, ":source_party"), #Source Party_id
  16866. (party_get_num_prisoner_stacks, ":num_stacks",":source_party"),
  16867. (try_for_range, ":stack_no", 0, ":num_stacks"),
  16868. (party_prisoner_stack_get_troop_id, ":stack_troop",":source_party",":stack_no"),
  16869. (this_or_next|neg|troop_is_hero, ":stack_troop"),
  16870. (eq, "$g_move_heroes", 1),
  16871. (party_prisoner_stack_get_size, ":stack_size",":source_party",":stack_no"),
  16872. (party_add_members, ":target_party", ":stack_troop", ":stack_size"),
  16873. (try_end),
  16874. ]),
  16875.  
  16876. #script_party_prisoners_add_party_companions:
  16877. # INPUT:
  16878. # param1: Party-id to add the second part
  16879. # param2: Party-id which will be added to the first one.
  16880. # "$g_move_heroes" : controls if heroes will also be added.
  16881.  
  16882. ("party_prisoners_add_party_companions",
  16883. [
  16884. (store_script_param_1, ":target_party"), #Target Party_id
  16885. (store_script_param_2, ":source_party"), #Source Party_id
  16886. (party_get_num_companion_stacks, ":num_stacks",":source_party"),
  16887. (try_for_range, ":stack_no", 0, ":num_stacks"),
  16888. (party_stack_get_troop_id, ":stack_troop",":source_party",":stack_no"),
  16889. (this_or_next|neg|troop_is_hero, ":stack_troop"),
  16890. (eq, "$g_move_heroes", 1),
  16891. (party_stack_get_size, ":stack_size",":source_party",":stack_no"),
  16892. (party_add_prisoners, ":target_party", ":stack_troop", ":stack_size"),
  16893. (try_end),
  16894. ]),
  16895.  
  16896. #script_party_prisoners_add_party_prisoners:
  16897. # INPUT:
  16898. # param1: Party-id to add the second part
  16899. # param2: Party-id which will be added to the first one.
  16900. # "$g_move_heroes" : controls if heroes will also be added.
  16901.  
  16902. ("party_prisoners_add_party_prisoners",
  16903. [
  16904. (store_script_param_1, ":target_party"), #Target Party_id
  16905. (store_script_param_2, ":source_party"), #Source Party_id
  16906. (party_get_num_prisoner_stacks, ":num_stacks",":source_party"),
  16907. (try_for_range, ":stack_no", 0, ":num_stacks"),
  16908. (party_prisoner_stack_get_troop_id, ":stack_troop",":source_party",":stack_no"),
  16909. (this_or_next|neg|troop_is_hero, ":stack_troop"),
  16910. (eq, "$g_move_heroes", 1),
  16911. (party_prisoner_stack_get_size, ":stack_size",":source_party",":stack_no"),
  16912. (party_add_prisoners, ":target_party", ":stack_troop", ":stack_size"),
  16913. (try_end),
  16914. ]),
  16915.  
  16916. # script_party_add_party:
  16917. # INPUT:
  16918. # param1: Party-id to add the second part
  16919. # param2: Party-id which will be added to the first one.
  16920. # "$g_move_heroes" : controls if heroes will also be added.
  16921.  
  16922. ("party_add_party",
  16923. [
  16924. (store_script_param_1, ":target_party"), #Target Party_id
  16925. (store_script_param_2, ":source_party"), #Source Party_id
  16926. (call_script, "script_party_add_party_companions", ":target_party", ":source_party"),
  16927. (call_script, "script_party_prisoners_add_party_prisoners", ":target_party", ":source_party"),
  16928. ]),
  16929.  
  16930.  
  16931. #script_party_copy:
  16932. # INPUT:
  16933. # param1: Party-id to copy the second party
  16934. # param2: Party-id which will be copied to the first one.
  16935.  
  16936. ("party_copy",
  16937. [
  16938. (assign, "$g_move_heroes", 1),
  16939. (store_script_param_1, ":target_party"), #Target Party_id
  16940. (store_script_param_2, ":source_party"), #Source Party_id
  16941. (party_clear, ":target_party"),
  16942. (call_script, "script_party_add_party", ":target_party", ":source_party"),
  16943. ]),
  16944.  
  16945.  
  16946. #script_clear_party_group:
  16947. # INPUT:
  16948. # param1: Party-id of the root of the group.
  16949. # This script will clear the root party and all parties attached to it recursively.
  16950.  
  16951. ("clear_party_group",
  16952. [
  16953. (store_script_param_1, ":root_party"),
  16954.  
  16955. (party_clear, ":root_party"),
  16956. (party_get_num_attached_parties, ":num_attached_parties", ":root_party"),
  16957. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  16958. (party_get_attached_party_with_rank, ":attached_party", ":root_party", ":attached_party_rank"),
  16959. (call_script, "script_clear_party_group", ":attached_party"),
  16960. (try_end),
  16961. ]),
  16962.  
  16963.  
  16964. #script_party_add_wounded_members_as_prisoners:
  16965. # INPUT:
  16966. # param1: Party-id to add the second party
  16967. # param2: Party-id which will be added to the first one.
  16968. # "$g_move_heroes" : controls if heroes will also be added.
  16969.  
  16970. ("party_add_wounded_members_as_prisoners",
  16971. [
  16972. (store_script_param_1, ":target_party"), #Target Party_id
  16973. (store_script_param_2, ":source_party"), #Source Party_id
  16974. (party_get_num_companion_stacks, ":num_stacks", ":source_party"),
  16975. (try_for_range, ":stack_no", 0, ":num_stacks"),
  16976. (party_stack_get_num_wounded, ":num_wounded", ":source_party", ":stack_no"),
  16977. (ge, ":num_wounded", 1),
  16978. (party_stack_get_troop_id, ":stack_troop", ":source_party", ":stack_no"),
  16979. (this_or_next|neg|troop_is_hero, ":stack_troop"),
  16980. (eq, "$g_move_heroes", 1),
  16981. #(party_prisoner_stack_get_size, ":stack_size",":source_party",":stack_no"),
  16982. (party_add_prisoners, ":target_party", ":stack_troop", ":num_wounded"),
  16983. (try_end),
  16984. ]),
  16985.  
  16986.  
  16987. #script_get_nonempty_party_in_group:
  16988. # INPUT:
  16989. # param1: Party-id of the root of the group.
  16990. # OUTPUT: reg0: nonempy party-id
  16991.  
  16992. ("get_nonempty_party_in_group",
  16993. [
  16994. (store_script_param_1, ":party_no"),
  16995. (party_get_num_companion_stacks, ":num_companion_stacks", ":party_no"),
  16996. (try_begin),
  16997. (gt, ":num_companion_stacks", 0),
  16998. (assign, reg0, ":party_no"),
  16999. (else_try),
  17000. (assign, reg0, -1),
  17001.  
  17002. (party_get_num_attached_parties, ":num_attached_parties", ":party_no"),
  17003. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  17004. (lt, reg0, 0),
  17005. (party_get_attached_party_with_rank, ":attached_party", ":party_no", ":attached_party_rank"),
  17006. (call_script, "script_get_nonempty_party_in_group", ":attached_party"),
  17007. (try_end),
  17008. (try_end),
  17009. ]),
  17010.  
  17011. #script_collect_prisoners_from_empty_parties:
  17012. # INPUT:
  17013. # param1: Party-id of the root of the group.
  17014. # param2: Party to collect prisoners in.
  17015. # make sure collection party is cleared before calling this.
  17016.  
  17017. ("collect_prisoners_from_empty_parties",
  17018. [
  17019. (store_script_param_1, ":party_no"),
  17020. (store_script_param_2, ":collection_party"),
  17021.  
  17022. (party_get_num_companions, ":num_companions", ":party_no"),
  17023. (try_begin),
  17024. (eq, ":num_companions", 0), #party is empty (has no companions). Collect its prisoners.
  17025. (party_get_num_prisoner_stacks, ":num_stacks",":party_no"),
  17026. (try_for_range, ":stack_no", 0, ":num_stacks"),
  17027. (party_prisoner_stack_get_troop_id, ":stack_troop", ":party_no", ":stack_no"),
  17028. (troop_is_hero, ":stack_troop"),
  17029. (party_add_members, ":collection_party", ":stack_troop", 1),
  17030. (try_end),
  17031. (try_end),
  17032. (party_get_num_attached_parties, ":num_attached_parties", ":party_no"),
  17033. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  17034. (party_get_attached_party_with_rank, ":attached_party", ":party_no", ":attached_party_rank"),
  17035. (call_script, "script_collect_prisoners_from_empty_parties", ":attached_party", ":collection_party"),
  17036. (try_end),
  17037. ]),
  17038.  
  17039. #script_change_party_morale:
  17040. # INPUT: party_no, morale_gained
  17041. # OUTPUT: none
  17042.  
  17043. ("change_party_morale",
  17044. [
  17045. (store_script_param_1, ":party_no"),
  17046. (store_script_param_2, ":morale_dif"),
  17047.  
  17048. (party_get_morale, ":cur_morale", ":party_no"),
  17049. (store_add, ":new_morale", ":cur_morale", ":morale_dif"),
  17050. (val_clamp, ":new_morale", 0, 100),
  17051. (party_set_morale, ":party_no", ":new_morale"),
  17052. (str_store_party_name, s1, ":party_no"),
  17053.  
  17054. (try_begin),
  17055. (lt, ":new_morale", ":cur_morale"),
  17056. (store_sub, reg1, ":cur_morale", ":new_morale"),
  17057. (else_try),
  17058. (gt, ":new_morale", ":cur_morale"),
  17059. (store_sub, reg1, ":new_morale", ":cur_morale"),
  17060. (try_end),
  17061. ]),
  17062.  
  17063. #script_count_casualties_and_adjust_morale:
  17064. # INPUT: none
  17065. # OUTPUT: none
  17066.  
  17067. ("count_casualties_and_adjust_morale",
  17068. [
  17069. (call_script, "script_calculate_main_party_shares"),
  17070. (assign, ":num_player_party_shares", reg0),
  17071.  
  17072. (assign, ":our_loss_score", 0),
  17073. (party_get_num_companion_stacks, ":num_stacks","p_player_casualties"),
  17074. (try_for_range, ":i_stack", 0, ":num_stacks"),
  17075. (party_stack_get_troop_id, ":stack_troop", "p_player_casualties", ":i_stack"),
  17076. (party_stack_get_size, ":stack_size", "p_player_casualties", ":i_stack"),
  17077.  
  17078. (party_stack_get_num_wounded, ":num_wounded", "p_player_casualties", ":i_stack"),
  17079. (store_mul, ":stack_size_mul_2", ":stack_size", 2),
  17080. ##diplomacy start+ Fix what appears to be a mistake in Native
  17081. #(store_sub, ":stack_size_mul_2_sub_wounded", ":num_wounded"),##OLD
  17082. (store_sub, ":stack_size_mul_2_sub_wounded", ":stack_size_mul_2", ":num_wounded"),##NEW
  17083. ##diplomacy end+
  17084.  
  17085. (store_character_level, ":level", ":stack_troop"),
  17086. (store_add, ":gain", ":level", 3),
  17087.  
  17088. #if died/wounded troop is player troop then give its level +30 while calculating troop die effect on morale
  17089. (try_begin),
  17090. (eq, ":stack_troop", "trp_player"),
  17091. (val_add, ":level", 75),
  17092. (else_try),
  17093. (troop_is_hero, ":stack_troop"),
  17094. (val_add, ":level", 50),
  17095. (try_end),
  17096.  
  17097. (val_mul, ":gain", ":gain"),
  17098. (val_div, ":gain", 10),
  17099. (assign, reg0, ":gain"),
  17100. (val_mul, ":gain", ":stack_size"),
  17101.  
  17102. (try_begin),
  17103. (neg|troop_is_hero, ":stack_troop"),
  17104. (val_mul, ":gain", ":stack_size_mul_2_sub_wounded"),
  17105. (val_div, ":gain", ":stack_size_mul_2"),
  17106. (try_end),
  17107.  
  17108. (try_begin),
  17109. (eq, "$cheat_mode", 1),
  17110. (assign, reg1, ":stack_size"),
  17111. (assign, reg2, ":gain"),
  17112. (display_message, "str_our_per_person__reg0_num_people__reg1_total_gain__reg2"),
  17113. (try_end),
  17114. (val_add, ":our_loss_score", ":gain"),
  17115. (try_end),
  17116.  
  17117. (assign, ":died_enemy_population", 0),
  17118. (assign, ":enemy_loss_score", 0),
  17119. (party_get_num_companion_stacks, ":num_stacks","p_enemy_casualties"),
  17120. (try_for_range, ":i_stack", 0, ":num_stacks"),
  17121. (party_stack_get_troop_id, ":stack_troop", "p_enemy_casualties", ":i_stack"),
  17122. (party_stack_get_size, ":stack_size", "p_enemy_casualties", ":i_stack"),
  17123.  
  17124. (party_stack_get_num_wounded, ":num_wounded", "p_enemy_casualties", ":i_stack"),
  17125. (store_mul, ":stack_size_mul_2", ":stack_size", 2),
  17126. (store_sub, ":stack_size_mul_2_sub_wounded", ":stack_size_mul_2", ":num_wounded"),
  17127.  
  17128. (store_character_level, ":level", ":stack_troop"),
  17129. (store_add, ":gain", ":level", 3),
  17130.  
  17131. #if troop is hero give extra +15 level while calculating troop die effect on morale
  17132. (try_begin),
  17133. (troop_is_hero, ":stack_troop"),
  17134. (val_add, ":level", 50),
  17135. (try_end),
  17136.  
  17137. (val_mul, ":gain", ":gain"),
  17138. (val_div, ":gain", 10),
  17139. (assign, reg0, ":gain"),
  17140. (val_mul, ":gain", ":stack_size"),
  17141.  
  17142. (try_begin),
  17143. (neg|troop_is_hero, ":stack_troop"),
  17144. (val_mul, ":gain", ":stack_size_mul_2_sub_wounded"),
  17145. (val_div, ":gain", ":stack_size_mul_2"),
  17146. (try_end),
  17147.  
  17148. (try_begin),
  17149. (eq, "$cheat_mode", 1),
  17150. (assign, reg1, ":stack_size"),
  17151. (assign, reg2, ":gain"),
  17152. (display_message, "str_ene_per_person__reg0_num_people__reg1_total_gain__reg2"),
  17153. (try_end),
  17154. (val_add, ":enemy_loss_score", ":gain"),
  17155. (val_add, ":died_enemy_population", ":stack_size"),
  17156. (try_end),
  17157.  
  17158. (assign, ":ally_loss_score", 0),
  17159. (try_begin),
  17160. (eq, "$any_allies_at_the_last_battle", 1),
  17161. (party_get_num_companion_stacks, ":num_stacks","p_ally_casualties"),
  17162. (try_for_range, ":i_stack", 0, ":num_stacks"),
  17163. (party_stack_get_troop_id, ":stack_troop", "p_ally_casualties", ":i_stack"),
  17164. (party_stack_get_size, ":stack_size", "p_ally_casualties", ":i_stack"),
  17165.  
  17166. (party_stack_get_num_wounded, ":num_wounded", "p_ally_casualties", ":i_stack"),
  17167. (store_mul, ":stack_size_mul_2", ":stack_size", 2),
  17168. ##diplomacy start+ Fix what appears to be a mistake in Native
  17169. #(store_sub, ":stack_size_mul_2_sub_wounded", ":num_wounded"),##OLD
  17170. (store_sub, ":stack_size_mul_2_sub_wounded", ":stack_size_mul_2", ":num_wounded"),##NEW
  17171. ##diplomacy end+
  17172.  
  17173. (store_character_level, ":level", ":stack_troop"),
  17174. (store_add, ":gain", ":level", 3),
  17175.  
  17176. #if troop is hero give extra +15 level while calculating troop die effect on morale
  17177. (try_begin),
  17178. (troop_is_hero, ":stack_troop"),
  17179. (val_add, ":level", 50),
  17180. (try_end),
  17181.  
  17182. (val_mul, ":gain", ":gain"),
  17183. (val_div, ":gain", 10),
  17184. (assign, reg0, ":gain"),
  17185. (val_mul, ":gain", ":stack_size"),
  17186.  
  17187. (try_begin),
  17188. (neg|troop_is_hero, ":stack_troop"),
  17189. (val_mul, ":gain", ":stack_size_mul_2_sub_wounded"),
  17190. (val_div, ":gain", ":stack_size_mul_2"),
  17191. (try_end),
  17192.  
  17193. (try_begin),
  17194. (eq, "$cheat_mode", 1),
  17195. (assign, reg1, ":stack_size"),
  17196. (assign, reg2, ":gain"),
  17197. (display_message, "str_all_per_person__reg0_num_people__reg1_total_gain__reg2"),
  17198. (try_end),
  17199. (val_add, ":ally_loss_score", ":gain"),
  17200. (try_end),
  17201. (try_end),
  17202.  
  17203. (store_add, ":our_losses", ":our_loss_score", ":ally_loss_score"),
  17204. (assign, ":enemy_losses", ":enemy_loss_score"),
  17205. (val_mul, ":our_losses", 100),
  17206.  
  17207. (try_begin),
  17208. (eq, "$cheat_mode", 1),
  17209. (assign, reg0, ":enemy_losses"),
  17210. (display_message, "@{!}DEBUGS : enemy_loses : {reg0}"),
  17211. (try_end),
  17212.  
  17213. (try_begin),
  17214. (gt, ":enemy_losses", 0),
  17215. (store_div, ":loss_ratio", ":our_losses", ":enemy_losses"),
  17216. (else_try),
  17217. (assign, ":loss_ratio", 1000),
  17218. (try_end),
  17219.  
  17220. (try_begin),
  17221. (eq, "$cheat_mode", 1),
  17222. (assign, reg1, ":loss_ratio"),
  17223. (display_message, "str_loss_ratio_is_reg1"),
  17224. (try_end),
  17225.  
  17226. (try_begin),
  17227. (neg|is_between, "$g_enemy_party", centers_begin, centers_end),
  17228. (store_sub, ":total_gain", 60, ":loss_ratio"),
  17229. (else_try),
  17230. (store_sub, ":total_gain", 100, ":loss_ratio"),
  17231. (try_end),
  17232.  
  17233. (try_begin),
  17234. (lt, ":total_gain", 0),
  17235. (val_div, ":total_gain", 2),
  17236. (try_end),
  17237.  
  17238. (try_begin),
  17239. (eq, "$cheat_mode", 1),
  17240. (assign, reg0, ":total_gain"),
  17241. (display_message, "@{!}DEBUGS1 : total_gain : {reg0}"),
  17242. (try_end),
  17243.  
  17244. (val_max, ":total_gain", -60), #total gain changes between -60(1.8+ loss ratio) and 60(0 loss ratio). We assumed average loss ratio is 0.6
  17245. (val_mul, ":total_gain", ":enemy_losses"),
  17246. (val_div, ":total_gain", 100),
  17247.  
  17248. (store_mul, ":total_enemy_morale_gain", ":total_gain", -1), #enemies get totally negative of the morale we get
  17249. (val_mul, ":total_gain", "$g_strength_contribution_of_player"),
  17250. (val_div, ":total_gain", 100),
  17251.  
  17252. (try_begin),
  17253. (eq, "$cheat_mode", 1),
  17254. (assign, reg0, ":total_gain"),
  17255. (display_message, "@{!}DEBUGS2 : total_gain : {reg0}"),
  17256. (try_end),
  17257.  
  17258. (try_begin),
  17259. (party_is_active, "$g_enemy_party"), #change enemy morale if and only if there is a valid enemy party
  17260.  
  17261. #main enemy party
  17262. (assign, ":total_enemy_population", 0),
  17263. (val_add, ":total_enemy_population", 10), #every part effect total population by number of agents they have plus 10
  17264. (party_get_num_companion_stacks, ":num_stacks", "$g_enemy_party"),
  17265. (try_for_range, ":i_stack", 0, ":num_stacks"),
  17266. (party_stack_get_troop_id, ":stack_troop", "$g_enemy_party", ":i_stack"),
  17267. (party_stack_get_size, ":stack_size", "$g_enemy_party", ":i_stack"),
  17268. (val_add, ":total_enemy_population", ":stack_size"),
  17269. (try_end),
  17270. (assign, ":main_enemy_party_population", ":total_enemy_population"),
  17271.  
  17272. #enemy attachers
  17273. (party_get_num_attached_parties, ":num_attached_parties", "$g_enemy_party"),
  17274. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  17275. (val_add, ":total_enemy_population", 10), #every part effect total population by number of agents they have plus 10
  17276. (party_get_attached_party_with_rank, ":attached_party", "$g_enemy_party", ":attached_party_rank"),
  17277. (party_get_num_companion_stacks, ":num_stacks", ":attached_party"),
  17278. (try_for_range, ":i_stack", 0, ":num_stacks"),
  17279. (party_stack_get_troop_id, ":stack_troop", ":attached_party", ":i_stack"),
  17280. (party_stack_get_size, ":stack_size", ":attached_party", ":i_stack"),
  17281. (val_add, ":total_enemy_population", ":stack_size"),
  17282. (try_end),
  17283. (try_end),
  17284.  
  17285. #(assign, reg3, ":total_enemy_population"),
  17286. #(assign, reg4, ":died_enemy_population"),
  17287. #(store_sub, ":remaining_enemy_population", ":total_enemy_population", ":died_enemy_population"),
  17288. #(val_add, ":remaining_enemy_population", 10),
  17289. #(assign, reg5, ":remaining_enemy_population"),
  17290. #(display_message, "@total : {reg3}, died : {reg4}, remaining : {reg5}"),
  17291.  
  17292. #remaining enemy population has 10+remaining soldiers in enemy party
  17293. (assign, ":remaining_enemy_population", ":total_enemy_population"),
  17294.  
  17295. (assign, reg5, ":remaining_enemy_population"),
  17296. (assign, reg6, ":total_enemy_morale_gain"),
  17297.  
  17298. (set_fixed_point_multiplier, 100),
  17299. (val_mul, ":remaining_enemy_population", 100),
  17300. (store_sqrt, ":sqrt_remaining_enemy_population", ":remaining_enemy_population"),
  17301. (val_div, ":sqrt_remaining_enemy_population", 100),
  17302. (val_div, ":total_enemy_morale_gain", ":sqrt_remaining_enemy_population"),
  17303. (val_div, ":total_enemy_morale_gain", 4),
  17304.  
  17305. (try_begin),
  17306. (eq, "$cheat_mode", 1),
  17307. (assign, reg7, ":total_enemy_morale_gain"),
  17308. (display_message, "str_total_enemy_morale_gain__reg6_last_total_enemy_morale_gain__reg7_remaining_enemy_population__reg5"),
  17309. (try_end),
  17310.  
  17311. (store_mul, ":party_morale_gain", ":total_enemy_morale_gain", ":main_enemy_party_population"),
  17312. (val_div, ":party_morale_gain", ":total_enemy_population"),
  17313.  
  17314. (try_begin),
  17315. (party_is_active, "$g_enemy_party"),
  17316.  
  17317. (call_script, "script_change_party_morale", "$g_enemy_party", ":party_morale_gain"),
  17318.  
  17319. (party_get_num_attached_parties, ":num_attached_parties", "$g_enemy_party"),
  17320. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  17321. (party_get_attached_party_with_rank, ":attached_party", "$g_enemy_party", ":attached_party_rank"),
  17322. (party_get_num_companion_stacks, ":num_stacks", ":attached_party"),
  17323. (assign, ":party_population", 0),
  17324. (try_for_range, ":i_stack", 0, ":num_stacks"),
  17325. (party_stack_get_troop_id, ":stack_troop", ":attached_party", ":i_stack"),
  17326. (party_stack_get_size, ":stack_size", ":attached_party", ":i_stack"),
  17327. (val_add, ":party_population", ":stack_size"),
  17328. (try_end),
  17329. #(store_div, ":party_ratio", ":total_enemy_population_multiplied_by_100", ":party_population"), #party ratio changes between 0..100, shows population ratio of that party among all enemy parties
  17330. (store_mul, ":party_morale_gain", ":total_enemy_morale_gain", ":party_population"),
  17331. (val_div, ":party_morale_gain", ":total_enemy_population"),
  17332. (call_script, "script_change_party_morale", ":attached_party", ":party_morale_gain"),
  17333. (try_end),
  17334. (try_end),
  17335. (try_end),
  17336.  
  17337. #Add morale
  17338. (assign, ":morale_gain", ":total_gain"),
  17339. (val_div, ":morale_gain", ":num_player_party_shares"),#if there are lots of soldiers in my party there will be less morale increase.
  17340.  
  17341. (try_begin),
  17342. (eq, "$cheat_mode", 1),
  17343. (assign, reg0, ":num_player_party_shares"),
  17344. (assign, reg1, ":total_gain"),
  17345. (display_message, "@{!}DEBUGS3 : num_player_party_shares:{reg0}, total_gain:{reg1}"),
  17346. (try_end),
  17347.  
  17348. (call_script, "script_change_player_party_morale", ":morale_gain"),
  17349.  
  17350. (store_mul, ":killed_enemies_by_our_soldiers", ":died_enemy_population", "$g_strength_contribution_of_player"),
  17351. (store_div, ":faction_morale_change", ":killed_enemies_by_our_soldiers", 8), #each 8 killed agent with any faction decreases morale of troops belong to that faction in our party by 1.
  17352. (try_begin),
  17353. (gt, ":faction_morale_change", 2000),
  17354. (assign, ":faction_morale_change", 2000),
  17355. (try_end),
  17356.  
  17357. (try_begin), #here we give positive morale to our troops of with same faction of ally party with 2/3x multipication.
  17358. (ge, "$g_ally_party", 0),
  17359.  
  17360. (store_div, ":ally_faction_morale_change", ":faction_morale_change", 3), #2/3x multipication (less than normal)
  17361. (val_mul, ":ally_faction_morale_change", 2),
  17362. (store_faction_of_party, ":ally_faction", "$g_ally_party"),
  17363. (call_script, "script_change_faction_troop_morale", ":ally_faction", ":faction_morale_change", 0),
  17364. # (faction_get_slot, ":faction_morale", ":ally_faction", slot_faction_morale_of_player_troops),
  17365. # (val_add, ":faction_morale", ":ally_faction_morale_change"),
  17366. # (faction_set_slot, ":ally_faction", slot_faction_morale_of_player_troops, ":faction_morale"),
  17367. (try_end),
  17368.  
  17369. (try_begin), #here we give positive morale to our troops of owner of rescued village's faction after saving village from bandits by x3 bonus.
  17370. (neg|party_is_active, "$g_enemy_party"),
  17371. (ge, "$current_town", 0),
  17372.  
  17373. (val_mul, ":faction_morale_change", 2), #2x bonus (more than normal)
  17374. (store_faction_of_party, ":ally_faction", "$current_town"),
  17375. #SB : script call
  17376. (call_script, "script_change_faction_troop_morale", ":ally_faction", ":faction_morale_change", 1), #SB : script call
  17377. # (faction_get_slot, ":faction_morale", ":ally_faction", slot_faction_morale_of_player_troops),
  17378. # (val_add, ":faction_morale", ":faction_morale_change"),
  17379. # (faction_set_slot, ":ally_faction", slot_faction_morale_of_player_troops, ":faction_morale"),
  17380. (else_try),
  17381. (party_is_active, "$g_enemy_party"),
  17382. (assign, ":currently_in_rebellion", 0),
  17383. (try_begin),
  17384. (eq, "$players_kingdom", "fac_player_supporters_faction"),
  17385. (neg|faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
  17386. (assign, ":currently_in_rebellion", 1),
  17387. (try_end),
  17388. (eq, ":currently_in_rebellion", 0),
  17389.  
  17390. (store_div, ":faction_morale_change", ":faction_morale_change", 3), #2/3x multipication (less than normal)
  17391. (val_mul, ":faction_morale_change", 2),
  17392. (store_faction_of_party, ":enemy_faction", "$g_enemy_party"),
  17393. (call_script, "script_change_faction_troop_morale", ":enemy_faction", ":faction_morale_change", 0), #SB : script call
  17394. # (faction_get_slot, ":faction_morale", ":enemy_faction", slot_faction_morale_of_player_troops),
  17395. # (val_sub, ":faction_morale", ":faction_morale_change"),
  17396. # (faction_set_slot, ":enemy_faction", slot_faction_morale_of_player_troops, ":faction_morale"),
  17397. (try_end),
  17398.  
  17399. ]),
  17400.  
  17401. #script_print_casualties_to_s0:
  17402. # INPUT:
  17403. # param1: Party_id, param2: 0 = use new line, 1 = use comma
  17404.  
  17405. #OUTPUT:
  17406. # string register 0.
  17407.  
  17408. ("print_casualties_to_s0",
  17409. [(store_script_param, ":party_no", 1),
  17410. (store_script_param, ":use_comma", 2),
  17411. (str_clear, s0),
  17412. (assign, ":total_reported", 0),
  17413. (assign, ":total_wounded", 0),
  17414. (assign, ":total_killed", 0),
  17415. (assign, ":total_routed", 0),
  17416. (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  17417. (try_for_range, ":i_stack", 0, ":num_stacks"),
  17418. (party_stack_get_troop_id, ":stack_troop_id", ":party_no", ":i_stack"),
  17419. (party_stack_get_size, ":stack_size", ":party_no", ":i_stack"),
  17420. (party_stack_get_num_wounded, ":num_wounded", ":party_no", ":i_stack"),
  17421. #get number of routed agent numbers
  17422. (try_begin),
  17423. (this_or_next|eq, ":party_no", "p_main_party"),
  17424. (eq, ":party_no", "p_player_casualties"),
  17425. (troop_get_slot, ":num_routed", ":stack_troop_id", slot_troop_player_routed_agents),
  17426. (troop_set_slot, ":stack_troop_id", slot_troop_player_routed_agents, 0),
  17427. (else_try),
  17428. (party_get_attached_to, ":attached_to", ":party_no"),
  17429. (this_or_next|eq, ":party_no", "p_ally_casualties"),
  17430. (ge, ":attached_to", 0),
  17431. (this_or_next|eq, ":party_no", "p_ally_casualties"),
  17432. (eq, ":attached_to", "p_main_party"),
  17433. (troop_get_slot, ":num_routed", ":stack_troop_id", slot_troop_ally_routed_agents),
  17434. (troop_set_slot, ":stack_troop_id", slot_troop_ally_routed_agents, 0),
  17435. (else_try),
  17436. (troop_get_slot, ":num_routed", ":stack_troop_id", slot_troop_enemy_routed_agents),
  17437. (troop_set_slot, ":stack_troop_id", slot_troop_enemy_routed_agents, 0),
  17438. (try_end),
  17439. (store_sub, ":num_killed", ":stack_size", ":num_wounded"),
  17440. (val_sub, ":num_killed", ":num_routed"),
  17441. (val_add, ":total_killed", ":num_killed"),
  17442. (val_add, ":total_wounded", ":num_wounded"),
  17443. (val_add, ":total_routed", ":num_routed"),
  17444. (try_begin),
  17445. (this_or_next|gt, ":num_killed", 0),
  17446. (this_or_next|gt, ":num_wounded", 0),
  17447. (gt, ":num_routed", 0),
  17448. (store_add, reg3, ":num_killed", ":num_wounded"),
  17449. (store_add, reg3, reg3, ":num_routed"),
  17450. (str_store_troop_name_by_count, s1, ":stack_troop_id", reg3),
  17451. (try_begin),
  17452. (troop_is_hero, ":stack_troop_id"),
  17453. (assign, reg3, 0),
  17454. (try_end),
  17455. (try_begin), #there are people who killed, wounded and routed.
  17456. (gt, ":num_killed", 0),
  17457. (gt, ":num_wounded", 0),
  17458. (gt, ":num_routed", 0),
  17459. (assign, reg4, ":num_killed"),
  17460. (assign, reg5, ":num_wounded"),
  17461. (assign, reg6, ":num_routed"),
  17462. (str_store_string, s2, "str_reg4_killed_reg5_wounded_reg6_routed"),
  17463. (else_try), #there are people who killed and routed.
  17464. (gt, ":num_killed", 0),
  17465. (gt, ":num_routed", 0),
  17466. (assign, reg4, ":num_killed"),
  17467. (assign, reg5, ":num_routed"),
  17468. (str_store_string, s2, "str_reg4_killed_reg5_routed"),
  17469. (else_try), #there are people who killed and wounded.
  17470. (gt, ":num_killed", 0),
  17471. (gt, ":num_wounded", 0),
  17472. (assign, reg4, ":num_killed"),
  17473. (assign, reg5, ":num_wounded"),
  17474. (str_store_string, s2, "str_reg4_killed_reg5_wounded"),
  17475. (else_try), #there are people who wounded and routed.
  17476. (gt, ":num_wounded", 0),
  17477. (gt, ":num_routed", 0),
  17478. (assign, reg4, ":num_wounded"),
  17479. (assign, reg5, ":num_routed"),
  17480. (str_store_string, s2, "str_reg4_wounded_reg5_routed"),
  17481. (else_try), #there are people who only killed.
  17482. (gt, ":num_killed", 0),
  17483. (assign, reg1, ":num_killed"),
  17484. (str_store_string, s3, "@killed"),
  17485. (str_store_string, s2, "str_reg1_blank_s3"),
  17486. (else_try), #there are people who only wounded.
  17487. (gt, ":num_wounded", 0),
  17488. (assign, reg1, ":num_wounded"),
  17489. (str_store_string, s3, "@wounded"),
  17490. (str_store_string, s2, "str_reg1_blank_s3"),
  17491. (else_try), #there are people who only routed.
  17492. (assign, reg1, ":num_routed"),
  17493. (str_store_string, s3, "str_routed"),
  17494. (str_store_string, s2, "str_reg1_blank_s3"),
  17495. (try_end),
  17496. (try_begin),
  17497. (eq, ":use_comma", 1),
  17498. (try_begin),
  17499. (eq, ":total_reported", 0),
  17500. (str_store_string, s0, "@{!}{reg3?{reg3}:} {s1} ({s2})"),
  17501. (else_try),
  17502. (str_store_string, s0, "@{!}{s0}, {reg3?{reg3}:} {s1} ({s2})"),
  17503. (try_end),
  17504. (else_try),
  17505. (str_store_string, s0, "@{!}{s0}^{reg3?{reg3}:} {s1} ({s2})"),
  17506. (try_end),
  17507. (val_add, ":total_reported", 1),
  17508. (try_end),
  17509. (try_end),
  17510. (try_begin),
  17511. (this_or_next|gt, ":total_killed", 0),
  17512. (this_or_next|gt, ":total_wounded", 0),
  17513. (gt, ":total_routed", 0),
  17514. (store_add, ":total_agents", ":total_killed", ":total_wounded"),
  17515. (val_add, ":total_agents", ":total_routed"),
  17516. (assign, reg3, ":total_agents"),
  17517. (try_begin),
  17518. (gt, ":total_killed", 0),
  17519. (gt, ":total_wounded", 0),
  17520. (gt, ":total_routed", 0),
  17521. (assign, reg4, ":total_killed"),
  17522. (assign, reg5, ":total_wounded"),
  17523. (assign, reg6, ":total_routed"),
  17524. (str_store_string, s2, "str_reg4_killed_reg5_wounded_reg6_routed"),
  17525. (else_try),
  17526. (gt, ":total_killed", 0),
  17527. (gt, ":total_routed", 0),
  17528. (assign, reg4, ":total_killed"),
  17529. (assign, reg5, ":total_routed"),
  17530. (str_store_string, s2, "str_reg4_killed_reg5_routed"),
  17531. (else_try),
  17532. (gt, ":total_killed", 0),
  17533. (gt, ":total_wounded", 0),
  17534. (assign, reg4, ":total_killed"),
  17535. (assign, reg5, ":total_wounded"),
  17536. (str_store_string, s2, "str_reg4_killed_reg5_wounded"),
  17537. (else_try),
  17538. (gt, ":total_wounded", 0),
  17539. (gt, ":total_routed", 0),
  17540. (assign, reg4, ":total_wounded"),
  17541. (assign, reg5, ":total_routed"),
  17542. (str_store_string, s2, "str_reg4_wounded_reg5_routed"),
  17543. (else_try),
  17544. (gt, ":total_killed", 0),
  17545. (str_store_string, s2, "@killed"),
  17546. (else_try),
  17547. (gt, ":total_wounded", 0),
  17548. (str_store_string, s2, "@wounded"),
  17549. (else_try),
  17550. (str_store_string, s2, "str_routed"),
  17551. (else_try),
  17552. (try_end),
  17553. (str_store_string, s0, "@{s0}^TOTAL: {reg3} ({s2})"),
  17554. (else_try),
  17555. (try_begin),
  17556. (eq, ":use_comma", 1),
  17557. (str_store_string, s0, "@None"),
  17558. (else_try),
  17559. (str_store_string, s0, "@^None"),
  17560. (try_end),
  17561. (try_end),
  17562. ]),
  17563.  
  17564. #script_write_fit_party_members_to_stack_selection
  17565. # INPUT:
  17566. # param1: party_no, exclude_leader
  17567. #OUTPUT:
  17568. # trp_stack_selection_amounts slots (slot 0 = number of stacks, 1 = number of men fit, 2..n = stack sizes (fit))
  17569. # trp_stack_selection_ids slots (2..n = stack troops)
  17570. ("write_fit_party_members_to_stack_selection",
  17571. [
  17572. (store_script_param, ":party_no", 1),
  17573. (store_script_param, ":exclude_leader", 2),
  17574. (party_get_num_companion_stacks, ":num_stacks", ":party_no"),
  17575. (assign, ":slot_index", 2),
  17576. (assign, ":total_fit", 0),
  17577. (try_for_range, ":stack_index", 0, ":num_stacks"),
  17578. (party_stack_get_troop_id, ":stack_troop", ":party_no", ":stack_index"),
  17579. (assign, ":num_fit", 0),
  17580. (try_begin),
  17581. (troop_is_hero, ":stack_troop"),
  17582. (try_begin),
  17583. (neg|troop_is_wounded, ":stack_troop"),
  17584. (this_or_next|eq, ":exclude_leader", 0),
  17585. (neq, ":stack_index", 0),
  17586. (assign, ":num_fit",1),
  17587. (try_end),
  17588. (else_try),
  17589. (party_stack_get_size, ":num_fit", ":party_no", ":stack_index"),
  17590. (party_stack_get_num_wounded, ":num_wounded", ":party_no", ":stack_index"),
  17591. (val_sub, ":num_fit", ":num_wounded"),
  17592. (try_end),
  17593. (try_begin),
  17594. (gt, ":num_fit", 0),
  17595. (troop_set_slot, "trp_stack_selection_amounts", ":slot_index", ":num_fit"),
  17596. (troop_set_slot, "trp_stack_selection_ids", ":slot_index", ":stack_troop"),
  17597. (val_add, ":slot_index", 1),
  17598. (try_end),
  17599. (val_add, ":total_fit", ":num_fit"),
  17600. (try_end),
  17601. (val_sub, ":slot_index", 2),
  17602. (troop_set_slot, "trp_stack_selection_amounts", 0, ":slot_index"),
  17603. (troop_set_slot, "trp_stack_selection_amounts", 1, ":total_fit"),
  17604. ]),
  17605.  
  17606. #script_remove_fit_party_member_from_stack_selection
  17607. # INPUT:
  17608. # param1: slot_index
  17609. #OUTPUT:
  17610. # reg0 = troop_no
  17611. # trp_stack_selection_amounts slots (slot 0 = number of stacks, 1 = number of men fit, 2..n = stack sizes (fit))
  17612. # trp_stack_selection_ids slots (2..n = stack troops)
  17613. ("remove_fit_party_member_from_stack_selection",
  17614. [
  17615. (store_script_param, ":slot_index", 1),
  17616. (val_add, ":slot_index", 2),
  17617. (troop_get_slot, ":amount", "trp_stack_selection_amounts", ":slot_index"),
  17618. (troop_get_slot, ":troop_no", "trp_stack_selection_ids", ":slot_index"),
  17619. (val_sub, ":amount", 1),
  17620. (troop_set_slot, "trp_stack_selection_amounts", ":slot_index", ":amount"),
  17621. (troop_get_slot, ":total_amount", "trp_stack_selection_amounts", 1),
  17622. (val_sub, ":total_amount", 1),
  17623. (troop_set_slot, "trp_stack_selection_amounts", 1, ":total_amount"),
  17624. (try_begin),
  17625. (le, ":amount", 0),
  17626. (troop_get_slot, ":num_slots", "trp_stack_selection_amounts", 0),
  17627. (store_add, ":end_cond", ":num_slots", 2),
  17628. (store_add, ":begin_cond", ":slot_index", 1),
  17629. (try_for_range, ":index", ":begin_cond", ":end_cond"),
  17630. (store_sub, ":prev_index", ":index", 1),
  17631. (troop_get_slot, ":value", "trp_stack_selection_amounts", ":index"),
  17632. (troop_set_slot, "trp_stack_selection_amounts", ":prev_index", ":value"),
  17633. (troop_get_slot, ":value", "trp_stack_selection_ids", ":index"),
  17634. (troop_set_slot, "trp_stack_selection_ids", ":prev_index", ":value"),
  17635. (try_end),
  17636. (val_sub, ":num_slots", 1),
  17637. (troop_set_slot, "trp_stack_selection_amounts", 0, ":num_slots"),
  17638. (try_end),
  17639. (assign, reg0, ":troop_no"),
  17640. ]),
  17641.  
  17642. #script_remove_random_fit_party_member_from_stack_selection
  17643. # INPUT:
  17644. # none
  17645. #OUTPUT:
  17646. # reg0 = troop_no
  17647. # trp_stack_selection_amounts slots (slot 0 = number of stacks, 1 = number of men fit, 2..n = stack sizes (fit))
  17648. # trp_stack_selection_ids slots (2..n = stack troops)
  17649. ("remove_random_fit_party_member_from_stack_selection",
  17650. [
  17651. (troop_get_slot, ":total_amount", "trp_stack_selection_amounts", 1),
  17652. (store_random_in_range, ":random_troop", 0, ":total_amount"),
  17653. (troop_get_slot, ":num_slots", "trp_stack_selection_amounts", 0),
  17654. (store_add, ":end_cond", ":num_slots", 2),
  17655. (try_for_range, ":index", 2, ":end_cond"),
  17656. (troop_get_slot, ":amount", "trp_stack_selection_amounts", ":index"),
  17657. (val_sub, ":random_troop", ":amount"),
  17658. (lt, ":random_troop", 0),
  17659. (assign, ":end_cond", 0),
  17660. (store_sub, ":slot_index", ":index", 2),
  17661. (try_end),
  17662. (call_script, "script_remove_fit_party_member_from_stack_selection", ":slot_index"),
  17663. ]),
  17664.  
  17665.  
  17666. #script_add_routed_party
  17667. #INPUT: none
  17668. #OUTPUT: none
  17669. ("add_routed_party",
  17670. [
  17671. (party_get_num_companion_stacks, ":num_stacks", "p_routed_enemies"), #question, I changed (total_enemy_casualties) with (p_routed_enemies) because this is not prisoner in p_routed_enemies party.
  17672. (assign, ":num_regulars", 0),
  17673. (assign, ":deleted_stacks", 0),
  17674. (try_for_range, ":stack_no", 0, ":num_stacks"),
  17675. (store_sub, ":difference", ":num_stacks", ":stack_no"),
  17676. (ge, ":difference", ":deleted_stacks"),
  17677. (store_sub, ":stack_no_minus_deleted", ":stack_no", ":deleted_stacks"),
  17678. (party_stack_get_troop_id, ":stack_troop", "p_routed_enemies", ":stack_no_minus_deleted"),
  17679. (try_begin),
  17680. (troop_is_hero, ":stack_troop"),
  17681. (party_stack_get_size, ":stack_size", "p_routed_enemies", ":stack_no_minus_deleted"),
  17682. (party_remove_members, "p_routed_enemies", ":stack_troop", 1),
  17683. (try_begin),
  17684. (le, ":stack_size", 1),
  17685. (val_add, ":deleted_stacks", 1), #if deleted hero is the only one in his troop, now we have one less stacks
  17686. (try_end),
  17687. (else_try),
  17688. (val_add, ":num_regulars", 1),
  17689. (try_end),
  17690. (try_end),
  17691.  
  17692. #add new party to map if there is at least one routed agent. (new party name : routed_party, template : routed_warriors)
  17693. (try_begin),
  17694. (ge, ":num_regulars", 1),
  17695.  
  17696. (set_spawn_radius, 2),
  17697. (spawn_around_party, "p_main_party", "pt_routed_warriors"),
  17698. (assign, ":routed_party", reg0),
  17699. # SB : white flag
  17700. (store_random_in_range, ":icon", custom_banner_map_icons_begin, custom_banner_map_icons_end),
  17701. (party_set_banner_icon, ":routed_party", ":icon"),
  17702. (party_set_slot, ":routed_party", slot_party_commander_party, -1), #we need this because 0 is player's party!
  17703.  
  17704. (assign, ":max_routed_agents", 0),
  17705. (assign, ":routed_party_faction", "fac_neutral"),
  17706. (try_for_range, ":cur_faction", npc_kingdoms_begin, npc_kingdoms_end),
  17707. (faction_get_slot, ":num_routed_agents_in_this_faction", ":cur_faction", slot_faction_num_routed_agents),
  17708. (gt, ":num_routed_agents_in_this_faction", ":max_routed_agents"),
  17709. (assign, ":max_routed_agents", ":num_routed_agents_in_this_faction"),
  17710. (assign, ":routed_party_faction", ":cur_faction"),
  17711. (try_end),
  17712.  
  17713. (party_set_faction, ":routed_party", ":routed_party_faction"),
  17714.  
  17715. (party_set_ai_behavior, ":routed_party", ai_bhvr_travel_to_party),
  17716.  
  17717. (assign, ":minimum_distance", 1000000),
  17718. #SB : get rid of useless range
  17719. (store_random_in_range, ":nearest_ally_city", walled_centers_begin, walled_centers_end),
  17720. (try_for_range, ":party_no", walled_centers_begin, walled_centers_end),
  17721. # (party_is_active, ":party_no"),
  17722. # (party_get_slot, ":cur_party_type", ":party_no", slot_party_type),
  17723. # (this_or_next|eq, ":cur_party_type", spt_town),
  17724. # (eq, ":cur_party_type", spt_castle),
  17725. (store_faction_of_party, ":cur_faction", ":party_no"),
  17726. (this_or_next|eq, ":routed_party_faction", "fac_neutral"),
  17727. (eq, ":cur_faction", ":routed_party_faction"),
  17728. (party_get_position, pos1, ":party_no"),
  17729. (store_distance_to_party_from_party, ":dist", ":party_no", "p_main_party"),
  17730. (try_begin),
  17731. (lt, ":dist", ":minimum_distance"),
  17732. (assign, ":minimum_distance", ":dist"),
  17733. (assign, ":nearest_ally_city", ":party_no"),
  17734. (try_end),
  17735. (try_end),
  17736.  
  17737. (party_get_position, pos1, "p_main_party"), #store position information of main party in pos1
  17738. (party_get_position, pos2, ":nearest_ally_city"), #store position information of target city in pos2
  17739.  
  17740. (assign, ":minimum_distance", 1000000),
  17741. (try_for_range, ":unused", 0, 10),
  17742. (map_get_random_position_around_position, pos3, pos1, 2), #store position of found random position (possible placing position for new routed party) around battle position in pos3
  17743. (get_distance_between_positions, ":dist", pos2, pos3), #store distance between found position and target city in ":dist".
  17744. (try_begin),
  17745. (lt, ":dist", ":minimum_distance"),
  17746. (assign, ":minimum_distance", ":dist"),
  17747. (copy_position, pos63, pos3),
  17748. (try_end),
  17749. (end_try),
  17750.  
  17751. (party_set_position, ":routed_party", pos63),
  17752.  
  17753. (party_set_ai_object, ":routed_party", ":nearest_ally_city"),
  17754. (party_set_flags, ":routed_party", pf_default_behavior, 1),
  17755. #SB : add extra slot to actually merge with garrison
  17756. (party_set_slot, ":routed_party", slot_party_type, spt_reinforcement),
  17757.  
  17758. #adding party members of p_routed_enemies to routed_party
  17759. (party_clear, ":routed_party"),
  17760. (party_get_num_companion_stacks, ":num_stacks", "p_routed_enemies"), #question, I changed (total_enemy_casualties) with (p_routed_enemies) because this is not prisoner in p_routed_enemies party.
  17761. (try_for_range, ":stack_no", 0, ":num_stacks"),
  17762. (party_stack_get_troop_id, ":stack_troop", "p_routed_enemies", ":stack_no"),
  17763. (try_begin),
  17764. (neg|troop_is_hero, ":stack_troop"), #do not add routed heroes to (new created) routed party for now.
  17765.  
  17766. (party_stack_get_size, ":stack_size", "p_routed_enemies", ":stack_no"),
  17767. (party_add_members, ":routed_party", ":stack_troop", ":stack_size"),
  17768. (try_end),
  17769. (try_end),
  17770. (try_end),
  17771. ]), #ozan
  17772.  
  17773.  
  17774. #script_cf_training_ground_sub_routine_1_for_melee_details
  17775. # INPUT:
  17776. # value
  17777. #OUTPUT:
  17778. # none
  17779. ("cf_training_ground_sub_routine_1_for_melee_details",
  17780. [
  17781. (store_script_param, ":value", 1),
  17782. (ge, "$temp_3", ":value"),
  17783. (val_add, ":value", 1),
  17784. (troop_get_slot, ":troop_id", "trp_stack_selection_ids", ":value"),
  17785. (str_store_troop_name, s0, ":troop_id"),
  17786. ]),
  17787.  
  17788. #script_training_ground_sub_routine_2_for_melee_details
  17789. # INPUT:
  17790. # value
  17791. #OUTPUT:
  17792. # none
  17793. ("training_ground_sub_routine_2_for_melee_details",
  17794. [
  17795. (store_script_param, ":value", 1),
  17796. (val_sub, ":value", 1),
  17797. (try_begin),
  17798. (lt, ":value", 0),
  17799. (call_script, "script_remove_random_fit_party_member_from_stack_selection"),
  17800. (else_try),
  17801. (call_script, "script_remove_fit_party_member_from_stack_selection", ":value"),
  17802. (try_end),
  17803. (assign, ":troop_id", reg0),
  17804. (store_sub, ":slot_index", "$temp_2", 1),
  17805. (troop_set_slot, "trp_temp_array_a", ":slot_index", ":troop_id"),
  17806. (try_begin),
  17807. (eq, "$temp", "$temp_2"),
  17808. (call_script, "script_start_training_at_training_ground", -1, "$temp"),
  17809. (else_try),
  17810. (val_add, "$temp_2", 1),
  17811. (jump_to_menu, "mnu_training_ground_selection_details_melee_2"),
  17812. (try_end),
  17813. ]),
  17814.  
  17815. #script_cf_training_ground_sub_routine_for_training_result
  17816. # INPUT:
  17817. # arg1: troop_id, arg2: stack_no, arg3: troop_count, arg4: xp_ratio_to_add
  17818. #OUTPUT:
  17819. # none
  17820. ("cf_training_ground_sub_routine_for_training_result",
  17821. [
  17822. (store_script_param, ":troop_id", 1),
  17823. (store_script_param, ":stack_no", 2),
  17824. (store_script_param, ":amount", 3),
  17825. (store_script_param, ":xp_ratio_to_add", 4),
  17826.  
  17827. (store_character_level, ":level", ":troop_id"),
  17828. (store_add, ":level_added", ":level", 5),
  17829. (store_mul, ":min_hardness", ":level_added", 3),
  17830. (val_min, ":min_hardness", 100),
  17831. (store_sub, ":hardness_dif", ":min_hardness", "$g_training_ground_training_hardness"),
  17832. (val_max, ":hardness_dif", 0),
  17833. (store_sub, ":hardness_dif", 100, ":hardness_dif"),
  17834. (val_mul, ":hardness_dif", ":hardness_dif"),
  17835. (val_div, ":hardness_dif", 10), # value over 1000
  17836. ## (assign, reg0, ":hardness_dif"),
  17837. ## (display_message, "@Hardness difference: {reg0}/1000"),
  17838. (store_mul, ":xp_ratio_to_add_for_stack", ":xp_ratio_to_add", ":hardness_dif"),
  17839. (val_div, ":xp_ratio_to_add_for_stack", 1000),
  17840. (try_begin),
  17841. (eq, ":troop_id", "trp_player"),
  17842. (val_mul, ":xp_ratio_to_add_for_stack", 1),
  17843. (else_try),
  17844. (try_begin),
  17845. (eq, "$g_mt_mode", ctm_melee),
  17846. (try_begin),
  17847. (this_or_next|troop_is_guarantee_ranged, ":troop_id"),
  17848. (troop_is_guarantee_horse, ":troop_id"),
  17849. (val_div, ":xp_ratio_to_add_for_stack", 4),
  17850. (try_end),
  17851. (else_try),
  17852. (eq, "$g_mt_mode", ctm_mounted),
  17853. (try_begin),
  17854. (neg|troop_is_guarantee_horse, ":troop_id"),
  17855. (assign, ":xp_ratio_to_add_for_stack", 0),
  17856. (try_end),
  17857. (else_try),
  17858. (neg|troop_is_guarantee_ranged, ":troop_id"),
  17859. (assign, ":xp_ratio_to_add_for_stack", 0),
  17860. (try_end),
  17861. (try_end),
  17862. (val_add, ":level", 1),
  17863. (store_mul, ":xp_to_add", 100, ":level"),
  17864. (val_mul, ":xp_to_add", ":amount"),
  17865. (val_div, ":xp_to_add", 20),
  17866. (val_mul, ":xp_to_add", ":xp_ratio_to_add_for_stack"),
  17867. (val_div, ":xp_to_add", 1000),
  17868. (store_mul, ":max_xp_to_add", ":xp_to_add", 3),
  17869. (val_div, ":max_xp_to_add", 2),
  17870. (store_div, ":min_xp_to_add", ":xp_to_add", 2),
  17871. (store_random_in_range, ":random_xp_to_add", ":min_xp_to_add", ":max_xp_to_add"),
  17872. (gt, ":random_xp_to_add", 0),
  17873. (try_begin),
  17874. (troop_is_hero, ":troop_id"),
  17875. (add_xp_to_troop, ":random_xp_to_add", ":troop_id"),
  17876. (store_div, ":proficiency_to_add", ":random_xp_to_add", 50),
  17877. (try_begin),
  17878. (gt, ":proficiency_to_add", 0),
  17879. (troop_raise_proficiency, ":troop_id", "$g_training_ground_used_weapon_proficiency", ":proficiency_to_add"),
  17880. (try_end),
  17881. (else_try),
  17882. (party_add_xp_to_stack, "p_main_party", ":stack_no", ":random_xp_to_add"),
  17883. (try_end),
  17884. (assign, reg0, ":random_xp_to_add"),
  17885. ]),
  17886.  
  17887.  
  17888. ## #script_cf_print_troop_name_with_stack_index_to_s0
  17889. ## # INPUT:
  17890. ## # param1: stack_index
  17891. ##
  17892. ## #OUTPUT:
  17893. ## # string register 0.
  17894. ## ("cf_print_troop_name_with_stack_index_to_s0",
  17895. ## [
  17896. ## (store_script_param_1, ":stack_index"),
  17897. ## (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  17898. ## (lt, ":stack_index", ":num_stacks"),
  17899. ## (party_stack_get_troop_id, ":stack_troop", "p_main_party", ":stack_index"),
  17900. ## (str_store_troop_name, s0, ":stack_troop"),
  17901. ## ]),
  17902.  
  17903. #script_print_troop_owned_centers_in_numbers_to_s0
  17904. # INPUT:
  17905. # param1: troop_no
  17906. #OUTPUT:
  17907. # string register 0.
  17908. ("print_troop_owned_centers_in_numbers_to_s0",
  17909. [
  17910. (store_script_param_1, ":troop_no"),
  17911. (str_store_string, s0, "@nothing"),
  17912. (assign, ":owned_towns", 0),
  17913. (assign, ":owned_castles", 0),
  17914. (assign, ":owned_villages", 0),
  17915. (try_for_range_backwards, ":cur_center", centers_begin, centers_end),
  17916. (party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
  17917. (try_begin),
  17918. (party_slot_eq, ":cur_center", slot_party_type, spt_town),
  17919. (val_add, ":owned_towns", 1),
  17920. (else_try),
  17921. (party_slot_eq, ":cur_center", slot_party_type, spt_castle),
  17922. (val_add, ":owned_castles", 1),
  17923. (else_try),
  17924. (val_add, ":owned_villages", 1),
  17925. (try_end),
  17926. (try_end),
  17927. (assign, ":num_types", 0),
  17928. (try_begin),
  17929. (gt, ":owned_villages", 0),
  17930. (assign, reg0, ":owned_villages"),
  17931. (store_sub, reg1, reg0, 1),
  17932. (str_store_string, s0, "@{reg0} village{reg1?s:}"),
  17933. (val_add, ":num_types", 1),
  17934. (try_end),
  17935. (try_begin),
  17936. (gt, ":owned_castles", 0),
  17937. (assign, reg0, ":owned_castles"),
  17938. (store_sub, reg1, reg0, 1),
  17939. (try_begin),
  17940. (eq, ":num_types", 0),
  17941. (str_store_string, s0, "@{reg0} castle{reg1?s:}"),
  17942. (else_try),
  17943. (str_store_string, s0, "@{reg0} castle{reg1?s:} and {s0}"),
  17944. (try_end),
  17945. (val_add, ":num_types", 1),
  17946. (try_end),
  17947. (try_begin),
  17948. (gt, ":owned_towns", 0),
  17949. (assign, reg0, ":owned_towns"),
  17950. (store_sub, reg1, reg0, 1),
  17951. (try_begin),
  17952. (eq, ":num_types", 0),
  17953. (str_store_string, s0, "@{reg0} town{reg1?s:}"),
  17954. (else_try),
  17955. (eq, ":num_types", 1),
  17956. (str_store_string, s0, "@{reg0} town{reg1?s:} and {s0}"),
  17957. (else_try),
  17958. (str_store_string, s0, "@{reg0} town{reg1?s:}, {s0}"),
  17959. (try_end),
  17960. (try_end),
  17961. (store_add, reg0, ":owned_villages", ":owned_castles"),
  17962. (val_add, reg0, ":owned_towns"),
  17963. ]),
  17964.  
  17965. #script_get_random_melee_training_weapon
  17966. # INPUT: none
  17967. # OUTPUT: reg0 = weapon_1, reg1 = weapon_2
  17968. ("get_random_melee_training_weapon",
  17969. [
  17970. (assign, ":weapon_1", -1),
  17971. (assign, ":weapon_2", -1),
  17972. (store_random_in_range, ":random_no", 0, 3),
  17973. (try_begin),
  17974. (eq, ":random_no", 0),
  17975. (assign, ":weapon_1", "itm_practice_staff"),
  17976. (else_try),
  17977. (eq, ":random_no", 1),
  17978. (assign, ":weapon_1", "itm_practice_sword"),
  17979. (assign, ":weapon_2", "itm_practice_shield"),
  17980. (else_try),
  17981. (assign, ":weapon_1", "itm_heavy_practice_sword"),
  17982. (try_end),
  17983. (assign, reg0, ":weapon_1"),
  17984. (assign, reg1, ":weapon_2"),
  17985. ]),
  17986.  
  17987. #script_start_training_at_training_ground
  17988. # INPUT:
  17989. # param1: training_weapon_type, param2: training_param
  17990. ("start_training_at_training_ground",
  17991. [
  17992. # (val_add, "$g_training_ground_training_count", 1),
  17993. (store_script_param, ":mission_weapon_type", 1),
  17994. (store_script_param, ":training_param", 2),
  17995.  
  17996. (set_jump_mission, "mt_training_ground_training"),
  17997. #SB : increment sparring count
  17998. (party_get_slot, ":count", "$g_encountered_party", slot_grounds_count),
  17999. (party_get_slot, ":trainer_troop", "$g_encountered_party", slot_grounds_trainer),
  18000. (val_add, ":count", 1),
  18001. (party_set_slot, "$g_encountered_party", slot_grounds_count, ":count"),
  18002.  
  18003.  
  18004. (assign, ":training_default_weapon_1", -1),
  18005. (assign, ":training_default_weapon_2", -1),
  18006. (assign, ":training_default_weapon_3", -1),
  18007. (assign, "$scene_num_total_gourds_destroyed", 0),
  18008. (try_begin),
  18009. (eq, ":mission_weapon_type", itp_type_bow),
  18010. (assign, "$g_training_ground_used_weapon_proficiency", wpt_archery),
  18011. (assign, ":training_default_weapon_1", "itm_practice_bow"),
  18012. (try_begin),
  18013. (eq, "$g_mt_mode", ctm_mounted),
  18014. (assign, ":training_default_weapon_2", "itm_practice_arrows_100_amount"),
  18015. (else_try),
  18016. (assign, ":training_default_weapon_2", "itm_practice_arrows_10_amount"),
  18017. (try_end),
  18018. (else_try),
  18019. (eq, ":mission_weapon_type", itp_type_crossbow),
  18020. (assign, "$g_training_ground_used_weapon_proficiency", wpt_crossbow),
  18021. (assign, ":training_default_weapon_1", "itm_practice_crossbow"),
  18022. (assign, ":training_default_weapon_2", "itm_practice_bolts_9_amount"),
  18023. (else_try),
  18024. (eq, ":mission_weapon_type", itp_type_thrown),
  18025. (assign, "$g_training_ground_used_weapon_proficiency", wpt_throwing),
  18026. (try_begin),
  18027. (eq, "$g_mt_mode", ctm_mounted),
  18028. (assign, ":training_default_weapon_2", "itm_practice_throwing_daggers_100_amount"),
  18029. (else_try),
  18030. (assign, ":training_default_weapon_2", "itm_practice_throwing_daggers"),
  18031. (try_end),
  18032. (else_try),
  18033. (eq, ":mission_weapon_type", itp_type_one_handed_wpn),
  18034. (assign, "$g_training_ground_used_weapon_proficiency", wpt_one_handed_weapon),
  18035. (assign, ":training_default_weapon_1", "itm_practice_sword"),
  18036. (else_try),
  18037. (eq, ":mission_weapon_type", itp_type_polearm),
  18038. (assign, "$g_training_ground_used_weapon_proficiency", wpt_polearm),
  18039. (assign, ":training_default_weapon_1", "itm_practice_lance"),
  18040. (else_try),
  18041. #weapon_type comes as -1 when melee training is selected
  18042. (assign, "$g_training_ground_used_weapon_proficiency", wpt_one_handed_weapon),
  18043. # (call_script, "script_get_random_melee_training_weapon"),
  18044. (try_begin),
  18045. (gt, ":trainer_troop", 0),
  18046. (troop_slot_ge, ":trainer_troop", slot_troop_trainer_training_difficulty, 4),
  18047. (call_script, "script_get_proficient_melee_training_weapon", "$g_player_troop"),
  18048. (try_begin), #sword and board
  18049. (eq, reg0, "itm_practice_sword"),
  18050. (assign, reg1, "itm_practice_shield"),
  18051. (try_end),
  18052. (else_try),
  18053. (call_script, "script_get_random_melee_training_weapon"),
  18054. (try_end),
  18055. (assign, ":training_default_weapon_1", reg0),
  18056. (assign, ":training_default_weapon_2", reg1),
  18057. (try_end),
  18058.  
  18059. ## (assign, "$g_training_ground_training_troop_stack_index", ":stack_index"),
  18060. (try_begin),
  18061. (eq, "$g_mt_mode", ctm_mounted),
  18062. (assign, ":training_default_weapon_3", "itm_practice_horse"),
  18063. #SB : use slot
  18064. (party_get_slot, "$g_training_ground_training_scene", "$g_encountered_party", slot_grounds_track),
  18065. (else_try),
  18066. #SB : use slot
  18067. (party_get_slot, "$g_training_ground_training_scene", "$g_encountered_party", slot_grounds_melee),
  18068. # (store_add, "$g_training_ground_training_scene", "scn_training_ground_ranged_melee_1", "$g_encountered_party"),
  18069. # (val_sub, "$g_training_ground_training_scene", training_grounds_begin),
  18070. (try_end),
  18071.  
  18072. (modify_visitors_at_site, "$g_training_ground_training_scene"),
  18073. (reset_visitors),
  18074. (set_visitor, 0, "trp_player"),
  18075.  
  18076. (assign, ":selected_weapon", -1),
  18077. (try_for_range, ":cur_slot", ek_item_0, ek_head),#equipment slots
  18078. (troop_get_inventory_slot, ":cur_item", "trp_player", ":cur_slot"),
  18079. (ge, ":cur_item", 0),
  18080. (item_get_type, ":item_type", ":cur_item"),
  18081. (try_begin),
  18082. (eq, ":item_type", ":mission_weapon_type"),
  18083. (eq, ":selected_weapon", -1),
  18084. (assign, ":selected_weapon", ":cur_item"),
  18085. (try_end),
  18086. (try_end),
  18087. (mission_tpl_entry_clear_override_items, "mt_training_ground_training", 0),
  18088. (mission_tpl_entry_add_override_item, "mt_training_ground_training", 0, "itm_practice_boots"),
  18089. (try_begin),
  18090. (ge, ":training_default_weapon_1", 0),
  18091. (try_begin),
  18092. (ge, ":selected_weapon", 0),
  18093. (mission_tpl_entry_add_override_item, "mt_training_ground_training", 0, ":selected_weapon"),
  18094. (else_try),
  18095. (mission_tpl_entry_add_override_item, "mt_training_ground_training", 0, ":training_default_weapon_1"),
  18096. (try_end),
  18097. (try_end),
  18098. (try_begin),
  18099. (ge, ":training_default_weapon_2", 0),
  18100. (mission_tpl_entry_add_override_item, "mt_training_ground_training", 0, ":training_default_weapon_2"),
  18101. (try_end),
  18102. (try_begin),
  18103. (ge, ":training_default_weapon_3", 0),
  18104. (mission_tpl_entry_add_override_item, "mt_training_ground_training", 0, ":training_default_weapon_3"),
  18105. (try_end),
  18106.  
  18107. (assign, ":cur_visitor_point", 5),
  18108. (troop_get_slot, ":num_fit", "trp_stack_selection_amounts", 1),
  18109. (store_add, ":end_cond", 5, ":num_fit"),
  18110. (val_min, ":end_cond", 13),
  18111. (try_for_range, ":cur_visitor_point", 5, ":end_cond"),
  18112. (call_script, "script_remove_random_fit_party_member_from_stack_selection"),
  18113. (set_visitor, ":cur_visitor_point", reg0),
  18114. (val_add, ":cur_visitor_point", 1),
  18115. (try_end),
  18116. (try_begin),
  18117. (eq, "$g_mt_mode", ctm_melee),
  18118. (assign, ":total_difficulty", 0),
  18119. (assign, ":cur_entry_point", 1),
  18120. (try_for_range, ":i", 0, ":training_param"),
  18121. (troop_get_slot, ":cur_troop", "trp_temp_array_a", ":i"),
  18122. # (store_add, ":cur_entry_point", ":i", 1),
  18123. (set_visitor, ":cur_entry_point", ":cur_troop"),
  18124. (mission_tpl_entry_clear_override_items, "mt_training_ground_training", ":cur_entry_point"),
  18125. (mission_tpl_entry_add_override_item, "mt_training_ground_training", ":cur_entry_point", "itm_practice_boots"),
  18126. (call_script, "script_get_random_melee_training_weapon"),
  18127. (mission_tpl_entry_add_override_item, "mt_training_ground_training", ":cur_entry_point", reg0),
  18128. (try_begin),
  18129. (ge, reg1, 0),
  18130. (mission_tpl_entry_add_override_item, "mt_training_ground_training", ":cur_entry_point", reg1),
  18131. (try_end),
  18132. (val_add, ":cur_entry_point", 1),
  18133. (store_character_level, ":cur_troop_level", ":cur_troop"),
  18134. (val_add, ":cur_troop_level", 10),
  18135. (val_mul, ":cur_troop_level", ":cur_troop_level"),
  18136. (val_add, ":total_difficulty", ":cur_troop_level"),
  18137. (try_end),
  18138.  
  18139. (assign, "$g_training_ground_training_num_enemies", ":training_param"),
  18140. (assign, "$g_training_ground_training_hardness", ":total_difficulty"),
  18141. (store_add, ":number_multiplier", "$g_training_ground_training_num_enemies", 4),
  18142. (val_mul, "$g_training_ground_training_hardness", ":number_multiplier"),
  18143. (val_div, "$g_training_ground_training_hardness", 2400),
  18144. #SB : store by count
  18145. # (str_store_string, s0, "@Your opponents are ready for the fight."),
  18146. (else_try),
  18147. (eq, "$g_mt_mode", ctm_mounted),
  18148. (try_begin),
  18149. (eq, ":mission_weapon_type", itp_type_bow),
  18150. (assign, "$g_training_ground_training_hardness", 350),
  18151. (assign, "$g_training_ground_training_num_gourds_to_destroy", 30),
  18152. (else_try),
  18153. (eq, ":mission_weapon_type", itp_type_thrown),
  18154. (assign, "$g_training_ground_training_hardness", 400),
  18155. (assign, "$g_training_ground_training_num_gourds_to_destroy", 30),
  18156. (else_try),
  18157. (eq, ":mission_weapon_type", itp_type_one_handed_wpn),
  18158. (assign, "$g_training_ground_training_hardness", 200),
  18159. (assign, "$g_training_ground_training_num_gourds_to_destroy", 45),
  18160. (else_try),
  18161. (eq, ":mission_weapon_type", itp_type_polearm),
  18162. (assign, "$g_training_ground_training_hardness", 280),
  18163. (assign, "$g_training_ground_training_num_gourds_to_destroy", 35),
  18164. (try_end),
  18165. # (str_store_string, s0, "@Try to destroy as many targets as you can. You have two and a half minutes to clear the track."),
  18166. (else_try),
  18167. (eq, "$g_mt_mode", ctm_ranged),
  18168. (store_mul, "$g_training_ground_ranged_distance", ":training_param", 100),
  18169. (assign, ":hardness_modifier", ":training_param"),
  18170. (val_mul, ":hardness_modifier", ":hardness_modifier"),
  18171. (try_begin),
  18172. (eq, ":mission_weapon_type", itp_type_bow),
  18173. (val_mul, ":hardness_modifier", 3),
  18174. (val_div, ":hardness_modifier", 2),
  18175. (else_try),
  18176. (eq, ":mission_weapon_type", itp_type_thrown),
  18177. (val_mul, ":hardness_modifier", 5),
  18178. (val_div, ":hardness_modifier", 2),
  18179. (val_mul, ":hardness_modifier", ":training_param"),
  18180. (val_div, ":hardness_modifier", 2),
  18181. (try_end),
  18182. (store_mul, "$g_training_ground_training_hardness", 100, ":hardness_modifier"),
  18183. (val_div, "$g_training_ground_training_hardness", 6000),
  18184. # (str_store_string, s0, "@Stay behind the line on the ground and shoot the targets. Try not to waste any shots."),
  18185. (try_end),
  18186. (jump_to_menu, "mnu_training_ground_description"),
  18187. ]),
  18188.  
  18189.  
  18190. #script_print_party_to_s0:
  18191. # INPUT:
  18192. # param1: Party-id
  18193.  
  18194. #OUTPUT:
  18195. # string register 0.
  18196.  
  18197. ## ("print_party_to_s0",
  18198. ## [
  18199. ## (store_script_param_1, ":party"), #Party_id
  18200. ## (party_get_num_companion_stacks, ":num_stacks",":party"),
  18201. ## (str_store_string, s50, "str_dplmc_none"),
  18202. ## (try_for_range, ":i_stack", 0, ":num_stacks"),
  18203. ## (party_stack_get_troop_id, ":stack_troop",":party",":i_stack"),
  18204. ## (party_stack_get_size, ":stack_size",":party",":i_stack"),
  18205. ## (str_store_troop_name_by_count, s61, ":stack_troop", ":stack_size"),
  18206. ## (try_begin),
  18207. ## (troop_is_hero, ":stack_troop"),
  18208. ## (str_store_string_reg, s51, s61),
  18209. ## (else_try),
  18210. ## (assign, reg60, ":stack_size"),
  18211. ## (str_store_string, s63, "str_reg60_s61"),
  18212. ## (try_end),
  18213. ## (try_begin),
  18214. ## (eq, ":i_stack", 0),
  18215. ## (str_store_string_reg, s50, s51),
  18216. ## (else_try),
  18217. ## (str_store_string, s50, "str_s50_comma_s51"),
  18218. ## (try_end),
  18219. ## (try_end),
  18220. ## (str_store_string_reg, s0, s50),
  18221. ## ]),
  18222.  
  18223.  
  18224.  
  18225. #script_party_count_fit_regulars:
  18226. # Returns the number of unwounded regular companions in a party
  18227. # INPUT:
  18228. # param1: Party-id
  18229.  
  18230. ("party_count_fit_regulars",
  18231. [
  18232. (store_script_param_1, ":party"), #Party_id
  18233. (party_get_num_companion_stacks, ":num_stacks", ":party"),
  18234. (assign, reg0, 0),
  18235. (try_for_range, ":i_stack", 0, ":num_stacks"),
  18236. (party_stack_get_troop_id, ":stack_troop", ":party", ":i_stack"),
  18237. (neg|troop_is_hero, ":stack_troop"),
  18238. (party_stack_get_size, ":stack_size",":party",":i_stack"),
  18239. (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
  18240. (val_sub, ":stack_size", ":num_wounded"),
  18241. (val_add, reg0, ":stack_size"),
  18242. (try_end),
  18243. ]),
  18244.  
  18245.  
  18246. #script_party_count_fit_for_battle:
  18247. # Returns the number of unwounded companions in a party
  18248. # INPUT:
  18249. # param1: Party-id
  18250. # OUTPUT: reg0 = result
  18251. ("party_count_fit_for_battle",
  18252. [
  18253. (store_script_param_1, ":party"), #Party_id
  18254. (party_get_num_companion_stacks, ":num_stacks",":party"),
  18255. (assign, reg0, 0),
  18256. (try_for_range, ":i_stack", 0, ":num_stacks"),
  18257. (party_stack_get_troop_id, ":stack_troop",":party",":i_stack"),
  18258. (assign, ":num_fit",0),
  18259. (try_begin),
  18260. (troop_is_hero, ":stack_troop"),
  18261. (try_begin),
  18262. (neg|troop_is_wounded, ":stack_troop"),
  18263. (assign, ":num_fit", 1),
  18264. (try_end),
  18265. (else_try),
  18266. (party_stack_get_size, ":num_fit",":party",":i_stack"),
  18267. (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
  18268. (val_sub, ":num_fit", ":num_wounded"),
  18269. (try_end),
  18270. (val_add, reg0, ":num_fit"),
  18271. (try_end),
  18272. ]),
  18273.  
  18274.  
  18275. #script_party_count_members_with_full_health
  18276. # Returns the number of unwounded regulars, and heroes other than player with 100% hitpoints in a party
  18277. # INPUT:
  18278. # param1: Party-id
  18279. # OUTPUT: reg0 = result
  18280. ("party_count_members_with_full_health",
  18281. [
  18282. (store_script_param_1, ":party"), #Party_id
  18283. (party_get_num_companion_stacks, ":num_stacks",":party"),
  18284. (assign, reg0, 0),
  18285. (try_for_range, ":i_stack", 0, ":num_stacks"),
  18286. (party_stack_get_troop_id, ":stack_troop",":party",":i_stack"),
  18287. (neq, ":stack_troop", "trp_player"),
  18288. (assign, ":num_fit",0),
  18289. (try_begin),
  18290. (troop_is_hero, ":stack_troop"),
  18291. (store_troop_health, ":troop_hp", ":stack_troop"),
  18292. (try_begin),
  18293. (ge, ":troop_hp", 80),
  18294. (assign, ":num_fit",1),
  18295. (try_end),
  18296. (else_try),
  18297. (party_stack_get_size, ":num_fit",":party",":i_stack"),
  18298. (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
  18299. (val_sub, ":num_fit", ":num_wounded"),
  18300. (val_max, ":num_fit", 0),
  18301. (try_end),
  18302. (val_add, reg0, ":num_fit"),
  18303. (try_end),
  18304. ]),
  18305.  
  18306.  
  18307. ## ("get_fit_stack_with_rank",
  18308. ## [
  18309. ## (store_script_param_1, ":party"), #Party_id
  18310. ## (store_script_param_2, ":rank"), #Rank
  18311. ## (party_get_num_companion_stacks, ":num_stacks",":party"),
  18312. ## (assign, reg0, -1),
  18313. ## (assign, ":num_total", 0),
  18314. ## (try_for_range, ":i_stack", 0, ":num_stacks"),
  18315. ## (eq, reg(0), -1), #continue only if we haven't found the result yet.
  18316. ## (party_stack_get_troop_id, ":stack_troop",":party",":i_stack"),
  18317. ## (assign, ":num_fit",0),
  18318. ## (try_begin),
  18319. ## (troop_is_hero, ":stack_troop"),
  18320. ## (store_troop_health, ":troop_hp", ":stack_troop"),
  18321. ## (try_begin),
  18322. ## (ge, ":troop_hp", 20),
  18323. ## (assign, ":num_fit",1),
  18324. ## (try_end),
  18325. ## (else_try),
  18326. ## (party_stack_get_size, ":num_fit",":party",":i_stack"),
  18327. ## (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
  18328. ## (val_sub, ":num_fit", ":num_wounded"),
  18329. ## (try_end),
  18330. ## (val_add, ":num_total", ":num_fit"),
  18331. ## (try_begin),
  18332. ## (lt, ":rank", ":num_total"),
  18333. ## (assign, reg(0), ":i_stack"),
  18334. ## (try_end),
  18335. ## (try_end),
  18336. ## ]),
  18337.  
  18338. #script_get_stack_with_rank:
  18339. # Returns the stack no, containing unwounded regular companions with rank rank.
  18340. # INPUT:
  18341. # param1: Party-id
  18342. # param2: rank
  18343.  
  18344. ("get_stack_with_rank",
  18345. [
  18346. (store_script_param_1, ":party"), #Party_id
  18347. (store_script_param_2, ":rank"), #Rank
  18348. (party_get_num_companion_stacks, ":num_stacks",":party"),
  18349. (assign, reg(0), -1),
  18350. (assign, ":num_total", 0),
  18351. (try_for_range, ":i_stack", 0, ":num_stacks"),
  18352. (eq, reg(0), -1), #continue only if we haven't found the result yet.
  18353. (party_stack_get_troop_id, ":stack_troop",":party",":i_stack"),
  18354. (neg|troop_is_hero, ":stack_troop"),
  18355. (party_stack_get_size, ":stack_size",":party",":i_stack"),
  18356. (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
  18357. (val_sub, ":stack_size", ":num_wounded"),
  18358. (val_add, ":num_total", ":stack_size"),
  18359. (try_begin),
  18360. (lt, ":rank", ":num_total"),
  18361. (assign, reg(0), ":i_stack"),
  18362. (try_end),
  18363. (try_end),
  18364. ]),
  18365.  
  18366. #script_inflict_casualties_to_party:
  18367. # INPUT:
  18368. # param1: Party-id
  18369. # param2: number of rounds
  18370.  
  18371. #OUTPUT:
  18372. # This script doesn't return a value but populates the parties p_temp_wounded and p_temp_killed with the wounded and killed.
  18373. #Example:
  18374. # (script_inflict_casualties_to_party, "_p_main_party" ,50),
  18375. # Simulate 50 rounds of casualties to main_party.
  18376.  
  18377. ("inflict_casualties_to_party",
  18378. [
  18379. (party_clear, "p_temp_casualties"),
  18380. (store_script_param_1, ":party"), #Party_id
  18381. (call_script, "script_party_count_fit_regulars", ":party"),
  18382. (assign, ":num_fit", reg(0)), #reg(47) = number of fit regulars.
  18383. (store_script_param_2, ":num_attack_rounds"), #number of attacks
  18384. (try_for_range, ":unused", 0, ":num_attack_rounds"),
  18385. (gt, ":num_fit", 0),
  18386. (store_random_in_range, ":attacked_troop_rank", 0 , ":num_fit"), #attack troop with rank reg(46)
  18387. (assign, reg1, ":attacked_troop_rank"),
  18388. (call_script, "script_get_stack_with_rank", ":party", ":attacked_troop_rank"),
  18389. (assign, ":attacked_stack", reg(0)), #reg(53) = stack no to attack.
  18390. (party_stack_get_troop_id, ":attacked_troop",":party",":attacked_stack"),
  18391. (store_character_level, ":troop_toughness", ":attacked_troop"),
  18392. (val_add, ":troop_toughness", 5), #troop-toughness = level + 5
  18393. (assign, ":casualty_chance", 10000),
  18394. (val_div, ":casualty_chance", ":troop_toughness"), #dying chance
  18395. (try_begin),
  18396. (store_random_in_range, ":rand_num", 0 ,10000),
  18397. (lt, ":rand_num", ":casualty_chance"), #check chance to be a casualty
  18398. (store_random_in_range, ":rand_num2", 0, 2), #check if this troop will be wounded or killed
  18399. (try_begin),
  18400. (troop_is_hero,":attacked_troop"), #currently troop can't be a hero, but no harm in keeping this.
  18401. (store_troop_health, ":troop_hp",":attacked_troop"),
  18402. (val_sub, ":troop_hp", 45),
  18403. (val_max, ":troop_hp", 1),
  18404. (troop_set_health, ":attacked_troop", ":troop_hp"),
  18405. (else_try),
  18406. (lt, ":rand_num2", 1), #wounded
  18407. (party_add_members, "p_temp_casualties", ":attacked_troop", 1),
  18408. (party_wound_members, "p_temp_casualties", ":attacked_troop", 1),
  18409. (party_wound_members, ":party", ":attacked_troop", 1),
  18410. (else_try), #killed
  18411. (party_add_members, "p_temp_casualties", ":attacked_troop", 1),
  18412. (party_remove_members, ":party", ":attacked_troop", 1),
  18413. (try_end),
  18414. (val_sub, ":num_fit", 1), #adjust number of fit regulars.
  18415. (try_end),
  18416. (try_end),
  18417. ]),
  18418.  
  18419.  
  18420. #script_move_members_with_ratio:
  18421. # INPUT:
  18422. # param1: Source Party-id
  18423. # param2: Target Party-id
  18424. # pin_number = ratio of members to move, multiplied by 1000
  18425.  
  18426. #OUTPUT:
  18427. # This script doesn't return a value but moves some of the members of source party to target party according to the given ratio.
  18428. ("move_members_with_ratio",
  18429. [
  18430. (store_script_param_1, ":source_party"), #Source Party_id
  18431. (store_script_param_2, ":target_party"), #Target Party_id
  18432. (party_get_num_prisoner_stacks, ":num_stacks",":source_party"),
  18433. (try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
  18434. (party_prisoner_stack_get_troop_id, ":stack_troop",":source_party",":stack_no"),
  18435. (party_prisoner_stack_get_size, ":stack_size",":source_party",":stack_no"),
  18436. (store_mul, ":number_to_move",":stack_size","$pin_number"),
  18437. (val_div, ":number_to_move", 1000),
  18438. (party_remove_prisoners, ":source_party", ":stack_troop", ":number_to_move"),
  18439. (assign, ":number_moved", reg0),
  18440. (party_add_prisoners, ":target_party", ":stack_troop", ":number_moved"),
  18441. (try_end),
  18442. (party_get_num_companion_stacks, ":num_stacks",":source_party"),
  18443. (try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
  18444. (party_stack_get_troop_id, ":stack_troop",":source_party",":stack_no"),
  18445. (party_stack_get_size, ":stack_size",":source_party",":stack_no"),
  18446. (store_mul, ":number_to_move",":stack_size","$pin_number"),
  18447. (val_div, ":number_to_move", 1000),
  18448. (party_remove_members, ":source_party", ":stack_troop", ":number_to_move"),
  18449. (assign, ":number_moved", reg0),
  18450. (party_add_members, ":target_party", ":stack_troop", ":number_moved"),
  18451. (try_end),
  18452. ]),
  18453.  
  18454.  
  18455. # script_count_parties_of_faction_and_party_type:
  18456. # counts number of active parties with a template and faction.
  18457. # Input: arg1 = faction_no, arg2 = party_type
  18458. # Output: reg0 = count
  18459.  
  18460. ("count_parties_of_faction_and_party_type",
  18461. [
  18462. (store_script_param_1, ":faction_no"),
  18463. (store_script_param_2, ":party_type"),
  18464. (assign, reg0, 0),
  18465. (try_for_parties, ":party_no"),
  18466. (party_is_active, ":party_no"),
  18467. (party_get_slot, ":cur_party_type", ":party_no", slot_party_type),
  18468. (store_faction_of_party, ":cur_faction", ":party_no"),
  18469. (eq, ":cur_party_type", ":party_type"),
  18470. (eq, ":cur_faction", ":faction_no"),
  18471. (val_add, reg0, 1),
  18472. (try_end),
  18473. ]),
  18474.  
  18475. # script_faction_get_number_of_armies
  18476. # Input: arg1 = faction_no
  18477. # Output: reg0 = number_of_armies
  18478. ("faction_get_number_of_armies",
  18479. [
  18480. (store_script_param_1, ":faction_no"),
  18481. (assign, ":num_armies", 0),
  18482. ##diplomacy start+ support for promoted kingdom ladies
  18483. (try_for_range, ":troop_no", heroes_begin, heroes_end),#<- changed from active_npcs to heroes
  18484. ##diplomacy end+
  18485. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  18486. (store_troop_faction, ":hero_faction_no", ":troop_no"),
  18487. (eq, ":hero_faction_no", ":faction_no"),
  18488. (troop_get_slot, ":hero_party", ":troop_no", slot_troop_leaded_party),
  18489. (ge, ":hero_party", 0),
  18490. (party_is_active, ":hero_party"),
  18491. (call_script, "script_party_count_fit_regulars", ":hero_party"),
  18492. (assign, ":party_size", reg0),
  18493. (call_script, "script_party_get_ideal_size", ":hero_party"),
  18494. (assign, ":ideal_size", reg0),
  18495. (val_mul, ":ideal_size", 60),
  18496. (val_div, ":ideal_size", 100),
  18497. (gt, ":party_size", ":ideal_size"),
  18498. (val_add, ":num_armies", 1),
  18499. (try_end),
  18500. (assign, reg0, ":num_armies"),
  18501. ]),
  18502.  
  18503.  
  18504. # script_faction_recalculate_strength
  18505. # Input: arg1 = faction_no
  18506. # Output: reg0 = strength
  18507. ("faction_recalculate_strength",
  18508. [
  18509. (store_script_param_1, ":faction_no"),
  18510.  
  18511. (call_script, "script_faction_get_number_of_armies", ":faction_no"),
  18512. (assign, ":num_armies", reg0),
  18513. (assign, ":num_castles", 0),
  18514. (assign, ":num_towns", 0),
  18515.  
  18516. (try_for_range, ":center_no", centers_begin, centers_end),
  18517. (store_faction_of_party, ":center_faction", ":center_no"),
  18518. (eq, ":center_faction", ":faction_no"),
  18519. (try_begin),
  18520. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  18521. (val_add, ":num_castles", 1),
  18522. (else_try),
  18523. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  18524. (val_add, ":num_towns", 1),
  18525. (try_end),
  18526. (try_end),
  18527.  
  18528. (faction_set_slot, ":faction_no", slot_faction_num_armies, ":num_armies"),
  18529. (faction_set_slot, ":faction_no", slot_faction_num_castles, ":num_castles"),
  18530. (faction_set_slot, ":faction_no", slot_faction_num_towns, ":num_towns"),
  18531.  
  18532. ]),
  18533.  
  18534. #script_select_random_town:
  18535. # This script selects a random town in range [towns_begin, towns_end)
  18536. # INPUTS:
  18537. # none
  18538.  
  18539. #OUTPUT:
  18540. # reg0: id of the selected random town
  18541. ## ("select_random_town",
  18542. ## [
  18543. ## (assign, ":num_towns", towns_end),
  18544. ## (val_sub,":num_towns", towns_begin),
  18545. ## (store_random, ":random_town", ":num_towns"),
  18546. ## (val_add,":random_town", towns_begin),
  18547. ## (assign, reg0, ":random_town"),
  18548. ## ]),
  18549.  
  18550. # ("select_random_spawn_point",
  18551. # [
  18552. # (assign, reg(20), spawn_points_end),
  18553. # (val_sub,reg(20), spawn_points_begin),
  18554. # (store_random, reg(21), reg(20)),
  18555. # (val_add,reg(21), spawn_points_begin),
  18556. # (assign, "$pout_town", reg(21)),
  18557. # ]),
  18558.  
  18559. #script_cf_select_random_town_with_faction:
  18560. # This script selects a random town in range [towns_begin, towns_end)
  18561. # such that faction of the town is equal to given_faction
  18562. # INPUT:
  18563. # arg1 = faction_no
  18564.  
  18565. #OUTPUT:
  18566. # This script may return false if there is no matching town.
  18567. # reg0 = town_no
  18568. ("cf_select_random_town_with_faction",
  18569. [
  18570. (store_script_param_1, ":faction_no"),
  18571. (assign, ":result", -1),
  18572. # First count num matching spawn points
  18573. (assign, ":no_towns", 0),
  18574. (try_for_range,":cur_town", towns_begin, towns_end),
  18575. (store_faction_of_party, ":cur_faction", ":cur_town"),
  18576. (eq, ":cur_faction", ":faction_no"),
  18577. (val_add, ":no_towns", 1),
  18578. (try_end),
  18579. (gt, ":no_towns", 0), #Fail if there are no towns
  18580. (store_random_in_range, ":random_town", 0, ":no_towns"),
  18581. (assign, ":no_towns", 0),
  18582. (try_for_range,":cur_town", towns_begin, towns_end),
  18583. (eq, ":result", -1),
  18584. (store_faction_of_party, ":cur_faction", ":cur_town"),
  18585. (eq, ":cur_faction", ":faction_no"),
  18586. (val_add, ":no_towns", 1),
  18587. (gt, ":no_towns", ":random_town"),
  18588. (assign, ":result", ":cur_town"),
  18589. (try_end),
  18590. (assign, reg0, ":result"),
  18591. ]),
  18592.  
  18593. #script_cf_select_random_village_with_faction:
  18594. # This script selects a random village in range [villages_begin, villages_end)
  18595. # such that faction of the village is equal to given_faction
  18596. # INPUT:
  18597. # arg1 = faction_no
  18598.  
  18599. #OUTPUT:
  18600. # This script may return false if there is no matching village.
  18601. # reg0 = village_no
  18602. ("cf_select_random_village_with_faction",
  18603. [
  18604. (store_script_param_1, ":faction_no"),
  18605. (assign, ":result", -1),
  18606. # First count num matching spawn points
  18607. (assign, ":no_villages", 0),
  18608. (try_for_range,":cur_village", villages_begin, villages_end),
  18609. (store_faction_of_party, ":cur_faction", ":cur_village"),
  18610. (eq, ":cur_faction", ":faction_no"),
  18611. (val_add, ":no_villages", 1),
  18612. (try_end),
  18613. (gt, ":no_villages", 0), #Fail if there are no villages
  18614. (store_random_in_range, ":random_village", 0, ":no_villages"),
  18615. (assign, ":no_villages", 0),
  18616. (try_for_range,":cur_village", villages_begin, villages_end),
  18617. (eq, ":result", -1),
  18618. (store_faction_of_party, ":cur_faction", ":cur_village"),
  18619. (eq, ":cur_faction", ":faction_no"),
  18620. (val_add, ":no_villages", 1),
  18621. (gt, ":no_villages", ":random_village"),
  18622. (assign, ":result", ":cur_village"),
  18623. (try_end),
  18624. (assign, reg0, ":result"),
  18625. ]),
  18626.  
  18627.  
  18628. #script_cf_select_random_walled_center_with_faction:
  18629. # This script selects a random center in range [centers_begin, centers_end)
  18630. # such that faction of the town is equal to given_faction
  18631. # INPUT:
  18632. # arg1 = faction_no
  18633. # arg2 = preferred_center_no
  18634.  
  18635. #OUTPUT:
  18636. # This script may return false if there is no matching town.
  18637. # reg0 = town_no (Can fail)
  18638. ("cf_select_random_walled_center_with_faction",
  18639. [
  18640. (store_script_param, ":faction_no", 1),
  18641. (store_script_param, ":preferred_center_no", 2),
  18642. (assign, ":result", -1),
  18643. # First count num matching spawn points
  18644. (assign, ":no_centers", 0),
  18645. (try_for_range,":cur_center", walled_centers_begin, walled_centers_end),
  18646. (store_faction_of_party, ":cur_faction", ":cur_center"),
  18647. (eq, ":cur_faction", ":faction_no"),
  18648. (val_add, ":no_centers", 1),
  18649. (eq, ":cur_center", ":preferred_center_no"),
  18650. (val_add, ":no_centers", 99),
  18651. (try_end),
  18652. (gt, ":no_centers", 0), #Fail if there are no centers
  18653. (store_random_in_range, ":random_center", 0, ":no_centers"),
  18654. (try_for_range,":cur_center", walled_centers_begin, walled_centers_end),
  18655. (eq, ":result", -1),
  18656. (store_faction_of_party, ":cur_faction", ":cur_center"),
  18657. (eq, ":cur_faction", ":faction_no"),
  18658. (val_sub, ":random_center", 1),
  18659. (try_begin),
  18660. (eq, ":cur_center", ":preferred_center_no"),
  18661. (val_sub, ":random_center", 99),
  18662. (try_end),
  18663. (lt, ":random_center", 0),
  18664. (assign, ":result", ":cur_center"),
  18665. (try_end),
  18666. (assign, reg0, ":result"),
  18667. ]),
  18668.  
  18669.  
  18670. #script_cf_select_random_walled_center_with_faction_and_owner_priority_no_siege:
  18671. # INPUT:
  18672. # arg1 = faction_no
  18673. # arg2 = owner_troop_no
  18674. #OUTPUT:
  18675. # This script may return false if there is no matching town.
  18676. # reg0 = center_no (Can fail)
  18677. ("cf_select_random_walled_center_with_faction_and_owner_priority_no_siege",
  18678. [
  18679. (store_script_param, ":faction_no", 1),
  18680. (store_script_param, ":troop_no", 2),
  18681. (assign, ":result", -1),
  18682. (assign, ":no_centers", 0),
  18683.  
  18684. #SB : faction active conditional
  18685. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  18686. (call_script, "script_lord_get_home_center", ":troop_no"),
  18687. (assign, ":home_center", reg0),
  18688.  
  18689. (try_for_range,":cur_center", walled_centers_begin, walled_centers_end),
  18690. (store_faction_of_party, ":cur_faction", ":cur_center"),
  18691. (eq, ":cur_faction", ":faction_no"),
  18692. (party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
  18693. (val_add, ":no_centers", 1),
  18694.  
  18695. #(party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
  18696. (eq, ":home_center", ":cur_center"), #I changed it with above line, now if lord is owner of any village its bound walled center is counted as 1000. Better this way. ozan-18.01.09
  18697.  
  18698. (val_add, ":no_centers", 1000),
  18699. (try_end),
  18700.  
  18701. #if no center is available count all centers not besieged do not care its faction.
  18702. (try_begin),
  18703. (le, ":no_centers", 0),
  18704. (ge, "$g_dplmc_lord_recycling", DPLMC_LORD_RECYCLING_ENABLE),
  18705. (assign, "$g_there_is_no_avaliable_centers", 1),
  18706.  
  18707. (try_for_range,":cur_center", walled_centers_begin, walled_centers_end),
  18708. #SB : probably original faction
  18709. (party_slot_eq, ":cur_center", slot_center_original_faction, ":faction_no"),
  18710. (party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
  18711. (val_add, ":no_centers", 1),
  18712. (try_end),
  18713. (else_try),
  18714. (assign, "$g_there_is_no_avaliable_centers", 0),
  18715. (try_end),
  18716.  
  18717. # (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader), #SB : only one check
  18718. (this_or_next|eq, "$g_there_is_no_avaliable_centers", 0),
  18719. (neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":troop_no"), #faction leaders cannot spawn if they have no centers.
  18720.  
  18721. (store_random_in_range, ":random_center", 0, ":no_centers"),
  18722. (try_for_range,":cur_center", walled_centers_begin, walled_centers_end),
  18723. (eq, ":result", -1),
  18724. (store_faction_of_party, ":cur_faction", ":cur_center"),
  18725. (this_or_next|eq, "$g_there_is_no_avaliable_centers", 1),
  18726. (eq, ":cur_faction", ":faction_no"),
  18727. (party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
  18728. (val_sub, ":random_center", 1),
  18729. (try_begin),
  18730. #(party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
  18731. (eq, ":home_center", ":cur_center"), #I changed it with above line, now if lord is owner of any village its bound walled center is counted as 1000. Better this way. ozan-18.01.09
  18732. (eq, "$g_there_is_no_avaliable_centers", 0),
  18733.  
  18734. (val_sub, ":random_center", 1000),
  18735. (try_end),
  18736. (lt, ":random_center", 0),
  18737. (assign, ":result", ":cur_center"),
  18738. (try_end),
  18739. (assign, reg0, ":result"),
  18740. ]),
  18741.  
  18742.  
  18743. #script_cf_select_random_walled_center_with_faction_and_less_strength_priority:
  18744. # This script selects a random center in range [centers_begin, centers_end)
  18745. # such that faction of the town is equal to given_faction
  18746. # INPUT:
  18747. # arg1 = faction_no
  18748. # arg2 = preferred_center_no
  18749.  
  18750. #OUTPUT:
  18751. # This script may return false if there is no matching town.
  18752. # reg0 = town_no (Can fail)
  18753. ("cf_select_random_walled_center_with_faction_and_less_strength_priority",
  18754. [
  18755. (store_script_param, ":faction_no", 1),
  18756. (store_script_param, ":preferred_center_no", 2),
  18757. (assign, ":result", -1),
  18758. # First count num matching spawn points
  18759. (assign, ":no_centers", 0),
  18760. (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
  18761. (store_faction_of_party, ":cur_faction", ":cur_center"),
  18762. (eq, ":cur_faction", ":faction_no"),
  18763. (party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
  18764. (val_add, ":no_centers", 1),
  18765. (try_begin),
  18766. (eq, ":cur_center", ":preferred_center_no"),
  18767. (val_add, ":no_centers", 99),
  18768. (try_end),
  18769. ## (call_script, "script_party_calculate_regular_strength", ":cur_center"),
  18770. ## (assign, ":strength", reg0),
  18771. ## (lt, ":strength", 80),
  18772. ## (store_sub, ":strength", 100, ":strength"),
  18773. ## (val_div, ":strength", 20),
  18774. ## (val_add, ":no_centers", ":strength"),
  18775. (try_end),
  18776. (gt, ":no_centers", 0), #Fail if there are no centers
  18777. (store_random_in_range, ":random_center", 0, ":no_centers"),
  18778. (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
  18779. (eq, ":result", -1),
  18780. (store_faction_of_party, ":cur_faction", ":cur_center"),
  18781. (eq, ":cur_faction", ":faction_no"),
  18782. (party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
  18783. (val_sub, ":random_center", 1),
  18784. (try_begin),
  18785. (eq, ":cur_center", ":preferred_center_no"),
  18786. (val_sub, ":random_center", 99),
  18787. (try_end),
  18788. ## (try_begin),
  18789. ## (call_script, "script_party_calculate_regular_strength", ":cur_center"),
  18790. ## (assign, ":strength", reg0),
  18791. ## (lt, ":strength", 80),
  18792. ## (store_sub, ":strength", 100, ":strength"),
  18793. ## (val_div, ":strength", 20),
  18794. ## (val_sub, ":random_center", ":strength"),
  18795. ## (try_end),
  18796. (lt, ":random_center", 0),
  18797. (assign, ":result", ":cur_center"),
  18798. (try_end),
  18799. (assign, reg0, ":result"),
  18800. ]),
  18801.  
  18802.  
  18803. #script_cf_select_random_town_at_peace_with_faction:
  18804. # This script selects a random town in range [towns_begin, towns_end)
  18805. # such that faction of the town is friendly to given_faction
  18806. # INPUT:
  18807. # arg1 = faction_no
  18808.  
  18809. #OUTPUT:
  18810. # This script may return false if there is no matching town.
  18811. # reg0 = town_no
  18812. ("cf_select_random_town_at_peace_with_faction",
  18813. [
  18814. (store_script_param_1, ":faction_no"),
  18815. (assign, ":result", -1),
  18816. # First count num matching towns
  18817. (assign, ":no_towns", 0),
  18818. (try_for_range,":cur_town", towns_begin, towns_end),
  18819. (store_faction_of_party, ":cur_faction", ":cur_town"),
  18820. (store_relation,":reln", ":cur_faction", ":faction_no"),
  18821. (ge, ":reln", 0),
  18822. (val_add, ":no_towns", 1),
  18823. (try_end),
  18824. (gt, ":no_towns", 0), #Fail if there are no towns
  18825. (store_random_in_range, ":random_town", 0, ":no_towns"),
  18826. (assign, ":no_towns", 0),
  18827. (try_for_range,":cur_town", towns_begin, towns_end),
  18828. (eq, ":result", -1),
  18829. (store_faction_of_party, ":cur_faction", ":cur_town"),
  18830. (store_relation,":reln", ":cur_faction", ":faction_no"),
  18831. (ge, ":reln", 0),
  18832. (val_add, ":no_towns", 1),
  18833. (gt, ":no_towns", ":random_town"),
  18834. (assign, ":result", ":cur_town"),
  18835. (try_end),
  18836. (assign, reg0, ":result"),
  18837. ]),
  18838.  
  18839. #script_cf_select_random_town_at_peace_with_faction_in_trade_route
  18840. # INPUT:
  18841. # arg1 = town_no
  18842. # arg2 = faction_no
  18843.  
  18844. #OUTPUT:
  18845. # This script may return false if there is no matching town.
  18846. # reg0 = town_no
  18847. ("cf_select_random_town_at_peace_with_faction_in_trade_route",
  18848. [
  18849. (store_script_param, ":town_no", 1),
  18850. (store_script_param, ":faction_no", 2),
  18851. (assign, ":result", -1),
  18852. (assign, ":no_towns", 0),
  18853. (try_for_range, ":cur_slot", slot_town_trade_routes_begin, slot_town_trade_routes_end),
  18854. (party_get_slot, ":cur_town", ":town_no", ":cur_slot"),
  18855. (gt, ":cur_town", 0),
  18856. (store_faction_of_party, ":cur_faction", ":cur_town"),
  18857. (store_relation, ":reln", ":cur_faction", ":faction_no"),
  18858. (ge, ":reln", 0),
  18859. (val_add, ":no_towns", 1),
  18860. (try_end),
  18861. (gt, ":no_towns", 0), #Fail if there are no towns
  18862. (store_random_in_range, ":random_town", 0, ":no_towns"),
  18863. (try_for_range, ":cur_slot", slot_town_trade_routes_begin, slot_town_trade_routes_end),
  18864. (eq, ":result", -1),
  18865. (party_get_slot, ":cur_town", ":town_no", ":cur_slot"),
  18866. (gt, ":cur_town", 0),
  18867. (store_faction_of_party, ":cur_faction", ":cur_town"),
  18868. (store_relation, ":reln", ":cur_faction", ":faction_no"),
  18869. (ge, ":reln", 0),
  18870. (val_sub, ":random_town", 1),
  18871. (lt, ":random_town", 0),
  18872. (assign, ":result", ":cur_town"),
  18873. (try_end),
  18874. (assign, reg0, ":result"),
  18875. ]),
  18876.  
  18877.  
  18878.  
  18879. #the following is a very simple adjustment - it measures the difference in prices between two towns
  18880. #all goods are weighted equally except for luxuries
  18881. #it does not take into account the prices of the goods, nor cargo capacity
  18882. #to do that properly, a merchant would have to virtually fill his baggage, slot by slot, for each town
  18883. #i also found that one needed to introduce demand inelasticity -- prices should vary a lot for grain, relatively little for iron
  18884. ##diplomacy start+
  18885. #
  18886. #Added a third parameter, the caravan party, for use in distance calculations and perhaps
  18887. #other things in the future. This may be -1, in which case the script attempts to find a
  18888. #general answer without referring to any specific attributes. It may also be a town,
  18889. #in which case its position is used for distance calculations.
  18890. ##diplomacy end+
  18891. ("cf_select_most_profitable_town_at_peace_with_faction_in_trade_route",
  18892. [
  18893. (store_script_param, ":town_no", 1),
  18894. (store_script_param, ":faction_no", 2),
  18895. ##diplomacy start+
  18896. (store_script_param, ":perspective_party", 3),
  18897. ##diplomacy end+
  18898.  
  18899. (assign, ":result", -1),
  18900. (assign, ":best_town_score", 0),
  18901. (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  18902.  
  18903. ##diplomacy start+
  18904. # If economics changes are enabled, the caravan may also take into account the distance
  18905. # to the destination or bias towards towns of its town faction.
  18906. (store_random_in_range, ":consider_distance", 0, 2),
  18907. (store_random_in_range, ":faction_bias", 0, 2),
  18908. (try_begin),
  18909. (lt, ":perspective_party", 0),
  18910. (assign, ":perspective_party", ":town_no"),
  18911. (try_end),
  18912. ##diplomacy end+
  18913.  
  18914. (try_for_range, ":cur_slot", slot_town_trade_routes_begin, slot_town_trade_routes_end),
  18915. (party_get_slot, ":cur_town", ":town_no", ":cur_slot"),
  18916. (gt, ":cur_town", 0),
  18917.  
  18918. (store_faction_of_party, ":cur_faction", ":cur_town"),
  18919. (store_relation, ":reln", ":cur_faction", ":faction_no"),
  18920. (ge, ":reln", 0),
  18921.  
  18922. (assign, ":cur_town_score", 0),
  18923. (try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
  18924. (neq, ":cur_goods", "itm_butter"), #Don't count perishables
  18925. (neq, ":cur_goods", "itm_cattle_meat"),
  18926. (neq, ":cur_goods", "itm_chicken"),
  18927. (neq, ":cur_goods", "itm_pork"),
  18928.  
  18929. (store_add, ":cur_goods_price_slot", ":cur_goods", ":item_to_price_slot"),
  18930. (party_get_slot, ":origin_price", ":town_no", ":cur_goods_price_slot"),
  18931. (party_get_slot, ":destination_price", ":cur_town", ":cur_goods_price_slot"),
  18932.  
  18933. (gt, ":destination_price", ":origin_price"),
  18934. (store_sub, ":price_dif", ":destination_price", ":origin_price"),
  18935.  
  18936. (try_begin), #weight luxury goods double
  18937. (this_or_next|eq, ":cur_goods", "itm_spice"),
  18938. (eq, ":cur_goods", "itm_velvet"),
  18939. (val_mul, ":price_dif", 2),
  18940. (try_end),
  18941. (val_add, ":cur_town_score", ":price_dif"),
  18942. (try_end),
  18943.  
  18944. ## (try_begin),
  18945. ## (eq, "$cheat_mode", 1),
  18946. ## (str_store_party_name, s10, ":town_no"),
  18947. ## (str_store_party_name, s11, ":cur_town"),
  18948. ## (assign, reg3, ":cur_town_score"),
  18949. ## (display_message, "str_caravan_in_s10_considers_s11_total_price_dif_=_reg3"),
  18950. ## (try_end),
  18951.  
  18952. ##diplomacy start+
  18953. (try_begin),
  18954. #Economic changes must be enabled, or the player must have decided
  18955. #to use mercantilism settings (which expresses a desire to see changes
  18956. #related to that setting applied), or a trade treaty must be in effect.
  18957. (this_or_next|neg|faction_slot_eq, "fac_player_supporters_faction", dplmc_slot_faction_mercantilism, 0),
  18958. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  18959. #Take into account distance, or treat factions preferentially
  18960. (try_begin),
  18961. #Bias towards own faction
  18962. (ge, ":faction_bias", 1),
  18963. (neq, ":faction_no", ":cur_faction"),
  18964.  
  18965. ##The penalty is based on the source faction's mercantilism rating, as well as
  18966. ##the other faction's mercantilism rating.
  18967. (faction_get_slot, ":source_mercantilism", ":faction_no", dplmc_slot_faction_mercantilism),
  18968. (val_clamp, ":source_mercantilism", -3, 4),
  18969. (faction_get_slot, ":dest_mercantilism", ":cur_faction", dplmc_slot_faction_mercantilism),
  18970. (val_clamp, ":dest_mercantilism", -3, 4),
  18971. ##Default (if both factions have mercantilism 0) is a 6% reduction. Possible range is 0% (least) to 12% (most).
  18972. (store_sub, ":percent", 94, ":source_mercantilism"),
  18973. (val_sub, ":percent", ":dest_mercantilism"),
  18974.  
  18975. (val_mul, ":cur_town_score", ":percent"),
  18976. (val_add, ":cur_town_score", 50),
  18977. (val_div, ":cur_town_score", 100),
  18978. (try_end),
  18979. (try_begin),
  18980. (ge, ":consider_distance", 1),#consider distance
  18981. (store_distance_to_party_from_party, ":dist", ":perspective_party",":cur_town"),
  18982. #Avoid asymptotic effects and undue weighting.
  18983. #Further explanation: What we really care about is time, not distance.
  18984. #It will take time to buy and sell once reaching our destination: halving
  18985. #the distance doesn't double the expected profit per month.
  18986. (val_max, ":dist", 0),
  18987. (val_add, ":dist", 12),
  18988. #Avoid possible problems trying to compare distant towns
  18989. (val_mul, ":cur_town_score", 100),
  18990. (val_div, ":cur_town_score", ":dist"),
  18991. (try_end),
  18992. (try_end),
  18993. ##diplomacy end+
  18994.  
  18995. (gt, ":cur_town_score", ":best_town_score"),
  18996. (assign, ":best_town_score", ":cur_town_score"),
  18997. (assign, ":result", ":cur_town"),
  18998.  
  18999. (try_end),
  19000.  
  19001. (gt, ":result", -1), #Fail if there are no towns
  19002.  
  19003. (assign, reg0, ":result"),
  19004.  
  19005. # (store_current_hours, ":hour"),
  19006. # (party_set_slot, ":result", slot_town_caravan_last_visit, ":hour"),
  19007.  
  19008. ## (try_begin),
  19009. ## (eq, "$cheat_mode", 1),
  19010. ## (assign, reg3, ":best_town_score"),
  19011. ## (str_store_party_name, s3, ":town_no"),
  19012. ## (str_store_party_name, s4, ":result"),
  19013. ## (display_message, "str_test__caravan_in_s3_selects_for_s4_trade_score_reg3"),
  19014. ## (try_end),
  19015.  
  19016. ]),
  19017.  
  19018.  
  19019. ## ("cf_select_faction_spawn_point",
  19020. ## [
  19021. ## # First count num matching spawn points
  19022. ## (assign, reg(24), 0),
  19023. ## (try_for_range,reg(25), spawn_points_begin, spawn_points_end),
  19024. ## (store_faction_of_party, reg(23), reg(25)),
  19025. ## (eq, reg(23), "$pin_faction"),
  19026. ## (val_add, reg(24), 1),
  19027. ## (end_try,0),
  19028. ## # reg4 now holds num towns of this faction.
  19029. ## (gt, reg(24), 0), #Fail if there are no towns
  19030. ## (store_random, reg(26), reg(24)),
  19031. ##
  19032. ## (assign, reg(24), 0), # reg24 = num points of this faction.
  19033. ## (try_for_range,reg(25), spawn_points_begin, spawn_points_end),
  19034. ## (store_faction_of_party, reg(23), reg(25)),
  19035. ## (eq, reg(23), "$pin_faction"),
  19036. ## (try_begin,0),
  19037. ## (eq, reg(24), reg(26)),
  19038. ## (assign, "$pout_town", reg(25)), # result is this town
  19039. ## (end_try,0),
  19040. ## (val_add, reg(24), 1),
  19041. ## (end_try,0),
  19042. ## ]),
  19043.  
  19044.  
  19045. #script_spawn_party_at_random_town:
  19046. # This script selects a random town in range [towns_begin, towns_end)
  19047. # such that faction of the town is equal to given_faction
  19048. # and spawns a new party there.
  19049. # INPUT:
  19050. # $pin_faction: given_faction
  19051. # $pin_party_template: given_party_template
  19052.  
  19053. #OUTPUT:
  19054. # This script may return false if party cannot be spawned.
  19055. # $pout_party: id of the spawned party
  19056. ## ("spawn_party_at_random_town",
  19057. ## [
  19058. ## (call_script,"script_select_random_spawn_point"),
  19059. ## (set_spawn_radius,1),
  19060. ## (spawn_around_party,"$pout_town","$pin_party_template"),
  19061. ## (assign, "$pout_party", reg(0)),
  19062. ## ]),
  19063.  
  19064. #script_cf_spawn_party_at_faction_town:
  19065. # This script selects a random town in range [towns_begin, towns_end)
  19066. # such that faction of the town is equal to given_faction
  19067. # and spawns a new party there.
  19068. # INPUT:
  19069. # $pin_faction: given_faction
  19070. # $pin_party_template: given_party_template
  19071.  
  19072. #OUTPUT:
  19073. # This script may return false if party cannot be spawned.
  19074. # $pout_party: id of the spawned party
  19075. ## ("cf_spawn_party_at_faction_town",
  19076. ## [
  19077. ## (call_script,"script_cf_select_faction_spawn_point"),
  19078. ## (set_spawn_radius,1),
  19079. ## (spawn_around_party,"$pout_town","$pin_party_template"),
  19080. ## (assign, "$pout_party", reg(0)),
  19081. ## ]),
  19082.  
  19083. #script_spawn_party_at_random_town_if_below_limit:
  19084. # This script checks if number of parties
  19085. # of specified template is less than limit,
  19086. # If so, it selects a random town in range [towns_begin, towns_end)
  19087. # and spawns a new party there.
  19088. # INPUT:
  19089. # $pin_party_template: given_party_template
  19090. # $pin_limit: limit value
  19091.  
  19092. #OUTPUT:
  19093. # $pout_party: id of the spawned party
  19094. # $pout_town: id of the selected faction town
  19095. # Note:
  19096. # This script may return false if number of parties
  19097. # of specified template is greater or equal to limit,
  19098. # or if party cannot be spawned.
  19099. ## ("cf_spawn_party_at_random_town_if_below_limit",
  19100. ## [
  19101. ## (store_num_parties_of_template, reg(22), "$pin_party_template"),
  19102. ## (lt,reg(22),"$pin_limit"), #check if we are below limit.
  19103. ## (call_script,"script_select_random_spawn_point"),
  19104. ## (set_spawn_radius,1),
  19105. ## (spawn_around_party,"$pout_town","$pin_party_template"),
  19106. ## (assign, "$pout_party", reg(0)),
  19107. ## ]),
  19108.  
  19109. ## #script_spawn_party_at_faction_town_if_below_limit:
  19110. ## # This script checks if number of parties
  19111. ## # of specified template is less than limit,
  19112. ## # If so, it selects a random town in range [towns_begin, towns_end)
  19113. ## # such that faction of the town is equal to given_faction
  19114. ## # and spawns a new party there.
  19115. ## # INPUT:
  19116. ## # $pin_faction: given_faction
  19117. ## # $pin_party_template: given_party_template
  19118. ## # $pin_limit: limit value
  19119. ##
  19120. ## #OUTPUT:
  19121. ## # $pout_party: id of the spawned party
  19122. ## # $pout_town: id of the selected faction town
  19123. ## # Note:
  19124. ## # This script may return false if number of parties
  19125. ## # of specified template is greater or equal to limit,
  19126. ## # or if party cannot be spawned.
  19127. ## ("cf_spawn_party_at_faction_town_if_below_limit",
  19128. ## [
  19129. ## (store_num_parties_of_template, reg(22), "$pin_party_template"),
  19130. ## (lt,reg(22),"$pin_limit"), #check if we are below limit.
  19131. ## (call_script,"script_cf_select_faction_spawn_point"),
  19132. ## (set_spawn_radius,1),
  19133. ## (spawn_around_party,"$pout_town","$pin_party_template"),
  19134. ## (assign, "$pout_party", reg(0)),
  19135. ## ]),
  19136.  
  19137. # script_shuffle_troop_slots:
  19138. # Shuffles a range of slots of a given troop.
  19139. # Used for exploiting a troop as an array.
  19140. # Input: arg1 = troop_no, arg2 = slot_begin, arg3 = slot_end
  19141. ("shuffle_troop_slots",
  19142. [
  19143. (store_script_param, ":troop_no", 1),
  19144. (store_script_param, ":slots_begin", 2),
  19145. (store_script_param, ":slots_end", 3),
  19146. (try_for_range, ":cur_slot_no", ":slots_begin", ":slots_end"),
  19147. (store_random_in_range, ":random_slot_no", ":slots_begin", ":slots_end"), #reg(58) = random slot. Now exchange slots reg(57) and reg(58)
  19148. (troop_get_slot, ":cur_slot_value", ":troop_no", ":cur_slot_no"), #temporarily store the value in slot reg(57) in reg(59)
  19149. (troop_get_slot, ":random_slot_value", ":troop_no", ":random_slot_no"), #temporarily store the value in slot reg(58) in reg(60)
  19150. (troop_set_slot, ":troop_no", ":cur_slot_no", ":random_slot_value"), # Now exchange the two...
  19151. (troop_set_slot, ":troop_no", ":random_slot_no", ":cur_slot_value"),
  19152. (try_end),
  19153. ]),
  19154.  
  19155.  
  19156. # script_get_quest - combines old get_random_quest with new get_dynamic_quest
  19157.  
  19158. # Input: arg1 = troop_no (of the troop in conversation), arg2 = min_importance (of the quest)
  19159. # Output: reg0 = quest_no (the slots of the quest will be filled after calling this script)
  19160. ("get_quest",
  19161. [
  19162. (store_script_param_1, ":giver_troop"),
  19163.  
  19164. (store_character_level, ":player_level", "trp_player"),
  19165. (store_troop_faction, ":giver_faction_no", ":giver_troop"),
  19166.  
  19167. (troop_get_slot, ":giver_party_no", ":giver_troop", slot_troop_leaded_party),
  19168. (troop_get_slot, ":giver_reputation", ":giver_troop", slot_lord_reputation_type),
  19169.  
  19170. (assign, ":giver_center_no", -1),
  19171. (try_begin),
  19172. (gt, ":giver_party_no", 0),
  19173. (party_get_attached_to, ":giver_center_no", ":giver_party_no"),
  19174. (else_try),
  19175. (is_between, "$g_encountered_party", centers_begin, centers_end),
  19176. (assign, ":giver_center_no", "$g_encountered_party"),
  19177. (try_end),
  19178.  
  19179. ##diplomacy start+
  19180. (call_script, "script_troop_get_player_relation", ":giver_troop"),
  19181. (assign, ":giver_relation", reg0),
  19182. (store_relation, ":giver_faction_relation", ":giver_faction_no", "fac_player_faction"),
  19183. #Assign some variables used later (mostly in lord checks) to re-enable
  19184. #quests which are usually disabled once the player has received homage.
  19185. (assign, ":is_close", 0),
  19186. (assign, ":nominal_superior", 0),
  19187. (try_begin),
  19188. #is valid hero:
  19189. (is_between, ":giver_troop", heroes_begin, heroes_end),
  19190. (troop_slot_ge, ":giver_troop", slot_troop_occupation, slto_inactive + 1),
  19191. (neg|troop_slot_ge, ":giver_troop", slot_troop_occupation, slto_retirement),
  19192.  
  19193. #is close:
  19194. (try_begin),
  19195. #affiliates, and spouse
  19196. (call_script, "script_dplmc_is_affiliated_family_member", ":giver_troop"),
  19197. (this_or_next|ge, reg0, 1),
  19198. (troop_slot_eq, "trp_player", slot_troop_spouse, ":giver_troop"),
  19199. (assign, ":is_close", 1),
  19200. (else_try),
  19201. (ge, ":giver_faction_relation", 0),
  19202. (ge, ":giver_relation", 50),
  19203. (try_begin),
  19204. (this_or_next|is_between, ":giver_troop", companions_begin, companions_end),
  19205. (is_between, ":giver_troop", pretenders_begin, pretenders_end),
  19206. (this_or_next|troop_slot_eq, ":giver_troop", slot_troop_occupation, slto_kingdom_hero),
  19207. (troop_slot_eq, ":giver_troop", slot_troop_occupation, slto_player_companion),
  19208. (neg|troop_slot_eq, ":giver_troop", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  19209. (assign, ":is_close", 1),
  19210. (else_try),
  19211. #(call_script, "script_troop_get_family_relation_to_troop", ":giver_troop", "trp_player"),
  19212. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":giver_troop", "trp_player"),
  19213. (ge, reg0, 2),
  19214. (assign, ":is_close", 1),
  19215. (try_end),
  19216. (try_end),
  19217.  
  19218. #is nominally the social superior of the player (or even if not the superior,
  19219. #is allowed to give the player orders in at least one context)
  19220. (try_begin),
  19221. #quest giver is faction leader or marshall, or player's father or mother
  19222. (this_or_next|troop_slot_eq, "trp_player", slot_troop_father, ":giver_troop"),
  19223. (this_or_next|troop_slot_eq, "trp_player", slot_troop_mother, ":giver_troop"),
  19224. (this_or_next|faction_slot_eq, ":giver_faction_no", slot_faction_leader, ":giver_troop"),
  19225. (faction_slot_eq, ":giver_faction_no", slot_faction_marshall, ":giver_troop"),
  19226. (assign, ":nominal_superior", 1),
  19227. (else_try),
  19228. #player has less than 3/4 of the quest giver's renown
  19229. (troop_get_slot, reg0, ":giver_troop", slot_troop_renown),
  19230. (val_mul, reg0, 3),
  19231. (val_div, reg0, 4),
  19232. (neg|troop_slot_ge, "trp_player", slot_troop_renown, reg0),
  19233. (assign, ":nominal_superior", 1),
  19234. (else_try),
  19235. #quest giver is player's father-in-law or mother-in-law
  19236. (troop_get_slot, ":player_spouse", "trp_player", slot_troop_spouse),
  19237. (is_between, ":player_spouse", heroes_begin, heroes_end),
  19238. (this_or_next|troop_slot_eq, ":player_spouse", slot_troop_father, ":giver_troop"),
  19239. (troop_slot_eq, ":player_spouse", slot_troop_mother, ":giver_troop"),
  19240. (assign, ":nominal_superior", 1),
  19241. (try_end),
  19242. (try_end),
  19243. ##diplomacy end+
  19244.  
  19245. (try_begin),
  19246. (troop_slot_eq, ":giver_troop", slot_troop_occupation, slto_kingdom_hero),
  19247. (try_begin),
  19248. (ge, "$g_talk_troop_faction_relation", 0),
  19249. (assign, ":quests_begin", lord_quests_begin),
  19250. (assign, ":quests_end", lord_quests_end),
  19251. (assign, ":quests_begin_2", lord_quests_begin_2),
  19252. (assign, ":quests_end_2", lord_quests_end_2),
  19253. (else_try),
  19254. (assign, ":quests_begin", enemy_lord_quests_begin),
  19255. (assign, ":quests_end", enemy_lord_quests_end),
  19256. (assign, ":quests_begin_2", 0),
  19257. (assign, ":quests_end_2", 0),
  19258. (try_end),
  19259. (else_try),
  19260. (is_between, ":giver_troop", village_elders_begin, village_elders_end),
  19261. (assign, ":quests_begin", village_elder_quests_begin),
  19262. (assign, ":quests_end", village_elder_quests_end),
  19263. (assign, ":quests_begin_2", village_elder_quests_begin_2),
  19264. (assign, ":quests_end_2", village_elder_quests_end_2),
  19265. (else_try),
  19266. (is_between, ":giver_troop", mayors_begin, mayors_end),
  19267. (assign, ":quests_begin", mayor_quests_begin),
  19268. (assign, ":quests_end", mayor_quests_end),
  19269. (assign, ":quests_begin_2", mayor_quests_begin_2),
  19270. (assign, ":quests_end_2", mayor_quests_end_2),
  19271. (else_try),
  19272. (assign, ":quests_begin", lady_quests_begin),
  19273. (assign, ":quests_end", lady_quests_end),
  19274. (assign, ":quests_begin_2", lady_quests_begin_2),
  19275. (assign, ":quests_end_2", lady_quests_end_2),
  19276. (try_end),
  19277.  
  19278. (assign, ":result", -1),
  19279. (assign, ":quest_target_troop", -1),
  19280. (assign, ":quest_target_center", -1),
  19281. (assign, ":quest_target_faction", -1),
  19282. (assign, ":quest_object_faction", -1),
  19283. (assign, ":quest_object_troop", -1),
  19284. (assign, ":quest_object_center", -1),
  19285. (assign, ":quest_target_party", -1),
  19286. (assign, ":quest_target_party_template", -1),
  19287. (assign, ":quest_target_amount", -1),
  19288. (assign, ":quest_target_dna", -1),
  19289. (assign, ":quest_target_item", -1),
  19290. (assign, ":quest_importance", 1),
  19291. (assign, ":quest_xp_reward", 0),
  19292. (assign, ":quest_gold_reward", 0),
  19293. (assign, ":quest_convince_value", 0),
  19294. (assign, ":quest_expiration_days", 0),
  19295. (assign, ":quest_dont_give_again_period", 0),
  19296.  
  19297. (try_begin), #get dynamic quest is a separate script, so that we can scan a number of different troops at once for it
  19298. (call_script, "script_get_dynamic_quest", "$g_talk_troop"),
  19299.  
  19300. (assign, ":result", reg0),
  19301. (assign, ":relevant_troop", reg1),
  19302. (assign, ":relevant_party", reg2),
  19303. (assign, ":relevant_faction", reg3),
  19304.  
  19305. #GUILDMASTER QUESTS
  19306. (try_begin),
  19307. (eq, ":result", "qst_track_down_bandits"),
  19308. (assign, ":quest_target_party", ":relevant_party"),
  19309. (assign ,":quest_expiration_days", 60),
  19310. (assign, ":quest_xp_reward", 1000),
  19311. (assign, ":quest_gold_reward", 1000),
  19312.  
  19313. (else_try),
  19314. (eq, ":result", "qst_retaliate_for_border_incident"),
  19315. (assign, ":quest_target_troop", ":relevant_troop"),
  19316. (assign, ":quest_target_faction", ":relevant_faction"),
  19317.  
  19318. (assign ,":quest_expiration_days", 30),
  19319. (assign, ":quest_xp_reward", 1000),
  19320. (assign, ":quest_gold_reward", 1000),
  19321.  
  19322. #KINGDOM LORD QUESTS
  19323. (else_try),
  19324. (eq, ":result", "qst_cause_provocation"),
  19325. (assign, ":quest_target_faction", ":relevant_faction"),
  19326. (assign, ":quest_expiration_days", 30),
  19327. (assign, ":quest_dont_give_again_period", 100),
  19328. (assign, ":quest_xp_reward", 1000),
  19329. (assign, ":quest_gold_reward", 1000),
  19330.  
  19331. (else_try),
  19332. (eq, ":result", "qst_destroy_bandit_lair"),
  19333. (assign, ":quest_target_party", ":relevant_party"),
  19334. (assign ,":quest_expiration_days", 60),
  19335. (assign, ":quest_xp_reward", 3000),
  19336. (assign, ":quest_gold_reward", 1500),
  19337.  
  19338. #KINGDOM LADY OR KINGDOM HERO QUESTS
  19339. (else_try),
  19340. (eq, ":result", "qst_rescue_prisoner"),
  19341. (assign, ":quest_target_troop", ":relevant_troop"),
  19342. (assign, ":quest_target_center", ":relevant_party"),
  19343.  
  19344. (assign, ":quest_expiration_days", 30),
  19345. (assign, ":quest_dont_give_again_period", 5),
  19346. (assign, ":quest_importance", 2),
  19347. (assign, ":quest_xp_reward", 1500),
  19348. (assign, ":quest_gold_reward", 2000), #actual reward in dialogues
  19349. (store_character_level, ":quest_convince_value", ":quest_target_troop"),
  19350. (val_mul, ":quest_convince_value", 65), #SB : we normalize this to match the gold reward for ~level 30 lords
  19351. (call_script, "script_calculate_ransom_amount_for_troop", ":quest_target_troop"), #SB: calculate a set amount
  19352. (assign, ":quest_target_amount", reg0),
  19353. (try_end),
  19354. (try_end),
  19355.  
  19356. #no dynamic quest available
  19357. (try_begin),
  19358. (eq, ":result", -1),
  19359.  
  19360. (try_for_range, ":unused", 0, 20), #Repeat trial twenty times
  19361. (eq, ":result", -1),
  19362. (assign, ":quest_target_troop", -1),
  19363. (assign, ":quest_target_center", -1),
  19364. (assign, ":quest_target_faction", -1),
  19365. (assign, ":quest_object_faction", -1),
  19366. (assign, ":quest_object_troop", -1),
  19367. (assign, ":quest_object_center", -1),
  19368. (assign, ":quest_target_party", -1),
  19369. (assign, ":quest_target_party_template", -1),
  19370. (assign, ":quest_target_amount", -1),
  19371. (assign, ":quest_target_dna", -1),
  19372. (assign, ":quest_target_item", -1),
  19373. (assign, ":quest_importance", 1),
  19374. (assign, ":quest_xp_reward", 0),
  19375. (assign, ":quest_gold_reward", 0),
  19376. (assign, ":quest_convince_value", 0),
  19377. (assign, ":quest_expiration_days", 0),
  19378. (assign, ":quest_dont_give_again_period", 0),
  19379.  
  19380. (store_sub, ":num_possible_old_quests", ":quests_end", ":quests_begin"),
  19381. (store_sub, ":num_possible_new_quests", ":quests_end_2", ":quests_begin_2"),
  19382. (store_add, ":num_possible_total_quests", ":num_possible_old_quests", ":num_possible_new_quests"),
  19383.  
  19384. (store_random_in_range, ":quest_no", 0, ":num_possible_total_quests"),
  19385. (try_begin),
  19386. (lt, ":quest_no", ":num_possible_old_quests"),
  19387. (store_random_in_range, ":quest_no", ":quests_begin", ":quests_end"),
  19388. (else_try),
  19389. (store_random_in_range, ":quest_no", ":quests_begin_2", ":quests_end_2"),
  19390. (try_end),
  19391.  
  19392. (neg|check_quest_active,":quest_no"),
  19393. (neg|quest_slot_ge, ":quest_no", slot_quest_dont_give_again_remaining_days, 1),
  19394. (try_begin),
  19395. # Village Elder quests
  19396. (eq, ":quest_no", "qst_deliver_grain"),
  19397. (try_begin),
  19398. (is_between, ":giver_center_no", villages_begin, villages_end),
  19399. #The quest giver is the village elder
  19400. (call_script, "script_get_troop_item_amount", ":giver_troop", "itm_grain"),
  19401. (eq, reg0, 0),
  19402. (neg|party_slot_ge, ":giver_center_no", slot_town_prosperity, 40),
  19403. (assign, ":quest_target_center", ":giver_center_no"),
  19404. (store_random_in_range, ":quest_target_amount", 4, 8),
  19405. (assign, ":quest_expiration_days", 30),
  19406. (assign, ":quest_dont_give_again_period", 20),
  19407. (assign, ":result", ":quest_no"),
  19408. (try_end),
  19409. (else_try),
  19410. (eq, ":quest_no", "qst_deliver_cattle"),
  19411. (try_begin),
  19412. (is_between, ":giver_center_no", villages_begin, villages_end),
  19413. #The quest giver is the village elder
  19414. (party_get_slot, ":num_cattle", ":giver_center_no", slot_village_number_of_cattle),
  19415. (lt, ":num_cattle", 50),
  19416. (assign, ":quest_target_center", ":giver_center_no"),
  19417. (store_random_in_range, ":quest_target_amount", 5, 10),
  19418. (assign, ":quest_expiration_days", 30),
  19419. (assign, ":quest_dont_give_again_period", 20),
  19420. (assign, ":result", ":quest_no"),
  19421. (try_end),
  19422. (else_try),
  19423. (eq, ":quest_no", "qst_train_peasants_against_bandits"),
  19424. (try_begin),
  19425. (is_between, ":giver_center_no", villages_begin, villages_end),
  19426. #The quest giver is the village elder
  19427. (store_skill_level, ":player_trainer", "skl_trainer", "trp_player"),
  19428. (gt, ":player_trainer", 0),
  19429. (store_random_in_range, ":quest_target_amount", 5, 8),
  19430. #SB : add condition to have at least this many farmers remaining to show up
  19431. (party_count_members_of_type, ":num_villagers", ":giver_center_no", "trp_farmer"), #disallow peasant woman
  19432. (gt, ":num_villagers", ":quest_target_amount"), #+1 for village elder
  19433. (assign, ":quest_target_center", ":giver_center_no"),
  19434. (assign, ":quest_expiration_days", 20),
  19435. (assign, ":quest_dont_give_again_period", 40),
  19436. (assign, ":result", ":quest_no"),
  19437. (try_end),
  19438. (else_try),
  19439. # Mayor quests
  19440. (eq, ":quest_no", "qst_escort_merchant_caravan"),
  19441. (is_between, ":giver_center_no", centers_begin, centers_end),
  19442. (store_random_party_in_range, ":quest_target_center", towns_begin, towns_end),
  19443. (store_distance_to_party_from_party, ":dist", ":giver_center_no",":quest_target_center"),
  19444. (assign, ":quest_gold_reward", ":dist"),
  19445. (val_add, ":quest_gold_reward", 25),
  19446. (val_mul, ":quest_gold_reward", 25),
  19447. (val_div, ":quest_gold_reward", 20),
  19448. (store_random_in_range, ":quest_target_amount", 6, 12),
  19449. # (assign, "$escort_merchant_caravan_mode", 0), #SB : useless global, use quest slots if necessary
  19450. (assign, ":result", ":quest_no"),
  19451. (else_try),
  19452. (eq, ":quest_no", "qst_deliver_wine"),
  19453. (is_between, ":giver_center_no", centers_begin, centers_end),
  19454. (store_random_party_in_range, ":quest_target_center", towns_begin, towns_end),
  19455. (store_random_in_range, ":random_no", 0, 2),
  19456. #SB : add chance of random food product
  19457. (try_begin),
  19458. (eq, ":random_no", 0), #as before, but skip the need for a quest variant
  19459. (store_random_in_range, ":quest_target_item", "itm_wine", food_begin),
  19460. (else_try),
  19461. (store_random_in_range, ":quest_target_item", food_begin, food_end),
  19462. (try_end),
  19463. (store_random_in_range, ":quest_target_amount", 6, 12),
  19464. (store_distance_to_party_from_party, ":dist", ":giver_center_no",":quest_target_center"),
  19465.  
  19466. #SB : also, instead of emptying target center of merchandise, pick one that's actually missing food
  19467. (assign, ":quest_gold_reward", ":dist"),
  19468. (val_add, ":quest_gold_reward", 2),
  19469. (assign, ":multiplier", 5),
  19470. (val_add, ":multiplier", ":quest_target_amount"),
  19471. (val_mul, ":quest_gold_reward", ":multiplier"),
  19472. (val_div, ":quest_gold_reward", 100),
  19473. (val_mul, ":quest_gold_reward", 10),
  19474. (item_get_max_ammo, ":max_amount", ":quest_target_item"),
  19475. (val_mul, ":quest_target_amount", ":max_amount"), #store actual quantity
  19476. #SB : roll this into a quest slot or recalculate, wtf
  19477. # (store_item_value,"$qst_deliver_wine_debt",":quest_target_item"),
  19478. # (val_mul,"$qst_deliver_wine_debt",":quest_target_amount"),
  19479. # (val_mul,"$qst_deliver_wine_debt", 6),
  19480. # (val_div,"$qst_deliver_wine_debt", 5),
  19481. (assign, ":quest_expiration_days", 7), #SB : probably calculate distance for possible spoilage?
  19482. (assign, ":quest_dont_give_again_period", 20),
  19483. (assign, ":result", ":quest_no"),
  19484. (else_try),
  19485. (eq, ":quest_no", "qst_troublesome_bandits"),
  19486. (is_between, ":giver_center_no", centers_begin, centers_end),
  19487. (store_character_level, ":quest_gold_reward", "trp_player"),
  19488. (val_add, ":quest_gold_reward", 20),
  19489. (val_mul, ":quest_gold_reward", 35),
  19490. (val_div, ":quest_gold_reward",100),
  19491. (val_mul, ":quest_gold_reward", 10),
  19492. (assign, ":quest_expiration_days", 30),
  19493. (assign, ":quest_dont_give_again_period", 30),
  19494. (assign, ":result", ":quest_no"),
  19495. (else_try),
  19496. (eq, ":quest_no", "qst_kidnapped_girl"),
  19497. (is_between, ":giver_center_no", centers_begin, centers_end),
  19498. (store_random_in_range, ":quest_target_center", villages_begin, villages_end),
  19499. (store_character_level, ":quest_target_amount"),
  19500. (val_add, ":quest_target_amount", 15),
  19501. (store_distance_to_party_from_party, ":dist", ":giver_center_no", ":quest_target_center"),
  19502. (val_add, ":dist", 15),
  19503. (val_mul, ":dist", 2),
  19504. (val_mul, ":quest_target_amount", ":dist"),
  19505. (val_div, ":quest_target_amount",100),
  19506. (val_mul, ":quest_target_amount",10),
  19507. (assign, ":quest_gold_reward", ":quest_target_amount"),
  19508. (val_div, ":quest_gold_reward", 40),
  19509. (val_mul, ":quest_gold_reward", 10),
  19510. (assign, ":quest_expiration_days", 15),
  19511. (assign, ":quest_dont_give_again_period", 30),
  19512. (assign, ":result", ":quest_no"),
  19513. (else_try),
  19514. (eq, ":quest_no", "qst_move_cattle_herd"),
  19515. (is_between, ":giver_center_no", centers_begin, centers_end),
  19516. (call_script, "script_cf_select_random_town_at_peace_with_faction", ":giver_faction_no"),
  19517. (neq, ":giver_center_no", reg0),
  19518. (assign, ":quest_target_center", reg0),
  19519. (store_distance_to_party_from_party, ":dist",":giver_center_no",":quest_target_center"),
  19520. (assign, ":quest_gold_reward", ":dist"),
  19521. (val_add, ":quest_gold_reward", 25),
  19522. (val_mul, ":quest_gold_reward", 50),
  19523. (val_div, ":quest_gold_reward", 20),
  19524. (assign, ":quest_expiration_days", 30),
  19525. (assign, ":quest_dont_give_again_period", 20),
  19526. (assign, ":result", ":quest_no"),
  19527. (else_try),
  19528. (eq, ":quest_no", "qst_persuade_lords_to_make_peace"),
  19529. (is_between, ":giver_center_no", centers_begin, centers_end),
  19530. (store_faction_of_party, ":cur_object_faction", ":giver_center_no"),
  19531. (call_script, "script_cf_faction_get_random_enemy_faction", ":cur_object_faction"),
  19532. (assign, ":cur_target_faction", reg0),
  19533. (call_script, "script_cf_get_random_lord_except_king_with_faction", ":cur_object_faction"),
  19534. (assign, ":cur_object_troop", reg0),
  19535. ##diplomacy start+
  19536. #may also be anyone with tmt_aristocrat > 0
  19537. (call_script, "script_dplmc_get_troop_morality_value", ":cur_object_troop", tmt_aristocratic),
  19538. (this_or_next|ge, reg0, 1),
  19539. ##diplomacy+
  19540. (this_or_next|troop_slot_eq, ":cur_object_troop", slot_lord_reputation_type, lrep_quarrelsome),
  19541. (this_or_next|troop_slot_eq, ":cur_object_troop", slot_lord_reputation_type, lrep_selfrighteous),
  19542. (this_or_next|troop_slot_eq, ":cur_object_troop", slot_lord_reputation_type, lrep_martial),
  19543. (troop_slot_eq, ":cur_object_troop", slot_lord_reputation_type, lrep_debauched),
  19544.  
  19545. (call_script, "script_cf_get_random_lord_except_king_with_faction", ":cur_target_faction"),
  19546. (assign, ":quest_target_troop", reg0),
  19547. ##diplomacy start+
  19548. #may also be anyone with tmt_aristocrat > 0
  19549. (call_script, "script_dplmc_get_troop_morality_value", ":quest_target_troop", tmt_aristocratic),
  19550. (this_or_next|ge, reg0, 1),
  19551. ##diplomacy+
  19552. (this_or_next|troop_slot_eq, ":quest_target_troop", slot_lord_reputation_type, lrep_quarrelsome),
  19553. (this_or_next|troop_slot_eq, ":quest_target_troop", slot_lord_reputation_type, lrep_selfrighteous),
  19554. (this_or_next|troop_slot_eq, ":quest_target_troop", slot_lord_reputation_type, lrep_martial),
  19555. (troop_slot_eq, ":quest_target_troop", slot_lord_reputation_type, lrep_debauched),
  19556.  
  19557. (assign, ":quest_object_troop", ":cur_object_troop"),
  19558. (assign, ":quest_target_faction", ":cur_target_faction"),
  19559. (assign, ":quest_object_faction", ":cur_object_faction"),
  19560. (assign, ":quest_gold_reward", 12000),
  19561. (assign, ":quest_convince_value", 7000),
  19562. (assign, ":quest_expiration_days", 30),
  19563. (assign, ":quest_dont_give_again_period", 100),
  19564. (assign, ":result", ":quest_no"),
  19565. (else_try),
  19566. (eq, ":quest_no", "qst_deal_with_looters"),
  19567. ##diplomacy start+
  19568. #re-enable looters quest at all levels for variety
  19569. #(is_between, ":player_level", 0, 15),
  19570. ##diplomacy end+
  19571. (is_between, ":giver_center_no", centers_begin, centers_end),
  19572. (store_faction_of_party, ":cur_object_faction", ":giver_center_no"),
  19573. (store_num_parties_destroyed_by_player, ":num_looters_destroyed", "pt_looters"),
  19574. (party_template_set_slot,"pt_looters",slot_party_template_num_killed,":num_looters_destroyed"),
  19575. (quest_set_slot,":quest_no",slot_quest_current_state,0),
  19576. (quest_set_slot,":quest_no",slot_quest_target_party_template,"pt_looters"),
  19577. (assign, ":quest_gold_reward", 500),
  19578. (assign, ":quest_xp_reward", 500),
  19579. (assign, ":quest_expiration_days", 20),
  19580. (assign, ":quest_dont_give_again_period", 30),
  19581. ##diplomacy start+
  19582. (try_begin),
  19583. #don't give full quest reward if outside the normal level range
  19584. (ge, ":player_level", 15),
  19585. (store_sub, ":quest_xp_award", ":player_level", 14),
  19586. (val_mul, ":quest_xp_award", -10),
  19587. (val_add, ":quest_xp_award", 500),
  19588. (val_max, ":quest_xp_award", 100),#XP drops by 10 per level over limit, until level 40
  19589. #To avoid being pestered with trivia, increase :quest_dont_give_again_period with the player's level
  19590. (store_add, ":quest_dont_give_again_period", ":player_level", 16),
  19591. (try_end),
  19592. ##diplomacy end+
  19593. (assign, ":result", ":quest_no"),
  19594. (else_try),
  19595. (eq, ":quest_no", "qst_deal_with_night_bandits"),
  19596. ##diplomacy start+
  19597. #re-enable quest at all levels for variety
  19598. #(is_between, ":player_level", 0, 15),
  19599. ##diplomacy end+
  19600. (is_between, ":giver_center_no", centers_begin, centers_end),
  19601. (party_slot_ge, ":giver_center_no", slot_center_has_bandits, 1),
  19602. (assign, ":quest_target_center", ":giver_center_no"),
  19603. (assign, ":quest_expiration_days", 4),
  19604. (assign, ":quest_dont_give_again_period", 15),
  19605. ##diplomacy start+
  19606. (try_begin),
  19607. #To avoid being pestered with trivia, increase :quest_dont_give_again_period with the player's level
  19608. (ge, ":player_level", 15),
  19609. (store_add, ":quest_dont_give_again_period", ":player_level", 1),
  19610. (try_end),
  19611. ##diplomacy end+
  19612. (assign, ":result", ":quest_no"),
  19613. (else_try),
  19614. # Lady quests
  19615. (eq, ":quest_no", "qst_rescue_lord_by_replace"),
  19616. (eq, 1, 0),
  19617. (try_begin),
  19618. (ge, "$g_talk_troop_faction_relation", 0),
  19619. ##diplomacy start+
  19620. #if this quest is not disabled, remove the upper level limit to increase play variety
  19621. #(is_between, ":player_level", 5, 25),
  19622. (ge, ":player_level", 5),
  19623. ##diplomacy end+
  19624.  
  19625. (assign, ":prisoner_relative", -1),
  19626.  
  19627. (try_begin),
  19628. (troop_get_slot, ":cur_target_troop", ":giver_troop", slot_troop_father), #get giver_troop's father
  19629. (gt, ":cur_target_troop", 0), #if giver_troop has a father as a troop in game
  19630. (troop_slot_ge, ":cur_target_troop", slot_troop_prisoner_of_party, 0), #if giver_troop's father is in a prison
  19631. (assign, ":prisoner_relative", ":cur_target_troop"),
  19632. (try_end),
  19633.  
  19634. (try_begin),
  19635. (eq, ":prisoner_relative", -1), #if giver_troop has no father or giver_troop's father is not in prison.
  19636. (troop_get_slot, ":cur_target_troop", ":giver_troop", slot_troop_spouse), #get giver_troop's spouse
  19637. (gt, ":cur_target_troop", 0), #if giver_troop has a spouse as a troop in game
  19638. (troop_slot_ge, ":cur_target_troop", slot_troop_prisoner_of_party, 0), #if giver_troop's spouse is in a prison
  19639. (assign, ":prisoner_relative", ":cur_target_troop"),
  19640. (try_end),
  19641.  
  19642. (try_begin),
  19643. (eq, ":prisoner_relative", -1), #if ((giver_troop has no father) or (giver_troop's father is not in prison)) and ((giver_troop has no spouse) or (giver_troop's spouse is not in prison)).
  19644. (troop_get_slot, ":cur_target_troop", ":giver_troop", slot_troop_guardian), #get giver_troop's spouse
  19645. (gt, ":cur_target_troop", 0), #if giver_troop has a guardian as a troop in game
  19646. (troop_slot_ge, ":cur_target_troop", slot_troop_prisoner_of_party, 0), #if giver_troop's guardian is in a prison
  19647. (assign, ":prisoner_relative", ":cur_target_troop"),
  19648. (try_end),
  19649.  
  19650. (try_begin),
  19651. (eq, "$cheat_mode", 1),
  19652. (assign, reg0, ":prisoner_relative"),
  19653. (display_message, "str_prisoner_relative_is_reg0"),
  19654. (try_end),
  19655.  
  19656. (gt, ":prisoner_relative", -1),
  19657. #(changed 2) no need to this anymore (troop_slot_ge, ":prisoner_relative", slot_troop_prisoner_of_party, 0),
  19658. (call_script, "script_search_troop_prisoner_of_party", ":prisoner_relative"),
  19659. (assign, ":cur_target_center", reg0),
  19660.  
  19661. #(changed 3) no need to check only towns anymore (is_between, ":cur_target_center", towns_begin, towns_end),#Skip if he is not in a town
  19662. (is_between, ":cur_target_center", walled_centers_begin, walled_centers_end), #Skip if he is not in a walled center
  19663.  
  19664. (assign, ":quest_target_center", ":cur_target_center"),
  19665. (assign, ":quest_target_troop", ":prisoner_relative"),
  19666. (assign, ":quest_expiration_days", 30),
  19667. (assign, ":quest_dont_give_again_period", 73),
  19668. (assign, ":result", ":quest_no"),
  19669. (try_end),
  19670. (else_try),
  19671. (eq, ":quest_no", "qst_deliver_message_to_prisoner_lord"),
  19672. ##diplomacy start+ enable this quest even when a vassal from an affiliated family member
  19673. ##...or from a faction leader, a faction marshall, or your spouse
  19674. (this_or_next|ge, ":is_close", 1),
  19675. (this_or_next|ge, ":nominal_superior", 1),
  19676. ##diplomacy end+
  19677. (eq, "$player_has_homage", 0),
  19678.  
  19679. (try_begin),
  19680. (ge, "$g_talk_troop_faction_relation", 0),
  19681. ##diplomacy start+
  19682. #Remove the upper level limit to increase play variety
  19683. #(is_between, ":player_level", 5, 25),
  19684. (ge, ":player_level", 5),
  19685. ##diplomacy end+
  19686. (troop_get_slot, ":cur_target_troop", ":giver_troop", slot_troop_father),
  19687. (try_begin),
  19688. (eq, ":cur_target_troop", 0),
  19689. (troop_get_slot, ":cur_target_troop", ":giver_troop", slot_troop_spouse),
  19690. (try_end),
  19691. #(troop_slot_eq, ":cur_target_troop", slot_troop_is_prisoner, 1),#Skip if the lady's father/husband is not in prison
  19692. (gt, ":cur_target_troop", -1),
  19693. (troop_slot_ge, ":cur_target_troop", slot_troop_prisoner_of_party, 0),
  19694. (call_script, "script_search_troop_prisoner_of_party", ":cur_target_troop"),
  19695. (assign, ":cur_target_center", reg0),
  19696. (is_between, ":cur_target_center", towns_begin, towns_end),#Skip if he is not in a town
  19697. (assign, ":quest_target_center", ":cur_target_center"),
  19698. (assign, ":quest_target_troop", ":cur_target_troop"),
  19699. (assign, ":quest_expiration_days", 30),
  19700. (assign, ":quest_dont_give_again_period", 30),
  19701. (assign, ":result", ":quest_no"),
  19702. (try_end),
  19703. (else_try),
  19704. (eq, ":quest_no", "qst_duel_for_lady"),
  19705. (try_begin),
  19706. (ge, "$g_talk_troop_faction_relation", 0),
  19707. (ge, ":player_level", 10),
  19708. (call_script, "script_cf_troop_get_random_enemy_troop_with_occupation", ":giver_troop", slto_kingdom_hero),#Can fail
  19709. (assign, ":cur_target_troop", reg0),
  19710. (neg|troop_slot_eq, ":giver_troop", slot_troop_spouse, ":cur_target_troop"), #must not be in the family
  19711. (neg|troop_slot_eq, ":giver_troop", slot_troop_father, ":cur_target_troop"),
  19712. (neg|troop_slot_ge, ":cur_target_troop", slot_troop_prisoner_of_party, 0),
  19713. (troop_slot_ge, ":cur_target_troop", slot_troop_leaded_party, 0),
  19714.  
  19715. ##diplomacy start+ add benefactor ~ goodnatured/upstanding equivalence
  19716. (neg|troop_slot_eq, ":cur_target_troop", slot_lord_reputation_type, lrep_benefactor),
  19717. #also disable challenging conventional & moralist ladies
  19718. (neg|troop_slot_eq, ":cur_target_troop", slot_lord_reputation_type, lrep_conventional),
  19719. (neg|troop_slot_eq, ":cur_target_troop", slot_lord_reputation_type, lrep_moralist),
  19720. #diplomacy end+
  19721. (neg|troop_slot_eq, ":cur_target_troop", slot_lord_reputation_type, lrep_goodnatured),
  19722. (neg|troop_slot_eq, ":cur_target_troop", slot_lord_reputation_type, lrep_upstanding),
  19723. (neg|troop_slot_eq, ":cur_target_troop", slot_lord_reputation_type, lrep_martial),
  19724.  
  19725. (assign, ":quest_target_troop", ":cur_target_troop"),
  19726. (assign, ":quest_expiration_days", 30),
  19727. (assign, ":quest_dont_give_again_period", 50),
  19728. (assign, ":result", ":quest_no"),
  19729. (try_end),
  19730. # Enemy Lord Quests
  19731. (else_try),
  19732. (eq, ":quest_no", "qst_lend_surgeon"),
  19733. (try_begin),
  19734. (eq, "$g_defending_against_siege", 0),#Skip if the center is under siege (because of resting)
  19735. ##diplomacy start+
  19736. #also disable for roguish lords with negative tmt_humanitarian ratings
  19737. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  19738. (this_or_next|neq, ":giver_reputation", lrep_roguish),
  19739. (lt, reg0, 0),
  19740. #Disable for anyone with a negative tmt_egalitarian rating, as this would be out of character.
  19741. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_egalitarian),
  19742. (ge, reg0, 0),
  19743. ##diplomacy end+
  19744. (neq, ":giver_reputation", lrep_quarrelsome),
  19745. (neq, ":giver_reputation", lrep_debauched),
  19746. (assign, ":max_surgery_level", 0),
  19747. (assign, ":best_surgeon", -1),
  19748. (party_get_num_companion_stacks, ":num_stacks","p_main_party"),
  19749. (try_for_range, ":i_stack", 1, ":num_stacks"),
  19750. (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
  19751. (troop_is_hero, ":stack_troop"),
  19752. #SB : has to be companion, otherwise pretender/wife gets called
  19753. (is_between, ":stack_troop", companions_begin, companions_end),
  19754. (store_skill_level, ":cur_surgery_skill", skl_surgery, ":stack_troop"),
  19755. (gt, ":cur_surgery_skill", ":max_surgery_level"),
  19756. (assign, ":max_surgery_level", ":cur_surgery_skill"),
  19757. (assign, ":best_surgeon", ":stack_troop"),
  19758. (try_end),
  19759.  
  19760. (store_character_level, ":cur_level", "trp_player"),
  19761. (assign, ":required_skill", 5),
  19762. (val_div, ":cur_level", 10),
  19763. (val_add, ":required_skill", ":cur_level"),
  19764. (ge, ":max_surgery_level", ":required_skill"), #Skip if party skill level is less than the required value
  19765.  
  19766. (assign, ":quest_object_troop", ":best_surgeon"),
  19767. (assign, ":quest_importance", 1),
  19768. #SB : this seems extremely low for cost of surgery, give at least 50 gold
  19769. (store_mul, ":quest_xp_reward", ":max_surgery_level", 10), #slightly better
  19770. (assign, ":quest_gold_reward", ":quest_xp_reward"),
  19771. (assign, ":quest_dont_give_again_period", 50),
  19772. (assign, ":result", ":quest_no"),
  19773. (try_end),
  19774. # Lord Quests
  19775. (else_try),
  19776. (eq, ":quest_no", "qst_meet_spy_in_enemy_town"),
  19777. ##diplomacy start+ enable this quest even when a vassal from an affiliated family member
  19778. #...or from a faction leader, a faction marshall, or your spouse
  19779. (this_or_next|ge, ":is_close", 1),
  19780. (this_or_next|ge, ":nominal_superior", 1),
  19781. ##diplomacy end+
  19782. (eq, "$player_has_homage", 0),
  19783.  
  19784. (try_begin),
  19785. (eq, "$players_kingdom", ":giver_faction_no"),
  19786. (neq, ":giver_reputation", lrep_goodnatured),
  19787. (neq, ":giver_reputation", lrep_martial),
  19788.  
  19789. (call_script, "script_troop_get_player_relation", ":giver_troop"),
  19790. (assign, ":giver_relation", reg0),
  19791. (gt, ":giver_relation", 3),
  19792. (call_script, "script_cf_faction_get_random_enemy_faction", ":giver_faction_no"),
  19793. (assign, ":enemy_faction", reg0),
  19794. (store_relation, ":reln", ":enemy_faction", "fac_player_supporters_faction"),
  19795. (lt, ":reln", 0),
  19796. (call_script, "script_cf_select_random_town_with_faction", ":enemy_faction"),
  19797. (assign, ":cur_target_center", reg0),
  19798. #Just to make sure that there is a free walker
  19799. (call_script, "script_cf_center_get_free_walker", ":cur_target_center"),
  19800. (assign, ":quest_target_center", ":cur_target_center"),
  19801. (store_random_in_range, ":quest_target_amount", secret_signs_begin, secret_signs_end),
  19802. (assign, ":result", ":quest_no"),
  19803. (assign, ":quest_gold_reward", 500),
  19804. (assign, ":quest_expiration_days", 30),
  19805. (assign, ":quest_dont_give_again_period", 50),
  19806. (quest_set_slot, "qst_meet_spy_in_enemy_town", slot_quest_gold_reward, 500),
  19807. (try_end),
  19808. (else_try),
  19809. (eq, ":quest_no", "qst_raid_caravan_to_start_war"),
  19810. (eq, 1, 0), #disable this as a random quest
  19811.  
  19812. (try_begin),
  19813. (eq, "$players_kingdom", ":giver_faction_no"),
  19814. ##diplomacy start+
  19815. #no lords who are opposed to raiding will suggest this, even if they match
  19816. #one of the listed personalities.
  19817. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  19818. (lt, reg0, 1),
  19819. #roguish lords can give this quest unless they're opposed to raiding
  19820. (this_or_next|eq, ":giver_reputation", lrep_roguish),
  19821. ##diplomacy end+
  19822. (this_or_next|eq, ":giver_reputation", lrep_cunning),
  19823. (this_or_next|eq, ":giver_reputation", lrep_quarrelsome),
  19824. ( eq, ":giver_reputation", lrep_debauched),
  19825. (gt, ":player_level", 10),
  19826. (eq, 1, 0), #disable this as a random quest
  19827.  
  19828. (neg|faction_slot_eq, ":giver_faction_no", slot_faction_leader, ":giver_troop"),#Can not take the quest from the king
  19829. (call_script, "script_cf_faction_get_random_friendly_faction", ":giver_faction_no"),#Can fail
  19830. (assign, ":quest_target_faction", reg0),
  19831. (store_troop_faction, ":quest_object_faction", ":giver_troop"),
  19832. (assign, ":quest_target_party_template", "pt_kingdom_caravan_party"),
  19833. (assign, ":quest_target_amount", 2),
  19834. (assign, ":result", ":quest_no"),
  19835. (assign, ":quest_expiration_days", 30),
  19836. (assign, ":quest_dont_give_again_period", 100),
  19837. (try_end),
  19838. (else_try),
  19839. (eq, ":quest_no", "qst_deliver_message"),
  19840. ##diplomacy start+ enable this quest even when a vassal from an affiliated family member
  19841. #...or from a faction leader, a faction marshall, or your spouse
  19842. (this_or_next|ge, ":is_close", 1),
  19843. (this_or_next|ge, ":nominal_superior", 1),
  19844. ##diplomacy end+
  19845. (eq, "$player_has_homage", 0),
  19846.  
  19847. (try_begin),
  19848. (ge, "$g_talk_troop_faction_relation", 0),
  19849. ##diplomacy start+
  19850. #increase the level/renown range validity of this quest
  19851. #(lt, ":player_level", 20),
  19852. #(neg|troop_slot_ge, "trp_player", slot_troop_renown, 125),
  19853. (store_character_level, reg0, ":giver_troop"),
  19854. (val_max, reg0, 20),#20 or quest-giver's level, whichever is greater
  19855. (lt, ":player_level", reg0),
  19856. (troop_get_slot, reg0, ":giver_troop", slot_troop_renown),
  19857. (val_div, reg0, 2),
  19858. (val_max, reg0, 125),#125 or 50% of quest-giver's renown, whichever is greater
  19859. ##diplomacy end+
  19860. (call_script, "script_cf_get_random_lord_in_a_center_with_faction", ":giver_faction_no"),#Can fail
  19861. (assign, ":cur_target_troop", reg0),
  19862. (neq, ":cur_target_troop", ":giver_troop"),#Skip himself
  19863. (call_script, "script_get_troop_attached_party", ":cur_target_troop"),
  19864. (assign, ":cur_target_center", reg0),#cur_target_center will definitely be a valid center
  19865. (neq,":giver_center_no", ":cur_target_center"),#Skip current center
  19866.  
  19867. (assign, ":quest_target_center", ":cur_target_center"),
  19868. (assign, ":quest_target_troop", ":cur_target_troop"),
  19869. (assign, ":quest_xp_reward", 30),
  19870. (assign, ":quest_gold_reward", 40),
  19871. (assign, ":quest_dont_give_again_period", 10),
  19872. ##diplomacy start+
  19873. (try_begin),
  19874. (this_or_next|troop_slot_ge, "trp_player", slot_troop_renown, 125),
  19875. (ge, ":player_level", 20),
  19876. (assign, ":quest_dont_give_again_period", ":player_level"),
  19877. (val_clamp, ":quest_dont_give_again_period", 10, 61),
  19878. (try_end),
  19879. ##diplomacy end+
  19880.  
  19881. (assign, ":result", ":quest_no"),
  19882.  
  19883. (assign, ":quest_expiration_days", 30),
  19884. (try_end),
  19885. (else_try),
  19886. (eq, ":quest_no", "qst_escort_lady"),
  19887. (try_begin),
  19888. (ge, "$g_talk_troop_faction_relation", 0),
  19889. (ge, ":player_level", 10),
  19890.  
  19891. (ge, ":giver_troop", 0), #skip troops without fathers in range
  19892.  
  19893. (assign, ":cur_object_troop", -1),
  19894. (try_for_range, ":lady", kingdom_ladies_begin, kingdom_ladies_end),
  19895. (troop_slot_eq, ":lady", slot_troop_father, ":giver_troop"),
  19896. (assign, ":cur_object_troop", ":lady"),
  19897. (try_end),
  19898.  
  19899. (ge, ":cur_object_troop", 0),
  19900.  
  19901. (troop_get_slot, ":giver_troop_confirm", ":cur_object_troop", slot_troop_father), # just to make sure
  19902. (eq, ":giver_troop", ":giver_troop_confirm"), # just to make sure
  19903.  
  19904. (store_random_in_range, ":random_no", 0, 2),
  19905. (try_begin),
  19906. (eq, ":random_no", 0),
  19907. (troop_get_slot, ":cur_object_troop_2", ":giver_troop", slot_troop_spouse),
  19908. (is_between, ":cur_object_troop_2", kingdom_ladies_begin, kingdom_ladies_end),
  19909. (troop_get_slot, ":giver_troop_confirm", ":cur_object_troop_2", slot_troop_spouse), # just to make sure
  19910. (eq, ":giver_troop", ":giver_troop_confirm"), # just to make sure
  19911. (assign, ":cur_object_troop", ":cur_object_troop_2"),
  19912. (try_end),
  19913. (gt, ":cur_object_troop", 0),#Skip lords without a lady
  19914. ##diplomacy start+ use a script for gender
  19915. #(troop_get_type, ":cur_troop_gender", ":cur_object_troop"),
  19916. (call_script, "script_dplmc_store_troop_is_female", ":cur_object_troop"),
  19917. (assign, ":cur_troop_gender", reg0),
  19918. #(eq, ":cur_troop_gender", 1),#Skip if it is not female
  19919. (neq, ":cur_troop_gender", 0),
  19920. ##diplomacy end+
  19921. (gt, ":giver_center_no", 0),#Skip if lord is outside the center
  19922. (troop_slot_eq, ":cur_object_troop", slot_troop_cur_center, ":giver_center_no"),#Skip if the lady is not at the same center
  19923. (call_script, "script_cf_select_random_town_with_faction", ":giver_faction_no"),#Can fail
  19924. (assign, ":cur_target_center", reg0),
  19925. (neq, ":cur_target_center", ":giver_center_no"),
  19926. (hero_can_join),#Skip if player has no available slots
  19927.  
  19928. (assign, ":quest_object_troop", ":cur_object_troop"),
  19929. (assign, ":quest_target_center", ":cur_target_center"),
  19930. (assign, ":quest_expiration_days", 20),
  19931. (assign, ":quest_dont_give_again_period", 30),
  19932. (assign, ":result", ":quest_no"),
  19933. (try_end),
  19934. ## (else_try),
  19935. ## (eq, ":quest_no", "qst_hunt_down_raiders"),
  19936. ## (try_begin),
  19937. ## (gt, ":player_level", 10),
  19938. ## (faction_slot_eq, ":giver_faction_no", slot_faction_leader, ":giver_troop"),
  19939. ## (call_script, "script_cf_select_random_town_with_faction", ":giver_faction_no"),#Can fail
  19940. ## (assign, ":cur_object_center", reg0),
  19941. ## (neq, ":cur_object_center", ":giver_center_no"),#Skip current center
  19942. ## (call_script, "script_get_random_enemy_center", ":giver_party_no"),
  19943. ## (assign, ":cur_target_center", reg0),
  19944. ## (ge, ":cur_target_center", 0),
  19945. ## (store_faction_of_party, ":cur_target_faction", ":cur_target_center"),
  19946. ## (is_between, ":cur_target_faction", kingdoms_begin, kingdoms_end),
  19947. ##
  19948. ## (assign, ":quest_object_center", ":cur_object_center"),
  19949. ## (assign, ":quest_target_center", ":cur_target_center"),
  19950. ## (assign, ":quest_importance", 1),
  19951. ## (assign, ":quest_xp_reward", 1500),
  19952. ## (assign, ":quest_gold_reward", 1000),
  19953. ## (assign, ":result", ":quest_no"),
  19954. ## (try_end),
  19955. ## (else_try),
  19956. ## (eq, ":quest_no", "qst_bring_back_deserters"),
  19957. ## (try_begin),
  19958. ## (gt, ":player_level", 5),
  19959. ## (faction_get_slot, ":cur_target_party_template", ":giver_faction_no", slot_faction_deserter_party_template),
  19960. ## (faction_get_slot, ":cur_target_troop", ":giver_faction_no", slot_faction_deserter_troop),
  19961. ## (gt, ":cur_target_party_template", 0),#Skip factions with no deserter party templates
  19962. ## (store_num_parties_of_template, ":num_deserters", ":cur_target_party_template"),
  19963. ## (ge, ":num_deserters", 2),#Skip if there are less than 2 active deserter parties
  19964. ##
  19965. ## (assign, ":quest_target_troop", ":cur_target_troop"),
  19966. ## (assign, ":quest_target_party_template", ":cur_target_party_template"),
  19967. ## (assign, ":quest_target_amount", 5),
  19968. ## (assign, ":quest_importance", 1),
  19969. ## (assign, ":quest_xp_reward", 500),
  19970. ## (assign, ":quest_gold_reward", 300),
  19971. ## (assign, ":result", ":quest_no"),
  19972. ## (try_end),
  19973. ## (else_try),
  19974. ## (eq, ":quest_no", "qst_deliver_supply_to_center_under_siege"),
  19975. ## (try_begin),
  19976. ## (gt, ":player_level", 10),
  19977. ## (gt, ":giver_center_no", 0),#Skip if lord is outside the center
  19978. ## (call_script, "script_cf_get_random_siege_location_with_faction", ":giver_faction_no"),#Can fail
  19979. ## (assign, ":quest_target_center", reg0),
  19980. ## (assign, ":quest_target_amount", 10),
  19981. ## (assign, ":quest_importance", 1),
  19982. ## (assign, ":quest_xp_reward", 500),
  19983. ## (assign, ":quest_gold_reward", 300),
  19984. ## (assign, ":result", ":quest_no"),
  19985. ## (try_end),
  19986. ## (else_try),
  19987. ## (eq, ":quest_no", "qst_rescue_lady_under_siege"),
  19988. ## (try_begin),
  19989. ## (gt, ":player_level", 15),
  19990. ## (troop_get_slot, ":cur_object_troop", ":giver_troop", slot_troop_daughter),
  19991. ## (store_random_in_range, ":random_no", 0, 2),
  19992. ## (try_begin),
  19993. ## (this_or_next|eq, ":cur_object_troop", 0),
  19994. ## (eq, ":random_no", 0),
  19995. ## (troop_get_slot, ":cur_object_troop_2", ":giver_troop", slot_troop_spouse),
  19996. ## (gt, ":cur_object_troop_2", 0),
  19997. ## (assign, ":cur_object_troop", ":cur_object_troop_2"),
  19998. ## (try_end),
  19999. ## (gt, ":cur_object_troop", 0),#Skip lords without a lady
  20000. ## (troop_get_type, ":cur_troop_gender", ":cur_object_troop"),
  20001. ## (eq, ":cur_troop_gender", 1),#Skip if lady is not female
  20002. ## (troop_get_slot, ":cur_target_center", ":cur_object_troop", slot_troop_cur_center),
  20003. ## (is_between, ":cur_target_center", centers_begin, centers_end),#Skip if she is not in a center
  20004. ## (neq,":giver_center_no", ":cur_target_center"),#Skip current center
  20005. ## (call_script, "script_cf_get_random_siege_location_with_faction", ":giver_faction_no"),#Can fail
  20006. ## (assign, ":cur_target_center", reg0),
  20007. ## (troop_set_slot, ":cur_object_troop", slot_troop_cur_center, ":cur_target_center"),#Move lady to the siege location
  20008. ## (assign, ":quest_object_troop", ":cur_object_troop"),
  20009. ## (assign, ":quest_target_center", ":cur_target_center"),
  20010. ## (assign, ":quest_target_troop", ":giver_troop"),
  20011. ## (assign, ":quest_importance", 1),
  20012. ## (assign, ":quest_xp_reward", 200),
  20013. ## (assign, ":quest_gold_reward", 750),
  20014. ## (assign, ":result", ":quest_no"),
  20015. ## (try_end),
  20016. ## (else_try),
  20017. ## (eq, ":quest_no", "qst_deliver_message_to_lover"),
  20018. ## (try_begin),
  20019. ## (is_between, ":player_level", 5, 30),
  20020. ## (troop_get_slot, ":cur_target_troop", ":giver_troop", slot_troop_lover),
  20021. ## (gt, ":cur_target_troop", 0),#Skip lords without a lover
  20022. ## (troop_get_slot, ":cur_target_center", ":cur_target_troop", slot_troop_cur_center),
  20023. ## (is_between, ":cur_target_center", centers_begin, centers_end),#Skip if she is not in a center
  20024. ## (neq,":giver_center_no", ":cur_target_center"),#Skip current center
  20025. ## (assign, ":quest_target_troop", ":cur_target_troop"),
  20026. ## (assign, ":quest_target_center", ":cur_target_center"),
  20027. ## (assign, ":result", ":quest_no"),
  20028. ## (try_end),
  20029. ## (else_try),
  20030. ## (eq, ":quest_no", "qst_bring_reinforcements_to_siege"),
  20031. ## (try_begin),
  20032. ## (gt, ":player_level", 10),
  20033. ## (call_script, "script_cf_get_random_siege_location_with_attacker_faction", ":giver_faction_no"),#Can fail
  20034. ## (assign, ":cur_target_center", reg0),
  20035. ## (store_random_in_range, ":random_no", 5, 11),
  20036. ## (troops_can_join, ":random_no"),#Skip if the player doesn't have enough room
  20037. ## (call_script, "script_cf_get_number_of_random_troops_from_party", ":giver_party_no", ":random_no"),#Can fail
  20038. ## (assign, ":cur_object_troop", reg0),
  20039. ## (party_get_battle_opponent, ":cur_target_party", ":cur_target_center"),
  20040. ## (party_get_num_companion_stacks, ":num_stacks", ":cur_target_party"),
  20041. ## (gt, ":num_stacks", 0),#Skip if the besieger party has no troops
  20042. ## (party_stack_get_troop_id, ":cur_target_troop", ":cur_target_party", 0),
  20043. ## (troop_is_hero, ":cur_target_troop"),#Skip if the besieger party has no heroes
  20044. ## (neq, ":cur_target_troop", ":giver_troop"),#Skip if the quest giver is the same troop
  20045. ## (assign, ":quest_target_troop", ":cur_target_troop"),
  20046. ## (assign, ":quest_object_troop", ":cur_object_troop"),
  20047. ## (assign, ":quest_target_party", ":cur_target_party"),
  20048. ## (assign, ":quest_target_center", ":cur_target_center"),
  20049. ## (assign, ":quest_target_amount", ":random_no"),
  20050. ## (assign, ":quest_importance", 1),
  20051. ## (assign, ":quest_xp_reward", 400),
  20052. ## (assign, ":quest_gold_reward", 200),
  20053. ## (assign, ":result", ":quest_no"),
  20054. ## (try_end),
  20055. (else_try),
  20056. (eq, ":quest_no", "qst_deliver_message_to_enemy_lord"),
  20057. (try_begin),
  20058. (ge, "$g_talk_troop_faction_relation", 0),
  20059. ##diplomacy start+
  20060. #remove upper level limit to increase play variety
  20061. #(is_between, ":player_level", 5,25),
  20062. (ge, ":player_level", 5),
  20063. ##diplomacy end+
  20064. (call_script, "script_cf_get_random_lord_from_another_faction_in_a_center", ":giver_faction_no"),#Can fail
  20065. (assign, ":cur_target_troop", reg0),
  20066. (call_script, "script_get_troop_attached_party", ":cur_target_troop"),
  20067. (assign, ":quest_target_center", reg0),#quest_target_center will definitely be a valid center
  20068. (assign, ":quest_target_troop", ":cur_target_troop"),
  20069. (assign, ":quest_importance", 1),
  20070. (assign, ":quest_xp_reward", 200),
  20071. ##diplomacy start+
  20072. #decrease XP reward as you exceed the maximum level
  20073. (try_begin),
  20074. (ge, ":player_level", 26),
  20075. (store_sub, ":quest_xp_reward", 25, ":player_level"),
  20076. (val_add, ":quest_xp_reward", 200),
  20077. (val_max, ":quest_xp_reward", 50),#minus 10 xp for every level above 25, to a minimum of 50 XP at level 40
  20078. (try_end),
  20079. ##diplomacy end+
  20080. (assign, ":quest_gold_reward", 0),
  20081. (assign, ":result", ":quest_no"),
  20082. (assign, ":quest_expiration_days", 40),
  20083. (try_end),
  20084. ## (else_try),
  20085. ## (eq, ":quest_no", "qst_bring_prisoners_to_enemy"),
  20086. ## (try_begin),
  20087. ## (gt, ":player_level", 10),
  20088. ## (is_between, ":giver_center_no", centers_begin, centers_end),#Skip if the quest giver is not at a center
  20089. ## (store_random_in_range, ":random_no", 5, 11),
  20090. ## (troops_can_join_as_prisoner, ":random_no"),#Skip if the player doesn't have enough room
  20091. ## (call_script, "script_get_random_enemy_town", ":giver_center_no"),
  20092. ## (assign, ":cur_target_center", reg0),
  20093. ## (ge, ":cur_target_center", 0),#Skip if there are no enemy towns
  20094. ## (store_faction_of_party, ":cur_target_faction", ":cur_target_center"),
  20095. ## (faction_get_slot, ":cur_object_troop", ":cur_target_faction", slot_faction_tier_5_troop),
  20096. ## (assign, ":quest_target_center", ":cur_target_center"),
  20097. ## (assign, ":quest_object_troop", ":cur_object_troop"),
  20098. ## (assign, ":quest_target_amount", ":random_no"),
  20099. ## (assign, ":quest_importance", 1),
  20100. ## (assign, ":quest_xp_reward", 300),
  20101. ## (assign, ":quest_gold_reward", 200),
  20102. ## (assign, ":result", ":quest_no"),
  20103. ## (try_end),
  20104. (else_try),
  20105. (eq, ":quest_no", "qst_deal_with_bandits_at_lords_village"),
  20106. (try_begin),
  20107. ##diplomacy start+
  20108. #Does not have negative "tmt_humanitarian" rating
  20109. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  20110. (ge, reg0, 0),
  20111. ##diplomacy end+
  20112. (neq, ":giver_reputation", lrep_debauched),
  20113. (neq, ":giver_reputation", lrep_quarrelsome),
  20114. (ge, "$g_talk_troop_faction_relation", 0),
  20115. (assign, ":end_cond", villages_end),
  20116. (assign, ":cur_target_center", -1),
  20117. (try_for_range, ":cur_village", villages_begin, ":end_cond"),
  20118. (party_slot_eq, ":cur_village", slot_town_lord, ":giver_troop"),
  20119. #SB : fix this to ge
  20120. (party_slot_ge, ":cur_village", slot_village_infested_by_bandits, 1),
  20121. (party_slot_eq, ":cur_village", slot_village_state, svs_normal),
  20122. (assign, ":cur_target_center", ":cur_village"),
  20123. (assign, ":end_cond", 0),
  20124. (try_end),
  20125. (ge, ":cur_target_center", 0),
  20126. (neg|check_quest_active, "qst_eliminate_bandits_infesting_village"),
  20127. (assign, ":quest_target_center", ":cur_target_center"),
  20128. (assign, ":result", ":quest_no"),
  20129. (assign, ":quest_expiration_days", 30),
  20130. #SB : do quest rewards here instead of upon completion
  20131. (store_character_level, ":quest_gold_reward", "trp_player"),
  20132. (val_mul, ":quest_gold_reward", 20),
  20133. (val_add, ":quest_gold_reward", 300),
  20134. (assign, ":quest_xp_reward", 350),
  20135. (try_end),
  20136. (else_try),
  20137. (eq, ":quest_no", "qst_raise_troops"),
  20138. (try_begin),
  20139. (neq, ":giver_reputation", lrep_martial),
  20140. ##diplomacy start+
  20141. #RE-ENABLE for player's faction
  20142. #(neq, ":giver_faction_no", "fac_player_supporters_faction"), #we need tier_1_troop a valid value
  20143. (assign, ":faction_for_troop", ":giver_faction_no"),
  20144. (try_begin),
  20145. (eq, ":giver_faction_no", "fac_player_supporters_faction"),
  20146. (assign, ":faction_for_troop", "$g_player_culture"),
  20147. (neg|is_between, ":faction_for_troop", npc_kingdoms_begin, npc_kingdoms_end),
  20148. (troop_get_slot, ":faction_for_troop", ":giver_troop", slot_troop_original_faction),
  20149. (try_end),
  20150. (is_between, ":faction_for_troop", npc_kingdoms_begin, npc_kingdoms_end), #we need tier_1_troop a valid value
  20151. ##diplomacy end+
  20152. (ge, "$g_talk_troop_faction_relation", 0),
  20153. (store_character_level, ":cur_level", "trp_player"),
  20154. (gt, ":cur_level", 5),
  20155. (troop_slot_ge, "trp_player", slot_troop_renown, 100),
  20156.  
  20157. (store_random_in_range, ":quest_target_amount", 5, 8),
  20158. (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
  20159. (le, ":quest_target_amount", ":free_capacity"),
  20160. (faction_get_slot, ":quest_object_troop", ":giver_faction_no", slot_faction_tier_1_troop),
  20161. (store_random_in_range, ":level_up", 20, 40),
  20162. (val_add, ":level_up", ":cur_level"),
  20163. (val_div, ":level_up", 10),
  20164.  
  20165. (store_mul, ":quest_gold_reward", ":quest_target_amount", 10),
  20166.  
  20167. (assign, ":quest_target_troop", ":quest_object_troop"),
  20168.  
  20169. (try_for_range, ":unused", 0, ":level_up"),
  20170. (troop_get_upgrade_troop, ":level_up_troop", ":quest_target_troop", 0),
  20171. (gt, ":level_up_troop", 0),
  20172. (assign, ":quest_target_troop", ":level_up_troop"),
  20173. ##diplomacy start+ Fix what appears to be a native bug,
  20174. #(val_mul, ":quest_gold_reward", ":quest_gold_reward", 7),
  20175. #(val_div, ":quest_gold_reward", ":quest_gold_reward", 4),
  20176. (val_mul, ":quest_gold_reward", 7),
  20177. (val_div, ":quest_gold_reward", 4),
  20178. ##diplomacy end+
  20179. (try_end),
  20180.  
  20181. (assign, ":quest_xp_reward", ":quest_gold_reward"),
  20182. (val_mul, ":quest_xp_reward", 3),
  20183. (val_div, ":quest_xp_reward", 10),
  20184. (assign, ":result", ":quest_no"),
  20185. (assign, ":quest_expiration_days", 120),
  20186. (assign, ":quest_dont_give_again_period", 15),
  20187. (try_end),
  20188. (else_try),
  20189. (eq, ":quest_no", "qst_collect_taxes"),
  20190. ##diplomacy start+ enable this quest even when a vassal,
  20191. #if the quest giver is an affiliated family member
  20192. #...or from the faction leader, the faction marshall, or your spouse
  20193. (this_or_next|ge, ":is_close", 1),
  20194. (this_or_next|ge, ":nominal_superior", 1),
  20195. ##diplomacy end+
  20196. (eq, "$player_has_homage", 0),
  20197.  
  20198. (try_begin),
  20199. ##diplomacy start+ benefactor lords do not give tax-collection quest because good-natured/upstanding do not
  20200. (neq, ":giver_reputation", lrep_benefactor),
  20201. #neither do certain lady personalities either (only ambitious do)
  20202. (neg|is_between, ":giver_reputation", lrep_conventional, lrep_ambitious),
  20203. (neq, ":giver_reputation", lrep_moralist),
  20204. ##diplomacy end+
  20205. (neq, ":giver_reputation", lrep_goodnatured),
  20206. (neq, ":giver_reputation", lrep_upstanding),
  20207. (ge, "$g_talk_troop_faction_relation", 0),
  20208. #SB : we've modified this script call with additional parameter
  20209. (call_script, "script_cf_troop_get_random_leaded_town_or_village_except_center", ":giver_troop", ":giver_center_no", svs_normal),
  20210. (assign, ":quest_target_center", reg0),
  20211. (assign, ":quest_importance", 1),
  20212. (assign, ":quest_gold_reward", 0),
  20213. (assign, ":quest_xp_reward", 100),
  20214. (assign, ":result", ":quest_no"),
  20215. (assign, ":quest_expiration_days", 50),
  20216. (assign, ":quest_dont_give_again_period", 20),
  20217. (try_end),
  20218. (else_try),
  20219. (eq, ":quest_no", "qst_hunt_down_fugitive"),
  20220. (try_begin),
  20221. (ge, "$g_talk_troop_faction_relation", 0),
  20222. #SB : change conditions to prevent selecting a village that's being raided or infested by bandits
  20223. ## although at higher levels we can make it so that the "kinsmen" are bandits
  20224. (assign, ":cur_target_center", -1),
  20225. (try_for_range, ":unused_2", 0, 10),
  20226. (call_script, "script_cf_select_random_village_with_faction", ":giver_faction_no"),
  20227. (call_script, "script_cf_village_normal_cond", reg0),
  20228. (assign, ":cur_target_center", reg0),
  20229. (try_end),
  20230. (neq, ":cur_target_center", -1),
  20231. # (call_script, "script_cf_select_random_village_with_faction", ":giver_faction_no"),
  20232. (assign, ":quest_target_center", ":cur_target_center"),
  20233. (store_random_in_range, ":quest_target_dna", 0, 1000000),
  20234. (assign, ":result", ":quest_no"),
  20235. (assign, ":quest_expiration_days", 30),
  20236. (assign, ":quest_dont_give_again_period", 30),
  20237. (try_end),
  20238. ## (else_try),
  20239. ## (eq, ":quest_no", "qst_capture_messenger"),
  20240. ## (try_begin),
  20241. ## (call_script, "script_cf_faction_get_random_enemy_faction", ":giver_faction_no"),
  20242. ## (assign, ":cur_target_faction", reg0),
  20243. ## (faction_get_slot, ":cur_target_troop", ":cur_target_faction", slot_faction_messenger_troop),
  20244. ## (gt, ":cur_target_troop", 0),#Checking the validiy of cur_target_troop
  20245. ## (store_num_parties_destroyed_by_player, ":quest_target_amount", "pt_messenger_party"),
  20246. ##
  20247. ## (assign, ":quest_target_troop", ":cur_target_troop"),
  20248. ## (assign, ":quest_target_party_template", ":cur_target_party_template"),
  20249. ## (assign, ":quest_importance", 1),
  20250. ## (assign, ":quest_xp_reward", 700),
  20251. ## (assign, ":quest_gold_reward", 400),
  20252. ## (assign, ":result", ":quest_no"),
  20253. ## (try_end),
  20254. (else_try),
  20255. (eq, ":quest_no", "qst_kill_local_merchant"),
  20256. ##diplomacy start+ enable this quest even when a vassal from an affiliated family member or your spouse
  20257. (this_or_next|ge, ":is_close", 1),
  20258. ##diplomacy end+
  20259. (eq, "$player_has_homage", 0),
  20260.  
  20261. (try_begin),
  20262. ##diplomacy start+
  20263. #Lords who dislike breaking deals do not give this quest
  20264. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_honest),
  20265. (lt, reg0, 1),
  20266. #Roguish lords can give the Kill Local Merchant quest, unless they dislike murder.
  20267. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  20268. (this_or_next|neq, ":giver_reputation", lrep_roguish),
  20269. (lt, reg0, 1),
  20270. #Ambitious ladies can give this quest
  20271. (this_or_next|eq, ":giver_reputation", lrep_ambitious),
  20272. (this_or_next|eq, ":giver_reputation", lrep_roguish),
  20273. ##diplomacy end+
  20274. (this_or_next|eq, ":giver_reputation", lrep_quarrelsome),
  20275. (this_or_next|eq, ":giver_reputation", lrep_cunning),
  20276. ( eq, ":giver_reputation", lrep_debauched),
  20277. (neg|faction_slot_eq, ":giver_faction_no", slot_faction_leader, ":giver_troop"),#Can not take the quest from the king
  20278. (ge, "$g_talk_troop_faction_relation", 0),
  20279. (gt, ":player_level", 5),
  20280. (is_between, ":giver_center_no", towns_begin, towns_end),
  20281. (assign, ":quest_importance", 1),
  20282. (assign, ":quest_xp_reward", 300),
  20283. (assign, ":quest_gold_reward", 1000),
  20284. (assign, ":result", ":quest_no"),
  20285. (assign, ":quest_expiration_days", 10),
  20286. (assign, ":quest_dont_give_again_period", 30),
  20287. (try_end),
  20288. (else_try),
  20289. (eq, ":quest_no", "qst_bring_back_runaway_serfs"),
  20290. (try_begin),
  20291. ##diplomacy start+
  20292. #companions who have compassion for commoners do not give the Runaway Serfs quest
  20293. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  20294. (lt, reg0, 1),
  20295. #neither do Benefactor lords
  20296. (neq, ":giver_reputation", lrep_benefactor),
  20297. #neither do most lady personalities (only ambitious do)
  20298. (neg|is_between, ":giver_reputation", lrep_conventional, lrep_ambitious),
  20299. (neq, ":giver_reputation", lrep_moralist),
  20300. ##diplomacy end+
  20301. (neq, ":giver_reputation", lrep_goodnatured),
  20302. (neq, ":giver_reputation", lrep_upstanding),
  20303. (ge, "$g_talk_troop_faction_relation", 0),
  20304. (ge, ":player_level", 5),
  20305. (gt, ":giver_center_no", 0),#Skip if lord is outside the center
  20306. (eq, "$g_defending_against_siege", 0),#Skip if the center is under siege (because of resting)
  20307.  
  20308. (assign, ":cur_object_center", -1),
  20309. (try_for_range, ":cur_village", villages_begin, villages_end),
  20310. (party_slot_eq, ":cur_village", slot_town_lord, ":giver_troop"),
  20311. (store_distance_to_party_from_party, ":dist", ":cur_village", ":giver_center_no"),
  20312. (lt, ":dist", 25),
  20313. (assign, ":cur_object_center", ":cur_village"),
  20314. (try_end),
  20315. (ge, ":cur_object_center", 0),#Skip if the quest giver is not the owner of any villages around the center
  20316. (call_script, "script_cf_select_random_town_with_faction", ":giver_faction_no"),
  20317. (assign, ":cur_target_center", reg0),
  20318. (neq, ":cur_target_center", ":giver_center_no"),#Skip current center
  20319. (store_distance_to_party_from_party, ":dist", ":cur_target_center", ":giver_center_no"),
  20320. (ge, ":dist", 20),
  20321. (assign, ":quest_target_party_template", "pt_runaway_serfs"),
  20322. (assign, ":quest_object_center", ":cur_object_center"),
  20323. (assign, ":quest_target_center", ":cur_target_center"),
  20324. (assign, ":quest_importance", 1),
  20325. (assign, ":quest_xp_reward", 200),
  20326. (assign, ":quest_gold_reward", 150),
  20327. (assign, ":result", ":quest_no"),
  20328. (assign, ":quest_expiration_days", 30),
  20329. (assign, ":quest_dont_give_again_period", 20),
  20330. (assign, "$qst_bring_back_runaway_serfs_num_parties_returned", 0),
  20331. (assign, "$qst_bring_back_runaway_serfs_num_parties_fleed", 0),
  20332. (try_end),
  20333. (else_try),
  20334. (eq, ":quest_no", "qst_follow_spy"),
  20335. ##diplomacy start+ enable this quest even when a vassal from an affiliated family member or your spouse
  20336. #or a nominal superior
  20337. (this_or_next|ge, ":is_close", 1),
  20338. (this_or_next|ge, ":nominal_superior", 1),
  20339. ##diplomacy end+
  20340. (eq, "$player_has_homage", 0),
  20341.  
  20342. (try_begin),
  20343. (ge, "$g_talk_troop_faction_relation", 0),
  20344. ##diplomacy start+
  20345. #Ladies other than the ambitious do not give this quest
  20346. (this_or_next|lt, reg0, 0),
  20347. (this_or_next|eq, ":giver_reputation", lrep_ambitious),
  20348. (neg|is_between, ":giver_reputation", lrep_conventional, lrep_moralist + 1),
  20349. #As the "success" dialogue refers to torture, humanitarians do not either
  20350. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  20351. (lt, reg0, 1),
  20352. #This is more open to interpretation, but I will also bar custodians from
  20353. #this, unless they have a negative tmt_humanitarian score.
  20354. (this_or_next|lt, reg0, 0),
  20355. (neq, ":giver_reputation", lrep_custodian),
  20356. (neq, ":giver_reputation", lrep_benefactor),
  20357. ##diplomacy end+
  20358. (neq, ":giver_reputation", lrep_goodnatured),
  20359. (party_get_skill_level, ":tracking_skill", "p_main_party", "skl_tracking"),
  20360. (ge, ":tracking_skill", 2),
  20361. (ge, ":player_level", 10),
  20362. (eq, "$g_defending_against_siege", 0), #Skip if the center is under siege (because of resting)
  20363. (gt, ":giver_party_no", 0), #Skip if the quest giver doesn't have a party
  20364. (gt, ":giver_center_no", 0), #skip if the quest giver is not in a center
  20365. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town), #skip if we are not in a town.
  20366. (party_get_position, pos2, "p_main_party"),
  20367. (assign, ":min_distance", 99999),
  20368. (assign, ":cur_object_center", -1),
  20369. (try_for_range, ":unused_2", 0, 10),
  20370. (call_script, "script_cf_get_random_enemy_center", ":giver_party_no"),
  20371. (assign, ":random_object_center", reg0),
  20372. (party_get_position, pos3, ":random_object_center"),
  20373. (map_get_random_position_around_position, pos4, pos3, 6),
  20374. (get_distance_between_positions, ":cur_distance", pos2, pos4),
  20375. (lt, ":cur_distance", ":min_distance"),
  20376. (assign, ":min_distance", ":cur_distance"),
  20377. (assign, ":cur_object_center", ":random_object_center"),
  20378. (copy_position, pos63, pos4), #Do not change pos63 until quest is accepted
  20379. (try_end),
  20380. (gt, ":cur_object_center", 0), #Skip if there are no enemy centers
  20381.  
  20382. (assign, ":quest_object_center", ":cur_object_center"),
  20383. (assign, ":quest_dont_give_again_period", 50),
  20384. (assign, ":result", ":quest_no"),
  20385. (assign, "$qst_follow_spy_run_away", 0),
  20386. (assign, "$qst_follow_spy_meeting_state", 0),
  20387. (assign, "$qst_follow_spy_meeting_counter", 0),
  20388. (assign, "$qst_follow_spy_spy_back_in_town", 0),
  20389. (assign, "$qst_follow_spy_partner_back_in_town", 0),
  20390. (assign, "$qst_follow_spy_no_active_parties", 0),
  20391. (try_end),
  20392. (else_try),
  20393. (eq, ":quest_no", "qst_capture_enemy_hero"),
  20394. (try_begin),
  20395. (eq, "$players_kingdom", ":giver_faction_no"),
  20396. ##diplomacy start+
  20397. (this_or_next|ge, ":is_close", 1),
  20398. (this_or_next|ge, ":nominal_superior", 1),
  20399. ##diplomacy end+
  20400. (neg|faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
  20401. (ge, ":player_level", 15),
  20402. (call_script, "script_cf_faction_get_random_enemy_faction", ":giver_faction_no"),#Can fail
  20403. (assign, ":quest_target_faction", reg0),
  20404. (assign, ":quest_expiration_days", 30),
  20405. ##diplomacy start+ change from 80 to 30
  20406. (assign, ":quest_dont_give_again_period", 30),#was 80
  20407. ##diplomacy end+
  20408. (assign, ":quest_gold_reward", 2000),
  20409. (assign, ":result", ":quest_no"),
  20410. (try_end),
  20411. (else_try),
  20412. (eq, ":quest_no", "qst_lend_companion"),
  20413. (try_begin),
  20414. (ge, "$g_talk_troop_faction_relation", 0),
  20415. (assign, ":total_heroes", 0),
  20416. (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  20417. #SB : pre-process
  20418. (try_for_range, ":troop_no", companions_begin, companions_end),
  20419. (troop_set_slot, ":troop_no", dplmc_slot_troop_temp_slot, 0),
  20420. (try_end),
  20421. (try_for_range, ":i_stack", 0, ":num_stacks"),
  20422. (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
  20423. (troop_is_hero, ":stack_troop"),
  20424. (is_between, ":stack_troop", companions_begin, companions_end),
  20425. (store_character_level, ":stack_level", ":stack_troop"),
  20426. (ge, ":stack_level", 15),
  20427. (assign, ":is_quest_hero", 0),
  20428. (try_for_range, ":i_quest", 0, all_quests_end),
  20429. (check_quest_active, ":i_quest"),
  20430. (this_or_next|quest_slot_eq, ":i_quest", slot_quest_target_troop, ":stack_troop"),
  20431. (quest_slot_eq, ":i_quest", slot_quest_object_troop, ":stack_troop"),
  20432. (assign, ":is_quest_hero", 1),
  20433. (try_end),
  20434. (eq, ":is_quest_hero", 0),
  20435. (val_add, ":total_heroes", 1),
  20436. (troop_set_slot, ":stack_troop", dplmc_slot_troop_temp_slot, 1), #SB : set flag here
  20437. (try_end),
  20438. (gt, ":total_heroes", 0),#Skip if party has no eligible heroes
  20439. (store_random_in_range, ":random_hero", 0, ":total_heroes"),
  20440. (assign, ":total_heroes", 0),
  20441. (assign, ":cur_target_troop", -1),
  20442. (try_for_range, ":stack_troop", companions_begin, companions_end),
  20443. (eq, ":cur_target_troop", -1),
  20444. # (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
  20445. # (troop_is_hero, ":stack_troop"),
  20446. # (is_between, ":stack_troop", companions_begin, companions_end),
  20447. # # (neq, ":stack_troop", "trp_player"), #SB : useless check
  20448. # (store_character_level, ":stack_level", ":stack_troop"),
  20449. # (ge, ":stack_level", 15),
  20450. # (assign, ":is_quest_hero", 0),
  20451. # (try_for_range, ":i_quest", 0, all_quests_end),
  20452. # (check_quest_active, ":i_quest"),
  20453. # (this_or_next|quest_slot_eq, ":i_quest", slot_quest_target_troop, ":stack_troop"),
  20454. # (quest_slot_eq, ":i_quest", slot_quest_object_troop, ":stack_troop"),
  20455. # (assign, ":is_quest_hero", 1),
  20456. # (try_end),
  20457. # (eq, ":is_quest_hero", 0),
  20458. #SB : check flag here
  20459. (troop_slot_eq, ":stack_troop", dplmc_slot_troop_temp_slot, 1),
  20460. (val_add, ":total_heroes", 1),
  20461. (gt, ":total_heroes", ":random_hero"),
  20462. (assign, ":cur_target_troop", ":stack_troop"),
  20463. (try_end),
  20464. (is_between, ":cur_target_troop", companions_begin, companions_end),
  20465.  
  20466. (assign, ":quest_target_troop", ":cur_target_troop"),
  20467. (store_current_day, ":quest_target_amount"),
  20468. (val_add, ":quest_target_amount", 8),
  20469.  
  20470. (assign, ":quest_importance", 1),
  20471. #SB : scale reward by level
  20472. (store_character_level, ":stack_level", ":quest_target_troop"),
  20473. (store_mul, ":quest_xp_reward", ":stack_level", 20), #base level of 15
  20474. # (assign, ":quest_xp_reward", 300),
  20475. # (assign, ":quest_gold_reward", 400),
  20476. (store_add, ":quest_gold_reward", ":quest_xp_reward", 100),
  20477. (assign, ":result", ":quest_no"),
  20478. (assign, ":quest_dont_give_again_period", 30),
  20479. (try_end),
  20480. (else_try),
  20481. (eq, ":quest_no", "qst_collect_debt"),
  20482. (eq, 1, 0), #disable this quest pending talk with armagan
  20483. (try_begin),
  20484. (ge, "$g_talk_troop_faction_relation", 0),
  20485. # Find a vassal (within the same kingdom?)
  20486. (call_script, "script_cf_get_random_lord_in_a_center_with_faction", ":giver_faction_no"),#Can fail
  20487. (assign, ":quest_target_troop", reg0),
  20488. (neq, ":quest_target_troop", ":giver_troop"),#Skip himself
  20489. (call_script, "script_get_troop_attached_party", ":quest_target_troop"),
  20490. (assign, ":quest_target_center", reg0),#cur_target_center will definitely be a valid center
  20491. (neq,":giver_center_no", ":quest_target_center"),#Skip current center
  20492.  
  20493. (assign, ":quest_xp_reward", 30),
  20494. (assign, ":quest_gold_reward", 40),
  20495. (assign, ":result", ":quest_no"),
  20496. (store_random_in_range, ":quest_target_amount", 6, 9),
  20497. (val_mul, ":quest_target_amount", 500),
  20498. (store_div, ":quest_convince_value", ":quest_target_amount", 5),
  20499. (assign, ":quest_expiration_days", 90),
  20500. (assign, ":quest_dont_give_again_period", 20),
  20501. (try_end),
  20502. ## (else_try),
  20503. ## (eq, ":quest_no", "qst_capture_conspirators"),
  20504. ## (try_begin),
  20505. ## (eq, 1,0), #TODO: disable this for now
  20506. ## (ge, ":player_level", 10),
  20507. ## (is_between, ":giver_center_no", towns_begin, towns_end),#Skip if quest giver's center is not a town
  20508. ## (party_slot_eq, ":giver_center_no", slot_town_lord, ":giver_troop"),#Skip if the current center is not ruled by the quest giver
  20509. ## (call_script, "script_cf_get_random_kingdom_hero", ":giver_faction_no"),#Can fail
  20510. ##
  20511. ## (assign, ":quest_target_troop", reg0),
  20512. ## (assign, ":quest_target_center", ":giver_center_no"),
  20513. ## (assign, ":quest_importance", 1),
  20514. ## (assign, ":quest_xp_reward", 10),
  20515. ## (assign, ":quest_gold_reward", 10),
  20516. ## (assign, ":result", ":quest_no"),
  20517. ## (store_character_level, ":cur_level"),
  20518. ## (val_div, ":cur_level", 5),
  20519. ## (val_max, ":cur_level", 3),
  20520. ## (store_add, ":max_parties", 4, ":cur_level"),
  20521. ## (store_random_in_range, "$qst_capture_conspirators_num_parties_to_spawn", 4, ":max_parties"),
  20522. ## (assign, "$qst_capture_conspirators_num_troops_to_capture", 0),
  20523. ## (assign, "$qst_capture_conspirators_num_parties_spawned", 0),
  20524. ## (assign, "$qst_capture_conspirators_leave_meeting_counter", 0),
  20525. ## (assign, "$qst_capture_conspirators_party_1", 0),
  20526. ## (assign, "$qst_capture_conspirators_party_2", 0),
  20527. ## (assign, "$qst_capture_conspirators_party_3", 0),
  20528. ## (assign, "$qst_capture_conspirators_party_4", 0),
  20529. ## (assign, "$qst_capture_conspirators_party_5", 0),
  20530. ## (assign, "$qst_capture_conspirators_party_6", 0),
  20531. ## (assign, "$qst_capture_conspirators_party_7", 0),
  20532. ## (try_end),
  20533. ## (else_try),
  20534. ## (eq, ":quest_no", "qst_defend_nobles_against_peasants"),
  20535. ## (try_begin),
  20536. ## (eq, 1,0), #TODO: disable this for now
  20537. ## (ge, ":player_level", 10),
  20538. ## (is_between, ":giver_center_no", towns_begin, towns_end),#Skip if quest giver's center is not a town
  20539. ## (party_slot_eq, ":giver_center_no", slot_town_lord, ":giver_troop"),#Skip if the current center is not ruled by the quest giver
  20540. ##
  20541. ## (assign, ":quest_target_center", ":giver_center_no"),
  20542. ## (assign, ":quest_importance", 1),
  20543. ## (assign, ":quest_xp_reward", 10),
  20544. ## (assign, ":quest_gold_reward", 10),
  20545. ## (assign, ":result", ":quest_no"),
  20546. ## (store_character_level, ":cur_level"),
  20547. ## (val_div, ":cur_level", 5),
  20548. ## (val_max, ":cur_level", 4),
  20549. ## (store_add, ":max_parties", 4, ":cur_level"),
  20550. ## (store_random_in_range, "$qst_defend_nobles_against_peasants_num_peasant_parties_to_spawn", 4, ":cur_level"),
  20551. ## (store_random_in_range, "$qst_defend_nobles_against_peasants_num_noble_parties_to_spawn", 4, ":cur_level"),
  20552. ## (assign, "$qst_defend_nobles_against_peasants_num_nobles_to_save", 0),
  20553. ## (assign, "$qst_defend_nobles_against_peasants_num_nobles_saved", 0),
  20554. ## (assign, "$qst_defend_nobles_against_peasants_peasant_party_1", 0),
  20555. ## (assign, "$qst_defend_nobles_against_peasants_peasant_party_2", 0),
  20556. ## (assign, "$qst_defend_nobles_against_peasants_peasant_party_3", 0),
  20557. ## (assign, "$qst_defend_nobles_against_peasants_peasant_party_4", 0),
  20558. ## (assign, "$qst_defend_nobles_against_peasants_peasant_party_5", 0),
  20559. ## (assign, "$qst_defend_nobles_against_peasants_peasant_party_6", 0),
  20560. ## (assign, "$qst_defend_nobles_against_peasants_peasant_party_7", 0),
  20561. ## (assign, "$qst_defend_nobles_against_peasants_peasant_party_8", 0),
  20562. ## (assign, "$qst_defend_nobles_against_peasants_noble_party_1", 0),
  20563. ## (assign, "$qst_defend_nobles_against_peasants_noble_party_2", 0),
  20564. ## (assign, "$qst_defend_nobles_against_peasants_noble_party_3", 0),
  20565. ## (assign, "$qst_defend_nobles_against_peasants_noble_party_4", 0),
  20566. ## (assign, "$qst_defend_nobles_against_peasants_noble_party_5", 0),
  20567. ## (assign, "$qst_defend_nobles_against_peasants_noble_party_6", 0),
  20568. ## (assign, "$qst_defend_nobles_against_peasants_noble_party_7", 0),
  20569. ## (assign, "$qst_defend_nobles_against_peasants_noble_party_8", 0),
  20570. ## (try_end),
  20571. (else_try),
  20572. (eq, ":quest_no", "qst_incriminate_loyal_commander"),
  20573. ##diplomacy start+ enable this quest even when a vassal from an affiliated family member
  20574. (this_or_next|ge, ":is_close", 1),
  20575. ##diplomacy end+
  20576. (eq, "$player_has_homage", 0),
  20577.  
  20578. (try_begin),
  20579. ##diplomacy start+ benefactors & moralists will not give this quest
  20580. (neq, ":giver_reputation", lrep_benefactor),
  20581. (neq, ":giver_reputation", lrep_moralist),
  20582. #neither will most lady personalities (only ambitious do)
  20583. (neg|is_between, ":giver_reputation", lrep_conventional, lrep_ambitious),
  20584. (neq, ":giver_reputation", lrep_moralist),
  20585. #neither will lords who dislike mistreating their own men, or who
  20586. #are forthright in their dealings
  20587. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_egalitarian),
  20588. (lt, reg0, 1),
  20589. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_honest),
  20590. (lt, reg0, 1),
  20591. #neither will other lords who dislike murder
  20592. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  20593. (lt, reg0, 1),
  20594. ##diplomacy end+
  20595. (neq, ":giver_reputation", lrep_upstanding),
  20596. (neq, ":giver_reputation", lrep_goodnatured),
  20597. (eq, "$players_kingdom", ":giver_faction_no"),
  20598. (ge, ":player_level", 10),
  20599. (faction_slot_eq, ":giver_faction_no", slot_faction_leader, ":giver_troop"),
  20600. (assign, ":try_times", 1),
  20601. (assign, ":found", 0),
  20602. (try_for_range, ":unused", 0, ":try_times"),
  20603. (call_script, "script_cf_faction_get_random_enemy_faction", ":giver_faction_no"),#Can fail
  20604. (assign, ":cur_target_faction", reg0),
  20605.  
  20606. (faction_get_slot, ":cur_target_troop", ":cur_target_faction", slot_faction_leader),
  20607. (assign, ":num_centerless_heroes", 0),
  20608. ##diplomacy start+ add support for promoted ladies
  20609. (try_for_range, ":cur_kingdom_hero", heroes_begin, heroes_end),#<- changed active_npcs to heroes
  20610. ##diplomacy end+
  20611. (troop_slot_eq, ":cur_kingdom_hero", slot_troop_occupation, slto_kingdom_hero),
  20612. #(troop_slot_eq, ":cur_kingdom_hero", slot_troop_is_prisoner, 0),
  20613. (neg|troop_slot_ge, ":cur_kingdom_hero", slot_troop_prisoner_of_party, 0),
  20614. (neq, ":cur_target_troop", ":cur_kingdom_hero"),
  20615. (store_troop_faction, ":cur_kingdom_hero_faction", ":cur_kingdom_hero"),
  20616. (eq, ":cur_target_faction", ":cur_kingdom_hero_faction"),
  20617. ## (call_script, "script_get_number_of_hero_centers", ":cur_kingdom_hero"),
  20618. ## (eq, reg0, 0),
  20619. (val_add, ":num_centerless_heroes", 1),
  20620. (try_end),
  20621. (gt, ":num_centerless_heroes", 0),
  20622. (assign, ":cur_object_troop", -1),
  20623. (store_random_in_range, ":random_kingdom_hero", 0, ":num_centerless_heroes"),
  20624. ##diplomacy start+ add support for promoted ladies
  20625. (try_for_range, ":cur_kingdom_hero", heroes_begin, heroes_end),#<- changed active_npcs to heroes
  20626. ##diplomacy end+
  20627. (eq, ":cur_object_troop", -1),
  20628. (troop_slot_eq, ":cur_kingdom_hero", slot_troop_occupation, slto_kingdom_hero),
  20629. (neq, ":cur_target_troop", ":cur_kingdom_hero"),
  20630. (store_troop_faction, ":cur_kingdom_hero_faction", ":cur_kingdom_hero"),
  20631. (eq, ":cur_target_faction", ":cur_kingdom_hero_faction"),
  20632. ## (call_script, "script_get_number_of_hero_centers", ":cur_kingdom_hero"),
  20633. ## (eq, reg0, 0),
  20634. (val_sub, ":random_kingdom_hero", 1),
  20635. (lt, ":random_kingdom_hero", 0),
  20636. (assign, ":cur_object_troop", ":cur_kingdom_hero"),
  20637. (try_end),
  20638.  
  20639. (assign, ":cur_target_center", -1),
  20640. (call_script, "script_get_troop_attached_party", ":cur_target_troop"),
  20641. (is_between, reg0, towns_begin, towns_end),
  20642. (party_slot_eq, reg0, slot_town_lord, ":cur_target_troop"),
  20643. (assign, ":cur_target_center", reg0),
  20644.  
  20645. (assign, ":try_times", -1),#Exit the second loop
  20646. (assign, ":found", 1),
  20647. (try_end),
  20648. (eq, ":found", 1),
  20649.  
  20650. (assign, "$incriminate_quest_sacrificed_troop", 0),
  20651.  
  20652. (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  20653. (try_for_range, ":i_stack", 1, ":num_stacks"),
  20654. (eq ,"$incriminate_quest_sacrificed_troop", 0),
  20655. (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
  20656. (neg|troop_is_hero, ":stack_troop"),
  20657. (store_character_level, ":stack_troop_level", ":stack_troop"),
  20658. (ge, ":stack_troop_level", 25), #this is "top tier"
  20659. (assign, "$incriminate_quest_sacrificed_troop", ":stack_troop"),
  20660. (try_end),
  20661. (gt, "$incriminate_quest_sacrificed_troop", 0),
  20662.  
  20663. (assign, ":quest_target_troop", ":cur_target_troop"),
  20664. (assign, ":quest_object_troop", ":cur_object_troop"),
  20665. (assign, ":quest_target_center", ":cur_target_center"),
  20666. (assign, ":quest_target_faction", ":cur_target_faction"),
  20667.  
  20668. (assign, ":quest_importance", 1),
  20669. (assign, ":quest_xp_reward", 700),
  20670. (assign, ":quest_gold_reward", 1000),
  20671. (assign, ":result", ":quest_no"),
  20672. (assign, ":quest_expiration_days", 30),
  20673. (assign, ":quest_dont_give_again_period", 180),
  20674. (try_end),
  20675. (else_try),
  20676. (eq, ":quest_no", "qst_capture_prisoners"),
  20677. ##diplomacy start+ enable this quest even when a vassal from an affiliated family member
  20678. (this_or_next|ge, ":is_close", 1),
  20679. (this_or_next|ge, ":nominal_superior", 1),
  20680. ##diplomacy end+
  20681. (eq, "$player_has_homage", 0),
  20682.  
  20683. (try_begin),
  20684. (eq, "$players_kingdom", ":giver_faction_no"),
  20685.  
  20686. # (store_add, ":max_tier_no", slot_faction_tier_5_troop, 1),
  20687. #SB : makes sure the giver doesn't already have these as prisoners when offering
  20688. (assign, ":cond", 20),
  20689. (assign, ":cur_target_faction", -1),
  20690. (assign, ":party_no", -1),
  20691. (try_begin), #store prisoner count
  20692. (is_between, ":giver_center_no", walled_centers_begin, walled_centers_end),
  20693. (party_slot_eq, ":giver_center_no", slot_town_lord, ":giver_troop"),
  20694. (assign, ":party_no", ":giver_center_no"),
  20695. (else_try), #technically we should store both, but while in center prisoners are dropped off
  20696. (party_is_active, ":giver_party_no"),
  20697. (assign, ":party_no", ":giver_party_no"),
  20698. (try_end),
  20699. # (gt, ":party_no", 0),
  20700. (try_for_range, ":unused", 0, ":cond"),
  20701. (call_script, "script_cf_faction_get_random_enemy_faction", ":giver_faction_no"),#Can fail
  20702. (assign, ":cur_target_faction", reg0),
  20703. (store_random_in_range, ":random_tier_no", slot_faction_tier_2_troop, slot_faction_tier_5_troop + 1),
  20704. (faction_get_slot, ":cur_target_troop", ":cur_target_faction", ":random_tier_no"),
  20705. (gt, ":cur_target_troop", 0),
  20706. (store_random_in_range, ":quest_target_amount", 3, 7),
  20707. (try_begin),
  20708. (gt, ":party_no", 0),
  20709. (party_count_prisoners_of_type, ":count", ":party_no", ":cur_target_troop"),
  20710. (val_sub, ":quest_target_amount", ":count"),
  20711. (try_end),
  20712. (gt, ":quest_target_amount", 1), #too minor to give a quest for 1 soldier
  20713. (assign, ":cond", 0),
  20714. (try_end),
  20715. (eq, ":cond", 0),
  20716. (assign, ":quest_target_troop", ":cur_target_troop"),
  20717. (assign, ":quest_target_faction", ":cur_target_faction"),
  20718. (assign, ":quest_importance", 1),
  20719. (store_character_level, ":quest_gold_reward", ":cur_target_troop"),
  20720. (val_add, ":quest_gold_reward", 5),
  20721. (val_mul, ":quest_gold_reward", ":quest_gold_reward"),
  20722. (val_div, ":quest_gold_reward", 5),
  20723. (val_mul, ":quest_gold_reward", ":quest_target_amount"),
  20724. (assign, ":quest_xp_reward", ":quest_gold_reward"),
  20725. (assign, ":result", ":quest_no"),
  20726. (assign, ":quest_expiration_days", 90),
  20727. (assign, ":quest_dont_give_again_period", 20),
  20728. (try_end),
  20729. (try_end),
  20730. (try_end),
  20731. (try_end),
  20732. #end of quest finding
  20733.  
  20734.  
  20735. (try_begin),
  20736. (neq, ":result", -1),
  20737.  
  20738. (try_begin),
  20739. (party_is_active, ":quest_target_center"),
  20740. (store_faction_of_party, ":quest_target_faction", ":quest_target_center"),
  20741. (try_end),
  20742.  
  20743. (quest_set_slot, ":result", slot_quest_target_troop, ":quest_target_troop"),
  20744. (quest_set_slot, ":result", slot_quest_target_center, ":quest_target_center"),
  20745. (quest_set_slot, ":result", slot_quest_object_troop, ":quest_object_troop"),
  20746. (quest_set_slot, ":result", slot_quest_target_faction, ":quest_target_faction"),
  20747. (quest_set_slot, ":result", slot_quest_object_faction, ":quest_object_faction"),
  20748. (quest_set_slot, ":result", slot_quest_object_center, ":quest_object_center"),
  20749. (quest_set_slot, ":result", slot_quest_target_party, ":quest_target_party"),
  20750. (quest_set_slot, ":result", slot_quest_target_party_template, ":quest_target_party_template"),
  20751. (quest_set_slot, ":result", slot_quest_target_amount, ":quest_target_amount"),
  20752. (quest_set_slot, ":result", slot_quest_importance, ":quest_importance"),
  20753. (quest_set_slot, ":result", slot_quest_xp_reward, ":quest_xp_reward"),
  20754. (quest_set_slot, ":result", slot_quest_gold_reward, ":quest_gold_reward"),
  20755. (quest_set_slot, ":result", slot_quest_convince_value, ":quest_convince_value"),
  20756. (quest_set_slot, ":result", slot_quest_expiration_days, ":quest_expiration_days"),
  20757. (quest_set_slot, ":result", slot_quest_dont_give_again_period, ":quest_dont_give_again_period"),
  20758. (quest_set_slot, ":result", slot_quest_current_state, 0),
  20759. (quest_set_slot, ":result", slot_quest_giver_troop, ":giver_troop"),
  20760. (quest_set_slot, ":result", slot_quest_giver_center, ":giver_center_no"),
  20761. (quest_set_slot, ":result", slot_quest_target_dna, ":quest_target_dna"),
  20762. (quest_set_slot, ":result", slot_quest_target_item, ":quest_target_item"),
  20763. (try_end),
  20764.  
  20765. (assign, reg0, ":result"),
  20766. ]),
  20767.  
  20768. ("get_dynamic_quest",
  20769. #Dynamic quests are rarer, more important quests
  20770. #this is a separate script from get_quest, so that tavern keepers can scan all NPCs for quests
  20771. [
  20772. (store_script_param_1, ":giver_troop"),
  20773.  
  20774. (assign, ":result", -1),
  20775. (assign, ":relevant_troop", -1),
  20776. (assign, ":relevant_party", -1),
  20777. (assign, ":relevant_faction", -1),
  20778.  
  20779. (try_begin),
  20780. ##diplomacy start+
  20781. ##OLD:
  20782. #(eq, ":giver_troop", -1),
  20783. ##NEW:
  20784. (lt, ":giver_troop", 0),
  20785. ##diplomacy end+
  20786. (else_try),
  20787. #1 rescue prisoner
  20788. (neg|check_quest_active, "qst_rescue_prisoner"),
  20789. (this_or_next|troop_slot_eq, ":giver_troop", slot_troop_occupation, slto_kingdom_hero),
  20790. (troop_slot_eq, ":giver_troop", slot_troop_occupation, slto_kingdom_lady),
  20791.  
  20792. (assign, ":target_troop", -1),
  20793. ##diplomacy start+ add support for promoted ladies
  20794. #(try_for_range, ":possible_prisoner", active_npcs_begin, active_npcs_end),
  20795. (try_for_range, ":possible_prisoner", heroes_begin, heroes_end),
  20796. (this_or_next|troop_slot_eq, ":possible_prisoner", slot_troop_occupation, slto_kingdom_hero),
  20797. (is_between, ":possible_prisoner", active_npcs_begin, active_npcs_end),
  20798. ##diplomacy end+
  20799. (troop_get_slot, ":captor_location", ":possible_prisoner", slot_troop_prisoner_of_party),
  20800. (is_between, ":captor_location", walled_centers_begin, walled_centers_end),
  20801. (store_troop_faction, ":giver_troop_faction_no", ":giver_troop"),
  20802. (store_faction_of_party, ":captor_location_faction_no", ":captor_location"),
  20803. (store_relation, ":giver_captor_relation", ":giver_troop_faction_no", ":captor_location_faction_no"),
  20804. (lt, ":giver_captor_relation", 0),
  20805.  
  20806. (call_script, "script_troop_get_family_relation_to_troop", ":giver_troop", ":possible_prisoner"),
  20807. ##diplomacy start+
  20808. #If optional behavior changes are enabled, allow this for more relatives.
  20809. #(In-laws, uncles, nieces.)
  20810. (try_begin),
  20811. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  20812. (ge, reg0, 4),
  20813. (val_max, reg0, 10),
  20814. (else_try),
  20815. #If the characters are related to each other, and both are
  20816. #affiliated with the player, consider them to be close enough.
  20817. (ge, reg0, 1),
  20818. (lt, reg0, 10),
  20819. (call_script, "script_dplmc_is_affiliated_family_member", ":giver_troop"),
  20820. (ge, reg0, 1),
  20821. (call_script, "script_dplmc_is_affiliated_family_member", ":possible_prisoner"),
  20822. (ge, reg0, 1),
  20823. (assign, reg0, 10),
  20824. (try_end),
  20825. ##diplomacy end+
  20826. (ge, reg0, 10),
  20827.  
  20828. (assign, ":offered_parole", 0),
  20829. (try_begin),
  20830. (call_script, "script_cf_prisoner_offered_parole", ":possible_prisoner"),
  20831. (assign, ":offered_parole", 1),
  20832. (try_end),
  20833. (eq, ":offered_parole", 0),
  20834.  
  20835. (neg|party_slot_eq, ":captor_location", slot_town_lord, "trp_player"),
  20836.  
  20837. (assign, ":target_troop", ":possible_prisoner"),
  20838. (assign, ":target_party", ":captor_location"),
  20839. (try_end),
  20840.  
  20841. (gt, ":target_troop", -1),
  20842. (assign, ":result", "qst_rescue_prisoner"),
  20843. (assign, ":relevant_troop", ":target_troop"),
  20844. (assign, ":relevant_party", ":target_party"),
  20845.  
  20846. (else_try),
  20847. #2 retaliate for border incident
  20848. (is_between, ":giver_troop", mayors_begin, mayors_end),
  20849. (store_faction_of_troop, ":giver_faction", ":giver_troop"),
  20850.  
  20851. (neg|check_quest_active, "qst_retaliate_for_border_incident"),
  20852. (quest_slot_eq, "qst_retaliate_for_border_incident", slot_quest_dont_give_again_remaining_days, 0),
  20853. (assign, ":target_leader", 0),
  20854.  
  20855. (try_for_range, ":kingdom", "fac_kingdom_1", kingdoms_end),
  20856. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":giver_faction", ":kingdom"),
  20857. (assign, ":diplomatic_status", reg0),
  20858. (eq, ":diplomatic_status", -1),
  20859. (assign, ":duration", reg1),
  20860. (ge, ":duration", 10),
  20861.  
  20862. ##diplomacy start+ add support for promoted kingdom ladies
  20863. #(try_for_range, ":lord", active_npcs_begin, active_npcs_end),
  20864. (try_for_range, ":lord", heroes_begin, heroes_end),
  20865. (this_or_next|is_between, ":lord", active_npcs_begin, active_npcs_end),
  20866. (troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  20867. ##diplomacy end+
  20868. (store_faction_of_troop, ":lord_faction", ":lord"),
  20869. (eq, ":lord_faction", ":kingdom"),
  20870.  
  20871. (troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_debauched),
  20872.  
  20873. (assign, ":target_leader", ":lord"),
  20874. (assign, ":target_faction", ":kingdom"),
  20875. (try_end),
  20876. (try_end),
  20877. ##diplomacy start+ add support for promoted kingdom ladies
  20878. #(is_between, ":target_leader", active_npcs_begin, active_npcs_end),
  20879. (is_between, ":target_leader", heroes_begin, heroes_end),
  20880. ##diplomacy end+
  20881.  
  20882. (assign, ":result", "qst_retaliate_for_border_incident"),
  20883. (assign, ":relevant_troop", ":target_leader"),
  20884. (assign, ":relevant_faction", ":target_faction"),
  20885. (else_try), #Find bandit hideout
  20886. (troop_slot_eq, ":giver_troop", slot_troop_occupation, slto_kingdom_hero),
  20887. (neg|check_quest_active, "qst_destroy_bandit_lair"),
  20888. (quest_slot_eq, "qst_destroy_bandit_lair", slot_quest_dont_give_again_remaining_days, 0),
  20889.  
  20890. # (display_message, "@Checking for bandit lair quest"),
  20891.  
  20892. (assign, ":lair_found", -1),
  20893.  
  20894. (try_for_range, ":bandit_template", bandit_party_templates_begin, bandit_party_templates_end), #SB : template range
  20895. (party_template_get_slot, ":bandit_lair", ":bandit_template", slot_party_template_lair_party),
  20896.  
  20897. #No party is active because bandit lairs are removed as soon as they are attacked, by the player -- but can only be removed by the player. This will reset bandit lair to zero
  20898. (gt, ":bandit_lair", "p_spawn_points_end"),
  20899.  
  20900. (assign, ":closest_town", -1),
  20901. (assign, ":score_to_beat", 99999),
  20902.  
  20903. (try_for_range, ":town_no", towns_begin, towns_end),
  20904. (store_distance_to_party_from_party, ":distance", ":bandit_lair", ":town_no"),
  20905. (lt, ":distance", ":score_to_beat"),
  20906. (assign, ":closest_town", ":town_no"),
  20907. (assign, ":score_to_beat", ":distance"),
  20908. (try_end),
  20909.  
  20910. #(str_store_party_name, s7, ":closest_town"),
  20911. #(party_get_slot, ":closest_town_lord", ":closest_town", slot_town_lord),
  20912. #(str_store_troop_name, s8, ":closest_town_lord"),
  20913.  
  20914. (party_slot_eq, ":closest_town", slot_town_lord, ":giver_troop"),
  20915. (assign, ":lair_found", ":bandit_lair"),
  20916. (try_end),
  20917.  
  20918. (gt, ":lair_found", "p_spawn_points_end"),
  20919.  
  20920. (assign ,":result", "qst_destroy_bandit_lair"),
  20921. (assign, ":relevant_party", ":lair_found"),
  20922. (else_try), #3 - bounty on bandit party
  20923. (is_between, ":giver_troop", mayors_begin, mayors_end),
  20924. (neg|check_quest_active, "qst_track_down_bandits"),
  20925. (quest_slot_eq, "qst_track_down_bandits", slot_quest_dont_give_again_remaining_days, 0),
  20926.  
  20927. (assign, ":cur_town", -1),
  20928. (try_for_range, ":town", towns_begin, towns_end),
  20929. (party_slot_eq, ":town", slot_town_elder, ":giver_troop"),
  20930. (assign, ":cur_town", ":town"),
  20931. (try_end),
  20932. (gt, ":cur_town", -1),
  20933.  
  20934. (call_script, "script_merchant_road_info_to_s42", ":cur_town"),
  20935. (assign, ":bandit_party_found", reg0),
  20936. (party_is_active, ":bandit_party_found"),
  20937. (gt, ":bandit_party_found", 0),
  20938.  
  20939. (try_begin),
  20940. (eq, "$cheat_mode", 1),
  20941. (display_message, "str_traveller_attack_found"),
  20942. (try_end),
  20943.  
  20944. (assign ,":result", "qst_track_down_bandits"),
  20945. (assign, ":relevant_party", ":bandit_party_found"),
  20946. (else_try), #raid a caravan to start war
  20947. ##diplomacy start+
  20948. #SB : quest not already active
  20949. (neg|check_quest_active, "qst_cause_provocation"),
  20950. ##Roguish and tmt_humanitarian < 0 also should qualify.
  20951. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  20952. (assign, ":humanitarian_value", reg0),
  20953. (lt, ":humanitarian_value", 1),
  20954. (assign, reg0, 0),#<-- satisfies requirement
  20955. (try_begin),
  20956. #Originally, only lrep_debauched qualified
  20957. (troop_slot_eq, ":giver_troop", slot_lord_reputation_type, lrep_debauched),
  20958. (assign, reg0, 1),
  20959. (else_try),
  20960. #Roguish qualifies for anti-humanitarians
  20961. (troop_slot_eq, ":giver_troop", slot_lord_reputation_type, lrep_roguish),
  20962. (lt, ":humanitarian_value", 1),
  20963. (assign, reg0, 1),
  20964. (try_end),
  20965. (eq, reg0, 1),
  20966. ##diplomacy end+
  20967. (store_faction_of_troop, ":giver_troop_faction", ":giver_troop"),
  20968.  
  20969. (assign, ":junior_debauched_lord_in_faction", -1),
  20970. ##diplomacy start+
  20971. #Add support for promoted kingdom ladies
  20972. #(try_for_range, ":lord_in_faction", active_npcs_begin, active_npcs_end),
  20973. (try_for_range, ":lord_in_faction", heroes_begin, heroes_end),
  20974. (this_or_next|is_between, ":lord_in_faction", active_npcs_begin, active_npcs_end),
  20975. (troop_slot_eq, ":lord_in_faction", slot_troop_occupation, slto_kingdom_hero),
  20976. (call_script, "script_dplmc_get_troop_morality_value", ":giver_troop", tmt_humanitarian),
  20977. (assign, ":other_humanitarian", reg0),
  20978. (lt, ":other_humanitarian", 1),
  20979. (assign, reg0, 0),#<-- satisfies personality requirement
  20980. (try_begin),
  20981. #originally just debauched lords
  20982. (troop_slot_eq, ":lord_in_faction", slot_lord_reputation_type, lrep_debauched),
  20983. (assign, reg0, 1),
  20984. (else_try),
  20985. #roguish qualifies for anti-humanitarians
  20986. (troop_slot_eq, ":giver_troop", slot_lord_reputation_type, lrep_roguish),
  20987. (lt, ":humanitarian_value", 1),
  20988. (assign, reg0, 1),
  20989. (try_end),
  20990. (eq, reg0, 1),
  20991. ##diplomacy end+
  20992. (store_faction_of_troop, ":debauched_lord_faction", ":lord_in_faction"),
  20993. (eq, ":debauched_lord_faction", ":giver_troop_faction"),
  20994. (assign, ":junior_debauched_lord_in_faction", ":lord_in_faction"),
  20995. (try_end),
  20996. (eq, ":giver_troop", ":junior_debauched_lord_in_faction"),
  20997.  
  20998. (assign, ":faction_to_attack", -1),
  20999. (assign, ":faction_to_attack_score", -1),
  21000.  
  21001. (try_for_range, ":faction_candidate", kingdoms_begin, kingdoms_end),
  21002. (neq, ":faction_candidate", ":giver_troop_faction"),
  21003. (faction_slot_eq, ":faction_candidate", slot_faction_state, sfs_active),
  21004. (neq, ":faction_candidate", "$players_kingdom"),
  21005.  
  21006. (store_relation, ":relation", ":faction_candidate", ":giver_troop_faction"),
  21007.  
  21008. (store_add, ":provocation_slot", ":giver_troop_faction", slot_faction_provocation_days_with_factions_begin),
  21009. (val_sub, ":provocation_slot", kingdoms_begin),
  21010. (faction_get_slot, ":provocation_days", ":faction_candidate", ":provocation_slot"),
  21011.  
  21012. (ge, ":relation", 0), #disqualifies if the faction is already at war
  21013. (le, ":provocation_days", 0), #disqualifies if the faction has already provoked someone
  21014.  
  21015. (store_random_in_range, ":faction_candidate_score", 0, 100),
  21016. #add in scores - no truce?
  21017. # (store_add, ":truce_slot", ":giver_troop_faction", slot_faction_truce_days_with_factions_begin),
  21018. # (store_add, ":provocation_slot", ":giver_troop_faction", slot_faction_provocation_days_with_factions_begin),
  21019. # (val_sub, ":truce_slot", kingdoms_begin),
  21020. # (val_sub, ":provocation_slot", kingdoms_begin),
  21021. # (faction_slot_eq, ":faction_candidate", ":provocation_slot", 0),
  21022. # (try_begin),
  21023. # (faction_slot_ge, ":faction_candidate", ":truce_slot", 1),
  21024. # (val_sub, ":faction_to_attack_temp_score", 1),
  21025. # (try_end),
  21026.  
  21027. (gt, ":faction_candidate_score", ":faction_to_attack_score"),
  21028. (assign, ":faction_to_attack", ":faction_candidate"),
  21029. (assign, ":faction_to_attack_score", ":faction_candidate_score"),
  21030. (try_end),
  21031.  
  21032. (is_between, ":faction_to_attack", kingdoms_begin, kingdoms_end),
  21033.  
  21034. (assign ,":result", "qst_cause_provocation"),
  21035. (assign, ":relevant_faction", ":faction_to_attack"),
  21036.  
  21037. (try_end),
  21038.  
  21039. (assign, reg0, ":result"),
  21040. (assign, reg1, ":relevant_troop"),
  21041. (assign, reg2, ":relevant_party"),
  21042. (assign, reg3, ":relevant_faction"),
  21043.  
  21044. ]),
  21045.  
  21046. ("get_political_quest",
  21047. #Political quests are given by the player's political "coach" -- ie, a spouse or the minister -- to improve standing in the faction
  21048. [
  21049. (store_script_param, ":giver_troop", 1),
  21050.  
  21051. (assign, ":result", -1),
  21052. (assign, ":quest_target_troop", -1),
  21053. (assign, ":quest_object_troop", -1),
  21054. (assign, ":quest_dont_give_again_period", 7), #one week on average
  21055.  
  21056.  
  21057.  
  21058. (try_begin), #this for kingdom hero, "we have a mutual enemy"
  21059. (neg|check_quest_active, "qst_denounce_lord"),
  21060. (try_begin),
  21061. (ge, "$cheat_mode", 1),
  21062. (quest_get_slot, reg4, "qst_denounce_lord", slot_quest_dont_give_again_remaining_days),
  21063. (display_message, "@{!}DEBUG -- Checking for denounce lord, eligible in {reg4} days"),
  21064. (try_end),
  21065.  
  21066. (neg|quest_slot_ge, "qst_denounce_lord", slot_quest_dont_give_again_remaining_days, 1),
  21067. (neq, ":giver_troop", "$g_player_minister"),
  21068. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, ":giver_troop"),
  21069. (neg|faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  21070.  
  21071.  
  21072. # (neg|troop_slot_eq, "$g_talk_troop", slot_lord_reputation_type, lrep_martial),
  21073. (neg|troop_slot_eq, "$g_talk_troop", slot_lord_reputation_type, lrep_quarrelsome),
  21074. (neg|troop_slot_eq, "$g_talk_troop", slot_lord_reputation_type, lrep_goodnatured),
  21075.  
  21076. # (neg|troop_slot_ge, "trp_player", slot_troop_controversy, 10),
  21077.  
  21078.  
  21079. (assign, ":target_lord", -1),
  21080. (assign, ":score_to_beat", 1),
  21081.  
  21082. ##diplomacy start+ support promoted ladies
  21083. #(try_for_range, ":potential_target", active_npcs_begin, active_npcs_end),
  21084. (try_for_range, ":potential_target", heroes_begin, heroes_end),
  21085. (this_or_next|is_between, ":potential_target", active_npcs_begin, active_npcs_end),
  21086. (troop_slot_eq, ":potential_target", slot_troop_occupation, slto_kingdom_hero),
  21087. (neg|troop_slot_ge, ":potential_target", slot_troop_occupation, slto_retirement),
  21088. ##diplomacy end+
  21089. (store_faction_of_troop, ":potential_target_faction", ":potential_target"),
  21090. (eq, ":potential_target_faction", "$players_kingdom"),
  21091. (neq, ":potential_target", ":giver_troop"),
  21092. (neg|faction_slot_eq, ":potential_target_faction", slot_faction_leader, ":potential_target"),
  21093.  
  21094. #cannot denounce if you also have an intrigue against lord active
  21095. (this_or_next|neg|check_quest_active, "qst_intrigue_against_lord"),
  21096. (neg|quest_slot_eq, "qst_intrigue_against_lord", slot_quest_target_troop, ":potential_target"),
  21097.  
  21098. (call_script, "script_troop_get_relation_with_troop", ":potential_target", ":giver_troop"),
  21099. (assign, ":relation_with_giver_troop", reg0),
  21100. (lt, ":relation_with_giver_troop", ":score_to_beat"),
  21101.  
  21102. (str_store_troop_name, s4, ":potential_target"),
  21103. (try_begin),
  21104. (ge, "$cheat_mode", 1),
  21105. (display_message, "@{!}DEBUG -- Rival found in {s4}"),
  21106. (try_end),
  21107.  
  21108. (try_begin),
  21109. (troop_slot_eq, "$g_talk_troop", slot_lord_reputation_type, lrep_debauched),
  21110. (assign, ":max_rel_w_player", 15),
  21111. (else_try),
  21112. ##diplomacy start+
  21113. (this_or_next|troop_slot_eq, "$g_talk_troop", slot_lord_reputation_type, lrep_ambitious),
  21114. ##diplomacy end+
  21115. (troop_slot_eq, "$g_talk_troop", slot_lord_reputation_type, lrep_quarrelsome),
  21116. (assign, ":max_rel_w_player", 10),
  21117. (else_try),
  21118. (assign, ":max_rel_w_player", 5),
  21119. (try_end),
  21120.  
  21121. (call_script, "script_troop_get_relation_with_troop", ":potential_target", "trp_player"),
  21122. (assign, ":relation_with_player", reg0),
  21123. (lt, ":relation_with_player", ":max_rel_w_player"),
  21124.  
  21125. (str_store_troop_name, s4, ":potential_target"),
  21126. (try_begin),
  21127. (ge, "$cheat_mode", 1),
  21128. (display_message, "@{!}DEBUG -- {s4} is not close friend of player"),
  21129. (try_end),
  21130.  
  21131. (assign, ":enemies_in_faction", 0),
  21132. ##diplomacy start+ support promoted ladies
  21133. #(try_for_range, ":other_lord", active_npcs_begin, active_npcs_end),
  21134. (try_for_range, ":other_lord", heroes_begin, heroes_end),
  21135. (this_or_next|is_between, ":other_lord", active_npcs_begin, active_npcs_end),
  21136. (troop_slot_eq, ":other_lord", slot_troop_occupation, slto_kingdom_hero),
  21137. #do not scheme regarding dead/exiled lords
  21138. (neg|troop_slot_ge, ":other_lord", slot_troop_occupation, slto_retirement),
  21139. ##diplomacy end+
  21140. (store_faction_of_troop, ":other_lord_faction", ":other_lord"),
  21141. (eq, ":other_lord_faction", "$players_kingdom"),
  21142. (call_script, "script_troop_get_relation_with_troop", ":potential_target", ":other_lord"),
  21143. (lt, reg0, 0),
  21144. (val_add, ":enemies_in_faction", 1),
  21145. (try_end),
  21146.  
  21147. (str_store_troop_name, s4, ":potential_target"),
  21148. (try_begin),
  21149. (ge, "$cheat_mode", 1),
  21150. (assign, reg3, ":enemies_in_faction"),
  21151. (display_message, "@{!}DEBUG -- {s4} has {reg3} rivals"),
  21152. (try_end),
  21153.  
  21154. (this_or_next|ge, ":enemies_in_faction", 3),
  21155. (ge, "$cheat_mode", 1),
  21156.  
  21157. (assign, ":score_to_beat", ":relation_with_giver_troop"),
  21158. (assign, ":target_lord", ":potential_target"),
  21159. (try_end),
  21160.  
  21161. ##diplomacy start+ support promoted ladies
  21162. #(is_between, ":target_lord", active_npcs_begin, active_npcs_end),
  21163. (is_between, ":target_lord", heroes_begin, heroes_end),
  21164. ##diplomacy end+
  21165.  
  21166. (assign, ":result", "qst_denounce_lord"),
  21167. (assign, ":quest_target_troop", ":target_lord"),
  21168.  
  21169. (else_try),
  21170. (neg|check_quest_active, "qst_intrigue_against_lord"),
  21171. (try_begin),
  21172. (eq, "$cheat_mode", 1),
  21173. (quest_get_slot, reg4, "qst_intrigue_against_lord", slot_quest_dont_give_again_remaining_days),
  21174. (display_message, "@{!}DEBUG -- Checking for intrigue, eligible in {reg4} days"),
  21175. (try_end),
  21176.  
  21177. (neg|quest_slot_ge, "qst_intrigue_against_lord", slot_quest_dont_give_again_remaining_days, 1),
  21178.  
  21179.  
  21180.  
  21181. (neq, ":giver_troop", "$g_player_minister"),
  21182. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, ":giver_troop"),
  21183. (neg|faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  21184.  
  21185. (try_begin),
  21186. (ge, "$cheat_mode", 1),
  21187. (display_message, "@{!}DEBUG -- Trying for intrigue against lord"),
  21188. (try_end),
  21189.  
  21190.  
  21191. (assign, ":target_lord", -1),
  21192. (assign, ":score_to_beat", 10),
  21193.  
  21194. ##diplomacy start+ Support promoted kingdom ladies
  21195. #(try_for_range, ":potential_target", active_npcs_begin, active_npcs_end),
  21196. (try_for_range, ":potential_target", heroes_begin, heroes_end),
  21197. (this_or_next|is_between, ":potential_target", active_npcs_begin, active_npcs_end),
  21198. (troop_slot_eq, ":potential_target", slot_troop_occupation, slto_kingdom_hero),
  21199. #do not scheme regarding dead/exiled lords
  21200. (neg|troop_slot_ge, ":potential_target", slot_troop_occupation, slto_retirement),
  21201. ##diplomacy end+
  21202. (store_faction_of_troop, ":potential_target_faction", ":potential_target"),
  21203. (eq, ":potential_target_faction", "$players_kingdom"),
  21204. (neq, ":potential_target", ":giver_troop"),
  21205. (neg|faction_slot_eq, ":potential_target_faction", slot_faction_leader, ":potential_target"),
  21206.  
  21207.  
  21208. (this_or_next|neg|check_quest_active, "qst_denounce_lord"),
  21209. (neg|quest_slot_eq, "qst_denounce_lord", slot_quest_target_troop, ":potential_target"),
  21210.  
  21211. (faction_get_slot, ":faction_liege", "$players_kingdom", slot_faction_leader),
  21212. (call_script, "script_troop_get_relation_with_troop", ":potential_target", ":faction_liege"),
  21213. (assign, ":relation_with_liege", reg0),
  21214. (lt, ":relation_with_liege", ":score_to_beat"),
  21215.  
  21216. (str_store_troop_name, s4, ":potential_target"),
  21217. (try_begin),
  21218. (ge, "$cheat_mode", 1),
  21219. (display_message, "@{!}DEBUG -- {s4} has sufficiently low relation with liege"),
  21220. (try_end),
  21221.  
  21222.  
  21223. (call_script, "script_troop_get_relation_with_troop", ":potential_target", ":giver_troop"),
  21224. (assign, ":relation_with_giver_troop", reg0),
  21225. (lt, ":relation_with_giver_troop", 0),
  21226.  
  21227. (str_store_troop_name, s4, ":potential_target"),
  21228. (try_begin),
  21229. (ge, "$cheat_mode", 1),
  21230. (display_message, "@{!}DEBUG -- {s4} has sufficiently low relation with giver troop"),
  21231. (try_end),
  21232.  
  21233.  
  21234. (call_script, "script_troop_get_relation_with_troop", ":potential_target", "trp_player"),
  21235. (assign, ":relation_with_player", reg0),
  21236. (lt, ":relation_with_player", 0),
  21237.  
  21238. (str_store_troop_name, s4, ":potential_target"),
  21239. (try_begin),
  21240. (ge, "$cheat_mode", 1),
  21241. (display_message, "@{!}DEBUG -- {s4} has sufficiently low relation with player"),
  21242. (try_end),
  21243.  
  21244. (assign, ":score_to_beat", ":relation_with_liege"),
  21245. (assign, ":target_lord", ":potential_target"),
  21246. (try_end),
  21247.  
  21248. ##diplomacy start+ support promoted ladies
  21249. #(is_between, ":target_lord", active_npcs_begin, active_npcs_end),
  21250. (is_between, ":target_lord", heroes_begin, heroes_end),
  21251. ##diplomacy end+
  21252.  
  21253. (assign, ":result", "qst_intrigue_against_lord"),
  21254. (assign, ":quest_target_troop", ":target_lord"),
  21255.  
  21256.  
  21257. (else_try),
  21258. #Resolve dispute, if there is a good chance of achieving the result
  21259. (try_begin),
  21260. (ge, "$cheat_mode", 1),
  21261. (quest_get_slot, reg4, "qst_resolve_dispute", slot_quest_dont_give_again_remaining_days),
  21262. (display_message, "@{!}DEBUG -- Checking for resolve dispute, eligible in {reg4} days"),
  21263. (try_end),
  21264.  
  21265. (neg|quest_slot_ge, "qst_resolve_dispute", slot_quest_dont_give_again_remaining_days, 1),
  21266.  
  21267.  
  21268. ##diplomacy start+
  21269. #Add additional relative options
  21270. ##(call_script, "script_troop_get_family_relation_to_troop", "trp_player", ":giver_troop"),
  21271. (call_script, "script_dplmc_troop_get_family_relation_to_troop", "trp_player", ":giver_troop"),
  21272. (this_or_next|ge, reg0, 4),
  21273. ##diplomacy end+
  21274. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, "$g_talk_troop"),
  21275. (eq, "$g_talk_troop", "$g_player_minister"),
  21276.  
  21277. (assign, ":target_lord", -1),
  21278. (assign, ":object_lord", -1),
  21279. (assign, ":best_chance_of_success", 20),
  21280.  
  21281. ##diplomacy start+ support promoted ladies
  21282. #(try_for_range, ":lord_1", active_npcs_begin, active_npcs_end),
  21283. (try_for_range, ":lord_1", heroes_begin, heroes_end),
  21284. (this_or_next|is_between, ":lord_1", active_npcs_begin, active_npcs_end),
  21285. (troop_slot_eq, ":lord_1", slot_troop_occupation, slto_kingdom_hero),
  21286. #do not use dead/exiled lords
  21287. (neg|troop_slot_ge, ":lord_1", slot_troop_occupation, slto_retirement),
  21288. ##diplomacy end+
  21289. (store_faction_of_troop, ":lord_1_faction", ":lord_1"),
  21290. (eq, ":lord_1_faction", "$players_kingdom"),
  21291. (neq, ":lord_1", "$g_talk_troop"),
  21292.  
  21293. ##diplomacy start+ support promoted ladies
  21294. #(try_for_range, ":lord_2", active_npcs_begin, active_npcs_end),
  21295. (try_for_range, ":lord_2", heroes_begin, heroes_end),
  21296. (this_or_next|is_between, ":lord_2", active_npcs_begin, active_npcs_end),
  21297. (troop_slot_eq, ":lord_2", slot_troop_occupation, slto_kingdom_hero),
  21298. #do not use dead/exiled lords
  21299. (neg|troop_slot_ge, ":lord_2", slot_troop_occupation, slto_retirement),
  21300. ##diplomacy end+
  21301. (store_faction_of_troop, ":lord_2_faction", ":lord_2"),
  21302. (eq, ":lord_2_faction", "$players_kingdom"),
  21303.  
  21304. (neq, ":lord_1", ":lord_2"),
  21305. (neq, ":lord_2", "$g_talk_troop"),
  21306.  
  21307. (call_script, "script_troop_get_relation_with_troop", ":lord_1", ":lord_2"),
  21308. (assign, ":lord_1_relation_with_lord_2", reg0),
  21309. (lt, ":lord_1_relation_with_lord_2", -5),
  21310.  
  21311. (call_script, "script_troop_get_relation_with_troop", ":lord_1", "trp_player"),
  21312. (assign, ":relation_with_lord_1", reg0),
  21313.  
  21314. (call_script, "script_troop_get_relation_with_troop", ":lord_2", "trp_player"),
  21315. (assign, ":relation_with_lord_2", reg0),
  21316.  
  21317. (gt, ":relation_with_lord_1", 0),
  21318. (gt, ":relation_with_lord_2", 0),
  21319.  
  21320. (store_mul, ":chance_of_success", ":relation_with_lord_1", ":relation_with_lord_2"),
  21321.  
  21322.  
  21323. (gt, ":chance_of_success", ":best_chance_of_success"),
  21324. (assign, ":best_chance_of_success", ":chance_of_success"),
  21325. (assign, ":target_lord", ":lord_1"),
  21326. (assign, ":object_lord", ":lord_2"),
  21327. (try_end),
  21328. (try_end),
  21329.  
  21330. ##diplomacy start+ support promoted ladies
  21331. #(is_between, ":target_lord", active_npcs_begin, active_npcs_end),
  21332. (is_between, ":target_lord", heroes_begin, heroes_end),
  21333. ##diplomacy end+
  21334.  
  21335. (assign, ":result", "qst_resolve_dispute"),
  21336. (assign, ":quest_target_troop", ":target_lord"),
  21337. (assign, ":quest_object_troop", ":object_lord"),
  21338.  
  21339. (else_try),
  21340. (try_begin),
  21341. (ge, "$cheat_mode", 1),
  21342. (quest_get_slot, reg4, "qst_offer_gift", slot_quest_dont_give_again_remaining_days),
  21343. (display_message, "@{!}DEBUG -- Checking for offer gift, eligible in {reg4} days"),
  21344. (try_end),
  21345.  
  21346. ##diplomacy start+ conventional ladies have a quicker "reset" time on this quest
  21347. (neg|quest_slot_ge, "qst_offer_gift", slot_quest_dont_give_again_remaining_days, 4),
  21348. (this_or_next|troop_slot_eq, ":giver_troop", slot_lord_reputation_type, lrep_conventional),
  21349. ##diplomacy end+
  21350. (neg|quest_slot_ge, "qst_offer_gift", slot_quest_dont_give_again_remaining_days, 1),
  21351.  
  21352. (assign, ":relative_found", -1),
  21353. (assign, ":score_to_beat", 5),
  21354. ##diplomacy start+
  21355. #Slightly expand the range of potential targets if changes are enabled
  21356. (try_begin),
  21357. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  21358. (assign, ":score_to_beat", 4),
  21359. (troop_slot_eq, ":giver_troop", slot_lord_reputation_type, lrep_conventional),
  21360. (assign, ":score_to_beat", 3),
  21361. (try_end),
  21362. ##diplomacy end+
  21363.  
  21364. ##diplomacy start+
  21365. #(try_for_range, ":potential_relative", active_npcs_begin, active_npcs_end),
  21366. #Add support for promoted ladies (TODO: add a variant for ordinary ladies as well)
  21367. (try_for_range, ":potential_relative", heroes_begin, heroes_end),
  21368. #do not use dead/exiled lords
  21369. (this_or_next|is_between, ":potential_relative", active_npcs_begin, active_npcs_end),
  21370. (troop_slot_eq, ":potential_relative", slot_troop_occupation, slto_kingdom_hero),
  21371. (neg|troop_slot_ge, ":potential_relative", slot_troop_occupation, slto_retirement),
  21372. ##diplomacy end+
  21373. (store_faction_of_troop, ":relative_faction", ":potential_relative"),
  21374. (eq, ":relative_faction", "$players_kingdom"),
  21375. (neq, ":potential_relative", ":giver_troop"),
  21376. (neg|faction_slot_eq, ":relative_faction", slot_faction_leader, ":potential_relative"),
  21377.  
  21378. (call_script, "script_troop_get_family_relation_to_troop", ":giver_troop", ":potential_relative"),
  21379. (assign, ":family_relation", reg0),
  21380. (ge, ":family_relation", ":score_to_beat"),
  21381.  
  21382. (store_sub, ":min_relation_w_player", 0, ":family_relation"),
  21383.  
  21384. (call_script, "script_troop_get_relation_with_troop", "trp_player", ":potential_relative"),
  21385. (assign, ":relation_with_player", reg0),
  21386. (is_between, ":relation_with_player", ":min_relation_w_player", 0),
  21387.  
  21388. (assign, ":score_to_beat", ":family_relation"),
  21389. (assign, ":relative_found", ":potential_relative"),
  21390.  
  21391. (try_end),
  21392.  
  21393. (is_between, ":relative_found", active_npcs_begin, active_npcs_end),
  21394.  
  21395. (assign, ":result", "qst_offer_gift"),
  21396. (assign, ":quest_target_troop", ":relative_found"),
  21397. (try_end),
  21398.  
  21399.  
  21400. (try_begin),
  21401. (gt, ":result", -1),
  21402. (quest_set_slot, ":result", slot_quest_target_troop, ":quest_target_troop"),
  21403. (quest_set_slot, ":result", slot_quest_target_troop, ":quest_object_troop"),
  21404.  
  21405. (quest_set_slot, ":result", slot_quest_giver_troop, ":giver_troop"),
  21406. (quest_set_slot, ":result", slot_quest_dont_give_again_period, ":quest_dont_give_again_period"),
  21407. (try_end),
  21408.  
  21409. (assign, reg0, ":result"),
  21410. (assign, reg1, ":quest_target_troop"),
  21411. (assign, reg2, ":quest_object_troop"),
  21412.  
  21413. ]),
  21414.  
  21415.  
  21416. ("npc_find_quest_for_player_to_s11",
  21417. [
  21418. (store_script_param, ":faction", 1),
  21419.  
  21420. (assign, ":quest_giver_found", -1),
  21421. (try_for_range, ":quest_giver", active_npcs_begin, mayors_end),
  21422. (eq, ":quest_giver_found", -1),
  21423.  
  21424. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, ":quest_giver"),
  21425.  
  21426. (gt, ":quest_giver", "$g_troop_list_no"),
  21427.  
  21428. (assign, "$g_troop_list_no", ":quest_giver"),
  21429.  
  21430. (this_or_next|troop_slot_eq, ":quest_giver", slot_troop_occupation, slto_kingdom_hero),
  21431. (is_between, ":quest_giver", mayors_begin, mayors_end),
  21432.  
  21433. (neg|troop_slot_ge, ":quest_giver", slot_troop_prisoner_of_party, centers_begin),
  21434.  
  21435. (try_begin),
  21436. (is_between, ":quest_giver", mayors_begin, mayors_end),
  21437. (assign, ":quest_giver_faction", -1),
  21438. (try_for_range,":town", towns_begin, towns_end),
  21439. (party_slot_eq, ":town", slot_town_elder, ":quest_giver"),
  21440. (store_faction_of_party, ":quest_giver_faction", ":town"),
  21441. (try_end),
  21442. (else_try),
  21443. (store_faction_of_troop, ":quest_giver_faction", ":quest_giver"),
  21444. (try_end),
  21445. (eq, ":faction", ":quest_giver_faction"),
  21446.  
  21447. (call_script, "script_get_dynamic_quest", ":quest_giver"),
  21448. (gt, reg0, -1),
  21449.  
  21450. (assign, ":quest_giver_found", ":quest_giver"),
  21451. (try_begin),
  21452. (eq, "$cheat_mode", 1),
  21453. (str_store_troop_name, s4, ":quest_giver_found"),
  21454. (display_message, "str_test_diagnostic_quest_found_for_s4"),
  21455. (try_end),
  21456.  
  21457. (try_end),
  21458.  
  21459. (assign, reg0, ":quest_giver_found"),
  21460.  
  21461. ]),
  21462.  
  21463.  
  21464.  
  21465. # script_cf_get_random_enemy_center_within_range
  21466. # Input: arg1 = party_no, arg2 = range (in kms)
  21467. # Output: reg0 = center_no
  21468. ("cf_get_random_enemy_center_within_range",
  21469. [
  21470. (store_script_param, ":party_no", 1),
  21471. (store_script_param, ":range", 2),
  21472.  
  21473. (assign, ":num_centers", 0),
  21474. (store_faction_of_party, ":faction_no", ":party_no"),
  21475. (try_for_range, ":cur_center", centers_begin, centers_end),
  21476. (store_faction_of_party, ":cur_faction", ":cur_center"),
  21477. (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
  21478. (lt, ":cur_relation", 0),
  21479. (store_distance_to_party_from_party, ":dist", ":party_no", ":cur_center"),
  21480. (le, ":dist", ":range"),
  21481. (val_add, ":num_centers", 1),
  21482. (try_end),
  21483. (gt, ":num_centers", 0),
  21484. (store_random_in_range, ":random_center", 0, ":num_centers"),
  21485. (assign, ":end_cond", centers_end),
  21486. (try_for_range, ":cur_center", centers_begin, ":end_cond"),
  21487. (store_faction_of_party, ":cur_faction", ":cur_center"),
  21488. (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
  21489. (lt, ":cur_relation", 0),
  21490. (store_distance_to_party_from_party, ":dist", ":party_no", ":cur_center"),
  21491. (le, ":dist", ":range"),
  21492. (val_sub, ":random_center", 1),
  21493. (lt, ":random_center", 0),
  21494. (assign, ":result", ":cur_center"),
  21495. (assign, ":end_cond", 0),#break
  21496. (try_end),
  21497. (assign, reg0, ":result"),
  21498. ]),
  21499.  
  21500. # script_cf_faction_get_random_enemy_faction
  21501. # Input: arg1 = faction_no
  21502. # Output: reg0 = faction_no (Can fail)
  21503. ("cf_faction_get_random_enemy_faction",
  21504. [
  21505. (store_script_param_1, ":faction_no"),
  21506.  
  21507. (assign, ":result", -1),
  21508. (assign, ":count_factions", 0),
  21509. (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  21510. (faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
  21511. (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
  21512. (le, ":cur_relation", -1),
  21513. (val_add, ":count_factions", 1),
  21514. (try_end),
  21515. (store_random_in_range,":random_faction",0,":count_factions"),
  21516. (assign, ":count_factions", 0),
  21517. (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  21518. (eq, ":result", -1),
  21519. (faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
  21520. (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
  21521. (le, ":cur_relation", -1),
  21522. (val_add, ":count_factions", 1),
  21523. (gt, ":count_factions", ":random_faction"),
  21524. (assign, ":result", ":cur_faction"),
  21525. (try_end),
  21526.  
  21527. (neq, ":result", -1),
  21528. (assign, reg0, ":result"),
  21529. ]),
  21530.  
  21531. # script_cf_faction_get_random_friendly_faction
  21532. # Input: arg1 = faction_no
  21533. # Output: reg0 = faction_no (Can fail)
  21534. ("cf_faction_get_random_friendly_faction",
  21535. [
  21536. (store_script_param_1, ":faction_no"),
  21537.  
  21538. (assign, ":result", -1),
  21539. (assign, ":count_factions", 0),
  21540. (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  21541. (faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
  21542. (neq, ":cur_faction", ":faction_no"),
  21543. (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
  21544. (ge, ":cur_relation", 0),
  21545. (val_add, ":count_factions", 1),
  21546. (try_end),
  21547. (store_random_in_range,":random_faction",0,":count_factions"),
  21548. (assign, ":count_factions", 0),
  21549. (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  21550. (eq, ":result", -1),
  21551. (faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
  21552. (neq, ":cur_faction", ":faction_no"),
  21553. (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
  21554. (ge, ":cur_relation", 0),
  21555. (val_add, ":count_factions", 1),
  21556. (gt, ":count_factions", ":random_faction"),
  21557. (assign, ":result", ":cur_faction"),
  21558. (try_end),
  21559.  
  21560. (neq, ":result", -1),
  21561. (assign, reg0, ":result"),
  21562. ]),
  21563.  
  21564. # script_cf_troop_get_random_enemy_troop_with_occupation
  21565. # Input: arg1 = troop_no,
  21566. # Output: reg0 = enemy_troop_no (Can fail)
  21567. ("cf_troop_get_random_enemy_troop_with_occupation",
  21568. [
  21569. (store_script_param_1, ":troop_no"),
  21570. (store_script_param_2, ":occupation"),
  21571.  
  21572. (assign, ":result", -1),
  21573. (assign, ":count_enemies", 0),
  21574. (try_for_range, ":enemy_troop_no", active_npcs_begin, active_npcs_end),
  21575. (troop_slot_eq, ":enemy_troop_no", slot_troop_occupation, ":occupation"),
  21576. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":enemy_troop_no"),
  21577. (lt, reg0, -10),
  21578. (val_add, ":count_enemies", 1),
  21579. (try_end),
  21580.  
  21581. (gt, ":count_enemies", 0),
  21582. (store_random_in_range,":random_enemy",0,":count_enemies"),
  21583.  
  21584. (assign, ":count_enemies", 0),
  21585. (try_for_range, ":enemy_troop_no", active_npcs_begin, active_npcs_end),
  21586. (troop_slot_eq, ":enemy_troop_no", slot_troop_occupation, ":occupation"),
  21587. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":enemy_troop_no"),
  21588. (lt, reg0, -10),
  21589. (val_add, ":count_enemies", 1),
  21590. (eq, ":random_enemy", ":count_enemies"),
  21591. (assign, ":result", ":enemy_troop_no"),
  21592. (try_end),
  21593.  
  21594. (neq, ":result", -1),
  21595. (assign, reg0, ":result"),
  21596. ]),
  21597.  
  21598.  
  21599. ## # script_cf_troop_get_random_enemy_troop_as_a_town_lord
  21600. ## # Input: arg1 = troop_no
  21601. ## # Output: reg0 = enemy_troop_no (Can fail)
  21602. ## ("cf_troop_get_random_enemy_troop_as_a_town_lord",
  21603. ## [
  21604. ## (store_script_param_1, ":troop_no"),
  21605. ##
  21606. ## (assign, ":result", -1),
  21607. ## (assign, ":count_enemies", 0),
  21608. ## (try_for_range, ":cur_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
  21609. ## (troop_get_slot, ":cur_enemy", ":troop_no", ":cur_slot"),
  21610. ## (gt, ":cur_enemy", 0),
  21611. ## (troop_slot_eq, ":cur_enemy", slot_troop_occupation, slto_kingdom_hero),
  21612. ## (call_script, "script_get_number_of_hero_centers", ":cur_enemy"),
  21613. ## (gt, reg0, 0),
  21614. ## (val_add, ":count_enemies", 1),
  21615. ## (try_end),
  21616. ## (store_random_in_range,":random_enemy",0,":count_enemies"),
  21617. ## (assign, ":count_enemies", 0),
  21618. ## (try_for_range, ":cur_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
  21619. ## (eq, ":result", -1),
  21620. ## (troop_get_slot, ":cur_enemy", ":troop_no", ":cur_slot"),
  21621. ## (gt, ":cur_enemy", 0),
  21622. ## (troop_slot_eq, ":cur_enemy", slot_troop_occupation, slto_kingdom_hero),
  21623. ## (call_script, "script_get_number_of_hero_centers", ":cur_enemy"),
  21624. ## (gt, reg0, 0),
  21625. ## (val_add, ":count_enemies", 1),
  21626. ## (gt, ":count_enemies", ":random_enemy"),
  21627. ## (assign, ":result", ":cur_enemy"),
  21628. ## (try_end),
  21629. ## (neq, ":result", -1),
  21630. ## (assign, reg0, ":result"),
  21631. ## ]),
  21632.  
  21633.  
  21634. ## # script_cf_get_random_enemy_with_valid_slot
  21635. ## # Input: arg1 = faction_no, arg2 = slot_no
  21636. ## # Output: reg0 = faction_no (Can fail)
  21637. ## ("cf_get_random_enemy_with_valid_slot",
  21638. ## [
  21639. ## (store_script_param_1, ":faction_no"),
  21640. ## (store_script_param_2, ":slot_no"),
  21641. ##
  21642. ## (assign, ":result", -1),
  21643. ## (assign, ":count_factions", 0),
  21644. ## (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  21645. ## (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
  21646. ## (le, ":cur_relation", -10),
  21647. ## (faction_get_slot, ":cur_value", ":cur_faction", ":slot_no"),
  21648. ## (gt, ":cur_value", 0),#Checking validity
  21649. ## (val_add, ":count_factions", 1),
  21650. ## (try_end),
  21651. ## (store_random_in_range,":random_faction",0,":count_factions"),
  21652. ## (assign, ":count_factions", 0),
  21653. ## (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  21654. ## (eq, ":result", -1),
  21655. ## (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
  21656. ## (le, ":cur_relation", -10),
  21657. ## (faction_get_slot, ":cur_value", ":cur_faction", ":slot_no"),
  21658. ## (gt, ":cur_value", 0),#Checking validity
  21659. ## (val_add, ":count_factions", 1),
  21660. ## (gt, ":count_factions", ":random_faction"),
  21661. ## (assign, ":result", ":cur_faction"),
  21662. ## (try_end),
  21663. ##
  21664. ## (neq, ":result", -1),
  21665. ## (assign, reg0, ":result"),
  21666. ## ]),
  21667.  
  21668.  
  21669. ## # script_cf_get_random_kingdom_hero
  21670. ## # Input: arg1 = faction_no
  21671. ## # Output: reg0 = troop_no (Can fail)
  21672. ## ("cf_get_random_kingdom_hero",
  21673. ## [
  21674. ## (store_script_param_1, ":faction_no"),
  21675. ## (assign, ":count_heroes", 0),
  21676. ## (try_for_range, ":center_no", centers_begin, centers_end),
  21677. ## (store_faction_of_party, ":cur_faction", ":center_no"),
  21678. ## (eq, ":cur_faction", ":faction_no"),
  21679. ## (party_get_slot, ":cur_lord", ":center_no", slot_town_lord),
  21680. ## (is_between, ":cur_lord", heroes_begin, heroes_end),
  21681. ## (val_add, ":count_heroes", 1),
  21682. ## (try_end),
  21683. ## (store_random_in_range, ":random_hero", 0, ":count_heroes"),
  21684. ## (assign, ":result", -1),
  21685. ## (assign, ":count_heroes", 0),
  21686. ## (try_for_range, ":center_no", centers_begin, centers_end),
  21687. ## (eq, ":result", -1),
  21688. ## (store_faction_of_party, ":cur_faction", ":center_no"),
  21689. ## (eq, ":cur_faction", ":faction_no"),
  21690. ## (party_get_slot, ":cur_lord", ":center_no", slot_town_lord),
  21691. ## (is_between, ":cur_lord", heroes_begin, heroes_end),
  21692. ## (val_add, ":count_heroes", 1),
  21693. ## (lt, ":random_hero", ":count_heroes"),
  21694. ## (assign, ":result", ":cur_lord"),
  21695. ## (try_end),
  21696. ## (neq, ":result", -1),
  21697. ## (assign, reg0, ":result"),
  21698. ## ]),
  21699.  
  21700.  
  21701. # script_cf_get_random_kingdom_hero_as_lover - removed
  21702.  
  21703.  
  21704.  
  21705. ## # script_cf_get_random_siege_location_with_faction
  21706. ## # Input: arg1 = faction_no
  21707. ## # Output: reg0 = center_no, Can Fail!
  21708. ## ("cf_get_random_siege_location_with_faction",
  21709. ## [
  21710. ## (store_script_param_1, ":faction_no"),
  21711. ## (assign, ":result", -1),
  21712. ## (assign, ":count_sieges", 0),
  21713. ## (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  21714. ## (party_get_battle_opponent, ":besieger_party", ":center_no"),
  21715. ## (gt, ":besieger_party", 0),
  21716. ## (store_faction_of_party, ":cur_faction_no", ":center_no"),
  21717. ## (eq, ":cur_faction_no", ":faction_no"),
  21718. ## (val_add, ":count_sieges", 1),
  21719. ## (try_end),
  21720. ## (store_random_in_range,":random_center",0,":count_sieges"),
  21721. ## (assign, ":count_sieges", 0),
  21722. ## (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  21723. ## (eq, ":result", -1),
  21724. ## (party_get_battle_opponent, ":besieger_party", ":center_no"),
  21725. ## (gt, ":besieger_party", 0),
  21726. ## (store_faction_of_party, ":cur_faction_no", ":center_no"),
  21727. ## (eq, ":cur_faction_no", ":faction_no"),
  21728. ## (val_add, ":count_sieges", 1),
  21729. ## (gt, ":count_sieges", ":random_center"),
  21730. ## (assign, ":result", ":center_no"),
  21731. ## (try_end),
  21732. ## (neq, ":result", -1),
  21733. ## (assign, reg0, ":result"),
  21734. ## ]),
  21735.  
  21736. ## # script_cf_get_random_siege_location_with_attacker_faction
  21737. ## # Input: arg1 = faction_no
  21738. ## # Output: reg0 = center_no, Can Fail!
  21739. ## ("cf_get_random_siege_location_with_attacker_faction",
  21740. ## [
  21741. ## (store_script_param_1, ":faction_no"),
  21742. ## (assign, ":result", -1),
  21743. ## (assign, ":count_sieges", 0),
  21744. ## (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  21745. ## (party_get_battle_opponent, ":besieger_party", ":center_no"),
  21746. ## (gt, ":besieger_party", 0),
  21747. ## (store_faction_of_party, ":cur_faction_no", ":besieger_party"),
  21748. ## (eq, ":cur_faction_no", ":faction_no"),
  21749. ## (val_add, ":count_sieges", 1),
  21750. ## (try_end),
  21751. ## (store_random_in_range,":random_center",0,":count_sieges"),
  21752. ## (assign, ":count_sieges", 0),
  21753. ## (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  21754. ## (eq, ":result", -1),
  21755. ## (party_get_battle_opponent, ":besieger_party", ":center_no"),
  21756. ## (gt, ":besieger_party", 0),
  21757. ## (store_faction_of_party, ":cur_faction_no", ":besieger_party"),
  21758. ## (eq, ":cur_faction_no", ":faction_no"),
  21759. ## (val_add, ":count_sieges", 1),
  21760. ## (gt, ":count_sieges", ":random_center"),
  21761. ## (assign, ":result", ":center_no"),
  21762. ## (try_end),
  21763. ## (neq, ":result", -1),
  21764. ## (assign, reg0, ":result"),
  21765. ## ]),
  21766.  
  21767.  
  21768.  
  21769. ## # script_cf_get_number_of_random_troops_from_party
  21770. ## # Input: arg1 = party_no, arg2 = number of troops to remove
  21771. ## # Output: reg0 = troop_no, Can fail if there are no slots having the required number of units!
  21772. ## ("cf_get_number_of_random_troops_from_party",
  21773. ## [
  21774. ## (store_script_param_1, ":party_no"),
  21775. ## (store_script_param_2, ":no_to_remove"),
  21776. ##
  21777. ## (assign, ":result", -1),
  21778. ## (assign, ":count_stacks", 0),
  21779. ##
  21780. ## (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  21781. ## (try_for_range, ":i_stack", 0, ":num_stacks"),
  21782. ## (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  21783. ## (party_stack_get_num_wounded, ":num_wounded",":party_no",":i_stack"),
  21784. ## (val_sub, ":stack_size", ":num_wounded"),
  21785. ## (ge, ":stack_size", ":no_to_remove"),
  21786. ## (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  21787. ## (neg|troop_is_hero, ":stack_troop"),
  21788. ## (val_add, ":count_stacks", 1),
  21789. ## (try_end),
  21790. ## (store_random_in_range,":random_stack",0,":count_stacks"),
  21791. ## (assign, ":count_stacks", 0),
  21792. ## (try_for_range, ":i_stack", 0, ":num_stacks"),
  21793. ## (eq, ":result", -1),
  21794. ## (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  21795. ## (party_stack_get_num_wounded, ":num_wounded",":party_no",":i_stack"),
  21796. ## (val_sub, ":stack_size", ":num_wounded"),
  21797. ## (ge, ":stack_size", ":no_to_remove"),
  21798. ## (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  21799. ## (neg|troop_is_hero, ":stack_troop"),
  21800. ## (val_add, ":count_stacks", 1),
  21801. ## (gt, ":count_stacks", ":random_stack"),
  21802. ## (assign, ":result", ":stack_troop"),
  21803. ## (try_end),
  21804. ##
  21805. ## (neq, ":result", -1),
  21806. ## (assign, reg0, ":result"),
  21807. ## ]),
  21808.  
  21809.  
  21810.  
  21811.  
  21812. # script_cf_get_random_lord_in_a_center_with_faction
  21813. # Input: arg1 = faction_no
  21814. # Output: reg0 = troop_no, Can Fail!
  21815. ("cf_get_random_lord_in_a_center_with_faction",
  21816. [
  21817. (store_script_param_1, ":faction_no"),
  21818. (assign, ":result", -1),
  21819. (assign, ":count_lords", 0),
  21820. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  21821. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  21822. (eq, ":faction_no", ":lord_faction_no"),
  21823. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  21824. #(troop_slot_eq, ":lord_no", slot_troop_is_prisoner, 0),
  21825. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  21826. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  21827. (ge, ":lord_party", 0),
  21828. (party_get_attached_to, ":lord_attachment", ":lord_party"),
  21829. (is_between, ":lord_attachment", centers_begin, centers_end), #is troop in a center?
  21830. (val_add, ":count_lords", 1),
  21831. (try_end),
  21832. (store_random_in_range, ":random_lord", 0, ":count_lords"),
  21833. (assign, ":count_lords", 0),
  21834. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  21835. (eq, ":result", -1),
  21836. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  21837. (eq, ":faction_no", ":lord_faction_no"),
  21838. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  21839. #(troop_slot_eq, ":lord_no", slot_troop_is_prisoner, 0),
  21840. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  21841. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  21842. (ge, ":lord_party", 0),
  21843. (party_get_attached_to, ":lord_attachment", ":lord_party"),
  21844. (is_between, ":lord_attachment", centers_begin, centers_end), #is troop in a center?
  21845. (val_add, ":count_lords", 1),
  21846. (lt, ":random_lord", ":count_lords"),
  21847. (assign, ":result", ":lord_no"),
  21848. (try_end),
  21849. (neq, ":result", -1),
  21850. (assign, reg0, ":result"),
  21851. ]),
  21852.  
  21853. # script_cf_get_random_lord_except_king_with_faction
  21854. # Input: arg1 = faction_no
  21855. # Output: reg0 = troop_no, Can Fail!
  21856. ("cf_get_random_lord_except_king_with_faction",
  21857. [
  21858. (store_script_param_1, ":faction_no"),
  21859. (assign, ":result", -1),
  21860. (assign, ":count_lords", 0),
  21861. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  21862. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  21863. (eq, ":faction_no", ":lord_faction_no"),
  21864. (neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":lord_no"),
  21865. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  21866. #(troop_slot_eq, ":lord_no", slot_troop_is_prisoner, 0),
  21867. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  21868. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  21869. (ge, ":lord_party", 0),
  21870. (val_add, ":count_lords", 1),
  21871. (try_end),
  21872. (store_random_in_range, ":random_lord", 0, ":count_lords"),
  21873. (assign, ":count_lords", 0),
  21874. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  21875. (eq, ":result", -1),
  21876. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  21877. (eq, ":faction_no", ":lord_faction_no"),
  21878. (neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":lord_no"),
  21879. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  21880. #(troop_slot_eq, ":lord_no", slot_troop_is_prisoner, 0),
  21881. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  21882. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  21883. (ge, ":lord_party", 0),
  21884. (val_add, ":count_lords", 1),
  21885. (lt, ":random_lord", ":count_lords"),
  21886. (assign, ":result", ":lord_no"),
  21887. (try_end),
  21888. (neq, ":result", -1),
  21889. (assign, reg0, ":result"),
  21890. ]),
  21891.  
  21892.  
  21893. # script_cf_get_random_lord_from_another_faction_in_a_center
  21894. # Input: arg1 = faction_no
  21895. # Output: reg0 = troop_no, Can Fail!
  21896. ("cf_get_random_lord_from_another_faction_in_a_center",
  21897. [
  21898. (store_script_param_1, ":faction_no"),
  21899. (assign, ":result", -1),
  21900. (assign, ":count_lords", 0),
  21901. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  21902. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  21903. (neq, ":lord_faction_no", ":faction_no"),
  21904. (store_relation, ":our_relation", ":lord_faction_no", "fac_player_supporters_faction"),
  21905. (store_relation, ":lord_relation", ":lord_faction_no", ":faction_no"),
  21906. (lt, ":lord_relation", 0),
  21907. (ge, ":our_relation", 0),
  21908. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  21909. #(troop_slot_eq, ":lord_no", slot_troop_is_prisoner, 0),
  21910. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  21911. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  21912. (ge, ":lord_party", 0),
  21913. (party_get_attached_to, ":lord_attachment", ":lord_party"),
  21914. (is_between, ":lord_attachment", centers_begin, centers_end), #is troop in a center?
  21915. (val_add, ":count_lords", 1),
  21916. (try_end),
  21917. (store_random_in_range, ":random_lord", 0, ":count_lords"),
  21918. (assign, ":count_lords", 0),
  21919. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  21920. (eq, ":result", -1),
  21921. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  21922. (neq, ":lord_faction_no", ":faction_no"),
  21923. (store_relation, ":our_relation", ":lord_faction_no", "fac_player_supporters_faction"),
  21924. (store_relation, ":lord_relation", ":lord_faction_no", ":faction_no"),
  21925. (lt, ":lord_relation", 0),
  21926. (ge, ":our_relation", 0),
  21927. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  21928. #(troop_slot_eq, ":lord_no", slot_troop_is_prisoner, 0),
  21929. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  21930. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  21931. (ge, ":lord_party", 0),
  21932. (party_get_attached_to, ":lord_attachment", ":lord_party"),
  21933. (is_between, ":lord_attachment", centers_begin, centers_end), #is troop in a center?
  21934. (val_add, ":count_lords", 1),
  21935. (lt, ":random_lord", ":count_lords"),
  21936. (assign, ":result", ":lord_no"),
  21937. (try_end),
  21938. (neq, ":result", -1),
  21939. (assign, reg0, ":result"),
  21940. ]),
  21941.  
  21942. # script_get_closest_walled_center
  21943. # Input: arg1 = party_no
  21944. # Output: reg0 = center_no (closest)
  21945. ("get_closest_walled_center",
  21946. [
  21947. (store_script_param_1, ":party_no"),
  21948. (assign, ":min_distance", 9999999),
  21949. (assign, reg0, -1),
  21950. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  21951. (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
  21952. (lt, ":party_distance", ":min_distance"),
  21953. (assign, ":min_distance", ":party_distance"),
  21954. (assign, reg0, ":center_no"),
  21955. (try_end),
  21956. ]),
  21957.  
  21958. # script_get_closest_center
  21959. # Input: arg1 = party_no
  21960. # Output: reg0 = center_no (closest)
  21961. ("get_closest_center",
  21962. [
  21963. (store_script_param_1, ":party_no"),
  21964. (assign, ":min_distance", 9999999),
  21965. (assign, reg0, -1),
  21966. (try_for_range, ":center_no", centers_begin, centers_end),
  21967. (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
  21968. (lt, ":party_distance", ":min_distance"),
  21969. (assign, ":min_distance", ":party_distance"),
  21970. (assign, reg0, ":center_no"),
  21971. (try_end),
  21972. ]),
  21973.  
  21974.  
  21975. # script_get_closest_center_of_faction
  21976. # Input: arg1 = party_no, arg2 = kingdom_no
  21977. # Output: reg0 = center_no (closest)
  21978. ("get_closest_center_of_faction",
  21979. [
  21980. (store_script_param_1, ":party_no"),
  21981. (store_script_param_2, ":kingdom_no"),
  21982. (assign, ":min_distance", 99999),
  21983. (assign, ":result", -1),
  21984. (try_for_range, ":center_no", centers_begin, centers_end),
  21985. (store_faction_of_party, ":faction_no", ":center_no"),
  21986. (eq, ":faction_no", ":kingdom_no"),
  21987. (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
  21988. (lt, ":party_distance", ":min_distance"),
  21989. (assign, ":min_distance", ":party_distance"),
  21990. (assign, ":result", ":center_no"),
  21991. (try_end),
  21992. (assign, reg0, ":result"),
  21993. ]),
  21994.  
  21995. # script_get_closest_walled_center_of_faction
  21996. # Input: arg1 = party_no, arg2 = kingdom_no
  21997. # Output: reg0 = center_no (closest)
  21998. ("get_closest_walled_center_of_faction",
  21999. [
  22000. (store_script_param_1, ":party_no"),
  22001. (store_script_param_2, ":kingdom_no"),
  22002. (assign, ":min_distance", 99999),
  22003. (assign, ":result", -1),
  22004. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  22005. (store_faction_of_party, ":faction_no", ":center_no"),
  22006. (eq, ":faction_no", ":kingdom_no"),
  22007. (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
  22008. (lt, ":party_distance", ":min_distance"),
  22009. (assign, ":min_distance", ":party_distance"),
  22010. (assign, ":result", ":center_no"),
  22011. (try_end),
  22012. (assign, reg0, ":result"),
  22013. ]),
  22014.  
  22015.  
  22016. ## # script_get_closest_town_of_faction
  22017. ## # Input: arg1 = party_no, arg2 = kingdom_no
  22018. ## # Output: reg0 = center_no (closest)
  22019. ## ("get_closest_town_of_faction",
  22020. ## [
  22021. ## (store_script_param_1, ":party_no"),
  22022. ## (store_script_param_2, ":kingdom_no"),
  22023. ## (assign, ":min_distance", 9999999),
  22024. ## (assign, ":result", -1),
  22025. ## (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  22026. ## (store_faction_of_party, ":faction_no", ":center_no"),
  22027. ## (eq, ":faction_no", ":kingdom_no"),
  22028. ## (party_slot_eq, ":center_no", slot_party_type, spt_town),
  22029. ## (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
  22030. ## (lt, ":party_distance", ":min_distance"),
  22031. ## (assign, ":min_distance", ":party_distance"),
  22032. ## (assign, ":result", ":center_no"),
  22033. ## (try_end),
  22034. ## (assign, reg0, ":result"),
  22035. ## ]),
  22036.  
  22037.  
  22038. # script_let_nearby_parties_join_current_battle
  22039. # Input: arg1 = besiege_mode, arg2 = dont_add_friends_other_than_accompanying
  22040. # Output: none
  22041. ("let_nearby_parties_join_current_battle",
  22042. [
  22043. (store_script_param, ":besiege_mode", 1),
  22044. (store_script_param, ":dont_add_friends_other_than_accompanying", 2),
  22045.  
  22046. (store_character_level, ":player_level", "trp_player"),
  22047. (try_for_parties, ":party_no"),
  22048. (party_is_active, ":party_no"),
  22049. (party_get_battle_opponent, ":opponent",":party_no"),
  22050. (lt, ":opponent", 0), #party is not itself involved in a battle
  22051. (party_get_attached_to, ":attached_to",":party_no"),
  22052. (lt, ":attached_to", 0), #party is not attached to another party
  22053. (get_party_ai_behavior, ":behavior", ":party_no"),
  22054. (neq, ":behavior", ai_bhvr_in_town),
  22055.  
  22056. (party_stack_get_troop_id, ":stack_troop", ":party_no", 0),
  22057. (party_get_template_id,":template_id",":party_no"),
  22058. #SB : exclude certain templates, quest, prisoners/routed troops
  22059. (neq, ":template_id", "pt_troublesome_bandits"),
  22060. (neq, ":template_id", "pt_bandits_awaiting_ransom"),
  22061. (neq, ":template_id", "pt_rescued_prisoners"),
  22062. (neq, ":template_id", "pt_routed_warriors"),
  22063.  
  22064. (try_begin),
  22065. (this_or_next|is_between, ":stack_troop", "trp_looter", bandits_end),
  22066. (is_between, ":template_id", bandit_party_templates_begin, bandit_party_templates_end), #SB : template range
  22067. (assign, ":is_bandit", 1),
  22068. (else_try),
  22069. (assign, ":is_bandit", 0),
  22070. (try_end),
  22071. (game_get_reduce_campaign_ai, ":join_sub"), #easier = smaller distance bandits
  22072. (try_begin),#Native behaviour
  22073. (eq, "$g_dplmc_terrain_advantage", DPLMC_TERRAIN_ADVANTAGE_DISABLE),
  22074. (try_begin),
  22075. (eq, ":is_bandit", 1),
  22076. (assign, ":join_distance", 5), #day/not bandit
  22077. (try_begin),
  22078. (is_currently_night),
  22079. (assign, ":join_distance", 3), #nigh/not bandit
  22080. (try_end),
  22081. (else_try),
  22082. (assign, ":join_distance", 3), #day/bandit
  22083. (try_begin),
  22084. (is_currently_night),
  22085. (assign, ":join_distance", 2), #night/bandit
  22086. (try_end),
  22087. (try_end),
  22088. (else_try), #SB : new distance calculation, based on spotting
  22089. (party_get_skill_level, ":join_distance", ":party_no", "skl_spotting"), #Native lords have none
  22090. (val_div, ":join_distance", 3),
  22091. (val_add, ":join_distance", 4), #from 4 to 7
  22092. (try_begin), #global night deduction
  22093. (is_currently_night),
  22094. (val_sub, ":join_distance", 2), #night/not bandit
  22095. (try_end),
  22096. (try_begin),
  22097. (eq, ":is_bandit", 1),
  22098. (val_sub, ":join_distance", 1), #day/bandit, value of 3
  22099. (val_sub, ":join_distance", ":join_sub"), #can reduce it down to 1 on easy mode
  22100. (is_currently_night), #night/bandit
  22101. (val_add, ":join_distance", 1), #less sharp penalty, value of 2
  22102. (try_end),
  22103. #booster to patrols etc. that makes up for new base of 4
  22104. (try_begin),
  22105. (eq, ":template_id", "pt_patrol_party"),
  22106. (val_add, ":join_distance", 1), #always true
  22107. (try_begin),
  22108. (get_party_ai_object, ":obj", ":party_no"),#just in case
  22109. (eq, ":behavior", ai_bhvr_escort_party),
  22110. (eq, ":obj", "p_main_party"),
  22111. (val_add, ":join_distance", ":join_sub"),#they stray off easily
  22112. (try_end),
  22113. # (else_try), #other behaviour score
  22114. # (eq, ":behavior", ai_bhvr_avoid_party), #fleeing
  22115. # (val_sub, ":join_distance", 1),
  22116. (else_try), #representing preparedness to join battle
  22117. (this_or_next|eq, ":behavior", ai_bhvr_patrol_party),
  22118. (this_or_next|eq, ":behavior", ai_bhvr_patrol_location),
  22119. (eq, ":behavior", ai_bhvr_escort_party),
  22120. (val_add, ":join_distance", 1),
  22121. (try_end),
  22122. (try_end),
  22123.  
  22124.  
  22125. # #Quest bandits do not join battle
  22126. # (this_or_next|neg|check_quest_active, "qst_track_down_bandits"),
  22127. # (neg|quest_slot_eq, "qst_track_down_bandits", slot_quest_target_party, ":party_no"),
  22128. # (this_or_next|neg|check_quest_active, "qst_troublesome_bandits"),
  22129. # (neg|quest_slot_eq, "qst_troublesome_bandits", slot_quest_target_party, ":party_no"),
  22130.  
  22131.  
  22132.  
  22133. (store_distance_to_party_from_party, ":distance", ":party_no", "p_main_party"),
  22134. (lt, ":distance", ":join_distance"),
  22135.  
  22136. (store_faction_of_party, ":faction_no", ":party_no"),
  22137. (store_faction_of_party, ":enemy_faction", "$g_enemy_party"),
  22138. (try_begin),
  22139. (eq, ":faction_no", "fac_player_supporters_faction"),
  22140. (assign, ":reln_with_player", 100),
  22141. (else_try),
  22142. (store_relation, ":reln_with_player", ":faction_no", "fac_player_supporters_faction"),
  22143. (try_end),
  22144. (try_begin),
  22145. (eq, ":faction_no", ":enemy_faction"),
  22146. (assign, ":reln_with_enemy", 100),
  22147. (else_try),
  22148. (store_relation, ":reln_with_enemy", ":faction_no", ":enemy_faction"),
  22149. (try_end),
  22150.  
  22151. (assign, ":enemy_side", 1),
  22152. (try_begin),
  22153. (neq, "$g_enemy_party", "$g_encountered_party"),
  22154. (assign, ":enemy_side", 2),
  22155. (try_end),
  22156.  
  22157. (try_begin),
  22158. (eq, ":besiege_mode", 0),
  22159. (lt, ":reln_with_player", 0),
  22160. (gt, ":reln_with_enemy", 0),
  22161. ##zerilius changes begin
  22162. ##wrong use of operation (native bug)
  22163. #(party_get_slot, ":party_type", ":party_no"),
  22164. (party_get_slot, ":party_type", ":party_no", slot_party_type),
  22165. ##zerilius changes end
  22166.  
  22167. (assign, ":enemy_is_bandit_party_and_level_is_greater_than_6", 0),
  22168. (try_begin), #SB : is_bandit
  22169. # (party_stack_get_troop_id, ":stack_troop", ":party_no", 0),
  22170. # (is_between, ":stack_troop", "trp_looter", "trp_black_khergit_horseman"),
  22171. (eq, ":is_bandit", 1),
  22172. (gt, ":player_level", 6),
  22173. (assign, ":enemy_is_bandit_party_and_level_is_greater_than_6", 1),
  22174. (try_end),
  22175.  
  22176. (this_or_next|eq, ":party_type", spt_kingdom_hero_party),
  22177. (eq, ":enemy_is_bandit_party_and_level_is_greater_than_6", 1),
  22178.  
  22179. (get_party_ai_behavior, ":ai_bhvr", ":party_no"),
  22180. (neq, ":ai_bhvr", ai_bhvr_avoid_party),
  22181. (party_quick_attach_to_current_battle, ":party_no", ":enemy_side"), #attach as enemy
  22182. (str_store_party_name, s1, ":party_no"),
  22183. #SB : colorize
  22184. (display_message, "str_s1_joined_battle_enemy", message_negative),
  22185. (else_try),
  22186. (try_begin),
  22187. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  22188. (party_slot_eq, ":party_no", slot_party_ai_object, "trp_player"),
  22189. (assign, ":party_is_accompanying_player", 1),
  22190. (else_try),
  22191. (assign, ":party_is_accompanying_player", 0),
  22192. (try_end),
  22193.  
  22194. (this_or_next|eq, ":dont_add_friends_other_than_accompanying", 0),
  22195. (eq, ":party_is_accompanying_player", 1),
  22196. (gt, ":reln_with_player", 0),
  22197. (lt, ":reln_with_enemy", 0),
  22198.  
  22199. (assign, ":following_player", 0),
  22200. (try_begin),
  22201. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  22202. (party_slot_eq, ":party_no", slot_party_ai_object, "p_main_party"),
  22203. (assign, ":following_player", 1),
  22204. (try_end),
  22205.  
  22206. (assign, ":do_join", 1),
  22207. (try_begin),
  22208. (eq, ":besiege_mode", 1),
  22209. (eq, ":following_player", 0),
  22210. (assign, ":do_join", 0),
  22211. (eq, ":faction_no", "$players_kingdom"),
  22212. (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
  22213. (assign, ":do_join", 1),
  22214. (try_end),
  22215. (eq, ":do_join", 1),
  22216.  
  22217. ##zerilius changes begin
  22218. ##wrong use of operation (native bug)
  22219. #(party_get_slot, ":party_type", ":party_no"),
  22220. (party_get_slot, ":party_type", ":party_no", slot_party_type),
  22221. ##zerilius changes end
  22222. (eq, ":party_type", spt_kingdom_hero_party),
  22223. (party_stack_get_troop_id, ":leader", ":party_no", 0),
  22224. #(troop_get_slot, ":player_relation", ":leader", slot_troop_player_relation),
  22225. (call_script, "script_troop_get_player_relation", ":leader"),
  22226. (assign, ":player_relation", reg0),
  22227.  
  22228. (assign, ":join_even_you_do_not_like_player", 0),
  22229. (try_begin),
  22230. (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"), #new added, if player is marshal and if he is accompanying then join battle even lord do not like player
  22231. (eq, ":following_player", 1),
  22232. (assign, ":join_even_you_do_not_like_player", 1),
  22233. ##diplomacy start+
  22234. #Affiliates will assist the player.
  22235. (else_try),
  22236. (lt, ":player_relation", 0),
  22237. (call_script, "script_dplmc_is_affiliated_family_member", ":leader"),
  22238. (val_max, ":player_relation", reg0),
  22239. ##diplomacy end+
  22240. (try_end),
  22241.  
  22242. (this_or_next|ge, ":player_relation", 0),
  22243. (eq, ":join_even_you_do_not_like_player", 1),
  22244.  
  22245. (party_quick_attach_to_current_battle, ":party_no", 0), #attach as friend
  22246. (str_store_party_name, s1, ":party_no"),
  22247. # ## SB : colorize
  22248. # (faction_get_color, ":color", ":faction_no"),
  22249. (display_message, "str_s1_joined_battle_friend", message_positive),
  22250. (try_end),
  22251. (try_end),
  22252. ]),
  22253.  
  22254. # script_party_wound_all_members_aux
  22255. # Input: arg1 = party_no
  22256. ("party_wound_all_members_aux",
  22257. [
  22258. (store_script_param_1, ":party_no"),
  22259.  
  22260. (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  22261. (try_for_range, ":i_stack", 0, ":num_stacks"),
  22262. (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  22263. (try_begin),
  22264. (neg|troop_is_hero, ":stack_troop"),
  22265. (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  22266. (party_wound_members, ":party_no", ":stack_troop", ":stack_size"),
  22267. (else_try),
  22268. (troop_set_health, ":stack_troop", 0),
  22269. (try_end),
  22270. (try_end),
  22271. (party_get_num_attached_parties, ":num_attached_parties", ":party_no"),
  22272. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  22273. (party_get_attached_party_with_rank, ":attached_party", ":party_no", ":attached_party_rank"),
  22274. (call_script, "script_party_wound_all_members_aux", ":attached_party"),
  22275. (try_end),
  22276. ]),
  22277.  
  22278. # script_party_wound_all_members
  22279. # Input: arg1 = party_no
  22280. ("party_wound_all_members",
  22281. [
  22282. (store_script_param_1, ":party_no"),
  22283.  
  22284. (call_script, "script_party_wound_all_members_aux", ":party_no"),
  22285. ]),
  22286.  
  22287.  
  22288.  
  22289. # script_calculate_battle_advantage
  22290. # Output: reg0 = battle advantage
  22291. ("calculate_battle_advantage",
  22292. [
  22293. (call_script, "script_party_count_fit_for_battle", "p_collective_friends"),
  22294. (assign, ":friend_count", reg(0)),
  22295.  
  22296. (party_get_skill_level, ":player_party_tactics", "p_main_party", skl_tactics),
  22297. (party_get_skill_level, ":ally_party_tactics", "p_collective_friends", skl_tactics),
  22298. (val_max, ":player_party_tactics", ":ally_party_tactics"),
  22299.  
  22300. (call_script, "script_party_count_fit_for_battle", "p_collective_enemy"),
  22301. (assign, ":enemy_count", reg(0)),
  22302.  
  22303. (party_get_skill_level, ":enemy_party_tactics", "p_collective_enemy", skl_tactics),
  22304.  
  22305. (val_add, ":friend_count", 1),
  22306. (val_add, ":enemy_count", 1),
  22307.  
  22308. (try_begin),
  22309. (ge, ":friend_count", ":enemy_count"),
  22310. (val_mul, ":friend_count", 100),
  22311. (store_div, ":ratio", ":friend_count", ":enemy_count"),
  22312. (store_sub, ":raw_advantage", ":ratio", 100),
  22313. (else_try),
  22314. (val_mul, ":enemy_count", 100),
  22315. (store_div, ":ratio", ":enemy_count", ":friend_count"),
  22316. (store_sub, ":raw_advantage", 100, ":ratio"),
  22317. (try_end),
  22318. (val_mul, ":raw_advantage", 2),
  22319.  
  22320. (val_mul, ":player_party_tactics", 30),
  22321. (val_mul, ":enemy_party_tactics", 30),
  22322. (val_add, ":raw_advantage", ":player_party_tactics"),
  22323. (val_sub, ":raw_advantage", ":enemy_party_tactics"),
  22324. (val_div, ":raw_advantage", 100),
  22325.  
  22326.  
  22327. (assign, reg0, ":raw_advantage"),
  22328. (display_message, "@Battle Advantage = {reg0}.", 0xFFFFFFFF),
  22329. ]),
  22330.  
  22331.  
  22332. # script_cf_check_enemies_nearby
  22333. # Input: none
  22334. # Output: none, fails when enemies are nearby
  22335. ("cf_check_enemies_nearby",
  22336. [
  22337. (get_player_agent_no, ":player_agent"),
  22338. (agent_is_alive, ":player_agent"),
  22339. (agent_get_position, pos1, ":player_agent"),
  22340. (assign, ":result", 0),
  22341. (set_fixed_point_multiplier, 100),
  22342. (try_for_agents,":cur_agent"),
  22343. (neq, ":cur_agent", ":player_agent"),
  22344. (agent_is_alive, ":cur_agent"),
  22345. (agent_is_human, ":cur_agent"),
  22346. (neg|agent_is_ally, ":cur_agent"),
  22347. (agent_get_position, pos2, ":cur_agent"),
  22348. (get_distance_between_positions, ":cur_distance", pos1, pos2),
  22349. (le, ":cur_distance", 1500), #15 meters
  22350. (assign, ":result", 1),
  22351. (try_end),
  22352. (eq, ":result", 0),
  22353. ]),
  22354.  
  22355. # script_get_heroes_attached_to_center_aux
  22356. # For internal use only
  22357. ("get_heroes_attached_to_center_aux",
  22358. [
  22359. (store_script_param_1, ":center_no"),
  22360. (store_script_param_2, ":party_no_to_collect_heroes"),
  22361. (party_get_num_companion_stacks, ":num_stacks",":center_no"),
  22362. (try_for_range, ":i_stack", 0, ":num_stacks"),
  22363. (party_stack_get_troop_id, ":stack_troop",":center_no",":i_stack"),
  22364. (troop_is_hero, ":stack_troop"),
  22365. (party_add_members, ":party_no_to_collect_heroes", ":stack_troop", 1),
  22366. (try_end),
  22367. (party_get_num_attached_parties, ":num_attached_parties", ":center_no"),
  22368. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  22369. (party_get_attached_party_with_rank, ":attached_party", ":center_no", ":attached_party_rank"),
  22370. (call_script, "script_get_heroes_attached_to_center_aux", ":attached_party", ":party_no_to_collect_heroes"),
  22371. (try_end),
  22372. ]),
  22373.  
  22374. # script_get_heroes_attached_to_center
  22375. # Input: arg1 = center_no, arg2 = party_no_to_collect_heroes
  22376. # Output: none, adds heroes to the party_no_to_collect_heroes party
  22377. ("get_heroes_attached_to_center",
  22378. [
  22379. (store_script_param_1, ":center_no"),
  22380. (store_script_param_2, ":party_no_to_collect_heroes"),
  22381. (party_clear, ":party_no_to_collect_heroes"),
  22382. (call_script, "script_get_heroes_attached_to_center_aux", ":center_no", ":party_no_to_collect_heroes"),
  22383.  
  22384. #rebellion changes begin -Arma
  22385. (try_for_range, ":pretender", pretenders_begin, pretenders_end),
  22386. (neq, ":pretender", "$supported_pretender"),
  22387. (troop_slot_eq, ":pretender", slot_troop_cur_center, ":center_no"),
  22388. (party_add_members, ":party_no_to_collect_heroes", ":pretender", 1),
  22389. (try_end),
  22390.  
  22391. # (try_for_range, ":rebel_faction", rebel_factions_begin, rebel_factions_end),
  22392. # (faction_slot_eq, ":rebel_faction", slot_faction_state, sfs_inactive_rebellion),
  22393. # (faction_slot_eq, ":rebel_faction", slot_faction_inactive_leader_location, ":center_no"),
  22394. # (faction_get_slot, ":pretender", ":rebel_faction", slot_faction_leader),
  22395. # (party_add_members, ":party_no_to_collect_heroes", ":pretender", 1),
  22396. # (try_end),
  22397. #rebellion changes end
  22398.  
  22399.  
  22400. ]),
  22401.  
  22402.  
  22403. # script_get_heroes_attached_to_center_as_prisoner_aux
  22404. # For internal use only
  22405. ("get_heroes_attached_to_center_as_prisoner_aux",
  22406. [
  22407. (store_script_param_1, ":center_no"),
  22408. (store_script_param_2, ":party_no_to_collect_heroes"),
  22409. (party_get_num_prisoner_stacks, ":num_stacks",":center_no"),
  22410. (try_for_range, ":i_stack", 0, ":num_stacks"),
  22411. (party_prisoner_stack_get_troop_id, ":stack_troop",":center_no",":i_stack"),
  22412. (troop_is_hero, ":stack_troop"),
  22413. (party_add_members, ":party_no_to_collect_heroes", ":stack_troop", 1),
  22414. (try_end),
  22415. (party_get_num_attached_parties, ":num_attached_parties", ":center_no"),
  22416. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  22417. (party_get_attached_party_with_rank, ":attached_party", ":center_no", ":attached_party_rank"),
  22418. (call_script, "script_get_heroes_attached_to_center_as_prisoner_aux", ":attached_party", ":party_no_to_collect_heroes"),
  22419. (try_end),
  22420. ]),
  22421.  
  22422.  
  22423. # script_get_heroes_attached_to_center_as_prisoner
  22424. # Input: arg1 = center_no, arg2 = party_no_to_collect_heroes
  22425. # Output: none, adds heroes to the party_no_to_collect_heroes party
  22426. ("get_heroes_attached_to_center_as_prisoner",
  22427. [
  22428. (store_script_param_1, ":center_no"),
  22429. (store_script_param_2, ":party_no_to_collect_heroes"),
  22430. (party_clear, ":party_no_to_collect_heroes"),
  22431. (call_script, "script_get_heroes_attached_to_center_as_prisoner_aux", ":center_no", ":party_no_to_collect_heroes"),
  22432. ]),
  22433.  
  22434. ##
  22435. ## # script_cf_get_party_leader
  22436. ## # Input: arg1 = party_no
  22437. ## # Output: reg0 = troop_no of the leader (Can fail)
  22438. ## ("cf_get_party_leader",
  22439. ## [
  22440. ## (store_script_param_1, ":party_no"),
  22441. ##
  22442. ## (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  22443. ## (gt, ":num_stacks", 0),
  22444. ## (party_stack_get_troop_id, ":stack_troop", ":party_no", 0),
  22445. ## (troop_is_hero, ":stack_troop"),
  22446. ## (assign, reg0, ":stack_troop"),
  22447. ## ]),
  22448.  
  22449. # script_give_center_to_faction
  22450. # Input: arg1 = center_no, arg2 = faction
  22451. ("give_center_to_faction",
  22452. [
  22453. (store_script_param_1, ":center_no"),
  22454. (store_script_param_2, ":faction_no"),
  22455.  
  22456. ##diplomacy begin
  22457. (party_set_slot, ":center_no", dplmc_slot_center_taxation, 0),
  22458. (try_begin),
  22459. (party_slot_eq, ":center_no", slot_village_infested_by_bandits, "trp_peasant_woman"),
  22460. (party_set_slot, ":center_no", slot_village_infested_by_bandits, 0),
  22461. (try_end),
  22462. (try_begin),
  22463. (eq, "$g_constable_training_center", ":center_no"),
  22464. (assign, "$g_constable_training_center", -1),
  22465. (try_end),
  22466. ##diplomacy end
  22467. (try_begin),
  22468. (eq, ":faction_no", "fac_player_supporters_faction"),
  22469. (faction_get_slot, ":player_faction_king", "fac_player_supporters_faction", slot_faction_leader),
  22470. (eq, ":player_faction_king", "trp_player"),
  22471.  
  22472. (try_begin),
  22473. (is_between, ":center_no", walled_centers_begin, walled_centers_end),
  22474. (assign, ":number_of_walled_centers_players_kingdom_has", 1),
  22475. (else_try),
  22476. (assign, ":number_of_walled_centers_players_kingdom_has", 0),
  22477. (try_end),
  22478.  
  22479. (try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
  22480. (store_faction_of_party, ":owner_faction_no", ":walled_center"),
  22481. (eq, ":owner_faction_no", "fac_player_supporters_faction"),
  22482. (val_add, ":number_of_walled_centers_players_kingdom_has", 1),
  22483. (try_end),
  22484.  
  22485. (ge, ":number_of_walled_centers_players_kingdom_has", 10),
  22486. (unlock_achievement, ACHIEVEMENT_VICTUM_SEQUENS),
  22487. (try_end),
  22488.  
  22489. (try_begin),
  22490. (check_quest_active, "qst_join_siege_with_army"),
  22491. (quest_slot_eq, "qst_join_siege_with_army", slot_quest_target_center, ":center_no"),
  22492. (call_script, "script_abort_quest", "qst_join_siege_with_army", 0),
  22493. #Reactivating follow army quest
  22494. (faction_get_slot, ":faction_marshall", "$players_kingdom", slot_faction_marshall),
  22495. (str_store_troop_name_link, s9, ":faction_marshall"),
  22496. (setup_quest_text, "qst_follow_army"),
  22497. (str_store_string, s2, "@{s9} wants you to resume following his army until further notice."),
  22498. (call_script, "script_start_quest", "qst_follow_army", ":faction_marshall"),
  22499. (assign, "$g_player_follow_army_warnings", 0),
  22500. (try_end),
  22501.  
  22502. #(store_faction_of_party, ":old_faction", ":center_no"),
  22503. (call_script, "script_give_center_to_faction_aux", ":center_no", ":faction_no"),
  22504. (call_script, "script_update_village_market_towns"),
  22505.  
  22506. (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  22507. (call_script, "script_faction_recalculate_strength", ":cur_faction"),
  22508. (try_end),
  22509. (assign, "$g_recalculate_ais", 1),
  22510.  
  22511. (try_begin),
  22512. (eq, ":faction_no", "fac_player_supporters_faction"),
  22513. (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_inactive),
  22514. (call_script, "script_activate_player_faction", "trp_player"),
  22515. (try_end),
  22516.  
  22517. #(call_script, "script_activate_deactivate_player_faction", ":old_faction"),
  22518. #(try_begin),
  22519. #(eq, ":faction_no", "fac_player_supporters_faction"),
  22520. #(faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
  22521. #(call_script, "script_give_center_to_lord", ":center_no", "trp_player", 0),
  22522.  
  22523. #check with Armagan -- what is this here for?
  22524. #(try_for_range, ":cur_village", villages_begin, villages_end),
  22525. #(store_faction_of_party, ":cur_village_faction", ":cur_village"),
  22526. #(eq, ":cur_village_faction", "fac_player_supporters_faction"),
  22527. #(neg|party_slot_eq, ":cur_village", slot_town_lord, "trp_player"),
  22528. #(call_script, "script_give_center_to_lord", ":cur_village", "trp_player", 0),
  22529. #(try_end),
  22530. #(try_end),
  22531. ]),
  22532.  
  22533. # script_give_center_to_faction_aux
  22534. # Input: arg1 = center_no, arg2 = faction
  22535. ("give_center_to_faction_aux",
  22536. [
  22537. (store_script_param_1, ":center_no"),
  22538. (store_script_param_2, ":faction_no"),
  22539.  
  22540. (store_faction_of_party, ":old_faction", ":center_no"),
  22541. (party_set_faction, ":center_no", ":faction_no"),
  22542.  
  22543. (try_begin),
  22544. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  22545. (try_begin),
  22546. (party_get_slot, ":farmer_party", ":center_no", slot_village_farmer_party),
  22547. (gt, ":farmer_party", 0),
  22548. (party_is_active, ":farmer_party"),
  22549. (party_set_faction, ":farmer_party", ":faction_no"),
  22550. (try_end),
  22551. #SB : reinforcements becomes deserters
  22552. (try_begin),
  22553. (party_get_slot, ":reinf_party", ":center_no", slot_village_reinforcement_party),
  22554. (gt, ":reinf_party", 0),
  22555. (party_is_active, ":reinf_party"),
  22556. (set_spawn_radius, 0),
  22557. (spawn_around_party, ":reinf_party", "pt_deserters"),
  22558. (assign, ":new_party", reg0),
  22559. #apply move_members_with_ratio, party_inflict_attrition, party_inflict_casualties, etc based on center relations/prosperity
  22560. (call_script, "script_party_add_party", ":new_party", ":reinf_party"),
  22561. (party_set_slot, ":center_no", slot_village_reinforcement_party, -1),
  22562. (party_set_ai_behavior, ":new_party", ai_bhvr_patrol_party),
  22563. (party_set_ai_object, ":new_party", ":center_no"), #or its market town
  22564. (party_set_ai_patrol_radius, ":new_party", 25),
  22565. (remove_party, ":reinf_party"),
  22566. (try_end),
  22567. (try_end),
  22568.  
  22569. (try_begin),
  22570. #This bit of seemingly redundant code (the neq condition) is designed to prevent a bug that occurs when a player first conquers a center -- apparently this script is called again AFTER it is handed to a lord
  22571. #Without this line, then the player's dialog selection does not have any affect, because town_lord is set again to stl_unassigned after the player makes his or her choice
  22572. (neq, ":faction_no", ":old_faction"),
  22573. ##diplomacy start+
  22574. (party_get_slot, ":old_ex_faction", ":center_no", slot_center_ex_faction),
  22575. ##diplomacy end+
  22576. (party_set_slot, ":center_no", slot_center_ex_faction, ":old_faction"),
  22577. (party_get_slot, ":old_town_lord", ":center_no", slot_town_lord),
  22578. ##diplomacy start+
  22579. (store_current_hours, ":hours"),
  22580. (party_get_slot, ":old_ex_lord", ":center_no", dplmc_slot_center_ex_lord),
  22581. #(party_get_slot, ":old_last_transfer", ":center_no", dplmc_slot_center_last_transfer_time),
  22582. (try_begin),
  22583. #When a faction regains a lost fief, if the ex-lord is a member of that faction,
  22584. #don't erase that information.
  22585. (this_or_next|party_slot_eq, ":center_no", slot_center_original_faction, ":faction_no"),#Handle several rapid sequential transfers
  22586. (eq, ":old_ex_faction", ":faction_no"),
  22587. (is_between, ":old_ex_lord", heroes_begin, heroes_end),
  22588. (store_faction_of_troop, ":old_ex_lord_faction", ":old_ex_lord"),
  22589. (eq, ":old_ex_lord_faction", ":faction_no"),
  22590. (else_try),
  22591. #Otherwise, if the center had a lord before this transfer, set the
  22592. #ex-lord to the lord losing this.
  22593. (neq, ":old_town_lord", stl_unassigned),
  22594. (ge, ":old_town_lord", 0),
  22595. (this_or_next|ge, ":old_town_lord", 1),#Don't apply to the player at the start of the game
  22596. (gt, ":hours", 0),
  22597.  
  22598. #Don't apply to fiefs lost by the faction leader, except for his "home",
  22599. #and any fiefs with him marked as the original lord.
  22600. (call_script, "script_dplmc_get_troop_standing_in_faction", ":old_town_lord", ":old_faction"),
  22601. (this_or_next|lt, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  22602. (this_or_next|troop_slot_eq, ":old_faction", slot_troop_home, ":center_no"),
  22603. (party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":old_town_lord"),
  22604.  
  22605. (party_set_slot, ":center_no", dplmc_slot_center_ex_lord, ":old_town_lord"),
  22606. (try_end),
  22607. (party_set_slot, ":center_no", dplmc_slot_center_last_transfer_time, ":hours"),
  22608. (party_set_slot, ":center_no", slot_town_lord, stl_unassigned),
  22609. (party_set_banner_icon, ":center_no", 0),#Removing banner
  22610. (call_script, "script_update_faction_notes", ":old_faction"),
  22611. #Invalidate old lord's cached center points
  22612. (gt, ":old_town_lord", -1),
  22613. (troop_set_slot, ":old_town_lord", dplmc_slot_troop_center_points_plus_one, 0),
  22614. (try_end),
  22615.  
  22616. (call_script, "script_update_faction_notes", ":faction_no"),
  22617. (call_script, "script_update_center_notes", ":center_no"),
  22618.  
  22619. (try_begin),
  22620. (ge, ":old_town_lord", 0),
  22621. (neq, ":faction_no", "fac_player_supporters_faction"),
  22622. (call_script, "script_update_troop_notes", ":old_town_lord"),
  22623. (try_end),
  22624.  
  22625. (try_for_range, ":other_center", centers_begin, centers_end),
  22626. (party_slot_eq, ":other_center", slot_village_bound_center, ":center_no"),
  22627. ##diplomacy start+ Avoid infinite recursion even if some foolish modder (such as myself)
  22628. #has set up bizarre cyclic dependencies
  22629. (store_faction_of_party, ":other_center_faction", ":other_center"),
  22630. ##The "this or next" is so that any weird uses of this function
  22631. ##in Native (to change something to its own faction) will be
  22632. ##replicated. The reason this works is that all villages have
  22633. ##higher ID numbers than castles or towns.
  22634. (this_or_next|gt, ":other_center", ":center_no"),
  22635. (neq, ":other_center_faction", ":old_faction"),
  22636. ##diplomacy end+
  22637. (call_script, "script_give_center_to_faction_aux", ":other_center", ":faction_no"),
  22638. (try_end),
  22639. ]),
  22640.  
  22641. # script_change_troop_faction
  22642. # Input: arg1 = troop_no, arg2 = faction
  22643. ("change_troop_faction",
  22644. [
  22645. (store_script_param_1, ":troop_no"),
  22646. (store_script_param_2, ":faction_no"),
  22647. (try_begin),
  22648. #Reactivating inactive or defeated faction
  22649. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  22650. (neg|faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  22651. (faction_set_slot, ":faction_no", slot_faction_state, sfs_active),
  22652. #(call_script, "script_store_average_center_value_per_faction"),
  22653. (try_end),
  22654.  
  22655. #Political ramifications
  22656. (store_faction_of_troop, ":orig_faction", ":troop_no"),
  22657. ##diplomacy start+ save these for reference
  22658. #(faction_get_slot, ":orig_faction_leader", ":orig_faction", slot_faction_leader),
  22659. (faction_get_slot, ":new_faction_leader", ":faction_no", slot_faction_leader),
  22660. (try_begin),
  22661. #Avoid letting heroes get stuck as slto_inactive if petitioners switch away from the player's faction
  22662. (eq, ":orig_faction", "fac_player_supporters_faction"),
  22663. (gt, ":troop_no", 0),
  22664. (troop_is_hero, ":troop_no"),
  22665. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive),
  22666. (this_or_next|is_between, ":troop_no", lords_begin, lords_end),
  22667. (this_or_next|is_between, ":troop_no", kings_begin, kings_end),
  22668. (this_or_next|is_between, ":troop_no", pretenders_begin, pretenders_end),
  22669. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_granted_fief),
  22670. (troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_lord_rejoined),
  22671. (troop_set_slot, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  22672. (try_end),
  22673. ##diplomacy end+
  22674.  
  22675. #remove if he is marshal
  22676. (try_begin),
  22677. (faction_slot_eq, ":orig_faction", slot_faction_marshall, ":troop_no"),
  22678. (call_script, "script_check_and_finish_active_army_quests_for_faction", ":orig_faction"),
  22679.  
  22680. #No current issue on the agenda
  22681. (try_begin),
  22682. (faction_slot_eq, ":orig_faction", slot_faction_political_issue, 0),
  22683.  
  22684. (faction_set_slot, ":orig_faction", slot_faction_political_issue, 1), #Appointment of marshal
  22685. (store_current_hours, ":hours"),
  22686. (val_max, ":hours", 0),
  22687. (faction_set_slot, ":orig_faction", slot_faction_political_issue_time, ":hours"), #Appointment of marshal
  22688. ##diplomacy start+ Reset political stance for kingdom ladies as well
  22689. #(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),##OLD
  22690. (try_for_range, ":active_npc", heroes_begin, heroes_end),##NEW
  22691. ##diplomacy end+
  22692. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  22693. (eq, ":active_npc_faction", ":orig_faction"),
  22694. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  22695. (try_end),
  22696. (try_begin),
  22697. (eq, "$players_kingdom", ":orig_faction"),
  22698. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  22699. (try_end),
  22700. (try_end),
  22701.  
  22702. (try_begin),
  22703. (troop_get_slot, ":old_marshall_party", ":troop_no", slot_troop_leaded_party),
  22704. (party_is_active, ":old_marshall_party"),
  22705. (party_set_marshal, ":old_marshall_party", 0),
  22706. (try_end),
  22707.  
  22708. (faction_set_slot, ":orig_faction", slot_faction_marshall, -1),
  22709. (try_end),
  22710. #Removal as marshal ends
  22711.  
  22712. #Other political ramifications
  22713. (troop_set_slot, ":troop_no", slot_troop_stance_on_faction_issue, -1),
  22714. ##diplomacy start+ Support promoted kingdom ladies
  22715. #(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
  22716. (try_for_range, ":active_npc", heroes_begin, heroes_end),
  22717. ##diplomacy end+
  22718. (troop_slot_eq, ":active_npc", slot_troop_stance_on_faction_issue, ":troop_no"),
  22719. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  22720. (try_end),
  22721. #Political ramifications end
  22722.  
  22723.  
  22724. (try_begin),
  22725. (ge, "$cheat_mode", 1),
  22726. (str_store_troop_name, s4, ":troop_no"),
  22727. (display_message, "@{!}DEBUG - {s4} faction changed in normal faction change"),
  22728. (try_end),
  22729.  
  22730. (troop_set_faction, ":troop_no", ":faction_no"),
  22731. ##diplomacy start+
  22732. ##Don't give lords amnesia about what the player said to recruit them.
  22733. ##OLD:
  22734. #(troop_set_slot, ":troop_no", slot_troop_recruitment_random, 0),
  22735. #(troop_set_slot, ":troop_no", slot_lord_recruitment_argument, 0),
  22736. #(troop_set_slot, ":troop_no", slot_lord_recruitment_candidate, 0),
  22737. #(troop_set_slot, ":troop_no", slot_troop_promised_fief, 0),
  22738. ##NEW
  22739. (try_begin),
  22740. (eq, ":troop_no", "trp_player"),
  22741. #Don't change of this for the player.
  22742. (else_try),
  22743. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  22744. (this_or_next|eq, ":faction_no", "fac_player_supporters_faction"),
  22745. (eq, ":faction_no", "$players_kingdom"),
  22746. (ge, ":new_faction_leader", 0),
  22747. (this_or_next|eq, ":faction_no", "fac_player_supporters_faction"),
  22748. (this_or_next|eq, ":new_faction_leader", "trp_player"),
  22749. (this_or_next|troop_slot_eq, ":new_faction_leader", slot_troop_spouse, "trp_player"),
  22750. (troop_slot_eq, "trp_player", slot_troop_spouse, ":new_faction_leader"),
  22751. #Joined faction that player is ruler or co-ruler of. Don't forget
  22752. #any promises received.
  22753. (troop_set_slot, ":troop_no", slot_troop_recruitment_random, 0),
  22754. (else_try),
  22755. #Joined a new faction. Previous promises moot.
  22756. (troop_set_slot, ":troop_no", slot_troop_recruitment_random, 0),
  22757. (troop_set_slot, ":troop_no", slot_lord_recruitment_argument, 0),
  22758. (troop_set_slot, ":troop_no", slot_lord_recruitment_candidate, 0),
  22759. (troop_set_slot, ":troop_no", slot_troop_promised_fief, 0),
  22760. (try_end),
  22761. ##diplomacy end+
  22762.  
  22763. #Give new title
  22764. (call_script, "script_troop_set_title_according_to_faction", ":troop_no", ":faction_no"),
  22765.  
  22766. (try_begin),
  22767. (this_or_next|eq, ":faction_no", "$players_kingdom"),
  22768. (eq, ":faction_no", "fac_player_supporters_faction"),
  22769. (call_script, "script_check_concilio_calradi_achievement"),
  22770. (try_end),
  22771.  
  22772. #Takes walled centers and dependent villages with him
  22773. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  22774. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  22775. (party_set_faction, ":center_no", ":faction_no"),
  22776. (try_for_range, ":village_no", villages_begin, villages_end),
  22777. (party_slot_eq, ":village_no", slot_village_bound_center, ":center_no"),
  22778. (party_set_faction, ":village_no", ":faction_no"),
  22779. (party_get_slot, ":farmer_party_no", ":village_no", slot_village_farmer_party),
  22780. (try_begin),
  22781. (gt, ":farmer_party_no", 0),
  22782. (party_is_active, ":farmer_party_no"),
  22783. (party_set_faction, ":farmer_party_no", ":faction_no"),
  22784. (try_end),
  22785. (try_begin),
  22786. (party_get_slot, ":old_town_lord", ":village_no", slot_town_lord),
  22787. (neq, ":old_town_lord", ":troop_no"),
  22788. (party_set_slot, ":village_no", slot_town_lord, stl_unassigned),
  22789. ##diplomacy start+ Invalidate old lord's cached center points
  22790. (gt, ":old_town_lord", -1),
  22791. (troop_set_slot, ":old_town_lord", dplmc_slot_troop_center_points_plus_one, 0),
  22792. ##diplomacy end+
  22793. (try_end),
  22794. (try_end),
  22795. (try_end),
  22796.  
  22797. #Dependant kingdom ladies switch faction
  22798. (try_for_range, ":kingdom_lady", kingdom_ladies_begin, kingdom_ladies_end),
  22799. ##diplomacy start+ This is required if kingdom ladies can be promoted to other roles
  22800. (this_or_next|troop_slot_eq, ":kingdom_lady", slot_troop_occupation, 0),#for prisoners
  22801. (troop_slot_eq, ":kingdom_lady", slot_troop_occupation, slto_kingdom_lady),
  22802. (store_faction_of_troop, reg0, ":kingdom_lady"),
  22803. (this_or_next|eq, reg0, ":orig_faction"),
  22804. (neg|faction_slot_eq, reg0, slot_faction_state, sfs_active),
  22805. ##diplomacy end+
  22806. (call_script, "script_get_kingdom_lady_social_determinants", ":kingdom_lady"),
  22807. (assign, ":closest_male_relative", reg0),
  22808. (assign, ":new_center", reg1),
  22809.  
  22810. (eq, ":closest_male_relative", ":troop_no"),
  22811.  
  22812. (try_begin),
  22813. (ge, "$cheat_mode", 1),
  22814. (str_store_troop_name, s4, ":kingdom_lady"),
  22815. (display_message, "@{!}DEBUG - {s4} faction changed by guardian moving"),
  22816. (try_end),
  22817.  
  22818. (troop_set_faction, ":kingdom_lady", ":faction_no"),
  22819. (troop_slot_eq, ":kingdom_lady", slot_troop_prisoner_of_party, -1),
  22820. (troop_set_slot, ":kingdom_lady", slot_troop_cur_center, ":new_center"),
  22821. (try_end),
  22822.  
  22823. #Remove his control over villages under another fortress
  22824. (try_for_range, ":village_no", villages_begin, villages_end),
  22825. (party_slot_eq, ":village_no", slot_town_lord, ":troop_no"),
  22826. (store_faction_of_party, ":village_faction", ":village_no"),
  22827. (try_begin),
  22828. (neq, ":village_faction", ":faction_no"),
  22829. (party_set_slot, ":village_no", slot_town_lord, stl_unassigned),
  22830. ##diplomacy start+ invalidate cached center points
  22831. (gt, ":old_town_lord", -1),
  22832. (troop_set_slot, ":troop_no", dplmc_slot_troop_center_points_plus_one, 0),
  22833. ##diplomacy end+
  22834. (try_end),
  22835. (try_end),
  22836.  
  22837. #Free prisoners
  22838. (try_begin),
  22839. (troop_get_slot, ":leaded_party", ":troop_no", slot_troop_leaded_party),
  22840. (gt, ":leaded_party", 0),
  22841. (party_set_faction, ":leaded_party", ":faction_no"),
  22842. (party_get_num_prisoner_stacks, ":num_stacks", ":leaded_party"),
  22843. (try_for_range_backwards, ":troop_iterator", 0, ":num_stacks"),
  22844. (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":leaded_party", ":troop_iterator"),
  22845. (store_troop_faction, ":cur_faction", ":cur_troop_id"),
  22846. (troop_is_hero, ":cur_troop_id"),
  22847. (eq, ":cur_faction", ":faction_no"),
  22848. (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
  22849. (party_remove_prisoners, ":leaded_party", ":cur_troop_id", 1),
  22850. (try_end),
  22851. (try_end),
  22852.  
  22853. #Annull all quests of which the lord is giver
  22854. (try_for_range, ":quest", all_quests_begin, all_quests_end),
  22855. (check_quest_active, ":quest"),
  22856. (quest_slot_eq, ":quest", slot_quest_giver_troop, ":troop_no"),
  22857.  
  22858. (str_store_troop_name, s4, ":troop_no"),
  22859. (try_begin),
  22860. (eq, "$cheat_mode", 1),
  22861. (display_message, "str_s4_changing_sides_aborts_quest"),
  22862. (try_end),
  22863. (call_script, "script_abort_quest", ":quest", 0),
  22864. (try_end),
  22865.  
  22866. #Boot all lords out of centers whose faction has changed
  22867. ##diplomacy start+ add check for promoted kingdom ladies
  22868. #(try_for_range, ":lord_to_move", active_npcs_begin, active_npcs_end),
  22869. (try_for_range, ":lord_to_move", heroes_begin, heroes_end),
  22870. (troop_slot_ge, ":lord_to_move", slot_troop_leaded_party, 1),
  22871. ##diplomacy end+
  22872. (troop_get_slot, ":lord_led_party", ":lord_to_move", slot_troop_leaded_party),
  22873. (party_is_active, ":lord_led_party"),
  22874. (party_get_attached_to, ":led_party_attached", ":lord_led_party"),
  22875. (is_between, ":led_party_attached", walled_centers_begin, walled_centers_end),
  22876. (store_faction_of_party, ":led_party_faction", ":lord_led_party"),
  22877. (store_faction_of_party, ":attached_party_faction", ":led_party_attached"),
  22878. (neq, ":led_party_faction", ":attached_party_faction"),
  22879.  
  22880. (party_detach, ":lord_led_party"),
  22881. (try_end),
  22882.  
  22883. #Increase relation with lord in new faction by 5
  22884. #Or, if player kingdom, make inactive pending confirmation
  22885. (faction_get_slot, ":faction_liege", ":faction_no", slot_faction_leader),
  22886. (try_begin),
  22887. (eq, ":faction_liege", "trp_player"),
  22888. (neq, ":troop_no", "$g_talk_troop"),
  22889. (troop_set_slot, ":troop_no", slot_troop_occupation, slto_inactive), #POSSIBLE REASON 1
  22890. (else_try),
  22891. ##diplomacy start+ Add support for promoted ladies
  22892. ##OLD:
  22893. #(is_between, ":faction_liege", active_npcs_begin, active_npcs_end),
  22894. #(is_between, ":troop_no", active_npcs_begin, active_npcs_end),
  22895. ##NEW:
  22896. (is_between, ":faction_liege", heroes_begin, heroes_end),
  22897. (is_between, ":troop_no", heroes_begin, heroes_end),
  22898. ##diplomacy end+
  22899. (call_script, "script_troop_change_relation_with_troop", ":faction_liege", ":troop_no", 5),
  22900. (val_add, "$total_indictment_changes", 5),
  22901. (try_end),
  22902.  
  22903. #Break courtship relations
  22904. (try_begin),
  22905. (troop_slot_ge, ":troop_no", slot_troop_spouse, 0),
  22906. #Already married, do nothing
  22907. (else_try),
  22908. (is_between, ":troop_no", active_npcs_begin, active_npcs_end),
  22909. ##diplomacy start+
  22910. #Bug fix: don't do this for pretenders.
  22911. (neg|is_between, ":troop_no", kings_begin, kings_end),
  22912. (neg|is_between, ":troop_no", pretenders_begin, pretenders_end),
  22913. ##diplomacy end+
  22914. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  22915. (troop_get_slot, ":courted_lady", ":troop_no", ":love_interest_slot"),
  22916. ##diplomacy start+ don't call this for bad values
  22917. (is_between, ":courted_lady", kingdom_ladies_begin, kingdom_ladies_end),
  22918. ##diplomacy end+
  22919. (call_script, "script_courtship_event_lady_break_relation_with_suitor", ":courted_lady", ":troop_no"),
  22920. (try_end),
  22921. ##diplomacy start+
  22922. # Don't call this script for married troops / rulers
  22923. #(call_script, "script_assign_troop_love_interests", ":troop_no"),
  22924. (try_begin),
  22925. (neg|troop_slot_ge, ":troop_no", slot_troop_spouse, 0),
  22926. (neg|is_between, ":troop_no", kings_begin, kings_end),
  22927. (neg|is_between, ":troop_no", pretenders_begin, pretenders_end),
  22928. (call_script, "script_assign_troop_love_interests", ":troop_no"),
  22929. (try_end),
  22930. ##diplomacy end+
  22931. (else_try),
  22932. (is_between, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  22933. (try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
  22934. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  22935. (troop_slot_eq, ":active_npc", ":love_interest_slot", ":troop_no"),
  22936. (call_script, "script_courtship_event_lady_break_relation_with_suitor", ":troop_no", ":active_npc"),
  22937. (try_end),
  22938. (try_end),
  22939. (try_end),
  22940.  
  22941. #Stop raidings/sieges of new faction's fief if there is any
  22942. (troop_get_slot, ":troop_party", ":troop_no", slot_troop_leaded_party),
  22943. (try_for_range, ":center_no", centers_begin, centers_end),
  22944. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  22945. (party_get_slot, ":raided_by", ":center_no", slot_village_raided_by),
  22946. (eq, ":raided_by", ":troop_party"),
  22947. (party_set_slot, ":center_no", slot_village_raided_by, -1),
  22948. (try_begin),
  22949. (party_slot_eq, ":center_no", slot_village_state, svs_being_raided),
  22950. (party_set_slot, ":center_no", slot_village_state, svs_normal),
  22951. (party_set_extra_text, ":center_no", "str_empty_string"),
  22952. (try_end),
  22953. (else_try),
  22954. (party_get_slot, ":besieged_by", ":center_no", slot_center_is_besieged_by),
  22955. (eq, ":besieged_by", ":troop_party"),
  22956. (party_set_slot, ":center_no", slot_center_is_besieged_by, -1),
  22957. (try_begin),
  22958. (party_slot_eq, ":center_no", slot_village_state, svs_under_siege),
  22959. (party_set_slot, ":center_no", slot_village_state, svs_normal),
  22960. (party_set_extra_text, ":center_no", "str_empty_string"),
  22961. (try_end),
  22962. (try_end),
  22963.  
  22964. (call_script, "script_update_all_notes"),
  22965.  
  22966. (call_script, "script_update_village_market_towns"),
  22967. (assign, "$g_recalculate_ais", 1),
  22968. ]),
  22969.  
  22970. # script_troop_set_title_according_to_faction
  22971. # Input: arg1 = troop_no, arg2 = faction_no
  22972. # EDITED FROM NATIVE TO ALLOW CUSTOM PLAYER KINGDOM TITLES
  22973. ("troop_set_title_according_to_faction",
  22974. [
  22975. (store_script_param, ":troop_no", 1),
  22976. (store_script_param, ":faction_no", 2),
  22977. ##diplomacy start+
  22978. # OLD CODE:
  22979. #(try_begin),
  22980. # (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  22981. # (str_store_troop_name_plural, s0, ":troop_no"),
  22982. # (troop_get_type, ":gender", ":troop_no"),
  22983. # (store_sub, ":title_index", ":faction_no", kingdoms_begin),
  22984. # (try_begin),
  22985. # (eq, ":gender", 0), #male
  22986. # (val_add, ":title_index", kingdom_titles_male_begin),
  22987. # (else_try),
  22988. # (val_add, ":title_index", kingdom_titles_female_begin),
  22989. # (try_end),
  22990. # (str_store_string, s1, ":title_index"),
  22991. # (troop_set_name, ":troop_no", s1),
  22992. # (troop_get_slot, ":troop_party", ":troop_no", slot_troop_leaded_party),
  22993. # (gt, ":troop_party", 0),
  22994. # (str_store_troop_name, s5, ":troop_no"),
  22995. # (party_set_name, ":troop_party", "str_s5_s_party"),
  22996. #(try_end),
  22997. #
  22998. # NEW CODE:
  22999. (assign, ":save_reg0", 0),
  23000. (assign, ":custom_name", 0),
  23001. (try_begin),
  23002. #Don't do anything when given a bad value.
  23003. #
  23004. #We could restrict this further, checking whether the troop is a hero,
  23005. #or whether it's between heroes_begin and heroes_end, but there are
  23006. #legitimate reasons a coder may want to run this to get a temporary value,
  23007. #or use this with temporary heroes, or so forth.
  23008. #
  23009. #However, some things are unambiguously errors:
  23010. (this_or_next|lt, ":troop_no", 0),# At best, the rename operation would fail.
  23011. (this_or_next|eq, ":troop_no", "trp_heroes_end"),# This is used to store custom titles, so applying a title to this will mess them up.
  23012. (this_or_next|eq, ":troop_no", "trp_kingdom_heroes_including_player_begin"),#This could easily end up changed due to carelessness
  23013. #There is also no legitimate reason to try to give the titles to generic soldiers.
  23014. (is_between, ":troop_no", soldiers_begin, soldiers_end),
  23015. ##Custom player kingdom vassal titles, credit Caba`drin start
  23016. #(Updated 2011-04-24, to use Caba`drin's 2011-04-20 bug-fix and update)
  23017. # See http://forums.taleworlds.com/index.php/topic,148259.0.html
  23018. (else_try),
  23019. (call_script, "script_dplmc_store_troop_is_female", ":troop_no"),#<- dplmc+ altered
  23020. (assign, ":troop_is_female", reg0),
  23021. ##Additional alteration start
  23022. #All Rhodok benefactor / custodian NPCs insist on the name "Tribune"
  23023. #Currently this is just Bunduk, but others could be added.
  23024. (try_begin),
  23025. (str_store_troop_name, s1, ":troop_no"),#s1 is overwritten below
  23026. #For dialogue reasons, this should be enabled even when the player
  23027. #is co-ruler of an NPC kingdom.
  23028. (this_or_next|eq, ":faction_no", "fac_player_supporters_faction"),
  23029. (eq, ":faction_no", "$players_kingdom"),
  23030. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_benefactor),
  23031. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_custodian),
  23032. (troop_slot_eq, ":troop_no", slot_troop_original_faction, "fac_kingdom_5"),
  23033. (assign, ":is_coruler", 0),
  23034. (try_begin),
  23035. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  23036. (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  23037. (gt, ":faction_leader", -1),
  23038. (this_or_next|eq, ":faction_leader", "trp_player"),
  23039. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, ":faction_leader"),
  23040. (troop_slot_eq, ":faction_leader", slot_troop_spouse, "trp_player"),
  23041. (assign, ":is_coruler", 1),
  23042. (try_end),
  23043. (this_or_next|eq, ":is_coruler", 1),
  23044. (eq, ":faction_no", "fac_player_supporters_faction"),
  23045. (str_store_string, s0, "@Tribune"),
  23046. (str_store_troop_name_plural, s1, ":troop_no"),
  23047. (str_store_string, s1, "str_s0_s1"),
  23048. ##Additional alteration end
  23049. (else_try),
  23050. (eq, ":faction_no", "fac_player_supporters_faction"),
  23051. #(troop_get_type, ":gender", ":troop_no"),#<- dplmc+ altered (use script for gender instead)
  23052. (try_begin),
  23053. (eq, ":troop_is_female", 0), #male #<- dplmc+ altered
  23054. (troop_slot_eq, "trp_heroes_end", 0, 1),
  23055. (str_store_troop_name, s0, "trp_heroes_end"),
  23056. (str_store_troop_name_plural, s1, ":troop_no"),
  23057. (str_store_string, s1, "str_s0_s1"),
  23058. (assign, ":custom_name", 1),
  23059. (else_try),
  23060. (troop_slot_eq, "trp_heroes_end", 1, 1),
  23061. (str_store_troop_name_plural, s0, "trp_heroes_end"),
  23062. (str_store_troop_name_plural, s1, ":troop_no"),
  23063. (str_store_string, s1, "str_s0_s1"),
  23064. (assign, ":custom_name", 1),
  23065. (try_end),
  23066. (eq, ":custom_name", 1), #So if it fails, will rename normally
  23067. (else_try),
  23068. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  23069. ##Additional section begin: add support for player kingdom culture
  23070. (try_begin),
  23071. (eq, ":faction_no", "fac_player_supporters_faction"),
  23072. (is_between, "$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  23073. (assign, ":faction_no", "$g_player_culture"),#<- Use title from culture if one is set, and not using custom titles
  23074. (try_end),
  23075. ##Additional section end
  23076. (str_store_troop_name_plural, s0, ":troop_no"),
  23077. #(troop_get_type, ":gender", ":troop_no"),#<- dplmc+ altered
  23078. (store_sub, ":title_index", ":faction_no", kingdoms_begin),
  23079. (try_begin),
  23080. (eq, ":troop_is_female", 0), #<- dplmc+ altered
  23081. (val_add, ":title_index", kingdom_titles_male_begin),
  23082. (else_try),
  23083. (val_add, ":title_index", kingdom_titles_female_begin),
  23084. (try_end),
  23085. (str_store_string, s1, ":title_index"),
  23086. (try_end),
  23087. (troop_set_name, ":troop_no", s1),
  23088. (troop_get_slot, ":troop_party", ":troop_no", slot_troop_leaded_party),
  23089. (gt, ":troop_party", 0),
  23090. (str_store_troop_name, s5, ":troop_no"),
  23091. (party_set_name, ":troop_party", "str_s5_s_party"),
  23092. (try_end),
  23093. ##Custom player kingdom vassal titles, credit Caba'drin end
  23094. (assign, reg0, ":save_reg0"),
  23095. ##diplomacy end+
  23096. ]),
  23097. # script_give_center_to_lord
  23098. # Input: arg1 = center_no, arg2 = lord_troop, arg3 = add_garrison_to_center
  23099. ("give_center_to_lord",
  23100. [
  23101. (store_script_param, ":center_no", 1),
  23102. (store_script_param, ":lord_troop_id", 2), #-1 only in the case of a player deferring ownership of a center
  23103. (store_script_param, ":add_garrison", 3),
  23104. ##diplomacy begin
  23105. (party_set_slot, ":center_no", dplmc_slot_center_taxation, 0),
  23106. (try_begin),
  23107. (party_slot_eq, ":center_no", slot_village_infested_by_bandits, "trp_peasant_woman"),
  23108. (party_set_slot, ":center_no", slot_village_infested_by_bandits, 0),
  23109. (try_end),
  23110. ##diplomacy end
  23111.  
  23112. ##diplomacy start+
  23113. #For relation changes below, store all heroes' center points and closest fiefs.
  23114. (call_script, "script_dplmc_prepare_hero_center_points_ignoring_center", ":center_no"),
  23115.  
  23116. #(assign, ":player_declines_honor", 0),
  23117. #(try_begin),
  23118. # (gt, "$g_dont_give_fief_to_player_days", 1),
  23119. # (assign, ":player_declines_honor", 1),
  23120. #(try_end),
  23121. ##diplomacy end+
  23122.  
  23123. (try_begin),
  23124. ##diplomacy start+ notable events like this should be logged by default
  23125. (store_current_hours, ":hours"),
  23126. (ge, ":hours", 1),#Don't spam the game log during world setup
  23127. (ge, ":lord_troop_id", 0),
  23128. (str_store_party_name_link, s4, ":center_no"),
  23129. (str_store_troop_name_link, s5, ":lord_troop_id"),
  23130. (store_troop_faction, ":msg_faction_no", ":lord_troop_id"),
  23131. (faction_get_color, ":color", ":msg_faction_no"), #SB : colorize
  23132. (str_store_faction_name_link, s7, ":msg_faction_no"),
  23133. (try_begin),
  23134. (faction_slot_eq, ":msg_faction_no", slot_faction_leader, ":lord_troop_id"),
  23135. (display_log_message, "@{s5} of the {s7} has taken ownership of {s4}.", ":color"),
  23136. (else_try),
  23137. (display_log_message, "@{s4} has been awarded to {s5} of the {s7}.", ":color"),
  23138. (try_end),
  23139. (else_try),
  23140. ##diplomacy end+
  23141. (eq, "$cheat_mode", 1),
  23142. (ge, ":lord_troop_id", 0),
  23143. (str_store_party_name, s4, ":center_no"),
  23144. (str_store_troop_name, s5, ":lord_troop_id"),
  23145. (display_message, "@{!}DEBUG -- {s4} awarded to {s5}"),
  23146. (try_end),
  23147.  
  23148. (try_begin),
  23149. (eq, ":lord_troop_id", "trp_player"),
  23150. (unlock_achievement, ACHIEVEMENT_ROYALITY_PAYMENT),
  23151.  
  23152. (assign, ":number_of_fiefs_player_have", 1),
  23153. (try_for_range, ":cur_center", centers_begin, centers_end),
  23154. (neq, ":cur_center", ":center_no"),
  23155. (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
  23156. (val_add, ":number_of_fiefs_player_have", 1),
  23157. (try_end),
  23158.  
  23159. (ge, ":number_of_fiefs_player_have", 5),
  23160. (unlock_achievement, ACHIEVEMENT_MEDIEVAL_EMLAK),
  23161. (try_end),
  23162.  
  23163. (party_get_slot, ":old_lord_troop_id", ":center_no", slot_town_lord),
  23164.  
  23165. (try_begin), #This script is ONLY called with lord_troop_id = -1 when it is the player faction
  23166. ##diplomacy start+
  23167. #The player can now also be co-ruler of a NPC kingdom.
  23168. (eq, ":lord_troop_id", -1),
  23169.  
  23170. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  23171. (faction_get_slot, ":players_kingdom_liege", "$players_kingdom", slot_faction_leader),
  23172. (gt, ":players_kingdom_liege", -1),
  23173. (this_or_next|eq, ":players_kingdom_liege", "trp_player"),
  23174. (this_or_next|troop_slot_eq, ":players_kingdom_liege", slot_troop_spouse, "trp_player"),
  23175. (troop_slot_eq, "trp_player", slot_troop_spouse, ":players_kingdom_liege"),
  23176.  
  23177. (assign, ":lord_troop_faction", "$players_kingdom"),
  23178. (party_set_banner_icon, ":center_no", 0),#Removing banner
  23179. (else_try),
  23180. ##diplomacy end+
  23181. (eq, ":lord_troop_id", -1),
  23182. (assign, ":lord_troop_faction", "fac_player_supporters_faction"),
  23183. (party_set_banner_icon, ":center_no", 0),#Removing banner
  23184.  
  23185. (else_try),
  23186. (eq, ":lord_troop_id", "trp_player"),
  23187. (assign, ":lord_troop_faction", "$players_kingdom"), #was changed on Apr 27 from fac_plyr_sup_fac
  23188.  
  23189. (else_try),
  23190. (store_troop_faction, ":lord_troop_faction", ":lord_troop_id"),
  23191. (try_end),
  23192. (faction_get_slot, ":faction_leader", ":lord_troop_faction", slot_faction_leader),
  23193.  
  23194. (try_begin),
  23195. (eq, ":faction_leader", "trp_player"),
  23196.  
  23197. (try_begin),
  23198. (troop_get_type, ":is_female", "trp_player"),
  23199. (eq, ":is_female", 1),
  23200. (unlock_achievement, ACHIEVEMENT_QUEEN),
  23201. (try_end),
  23202. (try_end),
  23203.  
  23204. (try_begin),
  23205. (eq, ":faction_leader", ":old_lord_troop_id"),
  23206. (call_script, "script_add_log_entry", logent_liege_grants_fief_to_vassal, ":faction_leader", ":center_no", ":lord_troop_id", ":lord_troop_faction"),
  23207. (troop_set_slot, ":lord_troop_id", slot_troop_promised_fief, 0),
  23208. (try_end),
  23209.  
  23210. (try_begin),
  23211. (eq, ":lord_troop_id", -1), #Lord troop ID -1 is only used when a player is deferring assignment of a fief
  23212. (party_set_faction, ":center_no", "$players_kingdom"),
  23213. (else_try),
  23214. (eq, ":lord_troop_id", "trp_player"),
  23215. (gt, "$players_kingdom", 0),
  23216. (party_set_faction, ":center_no", "$players_kingdom"),
  23217. (else_try),
  23218. (eq, ":lord_troop_id", "trp_player"),
  23219. (neg|is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
  23220. (party_set_faction, ":center_no", "fac_player_supporters_faction"),
  23221. (else_try),
  23222. (party_set_faction, ":center_no", ":lord_troop_faction"),
  23223. (try_end),
  23224. (party_set_slot, ":center_no", slot_town_lord, ":lord_troop_id"),
  23225.  
  23226. (try_begin),
  23227. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  23228. (party_get_slot, ":farmer_party_no", ":center_no", slot_village_farmer_party),
  23229. (gt, ":farmer_party_no", 0),
  23230. (party_is_active, ":farmer_party_no"),
  23231. (store_faction_of_party, ":center_faction", ":center_no"),
  23232. (party_set_faction, ":farmer_party_no", ":center_faction"),
  23233. (try_end),
  23234.  
  23235. (try_begin),
  23236. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  23237. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  23238. (gt, ":lord_troop_id", -1),
  23239.  
  23240. #normal_banner_begin
  23241. (troop_get_slot, ":cur_banner", ":lord_troop_id", slot_troop_banner_scene_prop),
  23242. (gt, ":cur_banner", 0),
  23243. (val_sub, ":cur_banner", banner_scene_props_begin),
  23244. (val_add, ":cur_banner", banner_map_icons_begin),
  23245. (party_set_banner_icon, ":center_no", ":cur_banner"),
  23246. # custom_banner_begin
  23247. # (troop_get_slot, ":flag_icon", ":lord_troop_id", slot_troop_custom_banner_map_flag_type),
  23248. # (ge, ":flag_icon", 0),
  23249. # (val_add, ":flag_icon", custom_banner_map_icons_begin),
  23250. # (party_set_banner_icon, ":center_no", ":flag_icon"),
  23251. (try_end),
  23252.  
  23253. # (try_begin),
  23254. # (eq, 1, 0),
  23255. # (eq, ":lord_troop_id", "trp_player"),
  23256. # (neq, ":old_lord_troop_id", "trp_player"),
  23257. # (party_get_slot, ":center_relation", ":center_no", slot_center_player_relation),
  23258. # (is_between, ":center_relation", -4, 5),
  23259. # (call_script, "script_change_player_relation_with_center", ":center_no", 5),
  23260. # (gt, ":old_lord_troop_id", 0),
  23261. # (call_script, "script_change_player_relation_with_troop", ":old_lord_troop_id", -25),
  23262. # (try_end),
  23263. (try_begin),
  23264. (gt, ":lord_troop_id", -1),
  23265. (call_script, "script_update_troop_notes", ":lord_troop_id"),
  23266. (try_end),
  23267.  
  23268. (call_script, "script_update_center_notes", ":center_no"),
  23269.  
  23270. (try_begin),
  23271. (gt, ":lord_troop_faction", 0),
  23272. (call_script, "script_update_faction_notes", ":lord_troop_faction"),
  23273. (try_end),
  23274.  
  23275. (try_begin),
  23276. (ge, ":old_lord_troop_id", 0),
  23277. (call_script, "script_update_troop_notes", ":old_lord_troop_id"),
  23278. (store_troop_faction, ":old_lord_troop_faction", ":old_lord_troop_id"),
  23279. (call_script, "script_update_faction_notes", ":old_lord_troop_faction"),
  23280. (try_end),
  23281.  
  23282. (try_begin),
  23283. (eq, ":add_garrison", 1),
  23284. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  23285. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  23286. (assign, ":garrison_strength", 3),
  23287. (try_begin),
  23288. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  23289. (assign, ":garrison_strength", 9),
  23290. (try_end),
  23291. (try_for_range, ":unused", 0, ":garrison_strength"),
  23292. (call_script, "script_cf_reinforce_party", ":center_no"),
  23293. (try_end),
  23294. ## ADD some XP initially
  23295. (try_for_range, ":unused", 0, 7),
  23296. (store_mul, ":xp_range_min", 150, ":garrison_strength"),
  23297. (store_mul, ":xp_range_max", 200, ":garrison_strength"),
  23298. (store_random_in_range, ":xp", ":xp_range_min", ":xp_range_max"),
  23299. (party_upgrade_with_xp, ":center_no", ":xp", 0),
  23300. (try_end),
  23301. (try_end),
  23302.  
  23303. (faction_get_slot, ":faction_leader", ":lord_troop_faction", slot_faction_leader),
  23304. (store_current_hours, ":hours"),
  23305.  
  23306. #the next block handles gratitude, objections and jealousies
  23307. (try_begin),
  23308. (gt, ":hours", 0),
  23309. (gt, ":lord_troop_id", 0),
  23310.  
  23311. (call_script, "script_troop_change_relation_with_troop", ":lord_troop_id", ":faction_leader", 10),
  23312. (val_add, "$total_promotion_changes", 10),
  23313.  
  23314. #smaller factions are more dramatically influenced by internal jealousies
  23315. #Disabled as of NOV 2010
  23316. # (try_begin),
  23317. # (neg|faction_slot_ge, ":lord_troop_faction", slot_faction_number_of_parties, 4),
  23318. # (assign, ":faction_size_multiplier", 6),
  23319. # (else_try),
  23320. # (neg|faction_slot_ge, ":lord_troop_faction", slot_faction_number_of_parties, 8),
  23321. # (assign, ":faction_size_multiplier", 5),
  23322. # (else_try),
  23323. # (neg|faction_slot_ge, ":lord_troop_faction", slot_faction_number_of_parties, 16),
  23324. # (assign, ":faction_size_multiplier", 4),
  23325. # (else_try),
  23326. # (neg|faction_slot_ge, ":lord_troop_faction", slot_faction_number_of_parties, 32),
  23327. # (assign, ":faction_size_multiplier", 3),
  23328. # (else_try),
  23329. # (assign, ":faction_size_multiplier", 2),
  23330. # (try_end),
  23331.  
  23332. #factional politics -- each lord in the faction adjusts his relation according to the relation with the lord receiving the faction
  23333. ##diplomacy start+ add support for kingdom ladies
  23334. #(try_for_range, ":other_lord", active_npcs_begin, active_npcs_end),
  23335. (try_for_range, ":other_lord", heroes_begin, heroes_end),
  23336. ##diplomacy end+
  23337. (troop_slot_eq, ":other_lord", slot_troop_occupation, slto_kingdom_hero),
  23338. (neq, ":other_lord", ":lord_troop_id"),
  23339.  
  23340. (store_troop_faction, ":other_troop_faction", ":other_lord"),
  23341. (eq, ":lord_troop_faction", ":other_troop_faction"),
  23342.  
  23343. (neq, ":other_lord", ":faction_leader"),
  23344.  
  23345. (call_script, "script_troop_get_relation_with_troop", ":other_lord", ":lord_troop_id"),
  23346. (assign, ":relation_with_troop", reg0),
  23347.  
  23348. #relation reduction = relation/10 minus 2. So,0 = -2, 8 = -1, 16+ = no change or bonus, 24+ gain one point
  23349. (store_div, ":relation_with_liege_change", ":relation_with_troop", 8), #changed from 16
  23350. (val_sub, ":relation_with_liege_change", 2),
  23351.  
  23352. (val_clamp, ":relation_with_liege_change", -5, 3),
  23353.  
  23354. (try_begin),
  23355. #upstanding and goodnatured lords will not lose relation unless they actively dislike the other lord
  23356. (this_or_next|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_upstanding),
  23357. ##diplomacy start+ add companion/lady personality types
  23358. (this_or_next|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_benefactor),
  23359. (this_or_next|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_conventional),
  23360. (this_or_next|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_moralist),
  23361. (this_or_next|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_otherworldly),
  23362. ##diplomacy end+
  23363. (troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_goodnatured),
  23364. (ge, ":relation_with_troop", 0),
  23365. (val_max, ":relation_with_liege_change", 0),
  23366. (else_try),
  23367. #penalty is increased for lords who have the more unpleasant reputation types
  23368. (this_or_next|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_selfrighteous),
  23369. (this_or_next|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_debauched),
  23370. (troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_quarrelsome),
  23371. (lt, ":relation_with_liege_change", 0),
  23372. (val_mul, ":relation_with_liege_change", 3),
  23373. (val_div, ":relation_with_liege_change", 2),
  23374. (try_end),
  23375. ##diplomacy start+
  23376.  
  23377. #TODO (idea for "high"): instead of being absolute, the sliding score system should be used.
  23378. #(So you can use a score instead of using relations.) The greater the
  23379. #difference in score, the greater the relation loss -- so if the lord
  23380. #was nearly indifferent between two candidates, the difference would be
  23381. #lesser.
  23382. (try_begin),
  23383. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  23384. (try_begin),
  23385. #Optional change: Non-jerkish lords will not object to giving a village to
  23386. #someone fiefless, unless they dislike him.
  23387. (neg|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_debauched),
  23388. (neg|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_selfrighteous),
  23389. (neg|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_quarrelsome),
  23390. (lt, ":relation_with_liege_change", 0),
  23391. (is_between, ":center_no", villages_begin, villages_end),
  23392. (troop_slot_eq, ":lord_troop_id", slot_troop_temp_slot, 0),
  23393. (ge, ":relation_with_troop", 0),
  23394. (val_max, ":relation_with_liege_change", 0),
  23395. (try_end),
  23396. (try_begin),
  23397. #Optional change: because taking a penalty for 'thrashing' the same fief
  23398. #back and forth is silly, if you're giving the fief back to the lord who
  23399. #last had it, reduce any penalty.
  23400. (lt, ":relation_with_liege_change", 0),
  23401. (party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, ":lord_troop_id"),
  23402. (neq, ":lord_troop_id", 0),
  23403. (val_add, ":relation_with_liege_change", 1),
  23404.  
  23405. #If the other lord doesn't have any claim of his own on the center,
  23406. #attenuate the penalty more.
  23407. (lt, ":relation_with_liege_change", 0),
  23408. (ge, ":relation_with_troop", 0),
  23409. (neg|party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":other_lord"),
  23410. (neg|troop_slot_eq, ":other_lord", slot_troop_home, ":center_no"),
  23411. (this_or_next|neg|troop_slot_ge, ":other_lord", slot_troop_stance_on_faction_issue, 0),
  23412. (neg|party_slot_eq, ":center_no", slot_center_last_taken_by_troop, ":other_lord"),
  23413. (val_add, ":relation_with_liege_change", 1),
  23414. (else_try),
  23415. #Similar logic, but for "original lord" instead of most recent lord
  23416. (lt, ":relation_with_liege_change", 0),
  23417. (neg|party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, ":lord_troop_id"),#don't apply this if the above "ex-center" check was applied
  23418. (this_or_next|party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":lord_troop_id"),
  23419. (troop_slot_eq, ":lord_troop_id", slot_troop_home, ":center_no"),
  23420.  
  23421. #Only attenuate the panelty if the other lord doesn't have any claim of his own on the center
  23422. (ge, ":relation_with_troop", 0),
  23423. (neg|troop_slot_eq, ":other_lord", slot_troop_home, ":center_no"),
  23424. (neg|party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":other_lord"),
  23425. (neg|party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, ":other_lord"),
  23426. (this_or_next|neg|troop_slot_ge, ":other_lord", slot_troop_stance_on_faction_issue, 0),
  23427. (neg|party_slot_eq, ":center_no", slot_center_last_taken_by_troop, ":other_lord"),
  23428.  
  23429. (val_add, ":relation_with_liege_change", 1),
  23430. (try_end),
  23431. (try_begin),
  23432. #On the minus side, lords whose homes and/or original fiefs are not
  23433. #disposed according to their wishes are that much more cross.
  23434. (lt, ":relation_with_liege_change", 1),
  23435. (this_or_next|party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, ":other_lord"),
  23436. (this_or_next|party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":other_lord"),
  23437. (troop_slot_eq, ":other_lord", slot_troop_home, ":center_no"),
  23438. (val_sub, ":relation_with_liege_change", 1),
  23439. (else_try),
  23440. #Optional change: martial lords are less displeased by awarding a fief to
  23441. #the one who conquered it.
  23442. (lt, ":relation_with_liege_change", 0),
  23443. (party_slot_eq, ":center_no", slot_center_last_taken_by_troop, ":lord_troop_id"),
  23444. (this_or_next|troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_upstanding),
  23445. (troop_slot_eq, ":other_lord", slot_lord_reputation_type, lrep_martial),
  23446. (val_add, ":relation_with_liege_change", 1),
  23447. (try_end),
  23448. (try_end),
  23449. ##diplomacy end+
  23450.  
  23451. (neq, ":relation_with_liege_change", 0),
  23452. #removed Nov 2010
  23453. # (val_mul, ":relation_reduction", ":faction_size_multiplier"),
  23454. # (val_div, ":relation_reduction", 2),
  23455. #removed Nov 2010
  23456.  
  23457. (try_begin),
  23458. (troop_slot_eq, ":other_lord", slot_troop_stance_on_faction_issue, ":lord_troop_id"),
  23459. (val_add, ":relation_with_liege_change", 1),
  23460. (val_max, ":relation_with_liege_change", 1),
  23461. (try_end),
  23462.  
  23463. (call_script, "script_troop_change_relation_with_troop", ":other_lord", ":faction_leader", ":relation_with_liege_change"),
  23464. (val_add, "$total_promotion_changes", ":relation_with_liege_change"),
  23465.  
  23466. (try_begin),
  23467. (this_or_next|le, ":relation_with_liege_change", -4), #Nov 2010 - changed from -8
  23468. (this_or_next|troop_slot_eq, ":other_lord", slot_troop_promised_fief, 1), #1 is any fief
  23469. (troop_slot_eq, ":other_lord", slot_troop_promised_fief, ":center_no"),
  23470. (call_script, "script_add_log_entry", logent_troop_feels_cheated_by_troop_over_land, ":other_lord", ":center_no", ":lord_troop_id", ":lord_troop_faction"),
  23471. (try_end),
  23472.  
  23473. (try_end),
  23474. (try_end),
  23475.  
  23476. ##diplomacy start+ invalidate cached center points
  23477. (try_begin),
  23478. (neq, ":old_lord_troop_id", ":lord_troop_id"),
  23479. (try_begin),
  23480. (gt, ":old_lord_troop_id", -1),
  23481. (troop_set_slot, ":old_lord_troop_id", dplmc_slot_troop_center_points_plus_one, 0),
  23482. (try_end),
  23483. (try_begin),
  23484. (gt, ":lord_troop_id", -1),
  23485. (troop_set_slot, ":lord_troop_id", dplmc_slot_troop_center_points_plus_one, 0),
  23486. (try_end),
  23487. (try_end),
  23488. ##diplomacy end+
  23489.  
  23490. #Villages from another faction will also be transferred along with a fortress
  23491. (try_begin),
  23492. (is_between, ":center_no", walled_centers_begin, walled_centers_end),
  23493. (try_for_range, ":cur_village", villages_begin, villages_end),
  23494. (party_slot_eq, ":cur_village", slot_village_bound_center, ":center_no"),
  23495. (store_faction_of_party, ":cur_village_faction", ":cur_village"),
  23496. (neq, ":cur_village_faction", ":lord_troop_faction"),
  23497.  
  23498. (call_script, "script_give_center_to_lord", ":cur_village", ":lord_troop_id", 0),
  23499. (try_end),
  23500. (try_end),
  23501. ]),
  23502.  
  23503. ## # script_give_town_to_besiegers
  23504. ## # Input: arg1 = center_no, arg2 = besieger_party
  23505. ## ("give_town_to_besiegers",
  23506. ## [
  23507. ## (store_script_param_1, ":center_no"),
  23508. ## (store_script_param_2, ":besieger_party"),
  23509. ## (store_faction_of_party, ":besieger_faction", ":besieger_party"),
  23510. ##
  23511. ## (try_begin),
  23512. ## (call_script, "script_cf_get_party_leader", ":besieger_party"),
  23513. ## (assign, ":new_leader", reg0),
  23514. ## (else_try),
  23515. ## (call_script, "script_select_kingdom_hero_for_new_center", ":besieger_faction"),
  23516. ## (assign, ":new_leader", reg0),
  23517. ## (try_end),
  23518. ##
  23519. ## (call_script, "script_give_center_to_lord", ":center_no", ":new_leader"),
  23520. ##
  23521. ## (try_for_parties, ":party_no"),
  23522. ## (get_party_ai_object, ":object", ":party_no"),
  23523. ## (get_party_ai_behavior, ":behavior", ":party_no"),
  23524. ## (eq, ":object", ":center_no"),
  23525. ## (this_or_next|eq, ":behavior", ai_bhvr_travel_to_party),
  23526. ## (eq, ":behavior", ai_bhvr_attack_party),
  23527. ## (party_set_ai_behavior, ":party_no", ai_bhvr_hold),
  23528. ## (party_set_slot, ":party_no", slot_party_ai_state, spai_undefined),
  23529. ## (party_set_flags, ":party_no", pf_default_behavior, 0),
  23530. ## (try_end),
  23531. ##
  23532. ## #Staying at the center for a while
  23533. ## (party_set_ai_behavior, ":besieger_party", ai_bhvr_hold),
  23534. ## (party_set_slot, ":besieger_party", slot_party_ai_state, spai_undefined),
  23535. ## (party_set_flags, ":besieger_party", pf_default_behavior, 0),
  23536. ##
  23537. ## (faction_get_slot, ":reinforcement_a", ":besieger_faction", slot_faction_reinforcements_a),
  23538. ## (faction_get_slot, ":reinforcement_b", ":besieger_faction", slot_faction_reinforcements_b),
  23539. ## (party_add_template, ":center_no", ":reinforcement_a"),
  23540. ## (party_add_template, ":center_no", ":reinforcement_b"),
  23541. ## ]),
  23542. ##
  23543.  
  23544. # script_get_number_of_hero_centers
  23545. # Input: arg1 = troop_no
  23546. # Output: reg0 = number of centers that are ruled by the hero
  23547. ("get_number_of_hero_centers",
  23548. [
  23549. (store_script_param_1, ":troop_no"),
  23550. (assign, ":result", 0),
  23551. (try_for_range, ":center_no", centers_begin, centers_end),
  23552. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  23553. (val_add, ":result", 1),
  23554. (try_end),
  23555. (assign, reg0, ":result"),
  23556. ]),
  23557.  
  23558.  
  23559. ## # script_cf_get_new_center_leader_chance_for_troop
  23560. ## # Input: arg1 = troop_no
  23561. ## # Output: reg0 = chance of the troop to rule a new center
  23562. ## ("cf_get_new_center_leader_chance_for_troop",
  23563. ## [
  23564. ## (store_script_param_1, ":troop_no"),
  23565. ## (troop_get_slot, ":troop_rank", ":troop_no", slot_troop_kingdom_rank),
  23566. ## (try_begin),
  23567. ## (eq, ":troop_rank", 4),
  23568. ## (assign, ":troop_chance", 1000),
  23569. ## (else_try),
  23570. ## (eq, ":troop_rank", 3),
  23571. ## (assign, ":troop_chance", 800),
  23572. ## (else_try),
  23573. ## (eq, ":troop_rank", 2),
  23574. ## (assign, ":troop_chance", 400),
  23575. ## (else_try),
  23576. ## (eq, ":troop_rank", 1),
  23577. ## (assign, ":troop_chance", 100),
  23578. ## (else_try),
  23579. ## (assign, ":troop_chance", 10),
  23580. ## (try_end),
  23581. ##
  23582. ## (call_script, "script_get_number_of_hero_centers", ":troop_no"),
  23583. ## (assign, ":number_of_hero_centers", reg0),
  23584. ## (try_begin),
  23585. ## (gt, ":number_of_hero_centers", 0),
  23586. ## (val_mul, ":number_of_hero_centers", 2),
  23587. ## (val_mul, ":number_of_hero_centers", ":number_of_hero_centers"),
  23588. ## (val_div, ":troop_chance", ":number_of_hero_centers"),
  23589. ## (try_end),
  23590. ## (assign, reg0, ":troop_chance"),
  23591. ## (eq, reg0, 0),
  23592. ## (assign, reg0, 1),
  23593. ## ]),
  23594.  
  23595.  
  23596. ## # script_select_kingdom_hero_for_new_center
  23597. ## # Input: arg1 = faction_no
  23598. ## # Output: reg0 = troop_no as the new leader
  23599. ## ("select_kingdom_hero_for_new_center",
  23600. ## [
  23601. ## (store_script_param_1, ":kingdom"),
  23602. ##
  23603. ## (assign, ":min_num_centers", -1),
  23604. ## (assign, ":min_num_centers_troop", -1),
  23605. ##
  23606. ## (try_for_range, ":troop_no", kingdom_heroes_begin, kingdom_heroes_end),
  23607. ## (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  23608. ## (store_troop_faction, ":troop_faction", ":troop_no"),
  23609. ## (eq, ":troop_faction", ":kingdom"),
  23610. ## (call_script, "script_get_number_of_hero_centers", ":troop_no"),
  23611. ## (assign, ":num_centers", reg0),
  23612. ## (try_begin),
  23613. ## (lt, ":num_centers", ":min_num_centers"),
  23614. ## (assign, ":min_num_centers", ":num_centers"),
  23615. ## (assign, ":min_num_centers_troop", ":troop_no"),
  23616. ## (try_end),
  23617. ## (try_end),
  23618. ## (assign, reg0, ":min_num_centers_troop"),
  23619. ## ]),
  23620.  
  23621.  
  23622. # script_cf_get_random_enemy_center
  23623. # Input: arg1 = party_no
  23624. # Output: reg0 = center_no
  23625. ("cf_get_random_enemy_center",
  23626. [
  23627. (store_script_param_1, ":party_no"),
  23628.  
  23629. (assign, ":result", -1),
  23630. (assign, ":total_enemy_centers", 0),
  23631. (store_faction_of_party, ":party_faction", ":party_no"),
  23632.  
  23633. (try_for_range, ":center_no", centers_begin, centers_end),
  23634. (store_faction_of_party, ":center_faction", ":center_no"),
  23635. (store_relation, ":party_relation", ":center_faction", ":party_faction"),
  23636. (lt, ":party_relation", 0),
  23637. (val_add, ":total_enemy_centers", 1),
  23638. (try_end),
  23639.  
  23640. (gt, ":total_enemy_centers", 0),
  23641. (store_random_in_range, ":random_center", 0, ":total_enemy_centers"),
  23642. (assign, ":total_enemy_centers", 0),
  23643. (try_for_range, ":center_no", centers_begin, centers_end),
  23644. (eq, ":result", -1),
  23645. (store_faction_of_party, ":center_faction", ":center_no"),
  23646. (store_relation, ":party_relation", ":center_faction", ":party_faction"),
  23647. (lt, ":party_relation", 0),
  23648. (val_sub, ":random_center", 1),
  23649. (lt, ":random_center", 0),
  23650. (assign, ":result", ":center_no"),
  23651. (try_end),
  23652. (assign, reg0, ":result"),
  23653. ]),
  23654.  
  23655.  
  23656. ## # script_get_random_enemy_town
  23657. ## # Input: arg1 = party_no
  23658. ## # Output: reg0 = center_no
  23659. ## ("get_random_enemy_town",
  23660. ## [
  23661. ## (store_script_param_1, ":party_no"),
  23662. ##
  23663. ## (assign, ":result", -1),
  23664. ## (assign, ":total_enemy_centers", 0),
  23665. ## (store_faction_of_party, ":party_faction", ":party_no"),
  23666. ##
  23667. ## (try_for_range, ":center_no", towns_begin, towns_end),
  23668. ## (store_faction_of_party, ":center_faction", ":center_no"),
  23669. ## (neq, ":center_faction", ":party_faction"),
  23670. ## (val_add, ":total_enemy_centers", 1),
  23671. ## (try_end),
  23672. ##
  23673. ## (try_begin),
  23674. ## (eq, ":total_enemy_centers", 0),
  23675. ## (else_try),
  23676. ## (store_random_in_range, ":random_center", 0, ":total_enemy_centers"),
  23677. ## (assign, ":total_enemy_centers", 0),
  23678. ## (try_for_range, ":center_no", towns_begin, towns_end),
  23679. ## (eq, ":result", -1),
  23680. ## (store_faction_of_party, ":center_faction", ":center_no"),
  23681. ## (neq, ":center_faction", ":party_faction"),
  23682. ## (store_relation, ":party_relation", ":center_faction", ":party_faction"),
  23683. ## (le, ":party_relation", -10),
  23684. ## (val_add, ":total_enemy_centers", 1),
  23685. ## (lt, ":random_center", ":total_enemy_centers"),
  23686. ## (assign, ":result", ":center_no"),
  23687. ## (try_end),
  23688. ## (try_end),
  23689. ## (assign, reg0, ":result"),
  23690. ## ]),
  23691.  
  23692.  
  23693.  
  23694. # script_find_travel_location
  23695. # Input: arg1 = center_no
  23696. # Output: reg0 = new_center_no (to travel within the same faction)
  23697. ("find_travel_location",
  23698. [
  23699. (store_script_param_1, ":center_no"),
  23700. (store_faction_of_party, ":faction_no", ":center_no"),
  23701. (assign, ":total_weight", 0),
  23702. (try_for_range, ":cur_center_no", centers_begin, centers_end),
  23703. (neq, ":center_no", ":cur_center_no"),
  23704. (store_faction_of_party, ":center_faction_no", ":cur_center_no"),
  23705. (eq, ":faction_no", ":center_faction_no"),
  23706.  
  23707. (store_distance_to_party_from_party, ":cur_distance", ":center_no", ":cur_center_no"),
  23708. (val_add, ":cur_distance", 1),
  23709.  
  23710. (assign, ":new_weight", 100000),
  23711. (val_div, ":new_weight", ":cur_distance"),
  23712. (val_add, ":total_weight", ":new_weight"),
  23713. (try_end),
  23714.  
  23715. (assign, reg0, -1),
  23716.  
  23717. (try_begin),
  23718. (eq, ":total_weight", 0),
  23719. (else_try),
  23720. (store_random_in_range, ":random_weight", 0 , ":total_weight"),
  23721. (assign, ":total_weight", 0),
  23722. (assign, ":done", 0),
  23723. (try_for_range, ":cur_center_no", centers_begin, centers_end),
  23724. (eq, ":done", 0),
  23725. (neq, ":center_no", ":cur_center_no"),
  23726. (store_faction_of_party, ":center_faction_no", ":cur_center_no"),
  23727. (eq, ":faction_no", ":center_faction_no"),
  23728.  
  23729. (store_distance_to_party_from_party, ":cur_distance", ":center_no", ":cur_center_no"),
  23730. (val_add, ":cur_distance", 1),
  23731.  
  23732. (assign, ":new_weight", 100000),
  23733. (val_div, ":new_weight", ":cur_distance"),
  23734. (val_add, ":total_weight", ":new_weight"),
  23735. (lt, ":random_weight", ":total_weight"),
  23736. (assign, reg0, ":cur_center_no"),
  23737. (assign, ":done", 1),
  23738. (try_end),
  23739. (try_end),
  23740. ]),
  23741.  
  23742.  
  23743. # script_get_relation_between_parties
  23744. # Input: arg1 = party_no_1, arg2 = party_no_2
  23745. # Output: reg0 = relation between parties
  23746. ("get_relation_between_parties",
  23747. [
  23748. (store_script_param_1, ":party_no_1"),
  23749. (store_script_param_2, ":party_no_2"),
  23750.  
  23751. (store_faction_of_party, ":party_no_1_faction", ":party_no_1"),
  23752. (store_faction_of_party, ":party_no_2_faction", ":party_no_2"),
  23753. (try_begin),
  23754. (eq, ":party_no_1_faction", ":party_no_2_faction"),
  23755. (assign, reg0, 100),
  23756. (else_try),
  23757. (store_relation, ":relation", ":party_no_1_faction", ":party_no_2_faction"),
  23758. (assign, reg0, ":relation"),
  23759. (try_end),
  23760. ]),
  23761. # script_calculate_weekly_party_wage
  23762. # Input: arg1 = party_no
  23763. # Output: reg0 = weekly wage
  23764. ("calculate_weekly_party_wage",
  23765. [
  23766. (store_script_param_1, ":party_no"),
  23767.  
  23768. (assign, ":result", 0),
  23769. (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  23770. (try_for_range, ":i_stack", 0, ":num_stacks"),
  23771. (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  23772. (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  23773. (call_script, "script_npc_get_troop_wage", ":stack_troop", ":party_no"),
  23774. (assign, ":cur_wage", reg0),
  23775. (val_mul, ":cur_wage", ":stack_size"),
  23776. (val_add, ":result", ":cur_wage"),
  23777. (try_end),
  23778. (assign, reg0, ":result"),
  23779. ]),
  23780.  
  23781. # script_calculate_player_faction_wage
  23782. # Input: arg1 = party_no
  23783. # Output: reg0 = weekly wage
  23784. ("calculate_player_faction_wage",
  23785. [(assign, ":nongarrison_wages", 0),
  23786. (assign, ":garrison_wages", 0),
  23787. (try_for_parties, ":party_no"),
  23788. (assign, ":garrison_troop", 0),
  23789. (try_begin),
  23790. (this_or_next|party_slot_eq, ":party_no", slot_party_type, spt_town),
  23791. (party_slot_eq, ":party_no", slot_party_type, spt_castle),
  23792. (party_slot_eq, ":party_no", slot_town_lord, "trp_player"),
  23793. (assign, ":garrison_troop", 1),
  23794. (try_end),
  23795. (this_or_next|eq, ":party_no", "p_main_party"),
  23796. (eq, ":garrison_troop", 1),
  23797. (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  23798. (try_for_range, ":i_stack", 0, ":num_stacks"),
  23799. (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  23800. (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  23801. (call_script, "script_game_get_troop_wage", ":stack_troop", ":party_no"),
  23802. (assign, ":cur_wage", reg0),
  23803. (val_mul, ":cur_wage", ":stack_size"),
  23804. (try_begin),
  23805. (eq, ":garrison_troop", 1),
  23806. (val_add, ":garrison_wages", ":cur_wage"),
  23807. (else_try),
  23808. (val_add, ":nongarrison_wages", ":cur_wage"),
  23809. (try_end),
  23810. (try_end),
  23811. (try_end),
  23812. (val_div, ":garrison_wages", 2),#Half payment for garrisons
  23813. (store_sub, ":total_payment", 14, "$g_cur_week_half_daily_wage_payments"), #between 0 and 7
  23814. (val_mul, ":nongarrison_wages", ":total_payment"),
  23815. (val_div, ":nongarrison_wages", 14),
  23816. ##diplomacy start+ centralization affects this in the player's kingdom
  23817. ###xxx TODO: This appears to be missing.
  23818. ##diplomacy end+
  23819. (store_add, reg0, ":nongarrison_wages", ":garrison_wages"),
  23820. ]),
  23821.  
  23822. # script_calculate_hero_weekly_net_income_and_add_to_wealth
  23823. # Input: arg1 = troop_no
  23824. # Output: none
  23825. ("calculate_hero_weekly_net_income_and_add_to_wealth",
  23826. [
  23827. (store_script_param_1, ":troop_no"),
  23828.  
  23829. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  23830. (troop_get_slot, ":cur_wealth", ":troop_no", slot_troop_wealth),
  23831.  
  23832. (assign, ":weekly_income", 750), #let every hero receive 750 denars by default
  23833.  
  23834. (store_character_level, ":troop_level", ":troop_no"),
  23835. (store_mul, ":level_income", ":troop_level", 10),
  23836. (val_add, ":weekly_income", ":level_income"),
  23837.  
  23838. (store_troop_faction,":faction_no", ":troop_no"),
  23839.  
  23840. ##diplomacy start+
  23841. #Bonus for marshall and/or faction leader (is 1000 in native)
  23842. (assign, ":leader_bonus_gold", 1000),
  23843. (assign, ":bonus_applied", 0),
  23844. (try_begin),
  23845. #OPTIONAL CHANGE (HIGH)
  23846. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_HIGH),
  23847. #Scale marshall and king bonus gold by number of remaining kingdoms,
  23848. #so the total amount paid out remains the same even as kingdoms disappear.
  23849. #This is only enabled if changes are on "HIGH".
  23850. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  23851. (store_sub, ":original_kingdoms", npc_kingdoms_end, npc_kingdoms_begin),#deliberately excludes player kingdom
  23852. (ge, ":original_kingdoms", 2),
  23853. (assign, ":current_kingdoms", 0),
  23854. (try_for_range, ":other_fac", kingdoms_begin, kingdoms_end),#deliberately include player kingdom
  23855. (faction_slot_eq, ":other_fac", slot_faction_state, sfs_active),
  23856. (val_add, ":current_kingdoms", 1),
  23857. (try_end),
  23858. (ge, ":current_kingdoms", 1),
  23859. (lt, ":current_kingdoms", ":original_kingdoms"),
  23860. (val_mul, ":leader_bonus_gold", ":original_kingdoms"),
  23861. (val_div, ":leader_bonus_gold", ":current_kingdoms"),
  23862. #Examples, assuming 6 starting kingdoms and no player kingdom:
  23863. #6 kingdoms: 1000 each, 1000 * 6 = 6000 total
  23864. #5 kingdoms: 1200 each, 1200 * 5 = 6000 total
  23865. #4 kingdoms: 1500 each, 1500 * 4 = 6000 total
  23866. #3 kingdoms: 2000 each, 2000 * 3 = 6000 total
  23867. #2 kingdoms: 3000 each, 3000 * 2 = 6000 total
  23868. #1 kingdom: 6000 each, 6000 * 1 = 6000 total
  23869. (try_end),
  23870. ##diplomacy end+
  23871.  
  23872. (try_begin), #check if troop is kingdom leader
  23873. (faction_slot_eq, ":faction_no", slot_faction_leader, ":troop_no"),
  23874. ##diplomacy start+
  23875. #OLD BEHAVIOR:
  23876. #(val_add, ":weekly_income", 1000),
  23877. #NEW BEHAVIOR:
  23878. (val_add, ":weekly_income", ":leader_bonus_gold"),
  23879. (val_add, ":bonus_applied", 1),
  23880. ##diplomacy end+
  23881. (try_end),
  23882.  
  23883. (try_begin), #check if troop is marshall
  23884. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  23885. ##diplomacy start+
  23886. #OLD BEHAVIOR:
  23887. #(val_add, ":weekly_income", 1000),
  23888. #NEW BEHAVIOR:
  23889. (val_add, ":weekly_income", ":leader_bonus_gold"),
  23890. (val_add, ":bonus_applied", 1),
  23891. ##diplomacy end+
  23892. (try_end),
  23893.  
  23894. ##diplomacy start+
  23895. (try_begin),
  23896. #OPTIONAL CHANGE (MEDIUM)
  23897. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),
  23898. #If the lord is the spouse of the faction leader and no better bonus
  23899. #applied, the lord gets half of the bonus if either (1) there is no
  23900. #marshall, or (2) the faction leader is the player.
  23901. (eq, ":bonus_applied", 0),
  23902. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  23903. #Don't do the usual polygamy check: the bonus only applies to
  23904. #one of the spouses.
  23905. (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  23906. (ge, ":faction_leader", 0),
  23907. (troop_slot_eq, ":faction_leader", slot_troop_spouse, ":troop_no"),
  23908. #Don't apply the bonus unless the faction leader bonus is going
  23909. #all/partially uncollected, or the marshal bonus is going uncollected.
  23910. (this_or_next|neg|faction_slot_ge, ":faction_no", slot_faction_marshall, 0),
  23911. (eq, ":faction_leader", "trp_player"),
  23912. #Apply bonus
  23913. (val_add, ":bonus_applied", 1),
  23914. (store_div, reg0, ":leader_bonus_gold", 2),
  23915. (val_add, ":weekly_income", reg0),
  23916. (try_end),
  23917. ##diplomacy end+
  23918.  
  23919. (assign, ":cur_weekly_wage", 0),
  23920. (try_begin),
  23921. (gt, ":party_no",0),
  23922. (call_script, "script_calculate_weekly_party_wage", ":party_no"),
  23923. (assign, ":cur_weekly_wage", reg0),
  23924. (try_end),
  23925. ##diplomacy start+
  23926. (try_begin),
  23927. #take into account leader's leadership skill, like in CC
  23928. #economics changes must be enabled
  23929. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_HIGH),
  23930. (store_skill_level, ":leadership_level", "skl_leadership", ":troop_no"),
  23931. (val_clamp, ":leadership_level", 0, 11),
  23932. (store_mul, ":leadership_bonus", 5, ":leadership_level"),
  23933. (store_sub, ":leadership_factor", 100, ":leadership_bonus"),
  23934. (val_mul, ":cur_weekly_wage", ":leadership_factor"), #wage = wage * (100 - 5*leadership)/100
  23935. (val_div, ":cur_weekly_wage", 100),
  23936. (try_end),
  23937.  
  23938. #Store the change in income for use below
  23939. (store_sub, ":net_income", ":weekly_income", ":cur_weekly_wage"),
  23940. ##diplomacy end+
  23941. (val_sub, ":weekly_income", ":cur_weekly_wage"),
  23942.  
  23943. (val_add, ":cur_wealth", ":weekly_income"),
  23944.  
  23945. (try_begin),
  23946. (lt, ":cur_wealth", 0),
  23947. (store_sub, ":percent_under", 0, ":cur_wealth"),
  23948. (val_mul, ":percent_under", 100),
  23949. (val_div, ":percent_under", ":cur_weekly_wage"),
  23950. (val_div, ":percent_under", 5), #Max 20 percent
  23951. ##diplomacy start+
  23952. #The above assumption could be violated if the lord entered this
  23953. #script with a negative wealth. Add a failsafe.
  23954. (val_clamp, ":percent_under", 0, 21),
  23955. ##diplomacy end+
  23956. (call_script, "script_party_inflict_attrition", ":party_no", ":percent_under", 1),
  23957. (try_end),
  23958.  
  23959. ##diplomacy start+
  23960. #Apply gold change
  23961. (try_begin),
  23962. #If the wealth change was positive, some of it may go to the lord's holdings.
  23963. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_HIGH),
  23964. (ge, ":net_income", 1),
  23965. (call_script, "script_dplmc_distribute_gold_to_lord_and_holdings", ":net_income", ":troop_no"),
  23966. (else_try),
  23967. #Fall through to old version:
  23968. #OLD VERSION:
  23969. (val_max, ":cur_wealth", 0),
  23970. (troop_set_slot, ":troop_no", slot_troop_wealth, ":cur_wealth"),
  23971. (try_end),
  23972. ##diplomacy end+
  23973. ]),
  23974.  
  23975. # script_cf_reinforce_party
  23976. # Input: arg1 = party_no,
  23977. # Output: none
  23978. # Adds reinforcement to party according to its type and faction
  23979. # Called from several places, simple_triggers for centers, script_hire_men_to_kingdom_hero_party for hero parties
  23980. ("cf_reinforce_party",
  23981. [
  23982. (store_script_param_1, ":party_no"),
  23983.  
  23984. (store_faction_of_party, ":party_faction", ":party_no"),
  23985. ##diplomacy start+ The party faction may be changed for culture, but we still need the original
  23986. (assign, ":real_party_faction", ":party_faction"),
  23987. ##diplomacy end+
  23988. (party_get_slot, ":party_type",":party_no", slot_party_type),
  23989.  
  23990. #Rebellion changes begin:
  23991. (try_begin),
  23992. (eq, ":party_type", spt_kingdom_hero_party),
  23993. (party_stack_get_troop_id, ":leader", ":party_no"),
  23994. (troop_get_slot, ":party_faction", ":leader", slot_troop_original_faction),
  23995. ##diplomacy start+ Use player culture for companions and spouse (and any hypothetical non-hero mercenaries)
  23996. (eq, ":real_party_faction", "fac_player_supporters_faction"),
  23997. (is_between, "$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  23998. (this_or_next|is_between, ":leader", companions_begin, companions_end),
  23999. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, ":leader"),
  24000. (neg|is_between, ":leader", heroes_begin, heroes_end),
  24001. (assign, ":party_faction", "$g_player_culture"),
  24002. ##diplomacy end+
  24003. (try_end),
  24004. #Rebellion changes end
  24005.  
  24006. (try_begin),
  24007. #SB : this block checks for town lords, which is invalid for kingdom parties
  24008. (is_between, ":party_type", spt_castle, spt_village),
  24009. (eq, ":party_faction", "fac_player_supporters_faction"),
  24010. (party_get_slot, ":town_lord", ":party_no", slot_town_lord),
  24011. (try_begin),
  24012. ##diplomacy begin
  24013. (is_between, "$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  24014. (assign, ":party_faction", "$g_player_culture"),
  24015.  
  24016. # (try_begin), #debug
  24017. # (eq, "$cheat_mode", 1),
  24018. # (str_store_party_name, s11, ":party_no"),
  24019. # (display_message, "@pt in {s11}"),
  24020. # (try_end),
  24021.  
  24022. (else_try),
  24023. ##diplomacy end
  24024. (gt, ":town_lord", 0),
  24025. (troop_get_slot, ":party_faction", ":town_lord", slot_troop_original_faction),
  24026. (gt, ":party_faction", 0), ## CC
  24027. (else_try),
  24028. (party_get_slot, ":party_faction", ":party_no", slot_center_original_faction),
  24029. (try_end),
  24030. (try_end),
  24031. ##diplomacy start+ Player culture cleanup (do this once here, instead of separately for each type)
  24032. (try_begin),
  24033. (gt, ":real_party_faction", "fac_commoners"),
  24034. (this_or_next|eq, ":real_party_faction", "fac_player_faction"),
  24035. (this_or_next|eq, ":real_party_faction", "fac_player_supporters_faction"),
  24036. (eq, ":real_party_faction", "$players_kingdom"),
  24037. (neg|is_between, ":party_faction", npc_kingdoms_begin, npc_kingdoms_end),
  24038. (is_between, "$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  24039. (assign, ":party_faction", "$g_player_culture"),
  24040. (try_end),
  24041. ##diplomacy end+
  24042.  
  24043. (faction_get_slot, ":party_template_a", ":party_faction", slot_faction_reinforcements_a),
  24044. (faction_get_slot, ":party_template_b", ":party_faction", slot_faction_reinforcements_b),
  24045. (faction_get_slot, ":party_template_c", ":party_faction", slot_faction_reinforcements_c),
  24046.  
  24047. (assign, ":party_template", 0),
  24048. (store_random_in_range, ":rand", 0, 100),
  24049. ##diplomacy start+
  24050. #Implement "quality vs. quantity" in a way that is visible in player battles
  24051. #(previously, quantity increased party size, but quality only had an effect
  24052. #in autocalc battles)
  24053. (try_begin),
  24054. (is_between, ":real_party_faction", kingdoms_begin, kingdoms_end),
  24055. (faction_get_slot, ":dplmc_quality", ":real_party_faction", dplmc_slot_faction_quality),
  24056. (val_clamp, ":dplmc_quality", -3, 4),
  24057. (val_add, ":rand", ":dplmc_quality"),
  24058. (val_clamp, ":rand", 0, 101),
  24059. (try_end),
  24060. ##diplomacy end+
  24061. (try_begin),
  24062. (this_or_next|eq, ":party_type", spt_town),
  24063. (eq, ":party_type", spt_castle), #CASTLE OR TOWN
  24064. (try_begin),
  24065. (lt, ":rand", 65),
  24066. (assign, ":party_template", ":party_template_a"),
  24067. (else_try),
  24068. (assign, ":party_template", ":party_template_b"),
  24069. (try_end),
  24070. (else_try),
  24071. (eq, ":party_type", spt_kingdom_hero_party),
  24072. (try_begin),
  24073. (lt, ":rand", 50),
  24074. (assign, ":party_template", ":party_template_a"),
  24075. (else_try),
  24076. (lt, ":rand", 75),
  24077. (assign, ":party_template", ":party_template_b"),
  24078. (else_try),
  24079. (assign, ":party_template", ":party_template_c"),
  24080. (try_end),
  24081. (else_try),
  24082. ##diplomacy start+ Reinforcements for patrols
  24083. (this_or_next|eq, ":party_type", spt_patrol),
  24084. (eq, ":party_type", spt_reinforcement), #SB : add more reinf if necessary
  24085. (try_begin),
  24086. (lt, ":rand", 65),
  24087. (assign, ":party_template", ":party_template_a"),
  24088. (else_try),
  24089. (assign, ":party_template", ":party_template_b"),
  24090. (try_end),
  24091. ##diplomacy end+
  24092. (try_end),
  24093.  
  24094. (try_begin),
  24095. (gt, ":party_template", 0),
  24096. (party_add_template, ":party_no", ":party_template"),
  24097. (try_end),
  24098. ]),
  24099.  
  24100. # script_hire_men_to_kingdom_hero_party
  24101. # Input: arg1 = troop_no (hero of the party)
  24102. # Output: none
  24103. ("hire_men_to_kingdom_hero_party",
  24104. [
  24105. (store_script_param_1, ":troop_no"),
  24106.  
  24107. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  24108. (troop_get_slot, ":cur_wealth", ":troop_no", slot_troop_wealth),
  24109.  
  24110. #while hiring reinforcements party leaders can only use 3/4 of their budget. This value is holding in ":hiring budget".
  24111. (assign, ":hiring_budget", ":cur_wealth"),
  24112. (val_mul, ":hiring_budget", 3),
  24113. (val_div, ":hiring_budget", 4),
  24114.  
  24115. (call_script, "script_party_get_ideal_size", ":party_no"),
  24116. (assign, ":ideal_size", reg0),
  24117. (store_mul, ":ideal_top_size", ":ideal_size", 3),
  24118. (val_div, ":ideal_top_size", 2),
  24119.  
  24120. #(try_begin),
  24121. # (ge, "$cheat_mode", 1),
  24122. # (str_store_troop_name, s7, ":troop_no"),
  24123. # (assign, reg9, ":cur_wealth"),
  24124. # (display_message, "@{!}DEBUGS : {s7} total budget is {reg9}"),
  24125. # (assign, reg6, ":ideal_size"),
  24126. # (assign, reg7, ":ideal_top_size"),
  24127. # (assign, reg8, ":hiring_budget"),
  24128. # (display_message, "str_debug__hiring_men_to_s7_ideal_size__reg6_ideal_top_size__reg7_hiring_budget__reg8"),
  24129. #(try_end),
  24130.  
  24131. (party_get_num_companions, ":party_size", ":party_no"),
  24132.  
  24133. (store_faction_of_party, ":party_faction", ":party_no"),
  24134. (try_begin),
  24135. (this_or_next|eq, ":party_faction", "fac_player_supporters_faction"),
  24136. (eq, ":party_faction", "$players_kingdom"),
  24137. (assign, ":reinforcement_cost", reinforcement_cost_moderate),
  24138. (else_try),
  24139. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  24140. (assign, ":reinforcement_cost", reinforcement_cost_moderate),
  24141. (try_begin),
  24142. (eq, ":reduce_campaign_ai", 0), #hard
  24143. (assign, ":reinforcement_cost", reinforcement_cost_hard),
  24144. (else_try),
  24145. (eq, ":reduce_campaign_ai", 1), #moderate
  24146. (assign, ":reinforcement_cost", reinforcement_cost_moderate),
  24147. (else_try),
  24148. (eq, ":reduce_campaign_ai", 2), #easy
  24149. (assign, ":reinforcement_cost", reinforcement_cost_easy),
  24150. (try_end),
  24151. (try_end),
  24152.  
  24153. (assign, ":num_rounds", 1),
  24154. (try_for_range, ":unused", 0 , ":num_rounds"),
  24155. (try_begin),
  24156. (lt, ":party_size", ":ideal_size"),
  24157. (gt, ":hiring_budget", ":reinforcement_cost"),
  24158. (gt, ":party_no", 0),
  24159. (call_script, "script_cf_reinforce_party", ":party_no"),
  24160. (val_sub, ":cur_wealth", ":reinforcement_cost"),
  24161. (troop_set_slot, ":troop_no", slot_troop_wealth, ":cur_wealth"),
  24162. (else_try),
  24163. (gt, ":party_size", ":ideal_top_size"),
  24164. (store_troop_faction, ":troop_faction", ":troop_no"),
  24165. (party_get_num_companion_stacks, ":num_stacks", ":party_no"),
  24166. (assign, ":total_regulars", 0),
  24167. (assign, ":total_regular_levels", 0),
  24168. (try_for_range_backwards, ":i_stack", 0, ":num_stacks"),
  24169. (party_stack_get_troop_id, ":stack_troop", ":party_no", ":i_stack"),
  24170. (neg|troop_is_hero, ":stack_troop"),
  24171. (party_stack_get_size, ":stack_size", ":party_no", ":i_stack"),
  24172. (store_character_level, ":stack_level", ":stack_troop"),
  24173. (store_troop_faction, ":stack_faction", ":stack_troop"),
  24174. (try_begin),
  24175. (eq, ":troop_faction", ":stack_faction"),
  24176. (val_mul, ":stack_level", 3), #reducing the chance of the faction troops' removal
  24177. (try_end),
  24178. (val_mul, ":stack_level", ":stack_size"),
  24179. (val_add, ":total_regulars", ":stack_size"),
  24180. (val_add, ":total_regular_levels", ":stack_level"),
  24181. (try_end),
  24182. (gt, ":total_regulars", 0),
  24183. (store_div, ":average_level", ":total_regular_levels", ":total_regulars"),
  24184. (try_for_range_backwards, ":i_stack", 0, ":num_stacks"),
  24185. (party_stack_get_troop_id, ":stack_troop", ":party_no", ":i_stack"),
  24186. (neg|troop_is_hero, ":stack_troop"),
  24187. (party_stack_get_size, ":stack_size", ":party_no", ":i_stack"),
  24188. (store_character_level, ":stack_level", ":stack_troop"),
  24189. (store_troop_faction, ":stack_faction", ":stack_troop"),
  24190. (try_begin),
  24191. (eq, ":troop_faction", ":stack_faction"),
  24192. (val_mul, ":stack_level", 3),
  24193. (try_end),
  24194. (store_sub, ":level_dif", ":average_level", ":stack_level"),
  24195. (val_div, ":level_dif", 3),
  24196. (store_add, ":prune_chance", 10, ":level_dif"),
  24197. (gt, ":prune_chance", 0),
  24198. (call_script, "script_get_percentage_with_randomized_round", ":stack_size", ":prune_chance"),
  24199. (gt, reg0, 0),
  24200. (party_remove_members, ":party_no", ":stack_troop", reg0),
  24201. (try_end),
  24202. (try_end),
  24203. (try_end),
  24204. ]),
  24205.  
  24206. # script_get_percentage_with_randomized_round
  24207. # Input: arg1 = value, arg2 = percentage
  24208. # Output: none
  24209. ("get_percentage_with_randomized_round",
  24210. [
  24211. (store_script_param, ":value", 1),
  24212. (store_script_param, ":percentage", 2),
  24213.  
  24214. (store_mul, ":result", ":value", ":percentage"),
  24215. (val_div, ":result", 100),
  24216. (store_mul, ":used_amount", ":result", 100),
  24217. (val_div, ":used_amount", ":percentage"),
  24218. (store_sub, ":left_amount", ":value", ":used_amount"),
  24219. (try_begin),
  24220. (gt, ":left_amount", 0),
  24221. (store_mul, ":chance", ":left_amount", ":percentage"),
  24222. (store_random_in_range, ":random_no", 0, 100),
  24223. (lt, ":random_no", ":chance"),
  24224. (val_add, ":result", 1),
  24225. (try_end),
  24226. (assign, reg0, ":result"),
  24227. ]),
  24228.  
  24229. # script_create_cattle_herd
  24230. # Input: arg1 = center_no, arg2 = amount (0 = default)
  24231. # Output: reg0 = party_no
  24232. ("create_cattle_herd",
  24233. [
  24234. (store_script_param_1, ":center_no"),
  24235. (store_script_param_2, ":amount"),
  24236.  
  24237. (assign, ":herd_party", -1),
  24238. (set_spawn_radius,1),
  24239.  
  24240. (spawn_around_party,":center_no", "pt_cattle_herd"),
  24241. (assign, ":herd_party", reg0),
  24242. (party_get_position, pos1, ":center_no"),
  24243. (call_script, "script_map_get_random_position_around_position_within_range", 1, 2),
  24244. (party_set_position, ":herd_party", pos2),
  24245.  
  24246. (party_set_slot, ":herd_party", slot_party_type, spt_cattle_herd),
  24247. (party_set_slot, ":herd_party", slot_party_ai_state, spai_undefined),
  24248. (party_set_ai_behavior, ":herd_party", ai_bhvr_hold),
  24249.  
  24250. (party_set_slot, ":herd_party", slot_party_commander_party, -1), #we need this because 0 is player's party!
  24251.  
  24252. (try_begin),
  24253. (gt, ":amount", 0),
  24254. (party_clear, ":herd_party"),
  24255. (party_add_members, ":herd_party", "trp_cattle", ":amount"),
  24256. (try_end),
  24257.  
  24258. (assign, reg0, ":herd_party"),
  24259. ]),
  24260.  
  24261. #script_buy_cattle_from_village
  24262. # Input: arg1 = village_no, arg2 = amount, arg3 = single_cost
  24263. # Output: reg0 = party_no
  24264. ("buy_cattle_from_village",
  24265. [
  24266. (store_script_param, ":village_no", 1),
  24267. (store_script_param, ":amount", 2),
  24268. (store_script_param, ":single_cost", 3),
  24269.  
  24270. #Changing price of the cattle
  24271. (try_for_range, ":unused", 0, ":amount"),
  24272. (call_script, "script_game_event_buy_item", "itm_cattle_meat", 0),
  24273. (call_script, "script_game_event_buy_item", "itm_cattle_meat", 0),
  24274. (try_end),
  24275.  
  24276. (party_get_slot, ":num_cattle", ":village_no", slot_village_number_of_cattle),
  24277. (val_sub, ":num_cattle", ":amount"),
  24278. (party_set_slot, ":village_no", slot_village_number_of_cattle, ":num_cattle"),
  24279. (store_mul, ":cost", ":single_cost", ":amount"),
  24280. (troop_remove_gold, "trp_player", ":cost"),
  24281. #SB : add gold back to elder
  24282. (try_begin),
  24283. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),
  24284. (party_get_slot, ":elder", ":village_no", slot_town_elder),
  24285. (gt, ":elder", 0),
  24286. (troop_add_gold, ":elder", ":cost"),
  24287. (try_end),
  24288.  
  24289. (assign, ":continue", 1),
  24290. (try_for_parties, ":cur_party"),
  24291. (eq, ":continue", 1),
  24292. (party_slot_eq, ":cur_party", slot_party_type, spt_cattle_herd),
  24293. (store_distance_to_party_from_party, ":dist", ":village_no", ":cur_party"),
  24294. (lt, ":dist", 6),
  24295. (assign, ":subcontinue", 1),
  24296. (try_begin),
  24297. (check_quest_active, "qst_move_cattle_herd"),
  24298. (quest_slot_eq, "qst_move_cattle_herd", slot_quest_target_party, ":cur_party"),
  24299. (assign, ":subcontinue", 0),
  24300. (try_end),
  24301. (eq, ":subcontinue", 1),
  24302. (party_add_members, ":cur_party", "trp_cattle", ":amount"),
  24303. (assign, ":continue", 0),
  24304. (assign, reg0, ":cur_party"),
  24305. (try_end),
  24306. (try_begin),
  24307. (eq, ":continue", 1),
  24308. (call_script, "script_create_cattle_herd", ":village_no", ":amount"),
  24309. (try_end),
  24310. ]),
  24311.  
  24312. #script_kill_cattle_from_herd
  24313. # Input: arg1 = party_no, arg2 = amount
  24314. # Output: none (fills trp_temp_troop's inventory)
  24315. ("kill_cattle_from_herd",
  24316. [
  24317. (store_script_param_1, ":party_no"),
  24318. (store_script_param_2, ":amount"),
  24319.  
  24320. (troop_clear_inventory, "trp_temp_troop"),
  24321. (store_mul, ":meat_amount", ":amount", 2),
  24322. (troop_add_items, "trp_temp_troop", "itm_cattle_meat", ":meat_amount"),
  24323.  
  24324. (troop_get_inventory_capacity, ":inv_size", "trp_temp_troop"),
  24325. (try_for_range, ":i_slot", 0, ":inv_size"),
  24326. (troop_get_inventory_slot, ":item_id", "trp_temp_troop", ":i_slot"),
  24327. (eq, ":item_id", "itm_cattle_meat"),
  24328. (troop_set_inventory_slot_modifier, "trp_temp_troop", ":i_slot", imod_fresh),
  24329. (try_end),
  24330.  
  24331. (party_get_num_companions, ":num_cattle", ":party_no"),
  24332. (try_begin),
  24333. (ge, ":amount", ":num_cattle"),
  24334. (remove_party, ":party_no"),
  24335. (else_try),
  24336. (party_remove_members, ":party_no", "trp_cattle", ":amount"),
  24337. (try_end),
  24338. ]),
  24339.  
  24340. # script_create_kingdom_hero_party
  24341. # Input: arg1 = troop_no, arg2 = center_no
  24342. # Output: $pout_party = party_no
  24343. ("create_kingdom_hero_party",
  24344. [
  24345. (store_script_param, ":troop_no", 1),
  24346. (store_script_param, ":center_no", 2),
  24347.  
  24348. (store_troop_faction, ":troop_faction_no", ":troop_no"),
  24349.  
  24350. (assign, "$pout_party", -1),
  24351. (try_begin),
  24352. (eq, "$g_there_is_no_avaliable_centers", 0),
  24353. (set_spawn_radius, 0),
  24354. (else_try),
  24355. (set_spawn_radius, 15),
  24356. (try_end),
  24357. (spawn_around_party, ":center_no", "pt_kingdom_hero_party"),
  24358.  
  24359. (assign, "$pout_party", reg0),
  24360.  
  24361. (party_set_faction, "$pout_party", ":troop_faction_no"),
  24362. (party_set_slot, "$pout_party", slot_party_type, spt_kingdom_hero_party),
  24363. (call_script, "script_party_set_ai_state", "$pout_party", spai_undefined, -1),
  24364. (troop_set_slot, ":troop_no", slot_troop_leaded_party, "$pout_party"),
  24365. (party_add_leader, "$pout_party", ":troop_no"),
  24366. (str_store_troop_name, s5, ":troop_no"),
  24367. (party_set_name, "$pout_party", "str_s5_s_party"),
  24368.  
  24369. (party_set_slot, "$pout_party", slot_party_commander_party, -1), #we need this because 0 is player's party!
  24370.  
  24371. #Setting the flag icon
  24372. #normal_banner_begin
  24373. (troop_get_slot, ":cur_banner", ":troop_no", slot_troop_banner_scene_prop),
  24374. (try_begin),
  24375. (gt, ":cur_banner", 0),
  24376. (val_sub, ":cur_banner", banner_scene_props_begin),
  24377. (val_add, ":cur_banner", banner_map_icons_begin),
  24378. (party_set_banner_icon, "$pout_party", ":cur_banner"),
  24379. #custom_banner_begin
  24380. #(troop_get_slot, ":flag_icon", ":troop_no", slot_troop_custom_banner_map_flag_type),
  24381. #(try_begin),
  24382. # (ge, ":flag_icon", 0),
  24383. # (val_add, ":flag_icon", custom_banner_map_icons_begin),
  24384. # (party_set_banner_icon, "$pout_party", ":flag_icon"),
  24385. (try_end),
  24386.  
  24387. (try_begin),
  24388. #because of below two lines, lords can only hire more than one party_template(stack) at game start once a time during all game.
  24389. (troop_slot_eq, ":troop_no", slot_troop_spawned_before, 0),
  24390. (troop_set_slot, ":troop_no", slot_troop_spawned_before, 1),
  24391. (assign, ":num_tries", 20),
  24392. (try_begin),
  24393. (store_troop_faction, ":troop_kingdom", ":troop_no"),
  24394. (faction_slot_eq, ":troop_kingdom", slot_faction_leader, ":troop_no"),
  24395. (assign, ":num_tries", 50),
  24396. (try_end),
  24397.  
  24398. #(str_store_troop_name, s0, ":troop_no"),
  24399. #(display_message, "{!}str_debug__hiring_men_to_party_for_s0"),
  24400.  
  24401. (try_for_range, ":unused", 0, ":num_tries"),
  24402. (call_script, "script_hire_men_to_kingdom_hero_party", ":troop_no"),
  24403. (try_end),
  24404.  
  24405. (assign, ":xp_rounds", 0),
  24406.  
  24407. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  24408. (try_begin),
  24409. (this_or_next|eq, ":troop_faction_no", "$players_kingdom"),
  24410. (eq, ":troop_faction_no", "fac_player_supporters_faction"),
  24411. (assign, ":xp_rounds", 0),
  24412. (else_try),
  24413. (eq, ":reduce_campaign_ai", 0), #hard
  24414. (assign, ":xp_rounds", 2),
  24415. (else_try),
  24416. (eq, ":reduce_campaign_ai", 1), #moderate
  24417. (assign, ":xp_rounds", 1),
  24418. (else_try),
  24419. (eq, ":reduce_campaign_ai", 2), #easy
  24420. (assign, ":xp_rounds", 0),
  24421. (try_end),
  24422.  
  24423. (troop_get_slot, ":renown", ":troop_no", slot_troop_renown),
  24424. (store_div, ":renown_xp_rounds", ":renown", 100),
  24425. (val_add, ":xp_rounds", ":renown_xp_rounds"),
  24426. (try_for_range, ":unused", 0, ":xp_rounds"),
  24427. (call_script, "script_upgrade_hero_party", "$pout_party", 4000),
  24428. (try_end),
  24429. (try_end),
  24430. ]),
  24431.  
  24432. # script_create_kingdom_party_if_below_limit
  24433. # Input: arg1 = faction_no, arg2 = party_type (variables beginning with spt_)
  24434. # Output: reg0 = party_no
  24435. ("create_kingdom_party_if_below_limit",
  24436. [
  24437. (store_script_param_1, ":faction_no"),
  24438. (store_script_param_2, ":party_type"),
  24439.  
  24440. (call_script, "script_count_parties_of_faction_and_party_type", ":faction_no", ":party_type"),
  24441. (assign, ":party_count", reg0),
  24442.  
  24443. (assign, ":party_count_limit", 0),
  24444.  
  24445. (faction_get_slot, ":num_towns", ":faction_no", slot_faction_num_towns),
  24446.  
  24447. (try_begin),
  24448. ## (eq, ":party_type", spt_forager),
  24449. ## (assign, ":party_count_limit", 1),
  24450. ## (else_try),
  24451. ## (eq, ":party_type", spt_scout),
  24452. ## (assign, ":party_count_limit", 1),
  24453. ## (else_try),
  24454. ## (eq, ":party_type", spt_patrol),
  24455. ## (assign, ":party_count_limit", 1),
  24456. ## (else_try),
  24457. ## (eq, ":party_type", spt_messenger),
  24458. ## (assign, ":party_count_limit", 1),
  24459. ## (else_try),
  24460. (eq, ":party_type", spt_kingdom_caravan),
  24461. (try_begin),
  24462. (eq, ":num_towns", 0),
  24463. (assign, ":party_count_limit", 0),
  24464. (else_try),
  24465. (eq, ":num_towns", 1),
  24466. (assign, ":party_count_limit", 1),
  24467. (else_try),
  24468. (eq, ":num_towns", 2),
  24469. (assign, ":party_count_limit", 3),
  24470. (else_try),
  24471. (assign, ":party_count_limit", 5),
  24472. (try_end),
  24473. ##diplomacy begin
  24474. #overwriting party count limit MAX(2 * X - 1, 0)
  24475. (store_mul, ":party_count_limit", ":num_towns", 2),
  24476. (val_sub, ":party_count_limit", 1),
  24477. (val_max, ":party_count_limit", 0),
  24478. ##diplomacy end
  24479.  
  24480. ## (else_try),
  24481. ## (eq, ":party_type", spt_prisoner_train),
  24482. ## (assign, ":party_count_limit", 1),
  24483. (try_end),
  24484.  
  24485. (assign, reg0, -1),
  24486. (try_begin),
  24487. (lt, ":party_count", ":party_count_limit"),
  24488. (call_script,"script_cf_create_kingdom_party", ":faction_no", ":party_type"),
  24489. (try_end),
  24490. ]),
  24491.  
  24492.  
  24493. # script_cf_create_kingdom_party
  24494. # Input: arg1 = faction_no, arg2 = party_type (variables beginning with spt_)
  24495. # Output: reg0 = party_no
  24496. ("cf_create_kingdom_party",
  24497. [
  24498. (store_script_param_1, ":faction_no"),
  24499. (store_script_param_2, ":party_type"),
  24500.  
  24501. (str_store_faction_name, s7, ":faction_no"),
  24502. (assign, ":party_name_str", "str_no_string"),
  24503.  
  24504. ## (faction_get_slot, ":reinforcements_a", ":faction_no", slot_faction_reinforcements_a),
  24505. (faction_get_slot, ":reinforcements_b", ":faction_no", slot_faction_reinforcements_b),
  24506. ## (faction_get_slot, ":reinforcements_c", ":faction_no", slot_faction_reinforcements_c),
  24507.  
  24508. (try_begin),
  24509. ## (eq, ":party_type", spt_forager),
  24510. ## (assign, ":party_template", "pt_forager_party"),
  24511. # (assign, ":party_name_str", "str_s7_foragers"),
  24512. ## (else_try),
  24513. ## (eq, ":party_type", spt_scout),
  24514. ## (assign, ":party_template", "pt_scout_party"),
  24515. # (assign, ":party_name_str", "str_s7_scouts"),
  24516. ## (else_try),
  24517. ## (eq, ":party_type", spt_patrol),
  24518. ## (assign, ":party_template", "pt_patrol_party"),
  24519. # (assign, ":party_name_str", "str_s7_patrol"),
  24520. ## (else_try),
  24521. (eq, ":party_type", spt_kingdom_caravan),
  24522. (assign, ":party_template", "pt_kingdom_caravan_party"),
  24523. # (assign, ":party_name_str", "str_s7_caravan"),
  24524. ## (else_try),
  24525. ## (eq, ":party_type", spt_messenger),
  24526. ## (assign, ":party_template", "pt_messenger_party"),
  24527. # (assign, ":party_name_str", "str_s7_messenger"),
  24528. ## (else_try),
  24529. ## (eq, ":party_type", spt_raider),
  24530. ## (assign, ":party_template", "pt_raider_party"),
  24531. ## (assign, ":party_name_str", "str_s7_raiders"),
  24532. ## (else_try),
  24533. ## (eq, ":party_type", spt_prisoner_train),
  24534. ## (assign, ":party_template", "pt_prisoner_train_party"),
  24535. # (assign, ":party_name_str", "str_s7_prisoner_train"),
  24536. (try_end),
  24537.  
  24538. (assign, ":result", -1),
  24539. (try_begin),
  24540. (try_begin),
  24541. (eq, ":party_type", spt_kingdom_caravan),
  24542. (call_script,"script_cf_select_random_town_with_faction", ":faction_no", -1),
  24543. (set_spawn_radius, 0),
  24544. (else_try), #not used at the moment
  24545. (call_script,"script_cf_select_random_walled_center_with_faction", ":faction_no", -1),
  24546. (set_spawn_radius, 1),
  24547. (try_end),
  24548. (assign, ":spawn_center", reg0),
  24549. (is_between, ":spawn_center", centers_begin, centers_end),
  24550. (spawn_around_party,":spawn_center",":party_template"),
  24551. (assign, ":result", reg0),
  24552. (party_set_faction, ":result", ":faction_no"),
  24553. (try_begin),
  24554. (eq, ":party_type", spt_kingdom_caravan),
  24555. (party_set_slot, ":result", slot_party_home_center, ":spawn_center"),
  24556. (party_set_slot, ":result", slot_party_last_traded_center, ":spawn_center"),
  24557. (try_end),
  24558. (party_set_slot, ":result", slot_party_type, ":party_type"),
  24559. (party_set_slot, ":result", slot_party_ai_state, spai_undefined),
  24560. (try_begin),
  24561. (neq, ":party_name_str", "str_no_string"),
  24562. (party_set_name, ":result", ":party_name_str"),
  24563. (try_end),
  24564.  
  24565. (try_begin),
  24566. ## (eq, ":party_type", spt_forager),
  24567. ## (party_add_template, ":result", ":reinforcements_a"),
  24568. ## (else_try),
  24569. ## (eq, ":party_type", spt_scout),
  24570. ## (party_add_template, ":result", ":reinforcements_c"),
  24571. ## (else_try),
  24572. ## (eq, ":party_type", spt_patrol),
  24573. ## (party_add_template, ":result", ":reinforcements_a"),
  24574. ## (party_add_template, ":result", ":reinforcements_b"),
  24575. ## (else_try),
  24576. (eq, ":party_type", spt_kingdom_caravan),
  24577. (try_begin),
  24578. (eq, ":faction_no", "fac_player_supporters_faction"),
  24579. (party_get_slot, ":reinforcement_faction", ":spawn_center", slot_center_original_faction),
  24580. (faction_get_slot, ":reinforcements_b", ":reinforcement_faction", slot_faction_reinforcements_b),
  24581. (try_end),
  24582. (party_add_template, ":result", ":reinforcements_b"),
  24583. (party_add_template, ":result", ":reinforcements_b"),
  24584. (party_set_ai_behavior,":result",ai_bhvr_travel_to_party),
  24585. (party_set_ai_object,":result",":spawn_center"),
  24586. (party_set_flags, ":result", pf_default_behavior, 1),
  24587. (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  24588. (try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
  24589. (store_add, ":cur_goods_price_slot", ":cur_goods", ":item_to_price_slot"),
  24590. (party_set_slot, ":result", ":cur_goods_price_slot", average_price_factor),
  24591. (try_end),
  24592. ## (else_try),
  24593. ## (eq, ":party_type", spt_messenger),
  24594. ## (faction_get_slot, ":messenger_troop", ":faction_no", slot_faction_messenger_troop),
  24595. ## (party_add_leader, ":result", ":messenger_troop"),
  24596. ## (party_set_ai_behavior,":result",ai_bhvr_travel_to_party),
  24597. ## (party_set_ai_object,":result",":spawn_center"),
  24598. ## (party_set_flags, ":result", pf_default_behavior, 0),
  24599. ## (else_try),
  24600. ## (eq, ":party_type", spt_raider),
  24601. ## (party_add_template, ":result", ":reinforcements_c"),
  24602. ## (party_add_template, ":result", ":reinforcements_b"),
  24603. ## (party_add_template, ":result", "pt_raider_captives"),
  24604. ## (else_try),
  24605. ## (eq, ":party_type", spt_prisoner_train),
  24606. ## (party_add_template, ":result", ":reinforcements_b"),
  24607. ## (party_add_template, ":result", ":reinforcements_a"),
  24608. ## (try_begin),
  24609. ## (call_script,"script_cf_faction_get_random_enemy_faction",":faction_no"),
  24610. ## (store_random_in_range,":r",0,3),
  24611. ## (try_begin),
  24612. ## (lt, ":r", 1),
  24613. ## (faction_get_slot, ":captive_reinforcements", reg0, slot_faction_reinforcements_b),
  24614. ## (else_try),
  24615. ## (faction_get_slot, ":captive_reinforcements", reg0, slot_faction_reinforcements_a),
  24616. ## (try_end),
  24617. ## (party_add_template, ":result", ":captive_reinforcements",1),
  24618. ## (else_try),
  24619. ## (party_add_template, ":result", "pt_default_prisoners"),
  24620. ## (try_end),
  24621. (try_end),
  24622. (try_end),
  24623. (ge, ":result", 0),
  24624. (assign, reg0, ":result"),
  24625. ]),
  24626.  
  24627. # script_get_troop_attached_party
  24628. # Input: arg1 = troop_no
  24629. # Output: reg0 = party_no (-1 if troop's party is not attached to a party)
  24630. ("get_troop_attached_party",
  24631. [
  24632. (store_script_param_1, ":troop_no"),
  24633.  
  24634. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  24635. (assign, ":attached_party_no", -1),
  24636. (try_begin),
  24637. (ge, ":party_no", 0),
  24638. (party_get_attached_to, ":attached_party_no", ":party_no"),
  24639. (try_end),
  24640. (assign, reg0, ":attached_party_no"),
  24641. ]),
  24642.  
  24643.  
  24644. # script_center_get_food_consumption
  24645. # Input: arg1 = center_no
  24646. # Output: reg0: food consumption (1 food item counts as 100 units)
  24647. ("center_get_food_consumption",
  24648. [
  24649. (store_script_param_1, ":center_no"),
  24650. (assign, ":food_consumption", 0),
  24651. (try_begin),
  24652. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  24653. (assign, ":food_consumption", 500),
  24654. (else_try),
  24655. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  24656. (assign, ":food_consumption", 50),
  24657. (try_end),
  24658. ##diplomacy start+
  24659. (try_begin),
  24660. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),
  24661. #Optional change: increase food consumption with garrison size
  24662. #The rationale goes like this:
  24663. #The average reinforcement size for a town or castle is 9.5 per round.
  24664. #At the start of the game:
  24665. #
  24666. # Castles get 15 reinforcement rounds, for around 142.5 troops
  24667. # Towns get 40 reinforcement rounds, for around 380 troops
  24668. #
  24669. #Of course both the castles and the towns have other people living
  24670. #there as well.
  24671. (party_get_num_companions, ":garrison_size", ":center_no"),
  24672. (try_begin),
  24673. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  24674. (gt, ":garrison_size", 150),
  24675. #Assume that the garrison accounts for most of the food consumption.
  24676. (store_div, ":food_consumption", ":garrison_size", 3),
  24677. (else_try),
  24678. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  24679. (gt, ":garrison_size", 380),
  24680. #Assume that the garrison makes the same contribution to size for towns.
  24681. (store_div, ":food_consumption", ":garrison_size", 3),#for 381, equals 127
  24682. (val_add, ":food_consumption", 500 - 127),
  24683. (try_end),
  24684.  
  24685. #Optional change: increase food consumption with prosperity
  24686. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  24687. (party_get_slot, reg0, ":center_no", slot_town_prosperity),
  24688. (gt, reg0, 50),#<- increase only
  24689. (val_add, reg0, 75),
  24690. (val_mul, ":food_consumption", reg0),
  24691. (val_add, ":food_consumption", 62),
  24692. (val_div, ":food_consumption", 125),
  24693. (try_end),
  24694. ##diplomacy+
  24695. (assign, reg0, ":food_consumption"),
  24696. ]),
  24697.  
  24698. # script_center_get_food_store_limit
  24699. # Input: arg1 = center_no
  24700. # Output: reg0: food consumption (1 food item counts as 100 units)
  24701. ("center_get_food_store_limit",
  24702. [
  24703. (store_script_param_1, ":center_no"),
  24704. (assign, ":food_store_limit", 0),
  24705. (try_begin),
  24706. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  24707. (assign, ":food_store_limit", 50000),
  24708. (else_try),
  24709. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  24710. (assign, ":food_store_limit", 1500),
  24711. (try_end),
  24712. (assign, reg0, ":food_store_limit"),
  24713. ]),
  24714.  
  24715. # script_refresh_village_merchant_inventory
  24716. # Input: arg1 = village_no
  24717. # Output: none
  24718. ("refresh_village_merchant_inventory",
  24719. [
  24720. (store_script_param_1, ":village_no"),
  24721. (party_get_slot, ":merchant_troop", ":village_no", slot_town_elder),
  24722. (reset_item_probabilities,0),
  24723.  
  24724. (party_get_slot, ":bound_center", ":village_no", slot_village_bound_center),
  24725.  
  24726. (assign, ":total_probability", 0),
  24727. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  24728. (call_script, "script_center_get_production", ":village_no", ":cur_good"),
  24729. (assign, ":cur_probability", reg0),
  24730.  
  24731. (call_script, "script_center_get_production", ":bound_center", ":cur_good"),
  24732. (val_div, reg0, 5), #also add 1/5 of bound center production to village's inventory.
  24733. (val_add, ":cur_probability", reg0),
  24734.  
  24735. (val_max, ":cur_probability", 5),
  24736. (val_add, ":total_probability", ":cur_probability"),
  24737. (try_end),
  24738.  
  24739. (try_begin),
  24740. (party_get_slot, ":prosperity", ":village_no", slot_town_prosperity),
  24741. (val_div, ":prosperity", 15), #up to 6
  24742. (store_add, ":number_of_items_in_village", ":prosperity", 1),
  24743. (try_end),
  24744.  
  24745. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  24746. (call_script, "script_center_get_production", ":village_no", ":cur_good"),
  24747. (assign, ":cur_probability", reg0),
  24748.  
  24749. (call_script, "script_center_get_production", ":bound_center", ":cur_good"),
  24750. (val_div, reg0, 5), #also add 1/5 of bound center production to village's inventory.
  24751. (val_add, ":cur_probability", reg0),
  24752.  
  24753. (val_max, ":cur_probability", 5),
  24754. (val_mul, ":cur_probability", ":number_of_items_in_village"),
  24755. (val_mul, ":cur_probability", 100),
  24756. (val_div, ":cur_probability", ":total_probability"),
  24757.  
  24758. (set_item_probability_in_merchandise, ":cur_good", ":cur_probability"),
  24759. (try_end),
  24760.  
  24761. #SB : probably do something like trash item at base values
  24762. (troop_clear_inventory, ":merchant_troop"),
  24763. (troop_add_merchandise, ":merchant_troop", itp_type_goods, ":number_of_items_in_village"),
  24764. (troop_ensure_inventory_space, ":merchant_troop", 80),
  24765.  
  24766. #Adding 1 prosperity to the village while reducing each 3000 gold from the elder
  24767. (store_troop_gold, ":gold",":merchant_troop"),
  24768. (try_begin),
  24769. (gt, ":gold", 3500),
  24770. (store_div, ":prosperity_added", ":gold", 3000),
  24771. (store_mul, ":gold_removed", ":prosperity_added", 3000),
  24772. (troop_remove_gold, ":merchant_troop", ":gold_removed"),
  24773. (call_script, "script_change_center_prosperity", ":village_no", ":prosperity_added"),
  24774. (try_end),
  24775. ]),
  24776.  
  24777. # script_refresh_village_defenders
  24778. # Input: arg1 = village_no
  24779. # Output: none
  24780. ("refresh_village_defenders",
  24781. [
  24782. (store_script_param_1, ":village_no"),
  24783.  
  24784. (assign, ":ideal_size", 50),
  24785. (try_begin),
  24786. (party_get_num_companions, ":party_size", ":village_no"),
  24787. (lt, ":party_size", ":ideal_size"),
  24788. #SB : add restriction of not reinforcing while looted or infested
  24789. (call_script, "script_cf_village_normal_cond", ":village_no"),
  24790. (party_add_template, ":village_no", "pt_village_defenders"),
  24791.  
  24792. (try_begin), #SB : upgrade into watchmen, each template had at least 10 farmers
  24793. (party_slot_ge, ":village_no", slot_center_has_watch_tower, 1),
  24794. (party_count_companions_of_type, ":count", ":village_no", "trp_watchman"),
  24795. (lt, ":count", 10),
  24796. (store_random_in_range, ":random_no", 2, 5),
  24797. (party_add_members, ":village_no", "trp_watchman", ":random_no"),
  24798. (party_remove_members, ":village_no", "trp_farmer"),
  24799. (try_end),
  24800. (try_begin), #SB : add messenger
  24801. (party_slot_ge, ":village_no", slot_center_has_messenger_post, 1),
  24802. (store_faction_of_party, ":faction_no", ":village_no"),
  24803. (assign, ":troop", "trp_dplmc_messenger"),
  24804. (try_begin),
  24805. (is_between, ":faction_no", npc_kingdoms_begin, npc_kingdoms_end),
  24806. (faction_get_slot, ":troop", ":faction_no", slot_faction_messenger_troop),
  24807. (try_end),
  24808. (party_count_companions_of_type, ":count", ":village_no", ":troop"),
  24809. (lt, ":count", 1),
  24810. (party_add_members, ":village_no", ":troop", 1),
  24811. (try_end),
  24812. (try_end),
  24813. ]),
  24814.  
  24815. # script_village_set_state
  24816. # Input: arg1 = center_no arg2:new_state
  24817. # Output: reg0: food consumption (1 food item counts as 100 units)
  24818. ("village_set_state",
  24819. [
  24820. (store_script_param_1, ":village_no"),
  24821. (store_script_param_2, ":new_state"),
  24822. ##diplomacy start+
  24823. (store_current_hours, ":hours"),
  24824. (party_get_slot, ":attacker_party", ":village_no", slot_village_raided_by),
  24825. (try_begin),
  24826. (ge, ":attacker_party", 0),
  24827. (party_is_active, ":attacker_party"),#added 2011-06-07
  24828. (party_stack_get_troop_id, ":attack_leader", ":attacker_party", 0),
  24829. (ge, ":attack_leader", 0),
  24830. (party_set_slot, ":village_no", dplmc_slot_center_last_attacked_time, ":hours"),
  24831. (party_set_slot, ":village_no", dplmc_slot_center_last_attacker, ":attack_leader"),
  24832.  
  24833.  
  24834. (try_begin),
  24835. (this_or_next|eq, ":new_state", svs_looted),
  24836. (eq, ":new_state", svs_deserted),
  24837. #SB : there's a fire whether real or fake, we set the bounding center to have guards investigate
  24838. (try_begin),
  24839. (party_get_slot, ":bound_center", ":village_no", slot_village_bound_center),
  24840. (is_between, ":bound_center", centers_begin, centers_end),
  24841. (party_set_slot, ":bound_center", slot_town_last_nearby_fire_time, ":hours"),
  24842. (try_end),
  24843. #SB : quest state
  24844. (try_begin),
  24845. (check_quest_active, "qst_hunt_down_fugitive"),
  24846. (quest_slot_eq, "qst_hunt_down_fugitive", slot_quest_target_center, ":village_no"),
  24847. #if we found and knocked him out in mission template this won't fire
  24848. (neg|check_quest_succeeded, "qst_hunt_down_fugitive"),
  24849. (neg|check_quest_failed, "qst_hunt_down_fugitive"),
  24850. (quest_set_slot, "qst_hunt_down_fugitive", slot_quest_current_state, 3),
  24851. (try_begin), #conclude quest if village raided
  24852. (neq, ":attacker_party", "p_main_party"),
  24853. (call_script, "script_conclude_quest", "qst_hunt_down_fugitive"),
  24854. (else_try), #player raided village for some reason
  24855. (call_script, "script_succeed_quest", "qst_hunt_down_fugitive"),
  24856. (try_end),
  24857. (try_end),
  24858. (try_end),
  24859. (try_end),
  24860. ##diplomacy end+
  24861.  
  24862. (try_begin),
  24863. (eq, ":new_state", svs_normal),
  24864. (party_set_extra_text, ":village_no", "str_empty_string"),
  24865. #SB : redo village recruits immediately
  24866. (try_begin),
  24867. (this_or_next|le, ":attacker_party", 0),
  24868. (neg|party_is_active, ":attacker_party"),
  24869. (call_script, "script_update_volunteer_troops_in_village", ":village_no"),
  24870. (call_script, "script_update_npc_volunteer_troops_in_village", ":village_no"),
  24871. (try_end),
  24872. (party_set_slot, ":village_no", slot_village_raided_by, -1),
  24873. (else_try),
  24874. (eq, ":new_state", svs_being_raided),
  24875. (party_set_extra_text, ":village_no", "@(Being Raided)"),
  24876. (else_try), #SB : deserted state as alternative to full looting
  24877. (eq, ":new_state", svs_deserted),
  24878. (party_set_extra_text, ":village_no", "@(Deserted)"),
  24879.  
  24880. (party_set_slot, ":village_no", slot_village_raided_by, -1),
  24881. (call_script, "script_change_center_prosperity", ":village_no", -20),
  24882. (val_add, "$newglob_total_prosperity_from_villageloot", -20),
  24883. (else_try),
  24884. (eq, ":new_state", svs_looted),
  24885. (party_set_extra_text, ":village_no", "@(Looted)"),
  24886.  
  24887. (party_set_slot, ":village_no", slot_village_raided_by, -1),
  24888. (call_script, "script_change_center_prosperity", ":village_no", -60),
  24889. (val_add, "$newglob_total_prosperity_from_villageloot", -60),
  24890.  
  24891. # (try_begin), #optional - lowers the relationship between a lord and his liege if his fief is looted
  24892. # (eq, 5, 0),
  24893. # (party_get_slot, ":town_lord", ":village_no", slot_town_lord),
  24894. # (is_between, ":town_lord", active_npcs_begin, active_npcs_end),
  24895. # (store_faction_of_troop, ":town_lord_faction", ":town_lord"),
  24896. # (faction_get_slot, ":faction_leader", ":town_lord_faction", slot_faction_leader),
  24897. # (call_script, "script_troop_change_relation_with_troop", ":town_lord", ":faction_leader", -1),
  24898. # (val_add, "$total_battle_ally_changes", -1),
  24899. # (try_end),
  24900. (else_try),
  24901. (eq, ":new_state", svs_under_siege),
  24902. (party_set_extra_text, ":village_no", "@(Under Siege)"),
  24903.  
  24904. #Divert all caravans heading to the center
  24905. #Note that occasionally, no alternative center will be found. In that case, the caravan will try to run the blockade
  24906. (try_for_parties, ":party_no"),
  24907. (gt, ":party_no", "p_spawn_points_end"),
  24908. (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_caravan),
  24909. (party_slot_eq, ":party_no", slot_party_ai_object, ":village_no"),
  24910.  
  24911. (party_get_slot, ":origin", ":party_no", slot_party_last_traded_center),
  24912. (store_faction_of_party, ":merchant_faction", ":party_no"),
  24913. ##diplomacy start+ added new third parameter, the caravan party itself
  24914. (call_script, "script_cf_select_most_profitable_town_at_peace_with_faction_in_trade_route", ":origin", ":merchant_faction",":party_no"),
  24915. ##diplomacy end+
  24916. (assign, ":target_center", reg0),
  24917. (is_between, ":target_center", centers_begin, centers_end),
  24918.  
  24919. (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
  24920. (party_set_ai_object, ":party_no", ":target_center"),
  24921. (party_set_flags, ":party_no", pf_default_behavior, 0),
  24922. (party_set_slot, ":party_no", slot_party_ai_state, spai_trading_with_town),
  24923. (party_set_slot, ":party_no", slot_party_ai_object, ":target_center"),
  24924. (try_end),
  24925. (try_end),
  24926. (party_set_slot, ":village_no", slot_village_state, ":new_state"),
  24927. ]),
  24928.  
  24929.  
  24930. # script_process_village_raids
  24931. # Input: none
  24932. # Output: none
  24933. # called from triggers every two hours
  24934. ("process_village_raids",
  24935. [
  24936. ##diplomacy start+
  24937. (store_current_hours, ":hours"),
  24938. ##diplomacy end+
  24939. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"), #SB: also move to top
  24940. (try_for_range, ":village_no", villages_begin, villages_end),
  24941. ##CABA Fix
  24942. (try_begin),
  24943. (this_or_next|is_between, ":village_no", "p_village_16", "p_village_23"), #Shapeshte through Shulus (up to Ilvia)
  24944. (this_or_next|is_between, ":village_no", "p_village_49", "p_village_51"), #Tismirr and Karindi
  24945. (this_or_next|eq, ":village_no", "p_village_75"), #Bhulaban
  24946. (is_between, ":village_no", "p_village_85", "p_village_87"), #Ismirala and Slezkh
  24947. (assign, ":normal_village_icon", "icon_village_snow_a"),
  24948. (assign, ":burnt_village_icon", "icon_village_snow_burnt_a"),
  24949. (assign, ":deserted_village_icon", "icon_village_snow_deserted_a"),
  24950. (else_try),
  24951. (is_between, ":village_no", "p_village_91", "p_salt_mine"), #Ayn Assuadi through Rushdigh
  24952. (assign, ":normal_village_icon", "icon_village_c"),
  24953. (assign, ":burnt_village_icon", "icon_village_burnt_c"),
  24954. (assign, ":deserted_village_icon", "icon_village_deserted_c"),
  24955. (else_try),
  24956. (assign, ":normal_village_icon", "icon_village_a"),
  24957. (assign, ":burnt_village_icon", "icon_village_burnt_a"),
  24958. (assign, ":deserted_village_icon", "icon_village_deserted_a"),
  24959. (try_end),
  24960. ##CABA Fix
  24961. (party_get_slot, ":village_raid_progress", ":village_no", slot_village_raid_progress),
  24962. (try_begin),
  24963. (party_slot_eq, ":village_no", slot_village_state, svs_normal), #village is normal
  24964. (val_sub, ":village_raid_progress", 5),
  24965. (val_max, ":village_raid_progress", 0),
  24966. (party_set_slot, ":village_no", slot_village_raid_progress, ":village_raid_progress"),
  24967. (try_begin),
  24968. (lt, ":village_raid_progress", 50),
  24969.  
  24970. (try_begin),
  24971. (party_get_icon, ":village_icon", ":village_no"),
  24972. (neq, ":village_icon", ":normal_village_icon"), ##CABA FIX
  24973. (party_set_icon, ":village_no", ":normal_village_icon"), ##CABA FIX
  24974. (try_end),
  24975.  
  24976. (party_slot_ge, ":village_no", slot_village_smoke_added, 1),
  24977. (party_set_slot, ":village_no", slot_village_smoke_added, 0),
  24978. (party_clear_particle_systems, ":village_no"),
  24979. (try_end),
  24980. (else_try),
  24981. (party_slot_eq, ":village_no", slot_village_state, svs_being_raided), #village is being raided
  24982. #End raid unless there is an enemy party nearby
  24983. (assign, ":raid_ended", 1),
  24984. (party_get_slot, ":raider_party", ":village_no", slot_village_raided_by),
  24985. # (call_script, "script_party_count_fit_regulars", ":village_no"), #SB : calculate cur size
  24986. # (assign, ":villager_count", reg0),
  24987. # (party_get_num_companions, ":villager_count", ":village_no"), #SB : calculate cur size, including wounded
  24988. (call_script, "script_party_calculate_strength", ":village_no", 0),
  24989. (store_div, ":village_strength", reg0, 2),
  24990. (try_begin),
  24991. (ge, ":raider_party", 0),
  24992. (party_is_active, ":raider_party"),
  24993. (party_stack_get_troop_id, ":raid_leader", ":raider_party", 0), #SB : moved to top
  24994. (this_or_next|neq, ":raider_party", "p_main_party"),
  24995. (eq, "$g_player_is_captive", 0),
  24996. #SB : strength conditional, player bypasses this however since they actually fought
  24997. (call_script, "script_party_calculate_strength", ":raider_party", 0),
  24998. (this_or_next|eq, ":raider_party", "p_main_party"), #player raiding conditions are different
  24999. (ge, reg0, ":village_strength"),
  25000. # (party_slot_ge, ":raider_party", slot_party_cached_strength, ":village_strength"),
  25001. (store_distance_to_party_from_party, ":distance", ":village_no", ":raider_party"),
  25002. (lt, ":distance", raid_distance),
  25003. (assign, ":raid_ended", 0),
  25004. (try_end),
  25005.  
  25006. (try_begin),
  25007. (eq, ":raid_ended", 1),
  25008. (call_script, "script_village_set_state", ":village_no", svs_normal), #clear raid flag
  25009. (party_set_slot, ":village_no", slot_village_smoke_added, 0),
  25010. (party_clear_particle_systems, ":village_no"),
  25011. (else_try),
  25012. (assign, ":raid_progress_increase", 11),
  25013. (party_get_slot, ":looter_party", ":village_no", slot_village_raided_by),
  25014. (try_begin),
  25015. (party_get_skill_level, ":looting_skill", ":looter_party", "skl_looting"),
  25016. (val_add, ":raid_progress_increase", ":looting_skill"),
  25017. (try_end),
  25018. (try_begin),
  25019. (party_slot_eq, ":village_no", slot_center_has_watch_tower, 1),
  25020. (val_mul, ":raid_progress_increase", 2),
  25021. (val_div, ":raid_progress_increase", 3),
  25022. (try_end),
  25023. (val_add, ":village_raid_progress", ":raid_progress_increase"),
  25024. #SB : delay construction while being looted
  25025. (try_begin),
  25026. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  25027. (party_slot_ge, ":village_no", slot_center_current_improvement, 1),
  25028. (party_get_slot, ":cur_improvement_end_time", ":village_no", slot_center_improvement_end_hour),
  25029. (store_div, ":delay", ":raid_progress_increase", 3),
  25030. (try_begin),
  25031. (party_slot_eq, ":village_no", slot_town_lord, "trp_player"),
  25032. (val_sub, ":delay", ":reduce_campaign_ai"),
  25033. (try_end),
  25034. (val_clamp, ":delay", 2, 8), #delayed for at least duration of raid
  25035. (val_add, ":cur_improvement_end_time", ":delay"),
  25036. (try_end),
  25037. (party_set_slot, ":village_no", slot_village_raid_progress, ":village_raid_progress"),
  25038. (try_begin),
  25039. (ge, ":village_raid_progress", 50),
  25040. (party_slot_eq, ":village_no", slot_village_smoke_added, 0),
  25041. (party_add_particle_system, ":village_no", "psys_map_village_fire"),
  25042. (party_add_particle_system, ":village_no", "psys_map_village_fire_smoke"),
  25043. (party_set_icon, ":village_no", ":burnt_village_icon"), ##CABA FIX
  25044. (party_set_slot, ":village_no", slot_village_smoke_added, 1),
  25045. (try_end),
  25046. ##diplomacy start+ set values of slots
  25047. (try_begin),
  25048. (ge, ":looter_party", 0),
  25049. # (party_stack_get_troop_id, ":raid_leader", ":looter_party", 0),
  25050. (ge, ":raid_leader", 0),
  25051. (party_set_slot, ":village_no", dplmc_slot_center_last_attacked_time, ":hours"),
  25052. (party_set_slot, ":village_no", dplmc_slot_center_last_attacker, ":raid_leader"),
  25053. (try_end),
  25054. (assign, ":raid_total_captured", 0),
  25055. (try_begin), #SB : enslavement mode
  25056. (eq, ":looter_party", "p_main_party"),
  25057. (party_slot_eq, ":village_no", slot_town_last_nearby_fire_time, 2), #enslavement mode
  25058.  
  25059. #do some wounding first, in the first iteration all wounded from the initial encounter will be grabbed
  25060. (store_random_in_range, ":random_no", ":reduce_campaign_ai", 4), #0 to 2 up to 3 per iteration
  25061. (party_wound_members, ":village_no", "trp_farmer", ":random_no"),
  25062. (val_mul, ":random_no", 2),
  25063. (val_div, ":random_no", 3),
  25064. (party_wound_members, ":village_no", "trp_peasant_woman", ":random_no"),
  25065.  
  25066. #this is only effective for p_main_party anyway
  25067. (call_script, "script_game_get_party_prisoner_limit", ":looter_party"),
  25068. (assign, ":prisoner_limit", reg0),
  25069. (party_get_num_prisoners, ":num_prisoners", ":looter_party"),
  25070. (val_sub, ":prisoner_limit", ":num_prisoners"),
  25071.  
  25072. (party_get_num_companion_stacks, ":num_stacks", ":village_no"),
  25073. # (assign, ":num_wounded", 0),
  25074. (party_get_slot, ":village_raid_progress", ":village_no", slot_village_raid_progress),
  25075. (try_for_range, ":stack_no", 0, ":num_stacks"),
  25076. (party_stack_get_num_wounded, ":cur_wounded",":village_no",":stack_no"),
  25077. (gt, ":cur_wounded", 0),
  25078. (val_add, ":raid_total_captured", ":cur_wounded"),
  25079.  
  25080. (party_stack_get_troop_id, ":stack_troop",":village_no",":stack_no"),
  25081. (party_remove_members_wounded_first, ":village_no", ":stack_troop", ":cur_wounded"),
  25082. (party_add_prisoners, "p_main_party", ":stack_troop", ":cur_wounded"),
  25083. (try_begin),
  25084. (val_sub, ":prisoner_limit", ":cur_wounded"),
  25085. (le, ":prisoner_limit", 0),
  25086. (assign, ":num_stacks", 0),
  25087. (try_end),
  25088. (try_end),
  25089. (assign, reg1, ":raid_total_captured"),
  25090. (try_begin),
  25091. (neq, reg1, 0),
  25092. (display_message, "@Captured {reg1} villagers."),
  25093. (val_add, "$qst_eliminate_bandits_infesting_village_num_villagers", ":raid_total_captured"),
  25094. (try_end),
  25095. (try_begin),
  25096. (party_get_num_companions, ":amount", ":village_no"),
  25097. (this_or_next|eq, ":amount", 0), #we have captured all
  25098. (eq, ":num_stacks", 0), #we have captured too many and broke the loop
  25099. (assign, ":raid_total_captured", -1), #mark this condition for later
  25100. (else_try),
  25101. #for each three prisoner taken we move back the counter a bit
  25102. (store_div, ":amount", ":raid_total_captured", 3),
  25103. (val_sub, ":village_raid_progress", ":amount"),
  25104. (party_set_slot, ":village_no", slot_village_raid_progress, ":village_raid_progress"),
  25105. (try_end),
  25106. (try_end),
  25107. #SB : probably spawn random refugees here as the raid progresses
  25108. ##diplomacy end+
  25109. #SB : add in enslavement function at around 75% completion, simulate each level taking off 0.5 hour
  25110. #if the looting skill is too high we won't capture as many peasants
  25111. (try_begin),
  25112. (eq, ":looter_party", "p_main_party"),
  25113. (party_slot_eq, ":village_no", slot_town_last_nearby_fire_time, 2), #enslavement mode
  25114. (party_get_skill_level, ":management", ":looter_party", "skl_prisoner_management"),
  25115. (val_mul, ":management", 5), #0 to 50 to 75
  25116. (val_div, ":management", 3), #around 25
  25117. (store_sub, ":threshold", 90, ":management"), #make sure this is before regular looting completes
  25118. # (party_get_num_companions, ":amount", ":village_no"),
  25119. # (party_get_free_prisoners_capacity, ":capacity", "p_main_party"), #or use previous calculation
  25120. # (this_or_next|le, ":amount", 0), #we have wounded and captured all inhabitants
  25121. # (this_or_next|le, ":capacity", 0), #we have no more room for capturing
  25122. (this_or_next|eq, ":raid_total_captured", -1),
  25123. (gt, ":village_raid_progress", ":threshold"),
  25124.  
  25125. (str_store_party_name_link, s1, ":village_no"),
  25126. (str_store_troop_name_link, s2, ":raid_leader"),
  25127. (store_faction_of_party, ":village_faction", ":village_no"),
  25128. (faction_get_color, ":color", ":village_faction"),
  25129. (display_log_message, "@The village of {s1} has been sacked by {s2}.", ":color"),
  25130.  
  25131. (try_begin),
  25132. (party_get_slot, ":village_lord", ":village_no", slot_town_lord),
  25133. (is_between, ":village_lord", active_npcs_begin, active_npcs_end),
  25134. (call_script, "script_troop_change_relation_with_troop", ":raid_leader", ":village_lord", -1),
  25135. (val_add, "$total_battle_enemy_changes", -1),
  25136. (try_end),
  25137. (call_script, "script_village_set_state", ":village_no", svs_deserted), #not svs_looted, less prosperity decrease
  25138. # (party_set_slot, ":village_no", slot_center_accumulated_rents, 0),
  25139. # (party_set_slot, ":village_no", slot_center_accumulated_tariffs, 0),
  25140. (party_set_slot, ":village_no", slot_village_raid_progress, 0),
  25141. (party_set_slot, ":village_no", slot_village_recover_progress, 50), #SB : jumps directly to deserted icon, not burnt
  25142. (party_set_slot, ":village_no", slot_village_smoke_added, 2), #to force trigger the icon
  25143.  
  25144. (try_begin), #SB : this crippled lords too much
  25145. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_HIGH),
  25146. (party_set_slot, ":village_no", slot_center_volunteer_troop_type, -1),
  25147. (party_set_slot, ":village_no", slot_center_volunteer_troop_amount, -1),
  25148. (party_set_slot, ":village_no", slot_center_npc_volunteer_troop_type, -1),
  25149. (party_set_slot, ":village_no", slot_center_npc_volunteer_troop_amount, -1),
  25150. (try_end),
  25151. (call_script, "script_add_log_entry", logent_village_raided, ":raid_leader", ":village_no", -1, -1),
  25152. (store_faction_of_party, ":looter_faction", ":looter_party"), #enslavement less severe than plundering
  25153. (call_script, "script_faction_inflict_war_damage_on_faction", ":looter_faction", ":village_faction", 4),
  25154. (else_try),
  25155. (gt, ":village_raid_progress", 100),
  25156. (str_store_party_name_link, s1, ":village_no"),
  25157. # (party_stack_get_troop_id, ":raid_leader", ":looter_party", 0), #SB : move to top
  25158. (ge, ":raid_leader", 0),
  25159. #SB : colorize, string link
  25160. # (str_store_party_name, s2, ":looter_party"),
  25161. (try_begin),
  25162. (troop_is_hero, ":raid_leader"),
  25163. (str_store_troop_name_link, s2, ":raid_leader"),
  25164. (else_try),
  25165. (str_store_party_name, s2, ":looter_party"),
  25166. (try_end),
  25167. (store_faction_of_party, ":village_faction", ":village_no"),
  25168. (faction_get_color, ":color", ":village_faction"),
  25169. (display_log_message, "@The village of {s1} has been looted by {s2}.", ":color"),
  25170.  
  25171. (try_begin),
  25172. (party_get_slot, ":village_lord", ":village_no", slot_town_lord),
  25173. (is_between, ":village_lord", active_npcs_begin, active_npcs_end),
  25174. (call_script, "script_troop_change_relation_with_troop", ":raid_leader", ":village_lord", -1),
  25175. (val_add, "$total_battle_enemy_changes", -1),
  25176. (try_end),
  25177.  
  25178. #give loot gold to raid leader
  25179. (troop_get_slot, ":raid_leader_gold", ":raid_leader", slot_troop_wealth),
  25180. ##diplomacy start+
  25181. #How did the next line ever work? isn't it missing a slot number?!
  25182. # (party_get_slot, ":village_prosperity", ":village_no"),
  25183. #Replace it with the following:
  25184. (party_get_slot, ":village_prosperity", ":village_no", slot_town_prosperity),
  25185. ##diplomacy end+
  25186. (store_mul, ":value_of_loot", ":village_prosperity", 60), #average is 3000
  25187. (val_add, ":raid_leader_gold", ":value_of_loot"),
  25188. (troop_set_slot, ":raid_leader", slot_troop_wealth, ":raid_leader_gold"),
  25189. (assign, reg2, ":raid_leader_gold"),
  25190. (str_store_troop_name_link, s2, ":raid_leader"),
  25191. (display_message, "@{s2} now has {reg2} denars from raiding"),#SB : debug
  25192. #take loot gold from village lord #new 1.126
  25193. ##diplomacy start+
  25194. #With economic changes enabled, this will first withdraw from accumulated taxes at center
  25195. (try_begin),
  25196. #To support the possibility of kingdom_ladies becoming enfeoffed, changed the
  25197. #below line from active_npcs_begin/active_npcs_end to heroes_begin/heroes_end
  25198. (is_between, ":village_lord", heroes_begin, heroes_end),
  25199. (neq, ":village_lord", "trp_kingdom_heroes_including_player_begin"),
  25200. (troop_get_slot, ":village_lord_gold", ":village_lord", slot_troop_wealth),
  25201. (try_begin),
  25202. #Optional behavior: subtract the looted wealth from the village's uncollected
  25203. #rents and tariffs
  25204. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_HIGH),#<-- check experimental changes are enabled
  25205. (assign, ":gold_lost_by_lord", ":value_of_loot"),
  25206. #Accumulated rents & tariffs get zeroed further down, so we don't need to worry
  25207. #about modifying the slot's value to reflect the loss.
  25208. (party_get_slot, ":x", ":village_no", slot_center_accumulated_rents),
  25209. (val_max, ":x", 0),
  25210. (val_sub, ":gold_lost_by_lord", ":x"),
  25211. (party_get_slot, ":x", ":village_no", slot_center_accumulated_tariffs),
  25212. (val_max, ":x", 0),
  25213. (val_sub, ":gold_lost_by_lord", ":x"),
  25214. #Only then subtract the remainder from the lord
  25215. (val_max, ":gold_lost_by_lord", 0),
  25216. (val_sub, ":village_lord_gold", ":gold_lost_by_lord"),
  25217. (else_try),
  25218. #Unaltered behavior
  25219. (val_sub, ":village_lord_gold", ":value_of_loot"),
  25220. (try_end),
  25221. #Apply the gold change
  25222. (val_max, ":village_lord_gold", 0),
  25223. (troop_set_slot, ":village_lord", slot_troop_wealth, ":village_lord_gold"),
  25224. (assign, reg2, ":village_lord_gold"),
  25225. (str_store_troop_name_link, s2, ":village_lord"),
  25226. (display_message, "@{s2} now has {reg2} denars from being raided"),#SB : debug
  25227. (else_try),
  25228. #Option: player loses gold when his fiefs are raided, just as an NPC does
  25229. #(default behavior in Native is the player loses no gold). The gold is
  25230. #lost from the treasury, and is reduced by uncollected taxes.
  25231. #
  25232. #Only do this if the option is explicitly enabled and the player has
  25233. # a chamberlain.
  25234. (eq, ":village_lord", "trp_player"),
  25235. (gt, "$g_player_chamberlain", 0),#check the player has a chamberlain
  25236. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),#<-- check experimental changes are enabled
  25237. (party_slot_eq, ":village_no", slot_town_lord, "trp_player"),
  25238. #Do some double-checking, to avoid potential erroneous gold loss
  25239. #if some careless code has improperly left the "slot_town_lord"
  25240. #slot of the village initialized to zero.
  25241. (store_faction_of_party, ":village_faction", ":village_no"),
  25242. ##diplomacy start+ Handle player is co-ruler of faction
  25243. (assign, ":is_coruler", 0),
  25244. (try_begin),
  25245. (eq, ":village_faction", "$players_kingdom"),
  25246. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  25247. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  25248. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  25249. (assign, ":is_coruler", 1),
  25250. (try_end),
  25251. (this_or_next|eq, ":is_coruler", 1),
  25252. ##diplomacy end+
  25253. (this_or_next|eq, "fac_player_supporters_faction", ":village_faction"),
  25254. (eq, "$players_kingdom", ":village_faction"),
  25255. #Adjust the amount lost by difficulty setting.
  25256. (assign, ":gold_lost_by_lord", ":value_of_loot"),
  25257. # (game_get_reduce_campaign_ai, ":reduce_campaign_ai"), #SB: move to top
  25258. (try_begin),
  25259. (eq, ":reduce_campaign_ai", 0),#hard, 125% loss
  25260. (val_mul, ":gold_lost_by_lord", 5),
  25261. (val_div, ":gold_lost_by_lord", 4),
  25262. (else_try),
  25263. (eq, ":reduce_campaign_ai", 1),#medium, 100% loss
  25264. (else_try),
  25265. (eq, ":reduce_campaign_ai", 2),#easy, 50% loss
  25266. (val_div, ":gold_lost_by_lord", 2),
  25267. (try_end),
  25268.  
  25269. #First defray the lost gold with rents and tarriffs from the village
  25270. (party_get_slot, ":x", ":village_no", slot_center_accumulated_rents),
  25271. (val_max, ":x", 0),
  25272. (val_sub, ":gold_lost_by_lord", ":x"),
  25273. (party_get_slot, ":x", ":village_no", slot_center_accumulated_tariffs),
  25274. (val_max, ":x", 0),
  25275. (val_sub, ":gold_lost_by_lord", ":x"),
  25276. (val_max, ":gold_lost_by_lord", 0),
  25277. #Remove the remainder (if any) from the player's treasury
  25278. (store_troop_gold, ":x", "trp_household_possessions"),
  25279. (val_min, ":gold_lost_by_lord", ":x"),
  25280. (ge, ":gold_lost_by_lord", 1),
  25281. (call_script, "script_dplmc_withdraw_from_treasury", ":gold_lost_by_lord"),
  25282. (try_end),
  25283. ##diplomacy end+
  25284.  
  25285. (call_script, "script_village_set_state", ":village_no", svs_looted),
  25286. (party_set_slot, ":village_no", slot_center_accumulated_rents, 0), #new 1.126
  25287. (party_set_slot, ":village_no", slot_center_accumulated_tariffs, 0), #new 1.126
  25288.  
  25289. (party_set_slot, ":village_no", slot_village_raid_progress, 0),
  25290. (party_set_slot, ":village_no", slot_village_recover_progress, 0),
  25291.  
  25292. #SB : also get rid of recruits, technically they should have perished in the fighting
  25293. (try_begin), #SB : this crippled lords too much
  25294. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_HIGH),
  25295. (party_set_slot, ":village_no", slot_center_volunteer_troop_type, -1),
  25296. (party_set_slot, ":village_no", slot_center_volunteer_troop_amount, -1),
  25297. (party_set_slot, ":village_no", slot_center_npc_volunteer_troop_type, -1),
  25298. (party_set_slot, ":village_no", slot_center_npc_volunteer_troop_amount, -1),
  25299. (try_end),
  25300. #finally clear the party
  25301. # (party_clear, ":village_no"),
  25302. (call_script, "script_party_wound_all_members", ":village_no"),
  25303. (try_begin),
  25304. (store_faction_of_party, ":village_faction", ":village_no"),
  25305. ##diplomacy start+ Handle player is co-ruler of faction
  25306. (assign, ":is_coruler", 0),
  25307. (try_begin),
  25308. (eq, ":village_faction", "$players_kingdom"),
  25309. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  25310. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  25311. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  25312. (assign, ":is_coruler", 1),
  25313. (try_end),
  25314. (this_or_next|eq, ":is_coruler", 1),
  25315. ##diplomacy end+
  25316. (this_or_next|party_slot_eq, ":village_no", slot_town_lord, "trp_player"),
  25317. (eq, ":village_faction", "fac_player_supporters_faction"),
  25318. (call_script, "script_add_notification_menu", "mnu_notification_village_raided", ":village_no", ":raid_leader"),
  25319. (try_end),
  25320. (call_script, "script_add_log_entry", logent_village_raided, ":raid_leader", ":village_no", -1, -1),
  25321. (store_faction_of_party, ":looter_faction", ":looter_party"),
  25322. (call_script, "script_faction_inflict_war_damage_on_faction", ":looter_faction", ":village_faction", 5),
  25323. (try_end),
  25324. (try_end),
  25325. (else_try),
  25326. (this_or_next|party_slot_eq, ":village_no", slot_village_state, svs_looted), #village is looted
  25327. (party_slot_eq, ":village_no", slot_village_state, svs_deserted), #SB : village is deserted
  25328. (party_get_slot, ":recover_progress", ":village_no", slot_village_recover_progress),
  25329. (val_add, ":recover_progress", 1),
  25330. (party_set_slot, ":village_no", slot_village_recover_progress, ":recover_progress"), #village looted
  25331.  
  25332. (try_begin), #SB : add some looters, around twice per lifetime
  25333. (store_mod, ":looter_chance", ":recover_progress", 10),
  25334. (eq, ":looter_chance", 0),
  25335. (store_random_in_range, ":random_value", 0, 5),
  25336. (eq, ":random_value", 0),
  25337. (set_spawn_radius, 5),
  25338. (spawn_around_party, ":village_no", "pt_looters"),
  25339. (try_end),
  25340. (try_begin),
  25341. (ge, ":recover_progress", 10),
  25342. (party_slot_eq, ":village_no", slot_village_smoke_added, 1),
  25343. (party_clear_particle_systems, ":village_no"),
  25344. (party_add_particle_system, ":village_no", "psys_map_village_looted_smoke"),
  25345. (party_set_slot, ":village_no", slot_village_smoke_added, 2),
  25346. (try_end),
  25347. (try_begin),
  25348. (gt, ":recover_progress", 50),
  25349. (party_slot_eq, ":village_no", slot_village_smoke_added, 2),
  25350. (party_clear_particle_systems, ":village_no"),
  25351. (party_set_slot, ":village_no", slot_village_smoke_added, 3),
  25352. (party_set_icon, ":village_no", ":deserted_village_icon"), ##CABA FIX
  25353. (try_end),
  25354. (try_begin),
  25355. (gt, ":recover_progress", 100),
  25356. (call_script, "script_village_set_state", ":village_no", svs_normal),#village back to normal
  25357. (party_set_slot, ":village_no", slot_village_recover_progress, 0),
  25358. (party_clear_particle_systems, ":village_no"),
  25359. (party_set_slot, ":village_no", slot_village_smoke_added, 0),
  25360. (party_set_icon, ":village_no", ":normal_village_icon"), ##CABA FIX
  25361. (try_end),
  25362. (try_end),
  25363. (try_end),
  25364. ]),
  25365.  
  25366.  
  25367. # script_process_sieges
  25368. # Input: none
  25369. # Output: none
  25370. #called from triggers
  25371. ("process_sieges",
  25372. [
  25373. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  25374. #Reducing siege hardness every day by 20
  25375. (party_get_slot, ":siege_hardness", ":center_no", slot_center_siege_hardness),
  25376. (val_sub, ":siege_hardness", 20),
  25377. (val_max, ":siege_hardness", 0),
  25378. (party_set_slot, ":center_no", slot_center_siege_hardness, ":siege_hardness"),
  25379.  
  25380. (party_get_slot, ":town_food_store", ":center_no", slot_party_food_store),
  25381. (call_script, "script_center_get_food_store_limit", ":center_no"),
  25382. (assign, ":food_store_limit", reg0),
  25383. (try_begin),
  25384. (party_get_slot, ":besieger_party", ":center_no", slot_center_is_besieged_by),
  25385. (ge, ":besieger_party", 0), #town is under siege
  25386.  
  25387. #Reduce prosperity of besieged castle/town by -0.33/-4 every day.
  25388. (try_begin),
  25389. (try_begin),
  25390. (is_between, ":center_no", castles_begin, castles_end),
  25391. (store_random_in_range, ":random_value", 0, 3),
  25392. (try_begin),
  25393. (eq, ":random_value", 0),
  25394. (assign, ":daily_siege_effect_on_prosperity", -1),
  25395. (else_try),
  25396. (assign, ":daily_siege_effect_on_prosperity", 0),
  25397. (try_end),
  25398. (else_try),
  25399. (assign, ":daily_siege_effect_on_prosperity", -4),
  25400. (try_end),
  25401.  
  25402. (call_script, "script_change_center_prosperity", ":center_no", ":daily_siege_effect_on_prosperity"),
  25403. (val_add, "$newglob_total_prosperity_from_townloot", ":daily_siege_effect_on_prosperity"),
  25404. (try_end),
  25405.  
  25406. (store_faction_of_party, ":center_faction", ":center_no"),
  25407. # Lift siege unless there is an enemy party nearby
  25408. (assign, ":siege_lifted", 0),
  25409. (try_begin),
  25410. (try_begin),
  25411. (neg|party_is_active, ":besieger_party"),
  25412. (assign, ":siege_lifted", 1),
  25413. (else_try),
  25414. (store_distance_to_party_from_party, ":besieger_distance", ":center_no", ":besieger_party"),
  25415. (gt, ":besieger_distance", 5),
  25416. (assign, ":siege_lifted", 1),
  25417. (else_try),
  25418. ##diplomacy begin
  25419. (neg|party_slot_eq, ":center_no", slot_village_infested_by_bandits, "trp_peasant_woman"),
  25420. ##diplomacy end
  25421. (store_faction_of_party, ":besieger_faction", ":besieger_party"),
  25422. (store_relation, ":reln", ":besieger_faction", ":center_faction"),
  25423. (ge, ":reln", 0),
  25424. (assign, ":siege_lifted", 1),
  25425. (try_end),
  25426.  
  25427.  
  25428. (eq, ":siege_lifted", 1),
  25429. #If another lord can take over the siege, it isn't lifted
  25430. ##diplomacy start+ Support promoted kingdom ladies
  25431. #(try_for_range, ":enemy_hero", active_npcs_begin, active_npcs_end),
  25432. (try_for_range, ":enemy_hero", heroes_begin, heroes_end),
  25433. ##diplomacy end+
  25434. (troop_slot_eq, ":enemy_hero", slot_troop_occupation, slto_kingdom_hero),
  25435. (troop_get_slot, ":enemy_party", ":enemy_hero", slot_troop_leaded_party),
  25436. (ge, ":enemy_party", 0),
  25437. (party_is_active, ":enemy_party"),
  25438. (store_faction_of_party, ":party_faction", ":enemy_party"),
  25439. (store_relation, ":reln", ":party_faction", ":center_faction"),
  25440. (lt, ":reln", 0),
  25441. (store_distance_to_party_from_party, ":distance", ":center_no", ":enemy_party"),
  25442. (lt, ":distance", 4),
  25443. (assign, ":besieger_party", ":enemy_party"),
  25444. (party_set_slot, ":center_no", slot_center_is_besieged_by, ":enemy_party"),
  25445. (assign, ":siege_lifted", 0),
  25446. (try_end),
  25447. (try_end),
  25448. (try_begin),
  25449. (eq, ":siege_lifted", 1),
  25450. (call_script, "script_lift_siege", ":center_no", 1),
  25451. (else_try),
  25452. (call_script, "script_center_get_food_consumption", ":center_no"),
  25453. (assign, ":food_consumption", reg0),
  25454. (val_sub, ":town_food_store", ":food_consumption"), # reduce food only under siege???
  25455. (try_begin),
  25456. (le, ":town_food_store", 0), #town is starving
  25457. (store_random_in_range, ":r", 0, 100),
  25458. (lt, ":r", 10),
  25459. (call_script, "script_party_wound_all_members", ":center_no"), # town falls with 10% chance if starving
  25460. (try_end),
  25461. (try_end),
  25462. (else_try),
  25463. #town is not under siege...
  25464. (val_add, ":town_food_store", 30), #add 30 food (significant for castles only.
  25465. (try_end),
  25466.  
  25467. (val_min, ":town_food_store", ":food_store_limit"),
  25468. (val_max, ":town_food_store", 0),
  25469. (party_set_slot, ":center_no", slot_party_food_store, ":town_food_store"),
  25470. (try_end),
  25471. ]),
  25472.  
  25473. # script_lift_siege
  25474. # Input: arg1 = center_no, arg2 = display_message
  25475. # Output: none
  25476. #called from triggers
  25477. ("lift_siege",
  25478. [
  25479. (store_script_param, ":center_no", 1),
  25480. (store_script_param, ":display_message", 2),
  25481. (party_set_slot, ":center_no", slot_center_is_besieged_by, -1), #clear siege
  25482. (call_script, "script_village_set_state", ":center_no", 0), #clear siege flag
  25483. (try_begin),
  25484. (eq, ":center_no", "$g_player_besiege_town"),
  25485. (assign, "$g_siege_method", 0), #remove siege progress
  25486. (try_end),
  25487. (try_begin),
  25488. (eq, ":display_message", 1),
  25489. (str_store_party_name_link, s3, ":center_no"),
  25490. (display_message, "@{s3} is no longer under siege."),
  25491. (try_end),
  25492.  
  25493. #SB : ideally we deal with post-conquest here but this is also called for cancelled sieges
  25494. ]),
  25495.  
  25496.  
  25497. # script_process_alarms
  25498. # Input: none
  25499. # Output: none
  25500. #called from triggers
  25501. ("process_alarms",
  25502. [
  25503. (assign, ":current_modula", "$g_alarm_modula"),
  25504. (val_add, "$g_alarm_modula", 1),
  25505. (try_begin),
  25506. (eq, "$g_alarm_modula", 3),
  25507. (assign, "$g_alarm_modula", 0),
  25508. (try_end),
  25509.  
  25510. (try_for_range, ":center_no", centers_begin, centers_end),
  25511. (store_mod, ":center_modula", ":center_no", 3),
  25512. (eq, ":center_modula", ":current_modula"),
  25513.  
  25514. (party_set_slot, ":center_no", slot_center_last_spotted_enemy, -1),
  25515. (party_set_slot, ":center_no", slot_center_sortie_strength, 0),
  25516. (party_set_slot, ":center_no", slot_center_sortie_enemy_strength, 0),
  25517.  
  25518. (assign, ":spotting_range", 3),
  25519. (try_begin),
  25520. (is_currently_night),
  25521. (assign, ":spotting_range", 2),
  25522. (try_end),
  25523.  
  25524. (try_begin),
  25525. (party_slot_eq, ":center_no", slot_center_has_watch_tower, 1),
  25526. (val_mul, ":spotting_range", 2),
  25527. (else_try),
  25528. (neg|is_between, ":center_no", villages_begin, villages_end),
  25529. (val_add, ":spotting_range", 1),
  25530. (val_mul, ":spotting_range", 2),
  25531. (try_end),
  25532.  
  25533. (store_faction_of_party, ":center_faction", ":center_no"),
  25534.  
  25535. (try_for_parties, ":party_no"),
  25536. (this_or_next|party_slot_eq, ":party_no", slot_party_type, spt_kingdom_hero_party),
  25537. (eq, ":party_no", "p_main_party"),
  25538.  
  25539. (store_faction_of_party, ":party_faction", ":party_no"),
  25540.  
  25541. (try_begin),
  25542. (eq, ":party_no", "p_main_party"),
  25543. (assign, ":party_faction", "$players_kingdom"),
  25544. (try_end),
  25545.  
  25546. (try_begin),
  25547. (eq, ":party_faction", ":center_faction"),
  25548.  
  25549. (store_distance_to_party_from_party, ":distance", ":party_no", ":center_no"),
  25550. (le, ":distance", ":spotting_range"),
  25551.  
  25552. (party_get_slot, ":cached_strength", ":party_no", slot_party_cached_strength),
  25553. (party_get_slot, ":sortie_strength", ":center_no", slot_center_sortie_strength),
  25554. (val_add, ":sortie_strength", ":cached_strength"),
  25555. (party_set_slot, ":center_no", slot_center_sortie_strength, ":sortie_strength"),
  25556. (else_try),
  25557. (neq, ":party_faction", ":center_faction"),
  25558.  
  25559. (store_distance_to_party_from_party, ":distance", ":party_no", ":center_no"),
  25560.  
  25561. (try_begin),
  25562. (lt, ":distance", 10),
  25563. (store_current_hours, ":hours"),
  25564. (store_sub, ":faction_recce_slot", ":party_faction", kingdoms_begin),
  25565. (val_add, ":faction_recce_slot", slot_center_last_reconnoitered_by_faction_time),
  25566. (party_set_slot, ":center_no", ":faction_recce_slot", ":hours"),
  25567.  
  25568. #(eq, "$cheat_mode", 1),
  25569. #(str_store_faction_name, s4, ":party_faction"),
  25570. #(str_store_party_name, s5, ":center_no"),
  25571. #(display_message, "@{!}DEBUG -- {s4} reconnoiters {s5}"),
  25572. (try_end),
  25573.  
  25574. (store_relation, ":reln", ":center_faction", ":party_faction"),
  25575. (lt, ":reln", 0),
  25576. (try_begin),
  25577. (le, ":distance", ":spotting_range"),
  25578.  
  25579. (party_get_slot, ":cached_strength", ":party_no", slot_party_cached_strength),
  25580. (party_get_slot, ":enemy_strength", ":center_no", slot_center_sortie_enemy_strength),
  25581. (val_add, ":enemy_strength", ":cached_strength"),
  25582. (party_set_slot, ":center_no", slot_center_sortie_enemy_strength, ":enemy_strength"),
  25583. (party_set_slot, ":center_no", slot_center_last_spotted_enemy, ":party_no"),
  25584. (try_end),
  25585.  
  25586. (try_end),
  25587. (try_end),
  25588. (try_end),
  25589.  
  25590. (try_for_range, ":center_no", centers_begin, centers_end),
  25591. (store_mod, ":center_modula", ":center_no", 3),
  25592. (eq, ":center_modula", ":current_modula"),
  25593.  
  25594. (try_begin), #eligible units sortie out of castle
  25595. (is_between, ":center_no", walled_centers_begin, walled_centers_end),
  25596. (party_slot_ge, ":center_no", slot_center_last_spotted_enemy, 0),
  25597.  
  25598. (party_get_slot, ":sortie_strength", ":center_no", slot_center_sortie_strength),
  25599. (party_get_slot, ":enemy_strength", ":center_no", slot_center_sortie_enemy_strength),
  25600.  
  25601. #Below two lines are new added by ozan. While AI want to drive nearby besieging enemy parties by making sortie them, they give up current battle if they are already joining one.
  25602. #Lets assume there is a battle inside the castle, because enemies are inside castle and they are so close to castle they will be also added to slot_center_sortie_enemy_strength
  25603. #But in this scenario, they are not outside the castle, so searching/patrolling enemy outside the castle is useless at this point.
  25604. #So if there is already a battle inside the center, do not sortie and search enemy outside.
  25605. (party_get_battle_opponent, ":center_battle_opponent", ":center_no"),
  25606. (try_begin),
  25607. (ge, "$cheat_mode", 1),
  25608. (ge, ":center_battle_opponent", 0),
  25609. (str_store_party_name, s7, ":center_no"),
  25610. (str_store_party_name, s6, ":center_battle_opponent"),
  25611. (display_message, "@{!}DEBUG : There are already enemies ({s6}) inside {s7}."),
  25612. (try_end),
  25613. (lt, ":center_battle_opponent", 0),
  25614. #New added by ozan ended.
  25615.  
  25616. (try_begin),
  25617. (eq, "$cheat_mode", 1),
  25618. (str_store_party_name, s4, ":center_no"),
  25619. (assign, reg3, ":sortie_strength"),
  25620. (assign, reg4, ":enemy_strength"),
  25621. (display_message, "@{!}DEBUG -- Calculating_sortie for {s4} strength of {reg3} vs {reg4} enemies"),
  25622. (try_end),
  25623.  
  25624. (store_mul, ":enemy_strength_mul_14_div_10", ":enemy_strength", 14),
  25625. (val_div, ":enemy_strength_mul_14_div_10", 10),
  25626. (gt, ":sortie_strength", ":enemy_strength_mul_14_div_10"),
  25627.  
  25628. (assign, ":at_least_one_party_sorties", 0),
  25629. (try_for_parties, ":sortie_party"),
  25630. (party_get_attached_to, ":town", ":sortie_party"),
  25631. (eq, ":town", ":center_no"),
  25632.  
  25633. (party_slot_eq, ":sortie_party", slot_party_type, spt_kingdom_hero_party),
  25634.  
  25635. (party_get_slot, ":cached_strength", ":sortie_party", slot_party_cached_strength),
  25636. (ge, ":cached_strength", 100),
  25637.  
  25638. (party_detach, ":sortie_party"),
  25639. (call_script, "script_party_set_ai_state", ":sortie_party", spai_patrolling_around_center, ":center_no"),
  25640.  
  25641. (try_begin),
  25642. (eq, "$cheat_mode", 1),
  25643. (str_store_party_name, s4, ":sortie_party"),
  25644. (display_message, "str_s4_sorties"),
  25645. (try_end),
  25646.  
  25647. (eq, ":at_least_one_party_sorties", 0),
  25648. (assign, ":at_least_one_party_sorties", ":sortie_party"),
  25649. (try_end),
  25650.  
  25651. (try_begin),
  25652. (party_is_in_town, "p_main_party", ":center_no"),
  25653. (eq, "$g_player_is_captive", 0),
  25654. (gt, ":at_least_one_party_sorties", 0),
  25655. (call_script, "script_add_notification_menu", "mnu_notification_sortie_possible", ":center_no", ":sortie_party"),
  25656. (try_end),
  25657. (try_end),
  25658.  
  25659. (store_faction_of_party, ":center_faction", ":center_no"),
  25660.  
  25661. #Send message
  25662. (this_or_next|eq, "$cheat_mode", 1), #this is message
  25663. (this_or_next|party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  25664. (eq, ":center_faction", "$players_kingdom"),
  25665.  
  25666. (party_get_slot, ":enemy_party", ":center_no", slot_center_last_spotted_enemy),
  25667. (ge, ":enemy_party", 0),
  25668. (store_distance_to_party_from_party, ":dist", "p_main_party", ":center_no"),
  25669. (assign, ":has_messenger", 0),
  25670. (try_begin),
  25671. ##diplomacy start+ Handle player is co-ruler of faction
  25672. (assign, ":is_coruler", 0),
  25673. (try_begin),
  25674. (eq, ":center_faction", "$players_kingdom"),
  25675. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  25676. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  25677. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  25678. (assign, ":is_coruler", 1),
  25679. (try_end),
  25680. (this_or_next|eq, ":is_coruler", 1),
  25681. ##diplomacy end+
  25682. (this_or_next|party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  25683. (eq, ":center_faction", "fac_player_supporters_faction"),
  25684. (party_slot_eq, ":center_no", slot_center_has_messenger_post, 1),
  25685. (assign, ":has_messenger", 1),
  25686. (try_end),
  25687.  
  25688. (this_or_next|eq, "$cheat_mode", 1),
  25689. (this_or_next|lt, ":dist", 30),
  25690. (eq, ":has_messenger", 1),
  25691.  
  25692. (str_store_party_name_link, s1, ":center_no"),
  25693. (party_get_slot, ":exact_enemy_strength", ":center_no", slot_center_sortie_enemy_strength),
  25694.  
  25695. (try_begin),
  25696. (lt, ":exact_enemy_strength", 500),
  25697. (display_message, "@Small bands of enemies spotted near {s1}."),
  25698. (else_try),
  25699. (lt, ":exact_enemy_strength", 1000),
  25700. (display_message, "@Enemy patrols spotted near {s1}."),
  25701. (else_try),
  25702. (lt, ":exact_enemy_strength", 2000),
  25703. (display_message, "@Medium-sized group of enemies spotted near {s1}."),
  25704. (else_try),
  25705. (lt, ":exact_enemy_strength", 4000),
  25706. (display_message, "@Significant group of enemies spotted near {s1}."),
  25707. (else_try),
  25708. (lt, ":exact_enemy_strength", 8000),
  25709. (display_message, "@Army of enemies spotted near {s1}."),
  25710. (else_try),
  25711. (lt, ":exact_enemy_strength", 16000),
  25712. (display_message, "@Large army of enemies spotted near {s1}."),
  25713. (else_try),
  25714. (display_message, "@Great host of enemies spotted near {s1}."),
  25715. (try_end),
  25716. #maybe do audio sound?
  25717.  
  25718. (try_end),
  25719. ]),
  25720.  
  25721. # script_allow_vassals_to_join_indoor_battle
  25722. # Input: none
  25723. # Output: none
  25724. ("allow_vassals_to_join_indoor_battle",
  25725. [
  25726. #if our commander attacks an enemy army
  25727. ##diplomacy start+ Support promoted kingdom ladies
  25728. #(try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
  25729. (try_for_range, ":troop_no", heroes_begin, heroes_end),
  25730. ##diplomacy end+
  25731. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  25732. (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  25733. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  25734. (gt, ":party_no", 0),
  25735. (party_is_active, ":party_no"),
  25736.  
  25737. (party_get_attached_to, ":party_is_attached_to", ":party_no"),
  25738. (lt, ":party_is_attached_to", 0),
  25739.  
  25740. (store_troop_faction, ":faction_no", ":troop_no"),
  25741.  
  25742. (try_begin),
  25743. #(faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemies_around_center),
  25744. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  25745. (party_get_slot, ":commander_party", ":party_no", slot_party_ai_object),
  25746. (gt, ":commander_party", 0),
  25747. (party_is_active, ":commander_party"),
  25748.  
  25749. (assign, ":besieged_center", -1),
  25750. (try_begin),
  25751. (party_slot_eq, ":commander_party", slot_party_ai_state, spai_holding_center), #if commander is holding a center
  25752. (party_get_slot, ":commander_object", ":commander_party", slot_party_ai_object), #get commander's ai object (center they are holding)
  25753. (party_get_battle_opponent, ":besieger_enemy", ":commander_object"), #get this object's battle opponent
  25754. (party_is_active, ":besieger_enemy"),
  25755. (assign, ":besieged_center", ":commander_object"),
  25756. (assign, ":commander_object", ":besieger_enemy"),
  25757. (else_try),
  25758. (party_slot_eq, ":commander_party", slot_party_ai_state, spai_engaging_army), #if commander is engaging an army
  25759. (party_get_slot, ":commander_object", ":commander_party", slot_party_ai_object), #get commander's ai object (army which they engaded)
  25760. (ge, ":commander_object", 0), #if commander has an object
  25761. (neg|is_between, ":commander_object", centers_begin, centers_end), #if this object is not a center, so it is a party
  25762. (party_is_active, ":commander_object"),
  25763. (party_get_battle_opponent, ":besieged_center", ":commander_object"), #get this object's battle opponent
  25764. (else_try),
  25765. (assign, ":besieged_center", -1),
  25766. (try_end),
  25767.  
  25768. (is_between, ":besieged_center", walled_centers_begin, walled_centers_end), #if battle opponent of our commander's ai object is a walled center
  25769.  
  25770. (party_get_attached_to, ":attached_to_party", ":commander_party"), #if commander is attached to besieged center already.
  25771. (eq, ":attached_to_party", ":besieged_center"),
  25772.  
  25773. (store_faction_of_party, ":besieged_center_faction", ":besieged_center"),#get (battle opponent of our commander's ai object)'s faction
  25774. (eq, ":besieged_center_faction", ":faction_no"), #if battle opponent of our commander's ai object is from same faction with current party
  25775. (party_is_active, ":commander_object"),
  25776. #make also follow_or_not check if needed
  25777.  
  25778. (call_script, "script_party_set_ai_state", ":party_no", spai_engaging_army, ":commander_object"), #go and help commander
  25779.  
  25780. (try_begin),
  25781. (eq, "$cheat_mode", 1),
  25782. (str_store_party_name, s7, ":party_no"),
  25783. (str_store_party_name, s6, ":commander_object"),
  25784. (display_message, "@{!}DEBUG : {s7} is helping his commander by fighting with {s6}."),
  25785. (try_end),
  25786. (else_try),
  25787. #(faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_center),
  25788.  
  25789. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  25790. (party_get_slot, ":commander_party", ":party_no", slot_party_ai_object),
  25791. (gt, ":commander_party", 0),
  25792. (party_is_active, ":commander_party"),
  25793.  
  25794. (party_get_battle_opponent, ":besieged_center", ":commander_party"), #get this object's battle opponent
  25795.  
  25796. #make also follow_or_not check if needed
  25797.  
  25798. (is_between, ":besieged_center", walled_centers_begin, walled_centers_end), #if this object is a center
  25799. (party_get_attached_to, ":attached_to_party", ":party_no"),
  25800. (neq, ":attached_to_party", ":besieged_center"),
  25801. (party_is_active, ":besieged_center"),
  25802.  
  25803. (call_script, "script_party_set_ai_state", ":party_no", spai_engaging_army, ":besieged_center"), #go and help commander
  25804.  
  25805. #(try_begin),
  25806. # (eq, "$cheat_mode", 1),
  25807. # (str_store_party_name, s7, ":party_no"),
  25808. # (str_store_party_name, s6, ":besieged_center"),
  25809. # (display_message, "@{!}DEBUG : {s7} is helping his commander by attacking {s6}."),
  25810. #(try_end),
  25811.  
  25812. #(party_set_ai_behavior, ":party_no", ai_bhvr_attack_party),
  25813. #(party_set_ai_object, ":party_no", ":besieged_center"),
  25814. #(party_set_flags, ":party_no", pf_default_behavior, 1), #is these needed?
  25815. #(party_set_slot, ":party_no", slot_party_ai_substate, 1), #is these needed?
  25816. (try_end),
  25817. (try_end),
  25818. ]),
  25819.  
  25820. # script_party_set_ai_state
  25821. # Input: arg1 = party_no, arg2 = new_ai_state, arg3 = action_object (if necessary)
  25822. # Output: none (Can fail)
  25823.  
  25824. #Redone somewhat on Feb 18 to make sure that initative is set properly
  25825.  
  25826. ("party_set_ai_state",
  25827. [
  25828. (store_script_param, ":party_no", 1),
  25829. (store_script_param, ":new_ai_state", 2),
  25830. (store_script_param, ":new_ai_object", 3),
  25831.  
  25832. (party_get_slot, ":old_ai_state", ":party_no", slot_party_ai_state),
  25833. (party_get_slot, ":old_ai_object", ":party_no", slot_party_ai_object),
  25834. (party_get_attached_to, ":attached_to_party", ":party_no"),
  25835. (assign, ":party_is_in_town", 0),
  25836. (try_begin),
  25837. (is_between, ":attached_to_party", centers_begin, centers_end),
  25838. (assign, ":party_is_in_town", ":attached_to_party"),
  25839. (try_end),
  25840.  
  25841. (assign, ":commander", -1),
  25842. (try_begin),
  25843. (party_is_active, ":party_no"),
  25844. (party_stack_get_troop_id, ":commander", ":party_no", 0),
  25845. (store_faction_of_party, ":faction_no", ":party_no"),
  25846. (try_end),
  25847.  
  25848. (try_begin),
  25849. (lt, ":commander", 0),
  25850. #sometimes 0 sized parties enter "party_set_ai_state" script. So only discard them
  25851. #(try_begin),
  25852. # (eq, "$cheat_mode", 1),
  25853. # (str_store_troop_name, s6, ":party_no"),
  25854. # (party_get_num_companions, reg6, ":party_no"),
  25855. # (display_message, "@{!}DEBUGS : party name is : {s6}, party size is : {reg6}, new ai discarded."),
  25856. #(try_end),
  25857. (else_try),
  25858. #Party does any business in town
  25859. (try_begin),
  25860. (is_between, ":party_is_in_town", walled_centers_begin, walled_centers_end),
  25861. (party_slot_eq, ":party_is_in_town", slot_center_is_besieged_by, -1),
  25862. (call_script, "script_troop_does_business_in_center", ":commander", ":party_is_in_town"),
  25863. (else_try),
  25864. (party_slot_eq, ":party_no", slot_party_ai_state, spai_visiting_village),
  25865. (party_get_slot, ":party_is_in_village", ":party_no", slot_party_ai_object),
  25866. (is_between, ":party_is_in_village", villages_begin, villages_end),
  25867. #(party_slot_eq, ":party_is_in_village", slot_center_is_looted_by, -1),
  25868. (call_script, "script_cf_village_normal_cond", ":party_is_in_village"), #SB : script condition
  25869. # (neg|party_slot_eq, ":party_is_in_village", slot_village_state, svs_being_raided),
  25870. # (neg|party_slot_eq, ":party_is_in_village", slot_village_state, svs_deserted), #SB : deserted condition
  25871. # (neg|party_slot_eq, ":party_is_in_village", slot_village_state, svs_looted),
  25872. (store_distance_to_party_from_party, ":distance", ":party_no", ":party_is_in_village"),
  25873. (lt, ":distance", 3),
  25874. (call_script, "script_troop_does_business_in_center", ":commander", ":party_is_in_village"),
  25875. (try_end),
  25876.  
  25877. (party_set_slot, ":party_no", slot_party_follow_me, 0),
  25878.  
  25879. (try_begin),
  25880. (eq, ":old_ai_state", ":new_ai_state"),
  25881. (eq, ":old_ai_object", ":new_ai_object"),
  25882. #do nothing. Nothing is changed.
  25883. (else_try),
  25884. (assign, ":initiative", 100),
  25885. (assign, ":aggressiveness", 8),
  25886. (assign, ":courage", 8),
  25887.  
  25888. (try_begin),
  25889. (this_or_next|eq, ":new_ai_state", spai_accompanying_army),
  25890. (eq, ":new_ai_state", spai_screening_army),
  25891.  
  25892. (party_set_ai_behavior, ":party_no", ai_bhvr_escort_party),
  25893. (party_set_ai_object, ":party_no", ":new_ai_object"),
  25894. (party_set_flags, ":party_no", pf_default_behavior, 0),
  25895.  
  25896. (try_begin),
  25897. (gt, ":party_is_in_town", 0),
  25898. (party_detach, ":party_no"),
  25899. (try_end),
  25900.  
  25901. (try_begin),
  25902. (eq, ":new_ai_state", spai_screening_army),
  25903. (assign, ":aggressiveness", 9),
  25904. (assign, ":courage", 9),
  25905. (assign, ":initiative", 80),
  25906. (else_try),
  25907. (assign, ":aggressiveness", 6),
  25908. (assign, ":courage", 9),
  25909. (assign, ":initiative", 10),
  25910. (try_end),
  25911. (else_try),
  25912. (eq, ":new_ai_state", spai_besieging_center),
  25913.  
  25914. (party_get_position, pos1, ":new_ai_object"),
  25915. (map_get_random_position_around_position, pos2, pos1, 2),
  25916. (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_point),
  25917. (party_set_ai_target_position, ":party_no", pos2),
  25918. (party_set_ai_object, ":party_no", ":new_ai_object"),
  25919. (party_set_flags, ":party_no", pf_default_behavior, 0),
  25920. (party_set_slot, ":party_no", slot_party_follow_me, 1),
  25921. (party_set_slot, ":party_no", slot_party_ai_substate, 0),
  25922.  
  25923. (try_begin),
  25924. (gt, ":party_is_in_town", 0),
  25925. (neq, ":party_is_in_town", ":new_ai_object"),
  25926. (party_detach, ":party_no"),
  25927. (try_end),
  25928.  
  25929. (assign, ":aggressiveness", 1),
  25930. (assign, ":courage", 9),
  25931. (assign, ":initiative", 20),
  25932. #(assign, ":initiative", 100),
  25933. (else_try),
  25934. (eq, ":new_ai_state", spai_holding_center),
  25935.  
  25936. (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
  25937. (party_set_ai_object, ":party_no", ":new_ai_object"),
  25938. (party_set_flags, ":party_no", pf_default_behavior, 0),
  25939.  
  25940. (try_begin),
  25941. (gt, ":party_is_in_town", 0),
  25942. (neq, ":party_is_in_town", ":new_ai_object"),
  25943. (party_detach, ":party_no"),
  25944. (try_end),
  25945.  
  25946. (assign, ":aggressiveness", 7),
  25947. (assign, ":courage", 9),
  25948. (assign, ":initiative", 100),
  25949. #(party_set_ai_initiative, ":party_no", 99),
  25950. (else_try),
  25951. (eq, ":new_ai_state", spai_patrolling_around_center),
  25952. (party_get_position, pos1, ":new_ai_object"),
  25953. (map_get_random_position_around_position, pos2, pos1, 1),
  25954. (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_point),
  25955. (party_set_ai_target_position, ":party_no", pos2),
  25956. (party_set_ai_object, ":party_no", ":new_ai_object"),
  25957.  
  25958. (try_begin),
  25959. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemies_around_center),
  25960. (party_set_ai_patrol_radius, ":party_no", 1), #line 100
  25961. (else_try),
  25962. (party_set_ai_patrol_radius, ":party_no", 5), #line 100
  25963. (try_end),
  25964.  
  25965. (party_set_flags, ":party_no", pf_default_behavior, 0),
  25966. (party_set_slot, ":party_no", slot_party_follow_me, 1),
  25967. (party_set_slot, ":party_no", slot_party_ai_substate, 0),
  25968.  
  25969. (try_begin),
  25970. (gt, ":party_is_in_town", 0),
  25971. (party_detach, ":party_no"),
  25972. (try_end),
  25973.  
  25974. (try_begin),
  25975. #new to avoid losing time of marshal with attacking unimportant targets while there is a threat in our centers.
  25976. (ge, ":commander", 0),
  25977. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":commander"),
  25978. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemies_around_center),
  25979.  
  25980. (party_get_position, pos3, ":party_no"),
  25981. (get_distance_between_positions, ":distance_to_center", pos1, pos3),
  25982.  
  25983. (try_begin),
  25984. (ge, ":distance_to_center", 800), #added new (1.122)
  25985. (assign, ":initiative", 10),
  25986. (assign, ":aggressiveness", 1),
  25987. (assign, ":courage", 8),
  25988. (else_try), #below added new (1.122)
  25989. (assign, ":initiative", 100),
  25990. (assign, ":aggressiveness", 8),
  25991. (assign, ":courage", 8),
  25992. (try_end),
  25993. (else_try),
  25994. (assign, ":aggressiveness", 8),
  25995. (assign, ":courage", 8),
  25996. (assign, ":initiative", 100),
  25997. (try_end),
  25998. (else_try),
  25999. (eq, ":new_ai_state", spai_visiting_village),
  26000. (party_get_position, pos1, ":new_ai_object"),
  26001. (map_get_random_position_around_position, pos2, pos1, 2),
  26002. (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_point),
  26003. (party_set_ai_target_position, ":party_no", pos2),
  26004. (party_set_ai_object, ":party_no", ":new_ai_object"),
  26005. (party_set_flags, ":party_no", pf_default_behavior, 0),
  26006. (party_set_slot, ":party_no", slot_party_ai_substate, 0),
  26007. (try_begin),
  26008. (gt, ":party_is_in_town", 0),
  26009. (neq, ":party_is_in_town", ":new_ai_object"),
  26010. (party_detach, ":party_no"),
  26011. (try_end),
  26012.  
  26013. (assign, ":aggressiveness", 8),
  26014. (assign, ":courage", 8),
  26015. (assign, ":initiative", 100),
  26016. (else_try), #0.660: this is where the 1625/1640 bugs happen with an improper ai_object
  26017. (eq, ":new_ai_state", spai_raiding_around_center),
  26018. (party_get_position, pos1, ":new_ai_object"),
  26019. (map_get_random_position_around_position, pos2, pos1, 1),
  26020. (party_set_ai_behavior, ":party_no", ai_bhvr_patrol_location),
  26021. (party_set_ai_patrol_radius, ":party_no", 10),
  26022. (party_set_ai_target_position, ":party_no", pos2),
  26023. (party_set_ai_object, ":party_no", ":new_ai_object"),
  26024. (party_set_flags, ":party_no", pf_default_behavior, 0),
  26025. (party_set_slot, ":party_no", slot_party_follow_me, 1),
  26026. (party_set_slot, ":party_no", slot_party_ai_substate, 0),
  26027. (try_begin),
  26028. (gt, ":party_is_in_town", 0),
  26029. (neq, ":party_is_in_town", ":new_ai_object"),
  26030. (party_detach, ":party_no"),
  26031. (try_end),
  26032.  
  26033. (try_begin),
  26034. (ge, ":commander", 0),
  26035. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":commander"),
  26036. (assign, ":aggressiveness", 1),
  26037. (assign, ":courage", 8),
  26038. (assign, ":initiative", 20),
  26039. (else_try),
  26040. (assign, ":aggressiveness", 7),
  26041. (assign, ":courage", 8),
  26042. (assign, ":initiative", 100),
  26043. (try_end),
  26044. (else_try),
  26045. (eq, ":new_ai_state", spai_engaging_army),
  26046.  
  26047. (party_set_ai_behavior, ":party_no", ai_bhvr_attack_party),
  26048. (party_set_ai_object, ":party_no", ":new_ai_object"),
  26049. (party_set_flags, ":party_no", pf_default_behavior, 0),
  26050. (try_begin),
  26051. (gt, ":party_is_in_town", 0),
  26052. (party_detach, ":party_no"),
  26053. (try_end),
  26054.  
  26055. (try_begin),
  26056. #new to avoid losing time of marshal with attacking unimportant targets while there is a threat in our centers.
  26057. (ge, ":commander", 0),
  26058. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":commander"),
  26059. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemies_around_center),
  26060. (assign, ":initiative", 10),
  26061. (assign, ":aggressiveness", 1),
  26062. (assign, ":courage", 8),
  26063. (else_try),
  26064. (assign, ":aggressiveness", 8),
  26065. (assign, ":courage", 8),
  26066. (assign, ":initiative", 100),
  26067. (try_end),
  26068. (else_try),
  26069. (eq, ":new_ai_state", spai_retreating_to_center),
  26070. (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
  26071. (party_set_ai_object, ":party_no", ":new_ai_object"),
  26072. (party_set_flags, ":party_no", pf_default_behavior, 1),
  26073. (party_set_slot, ":party_no", slot_party_commander_party, -1),
  26074. (try_begin),
  26075. (gt, ":party_is_in_town", 0),
  26076. (neq, ":party_is_in_town", ":new_ai_object"),
  26077. (party_detach, ":party_no"),
  26078. (try_end),
  26079.  
  26080. (assign, ":aggressiveness", 3),
  26081. (assign, ":courage", 4),
  26082. (assign, ":initiative", 100),
  26083. (else_try),
  26084. (eq, ":new_ai_state", spai_undefined),
  26085. (party_set_ai_behavior, ":party_no", ai_bhvr_hold),
  26086. (party_set_flags, ":party_no", pf_default_behavior, 0),
  26087. (try_end),
  26088.  
  26089. (try_begin),
  26090. (troop_slot_eq, ":commander", slot_lord_reputation_type, lrep_martial),
  26091. (val_add, ":aggressiveness", 2),
  26092. (val_add, ":courage", 2),
  26093. (else_try),
  26094. ##diplomacy start+ support lady personality types
  26095. (neg|troop_slot_eq, ":commander", slot_lord_reputation_type, lrep_adventurous),
  26096. (this_or_next|troop_slot_ge, ":commander", slot_lord_reputation_type, dplmc_lrep_ladies_begin),
  26097. ##diplomacy end+
  26098. (troop_slot_eq, ":commander", slot_lord_reputation_type, lrep_debauched),
  26099. (val_sub, ":aggressiveness", 1),
  26100. (val_sub, ":courage", 1),
  26101. (try_end),
  26102.  
  26103. (party_set_slot, ":party_no", slot_party_ai_state, ":new_ai_state"),
  26104. (party_set_slot, ":party_no", slot_party_ai_object, ":new_ai_object"),
  26105. (party_set_aggressiveness, ":party_no", ":aggressiveness"),
  26106. (party_set_courage, ":party_no", ":courage"),
  26107. (party_set_ai_initiative, ":party_no", ":initiative"),
  26108. (try_end),
  26109. (try_end),
  26110.  
  26111. #Helpfulness
  26112. (try_begin),
  26113. (ge, ":commander", 0),
  26114.  
  26115. (party_set_helpfulness, ":party_no", 101),
  26116. (try_begin),
  26117. (troop_slot_eq, ":commander", slot_lord_reputation_type, lrep_martial),
  26118. (party_set_helpfulness, ":party_no", 200),
  26119. (else_try),
  26120. (troop_slot_eq, ":commander", slot_lord_reputation_type, lrep_upstanding),
  26121. (party_set_helpfulness, ":party_no", 150),
  26122. (else_try),
  26123. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  26124. (party_set_helpfulness, ":party_no", 110),
  26125. (else_try),
  26126. (troop_slot_eq, ":commander", slot_lord_reputation_type, lrep_quarrelsome),
  26127. (party_set_helpfulness, ":party_no", 90),
  26128. (else_try),
  26129. (troop_slot_eq, ":commander", slot_lord_reputation_type, lrep_selfrighteous),
  26130. (party_set_helpfulness, ":party_no", 80),
  26131. (else_try),
  26132. (troop_slot_eq, ":commander", slot_lord_reputation_type, lrep_debauched),
  26133. (party_set_helpfulness, ":party_no", 50),
  26134. (try_end),
  26135. (try_end),
  26136. ]),
  26137.  
  26138. ("cf_party_under_player_suggestion",
  26139. [
  26140. (store_script_param, ":party_no", 1),
  26141.  
  26142. (party_slot_eq, ":party_no", slot_party_following_orders_of_troop, "trp_kingdom_heroes_including_player_begin"),
  26143.  
  26144. (party_get_slot, ":ai_state", ":party_no", slot_party_ai_state),
  26145. (party_slot_eq, ":party_no", slot_party_orders_type, ":ai_state"),
  26146.  
  26147. (party_get_slot, ":ai_object", ":party_no", slot_party_ai_object),
  26148. (party_slot_eq, ":party_no", slot_party_orders_object, ":ai_object"),
  26149.  
  26150. (store_current_hours, ":hours_since_orders_given"),
  26151. (party_get_slot, ":orders_time", ":party_no", slot_party_orders_time),
  26152.  
  26153. (val_sub, ":hours_since_orders_given", ":orders_time"),
  26154. (lt, ":hours_since_orders_given", 12),
  26155. ]),
  26156.  
  26157. #Currently called from process_ai_state, could be called from elsewhere
  26158. #It is used for lord to (1)Court ladies (2)Collect rents (3)Look for volunteers
  26159. ## Upgrade equipment (by quality) and hire mercenaries (if Martial personality)
  26160. ("troop_does_business_in_center",
  26161. [
  26162. (store_script_param, ":troop_no", 1),
  26163. (store_script_param, ":center_no", 2),
  26164. ##diplomacy start+
  26165. #Call this once and reuse below.
  26166. (call_script, "script_dplmc_is_affiliated_family_member", ":troop_no"),
  26167. (assign, ":is_affiliated", reg0),
  26168. #Also enable for the spouse, unless you're on bad terms
  26169. (try_begin),
  26170. (lt, ":is_affiliated", 0),
  26171. (this_or_next|troop_slot_eq,":troop_no",slot_troop_spouse, "trp_player"),
  26172. (troop_slot_eq,"trp_player",slot_troop_spouse, ":troop_no"),
  26173. (call_script, "script_troop_get_player_relation", ":troop_no"),
  26174. (store_skill_level, ":persuasion", "skl_persuasion", "trp_player"),
  26175. (val_add, reg0, ":persuasion"),
  26176. #reduce magnitude, since >= 0 succeeds
  26177. (store_sub, ":persuasion_modifier", 20, ":persuasion"),
  26178. (val_mul, reg0, ":persuasion_modifier"),
  26179. (val_div, reg0, 20),
  26180. #final number must be >= -5
  26181. (ge, reg0, -5),
  26182. (assign, ":is_affiliated", 1),
  26183. (try_end),
  26184. ##diplomacy end+
  26185.  
  26186. (troop_get_slot, ":led_party", ":troop_no", slot_troop_leaded_party),
  26187. (troop_get_slot, ":troop_wealth", ":troop_no", slot_troop_wealth), #SB : moved up
  26188. (assign, ":initial_wealth", ":troop_wealth"), #DEBUG
  26189.  
  26190. (store_current_hours, ":current_time"),
  26191. (try_begin),
  26192. # (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"), #this was added to get lords in centers out and visiting their fiefs, but I've adjusted the decision checklist
  26193. (is_between, ":center_no", walled_centers_begin, walled_centers_end),
  26194. (party_set_slot, ":led_party", slot_party_last_in_any_center, ":current_time"),
  26195. (try_begin),
  26196. (call_script, "script_lord_get_home_center", ":troop_no"),
  26197. (eq, ":center_no", reg0),
  26198. (party_set_slot, ":led_party", slot_party_last_in_home_center, ":current_time"),
  26199. (try_end),
  26200. (try_end),
  26201.  
  26202. #Collect the rents
  26203. (try_begin),
  26204. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  26205.  
  26206. (party_get_slot, ":accumulated_rents", ":center_no", slot_center_accumulated_rents),
  26207. (party_get_slot, ":accumulated_tariffs", ":center_no", slot_center_accumulated_tariffs),
  26208. # (troop_get_slot, ":troop_wealth", ":troop_no", slot_troop_wealth),
  26209. (val_add, ":troop_wealth", ":accumulated_rents"),
  26210. (val_add, ":troop_wealth", ":accumulated_tariffs"),
  26211.  
  26212. (troop_set_slot, ":troop_no", slot_troop_wealth, ":troop_wealth"),
  26213. (party_set_slot, ":center_no", slot_center_accumulated_rents, 0),
  26214. (party_set_slot, ":center_no", slot_center_accumulated_tariffs, 0),
  26215.  
  26216. ## upgrade owned centers
  26217.  
  26218. (call_script, "script_calculate_improvement_limit", ":troop_no", ":center_no"),
  26219. (assign, ":limit", reg0),
  26220.  
  26221. (try_begin),
  26222. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  26223. (gt, ":troop_wealth", ":limit"), #surplus cash
  26224. (party_slot_eq, ":center_no", slot_center_current_improvement, 0), #not already building
  26225. (assign, ":continue", 1),
  26226. #this randomization applies so that there is a chance of not building an improvement (1/6) or (4/6)
  26227. (store_random_in_range, ":improvement_no", village_improvements_begin, walled_center_improvements_end),
  26228. (party_slot_eq, ":center_no", ":improvement_no", 0), #not already built
  26229. (try_begin), #villages
  26230. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  26231. (ge, ":improvement_no", village_improvements_end),
  26232. (assign, ":continue", 0),
  26233. (else_try), #towns, castles
  26234. (lt, ":improvement_no", walled_center_improvements_begin),
  26235. (assign, ":continue", 0),
  26236. (try_end),
  26237. (eq, ":continue", 1),
  26238. (call_script, "script_get_improvement_details", ":improvement_no"),
  26239. (assign, ":improvement_cost", reg0), # 4000-9000
  26240. # calculate cost offset from lord
  26241. (store_attribute_level, ":int", ":troop_no", ca_intelligence), #10-70
  26242. (store_skill_level, ":skill", "skl_engineer", ":troop_no"), #0 to 15
  26243. (val_mul, ":skill", ":int"), # 0 to 105
  26244. (store_character_level, ":level", ":troop_no"), #22-50
  26245. (val_add, ":skill", ":level"),
  26246. (val_sub, ":improvement_cost", ":skill"),
  26247.  
  26248. #get working strength
  26249. (party_get_num_companions, ":divider", ":center_no"), #0~300, ignoring wounded
  26250. (party_get_num_prisoners, ":num_prisoners", ":center_no"), #possibly up to 100
  26251. (val_min, ":num_prisoners", 100),
  26252.  
  26253. #account for serfs, each level past base adds 25 effective manpower
  26254. (store_faction_of_party, ":faction_no", ":center_no"),
  26255. (faction_get_slot, ":serfdom", ":faction_no", dplmc_slot_faction_serfdom),
  26256. (val_add, ":serfdom", 3),
  26257. (val_mul, ":serfdom", 25),
  26258. (val_add, ":divider", ":serfdom"),
  26259. (gt, ":divider", ":num_prisoners"),
  26260.  
  26261. #calculate time - manpower, prosperity, and int/level-based
  26262. (party_get_slot, ":multiplier", ":center_no", slot_town_prosperity), #0 to 100
  26263. (val_sub, ":multiplier", ":num_prisoners"), #feeding drags prosperity down
  26264. (store_sub, ":multiplier", 300, ":multiplier"), #300 to 100
  26265. (val_add, ":divider", ":skill"), #total 30~500 added from lord
  26266.  
  26267. (store_mul, ":improvement_time", ":improvement_cost", ":multiplier"), #400000 - 2700000
  26268. (val_div, ":improvement_time", 100),
  26269. (val_div, ":improvement_time", ":divider"), #18.18~800
  26270. (lt, ":improvement_time", 160), #feasible
  26271. (val_max, ":improvement_time", 3), #not instantaneous
  26272.  
  26273. (val_sub, ":troop_wealth", ":improvement_cost"),
  26274. (troop_set_slot, ":troop_no", slot_troop_wealth, ":troop_wealth"),
  26275. (try_begin),
  26276. (this_or_next|eq, "$cheat_mode", 3),
  26277. (ge, ":is_affiliated", 1),#<-- dplmc+ added
  26278. (assign, reg6, ":improvement_time"),
  26279. (str_store_troop_name_link, s10, ":troop_no"),
  26280. #s0 comes from improvement_details
  26281. (display_log_message, "@{s10} constructs a {s0} in {s4}", message_alert),
  26282. (try_end),
  26283. (assign, "$g_improvement_type", ":improvement_no"),
  26284. # (assign, reg6, ":improvement_time"),
  26285. (call_script, "script_improve_center", ":center_no", ":troop_no", ":improvement_time"),
  26286. (try_end),
  26287. ##
  26288. ##diplomacy start+
  26289. #Modify the next block to display for affiliates
  26290. (try_begin),
  26291. (this_or_next|ge, ":is_affiliated", 1),#<-- dplmc+ added
  26292. (this_or_next|eq, "$cheat_mode", 1),
  26293. (eq, "$cheat_mode", 3),
  26294. (assign, reg1, ":troop_wealth"),
  26295. (str_store_party_name_link, s4, ":center_no"),
  26296. (add_troop_note_from_sreg, ":troop_no", 1, "str_current_wealth_reg1_taxes_last_collected_from_s4", 0),
  26297. #New section, print a message for affiliates:
  26298. (ge, ":is_affiliated", 1),
  26299. (store_add, reg0, ":accumulated_rents", ":accumulated_tariffs"),
  26300. (str_store_troop_name_link, s0, ":troop_no"),
  26301. (try_begin),
  26302. (gt, reg0, 0),
  26303. (display_log_message, "@{s0} collects {reg0} denars from {s4}, current wealth: {reg1} denars"),
  26304. (try_end),
  26305. (try_end),
  26306. ##diplomacy end+
  26307. (try_end),
  26308.  
  26309. #Recruit volunteers
  26310. (try_begin),
  26311. (is_between, ":center_no", villages_begin, villages_end),
  26312. (party_get_slot, ":troop_amount", ":center_no", slot_center_npc_volunteer_troop_amount),
  26313. (gt, ":troop_amount", 0),
  26314.  
  26315. (party_get_slot, ":troop_type", ":center_no", slot_center_npc_volunteer_troop_type),
  26316. (party_set_slot, ":center_no", slot_center_npc_volunteer_troop_amount, -1),
  26317. ##diplomacy begin
  26318. (try_begin),
  26319. (store_faction_of_party, ":party_faction", ":led_party"),
  26320. (eq, ":party_faction", "fac_player_supporters_faction"),
  26321. (is_between, "$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  26322. (faction_get_slot, ":troop_type", "$g_player_culture", slot_faction_tier_1_troop),
  26323. (try_end),
  26324.  
  26325. (try_begin), #debug
  26326. ##nested diplomacy start+
  26327. (this_or_next|ge, ":is_affiliated", 1),#<- Show for affiliates
  26328. (eq, "$cheat_mode", 1),
  26329. ##nested diplomacy end+
  26330. (assign, reg2, ":troop_amount"),
  26331. # (str_store_string, s11, "@{reg2}"),
  26332. (str_store_troop_name, s12, ":troop_type"),
  26333. (str_store_faction_name_link, s13, ":party_faction"),
  26334. (str_store_party_name_link, s14, ":center_no"),
  26335. (str_store_party_name, s10, ":led_party"),
  26336. (display_log_message, "@ {s10} of {s13} recruits {reg2} {s12} in {s14}"),
  26337. (try_end),
  26338.  
  26339. ##diplomacy end
  26340. (party_add_members, ":led_party", ":troop_type", ":troop_amount"),
  26341. (else_try), ##do business in centers
  26342. (is_between, ":center_no", towns_begin, towns_end),
  26343. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  26344.  
  26345. (try_begin), #hiring mercenaries
  26346. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_morality_type, tmt_egalitarian),
  26347. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_2ary_morality_type, tmt_egalitarian),
  26348. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_2ary_morality_type, tmt_aristocratic),
  26349. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_martial),
  26350. (party_get_slot, ":mercenary_troop", ":center_no", slot_center_mercenary_troop_type),
  26351. (gt, ":mercenary_troop", 0),
  26352. (store_character_level, ":level", ":mercenary_troop"),
  26353. #chance of not hiring
  26354. (store_random_in_range, ":reduce", ":level", 100),
  26355. (gt, ":reduce", 69), #favors high-level
  26356. # (game_get_reduce_campaign_ai, ":reduce"), #0 to 2
  26357. # (val_mul, ":reduce", 5), #0 to 10
  26358. # (store_sub, ":reduce", 26, ":reduce"), #26 to 16
  26359. # (lt, ":level", ":reduce"), #no special mercs - on hard can hire top-tier, on easy caravan guard/xbow/lower
  26360. (party_get_slot, ":mercenary_amount", ":center_no", slot_center_mercenary_troop_amount),
  26361. (call_script, "script_game_get_join_cost", ":mercenary_troop"),
  26362. (assign, ":troop_cost", reg0),
  26363. # (try_begin), #slight discount for improvement
  26364. # (party_get_slot, ":reduce", ":center_no", slot_center_has_mercenary_hall),
  26365. # (val_add, ":reduce", 5),
  26366. # (val_mul, ":troop_cost", 5),
  26367. # (val_div, ":troop_cost", ":reduce"),
  26368. # (try_end),
  26369. #test wealth levels - a tenth normally can be used
  26370. (store_faction_of_troop, ":faction_no", ":troop_no"),
  26371. (faction_get_slot, ":quality", ":faction_no", dplmc_slot_faction_quality),
  26372. (val_add, ":quality", 10),
  26373. #use faction quality to determine percentage of wealth used for mercenaries
  26374. (store_div, ":divider", ":troop_wealth", ":quality"),
  26375. (val_div, ":divider", ":troop_cost"),
  26376. (val_min, ":divider", ":mercenary_amount"),
  26377.  
  26378.  
  26379. #set the proper slots
  26380. (try_begin),
  26381. (gt, ":divider", 0),
  26382. (party_add_members, ":led_party", ":mercenary_troop", ":divider"),
  26383. (val_mul, ":troop_cost", ":divider"),
  26384. (val_sub, ":troop_wealth", ":troop_cost"),
  26385. (store_sub, ":mercenary_amount", ":mercenary_amount", ":divider"),
  26386. (party_set_slot, ":center_no", slot_center_mercenary_troop_amount, ":mercenary_amount"),
  26387. (try_begin),
  26388. (le, ":mercenary_amount", 0),
  26389. (party_set_slot, ":center_no", slot_center_mercenary_troop_amount, -1),
  26390. (party_set_slot, ":center_no", slot_center_mercenary_troop_type, -1),
  26391. (else_try),
  26392. (party_set_slot, ":center_no", slot_center_mercenary_troop_amount, ":mercenary_amount"),
  26393. (try_end),
  26394. (try_begin), #debug
  26395. (this_or_next|ge, ":is_affiliated", 1),#<- Show for affiliates
  26396. (ge, "$cheat_mode", 1),
  26397. (assign, reg2, ":divider"),
  26398. (str_store_troop_name_by_count, s12, ":mercenary_troop", reg2),
  26399. (display_log_message, "@{s10} hires {reg2} {s12} in {s4}"),
  26400. (try_end),
  26401. (try_end),
  26402. (try_end),
  26403. ##upgrade equipment from merchants
  26404. (call_script, "script_calculate_equipment_limit", ":troop_no", ":center_no"),
  26405. (assign, ":equipment_limit", reg0),
  26406. #we assume startup gear is sufficient - only quality matters
  26407. # (try_for_range, ":slot", ek_item_0, ek_food), #can't only check equipment, it'll reload if you visit lord's hall
  26408. (troop_get_inventory_capacity, ":cap", ":troop_no"),
  26409. (try_for_range, ":slot", ek_item_0, ":cap"),
  26410. (gt, ":troop_wealth", ":equipment_limit"), #has spare cash
  26411. (troop_get_inventory_slot, ":item_no", ":troop_no", ":slot"),
  26412. (neq, ":item_no", -1),
  26413. (neg|item_has_property, ":item_no", itp_unique),
  26414. (neg|item_has_property, ":item_no", itp_civilian), #why bother upgrading underwear
  26415. (item_has_property, ":item_no", itp_merchandise), #can be sold, although player can drop loot off
  26416. (troop_get_inventory_slot_modifier, ":old_imod", ":troop_no", ":slot"),
  26417. # (item_get_slot, ":imod_mult", ":old_imod", slot_item_modifier_multiplier),
  26418. (call_script, "script_dplmc_get_item_value_with_imod", ":item_no", ":old_imod"),
  26419. (assign, ":imod_mult", reg0),
  26420. (try_begin),
  26421. (is_between, ":slot", ek_item_0, ek_head),
  26422. (assign, ":merchant", slot_town_weaponsmith),
  26423. (else_try),
  26424. (is_between, ":slot", ek_item_0, ek_head),
  26425. (assign, ":merchant", slot_town_armorer),
  26426. (else_try),
  26427. (eq, ":slot", ek_horse),
  26428. (assign, ":merchant", slot_town_horse_merchant),
  26429. (try_end),
  26430. (party_get_slot, ":merchant", ":center_no", ":merchant"),
  26431. #valid merchant
  26432. (is_between, ":merchant", armor_merchants_begin, mayors_begin),
  26433. (troop_get_inventory_capacity, ":cap", ":merchant"),
  26434. (try_for_range, ":i_slot", 10, ":cap"),
  26435. (troop_get_inventory_slot, ":item_id", ":merchant", ":i_slot"),
  26436. (eq, ":item_id", ":item_no"), #same item found
  26437. (troop_get_inventory_slot_modifier, ":imod", ":merchant", ":i_slot"),
  26438. (neq, ":imod", ":old_imod"), ## in general higher imod = upgrade
  26439.  
  26440. # (is_between, ":imod", imod_balanced, imod_large_bag + 1), #eliminate bad+plain ones
  26441. # (item_get_slot, ":imod_cost", ":imod", slot_item_modifier_multiplier),
  26442. (call_script, "script_dplmc_get_item_value_with_imod", ":item_id", ":imod"),
  26443. (assign, ":imod_cost", reg0),
  26444. (gt, ":imod_cost", ":imod_mult"), #superior price not necessarily better quality
  26445. #troop can use item
  26446. (call_script, "script_dplmc_troop_can_use_item", ":troop_no", ":item_id", ":imod"),
  26447. (eq, reg0, 1),
  26448. #we go for a pure value ratio - get_trade_penalty applies to player only
  26449. (store_item_value, ":val", ":item_no"),
  26450. (store_sub, ":cost", ":imod_cost", ":imod_mult"),
  26451. (val_mul, ":cost", ":val"),
  26452. (val_div, ":cost", 100),#base
  26453. (gt, ":troop_wealth", ":cost"),
  26454. (try_begin), #debug
  26455. (eq, "$cheat_mode", 2),
  26456. #(str_store_string, s11, "@{reg2}"),
  26457.  
  26458. # (str_store_party_name_link, s14, ":center_no"),
  26459. (str_store_item_name, s11, ":item_no"),
  26460. (str_store_troop_name_link, s10, ":troop_no"),
  26461. (str_store_party_name_link, s4, ":center_no"),
  26462. (store_add, ":string", ":old_imod", "str_imod_plain"),
  26463. (str_store_string, s3, ":string"),
  26464. (call_script, "script_game_get_money_text", ":cost"),
  26465. (assign, reg0, ":troop_wealth"),
  26466. (display_log_message, "@{s10} upgrades {s3}{s11} (costing {s1}) in {s4}, {reg0} denars remaining."),
  26467. (try_end),
  26468. (val_sub, ":troop_wealth", ":cost"),
  26469. (troop_set_inventory_slot_modifier, ":troop_no", ":slot", ":imod"),
  26470. (troop_set_inventory_slot_modifier, ":merchant", ":i_slot", ":old_imod"),
  26471. (troop_add_gold, ":merchant", ":cost"),
  26472. (assign, ":cap", 10), #one item has one upgrade at a time
  26473. (try_end),
  26474. (try_end),
  26475. ##upgrade end
  26476. (try_end),
  26477.  
  26478. # SB : set wealth after tax and consumption
  26479. (troop_set_slot, ":troop_no", slot_troop_wealth, ":troop_wealth"),
  26480. #DEBUG
  26481. (try_begin),
  26482. (neq, ":troop_wealth", ":initial_wealth"),
  26483. (assign, reg1, ":initial_wealth"),
  26484. (str_store_troop_name_link, s1, ":troop_no"),
  26485. (str_store_party_name_link, s2, ":center_no"),
  26486. (assign, reg2, ":troop_wealth"),
  26487. (display_message, "@{s1} spends time in {s2}, {reg1} -> {reg2} denars"),
  26488. (try_end),
  26489. #Courtship
  26490. (try_begin),
  26491. (party_get_slot, ":time_of_last_courtship", ":led_party", slot_party_leader_last_courted),
  26492. (store_sub, ":hours_since_last_courtship", ":current_time", ":time_of_last_courtship"),
  26493. (gt, ":hours_since_last_courtship", 72),
  26494.  
  26495. (troop_slot_eq, ":troop_no", slot_troop_spouse, -1),
  26496. ##diplomacy start+ Disable this for inappropriate types
  26497. (neg|is_between, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),#They use the last visited slots for other purposes
  26498. (neg|is_between, ":troop_no", kings_begin, kings_end),#They should not be participating in this system
  26499. (neg|is_between, ":troop_no", pretenders_begin, pretenders_end),#They should not be participating in this system
  26500. ##diplomacy end+
  26501. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  26502. (troop_get_slot, ":love_interest", ":troop_no", ":love_interest_slot"),
  26503. (gt, ":love_interest", 0),
  26504. (troop_get_slot, ":love_interest_town", ":love_interest", slot_troop_cur_center),
  26505. (eq, ":center_no", ":love_interest_town"),
  26506.  
  26507. (call_script, "script_courtship_event_troop_court_lady", ":troop_no", ":love_interest"),
  26508. (party_set_slot, ":led_party", slot_party_leader_last_courted, ":current_time"),
  26509. (try_end),
  26510. (try_end),
  26511.  
  26512. ]),
  26513.  
  26514. # script_process_kingdom_parties_ai
  26515. # This is called more frequently than decide_kingdom_parties_ai
  26516. # Input: none
  26517. # Output: none
  26518. #called from triggers
  26519. ("process_kingdom_parties_ai",
  26520. [
  26521. ##diplomacy start+ add support for promoted kingdom ladies
  26522. (try_for_range, ":troop_no", heroes_begin, heroes_end),#<- change active_npcs to heroes
  26523. ##diplomacy end+
  26524. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  26525. (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  26526. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  26527. (gt, ":party_no", 0),
  26528. (call_script, "script_process_hero_ai", ":troop_no"),
  26529. (try_end),
  26530. ]),
  26531.  
  26532. # script_process_hero_ai
  26533. # This is called more frequently than script_decide_kingdom_party_ais
  26534. #Handles sieges, raids, etc -- does not change the party's basic mission.
  26535. # Input: none
  26536. # Output: none
  26537. #called from triggers
  26538. ("process_hero_ai",
  26539. [
  26540. (store_script_param_1, ":troop_no"),
  26541. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  26542. (try_begin),
  26543. (party_is_active, ":party_no"),
  26544. (store_faction_of_party, ":faction_no", ":party_no"),
  26545. (party_get_slot, ":ai_state", ":party_no", slot_party_ai_state),
  26546. (party_get_slot, ":ai_object", ":party_no", slot_party_ai_object),
  26547. (try_begin),
  26548. (eq, ":ai_state", spai_besieging_center),
  26549. (try_begin),
  26550. (party_slot_eq, ":ai_object", slot_center_is_besieged_by, -1),
  26551. (store_distance_to_party_from_party, ":distance", ":party_no", ":ai_object"),
  26552. (lt, ":distance", 3),
  26553. (try_begin),
  26554. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  26555. (party_get_slot, ":commander_party", ":party_no", slot_party_ai_object),
  26556. (party_set_slot, ":ai_object", slot_center_is_besieged_by, ":commander_party"),
  26557. (else_try),
  26558. (party_set_slot, ":ai_object", slot_center_is_besieged_by, ":party_no"),
  26559. (try_end),
  26560. (store_current_hours, ":cur_hours"),
  26561. (party_set_slot, ":ai_object", slot_center_siege_begin_hours, ":cur_hours"),
  26562.  
  26563.  
  26564. (try_begin),
  26565. (store_faction_of_party, ":ai_object_faction", ":ai_object"),
  26566. ##diplomacy start+ Handle player is co-ruler of faction
  26567. (assign, ":is_coruler", 0),
  26568. (try_begin),
  26569. (eq, ":ai_object_faction", "$players_kingdom"),
  26570. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  26571. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  26572. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  26573. (assign, ":is_coruler", 1),
  26574. (try_end),
  26575. (this_or_next|eq, ":is_coruler", 1),
  26576. ##diplomacy end+
  26577. (this_or_next|party_slot_eq, ":ai_object", slot_town_lord, "trp_player"),
  26578. (eq, ":ai_object_faction", "fac_player_supporters_faction"),
  26579. (call_script, "script_add_notification_menu", "mnu_notification_center_under_siege", ":ai_object", ":troop_no"),
  26580. (try_end),
  26581. (str_store_party_name_link, s1, ":ai_object"),
  26582. (str_store_troop_name_link, s2, ":troop_no"),
  26583. (str_store_faction_name_link, s3, ":faction_no"),
  26584. #SB : store color of center object
  26585. (faction_get_color, ":color", ":ai_object_faction"),
  26586. (display_log_message, "@{s1} has been besieged by {s2} of {s3}.", ":color"),
  26587. (call_script, "script_village_set_state", ":ai_object", svs_under_siege),
  26588. (assign, "$g_recalculate_ais", 1),
  26589. (try_end),
  26590. (else_try),
  26591. (eq, ":ai_state", spai_raiding_around_center),
  26592. (party_slot_eq, ":party_no", slot_party_ai_substate, 0),
  26593. (assign, ":selected_village", 0),
  26594. (try_for_range, ":enemy_village_no", villages_begin, villages_end),
  26595. (eq, ":selected_village", 0),
  26596. (store_faction_of_party, ":enemy_village_faction", ":enemy_village_no"),
  26597. (try_begin),
  26598. (party_slot_eq, ":enemy_village_no", slot_town_lord, "trp_player"),
  26599. (store_relation, ":reln", "fac_player_supporters_faction", ":faction_no"),
  26600. (else_try),
  26601. (store_relation, ":reln", ":enemy_village_faction", ":faction_no"),
  26602. (try_end),
  26603. (lt, ":reln", 0),
  26604. (store_distance_to_party_from_party, ":dist", ":enemy_village_no", ":party_no"),
  26605. (lt, ":dist", 15),
  26606. (party_slot_eq, ":enemy_village_no", slot_village_state, svs_normal), #village is not already raided
  26607. #CHANGE STATE TO RAID THIS VILLAGE
  26608. (assign, ":selected_village", ":enemy_village_no"),
  26609. (try_end),
  26610. (try_begin),
  26611. (eq, ":selected_village", 0),
  26612. (is_between, ":ai_object", villages_begin, villages_end),
  26613. (assign, ":selected_village", ":ai_object"),
  26614. (try_end),
  26615. (try_begin),
  26616. (gt, ":selected_village", 0),
  26617. #SB : minimum of 15 in raiding party, although in process_village_raids we calculate actual ratio
  26618. (party_get_num_companions, ":num_troops", ":party_no"),
  26619. (ge, ":num_troops", 15), #about 2 party template of reinforcements
  26620. (call_script, "script_party_set_ai_state", ":party_no", spai_raiding_around_center, ":selected_village"),
  26621. (try_begin),
  26622. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  26623. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_raiding_village),
  26624. (faction_set_slot, ":faction_no", slot_faction_ai_object, ":selected_village"),
  26625. (try_end),
  26626. (party_get_position, pos1, ":selected_village"),
  26627. (map_get_random_position_around_position, pos2, pos1, 1),
  26628. (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_point),
  26629. (party_set_ai_target_position, ":party_no", pos2),
  26630. (party_set_ai_object, ":party_no", ":selected_village"),
  26631. (party_set_slot, ":party_no", slot_party_ai_substate, 1),
  26632. (try_end),
  26633. (else_try),
  26634. (eq, ":ai_state", spai_raiding_around_center),#substate is 1
  26635. (try_begin),
  26636. (store_distance_to_party_from_party, ":distance", ":party_no", ":ai_object"),
  26637. (lt, ":distance", 2),
  26638. (try_begin),
  26639. (party_slot_eq, ":ai_object", slot_village_state, svs_normal),
  26640. (call_script, "script_village_set_state", ":ai_object", svs_being_raided),
  26641. (party_set_slot, ":ai_object", slot_village_raided_by, ":party_no"),
  26642. (try_begin),
  26643. (store_faction_of_party, ":village_faction", ":ai_object"),
  26644. ##diplomacy start+ Handle player is co-ruler of faction
  26645. (assign, ":is_coruler", 0),
  26646. (try_begin),
  26647. (eq, ":village_faction", "$players_kingdom"),
  26648. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  26649. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  26650. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  26651. (assign, ":is_coruler", 1),
  26652. (try_end),
  26653. (this_or_next|eq, ":is_coruler", 1),
  26654. ##diplomacy end+
  26655. (this_or_next|party_slot_eq, ":ai_object", slot_town_lord, "trp_player"),
  26656. (eq, ":village_faction", "fac_player_supporters_faction"),
  26657. (store_distance_to_party_from_party, ":dist", "p_main_party", ":ai_object"),
  26658. (this_or_next|lt, ":dist", 30),
  26659. (party_slot_eq, ":ai_object", slot_center_has_messenger_post, 1),
  26660. (call_script, "script_add_notification_menu", "mnu_notification_village_raid_started", ":ai_object", ":troop_no"),
  26661. (try_end),
  26662. (else_try),
  26663. (party_slot_eq, ":ai_object", slot_village_state, svs_being_raided),
  26664. (else_try),
  26665. #if anything other than being_raided leave
  26666. (party_set_slot, ":party_no", slot_party_ai_substate, 0),
  26667. (try_end),
  26668. (try_end),
  26669. (else_try),
  26670. (eq, ":ai_state", spai_retreating_to_center),
  26671. (try_begin),
  26672. (party_get_battle_opponent, ":enemy_party", ":party_no"),
  26673. (ge, ":enemy_party", 0), #we are in a battle! we may be caught in a loop!
  26674. (call_script, "script_party_set_ai_state", ":party_no", spai_undefined, -1),
  26675. (party_set_flags, ":party_no", pf_default_behavior, 0),
  26676. (party_set_slot, ":party_no", slot_party_commander_party, -1),
  26677. (try_end),
  26678. (else_try),
  26679. (eq, ":ai_state", spai_patrolling_around_center),
  26680.  
  26681. (try_begin),
  26682. (party_slot_eq, ":party_no", slot_party_ai_substate, 0),
  26683. (store_distance_to_party_from_party, ":distance", ":party_no", ":ai_object"),
  26684. (lt, ":distance", 6),
  26685. (party_set_slot, ":party_no", slot_party_ai_substate, 1),
  26686.  
  26687. (party_set_aggressiveness, ":party_no", 8),
  26688. (party_set_courage, ":party_no", 8),
  26689. (party_set_ai_initiative, ":party_no", 100),
  26690.  
  26691. (party_set_ai_behavior, ":party_no", ai_bhvr_patrol_party),
  26692. (party_set_ai_object, ":party_no", ":ai_object"),
  26693. (try_end),
  26694. (else_try),
  26695. (eq, ":ai_state", spai_holding_center),
  26696. (try_end),
  26697. (try_end),
  26698. ]),
  26699.  
  26700. # script_begin_assault_on_center
  26701. # Input: arg1: faction_no
  26702. # Output: none
  26703. #called from triggers
  26704. ("begin_assault_on_center",
  26705. [
  26706. (store_script_param, ":center_no", 1),
  26707. ##diplomacy start+ add support for promoted kingdom ladies
  26708. (try_for_range, ":troop_no", heroes_begin, heroes_end),#<- change active_npcs to heroes
  26709. ##diplomacy end+
  26710. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  26711. (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  26712. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  26713. (gt, ":party_no", 0),
  26714. (party_is_active, ":party_no"),
  26715.  
  26716. (assign, ":continue", 0),
  26717. (try_begin),
  26718. (party_slot_eq, ":party_no", slot_party_ai_state, spai_besieging_center),
  26719. (party_slot_eq, ":party_no", slot_party_ai_object, ":center_no"),
  26720. (party_slot_eq, ":party_no", slot_party_ai_substate, 0),
  26721. (assign, ":continue", 1),
  26722. (else_try),
  26723. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  26724. (party_get_slot, ":commander_party", ":party_no", slot_party_ai_object),
  26725. (gt, ":commander_party", 0),
  26726. (party_is_active, ":commander_party"),
  26727. (party_slot_eq, ":commander_party", slot_party_ai_state, spai_besieging_center),
  26728. (party_slot_eq, ":commander_party", slot_party_ai_object, ":center_no"),
  26729. (call_script, "script_party_set_ai_state", ":party_no", spai_besieging_center, ":center_no"),
  26730. (assign, ":continue", 1),
  26731. (try_end),
  26732.  
  26733. (eq, ":continue", 1),
  26734.  
  26735. (party_set_ai_behavior, ":party_no", ai_bhvr_attack_party),
  26736. (party_set_ai_object, ":party_no", ":center_no"),
  26737. (party_set_flags, ":party_no", pf_default_behavior, 1),
  26738. (party_set_slot, ":party_no", slot_party_ai_substate, 1),
  26739. (try_end),
  26740. ]),
  26741.  
  26742. #DEPRECATED - Using new political issue system instead
  26743. ("select_faction_marshall",
  26744. [
  26745. # (store_script_param_1, ":faction_no"),
  26746. # (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  26747. # (faction_get_slot, ":old_faction_marshall", ":faction_no", slot_faction_marshall),
  26748.  
  26749. # (assign, ":old_marshal_is_avaliable", 0),
  26750. # (try_begin),
  26751. # (gt, ":old_faction_marshall", 0),
  26752. # (troop_get_slot, ":old_marshal_party", ":old_faction_marshall", slot_troop_leaded_party),
  26753. # (party_is_active, ":old_marshal_party"),
  26754. # (assign, ":old_marshal_is_avaliable", 1),
  26755. # (try_end),
  26756.  
  26757. #Ozan : I am adding some codes here because sometimes armies demobilize during last seconds of an
  26758. #important event like taking a castle, ext because of marshal change. When marshal changes during
  26759. #an important event occurs new marshal's followers become 0 and continueing siege attack seems less
  26760. #valuable then armies demobilize, faction ai become "do nothing", "I cannot think anything to do" ext.
  26761.  
  26762. # (assign, ":there_is_an_important_situation", 0),
  26763. # (faction_get_slot, ":current_ai_object", ":faction_no", slot_faction_ai_object),
  26764.  
  26765. # (try_begin), #do not demobilize during taking a castle/town (fighting in the castle)
  26766. # (is_between, ":current_ai_object", walled_centers_begin, walled_centers_end),
  26767. # (party_get_battle_opponent, ":besieger_party", ":current_ai_object"),
  26768. # (ge, ":besieger_party", 0),
  26769. # (party_is_active, ":besieger_party"),
  26770. # (store_faction_of_party, ":besieger_faction", ":besieger_party"),
  26771. # (this_or_next|eq, ":besieger_faction", ":faction_no"),
  26772. # (eq, ":besieger_faction", "fac_player_faction"),
  26773. # (assign, ":there_is_an_important_situation", 1),
  26774. # (try_end),
  26775.  
  26776. # (try_begin), #do not demobilize during raiding a village (holding around village)
  26777. # (is_between, ":current_ai_object", centers_begin, centers_end),
  26778. # (neg|is_between, ":current_ai_object", walled_centers_begin, walled_centers_end),
  26779. # (party_slot_eq, ":current_ai_object", slot_village_state, svs_being_raided),
  26780. # (assign, ":there_is_an_important_situation", 1),
  26781. # (try_end),
  26782.  
  26783. # (try_begin), #do not demobilize during besigning a siege (holding around castle)
  26784. # (is_between, ":current_ai_object", walled_centers_begin, walled_centers_end),
  26785. # #(str_store_party_name, s7, ":current_ai_object"),
  26786. # (party_get_slot, ":besieger_party", ":current_ai_object", slot_center_is_besieged_by),
  26787. # (ge, ":besieger_party", 0),
  26788. # (party_is_active, ":besieger_party"),
  26789. # #(str_store_party_name, s7, ":besieger_party"),
  26790. # (store_faction_of_party, ":besieger_faction", ":besieger_party"),
  26791. # (this_or_next|eq, ":besieger_faction", ":faction_no"),
  26792. # (eq, ":besieger_faction", "fac_player_faction"),
  26793. # (assign, ":there_is_an_important_situation", 1),
  26794. # (try_end),
  26795.  
  26796. # (try_begin),
  26797. # (this_or_next|eq, ":there_is_an_important_situation", 0),
  26798. # (eq, ":old_marshal_is_avaliable", 0),
  26799. #end addition ozan
  26800.  
  26801.  
  26802. # (assign, ":total_renown", 0),
  26803. # (try_for_range, ":loop_var", active_npcs_including_player_begin, active_npcs_end),
  26804. # (assign, ":cur_troop", ":loop_var"),
  26805. # (assign, ":continue", 0),
  26806. # (try_begin),
  26807. # (eq, ":loop_var", "trp_kingdom_heroes_including_player_begin"),
  26808. # (assign, ":cur_troop", "trp_player"),
  26809. # (try_begin),
  26810. # (eq, ":faction_no", "$players_kingdom"),
  26811. # (assign, ":continue", 1),
  26812. # (try_end),
  26813. # (else_try),
  26814. # (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  26815. # (store_troop_faction, ":cur_faction", ":cur_troop"),
  26816. # (eq, ":cur_faction", ":faction_no"),
  26817. # (troop_get_slot, ":cur_party", ":cur_troop", slot_troop_leaded_party),
  26818. # (gt, ":cur_party", 0),
  26819. # (party_is_active, ":cur_party"),
  26820. # (call_script, "script_party_count_fit_for_battle", ":cur_party"),
  26821. # (assign, ":party_fit_for_battle", reg0),
  26822. # (call_script, "script_party_get_ideal_size", ":cur_party"),
  26823. # (assign, ":ideal_size", reg0),
  26824. # (store_mul, ":relative_strength", ":party_fit_for_battle", 100),
  26825. # (val_div, ":relative_strength", ":ideal_size"),
  26826. # (ge, ":relative_strength", 25),
  26827. # (assign, ":continue", 1),
  26828. # (try_end),
  26829.  
  26830. # (eq, ":continue", 1),
  26831.  
  26832. # (troop_get_slot, ":renown", ":cur_troop", slot_troop_renown),
  26833. # (call_script, "script_troop_get_relation_with_troop", ":cur_troop", ":faction_leader"),
  26834. # (store_mul, ":relation_modifier", reg0, 15),
  26835. # (val_add, ":renown", ":relation_modifier"),
  26836. # (val_max, ":renown", 1),
  26837. #
  26838. # (try_begin),
  26839. # (eq, ":cur_troop", "trp_player"),
  26840. # (neq, ":old_faction_marshall", "trp_player"),
  26841. # (assign, ":renown", 0),
  26842. # (try_end),
  26843. # (try_begin),
  26844. # (eq, ":cur_troop", ":faction_leader"),
  26845. # (val_mul, ":renown", 3),
  26846. # (val_div, ":renown", 4),
  26847. # (try_end),
  26848. # (try_begin),
  26849. # (eq, ":cur_troop", ":old_faction_marshall"),
  26850. # (val_mul, ":renown", 1000),
  26851. # (try_end),
  26852. # (val_add, ":total_renown", ":renown"),
  26853. # (try_end),
  26854. # (assign, ":result", -1),
  26855. # (try_begin),
  26856. # (gt, ":total_renown", 0),
  26857. # (store_random_in_range, ":random_renown", 0, ":total_renown"),
  26858. # (try_for_range, ":loop_var", active_npcs_including_player_begin, active_npcs_end),
  26859. # (eq, ":result", -1),
  26860. # (assign, ":cur_troop", ":loop_var"),
  26861. # (assign, ":continue", 0),
  26862. # (try_begin),
  26863. # (eq, ":loop_var", "trp_kingdom_heroes_including_player_begin"),
  26864. # (assign, ":cur_troop", "trp_player"),
  26865. # (try_begin),
  26866. # (eq, ":faction_no", "$players_kingdom"),
  26867. # (assign, ":continue", 1),
  26868. # (try_end),
  26869. # (else_try),
  26870. # (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  26871. # (store_troop_faction, ":cur_faction", ":cur_troop"),
  26872. # (eq, ":cur_faction", ":faction_no"),
  26873. # (troop_get_slot, ":cur_party", ":cur_troop", slot_troop_leaded_party),
  26874. # (gt, ":cur_party", 0),
  26875. # (party_is_active, ":cur_party"),
  26876. # (call_script, "script_party_count_fit_for_battle", ":cur_party"),
  26877. # (assign, ":party_fit_for_battle", reg0),
  26878. # (call_script, "script_party_get_ideal_size", ":cur_party"),
  26879. # (assign, ":ideal_size", reg0),
  26880. # (store_mul, ":relative_strength", ":party_fit_for_battle", 100),
  26881. # (val_div, ":relative_strength", ":ideal_size"),
  26882. # (ge, ":relative_strength", 25),
  26883. # (assign, ":continue", 1),
  26884. # (try_end),
  26885. # (eq, ":continue", 1),
  26886.  
  26887. # (troop_get_slot, ":renown", ":cur_troop", slot_troop_renown),
  26888. # (call_script, "script_troop_get_relation_with_troop", ":cur_troop", ":faction_leader"),
  26889. # (store_mul, ":relation_modifier", reg0, 15),
  26890. # (val_add, ":renown", ":relation_modifier"),
  26891. # (val_max, ":renown", 1),
  26892. #
  26893. # (try_begin),
  26894. # (eq, ":cur_troop", "trp_player"),
  26895. # (neq, ":old_faction_marshall", "trp_player"),
  26896. # (assign, ":renown", 0),
  26897. # (try_end),
  26898. # (try_begin),
  26899. # (eq, ":cur_troop", ":faction_leader"),
  26900. # (val_mul, ":renown", 3),
  26901. # (val_div, ":renown", 4),
  26902. # (try_end),
  26903. # (try_begin),
  26904. # (eq, ":cur_troop", ":old_faction_marshall"),
  26905. # (val_mul, ":renown", 1000),
  26906. # (try_end),
  26907. # (val_sub, ":random_renown", ":renown"),
  26908. # (lt, ":random_renown", 0),
  26909. # (assign, ":result", ":cur_troop"),
  26910. # (try_end),
  26911. # (try_end),
  26912. # (try_begin),
  26913. #(eq, "$cheat_mode", 1),
  26914. # (ge, ":result", 0),
  26915. # (str_store_troop_name, s1, ":result"),
  26916. # (str_store_faction_name, s2, ":faction_no"),
  26917. # (display_message, "@{!}{s1} is chosen as the marshall of {s2}."),
  26918. # (try_end),
  26919. # (else_try),
  26920. # (faction_get_slot, ":old_faction_marshall", ":faction_no", slot_faction_marshall),
  26921. # (assign, ":result", ":old_faction_marshall"),
  26922. # (try_end),
  26923.  
  26924. # (assign, reg0, ":result"),
  26925. ]),
  26926.  
  26927.  
  26928.  
  26929.  
  26930. # script_get_center_faction_relation_including_player
  26931. # Input: arg1: center_no, arg2: target_faction_no
  26932. # Output: reg0: relation
  26933. #called from triggers
  26934. ("get_center_faction_relation_including_player",
  26935. [
  26936. (store_script_param, ":center_no", 1),
  26937. (store_script_param, ":target_faction_no", 2),
  26938. (store_faction_of_party, ":center_faction", ":center_no"),
  26939. (store_relation, ":relation", ":center_faction", ":target_faction_no"),
  26940. (try_begin),
  26941. (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  26942. (store_relation, ":relation", "fac_player_supporters_faction", ":target_faction_no"),
  26943. (try_end),
  26944. (assign, reg0, ":relation"),
  26945. ]),
  26946.  
  26947. #script_update_report_to_army_quest_note
  26948. ("update_report_to_army_quest_note",
  26949. [
  26950. (store_script_param, ":faction_no", 1),
  26951. (store_script_param, ":new_strategy", 2),
  26952. (store_script_param, ":old_faction_ai_state", 3),
  26953.  
  26954. (try_begin),
  26955. (le, "$number_of_report_to_army_quest_notes", 13),
  26956.  
  26957. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  26958.  
  26959. (try_begin), #updating quest notes for only report to army quest
  26960. (eq, ":faction_no", "$players_kingdom"),
  26961. (neq, ":new_strategy", ":old_faction_ai_state"),
  26962. (check_quest_active, "qst_report_to_army"),
  26963. (ge, ":faction_marshal", 0),
  26964.  
  26965. (str_store_troop_name_link, s11, ":faction_marshal"),
  26966. (store_current_hours, ":hours"),
  26967. (call_script, "script_game_get_date_text", 0, ":hours"),
  26968.  
  26969. (try_begin),
  26970. (this_or_next|eq, ":new_strategy", sfai_attacking_enemies_around_center),
  26971. (this_or_next|eq, ":new_strategy", sfai_attacking_center),
  26972. (eq, ":new_strategy", sfai_gathering_army),
  26973. (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
  26974. (ge, ":faction_object", 0),
  26975. (str_store_party_name_link, s21, ":faction_object"),
  26976. (try_end),
  26977.  
  26978. (try_begin),
  26979. (eq, ":new_strategy", sfai_gathering_army),
  26980.  
  26981. (try_begin),
  26982. (ge, "$g_gathering_reason", 0),
  26983. (str_store_party_name_link, s21, "$g_gathering_reason"),
  26984. (str_store_string, s14, "str_we_should_prepare_to_defend_s21_but_we_should_gather_our_forces_until_we_are_strong_enough_to_engage_them"),
  26985. (else_try),
  26986. (str_store_string, s14, "str_it_is_time_to_go_on_the_offensive_and_we_must_first_assemble_the_army"),
  26987. (try_end),
  26988.  
  26989. (str_store_string, s14, "@({s1}) {s11}: {s14}"),
  26990. (add_quest_note_from_sreg, "qst_report_to_army", "$number_of_report_to_army_quest_notes", s14, 0),
  26991. (val_add, "$number_of_report_to_army_quest_notes", 1),
  26992. (else_try),
  26993. (eq, ":new_strategy", sfai_attacking_enemies_around_center),
  26994.  
  26995. (try_begin),
  26996. (is_between, ":faction_object", walled_centers_begin, walled_centers_end),
  26997. (str_store_string, s14, "str_we_should_ride_to_break_the_siege_of_s21"),
  26998. (str_store_string, s14, "@({s1}) {s11}: {s14}"),
  26999. (add_quest_note_from_sreg, "qst_report_to_army", "$number_of_report_to_army_quest_notes", s14, 0),
  27000. (val_add, "$number_of_report_to_army_quest_notes", 1),
  27001. (else_try),
  27002. (is_between, ":faction_object", villages_begin, villages_end),
  27003. (str_store_string, s14, "str_we_should_ride_to_defeat_the_enemy_gathered_near_s21"),
  27004. (str_store_string, s14, "@({s1}) {s11}: {s14}"),
  27005. (add_quest_note_from_sreg, "qst_report_to_army", "$number_of_report_to_army_quest_notes", s14, 0),
  27006. (val_add, "$number_of_report_to_army_quest_notes", 1),
  27007. (try_end),
  27008. (else_try),
  27009. (this_or_next|eq, ":new_strategy", sfai_attacking_center),
  27010. (eq, ":new_strategy", sfai_raiding_village),
  27011.  
  27012. (try_begin),
  27013. (is_between, ":faction_object", walled_centers_begin, walled_centers_end),
  27014. (str_store_string, s14, "str_we_believe_the_fortress_will_be_worth_the_effort_to_take_it"),
  27015. (str_store_string, s14, "@{s14} ({s21})"),
  27016. (str_store_string, s14, "@({s1}) {s11}: {s14}"),
  27017. (add_quest_note_from_sreg, "qst_report_to_army", "$number_of_report_to_army_quest_notes", s14, 0),
  27018. (val_add, "$number_of_report_to_army_quest_notes", 1),
  27019. (else_try),
  27020. (is_between, ":faction_object", villages_begin, villages_end),
  27021. (str_store_string, s14, "str_we_shall_leave_a_fiery_trail_through_the_heart_of_the_enemys_lands_targeting_the_wealthy_settlements_if_we_can"),
  27022. (str_store_string, s14, "@{s14} ({s21})"),
  27023. (str_store_string, s14, "@({s1}) {s11}: {s14}"),
  27024. (add_quest_note_from_sreg, "qst_report_to_army", "$number_of_report_to_army_quest_notes", s14, 0),
  27025. (val_add, "$number_of_report_to_army_quest_notes", 1),
  27026. (try_end),
  27027. (try_end),
  27028. (try_end),
  27029. (try_end),
  27030. ]),
  27031.  
  27032.  
  27033. # script_decide_faction_ai
  27034. # Input: arg1: faction_no
  27035. # Output: none
  27036. #called from triggers
  27037. ("decide_faction_ai",
  27038. #This handles political issues and faction issues
  27039. [
  27040. (store_script_param_1, ":faction_no"),
  27041.  
  27042.  
  27043. (faction_get_slot, ":old_faction_ai_state", ":faction_no", slot_faction_ai_state),
  27044. (faction_get_slot, ":old_faction_ai_object", ":faction_no", slot_faction_ai_object),
  27045. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  27046.  
  27047.  
  27048. #Remove marshal if he has become too controversial,, or he has defected, or has been taken prisoner
  27049. (try_begin),
  27050. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  27051. (neq, ":faction_no", "fac_player_supporters_faction"),
  27052. (ge, ":faction_marshal", "trp_player"),
  27053.  
  27054. (store_faction_of_troop, ":marshal_faction", ":faction_marshal"),
  27055. (try_begin),
  27056. (eq, ":faction_marshal", "trp_player"),
  27057. (assign, ":marshal_faction", "$players_kingdom"),
  27058. (try_end),
  27059.  
  27060.  
  27061. (assign, ":player_marshal_is_prisoner", 0),
  27062. (try_begin),
  27063. (eq, ":faction_marshal", "trp_player"),
  27064. (eq, "$g_player_is_captive", 1),
  27065. (assign, ":player_marshal_is_prisoner", 1),
  27066. (try_end),
  27067.  
  27068.  
  27069. #High controversy level, or marshal has defected, or is prisoner
  27070. (this_or_next|neq, ":marshal_faction", ":faction_no"),
  27071. (this_or_next|troop_slot_ge, ":faction_marshal", slot_troop_controversy, 80),
  27072. (this_or_next|eq, ":player_marshal_is_prisoner", 1),
  27073. (troop_slot_ge, ":faction_marshal", slot_troop_prisoner_of_party, 0),
  27074.  
  27075. (assign, ":few_following_player_campaign", 0),
  27076. (try_begin),
  27077. (eq, ":faction_marshal", "trp_player"),
  27078. (assign, ":vassals_following_player_campaign", 0),
  27079. (gt, "$g_player_days_as_marshal", 1),
  27080. (try_for_range, ":vassal", active_npcs_begin, active_npcs_end),
  27081. (troop_slot_eq, ":vassal", slot_troop_occupation, slto_kingdom_hero),
  27082. (store_faction_of_troop, ":vassal_faction", ":vassal"),
  27083. (eq, ":vassal_faction", ":faction_no"),
  27084. (call_script, "script_npc_decision_checklist_troop_follow_or_not", ":vassal"),
  27085. (eq, reg0, 1),
  27086. (val_add, ":vassals_following_player_campaign", 1),
  27087. (try_end),
  27088. (lt, ":vassals_following_player_campaign", 4),
  27089. (assign, ":few_following_player_campaign", 1),
  27090. (try_end),
  27091.  
  27092. #Only remove marshal for controversy if offensive campaign in progress
  27093. (this_or_next|eq, ":old_faction_ai_state", sfai_default),
  27094. (this_or_next|eq, ":old_faction_ai_state", sfai_feast),
  27095. (this_or_next|neq, ":marshal_faction", ":faction_no"),
  27096. (this_or_next|eq, ":few_following_player_campaign", 1),
  27097. (this_or_next|eq, ":player_marshal_is_prisoner", 1),
  27098. (troop_slot_ge, ":faction_marshal", slot_troop_prisoner_of_party, 0),
  27099.  
  27100. #No current issue on the agenda
  27101. (this_or_next|faction_slot_eq, ":faction_no", slot_faction_political_issue, 0),
  27102. (this_or_next|eq, ":player_marshal_is_prisoner", 1),
  27103. (troop_slot_ge, ":faction_marshal", slot_troop_prisoner_of_party, 0),
  27104.  
  27105. (faction_set_slot, ":faction_no", slot_faction_political_issue, 1), #Appointment of marshal
  27106. (store_current_hours, ":hours"),
  27107. (val_max, ":hours", 0),
  27108. (faction_set_slot, ":faction_no", slot_faction_political_issue_time, ":hours"), #Appointment of marshal
  27109.  
  27110. (faction_get_slot, ":old_marshall", ":faction_no", slot_faction_marshall),
  27111. (try_begin),
  27112. (ge, ":old_marshall", 0),
  27113. (troop_get_slot, ":old_marshall_party", ":old_marshall", slot_troop_leaded_party),
  27114. (party_is_active, ":old_marshall_party"),
  27115. (party_set_marshal, ":old_marshall_party", 0),
  27116. (try_end),
  27117.  
  27118. (try_begin),
  27119. (eq, "$players_kingdom", ":faction_no"),
  27120. (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
  27121. (call_script, "script_add_notification_menu", "mnu_notification_relieved_as_marshal", 0, 0),
  27122. (else_try),
  27123. (neq, ":old_marshall", "trp_player"),
  27124. (call_script, "script_change_troop_renown", ":old_marshall", 15),
  27125. (try_end),
  27126. (faction_set_slot, ":faction_no", slot_faction_marshall, -1),
  27127. (assign, ":faction_marshal", -1),
  27128.  
  27129.  
  27130. ##diplomacy start+ add support for promoted kingdom ladies
  27131. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27132. ##diplomacy end+
  27133. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  27134. (eq, ":active_npc_faction", ":faction_no"),
  27135. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  27136. (try_end),
  27137. (try_begin),
  27138. (eq, "$players_kingdom", ":faction_no"),
  27139. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  27140. (try_end),
  27141.  
  27142. (else_try), #If marshal not present, and not already on agenda, make political issue
  27143. (eq, ":faction_marshal", -1),
  27144. (neg|faction_slot_ge, ":faction_no", slot_faction_political_issue, 1), #This to avoid resetting votes every time
  27145.  
  27146. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  27147. (neq, ":faction_no", "fac_player_supporters_faction"),
  27148.  
  27149. (faction_set_slot, ":faction_no", slot_faction_political_issue, 1), #Appointment of marshal
  27150. (store_current_hours, ":hours"),
  27151. (val_max, ":hours", 0),
  27152. (faction_set_slot, ":faction_no", slot_faction_political_issue_time, ":hours"), #Appointment of marshal
  27153.  
  27154. ##diplomacy start+ add support for promoted kingdom ladies
  27155. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27156. ##diplomacy end+
  27157. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  27158. (eq, ":active_npc_faction", ":faction_no"),
  27159. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  27160. (try_end),
  27161. (try_begin),
  27162. (eq, "$players_kingdom", ":faction_no"),
  27163. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  27164. (try_end),
  27165.  
  27166.  
  27167. (else_try), #If player is marshal, but not part of faction
  27168. (eq, ":faction_marshal", "trp_player"),
  27169. (neq, "$players_kingdom", ":faction_no"),
  27170.  
  27171. (faction_set_slot, ":faction_no", slot_faction_political_issue, 1), #Appointment of marshal
  27172. (store_current_hours, ":hours"),
  27173. (val_max, ":hours", 0),
  27174. (faction_set_slot, ":faction_no", slot_faction_political_issue_time, ":hours"), #Appointment of marshal
  27175.  
  27176. (faction_get_slot, ":old_marshall", ":faction_no", slot_faction_marshall),
  27177. (try_begin),
  27178. (ge, ":old_marshall", 0),
  27179. (troop_get_slot, ":old_marshall_party", ":old_marshall", slot_troop_leaded_party),
  27180. (party_is_active, ":old_marshall_party"),
  27181. (party_set_marshal, ":old_marshall_party", 0),
  27182. (try_end),
  27183.  
  27184. (faction_set_slot, ":faction_no", slot_faction_marshall, -1),
  27185. (assign, ":faction_marshal", -1),
  27186.  
  27187. ##diplomacy start+ add support for promoted kingdom ladies
  27188. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27189. ##diplomacy end+
  27190. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  27191. (eq, ":active_npc_faction", ":faction_no"),
  27192. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  27193. (try_end),
  27194. (try_begin),
  27195. (eq, "$players_kingdom", ":faction_no"),
  27196. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  27197. (try_end),
  27198.  
  27199. (try_end),
  27200.  
  27201. #If the faction issue is a center no longer under faction control, remove and reset
  27202. (try_begin),
  27203. (faction_get_slot, ":faction_political_issue", ":faction_no", slot_faction_political_issue),
  27204. (is_between, ":faction_political_issue", centers_begin, centers_end),
  27205. (store_faction_of_party, ":disputed_center_faction", ":faction_political_issue"),
  27206. (neq, ":disputed_center_faction", ":faction_no"),
  27207.  
  27208. (try_begin),
  27209. (eq, "$cheat_mode", 1),
  27210. (str_store_faction_name, s4, ":faction_no"),
  27211. (str_store_party_name, s5, ":disputed_center_faction"),
  27212. (display_message, "@{!}DEBUG -- {s4} drops {s5} as issue as it has changed hands"),
  27213. (try_end),
  27214.  
  27215. #Reset political issue
  27216. (faction_set_slot, ":faction_no", slot_faction_political_issue, 0),
  27217. ##diplomacy start+ add support for promoted kingdom ladies
  27218. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27219. ##diplomacy end+
  27220. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  27221. (eq, ":active_npc_faction", ":faction_no"),
  27222. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  27223. (try_end),
  27224. (try_begin),
  27225. (eq, "$players_kingdom", ":faction_no"),
  27226. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  27227. (try_end),
  27228.  
  27229. (try_end),
  27230.  
  27231.  
  27232. #Resolve the political issue on the agenda
  27233. (try_begin),
  27234. (faction_slot_ge, ":faction_no", slot_faction_political_issue, 1),
  27235. (neq, ":faction_no", "fac_player_supporters_faction"),
  27236.  
  27237. #Do not switch marshals during a campaign
  27238. (this_or_next|faction_slot_ge, ":faction_no", slot_faction_political_issue, centers_begin),
  27239. (this_or_next|faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_default),
  27240. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_feast),
  27241.  
  27242.  
  27243. (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  27244.  
  27245. (assign, ":total_lords", 0),
  27246. (assign, ":lords_who_have_voted", 0),
  27247. (assign, ":popular_favorite", -1),
  27248.  
  27249. #Reset number of votes
  27250. (troop_set_slot, "trp_player", slot_troop_temp_slot, 0),
  27251. ##diplomacy start+ add support for promoted kingdom ladies
  27252. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27253. ##diplomacy end+
  27254. (troop_set_slot, ":active_npc", slot_troop_temp_slot, 0),
  27255. (try_end),
  27256.  
  27257. #Tabulate votes
  27258.  
  27259. ##diplomacy start+
  27260. (try_begin),#count the player's vote
  27261. (eq, "$players_kingdom", ":faction_no"),
  27262. (ge, "$player_has_homage", 1),
  27263. (troop_get_slot, ":lord_chosen_candidate", "trp_player", slot_troop_stance_on_faction_issue),
  27264. (gt, ":lord_chosen_candidate", -1),
  27265. #You may notice that I don't count the player for "total_lords" if he was undecided.
  27266. #This is so faction behavior will not be changed from Native if the player did not
  27267. #support anyone.
  27268. (val_add, ":total_lords", 1),
  27269. (val_add, ":lords_who_have_voted", 1),
  27270. (troop_set_slot, ":lord_chosen_candidate", slot_troop_temp_slot, 1),
  27271. (assign, ":popular_favorite", ":lord_chosen_candidate"),
  27272. (try_end),
  27273. #add support for promoted kingdom ladies
  27274. (try_for_range, ":voting_lord", heroes_begin, heroes_end),#<- changed active_npcs_begin/end to heroes_begin/end
  27275. (this_or_next|troop_slot_eq, ":voting_lord", slot_troop_occupation, slto_kingdom_hero),
  27276. (is_between, ":voting_lord", active_npcs_begin, active_npcs_end),
  27277. #the dead / retired / exiled do not vote
  27278. (neg|troop_slot_ge, ":voting_lord", slot_troop_occupation, slto_retirement),
  27279. ##diplomacy end+
  27280. (store_faction_of_troop, ":voting_lord_faction", ":voting_lord"),
  27281. (eq, ":voting_lord_faction", ":faction_no"),
  27282. (val_add, ":total_lords", 1),
  27283. (troop_get_slot, ":lord_chosen_candidate", ":voting_lord", slot_troop_stance_on_faction_issue),
  27284. (gt, ":lord_chosen_candidate", -1),
  27285. (val_add, ":lords_who_have_voted", 1),
  27286. (troop_get_slot, ":total_votes", ":lord_chosen_candidate", slot_troop_temp_slot),
  27287. (val_add, ":total_votes", 1),
  27288. (troop_set_slot, ":lord_chosen_candidate", slot_troop_temp_slot, ":total_votes"),
  27289. (try_begin),
  27290. (gt, ":popular_favorite", -1),
  27291. (troop_get_slot, ":current_winner_votes", ":popular_favorite", slot_troop_temp_slot),
  27292. (gt, ":total_votes", ":current_winner_votes"),
  27293. (assign, ":popular_favorite", ":lord_chosen_candidate"),
  27294. (else_try),
  27295. (eq, ":popular_favorite", -1),
  27296. (assign, ":popular_favorite", ":lord_chosen_candidate"),
  27297. (try_end),
  27298. (try_end),
  27299.  
  27300. #Check to see if enough lords have voted
  27301. (store_div, ":number_required_for_quorum", ":total_lords", 5),
  27302. (val_mul, ":number_required_for_quorum", 4),
  27303. ##diplomacy start+
  27304. #Replace number required for quorum, altering it based on the centralization
  27305. #value. Do the same for the minimum time left on the agenda.
  27306. (faction_get_slot, ":centralization", ":faction_no", dplmc_slot_faction_centralization),
  27307. (val_clamp, ":centralization", -3, 4),
  27308. (try_begin),
  27309. #Disable this for now, since NPC kingdoms set their policies randomly.
  27310. (eq, 0, 1),
  27311. (neq, ":centralization", 0),
  27312. (store_sub, ":number_required_for_quorum", 15, ":centralization"),#fully centralized = 12/20 , fully decentralized = 18/20
  27313. (try_begin),
  27314. #If the plutocracy/aristocracy slider is negative, allow it to offset
  27315. #a negative centralization value for the purpose of quorum, on the
  27316. #assumption that part of the "quorum" is accounted for by the influence
  27317. #of merchants. They do not vote currently, although integrating guild masters
  27318. #and/or village elders into the faction issue system is something to consider
  27319. #for the future.
  27320. (ge, ":number_required_for_quorum", 16),
  27321. (faction_get_slot, ":aristocracy", ":faction_no", dplmc_slot_faction_aristocracy),
  27322. (lt, ":aristocracy", 0),
  27323. (val_clamp, ":aristocracy", -3, 4),
  27324. (val_add, ":number_required_for_quorum", ":aristocracy"),
  27325. (val_max, ":number_required_for_quorum", 15),
  27326. (try_end),
  27327. (val_mul, ":number_required_for_quorum", ":total_lords"),
  27328. (val_div, ":number_required_for_quorum", 20),
  27329. (try_end),
  27330. ##diplomacy end+
  27331.  
  27332. # (gt, ":lords_who_have_voted", ":number_required_for_quorum"),
  27333.  
  27334. (store_current_hours, ":hours_on_agenda"),
  27335. (faction_get_slot, ":hours_when_put_on_agenda", ":faction_no", slot_faction_political_issue_time), #Appointment of marshal
  27336. (val_sub, ":hours_on_agenda", ":hours_when_put_on_agenda"),
  27337.  
  27338. ##diplomacy start+
  27339. #Before, the maximum number of hours on the agenda for an issue before it became
  27340. #eligible for resolution regardless of quorum was fixed at 120 (five days).
  27341. #Modify this by 16 hours for every point of centralization, for a minimum
  27342. #of 3 days and a maximum of 7 days.
  27343. (assign, ":hours_on_agenda_threshold", 120),
  27344. (try_begin),
  27345. #Disable this for now, since arguably all of the NPC kingdoms are
  27346. #supposed to have fairly similar structures. From a gameplay perspective,
  27347. #they choose their kingdom policy at random, so enabling this is probably
  27348. #not going to have good effects, unless more thought is given to balancing
  27349. #centralization/decentralization for NPC kingdoms.
  27350. (eq, 0, 1),
  27351. (store_mul, ":hours_on_agenda_threshold", ":centralization", 16),
  27352. (val_add, ":hours_on_agenda_threshold", 120),
  27353. (try_begin),
  27354. (neq, ":centralization", 0),
  27355. (try_end),
  27356. (try_end),
  27357.  
  27358. #(this_or_next|gt, ":lords_who_have_voted", ":number_required_for_quorum"),
  27359. # (ge, ":hours_on_agenda", 120),
  27360.  
  27361. (this_or_next|gt, ":lords_who_have_voted", ":number_required_for_quorum"),
  27362. (ge, ":hours_on_agenda", ":hours_on_agenda_threshold"),
  27363. ##diplomacy end+
  27364.  
  27365. (try_begin),
  27366. (eq, "$cheat_mode", 1),
  27367. (assign, reg4, ":lords_who_have_voted"),
  27368. (assign, reg5, ":number_required_for_quorum"),
  27369. (assign, reg7, ":hours_on_agenda"),
  27370. (str_store_faction_name, s4, ":faction_no"),
  27371. (display_message, "@{!}DEBUG -- Issue resolution for {s4}: {reg4} votes for a quorum of {reg5}, {reg7} hours on agenda"),
  27372. (try_end),
  27373.  
  27374.  
  27375. (try_begin),
  27376. (eq, "$cheat_mode", 1),
  27377. (display_message, "@{!}DEBUG -- Faction resolves political issue"),
  27378. (try_end),
  27379.  
  27380.  
  27381. #Resolve faction political issue
  27382. (assign, ":winning_candidate", -1),
  27383.  
  27384. ##diplomacy start+
  27385. #Change "liege overrules lords" check. The version in Native caused relation death spirals:
  27386. #a lord who has no fiefs becomes unhappy, and since relation is symmetrical, this can result
  27387. #in the liege never granting him fiefs.
  27388. #
  27389. #OLD BEHAVIOR:
  27390. # (else_try)
  27391. # (call_script, "script_troop_get_relation_with_troop", ":faction_leader", ":popular_favorite"),
  27392. # (this_or_next|ge, reg0, 10),
  27393. # (this_or_next|troop_slot_eq, ":faction_leader", slot_troop_stance_on_faction_issue, ":popular_favorite"),
  27394. # (troop_slot_eq, ":faction_leader", slot_troop_stance_on_faction_issue, -1),
  27395. #
  27396. # (assign, ":winning_candidate", ":popular_favorite"),
  27397. # (else_try),#Lord overrules lords' opinion
  27398. # (gt, ":faction_leader", -1), #not sure why this is necessary
  27399. # (troop_get_slot, ":liege_choice", ":faction_leader", slot_troop_stance_on_faction_issue),
  27400. # (ge, ":liege_choice", -1),
  27401. #
  27402. # (assign, ":winning_candidate", ":liege_choice"),
  27403. # (try_end),
  27404. #
  27405. # NEW BEHAVIOR
  27406. (troop_get_slot, ":liege_choice", ":faction_leader", slot_troop_stance_on_faction_issue),
  27407. (assign, ":min_liege_relation", 10),#<-- Same as in default
  27408. (faction_get_slot, ":issue_on_table", ":faction_no", slot_faction_political_issue),
  27409. (try_begin),
  27410. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  27411. #Alter the minimum for villages and castles, but not towns or the marshall.
  27412. (this_or_next|is_between, ":issue_on_table", villages_begin, villages_end),
  27413. (is_between, ":issue_on_table", castles_begin, castles_end),
  27414. (store_random_in_range, ":min_liege_relation", 0, 16),
  27415. (val_sub, ":min_liege_relation", 5),#-5 to 10
  27416. (try_end),
  27417. #New override check
  27418. (try_begin),
  27419. #When the player is co-ruler of the kingdom, his/her support for the popular
  27420. #candidate can be sufficient to guarantee success over the opposition of the
  27421. #king/queen.
  27422. (ge, ":faction_leader", 1),
  27423. (eq, "$players_kingdom", ":faction_no"),
  27424. (this_or_next|troop_slot_eq, ":faction_leader", slot_troop_spouse, "trp_player"),
  27425. (troop_slot_eq, "trp_player", slot_troop_spouse, ":faction_leader"),
  27426. (troop_slot_eq, "trp_player", slot_troop_stance_on_faction_issue, ":popular_favorite"),
  27427. (assign, ":winning_candidate", ":popular_favorite"),
  27428. (else_try),
  27429. #The leader may overrule a choice he disagrees with, if he dislikes the candidate
  27430. #sufficiently and has someone else in mind.
  27431. (ge, ":faction_leader", 1),
  27432. (neq, ":liege_choice", ":popular_favorite"),
  27433. (gt, ":liege_choice", -1),
  27434. (call_script, "script_troop_get_relation_with_troop", ":faction_leader", ":liege_choice"),
  27435. (val_min, ":min_liege_relation", reg0),
  27436. (call_script, "script_troop_get_relation_with_troop", ":faction_leader", ":popular_favorite"),
  27437. (gt, ":min_liege_relation", reg0),
  27438. (assign, reg0, 0),
  27439. (try_begin),
  27440. (troop_slot_ge, ":faction_leader", slot_troop_prisoner_of_party, 0),
  27441. (store_random_in_range, reg0, 0, 2),
  27442. (try_end),
  27443. (try_begin),
  27444. #The leader would have overruled the choice, but cannot because he is a prisoner.
  27445. #Print a message letting people know when this happens.
  27446. (eq, reg0, 1),
  27447. (gt, ":popular_favorite", -1),
  27448. (this_or_next|eq, "$players_kingdom", ":faction_no"),
  27449. (ge, "$cheat_mode", 1),
  27450. (str_store_faction_name, s4, ":faction_no"),
  27451. (str_store_troop_name, s5, ":popular_favorite"),
  27452. (str_store_troop_name, s0, ":faction_leader"),
  27453. (try_begin),
  27454. (eq, ":issue_on_table", 1),
  27455. (display_message, "@{s5} has the greatest support among the lords of the {s4} to be the next marshall. {s0} is indisposed and cannot overrule their choice."),
  27456. (else_try),
  27457. (is_between, ":issue_on_table", centers_begin, centers_end),
  27458. (str_store_party_name, s1, ":issue_on_table"),
  27459. (display_message, "@{s5} has the greatest support among the lords of the {s4} to receive {s1}. {s0} is indisposed and cannot overrule their choice."),
  27460. (try_end),
  27461. (try_end),
  27462. (eq, reg0, 0),
  27463. (assign, ":winning_candidate", ":liege_choice"),
  27464. (try_begin),
  27465. #Print a message letting people know when this happens.
  27466. (gt, ":popular_favorite", -1),
  27467. (this_or_next|eq, "$players_kingdom", ":faction_no"),
  27468. (ge, "$cheat_mode", 1),
  27469. (str_store_faction_name, s4, ":faction_no"),
  27470. (str_store_troop_name, s5, ":popular_favorite"),
  27471. (str_store_troop_name, s0, ":faction_leader"),
  27472. (try_begin),
  27473. (eq, ":issue_on_table", 1),
  27474. (display_message, "@{s5} has the greatest support among the lords of the {s4} to be the next marshall, but {s0} overrules their choice."),
  27475. (else_try),
  27476. (is_between, ":issue_on_table", centers_begin, centers_end),
  27477. (str_store_party_name, s1, ":issue_on_table"),
  27478. (display_message, "@{s5} has the greatest support among the lords of the {s4} to receive {s1}, but {s0} overrules their choice."),
  27479. (try_end),
  27480. (try_end),
  27481. (else_try),
  27482. #No override: use popular candidate
  27483. (assign, ":winning_candidate", ":popular_favorite"),
  27484. (try_end),
  27485. ##diplomacy end+
  27486.  
  27487. #Carry out faction decision
  27488. (try_begin), #Nothing happens
  27489. (eq, ":winning_candidate", -1),
  27490.  
  27491. (else_try), #For player, create a menu to accept or refuse
  27492. (eq, ":winning_candidate", "trp_player"),
  27493. (eq, "$players_kingdom", ":faction_no"),
  27494. (call_script, "script_add_notification_menu", "mnu_notification_player_faction_political_issue_resolved_for_player", 0, 0),
  27495. (else_try),
  27496. (eq, ":winning_candidate", "trp_player"),
  27497. (neq, "$players_kingdom", ":faction_no"),
  27498.  
  27499. (try_begin),
  27500. (eq, "$cheat_mode", 1),
  27501. (str_store_faction_name, s4, ":faction_no"),
  27502. (str_store_party_name, s5, ":winning_candidate"),
  27503. (display_message, "@{!}DEBUG -- {s4} drops {s5} as winner, for having changed sides"),
  27504. (try_end),
  27505.  
  27506. ##diplomacy start+ add support for promoted kingdom ladies
  27507. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27508. (this_or_next|troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  27509. (is_between, ":active_npc", active_npcs_begin, active_npcs_end),
  27510. ##diplomacy end+
  27511. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  27512. (eq, ":active_npc_faction", ":faction_no"),
  27513. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  27514. (try_end),
  27515. (try_begin),
  27516. (eq, "$players_kingdom", ":faction_no"),
  27517. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  27518. (try_end),
  27519.  
  27520. (else_try), #If candidate is not of winning faction, reset lrod votes
  27521. (store_faction_of_troop, ":winning_candidate_faction", ":winning_candidate"),
  27522. (neq, ":winning_candidate_faction", ":faction_no"),
  27523.  
  27524. (try_begin),
  27525. (eq, "$cheat_mode", 1),
  27526. (str_store_faction_name, s4, ":faction_no"),
  27527. (str_store_party_name, s5, ":winning_candidate"),
  27528. (display_message, "@{!}DEBUG -- {s4} drops {s5} as winner, for having changed sides"),
  27529. (try_end),
  27530. ##diplomacy start+ add support for promoted kingdom ladies
  27531. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27532. (this_or_next|troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  27533. (is_between, ":active_npc", active_npcs_begin, active_npcs_end),
  27534. ##diplomacy end+
  27535. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  27536. (eq, ":active_npc_faction", ":faction_no"),
  27537. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  27538. (try_end),
  27539. (try_begin),
  27540. (eq, "$players_kingdom", ":faction_no"),
  27541. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  27542. (try_end),
  27543.  
  27544. (else_try), #Honor awarded to another
  27545. (faction_get_slot, ":issue_on_table", ":faction_no", slot_faction_political_issue),
  27546. (try_begin), #A marshalship awarded to another
  27547. (eq, ":issue_on_table", 1),
  27548. (is_between, ":winning_candidate", active_npcs_begin, active_npcs_end),
  27549.  
  27550. ##diplomacy start+ add support for promoted kingdom ladies
  27551. (this_or_next|is_between, ":winning_candidate", heroes_begin, heroes_end),
  27552. (eq, "$players_kingdom", ":faction_no"),
  27553. (this_or_next|troop_slot_eq, ":winning_candidate", slot_troop_occupation, slto_kingdom_hero),
  27554. ##diplomacy end+
  27555. (this_or_next|is_between, ":winning_candidate", active_npcs_begin, active_npcs_end), #Prevents bug in which player given marshaldom of kingdom of which he/she is not a member
  27556. (eq, "$players_kingdom", ":faction_no"),
  27557.  
  27558. (assign, ":faction_marshal", ":winning_candidate"),
  27559. (else_try), #A fief awarded to another
  27560. (is_between, ":issue_on_table", centers_begin, centers_end),
  27561.  
  27562. #If given to the player, resolved above
  27563. (call_script, "script_give_center_to_lord", ":issue_on_table", ":winning_candidate", 0), #Zero means don't add garrison
  27564.  
  27565. #If the player had requested a captured castle
  27566. (try_begin),
  27567. (eq, ":issue_on_table", "$g_castle_requested_by_player"),
  27568. (party_slot_ge, ":issue_on_table", slot_town_lord, active_npcs_begin),
  27569. (store_faction_of_party, ":faction_of_issue", ":issue_on_table"),
  27570. (eq, ":faction_of_issue", "$players_kingdom"),
  27571. (assign, "$g_center_to_give_to_player", ":issue_on_table"),
  27572. (try_begin),
  27573. (troop_get_slot, ":husband", "trp_player", slot_troop_spouse),
  27574. ##diplomacy start+ add support for promotede kingdom ladies
  27575. (is_between, ":husband", heroes_begin, heroes_end),
  27576. (this_or_next|troop_slot_eq, ":winning_candidate", slot_troop_occupation, slto_kingdom_hero),
  27577. ##diplomacy end+
  27578. (is_between, ":husband", active_npcs_begin, active_npcs_end),
  27579. (eq, "$g_castle_requested_for_troop", ":husband"),
  27580. (neq, ":winning_candidate", ":husband"),
  27581. (jump_to_menu, "mnu_requested_castle_granted_to_another_female"),
  27582. (else_try),
  27583. (jump_to_menu, "mnu_requested_castle_granted_to_another"),
  27584. (try_end),
  27585. (try_end),
  27586.  
  27587. (try_end),
  27588.  
  27589. (try_begin),
  27590. (eq, ":faction_no", "$players_kingdom"),
  27591. (call_script, "script_add_notification_menu", "mnu_notification_player_faction_political_issue_resolved", ":issue_on_table", ":winning_candidate"),
  27592. (try_end),
  27593.  
  27594. #Reset political issue
  27595. (faction_set_slot, ":faction_no", slot_faction_political_issue, 0),
  27596. ##diplomacy start+ add support for promoted kingdom ladies
  27597. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27598. ##diplomacy end+
  27599. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  27600. (eq, ":active_npc_faction", ":faction_no"),
  27601. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  27602. (try_end),
  27603. (try_begin),
  27604. (eq, "$players_kingdom", ":faction_no"),
  27605. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  27606. (try_end),
  27607. (try_end),
  27608. (try_end),
  27609.  
  27610. #Add fief to faction issues
  27611. (try_begin),
  27612. (faction_get_slot, ":faction_issue", ":faction_no", slot_faction_political_issue),
  27613. (le, ":faction_issue", 0),
  27614.  
  27615. (assign, ":landless_lords", 0),
  27616. (assign, ":unassigned_centers", 0),
  27617. (assign, ":first_unassigned_center_found", 0),
  27618.  
  27619. (troop_set_slot, "trp_player", slot_troop_temp_slot, 0),
  27620. ##diplomacy start+ add support for promoted kingdom ladies
  27621. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27622. ##diplomacy end+
  27623. (troop_set_slot, ":active_npc", slot_troop_temp_slot, 0),
  27624. (try_end),
  27625.  
  27626. (try_for_range, ":center", centers_begin, centers_end),
  27627. (store_faction_of_party, ":center_faction", ":center"),
  27628. (eq, ":center_faction", ":faction_no"),
  27629.  
  27630. (party_get_slot, ":town_lord", ":center", slot_town_lord),
  27631.  
  27632. (try_begin),
  27633. (lt, ":town_lord", 0),
  27634. (val_add, ":unassigned_centers", 1),
  27635. (try_begin),
  27636. (eq, ":first_unassigned_center_found", 0),
  27637. (assign, ":first_unassigned_center_found", ":center"),
  27638. (try_end),
  27639. (else_try),
  27640. (troop_set_slot, ":town_lord", slot_troop_temp_slot, 1),
  27641. (try_end),
  27642. (try_end),
  27643.  
  27644. (store_add, ":landless_lords_plus_unassigned_centers", ":landless_lords", ":unassigned_centers"),
  27645. (ge, ":landless_lords_plus_unassigned_centers", 2),
  27646.  
  27647. (faction_set_slot, ":faction_no", slot_faction_political_issue, ":first_unassigned_center_found"),
  27648. (store_current_hours, ":hours"),
  27649. (faction_set_slot, ":faction_no", slot_faction_political_issue_time, ":hours"), #Fief put on agenda
  27650.  
  27651. ##diplomacy start+ add support for promoted kingdom ladies
  27652. (try_for_range, ":active_npc", heroes_begin, heroes_end),#<- change active_npcs to heroes
  27653. ##diplomacy end+
  27654. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  27655. (eq, ":active_npc_faction", ":faction_no"),
  27656. (troop_set_slot, ":active_npc", slot_troop_stance_on_faction_issue, -1),
  27657. (try_end),
  27658. (try_begin),
  27659. (eq, "$players_kingdom", ":faction_no"),
  27660. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  27661. (try_end),
  27662. (try_end),
  27663.  
  27664.  
  27665. (try_begin), #If the marshal is changed
  27666. (neg|faction_slot_eq, ":faction_no", slot_faction_marshall, ":faction_marshal"),
  27667. #(assign, ":marshall_changed", 1),
  27668. (eq, "$players_kingdom", ":faction_no"),
  27669. (str_store_troop_name_link, s1, ":faction_marshal"),
  27670. (str_store_faction_name_link, s2, ":faction_no"),
  27671. (display_message, "@{s1} is the new marshal of {s2}."),
  27672. (call_script, "script_check_and_finish_active_army_quests_for_faction", ":faction_no"),
  27673. (try_end),
  27674.  
  27675. (try_begin), #If the marshal is changed
  27676. (neg|faction_slot_eq, ":faction_no", slot_faction_marshall, ":faction_marshal"),
  27677. (gt, ":faction_marshal", -1),
  27678. (call_script, "script_appoint_faction_marshall", ":faction_no", ":faction_marshal"),
  27679. (try_end),
  27680.  
  27681. #DO FACTION AI HERE
  27682. (try_begin),
  27683. (eq, ":faction_no", "$players_kingdom"),
  27684. (eq, ":faction_marshal", "trp_player"),
  27685. (assign, ":faction_ai_decider", "trp_player"),
  27686. (else_try),
  27687. ##diplomacy start+ add support for promoted kingdom ladies
  27688. (is_between, ":faction_marshal", heroes_begin, heroes_end),
  27689. #(this_or_next|troop_slot_eq, ":faction_marshal", slot_troop_occupation, slto_kingdom_hero),
  27690. #(is_between, ":faction_marshal", active_npcs_begin, active_npcs_end),
  27691. ##diplomacy end+
  27692. (assign, ":faction_ai_decider", ":faction_marshal"),
  27693. (else_try),
  27694. (faction_get_slot, ":faction_ai_decider", ":faction_no", slot_faction_leader),
  27695. (try_end),
  27696.  
  27697. (call_script, "script_npc_decision_checklist_faction_ai_alt", ":faction_ai_decider"),
  27698. (assign, ":new_strategy", reg0),
  27699. (assign, ":new_object", reg1),
  27700.  
  27701. #new ozan
  27702. (try_begin),
  27703. (neq, ":new_strategy", ":old_faction_ai_state"),
  27704. (eq, ":new_strategy", sfai_gathering_army),
  27705. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  27706. ##diplomacy begin
  27707. #native script error bug fix when no marshal
  27708. (gt, ":faction_marshal", -1),
  27709. ##diplomacy end
  27710. (troop_get_slot, ":marshal_party", ":faction_marshal", slot_troop_leaded_party),
  27711. (party_set_slot, ":marshal_party", slot_party_ai_object, -1),
  27712. (assign, "$g_gathering_new_started", 1),
  27713. (call_script, "script_npc_decision_checklist_party_ai", ":faction_marshal"), #This handles AI for both marshal and other parties
  27714. (call_script, "script_party_set_ai_state", ":marshal_party", reg0, reg1),
  27715. (assign, "$g_gathering_new_started", 0),
  27716. (else_try),
  27717. #check if marshal arrived his target city during active gathering
  27718.  
  27719. #for now i disabled below lines because after always/active gathering armies become very large.
  27720. #in current style marshal makes active gathering only at first, it travels to a city and waits there.
  27721.  
  27722. (eq, ":new_strategy", ":old_faction_ai_state"),
  27723. (eq, ":new_strategy", sfai_gathering_army),
  27724. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  27725. ##diplomacy begin
  27726. #native script error bug fix when no marshal
  27727. (gt, ":faction_marshal", -1),
  27728. ##diplomacy end
  27729. (troop_get_slot, ":marshal_party", ":faction_marshal", slot_troop_leaded_party),
  27730. ##diplomacy start+ 2011-06-08 Fix bug when the marshall leaded party is set negative!
  27731. (gt, ":marshal_party", -1),
  27732. ##diplomacy end+
  27733. (party_get_slot, ":party_ai_object", ":marshal_party", slot_party_ai_object),
  27734. (ge, ":party_ai_object", 0),
  27735. (ge, ":marshal_party", 0),
  27736. (party_is_active, ":marshal_party"),
  27737. (party_is_active, ":party_ai_object"),
  27738. (store_distance_to_party_from_party, ":dist", ":marshal_party", ":party_ai_object"),
  27739. (le, ":dist", 5),
  27740. (party_set_slot, ":marshal_party", slot_party_ai_object, -1),
  27741. (try_end),
  27742. #end ozan
  27743.  
  27744. #The following logic is mostly transplanted to the new decision_checklist
  27745. #Decision_checklist is used because I want to be able to reproduce the logic for strings
  27746. #(call_script, "script_old_faction_ai"),
  27747. #ozan - I collected all comment-out lines in here (faction ai script) and placed most bottom of scripts.py to avoid confusing.
  27748.  
  27749. (faction_set_slot, ":faction_no", slot_faction_ai_state, ":new_strategy"),
  27750. (faction_set_slot, ":faction_no", slot_faction_ai_object, ":new_object"),
  27751.  
  27752. (call_script, "script_update_report_to_army_quest_note", ":faction_no", ":new_strategy", ":old_faction_ai_state"),
  27753.  
  27754. (try_begin),
  27755. (eq, ":new_strategy", sfai_feast),
  27756.  
  27757. (store_current_hours, ":hours"),
  27758. (faction_set_slot, ":faction_no", slot_faction_last_feast_start_time, ":hours"), #new
  27759.  
  27760. (try_begin),
  27761. (eq, "$g_player_eligible_feast_center_no", ":new_object"),
  27762. (assign, "$g_player_eligible_feast_center_no", -1), #reset needed
  27763. (try_end),
  27764. (try_begin),
  27765. (is_between, ":new_object", towns_begin, towns_end),
  27766. (party_set_slot, ":new_object", slot_town_has_tournament, 2),
  27767. (try_end),
  27768. (try_end),
  27769.  
  27770. #Change of strategy
  27771. (try_begin),
  27772. (neq, ":new_strategy", ":old_faction_ai_state"),
  27773.  
  27774. (try_begin),
  27775. (ge, "$cheat_mode", 1),
  27776. (str_store_faction_name, s5, ":faction_no"),
  27777. (display_message, "str_s5_decides_s14"),
  27778. (try_end),
  27779.  
  27780. (store_current_hours, ":hours"),
  27781. (faction_set_slot, ":faction_no", slot_faction_ai_current_state_started, ":hours"),
  27782.  
  27783. #Feast ends
  27784. (try_begin),
  27785. (eq, ":old_faction_ai_state", sfai_feast),
  27786. (call_script, "script_faction_conclude_feast", ":faction_no", ":old_faction_ai_object"),
  27787. (try_end),
  27788.  
  27789.  
  27790. #Feast begins
  27791. (try_begin),
  27792. (eq, ":new_strategy", sfai_feast),
  27793. (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
  27794.  
  27795. ## (str_store_faction_name, s1, ":faction_no"),
  27796. ## (str_store_party_name, s2, ":faction_object"),
  27797. ## (display_message, "str_lords_of_the_s1_gather_for_a_feast_at_s2"),
  27798.  
  27799. (party_get_slot, ":feast_host", ":faction_object", slot_town_lord),
  27800.  
  27801. (try_begin),
  27802. (check_quest_active, "qst_wed_betrothed"),
  27803.  
  27804. (quest_slot_eq, "qst_wed_betrothed", slot_quest_giver_troop, ":feast_host"),
  27805. (neg|quest_slot_ge, "qst_wed_betrothed", slot_quest_expiration_days, 362),
  27806. (call_script, "script_add_notification_menu", "mnu_notification_player_wedding_day", ":feast_host", ":faction_object"),
  27807. (else_try),
  27808. (check_quest_active, "qst_wed_betrothed_female"),
  27809.  
  27810. (quest_get_slot, ":player_betrothed", "qst_wed_betrothed", slot_quest_giver_troop),
  27811. (store_faction_of_troop, ":player_betrothed_faction", ":player_betrothed"),
  27812. (eq, ":player_betrothed_faction", ":faction_no"),
  27813. (neg|quest_slot_ge, "qst_wed_betrothed", slot_quest_expiration_days, 362),
  27814. (call_script, "script_add_notification_menu", "mnu_notification_player_kingdom_holds_feast", ":feast_host", ":faction_object"),
  27815. (else_try),
  27816. (eq, "$players_kingdom", ":faction_no"),
  27817. (troop_slot_ge, "trp_player", slot_troop_renown, 150),
  27818.  
  27819.  
  27820. (party_get_slot, ":feast_host", ":faction_object", slot_town_lord),
  27821. (call_script, "script_add_notification_menu", "mnu_notification_player_kingdom_holds_feast", ":feast_host", ":faction_object"),
  27822. (try_end),
  27823. (try_end),
  27824.  
  27825.  
  27826. #Offensive begins
  27827. (try_begin),
  27828. (eq, ":old_faction_ai_state", sfai_gathering_army),
  27829. (is_between, ":new_strategy", sfai_attacking_center, sfai_feast),
  27830. (try_begin),
  27831. (eq, "$cheat_mode", 1),
  27832. (str_store_faction_name, s5, ":faction_no"),
  27833. (display_message, "str_s5_begins_offensive"),
  27834. (try_end),
  27835.  
  27836. #Appoint screening party
  27837. (try_begin),
  27838. (assign, ":total_lords_participating", 0),
  27839. (assign, ":best_screening_party", -1),
  27840. (assign, ":score_to_beat", 30), #closest in size to 50
  27841. (troop_get_slot, ":faction_marshal_party", ":faction_marshal", slot_troop_leaded_party),
  27842. (party_is_active, ":faction_marshal_party"),
  27843.  
  27844. ##diplomacy start+
  27845. # (try_for_range, ":screen_leader", active_npcs_begin, active_npcs_end),##OLD
  27846. (try_for_range, ":screen_leader", heroes_begin, heroes_end),##NEW
  27847. ##diplomacy end+
  27848. (store_faction_of_troop, ":screen_leader_faction", ":screen_leader"),
  27849. (eq, ":screen_leader_faction", ":faction_no"),
  27850.  
  27851. (troop_get_slot, ":screening_party", ":screen_leader", slot_troop_leaded_party),
  27852. ##diplomacy start+ Guard against things such as the party being 0 (p_main_party)
  27853. (gt, ":screening_party", 0),
  27854. ##diplomacy end+
  27855. (party_is_active, ":screening_party"),
  27856. (party_slot_eq, ":screening_party", slot_party_ai_state, spai_accompanying_army),
  27857. (party_slot_eq, ":screening_party", slot_party_ai_object, ":faction_marshal_party"),
  27858. (val_add, ":total_lords_participating", 1),
  27859.  
  27860. (try_begin),
  27861. (ge, "$cheat_mode", 1),
  27862. (str_store_party_name, s4, ":screening_party"),
  27863. (display_message, "@{!}DEBUG -- {s4} participates in offensive"),
  27864. (try_end),
  27865.  
  27866.  
  27867. (store_party_size_wo_prisoners, ":screening_party_score", ":screening_party"),
  27868. (val_sub, ":screening_party_score", 50),
  27869. (val_abs, ":screening_party_score"),
  27870.  
  27871.  
  27872. (lt, ":screening_party_score", ":score_to_beat"),
  27873.  
  27874. #set party and score
  27875. (assign, ":best_screening_party", ":screening_party"),
  27876. (assign, ":score_to_beat", ":screening_party_score"),
  27877. (try_end),
  27878.  
  27879. (gt, ":total_lords_participating", 2),
  27880. (party_is_active, ":best_screening_party"),
  27881. (party_is_active, ":faction_marshal_party"),
  27882. (call_script, "script_party_set_ai_state", ":best_screening_party", spai_screening_army, ":faction_marshal_party"),
  27883. (try_begin),
  27884. (ge, "$cheat_mode", 1),
  27885. (str_store_party_name, s4, ":best_screening_party"),
  27886. (display_message, "@{!}DEBUG -- {s4} chosen as screen"),
  27887. (try_end),
  27888. #after this - dialogs on what doing, npc_decision_checklist
  27889. (try_end),
  27890.  
  27891. #Offensive concludes
  27892. (else_try),
  27893. (store_current_hours, ":hours"),
  27894. (this_or_next|eq, ":old_faction_ai_state", sfai_gathering_army),
  27895. (this_or_next|eq, ":old_faction_ai_state", sfai_attacking_center),
  27896. (this_or_next|eq, ":old_faction_ai_state", sfai_raiding_village),
  27897. #(this_or_next|eq, ":old_faction_ai_state", sfai_attacking_enemies_around_center),
  27898. (eq, ":old_faction_ai_state", sfai_attacking_enemy_army),
  27899.  
  27900. (this_or_next|eq, ":new_strategy", sfai_default),
  27901. (eq, ":new_strategy", sfai_feast),
  27902.  
  27903. (call_script, "script_check_and_finish_active_army_quests_for_faction", ":faction_no"),
  27904. (faction_set_slot, ":faction_no", slot_faction_last_offensive_concluded, ":hours"),
  27905. (try_end),
  27906. (try_end),
  27907.  
  27908. (try_begin),
  27909. (eq, "$players_kingdom", ":faction_no"),
  27910. (neg|faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_center),
  27911. (check_quest_active, "qst_join_siege_with_army"),
  27912. (call_script, "script_abort_quest", "qst_join_siege_with_army", 0),
  27913. (try_end),
  27914.  
  27915. (try_begin),
  27916. #old condition to rest, I changed below part - ozan, to rest (a faction's old strategy should be feast or default) and (a faction's new strategy should be feast or default)
  27917. #(this_or_next|eq, ":new_strategy", sfai_default),
  27918. #(this_or_next|eq, ":new_strategy", sfai_feast),
  27919. #(this_or_next|eq, ":old_faction_ai_state", sfai_default),
  27920. #(eq, ":old_faction_ai_state", sfai_feast),
  27921.  
  27922. #new condition to rest, (a faction's new strategy should be feast or default) and (":hours_at_current_state" > 20)
  27923. (this_or_next|eq, ":new_strategy", sfai_default),
  27924. (eq, ":new_strategy", sfai_feast),
  27925.  
  27926. (store_current_hours, ":hours_at_current_state"),
  27927. (faction_get_slot, ":current_state_started", ":faction_no", slot_faction_ai_current_state_started),
  27928. (val_sub, ":hours_at_current_state", ":current_state_started"),
  27929. (ge, ":hours_at_current_state", 18), #Must have at least 18 hours to reset
  27930.  
  27931. (store_current_hours, ":hours"),
  27932. (faction_set_slot, ":faction_no", slot_faction_ai_last_rest_time, ":hours"),
  27933. (try_end),
  27934. ]),
  27935.  
  27936. # script_check_and_finish_active_army_quests_for_faction
  27937. # Input: faction_no
  27938. # Output: none
  27939. ("check_and_finish_active_army_quests_for_faction",
  27940. [
  27941. (store_script_param_1, ":faction_no"),
  27942. (try_begin),
  27943. (eq, "$players_kingdom", ":faction_no"),
  27944. (try_begin),
  27945. (check_quest_active, "qst_report_to_army"),
  27946. (call_script, "script_cancel_quest", "qst_report_to_army"),
  27947. (try_end),
  27948. (assign, ":one_active", 0),
  27949. (try_for_range, ":quest_no", army_quests_begin, army_quests_end),
  27950. (check_quest_active, ":quest_no"),
  27951. (call_script, "script_cancel_quest", ":quest_no"),
  27952. (troop_get_slot, ":army_quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  27953. (assign, ":one_active", 1),
  27954. (try_end),
  27955. (try_begin),
  27956. (check_quest_active, "qst_follow_army"),
  27957. (assign, ":one_active", 1),
  27958. (troop_get_slot, ":army_quest_giver_troop", "qst_follow_army", slot_quest_giver_troop),
  27959. (call_script, "script_end_quest", "qst_follow_army"),
  27960. (try_end),
  27961. (eq, ":one_active", 1),
  27962. (faction_get_slot, ":last_offensive_time", ":faction_no", slot_faction_last_offensive_concluded),
  27963. (store_current_hours, ":cur_hours"),
  27964. (store_sub, ":total_time_served", ":cur_hours", ":last_offensive_time"),
  27965. (store_mul, ":xp_reward", ":total_time_served", 5),
  27966. (val_div, ":xp_reward", 50),
  27967. (val_mul, ":xp_reward", 50),
  27968. (val_add, ":xp_reward", 50),
  27969. (add_xp_as_reward, ":xp_reward"),
  27970. (call_script, "script_troop_change_relation_with_troop", "trp_player", ":army_quest_giver_troop", 2),
  27971. (try_end),
  27972. ]),
  27973.  
  27974. # script_troop_get_player_relation
  27975. # Input: arg1 = troop_no
  27976. # Output: reg0 = effective relation (modified by troop reputation, honor, etc.)
  27977. ("troop_get_player_relation",
  27978. [
  27979. (store_script_param_1, ":troop_no"),
  27980. (troop_get_slot, ":reputation", ":troop_no", slot_lord_reputation_type),
  27981. (troop_get_slot, ":effective_relation", ":troop_no", slot_troop_player_relation),
  27982. (assign, ":honor_bonus", 0),
  27983. (try_begin),
  27984. (eq, ":reputation", lrep_quarrelsome),
  27985. (val_add, ":effective_relation", -3),
  27986. (try_end),
  27987. (try_begin),
  27988. (ge, "$player_honor", 0),
  27989. (try_begin),
  27990. (this_or_next|eq, ":reputation", lrep_upstanding),
  27991. ( eq, ":reputation", lrep_goodnatured),
  27992. (store_div, ":honor_bonus", "$player_honor", 3),
  27993. ##diplomacy start+
  27994. (else_try),
  27995. #In general this should not apply to ladies, as they operate by different
  27996. #reputation rules, but if a "kingdom lady" has become a "kingdom hero" instead,
  27997. #it should apply.
  27998. (eq, ":reputation", lrep_moralist),#-- verify that the lady is effectively a lord:
  27999. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  28000. (store_div, ":honor_bonus", "$player_honor", 3),
  28001. (else_try),
  28002. #Personality type that values keeping your word
  28003. (call_script, "script_dplmc_get_troop_morality_value", ":troop_no", tmt_honest),
  28004. (ge, reg0, 1),
  28005. (store_div, ":honor_bonus", "$player_honor", 3),
  28006. ##diplomacy end+
  28007. (try_end),
  28008. (try_end),
  28009. (try_begin),
  28010. (lt, "$player_honor", 0),
  28011. (try_begin),
  28012. (this_or_next|eq, ":reputation", lrep_upstanding),
  28013. ( eq, ":reputation", lrep_goodnatured),
  28014. (store_div, ":honor_bonus", "$player_honor", 3),
  28015. ##diplomacy start+
  28016. (else_try),
  28017. (call_script, "script_dplmc_get_troop_morality_value", ":troop_no", tmt_honest),
  28018. (ge, reg0, 1),#Personality type that values keeping your word
  28019. (store_div, ":honor_bonus", "$player_honor", 3),
  28020. (else_try),
  28021. #"My kind of scum" - a few rare individuals might actively approve.
  28022. (lt, reg0, 0),#<-- must have negative value for tmt_honest; by default this is only Rolf.
  28023. (this_or_next|eq, ":reputation", lrep_roguish),
  28024. (this_or_next|eq, ":reputation", lrep_custodian),
  28025. (this_or_next|eq, ":reputation", lrep_debauched),
  28026. (this_or_next|eq, ":reputation", lrep_ambitious),
  28027. (eq, ":reputation", lrep_cunning),
  28028. (store_div, ":honor_bonus", "$player_honor", -5),
  28029. (val_clamp, ":honor_bonus", 1, 6),
  28030. (else_try),
  28031. #"Honorable" lords can be awful people, so no bonus with benefactors,
  28032. #but dishonorable lords are *guaranteed* to be awful.
  28033. (eq, ":reputation", lrep_benefactor),
  28034. (store_div, ":honor_bonus", "$player_honor", 5),
  28035. (else_try),
  28036. #Self-righteous lords are moralizing but hypocritical.
  28037. (eq, ":reputation", lrep_selfrighteous),
  28038. (store_div, ":honor_bonus", "$player_honor", 5),
  28039. (else_try),
  28040. #In general this should not apply to ladies, as they operate by different
  28041. #reputation rules, but if a "kingdom lady" has become a "kingdom hero" instead,
  28042. #it should apply.
  28043. (eq, ":reputation", lrep_moralist),#-- verify that the lady is effectively a lord:
  28044. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  28045. (store_div, ":honor_bonus", "$player_honor", 3),
  28046. (else_try),
  28047. (eq, ":reputation", lrep_conventional),#-- verify that the lady is effectively a lord:
  28048. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  28049. (store_div, ":honor_bonus", "$player_honor", 5),
  28050. ##diplomacy end+
  28051. (else_try),
  28052. (eq, ":reputation", lrep_martial),
  28053. (store_div, ":honor_bonus", "$player_honor", 5),
  28054. (try_end),
  28055. (try_end),
  28056. (val_add, ":effective_relation", ":honor_bonus"),
  28057. (val_clamp, ":effective_relation", -100, 101),
  28058. (assign, reg0, ":effective_relation"),
  28059. ]),
  28060.  
  28061. # script_change_troop_renown
  28062. # Input: arg1 = troop_no, arg2 = relation difference
  28063. # Output: none
  28064. ("change_troop_renown",
  28065. [
  28066. (store_script_param_1, ":troop_no"),
  28067. (store_script_param_2, ":renown_change"),
  28068.  
  28069. (troop_get_slot, ":old_renown", ":troop_no", slot_troop_renown),
  28070.  
  28071. (try_begin),
  28072. (gt, ":renown_change", 0),
  28073. (assign, reg4, ":renown_change"),
  28074.  
  28075. (store_div, ":subtraction", ":old_renown", 200),
  28076. (val_sub, ":renown_change", ":subtraction"),
  28077. (val_max, ":renown_change", 0),
  28078.  
  28079. (eq, ":troop_no", "trp_player"),
  28080. (assign, reg5, ":renown_change"),
  28081.  
  28082. (eq, "$cheat_mode", 1),
  28083. (display_message, "str_renown_change_of_reg4_reduced_to_reg5_because_of_high_existing_renown"),
  28084. (try_end),
  28085.  
  28086. (store_add, ":new_renown", ":old_renown", ":renown_change"),
  28087. (val_max, ":new_renown", 0),
  28088. (troop_set_slot, ":troop_no", slot_troop_renown, ":new_renown"),
  28089.  
  28090. (try_begin),
  28091. (eq, ":troop_no", "trp_player"),
  28092.  
  28093. (try_begin),
  28094. (ge, ":new_renown", 50),
  28095.  
  28096. (try_begin),
  28097. (troop_get_type, ":is_female", "trp_player"),
  28098. (eq, ":is_female", 1),
  28099. (unlock_achievement, ACHIEVEMENT_TALK_OF_THE_TOWN),
  28100. (try_end),
  28101. (try_end),
  28102.  
  28103. # (str_store_troop_name, s1, ":troop_no"),
  28104. (assign, reg12, ":renown_change"),
  28105. (val_abs, reg12),
  28106. (try_begin),
  28107. (gt, ":renown_change", 0),
  28108. (display_message, "@You gained {reg12} renown.", message_positive),
  28109. (else_try),
  28110. (lt, ":renown_change", 0),
  28111. (display_message, "@You lose {reg12} renown.", message_negative),
  28112. (try_end),
  28113. (try_end),
  28114. (call_script, "script_update_troop_notes", ":troop_no"),
  28115. ]),
  28116.  
  28117.  
  28118. # script_change_player_relation_with_troop
  28119. # Input: arg1 = troop_no, arg2 = relation difference
  28120. # Output: none
  28121. ("change_player_relation_with_troop",
  28122. [
  28123. (store_script_param_1, ":troop_no"),
  28124. (store_script_param_2, ":difference"),
  28125.  
  28126. (try_begin),
  28127. (neq, ":troop_no", "trp_player"),
  28128. (neg|is_between, ":troop_no", soldiers_begin, soldiers_end),
  28129. ##diplomacy start+
  28130. (neq, ":troop_no", "trp_kingdom_heroes_including_player_begin"),
  28131. #(neq, ":troop_no", -1),#OLD
  28132. (ge, ":troop_no", 1),#NEW
  28133. ##diplomacy end+
  28134. (neq, ":difference", 0),
  28135. (call_script, "script_troop_get_player_relation", ":troop_no"),
  28136. (assign, ":old_effective_relation", reg0),
  28137. (troop_get_slot, ":player_relation", ":troop_no", slot_troop_player_relation),
  28138. (val_add, ":player_relation", ":difference"),
  28139. (val_clamp, ":player_relation", -100, 101),
  28140. (try_begin),
  28141. (troop_set_slot, ":troop_no", slot_troop_player_relation, ":player_relation"),
  28142.  
  28143. (try_begin),
  28144. (le, ":player_relation", -50),
  28145. (unlock_achievement, ACHIEVEMENT_OLD_DIRTY_SCOUNDREL),
  28146. (try_end),
  28147.  
  28148. (str_store_troop_name_link, s1, ":troop_no"),
  28149. (call_script, "script_troop_get_player_relation", ":troop_no"),
  28150. (assign, ":new_effective_relation", reg0),
  28151. (neq, ":old_effective_relation", ":new_effective_relation"),
  28152. (assign, reg1, ":old_effective_relation"),
  28153. (assign, reg2, ":new_effective_relation"),
  28154. (try_begin),
  28155. ##diplomacy start+ Suppress this message for dead people except in cheat mode
  28156. (lt, "$cheat_mode", 1),
  28157. (troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_dead),
  28158. (neq, ":troop_no", "$g_talk_troop"),
  28159. (else_try),
  28160. ##diplomacy end+
  28161. (gt, ":difference", 0),
  28162. (display_message, "str_troop_relation_increased", message_positive),
  28163. (else_try),
  28164. (lt, ":difference", 0),
  28165. (display_message, "str_troop_relation_detoriated", message_negative),
  28166. (try_end),
  28167. (try_begin),
  28168. (eq, ":troop_no", "$g_talk_troop"),
  28169. (assign, "$g_talk_troop_relation", ":new_effective_relation"),
  28170. (call_script, "script_setup_talk_info"),
  28171. (try_end),
  28172. (call_script, "script_update_troop_notes", ":troop_no"),
  28173. (try_end),
  28174. (try_end),
  28175. ]),
  28176.  
  28177. # script_change_player_relation_with_center
  28178. # Input: arg1 = party_no, arg2 = relation difference
  28179. # Output: none
  28180. ("change_player_relation_with_center",
  28181. [
  28182. (store_script_param_1, ":center_no"),
  28183. (store_script_param_2, ":difference"),
  28184.  
  28185. (party_get_slot, ":player_relation", ":center_no", slot_center_player_relation),
  28186. (assign, reg1, ":player_relation"),
  28187. (val_add, ":player_relation", ":difference"),
  28188. (val_clamp, ":player_relation", -100, 100),
  28189. (assign, reg2, ":player_relation"),
  28190. (party_set_slot, ":center_no", slot_center_player_relation, ":player_relation"),
  28191.  
  28192. (try_begin),
  28193. (le, ":player_relation", -50),
  28194. (unlock_achievement, ACHIEVEMENT_OLD_DIRTY_SCOUNDREL),
  28195. (try_end),
  28196.  
  28197.  
  28198. (str_store_party_name_link, s1, ":center_no"),
  28199. (try_begin),
  28200. (gt, ":difference", 0),
  28201. (display_message, "@Your relation with {s1} has improved.", message_positive),
  28202. (else_try),
  28203. (lt, ":difference", 0),
  28204. (display_message, "@Your relation with {s1} has deteriorated.", message_negative),
  28205. (try_end),
  28206. (try_begin),
  28207. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  28208. (call_script, "script_update_volunteer_troops_in_village", ":center_no"),
  28209. (try_end),
  28210.  
  28211. (try_begin),
  28212. (this_or_next|is_between, "$g_talk_troop", village_elders_begin, village_elders_end),
  28213. (is_between, "$g_talk_troop", mayors_begin, mayors_end),
  28214. ##diplomacy start+
  28215. #Fix potential bug: don't adjust relations except with *that* center's
  28216. #mayor.
  28217. (party_slot_eq, ":center_no", slot_town_elder, "$g_talk_troop"),
  28218. ##diplomacy end+
  28219. (assign, "$g_talk_troop_relation", ":player_relation"),
  28220. (call_script, "script_setup_talk_info"),
  28221. (try_end),
  28222. ]),
  28223.  
  28224.  
  28225. # script_change_player_relation_with_faction
  28226. # Input: arg1 = faction_no, arg2 = relation difference
  28227. # Output: none
  28228. ("change_player_relation_with_faction",
  28229. [
  28230. (store_script_param_1, ":faction_no"),
  28231. (store_script_param_2, ":difference"),
  28232.  
  28233. (store_relation, ":player_relation", ":faction_no", "fac_player_supporters_faction"),
  28234. (assign, reg1, ":player_relation"),
  28235. (val_add, ":player_relation", ":difference"),
  28236. (assign, reg2, ":player_relation"),
  28237. (set_relation, ":faction_no", "fac_player_faction", ":player_relation"),
  28238. (set_relation, ":faction_no", "fac_player_supporters_faction", ":player_relation"),
  28239.  
  28240. (try_begin),
  28241. (le, ":player_relation", -50),
  28242. (unlock_achievement, ACHIEVEMENT_OLD_DIRTY_SCOUNDREL),
  28243. (try_end),
  28244.  
  28245.  
  28246. (str_store_faction_name_link, s1, ":faction_no"),
  28247. #SB : colorize message, although faction color might be better
  28248. (try_begin),
  28249. (gt, ":difference", 0),
  28250. (display_message, "str_faction_relation_increased", message_positive),
  28251. (else_try),
  28252. (lt, ":difference", 0),
  28253. (display_message, "str_faction_relation_detoriated", message_negative),
  28254. (try_end),
  28255. (call_script, "script_update_all_notes"),
  28256. ]),
  28257.  
  28258. # script_set_player_relation_with_faction
  28259. # Input: arg1 = faction_no, arg2 = relation
  28260. # Output: none
  28261. ("set_player_relation_with_faction",
  28262. [
  28263. (store_script_param_1, ":faction_no"),
  28264. (store_script_param_2, ":relation"),
  28265.  
  28266. (store_relation, ":player_relation", ":faction_no", "fac_player_supporters_faction"),
  28267. (store_sub, ":reln_dif", ":relation", ":player_relation"),
  28268. (call_script, "script_change_player_relation_with_faction", ":faction_no", ":reln_dif"),
  28269. ]),
  28270.  
  28271.  
  28272.  
  28273. # script_change_player_relation_with_faction_ex
  28274. # changes relations with other factions also (according to their relations between each other)
  28275. # Input: arg1 = faction_no, arg2 = relation difference
  28276. # Output: none
  28277. ("change_player_relation_with_faction_ex",
  28278. [
  28279. (store_script_param_1, ":faction_no"),
  28280. (store_script_param_2, ":difference"),
  28281.  
  28282. (store_relation, ":player_relation", ":faction_no", "fac_player_supporters_faction"),
  28283. (assign, reg1, ":player_relation"),
  28284. (val_add, ":player_relation", ":difference"),
  28285. (assign, reg2, ":player_relation"),
  28286. (set_relation, ":faction_no", "fac_player_faction", ":player_relation"),
  28287. (set_relation, ":faction_no", "fac_player_supporters_faction", ":player_relation"),
  28288.  
  28289. (str_store_faction_name_link, s1, ":faction_no"),
  28290. #SB : positive/negative messages
  28291. (try_begin),
  28292. (gt, ":difference", 0),
  28293. (display_message, "str_faction_relation_increased", message_positive),
  28294. (else_try),
  28295. (lt, ":difference", 0),
  28296. (display_message, "str_faction_relation_detoriated", message_negative),
  28297. (try_end),
  28298. #SB : morale adjustments
  28299. (store_mul, ":morale_change", ":difference", 50), #instead of x100
  28300. (call_script, "script_change_faction_troop_morale", ":faction_no", ":morale_change", 0),
  28301.  
  28302. (try_for_range, ":other_faction", kingdoms_begin, kingdoms_end),
  28303. (faction_slot_eq, ":other_faction", slot_faction_state, sfs_active),
  28304. (neq, ":faction_no", ":other_faction"),
  28305. (store_relation, ":other_faction_relation", ":faction_no", ":other_faction"),
  28306. (store_relation, ":player_relation", ":other_faction", "fac_player_supporters_faction"),
  28307. (store_mul, ":relation_change", ":difference", ":other_faction_relation"),
  28308. (val_div, ":relation_change", 100),
  28309. (val_add, ":player_relation", ":relation_change"),
  28310. ##diplomacy start
  28311. (try_begin),
  28312. (store_add, ":truce_slot", "fac_player_supporters_faction", slot_faction_truce_days_with_factions_begin),
  28313. (val_sub, ":truce_slot", kingdoms_begin),
  28314. (faction_get_slot, ":truce_days", ":other_faction", ":truce_slot"),
  28315. ##nested diplomacy start+ Changed "eq 0", to "le 0", since now negative truce days track war length
  28316. (this_or_next|le, ":truce_days", 0), #other faction only affected if no truce
  28317. ##nested diplomacy end+
  28318. (gt, ":difference", 0), #or change > 0
  28319. (store_relation, ":cur_relation", ":other_faction", "fac_player_supporters_faction"),
  28320.  
  28321. #display relation change message
  28322. (store_sub, ":relation_change", ":player_relation", ":cur_relation"),
  28323. (str_store_faction_name_link, s1, ":other_faction"),
  28324. (assign, reg1, ":cur_relation"),
  28325. (assign, reg2, ":player_relation"),
  28326. (try_begin),
  28327. (gt, ":relation_change", 0),
  28328. (display_message, "str_faction_relation_increased", message_positive),
  28329. (else_try),
  28330. (lt, ":relation_change", 0),
  28331. (display_message, "str_faction_relation_detoriated", message_negative),
  28332. (try_end),
  28333.  
  28334. #display war declaration
  28335. (try_begin),
  28336. (ge, ":cur_relation", 0), #old relation > 0 -> peace
  28337. (lt, ":player_relation", 0), #new relation < 0 -> war
  28338. ##nested diplomacy start+
  28339. #This is the source of the "fake war" bug. I think this should get rid of it:
  28340. (try_begin),
  28341. (this_or_next|eq, "$players_kingdom", "fac_player_faction"),
  28342. (eq, "$players_kingdom", "fac_player_supporters_faction"),
  28343. ##nested diplomacy end+
  28344. (call_script, "script_add_notification_menu", "mnu_notification_war_declared", ":other_faction", "$players_kingdom"),
  28345. ##nested diplomacy start+
  28346. (else_try),
  28347. (is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
  28348. (store_relation, ":players_kingdom_relation", ":other_faction", "$players_kingdom"),
  28349. (lt, ":players_kingdom_relation", 0),
  28350. (call_script, "script_add_notification_menu", "mnu_notification_war_declared", ":other_faction", "$players_kingdom"),
  28351. (else_try),
  28352. #Display some sort of message so you know something happened
  28353. (display_message, "@{!} There is widespread ill-will towards you in the {s1}."),
  28354. (try_end),
  28355. ##nested diplomacy end+
  28356. (try_end),
  28357. ##diplomacy end
  28358. (set_relation, ":other_faction", "fac_player_faction", ":player_relation"),
  28359. (set_relation, ":other_faction", "fac_player_supporters_faction", ":player_relation"),
  28360. ##diplomacy begin
  28361. (try_end),
  28362. ##diplomacy end
  28363. (try_end),
  28364. (try_begin),
  28365. (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_active),
  28366. (try_for_range, ":kingdom_no", kingdoms_begin, kingdoms_end),
  28367. (faction_slot_eq, ":kingdom_no", slot_faction_state, sfs_active),
  28368. (call_script, "script_update_faction_notes", ":kingdom_no"),
  28369. (try_end),
  28370. (try_end),
  28371. ]),
  28372.  
  28373. # script_cf_get_random_active_faction_except_player_faction_and_faction
  28374. # Input: arg1 = except_faction_no
  28375. # Output: reg0 = random_faction
  28376. ("cf_get_random_active_faction_except_player_faction_and_faction",
  28377. [
  28378. (store_script_param_1, ":except_faction_no"),
  28379. (assign, ":num_factions", 0),
  28380. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  28381. (neq, ":faction_no", "fac_player_supporters_faction"),
  28382. (neq, ":faction_no", ":except_faction_no"),
  28383. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  28384. (val_add, ":num_factions", 1),
  28385. (try_end),
  28386. (gt, ":num_factions", 0),
  28387. (assign, ":selected_faction", -1),
  28388. (store_random_in_range, ":random_faction", 0, ":num_factions"),
  28389. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  28390. (ge, ":random_faction", 0),
  28391. (neq, ":faction_no", "fac_player_supporters_faction"),
  28392. (neq, ":faction_no", ":except_faction_no"),
  28393. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  28394. (val_sub, ":random_faction", 1),
  28395. (lt, ":random_faction", 0),
  28396. (assign, ":selected_faction", ":faction_no"),
  28397. (try_end),
  28398. (assign, reg0, ":selected_faction"),
  28399. ]),
  28400.  
  28401. # script_make_kingdom_hostile_to_player
  28402. # Input: arg1 = faction_no, arg2 = relation difference
  28403. # Output: none
  28404. ("make_kingdom_hostile_to_player",
  28405. [
  28406. (store_script_param_1, ":kingdom_no"),
  28407. (store_script_param_2, ":difference"),
  28408.  
  28409. (try_begin),
  28410. (lt, ":difference", 0),
  28411. (store_relation, ":player_relation", ":kingdom_no", "fac_player_supporters_faction"),
  28412. (val_min, ":player_relation", 0),
  28413. (val_add, ":player_relation", ":difference"),
  28414. (call_script, "script_set_player_relation_with_faction", ":kingdom_no", ":player_relation"),
  28415. (try_end),
  28416. ]),
  28417.  
  28418. # script_change_player_honor
  28419. # Input: arg1 = honor difference
  28420. # Output: none
  28421. ("change_player_honor",
  28422. [
  28423. (store_script_param_1, ":honor_dif"),
  28424. ##diplomacy start+
  28425. #Exacerbate the effect of honor losses as the player's honor increases
  28426. (try_begin),
  28427. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_HIGH),#<-- experimental settings must be enabled
  28428. (ge, "$player_honor", 10),
  28429. (lt, ":honor_dif", 0),
  28430. (store_add, ":honor_multiplier", "$player_honor", 100),
  28431. (val_mul, ":honor_dif", ":honor_multiplier"),
  28432. (val_sub, ":honor_dif", 50),
  28433. (val_div, ":honor_dif", 100),
  28434. (try_end),
  28435. ##diplomacy end+
  28436. (val_add, "$player_honor", ":honor_dif"),
  28437. (try_begin),
  28438. (gt, ":honor_dif", 0),
  28439. (display_message, "@You gain honour.", message_positive),
  28440. (else_try),
  28441. (lt, ":honor_dif", 0),
  28442. (display_message, "@You lose honour.", message_negative),
  28443. (try_end),
  28444.  
  28445. ## (val_mul, ":honor_dif", 1000),
  28446. ## (assign, ":temp_honor", 0),
  28447. ## (assign, ":num_nonlinear_steps", 10),
  28448. ## (try_begin),
  28449. ## (gt, "$player_honor", 0),
  28450. ## (lt, ":honor_dif", 0),
  28451. ## (assign, ":num_nonlinear_steps", 0),
  28452. ## (else_try),
  28453. ## (lt, "$player_honor", 0),
  28454. ## (gt, ":honor_dif", 0),
  28455. ## (assign, ":num_nonlinear_steps", 3),
  28456. ## (try_end),
  28457. ##
  28458. ## (try_begin),
  28459. ## (ge, "$player_honor", 0),
  28460. ## (assign, ":temp_honor", "$player_honor"),
  28461. ## (else_try),
  28462. ## (val_sub, ":temp_honor", "$player_honor"),
  28463. ## (try_end),
  28464. ## (try_for_range, ":unused",0,":num_nonlinear_steps"),
  28465. ## (ge, ":temp_honor", 10000),
  28466. ## (val_div, ":temp_honor", 2),
  28467. ## (val_div, ":honor_dif", 2),
  28468. ## (try_end),
  28469. ## (val_add, "$player_honor", ":honor_dif"),
  28470. ]),
  28471.  
  28472. # script_change_player_party_morale
  28473. # Input: arg1 = morale difference
  28474. # Output: none
  28475. ("change_player_party_morale",
  28476. [
  28477. (store_script_param_1, ":morale_dif"),
  28478. (party_get_morale, ":cur_morale", "p_main_party"),
  28479. (val_clamp, ":cur_morale", 0, 100),
  28480.  
  28481. (store_add, ":new_morale", ":cur_morale", ":morale_dif"),
  28482. (val_clamp, ":new_morale", 0, 100),
  28483.  
  28484. (party_set_morale, "p_main_party", ":new_morale"),
  28485. #SB : colorize message
  28486. (try_begin),
  28487. (lt, ":new_morale", ":cur_morale"),
  28488. (store_sub, reg1, ":cur_morale", ":new_morale"),
  28489. (display_message, "str_party_lost_morale", message_negative),
  28490. (else_try),
  28491. (gt, ":new_morale", ":cur_morale"),
  28492. (store_sub, reg1, ":new_morale", ":cur_morale"),
  28493. (display_message, "str_party_gained_morale", message_positive),
  28494. (try_end),
  28495. ]),
  28496.  
  28497. # script_cf_player_has_item_without_modifier
  28498. # Input: arg1 = item_id, arg2 = modifier
  28499. # Output: none (can_fail)
  28500. ("cf_player_has_item_without_modifier",
  28501. [
  28502. (store_script_param, ":item_id", 1),
  28503. (store_script_param, ":modifier", 2),
  28504. (player_has_item, ":item_id"),
  28505. #checking if any of the meat is not rotten
  28506. (assign, ":has_without_modifier", 0),
  28507. (troop_get_inventory_capacity, ":inv_size", "trp_player"),
  28508. (try_for_range, ":i_slot", 0, ":inv_size"),
  28509. (troop_get_inventory_slot, ":cur_item", "trp_player", ":i_slot"),
  28510. (eq, ":cur_item", ":item_id"),
  28511. (troop_get_inventory_slot_modifier, ":cur_modifier", "trp_player", ":i_slot"),
  28512. (neq, ":cur_modifier", ":modifier"),
  28513. (assign, ":has_without_modifier", 1),
  28514. (assign, ":inv_size", 0), #break
  28515. (try_end),
  28516. (eq, ":has_without_modifier", 1),
  28517. ]),
  28518.  
  28519. # script_get_player_party_morale_values
  28520. # Output: reg0 = player_party_morale_target
  28521. ("get_player_party_morale_values",
  28522. [
  28523. (party_get_num_companion_stacks, ":num_stacks","p_main_party"),
  28524. (assign, ":num_men", 0),
  28525. (try_for_range, ":i_stack", 1, ":num_stacks"),
  28526. (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
  28527. (try_begin),
  28528. (troop_is_hero, ":stack_troop"),
  28529. (val_add, ":num_men", 1), #it was 3 in "Mount&Blade", now it is 1 in Warband
  28530. (else_try),
  28531. (party_stack_get_size, ":stack_size","p_main_party",":i_stack"),
  28532. (val_add, ":num_men", ":stack_size"),
  28533. (try_end),
  28534. (try_end),
  28535. (assign, "$g_player_party_morale_modifier_party_size", ":num_men"),
  28536.  
  28537. (store_skill_level, ":player_leadership", "skl_leadership", "trp_player"),
  28538.  
  28539. (try_begin),
  28540. (eq, "$players_kingdom", "fac_player_supporters_faction"),
  28541. (faction_get_slot, ":cur_faction_king", "$players_kingdom", slot_faction_leader),
  28542. (eq, ":cur_faction_king", "trp_player"),
  28543. (store_mul, "$g_player_party_morale_modifier_leadership", ":player_leadership", 15),
  28544. (else_try),
  28545. (store_mul, "$g_player_party_morale_modifier_leadership", ":player_leadership", 12),
  28546. (try_end),
  28547.  
  28548. (assign, ":new_morale", "$g_player_party_morale_modifier_leadership"),
  28549. (val_sub, ":new_morale", "$g_player_party_morale_modifier_party_size"),
  28550.  
  28551. (val_add, ":new_morale", 50),
  28552.  
  28553. (assign, "$g_player_party_morale_modifier_food", 0),
  28554. (try_for_range, ":cur_edible", food_begin, food_end),
  28555. (call_script, "script_cf_player_has_item_without_modifier", ":cur_edible", imod_rotten),
  28556. (item_get_slot, ":food_bonus", ":cur_edible", slot_item_food_bonus),
  28557.  
  28558. (val_mul, ":food_bonus", 3),
  28559. (val_div, ":food_bonus", 2),
  28560.  
  28561. (val_add, "$g_player_party_morale_modifier_food", ":food_bonus"),
  28562. (try_end),
  28563. (val_add, ":new_morale", "$g_player_party_morale_modifier_food"),
  28564.  
  28565. (try_begin),
  28566. (eq, "$g_player_party_morale_modifier_food", 0),
  28567. (assign, "$g_player_party_morale_modifier_no_food", 30),
  28568. (val_sub, ":new_morale", "$g_player_party_morale_modifier_no_food"),
  28569. (else_try),
  28570. (assign, "$g_player_party_morale_modifier_no_food", 0),
  28571. (try_end),
  28572.  
  28573. (assign, "$g_player_party_morale_modifier_debt", 0),
  28574. (try_begin),
  28575. (gt, "$g_player_debt_to_party_members", 0),
  28576. (call_script, "script_calculate_player_faction_wage"),
  28577. (assign, ":total_wages", reg0),
  28578. (store_mul, "$g_player_party_morale_modifier_debt", "$g_player_debt_to_party_members", 10),
  28579. (val_max, ":total_wages", 1),
  28580. (val_div, "$g_player_party_morale_modifier_debt", ":total_wages"),
  28581. (val_clamp, "$g_player_party_morale_modifier_debt", 1, 31),
  28582. (val_sub, ":new_morale", "$g_player_party_morale_modifier_debt"),
  28583. (try_end),
  28584.  
  28585. (val_clamp, ":new_morale", 0, 100),
  28586. (assign, reg0, ":new_morale"),
  28587. ]),
  28588.  
  28589. # script_diplomacy_start_war_between_kingdoms
  28590. # Input: arg1 = kingdom_1, arg2 = kingdom_2, arg3 = initializing_war_peace_cond
  28591. # Output: none
  28592. ("diplomacy_start_war_between_kingdoms", #sets relations between two kingdoms and their vassals.
  28593. [
  28594. (store_script_param, ":kingdom_a", 1),
  28595. (store_script_param, ":kingdom_b", 2),
  28596. (store_script_param, ":initializing_war_peace_cond", 3), #1 = after start of game
  28597.  
  28598. (call_script, "script_npc_decision_checklist_peace_or_war", ":kingdom_a", ":kingdom_b", -1),
  28599. (assign, ":explainer_string", reg1),
  28600.  
  28601. #
  28602. ##diplomacy begin
  28603. (try_begin),
  28604. (lt, ":initializing_war_peace_cond", 2),
  28605. ##diplomacy end
  28606. (try_begin),
  28607. (eq, ":kingdom_a", "fac_player_supporters_faction"),
  28608. (assign, ":war_event", logent_player_faction_declares_war),
  28609. (else_try),
  28610. (eq, ":explainer_string", "str_s12s15_declared_war_to_control_calradia"),
  28611. (assign, ":war_event", logent_player_faction_declares_war), #for savegame compatibility, this event stands in for the attempt to declare war on all of calradia
  28612. (else_try),
  28613. (eq, ":explainer_string", "str_s12s15_considers_s16_to_be_dangerous_and_untrustworthy_and_shehe_wants_to_bring_s16_down"),
  28614. (assign, ":war_event", logent_faction_declares_war_out_of_personal_enmity),
  28615. (else_try),
  28616. (eq, ":explainer_string", "str_s12s15_is_anxious_to_reclaim_old_lands_such_as_s18_now_held_by_s16"),
  28617. (assign, ":war_event", logent_faction_declares_war_to_regain_territory),
  28618. (else_try),
  28619. (eq, ":explainer_string", "str_s12s15_faces_too_much_internal_discontent_to_feel_comfortable_ignoring_recent_provocations_by_s16s_subjects"),
  28620. (assign, ":war_event", logent_faction_declares_war_to_respond_to_provocation),
  28621. (else_try),
  28622. (eq, ":explainer_string", "str_s12s15_is_alarmed_by_the_growing_power_of_s16"),
  28623. (assign, ":war_event", logent_faction_declares_war_to_curb_power),
  28624. (try_end),
  28625. (call_script, "script_add_log_entry", ":war_event", ":kingdom_a", 0, 0, ":kingdom_b"),
  28626.  
  28627.  
  28628.  
  28629. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":kingdom_a", ":kingdom_b"),
  28630. (assign, ":current_diplomatic_status", reg0),
  28631. (try_begin), #effects of policy only after the start of the game
  28632. (eq, ":initializing_war_peace_cond", 1),
  28633. (eq, ":current_diplomatic_status", -1),
  28634. (call_script, "script_faction_follows_controversial_policy", ":kingdom_a", logent_policy_ruler_declares_war_with_justification),
  28635. (else_try),
  28636. (eq, ":initializing_war_peace_cond", 1),
  28637. (eq, ":current_diplomatic_status", 0),
  28638. (call_script, "script_faction_follows_controversial_policy", ":kingdom_a", logent_policy_ruler_attacks_without_provocation),
  28639. (else_try),
  28640. (eq, ":current_diplomatic_status", 1),
  28641. (call_script, "script_faction_follows_controversial_policy", ":kingdom_a", logent_policy_ruler_breaks_truce),
  28642. (try_end),
  28643. ##diplomacy begin
  28644. (else_try),
  28645. (assign, ":war_event", logent_faction_declares_war_to_fulfil_pact),
  28646. (call_script, "script_faction_follows_controversial_policy", ":kingdom_a", logent_policy_ruler_declares_war_with_justification),
  28647. (assign, ":initializing_war_peace_cond", 1),
  28648. (try_end),
  28649. ##diplomacy end
  28650.  
  28651. (store_relation, ":relation", ":kingdom_a", ":kingdom_b"),
  28652. (val_min, ":relation", -10),
  28653. (val_add, ":relation", -30),
  28654. (set_relation, ":kingdom_a", ":kingdom_b", ":relation"),
  28655.  
  28656. (try_begin),
  28657. (eq, "$players_kingdom", ":kingdom_a"),
  28658. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_b"),
  28659. (val_min, ":relation", -30),
  28660. (call_script, "script_set_player_relation_with_faction", ":kingdom_b", ":relation"),
  28661. (else_try),
  28662. (eq, "$players_kingdom", ":kingdom_b"),
  28663. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_a"),
  28664. (val_min, ":relation", -30),
  28665. (call_script, "script_set_player_relation_with_faction", ":kingdom_a", ":relation"),
  28666. (try_end),
  28667.  
  28668. (try_begin),
  28669. (eq, ":initializing_war_peace_cond", 1),
  28670.  
  28671. #Remove this -- this scrambles who declares war on whom
  28672. # (try_begin),
  28673. # (store_random_in_range, ":random_no", 0, 2),
  28674. # (this_or_next|eq, ":kingdom_a", "fac_player_supporters_faction"),
  28675. # (eq, ":random_no", 0),
  28676. # (assign, ":local_temp", ":kingdom_a"),
  28677. # (assign, ":kingdom_a", ":kingdom_b"),
  28678. # (assign, ":kingdom_b", ":local_temp"),
  28679. #(try_end),
  28680.  
  28681. (str_store_faction_name_link, s1, ":kingdom_a"),
  28682. #SB : don't colorize message, if it's relevant script_set_player_relation_with_faction calls will show it
  28683. # (faction_get_color, ":color", ":kingdom_a"),
  28684. (str_store_faction_name_link, s2, ":kingdom_b"),
  28685. (display_log_message, "@{s1} has declared war against {s2}.", message_alert),
  28686.  
  28687. (store_current_hours, ":hours"),
  28688. (faction_set_slot, ":kingdom_a", slot_faction_ai_last_decisive_event, ":hours"),
  28689. (faction_set_slot, ":kingdom_b", slot_faction_ai_last_decisive_event, ":hours"),
  28690.  
  28691. #set provocation and truce days
  28692. (store_add, ":truce_slot", ":kingdom_b", slot_faction_truce_days_with_factions_begin),
  28693. (store_add, ":provocation_slot", ":kingdom_b", slot_faction_provocation_days_with_factions_begin),
  28694. (val_sub, ":truce_slot", kingdoms_begin),
  28695. (val_sub, ":provocation_slot", kingdoms_begin),
  28696. (faction_set_slot, ":kingdom_a", ":truce_slot", 0),
  28697. (faction_set_slot, ":kingdom_a", ":provocation_slot", 0),
  28698.  
  28699. (store_add, ":truce_slot", ":kingdom_a", slot_faction_truce_days_with_factions_begin),
  28700. (store_add, ":provocation_slot", ":kingdom_a", slot_faction_provocation_days_with_factions_begin),
  28701. (val_sub, ":truce_slot", kingdoms_begin),
  28702. (val_sub, ":provocation_slot", kingdoms_begin),
  28703. (faction_set_slot, ":kingdom_b", ":truce_slot", 0),
  28704. (faction_set_slot, ":kingdom_b", ":provocation_slot", 0),
  28705.  
  28706. (call_script, "script_add_notification_menu", "mnu_notification_war_declared", ":kingdom_a", ":kingdom_b"),
  28707.  
  28708. (call_script, "script_update_faction_notes", ":kingdom_a"),
  28709. (call_script, "script_update_faction_notes", ":kingdom_b"),
  28710. (assign, "$g_recalculate_ais", 1),
  28711. (try_end),
  28712.  
  28713. (try_begin),
  28714. (check_quest_active, "qst_cause_provocation"),
  28715. (neg|check_quest_succeeded, "qst_cause_provocation"),
  28716. (this_or_next|eq, "$players_kingdom", ":kingdom_a"),
  28717. (eq, "$players_kingdom", ":kingdom_b"),
  28718. (call_script, "script_abort_quest", "qst_cause_provocation", 0),
  28719. (try_end),
  28720. ##diplomacy begin
  28721. #check for defensive
  28722. (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
  28723. (neq, ":cur_kingdom", ":kingdom_a"),
  28724. (neq, ":cur_kingdom", ":kingdom_b"),
  28725.  
  28726. (store_relation, ":cur_relation", ":cur_kingdom", ":kingdom_a"),
  28727. (ge, ":cur_relation", 0), #AT PEACE
  28728.  
  28729. (store_add, ":truce_slot", ":kingdom_b", slot_faction_truce_days_with_factions_begin),
  28730. (val_sub, ":truce_slot", kingdoms_begin),
  28731. (faction_get_slot, ":truce_days", ":cur_kingdom", ":truce_slot"),
  28732. ##nested diplomacy start+ replace "40" with a named constant
  28733. #(gt, ":truce_days", 40),
  28734. (gt, ":truce_days", dplmc_treaty_defense_days_expire),
  28735. ##nested diplomacy end+
  28736. (try_begin),
  28737. (lt, ":initializing_war_peace_cond", 2), #only if war was not caused by defensive or alliance pact
  28738. (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":kingdom_a", 2),
  28739. (try_end),
  28740. (try_end),
  28741.  
  28742. #check for alliance
  28743. (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
  28744. (neq, ":cur_kingdom", ":kingdom_a"),
  28745. (neq, ":cur_kingdom", ":kingdom_b"),
  28746.  
  28747. (store_relation, ":cur_relation", ":cur_kingdom", ":kingdom_b"),
  28748. (ge, ":cur_relation", 0), #AT PEACE
  28749.  
  28750. (store_add, ":truce_slot", ":kingdom_a", slot_faction_truce_days_with_factions_begin),
  28751. (val_sub, ":truce_slot", kingdoms_begin),
  28752. (faction_get_slot, ":truce_days", ":cur_kingdom", ":truce_slot"),
  28753. ##nested diplomacy start+ replace "60" with a named constant
  28754. #(gt, ":truce_days", 60),
  28755. (gt, ":truce_days", dplmc_treaty_alliance_days_expire),
  28756. ##nested diplomacy end+
  28757. (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":kingdom_b", 3),
  28758. (try_end),
  28759. ##diplomacy end
  28760. ]),
  28761.  
  28762.  
  28763. #script_diplomacy_party_attacks_neutral
  28764. ("diplomacy_party_attacks_neutral", #called from game_menus (plundering a village, raiding a village), from dialogs: surprise attacking a neutral lord, any attack on caravan or villagers
  28765. #Has no effect if factions are already at war
  28766. [
  28767. (store_script_param, ":attacker_party", 1),
  28768. (store_script_param, ":defender_party", 2),
  28769.  
  28770. (store_faction_of_party, ":attacker_faction", ":attacker_party"),
  28771. (store_faction_of_party, ":defender_faction", ":defender_party"),
  28772.  
  28773. (party_stack_get_troop_id, ":attacker_leader", ":attacker_party", 0),
  28774.  
  28775. (try_begin),
  28776. (eq, ":attacker_party", "p_main_party"),
  28777. (neq, ":attacker_faction", "fac_player_supporters_faction"),
  28778. (assign, ":attacker_faction", "$players_kingdom"),
  28779. (else_try),
  28780. (eq, ":attacker_party", "p_main_party"),
  28781. (eq, ":attacker_faction", "fac_player_supporters_faction"),
  28782. (try_end),
  28783.  
  28784. (try_begin),
  28785. (eq, ":attacker_party", "p_main_party"),
  28786. (store_relation, ":relation", ":attacker_faction", ":defender_faction"),
  28787. (ge, ":relation", 0),
  28788. (call_script, "script_change_player_honor", -2),
  28789. (try_end),
  28790.  
  28791.  
  28792. (try_begin),
  28793. (check_quest_active, "qst_cause_provocation"),
  28794. (quest_slot_eq, "qst_cause_provocation", slot_quest_target_faction, ":defender_faction"),
  28795. (quest_get_slot, ":giver_troop", "qst_cause_provocation", slot_quest_giver_troop),
  28796. (store_faction_of_troop, ":attacker_faction", ":giver_troop"),
  28797. (call_script, "script_succeed_quest", "qst_cause_provocation"),
  28798. (try_end),
  28799.  
  28800. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":attacker_faction", ":defender_faction"),
  28801. (assign, ":diplomatic_status", reg0),
  28802.  
  28803. (try_begin),
  28804. (eq, ":attacker_faction", "fac_player_supporters_faction"),
  28805. (neg|faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_active),
  28806. #player faction inactive, no effect
  28807. (else_try),
  28808. (eq, ":diplomatic_status", -2),
  28809. #war, no effect
  28810. (else_try),
  28811.  
  28812. (eq, ":attacker_faction", "fac_player_supporters_faction"),
  28813. (faction_slot_eq, ":attacker_faction", slot_faction_leader, "trp_player"),
  28814. (call_script, "script_faction_follows_controversial_policy", "fac_player_supporters_faction",logent_policy_ruler_attacks_without_provocation),
  28815. (else_try),
  28816. (eq, ":diplomatic_status", 1),
  28817. #truce
  28818. (party_stack_get_troop_id, ":defender_party_leader", ":defender_party", 0),
  28819. (try_begin),
  28820. ##diplomacy start+ add support for promoted kingdom ladies
  28821. #(i.e. verify not a promoted kingdom lady, since they exist)
  28822. (this_or_next|neg|is_between, ":defender_party_leader", kingdom_ladies_begin, kingdom_ladies_end),
  28823. (neg|troop_slot_eq, ":defender_party_leader", slot_troop_occupation, slto_kingdom_hero),
  28824. ##diplomacy end+
  28825. (neg|is_between, ":defender_party_leader", active_npcs_begin, active_npcs_end),
  28826. (store_faction_of_party, ":defender_party_faction", ":defender_party"),
  28827. (faction_get_slot, ":defender_party_leader", ":defender_party_faction", slot_faction_leader),
  28828. (try_end),
  28829.  
  28830. (call_script, "script_add_log_entry", logent_border_incident_troop_breaks_truce, ":attacker_leader", -1, ":defender_party_leader", ":attacker_faction"),
  28831. (else_try),
  28832. #truce
  28833. (call_script, "script_add_log_entry", logent_border_incident_troop_attacks_neutral, ":attacker_leader", -1, ":defender_party_leader", ":attacker_faction"),
  28834. (try_end),
  28835.  
  28836. (try_begin),
  28837. (is_between, ":defender_party", villages_begin, villages_end),
  28838. (call_script, "script_add_log_entry", logent_village_raided, ":attacker_leader", ":defender_party", -1, ":defender_faction"),
  28839. #SB : add quest cancellation when raiding villages
  28840. (try_begin),
  28841. (eq, ":attacker_party", "p_main_party"),
  28842. (party_get_slot, ":elder", ":defender_party", slot_town_elder),
  28843. (gt, ":elder", 0),
  28844. (try_for_range, ":quest_no", village_elder_quests_begin, village_elder_quests_end),
  28845. (quest_slot_eq, ":quest_no", slot_quest_giver_troop, ":elder"),
  28846. (call_script, "script_abort_quest", ":quest_no", 1),
  28847. (try_end),
  28848. (try_end),
  28849. (else_try),
  28850. (party_get_template_id, ":template", ":defender_party"),
  28851. # (neq, ":template", "pt_kingdom_hero_party"),
  28852. (eq, ":template", "pt_kingdom_caravan_party"), #SB: fix this to specifically apply to caravans
  28853. (try_begin),
  28854. (ge, "$cheat_mode", 1),
  28855. (str_store_faction_name, s5, ":defender_faction"),
  28856. (display_message, "@{!}Debug - {s5} caravan attacked"),
  28857. (try_end),
  28858.  
  28859. (call_script, "script_add_log_entry", logent_caravan_accosted, ":attacker_leader", -1, -1, ":defender_faction"),
  28860. (try_end),
  28861.  
  28862. (store_add, ":slot_truce_days", ":attacker_faction", slot_faction_provocation_days_with_factions_begin),
  28863. (val_sub, ":slot_truce_days", kingdoms_begin),
  28864. (faction_set_slot, ":defender_faction", ":slot_truce_days", 0),
  28865.  
  28866. (store_add, ":slot_provocation_days", ":attacker_faction", slot_faction_provocation_days_with_factions_begin),
  28867. (val_sub, ":slot_provocation_days", kingdoms_begin),
  28868. (try_begin),
  28869. (neq, ":diplomatic_status", -2),
  28870. (faction_slot_eq, ":defender_faction", ":slot_provocation_days", 0),
  28871. (faction_set_slot, ":defender_faction", ":slot_provocation_days", 30),
  28872. (try_end),
  28873. ]),
  28874.  
  28875. # script_party_calculate_and_set_nearby_friend_enemy_follower_strengths
  28876. # Input: party_no
  28877. # Output: none
  28878. ("party_calculate_and_set_nearby_friend_enemy_follower_strengths",
  28879. [
  28880. (store_script_param, ":party_no", 1),
  28881. (assign, ":follower_strength", 0),
  28882. (assign, ":friend_strength", 0),
  28883. (assign, ":enemy_strength", 0),
  28884. (store_faction_of_party, ":party_faction", ":party_no"),
  28885. ##diplomacy start+ add support for promoted kingdom ladies
  28886. (store_add, ":end_cond", heroes_end, 1),#<- changed active_npcs to heroes
  28887. (try_for_range, ":iteration", heroes_begin, ":end_cond"),#<- changed active_npcs to heroes
  28888. (try_begin),
  28889. (eq, ":iteration", heroes_end),#<- changed active_npcs to heroes
  28890. (assign, ":cur_troop", "trp_player"),
  28891. (else_try),
  28892. (assign, ":cur_troop", ":iteration"),
  28893. (try_end),
  28894. ##diplomacy end+
  28895.  
  28896. (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  28897. (troop_get_slot, ":cur_troop_party", ":cur_troop", slot_troop_leaded_party),
  28898. (ge, ":cur_troop_party", 0),
  28899. (party_is_active, ":cur_troop_party"),
  28900.  
  28901.  
  28902. #I moved these lines here from (*1) to faster process, ozan.
  28903. (store_troop_faction, ":army_faction", ":cur_troop"),
  28904. (store_relation, ":relation", ":army_faction", ":party_faction"),
  28905. (this_or_next|neq, ":relation", 0),
  28906. (eq, ":army_faction", ":party_faction"),
  28907. #ozan end
  28908.  
  28909.  
  28910. (neq, ":party_no", ":cur_troop_party"),
  28911. (party_get_slot, ":str", ":cur_troop_party", slot_party_cached_strength),
  28912. (try_begin),
  28913. (neg|is_between, ":party_no", centers_begin, centers_end),
  28914. (party_slot_eq, ":cur_troop_party", slot_party_ai_state, spai_accompanying_army),
  28915. (party_get_slot, ":commander_party", ":cur_troop_party", slot_party_ai_object),
  28916. (eq, ":commander_party", ":party_no"),
  28917. (val_add, ":follower_strength", ":str"),
  28918. (else_try),
  28919. (store_distance_to_party_from_party, ":distance", ":cur_troop_party", ":party_no"),
  28920. (lt, ":distance", 20),
  28921.  
  28922. #(*1)
  28923.  
  28924. (try_begin),
  28925. (lt, ":distance", 5),
  28926. (assign, ":str_divided", ":str"),
  28927. (else_try),
  28928. (lt, ":distance", 10),
  28929. (store_div, ":str_divided", ":str", 2),
  28930. (else_try),
  28931. (lt, ":distance", 15),
  28932. (store_div, ":str_divided", ":str", 4),
  28933. (else_try),
  28934. (store_div, ":str_divided", ":str", 8),
  28935. (try_end),
  28936.  
  28937. (try_begin),
  28938. (this_or_next|eq, ":army_faction", ":party_faction"),
  28939. (gt, ":relation", 0),
  28940. (val_add, ":friend_strength", ":str_divided"),
  28941. (else_try),
  28942. (lt, ":relation", 0),
  28943. (val_add, ":enemy_strength", ":str_divided"),
  28944. (try_end),
  28945. (try_end),
  28946. (try_end),
  28947.  
  28948. (party_set_slot, ":party_no", slot_party_follower_strength, ":follower_strength"),
  28949. (party_set_slot, ":party_no", slot_party_nearby_friend_strength, ":friend_strength"),
  28950. (party_set_slot, ":party_no", slot_party_nearby_enemy_strength, ":enemy_strength"),
  28951. ]),
  28952.  
  28953. # script_init_ai_calculation
  28954. # Input: none
  28955. # Output: none
  28956. ("init_ai_calculation",
  28957. [
  28958. ##diplomacy start+
  28959. #(assign, ":real_party_strength"),
  28960. ##If terrain advantage is enabled, use it to calculate troop strengths.
  28961. (try_begin),
  28962. (eq, "$g_dplmc_terrain_advantage", DPLMC_TERRAIN_ADVANTAGE_ENABLE),
  28963.  
  28964. #First update all lords
  28965. (try_for_range, ":cur_troop", heroes_begin, heroes_end),
  28966. (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  28967. (troop_get_slot, ":cur_party", ":cur_troop", slot_troop_leaded_party),
  28968. (gt, ":cur_party", 0),
  28969. (party_is_active, ":cur_party"),
  28970.  
  28971. (party_get_current_terrain, ":terrain_code", ":cur_party"),
  28972.  
  28973. (party_get_attached_to, ":attachment", ":cur_party"),
  28974. (try_begin),
  28975. (ge, ":attachment", 0),
  28976. (is_between, ":attachment", centers_begin, centers_end),
  28977. (assign, ":terrain_code", dplmc_terrain_code_siege),#siege constant defined in header_terrain_types.py
  28978. (try_end),
  28979.  
  28980. (call_script, "script_dplmc_party_calculate_strength_in_terrain", ":cur_party", ":terrain_code", 0, 1), #will update slot_party_cached_strength
  28981. (try_end),
  28982.  
  28983. #Then update player
  28984. (party_get_current_terrain, ":terrain_code", "p_main_party"),
  28985.  
  28986. (party_get_attached_to, ":attachment", "p_main_party"),
  28987. (try_begin),
  28988. (ge, ":attachment", 0),
  28989. (is_between, ":attachment", centers_begin, centers_end),
  28990. (assign, ":terrain_code", dplmc_terrain_code_siege),#siege constant defined in header_terrain_types.py
  28991. (try_end),
  28992.  
  28993. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_main_party", ":terrain_code", 0, 1), #will update slot_party_cached_strength
  28994.  
  28995. (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
  28996. #Update with walled center alterations
  28997. (call_script, "script_dplmc_party_calculate_strength_in_terrain", ":cur_center", -2, 0, 1),
  28998. (try_end),
  28999. (else_try),
  29000. #The old behavior, unchanged:
  29001. (try_for_range, ":cur_troop", heroes_begin, heroes_end),
  29002. (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  29003. (troop_get_slot, ":cur_party", ":cur_troop", slot_troop_leaded_party),
  29004. (party_is_active, ":cur_party"),
  29005. (call_script, "script_party_calculate_strength", ":cur_party", 0), #will update slot_party_cached_strength
  29006. (try_end),
  29007. (call_script, "script_party_calculate_strength", "p_main_party", 0), #will update slot_party_cached_strength
  29008. (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
  29009. (call_script, "script_party_calculate_strength", ":cur_center", 0), #will update slot_party_cached_strength
  29010. (try_end),
  29011. (try_end),
  29012. ##diplomacy end+
  29013.  
  29014. (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
  29015. (call_script, "script_party_calculate_and_set_nearby_friend_enemy_follower_strengths", ":cur_center"),
  29016. (try_end),
  29017.  
  29018. (try_for_range, ":cur_troop", heroes_begin, heroes_end),
  29019. (troop_get_slot, ":cur_troop_party", ":cur_troop", slot_troop_leaded_party),
  29020. (gt, ":cur_troop_party", 0),
  29021. (party_is_active, ":cur_troop_party"),
  29022. (call_script, "script_party_calculate_and_set_nearby_friend_enemy_follower_strengths", ":cur_troop_party"),
  29023. (try_end),
  29024. (call_script, "script_party_calculate_and_set_nearby_friend_enemy_follower_strengths", "p_main_party"),
  29025. ]),
  29026.  
  29027.  
  29028. # script_recalculate_ais
  29029. # Input: none
  29030. # Output: none
  29031.  
  29032. #When a lord changes factions
  29033. #When a center changes factions
  29034. #When a center is captured
  29035. #When a marshal is defeated
  29036. #Every 23 hours
  29037. ("recalculate_ais",
  29038. [
  29039. (call_script, "script_init_ai_calculation"),
  29040.  
  29041. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  29042. (assign, reg8, ":faction_no"),
  29043. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  29044. #(neg|faction_slot_eq, ":faction_no", slot_faction_marshall, "trp_player"),
  29045. (call_script, "script_decide_faction_ai", ":faction_no"),
  29046. (try_end),
  29047.  
  29048. ##diplomacy start+ add support for promoted kingdom ladies
  29049. (try_for_range, ":troop_no", heroes_begin, heroes_end),#<- change active_npcs to heroes
  29050. ##diplomacy end+
  29051. (store_troop_faction, ":faction_no", ":troop_no"),
  29052. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  29053. (call_script, "script_calculate_troop_ai", ":troop_no"),
  29054. (try_end),
  29055. ]),
  29056.  
  29057. # script_calculate_troop_ai
  29058. # Input: troop_no
  29059. # Output: none
  29060. #Now called directly from scripts
  29061. ("calculate_troop_ai",
  29062. [
  29063. (store_script_param, ":troop_no", 1),
  29064.  
  29065. (try_begin),
  29066. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  29067. (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  29068. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  29069. (gt, ":party_no", 0),
  29070. (party_is_active, ":party_no"),
  29071. ##diplomacy start+
  29072. #Testing notifications
  29073. (party_get_slot, ":old_ai_state", ":party_no", slot_party_ai_state),
  29074. #(party_get_slot, ":old_ai_object", ":party_no", slot_party_ai_object),
  29075. ##diplomacy end+
  29076. (call_script, "script_npc_decision_checklist_party_ai", ":troop_no"), #This handles AI for both marshal and other parties
  29077. (call_script, "script_party_set_ai_state", ":party_no", reg0, reg1),
  29078. ##diplomacy start+
  29079. #Notify the player of changes to spouse and affiliates
  29080. (party_get_slot, ":new_ai_state", ":party_no", slot_party_ai_state),
  29081. (party_get_slot, ":new_ai_object", ":party_no", slot_party_ai_object),
  29082.  
  29083. ##(this_or_next|neq, ":old_ai_object", ":new_ai_object",
  29084. (neq, ":old_ai_state", ":new_ai_state"),
  29085. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  29086. #(assign, reg0, 0),
  29087. #(try_begin),
  29088. # (this_or_next|troop_slot_eq, ":troop_no", slot_troop_spouse, "trp_player"),
  29089. # (troop_slot_eq, "trp_player", slot_troop_spouse, ":troop_no"),
  29090. # (assign, reg0, 1),
  29091. ##(else_try),
  29092. ## (store_faction_of_troop, ":troop_faction", ":troop_no"),
  29093. ## (is_between,
  29094. ##(else_try),
  29095. # (call_script, "script_dplmc_is_affiliated_family_member", ":troop_no"),
  29096. #(try_end),
  29097. (call_script, "script_dplmc_store_troop_is_eligible_for_affiliate_messages", ":troop_no"),
  29098. (gt, reg0, 0),
  29099.  
  29100.  
  29101. #Some of these have non-obvious secondary uses.
  29102. #xxx TODO: Later, I should go and verify all of them.
  29103. (str_store_troop_name, s0, ":troop_no"),
  29104.  
  29105. (try_begin),
  29106. (eq, ":new_ai_state", spai_besieging_center),
  29107. (is_between, ":new_ai_object", centers_begin, centers_end),
  29108. (str_store_party_name, s1, ":new_ai_object"),
  29109. (display_message, "@{s0} is laying siege to {s1}."),
  29110. (else_try),
  29111. (eq, ":new_ai_state", spai_patrolling_around_center),
  29112. (is_between, ":new_ai_object", centers_begin, centers_end),
  29113. (str_store_party_name, s1, ":new_ai_object"),
  29114. (display_message, "@{s0} is patrolling around {s1}."),
  29115. (else_try),
  29116. (eq, ":new_ai_state", spai_raiding_around_center),
  29117. (is_between, ":new_ai_object", centers_begin, centers_end),
  29118. (str_store_party_name, s1, ":new_ai_object"),
  29119. (display_message, "@{s0} is raiding around {s1}."),
  29120. (else_try),
  29121. (eq, ":new_ai_state", spai_engaging_army),
  29122. (gt, ":new_ai_object", -1),
  29123. (party_is_active, ":new_ai_object"),
  29124. (str_store_party_name, s1, ":new_ai_object"),
  29125. (display_message, "@{s0} is engaging {s1}."),
  29126. (else_try),
  29127. (eq, ":new_ai_state", spai_accompanying_army),
  29128. (gt, ":new_ai_object", -1),
  29129. (party_is_active, ":new_ai_object"),
  29130. (str_store_party_name, s1, ":new_ai_object"),
  29131. (display_message, "@{s0} is accompanying {s1}."),
  29132. (else_try),
  29133. (eq, ":new_ai_state", spai_screening_army),
  29134. (gt, ":new_ai_object", -1),
  29135. (party_is_active, ":new_ai_object"),
  29136. (str_store_party_name, s1, ":new_ai_object"),
  29137. (display_message, "@{s0} is screening the advance of {s1}."),
  29138. (else_try),
  29139. (eq, ":new_ai_state", spai_trading_with_town),
  29140. (is_between, ":new_ai_object", centers_begin, centers_end),
  29141. (str_store_party_name, s1, ":new_ai_object"),
  29142. (display_message, "@{s0} is trading with {s1}."),
  29143. (else_try),
  29144. (eq, ":new_ai_state", spai_retreating_to_center),
  29145. (is_between, ":new_ai_object", centers_begin, centers_end),
  29146. (str_store_party_name, s1, ":new_ai_object"),
  29147. (display_message, "@{s0} is retreating to {s1}."),
  29148. (else_try),
  29149. (eq, ":new_ai_state", spai_visiting_village),
  29150. (is_between, ":new_ai_object", centers_begin, centers_end),
  29151. (str_store_party_name, s1, ":new_ai_object"),
  29152. (display_message, "@{s0} is visiting {s1}."),
  29153. (try_end),
  29154. #Make it obvious that something went wrong if something tries to use the registers
  29155. (str_store_string, s0, "str_ERROR_string"),
  29156. (str_store_string, s1, "str_ERROR_string"),
  29157. ##diplomacy end+
  29158. (try_end),
  29159. ]),
  29160.  
  29161. # script_diplomacy_start_peace_between_kingdoms
  29162. # Input: arg1 = kingdom_1, arg2 = kingdom_2, arg3 = initializing_war_peace_cond
  29163. # Output: none
  29164. ("diplomacy_start_peace_between_kingdoms", #sets relations between two kingdoms
  29165. [
  29166. (store_script_param, ":kingdom_a", 1),
  29167. (store_script_param, ":kingdom_b", 2),
  29168. (store_script_param, ":initializing_war_peace_cond", 3), #set to 1 if not the start of the game
  29169.  
  29170. (store_relation, ":relation", ":kingdom_a", ":kingdom_b"),
  29171. (val_max, ":relation", 0),
  29172. (set_relation, ":kingdom_a", ":kingdom_b", ":relation"),
  29173. (call_script, "script_exchange_prisoners_between_factions", ":kingdom_a", ":kingdom_b"),
  29174.  
  29175. (try_begin),
  29176. (eq, "$players_kingdom", ":kingdom_a"),
  29177. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_b"),
  29178. (val_max, ":relation", 0),
  29179. (call_script, "script_set_player_relation_with_faction", ":kingdom_b", ":relation"),
  29180. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", "fac_player_supporters_faction"), #event cancels certain quests
  29181. (else_try),
  29182. (eq, "$players_kingdom", ":kingdom_b"),
  29183. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_a"),
  29184. (val_max, ":relation", 0),
  29185. (call_script, "script_set_player_relation_with_faction", ":kingdom_a", ":relation"),
  29186. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", "fac_player_supporters_faction"), #event cancels certain quests
  29187. (try_end),
  29188.  
  29189. (try_for_range, ":cur_center", centers_begin, centers_end),
  29190. (store_faction_of_party, ":faction_no", ":cur_center"),
  29191. (this_or_next|eq, ":faction_no", ":kingdom_a"),
  29192. (eq, ":faction_no", ":kingdom_b"),
  29193. (party_get_slot, ":besieger_party", ":cur_center", slot_center_is_besieged_by),
  29194. (ge, ":besieger_party", 0), #town is under siege
  29195. (party_is_active, ":besieger_party"),
  29196. (store_faction_of_party, ":besieger_party_faction_no", ":besieger_party"),
  29197. (this_or_next|eq, ":besieger_party_faction_no", ":kingdom_a"),
  29198. (eq, ":besieger_party_faction_no", ":kingdom_b"),
  29199. (call_script, "script_lift_siege", ":cur_center", 0),
  29200. (try_end),
  29201.  
  29202. (try_begin),
  29203. (this_or_next|eq, "$players_kingdom", ":kingdom_a"),
  29204. (eq, "$players_kingdom", ":kingdom_b"),
  29205.  
  29206. (ge, "$g_player_besiege_town", 0),
  29207. (party_is_active, "$g_player_besiege_town"),
  29208.  
  29209. (store_faction_of_party, ":besieged_center_faction_no", "$g_player_besiege_town"),
  29210.  
  29211. (this_or_next|eq, ":besieged_center_faction_no", ":kingdom_a"),
  29212. (eq, ":besieged_center_faction_no", ":kingdom_b"),
  29213.  
  29214. (call_script, "script_lift_siege", "$g_player_besiege_town", 0),
  29215. (assign, "$g_player_besiege_town", -1),
  29216. (try_end),
  29217.  
  29218. (try_begin),
  29219. (eq, ":initializing_war_peace_cond", 1),
  29220. (str_store_faction_name_link, s1, ":kingdom_a"),
  29221. (str_store_faction_name_link, s2, ":kingdom_b"),
  29222. (display_log_message, "@{s1} and {s2} have made peace with each other.", message_alert),
  29223. (call_script, "script_add_notification_menu", "mnu_notification_peace_declared", ":kingdom_a", ":kingdom_b"), #stability penalty for early peace is in the menu
  29224. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", ":kingdom_b"), #cancels quests
  29225. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", ":kingdom_a"), #cancels quests
  29226. (assign, "$g_recalculate_ais", 1),
  29227. (try_end),
  29228.  
  29229. (try_begin), #add truce
  29230. (store_add, ":truce_slot", ":kingdom_a", slot_faction_truce_days_with_factions_begin),
  29231. (val_sub, ":truce_slot", kingdoms_begin),
  29232. ##diplomacy begin
  29233. #(faction_set_slot, ":kingdom_b", ":truce_slot", 40),
  29234. ##nested diplomacy start+ replace "20" with constant for truce length
  29235. # (faction_set_slot, ":kingdom_b", ":truce_slot", 20),
  29236. (faction_set_slot, ":kingdom_b", ":truce_slot", dplmc_treaty_truce_days_initial),
  29237. ##nested diplomacy end+
  29238. ##diplomacy end
  29239. (store_add, ":truce_slot", ":kingdom_b", slot_faction_truce_days_with_factions_begin),
  29240. (val_sub, ":truce_slot", kingdoms_begin),
  29241. ##diplomacy begin
  29242. #(faction_set_slot, ":kingdom_a", ":truce_slot", 40),
  29243. ##nested diplomacy start+ replace "20" with constant for truce length
  29244. #(faction_set_slot, ":kingdom_a", ":truce_slot", 20),
  29245. (faction_set_slot, ":kingdom_a", ":truce_slot", dplmc_treaty_truce_days_initial),
  29246. ##nested diplomacy end+
  29247. ##diplomacy end
  29248. (store_add, ":slot_war_damage_inflicted_on_b", ":kingdom_b", slot_faction_war_damage_inflicted_on_factions_begin),
  29249. (val_sub, ":slot_war_damage_inflicted_on_b", kingdoms_begin),
  29250. #(faction_get_slot, ":damage_inflicted_by_a", ":kingdom_a", ":slot_war_damage_inflicted_on_b"),
  29251. (faction_set_slot, ":kingdom_a", ":slot_war_damage_inflicted_on_b", 0),
  29252. (store_add, ":slot_war_damage_inflicted_on_a", ":kingdom_a", slot_faction_war_damage_inflicted_on_factions_begin),
  29253. (val_sub, ":slot_war_damage_inflicted_on_a", kingdoms_begin),
  29254. #(faction_get_slot, ":damage_inflicted_by_b", ":kingdom_b", ":slot_war_damage_inflicted_on_a"),
  29255. (faction_set_slot, ":kingdom_b", ":slot_war_damage_inflicted_on_a", 0),
  29256. (try_end),
  29257. ]),
  29258.  
  29259.  
  29260.  
  29261. ("event_kingdom_make_peace_with_kingdom",
  29262. [
  29263. (store_script_param_1, ":source_kingdom"),
  29264. (store_script_param_2, ":target_kingdom"),
  29265. (try_begin),
  29266. (check_quest_active, "qst_capture_prisoners"),
  29267. (try_begin),
  29268. (eq, "$players_kingdom", ":source_kingdom"),
  29269. (quest_slot_eq, "qst_capture_prisoners", slot_quest_target_faction, ":target_kingdom"),
  29270. (call_script, "script_cancel_quest", "qst_capture_prisoners"),
  29271. (else_try),
  29272. (eq, "$players_kingdom", ":target_kingdom"),
  29273. (quest_slot_eq, "qst_capture_prisoners", slot_quest_target_faction, ":source_kingdom"),
  29274. (call_script, "script_cancel_quest", "qst_capture_prisoners"),
  29275. (try_end),
  29276. (try_end),
  29277.  
  29278. (try_begin),
  29279. (check_quest_active, "qst_capture_enemy_hero"),
  29280. (try_begin),
  29281. (eq, "$players_kingdom", ":source_kingdom"),
  29282. (quest_slot_eq, "qst_capture_enemy_hero", slot_quest_target_faction, ":target_kingdom"),
  29283. (call_script, "script_cancel_quest", "qst_capture_enemy_hero"),
  29284. (else_try),
  29285. (eq, "$players_kingdom", ":target_kingdom"),
  29286. (quest_slot_eq, "qst_capture_enemy_hero", slot_quest_target_faction, ":source_kingdom"),
  29287. (call_script, "script_cancel_quest", "qst_capture_enemy_hero"),
  29288. (try_end),
  29289. (try_end),
  29290.  
  29291.  
  29292.  
  29293. (try_begin),
  29294. (check_quest_active, "qst_persuade_lords_to_make_peace"),
  29295. (quest_get_slot, ":lord_1", "qst_persuade_lords_to_make_peace", slot_quest_target_troop),
  29296. (quest_get_slot, ":lord_2", "qst_persuade_lords_to_make_peace", slot_quest_object_troop),
  29297.  
  29298. (try_begin),
  29299. (lt, ":lord_1", 0),
  29300. (val_mul, ":lord_1", -1),
  29301. (try_end),
  29302. (try_begin),
  29303. (lt, ":lord_2", 0),
  29304. (val_mul, ":lord_2", -1),
  29305. (try_end),
  29306.  
  29307.  
  29308. (store_faction_of_troop, ":lord_1_faction", ":lord_1"),
  29309. (store_faction_of_troop, ":lord_2_faction", ":lord_2"),
  29310.  
  29311. (this_or_next|eq, ":lord_1_faction", ":source_kingdom"),
  29312. (eq, ":lord_2_faction", ":source_kingdom"),
  29313.  
  29314. (this_or_next|eq, ":lord_1_faction", ":target_kingdom"),
  29315. (eq, ":lord_2_faction", ":target_kingdom"),
  29316.  
  29317. (call_script, "script_cancel_quest", "qst_persuade_lords_to_make_peace"),
  29318.  
  29319. (try_end),
  29320.  
  29321. #Rescue prisoners cancelled in simple_triggers
  29322.  
  29323. (try_begin),
  29324. #SB : better checking, also adds rtr for co-ruler
  29325. (this_or_next|eq, "$players_kingdom", ":source_kingdom"),
  29326. (eq, "$players_kingdom", ":target_kingdom"),
  29327. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  29328. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  29329. (call_script, "script_change_player_right_to_rule", 3),
  29330. (try_end),
  29331.  
  29332. ]),
  29333.  
  29334. # script_randomly_start_war_peace
  29335. # Input: arg1 = initializing_war_peace_cond (1 = true, 0 = false)
  29336. # Output: none
  29337.  
  29338. #Aims to introduce a slightly simpler system in which the AI kings' reasoning could be made more transparent to the player. At the start of the game, this may lead to less variation in outcomes, though
  29339. ("randomly_start_war_peace_new",
  29340. [
  29341. (store_script_param_1, ":initializing_war_peace_cond"),
  29342.  
  29343. (assign, ":players_kingdom_at_peace", 0), #if the player kingdom is at peace, then create an enmity
  29344. (try_begin),
  29345. (is_between, "$players_kingdom", "fac_kingdom_1", kingdoms_end),
  29346. (assign, ":players_kingdom_at_peace", 1),
  29347. (try_end),
  29348.  
  29349. ##diplomacy start+
  29350. #Introduce some minor variation by changing the order in which factions consider things.
  29351. ##OLD:
  29352. #(try_for_range, ":cur_kingdom", "fac_kingdom_1", kingdoms_end),
  29353. # (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
  29354. #
  29355. # (try_for_range, ":cur_kingdom_2", kingdoms_begin, kingdoms_end),
  29356. ##NEW:
  29357. (store_random_in_range, ":random_offset_1", "fac_kingdom_1", kingdoms_end),
  29358. (val_sub, ":random_offset_1", "fac_kingdom_1"),
  29359. (try_for_range, ":cur_kingdom", "fac_kingdom_1", kingdoms_end),
  29360. (val_add, ":cur_kingdom", ":random_offset_1"),
  29361. (try_begin),
  29362. (ge, ":cur_kingdom", kingdoms_end),
  29363. (val_sub, ":cur_kingdom", kingdoms_end),
  29364. (val_add, ":cur_kingdom", "fac_kingdom_1"),
  29365. (try_end),
  29366. (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
  29367. (store_random_in_range, ":random_offset_2", kingdoms_begin, kingdoms_end),
  29368. (val_sub, ":random_offset_2", kingdoms_begin),
  29369. (try_for_range, ":cur_kingdom_2", kingdoms_begin, kingdoms_end),
  29370. (val_add, ":cur_kingdom_2", ":random_offset_2"),
  29371. (try_begin),
  29372. (ge, ":cur_kingdom_2", kingdoms_end),
  29373. (val_sub, ":cur_kingdom_2", kingdoms_end),
  29374. (val_add, ":cur_kingdom_2", kingdoms_begin),
  29375. (try_end),
  29376. ##diplomacy end+
  29377. (neq, ":cur_kingdom", ":cur_kingdom_2"),
  29378. (faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),
  29379.  
  29380. (call_script, "script_npc_decision_checklist_peace_or_war", ":cur_kingdom", ":cur_kingdom_2", -1),
  29381. (assign, ":kingdom_1_to_kingdom_2", reg0),
  29382.  
  29383. (store_relation, ":cur_relation", ":cur_kingdom", ":cur_kingdom_2"),
  29384. (try_begin),
  29385. (lt, ":cur_relation", 0), #AT WAR
  29386.  
  29387. (try_begin),
  29388. (eq, ":cur_kingdom", "$players_kingdom"),
  29389. (assign, ":players_kingdom_at_peace", 0),
  29390. (try_end),
  29391.  
  29392. (ge, ":kingdom_1_to_kingdom_2", 1),
  29393.  
  29394. ##diplomacy begin
  29395. (try_begin),
  29396. (store_current_hours, ":cur_hours"),
  29397. (faction_get_slot, ":faction_ai_last_decisive_event", ":cur_kingdom", slot_faction_ai_last_decisive_event),
  29398. (store_sub, ":hours_since_last_decisive_event", ":cur_hours", ":faction_ai_last_decisive_event"),
  29399. (ge, ":hours_since_last_decisive_event", 96), #wait 4 days until you conclude peace after war
  29400. ##diplomacy end
  29401. (try_begin),
  29402. (eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
  29403.  
  29404. (store_mul, ":goodwill_level", ":kingdom_1_to_kingdom_2", 2),
  29405. (store_random_in_range, ":random", 0, 20),
  29406. (try_begin),
  29407. (lt, ":random", ":goodwill_level"),
  29408. (call_script, "script_add_notification_menu", "mnu_question_peace_offer", ":cur_kingdom", 0),
  29409. (try_end),
  29410. (else_try),
  29411. (call_script, "script_npc_decision_checklist_peace_or_war", ":cur_kingdom_2", ":cur_kingdom", -1),
  29412. (assign, ":kingdom_2_to_kingdom_1", reg0),
  29413. (ge, ":kingdom_2_to_kingdom_1", 1),
  29414.  
  29415. (store_mul, ":goodwill_level", ":kingdom_1_to_kingdom_2", ":kingdom_2_to_kingdom_1"),
  29416. (store_random_in_range, ":random", 0, 20),
  29417. (lt, ":random", ":goodwill_level"),
  29418.  
  29419. (try_begin),
  29420. (eq, "$g_include_diplo_explanation", 0),
  29421. (assign, "$g_include_diplo_explanation", ":cur_kingdom"),
  29422. (str_store_string, s57, "str_s14"),
  29423. (try_end),
  29424.  
  29425. (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
  29426. (try_end),
  29427. ##diplomacy begin
  29428. (try_end),
  29429. ##diplomacy end
  29430. (else_try),
  29431. (ge, ":cur_relation", 0), #AT PEACE
  29432.  
  29433. (call_script, "script_npc_decision_checklist_peace_or_war", ":cur_kingdom", ":cur_kingdom_2", -1),
  29434.  
  29435. #negative, leans towards war/positive, leans towards peace
  29436. (le, reg0, 0), #still no chance of war unless provocation, or at start of game
  29437.  
  29438. (assign, ":hostility", reg0),
  29439.  
  29440. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":cur_kingdom", ":cur_kingdom_2"),
  29441. (le, reg0, 0), #no truce
  29442.  
  29443. (val_add, ":hostility", reg0), #increase hostility if there is a provocation
  29444.  
  29445. (val_sub, ":hostility", 1), #greater chance at start of game
  29446. (val_add, ":hostility", ":initializing_war_peace_cond"), #this variable = 1 after the start
  29447.  
  29448. (store_mul, ":hostility_squared", ":hostility", ":hostility"),
  29449. (store_random_in_range, ":random", 0, 50),
  29450.  
  29451. ##diplomacy begin
  29452. #check for pact and lower probability if there is one
  29453. (try_for_range, ":third_kingdom", kingdoms_begin, kingdoms_end),
  29454. (neq, ":third_kingdom", ":cur_kingdom"),
  29455. (neq, ":third_kingdom", ":cur_kingdom_2"),
  29456. ##nested diplomacy start+ Faction must be active
  29457. (faction_slot_eq, ":third_kingdom", slot_faction_state, sfs_active),
  29458. ##nested diplomacy end+
  29459.  
  29460. (store_relation, ":cur_relation", ":cur_kingdom_2", ":third_kingdom"),
  29461. (ge, ":cur_relation", 0), #AT PEACE
  29462.  
  29463. (store_add, ":truce_slot", ":third_kingdom", slot_faction_truce_days_with_factions_begin),
  29464. (val_sub, ":truce_slot", kingdoms_begin),
  29465. (faction_get_slot, ":truce_days", ":cur_kingdom_2", ":truce_slot"),
  29466. ##nested diplomacy start+ replace "40" with a named constant
  29467. #(gt, ":truce_days", 40),
  29468. (gt, ":truce_days", dplmc_treaty_defense_days_expire),
  29469. ##nested diplomacy end+
  29470. (store_div, ":hostility_change", ":truce_days", 20),
  29471. (val_sub, ":hostility_squared", ":hostility_change"),
  29472. (try_end),
  29473. ##diplomacy end
  29474.  
  29475. (lt, ":random", ":hostility_squared"),
  29476.  
  29477. (try_begin),
  29478. (eq, "$g_include_diplo_explanation", 0),
  29479. (assign, "$g_include_diplo_explanation", ":cur_kingdom"),
  29480. (str_store_string, s57, "str_s14"),
  29481. (try_end),
  29482. (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
  29483.  
  29484. (try_begin), #do some war damage for
  29485. (eq, ":initializing_war_peace_cond", 0),
  29486. (store_random_in_range, ":war_damage_inflicted", 10, 120),
  29487. (store_add, ":slot_war_damage_inflicted", ":cur_kingdom", slot_faction_war_damage_inflicted_on_factions_begin),
  29488. (val_sub, ":slot_war_damage_inflicted", kingdoms_begin),
  29489. (faction_set_slot, ":cur_kingdom_2", ":slot_war_damage_inflicted", ":war_damage_inflicted"),
  29490.  
  29491. (store_add, ":slot_war_damage_inflicted", ":cur_kingdom_2", slot_faction_war_damage_inflicted_on_factions_begin),
  29492. (val_sub, ":slot_war_damage_inflicted", kingdoms_begin),
  29493. (faction_set_slot, ":cur_kingdom", ":slot_war_damage_inflicted", ":war_damage_inflicted"),
  29494. (try_end),
  29495. ##diplomacy begin
  29496. (else_try),
  29497. (ge, ":cur_relation", 0), #AT PEACE
  29498. (ge, ":kingdom_1_to_kingdom_2", 1),
  29499.  
  29500. #(assign, ":barrier", 2),
  29501. (store_add, ":faction1_to_faction2_slot", ":cur_kingdom_2", dplmc_slot_faction_attitude_begin),
  29502. (party_get_slot, ":barrier",":cur_kingdom", ":faction1_to_faction2_slot"),
  29503.  
  29504. (try_for_range, ":third_kingdom", kingdoms_begin, kingdoms_end),
  29505. (neq, ":third_kingdom", ":cur_kingdom"),
  29506. (neq, ":third_kingdom", ":cur_kingdom_2"),
  29507.  
  29508. (store_add, ":slot_truce_days", ":cur_kingdom", slot_faction_truce_days_with_factions_begin),
  29509. (val_sub, ":slot_truce_days", kingdoms_begin),
  29510. (faction_get_slot, ":truce_days", ":third_kingdom", ":slot_truce_days"),
  29511. ##nested diplomacy start+ change to use constants
  29512. #(gt, ":truce_days", 10),
  29513. (gt, ":truce_days", dplmc_treaty_truce_days_half_done),
  29514. ##nested diplomacy end+
  29515. (val_sub, ":barrier", 1),
  29516.  
  29517. (try_begin), #debug
  29518. (eq, "$cheat_mode", 1),
  29519. (str_store_faction_name, s5, ":cur_kingdom"),
  29520. (str_store_faction_name, s6, ":third_kingdom"),
  29521. (str_store_faction_name, s7, ":cur_kingdom_2"),
  29522. (display_message, "@{!}DEBUG: {s5} has truce with {s6}. Pact with {s7} is harder!"),
  29523. (try_end),
  29524.  
  29525. (try_end),
  29526.  
  29527. (val_max, ":barrier", 0),
  29528. (store_random_in_range, ":random", 0, 130),
  29529. (le, ":random", ":barrier"),
  29530.  
  29531. (store_add, ":slot_truce_days", ":cur_kingdom", slot_faction_truce_days_with_factions_begin),
  29532. (val_sub, ":slot_truce_days", kingdoms_begin),
  29533. (faction_get_slot, ":truce_days", ":cur_kingdom_2", ":slot_truce_days"),
  29534.  
  29535. (store_random_in_range, ":random", 0, 3),
  29536. (assign, ":continue", 0),
  29537. (try_begin),
  29538. ##nested diplomacy start+ change to use constants
  29539. #(is_between, ":truce_days", 0, 50),
  29540. (is_between, ":truce_days", 0, dplmc_treaty_defense_days_half_done),#50 = halfway from a defensive alliance to a trade treaty
  29541. ##nested diplomacy end+
  29542. (ge, ":cur_relation", 20),
  29543. (try_begin),
  29544. (le, ":random", 0), #1/3 for alliance, defensive
  29545. (assign, ":continue", 1),
  29546. (try_end),
  29547. (else_try),
  29548. ##nested diplomacy start+ change to use constants
  29549. #(is_between, ":truce_days", 0, 10),
  29550. (is_between, ":truce_days", 0, dplmc_treaty_truce_days_half_done),#10 = halfway done with a truce
  29551. ##nested diplomacy end+
  29552. (ge, ":cur_relation", 10),
  29553. (try_begin),
  29554. (le, ":random", 1), #2/3 # for trade
  29555. (assign, ":continue", 1),
  29556. (try_end),
  29557. (else_try),
  29558. (assign, ":continue", 1), # for non-aggression
  29559. (try_end),
  29560. (eq, ":continue", 1),
  29561.  
  29562. (try_begin),
  29563. ##nested diplomacy start+
  29564. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", ":cur_kingdom_2"),
  29565. (this_or_next|ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  29566. ##nested diplomacy end+
  29567. (eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
  29568. (ge, ":kingdom_1_to_kingdom_2", 1),
  29569.  
  29570. (try_begin),
  29571. ##nested diplomacy start+ change to use constants
  29572. #(is_between, ":truce_days", 20, 50),
  29573. (is_between, ":truce_days", dplmc_treaty_trade_days_expire, dplmc_treaty_defense_days_half_done),
  29574. ##nested diplomacy end+
  29575. (ge, ":cur_relation", 30),
  29576. (faction_slot_eq, ":cur_kingdom", slot_faction_recognized_player, 1), #recognized us
  29577. (call_script, "script_add_notification_menu", "mnu_dplmc_question_alliance_offer", ":cur_kingdom", 0),
  29578. (else_try),
  29579. ##nested diplomacy start+ change to use constants
  29580. #(is_between, ":truce_days", 0, 30), #you need a non-aggression or trade aggreement for an defensive pact
  29581. (is_between, ":truce_days", 0, dplmc_treaty_trade_days_half_done),
  29582. ##nested diplomacy end+
  29583. (ge, ":cur_relation", 20),
  29584. (faction_slot_eq, ":cur_kingdom", slot_faction_recognized_player, 1), #recognized us
  29585. (call_script, "script_add_notification_menu", "mnu_dplmc_question_defensive_offer", ":cur_kingdom", 0),
  29586. (else_try),
  29587. ##nested diplomacy start+ change to use constants
  29588. #(is_between, ":truce_days", 0, 10),
  29589. (is_between, ":truce_days", 0, dplmc_treaty_truce_days_half_done),
  29590. ##diplomacy end+
  29591. (ge, ":cur_relation", 10),
  29592. (faction_slot_eq, ":cur_kingdom", slot_faction_recognized_player, 1), #recognized us
  29593. (call_script, "script_add_notification_menu", "mnu_dplmc_question_trade_offer", ":cur_kingdom", 0),
  29594. (else_try),
  29595. (eq, ":truce_days", 0),
  29596. (ge, ":cur_relation", 5),
  29597. (call_script, "script_add_notification_menu", "mnu_dplmc_question_nonaggression_offer", ":cur_kingdom", 0),
  29598. (try_end),
  29599. (else_try),
  29600. (ge, ":kingdom_1_to_kingdom_2", 1),
  29601.  
  29602. (call_script, "script_npc_decision_checklist_peace_or_war", ":cur_kingdom_2", ":cur_kingdom", -1),
  29603. (assign, ":kingdom_2_to_kingdom_1", reg0),
  29604. (ge, ":kingdom_2_to_kingdom_1", 1),
  29605.  
  29606. (try_begin),
  29607. ##nested diplomacy start+ change to use constants
  29608. #(is_between, ":truce_days", 20, 50),
  29609. (is_between, ":truce_days", dplmc_treaty_trade_days_expire, dplmc_treaty_defense_days_half_done),
  29610. ##nested diplomacy end+
  29611. (ge, ":cur_relation", 30),
  29612. (call_script, "script_dplmc_start_alliance_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
  29613. (else_try),
  29614. ##nested diplomacy start+ change to use constants
  29615. #(is_between, ":truce_days", 0, 30), #you need a non-aggression or trade aggreement for an defensive pact
  29616. (is_between, ":truce_days", 0, dplmc_treaty_trade_days_half_done),
  29617. ##nested diplomacy end+
  29618. (ge, ":cur_relation", 20),
  29619. (call_script, "script_dplmc_start_defensive_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
  29620. (else_try),
  29621. ##nested diplomacy start+ change to use constants
  29622. #(is_between, ":truce_days", 0, 10),
  29623. (is_between, ":truce_days", 0, dplmc_treaty_truce_days_half_done),
  29624. ##nested diplomacy end+
  29625. (ge, ":cur_relation", 10),
  29626. (call_script, "script_dplmc_start_trade_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
  29627. (else_try),
  29628. (eq, ":truce_days", 0),
  29629. (call_script, "script_dplmc_start_nonaggression_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
  29630. (try_end),
  29631. (try_end),
  29632. ##diplomacy end
  29633. (try_end),
  29634. (try_end),
  29635. (try_end),
  29636.  
  29637. (try_begin),
  29638. (eq, ":players_kingdom_at_peace", 1),
  29639. (val_add, "$players_kingdom_days_at_peace", 1),
  29640. (try_begin),
  29641. (eq, "$cheat_mode", 1),
  29642. (assign, reg3, "$players_kingdom_days_at_peace"),
  29643. (display_message, "@{!}DEBUG -- Player's kingdom has had {reg3} days of peace"),
  29644. (try_end),
  29645. (else_try),
  29646. (assign, "$players_kingdom_days_at_peace", 0),
  29647. (try_end),
  29648.  
  29649. ]),
  29650.  
  29651.  
  29652. # script_randomly_start_war_peace
  29653. # Input: arg1 = initializing_war_peace_cond (1 = true, 0 = false)
  29654. # Output: none
  29655. # ("randomly_start_war_peace",
  29656. # [
  29657. # (store_script_param_1, ":initializing_war_peace_cond"),
  29658. # (assign, ":total_resources", 0),
  29659. # (assign, ":total_active_kingdoms", 0),
  29660. # (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
  29661. # (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
  29662. # (val_add, ":total_active_kingdoms", 1),
  29663. # (faction_get_slot, ":num_towns", ":cur_kingdom", slot_faction_num_towns),
  29664. # (store_mul, ":kingdom_resources_value", ":num_towns", 2),
  29665. # (faction_get_slot, ":num_castles", ":cur_kingdom", slot_faction_num_castles),
  29666. # (val_add, ":kingdom_resources_value", ":num_castles"),
  29667. # (val_mul, ":kingdom_resources_value", 10),
  29668. # (val_max, ":kingdom_resources_value", 1),
  29669. # (val_mul, ":kingdom_resources_value", 1000),
  29670. # (faction_get_slot, ":num_armies", ":cur_kingdom", slot_faction_num_armies),
  29671. # (val_max, ":num_armies", 1),
  29672. # (val_div, ":kingdom_resources_value", ":num_armies"),
  29673. # (val_add, ":total_resources", ":kingdom_resources_value"),
  29674. # (try_end),
  29675. # (val_max, ":total_active_kingdoms", 1),
  29676. # (store_div, ":average_resources", ":total_resources", ":total_active_kingdoms"),
  29677.  
  29678. # (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
  29679. ## (neq, ":cur_kingdom", "fac_player_supporters_faction"),
  29680. # (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
  29681. # (assign, ":num_ongoing_wars", 0),
  29682. # (try_for_range, ":other_kingdom", kingdoms_begin, kingdoms_end),
  29683. # (faction_slot_eq, ":other_kingdom", slot_faction_state, sfs_active),
  29684. # (store_relation, ":other_relation", ":cur_kingdom", ":other_kingdom"),
  29685. # (lt, ":other_relation", 0),
  29686. # (val_add, ":num_ongoing_wars", 1),
  29687. # (try_end),
  29688.  
  29689. # (faction_get_slot, ":num_towns", ":cur_kingdom", slot_faction_num_towns),
  29690. # (store_mul, ":kingdom_1_resources_value", ":num_towns", 2),
  29691. # (faction_get_slot, ":num_castles", ":cur_kingdom", slot_faction_num_castles),
  29692. # (val_add, ":kingdom_1_resources_value", ":num_castles"),
  29693. # (val_mul, ":kingdom_1_resources_value", 10),
  29694. # (val_max, ":kingdom_1_resources_value", 1),
  29695. # (val_mul, ":kingdom_1_resources_value", 1000),
  29696. # (faction_get_slot, ":num_armies", ":cur_kingdom", slot_faction_num_armies),
  29697. # (val_max, ":num_armies", 1),
  29698. # (val_div, ":kingdom_1_resources_value", ":num_armies"),
  29699.  
  29700. # (store_add, ":start_cond", ":cur_kingdom", 1),
  29701. # (try_for_range, ":cur_kingdom_2", ":start_cond", kingdoms_end),
  29702. ## (neq, ":cur_kingdom", "fac_player_supporters_faction"),
  29703. # (faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),
  29704.  
  29705. # (assign, ":num_ongoing_wars_2", 0),
  29706. # (try_for_range, ":other_kingdom", kingdoms_begin, kingdoms_end),
  29707. # (faction_slot_eq, ":other_kingdom", slot_faction_state, sfs_active),
  29708. # (store_relation, ":other_relation", ":cur_kingdom_2", ":other_kingdom"),
  29709. # (lt, ":other_relation", 0),
  29710. # (val_add, ":num_ongoing_wars_2", 1),
  29711. # (try_end),
  29712.  
  29713. # (store_add, ":total_ongoing_wars", ":num_ongoing_wars", ":num_ongoing_wars_2"),
  29714.  
  29715. # (faction_get_slot, ":num_towns", ":cur_kingdom_2", slot_faction_num_towns),
  29716. # (store_mul, ":kingdom_2_resources_value", ":num_towns", 2),
  29717. # (faction_get_slot, ":num_castles", ":cur_kingdom_2", slot_faction_num_castles),
  29718. # (val_add, ":kingdom_2_resources_value", ":num_castles"),
  29719. # (val_mul, ":kingdom_2_resources_value", 10),
  29720. # (val_max, ":kingdom_2_resources_value", 1),
  29721. # (val_mul, ":kingdom_2_resources_value", 1000),
  29722. # (faction_get_slot, ":num_armies", ":cur_kingdom_2", slot_faction_num_armies),
  29723. # (val_max, ":num_armies", 1),
  29724. # (val_div, ":kingdom_2_resources_value", ":num_armies"),
  29725.  
  29726. # (assign, ":max_resources_value", ":kingdom_1_resources_value"),
  29727. # (val_max, ":max_resources_value", ":kingdom_2_resources_value"),
  29728. # (val_mul, ":max_resources_value", 100),
  29729. # (val_div, ":max_resources_value", ":average_resources"),
  29730.  
  29731. # (assign, ":cur_king", -1),
  29732. # (try_begin),
  29733. # (eq, ":cur_kingdom", "fac_player_supporters_faction"),
  29734. # (faction_get_slot, ":cur_king", ":cur_kingdom_2", slot_faction_leader),
  29735. # (assign, ":cur_relation", reg0),
  29736. # (store_sub, ":relation_effect", 200, ":cur_relation"),
  29737. # (val_mul, ":kingdom_1_resources_value", ":relation_effect"),
  29738. # (val_div, ":kingdom_1_resources_value", 200),
  29739. # (else_try),
  29740. # (eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
  29741. # (faction_get_slot, ":cur_king", ":cur_kingdom", slot_faction_leader),
  29742. # (try_end),
  29743.  
  29744. # (try_begin),
  29745. # (ge, ":cur_king", 0),
  29746. # (call_script, "script_troop_get_player_relation", ":cur_king"),
  29747. # (assign, ":cur_relation", reg0),
  29748. # (store_sub, ":relation_effect", 200, ":cur_relation"),
  29749. # (val_mul, ":max_resources_value", ":relation_effect"),
  29750. # (val_div, ":max_resources_value", 200),
  29751. # (try_end),
  29752.  
  29753. #max_resources_value is the obtained value that gives us how tempting the kingdom's values are
  29754. #average is 100
  29755. # (val_clamp, ":max_resources_value", 20, 500),
  29756. #not letting more than 5 times higher chance of declaring war or peace
  29757.  
  29758. # (store_random_in_range, ":random_no", 0, 10000),
  29759. # (store_relation, ":cur_relation", ":cur_kingdom", ":cur_kingdom_2"),
  29760. # (try_begin),
  29761. # (lt, ":cur_relation", 0), #AT WAR
  29762. # (store_mul, ":chance_to_make_peace", ":total_ongoing_wars", 50),
  29763. # (val_mul, ":chance_to_make_peace", 100),
  29764. # (val_div, ":chance_to_make_peace", ":max_resources_value"),
  29765. # (try_begin),
  29766. #disable random peace for special conditions
  29767. # (this_or_next|eq, ":cur_kingdom", "fac_player_supporters_faction"),
  29768. # (eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
  29769. # (assign, ":continue", 0),
  29770. # (try_begin),
  29771. # (gt, "$supported_pretender", 0),
  29772. # (this_or_next|eq, ":cur_kingdom", "$supported_pretender_old_faction"),
  29773. # (eq, ":cur_kingdom_2", "$supported_pretender_old_faction"),
  29774. # (assign, ":continue", 1),
  29775. # (else_try),
  29776. # (is_between, "$players_oath_renounced_against_kingdom", kingdoms_begin, kingdoms_end),
  29777. # (this_or_next|eq, ":cur_kingdom", "$players_oath_renounced_against_kingdom"),
  29778. # (eq, ":cur_kingdom_2", "$players_oath_renounced_against_kingdom"),
  29779. # (assign, ":continue", 1),
  29780. # (try_end),
  29781. # (eq, ":continue", 1),
  29782. # (assign, ":chance_to_make_peace", 0),
  29783. # (try_end),
  29784. # (try_begin),
  29785. # (lt, ":random_no", ":chance_to_make_peace"),
  29786. # (assign, ":continue", 1),
  29787. # (try_begin),
  29788. # (check_quest_active, "qst_persuade_lords_to_make_peace"),
  29789. # (quest_get_slot, ":quest_target_faction", "qst_persuade_lords_to_make_peace", slot_quest_target_faction),
  29790. # (quest_get_slot, ":quest_object_faction", "qst_persuade_lords_to_make_peace", slot_quest_object_faction),
  29791. # (this_or_next|eq, ":cur_kingdom", ":quest_target_faction"),
  29792. # (eq, ":cur_kingdom", ":quest_object_faction"),
  29793. # (this_or_next|eq, ":cur_kingdom_2", ":quest_target_faction"),
  29794. # (eq, ":cur_kingdom_2", ":quest_object_faction"),
  29795. # (assign, ":continue", 0), #Do not declare war if the quest is active for the specific kingdoms
  29796. # (try_end),
  29797. # (eq, ":continue", 1),
  29798. # (try_begin),
  29799. # (eq, ":cur_kingdom", "fac_player_supporters_faction"),
  29800. # (call_script, "script_add_notification_menu", "mnu_question_peace_offer", ":cur_kingdom_2", 0),
  29801. # (else_try),
  29802. # (eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
  29803. # (call_script, "script_add_notification_menu", "mnu_question_peace_offer", ":cur_kingdom", 0),
  29804. # (else_try),
  29805. # (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
  29806. # (try_end),
  29807. # (try_end),
  29808. # (else_try), # AT PEACE
  29809. # (assign, ":chance_to_declare_war", 6),
  29810. # (val_sub, ":chance_to_declare_war", ":total_ongoing_wars"),
  29811. # (val_mul, ":chance_to_declare_war", 50),
  29812. # (val_mul, ":chance_to_declare_war", ":max_resources_value"),
  29813. # (val_div, ":chance_to_declare_war", 100),
  29814. # (try_begin),
  29815. # (lt, ":random_no", ":chance_to_declare_war"),
  29816. # (assign, ":continue", 1),
  29817. # (try_begin),
  29818. # (check_quest_active, "qst_raid_caravan_to_start_war"),
  29819. # (quest_get_slot, ":quest_target_faction", "qst_raid_caravan_to_start_war", slot_quest_target_faction),
  29820. # (quest_get_slot, ":quest_object_faction", "qst_raid_caravan_to_start_war", slot_quest_object_faction),
  29821. # (this_or_next|eq, ":cur_kingdom", ":quest_target_faction"),
  29822. # (eq, ":cur_kingdom", ":quest_object_faction"),
  29823. # (this_or_next|eq, ":cur_kingdom_2", ":quest_target_faction"),
  29824. # (eq, ":cur_kingdom_2", ":quest_object_faction"),
  29825. # (assign, ":continue", 0), #Do not declare war if the quest is active for the specific kingdoms
  29826. # (try_end),
  29827. # (eq, ":continue", 1),
  29828. # (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
  29829. # (try_end),
  29830. # (try_end),
  29831. # (try_end),
  29832. # (try_end),
  29833. # ]),
  29834.  
  29835.  
  29836.  
  29837. # script_exchange_prisoners_between_factions
  29838. # Input: arg1 = faction_no_1, arg2 = faction_no_2
  29839. ("exchange_prisoners_between_factions",
  29840. [
  29841. (store_script_param_1, ":faction_no_1"),
  29842. (store_script_param_2, ":faction_no_2"),
  29843. (assign, ":faction_no_3", -1),
  29844. (assign, ":faction_no_4", -1),
  29845. (assign, ":free_companions_too", 0),
  29846. (try_begin),
  29847. (this_or_next|eq, "$players_kingdom", ":faction_no_1"),
  29848. (eq, "$players_kingdom", ":faction_no_2"),
  29849. (assign, ":faction_no_3", "fac_player_faction"),
  29850. (assign, ":faction_no_4", "fac_player_supporters_faction"),
  29851. (assign, ":free_companions_too", 1),
  29852. (try_end),
  29853.  
  29854. (try_for_parties, ":party_no"),
  29855. (store_faction_of_party, ":party_faction", ":party_no"),
  29856. (this_or_next|eq, ":party_faction", ":faction_no_1"),
  29857. (this_or_next|eq, ":party_faction", ":faction_no_2"),
  29858. (this_or_next|eq, ":party_faction", ":faction_no_3"),
  29859. (eq, ":party_faction", ":faction_no_4"),
  29860. (party_get_num_prisoner_stacks, ":num_stacks", ":party_no"),
  29861. (try_for_range_backwards, ":troop_iterator", 0, ":num_stacks"),
  29862. (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":party_no", ":troop_iterator"),
  29863.  
  29864. (assign, ":continue", 0),
  29865. (try_begin),
  29866. (is_between, ":cur_troop_id", companions_begin, companions_end),
  29867. (eq, ":free_companions_too", 1),
  29868. (assign, ":continue", 1),
  29869. (else_try),
  29870. (neg|is_between, ":cur_troop_id", companions_begin, companions_end),
  29871. (store_troop_faction, ":cur_faction", ":cur_troop_id"),
  29872. (this_or_next|eq, ":cur_faction", ":faction_no_1"),
  29873. (this_or_next|eq, ":cur_faction", ":faction_no_2"),
  29874. (this_or_next|eq, ":cur_faction", ":faction_no_3"),
  29875. (eq, ":cur_faction", ":faction_no_4"),
  29876. (assign, ":continue", 1),
  29877. (try_end),
  29878. (eq, ":continue", 1),
  29879.  
  29880. (try_begin),
  29881. (troop_is_hero, ":cur_troop_id"),
  29882. (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
  29883. (try_end),
  29884. (party_prisoner_stack_get_size, ":stack_size", ":party_no", ":troop_iterator"),
  29885. (party_remove_prisoners, ":party_no", ":cur_troop_id", ":stack_size"),
  29886. (try_end),
  29887. (try_end),
  29888.  
  29889. ]),
  29890.  
  29891. # script_add_notification_menu
  29892. # Input: arg1 = menu_no, arg2 = menu_var_1, arg3 = menu_var_2
  29893. # Output: none
  29894. ("add_notification_menu",
  29895. [
  29896. (try_begin),
  29897. (eq, "$g_infinite_camping", 0),
  29898. (store_script_param, ":menu_no", 1),
  29899. (store_script_param, ":menu_var_1", 2),
  29900. (store_script_param, ":menu_var_2", 3),
  29901. (assign, ":end_cond", 1),
  29902. (try_for_range, ":cur_slot", 0, ":end_cond"),
  29903. (try_begin),
  29904. (troop_slot_ge, "trp_notification_menu_types", ":cur_slot", 1),
  29905. (val_add, ":end_cond", 1),
  29906. (else_try),
  29907. (troop_set_slot, "trp_notification_menu_types", ":cur_slot", ":menu_no"),
  29908. (troop_set_slot, "trp_notification_menu_var1", ":cur_slot", ":menu_var_1"),
  29909. (troop_set_slot, "trp_notification_menu_var2", ":cur_slot", ":menu_var_2"),
  29910. (try_end),
  29911. (try_end),
  29912. (try_end),
  29913. ]),
  29914.  
  29915. # script_finish_quest
  29916. # Input: arg1 = quest_no, arg2 = finish_percentage
  29917. # Output: none
  29918. ("finish_quest",
  29919. [
  29920. (store_script_param_1, ":quest_no"),
  29921. (store_script_param_2, ":finish_percentage"),
  29922.  
  29923. (quest_get_slot, ":quest_giver", ":quest_no", slot_quest_giver_troop),
  29924. (quest_get_slot, ":quest_importance", ":quest_no", slot_quest_importance),
  29925. (quest_get_slot, ":quest_xp_reward", ":quest_no", slot_quest_xp_reward),
  29926. (quest_get_slot, ":quest_gold_reward", ":quest_no", slot_quest_gold_reward),
  29927.  
  29928. (try_begin),
  29929. (lt, ":finish_percentage", 100),
  29930. (val_mul, ":quest_xp_reward", ":finish_percentage"),
  29931. (val_div, ":quest_xp_reward", 100),
  29932. (val_mul, ":quest_gold_reward", ":finish_percentage"),
  29933. (val_div, ":quest_gold_reward", 100),
  29934. #Changing the relation factor. Negative relation if less than 75% of the quest is finished.
  29935. #Positive relation if more than 75% of the quest is finished.
  29936. (neq, ":quest_importance", -1), #has to have a value assigned
  29937. (assign, ":importance_multiplier", ":finish_percentage"),
  29938. (val_sub, ":importance_multiplier", 75),
  29939. (val_mul, ":quest_importance", ":importance_multiplier"),
  29940. (val_div, ":quest_importance", 100),
  29941. (try_end),
  29942. #SB : separate condition
  29943. (try_begin),
  29944. (neq, ":quest_importance", -1), #has to have a value assigned
  29945. (val_mul, ":quest_importance", 4), #was div 4. Relation was increasing very less. I changed it to mul 4.
  29946. (val_add, ":quest_importance", 1),
  29947. (call_script, "script_change_player_relation_with_troop", ":quest_giver", ":quest_importance"),
  29948. (try_end),
  29949.  
  29950. (add_xp_as_reward, ":quest_xp_reward"),
  29951. (call_script, "script_troop_add_gold", "trp_player", ":quest_gold_reward"),
  29952. (call_script, "script_end_quest", ":quest_no"),
  29953.  
  29954. ]),
  29955.  
  29956.  
  29957. # script_get_information_about_troops_position
  29958. # Input: arg1 = troop_no, arg2 = time (0 if present tense, 1 if past tense)
  29959. # Output: s1 = String, reg0 = knows-or-not
  29960. ("get_information_about_troops_position",
  29961. [
  29962. (store_script_param_1, ":troop_no"),
  29963. (store_script_param_2, reg3),
  29964. ##diplomacy start+
  29965. #(troop_get_type, reg4, ":troop_no"),
  29966. (call_script, "script_dplmc_store_troop_is_female_reg", ":troop_no", 4),
  29967. ##diplomacy end+
  29968. (str_store_troop_name, s2, ":troop_no"),
  29969.  
  29970. (assign, ":found", 0),
  29971. (troop_get_slot, ":center_no", ":troop_no", slot_troop_cur_center),
  29972. (try_begin),
  29973. (gt, ":center_no", 0),
  29974. (is_between, ":center_no", centers_begin, centers_end),
  29975. (str_store_party_name_link, s3, ":center_no"),
  29976. (str_store_string, s1, "@{s2} {reg3?was:is currently} at {s3}."),
  29977. (assign, ":found", 1),
  29978. (else_try),
  29979. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  29980. (gt, ":party_no", 0),
  29981. (call_script, "script_get_troop_attached_party", ":troop_no"),
  29982. (assign, ":center_no", reg0),
  29983. (try_begin),
  29984. (is_between, ":center_no", centers_begin, centers_end),
  29985. (str_store_party_name_link, s3, ":center_no"),
  29986. (str_store_string, s1, "@{s2} {reg3?was:is currently} at {s3}."),
  29987. (assign, ":found", 1),
  29988. (else_try),
  29989. (get_party_ai_behavior, ":ai_behavior", ":party_no"),
  29990. (eq, ":ai_behavior", ai_bhvr_travel_to_party),
  29991. (get_party_ai_object, ":ai_object", ":party_no"),
  29992. (is_between, ":ai_object", centers_begin, centers_end),
  29993. ##diplomacy start+
  29994. #(call_script, "script_get_closest_center", ":party_no"),
  29995. (call_script, "script_dplmc_get_closest_center_or_two", ":party_no"),
  29996. ##diplomacy end+
  29997. (str_store_party_name_link, s4, reg0),
  29998. (str_store_party_name_link, s3, ":ai_object"),
  29999. (str_store_string, s1, "@{s2} {reg3?was:is} travelling to {s3} and {reg4?she:he} {reg3?was:should be} close to {s4}{reg3?: at the moment}."),
  30000. (assign, ":found", 1),
  30001. ##diplomacy start+
  30002. (try_begin),
  30003. (gt, reg1, -1),
  30004. (str_store_party_name_link, s1, reg1),
  30005. (str_store_string, s1, "@{s2} {reg3?was:is} travelling to {s3} and {reg4?she:he} {reg3?was:should be} between {s4} and {s1}{reg3?: at the moment}."),
  30006. (try_end),
  30007. ##diplomacy end+
  30008. (else_try),
  30009. ##diplomacy start+
  30010. #(call_script, "script_get_closest_center", ":party_no"),
  30011. (call_script, "script_dplmc_get_closest_center_or_two", ":party_no"),
  30012. ##diplomacy end+
  30013. (str_store_party_name_link, s3, reg0),
  30014. (str_store_string, s1, "@{s2} {reg3?was:is} in the field and {reg4?she:he} {reg3?was:should be} close to {s3}{reg3?: at the moment}."),
  30015. (assign, ":found", 1),
  30016. ##diplomacy start+
  30017. (try_begin),
  30018. (gt, reg1, -1),
  30019. (str_store_party_name_link, s1, reg1),
  30020. (str_store_string, s1, "@{s2} {reg3?was:is} in the field and {reg4?she:he} {reg3?was:should be} between {s3} and {s1}{reg3?: at the moment}."),
  30021. (try_end),
  30022. ##diplomacy end+
  30023. (try_end),
  30024. (else_try),
  30025. #(troop_slot_ge, ":troop_no", slot_troop_is_prisoner, 1),
  30026. (troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  30027. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  30028. (party_count_prisoners_of_type, ":num_prisoners", ":center_no", ":troop_no"),
  30029. (gt, ":num_prisoners", 0),
  30030. (assign, ":found", 1),
  30031. (str_store_party_name_link, s3, ":center_no"),
  30032. (str_store_string, s1, "@{s2} {reg3?was:is} being held captive at {s3}."),
  30033. (try_end),
  30034. (try_begin),
  30035. (eq, ":found", 0),
  30036. (str_store_string, s1, "@{s2} {reg3?was:has been} taken captive by {reg4?her:his} enemies."),
  30037. (assign, ":found", 1),
  30038. (try_end),
  30039. (try_end),
  30040. (try_begin),
  30041. (eq, ":found", 0),
  30042. (str_store_string, s1, "@{reg3?{s2}'s location was unknown:I don't know where {s2} is}."),
  30043. (try_end),
  30044. (assign, reg0, ":found"),
  30045. ]),
  30046.  
  30047. # script_recruit_troop_as_companion
  30048. # Input: arg1 = troop_no,
  30049. # Output: none
  30050. ("recruit_troop_as_companion",
  30051. [
  30052. (store_script_param_1, ":troop_no"),
  30053. ##diplomacy start+
  30054. ##Save civilian clothing of companions (and ladies, etc.)
  30055. (try_begin),
  30056. (troop_is_hero, ":troop_no"),
  30057. (neg|troop_slot_ge, ":troop_no", slot_troop_playerparty_history, 1),#only call this the first time they join
  30058. (call_script, "script_dplmc_save_civilian_clothing", ":troop_no"),#although, redundant calls should be save
  30059. (call_script, "script_change_troop_renown", ":troop_no", 1),#although, redundant calls should be save
  30060. (try_end),
  30061. ##Preserve former occupations enfeoffed companions
  30062. (try_begin),
  30063. (troop_is_hero, ":troop_no"),
  30064. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  30065. (neg|troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  30066. (troop_set_slot, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_lord_rejoined),
  30067. (try_end),
  30068. ##diplomacy end+
  30069. (try_begin), #SB : spouse scripts
  30070. (neg|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_lady),
  30071. (troop_set_slot, ":troop_no", slot_troop_occupation, slto_player_companion),
  30072. (troop_set_slot, ":troop_no", slot_troop_cur_center, -1),
  30073. (else_try), #SB : store that lady was recruited as companion
  30074. (troop_set_slot, ":troop_no", slot_troop_first_encountered, "$current_town"),
  30075. (try_end),
  30076. (troop_set_auto_equip, ":troop_no", 0),
  30077. (party_add_members, "p_main_party", ":troop_no", 1),
  30078. (str_store_troop_name_link, s6, ":troop_no"),
  30079. (display_log_message, "@{s6} has joined your party.", message_alert), #SB : colourize
  30080. (play_sound, "snd_tutorial_2"), #SB : chime sound
  30081. (troop_set_note_available, ":troop_no", 1),
  30082.  
  30083. (try_begin),
  30084. (is_between, ":troop_no", companions_begin, companions_end),
  30085. (store_sub, ":companion_number", ":troop_no", companions_begin),
  30086.  
  30087. (set_achievement_stat, ACHIEVEMENT_KNIGHTS_OF_THE_ROUND, ":companion_number", 1),
  30088.  
  30089. (assign, ":number_of_companions_hired", 0),
  30090. (try_for_range, ":cur_companion", 0, 16),
  30091. (get_achievement_stat, ":is_hired", ACHIEVEMENT_KNIGHTS_OF_THE_ROUND, ":cur_companion"),
  30092. (eq, ":is_hired", 1),
  30093. (val_add, ":number_of_companions_hired", 1),
  30094. (try_end),
  30095.  
  30096. (try_begin),
  30097. (ge, ":number_of_companions_hired", 6),
  30098. (unlock_achievement, ACHIEVEMENT_KNIGHTS_OF_THE_ROUND),
  30099. (try_end),
  30100. (try_end),
  30101. ]),
  30102.  
  30103.  
  30104. # script_setup_random_scene
  30105. # Input: arg1 = center_no, arg2 = mission_template_no
  30106. # Output: none
  30107. ("setup_random_scene",
  30108. [
  30109. (party_get_current_terrain, ":terrain_type", "p_main_party"),
  30110. (assign, ":scene_to_use", "scn_random_scene"),
  30111. (try_begin),
  30112. (eq, ":terrain_type", rt_steppe),
  30113. (assign, ":scene_to_use", "scn_random_scene_steppe"),
  30114. (else_try),
  30115. (eq, ":terrain_type", rt_plain),
  30116. (assign, ":scene_to_use", "scn_random_scene_plain"),
  30117. (else_try),
  30118. (eq, ":terrain_type", rt_snow),
  30119. (assign, ":scene_to_use", "scn_random_scene_snow"),
  30120. (else_try),
  30121. (eq, ":terrain_type", rt_desert),
  30122. (assign, ":scene_to_use", "scn_random_scene_desert"),
  30123. (else_try),
  30124. (eq, ":terrain_type", rt_steppe_forest),
  30125. (assign, ":scene_to_use", "scn_random_scene_steppe_forest"),
  30126. (else_try),
  30127. (eq, ":terrain_type", rt_forest),
  30128. (assign, ":scene_to_use", "scn_random_scene_plain_forest"),
  30129. (else_try),
  30130. (eq, ":terrain_type", rt_snow_forest),
  30131. (assign, ":scene_to_use", "scn_random_scene_snow_forest"),
  30132. (else_try),
  30133. (eq, ":terrain_type", rt_desert_forest),
  30134. (assign, ":scene_to_use", "scn_random_scene_desert_forest"),
  30135. (else_try),
  30136. (eq, ":terrain_type", rt_water),
  30137. (assign, ":scene_to_use", "scn_water"),
  30138. (else_try),
  30139. (eq, ":terrain_type", rt_bridge),
  30140. (assign, ":scene_to_use", "scn_random_scene_plain"),
  30141. (try_end),
  30142. (jump_to_scene,":scene_to_use"),
  30143. ]),
  30144.  
  30145. # script_enter_dungeon
  30146. # Input: arg1 = center_no, arg2 = mission_template_no
  30147. # Output: none
  30148. ("enter_dungeon",
  30149. [
  30150. (store_script_param_1, ":center_no"),
  30151. (store_script_param_2, ":mission_template_no"),
  30152.  
  30153. (set_jump_mission,":mission_template_no"),
  30154. #new added...
  30155. (mission_tpl_entry_set_override_flags, ":mission_template_no", 0, af_override_horse),
  30156. (try_begin),
  30157. (gt, "$sneaked_into_town", disguise_none),
  30158. (mission_tpl_entry_set_override_flags, ":mission_template_no", 0, af_override_everything), #boots + gloves
  30159. # (mission_tpl_entry_clear_override_items, ":mission_template_no", 0),
  30160. #SB : different disguises
  30161. (call_script, "script_set_disguise_override_items", ":mission_template_no", 0, 0), #no weapons
  30162. # (mission_tpl_entry_add_override_item, ":mission_template_no", 0, "itm_pilgrim_hood"),
  30163. # (mission_tpl_entry_add_override_item, ":mission_template_no", 0, "itm_wrapping_boots"), #SB add boots
  30164. # (mission_tpl_entry_add_override_item, ":mission_template_no", 0, "itm_pilgrim_disguise"),
  30165. # (mission_tpl_entry_add_override_item, ":mission_template_no", 0, "itm_practice_staff"),
  30166. # (mission_tpl_entry_add_override_item, ":mission_template_no", 0, "itm_throwing_daggers"),
  30167. (try_end),
  30168. #new added end
  30169.  
  30170. (party_get_slot, ":dungeon_scene", ":center_no", slot_town_prison),
  30171.  
  30172. (modify_visitors_at_site,":dungeon_scene"),
  30173. (reset_visitors),
  30174. (assign, ":cur_pos", 16),
  30175.  
  30176.  
  30177. (call_script, "script_get_heroes_attached_to_center_as_prisoner", ":center_no", "p_temp_party"),
  30178. (party_get_num_companion_stacks, ":num_stacks","p_temp_party"),
  30179. ##diplomacy start+ Allow some variation in which prisoners appear,
  30180. #when there are too many to all fit in the jail at once.
  30181. (try_begin),
  30182. (gt, ":num_stacks", 15),
  30183. (store_random_in_range, ":offset", 0, ":num_stacks"),
  30184. (else_try),
  30185. (assign, ":offset", 0),
  30186. (try_end),
  30187. ##diplomacy end+
  30188. (try_for_range, ":i_stack", 0, ":num_stacks"),
  30189. ##diplomacy start+
  30190. (val_add, ":i_stack", ":offset"),
  30191. (try_begin),
  30192. (ge, ":i_stack", ":num_stacks"),
  30193. (val_sub, ":i_stack", ":num_stacks"),
  30194. (try_end),
  30195. ##diplomacy end+
  30196. (party_stack_get_troop_id, ":stack_troop","p_temp_party",":i_stack"),
  30197.  
  30198. (assign, ":prisoner_offered_parole", 0),
  30199. (try_begin),
  30200. (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  30201. (else_try),
  30202. (call_script, "script_cf_prisoner_offered_parole", ":stack_troop"),
  30203. (assign, ":prisoner_offered_parole", 1),
  30204. (else_try),
  30205. (assign, ":prisoner_offered_parole", 0),
  30206. (try_end),
  30207. (eq, ":prisoner_offered_parole", 0),
  30208.  
  30209. (lt, ":cur_pos", 32), # spawn up to entry point 32
  30210. (set_visitor, ":cur_pos", ":stack_troop"),
  30211. (val_add,":cur_pos", 1),
  30212. (try_end),
  30213.  
  30214. # (set_visitor, ":cur_pos", "trp_npc3"),
  30215. # (troop_set_slot, "trp_npc3", slot_troop_prisoner_of_party, "$g_encountered_party"),
  30216.  
  30217. (set_jump_entry, 0),
  30218. (jump_to_scene,":dungeon_scene"),
  30219. (scene_set_slot, ":dungeon_scene", slot_scene_visited, 1),
  30220. (change_screen_mission),
  30221. ]),
  30222.  
  30223. # script_enter_court
  30224. # Input: arg1 = center_no
  30225. # Output: none
  30226. #other search term: setup_court
  30227. ("enter_court",
  30228. [
  30229. (store_script_param_1, ":center_no"),
  30230.  
  30231. (assign, "$talk_context", tc_court_talk),
  30232.  
  30233. (set_jump_mission,"mt_visit_town_castle"),
  30234.  
  30235. (mission_tpl_entry_clear_override_items, "mt_visit_town_castle", 0),
  30236. #(mission_tpl_entry_set_override_flags, "mt_visit_town_castle", 0, af_override_all),
  30237.  
  30238. (party_get_slot, ":castle_scene", ":center_no", slot_town_castle),
  30239. (modify_visitors_at_site,":castle_scene"),
  30240. (reset_visitors),
  30241. #Adding guards
  30242. (store_faction_of_party, ":center_faction", ":center_no"),
  30243. ##diplomacy begin
  30244. (try_begin),
  30245. (eq, ":center_faction", "$players_kingdom"),
  30246. (is_between, "$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  30247. (faction_get_slot, ":guard_troop", "$g_player_culture", slot_faction_guard_troop),
  30248. ##nested diplomacy start+
  30249. (else_try),
  30250. #Reflect multicultural empires.
  30251. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  30252. (gt, ":town_lord", "trp_player"),
  30253. (troop_get_slot, ":lord_original_faction", ":town_lord", slot_troop_original_faction),
  30254. (neq, ":lord_original_faction", ":center_faction"),
  30255. (is_between, ":lord_original_faction", npc_kingdoms_begin, npc_kingdoms_end),
  30256. (this_or_next|party_slot_eq, ":center_no", slot_center_original_faction, ":lord_original_faction"),
  30257. (troop_slot_eq, ":town_lord", slot_troop_home, ":center_no"),
  30258. (faction_get_slot, ":guard_troop", ":lord_original_faction", slot_faction_guard_troop),
  30259. ##nested diplomacy end+
  30260. (else_try),
  30261. (faction_get_slot, ":guard_troop", ":center_faction", slot_faction_guard_troop),
  30262. (try_end),
  30263. ##diplomacy end
  30264. (try_begin),
  30265. (le, ":guard_troop", 0),
  30266. #diplomacy start+
  30267. #rubik changes this in Custom Commander, and I agree: the "generic" guard
  30268. #should be non-faction-specific.
  30269. ##OLD:
  30270. #(assign, ":guard_troop", "trp_swadian_sergeant"),
  30271. ##NEW:
  30272. (assign, ":guard_troop", "trp_hired_blade"),
  30273. ##diplomacy end+
  30274. (try_end),
  30275. (set_visitor, 6, ":guard_troop"),
  30276. (set_visitor, 7, ":guard_troop"),
  30277.  
  30278. (assign, ":cur_pos", 16),
  30279.  
  30280. (try_begin),
  30281. (troop_get_slot, ":player_spouse", "trp_player", slot_troop_spouse),
  30282. (gt, ":player_spouse", 0),
  30283. (troop_slot_eq, ":player_spouse", slot_troop_cur_center, ":center_no"),
  30284. (set_visitor, ":cur_pos", ":player_spouse"),
  30285. (val_add,":cur_pos", 1),
  30286. (else_try),
  30287. (troop_get_slot, ":player_betrothed", "trp_player", slot_troop_betrothed),
  30288. (gt, ":player_betrothed", 0),
  30289. (troop_slot_eq, ":player_betrothed", slot_troop_cur_center, ":center_no"),
  30290. (set_visitor, ":cur_pos", ":player_betrothed"),
  30291. (val_add,":cur_pos", 1),
  30292. (try_end),
  30293.  
  30294. (try_begin),
  30295. (eq, "$g_player_court", ":center_no"),
  30296. (gt, "$g_player_minister", 0),
  30297. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, "$g_player_minister"),
  30298. (set_visitor, ":cur_pos", "$g_player_minister"),
  30299. (val_add,":cur_pos", 1),
  30300. (try_end),
  30301. ##diplomacy begin
  30302. (try_begin),
  30303. (gt, "$g_player_chamberlain", 0),
  30304. (call_script, "script_dplmc_appoint_chamberlain"), #fix for wrong troops after update
  30305. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  30306. (eq, ":town_lord", "trp_player"),
  30307. (set_visitor, ":cur_pos", "$g_player_chamberlain"),
  30308. (val_add,":cur_pos", 1),
  30309. (try_end),
  30310.  
  30311. (try_begin),
  30312. (gt, "$g_player_constable", 0),
  30313. (call_script, "script_dplmc_appoint_constable"), #fix for wrong troops after update
  30314. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  30315. (eq, ":town_lord", "trp_player"),
  30316. (set_visitor, ":cur_pos", "$g_player_constable"),
  30317. (val_add,":cur_pos", 1),
  30318. (try_end),
  30319.  
  30320. (try_begin),
  30321. (gt, "$g_player_chancellor", 0),
  30322. (call_script, "script_dplmc_appoint_chancellor"), #fix for wrong troops after update
  30323. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  30324. (eq, ":town_lord", "trp_player"),
  30325. (set_visitor, ":cur_pos", "$g_player_chancellor"),
  30326. (val_add,":cur_pos", 1),
  30327. (try_end),
  30328. ##diplomacy end
  30329.  
  30330. #Lords wishing to pledge allegiance - inactive, but part of player faction
  30331. #SB : move down to sorted script call
  30332.  
  30333. ##diplomacy start+
  30334. #Show heroes you haven't seen recently first, to deal with crowded feast halls
  30335. #(call_script, "script_get_heroes_attached_to_center", ":center_no", "p_temp_party"),
  30336. (call_script, "script_dplmc_time_sorted_heroes_for_center", ":center_no", "p_temp_party"),
  30337. #Reserve a certain number of feast positions for ladies, both for practical
  30338. #reasons of courtship and for visual variety.
  30339. (try_begin),
  30340. #If the player is unmarried, reserve zero to 8 slots for women
  30341. (lt, ":player_spouse", 1),
  30342. (store_random_in_range, ":reserved", 0, 9),
  30343. (else_try),
  30344. #If the player is married, reserve zero to four slots for women
  30345. (store_random_in_range, ":reserved", 0, 5),
  30346. (try_end),
  30347. (store_sub, ":non_lady_max", 32, ":reserved"),
  30348. #diplomacy end+
  30349. (party_get_num_companion_stacks, ":num_stacks","p_temp_party"),
  30350. (try_for_range, ":i_stack", 0, ":num_stacks"),
  30351. (party_stack_get_troop_id, ":stack_troop","p_temp_party",":i_stack"),
  30352. ##diplomacy start+
  30353. #(lt, ":cur_pos", 32), # spawn up to entry point 32 - is it possible to add another 10 spots?
  30354. (lt, ":cur_pos", ":non_lady_max"),#Leave some room for ladies in huge feasts
  30355. ##diplomacy end+
  30356. (set_visitor, ":cur_pos", ":stack_troop"),
  30357. (val_add,":cur_pos", 1),
  30358. (try_end),
  30359. (try_for_range, ":cur_troop", kingdom_ladies_begin, kingdom_ladies_end),
  30360. (neq, ":cur_troop", "trp_knight_1_1_wife"), #The one who should not appear in game
  30361. #(troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_lady),
  30362. (troop_slot_eq, ":cur_troop", slot_troop_cur_center, ":center_no"),
  30363.  
  30364. (assign, ":lady_meets_visitors", 0),
  30365. (try_begin),
  30366. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, ":cur_troop"), #player spouse goes in position of honor
  30367. (troop_slot_eq, "trp_player", slot_troop_betrothed, ":cur_troop"), #player spouse goes in position of honor
  30368. (assign, ":lady_meets_visitors", 0), #She is already in the place of honor
  30369. (try_begin), #SB : primary spouse
  30370. (eq, "$cheat_mode", 1),
  30371. (str_store_troop_name, s4, ":cur_troop"),
  30372. (display_message, "str_s4_is_present_at_the_center_and_in_place_of_honor"),
  30373. (try_end),
  30374. (else_try),
  30375. (this_or_next|troop_slot_eq, ":cur_troop", slot_troop_spouse, "trp_player"), #player spouse goes in position of honor
  30376. (troop_slot_eq, ":cur_troop", slot_troop_betrothed, "trp_player"),
  30377. (assign, ":lady_meets_visitors", 1),
  30378. (try_begin), #SB : secondary spouse, normally shadowed due to above behaviour
  30379. (eq, "$cheat_mode", 1),
  30380. (str_store_troop_name, s4, ":cur_troop"),
  30381. (display_message, "str_s4_is_present_at_the_center_and_is_married"),
  30382. (try_end),
  30383. (else_try), #lady is troop
  30384. (store_faction_of_troop, ":lady_faction", ":cur_troop"),
  30385. (neq, ":lady_faction", ":center_faction"),
  30386.  
  30387. (assign, ":lady_meets_visitors", 1),
  30388.  
  30389.  
  30390. (try_begin),
  30391. (eq, "$cheat_mode", 1),
  30392. (str_store_troop_name, s4, ":cur_troop"),
  30393. (try_begin), #SB : distinguish between refugee and prisoner
  30394. (troop_slot_eq, ":cur_troop", slot_troop_prisoner_of_party, ":center_no"),
  30395. (display_message, "@{s4} is present at the center as a prisoner"),
  30396. (else_try),
  30397. (display_message, "str_s4_is_present_at_the_center_as_a_refugee"),
  30398. (try_end),
  30399. (try_end),
  30400.  
  30401. (else_try),
  30402. (troop_slot_ge, ":cur_troop", slot_troop_spouse, 1),
  30403.  
  30404. (try_begin),
  30405. #married ladies at a feast will not mingle - this is ahistorical, as married women and widows probably had much more freedom than unmarried ones, at least in the West, but the game needs to leave slots for them to show off their unmarried daughters
  30406. (faction_slot_eq, ":center_faction", slot_faction_ai_state, sfai_feast),
  30407. (faction_slot_eq, ":center_faction", slot_faction_ai_object, ":center_no"),
  30408. (assign, ":lady_meets_visitors", 0),
  30409.  
  30410. (try_begin),
  30411. (eq, "$cheat_mode", 1),
  30412. (str_store_troop_name, s4, ":cur_troop"),
  30413. (display_message, "str_s4_is_present_at_the_center_and_not_attending_the_feast"),
  30414. (try_end),
  30415. (else_try),
  30416. (assign, ":lady_meets_visitors", 1),
  30417.  
  30418. (try_begin),
  30419. (eq, "$cheat_mode", 1),
  30420. (str_store_troop_name, s4, ":cur_troop"),
  30421. (display_message, "str_s4_is_present_at_the_center_and_is_married"),
  30422. (try_end),
  30423. (try_end),
  30424.  
  30425. (else_try), #feast is in progress
  30426. (faction_slot_eq, ":center_faction", slot_faction_ai_state, sfai_feast),
  30427. (faction_slot_eq, ":center_faction", slot_faction_ai_object, ":center_no"),
  30428. (assign, ":lady_meets_visitors", 1),
  30429.  
  30430. (try_begin),
  30431. (eq, "$cheat_mode", 1),
  30432. (str_store_troop_name, s4, ":cur_troop"),
  30433. (display_message, "@{!}DEBUG -- {s4} is present at the center and is attending the feast"),
  30434. (try_end),
  30435.  
  30436. (else_try), #already met - awaits in private
  30437. (troop_slot_ge, ":cur_troop", slot_troop_met, 2),
  30438. (assign, ":lady_meets_visitors", 0),
  30439.  
  30440. (try_begin),
  30441. (eq, "$cheat_mode", 1),
  30442. (str_store_troop_name, s4, ":cur_troop"),
  30443. (display_message, "@{!}DEBUG -- {s4} is present at the center and is awaiting the player in private"),
  30444. (try_end),
  30445.  
  30446. (else_try),
  30447. (call_script, "script_get_kingdom_lady_social_determinants", ":cur_troop"),
  30448. (call_script, "script_npc_decision_checklist_male_guardian_assess_suitor", reg0, "trp_player"),
  30449. (gt, reg0, 0),
  30450. (assign, ":lady_meets_visitors", 1),
  30451.  
  30452. (try_begin),
  30453. (eq, "$cheat_mode", 1),
  30454. (str_store_troop_name, s4, ":cur_troop"),
  30455. (display_message, "@{!}DEBUG -- {s4} is_present_at_the_center_and_is_allowed_to_meet_the_player"),
  30456. (try_end),
  30457.  
  30458. (else_try),
  30459. (try_begin),
  30460. (eq, "$cheat_mode", 1),
  30461. (str_store_troop_name, s4, ":cur_troop"),
  30462. (display_message, "@{!}DEBUG -- {s4}is_present_at_the_center_and_is_not_allowed_to_meet_the_player"),
  30463. (try_end),
  30464.  
  30465. (try_end),
  30466.  
  30467. (eq, ":lady_meets_visitors", 1),
  30468.  
  30469. (lt, ":cur_pos", 32), # spawn up to entry point 32
  30470. (set_visitor, ":cur_pos", ":cur_troop"),
  30471. (val_add,":cur_pos", 1),
  30472. (try_end),
  30473.  
  30474. (set_jump_entry, 0),
  30475.  
  30476. (jump_to_scene,":castle_scene"),
  30477. (scene_set_slot, ":castle_scene", slot_scene_visited, 1),
  30478. (change_screen_mission),
  30479. ]),
  30480.  
  30481.  
  30482. ("setup_meet_lady",
  30483. [
  30484. (store_script_param_1, ":lady_no"),
  30485. (store_script_param_2, ":center_no"),
  30486.  
  30487. #(mission_tpl_entry_set_override_flags, "mt_visit_town_castle", 0, af_override_horse),
  30488. (troop_set_slot, ":lady_no", slot_lady_last_suitor, "trp_player"),
  30489.  
  30490. (set_jump_mission,"mt_visit_town_castle"),
  30491. (party_get_slot, ":castle_scene", ":center_no", slot_town_castle),
  30492. (modify_visitors_at_site,":castle_scene"),
  30493. (reset_visitors),
  30494.  
  30495. (troop_set_age, "trp_nurse_for_lady", 100),
  30496. (set_visitor, 7, "trp_nurse_for_lady"),
  30497.  
  30498. (assign, ":cur_pos", 16),
  30499. (set_visitor, ":cur_pos", ":lady_no"),
  30500.  
  30501. (assign, "$talk_context", tc_garden),
  30502.  
  30503. (jump_to_scene,":castle_scene"),
  30504. (scene_set_slot, ":castle_scene", slot_scene_visited, 1),
  30505. (change_screen_mission),
  30506. ]),
  30507.  
  30508. # script_find_high_ground_around_pos1
  30509. # Input: pos1 should hold center_position_no
  30510. # arg1: team_no
  30511. # arg2: search_radius (in meters)
  30512. # Output: pos52 contains highest ground within <search_radius> meters of team leader
  30513. # Destroys position registers: pos10, pos11, pos15
  30514. ("find_high_ground_around_pos1",
  30515. [
  30516. (store_script_param, ":team_no", 1),
  30517. (store_script_param, ":search_radius", 2),
  30518. (val_mul, ":search_radius", 100),
  30519. (get_scene_boundaries, pos10,pos11),
  30520. (team_get_leader, ":ai_leader", ":team_no"),
  30521. (agent_get_position, pos1, ":ai_leader"),
  30522. (set_fixed_point_multiplier, 100),
  30523. (position_get_x, ":o_x", pos1),
  30524. (position_get_y, ":o_y", pos1),
  30525. (store_sub, ":min_x", ":o_x", ":search_radius"),
  30526. (store_sub, ":min_y", ":o_y", ":search_radius"),
  30527. (store_add, ":max_x", ":o_x", ":search_radius"),
  30528. (store_add, ":max_y", ":o_y", ":search_radius"),
  30529. (position_get_x, ":scene_min_x", pos10),
  30530. (position_get_x, ":scene_max_x", pos11),
  30531. (position_get_y, ":scene_min_y", pos10),
  30532. (position_get_y, ":scene_max_y", pos11),
  30533. #do not find positions close to borders (20 m)
  30534. (val_add, ":scene_min_x", 2000),
  30535. (val_sub, ":scene_max_x", 2000),
  30536. (val_add, ":scene_min_y", 2000),
  30537. (val_sub, ":scene_max_y", 2000),
  30538. (val_max, ":min_x", ":scene_min_x"),
  30539. (val_max, ":min_y", ":scene_min_y"),
  30540. (val_min, ":max_x", ":scene_max_x"),
  30541. (val_min, ":max_y", ":scene_max_y"),
  30542.  
  30543. (store_div, ":min_x_meters", ":min_x", 100),
  30544. (store_div, ":min_y_meters", ":min_y", 100),
  30545. (store_div, ":max_x_meters", ":max_x", 100),
  30546. (store_div, ":max_y_meters", ":max_y", 100),
  30547.  
  30548. (assign, ":highest_pos_z", -10000),
  30549. (copy_position, pos52, pos1),
  30550. (init_position, pos15),
  30551.  
  30552. (try_for_range, ":i_x", ":min_x_meters", ":max_x_meters"),
  30553. (store_mul, ":i_x_cm", ":i_x", 100),
  30554. (try_for_range, ":i_y", ":min_y_meters", ":max_y_meters"),
  30555. (store_mul, ":i_y_cm", ":i_y", 100),
  30556. (position_set_x, pos15, ":i_x_cm"),
  30557. (position_set_y, pos15, ":i_y_cm"),
  30558. (position_set_z, pos15, 10000),
  30559. (position_set_z_to_ground_level, pos15),
  30560. (position_get_z, ":cur_pos_z", pos15),
  30561. (try_begin),
  30562. (gt, ":cur_pos_z", ":highest_pos_z"),
  30563. (copy_position, pos52, pos15),
  30564. (assign, ":highest_pos_z", ":cur_pos_z"),
  30565. (try_end),
  30566. (try_end),
  30567. (try_end),
  30568. ]),
  30569.  
  30570. # script_select_battle_tactic
  30571. # Input: none
  30572. # Output: none
  30573. ("select_battle_tactic",
  30574. [
  30575. (assign, "$ai_team_1_battle_tactic", 0),
  30576. (get_player_agent_no, ":player_agent"),
  30577. (agent_get_team, ":player_team", ":player_agent"),
  30578. (try_begin),
  30579. (num_active_teams_le, 2),
  30580. (try_begin),
  30581. (eq, ":player_team", 0),
  30582. (assign, "$ai_team_1", 1),
  30583. (else_try),
  30584. (assign, "$ai_team_1", 0),
  30585. (try_end),
  30586. (assign, "$ai_team_2", -1),
  30587. (else_try),
  30588. (try_begin),
  30589. (eq, ":player_team", 0),
  30590. (assign, "$ai_team_1", 1),
  30591. (else_try),
  30592. (assign, "$ai_team_1", 0),
  30593. (try_end),
  30594. (store_add, "$ai_team_2", ":player_team", 2),
  30595. (try_end),
  30596. (call_script, "script_select_battle_tactic_aux", "$ai_team_1", 0),
  30597. (assign, "$ai_team_1_battle_tactic", reg0),
  30598. (try_begin),
  30599. (ge, "$ai_team_2", 0),
  30600. (assign, ":defense_not_an_option", 0),
  30601. (try_begin),
  30602. (eq, "$ai_team_1_battle_tactic", btactic_hold),
  30603. (assign, ":defense_not_an_option", 1), #don't let two AI defend at the same time
  30604. (try_end),
  30605. (call_script, "script_select_battle_tactic_aux", "$ai_team_2", ":defense_not_an_option"),
  30606. (assign, "$ai_team_2_battle_tactic", reg0),
  30607. (try_end),
  30608. ]),
  30609.  
  30610. # script_select_battle_tactic_aux
  30611. # Input: team_no
  30612. # Output: battle_tactic
  30613. ("select_battle_tactic_aux",
  30614. [
  30615. (store_script_param, ":team_no", 1),
  30616. (store_script_param, ":defense_not_an_option", 2),
  30617. (assign, ":battle_tactic", 0),
  30618. (get_player_agent_no, ":player_agent"),
  30619. (agent_get_team, ":player_team", ":player_agent"),
  30620. (try_begin),
  30621. (eq, "$cant_leave_encounter", 1),
  30622. (teams_are_enemies, ":team_no", ":player_team"),
  30623. (assign, ":defense_not_an_option", 1),
  30624. (try_end),
  30625. (call_script, "script_team_get_class_percentages", ":team_no", 0),
  30626. # (assign, ":ai_perc_infantry", reg0),
  30627. (assign, ":ai_perc_archers", reg1),
  30628. (assign, ":ai_perc_cavalry", reg2),
  30629. (call_script, "script_team_get_class_percentages", ":team_no", 1),#enemies of the ai_team
  30630. # (assign, ":enemy_perc_infantry", reg0),
  30631. # (assign, ":enemy_perc_archers", reg1),
  30632. # (assign, ":enemy_perc_cavalry", reg2),
  30633.  
  30634. (store_random_in_range, ":rand", 0, 100),
  30635. (try_begin),
  30636. (assign, ":continue", 0),
  30637. (try_begin),
  30638. (teams_are_enemies, ":team_no", ":player_team"),
  30639. (party_slot_eq, "$g_enemy_party", slot_party_type, spt_kingdom_hero_party),
  30640. (assign, ":continue", 1),
  30641. (else_try),
  30642. (neg|teams_are_enemies, ":team_no", ":player_team"),
  30643. (gt, "$g_ally_party", 0),
  30644. (party_slot_eq, "$g_ally_party", slot_party_type, spt_kingdom_hero_party),
  30645. (assign, ":continue", 1),
  30646. (try_end),
  30647. #(this_or_next|lt, ":rand", 20),
  30648. (eq, ":continue", 1),
  30649. (store_faction_of_party, ":enemy_faction_no", "$g_enemy_party"),
  30650. (neq, ":enemy_faction_no", "fac_kingdom_3"), #don't let khergits use battle tactics
  30651. (try_begin),
  30652. (eq, ":defense_not_an_option", 0),
  30653. (gt, ":ai_perc_archers", 50),
  30654. (lt, ":ai_perc_cavalry", 35),
  30655. (assign, ":battle_tactic", btactic_hold),
  30656. (else_try),
  30657. (lt, ":rand", 80),
  30658. (assign, ":battle_tactic", btactic_follow_leader),
  30659. (try_end),
  30660. (try_end),
  30661. (assign, reg0, ":battle_tactic"),
  30662. ]),
  30663.  
  30664. # script_battle_calculate_initial_powers
  30665. # Input: none
  30666. # Output: none
  30667. #("battle_calculate_initial_powers",
  30668. # [
  30669. # (try_for_agents, ":agent_no"),
  30670. # (agent_is_human, ":agent_no"),
  30671. #
  30672. # (call_script, "script_calculate_team_powers", ":agent_no"),
  30673. # (assign, ":ally_power", reg0),
  30674. # (assign, ":enemy_power", reg1),
  30675. #
  30676. # (agent_set_slot, ":agent_no", slot_agent_initial_ally_power, ":ally_power"),
  30677. # (agent_set_slot, ":agent_no", slot_agent_initial_enemy_power, ":enemy_power"),
  30678. # (try_end),
  30679. #]),
  30680.  
  30681. # script_battle_tactic_init
  30682. # Input: none
  30683. # Output: none
  30684. ("battle_tactic_init",
  30685. [
  30686. (call_script, "script_battle_tactic_init_aux", "$ai_team_1", "$ai_team_1_battle_tactic"),
  30687. (try_begin),
  30688. (ge, "$ai_team_2", 0),
  30689. (call_script, "script_battle_tactic_init_aux", "$ai_team_2", "$ai_team_2_battle_tactic"),
  30690. (try_end),
  30691.  
  30692. (try_for_agents, ":cur_agent"),
  30693. (agent_set_slot, ":cur_agent", slot_agent_is_running_away, 0), #initially nobody is running away.
  30694. (try_end),
  30695. ]),
  30696.  
  30697. # script_battle_tactic_init_aux
  30698. # Input: team_no, battle_tactic
  30699. # Output: none
  30700. ("battle_tactic_init_aux",
  30701. [
  30702. (store_script_param, ":team_no", 1),
  30703. (store_script_param, ":battle_tactic", 2),
  30704. (team_get_leader, ":ai_leader", ":team_no"),
  30705. (try_begin),
  30706. (eq, ":battle_tactic", btactic_hold),
  30707. (agent_get_position, pos1, ":ai_leader"),
  30708. (call_script, "script_find_high_ground_around_pos1", ":team_no", 30),
  30709. (copy_position, pos1, pos52),
  30710. (call_script, "script_find_high_ground_around_pos1", ":team_no", 30), # call again just in case we are not at peak point.
  30711. (copy_position, pos1, pos52),
  30712. (call_script, "script_find_high_ground_around_pos1", ":team_no", 30), # call again just in case we are not at peak point.
  30713. (team_give_order, ":team_no", grc_everyone, mordr_hold),
  30714. (team_set_order_position, ":team_no", grc_everyone, pos52),
  30715. (team_give_order, ":team_no", grc_archers, mordr_advance),
  30716. (team_give_order, ":team_no", grc_archers, mordr_advance),
  30717. (else_try),
  30718. (eq, ":battle_tactic", btactic_follow_leader),
  30719. (team_get_leader, ":ai_leader", ":team_no"),
  30720. (ge, ":ai_leader", 0),
  30721. (agent_set_speed_limit, ":ai_leader", 8),
  30722. (agent_get_position, pos60, ":ai_leader"),
  30723. (team_give_order, ":team_no", grc_everyone, mordr_hold),
  30724. (team_set_order_position, ":team_no", grc_everyone, pos60),
  30725. (try_end),
  30726. ]),
  30727.  
  30728. # script_calculate_team_powers
  30729. # Input: none
  30730. # Output: ally_power, enemy_power
  30731. ("calculate_team_powers",
  30732. [
  30733. (store_script_param, ":agent_no", 1),
  30734.  
  30735. (try_begin),
  30736. (assign, ":agent_side", 0),
  30737. (agent_is_ally, ":agent_no"),
  30738. (assign, ":agent_side", 1),
  30739. (try_end),
  30740.  
  30741. (assign, ":ally_power", 0),
  30742. (assign, ":enemy_power", 0),
  30743.  
  30744. (try_for_agents, ":cur_agent"),
  30745. (agent_is_human, ":cur_agent"),
  30746. (agent_is_alive, ":cur_agent"),
  30747.  
  30748. (try_begin),
  30749. (assign, ":agent_side_cur", 0),
  30750. (agent_is_ally, ":cur_agent"),
  30751. (assign, ":agent_side_cur", 1),
  30752. (try_end),
  30753.  
  30754. (try_begin),
  30755. (agent_get_horse, ":agent_horse_id", ":cur_agent"),
  30756. (neq, ":agent_horse_id", -1),
  30757. (assign, ":agent_power", 2), #if this agent is horseman then his power effect is 2
  30758. (else_try),
  30759. (assign, ":agent_power", 1), #if this agent is walker then his power effect is 1
  30760. (try_end),
  30761.  
  30762. (try_begin),
  30763. (eq, ":agent_side", ":agent_side_cur"),
  30764. (val_add, ":ally_power", ":agent_power"),
  30765. (else_try),
  30766. (val_add, ":enemy_power", ":agent_power"),
  30767. (try_end),
  30768. (try_end),
  30769.  
  30770. (assign, reg0, ":ally_power"),
  30771. (assign, reg1, ":enemy_power"),
  30772. ]), #ozan
  30773.  
  30774. # script_apply_effect_of_other_people_on_courage_scores
  30775. # Input: none
  30776. # Output: none
  30777. ("apply_effect_of_other_people_on_courage_scores",
  30778. [
  30779. (get_player_agent_no, ":player_agent"),
  30780.  
  30781. (try_for_agents, ":centered_agent_no"),
  30782. (agent_is_human, ":centered_agent_no"),
  30783. (agent_is_alive, ":centered_agent_no"),
  30784. (neq, ":centered_agent_no", ":player_agent"),
  30785. (agent_get_position, pos0, ":centered_agent_no"),
  30786. (try_begin),
  30787. (agent_is_ally, ":centered_agent_no"),
  30788. (assign, ":is_centered_agent_ally", 1),
  30789. (else_try),
  30790. (assign, ":is_centered_agent_ally", 0),
  30791. (try_end),
  30792.  
  30793. (try_for_agents, ":agent_no"),
  30794. (agent_is_human, ":agent_no"),
  30795. (agent_is_alive, ":agent_no"),
  30796. (neq, ":centered_agent_no", ":agent_no"),
  30797.  
  30798. (try_begin),
  30799. (agent_is_ally, ":agent_no"),
  30800. (assign, ":is_agent_ally", 1),
  30801. (else_try),
  30802. (assign, ":is_agent_ally", 0),
  30803. (try_end),
  30804.  
  30805. (eq, ":is_centered_agent_ally", ":is_agent_ally"), #if centered agent and other agent is at same team then continue.
  30806. (agent_get_slot, ":agent_is_running_away_or_not", ":agent_no", slot_agent_is_running_away),
  30807.  
  30808. (try_begin),
  30809. (eq, ":agent_no", ":player_agent"),
  30810. (assign, ":agent_delta_courage_score", 6),
  30811. (else_try),
  30812. (agent_get_troop_id, ":troop_id", ":agent_no"),
  30813. (troop_is_hero, ":troop_id"),
  30814.  
  30815. #Hero Agent : if near agent (hero, agent_no) is not running away his positive effect on centered agent (centered_agent_no) fighting at his side is effected by his hit points.
  30816. (try_begin),
  30817. (neq, ":agent_is_running_away_or_not", 1), #if agent is not running away
  30818. (store_agent_hit_points, ":agent_hit_points", ":agent_no"),
  30819. (try_begin),
  30820. (eq, ":agent_hit_points", 100),
  30821. (assign, ":agent_delta_courage_score", 6),
  30822. (else_try),
  30823. (ge, ":agent_hit_points", 75),
  30824. (assign, ":agent_delta_courage_score", 5),
  30825. (else_try),
  30826. (ge, ":agent_hit_points", 60),
  30827. (assign, ":agent_delta_courage_score", 4),
  30828. (else_try),
  30829. (ge, ":agent_hit_points", 45),
  30830. (assign, ":agent_delta_courage_score", 3),
  30831. (else_try),
  30832. (ge, ":agent_hit_points", 30),
  30833. (assign, ":agent_delta_courage_score", 2),
  30834. (else_try),
  30835. (ge, ":agent_hit_points", 15),
  30836. (assign, ":agent_delta_courage_score", 1),
  30837. (end_try),
  30838. (else_try),
  30839. (assign, ":agent_delta_courage_score", 4),
  30840. (end_try),
  30841. (else_try),
  30842. #Normal Agent : if near agent (agent_no) is not running away his positive effect on centered agent (centered_agent_no) fighting at his side is effected by his hit points.
  30843. (try_begin),
  30844. (neq, ":agent_is_running_away_or_not", 1), # if agent is not running away
  30845. (store_agent_hit_points, ":agent_hit_points", ":agent_no"),
  30846. (try_begin),
  30847. (eq, ":agent_hit_points", 100),
  30848. (assign, ":agent_delta_courage_score", 4),
  30849. (else_try),
  30850. (ge, ":agent_hit_points", 75),
  30851. (assign, ":agent_delta_courage_score", 3),
  30852. (else_try),
  30853. (ge, ":agent_hit_points", 50),
  30854. (assign, ":agent_delta_courage_score", 2),
  30855. (else_try),
  30856. (ge, ":agent_hit_points", 25),
  30857. (assign, ":agent_delta_courage_score", 1),
  30858. (try_end),
  30859. (try_begin), # to make our warrior run away easier we decrease one, because they have player_agent (+6) advantage.
  30860. (agent_is_ally, ":agent_no"),
  30861. (val_sub, ":agent_delta_courage_score", 1),
  30862. (try_end),
  30863. (else_try),
  30864. (assign, ":agent_delta_courage_score", 2),
  30865. (end_try),
  30866. (try_end),
  30867.  
  30868. (try_begin),
  30869. (neq, ":agent_is_running_away_or_not", 1),
  30870. (val_mul, ":agent_delta_courage_score", 1),
  30871. (try_begin), # centered agent not running away cannot take positive courage score from one another agent not running away.
  30872. (agent_get_slot, ":agent_is_running_away_or_not", ":centered_agent_no", slot_agent_is_running_away),
  30873. (eq, ":agent_is_running_away_or_not", 0),
  30874. (val_mul, ":agent_delta_courage_score", 0),
  30875. (try_end),
  30876. (else_try),
  30877. (try_begin),
  30878. (agent_get_slot, ":agent_is_running_away_or_not", ":agent_no", slot_agent_is_running_away),
  30879. (eq, ":agent_is_running_away_or_not", 0),
  30880. (val_mul, ":agent_delta_courage_score", -2), # running away agent fears not running away agent more.
  30881. (else_try),
  30882. (val_mul, ":agent_delta_courage_score", -1),
  30883. (try_end),
  30884. (try_end),
  30885.  
  30886. (neq, ":agent_delta_courage_score", 0),
  30887.  
  30888. (agent_get_position, pos1, ":agent_no"),
  30889. (get_distance_between_positions, ":dist", pos0, pos1),
  30890.  
  30891. (try_begin),
  30892. (ge, ":agent_delta_courage_score", 0),
  30893. (try_begin),
  30894. (lt, ":dist", 2000), #0-20 meter
  30895. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30896. (val_mul, ":agent_delta_courage_score", 50),
  30897. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30898. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30899. (else_try),
  30900. (lt, ":dist", 4000), #21-40 meter
  30901. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30902. (val_mul, ":agent_delta_courage_score", 40),
  30903. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30904. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30905. (else_try),
  30906. (lt, ":dist", 7000), #41-70 meter
  30907. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30908. (val_mul, ":agent_delta_courage_score", 30),
  30909. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30910. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30911. (else_try),
  30912. (lt, ":dist", 11000), #71-110 meter
  30913. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30914. (val_mul, ":agent_delta_courage_score", 20),
  30915. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30916. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30917. (else_try),
  30918. (lt, ":dist", 16000), # 111-160 meter, assumed that eye can see agents friendly at most 160 meters far while fighting.
  30919. # this is more than below limit (108 meters) because we hear that allies come from further.
  30920. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30921. (val_mul, ":agent_delta_courage_score", 10),
  30922. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30923. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30924. (try_end),
  30925. (else_try), # negative effect of running agent on other ally agents are lower then positive effects above, to avoid starting
  30926. (try_begin), # run away of all agents at a moment. I want to see agents running away one by one during battle, not all together.
  30927. (lt, ":dist", 200), #1-2 meter, # this would create better game play.
  30928. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30929. (val_mul, ":agent_delta_courage_score", 15),
  30930. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30931. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30932. (else_try),
  30933. (lt, ":dist", 400), #3-4 meter,
  30934. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30935. (val_mul, ":agent_delta_courage_score", 13),
  30936. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30937. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30938. (else_try),
  30939. (lt, ":dist", 600), #5-6 meter
  30940. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30941. (val_mul, ":agent_delta_courage_score", 11),
  30942. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30943. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30944. (else_try),
  30945. (lt, ":dist", 800), #7-8 meter
  30946. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30947. (val_mul, ":agent_delta_courage_score", 9),
  30948. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30949. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30950. (else_try),
  30951. (lt, ":dist", 1200), #9-12 meters
  30952. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30953. (val_mul, ":agent_delta_courage_score", 7),
  30954. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30955. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30956. (else_try),
  30957. (lt, ":dist", 2400), #13-24 meters
  30958. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30959. (val_mul, ":agent_delta_courage_score", 5),
  30960. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30961. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30962. (else_try),
  30963. (lt, ":dist", 4800), #25-48 meters
  30964. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30965. (val_mul, ":agent_delta_courage_score", 3),
  30966. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30967. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30968. (else_try),
  30969. (lt, ":dist", 9600), #49-98 meters, assumed that eye can see agents running away at most 98 meters far while fighting.
  30970. (agent_get_slot, ":agent_courage_score", ":centered_agent_no", slot_agent_courage_score),
  30971. (val_mul, ":agent_delta_courage_score", 1),
  30972. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  30973. (agent_set_slot, ":centered_agent_no", slot_agent_courage_score, ":agent_courage_score"),
  30974. (try_end),
  30975. (try_end),
  30976. (try_end),
  30977. (try_end),
  30978. ]), #ozan
  30979.  
  30980.  
  30981. # script_apply_death_effect_on_courage_scores
  30982. # Input: dead agent id, killer agent id
  30983. # Output: none
  30984. ("apply_death_effect_on_courage_scores",
  30985. [
  30986. (store_script_param, ":dead_agent_no", 1),
  30987. (store_script_param, ":killer_agent_no", 2),
  30988.  
  30989. (try_begin),
  30990. (agent_is_human, ":dead_agent_no"),
  30991.  
  30992. (try_begin),
  30993. (agent_is_ally, ":dead_agent_no"),
  30994. (assign, ":is_dead_agent_ally", 1),
  30995. (else_try),
  30996. (assign, ":is_dead_agent_ally", 0),
  30997. (try_end),
  30998.  
  30999. (agent_get_position, pos0, ":dead_agent_no"),
  31000. (assign, ":number_of_near_allies_to_dead_agent", 0),
  31001.  
  31002. (try_for_agents, ":agent_no"),
  31003. (agent_is_human, ":agent_no"),
  31004. (agent_is_alive, ":agent_no"),
  31005.  
  31006. (agent_get_position, pos1, ":agent_no"),
  31007. (get_distance_between_positions, ":dist", pos0, pos1),
  31008.  
  31009. (le, ":dist", 1300), # to count number of allies within 13 meters to dead agent.
  31010.  
  31011. (try_begin),
  31012. (agent_is_ally, ":agent_no"),
  31013. (assign, ":is_agent_ally", 1),
  31014. (else_try),
  31015. (assign, ":is_agent_ally", 0),
  31016. (try_end),
  31017.  
  31018. (try_begin),
  31019. (eq, ":is_dead_agent_ally", ":is_agent_ally"),
  31020. (val_add, ":number_of_near_allies_to_dead_agent", 1), # (number_of_near_allies_to_dead_agent) is counted because if there are
  31021. (try_end), # many allies of dead agent around him, negative courage effect become less.
  31022. (try_end),
  31023.  
  31024. (try_for_agents, ":agent_no"),
  31025. (agent_is_human, ":agent_no"),
  31026. (agent_is_alive, ":agent_no"),
  31027.  
  31028. (try_begin),
  31029. (agent_is_ally, ":agent_no"),
  31030. (assign, ":is_agent_ally", 1),
  31031. (else_try),
  31032. (assign, ":is_agent_ally", 0),
  31033. (try_end),
  31034.  
  31035. (try_begin), # each agent is effected by a killed agent positively if he is rival or negatively if he is ally.
  31036. (neq, ":is_dead_agent_ally", ":is_agent_ally"),
  31037. (assign, ":agent_delta_courage_score", 10), # if killed agent is agent of rival side, add points to fear score
  31038. (else_try),
  31039. (assign, ":agent_delta_courage_score", -15), # if killed agent is agent of our side, decrease points from fear score
  31040. (val_add, ":agent_delta_courage_score", ":number_of_near_allies_to_dead_agent"), # ":number_of_near_allies_to_dead_agent" is added because if there are many
  31041. (try_begin), # allies of dead agent around him, negative courage effect become less.
  31042. (gt, ":agent_delta_courage_score", -5),
  31043. (assign, ":agent_delta_courage_score", -5),
  31044. (try_end),
  31045.  
  31046. (agent_get_slot, ":dead_agent_was_running_away_or_not", ":dead_agent_no", slot_agent_is_running_away), #look dead agent was running away or not.
  31047. (try_begin),
  31048. (eq, ":dead_agent_was_running_away_or_not", 1),
  31049. (val_div, ":agent_delta_courage_score", 3), # if killed agent was running away his negative effect on ally courage scores become very less. This added because
  31050. (try_end), # running away agents are easily killed and courage scores become very in a running away group after a time, and
  31051. (try_end), # they do not stop running away althought they pass near a new powerfull ally party.
  31052. (agent_get_position, pos1, ":agent_no"),
  31053. (get_distance_between_positions, ":dist", pos0, pos1),
  31054.  
  31055. (try_begin),
  31056. (eq, ":killer_agent_no", ":agent_no"),
  31057. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31058. (val_mul, ":agent_delta_courage_score", 20),
  31059. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31060. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31061. (try_end),
  31062.  
  31063. (try_begin),
  31064. (lt, ":dist", 100), #0-1 meters
  31065. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31066. (val_mul, ":agent_delta_courage_score", 150),
  31067. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31068. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31069. (else_try),
  31070. (lt, ":dist", 200), #2 meters
  31071. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31072. (val_mul, ":agent_delta_courage_score", 120),
  31073. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31074. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31075. (else_try),
  31076. (lt, ":dist", 300), #3 meter
  31077. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31078. (val_mul, ":agent_delta_courage_score", 100),
  31079. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31080. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31081. (else_try),
  31082. (lt, ":dist", 400), #4 meters
  31083. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31084. (val_mul, ":agent_delta_courage_score", 90),
  31085. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31086. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31087. (else_try),
  31088. (lt, ":dist", 600), #5-6 meters
  31089. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31090. (val_mul, ":agent_delta_courage_score", 80),
  31091. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31092. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31093. (else_try),
  31094. (lt, ":dist", 800), #7-8 meters
  31095. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31096. (val_mul, ":agent_delta_courage_score", 70),
  31097. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31098. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31099. (else_try),
  31100. (lt, ":dist", 1000), #9-10 meters
  31101. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31102. (val_mul, ":agent_delta_courage_score", 60),
  31103. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31104. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31105. (else_try),
  31106. (lt, ":dist", 1500), #11-15 meter
  31107. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31108. (val_mul, ":agent_delta_courage_score", 50),
  31109. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31110. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31111. (else_try),
  31112. (lt, ":dist", 2500), #16-25 meters
  31113. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31114. (val_mul, ":agent_delta_courage_score", 40),
  31115. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31116. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31117. (else_try),
  31118. (lt, ":dist", 4000), #26-40 meters
  31119. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31120. (val_mul, ":agent_delta_courage_score", 30),
  31121. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31122. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31123. (else_try),
  31124. (lt, ":dist", 6500), #41-65 meters
  31125. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31126. (val_mul, ":agent_delta_courage_score", 20),
  31127. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31128. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31129. (else_try),
  31130. (lt, ":dist", 10000), #61-100 meters
  31131. (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
  31132. (val_mul, ":agent_delta_courage_score", 10),
  31133. (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
  31134. (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),
  31135. (try_end),
  31136. (try_end),
  31137. (try_end),
  31138. ]), #ozan
  31139.  
  31140. # script_decide_run_away_or_not
  31141. # Input: none
  31142. # Output: none
  31143. ("decide_run_away_or_not",
  31144. [
  31145. (store_script_param, ":cur_agent", 1),
  31146. (store_script_param, ":mission_time", 2),
  31147.  
  31148. (assign, ":force_retreat", 0),
  31149. (agent_get_team, ":agent_team", ":cur_agent"),
  31150. (agent_get_division, ":agent_division", ":cur_agent"),
  31151. (try_begin),
  31152. (lt, ":agent_division", 9), #static classes
  31153. (team_get_movement_order, ":agent_movement_order", ":agent_team", ":agent_division"),
  31154. (eq, ":agent_movement_order", mordr_retreat),
  31155. (assign, ":force_retreat", 1),
  31156. (try_end),
  31157.  
  31158. (agent_get_slot, ":is_cur_agent_running_away", ":cur_agent", slot_agent_is_running_away),
  31159. (try_begin),
  31160. (eq, ":is_cur_agent_running_away", 0),
  31161. (try_begin),
  31162. (eq, ":force_retreat", 1),
  31163. (agent_start_running_away, ":cur_agent"),
  31164. (agent_set_slot, ":cur_agent", slot_agent_is_running_away, 1),
  31165. (else_try),
  31166. (ge, ":mission_time", 45), #first 45 seconds anyone does not run away whatever happens.
  31167. (agent_get_slot, ":agent_courage_score", ":cur_agent", slot_agent_courage_score),
  31168. (store_agent_hit_points, ":agent_hit_points", ":cur_agent"),
  31169. (val_mul, ":agent_hit_points", 4),
  31170. (try_begin),
  31171. (agent_is_ally, ":cur_agent"),
  31172. (val_sub, ":agent_hit_points", 100), #ally agents will be more tend to run away, to make game more funnier/harder
  31173. (try_end),
  31174. (val_mul, ":agent_hit_points", 10),
  31175. (store_sub, ":start_running_away_courage_score_limit", 3500, ":agent_hit_points"),
  31176. (lt, ":agent_courage_score", ":start_running_away_courage_score_limit"), #if (courage score < 3500 - (agent hit points * 40)) and (agent is not running away) then start running away, average hit points : 50, average running away limit = 1500
  31177.  
  31178. (agent_get_troop_id, ":troop_id", ":cur_agent"), #for now do not let heroes to run away from battle
  31179. (neg|troop_is_hero, ":troop_id"),
  31180.  
  31181. (agent_start_running_away, ":cur_agent"),
  31182. (agent_set_slot, ":cur_agent", slot_agent_is_running_away, 1),
  31183. (try_end),
  31184. (else_try),
  31185. (neq, ":force_retreat", 1),
  31186. (agent_get_slot, ":agent_courage_score", ":cur_agent", slot_agent_courage_score),
  31187. (store_agent_hit_points, ":agent_hit_points", ":cur_agent"),
  31188. (val_mul, ":agent_hit_points", 4),
  31189. (try_begin),
  31190. (agent_is_ally, ":cur_agent"),
  31191. (val_sub, ":agent_hit_points", 100), #ally agents will be more tend to run away, to make game more funnier/harder
  31192. (try_end),
  31193. (val_mul, ":agent_hit_points", 10),
  31194. (store_sub, ":stop_running_away_courage_score_limit", 3700, ":agent_hit_points"),
  31195. (ge, ":agent_courage_score", ":stop_running_away_courage_score_limit"), #if (courage score > 3700 - agent hit points) and (agent is running away) then stop running away, average hit points : 50, average running away limit = 1700
  31196. (agent_stop_running_away, ":cur_agent"),
  31197. (agent_set_slot, ":cur_agent", slot_agent_is_running_away, 0),
  31198. (try_end),
  31199. ]), #ozan
  31200.  
  31201. # script_battle_tactic_apply
  31202. # Input: none
  31203. # Output: none
  31204. ("battle_tactic_apply",
  31205. [
  31206. (call_script, "script_battle_tactic_apply_aux", "$ai_team_1", "$ai_team_1_battle_tactic"),
  31207. (assign, "$ai_team_1_battle_tactic", reg0),
  31208. (try_begin),
  31209. (ge, "$ai_team_2", 0),
  31210. (call_script, "script_battle_tactic_apply_aux", "$ai_team_2", "$ai_team_2_battle_tactic"),
  31211. (assign, "$ai_team_2_battle_tactic", reg0),
  31212. (try_end),
  31213. ]),
  31214.  
  31215. # script_battle_tactic_apply_aux
  31216. # Input: team_no, battle_tactic
  31217. # Output: battle_tactic
  31218. ("battle_tactic_apply_aux",
  31219. [
  31220. (store_script_param, ":team_no", 1),
  31221. (store_script_param, ":battle_tactic", 2),
  31222. (store_mission_timer_a, ":mission_time"),
  31223. (try_begin),
  31224. (eq, ":battle_tactic", btactic_hold),
  31225. (copy_position, pos1, pos52),
  31226. (call_script, "script_get_closest3_distance_of_enemies_at_pos1", ":team_no", 1),
  31227. (assign, ":avg_dist", reg0),
  31228. (assign, ":min_dist", reg1),
  31229. (try_begin),
  31230. (this_or_next|lt, ":min_dist", 1000),
  31231. (lt, ":avg_dist", 4000),
  31232. (assign, ":battle_tactic", 0),
  31233. (team_give_order, ":team_no", grc_everyone, mordr_charge),
  31234. (try_end),
  31235. (else_try),
  31236. (eq, ":battle_tactic", btactic_follow_leader),
  31237. (team_get_leader, ":ai_leader", ":team_no"),
  31238. (try_begin),
  31239. (ge, ":ai_leader", 0),
  31240. (agent_is_alive, ":ai_leader"),
  31241. (agent_set_speed_limit, ":ai_leader", 9),
  31242. (call_script, "script_team_get_average_position_of_enemies", ":team_no"),
  31243. (copy_position, pos60, pos0),
  31244. (agent_get_position, pos61, ":ai_leader"),
  31245. (position_transform_position_to_local, pos62, pos61, pos60), #pos62 = vector to enemy w.r.t leader
  31246. (position_normalize_origin, ":distance_to_enemy", pos62),
  31247. (convert_from_fixed_point, ":distance_to_enemy"),
  31248. (assign, reg17, ":distance_to_enemy"),
  31249. (position_get_x, ":dir_x", pos62),
  31250. (position_get_y, ":dir_y", pos62),
  31251. (val_mul, ":dir_x", 23),
  31252. (val_mul, ":dir_y", 23), #move 23 meters
  31253. (position_set_x, pos62, ":dir_x"),
  31254. (position_set_y, pos62, ":dir_y"),
  31255.  
  31256. (position_transform_position_to_parent, pos63, pos61, pos62), #pos63 is 23m away from leader in the direction of the enemy.
  31257. (position_set_z_to_ground_level, pos63),
  31258.  
  31259. (team_give_order, ":team_no", grc_everyone, mordr_hold),
  31260. (team_set_order_position, ":team_no", grc_everyone, pos63),
  31261. (agent_get_position, pos1, ":ai_leader"),
  31262. (try_begin),
  31263. (lt, ":distance_to_enemy", 50),
  31264. (ge, ":mission_time", 30),
  31265. (assign, ":battle_tactic", 0),
  31266. (team_give_order, ":team_no", grc_everyone, mordr_charge),
  31267. (agent_set_speed_limit, ":ai_leader", 60),
  31268. (try_end),
  31269. (else_try),
  31270. (assign, ":battle_tactic", 0),
  31271. (team_give_order, ":team_no", grc_everyone, mordr_charge),
  31272. (try_end),
  31273. (try_end),
  31274.  
  31275. (try_begin), # charge everyone after a while
  31276. (neq, ":battle_tactic", 0),
  31277. (ge, ":mission_time", 300),
  31278. (assign, ":battle_tactic", 0),
  31279. (team_give_order, ":team_no", grc_everyone, mordr_charge),
  31280. (team_get_leader, ":ai_leader", ":team_no"),
  31281. (agent_set_speed_limit, ":ai_leader", 60),
  31282. (try_end),
  31283. (assign, reg0, ":battle_tactic"),
  31284. ]),
  31285.  
  31286.  
  31287. ## # script_siege_defender_tactic_apply
  31288. ## # Input: none
  31289. ## # Output: none
  31290. ## ("siege_defender_tactic_apply",
  31291. ## [
  31292. ## (try_begin),
  31293. ## (eq, "$defender_team", 1),
  31294. ## (ge, "$belfry_positioned", 2),
  31295. ##
  31296. ## (assign, ":enemy_too_weak", 0),
  31297. ## (try_begin),
  31298. ## (ge, "$attacker_reinforcement_stage", 2),
  31299. ## (call_script, "script_calculate_team_strength", "$defender_team"),
  31300. ## (assign, ":defender_strength", reg0),
  31301. ## (call_script, "script_calculate_team_strength", "$attacker_team"),
  31302. ## (assign, ":attacker_strength", reg0),
  31303. ## (store_mul, ":attacker_strength_multiplied", ":attacker_strength", 2),
  31304. ## (ge, ":defender_strength", ":attacker_strength_multiplied"),
  31305. ## (assign, ":enemy_too_weak", 1),
  31306. ## (try_end),
  31307. ##
  31308. ## (try_begin),
  31309. ## (eq, ":enemy_too_weak", 1),
  31310. ## (neq, "$ai_battle_tactic", btactic_charge),
  31311. ## (assign, "$ai_battle_tactic", btactic_charge),
  31312. ## (team_give_order, "$defender_team", grc_infantry, mordr_charge),
  31313. ## (else_try),
  31314. ## (neq, "$ai_battle_tactic", btactic_charge),
  31315. ## (neq, "$ai_battle_tactic", btactic_hold),
  31316. ## (assign, "$ai_battle_tactic", btactic_hold),
  31317. ## (team_give_order, "$defender_team", grc_infantry, mordr_hold),
  31318. ## (team_give_order, "$defender_team", grc_heroes, mordr_hold),
  31319. ## (entry_point_get_position,pos1,10),
  31320. ## (team_set_order_position, "$defender_team", grc_infantry, pos1),
  31321. ## (team_set_order_position, "$defender_team", grc_heroes, pos1),
  31322. ## (try_end),
  31323. ## (try_end),
  31324. ## ]),
  31325.  
  31326.  
  31327. # script_team_get_class_percentages
  31328. # Input: arg1: team_no, arg2: try for team's enemies
  31329. # Output: reg0: percentage infantry, reg1: percentage archers, reg2: percentage cavalry
  31330. ("team_get_class_percentages",
  31331. [
  31332. (assign, ":num_infantry", 0),
  31333. (assign, ":num_archers", 0),
  31334. (assign, ":num_cavalry", 0),
  31335. (assign, ":num_total", 0),
  31336. (store_script_param, ":team_no", 1),
  31337. (store_script_param, ":negate", 2),
  31338. (try_for_agents,":cur_agent"),
  31339. (agent_is_alive, ":cur_agent"),
  31340. (agent_is_human, ":cur_agent"),
  31341. (agent_get_team, ":agent_team", ":cur_agent"),
  31342. (assign, ":continue", 0),
  31343. (try_begin),
  31344. (eq, ":negate", 1),
  31345. (teams_are_enemies, ":agent_team", ":team_no"),
  31346. (assign, ":continue", 1),
  31347. (else_try),
  31348. (eq, ":agent_team", ":team_no"),
  31349. (assign, ":continue", 1),
  31350. (try_end),
  31351. (eq, ":continue", 1),
  31352. (val_add, ":num_total", 1),
  31353. (agent_get_class, ":agent_class", ":cur_agent"),
  31354. (try_begin),
  31355. (eq, ":agent_class", grc_infantry),
  31356. (val_add, ":num_infantry", 1),
  31357. (else_try),
  31358. (eq, ":agent_class", grc_archers),
  31359. (val_add, ":num_archers", 1),
  31360. (else_try),
  31361. (eq, ":agent_class", grc_cavalry),
  31362. (val_add, ":num_cavalry", 1),
  31363. (try_end),
  31364. (try_end),
  31365. (try_begin),
  31366. (eq, ":num_total", 0),
  31367. (assign, ":num_total", 1),
  31368. (try_end),
  31369. (store_mul, ":perc_infantry",":num_infantry",100),
  31370. (val_div, ":perc_infantry",":num_total"),
  31371. (store_mul, ":perc_archers",":num_archers",100),
  31372. (val_div, ":perc_archers",":num_total"),
  31373. (store_mul, ":perc_cavalry",":num_cavalry",100),
  31374. (val_div, ":perc_cavalry",":num_total"),
  31375. (assign, reg0, ":perc_infantry"),
  31376. (assign, reg1, ":perc_archers"),
  31377. (assign, reg2, ":perc_cavalry"),
  31378. ]),
  31379.  
  31380. # script_get_closest3_distance_of_enemies_at_pos1
  31381. # Input: arg1: team_no, pos1
  31382. # Output: reg0: distance in cms.
  31383. ("get_closest3_distance_of_enemies_at_pos1",
  31384. [
  31385. (assign, ":min_distance_1", 100000),
  31386. (assign, ":min_distance_2", 100000),
  31387. (assign, ":min_distance_3", 100000),
  31388.  
  31389. (store_script_param, ":team_no", 1),
  31390. (try_for_agents,":cur_agent"),
  31391. (agent_is_alive, ":cur_agent"),
  31392. (agent_is_human, ":cur_agent"),
  31393. (agent_get_team, ":agent_team", ":cur_agent"),
  31394. (teams_are_enemies, ":agent_team", ":team_no"),
  31395.  
  31396. (agent_get_position, pos2, ":cur_agent"),
  31397. (get_distance_between_positions,":cur_dist",pos2,pos1),
  31398. (try_begin),
  31399. (lt, ":cur_dist", ":min_distance_1"),
  31400. (assign, ":min_distance_3", ":min_distance_2"),
  31401. (assign, ":min_distance_2", ":min_distance_1"),
  31402. (assign, ":min_distance_1", ":cur_dist"),
  31403. (else_try),
  31404. (lt, ":cur_dist", ":min_distance_2"),
  31405. (assign, ":min_distance_3", ":min_distance_2"),
  31406. (assign, ":min_distance_2", ":cur_dist"),
  31407. (else_try),
  31408. (lt, ":cur_dist", ":min_distance_3"),
  31409. (assign, ":min_distance_3", ":cur_dist"),
  31410. (try_end),
  31411. (try_end),
  31412.  
  31413. (assign, ":total_distance", 0),
  31414. (assign, ":total_count", 0),
  31415. (try_begin),
  31416. (lt, ":min_distance_1", 100000),
  31417. (val_add, ":total_distance", ":min_distance_1"),
  31418. (val_add, ":total_count", 1),
  31419. (try_end),
  31420. (try_begin),
  31421. (lt, ":min_distance_2", 100000),
  31422. (val_add, ":total_distance", ":min_distance_2"),
  31423. (val_add, ":total_count", 1),
  31424. (try_end),
  31425. (try_begin),
  31426. (lt, ":min_distance_3", 100000),
  31427. (val_add, ":total_distance", ":min_distance_3"),
  31428. (val_add, ":total_count", 1),
  31429. (try_end),
  31430. (assign, ":average_distance", 100000),
  31431. (try_begin),
  31432. (gt, ":total_count", 0),
  31433. (store_div, ":average_distance", ":total_distance", ":total_count"),
  31434. (try_end),
  31435. (assign, reg0, ":average_distance"),
  31436. (assign, reg1, ":min_distance_1"),
  31437. (assign, reg2, ":min_distance_2"),
  31438. (assign, reg3, ":min_distance_3"),
  31439. ]),
  31440.  
  31441. # script_team_get_average_position_of_enemies
  31442. # Input: arg1: team_no,
  31443. # Output: pos0: average position.
  31444. ("team_get_average_position_of_enemies",
  31445. [
  31446. (store_script_param_1, ":team_no"),
  31447. (init_position, pos0),
  31448. (assign, ":num_enemies", 0),
  31449. (assign, ":accum_x", 0),
  31450. (assign, ":accum_y", 0),
  31451. (assign, ":accum_z", 0),
  31452. (try_for_agents,":enemy_agent"),
  31453. (agent_is_alive, ":enemy_agent"),
  31454. (agent_is_human, ":enemy_agent"),
  31455. (agent_get_team, ":enemy_team", ":enemy_agent"),
  31456. (teams_are_enemies, ":team_no", ":enemy_team"),
  31457.  
  31458. (agent_get_position, pos62, ":enemy_agent"),
  31459.  
  31460. (position_get_x, ":x", pos62),
  31461. (position_get_y, ":y", pos62),
  31462. (position_get_z, ":z", pos62),
  31463.  
  31464. (val_add, ":accum_x", ":x"),
  31465. (val_add, ":accum_y", ":y"),
  31466. (val_add, ":accum_z", ":z"),
  31467. (val_add, ":num_enemies", 1),
  31468. (try_end),
  31469.  
  31470. (try_begin), #to avoid division by zeros at below division part.
  31471. (le, ":num_enemies", 0),
  31472. (assign, ":num_enemies", 1),
  31473. (try_end),
  31474.  
  31475. (store_div, ":average_x", ":accum_x", ":num_enemies"),
  31476. (store_div, ":average_y", ":accum_y", ":num_enemies"),
  31477. (store_div, ":average_z", ":accum_z", ":num_enemies"),
  31478.  
  31479. (position_set_x, pos0, ":average_x"),
  31480. (position_set_y, pos0, ":average_y"),
  31481. (position_set_z, pos0, ":average_z"),
  31482.  
  31483. (assign, reg0, ":num_enemies"),
  31484. ]),
  31485.  
  31486.  
  31487. # script_search_troop_prisoner_of_party
  31488. # Input: arg1 = troop_no
  31489. # Output: reg0 = party_no (-1 if troop is not a prisoner.)
  31490. ("search_troop_prisoner_of_party",
  31491. [
  31492. (store_script_param_1, ":troop_no"),
  31493. (assign, ":prisoner_of", -1),
  31494. (try_for_parties, ":party_no"),
  31495. (eq, ":prisoner_of", -1),
  31496. (this_or_next|eq, ":party_no", "p_main_party"),
  31497. (ge, ":party_no", centers_begin),
  31498. (party_count_prisoners_of_type, ":troop_found", ":party_no", ":troop_no"),
  31499. (gt, ":troop_found", 0),
  31500. (assign, ":prisoner_of", ":party_no"),
  31501. (try_end),
  31502. (assign, reg0, ":prisoner_of"),
  31503. ]),
  31504.  
  31505.  
  31506. ## # script_clear_last_quest
  31507. ## # Input: arg1 = troop_no
  31508. ## # Output: none
  31509. ## ("clear_last_quest",
  31510. ## [
  31511. ## (store_script_param_1, ":troop_no"),
  31512. ##
  31513. ## (troop_set_slot, ":troop_no",slot_troop_last_quest, 0),
  31514. ## (troop_set_slot, ":troop_no",slot_troop_last_quest_betrayed, 0)
  31515. ## ]),
  31516.  
  31517.  
  31518.  
  31519. # script_change_debt_to_troop
  31520. # Input: arg1 = troop_no, arg2 = new debt amount
  31521. # Output: none
  31522. ("change_debt_to_troop",
  31523. [
  31524. (store_script_param_1, ":troop_no"),
  31525. (store_script_param_2, ":new_debt"),
  31526.  
  31527. (troop_get_slot, ":cur_debt", ":troop_no", slot_troop_player_debt),
  31528. (assign, reg1, ":cur_debt"),
  31529. (val_add, ":cur_debt", ":new_debt"),
  31530. (assign, reg2, ":cur_debt"),
  31531. (troop_set_slot, ":troop_no", slot_troop_player_debt, ":cur_debt"),
  31532. (try_begin), #SB : display only if > 0
  31533. (gt, ":cur_debt", 0),
  31534. (str_store_troop_name_link, s1, ":troop_no"),
  31535. (display_message, "@You now owe {reg2} denars to {s1}.", message_negative),
  31536. (try_end),
  31537. ]),
  31538.  
  31539.  
  31540.  
  31541.  
  31542. # script_abort_quest
  31543. # Input: arg1 = quest_no, arg2 = apply relation penalty
  31544. # Output: none
  31545. ("abort_quest",
  31546. [
  31547. (store_script_param_1, ":quest_no"),
  31548. (store_script_param_2, ":abort_type"), #0=aborted by event, 1=abort by talking 2=abort by expire
  31549.  
  31550. (assign, ":quest_return_penalty", -1),
  31551. (assign, ":quest_expire_penalty", -2),
  31552.  
  31553. # (quest_get_slot, ":quest_object_troop", ":quest_no", slot_quest_object_troop),
  31554. (try_begin),
  31555. (this_or_next|eq, ":quest_no", "qst_deliver_message"),
  31556. (eq, ":quest_no", "qst_deliver_message_to_enemy_lord"),
  31557. (assign, ":quest_return_penalty", -2),
  31558. (assign, ":quest_expire_penalty", -3),
  31559. (else_try),
  31560. (eq, ":quest_no", "qst_kidnapped_girl"),
  31561. (party_remove_members, "p_main_party", "trp_kidnapped_girl", 1),
  31562. (quest_get_slot, ":quest_target_party", "qst_kidnapped_girl", slot_quest_target_party),
  31563. (try_begin),
  31564. (party_is_active, ":quest_target_party"),
  31565. (remove_party, ":quest_target_party"),
  31566. (try_end),
  31567. (else_try),
  31568. (eq, ":quest_no", "qst_escort_lady"),
  31569. (quest_get_slot, ":quest_object_troop", "qst_escort_lady", slot_quest_object_troop),
  31570. (party_remove_members, "p_main_party", ":quest_object_troop", 1),
  31571. (assign, ":quest_return_penalty", -2),
  31572. (assign, ":quest_expire_penalty", -3),
  31573. ## (else_try),
  31574. ## (eq, ":quest_no", "qst_rescue_lady_under_siege"),
  31575. ## (party_remove_members, "p_main_party", ":quest_object_troop", 1),
  31576. ## (else_try),
  31577. ## (eq, ":quest_no", "qst_deliver_message_to_lover"),
  31578. ## (else_try),
  31579. ## (eq, ":quest_no", "qst_bring_prisoners_to_enemy"),
  31580. ## (try_begin),
  31581. ## (check_quest_succeeded, ":quest_no"),
  31582. ## (quest_get_slot, ":quest_target_amount", ":quest_no", slot_quest_target_amount),
  31583. ## (quest_get_slot, ":quest_object_troop", ":quest_no", slot_quest_object_troop),
  31584. ## (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  31585. ## (call_script, "script_game_get_join_cost", ":quest_object_troop"),
  31586. ## (assign, ":reward", reg0),
  31587. ## (val_mul, ":reward", ":quest_target_amount"),
  31588. ## (val_div, ":reward", 2),
  31589. ## (else_try),
  31590. ## (quest_get_slot, ":reward", ":quest_no", slot_quest_target_amount),
  31591. ## (try_end),
  31592. ## (call_script, "script_change_debt_to_troop", ":quest_giver_troop", ":reward"),
  31593. ## (else_try),
  31594. ## (eq, ":quest_no", "qst_bring_reinforcements_to_siege"),
  31595. ## (quest_get_slot, ":quest_target_amount", ":quest_no", slot_quest_target_amount),
  31596. ## (quest_get_slot, ":quest_object_troop", ":quest_no", slot_quest_object_troop),
  31597. ## (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  31598. ## (call_script, "script_game_get_join_cost", ":quest_object_troop"),
  31599. ## (assign, ":reward", reg0),
  31600. ## (val_mul, ":reward", ":quest_target_amount"),
  31601. ## (val_mul, ":reward", 2),
  31602. ## (call_script, "script_change_debt_to_troop", ":quest_giver_troop", ":reward"),
  31603. ## (else_try),
  31604. ## (eq, ":quest_no", "qst_deliver_supply_to_center_under_siege"),
  31605. ## (quest_get_slot, ":quest_target_amount", ":quest_no", slot_quest_target_amount),
  31606. ## (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  31607. ## (store_item_value, ":reward", "itm_siege_supply"),
  31608. ## (val_mul, ":reward", ":quest_target_amount"),
  31609. ## (call_script, "script_change_debt_to_troop", ":quest_giver_troop", ":reward"),
  31610. (else_try),
  31611. (eq, ":quest_no", "qst_raise_troops"),
  31612. (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  31613. (call_script, "script_change_debt_to_troop", ":quest_giver_troop", 100),
  31614. (assign, ":quest_return_penalty", -4),
  31615. (assign, ":quest_expire_penalty", -5),
  31616. (else_try),
  31617. (eq, ":quest_no", "qst_deal_with_looters"),
  31618. (try_for_parties, ":cur_party_no"),
  31619. (party_get_template_id, ":cur_party_template", ":cur_party_no"),
  31620. (eq, ":cur_party_template", "pt_looters"),
  31621. (party_set_flags, ":cur_party_no", pf_quest_party, 0),
  31622. (try_end),
  31623. (assign, ":quest_return_penalty", -4),
  31624. (assign, ":quest_expire_penalty", -5),
  31625. (else_try),
  31626. (eq, ":quest_no", "qst_deal_with_bandits_at_lords_village"),
  31627. (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  31628. (call_script, "script_change_debt_to_troop", ":quest_giver_troop", 200),
  31629. (assign, ":quest_return_penalty", -5),
  31630. (assign, ":quest_expire_penalty", -6),
  31631. (else_try),
  31632. (eq, ":quest_no", "qst_collect_taxes"),
  31633. (quest_get_slot, ":gold_reward", ":quest_no", slot_quest_gold_reward),
  31634. (quest_set_slot, ":quest_no", slot_quest_gold_reward, 0),
  31635. (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  31636. (call_script, "script_change_debt_to_troop", ":quest_giver_troop", ":gold_reward"),
  31637. (assign, ":quest_return_penalty", -4),
  31638. (assign, ":quest_expire_penalty", -6),
  31639. ## (else_try),
  31640. ## (eq, ":quest_no", "qst_capture_messenger"),
  31641. ## (else_try),
  31642. ## (eq, ":quest_no", "qst_bring_back_deserters"),
  31643. (else_try),
  31644. (eq, ":quest_no", "qst_hunt_down_fugitive"),
  31645. (assign, ":quest_return_penalty", -3),
  31646. (assign, ":quest_expire_penalty", -4),
  31647. #SB : remove prisoner if player kept it intentionally
  31648. (party_remove_prisoners, "p_main_party", "trp_fugitive", 1),
  31649. (else_try),
  31650. (eq, ":quest_no", "qst_kill_local_merchant"),
  31651. (else_try),
  31652. (eq, ":quest_no", "qst_bring_back_runaway_serfs"),
  31653. (assign, ":quest_return_penalty", -1),
  31654. (assign, ":quest_expire_penalty", -1),
  31655. (else_try),
  31656. (eq, ":quest_no", "qst_collect_debt"),
  31657. (try_begin),
  31658. (quest_slot_eq, "qst_collect_debt", slot_quest_current_state, 1), #debt collected but not delivered
  31659. (quest_get_slot, ":debt", "qst_collect_debt", slot_quest_target_amount),
  31660. (quest_get_slot, ":quest_giver", "qst_collect_debt", slot_quest_giver_troop),
  31661. (call_script, "script_change_debt_to_troop", ":quest_giver", ":debt"),
  31662. (assign, ":quest_return_penalty", -3),
  31663. (assign, ":quest_expire_penalty", -6),
  31664. (else_try),
  31665. (assign, ":quest_return_penalty", -3),
  31666. (assign, ":quest_expire_penalty", -4),
  31667. (try_end),
  31668. (else_try),
  31669. (eq, ":quest_no", "qst_deal_with_bandits_at_lords_village"),
  31670. (assign, ":quest_return_penalty", -6),
  31671. (assign, ":quest_expire_penalty", -6),
  31672. (else_try),
  31673. (eq, ":quest_no", "qst_cause_provocation"),
  31674. (assign, ":quest_return_penalty", -10),
  31675. (assign, ":quest_expire_penalty", -13),
  31676. (else_try),
  31677. (eq, ":quest_no", "qst_persuade_lords_to_make_peace"),
  31678. (assign, ":quest_return_penalty", -10),
  31679. (assign, ":quest_expire_penalty", -13),
  31680. (else_try),
  31681. (eq, ":quest_no", "qst_deal_with_night_bandits"),
  31682. (assign, ":quest_return_penalty", -1),
  31683. (assign, ":quest_expire_penalty", -1),
  31684.  
  31685. (else_try),
  31686. (eq, ":quest_no", "qst_follow_spy"),
  31687. (assign, ":quest_return_penalty", -2),
  31688. (assign, ":quest_expire_penalty", -3),
  31689. (try_begin),
  31690. (party_is_active, "$qst_follow_spy_spy_party"),
  31691. (remove_party, "$qst_follow_spy_spy_party"),
  31692. (try_end),
  31693. (try_begin),
  31694. (party_is_active, "$qst_follow_spy_spy_partners_party"),
  31695. (remove_party, "$qst_follow_spy_spy_partners_party"),
  31696. (try_end),
  31697. (else_try),
  31698. (eq, ":quest_no", "qst_capture_enemy_hero"),
  31699. (assign, ":quest_return_penalty", -3),
  31700. (assign, ":quest_expire_penalty", -4),
  31701. (else_try),
  31702. (eq, ":quest_no", "qst_lend_companion"),
  31703. (quest_get_slot, ":quest_target_troop", "qst_lend_companion", slot_quest_target_troop),
  31704. (troop_set_slot, ":quest_target_troop", slot_troop_current_mission, npc_mission_rejoin_when_possible),
  31705. (troop_set_slot, ":quest_target_troop", slot_troop_days_on_mission, 0),
  31706. (else_try),
  31707. (eq, ":quest_no", "qst_lend_surgeon"),
  31708. (quest_get_slot, ":quest_target_troop", "qst_lend_surgeon", slot_quest_target_troop),
  31709. (troop_set_slot, ":quest_target_troop", slot_troop_current_mission, npc_mission_rejoin_when_possible),
  31710. (troop_set_slot, ":quest_target_troop", slot_troop_days_on_mission, 0),
  31711. ## (else_try),
  31712. ## (eq, ":quest_no", "qst_lend_companion"),
  31713. ## (quest_get_slot, ":quest_target_troop", "qst_lend_companion", slot_quest_target_troop),
  31714. ## (party_add_members, "p_main_party", ":quest_target_troop", 1),
  31715. ## (else_try),
  31716. ## (eq, ":quest_no", "qst_capture_conspirators"),
  31717. ## (else_try),
  31718. ## (eq, ":quest_no", "qst_defend_nobles_against_peasants"),
  31719. (else_try),
  31720. (eq, ":quest_no", "qst_incriminate_loyal_commander"),
  31721. (assign, ":quest_return_penalty", -5),
  31722. (assign, ":quest_expire_penalty", -6),
  31723. ## (else_try),
  31724. ## (eq, ":quest_no", "qst_hunt_down_raiders"),
  31725. ## (else_try),
  31726. ## (eq, ":quest_no", "qst_capture_prisoners"),
  31727. ## #Enemy lord quests
  31728. (else_try),
  31729. (eq, ":quest_no", "qst_lend_surgeon"),
  31730.  
  31731. #Kingdom lady quests
  31732. (else_try),
  31733. (eq, ":quest_no", "qst_rescue_lord_by_replace"),
  31734. (assign, ":quest_return_penalty", -1),
  31735. (assign, ":quest_expire_penalty", -1),
  31736. (else_try),
  31737. (eq, ":quest_no", "qst_deliver_message_to_prisoner_lord"),
  31738. (assign, ":quest_return_penalty", 0),
  31739. (assign, ":quest_expire_penalty", -1),
  31740. (else_try),
  31741. (eq, ":quest_no", "qst_duel_for_lady"),
  31742. (assign, ":quest_return_penalty", -1),
  31743. (assign, ":quest_expire_penalty", -1),
  31744.  
  31745. #Kingdom Army quests
  31746. (else_try),
  31747. (eq, ":quest_no", "qst_follow_army"),
  31748. (assign, ":quest_return_penalty", 0), #was -4
  31749. (assign, ":quest_expire_penalty", 0), #was -5
  31750. (else_try),
  31751. (eq, ":quest_no", "qst_deliver_cattle_to_army"),
  31752. (assign, ":quest_return_penalty", 0),
  31753. (assign, ":quest_expire_penalty", 0),
  31754. (else_try),
  31755. (eq, ":quest_no", "qst_join_siege_with_army"),
  31756. (assign, ":quest_return_penalty", -1),
  31757. (assign, ":quest_expire_penalty", -2),
  31758. (else_try),
  31759. (eq, ":quest_no", "qst_scout_waypoints"),
  31760. (assign, ":quest_return_penalty", 0),
  31761. (assign, ":quest_expire_penalty", 0),
  31762.  
  31763. #Village Elder quests
  31764. (else_try),
  31765. (eq, ":quest_no", "qst_deliver_grain"),
  31766. (assign, ":quest_return_penalty", -6),
  31767. (assign, ":quest_expire_penalty", -7),
  31768. (else_try),
  31769. (eq, ":quest_no", "qst_deliver_cattle"),
  31770. (assign, ":quest_return_penalty", -3),
  31771. (assign, ":quest_expire_penalty", -4),
  31772. (else_try),
  31773. (eq, ":quest_no", "qst_train_peasants_against_bandits"),
  31774. (assign, ":quest_return_penalty", -4),
  31775. (assign, ":quest_expire_penalty", -5),
  31776.  
  31777. #Mayor quests
  31778. (else_try),
  31779. (eq, ":quest_no", "qst_deliver_wine"),
  31780. (assign, ":quest_return_penalty", -1),
  31781. (assign, ":quest_expire_penalty", -3),
  31782. #SB : recalculate here
  31783. (quest_get_slot, ":quest_target_item", ":quest_no", slot_quest_target_item),
  31784. (quest_get_slot, ":quest_target_amount", ":quest_no", slot_quest_target_amount),
  31785. (store_item_value,":qst_deliver_wine_debt",":quest_target_item"),
  31786. (item_get_max_ammo, ":max_amount", ":quest_target_item"),
  31787. (val_mul,":qst_deliver_wine_debt",":quest_target_amount"),
  31788. (val_mul,":qst_deliver_wine_debt", 6),
  31789. (val_div,":qst_deliver_wine_debt", 5),
  31790. (val_div, ":qst_deliver_wine_debt", ":max_amount"),
  31791. (val_add, "$debt_to_merchants_guild", ":qst_deliver_wine_debt"),
  31792. (else_try),
  31793. (eq, ":quest_no", "qst_move_cattle_herd"),
  31794. (assign, ":quest_return_penalty", -1),
  31795. (assign, ":quest_expire_penalty", -3),
  31796. (else_try),
  31797. (eq, ":quest_no", "qst_escort_merchant_caravan"),
  31798. (assign, ":quest_return_penalty", -1),
  31799. (assign, ":quest_expire_penalty", -3),
  31800. (else_try),
  31801. (eq, ":quest_no", "qst_troublesome_bandits"),
  31802. (assign, ":quest_return_penalty", -1),
  31803. (assign, ":quest_expire_penalty", -2),
  31804. #Other quests
  31805. (else_try),
  31806. (eq, ":quest_no", "qst_join_faction"),
  31807. (assign, ":quest_return_penalty", -3),
  31808. (assign, ":quest_expire_penalty", -3),
  31809. (try_begin),
  31810. (call_script, "script_get_number_of_hero_centers", "trp_player"),
  31811. (gt, reg0, 0),
  31812. (call_script, "script_change_player_relation_with_faction", "$g_invite_faction", -10),
  31813. (try_end),
  31814.  
  31815.  
  31816. (try_begin), #if the vassalage is part of a surrender option, then the faction returns to a state of war
  31817. (quest_slot_eq, "qst_join_faction", slot_quest_failure_consequence, 1),
  31818. (call_script, "script_diplomacy_start_war_between_kingdoms", "fac_player_supporters_faction", "$g_invite_faction", 0),
  31819. (call_script, "script_change_player_honor", -5),
  31820. (quest_set_slot, "qst_join_faction", slot_quest_failure_consequence, 0),
  31821. (try_end),
  31822.  
  31823.  
  31824. (assign, "$g_invite_faction", 0),
  31825. (assign, "$g_invite_faction_lord", 0),
  31826. (assign, "$g_invite_offered_center", 0),
  31827. (else_try),
  31828. (eq, ":quest_no", "qst_eliminate_bandits_infesting_village"),
  31829. (assign, ":quest_return_penalty", -3),
  31830. (assign, ":quest_expire_penalty", -3),
  31831. (else_try),
  31832. (ge, ":quest_no", "qst_resolve_dispute"),
  31833. (assign, ":authority_loss", -2),
  31834. (assign, ":quest_return_penalty", 0),
  31835. (assign, ":quest_expire_penalty", 0),
  31836. (else_try),
  31837. (ge, ":quest_no", "qst_consult_with_minister"),
  31838. (assign, ":authority_loss", -2),
  31839. (assign, ":quest_return_penalty", 0),
  31840. (assign, ":quest_expire_penalty", 0),
  31841. (try_end),
  31842.  
  31843. (try_begin),
  31844. (gt, ":abort_type", 0),
  31845. (lt, ":quest_no", "qst_resolve_dispute"),
  31846.  
  31847. (quest_get_slot, ":quest_giver", ":quest_no", slot_quest_giver_troop),
  31848. (assign, ":relation_penalty", ":quest_return_penalty"),
  31849. (try_begin),
  31850. (eq, ":abort_type", 2),
  31851. (assign, ":relation_penalty", ":quest_expire_penalty"),
  31852. (try_end),
  31853. (try_begin),
  31854. (this_or_next|is_between, ":quest_giver", village_elders_begin, village_elders_end),
  31855. (is_between, ":quest_giver", mayors_begin, mayors_end),
  31856. (quest_get_slot, ":quest_giver_center", ":quest_no", slot_quest_giver_center),
  31857. (call_script, "script_change_player_relation_with_center", ":quest_giver_center", ":relation_penalty"),
  31858. (else_try),
  31859. (call_script, "script_change_player_relation_with_troop", ":quest_giver", ":relation_penalty"),
  31860. (try_end),
  31861. (try_end),
  31862.  
  31863. (fail_quest, ":quest_no"),
  31864.  
  31865. #NPC companion changes begin
  31866. (try_begin),
  31867. (gt, ":abort_type", 0),
  31868. (neq, ":quest_no", "qst_consult_with_minister"),
  31869. (neq, ":quest_no", "qst_resolve_dispute"),
  31870. (neq, ":quest_no", "qst_visit_lady"),
  31871. (neq, ":quest_no", "qst_formal_marriage_proposal"),
  31872. (neq, ":quest_no", "qst_duel_courtship_rival"),
  31873. (neq, ":quest_no", "qst_follow_army"),
  31874. (neq, ":quest_no", "qst_denounce_lord"),
  31875. (neq, ":quest_no", "qst_intrigue_against_lord"),
  31876. (neq, ":quest_no", "qst_offer_gift"),
  31877. (neq, ":quest_no", "qst_organize_feast"),
  31878.  
  31879. (call_script, "script_objectionable_action", tmt_honest, "str_fail_quest"),
  31880. (try_end),
  31881. #NPC companion changes end
  31882.  
  31883. (try_begin),
  31884. (eq, ":quest_no", "qst_resolve_dispute"),
  31885. ##diplomacy start+
  31886. #add support for "spouse of leader" arrangements
  31887. #(faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  31888. (faction_get_slot, ":leader", "$players_kingdom", slot_faction_leader),#added
  31889. (ge, ":leader", 0),
  31890. (this_or_next|troop_slot_eq, ":leader", slot_troop_spouse, "trp_player"),
  31891. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, ":leader"),
  31892. (eq, ":leader", "trp_player"),
  31893. (call_script, "script_change_player_right_to_rule", ":authority_loss"),#<- unaltered
  31894. #add support for promoted kingdom ladies
  31895. (try_for_range, ":lord", heroes_begin, heroes_end),#<- changed active_npcs to heroes
  31896. (this_or_next|troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  31897. (is_between, ":lord", active_npcs_begin, active_npcs_end),
  31898. #exempt retired/exiled/dead lords
  31899. (neg|troop_slot_ge, ":lord", slot_troop_occupation, slto_retirement),
  31900. (store_faction_of_troop, ":lord_faction", ":lord"),#<- unaltered
  31901. (this_or_next|eq, ":lord_faction", "$players_kingdom"),#added for "spouse of leader" arrangements
  31902. ##diplomacy end+
  31903. (eq, ":lord_faction", "fac_player_supporters_faction"),
  31904. (call_script, "script_troop_change_relation_with_troop", ":lord", "trp_player", ":authority_loss"),
  31905. (try_end),
  31906. (try_end),
  31907.  
  31908.  
  31909. (try_begin),
  31910. (eq, ":quest_no", "qst_organize_feast"),
  31911. (call_script, "script_add_notification_menu", "mnu_notification_feast_quest_expired", 0, 0),
  31912. (try_end),
  31913.  
  31914.  
  31915. (call_script, "script_end_quest", ":quest_no"),
  31916. ]),
  31917.  
  31918.  
  31919. ## # script_event_center_captured
  31920. ## # Input: arg1 = center_no, arg2 = old_faction_no
  31921. ## # Output: none
  31922. ## ("event_center_captured",
  31923. ## [
  31924. ## # (store_script_param_1, ":center_no"),
  31925. ## # (store_script_param_2, ":old_faction_no"),
  31926. ## # (store_faction_of_party, ":faction_no"),
  31927. ##
  31928. ## (try_begin),
  31929. ## (check_quest_active, "qst_deliver_message"),
  31930. ## (try_end),
  31931. ## (try_begin),
  31932. ## (check_quest_active, "qst_escort_lady"),
  31933. ## (quest_slot_eq, "qst_escort_lady", slot_quest_target_center, ":center_no"),
  31934. ## (call_script, "script_abort_quest", "qst_escort_lady"),
  31935. ## (try_end),
  31936. ## (try_begin),
  31937. ## (check_quest_active, "qst_rescue_lady_under_siege"),
  31938. ## (quest_slot_eq, "qst_rescue_lady_under_siege", slot_quest_target_center, ":center_no"),
  31939. ## (quest_slot_eq, "qst_rescue_lady_under_siege", slot_quest_current_state, 0),
  31940. ## (call_script, "script_abort_quest", "qst_rescue_lady_under_siege", 1),
  31941. ## (try_end),
  31942. ## (try_begin),
  31943. ## (check_quest_active, "qst_deliver_message_to_lover"),
  31944. ## (try_end),
  31945. ## (try_begin),
  31946. ## (check_quest_active, "qst_deliver_message_to_enemy_lord"),
  31947. ## (try_end),
  31948. ## (try_begin),
  31949. ## (check_quest_active, "qst_bring_prisoners_to_enemy"),
  31950. ## (quest_slot_eq, "qst_bring_prisoners_to_enemy", slot_quest_target_center, ":center_no"),
  31951. ## (neg|check_quest_succeeded, "qst_bring_prisoners_to_enemy"),
  31952. ## (call_script, "script_abort_quest", "qst_bring_prisoners_to_enemy"),
  31953. ## (try_end),
  31954. ## (try_begin),
  31955. ## (check_quest_active, "qst_bring_reinforcements_to_siege"),
  31956. ## (try_end),
  31957. ## (try_begin),
  31958. ## (check_quest_active, "qst_deliver_supply_to_center_under_siege"),
  31959. ## (quest_slot_eq, "qst_deliver_supply_to_center_under_siege", slot_quest_target_center, ":center_no"),
  31960. ## (call_script, "script_abort_quest", "qst_deliver_supply_to_center_under_siege", 1),
  31961. ## (try_end),
  31962. ## (try_begin),
  31963. ## (check_quest_active, "qst_raise_troops"),
  31964. ## (try_end),
  31965. ## (try_begin),
  31966. ## (check_quest_active, "qst_capture_messenger"),
  31967. ## (try_end),
  31968. ## (try_begin),
  31969. ## (check_quest_active, "qst_bring_back_deserters"),
  31970. ## (try_end),
  31971. ## (try_begin),
  31972. ## (check_quest_active, "qst_kill_local_merchant"),
  31973. ## (try_end),
  31974. ## (try_begin),
  31975. ## (check_quest_active, "qst_bring_back_runaway_serfs"),
  31976. ## (quest_slot_eq, "qst_bring_back_runaway_serfs", slot_quest_object_center, ":center_no"),
  31977. ## (neg|check_quest_succeeded, "qst_bring_back_runaway_serfs"),
  31978. ## (neg|check_quest_failed, "qst_bring_back_runaway_serfs"),
  31979. ## (call_script, "script_abort_quest", "qst_bring_back_runaway_serfs"),
  31980. ## (try_end),
  31981. ## (try_begin),
  31982. ## (check_quest_active, "qst_follow_spy"),
  31983. ## (try_end),
  31984. ## (try_begin),
  31985. ## (check_quest_active, "qst_capture_enemy_hero"),
  31986. ## (try_end),
  31987. ## (try_begin),
  31988. ## (check_quest_active, "qst_lend_companion"),
  31989. ## (try_end),
  31990. ## (try_begin),
  31991. ## (check_quest_active, "qst_capture_conspirators"),
  31992. ## (try_end),
  31993. ## (try_begin),
  31994. ## (check_quest_active, "qst_defend_nobles_against_peasants"),
  31995. ## (try_end),
  31996. ## (try_begin),
  31997. ## (check_quest_active, "qst_incriminate_loyal_commander"),
  31998. ## (try_end),
  31999. ## (try_begin),
  32000. ## (check_quest_active, "qst_hunt_down_raiders"),
  32001. ## (try_end),
  32002. ## (try_begin),
  32003. ## (check_quest_active, "qst_capture_prisoners"),
  32004. ## (try_end),
  32005. ## #Enemy lord quests
  32006. ## (try_begin),
  32007. ## (check_quest_active, "qst_lend_surgeon"),
  32008. ## (try_end),
  32009. ## #Kingdom lady quests
  32010. ## (try_begin),
  32011. ## (check_quest_active, "qst_rescue_lord_by_replace"),
  32012. ## (quest_get_slot, ":quest_target_troop", "qst_rescue_lord_by_replace", slot_quest_target_troop),
  32013. ## (troop_slot_eq, ":quest_target_troop", slot_troop_is_prisoner, 0),
  32014. ## (neg|check_quest_succeeded, "qst_rescue_lord_by_replace"),
  32015. ## (call_script, "script_abort_quest", "qst_rescue_lord_by_replace"),
  32016. ## (try_end),
  32017. ## (try_begin),
  32018. ## (check_quest_active, "qst_deliver_message_to_prisoner_lord"),
  32019. ## (try_end),
  32020. ## (try_begin),
  32021. ## (check_quest_active, "qst_duel_for_lady"),
  32022. ## (try_end),
  32023. ## ]),
  32024.  
  32025. # script_cf_is_quest_troop
  32026. # Input: arg1 = troop_no
  32027. # Output: none (can fail)
  32028. ("cf_is_quest_troop",
  32029. [
  32030. (store_script_param_1, ":troop_no"),
  32031. (assign, ":is_quest_troop", 0),
  32032. (try_for_range, ":cur_quest", all_quests_begin, all_quests_end),
  32033. (check_quest_active, ":cur_quest"),
  32034. (quest_get_slot, ":quest_troop_1", ":cur_quest", slot_quest_target_troop),
  32035. (quest_get_slot, ":quest_troop_2", ":cur_quest", slot_quest_object_troop),
  32036. (quest_get_slot, ":quest_troop_3", ":cur_quest", slot_quest_giver_troop),
  32037. (this_or_next|eq, ":quest_troop_1", ":troop_no"),
  32038. (this_or_next|eq, ":quest_troop_2", ":troop_no"),
  32039. (eq, ":quest_troop_3", ":troop_no"),
  32040. (assign, ":is_quest_troop", 1),
  32041. (try_end),
  32042. (eq, ":is_quest_troop", 1),
  32043. ]),
  32044.  
  32045.  
  32046. ## # script_calculate_team_strength
  32047. ## # Input: arg1 = team_no
  32048. ## # Output: strength
  32049. ## ("calculate_team_strength",
  32050. ## [
  32051. ## (store_script_param_1, ":team_no"),
  32052. ## (assign, ":total_strength", 0),
  32053. ## (try_for_agents, ":cur_agent"),
  32054. ## (agent_get_team, ":agent_team", ":cur_agent"),
  32055. ## (eq, ":team_no", ":agent_team"),
  32056. ## (agent_is_human, ":cur_agent"),
  32057. ## (agent_is_alive, ":cur_agent"),
  32058. ##
  32059. ## (agent_get_troop_id, ":cur_troop", ":cur_agent"),
  32060. ## (store_character_level, ":cur_level", ":cur_troop"),
  32061. ## (val_add, ":cur_level", 5),
  32062. ## (try_begin),
  32063. ## (troop_is_hero, ":cur_troop"),
  32064. ## (val_add, ":cur_level", 5),
  32065. ## (try_end),
  32066. ## (val_add, ":total_strength", ":cur_level"),
  32067. ## (try_end),
  32068. ## (assign, reg0, ":total_strength"),
  32069. ## ]),
  32070.  
  32071. # script_check_friendly_kills
  32072. # Input: none
  32073. # Output: none (changes the morale of the player's party)
  32074. ("check_friendly_kills",
  32075. [(get_player_agent_own_troop_kill_count, ":count"),
  32076. (try_begin),
  32077. (neq, "$g_player_current_own_troop_kills", ":count"),
  32078. (val_sub, ":count", "$g_player_current_own_troop_kills"),
  32079. (val_add, "$g_player_current_own_troop_kills", ":count"),
  32080. (val_mul, ":count", -1),
  32081. (call_script, "script_change_player_party_morale", ":count"),
  32082. (try_end),
  32083. ]),
  32084.  
  32085. # script_simulate_retreat
  32086. # Input: arg1 = players_side_damage, arg2 = enemy_side_damage, arg3 = continue_battle s5 = title_string
  32087. # Output: none
  32088. ("simulate_retreat",
  32089. [
  32090. (call_script, "script_music_set_situation_with_culture", mtf_sit_killed),
  32091. (set_show_messages, 0),
  32092. (store_script_param, ":players_side_damage", 1),
  32093. (store_script_param, ":enemy_side_damage", 2),
  32094. (store_script_param, ":continue_battle", 3),
  32095.  
  32096. (assign, ":players_side_strength", 0),
  32097. (assign, ":enemy_side_strength", 0),
  32098.  
  32099. (assign, ":do_calculate", 1),
  32100. (try_begin),
  32101. (try_for_agents, ":cur_agent"),
  32102. (agent_is_human, ":cur_agent"),
  32103. (agent_is_alive, ":cur_agent"),
  32104. (agent_set_slot, ":cur_agent", slot_agent_is_alive_before_retreat, 1),#needed for simulation
  32105.  
  32106. (agent_get_troop_id, ":cur_troop", ":cur_agent"),
  32107. (store_character_level, ":cur_level", ":cur_troop"),
  32108. (val_add, ":cur_level", 5),
  32109. (try_begin),
  32110. (troop_is_hero, ":cur_troop"),
  32111. (val_add, ":cur_level", 5),
  32112. (try_end),
  32113. (try_begin),
  32114. (agent_is_ally, ":cur_agent"),
  32115. (val_add, ":players_side_strength", ":cur_level"),
  32116. (else_try),
  32117. (val_add, ":enemy_side_strength", ":cur_level"),
  32118. (try_end),
  32119. (try_end),
  32120. (eq, "$pin_player_fallen", 0),
  32121. (lt, ":enemy_side_strength", ":players_side_strength"),
  32122. (eq, ":continue_battle", 1),
  32123. (assign, ":do_calculate", 0),
  32124. (try_end),
  32125.  
  32126. (try_begin),
  32127. (eq, ":do_calculate", 1),
  32128.  
  32129. (assign, "$g_last_mission_player_damage", 0),
  32130. (party_clear, "p_temp_party"),
  32131. (party_clear, "p_temp_party_2"),
  32132. (call_script, "script_simulate_battle_with_agents_aux", 0, ":players_side_damage"),
  32133. (call_script, "script_simulate_battle_with_agents_aux", 1, ":enemy_side_damage"),
  32134.  
  32135. (assign, ":display_casualties", 0),
  32136.  
  32137. (try_begin),
  32138. (gt, "$g_last_mission_player_damage", 0),
  32139. (assign, ":display_casualties", 1),
  32140. (assign, reg1, "$g_last_mission_player_damage"),
  32141. (str_store_string, s12, "str_casualty_display_hp"),
  32142. (else_try),
  32143. (str_clear, s12),
  32144. (try_end),
  32145.  
  32146. (call_script, "script_print_casualties_to_s0", "p_temp_party", 1),
  32147. (try_begin),
  32148. (party_get_num_companion_stacks, ":num_stacks", "p_temp_party"),
  32149. (gt, ":num_stacks", 0),
  32150. (assign, ":display_casualties", 1),
  32151. (try_end),
  32152. (str_store_string_reg, s10, s0),
  32153.  
  32154. (call_script, "script_print_casualties_to_s0", "p_temp_party_2", 1),
  32155. (try_begin),
  32156. (party_get_num_companion_stacks, ":num_stacks", "p_temp_party_2"),
  32157. (gt, ":num_stacks", 0),
  32158. (assign, ":display_casualties", 1),
  32159. (try_end),
  32160. (str_store_string_reg, s11, s0),
  32161. (try_begin),
  32162. (eq, ":display_casualties", 1),
  32163. (dialog_box,"str_casualty_display", s5),
  32164. (try_end),
  32165. (try_end),
  32166. (set_show_messages, 1),
  32167.  
  32168. #Calculating morale penalty (can be between 0-30)
  32169. (assign, ":ally_casualties", 0),
  32170. (assign, ":enemy_casualties", 0),
  32171. (assign, ":total_allies", 0),
  32172.  
  32173. (try_for_agents, ":cur_agent"),
  32174. (agent_is_human, ":cur_agent"),
  32175. (try_begin),
  32176. (agent_is_ally, ":cur_agent"),
  32177. (val_add, ":total_allies", 1),
  32178. (try_begin),
  32179. (neg|agent_is_alive, ":cur_agent"),
  32180. (val_add, ":ally_casualties", 1),
  32181. (try_end),
  32182. (else_try),
  32183. (neg|agent_is_alive, ":cur_agent"),
  32184. (val_add, ":enemy_casualties", 1),
  32185. (try_end),
  32186. (try_end),
  32187. (store_add, ":total_casualties", ":ally_casualties", ":enemy_casualties"),
  32188. (try_begin),
  32189. (gt, ":total_casualties", 0),
  32190. (store_mul, ":morale_adder", ":ally_casualties", 100),
  32191. (val_div, ":morale_adder", ":total_casualties"),
  32192. (val_mul, ":morale_adder", ":ally_casualties"),
  32193. (val_div, ":morale_adder", ":total_allies"),
  32194. (val_mul, ":morale_adder", -30),
  32195. (val_div, ":morale_adder", 100),
  32196. (call_script, "script_change_player_party_morale", ":morale_adder"),
  32197. (try_end),
  32198. ]),
  32199.  
  32200.  
  32201.  
  32202. # script_simulate_battle_with_agents_aux
  32203. # For internal use only
  32204. # Input: arg1 = attacker_side (0 = ally, 1 = enemy), arg2 = damage amount
  32205. # Output: none
  32206. ("simulate_battle_with_agents_aux",
  32207. [
  32208. (store_script_param_1, ":attacker_side"),
  32209. (store_script_param_2, ":damage"),
  32210.  
  32211. (get_player_agent_no, ":player_agent"),
  32212. (try_for_agents, ":cur_agent"),
  32213. (neq, ":player_agent", ":cur_agent"),
  32214. (agent_is_human, ":cur_agent"),
  32215. #do not check agent_is_alive, check slot_agent_is_alive_before_retreat instead, so that dead agents can still hit enemies
  32216. (agent_slot_eq, ":cur_agent", slot_agent_is_alive_before_retreat, 1),
  32217. (try_begin),
  32218. (agent_is_ally, ":cur_agent"),
  32219. (assign, ":cur_agents_side", 0),
  32220. (else_try),
  32221. (assign, ":cur_agents_side", 1),
  32222. (try_end),
  32223. (eq, ":cur_agents_side", ":attacker_side"),
  32224. (agent_get_position, pos2, ":cur_agent"),
  32225. (assign, ":closest_agent", -1),
  32226. (assign, ":min_distance", 100000),
  32227. (try_for_agents, ":cur_agent_2"),
  32228. (agent_is_human, ":cur_agent_2"),
  32229. (agent_is_alive, ":cur_agent_2"),
  32230. (try_begin),
  32231. (agent_is_ally, ":cur_agent_2"),
  32232. (assign, ":cur_agents_side_2", 0),
  32233. (else_try),
  32234. (assign, ":cur_agents_side_2", 1),
  32235. (try_end),
  32236. (this_or_next|neq, ":cur_agent_2", ":player_agent"),
  32237. (eq, "$pin_player_fallen", 0),
  32238. (neq, ":attacker_side", ":cur_agents_side_2"),
  32239. (agent_get_position, pos3, ":cur_agent_2"),
  32240. (get_distance_between_positions, ":cur_distance", pos2, pos3),
  32241. (lt, ":cur_distance", ":min_distance"),
  32242. (assign, ":min_distance", ":cur_distance"),
  32243. (assign, ":closest_agent", ":cur_agent_2"),
  32244. (try_end),
  32245. (ge, ":closest_agent", 0),
  32246. #Fight
  32247. (agent_get_class, ":agent_class", ":cur_agent"),
  32248. (assign, ":agents_speed", 1),
  32249. (assign, ":agents_additional_hit", 0),
  32250. (try_begin),
  32251. (eq, ":agent_class", grc_archers),
  32252. (assign, ":agents_additional_hit", 2),
  32253. (else_try),
  32254. (eq, ":agent_class", grc_cavalry),
  32255. (assign, ":agents_speed", 2),
  32256. (try_end),
  32257. (agent_get_class, ":agent_class", ":closest_agent"),
  32258. (assign, ":agents_speed_2", 1),
  32259. (try_begin),
  32260. (eq, ":agent_class", grc_cavalry),
  32261. (assign, ":agents_speed_2", 2),
  32262. (try_end),
  32263. (assign, ":agents_hit", 18000),
  32264. (val_add, ":min_distance", 3000),
  32265. (val_div, ":agents_hit", ":min_distance"),
  32266. (val_mul, ":agents_hit", 2),# max 10, min 2 hits within 150 meters
  32267.  
  32268. (val_mul, ":agents_hit", ":agents_speed"),
  32269. (val_div, ":agents_hit", ":agents_speed_2"),
  32270. (val_add, ":agents_hit", ":agents_additional_hit"),
  32271.  
  32272. (assign, ":cur_damage", ":damage"),
  32273. (agent_get_troop_id, ":closest_troop", ":closest_agent"),
  32274. (agent_get_troop_id, ":cur_troop", ":cur_agent"),
  32275. (store_character_level, ":closest_level", ":closest_troop"),
  32276. (store_character_level, ":cur_level", ":cur_troop"),
  32277. (store_sub, ":level_dif", ":cur_level", ":closest_level"),
  32278. (val_div, ":level_dif", 5),
  32279. (val_add, ":cur_damage", ":level_dif"),
  32280.  
  32281. (try_begin),
  32282. (eq, ":closest_agent", ":player_agent"),
  32283. (val_div, ":cur_damage", 2),
  32284. (store_agent_hit_points, ":init_player_hit_points", ":player_agent", 1),
  32285. (try_end),
  32286.  
  32287. (try_for_range, ":unused", 0, ":agents_hit"),
  32288. (store_random_in_range, ":random_damage", 0, 100),
  32289. (lt, ":random_damage", ":cur_damage"),
  32290. (agent_deliver_damage_to_agent, ":cur_agent", ":closest_agent"),
  32291. (try_end),
  32292.  
  32293. (try_begin),
  32294. (eq, ":closest_agent", ":player_agent"),
  32295. (store_agent_hit_points, ":final_player_hit_points", ":player_agent", 1),
  32296. (store_sub, ":hit_points_difference", ":init_player_hit_points", ":final_player_hit_points"),
  32297. (val_add, "$g_last_mission_player_damage", ":hit_points_difference"),
  32298. (try_end),
  32299.  
  32300. (neg|agent_is_alive, ":closest_agent"),
  32301. (try_begin),
  32302. (eq, ":attacker_side", 1),
  32303. (party_add_members, "p_temp_party", ":closest_troop", 1),
  32304. (try_begin),
  32305. (agent_is_wounded, ":closest_agent"),
  32306. (party_wound_members, "p_temp_party", ":closest_troop", 1),
  32307. (try_end),
  32308. (else_try),
  32309. (party_add_members, "p_temp_party_2", ":closest_troop", 1),
  32310. (try_begin),
  32311. (agent_is_wounded, ":closest_agent"),
  32312. (party_wound_members, "p_temp_party_2", ":closest_troop", 1),
  32313. (try_end),
  32314. (try_end),
  32315. (try_end),
  32316. ]),
  32317.  
  32318.  
  32319. # script_map_get_random_position_around_position_within_range
  32320. # Input: arg1 = minimum_distance in km, arg2 = maximum_distance in km, pos1 = origin position
  32321. # Output: pos2 = result position
  32322. ("map_get_random_position_around_position_within_range",
  32323. [
  32324. (store_script_param_1, ":min_distance"),
  32325. (store_script_param_2, ":max_distance"),
  32326. (val_mul, ":min_distance", 100),
  32327. (assign, ":continue", 1),
  32328. (try_for_range, ":unused", 0, 20),
  32329. (eq, ":continue", 1),
  32330. (map_get_random_position_around_position, pos2, pos1, ":max_distance"),
  32331. (get_distance_between_positions, ":distance", pos2, pos1),
  32332. (ge, ":distance", ":min_distance"),
  32333. (assign, ":continue", 0),
  32334. (try_end),
  32335. ]),
  32336.  
  32337.  
  32338. # script_get_number_of_unclaimed_centers_by_player
  32339. # Input: none
  32340. # Output: reg0 = number of unclaimed centers, reg1 = last unclaimed center_no
  32341. ("get_number_of_unclaimed_centers_by_player",
  32342. [
  32343. (assign, ":unclaimed_centers", 0),
  32344. (assign, reg1, -1),
  32345. (try_for_range, ":center_no", centers_begin, centers_end),
  32346. (store_faction_of_party, ":faction_no", ":center_no"),
  32347. (eq, ":faction_no", "fac_player_supporters_faction"),
  32348. (party_slot_eq, ":center_no", slot_town_claimed_by_player, 0),
  32349. (party_get_num_companion_stacks, ":num_stacks", ":center_no"),
  32350. (ge, ":num_stacks", 1), #castle is garrisoned
  32351. (assign, reg1, ":center_no"),
  32352. (val_add, ":unclaimed_centers", 1),
  32353. (try_end),
  32354. (assign, reg0, ":unclaimed_centers"),
  32355. ]),
  32356.  
  32357. # script_troop_count_number_of_enemy_troops
  32358. # Input: arg1 = troop_no
  32359. # Output: reg0 = number_of_enemy_troops
  32360. # ("troop_count_number_of_enemy_troops",
  32361. # [
  32362. # (store_script_param_1, ":troop_no"),
  32363. # (assign, ":enemy_count", 0),
  32364. # (try_for_range, ":i_enemy_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
  32365. # (troop_slot_ge, ":troop_no", ":i_enemy_slot", 1),
  32366. # (val_add, ":enemy_count", 1),
  32367. # (try_end),
  32368. # (assign, reg0, ":enemy_count"),
  32369. # ]),
  32370.  
  32371.  
  32372. # script_cf_troop_check_troop_is_enemy
  32373. # Input: arg1 = troop_no, arg2 = checked_troop_no
  32374. # Output: none (Can fail)
  32375. ("cf_troop_check_troop_is_enemy",
  32376. [
  32377. (store_script_param_1, ":troop_no"),
  32378. (store_script_param_2, ":checked_troop_no"),
  32379. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":checked_troop_no"),
  32380. (lt, reg0, -10),
  32381. ]),
  32382.  
  32383.  
  32384. # script_troop_get_leaded_center_with_index
  32385. # Input: arg1 = troop_no, arg2 = center index within range between zero and the number of centers that troop owns
  32386. # Output: reg0 = center_no
  32387. ("troop_get_leaded_center_with_index",
  32388. [
  32389. (store_script_param_1, ":troop_no"),
  32390. (store_script_param_2, ":random_center"),
  32391. (assign, ":result", -1),
  32392. (assign, ":center_count", 0),
  32393. (try_for_range, ":center_no", centers_begin, centers_end),
  32394. (eq, ":result", -1),
  32395. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  32396. (val_add, ":center_count", 1),
  32397. (gt, ":center_count", ":random_center"),
  32398. (assign, ":result", ":center_no"),
  32399. (try_end),
  32400. (assign, reg0, ":result"),
  32401. ]),
  32402.  
  32403. # script_cf_troop_get_random_leaded_walled_center_with_less_strength_priority
  32404. # Input: arg1 = troop_no, arg2 = preferred_center_no
  32405. # Output: reg0 = center_no (Can fail)
  32406. ("cf_troop_get_random_leaded_walled_center_with_less_strength_priority",
  32407. [
  32408. (store_script_param, ":troop_no", 1),
  32409. (store_script_param, ":preferred_center_no", 2),
  32410.  
  32411. (assign, ":num_centers", 0),
  32412. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  32413. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  32414. (party_slot_eq, ":center_no", slot_center_is_besieged_by, -1),
  32415. (val_add, ":num_centers", 1),
  32416. (try_begin),
  32417. (eq, ":center_no", ":preferred_center_no"),
  32418. (val_add, ":num_centers", 99),
  32419. (try_end),
  32420. ## (call_script, "script_party_calculate_regular_strength", ":center_no"),
  32421. ## (assign, ":strength", reg0),
  32422. ## (lt, ":strength", 80),
  32423. ## (store_sub, ":strength", 100, ":strength"),
  32424. ## (val_div, ":strength", 20),
  32425. ## (val_add, ":num_centers", ":strength"),
  32426. (try_end),
  32427. (gt, ":num_centers", 0),
  32428. (store_random_in_range, ":random_center", 0, ":num_centers"),
  32429. (assign, ":result", -1),
  32430. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  32431. (eq, ":result", -1),
  32432. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  32433. (party_slot_eq, ":center_no", slot_center_is_besieged_by, -1),
  32434. (val_sub, ":random_center", 1),
  32435. (try_begin),
  32436. (eq, ":center_no", ":preferred_center_no"),
  32437. (val_sub, ":random_center", 99),
  32438. (try_end),
  32439. ## (try_begin),
  32440. ## (call_script, "script_party_calculate_regular_strength", ":center_no"),
  32441. ## (assign, ":strength", reg0),
  32442. ## (lt, ":strength", 80),
  32443. ## (store_sub, ":strength", 100, ":strength"),
  32444. ## (val_div, ":strength", 20),
  32445. ## (val_sub, ":random_center", ":strength"),
  32446. ## (try_end),
  32447. (lt, ":random_center", 0),
  32448. (assign, ":result", ":center_no"),
  32449. (try_end),
  32450. (assign, reg0, ":result"),
  32451. ]),
  32452.  
  32453. # script_cf_troop_get_random_leaded_town_or_village_except_center
  32454. # Input: arg1 = troop_no, arg2 = except_center_no
  32455. # Output: reg0 = center_no (Can fail)
  32456. #SB : only called from checking qst_collect_taxes, apply condition as follows
  32457. ## not close to arg2 (Native only checks if quest giver is inside town)
  32458. ## not under siege/raided (arg3)
  32459. ("cf_troop_get_random_leaded_town_or_village_except_center",
  32460. [
  32461. (store_script_param, ":troop_no", 1),
  32462. (store_script_param, ":except_center_no", 2), #unused I guess
  32463. (store_script_param, ":center_state", 3), #pass in svs_normal
  32464.  
  32465. #SB : re-use except_center_no as a check
  32466. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  32467. (try_begin),
  32468. (le, ":party_no", 0),
  32469. (assign, ":party_no", ":except_center_no"),
  32470. (try_end),
  32471. (assign, ":num_centers", 0),
  32472. (try_for_range, ":center_no", centers_begin, centers_end),
  32473.  
  32474. # (party_set_slot, ":center_no", slot_party_temp_slot_1, 0),
  32475. (neg|party_slot_eq, ":center_no", slot_party_type, spt_castle),
  32476. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  32477. (neq, ":center_no", ":except_center_no"),
  32478. (assign, ":dist", 9999),
  32479. (try_begin),
  32480. (gt, ":party_no", 0),
  32481. (store_distance_to_party_from_party, ":dist", ":center_no", ":party_no"),
  32482. (try_end),
  32483. (gt, ":dist", 15), #can't be within a day's travel
  32484. (party_slot_eq, ":center_no", slot_village_state, ":center_state"),
  32485. # (party_set_slot, ":center_no", slot_party_temp_slot_1, 1),
  32486. (troop_set_slot, "trp_random_town_sequence", ":num_centers", ":center_no"),
  32487. (val_add, ":num_centers", 1),
  32488. (try_end),
  32489.  
  32490. (gt, ":num_centers", 0),
  32491. (store_random_in_range, ":random_center", 0, ":num_centers"),
  32492. (troop_get_slot, reg0, "trp_random_town_sequence", ":random_center"),
  32493. # (assign, ":end_cond", centers_end),
  32494. # (try_for_range, ":center_no", centers_begin, ":end_cond"),
  32495. # (neg|party_slot_eq, ":center_no", slot_party_type, spt_castle),
  32496. # (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  32497. # (neq, ":center_no", ":except_center_no"),
  32498. # (val_sub, ":random_center", 1),
  32499. # (lt, ":random_center", 0),
  32500. # (assign, ":target_center", ":center_no"),
  32501. # (assign, ":end_cond", 0),
  32502. # (try_end),
  32503. # (assign, reg0, ":target_center"),
  32504. ]),
  32505.  
  32506. # script_troop_write_owned_centers_to_s2
  32507. # Input: arg1 = troop_no
  32508. # Output: none
  32509. ("troop_write_owned_centers_to_s2",
  32510. [
  32511. (store_script_param_1, ":troop_no"),
  32512.  
  32513. (call_script, "script_get_number_of_hero_centers", ":troop_no"),
  32514. (assign, ":no_centers", reg0),
  32515.  
  32516. (str_store_troop_name, s5, ":troop_no"),
  32517.  
  32518. (try_begin),
  32519. (gt, ":no_centers", 1),
  32520. (try_for_range, ":i_center", 1, ":no_centers"),
  32521. (call_script, "script_troop_get_leaded_center_with_index", ":troop_no", ":i_center"),
  32522. (str_store_party_name_link, s50, reg0),
  32523. (try_begin),
  32524. (eq, ":i_center", 1),
  32525. (call_script, "script_troop_get_leaded_center_with_index", ":troop_no", 0),
  32526. (str_store_party_name_link, s51, reg0),
  32527. (str_store_string, s51, "str_s50_and_s51"),
  32528. (else_try),
  32529. (str_store_string, s51, "str_s50_comma_s51"),
  32530. (try_end),
  32531. (try_end),
  32532. (str_store_string, s2, "str_s5_is_the_ruler_of_s51"),
  32533. (else_try),
  32534. (eq, ":no_centers", 1),
  32535. (call_script, "script_troop_get_leaded_center_with_index", ":troop_no", 0),
  32536. (str_store_party_name_link, s51, reg0),
  32537. (str_store_string, s2, "str_s5_is_the_ruler_of_s51"),
  32538. (else_try),
  32539. (store_troop_faction, ":faction_no", ":troop_no"),
  32540. (str_store_faction_name_link, s6, ":faction_no"),
  32541. ##diplomacy start+ make gender-correct
  32542. #(troop_get_type, reg4, ":troop_no"),
  32543. (assign, ":save_reg4", reg4),
  32544. (call_script, "script_dplmc_store_troop_is_female_reg", ":troop_no", 4),
  32545. (str_store_string, s2, "str_s5_is_a_nobleman_of_s6"),
  32546. (assign, reg4, ":save_reg4"),
  32547. ##diplomacy end+
  32548. (try_end),
  32549. ]),
  32550.  
  32551. ("troop_write_family_relations_to_s1",
  32552. [
  32553. (str_clear, s1),
  32554. #redo, possibly using base from update_troop_notes
  32555. ]),
  32556.  
  32557. # script_write_family_relation_as_s3s_s2_to_s4
  32558.  
  32559. # Inputs: arg1 = troop_no, arg2 = family_no (valid slot no after slot_troop_family_begin)
  32560. # Outputs: s11 = what troop_1 is to troop_2, reg0 = strength of relationship. Normally, "$g_talk_troop" should be troop_2
  32561.  
  32562. ("troop_get_family_relation_to_troop",
  32563. [
  32564. (store_script_param_1, ":troop_1"),
  32565. (store_script_param_2, ":troop_2"),
  32566.  
  32567. ##diplomacy start+ use gender script
  32568. #(troop_get_type, ":gender_1", ":troop_1"),
  32569. (call_script, "script_dplmc_store_troop_is_female", ":troop_1"),
  32570. (assign, ":gender_1", reg0),
  32571. ##diplomacy end+
  32572. (assign, ":relation_strength", 0),
  32573.  
  32574. (troop_get_slot, ":spouse_of_1", ":troop_1", slot_troop_spouse),
  32575. (troop_get_slot, ":spouse_of_2", ":troop_2", slot_troop_spouse),
  32576.  
  32577. (try_begin),
  32578. (gt, ":spouse_of_1", -1),
  32579. (troop_get_slot, ":father_of_spouse_of_1", ":spouse_of_1", slot_troop_father),
  32580. (else_try),
  32581. (assign, ":father_of_spouse_of_1", -1),
  32582. (try_end),
  32583.  
  32584. (try_begin),
  32585. (gt, ":spouse_of_2", -1),
  32586. (troop_get_slot, ":father_of_spouse_of_2", ":spouse_of_2", slot_troop_father),
  32587. (else_try),
  32588. (assign, ":father_of_spouse_of_2", -1),
  32589. (try_end),
  32590.  
  32591. (try_begin),
  32592. (gt, ":spouse_of_2", -1),
  32593. (troop_get_slot, ":mother_of_spouse_of_2", ":spouse_of_2", slot_troop_mother),
  32594. (else_try),
  32595. (assign, ":mother_of_spouse_of_2", -1),
  32596. (try_end),
  32597.  
  32598. (troop_get_slot, ":father_of_1", ":troop_1", slot_troop_father),
  32599. (troop_get_slot, ":father_of_2", ":troop_2", slot_troop_father),
  32600.  
  32601. #For the sake of simplicity, we can assume that all male aristocrats in prior generations either married commoners or procured their brides from the Old Country, thus discounting intermarriage
  32602. (troop_get_slot, ":mother_of_1", ":troop_1", slot_troop_mother),
  32603. (troop_get_slot, ":mother_of_2", ":troop_2", slot_troop_mother),
  32604.  
  32605. ##diplomacy start+
  32606. #Fix a native bug where daughters are their own mothers
  32607. #(fixed in this mod, but still affects old saved games)
  32608. #REMOVED - Instead this occurs once in simple triggers
  32609.  
  32610. ##Adding paternal grandmother (begin mostly-unaltered section)
  32611. (try_begin),
  32612. (this_or_next|eq, ":father_of_1", "trp_player"),#dplmc+ added
  32613. (is_between, ":father_of_1", companions_begin, kingdom_ladies_end),
  32614. (troop_get_slot, ":paternal_grandfather_of_1", ":father_of_1", slot_troop_father),
  32615. (troop_get_slot, ":paternal_grandmother_of_1", ":father_of_1", slot_troop_mother),#added
  32616. (else_try),
  32617. (assign, ":paternal_grandfather_of_1", -1),
  32618. (assign, ":paternal_grandmother_of_1", -1),#added
  32619. (try_end),
  32620.  
  32621. (try_begin),
  32622. (this_or_next|eq, ":father_of_2", "trp_player"),#dplmc+ added
  32623. (is_between, ":father_of_2", companions_begin, kingdom_ladies_end),
  32624. (troop_get_slot, ":paternal_grandfather_of_2", ":father_of_2", slot_troop_father),
  32625. (troop_get_slot, ":paternal_grandmother_of_2", ":father_of_2", slot_troop_mother),#added
  32626. (else_try),
  32627. (assign, ":paternal_grandfather_of_2", -1),
  32628. (assign, ":paternal_grandmother_of_2", -1),#added
  32629. (try_end),
  32630. #(end mostly-unaltered section)
  32631.  
  32632. ##Adding maternal grandfather and maternal grandmother
  32633. (try_begin),
  32634. (this_or_next|eq, ":mother_of_1", "trp_player"),#dplmc+ added
  32635. (is_between, ":mother_of_1", companions_begin, kingdom_ladies_end),
  32636. (troop_get_slot, ":maternal_grandfather_of_1", ":mother_of_1", slot_troop_father),
  32637. (troop_get_slot, ":maternal_grandmother_of_1", ":mother_of_1", slot_troop_mother),
  32638. (else_try),
  32639. (assign, ":maternal_grandfather_of_1", -1),
  32640. (assign, ":maternal_grandmother_of_1", -1),
  32641. (try_end),
  32642.  
  32643. (try_begin),
  32644. (this_or_next|eq, ":mother_of_2", "trp_player"),#dplmc+ added
  32645. (is_between, ":mother_of_2", companions_begin, kingdom_ladies_end),
  32646. (troop_get_slot, ":maternal_grandfather_of_2", ":mother_of_2", slot_troop_father),
  32647. (troop_get_slot, ":maternal_grandmother_of_2", ":mother_of_2", slot_troop_mother),
  32648. (else_try),
  32649. (assign, ":maternal_grandfather_of_2", -1),
  32650. (assign, ":maternal_grandmother_of_2", -1),
  32651. (try_end),
  32652. ##diplomacy end+
  32653.  
  32654. (troop_get_slot, ":guardian_of_1", ":troop_1", slot_troop_guardian),
  32655. (troop_get_slot, ":guardian_of_2", ":troop_2", slot_troop_guardian),
  32656.  
  32657. (str_store_string, s11, "str_no_relation"),
  32658.  
  32659. (try_begin),
  32660. (eq, ":troop_1", ":troop_2"),
  32661. #self
  32662. (else_try),
  32663. ##diplomacy start+
  32664. (this_or_next|eq, ":spouse_of_2", ":troop_1"),#polygamy helper
  32665. ##diplomacy end+
  32666. (eq, ":spouse_of_1", ":troop_2"),
  32667. (assign, ":relation_strength", 20),
  32668. (try_begin),
  32669. (eq, ":gender_1", tf_female),
  32670. (str_store_string, s11, "str_wife"),
  32671. (else_try),
  32672. (str_store_string, s11, "str_husband"),
  32673. (try_end),
  32674. (else_try),
  32675. (eq, ":father_of_2", ":troop_1"),
  32676. (assign, ":relation_strength", 15),
  32677. (str_store_string, s11, "str_father"),
  32678. (else_try),
  32679. (eq, ":mother_of_2", ":troop_1"),
  32680. (assign, ":relation_strength", 15),
  32681. (str_store_string, s11, "str_mother"),
  32682. (else_try),
  32683. (this_or_next|eq, ":father_of_1", ":troop_2"),
  32684. (eq, ":mother_of_1", ":troop_2"),
  32685. (assign, ":relation_strength", 15),
  32686. (try_begin),
  32687. (eq, ":gender_1", tf_female),
  32688. (str_store_string, s11, "str_daughter"),
  32689. (else_try),
  32690. (str_store_string, s11, "str_son"),
  32691. (try_end),
  32692. ##diplomacy start+
  32693. (else_try),
  32694. #Check for half-siblings: sharing a father
  32695. (neq, ":father_of_1", -1),
  32696. (eq, ":father_of_1", ":father_of_2"),
  32697. (neq, ":mother_of_1", ":mother_of_2"),
  32698. (assign, ":relation_strength", 10),
  32699. (try_begin),
  32700. (eq, ":gender_1", tf_female),
  32701. (str_store_string, s11, "str_dplmc_half_sister"),
  32702. (else_try),
  32703. (str_store_string, s11, "str_dplmc_half_brother"),
  32704. (try_end),
  32705. (else_try),
  32706. #Check for half-siblings: sharing a mother
  32707. (neq, ":mother_of_1", -1),
  32708. (eq, ":mother_of_1", ":mother_of_2"),
  32709. (neq, ":father_of_1", ":father_of_2"),
  32710. (assign, ":relation_strength", 10),
  32711. (try_begin),
  32712. (eq, ":gender_1", tf_female),
  32713. (str_store_string, s11, "str_dplmc_half_sister"),
  32714. (else_try),
  32715. (str_store_string, s11, "str_dplmc_half_brother"),
  32716. (try_end),
  32717. ##diplomacy end+
  32718. (else_try),
  32719. #(gt, ":father_of_1", -1), #necessary, as some lords do not have the father registered #dplmc+ replaced
  32720. (neq, ":father_of_1", -1), #dplmc+ added
  32721. (eq, ":father_of_1", ":father_of_2"),
  32722. (assign, ":relation_strength", 10),
  32723. (try_begin),
  32724. (eq, ":gender_1", tf_female),
  32725. (str_store_string, s11, "str_sister"),
  32726. (else_try),
  32727. (str_store_string, s11, "str_brother"),
  32728. (try_end),
  32729. (else_try),
  32730. (eq, ":guardian_of_2", ":troop_1"),
  32731. (assign, ":relation_strength", 10),
  32732. (try_begin),
  32733. (eq, ":gender_1", tf_female),
  32734. (str_store_string, s11, "str_sister"),
  32735. (else_try),
  32736. (str_store_string, s11, "str_brother"),
  32737. (try_end),
  32738. (else_try),
  32739. (eq, ":guardian_of_1", ":troop_2"),
  32740. (assign, ":relation_strength", 10),
  32741. (try_begin),
  32742. (eq, ":gender_1", tf_female),
  32743. (str_store_string, s11, "str_sister"),
  32744. (else_try),
  32745. (str_store_string, s11, "str_brother"),
  32746. (try_end),
  32747. ##diplomacy start+
  32748. (else_try),#polygamy, between two people married to the same person
  32749. (neq, ":spouse_of_1", -1),
  32750. (eq, ":spouse_of_2", ":spouse_of_1"),
  32751. (assign, ":relation_strength", 10),
  32752. (try_begin),
  32753. (eq, ":gender_1", tf_female),
  32754. (str_store_string, s11, "str_dplmc_sister_wife"),
  32755. (else_try),
  32756. (str_store_string, s11, "str_dplmc_co_husband"),
  32757. (try_end),
  32758. ##diplomacy end+
  32759. (else_try),
  32760. #(gt, ":paternal_grandfather_of_1", -1),#dplmc+ replaced
  32761. (neq, ":father_of_2", -1),#dplmc+ added
  32762. (this_or_next|eq, ":maternal_grandfather_of_1", ":father_of_2"),#dplmc+ added
  32763. (eq, ":paternal_grandfather_of_1", ":father_of_2"),
  32764. (assign, ":relation_strength", 4),
  32765. (try_begin),
  32766. (eq, ":gender_1", tf_female),
  32767. (str_store_string, s11, "str_niece"),
  32768. (else_try),
  32769. (str_store_string, s11, "str_nephew"),
  32770. (try_end),
  32771. ##diplomacy start+: add niece/nephew through mother
  32772. (else_try),
  32773. (neq, ":mother_of_2", -1),
  32774. (this_or_next|eq, ":maternal_grandmother_of_1", ":mother_of_2"),
  32775. (eq, ":paternal_grandmother_of_1", ":mother_of_2"),
  32776. (assign, ":relation_strength", 4),
  32777. (try_begin),
  32778. (eq, ":gender_1", tf_female),
  32779. (str_store_string, s11, "str_niece"),
  32780. (else_try),
  32781. (str_store_string, s11, "str_nephew"),
  32782. (try_end),
  32783. ##diplomacy end+
  32784. (else_try), #specifically aunt and uncle by blood -- i assume that in a medieval society with lots of internal family conflicts, they would not include aunts and uncles by marriage
  32785. #(gt, ":paternal_grandfather_of_2", -1),#dplmc+ replaced
  32786. (neq, ":father_of_1", -1),#dplmc+ added
  32787. (this_or_next|eq, ":maternal_grandfather_of_2", ":father_of_1"),#dplmc+ added
  32788. (eq, ":paternal_grandfather_of_2", ":father_of_1"),
  32789. (assign, ":relation_strength", 4),
  32790. (try_begin),
  32791. (eq, ":gender_1", tf_female),
  32792. (str_store_string, s11, "str_aunt"),
  32793. (else_try),
  32794. (str_store_string, s11, "str_uncle"),
  32795. (try_end),
  32796. ##diplomacy start+
  32797. #blood uncles & blood aunts, continued (via mother)
  32798. (else_try),
  32799. (neq, ":mother_of_1", -1),
  32800. (this_or_next|eq, ":maternal_grandmother_of_2", ":mother_of_1"),
  32801. (eq, ":paternal_grandmother_of_2", ":mother_of_1"),
  32802. (assign, ":relation_strength", 4),
  32803. (try_begin),
  32804. (eq, ":gender_1", tf_female),
  32805. (str_store_string, s11, "str_aunt"),
  32806. (else_try),
  32807. (str_store_string, s11, "str_uncle"),
  32808. (try_end),
  32809. ##diplomacy end+
  32810. (else_try),
  32811. #(gt, ":paternal_grandfather_of_1", 0),#dplmc+ replaced (why was this one "gt 0" but the previous "gt -1"?)
  32812. (neq, ":paternal_grandfather_of_1", -1),#dplmc+ added
  32813. (this_or_next|eq, ":maternal_grandfather_of_2", ":paternal_grandfather_of_1"),#dplmc+ added
  32814. (eq, ":paternal_grandfather_of_2", ":paternal_grandfather_of_1"),
  32815. (assign, ":relation_strength", 2),
  32816. (str_store_string, s11, "str_cousin"),
  32817. ##diplomacy start+
  32818. #Add cousin via paternal grandmother or maternal grandparents
  32819. (else_try),
  32820. (neq, ":maternal_grandfather_of_1", -1),
  32821. (this_or_next|eq, ":maternal_grandfather_of_2", ":maternal_grandfather_of_1"),
  32822. (eq, ":paternal_grandfather_of_2", ":maternal_grandfather_of_1"),
  32823. (assign, ":relation_strength", 2),
  32824. (str_store_string, s11, "str_cousin"),
  32825. (else_try),
  32826. (neq, ":paternal_grandmother_of_1", -1),
  32827. (this_or_next|eq, ":maternal_grandmother_of_2", ":paternal_grandmother_of_1"),
  32828. (eq, ":paternal_grandmother_of_2", ":paternal_grandmother_of_1"),
  32829. (assign, ":relation_strength", 2),
  32830. (str_store_string, s11, "str_cousin"),
  32831. (else_try),
  32832. (neq, ":maternal_grandmother_of_1", -1),
  32833. (this_or_next|eq, ":maternal_grandmother_of_2", ":maternal_grandmother_of_1"),
  32834. (eq, ":paternal_grandmother_of_2", ":maternal_grandmother_of_1"),
  32835. (assign, ":relation_strength", 2),
  32836. (str_store_string, s11, "str_cousin"),
  32837. ##diplomacy end+
  32838. (else_try),
  32839. (eq, ":father_of_spouse_of_1", ":troop_2"),
  32840. (assign, ":relation_strength", 5),
  32841. (try_begin),
  32842. (eq, ":gender_1", tf_female),
  32843. (str_store_string, s11, "str_daughterinlaw"),
  32844. (else_try),
  32845. (str_store_string, s11, "str_soninlaw"),
  32846. (try_end),
  32847. (else_try),
  32848. (eq, ":father_of_spouse_of_2", ":troop_1"),
  32849. (assign, ":relation_strength", 5),
  32850. (str_store_string, s11, "str_fatherinlaw"),
  32851. (else_try),
  32852. (eq, ":mother_of_spouse_of_2", ":troop_1"),
  32853. (neq, ":mother_of_spouse_of_2", "trp_player"), #May be necessary if mother for troops not set to -1
  32854. (assign, ":relation_strength", 5),
  32855. (str_store_string, s11, "str_motherinlaw"),
  32856.  
  32857. (else_try),
  32858. #(gt, ":father_of_spouse_of_1", -1), #necessary #dplmc+ replaced
  32859. (neq, ":father_of_spouse_of_1", -1), #dplmc+ added
  32860. (eq, ":father_of_spouse_of_1", ":father_of_2"),
  32861. (assign, ":relation_strength", 5),
  32862. (try_begin),
  32863. (eq, ":gender_1", tf_female),
  32864. (str_store_string, s11, "str_sisterinlaw"),
  32865. (else_try),
  32866. (str_store_string, s11, "str_brotherinlaw"),
  32867. (try_end),
  32868. (else_try),
  32869. #(gt, ":father_of_spouse_of_2", -1), #necessary #dplmc+ replaced
  32870. (neq, ":father_of_spouse_of_2", -1), #dplmc+ added
  32871. (eq, ":father_of_spouse_of_2", ":father_of_1"),
  32872. (assign, ":relation_strength", 5),
  32873. (try_begin),
  32874. (eq, ":gender_1", tf_female),
  32875. (str_store_string, s11, "str_sisterinlaw"),
  32876. (else_try),
  32877. (str_store_string, s11, "str_brotherinlaw"),
  32878. (try_end),
  32879. (else_try),
  32880. # (gt, ":spouse_of_2", -1), #necessary to avoid bug #dplmc+ replaced
  32881. (neq, ":spouse_of_2", -1), #dplmc+ added
  32882. (troop_slot_eq, ":spouse_of_2", slot_troop_guardian, ":troop_1"),
  32883. (assign, ":relation_strength", 5),
  32884. (try_begin),
  32885. #(eq, ":gender_1", tf_female),#dplmc+ replaced
  32886. (eq, ":gender_1", tf_female),#dplmc+ added
  32887. (str_store_string, s11, "str_sisterinlaw"),
  32888. (else_try),
  32889. (str_store_string, s11, "str_brotherinlaw"),
  32890. (try_end),
  32891. (else_try),
  32892. #(gt, ":spouse_of_1", -1), #necessary to avoid bug #dplmc+ replaced
  32893. (neq, ":spouse_of_1", -1), #dplmc+ added
  32894. (troop_slot_eq, ":spouse_of_1", slot_troop_guardian, ":troop_2"),
  32895. (assign, ":relation_strength", 5),
  32896. (try_begin),
  32897. (eq, ":gender_1", tf_female),
  32898. (str_store_string, s11, "str_sisterinlaw"),
  32899. (else_try),
  32900. (str_store_string, s11, "str_brotherinlaw"),
  32901. (try_end),
  32902. (else_try),
  32903. #grandchild
  32904. (neq, ":troop_2", -1),
  32905. (this_or_next|eq, ":paternal_grandfather_of_1", ":troop_2"),
  32906. (this_or_next|eq, ":maternal_grandfather_of_1", ":troop_2"),
  32907. (this_or_next|eq, ":paternal_grandmother_of_1", ":troop_2"),
  32908. (eq, ":maternal_grandmother_of_1", ":troop_2"),
  32909. (assign, ":relation_strength", 4),
  32910. (try_begin),
  32911. (eq, ":gender_1", tf_female),
  32912. (str_store_string, s11, "str_dplmc_granddaughter"),
  32913. (else_try),
  32914. (str_store_string, s11, "str_dplmc_grandson"),
  32915. (try_end),
  32916. (else_try),
  32917. #grandparent
  32918. (neq, ":troop_1", -1),
  32919. (this_or_next|eq, ":paternal_grandfather_of_2", ":troop_1"),
  32920. (this_or_next|eq, ":maternal_grandfather_of_2", ":troop_1"),
  32921. (this_or_next|eq, ":paternal_grandmother_of_2", ":troop_1"),
  32922. (eq, ":maternal_grandmother_of_2", ":troop_1"),
  32923. (assign, ":relation_strength", 4),
  32924. (try_begin),
  32925. (eq, ":gender_1", tf_female),
  32926. (str_store_string, s11, "str_dplmc_grandmother"),
  32927. (else_try),
  32928. (str_store_string, s11, "str_dplmc_grandfather"),
  32929. (try_end),
  32930. (try_end),
  32931.  
  32932. ##diplomacy start+
  32933. ##Add relations for rulers not already encoded
  32934. (try_begin),
  32935. (eq, ":relation_strength", 0),
  32936. (neq, ":troop_1", ":troop_2"),
  32937. (try_begin),
  32938. #Lady Isolla of Suno's father King Esterich was King Harlaus's cousin,
  32939. #making them first cousins once removed. Assign a weight of "1"
  32940. #to this (for reference, the lowest value normally given in Native is 2).
  32941. (this_or_next|eq, ":troop_1", "trp_kingdom_1_lord"),
  32942. (eq, ":troop_1", "trp_kingdom_1_pretender"),
  32943. (this_or_next|eq, ":troop_2", "trp_kingdom_1_lord"),
  32944. (eq, ":troop_2", "trp_kingdom_1_pretender"),
  32945. (assign, ":relation_strength", 1),
  32946. (str_store_string, s11, "str_cousin"),
  32947. (else_try),
  32948. #Prince Valdym's uncle was Regent Burelek, father of King Yaroglek,
  32949. #making the two of them first cousins.
  32950. (this_or_next|eq, ":troop_1", "trp_kingdom_2_lord"),
  32951. (eq, ":troop_1", "trp_kingdom_2_pretender"),
  32952. (this_or_next|eq, ":troop_2", "trp_kingdom_2_lord"),
  32953. (eq, ":troop_2", "trp_kingdom_2_pretender"),
  32954. (assign, ":relation_strength", 2),
  32955. (str_store_string, s11, "str_cousin"),
  32956. (else_try),
  32957. #Sanjar Khan and Dustum Khan were both sons of Janakir Khan
  32958. #(although by different mothers) making them half-brothers.
  32959. (this_or_next|eq, ":troop_1", "trp_kingdom_3_lord"),
  32960. (eq, ":troop_1", "trp_kingdom_3_pretender"),
  32961. (this_or_next|eq, ":troop_2", "trp_kingdom_3_lord"),
  32962. (eq, ":troop_2", "trp_kingdom_3_pretender"),
  32963. (assign, ":relation_strength", 10),
  32964. (str_store_string, s11, "str_dplmc_half_brother"),
  32965. #Adjust their parentage to make this work automatically
  32966. (try_begin),
  32967. (troop_slot_eq, ":troop_1", slot_troop_father, -1),
  32968. (troop_slot_eq, ":troop_2", slot_troop_father, -1),
  32969. #Set their "father" slot to a number guaranteed not to have spurious collisions
  32970. (store_mul, ":janakir_khan", "trp_kingdom_3_lord", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),#defined in module_constants.py
  32971. (val_add, ":janakir_khan", DPLMC_VIRTUAL_RELATIVE_FATHER_OFFSET),#defined in module_constants.py
  32972. (troop_set_slot, ":troop_1", slot_troop_father, ":janakir_khan"),
  32973. (troop_set_slot, ":troop_2", slot_troop_father, ":janakir_khan"),
  32974. #Differentiate their mothers, so they are half-brothers instead of full-brothers
  32975. (try_begin),
  32976. (troop_slot_eq, ":troop_1", slot_troop_mother, -1),
  32977. (store_mul, reg0, ":troop_1", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),
  32978. (val_add, reg0, DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),
  32979. (troop_set_slot, ":troop_1", slot_troop_mother, reg0),
  32980. (try_end),
  32981. (try_begin),
  32982. (troop_slot_eq, ":troop_2", slot_troop_mother, -1),
  32983. (store_mul, reg0, ":troop_2", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),
  32984. (val_add, reg0, DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),
  32985. (troop_set_slot, ":troop_2", slot_troop_mother, reg0),
  32986. (try_end),
  32987. (try_end),
  32988. (try_end),
  32989. (try_end),
  32990. ##Add uncles and aunts by marriage.
  32991. ##In Native, the relation strength for blood uncles/aunts is 4, and for cousins is 2.
  32992. ##In light of this I've decided to set the relation strength for aunts/uncles by marriage to 2.
  32993. (try_begin),
  32994. (lt, ":relation_strength", 2),#Skip this check if a stronger relation has been found.
  32995. #Test if troop_1 is married to a sibling of one of troop_2's parents, pt. 1
  32996. (ge, ":spouse_of_1", 0),
  32997. (neg|troop_slot_eq, ":spouse_of_1", slot_troop_father, -1),
  32998. (this_or_next|troop_slot_eq, ":spouse_of_1", slot_troop_father, ":paternal_grandfather_of_2"),
  32999. (troop_slot_eq, ":spouse_of_1", slot_troop_father, ":maternal_grandfather_of_2"),
  33000. (assign, ":relation_strength", 2),
  33001. (try_begin),
  33002. (eq, ":gender_1", tf_female),
  33003. (str_store_string, s11, "str_aunt"),
  33004. (else_try),
  33005. (str_store_string, s11, "str_uncle"),
  33006. (try_end),
  33007. (else_try),
  33008. (lt, ":relation_strength", 2),#Skip this check if a stronger relation has been found.
  33009. #Test if troop_1 is married to a sibling of one of troop_2's parents, pt. 2
  33010. (ge, ":spouse_of_1", 0),
  33011. (neg|troop_slot_eq, ":spouse_of_1", slot_troop_mother, -1),
  33012. (this_or_next|troop_slot_eq, ":spouse_of_1", slot_troop_mother, ":paternal_grandmother_of_2"),
  33013. (troop_slot_eq, ":spouse_of_1", slot_troop_mother, ":maternal_grandmother_of_2"),
  33014. (assign, ":relation_strength", 2),
  33015. (try_begin),
  33016. (eq, ":gender_1", tf_female),
  33017. (str_store_string, s11, "str_aunt"),
  33018. (else_try),
  33019. (str_store_string, s11, "str_uncle"),
  33020. (try_end),
  33021. (else_try),
  33022. (lt, ":relation_strength", 2),#Skip this check if a stronger relation has been found.
  33023. #Test if troop_2 is married to a sibling of one of troop_1's parents, pt. 1
  33024. (ge, ":spouse_of_2", 0),
  33025. (neg|troop_slot_eq, ":spouse_of_2", slot_troop_father, -1),
  33026. (this_or_next|troop_slot_eq, ":spouse_of_2", slot_troop_father, ":paternal_grandfather_of_1"),
  33027. (troop_slot_eq, ":spouse_of_2", slot_troop_father, ":maternal_grandfather_of_1"),
  33028. (assign, ":relation_strength", 2),
  33029. (try_begin),
  33030. (eq, ":gender_1", tf_female),
  33031. (str_store_string, s11, "str_niece"),
  33032. (else_try),
  33033. (str_store_string, s11, "str_nephew"),
  33034. (try_end),
  33035. (else_try),
  33036. (lt, ":relation_strength", 2),#Skip this check if a stronger relation has been found.
  33037. #Test if troop_2 is married to a sibling of one of troop_1's parents, pt. 2
  33038. (ge, ":spouse_of_2", 0),
  33039. (neg|troop_slot_eq, ":spouse_of_2", slot_troop_mother, -1),
  33040. (this_or_next|troop_slot_eq, ":spouse_of_2", slot_troop_mother, ":paternal_grandmother_of_1"),
  33041. (troop_slot_eq, ":spouse_of_2", slot_troop_mother, ":maternal_grandmother_of_1"),
  33042. (assign, ":relation_strength", 2),
  33043. (try_begin),
  33044. (eq, ":gender_1", tf_female),
  33045. (str_store_string, s11, "str_niece"),
  33046. (else_try),
  33047. (str_store_string, s11, "str_nephew"),
  33048. (try_end),
  33049. (try_end),
  33050. ##diplomacy end+
  33051. (assign, reg4, ":gender_1"),
  33052. (assign, reg0, ":relation_strength"),
  33053. ]),
  33054.  
  33055.  
  33056. # script_complete_family_relations
  33057. # Inputs: none
  33058. # Outputs: none
  33059.  
  33060. #complete family relations removed
  33061.  
  33062. # script_collect_friendly_parties
  33063. # Fills the party p_collective_friends with the members of parties attached to main_party and ally_party_no
  33064. ("collect_friendly_parties",
  33065. [
  33066. (party_collect_attachments_to_party, "p_main_party", "p_collective_friends"),
  33067. (try_begin),
  33068. (gt, "$g_ally_party", 0),
  33069. (party_collect_attachments_to_party, "$g_ally_party", "p_temp_party"),
  33070. (assign, "$g_move_heroes", 1),
  33071. (call_script, "script_party_add_party", "p_collective_friends", "p_temp_party"),
  33072. (try_end),
  33073. ]),
  33074.  
  33075. # script_encounter_calculate_fit
  33076. # Input: arg1 = troop_no
  33077. # Output: none
  33078. ("encounter_calculate_fit",
  33079. [
  33080. #(assign, "$g_enemy_fit_for_battle_old", "$g_enemy_fit_for_battle"),
  33081. #(assign, "$g_friend_fit_for_battle_old", "$g_friend_fit_for_battle"),
  33082. #(assign, "$g_main_party_fit_for_battle_old", "$g_main_party_fit_for_battle"),
  33083. (call_script, "script_party_count_fit_for_battle", "p_main_party"),
  33084. #(assign, "$g_main_party_fit_for_battle", reg(0)),
  33085. (call_script, "script_collect_friendly_parties"),
  33086. (call_script, "script_party_count_fit_for_battle", "p_collective_friends"),
  33087. (assign, "$g_friend_fit_for_battle", reg(0)),
  33088.  
  33089. (party_clear, "p_collective_ally"),
  33090. (try_begin),
  33091. (gt, "$g_ally_party", 0),
  33092. (party_is_active, "$g_ally_party"),
  33093. (party_collect_attachments_to_party, "$g_ally_party", "p_collective_ally"),
  33094. #(call_script, "script_party_count_fit_for_battle", "p_collective_ally"),
  33095. #(val_add, "$g_friend_fit_for_battle", reg(0)),
  33096. #SB : pre-process command structure here
  33097. (party_get_num_attached_parties, ":attached", "$g_ally_party"),
  33098. (troop_get_slot, ":limit", "$g_player_troop", slot_troop_renown),
  33099. (val_sub, ":limit", dplmc_command_renown_limit),
  33100. (game_get_reduce_campaign_ai, ":bonus"),
  33101. (val_mul, ":bonus", "$player_right_to_rule"),
  33102. (val_add, ":limit", ":bonus"),
  33103. (try_for_range, ":rank", 0, ":attached"),
  33104. (party_get_attached_party_with_rank, ":party_no", "$g_ally_party", ":rank"),
  33105. (assign, ":continue", -1),
  33106.  
  33107. (try_begin),
  33108. (eq, ":party_no", "p_main_party"),
  33109. (assign, ":continue", 0),
  33110. (else_try),
  33111. (store_faction_of_party, ":party_faction", ":party_no"),
  33112. (party_stack_get_troop_id, ":leader_troop_id", ":party_no", 0),
  33113. (assign, ":continue", -1), #by default, not under command
  33114. (try_end),
  33115.  
  33116. (try_begin), #under command if marshal
  33117. (eq, ":party_faction", "$players_kingdom"),
  33118. (try_begin), #as marshal
  33119. # (is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
  33120. # (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
  33121. # (assign, ":continue", 0),
  33122. # (else_try), #as ruler/pretender marshal
  33123. # (faction_slot_eq, ":party_faction", slot_faction_state, sfs_active),
  33124. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", ":party_faction"),
  33125. (ge, reg0, DPLMC_FACTION_STANDING_MARSHALL),
  33126. # (this_or_next|faction_slot_eq, ":party_faction", slot_faction_marshall, "trp_player"),
  33127. # (faction_slot_eq, ":party_faction", slot_faction_leader, "$g_player_troop"),
  33128. (assign, ":continue", 0),
  33129. (try_end),
  33130. (eq, ":continue", -1), #If still not satisfied, check other conditions
  33131. (else_try), #or high enough renown
  33132. (troop_slot_eq, ":leader_troop_id", slot_troop_occupation, slto_kingdom_hero),
  33133. (troop_get_slot, ":renown", ":leader_troop_id", slot_troop_renown),
  33134. (call_script, "script_troop_get_relation_with_troop", ":leader_troop_id", "$g_player_troop"),
  33135. (val_sub, ":renown", reg0), #higher relation means less renown needed.
  33136. (le, ":renown", ":limit"),
  33137. (assign, ":continue", 0),
  33138. (else_try), #straggler parties - patrols, caravans, etc.
  33139. (neg|is_between, ":leader_troop_id", active_npcs_begin, active_npcs_end),
  33140. (assign, ":continue", 0),
  33141. (try_end),
  33142. (party_set_slot, ":party_no", slot_party_temp_slot_1, ":continue"),
  33143. (try_begin),
  33144. (ge, "$cheat_mode", 1),
  33145. (assign, reg0, ":continue"),
  33146. # (str_store_party_name, s0, ":party_no"),
  33147. (str_store_party_name, s0, ":party_no"),
  33148. (faction_get_color, ":color", ":party_faction"),
  33149. (display_message, "@{s0} will {reg0?:not }be under your command", ":color"),
  33150. (try_end),
  33151. (try_end),
  33152. (try_end),
  33153.  
  33154. (party_clear, "p_collective_enemy"),
  33155. (try_begin),
  33156. (party_is_active, "$g_enemy_party"),
  33157. (party_collect_attachments_to_party, "$g_enemy_party", "p_collective_enemy"),
  33158. (try_end),
  33159. (call_script, "script_party_count_fit_for_battle", "p_collective_enemy"),
  33160. (assign, "$g_enemy_fit_for_battle", reg(0)),
  33161. (assign, reg11, "$g_enemy_fit_for_battle"),
  33162. (assign, reg10, "$g_friend_fit_for_battle"),
  33163. ]),
  33164.  
  33165. # script_encounter_init_variables
  33166. # Input: arg1 = troop_no
  33167. # Output: none
  33168. ("encounter_init_variables",
  33169. [
  33170. (assign, "$capture_screen_shown", 0),
  33171. (assign, "$loot_screen_shown", 0),
  33172. (assign, "$thanked_by_ally_leader", 0),
  33173. (assign, "$g_battle_result", 0),
  33174. (assign, "$cant_leave_encounter", 0),
  33175. (assign, "$cant_talk_to_enemy", 0),
  33176. (assign, "$last_defeated_hero", 0),
  33177. (assign, "$last_freed_hero", 0),
  33178.  
  33179. (call_script, "script_encounter_calculate_fit"),
  33180. (call_script, "script_party_copy", "p_main_party_backup", "p_main_party"),
  33181. ##diplomacy start+
  33182. #If terrain advantage is enabled, use it to initialize the variables.
  33183. (assign, ":terrain_code", -1),
  33184. (try_begin),
  33185. (eq, "$g_dplmc_terrain_advantage", DPLMC_TERRAIN_ADVANTAGE_ENABLE),
  33186. (lt, "$g_encounter_is_in_village", 1),#Do not apply to village encounters
  33187. (try_begin),
  33188. (encountered_party_is_attacker),
  33189. (call_script, "script_dplmc_get_terrain_code_for_battle", "$g_encountered_party", "p_main_party"),
  33190. (else_try),
  33191. (call_script, "script_dplmc_get_terrain_code_for_battle", "p_main_party", "$g_encountered_party"),
  33192. (try_end),
  33193. (assign, ":terrain_code", reg0),
  33194. #calculate party strength with terrain
  33195. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_main_party", ":terrain_code", 0, 1),
  33196. (assign, "$g_starting_strength_main_party", reg0),
  33197. (try_begin),
  33198. #Print debug Message
  33199. (ge, "$cheat_mode", 1),
  33200. (assign, reg2, ":terrain_code"),
  33201. (display_message, "@{!}DEBUG - Main party raw strength {reg1}, terrain code {reg2}, modified strength {reg0}"),
  33202. (try_end),
  33203. #calculate enemy strength with terrain
  33204. (call_script, "script_party_copy", "p_encountered_party_backup", "p_collective_enemy"),
  33205. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_collective_enemy", ":terrain_code", 0, 1),
  33206. (assign, "$g_starting_strength_enemy_party", reg0),
  33207. (assign, "$g_strength_contribution_of_player", 100),
  33208. (try_begin),
  33209. (ge, "$cheat_mode", 1),#debug
  33210. (assign, reg2, ":terrain_code"),
  33211. (display_message, "@{!} DEBUG - Enemy party raw strength {reg1}, terrain code {reg2}, modified strength {reg0}"),
  33212. (try_end),
  33213. #calculate friends strength with terrain
  33214. (call_script, "script_party_copy", "p_collective_friends_backup", "p_collective_friends"),
  33215. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_collective_friends", ":terrain_code", 0, 1),
  33216. (assign, "$g_starting_strength_friends", reg0),
  33217. (else_try),
  33218. ##Calculate all party strengths without terrain:
  33219. #calculate main party strength
  33220. (call_script, "script_party_calculate_strength", "p_main_party", 0),
  33221. (assign, "$g_starting_strength_main_party", reg0),
  33222. #calculate enemy strength
  33223. (call_script, "script_party_copy", "p_encountered_party_backup", "p_collective_enemy"),
  33224. (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
  33225. (assign, "$g_starting_strength_enemy_party", reg0),
  33226. (assign, "$g_strength_contribution_of_player", 100),
  33227. #calculate friends strength
  33228. (call_script, "script_party_copy", "p_collective_friends_backup", "p_collective_friends"),
  33229. (call_script, "script_party_calculate_strength", "p_collective_friends", 0),
  33230. (assign, "$g_starting_strength_friends", reg0),
  33231. (try_end),
  33232. ##diplomacy end+
  33233.  
  33234. (store_mul, "$g_strength_contribution_of_player","$g_starting_strength_main_party", 100), # reduce contribution if we are helping someone.
  33235.  
  33236. (try_begin),
  33237. (gt, "$g_starting_strength_friends", 0), #this new to prevent occasional div by zero error
  33238. (val_div, "$g_strength_contribution_of_player","$g_starting_strength_friends"),
  33239. (else_try),
  33240. (assign, "$g_strength_contribution_of_player", 100), #Or zero, maybe
  33241. (try_end),
  33242.  
  33243. (party_clear, "p_routed_enemies"), #new
  33244. (assign, "$num_routed_us", 0),#newtoday
  33245. (assign, "$num_routed_allies", 0),#newtoday
  33246. (assign, "$num_routed_enemies", 0),#newtoday
  33247. (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  33248. (try_for_range, ":i_stack", 0, ":num_stacks"),
  33249. (party_stack_get_troop_id, ":stack_troop_id", "p_main_party", ":i_stack"),
  33250. (try_begin),
  33251. (troop_set_slot, ":stack_troop_id", slot_troop_player_routed_agents, 0),
  33252. #(troop_set_slot, ":stack_troop_id", slot_troop_enemy_routed_agents, 0),
  33253. #(troop_set_slot, ":stack_troop_id", slot_troop_ally_routed_agents, 0),
  33254. (try_end),
  33255. (try_end),
  33256.  
  33257. (party_get_num_companion_stacks, ":num_stacks", "p_collective_friends"),
  33258. (try_for_range, ":i_stack", 0, ":num_stacks"),
  33259. (party_stack_get_troop_id, ":stack_troop_id", "p_collective_friends", ":i_stack"),
  33260. (try_begin),
  33261. #(troop_set_slot, ":stack_troop_id", slot_troop_player_routed_agents, 0),
  33262. #(troop_set_slot, ":stack_troop_id", slot_troop_enemy_routed_agents, 0),
  33263. (troop_set_slot, ":stack_troop_id", slot_troop_ally_routed_agents, 0),
  33264. (try_end),
  33265. (try_end),
  33266.  
  33267. (party_get_num_companion_stacks, ":num_stacks", "p_collective_enemy"),
  33268. (try_for_range, ":i_stack", 0, ":num_stacks"),
  33269. (party_stack_get_troop_id, ":stack_troop_id", "p_collective_enemy", ":i_stack"),
  33270. (try_begin),
  33271. #(troop_set_slot, ":stack_troop_id", slot_troop_player_routed_agents, 0),
  33272. (troop_set_slot, ":stack_troop_id", slot_troop_enemy_routed_agents, 0),
  33273. #(troop_set_slot, ":stack_troop_id", slot_troop_ally_routed_agents, 0),
  33274. (try_end),
  33275. (try_end),
  33276.  
  33277. (try_for_range, ":cur_faction", npc_kingdoms_begin, npc_kingdoms_end),
  33278. (faction_set_slot, ":cur_faction", slot_faction_num_routed_agents, 0),
  33279. (try_end),
  33280.  
  33281. (assign, "$routed_party_added", 0), #new
  33282. (party_clear, "p_total_enemy_casualties"), #new
  33283.  
  33284. # (try_begin),
  33285. # (gt, "$g_ally_party", 0),
  33286. # (call_script, "script_party_copy", "p_ally_party_backup", "p_collective_ally"),
  33287. # (call_script, "script_party_calculate_strength", "p_collective_ally"),
  33288. # (assign, "$g_starting_strength_ally_party", reg0),
  33289. # (store_add, ":starting_strength_factor_combined","$g_starting_strength_ally_party","$g_starting_strength_main_party"),
  33290. # (store_mul, "$g_strength_contribution_of_player","$g_starting_strength_main_party", 80), #reduce contribution if we are helping someone.
  33291. # (val_div, "$g_strength_contribution_of_player",":starting_strength_factor_combined"),
  33292. # (try_end),
  33293. ]),
  33294.  
  33295. # script_calculate_renown_value
  33296. # Input: arg1 = troop_no
  33297. # Output: fills $battle_renown_value
  33298. ("calculate_renown_value",
  33299. [
  33300. ##diplomacy start+
  33301. #If terrain advantage is enabled, use it to avoid messing up cached
  33302. #strength values, but do not take it into consideration for renown
  33303. #granted.
  33304. (assign, ":main_party_strength", 1),
  33305. (assign, ":enemy_strength", 1),
  33306. (assign, ":friends_strength", 1),
  33307. (assign, ":terrain_code", -1),
  33308. (try_begin),
  33309. (eq, "$g_dplmc_terrain_advantage", DPLMC_TERRAIN_ADVANTAGE_ENABLE),
  33310. (try_begin),
  33311. (encountered_party_is_attacker),
  33312. (call_script, "script_dplmc_get_terrain_code_for_battle", "$g_encountered_party", "p_main_party"),
  33313. (else_try),
  33314. (call_script, "script_dplmc_get_terrain_code_for_battle", "p_main_party", "$g_encountered_party"),
  33315. (try_end),
  33316. (assign, ":terrain_code", reg0),
  33317. ##Alternate option: calculate with terrain, but don't use it for renown
  33318. #(but do use it to update the cached strength for the party)
  33319. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_main_party", ":terrain_code",0,1),
  33320. (assign, ":main_party_strength", reg1),#use non-terrain version!
  33321. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_collective_enemy", ":terrain_code",0,1),
  33322. (assign, ":enemy_strength", reg1),#use non-terrain version!
  33323. (call_script, "script_dplmc_party_calculate_strength_in_terrain", "p_collective_friends", ":terrain_code",0,1),
  33324. (assign, ":friends_strength", reg1),#use non-terrain version!
  33325. (else_try),
  33326. ##Original option: calculate without terrain
  33327. (call_script, "script_party_calculate_strength", "p_main_party", 0),
  33328. (assign, ":main_party_strength", reg0),
  33329. (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
  33330. (assign, ":enemy_strength", reg0),
  33331. (call_script, "script_party_calculate_strength", "p_collective_friends", 0),
  33332. (assign, ":friends_strength", reg0),
  33333. (try_end),
  33334. ##diplomacy end+
  33335.  
  33336. (val_add, ":friends_strength", 1),
  33337. (store_mul, ":enemy_strength_ratio", ":enemy_strength", 100),
  33338. (val_div, ":enemy_strength_ratio", ":friends_strength"),
  33339.  
  33340. (assign, ":renown_val", ":enemy_strength"),
  33341. (val_mul, ":renown_val", ":enemy_strength_ratio"),
  33342. (val_div, ":renown_val", 100),
  33343.  
  33344. (val_mul, ":renown_val", ":main_party_strength"),
  33345. (val_div, ":renown_val",":friends_strength"),
  33346.  
  33347. (store_div, "$battle_renown_value", ":renown_val", 5),
  33348. (val_min, "$battle_renown_value", 2500),
  33349. (convert_to_fixed_point, "$battle_renown_value"),
  33350. (store_sqrt, "$battle_renown_value", "$battle_renown_value"),
  33351. (convert_from_fixed_point, "$battle_renown_value"),
  33352. (assign, reg8, "$battle_renown_value"),
  33353. (display_message, "@Renown value for this battle is {reg8}.",0xFFFFFFFF),
  33354. ]),
  33355.  
  33356.  
  33357. ## # script_calculate_weekly_wage_for_player
  33358. ## # Input: none
  33359. ## # Output: none
  33360. ## ("calculate_weekly_wage_for_player",
  33361. ## [
  33362. ## (call_script, "script_calculate_weekly_party_wage", "p_main_party"),
  33363. ## (assign, ":result", reg0),
  33364. ## (try_for_parties, ":party_no"),
  33365. ## (store_faction_of_party, ":party_faction", ":party_no"),
  33366. ## (eq, ":party_faction", "fac_player_supporters_faction"),
  33367. ## (call_script, "script_calculate_weekly_party_wage", ":party_no"),
  33368. ## (val_add, ":result", reg0),
  33369. ## (try_end),
  33370. ## (assign, reg0, ":result"),
  33371. ## ]),
  33372.  
  33373.  
  33374. # script_get_first_agent_with_troop_id
  33375. # Input: arg1 = troop_no
  33376. # Output: agent_id
  33377. ("cf_get_first_agent_with_troop_id",
  33378. [
  33379. (store_script_param_1, ":troop_no"),
  33380. # (store_script_param_2, ":agent_no_to_begin_searching_after"),
  33381. (assign, ":result", -1),
  33382. (try_for_agents, ":cur_agent"),
  33383. (eq, ":result", -1),
  33384. ## (try_begin),
  33385. ## (eq, ":cur_agent", ":agent_no_to_begin_searching_after"),
  33386. ## (assign, ":agent_no_to_begin_searching_after", -1),
  33387. ## (try_end),
  33388. ## (eq, ":agent_no_to_begin_searching_after", -1),
  33389. (agent_get_troop_id, ":cur_troop_no", ":cur_agent"),
  33390. (eq, ":cur_troop_no", ":troop_no"),
  33391. (assign, ":result", ":cur_agent"),
  33392. (try_end),
  33393. (assign, reg0, ":result"),
  33394. (neq, reg0, -1),
  33395. ]),
  33396.  
  33397.  
  33398. # script_cf_team_get_average_position_of_agents_with_type_to_pos1
  33399. # Input: arg1 = team_no, arg2 = class_no (grc_everyone, grc_infantry, grc_cavalry, grc_archers, grc_heroes)
  33400. # Output: none, pos1 = average_position (0,0,0 if there are no matching agents)
  33401. ("cf_team_get_average_position_of_agents_with_type_to_pos1",
  33402. [
  33403. (store_script_param_1, ":team_no"),
  33404. (store_script_param_2, ":division_no"),
  33405. (assign, ":total_pos_x", 0),
  33406. (assign, ":total_pos_y", 0),
  33407. (assign, ":total_pos_z", 0),
  33408. (assign, ":num_agents", 0),
  33409. (set_fixed_point_multiplier, 100),
  33410. (try_for_agents, ":cur_agent"),
  33411. (agent_is_alive, ":cur_agent"),
  33412. (agent_is_human, ":cur_agent"),
  33413. (agent_get_team, ":cur_team_no", ":cur_agent"),
  33414. (eq, ":cur_team_no", ":team_no"),
  33415. (agent_get_division, ":cur_agent_division", ":cur_agent"),
  33416. (this_or_next|eq, ":division_no", grc_everyone),
  33417. (eq, ":division_no", ":cur_agent_division"),
  33418. (agent_get_position, pos1, ":cur_agent"),
  33419. (position_get_x, ":cur_pos_x", pos1),
  33420. (val_add, ":total_pos_x", ":cur_pos_x"),
  33421. (position_get_y, ":cur_pos_y", pos1),
  33422. (val_add, ":total_pos_y", ":cur_pos_y"),
  33423. (position_get_z, ":cur_pos_z", pos1),
  33424. (val_add, ":total_pos_z", ":cur_pos_z"),
  33425. (val_add, ":num_agents", 1),
  33426. (try_end),
  33427. (gt, ":num_agents", 1),
  33428. (val_div, ":total_pos_x", ":num_agents"),
  33429. (val_div, ":total_pos_y", ":num_agents"),
  33430. (val_div, ":total_pos_z", ":num_agents"),
  33431. (init_position, pos1),
  33432. (position_move_x, pos1, ":total_pos_x"),
  33433. (position_move_y, pos1, ":total_pos_y"),
  33434. (position_move_z, pos1, ":total_pos_z"),
  33435. ]),
  33436.  
  33437. # script_cf_turn_windmill_fans
  33438. # Input: arg1 = instance_no (none = 0)
  33439. # Output: none
  33440. ("cf_turn_windmill_fans",
  33441. [(store_script_param_1, ":instance_no"),
  33442. (scene_prop_get_instance, ":windmill_fan_object", "spr_windmill_fan_turning", ":instance_no"),
  33443. (ge, ":windmill_fan_object", 0),
  33444. (prop_instance_get_position, pos1, ":windmill_fan_object"),
  33445. (position_rotate_y, pos1, 10),
  33446. (prop_instance_animate_to_position, ":windmill_fan_object", pos1, 100),
  33447. (val_add, ":instance_no", 1),
  33448. (call_script, "script_cf_turn_windmill_fans", ":instance_no"),
  33449. ]),
  33450.  
  33451. # script_print_party_members
  33452. # Input: arg1 = party_no
  33453. # Output: s51 = output string. "noone" if the party is empty
  33454. ("print_party_members",
  33455. [
  33456. (store_script_param_1, ":party_no"),
  33457. (party_get_num_companion_stacks, ":num_stacks", ":party_no"),
  33458. (assign, reg10, ":num_stacks"),
  33459. (try_for_range, ":i_stack", 0, ":num_stacks"),
  33460. (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  33461. (troop_is_hero, ":stack_troop"),
  33462. (try_begin),
  33463. (eq, ":i_stack", 0),
  33464. (str_store_troop_name, s51, ":stack_troop"),
  33465. (try_end),
  33466. (str_store_troop_name, s52, ":stack_troop"),
  33467. (try_begin),
  33468. (eq, ":i_stack", 1),
  33469. (str_store_string, s51, "str_s52_and_s51"),
  33470. (else_try),
  33471. (gt, ":i_stack", 1),
  33472. (str_store_string, s51, "str_s52_comma_s51"),
  33473. (try_end),
  33474. (try_end),
  33475. (try_begin),
  33476. (eq, ":num_stacks", 0),
  33477. (str_store_string, s51, "str_noone"),
  33478. (try_end),
  33479. ]),
  33480.  
  33481. # script_round_value
  33482. # Input: arg1 = value
  33483. # Output: reg0 = rounded_value
  33484. ("round_value",
  33485. [
  33486. (store_script_param_1, ":value"),
  33487. (try_begin),
  33488. (lt, ":value", 100),
  33489. (neq, ":value", 0),
  33490. (val_add, ":value", 5),
  33491. (val_div, ":value", 10),
  33492. (val_mul, ":value", 10),
  33493. (try_begin),
  33494. (eq, ":value", 0),
  33495. (assign, ":value", 5),
  33496. (try_end),
  33497. (else_try),
  33498. (lt, ":value", 300),
  33499. (val_add, ":value", 25),
  33500. (val_div, ":value", 50),
  33501. (val_mul, ":value", 50),
  33502. (else_try),
  33503. (val_add, ":value", 50),
  33504. (val_div, ":value", 100),
  33505. (val_mul, ":value", 100),
  33506. (try_end),
  33507. (assign, reg0, ":value"),
  33508. ]),
  33509.  
  33510.  
  33511. # script_change_banners_and_chest
  33512. # Input: none
  33513. # Output: none
  33514. ("change_banners_and_chest",
  33515. [(party_get_slot, ":cur_leader", "$g_encountered_party", slot_town_lord),
  33516. (try_begin),
  33517. (ge, ":cur_leader", 0),
  33518. #normal_banner_begin
  33519. (troop_get_slot, ":troop_banner_object", ":cur_leader", slot_troop_banner_scene_prop),
  33520. (gt, ":troop_banner_object", 0),
  33521. (replace_scene_props, banner_scene_props_begin, ":troop_banner_object"),
  33522. (else_try),
  33523. (replace_scene_props, banner_scene_props_begin, "spr_empty"),
  33524. (try_end),
  33525. (try_begin),
  33526. (neq, ":cur_leader", "trp_player"),
  33527. (replace_scene_props, "spr_player_chest", "spr_locked_player_chest"),
  33528. (try_end),
  33529. ]),
  33530.  
  33531.  
  33532. # script_remove_siege_objects
  33533. # Input: none
  33534. # Output: none
  33535. ("remove_siege_objects",
  33536. [
  33537. (replace_scene_props, "spr_battlement_a_destroyed", "spr_battlement_a"),
  33538. (replace_scene_props, "spr_snowy_castle_battlement_a_destroyed", "spr_snowy_castle_battlement_a"),
  33539. (replace_scene_props, "spr_castle_e_battlement_a_destroyed", "spr_castle_e_battlement_a"),
  33540. (replace_scene_props, "spr_castle_battlement_a_destroyed", "spr_castle_battlement_a"),
  33541. (replace_scene_props, "spr_castle_battlement_b_destroyed", "spr_castle_battlement_b"),
  33542. (replace_scene_props, "spr_earth_wall_a2", "spr_earth_wall_a"),
  33543. (replace_scene_props, "spr_earth_wall_b2", "spr_earth_wall_b"),
  33544. (replace_scene_props, "spr_belfry_platform_b", "spr_empty"),
  33545. (replace_scene_props, "spr_belfry_platform_a", "spr_empty"),
  33546. (replace_scene_props, "spr_belfry_a", "spr_empty"),
  33547. (replace_scene_props, "spr_belfry_wheel", "spr_empty"),
  33548. (replace_scene_props, "spr_siege_ladder_move_6m", "spr_empty"),
  33549. (replace_scene_props, "spr_siege_ladder_move_8m", "spr_empty"),
  33550. (replace_scene_props, "spr_siege_ladder_move_10m", "spr_empty"),
  33551. (replace_scene_props, "spr_siege_ladder_move_12m", "spr_empty"),
  33552. (replace_scene_props, "spr_siege_ladder_move_14m", "spr_empty"),
  33553. (replace_scene_props, "spr_siege_ladder_12m", "spr_empty"),
  33554. (replace_scene_props, "spr_siege_ladder_14m", "spr_empty"),
  33555. (replace_scene_props, "spr_mangonel", "spr_empty"),
  33556. (replace_scene_props, "spr_trebuchet_old", "spr_empty"),
  33557. (replace_scene_props, "spr_trebuchet_new", "spr_empty"),
  33558. (replace_scene_props, "spr_stone_ball", "spr_empty"),
  33559. (replace_scene_props, "spr_village_fire_big", "spr_empty"),
  33560. ]),
  33561.  
  33562. # script_describe_relation_to_s63
  33563. # Input: arg1 = relation (-100 .. 100)
  33564. # Output: none
  33565. ("describe_relation_to_s63",
  33566. [(store_script_param_1, ":relation"),
  33567. (store_add, ":normalized_relation", ":relation", 100),
  33568. (val_add, ":normalized_relation", 5),
  33569. (store_div, ":str_offset", ":normalized_relation", 10),
  33570. (val_clamp, ":str_offset", 0, 20),
  33571. (store_add, ":str_id", "str_relation_mnus_100", ":str_offset"),
  33572. (str_store_string, s63, ":str_id"),
  33573. ]),
  33574.  
  33575. # script_describe_center_relation_to_s3
  33576. # Input: arg1 = relation (-100 .. 100)
  33577. # Output: none
  33578. ("describe_center_relation_to_s3",
  33579. [(store_script_param_1, ":relation"),
  33580. (store_add, ":normalized_relation", ":relation", 100),
  33581. (val_add, ":normalized_relation", 5),
  33582. (store_div, ":str_offset", ":normalized_relation", 10),
  33583. (val_clamp, ":str_offset", 0, 20),
  33584. (store_add, ":str_id", "str_center_relation_mnus_100", ":str_offset"),
  33585. (str_store_string, s3, ":str_id"),
  33586. ]),
  33587.  
  33588.  
  33589. # script_center_ambiance_sounds
  33590. # Input: none
  33591. # Output: none
  33592. # to be called every two seconds
  33593. ("center_ambiance_sounds",
  33594. [
  33595. (assign, ":sound_1", -1),
  33596. (assign, ":sound_2", -1),
  33597. (assign, ":sound_3", -1),
  33598. (assign, ":sound_4", -1),
  33599. (assign, ":sound_5", -1),
  33600. (try_begin),
  33601. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_village),
  33602. (try_begin),
  33603. (neg|is_currently_night),
  33604. (assign, ":sound_3", "snd_distant_dog_bark"),
  33605. (assign, ":sound_3", "snd_distant_chicken"),
  33606. (else_try),
  33607. (assign, ":sound_1", "snd_distant_dog_bark"),
  33608. (assign, ":sound_2", "snd_distant_owl"),
  33609. (try_end),
  33610. (else_try),
  33611. (party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
  33612. (try_begin),
  33613. (neg|is_currently_night),
  33614. (assign, ":sound_1", "snd_distant_carpenter"),
  33615. (assign, ":sound_2", "snd_distant_blacksmith"),
  33616. (assign, ":sound_3", "snd_distant_dog_bark"),
  33617. (else_try),
  33618. (assign, ":sound_1", "snd_distant_dog_bark"),
  33619. (try_end),
  33620. (try_end),
  33621. (try_begin),
  33622. (store_random_in_range, ":r", 0, 7),
  33623. (try_begin),
  33624. (eq, ":r", 1),
  33625. (ge, ":sound_1", 0),
  33626. (play_sound, ":sound_1"),
  33627. (else_try),
  33628. (eq, ":r", 2),
  33629. (ge, ":sound_2", 0),
  33630. (play_sound, ":sound_2"),
  33631. (else_try),
  33632. (eq, ":r", 3),
  33633. (ge, ":sound_3", 0),
  33634. (play_sound, ":sound_3"),
  33635. (else_try),
  33636. (eq, ":r", 4),
  33637. (ge, ":sound_4", 0),
  33638. (play_sound, ":sound_4"),
  33639. (else_try),
  33640. (eq, ":r", 5),
  33641. (ge, ":sound_5", 0),
  33642. (play_sound, ":sound_5"),
  33643. (try_end),
  33644. (try_end),
  33645. ]),
  33646.  
  33647. # script_center_set_walker_to_type
  33648. # Input: arg1 = center_no, arg2 = walker_no, arg3 = walker_type,
  33649. # Output: none
  33650. ("center_set_walker_to_type",
  33651. [
  33652. (store_script_param, ":center_no", 1),
  33653. (store_script_param, ":walker_no", 2),
  33654. (store_script_param, ":walker_type", 3),
  33655. (store_add, ":type_slot", slot_center_walker_0_type, ":walker_no"),
  33656. (party_set_slot, ":center_no", ":type_slot", ":walker_type"),
  33657. (party_get_slot, ":center_faction", ":center_no", slot_center_original_faction),
  33658. (faction_get_slot, ":center_culture", ":center_faction", slot_faction_culture),
  33659. (store_random_in_range, ":walker_troop_slot", 0, 2),
  33660. (try_begin),
  33661. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  33662. (val_add, ":walker_troop_slot", slot_faction_village_walker_male_troop),
  33663. (else_try),
  33664. (val_add, ":walker_troop_slot", slot_faction_town_walker_male_troop),
  33665. (try_end),
  33666. (try_begin),
  33667. (eq,":walker_type", walkert_spy),
  33668. (assign,":original_walker_slot",":walker_troop_slot"),
  33669. (val_add,":walker_troop_slot",4), # select spy troop id slot
  33670. (try_end),
  33671. (faction_get_slot, ":walker_troop_id", ":center_culture", ":walker_troop_slot"),
  33672. (try_begin),
  33673. (eq,":walker_type", walkert_spy),
  33674. (faction_get_slot, ":original_walker", ":center_culture", ":original_walker_slot"),
  33675. # restore spy inventory
  33676. (try_for_range,":item_no","itm_horse_meat","itm_wooden_stick"),
  33677. (store_item_kind_count,":num_items",":item_no",":original_walker"),
  33678. (ge,":num_items",1),
  33679. (store_item_kind_count,":num_items",":item_no",":walker_troop_id"),
  33680. (lt,":num_items",1),
  33681. (troop_add_items,":walker_troop_id",":item_no",1),
  33682. (try_end),
  33683. # determine spy recognition item
  33684. (store_random_in_range,":spy_item_type",itp_type_head_armor,itp_type_hand_armor),
  33685. (assign,":num",0),
  33686. (try_for_range,":item_no","itm_horse_meat","itm_wooden_stick"),
  33687. (store_item_kind_count,":num_items",":item_no",":walker_troop_id"),
  33688. (ge,":num_items",1),
  33689. (item_get_type, ":itp", ":item_no"),
  33690. (eq,":itp",":spy_item_type"),
  33691. (val_add,":num",1),
  33692. (troop_remove_items,":walker_troop_id",":item_no",":num_items"),
  33693. (try_end),
  33694. (store_random_in_range,":random_item",0,":num"),
  33695. (assign,":num",-1),
  33696. (try_for_range,":item_no","itm_horse_meat","itm_wooden_stick"),
  33697. (store_item_kind_count,":num_items",":item_no",":original_walker"),
  33698. (ge,":num_items",1),
  33699. (item_get_type, ":itp", ":item_no"),
  33700. (eq,":itp",":spy_item_type"),
  33701. (val_add,":num",1),
  33702. (eq,":num",":random_item"),
  33703. (troop_add_items,":walker_troop_id",":item_no",1),
  33704. (assign,":spy_item",":item_no"),
  33705. (try_end),
  33706. (assign,"$spy_item_worn",":spy_item"),
  33707. (assign,"$spy_quest_troop",":walker_troop_id"),
  33708. (troop_equip_items,":walker_troop_id"),
  33709. (try_end),
  33710. (store_add, ":troop_slot", slot_center_walker_0_troop, ":walker_no"),
  33711. (party_set_slot, ":center_no", ":troop_slot", ":walker_troop_id"),
  33712. (store_random_in_range, ":walker_dna", 0, 1000000),
  33713. (store_add, ":dna_slot", slot_center_walker_0_dna, ":walker_no"),
  33714. (party_set_slot, ":center_no", ":dna_slot", ":walker_dna"),
  33715. ]),
  33716.  
  33717.  
  33718. # script_cf_center_get_free_walker
  33719. # Input: arg1 = center_no
  33720. # Output: reg0 = walker no (can fail)
  33721. ("cf_center_get_free_walker",
  33722. [
  33723. (store_script_param, ":center_no", 1),
  33724. (assign, ":num_free_walkers", 0),
  33725. (try_for_range, ":walker_no", 0, num_town_walkers),
  33726. (store_add, ":type_slot", slot_center_walker_0_type, ":walker_no"),
  33727. (party_slot_eq, ":center_no", ":type_slot", walkert_default),
  33728. (val_add, ":num_free_walkers", 1),
  33729. (try_end),
  33730. (gt, ":num_free_walkers", 0),
  33731. (assign, reg0, -1),
  33732. (store_random_in_range, ":random_rank", 0, ":num_free_walkers"),
  33733. (try_for_range, ":walker_no", 0, num_town_walkers),
  33734. (store_add, ":type_slot", slot_center_walker_0_type, ":walker_no"),
  33735. (party_slot_eq, ":center_no", ":type_slot", walkert_default),
  33736. (val_sub, ":num_free_walkers", 1),
  33737. (eq, ":num_free_walkers", ":random_rank"),
  33738. (assign, reg0, ":walker_no"),
  33739. (try_end),
  33740. ]),
  33741.  
  33742. # script_center_remove_walker_type_from_walkers
  33743. # Input: arg1 = center_no, arg2 = walker_type,
  33744. # Output: reg0 = 1 if comment found, 0 otherwise; s61 will contain comment string if found
  33745. ("center_remove_walker_type_from_walkers",
  33746. [
  33747. (store_script_param, ":center_no", 1),
  33748. (store_script_param, ":walker_type", 2),
  33749. (try_for_range, ":walker_no", 0, num_town_walkers),
  33750. (store_add, ":type_slot", slot_center_walker_0_type, ":walker_no"),
  33751. (party_slot_eq, ":center_no", ":type_slot", ":walker_type"),
  33752. (call_script, "script_center_set_walker_to_type", ":center_no", ":walker_no", walkert_default),
  33753. (try_end),
  33754. ]),
  33755.  
  33756.  
  33757. # script_init_town_walkers
  33758. # Input: none
  33759. # Output: none
  33760. ("init_town_walkers",
  33761. [
  33762. (try_begin),
  33763. (eq, "$town_nighttime", 0),
  33764. (try_for_range, ":walker_no", 0, num_town_walkers),
  33765. (store_add, ":troop_slot", slot_center_walker_0_troop, ":walker_no"),
  33766. (party_get_slot, ":walker_troop_id", "$current_town", ":troop_slot"),
  33767. (gt, ":walker_troop_id", 0),
  33768. (store_add, ":entry_no", town_walker_entries_start, ":walker_no"),
  33769. (set_visitor, ":entry_no", ":walker_troop_id"),
  33770. (try_end),
  33771. (try_end),
  33772. ]),
  33773.  
  33774.  
  33775. # script_cf_enter_center_location_bandit_check
  33776. # Input: none
  33777. # Output: none
  33778. ("cf_enter_center_location_bandit_check",
  33779. [
  33780. (neq, "$town_nighttime", 0),
  33781. (party_slot_ge, "$current_town", slot_center_has_bandits, 1),
  33782. (eq, "$g_defending_against_siege", 0),#Skip if the center is under siege (because of resting)
  33783. (eq, "$sneaked_into_town", disguise_none),#Skip if sneaked
  33784. (try_begin),
  33785. (party_slot_eq, "$current_town", slot_party_type, spt_village),
  33786. (party_get_slot, ":cur_scene", "$current_town", slot_castle_exterior),
  33787. (else_try),
  33788. (party_get_slot, ":cur_scene", "$current_town", slot_town_center),
  33789. (try_end),
  33790. (modify_visitors_at_site, ":cur_scene"),
  33791. (reset_visitors),
  33792. (party_get_slot, ":bandit_troop", "$current_town", slot_center_has_bandits),
  33793. (store_character_level, ":level", "trp_player"),
  33794.  
  33795. (set_jump_mission, "mt_bandits_at_night"),
  33796. (try_begin),
  33797. (party_slot_eq, "$current_town", slot_party_type, spt_village),
  33798. (assign, ":spawn_amount", 2),
  33799. (store_div, ":level_fac", ":level", 10),
  33800. (val_add, ":spawn_amount", ":level_fac"),
  33801. (try_for_range, ":unused", 0, 3),
  33802. (gt, ":level", 10),
  33803. (store_random_in_range, ":random_no", 0, 100),
  33804. (lt, ":random_no", ":level"),
  33805. (val_add, ":spawn_amount", 1),
  33806. (try_end),
  33807. (set_visitors, 4, ":bandit_troop", ":spawn_amount"),
  33808. (assign, "$num_center_bandits", ":spawn_amount"),
  33809. (set_jump_entry, 2),
  33810. (else_try),
  33811. (assign, ":spawn_amount", 1),
  33812. (assign, "$num_center_bandits", 0),
  33813. (try_begin),
  33814. (gt, ":level", 15),
  33815. (store_random_in_range, ":random_no", 0, 100),
  33816. (lt, ":random_no", ":level"),
  33817. (assign, ":spawn_amount", 2),
  33818. (try_end),
  33819. (val_add, "$num_center_bandits", ":spawn_amount"),
  33820. (set_visitors, 11, ":bandit_troop", ":spawn_amount"),
  33821. (assign, ":spawn_amount", 1),
  33822. (try_begin),
  33823. (gt, ":level", 20),
  33824. (store_random_in_range, ":random_no", 0, 100),
  33825. (lt, ":random_no", ":level"),
  33826. (assign, ":spawn_amount", 2),
  33827. (try_end),
  33828. (set_visitors, 27, ":bandit_troop", ":spawn_amount"),
  33829. (val_add, "$num_center_bandits", ":spawn_amount"),
  33830. (try_begin),
  33831. (gt, ":level", 9),
  33832. (assign, ":spawn_amount", 1),
  33833. (try_begin),
  33834. (gt, ":level", 25),
  33835. (store_random_in_range, ":random_no", 0, 100),
  33836. (lt, ":random_no", ":level"),
  33837. (assign, ":spawn_amount", 2),
  33838. (try_end),
  33839. (set_visitors, 28, ":bandit_troop", ":spawn_amount"),
  33840. (val_add, "$num_center_bandits", ":spawn_amount"),
  33841. (try_end),
  33842. (assign, "$town_entered", 1),
  33843. (assign, "$all_doors_locked", 1),
  33844. (try_end),
  33845.  
  33846. (display_message, "@You have run into a trap!", message_negative),
  33847. #SB : store actual bandit names
  33848. (str_store_troop_name_plural, s1, ":bandit_troop"),
  33849. (display_message, "@You are attacked by a group of {s1}!", message_negative),
  33850. (play_sound, "snd_encounter_looters"), #more generic than bandit sounds
  33851. (jump_to_scene, ":cur_scene"),
  33852. (change_screen_mission),
  33853. ]),
  33854.  
  33855. # script_init_town_agent
  33856. # Input: none
  33857. # Output: none
  33858. ("init_town_agent",
  33859. [
  33860. (store_script_param, ":agent_no", 1),
  33861. (agent_get_troop_id, ":troop_no", ":agent_no"),
  33862. (set_fixed_point_multiplier, 100),
  33863. (assign, ":stand_animation", -1),
  33864. (try_begin),
  33865. (this_or_next|is_between, ":troop_no", armor_merchants_begin, armor_merchants_end),
  33866. (is_between, ":troop_no", weapon_merchants_begin, weapon_merchants_end),
  33867. (try_begin),
  33868. (troop_get_type, ":cur_troop_gender", ":troop_no"),
  33869. (eq, ":cur_troop_gender", 0),
  33870. (agent_set_animation, ":agent_no", "anim_stand_townguard"),
  33871. (else_try),
  33872. (agent_set_animation, ":agent_no", "anim_stand_townguard"),
  33873. (end_try),
  33874. (else_try),
  33875. (is_between, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  33876. (assign, ":stand_animation", "anim_stand_lady"),
  33877. (else_try),
  33878. (is_between, ":troop_no", active_npcs_begin, active_npcs_end),
  33879. (assign, ":stand_animation", "anim_stand_lord"),
  33880. (else_try),
  33881. (is_between, ":troop_no", soldiers_begin, soldiers_end),
  33882. (assign, ":stand_animation", "anim_stand_townguard"),
  33883. (try_end),
  33884. (try_begin),
  33885. (ge, ":stand_animation", 0),
  33886. (agent_set_stand_animation, ":agent_no", ":stand_animation"),
  33887. (agent_set_animation, ":agent_no", ":stand_animation"),
  33888. (store_random_in_range, ":random_no", 0, 100),
  33889. (agent_set_animation_progress, ":agent_no", ":random_no"),
  33890. (try_end),
  33891. ]),
  33892.  
  33893. # script_init_town_walker_agents
  33894. # Input: none
  33895. # Output: none
  33896. ("init_town_walker_agents",
  33897. [(assign, ":num_walkers", 0),
  33898. (try_for_agents, ":cur_agent"),
  33899. (agent_get_troop_id, ":cur_troop", ":cur_agent"),
  33900. (is_between, ":cur_troop", walkers_begin, walkers_end),
  33901. (val_add, ":num_walkers", 1),
  33902. (agent_get_position, pos1, ":cur_agent"),
  33903. (try_for_range, ":i_e_p", 9, 40),#Entry points
  33904. (entry_point_get_position, pos2, ":i_e_p"),
  33905. (get_distance_between_positions, ":distance", pos1, pos2),
  33906. (lt, ":distance", 200),
  33907. (agent_set_slot, ":cur_agent", 0, ":i_e_p"),
  33908. (try_end),
  33909. (call_script, "script_set_town_walker_destination", ":cur_agent"),
  33910. (try_end),
  33911. ]),
  33912.  
  33913. # script_agent_get_town_walker_details
  33914. # This script assumes this is one of town walkers.
  33915. # Input: agent_id
  33916. # Output: reg0: town_walker_type, reg1: town_walker_dna
  33917. ("agent_get_town_walker_details",
  33918. [(store_script_param, ":agent_no", 1),
  33919. (agent_get_entry_no, ":entry_no", ":agent_no"),
  33920. (store_sub, ":walker_no", ":entry_no", town_walker_entries_start),
  33921.  
  33922. (store_add, ":type_slot", slot_center_walker_0_type, ":walker_no"),
  33923. (party_get_slot, ":walker_type", "$current_town", ":type_slot"),
  33924. (store_add, ":dna_slot", slot_center_walker_0_dna, ":walker_no"),
  33925. (party_get_slot, ":walker_dna", "$current_town", ":dna_slot"),
  33926. (assign, reg0, ":walker_type"),
  33927. (assign, reg1, ":walker_dna"),
  33928. (assign, reg2, ":walker_no"),
  33929. ]),
  33930.  
  33931.  
  33932. ##diplomacy start+
  33933. ##WARNING: this will also clobber s0 now
  33934. ##diplomacy end+
  33935. ("town_walker_occupation_string_to_s14",
  33936. [
  33937. (store_script_param, ":agent_no", 1),
  33938.  
  33939. #Cairo, approx 1799:
  33940. #adult males = 114,000
  33941. #military, 10,400
  33942. #civil, including religious 5,000
  33943. #commerce 3,500
  33944. #merchants 4,500
  33945. #coffee shops, 1,500 (maybe broaden to inns and taverns)
  33946. #artisans 21,800
  33947. #workmen 4,300
  33948. #itinerants 8,600
  33949. #servants (inc water carriers) 26,400
  33950. (assign, ":check_for_good_price", 0),
  33951. ##diplomacy start+ escalate "sir/madame" to "my lord/lady" or "your highness" if appropriate
  33952. (call_script, "script_dplmc_print_subordinate_says_sir_madame_to_s0"),
  33953. ##diplomacy end+
  33954. (str_store_string, s14, "str_i_take_what_work_i_can_sirmadame_i_carry_water_or_help_the_merchants_with_their_loads_or_help_build_things_if_theres_things_to_be_built"),
  33955.  
  33956. (call_script, "script_agent_get_town_walker_details", ":agent_no"),
  33957. (assign, ":type", reg0),
  33958. (assign, ":walker_dna", reg1),
  33959.  
  33960. (assign, ":item", -1),
  33961. (assign, ":total_item_production", 0),
  33962. (try_for_range, ":trade_good", trade_goods_begin, trade_goods_end),
  33963. (call_script, "script_center_get_production", "$g_encountered_party", ":trade_good"),
  33964. (val_add, ":total_item_production", reg0),
  33965. (try_end),
  33966.  
  33967. (val_max, ":total_item_production", 1),
  33968.  
  33969. (store_mod, ":semi_random_number", ":walker_dna", ":total_item_production"),
  33970.  
  33971.  
  33972. (try_begin),
  33973. (eq, "$cheat_mode", 1),
  33974. (assign, reg4, ":walker_dna"),
  33975. (assign, reg5, ":total_item_production"),
  33976. (assign, reg7, ":semi_random_number"),
  33977. (display_message, "str_dna_reg4_total_production_reg5_modula_reg7"),
  33978. (try_end),
  33979.  
  33980. (try_for_range, ":trade_good", trade_goods_begin, trade_goods_end),
  33981. (gt, ":semi_random_number", -1),
  33982. (call_script, "script_center_get_production", "$g_encountered_party", ":trade_good"),
  33983. (val_sub, ":semi_random_number", reg0),
  33984. (lt, ":semi_random_number", 0),
  33985. (try_begin),
  33986. (eq, "$cheat_mode", 1),
  33987. (str_store_item_name, s9, ":trade_good"),
  33988. (display_message, "str_agent_produces_s9"),
  33989. (try_end),
  33990. (assign, ":item", ":trade_good"),
  33991. (try_end),
  33992.  
  33993.  
  33994. (try_begin),
  33995. (eq, ":type", walkert_needs_money),
  33996. (is_between, "$g_encountered_party", towns_begin, towns_end),
  33997. (str_store_string, s14, "str_im_not_doing_anything_sirmadame_theres_no_work_to_be_had_around_here_these_days"),
  33998. (else_try),
  33999. (eq, ":type", walkert_needs_money),
  34000. (str_store_string, s14, "str_im_not_doing_anything_sirmadame_i_have_no_land_of_my_own_and_theres_no_work_to_be_had_around_here_these_days"),
  34001. (else_try),
  34002. (eq, ":type", walkert_needs_money_helped),
  34003. (str_store_string, s14, "str_why_im_still_living_off_of_your_kindness_and_goodness_sirmadame_hopefully_there_will_be_work_shortly"),
  34004. (else_try),
  34005. (eq, ":item", "itm_grain"),
  34006. #SB : refactor
  34007. (try_begin),
  34008. (is_between, "$g_encountered_party", towns_begin, towns_end),
  34009. (str_store_string, s14, "str_i_work_in_the_fields_just_outside_the_walls_where_they_grow_grain_we_dont_quite_grow_enough_to_meet_our_needs_though_and_have_to_import_grain_from_the_surrounding_countryside"),
  34010. (else_try),
  34011. (str_store_string, s14, "str_i_work_mostly_in_the_fields_growing_grain_in_the_town_they_grind_it_to_make_bread_or_ale_and_we_can_also_boil_it_as_a_porridge"),
  34012. (try_end),
  34013. (assign, ":check_for_good_price", 1),
  34014. (else_try),
  34015. (eq, ":item", "itm_ale"),
  34016. (str_store_string, s14, "str_i_work_in_the_breweries_making_ale_the_poor_folk_drink_a_lot_of_it_as_its_cheaper_than_wine_we_make_it_with_grain_brought_in_from_the_countryside"),
  34017. (assign, ":check_for_good_price", 1),
  34018.  
  34019. (else_try),
  34020. (eq, ":item", "itm_bread"),
  34021. (str_store_string, s14, "str_i_work_in_a_mill_grinding_flour_to_make_bread_bread_is_cheap_keeps_well_and_fills_the_stomach"),
  34022. (assign, ":check_for_good_price", 1),
  34023.  
  34024. (else_try),
  34025. (eq, ":item", "itm_dried_meat"),
  34026. (str_store_string, s14, "str_i_tend_cattle_we_dry_and_salt_meat_to_preserve_it_and_make_cheese_from_the_milk"),
  34027. (assign, ":check_for_good_price", 1),
  34028.  
  34029. (else_try), #SB : combine two strings
  34030. (this_or_next|eq, ":item", "itm_cheese"),
  34031. (eq, ":item", "itm_butter"),
  34032. # (str_store_string, s14, "str_i_tend_cattle_we_dry_and_salt_meat_to_preserve_it_and_make_cheese_from_the_milk_so_it_doesnt_spoil"),
  34033. # (assign, ":check_for_good_price", 1),
  34034.  
  34035. # (else_try),
  34036. (str_store_string, s14, "str_i_tend_cattle_we_dry_and_salt_meat_to_preserve_it_and_make_cheese_from_the_milk_so_it_doesnt_spoil"),
  34037. (assign, ":check_for_good_price", 1),
  34038.  
  34039. (else_try), #SB : combine two strings
  34040. (this_or_next|eq, ":item", "itm_wool"),
  34041. (eq, ":item", "itm_sausages"),
  34042. # (str_store_string, s14, "str_i_tend_sheep_we_send_the_wool_to_the_cities_to_be_woven_into_cloth_and_make_mutton_sausage_when_we_cull_the_herds"),
  34043. # (assign, ":check_for_good_price", 1),
  34044.  
  34045. # (else_try),
  34046. # (eq, ":item", "itm_sausages"),
  34047. (str_store_string, s14, "str_i_tend_sheep_we_send_the_wool_to_the_cities_to_be_woven_into_cloth_and_make_mutton_sausage_when_we_cull_the_herds"),
  34048. (assign, ":check_for_good_price", 1),
  34049.  
  34050. (else_try),
  34051. (eq, ":item", "itm_wool_cloth"),
  34052. (str_store_string, s14, "str_i_work_at_a_loom_spinning_cloth_from_wool_wool_is_some_of_the_cheapest_cloth_you_can_buy_but_it_will_still_keep_you_warm"),
  34053. (assign, ":check_for_good_price", 1),
  34054.  
  34055. (else_try),
  34056. (eq, ":item", "itm_smoked_fish"),
  34057. (str_store_string, s14, "str_i_crew_a_fishing_boat_we_salt_and_smoke_the_flesh_to_sell_it_far_inland"),
  34058. (assign, ":check_for_good_price", 1),
  34059.  
  34060. (else_try),
  34061. (eq, ":item", "itm_salt"),
  34062. (str_store_string, s14, "str_i_sift_salt_from_a_nearby_flat_they_need_salt_everywhere_to_preserve_meat_and_fish"),
  34063. (assign, ":check_for_good_price", 1),
  34064.  
  34065. (else_try),
  34066. (eq, ":item", "itm_iron"),
  34067. (str_store_string, s14, "str_i_mine_iron_from_a_vein_in_a_nearby_cliffside_they_use_it_to_make_tools_arms_and_other_goods"),
  34068. (assign, ":check_for_good_price", 1),
  34069.  
  34070. (else_try),
  34071. (eq, ":item", "itm_pottery"),
  34072. (str_store_string, s14, "str_i_make_pottery_which_people_use_to_store_grain_and_carry_water"),
  34073. (assign, ":check_for_good_price", 1),
  34074.  
  34075. (else_try),
  34076. (eq, ":item", "itm_tools"),
  34077. (str_store_string, s14, "str_trade_explanation_tools"),
  34078. (assign, ":check_for_good_price", 1),
  34079.  
  34080. (else_try),
  34081. (eq, ":item", "itm_oil"),
  34082. (str_store_string, s14, "str_trade_explanation_oil"),
  34083. (assign, ":check_for_good_price", 1),
  34084.  
  34085. (else_try),
  34086. (eq, ":item", "itm_linen"),
  34087. (str_store_string, s14, "str_trade_explanation_linen"),
  34088. (assign, ":check_for_good_price", 1),
  34089.  
  34090. (else_try),
  34091. (eq, ":item", "itm_velvet"),
  34092. (str_store_string, s14, "str_trade_explanation_velvet"),
  34093. (assign, ":check_for_good_price", 1),
  34094.  
  34095. (else_try),
  34096. (eq, ":item", "itm_spice"),
  34097. (str_store_string, s14, "str_trade_explanation_spice"),
  34098. (assign, ":check_for_good_price", 1),
  34099. #SB : add missing explanation strings
  34100. (else_try),
  34101. (eq, ":item", "itm_apples"),
  34102. (str_store_string, s14, "str_trade_explanation_apples"),
  34103. (assign, ":check_for_good_price", 1),
  34104. (else_try),
  34105. (eq, ":item", "itm_raw_grapes"),
  34106. (str_store_string, s14, "str_trade_explanation_grapes"),
  34107. (assign, ":check_for_good_price", 1),
  34108. (else_try),
  34109. (eq, ":item", "itm_raw_dyes"),
  34110. (str_store_string, s14, "str_trade_explanation_dyes"),
  34111. (assign, ":check_for_good_price", 1),
  34112. (else_try),
  34113. (this_or_next|eq, ":item", "itm_raw_leather"),
  34114. (eq, ":item", "itm_leatherwork"),
  34115. (str_store_string, s14, "str_trade_explanation_leatherwork"),
  34116. (assign, ":check_for_good_price", 1),
  34117. (else_try),
  34118. (eq, ":item", "itm_raw_flax"),
  34119. (str_store_string, s14, "str_trade_explanation_flax"),
  34120. (assign, ":check_for_good_price", 1),
  34121. (else_try),
  34122. (eq, ":item", "itm_raw_date_fruit"),
  34123. (try_begin),
  34124. (is_between, "$g_encountered_party", towns_begin, towns_end),
  34125. (str_store_string, s14, "str_trade_explanation_dates_town"),
  34126. (else_try),
  34127. (str_store_string, s14, "str_trade_explanation_dates_village"),
  34128. (try_end),
  34129. (assign, ":check_for_good_price", 1),
  34130. (else_try),
  34131. (eq, ":item", "itm_raw_olives"),
  34132. (str_store_string, s14, "str_trade_explanation_olives"),
  34133. (assign, ":check_for_good_price", 1),
  34134. (try_end),
  34135.  
  34136.  
  34137. (try_begin),
  34138. (eq, ":check_for_good_price", 1),
  34139.  
  34140. (assign, ":trade_destination", -1),
  34141. (store_skill_level, ":trade_skill", "skl_trade", "trp_player"),
  34142.  
  34143. (try_begin),
  34144. (is_between, "$g_encountered_party", villages_begin, villages_end),
  34145. (party_get_slot, ":trade_town", "$g_encountered_party", slot_village_market_town),
  34146. (else_try),
  34147. (assign, ":trade_town", "$g_encountered_party"),
  34148. (try_end),
  34149.  
  34150. (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  34151. (store_add, ":cur_good_price_slot", ":item", ":item_to_price_slot"),
  34152. (party_get_slot, ":score_to_beat", ":trade_town", ":cur_good_price_slot"),
  34153. (val_add, ":score_to_beat", 400),
  34154. (store_mul, ":deduction_for_trade_skill", ":trade_skill", 35),
  34155. (try_begin),
  34156. (is_between, "$g_encountered_party", villages_begin, villages_end),
  34157. (val_add, ":score_to_beat", 200),
  34158. (try_end),
  34159. (val_sub, ":score_to_beat", ":deduction_for_trade_skill"),
  34160.  
  34161. (try_for_range, ":trade_route_slot", slot_town_trade_routes_begin, slot_town_trade_routes_end),
  34162. (party_get_slot, ":other_town", ":trade_town", ":trade_route_slot"),
  34163. (is_between, ":other_town", towns_begin, towns_end), #SB: add condition for valid town
  34164. (party_get_slot, ":price_in_other_town", ":other_town", ":cur_good_price_slot"),
  34165.  
  34166.  
  34167. (try_begin),
  34168. (eq, "$cheat_mode", 1),
  34169. (assign, reg4, ":price_in_other_town"),
  34170. (assign, reg5, ":score_to_beat"),
  34171. (str_store_party_name, s10, ":other_town"),
  34172. (display_message, "str_s10_has_reg4_needs_reg5"),
  34173. (try_end),
  34174.  
  34175. (gt, ":price_in_other_town", ":score_to_beat"),
  34176.  
  34177. (assign, ":trade_destination", ":other_town"),
  34178. (assign, ":score_to_beat", ":price_in_other_town"),
  34179. (try_end),
  34180.  
  34181. (is_between, ":trade_destination", centers_begin, centers_end),
  34182.  
  34183. (str_store_party_name, s15, ":trade_destination"),
  34184. (str_store_string, s14, "str_s14_i_hear_that_you_can_find_a_good_price_for_it_in_s15"),
  34185.  
  34186. #Reasons -- raw material
  34187. #Reason -- road cut
  34188. #Reason -- villages looted
  34189.  
  34190. (try_end),
  34191.  
  34192.  
  34193. ]),
  34194.  
  34195.  
  34196.  
  34197.  
  34198.  
  34199.  
  34200.  
  34201. # script_tick_town_walkers
  34202. # Input: none
  34203. # Output: none
  34204. ("tick_town_walkers",
  34205. [(try_for_agents, ":cur_agent"),
  34206. (agent_get_troop_id, ":cur_troop", ":cur_agent"),
  34207. (is_between, ":cur_troop", walkers_begin, walkers_end),
  34208. (agent_get_slot, ":target_entry_point", ":cur_agent", 0),
  34209. (entry_point_get_position, pos1, ":target_entry_point"),
  34210. (try_begin),
  34211. (lt, ":target_entry_point", 32),
  34212. (init_position, pos2),
  34213. (position_set_y, pos2, 250),
  34214. (position_transform_position_to_parent, pos1, pos1, pos2),
  34215. (try_end),
  34216. (agent_get_position, pos2, ":cur_agent"),
  34217. (get_distance_between_positions, ":distance", pos1, pos2),
  34218. (lt, ":distance", 400),
  34219. (assign, ":random_no", 0),
  34220. (try_begin),
  34221. (lt, ":target_entry_point", 32),
  34222. (store_random_in_range, ":random_no", 0, 100),
  34223. (try_end),
  34224. (lt, ":random_no", 20),
  34225. (call_script, "script_set_town_walker_destination", ":cur_agent"),
  34226. (try_end),
  34227. ]),
  34228.  
  34229.  
  34230. # script_set_town_walker_destination
  34231. # Input: arg1 = agent_no
  34232. # Output: none
  34233. ("set_town_walker_destination",
  34234. [(store_script_param_1, ":agent_no"),
  34235. (assign, reg0, 9),
  34236. (assign, reg1, 10),
  34237. (assign, reg2, 12),
  34238. (assign, reg3, 32),
  34239. (assign, reg4, 33),
  34240. (assign, reg5, 34),
  34241. (assign, reg6, 35),
  34242. (assign, reg7, 36),
  34243. (assign, reg8, 37),
  34244. (assign, reg9, 38),
  34245. (assign, reg10, 39),
  34246. (try_for_agents, ":cur_agent"),
  34247. (agent_get_troop_id, ":cur_troop", ":cur_agent"),
  34248. (is_between, ":cur_troop", walkers_begin, walkers_end),
  34249. (agent_get_slot, ":target_entry_point", ":cur_agent", 0),
  34250. (try_begin),
  34251. (eq, ":target_entry_point", 9),
  34252. (assign, reg0, 0),
  34253. (else_try),
  34254. (eq, ":target_entry_point", 10),
  34255. (assign, reg1, 0),
  34256. (else_try),
  34257. (eq, ":target_entry_point", 12),
  34258. (assign, reg2, 0),
  34259. (else_try),
  34260. (eq, ":target_entry_point", 32),
  34261. (assign, reg3, 0),
  34262. (else_try),
  34263. (eq, ":target_entry_point", 33),
  34264. (assign, reg4, 0),
  34265. (else_try),
  34266. (eq, ":target_entry_point", 34),
  34267. (assign, reg5, 0),
  34268. (else_try),
  34269. (eq, ":target_entry_point", 35),
  34270. (assign, reg6, 0),
  34271. (else_try),
  34272. (eq, ":target_entry_point", 36),
  34273. (assign, reg7, 0),
  34274. (else_try),
  34275. (eq, ":target_entry_point", 37),
  34276. (assign, reg8, 0),
  34277. (else_try),
  34278. (eq, ":target_entry_point", 38),
  34279. (assign, reg9, 0),
  34280. (else_try),
  34281. (eq, ":target_entry_point", 39),
  34282. (assign, reg10, 0),
  34283. (try_end),
  34284. (try_end),
  34285. (assign, ":try_limit", 100),
  34286. (assign, ":target_entry_point", 0),
  34287. (try_for_range, ":unused", 0, ":try_limit"),
  34288. (shuffle_range, 0, 11),
  34289. (gt, reg0, 0),
  34290. (assign, ":target_entry_point", reg0),
  34291. (assign, ":try_limit", 0),
  34292. (try_end),
  34293. (try_begin),
  34294. (gt, ":target_entry_point", 0),
  34295. (agent_set_slot, ":agent_no", 0, ":target_entry_point"),
  34296. (entry_point_get_position, pos1, ":target_entry_point"),
  34297. (try_begin),
  34298. (lt, ":target_entry_point", 32),
  34299. (init_position, pos2),
  34300. (position_set_y, pos2, 250),
  34301. (position_transform_position_to_parent, pos1, pos1, pos2),
  34302. (try_end),
  34303. (agent_set_scripted_destination, ":agent_no", pos1, 0),
  34304. (agent_set_speed_limit, ":agent_no", 5),
  34305. (try_end),
  34306. ]),
  34307.  
  34308. # script_town_init_doors
  34309. # Input: door_state (-1 = closed, 1 = open, 0 = use $town_nighttime)
  34310. # Output: none (required for siege mission templates)
  34311. ("town_init_doors",
  34312. [(store_script_param, ":door_state", 1),
  34313. (try_begin),
  34314. (assign, ":continue", 0),
  34315. (try_begin),
  34316. (eq, ":door_state", 1),
  34317. (assign, ":continue", 1),
  34318. (else_try),
  34319. (eq, ":door_state", 0),
  34320. (eq, "$town_nighttime", 0),
  34321. (assign, ":continue", 1),
  34322. (try_end),
  34323. (eq, ":continue", 1),# open doors
  34324. (assign, ":end_cond", 1),
  34325. (try_for_range, ":i_instance", 0, ":end_cond"),
  34326. (scene_prop_get_instance, ":object", "spr_towngate_door_left", ":i_instance"),
  34327. (ge, ":object", 0),
  34328. (val_add, ":end_cond", 1),
  34329. (prop_instance_get_position, pos1, ":object"),
  34330. (position_rotate_z, pos1, -100),
  34331. (prop_instance_animate_to_position, ":object", pos1, 1),
  34332. (try_end),
  34333. (assign, ":end_cond", 1),
  34334. (try_for_range, ":i_instance", 0, ":end_cond"),
  34335. (scene_prop_get_instance, ":object", "spr_towngate_rectangle_door_left", ":i_instance"),
  34336. (ge, ":object", 0),
  34337. (val_add, ":end_cond", 1),
  34338. (prop_instance_get_position, pos1, ":object"),
  34339. (position_rotate_z, pos1, -80),
  34340. (prop_instance_animate_to_position, ":object", pos1, 1),
  34341. (try_end),
  34342. (assign, ":end_cond", 1),
  34343. (try_for_range, ":i_instance", 0, ":end_cond"),
  34344. (scene_prop_get_instance, ":object", "spr_towngate_door_right", ":i_instance"),
  34345. (ge, ":object", 0),
  34346. (val_add, ":end_cond", 1),
  34347. (prop_instance_get_position, pos1, ":object"),
  34348. (position_rotate_z, pos1, 100),
  34349. (prop_instance_animate_to_position, ":object", pos1, 1),
  34350. (try_end),
  34351. (assign, ":end_cond", 1),
  34352. (try_for_range, ":i_instance", 0, ":end_cond"),
  34353. (scene_prop_get_instance, ":object", "spr_towngate_rectangle_door_right", ":i_instance"),
  34354. (ge, ":object", 0),
  34355. (val_add, ":end_cond", 1),
  34356. (prop_instance_get_position, pos1, ":object"),
  34357. (position_rotate_z, pos1, 80),
  34358. (prop_instance_animate_to_position, ":object", pos1, 1),
  34359. (try_end),
  34360. (try_end),
  34361. ]),
  34362.  
  34363. # script_siege_init_ai_and_belfry
  34364. # Input: none
  34365. # Output: none (required for siege mission templates)
  34366. ("siege_init_ai_and_belfry",
  34367. [(assign, "$cur_belfry_pos", 50),
  34368. (assign, ":cur_belfry_object_pos", slot_scene_belfry_props_begin),
  34369. (store_current_scene, ":cur_scene"),
  34370. #Collecting belfry objects
  34371. (try_for_range, ":i_belfry_instance", 0, 3),
  34372. (scene_prop_get_instance, ":belfry_object", "spr_belfry_a", ":i_belfry_instance"),
  34373. (ge, ":belfry_object", 0),
  34374. (scene_set_slot, ":cur_scene", ":cur_belfry_object_pos", ":belfry_object"),
  34375. (val_add, ":cur_belfry_object_pos", 1),
  34376. (try_end),
  34377. (try_for_range, ":i_belfry_instance", 0, 3),
  34378. (scene_prop_get_instance, ":belfry_object", "spr_belfry_platform_a", ":i_belfry_instance"),
  34379. (ge, ":belfry_object", 0),
  34380. (scene_set_slot, ":cur_scene", ":cur_belfry_object_pos", ":belfry_object"),
  34381. (val_add, ":cur_belfry_object_pos", 1),
  34382. (try_end),
  34383. (try_for_range, ":i_belfry_instance", 0, 3),
  34384. (scene_prop_get_instance, ":belfry_object", "spr_belfry_platform_b", ":i_belfry_instance"),
  34385. (ge, ":belfry_object", 0),
  34386. (scene_set_slot, ":cur_scene", ":cur_belfry_object_pos", ":belfry_object"),
  34387. (val_add, ":cur_belfry_object_pos", 1),
  34388. (try_end),
  34389. (assign, "$belfry_rotating_objects_begin", ":cur_belfry_object_pos"),
  34390. (try_for_range, ":i_belfry_instance", 0, 5),
  34391. (scene_prop_get_instance, ":belfry_object", "spr_belfry_wheel", ":i_belfry_instance"),
  34392. (ge, ":belfry_object", 0),
  34393. (scene_set_slot, ":cur_scene", ":cur_belfry_object_pos", ":belfry_object"),
  34394. (val_add, ":cur_belfry_object_pos", 1),
  34395. (try_end),
  34396. (assign, "$last_belfry_object_pos", ":cur_belfry_object_pos"),
  34397.  
  34398. #Lifting up the platform at the beginning
  34399. (try_begin),
  34400. (scene_prop_get_instance, ":belfry_object_to_rotate", "spr_belfry_platform_a", 0),
  34401. (try_end),
  34402.  
  34403. #Moving the belfry objects to their starting position
  34404. (entry_point_get_position,pos1,55),
  34405. (entry_point_get_position,pos3,50),
  34406. (try_for_range, ":i_belfry_object_pos", slot_scene_belfry_props_begin, "$last_belfry_object_pos"),
  34407. (assign, ":pos_no", pos_belfry_begin),
  34408. (val_add, ":pos_no", ":i_belfry_object_pos"),
  34409. (val_sub, ":pos_no", slot_scene_belfry_props_begin),
  34410. (scene_get_slot, ":cur_belfry_object", ":cur_scene", ":i_belfry_object_pos"),
  34411. (prop_instance_get_position, pos2, ":cur_belfry_object"),
  34412. (try_begin),
  34413. (eq, ":cur_belfry_object", ":belfry_object_to_rotate"),
  34414. (position_rotate_x, pos2, 90),
  34415. (try_end),
  34416. (position_transform_position_to_local, ":pos_no", pos1, pos2),
  34417. (position_transform_position_to_parent, pos4, pos3, ":pos_no"),
  34418. (prop_instance_animate_to_position, ":cur_belfry_object", pos4, 1),
  34419. (try_end),
  34420. (assign, "$belfry_positioned", 0),
  34421. (assign, "$belfry_num_slots_positioned", 0),
  34422. (assign, "$belfry_num_men_pushing", 0),
  34423.  
  34424. (set_show_messages, 0),
  34425. (team_give_order, "$attacker_team", grc_everyone, mordr_stand_ground),
  34426. (team_give_order, "$attacker_team_2", grc_everyone, mordr_stand_ground),
  34427. (set_show_messages, 1),
  34428. ]),
  34429.  
  34430. # script_cf_siege_move_belfry
  34431. # Input: none
  34432. # Output: none (required for siege mission templates)
  34433. ("cf_siege_move_belfry",
  34434. [(neq, "$last_belfry_object_pos", slot_scene_belfry_props_begin),
  34435. (entry_point_get_position,pos1,50),
  34436. (entry_point_get_position,pos4,55),
  34437. (get_distance_between_positions, ":total_distance", pos4, pos1),
  34438. (store_current_scene, ":cur_scene"),
  34439. (scene_get_slot, ":first_belfry_object", ":cur_scene", slot_scene_belfry_props_begin),
  34440. (prop_instance_get_position, pos2, ":first_belfry_object"),
  34441. (entry_point_get_position,pos1,"$cur_belfry_pos"),
  34442. (position_transform_position_to_parent, pos3, pos1, pos_belfry_begin),
  34443. (position_transform_position_to_parent, pos5, pos4, pos_belfry_begin),
  34444. (get_distance_between_positions, ":cur_distance", pos2, pos3),
  34445. (get_distance_between_positions, ":distance_left", pos2, pos5),
  34446. (try_begin),
  34447. (le, ":cur_distance", 10),
  34448. (val_add, "$cur_belfry_pos", 1),
  34449. (entry_point_get_position,pos1,"$cur_belfry_pos"),
  34450. (position_transform_position_to_parent, pos3, pos1, pos_belfry_begin),
  34451. (get_distance_between_positions, ":cur_distance", pos2, pos3),
  34452. (try_end),
  34453. (neq, "$cur_belfry_pos", 50),
  34454.  
  34455. (assign, ":base_speed", 20),
  34456. (store_div, ":slow_range", ":total_distance", 60),
  34457. (store_sub, ":distance_moved", ":total_distance", ":distance_left"),
  34458.  
  34459. (try_begin),
  34460. (lt, ":distance_moved", ":slow_range"),
  34461. (store_mul, ":base_speed", ":distance_moved", -60),
  34462. (val_div, ":base_speed", ":slow_range"),
  34463. (val_add, ":base_speed", 80),
  34464. (else_try),
  34465. (lt, ":distance_left", ":slow_range"),
  34466. (store_mul, ":base_speed", ":distance_left", -60),
  34467. (val_div, ":base_speed", ":slow_range"),
  34468. (val_add, ":base_speed", 80),
  34469. (try_end),
  34470. (store_mul, ":belfry_speed", ":cur_distance", ":base_speed"),
  34471. (try_begin),
  34472. (eq, "$belfry_num_men_pushing", 0),
  34473. (assign, ":belfry_speed", 1000000),
  34474. (else_try),
  34475. (val_div, ":belfry_speed", "$belfry_num_men_pushing"),
  34476. (try_end),
  34477.  
  34478. (try_begin),
  34479. (le, "$cur_belfry_pos", 55),
  34480. (init_position, pos3),
  34481. (position_rotate_x, pos3, ":distance_moved"),
  34482. (scene_get_slot, ":base_belfry_object", ":cur_scene", slot_scene_belfry_props_begin),
  34483. (prop_instance_get_position, pos4, ":base_belfry_object"),
  34484. (entry_point_get_position,pos1,"$cur_belfry_pos"),
  34485. (try_for_range, ":i_belfry_object_pos", slot_scene_belfry_props_begin, "$last_belfry_object_pos"),
  34486. (scene_get_slot, ":cur_belfry_object", ":cur_scene", ":i_belfry_object_pos"),
  34487. (try_begin),
  34488. (ge, ":i_belfry_object_pos", "$belfry_rotating_objects_begin"),
  34489. (prop_instance_get_starting_position, pos5, ":base_belfry_object"),
  34490. (prop_instance_get_starting_position, pos6, ":cur_belfry_object"),
  34491. (position_transform_position_to_local, pos7, pos5, pos6),
  34492. (position_transform_position_to_parent, pos5, pos4, pos7),
  34493. (position_transform_position_to_parent, pos6, pos5, pos3),
  34494. (prop_instance_set_position, ":cur_belfry_object", pos6),
  34495. (else_try),
  34496. (assign, ":pos_no", pos_belfry_begin),
  34497. (val_add, ":pos_no", ":i_belfry_object_pos"),
  34498. (val_sub, ":pos_no", slot_scene_belfry_props_begin),
  34499. (position_transform_position_to_parent, pos2, pos1, ":pos_no"),
  34500. (prop_instance_animate_to_position, ":cur_belfry_object", pos2, ":belfry_speed"),
  34501. (try_end),
  34502. (try_end),
  34503. (try_end),
  34504. (gt, "$cur_belfry_pos", 55),
  34505. (assign, "$belfry_positioned", 1),
  34506. ]),
  34507.  
  34508. # script_cf_siege_rotate_belfry_platform
  34509. # Input: none
  34510. # Output: none (required for siege mission templates)
  34511. ("cf_siege_rotate_belfry_platform",
  34512. [(eq, "$belfry_positioned", 1),
  34513. (scene_prop_get_instance, ":belfry_object", "spr_belfry_platform_a", 0),
  34514. (prop_instance_get_position, pos1, ":belfry_object"),
  34515. (position_rotate_x, pos1, -90),
  34516. (prop_instance_animate_to_position, ":belfry_object", pos1, 400),
  34517. (assign, "$belfry_positioned", 2),
  34518. ]),
  34519.  
  34520. # script_cf_siege_assign_men_to_belfry
  34521. # Input: none
  34522. # Output: none (required for siege mission templates)
  34523. ("cf_siege_assign_men_to_belfry",
  34524. [
  34525. ## (store_mission_timer_a, ":cur_seconds"),
  34526. (neq, "$last_belfry_object_pos", slot_scene_belfry_props_begin),
  34527. (assign, ":end_trigger", 0),
  34528. (try_begin),
  34529. (lt, "$belfry_positioned", 3),
  34530. (get_player_agent_no, ":player_agent"),
  34531. (store_current_scene, ":cur_scene"),
  34532. (scene_get_slot, ":first_belfry_object", ":cur_scene", slot_scene_belfry_props_begin),
  34533. (prop_instance_get_position, pos2, ":first_belfry_object"),
  34534. (assign, ":slot_1_positioned", 0),
  34535. (assign, ":slot_2_positioned", 0),
  34536. (assign, ":slot_3_positioned", 0),
  34537. (assign, ":slot_4_positioned", 0),
  34538. (assign, ":slot_5_positioned", 0),
  34539. (assign, ":slot_6_positioned", 0),
  34540. (assign, "$belfry_num_slots_positioned", 0),
  34541. (assign, "$belfry_num_men_pushing", 0),
  34542. (try_for_agents, ":cur_agent"),
  34543. (agent_is_alive, ":cur_agent"),
  34544. (agent_is_human, ":cur_agent"),
  34545. (try_begin),
  34546. (agent_get_slot, ":x_pos", ":cur_agent", slot_agent_target_x_pos),
  34547. (neq, ":x_pos", 0),
  34548. (agent_get_slot, ":y_pos", ":cur_agent", slot_agent_target_y_pos),
  34549. (try_begin),
  34550. (eq, ":x_pos", -600),
  34551. (try_begin),
  34552. (eq, ":y_pos", 0),
  34553. (assign, ":slot_1_positioned", 1),
  34554. (else_try),
  34555. (eq, ":y_pos", -200),
  34556. (assign, ":slot_2_positioned", 1),
  34557. (else_try),
  34558. (assign, ":slot_3_positioned", 1),
  34559. (try_end),
  34560. (else_try),
  34561. (try_begin),
  34562. (eq, ":y_pos", 0),
  34563. (assign, ":slot_4_positioned", 1),
  34564. (else_try),
  34565. (eq, ":y_pos", -200),
  34566. (assign, ":slot_5_positioned", 1),
  34567. (else_try),
  34568. (assign, ":slot_6_positioned", 1),
  34569. (try_end),
  34570. (try_end),
  34571. (val_add, "$belfry_num_slots_positioned", 1),
  34572. (init_position, pos1),
  34573. (position_move_x, pos1, ":x_pos"),
  34574. (position_move_y, pos1, ":y_pos"),
  34575. (init_position, pos3),
  34576. (position_move_x, pos3, ":x_pos"),
  34577. (position_move_y, pos3, -1000),
  34578. (position_transform_position_to_parent, pos4, pos2, pos1),
  34579. (position_transform_position_to_parent, pos5, pos2, pos3),
  34580. (agent_get_position, pos6, ":cur_agent"),
  34581. (get_distance_between_positions, ":target_distance", pos6, pos4),
  34582. (get_distance_between_positions, ":waypoint_distance", pos6, pos5),
  34583. (try_begin),
  34584. (this_or_next|lt, ":target_distance", ":waypoint_distance"),
  34585. (lt, ":waypoint_distance", 600),
  34586. (agent_set_scripted_destination, ":cur_agent", pos4, 1),
  34587. (else_try),
  34588. (agent_set_scripted_destination, ":cur_agent", pos5, 1),
  34589. (try_end),
  34590. (try_begin),
  34591. (le, ":target_distance", 300),
  34592. (val_add, "$belfry_num_men_pushing", 1),
  34593. (try_end),
  34594. ## (else_try),
  34595. ## (agent_get_team, ":cur_agent_team", ":cur_agent"),
  34596. ## (this_or_next|eq, "$attacker_team", ":cur_agent_team"),
  34597. ## ( eq, "$attacker_team_2", ":cur_agent_team"),
  34598. ## (try_begin),
  34599. ## (gt, ":cur_seconds", 20),
  34600. ## (agent_get_position, pos1, ":cur_agent"),
  34601. ## (agent_set_scripted_destination, ":cur_agent", pos1, 0),
  34602. ## (else_try),
  34603. ## (try_begin),
  34604. ## (team_get_movement_order, ":order1", "$attacker_team", grc_infantry),
  34605. ## (team_get_movement_order, ":order2", "$attacker_team", grc_cavalry),
  34606. ## (team_get_movement_order, ":order3", "$attacker_team", grc_archers),
  34607. ## (this_or_next|neq, ":order1", mordr_stand_ground),
  34608. ## (this_or_next|neq, ":order2", mordr_stand_ground),
  34609. ## (neq, ":order3", mordr_stand_ground),
  34610. ## (set_show_messages, 0),
  34611. ## (team_give_order, "$attacker_team", grc_everyone, mordr_stand_ground),
  34612. ## (set_show_messages, 1),
  34613. ## (try_end),
  34614. ## (try_end),
  34615. (try_end),
  34616. (try_end),
  34617. (try_begin),
  34618. (lt, "$belfry_num_slots_positioned", 6),
  34619. (try_for_agents, ":cur_agent"),
  34620. (agent_is_alive, ":cur_agent"),
  34621. (agent_get_team, ":cur_agent_team", ":cur_agent"),
  34622. (this_or_next|eq, "$attacker_team", ":cur_agent_team"),
  34623. (eq, "$attacker_team_2", ":cur_agent_team"),
  34624. (neq, ":player_agent", ":cur_agent"),
  34625. (agent_get_class, ":agent_class", ":cur_agent"),
  34626. (this_or_next|eq, ":agent_class", grc_infantry),
  34627. (eq, ":agent_class", grc_cavalry),
  34628. (agent_get_slot, ":x_pos", ":cur_agent", 1),
  34629. (eq, ":x_pos", 0),
  34630. (assign, ":y_pos", 0),
  34631. (try_begin),
  34632. (eq, ":slot_1_positioned", 0),
  34633. (assign, ":x_pos", -600),
  34634. (assign, ":y_pos", 0),
  34635. (val_add, ":slot_1_positioned", 1),
  34636. (else_try),
  34637. (eq, ":slot_2_positioned", 0),
  34638. (assign, ":x_pos", -600),
  34639. (assign, ":y_pos", -200),
  34640. (val_add, ":slot_2_positioned", 1),
  34641. (else_try),
  34642. (eq, ":slot_3_positioned", 0),
  34643. (assign, ":x_pos", -600),
  34644. (assign, ":y_pos", -400),
  34645. (val_add, ":slot_3_positioned", 1),
  34646. (else_try),
  34647. (eq, ":slot_4_positioned", 0),
  34648. (assign, ":x_pos", 600),
  34649. (assign, ":y_pos", 0),
  34650. (val_add, ":slot_4_positioned", 1),
  34651. (else_try),
  34652. (eq, ":slot_5_positioned", 0),
  34653. (assign, ":x_pos", 600),
  34654. (assign, ":y_pos", -200),
  34655. (val_add, ":slot_5_positioned", 1),
  34656. (else_try),
  34657. (eq, ":slot_6_positioned", 0),
  34658. (assign, ":x_pos", 600),
  34659. (assign, ":y_pos", -400),
  34660. (val_add, ":slot_6_positioned", 1),
  34661. (try_end),
  34662. (val_add, "$belfry_num_slots_positioned", 1),
  34663. (agent_set_slot, ":cur_agent", 1, ":x_pos"),
  34664. (agent_set_slot, ":cur_agent", 2, ":y_pos"),
  34665. (try_end),
  34666. (try_end),
  34667. (try_begin),
  34668. (store_mission_timer_a, ":cur_timer"),
  34669. (gt, ":cur_timer", 20),
  34670. (lt, "$belfry_num_slots_positioned", 6),
  34671. (try_for_agents, ":cur_agent"),
  34672. (agent_is_alive, ":cur_agent"),
  34673. (agent_get_team, ":cur_agent_team", ":cur_agent"),
  34674. (this_or_next|eq, "$attacker_team", ":cur_agent_team"),
  34675. ( eq, "$attacker_team_2", ":cur_agent_team"),
  34676. (neq, ":player_agent", ":cur_agent"),
  34677. (agent_get_slot, ":x_pos", ":cur_agent", 1),
  34678. (eq, ":x_pos", 0),
  34679. (assign, ":y_pos", 0),
  34680. (try_begin),
  34681. (eq, ":slot_1_positioned", 0),
  34682. (assign, ":x_pos", -600),
  34683. (assign, ":y_pos", 0),
  34684. (val_add, ":slot_1_positioned", 1),
  34685. (else_try),
  34686. (eq, ":slot_2_positioned", 0),
  34687. (assign, ":x_pos", -600),
  34688. (assign, ":y_pos", -200),
  34689. (val_add, ":slot_2_positioned", 1),
  34690. (else_try),
  34691. (eq, ":slot_3_positioned", 0),
  34692. (assign, ":x_pos", -600),
  34693. (assign, ":y_pos", -400),
  34694. (val_add, ":slot_3_positioned", 1),
  34695. (else_try),
  34696. (eq, ":slot_4_positioned", 0),
  34697. (assign, ":x_pos", 600),
  34698. (assign, ":y_pos", 0),
  34699. (val_add, ":slot_4_positioned", 1),
  34700. (else_try),
  34701. (eq, ":slot_5_positioned", 0),
  34702. (assign, ":x_pos", 600),
  34703. (assign, ":y_pos", -200),
  34704. (val_add, ":slot_5_positioned", 1),
  34705. (else_try),
  34706. (eq, ":slot_6_positioned", 0),
  34707. (assign, ":x_pos", 600),
  34708. (assign, ":y_pos", -400),
  34709. (val_add, ":slot_6_positioned", 1),
  34710. (try_end),
  34711. (val_add, "$belfry_num_slots_positioned", 1),
  34712. (agent_set_slot, ":cur_agent", 1, ":x_pos"),
  34713. (agent_set_slot, ":cur_agent", 2, ":y_pos"),
  34714. (try_end),
  34715. (try_end),
  34716. (else_try),
  34717. (assign, ":end_trigger", 1),
  34718. (try_for_agents, ":cur_agent"),
  34719. (agent_clear_scripted_mode, ":cur_agent"),
  34720. (try_end),
  34721. (set_show_messages, 0),
  34722. (team_give_order, "$attacker_team", grc_everyone, mordr_charge),
  34723. (set_show_messages, 1),
  34724. (try_end),
  34725. (eq, ":end_trigger", 1),
  34726. ]),
  34727.  
  34728. # script_siege_move_archers_to_archer_positions
  34729. # Input: none
  34730. # Output: none
  34731. ("siege_move_archers_to_archer_positions",
  34732. [
  34733. (try_for_agents, ":agent_no"),
  34734. (agent_is_alive, ":agent_no"),
  34735. (agent_slot_eq, ":agent_no", slot_agent_is_not_reinforcement, 0),
  34736. (agent_is_defender, ":agent_no"),
  34737. (agent_get_class, ":agent_class", ":agent_no"),
  34738. (agent_get_troop_id, ":agent_troop", ":agent_no"),
  34739. (eq, ":agent_class", grc_archers),
  34740. (try_begin),
  34741. (agent_slot_eq, ":agent_no", slot_agent_target_entry_point, 0),
  34742. (store_random_in_range, ":random_entry_point", 40, 44),
  34743. (agent_set_slot, ":agent_no", slot_agent_target_entry_point, ":random_entry_point"),
  34744. (try_end),
  34745. (try_begin),
  34746. (agent_get_position, pos0, ":agent_no"),
  34747. (entry_point_get_position, pos1, ":random_entry_point"),
  34748. (get_distance_between_positions, ":dist", pos0, pos1),
  34749. (lt, ":dist", 300),
  34750. (agent_clear_scripted_mode, ":agent_no"),
  34751. (agent_set_slot, ":agent_no", slot_agent_is_in_scripted_mode, 0),
  34752. (agent_set_slot, ":agent_no", slot_agent_is_not_reinforcement, 1),
  34753. (str_store_troop_name, s1, ":agent_troop"),
  34754. (assign, reg0, ":agent_no"),
  34755. # (display_message, "@{s1} ({reg0}) reached pos"),
  34756. (else_try),
  34757. (agent_get_simple_behavior, ":agent_sb", ":agent_no"),
  34758. (agent_get_combat_state, ":agent_cs", ":agent_no"),
  34759. (this_or_next|eq, ":agent_sb", aisb_ranged),
  34760. (eq, ":agent_sb", aisb_go_to_pos),#scripted mode
  34761. (eq, ":agent_cs", 7), # 7 = no visible targets (state for ranged units)
  34762. (try_begin),
  34763. (agent_slot_eq, ":agent_no", slot_agent_is_in_scripted_mode, 0),
  34764. (agent_set_scripted_destination, ":agent_no", pos1, 0),
  34765. (agent_set_slot, ":agent_no", slot_agent_is_in_scripted_mode, 1),
  34766. (str_store_troop_name, s1, ":agent_troop"),
  34767. (assign, reg0, ":agent_no"),
  34768. # (display_message, "@{s1} ({reg0}) moving to pos"),
  34769. (try_end),
  34770. (else_try),
  34771. (try_begin),
  34772. (agent_slot_eq, ":agent_no", slot_agent_is_in_scripted_mode, 1),
  34773. (agent_clear_scripted_mode, ":agent_no"),
  34774. (agent_set_slot, ":agent_no", slot_agent_is_in_scripted_mode, 0),
  34775. (str_store_troop_name, s1, ":agent_troop"),
  34776. (assign, reg0, ":agent_no"),
  34777. # (display_message, "@{s1} ({reg0}) seeing target or changed mode"),
  34778. (try_end),
  34779. (try_end),
  34780. (try_end),
  34781. ]),
  34782.  
  34783.  
  34784. # script_store_movement_order_name_to_s1
  34785. # Input: arg1 = team_no, arg2 = class_no
  34786. # Output: s1 = order_name
  34787. ("store_movement_order_name_to_s1",
  34788. [(store_script_param_1, ":team_no"),
  34789. (store_script_param_2, ":class_no"),
  34790. (team_get_movement_order, ":cur_order", ":team_no", ":class_no"),
  34791. (try_begin),
  34792. (eq, ":cur_order", mordr_hold),
  34793. (str_store_string, s1, "@Holding"),
  34794. (else_try),
  34795. (eq, ":cur_order", mordr_follow),
  34796. (str_store_string, s1, "@Following"),
  34797. (else_try),
  34798. (eq, ":cur_order", mordr_charge),
  34799. (str_store_string, s1, "@Charging"),
  34800. (else_try),
  34801. (eq, ":cur_order", mordr_advance),
  34802. (str_store_string, s1, "@Advancing"),
  34803. (else_try),
  34804. (eq, ":cur_order", mordr_fall_back),
  34805. (str_store_string, s1, "@Falling Back"),
  34806. (else_try),
  34807. (eq, ":cur_order", mordr_stand_closer),
  34808. (str_store_string, s1, "@Standing Closer"),
  34809. (else_try),
  34810. (eq, ":cur_order", mordr_spread_out),
  34811. (str_store_string, s1, "@Spreading Out"),
  34812. (else_try),
  34813. (eq, ":cur_order", mordr_stand_ground),
  34814. (str_store_string, s1, "@Standing"),
  34815. (else_try),
  34816. (str_store_string, s1, "@N/A"),
  34817. (try_end),
  34818. ]),
  34819.  
  34820. # script_store_riding_order_name_to_s1
  34821. # Input: arg1 = team_no, arg2 = class_no
  34822. # Output: s1 = order_name
  34823. ("store_riding_order_name_to_s1",
  34824. [(store_script_param_1, ":team_no"),
  34825. (store_script_param_2, ":class_no"),
  34826. (team_get_riding_order, ":cur_order", ":team_no", ":class_no"),
  34827. (try_begin),
  34828. (eq, ":cur_order", rordr_free),
  34829. (str_store_string, s1, "@Free"),
  34830. (else_try),
  34831. (eq, ":cur_order", rordr_mount),
  34832. (str_store_string, s1, "@Mount"),
  34833. (else_try),
  34834. (eq, ":cur_order", rordr_dismount),
  34835. (str_store_string, s1, "@Dismount"),
  34836. (else_try),
  34837. (str_store_string, s1, "@N/A"),
  34838. (try_end),
  34839. ]),
  34840.  
  34841. # script_store_weapon_usage_order_name_to_s1
  34842. # Input: arg1 = team_no, arg2 = class_no
  34843. # Output: s1 = order_name
  34844. ("store_weapon_usage_order_name_to_s1",
  34845. [(store_script_param_1, ":team_no"),
  34846. (store_script_param_2, ":class_no"),
  34847. (team_get_weapon_usage_order, ":cur_order", ":team_no", ":class_no"),
  34848. (team_get_hold_fire_order, ":cur_hold_fire", ":team_no", ":class_no"),
  34849. (try_begin),
  34850. (eq, ":cur_order", wordr_use_any_weapon),
  34851. (eq, ":cur_hold_fire", aordr_fire_at_will),
  34852. (str_store_string, s1, "@Any Weapon"),
  34853. (else_try),
  34854. (eq, ":cur_order", wordr_use_blunt_weapons),
  34855. (eq, ":cur_hold_fire", aordr_fire_at_will),
  34856. (str_store_string, s1, "@Blunt Weapons"),
  34857. (else_try),
  34858. (eq, ":cur_order", wordr_use_any_weapon),
  34859. (eq, ":cur_hold_fire", aordr_hold_your_fire),
  34860. (str_store_string, s1, "str_hold_fire"),
  34861. (else_try),
  34862. (eq, ":cur_order", wordr_use_blunt_weapons),
  34863. (eq, ":cur_hold_fire", aordr_hold_your_fire),
  34864. (str_store_string, s1, "str_blunt_hold_fire"),
  34865. (else_try),
  34866. (str_store_string, s1, "@N/A"),
  34867. (try_end),
  34868. ]),
  34869.  
  34870. # script_team_give_order_from_order_panel
  34871. # Input: arg1 = leader_agent_no, arg2 = class_no
  34872. # Output: none
  34873. ("team_give_order_from_order_panel",
  34874. [(store_script_param_1, ":leader_agent_no"),
  34875. (store_script_param_2, ":order"),
  34876. (agent_get_team, ":team_no", ":leader_agent_no"),
  34877. (set_show_messages, 0),
  34878. (try_begin),
  34879. (eq, "$g_formation_group0_selected", 1),
  34880. (team_give_order, ":team_no", 0, ":order"),
  34881. (try_end),
  34882. (try_begin),
  34883. (eq, "$g_formation_group1_selected", 1),
  34884. (team_give_order, ":team_no", 1, ":order"),
  34885. (try_end),
  34886. (try_begin),
  34887. (eq, "$g_formation_group2_selected", 1),
  34888. (team_give_order, ":team_no", 2, ":order"),
  34889. (try_end),
  34890. (try_begin),
  34891. (eq, "$g_formation_group3_selected", 1),
  34892. (team_give_order, ":team_no", 3, ":order"),
  34893. (try_end),
  34894. (try_begin),
  34895. (eq, "$g_formation_group4_selected", 1),
  34896. (team_give_order, ":team_no", 4, ":order"),
  34897. (try_end),
  34898. (try_begin),
  34899. (eq, "$g_formation_group5_selected", 1),
  34900. (team_give_order, ":team_no", 5, ":order"),
  34901. (try_end),
  34902. (try_begin),
  34903. (eq, "$g_formation_group6_selected", 1),
  34904. (team_give_order, ":team_no", 6, ":order"),
  34905. (try_end),
  34906. (try_begin),
  34907. (eq, "$g_formation_group7_selected", 1),
  34908. (team_give_order, ":team_no", 7, ":order"),
  34909. (try_end),
  34910. (try_begin),
  34911. (eq, "$g_formation_group8_selected", 1),
  34912. (team_give_order, ":team_no", 8, ":order"),
  34913. (try_end),
  34914.  
  34915. (try_begin),
  34916. (eq, ":order", mordr_hold),
  34917. (agent_get_position, pos1, ":leader_agent_no"),
  34918. (try_begin),
  34919. (eq, "$g_formation_group0_selected", 1),
  34920. (team_set_order_position, ":team_no", 0, pos1),
  34921. (try_end),
  34922. (try_begin),
  34923. (eq, "$g_formation_group1_selected", 1),
  34924. (team_set_order_position, ":team_no", 1, pos1),
  34925. (try_end),
  34926. (try_begin),
  34927. (eq, "$g_formation_group2_selected", 1),
  34928. (team_set_order_position, ":team_no", 2, pos1),
  34929. (try_end),
  34930. (try_begin),
  34931. (eq, "$g_formation_group3_selected", 1),
  34932. (team_set_order_position, ":team_no", 3, pos1),
  34933. (try_end),
  34934. (try_begin),
  34935. (eq, "$g_formation_group4_selected", 1),
  34936. (team_set_order_position, ":team_no", 4, pos1),
  34937. (try_end),
  34938. (try_begin),
  34939. (eq, "$g_formation_group5_selected", 1),
  34940. (team_set_order_position, ":team_no", 5, pos1),
  34941. (try_end),
  34942. (try_begin),
  34943. (eq, "$g_formation_group6_selected", 1),
  34944. (team_set_order_position, ":team_no", 6, pos1),
  34945. (try_end),
  34946. (try_begin),
  34947. (eq, "$g_formation_group7_selected", 1),
  34948. (team_set_order_position, ":team_no", 7, pos1),
  34949. (try_end),
  34950. (try_begin),
  34951. (eq, "$g_formation_group8_selected", 1),
  34952. (team_set_order_position, ":team_no", 8, pos1),
  34953. (try_end),
  34954. (try_end),
  34955. (set_show_messages, 1),
  34956. ]),
  34957.  
  34958.  
  34959. # script_update_order_panel
  34960. # Input: arg1 = team_no
  34961. # Output: none
  34962. ("update_order_panel",
  34963. [(store_script_param_1, ":team_no"),
  34964. (set_fixed_point_multiplier, 1000),
  34965.  
  34966. #ozan added
  34967. (try_begin),
  34968. (eq, "$group0_has_troops", 1),
  34969. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 0),
  34970. (overlay_set_text, "$g_presentation_but0_movement", s1),
  34971. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 0),
  34972. (overlay_set_text, "$g_presentation_but0_riding", s1),
  34973. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 0),
  34974. (overlay_set_text, "$g_presentation_but0_weapon_usage", s1),
  34975. (try_end),
  34976. (try_begin),
  34977. (eq, "$group1_has_troops", 1),
  34978. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 1),
  34979. (overlay_set_text, "$g_presentation_but1_movement", s1),
  34980. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 1),
  34981. (overlay_set_text, "$g_presentation_but1_riding", s1),
  34982. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 1),
  34983. (overlay_set_text, "$g_presentation_but1_weapon_usage", s1),
  34984. (try_end),
  34985. (try_begin),
  34986. (eq, "$group2_has_troops", 1),
  34987. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 2),
  34988. (overlay_set_text, "$g_presentation_but2_movement", s1),
  34989. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 2),
  34990. (overlay_set_text, "$g_presentation_but2_riding", s1),
  34991. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 2),
  34992. (overlay_set_text, "$g_presentation_but2_weapon_usage", s1),
  34993. (try_end),
  34994. (try_begin),
  34995. (eq, "$group3_has_troops", 1),
  34996. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 3),
  34997. (overlay_set_text, "$g_presentation_but3_movement", s1),
  34998. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 3),
  34999. (overlay_set_text, "$g_presentation_but3_riding", s1),
  35000. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 3),
  35001. (overlay_set_text, "$g_presentation_but3_weapon_usage", s1),
  35002. (try_end),
  35003. (try_begin),
  35004. (eq, "$group4_has_troops", 1),
  35005. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 4),
  35006. (overlay_set_text, "$g_presentation_but4_movement", s1),
  35007. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 4),
  35008. (overlay_set_text, "$g_presentation_but4_riding", s1),
  35009. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 4),
  35010. (overlay_set_text, "$g_presentation_but4_weapon_usage", s1),
  35011. (try_end),
  35012. (try_begin),
  35013. (eq, "$group5_has_troops", 1),
  35014. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 5),
  35015. (overlay_set_text, "$g_presentation_but5_movement", s1),
  35016. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 5),
  35017. (overlay_set_text, "$g_presentation_but5_riding", s1),
  35018. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 5),
  35019. (overlay_set_text, "$g_presentation_but5_weapon_usage", s1),
  35020. (try_end),
  35021. (try_begin),
  35022. (eq, "$group6_has_troops", 1),
  35023. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 6),
  35024. (overlay_set_text, "$g_presentation_but6_movement", s1),
  35025. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 6),
  35026. (overlay_set_text, "$g_presentation_but6_riding", s1),
  35027. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 6),
  35028. (overlay_set_text, "$g_presentation_but6_weapon_usage", s1),
  35029. (try_end),
  35030. (try_begin),
  35031. (eq, "$group7_has_troops", 1),
  35032. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 7),
  35033. (overlay_set_text, "$g_presentation_but7_movement", s1),
  35034. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 7),
  35035. (overlay_set_text, "$g_presentation_but7_riding", s1),
  35036. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 7),
  35037. (overlay_set_text, "$g_presentation_but7_weapon_usage", s1),
  35038. (try_end),
  35039. (try_begin),
  35040. (eq, "$group8_has_troops", 1),
  35041. (call_script, "script_store_movement_order_name_to_s1", ":team_no", 8),
  35042. (overlay_set_text, "$g_presentation_but8_movement", s1),
  35043. (call_script, "script_store_riding_order_name_to_s1", ":team_no", 8),
  35044. (overlay_set_text, "$g_presentation_but8_riding", s1),
  35045. (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", 8),
  35046. (overlay_set_text, "$g_presentation_but8_weapon_usage", s1),
  35047. (try_end),
  35048.  
  35049. #ozan added
  35050. (assign, ":stat_position_y", 660),
  35051. (try_begin),
  35052. (position_set_y, pos1, ":stat_position_y"),
  35053. (eq, "$group0_has_troops", 1),
  35054. (position_set_x, pos1, 270),
  35055. (overlay_set_position, "$g_presentation_but0_movement", pos1),
  35056. (position_set_x, pos1, 410),
  35057. (overlay_set_position, "$g_presentation_but0_riding", pos1),
  35058. (position_set_x, pos1, 550),
  35059. (overlay_set_position, "$g_presentation_but0_weapon_usage", pos1),
  35060. (val_add, ":stat_position_y", -40),
  35061. (try_end),
  35062. (try_begin),
  35063. (position_set_y, pos1, ":stat_position_y"),
  35064. (eq, "$group1_has_troops", 1),
  35065. (position_set_x, pos1, 270),
  35066. (overlay_set_position, "$g_presentation_but1_movement", pos1),
  35067. (position_set_x, pos1, 410),
  35068. (overlay_set_position, "$g_presentation_but1_riding", pos1),
  35069. (position_set_x, pos1, 550),
  35070. (overlay_set_position, "$g_presentation_but1_weapon_usage", pos1),
  35071. (val_add, ":stat_position_y", -40),
  35072. (try_end),
  35073. (try_begin),
  35074. (position_set_y, pos1, ":stat_position_y"),
  35075. (eq, "$group2_has_troops", 1),
  35076. (position_set_x, pos1, 270),
  35077. (overlay_set_position, "$g_presentation_but2_movement", pos1),
  35078. (position_set_x, pos1, 410),
  35079. (overlay_set_position, "$g_presentation_but2_riding", pos1),
  35080. (position_set_x, pos1, 550),
  35081. (overlay_set_position, "$g_presentation_but2_weapon_usage", pos1),
  35082. (val_add, ":stat_position_y", -40),
  35083. (try_end),
  35084. (try_begin),
  35085. (position_set_y, pos1, ":stat_position_y"),
  35086. (eq, "$group3_has_troops", 1),
  35087. (position_set_x, pos1, 270),
  35088. (overlay_set_position, "$g_presentation_but3_movement", pos1),
  35089. (position_set_x, pos1, 410),
  35090. (overlay_set_position, "$g_presentation_but3_riding", pos1),
  35091. (position_set_x, pos1, 550),
  35092. (overlay_set_position, "$g_presentation_but3_weapon_usage", pos1),
  35093. (val_add, ":stat_position_y", -40),
  35094. (try_end),
  35095. (try_begin),
  35096. (position_set_y, pos1, ":stat_position_y"),
  35097. (eq, "$group4_has_troops", 1),
  35098. (position_set_x, pos1, 270),
  35099. (overlay_set_position, "$g_presentation_but4_movement", pos1),
  35100. (position_set_x, pos1, 410),
  35101. (overlay_set_position, "$g_presentation_but4_riding", pos1),
  35102. (position_set_x, pos1, 550),
  35103. (overlay_set_position, "$g_presentation_but4_weapon_usage", pos1),
  35104. (val_add, ":stat_position_y", -40),
  35105. (try_end),
  35106. (try_begin),
  35107. (position_set_y, pos1, ":stat_position_y"),
  35108. (eq, "$group5_has_troops", 1),
  35109. (position_set_x, pos1, 270),
  35110. (overlay_set_position, "$g_presentation_but5_movement", pos1),
  35111. (position_set_x, pos1, 410),
  35112. (overlay_set_position, "$g_presentation_but5_riding", pos1),
  35113. (position_set_x, pos1, 550),
  35114. (overlay_set_position, "$g_presentation_but5_weapon_usage", pos1),
  35115. (val_add, ":stat_position_y", -40),
  35116. (try_end),
  35117. (try_begin),
  35118. (position_set_y, pos1, ":stat_position_y"),
  35119. (eq, "$group6_has_troops", 1),
  35120. (position_set_x, pos1, 270),
  35121. (overlay_set_position, "$g_presentation_but6_movement", pos1),
  35122. (position_set_x, pos1, 410),
  35123. (overlay_set_position, "$g_presentation_but6_riding", pos1),
  35124. (position_set_x, pos1, 550),
  35125. (overlay_set_position, "$g_presentation_but6_weapon_usage", pos1),
  35126. (val_add, ":stat_position_y", -40),
  35127. (try_end),
  35128. (try_begin),
  35129. (position_set_y, pos1, ":stat_position_y"),
  35130. (eq, "$group7_has_troops", 1),
  35131. (position_set_x, pos1, 270),
  35132. (overlay_set_position, "$g_presentation_but7_movement", pos1),
  35133. (position_set_x, pos1, 410),
  35134. (overlay_set_position, "$g_presentation_but7_riding", pos1),
  35135. (position_set_x, pos1, 550),
  35136. (overlay_set_position, "$g_presentation_but7_weapon_usage", pos1),
  35137. (val_add, ":stat_position_y", -40),
  35138. (try_end),
  35139. (try_begin),
  35140. (position_set_y, pos1, ":stat_position_y"),
  35141. (eq, "$group8_has_troops", 1),
  35142. (position_set_x, pos1, 270),
  35143. (overlay_set_position, "$g_presentation_but8_movement", pos1),
  35144. (position_set_x, pos1, 410),
  35145. (overlay_set_position, "$g_presentation_but8_riding", pos1),
  35146. (position_set_x, pos1, 550),
  35147. (overlay_set_position, "$g_presentation_but8_weapon_usage", pos1),
  35148. (val_add, ":stat_position_y", -40),
  35149. (try_end),
  35150. ]),
  35151.  
  35152. # script_update_agent_position_on_map
  35153. # Input: arg1 = agent_no, pos2 = map_size_pos
  35154. # Output: none
  35155. ("update_agent_position_on_map",
  35156. [(store_script_param_1, ":agent_no"),
  35157. (agent_get_slot, ":agent_overlay", ":agent_no", slot_agent_map_overlay_id),
  35158.  
  35159. (get_player_agent_no, ":player_agent"),
  35160. (try_begin),
  35161. (le, ":agent_overlay", 0),
  35162. (set_fixed_point_multiplier, 1000),
  35163. (try_begin),
  35164. (eq, ":agent_no", ":player_agent"),
  35165. (create_mesh_overlay, reg1, "mesh_player_dot"),
  35166. (position_set_x, pos1, 500),
  35167. (position_set_y, pos1, 500),
  35168. (overlay_set_size, reg1, pos1),
  35169. (else_try),
  35170. (create_mesh_overlay, reg1, "mesh_white_dot"),
  35171. (position_set_x, pos1, 200),
  35172. (position_set_y, pos1, 200),
  35173. (overlay_set_size, reg1, pos1),
  35174. (try_end),
  35175. (overlay_set_alpha, reg1, 0x88),
  35176. (agent_set_slot, ":agent_no", slot_agent_map_overlay_id, reg1),
  35177. (assign, ":agent_overlay", reg1),
  35178. (try_end),
  35179.  
  35180. (try_begin),
  35181. (neq, ":agent_no", ":player_agent"),
  35182. (agent_get_party_id, ":agent_party", ":agent_no"),
  35183. (try_begin),
  35184. (eq, ":agent_party", "p_main_party"),
  35185. (agent_get_division, ":agent_division", ":agent_no"),
  35186. (try_begin),
  35187. (eq, ":agent_division", 0),
  35188. (overlay_set_color, ":agent_overlay", 0x8d5220),
  35189. (else_try),
  35190. (eq, ":agent_division", 1),
  35191. (overlay_set_color, ":agent_overlay", 0x34c6e4),
  35192. (else_try),
  35193. (eq, ":agent_division", 2),
  35194. (overlay_set_color, ":agent_overlay", 0x569619),
  35195. (else_try),
  35196. (eq, ":agent_division", 3),
  35197. (overlay_set_color, ":agent_overlay", 0xFFE500),
  35198. (else_try),
  35199. (eq, ":agent_division", 4),
  35200. (overlay_set_color, ":agent_overlay", 0x990099),
  35201. (else_try),
  35202. (eq, ":agent_division", 5),
  35203. (overlay_set_color, ":agent_overlay", 0x99FE80),
  35204. (else_try),
  35205. (eq, ":agent_division", 6),
  35206. (overlay_set_color, ":agent_overlay", 0x9DEFFE),
  35207. (else_try),
  35208. (eq, ":agent_division", 7),
  35209. (overlay_set_color, ":agent_overlay", 0xFECB9D),
  35210. (else_try),
  35211. (eq, ":agent_division", 8),
  35212. (overlay_set_color, ":agent_overlay", 0xB19C9C),
  35213. (try_end),
  35214. (else_try),
  35215. (agent_is_ally, ":agent_no"),
  35216. (overlay_set_color, ":agent_overlay", 0x5555FF),
  35217. (else_try),
  35218. (overlay_set_color, ":agent_overlay", 0xFF0000),
  35219. (try_end),
  35220. (try_end),
  35221.  
  35222. (try_begin),
  35223. (eq, ":agent_no", ":player_agent"),
  35224. (agent_get_look_position, pos1, ":agent_no"),
  35225. (position_get_rotation_around_z, ":rot", pos1),
  35226. (init_position, pos10),
  35227. (position_rotate_z, pos10, ":rot"),
  35228. (overlay_set_mesh_rotation, ":agent_overlay", pos10),
  35229. (call_script, "script_convert_3d_pos_to_map_pos"),
  35230. (else_try),
  35231. (agent_get_position, pos1, ":agent_no"),
  35232. (call_script, "script_convert_3d_pos_to_map_pos"),
  35233. (try_end),
  35234. (overlay_set_position, ":agent_overlay", pos0),
  35235. ]),
  35236.  
  35237. # script_convert_3d_pos_to_map_pos
  35238. # Input: pos1 = 3d_pos, pos2 = map_size_pos
  35239. # Output: pos0 = map_pos
  35240. ("convert_3d_pos_to_map_pos",
  35241. [(set_fixed_point_multiplier, 1000),
  35242. (position_transform_position_to_local, pos3, pos2, pos1),
  35243. (position_get_x, ":agent_x_pos", pos3),
  35244. (position_get_y, ":agent_y_pos", pos3),
  35245. (val_div, ":agent_x_pos", "$g_battle_map_scale"),
  35246. (val_div, ":agent_y_pos", "$g_battle_map_scale"),
  35247. (set_fixed_point_multiplier, 1000),
  35248. (store_sub, ":map_x", 980, "$g_battle_map_width"),
  35249. (store_sub, ":map_y", 730, "$g_battle_map_height"),
  35250. (val_add, ":agent_x_pos", ":map_x"),
  35251. (val_add, ":agent_y_pos", ":map_y"),
  35252. (position_set_x, pos0, ":agent_x_pos"),
  35253. (position_set_y, pos0, ":agent_y_pos"),
  35254. ]),
  35255.  
  35256. # script_update_order_flags_on_map
  35257. # Input: none
  35258. # Output: none
  35259. ("update_order_flags_on_map",
  35260. [(set_fixed_point_multiplier, 1000),
  35261. (get_player_agent_no, ":player_agent"),
  35262. (agent_get_team, ":player_team", ":player_agent"),
  35263.  
  35264. (get_scene_boundaries, pos2, pos3),
  35265.  
  35266. (team_get_movement_order, ":cur_order", ":player_team", grc_infantry),
  35267. (try_begin),
  35268. (eq, ":cur_order", mordr_hold),
  35269. (team_get_order_position, pos1, ":player_team", grc_infantry),
  35270. (call_script, "script_convert_3d_pos_to_map_pos"),
  35271. (overlay_set_alpha, "$g_battle_map_infantry_order_flag", 0xFF),
  35272. (overlay_set_position, "$g_battle_map_infantry_order_flag", pos0),
  35273. (else_try),
  35274. (overlay_set_alpha, "$g_battle_map_infantry_order_flag", 0),
  35275. (try_end),
  35276. (team_get_movement_order, ":cur_order", ":player_team", grc_archers),
  35277. (try_begin),
  35278. (eq, ":cur_order", mordr_hold),
  35279. (team_get_order_position, pos1, ":player_team", grc_archers),
  35280. (call_script, "script_convert_3d_pos_to_map_pos"),
  35281. (overlay_set_alpha, "$g_battle_map_archers_order_flag", 0xFF),
  35282. (overlay_set_position, "$g_battle_map_archers_order_flag", pos0),
  35283. (else_try),
  35284. (overlay_set_alpha, "$g_battle_map_archers_order_flag", 0),
  35285. (try_end),
  35286. (team_get_movement_order, ":cur_order", ":player_team", grc_cavalry),
  35287. (try_begin),
  35288. (eq, ":cur_order", mordr_hold),
  35289. (team_get_order_position, pos1, ":player_team", grc_cavalry),
  35290. (call_script, "script_convert_3d_pos_to_map_pos"),
  35291. (overlay_set_alpha, "$g_battle_map_cavalry_order_flag", 0xFF),
  35292. (overlay_set_position, "$g_battle_map_cavalry_order_flag", pos0),
  35293. (else_try),
  35294. (overlay_set_alpha, "$g_battle_map_cavalry_order_flag", 0),
  35295. (try_end),
  35296. ]),
  35297.  
  35298. # script_update_order_panel_checked_classes
  35299. # Input: none
  35300. # Output: none
  35301. ("update_order_panel_checked_classes",
  35302. [(get_player_agent_no, ":player_agent"),
  35303. (agent_get_team, ":player_team", ":player_agent"),
  35304.  
  35305. (try_begin),
  35306. (eq, "$group0_has_troops", 1),
  35307. (class_is_listening_order, ":player_team", 0),
  35308. (overlay_set_val, "$g_presentation_obj_battle_check0", 1),
  35309. (assign, "$g_formation_group0_selected", 1),
  35310. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but0", 250, 0x44),
  35311. (else_try),
  35312. (eq, "$group0_has_troops", 1),
  35313. (overlay_set_val, "$g_presentation_obj_battle_check0", 0),
  35314. (assign, "$g_formation_group0_selected", 0),
  35315. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but0", 250, 0),
  35316. (try_end),
  35317. (try_begin),
  35318. (eq, "$group1_has_troops", 1),
  35319. (class_is_listening_order, ":player_team", 1),
  35320. (overlay_set_val, "$g_presentation_obj_battle_check1", 1),
  35321. (assign, "$g_formation_group1_selected", 1),
  35322. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but1", 250, 0x44),
  35323. (else_try),
  35324. (eq, "$group1_has_troops", 1),
  35325. (overlay_set_val, "$g_presentation_obj_battle_check1", 0),
  35326. (assign, "$g_formation_group1_selected", 0),
  35327. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but1", 250, 0),
  35328. (try_end),
  35329. (try_begin),
  35330. (eq, "$group2_has_troops", 1),
  35331. (class_is_listening_order, ":player_team", 2),
  35332. (overlay_set_val, "$g_presentation_obj_battle_check2", 1),
  35333. (assign, "$g_formation_group2_selected", 1),
  35334. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but2", 250, 0x44),
  35335. (else_try),
  35336. (eq, "$group2_has_troops", 1),
  35337. (overlay_set_val, "$g_presentation_obj_battle_check2", 0),
  35338. (assign, "$g_formation_group2_selected", 0),
  35339. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but2", 250, 0),
  35340. (try_end),
  35341. (try_begin),
  35342. (eq, "$group3_has_troops", 1),
  35343. (class_is_listening_order, ":player_team", 3),
  35344. (overlay_set_val, "$g_presentation_obj_battle_check3", 1),
  35345. (assign, "$g_formation_group3_selected", 1),
  35346. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but3", 250, 0x44),
  35347. (else_try),
  35348. (eq, "$group3_has_troops", 1),
  35349. (overlay_set_val, "$g_presentation_obj_battle_check3", 0),
  35350. (assign, "$g_formation_group3_selected", 0),
  35351. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but3", 250, 0),
  35352. (try_end),
  35353. (try_begin),
  35354. (eq, "$group4_has_troops", 1),
  35355. (class_is_listening_order, ":player_team", 4),
  35356. (overlay_set_val, "$g_presentation_obj_battle_check4", 1),
  35357. (assign, "$g_formation_group4_selected", 1),
  35358. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but4", 250, 0x44),
  35359. (else_try),
  35360. (eq, "$group4_has_troops", 1),
  35361. (overlay_set_val, "$g_presentation_obj_battle_check4", 0),
  35362. (assign, "$g_formation_group4_selected", 0),
  35363. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but4", 250, 0),
  35364. (try_end),
  35365. (try_begin),
  35366. (eq, "$group5_has_troops", 1),
  35367. (class_is_listening_order, ":player_team", 5),
  35368. (overlay_set_val, "$g_presentation_obj_battle_check5", 1),
  35369. (assign, "$g_formation_group5_selected", 1),
  35370. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but5", 250, 0x44),
  35371. (else_try),
  35372. (eq, "$group5_has_troops", 1),
  35373. (overlay_set_val, "$g_presentation_obj_battle_check5", 0),
  35374. (assign, "$g_formation_group5_selected", 0),
  35375. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but5", 250, 0),
  35376. (try_end),
  35377. (try_begin),
  35378. (eq, "$group6_has_troops", 1),
  35379. (class_is_listening_order, ":player_team", 6),
  35380. (overlay_set_val, "$g_presentation_obj_battle_check6", 1),
  35381. (assign, "$g_formation_group6_selected", 1),
  35382. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but6", 250, 0x44),
  35383. (else_try),
  35384. (eq, "$group6_has_troops", 1),
  35385. (overlay_set_val, "$g_presentation_obj_battle_check6", 0),
  35386. (assign, "$g_formation_group6_selected", 0),
  35387. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but6", 250, 0),
  35388. (try_end),
  35389. (try_begin),
  35390. (eq, "$group7_has_troops", 1),
  35391. (class_is_listening_order, ":player_team", 7),
  35392. (overlay_set_val, "$g_presentation_obj_battle_check7", 1),
  35393. (assign, "$g_formation_group7_selected", 1),
  35394. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but7", 250, 0x44),
  35395. (else_try),
  35396. (eq, "$group7_has_troops", 1),
  35397. (overlay_set_val, "$g_presentation_obj_battle_check7", 0),
  35398. (assign, "$g_formation_group7_selected", 0),
  35399. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but7", 250, 0),
  35400. (try_end),
  35401. (try_begin),
  35402. (eq, "$group8_has_troops", 1),
  35403. (class_is_listening_order, ":player_team", 8),
  35404. (overlay_set_val, "$g_presentation_obj_battle_check8", 1),
  35405. (assign, "$g_formation_group8_selected", 1),
  35406. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but8", 250, 0x44),
  35407. (else_try),
  35408. (eq, "$group8_has_troops", 1),
  35409. (overlay_set_val, "$g_presentation_obj_battle_check8", 0),
  35410. (assign, "$g_formation_group8_selected", 0),
  35411. (overlay_animate_to_alpha, "$g_presentation_obj_battle_but8", 250, 0),
  35412. (try_end),
  35413. ]),
  35414.  
  35415. # script_update_order_panel_statistics_and_map
  35416. # Input: none
  35417. # Output: none
  35418. ("update_order_panel_statistics_and_map", #TODO: Call this in every battle mission template, once per second
  35419. [(set_fixed_point_multiplier, 1000),
  35420.  
  35421. (assign, ":num_us_ready_group0", 0),
  35422. (assign, ":num_us_ready_group1", 0),
  35423. (assign, ":num_us_ready_group2", 0),
  35424. (assign, ":num_us_ready_group3", 0),
  35425. (assign, ":num_us_ready_group4", 0),
  35426. (assign, ":num_us_ready_group5", 0),
  35427. (assign, ":num_us_ready_group6", 0),
  35428. (assign, ":num_us_ready_group7", 0),
  35429. (assign, ":num_us_ready_group8", 0),
  35430.  
  35431. (assign, ":num_us_ready_men", 0),
  35432. (assign, ":num_us_wounded_men", 0),
  35433. (assign, ":num_us_routed_men", 0),
  35434. (assign, ":num_us_dead_men", 0),
  35435. (assign, ":num_allies_ready_men", 0),
  35436. (assign, ":num_allies_wounded_men", 0),
  35437. (assign, ":num_allies_routed_men", 0),
  35438. (assign, ":num_allies_dead_men", 0),
  35439. (assign, ":num_enemies_ready_men", 0),
  35440. (assign, ":num_enemies_wounded_men", 0),
  35441. (assign, ":num_enemies_routed_men", 0),
  35442. (assign, ":num_enemies_dead_men", 0),
  35443.  
  35444. (get_scene_boundaries, pos2, pos3),
  35445.  
  35446. (try_for_agents,":cur_agent"),
  35447. (agent_is_human, ":cur_agent"),
  35448. (agent_get_division, ":agent_division", ":cur_agent"),
  35449. (agent_get_party_id, ":agent_party", ":cur_agent"),
  35450. (agent_get_slot, ":agent_overlay", ":cur_agent", slot_agent_map_overlay_id),
  35451. (try_begin),
  35452. (eq, ":agent_party", "p_main_party"),
  35453. (try_begin),
  35454. (agent_is_alive, ":cur_agent"),
  35455. (call_script, "script_update_agent_position_on_map", ":cur_agent"),
  35456. (try_begin),
  35457. (eq, ":agent_division", 0),
  35458. (val_add, ":num_us_ready_group0", 1),
  35459. (eq, "$group0_has_troops", 1), #added to solve problem. test this.
  35460. (else_try),
  35461. (eq, ":agent_division", 1),
  35462. (val_add, ":num_us_ready_group1", 1),
  35463. (eq, "$group1_has_troops", 1), #added to solve problem.
  35464. (else_try),
  35465. (eq, ":agent_division", 2),
  35466. (val_add, ":num_us_ready_group2", 1),
  35467. (eq, "$group2_has_troops", 1), #added to solve problem.
  35468. (else_try),
  35469. (eq, ":agent_division", 3),
  35470. (val_add, ":num_us_ready_group3", 1),
  35471. (eq, "$group3_has_troops", 1), #added to solve problem.
  35472. (else_try),
  35473. (eq, ":agent_division", 4),
  35474. (val_add, ":num_us_ready_group4", 1),
  35475. (eq, "$group4_has_troops", 1), #added to solve problem.
  35476. (else_try),
  35477. (eq, ":agent_division", 5),
  35478. (val_add, ":num_us_ready_group5", 1),
  35479. (eq, "$group5_has_troops", 1), #added to solve problem.
  35480. (else_try),
  35481. (eq, ":agent_division", 6),
  35482. (val_add, ":num_us_ready_group6", 1),
  35483. (eq, "$group6_has_troops", 1), #added to solve problem.
  35484. (else_try),
  35485. (eq, ":agent_division", 7),
  35486. (val_add, ":num_us_ready_group7", 1),
  35487. (eq, "$group7_has_troops", 1), #added to solve problem.
  35488. (else_try),
  35489. (eq, ":agent_division", 8),
  35490. (val_add, ":num_us_ready_group8", 1),
  35491. (eq, "$group8_has_troops", 1), #added to solve problem.
  35492. (try_end),
  35493. (val_add, ":num_us_ready_men", 1),
  35494. (else_try),
  35495. (overlay_set_alpha, ":agent_overlay", 0),
  35496. (agent_is_wounded, ":cur_agent"),
  35497. (val_add, ":num_us_wounded_men", 1),
  35498. (else_try),
  35499. (agent_is_routed, ":cur_agent"),
  35500. (val_add, ":num_us_routed_men", 1),
  35501. (else_try),
  35502. (val_add, ":num_us_dead_men", 1),
  35503. (try_end),
  35504. (else_try),
  35505. (agent_is_ally, ":cur_agent"),
  35506. (try_begin),
  35507. (agent_is_alive, ":cur_agent"),
  35508. (call_script, "script_update_agent_position_on_map", ":cur_agent"),
  35509. (val_add, ":num_allies_ready_men", 1),
  35510. (else_try),
  35511. (overlay_set_alpha, ":agent_overlay", 0),
  35512. (agent_is_wounded, ":cur_agent"),
  35513. (val_add, ":num_allies_wounded_men", 1),
  35514. (else_try),
  35515. (agent_is_routed, ":cur_agent"),
  35516. (val_add, ":num_allies_routed_men", 1),
  35517. (else_try),
  35518. (val_add, ":num_allies_dead_men", 1),
  35519. (try_end),
  35520. (else_try),
  35521. (try_begin),
  35522. (agent_is_alive, ":cur_agent"),
  35523. (call_script, "script_update_agent_position_on_map", ":cur_agent"),
  35524. (val_add, ":num_enemies_ready_men", 1),
  35525. (else_try),
  35526. (overlay_set_alpha, ":agent_overlay", 0),
  35527. (agent_is_wounded, ":cur_agent"),
  35528. (val_add, ":num_enemies_wounded_men", 1),
  35529. (else_try),
  35530. (agent_is_routed, ":cur_agent"),
  35531. (val_add, ":num_enemies_routed_men", 1),
  35532. (else_try),
  35533. (val_add, ":num_enemies_dead_men", 1),
  35534. (try_end),
  35535. (try_end),
  35536. (try_end),
  35537.  
  35538. (assign, reg1, ":num_us_ready_group0"),
  35539. (assign, reg2, ":num_us_ready_group1"),
  35540. (assign, reg3, ":num_us_ready_group2"),
  35541. (assign, reg4, ":num_us_ready_group3"),
  35542. (assign, reg5, ":num_us_ready_group4"),
  35543. (assign, reg6, ":num_us_ready_group5"),
  35544. (assign, reg7, ":num_us_ready_group6"),
  35545. (assign, reg8, ":num_us_ready_group7"),
  35546. (assign, reg9, ":num_us_ready_group8"),
  35547. (assign, reg10, ":num_us_ready_men"),
  35548. (assign, reg11, ":num_us_wounded_men"),
  35549. (assign, reg12, ":num_us_routed_men"),
  35550. (assign, reg13, ":num_us_dead_men"),
  35551. (assign, reg14, ":num_allies_ready_men"),
  35552. (assign, reg15, ":num_allies_wounded_men"),
  35553. (assign, reg16, ":num_allies_routed_men"),
  35554. (assign, reg17, ":num_allies_dead_men"),
  35555. (assign, reg18, ":num_enemies_ready_men"),
  35556. (assign, reg19, ":num_enemies_wounded_men"),
  35557. (assign, reg20, ":num_enemies_routed_men"),
  35558. (assign, reg21, ":num_enemies_dead_men"),
  35559.  
  35560. (try_begin),
  35561. (eq, "$group0_has_troops", 1),
  35562. (str_store_class_name, s1, 0),
  35563. (overlay_set_text, "$g_presentation_obj_battle_name0", "str_s1_reg1"),
  35564. (try_end),
  35565. (try_begin),
  35566. (eq, "$group1_has_troops", 1),
  35567. (str_store_class_name, s1, 1),
  35568. (overlay_set_text, "$g_presentation_obj_battle_name1", "str_s1_reg2"),
  35569. (try_end),
  35570. (try_begin),
  35571. (eq, "$group2_has_troops", 1),
  35572. (str_store_class_name, s1, 2),
  35573. (overlay_set_text, "$g_presentation_obj_battle_name2", "str_s1_reg3"),
  35574. (try_end),
  35575. (try_begin),
  35576. (eq, "$group3_has_troops", 1),
  35577. (str_store_class_name, s1, 3),
  35578. (overlay_set_text, "$g_presentation_obj_battle_name3", "str_s1_reg4"),
  35579. (try_end),
  35580. (try_begin),
  35581. (eq, "$group4_has_troops", 1),
  35582. (str_store_class_name, s1, 4),
  35583. (overlay_set_text, "$g_presentation_obj_battle_name4", "str_s1_reg5"),
  35584. (try_end),
  35585. (try_begin),
  35586. (eq, "$group5_has_troops", 1),
  35587. (str_store_class_name, s1, 5),
  35588. (overlay_set_text, "$g_presentation_obj_battle_name5", "str_s1_reg6"),
  35589. (try_end),
  35590. (try_begin),
  35591. (eq, "$group6_has_troops", 1),
  35592. (str_store_class_name, s1, 6),
  35593. (overlay_set_text, "$g_presentation_obj_battle_name6", "str_s1_reg7"),
  35594. (try_end),
  35595. (try_begin),
  35596. (eq, "$group7_has_troops", 1),
  35597. (str_store_class_name, s1, 7),
  35598. (overlay_set_text, "$g_presentation_obj_battle_name7", "str_s1_reg8"),
  35599. (try_end),
  35600. (try_begin),
  35601. (eq, "$group8_has_troops", 1),
  35602. (str_store_class_name, s1, 8),
  35603. (overlay_set_text, "$g_presentation_obj_battle_name8", "str_s1_reg9"),
  35604. (try_end),
  35605.  
  35606. (overlay_set_text, "$g_battle_us_ready", "@{!}{reg10}"),
  35607. (overlay_set_text, "$g_battle_us_wounded", "@{!}{reg11}"),
  35608. (overlay_set_text, "$g_battle_us_routed", "@{!}{reg12}"),
  35609. (overlay_set_text, "$g_battle_us_dead", "str_reg13"),
  35610. (overlay_set_text, "$g_battle_allies_ready", "str_reg14"),
  35611. (overlay_set_text, "$g_battle_allies_wounded", "str_reg15"),
  35612. (overlay_set_text, "$g_battle_allies_routed", "str_reg16"),
  35613. (overlay_set_text, "$g_battle_allies_dead", "str_reg17"),
  35614. (overlay_set_text, "$g_battle_enemies_ready", "str_reg18"),
  35615. (overlay_set_text, "$g_battle_enemies_wounded", "str_reg19"),
  35616. (overlay_set_text, "$g_battle_enemies_routed", "str_reg20"),
  35617. (overlay_set_text, "$g_battle_enemies_dead", "str_reg21"),
  35618.  
  35619. (assign, ":stat_position_x", 675),
  35620. (assign, ":stat_position_y", 280),
  35621. (val_add, ":stat_position_x", 70),
  35622. (val_add, ":stat_position_y", 60),
  35623. (position_set_x, pos1, ":stat_position_x"),
  35624. (position_set_y, pos1, ":stat_position_y"),
  35625. (overlay_set_position, "$g_battle_us_ready", pos1),
  35626. (val_add, ":stat_position_x", 70),
  35627. (position_set_x, pos1, ":stat_position_x"),
  35628. (overlay_set_position, "$g_battle_us_wounded", pos1),
  35629. (val_add, ":stat_position_x", 70),
  35630. (position_set_x, pos1, ":stat_position_x"),
  35631. (overlay_set_position, "$g_battle_us_routed", pos1),
  35632. (val_add, ":stat_position_x", 70),
  35633. (position_set_x, pos1, ":stat_position_x"),
  35634. (overlay_set_position, "$g_battle_us_dead", pos1),
  35635. (val_add, ":stat_position_x", -210),
  35636. (val_add, ":stat_position_y", -30),
  35637. (position_set_x, pos1, ":stat_position_x"),
  35638. (position_set_y, pos1, ":stat_position_y"),
  35639. (overlay_set_position, "$g_battle_allies_ready", pos1),
  35640. (val_add, ":stat_position_x", 70),
  35641. (position_set_x, pos1, ":stat_position_x"),
  35642. (overlay_set_position, "$g_battle_allies_wounded", pos1),
  35643. (val_add, ":stat_position_x", 70),
  35644. (position_set_x, pos1, ":stat_position_x"),
  35645. (overlay_set_position, "$g_battle_allies_routed", pos1),
  35646. (val_add, ":stat_position_x", 70),
  35647. (position_set_x, pos1, ":stat_position_x"),
  35648. (overlay_set_position, "$g_battle_allies_dead", pos1),
  35649. (val_add, ":stat_position_x", -210),
  35650. (val_add, ":stat_position_y", -30),
  35651. (position_set_x, pos1, ":stat_position_x"),
  35652. (position_set_y, pos1, ":stat_position_y"),
  35653. (overlay_set_position, "$g_battle_enemies_ready", pos1),
  35654. (val_add, ":stat_position_x", 70),
  35655. (position_set_x, pos1, ":stat_position_x"),
  35656. (overlay_set_position, "$g_battle_enemies_wounded", pos1),
  35657. (val_add, ":stat_position_x", 70),
  35658. (position_set_x, pos1, ":stat_position_x"),
  35659. (overlay_set_position, "$g_battle_enemies_routed", pos1),
  35660. (val_add, ":stat_position_x", 70),
  35661. (position_set_x, pos1, ":stat_position_x"),
  35662. (overlay_set_position, "$g_battle_enemies_dead", pos1),
  35663.  
  35664. (call_script, "script_update_order_flags_on_map"),
  35665. ]),
  35666.  
  35667. # script_set_town_picture
  35668. # Input: none
  35669. # Output: none
  35670. ("set_town_picture",
  35671. [
  35672. (try_begin),
  35673. (party_get_current_terrain, ":cur_terrain", "$current_town"),
  35674. (party_slot_eq,"$current_town",slot_party_type, spt_town),
  35675. (try_begin),
  35676. (this_or_next|eq, ":cur_terrain", rt_steppe),
  35677. (this_or_next|eq, ":cur_terrain", rt_steppe_forest),
  35678. (this_or_next|eq, ":cur_terrain", rt_desert),
  35679. ( eq, ":cur_terrain", rt_desert_forest),
  35680. (set_background_mesh, "mesh_pic_towndes"),
  35681. (else_try),
  35682. (this_or_next|eq, ":cur_terrain", rt_snow),
  35683. ( eq, ":cur_terrain", rt_snow_forest),
  35684. (set_background_mesh, "mesh_pic_townsnow"),
  35685. (else_try),
  35686. (set_background_mesh, "mesh_pic_town1"),
  35687. (try_end),
  35688. (else_try),
  35689. (party_slot_eq,"$current_town",slot_party_type, spt_castle),
  35690. (try_begin),
  35691. (this_or_next|eq, ":cur_terrain", rt_steppe),
  35692. (this_or_next|eq, ":cur_terrain", rt_steppe_forest),
  35693. (this_or_next|eq, ":cur_terrain", rt_desert),
  35694. ( eq, ":cur_terrain", rt_desert_forest),
  35695. (set_background_mesh, "mesh_pic_castledes"),
  35696. (else_try),
  35697. (this_or_next|eq, ":cur_terrain", rt_snow),
  35698. ( eq, ":cur_terrain", rt_snow_forest),
  35699. (set_background_mesh, "mesh_pic_castlesnow"),
  35700. (else_try),
  35701. (set_background_mesh, "mesh_pic_castle1"),
  35702. (try_end),
  35703. (else_try), #SB : enable for villages
  35704. (party_slot_eq,"$current_town",slot_party_type, spt_village),
  35705. (try_begin),
  35706. (this_or_next|eq, ":cur_terrain", rt_steppe),
  35707. (this_or_next|eq, ":cur_terrain", rt_steppe_forest),
  35708. (this_or_next|eq, ":cur_terrain", rt_desert),
  35709. ( eq, ":cur_terrain", rt_desert_forest),
  35710. (set_background_mesh, "mesh_pic_village_s"),
  35711. (else_try),
  35712. (this_or_next|eq, ":cur_terrain", rt_snow),
  35713. ( eq, ":cur_terrain", rt_snow_forest),
  35714. (set_background_mesh, "mesh_pic_village_w"),
  35715. (else_try),
  35716. (set_background_mesh, "mesh_pic_village_p"),
  35717. (try_end),
  35718. (try_end),
  35719. ]),
  35720.  
  35721.  
  35722. # script_consume_food
  35723. # Input: arg1: order of the food to be consumed
  35724. # Output: none
  35725. ("consume_food",
  35726. [(store_script_param, ":selected_food", 1),
  35727. (troop_get_inventory_capacity, ":capacity", "trp_player"),
  35728. (try_for_range, ":cur_slot", 0, ":capacity"),
  35729. (troop_get_inventory_slot, ":cur_item", "trp_player", ":cur_slot"),
  35730. (is_between, ":cur_item", food_begin, food_end),
  35731. (troop_get_inventory_slot_modifier, ":item_modifier", "trp_player", ":cur_slot"),
  35732. (neq, ":item_modifier", imod_rotten),
  35733. #SB : TODO check for qst_deliver_wine items and prevent consumption
  35734. (item_slot_eq, ":cur_item", slot_item_is_checked, 0),
  35735. (item_set_slot, ":cur_item", slot_item_is_checked, 1),
  35736. (val_sub, ":selected_food", 1),
  35737. (lt, ":selected_food", 0),
  35738. (assign, ":capacity", 0),
  35739. (troop_inventory_slot_get_item_amount, ":cur_amount", "trp_player", ":cur_slot"),
  35740. (val_sub, ":cur_amount", 1),
  35741. (troop_inventory_slot_set_item_amount, "trp_player", ":cur_slot", ":cur_amount"),
  35742. (try_end),
  35743. ]),
  35744.  
  35745.  
  35746.  
  35747. # script_calculate_troop_score_for_center
  35748. # Input: arg1 = troop_no, arg2 = center_no
  35749. # Output: reg0 = score
  35750. ("calculate_troop_score_for_center",
  35751. [(store_script_param, ":troop_no", 1),
  35752. (store_script_param, ":center_no", 2),
  35753. (assign, ":num_center_points", 1),
  35754. (try_for_range, ":cur_center", centers_begin, centers_end),
  35755. (assign, ":center_owned", 0),
  35756. (try_begin),
  35757. (eq, ":troop_no", "trp_player"),
  35758. (party_slot_eq, ":cur_center", slot_town_lord, stl_reserved_for_player),
  35759. (assign, ":center_owned", 1),
  35760. (try_end),
  35761. (this_or_next|party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
  35762. (eq, ":center_owned", 1),
  35763. (try_begin),
  35764. (party_slot_eq, ":cur_center", slot_party_type, spt_town),
  35765. (val_add, ":num_center_points", 4),
  35766. (else_try),
  35767. (party_slot_eq, ":cur_center", slot_party_type, spt_castle),
  35768. (val_add, ":num_center_points", 2),
  35769. (else_try),
  35770. (val_add, ":num_center_points", 1),
  35771. (try_end),
  35772. (try_end),
  35773. (troop_get_slot, ":troop_renown", ":troop_no", slot_troop_renown),
  35774. (store_add, ":score", 500, ":troop_renown"),
  35775. (val_div, ":score", ":num_center_points"),
  35776. (store_random_in_range, ":random", 50, 100),
  35777. (val_mul, ":score", ":random"),
  35778. (try_begin),
  35779. (party_slot_eq, ":center_no", slot_center_last_taken_by_troop, ":troop_no"),
  35780. (val_mul, ":score", 3),
  35781. (val_div, ":score", 2),
  35782. ##diplomacy start+
  35783. #Take into account original/most-recent lord and home slots.
  35784. #Fief allocations during rebellions are an example of when this would apply.
  35785. (else_try),
  35786. #Bonus for original owner
  35787. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  35788. (party_slot_ge, ":center_no", dplmc_slot_center_original_lord, 1),
  35789. (party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":troop_no"),
  35790. (val_mul, ":score", 3),
  35791. (val_div, ":score", 2),
  35792. (else_try),
  35793. #Bonus for previous owner
  35794. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  35795. (party_slot_ge, ":center_no", dplmc_slot_center_ex_lord, 1),
  35796. (party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, ":troop_no"),
  35797. (val_mul, ":score", 3),
  35798. (val_div, ":score", 2),
  35799. (else_try),
  35800. #Bonus for lord claiming the center as home
  35801. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  35802. (troop_slot_eq, ":troop_no", slot_troop_home, ":center_no"),
  35803. (val_mul, ":score", 3),
  35804. (val_div, ":score", 2),
  35805. ##diplomacy end+
  35806. (try_end),
  35807. (try_begin),
  35808. (eq, ":troop_no", "trp_player"),
  35809. ##diplomacy start+ xxx Replaced next line (slot 0 is not the faction leader slot):
  35810. #(faction_get_slot, ":faction_leader", "$players_kingdom"),
  35811. (faction_get_slot, ":faction_leader", "$players_kingdom", slot_faction_leader),
  35812. ##diplomacy end+
  35813. (call_script, "script_troop_get_player_relation", ":faction_leader"),
  35814. (assign, ":leader_relation", reg0),
  35815. #(troop_get_slot, ":leader_relation", ":faction_leader", slot_troop_player_relation),
  35816. (val_mul, ":leader_relation", 2),
  35817. (val_add, ":score", ":leader_relation"),
  35818. (try_end),
  35819. (assign, reg0, ":score"),
  35820. ]),
  35821.  
  35822.  
  35823. # script_assign_lords_to_empty_centers
  35824. # Input: none
  35825. # Output: none
  35826. #Now ONLY called from the start
  35827. ("assign_lords_to_empty_centers",
  35828. [
  35829.  
  35830. (try_begin),
  35831. (eq, "$cheat_mode", 1),
  35832. (display_message, "str_assigning_lords_to_empty_centers"),
  35833. (str_store_string, s65, "str_assign_lords_to_empty_centers_just_happened"),
  35834. (call_script, "script_add_notification_menu", "mnu_debug_alert_from_s65", 0, 0),
  35835. (try_end),
  35836.  
  35837. (try_for_range, ":faction", kingdoms_begin, kingdoms_end),
  35838. (faction_set_slot, ":faction", slot_faction_temp_slot, 0),
  35839. (try_end),
  35840.  
  35841. (try_for_range, ":active_npc", 0, active_npcs_end),
  35842. (troop_set_slot, ":active_npc", slot_troop_temp_slot, 0),
  35843. (try_end),
  35844.  
  35845. #Factions will keep one unassigned center in reserve, unless they have landless lords
  35846. (try_for_range, ":cur_center", centers_begin, centers_end),
  35847. (party_get_slot, ":center_lord", ":cur_center", slot_town_lord),
  35848. (try_begin),
  35849. (this_or_next|eq, ":center_lord", stl_unassigned),
  35850. (eq, ":center_lord", stl_rejected_by_player),
  35851. (store_faction_of_party, ":center_faction", ":cur_center"),
  35852.  
  35853. (try_begin),
  35854. (eq, "$cheat_mode", 1),
  35855. (str_store_party_name, s4, ":cur_center"),
  35856. (str_store_faction_name, s5, ":center_faction"),
  35857. (display_message, "str_s4_of_the_s5_is_unassigned"),
  35858. (try_end),
  35859.  
  35860. (faction_get_slot, ":number_of_unassigned_centers_plus_landless_lords", ":center_faction", slot_faction_temp_slot),
  35861. (val_add, ":number_of_unassigned_centers_plus_landless_lords", 1),
  35862. (faction_set_slot, ":center_faction", slot_faction_temp_slot, ":number_of_unassigned_centers_plus_landless_lords"),
  35863. (else_try),
  35864. (eq, ":center_lord", stl_reserved_for_player),
  35865.  
  35866. (try_begin),
  35867. (eq, "$cheat_mode", 1),
  35868. (str_store_party_name, s4, ":cur_center"),
  35869. (str_store_faction_name, s5, ":center_faction"),
  35870. (display_message, "str_s4_of_the_s5_is_reserved_for_player"),
  35871. (try_end),
  35872.  
  35873. (else_try),
  35874. (ge, ":center_lord", 0),
  35875. (troop_set_slot, ":center_lord", slot_troop_temp_slot, 1),
  35876. (try_end),
  35877. (try_end),
  35878.  
  35879. (try_for_range, ":active_npc", 0, active_npcs_end),
  35880. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  35881. (this_or_next|gt, ":active_npc", "trp_player"),
  35882. (eq, "$player_has_homage", 1),
  35883.  
  35884. (troop_slot_eq, ":active_npc", slot_troop_temp_slot, 0),
  35885. (store_faction_of_troop, ":npc_faction", ":active_npc"),
  35886.  
  35887. (is_between, ":npc_faction", npc_kingdoms_begin, npc_kingdoms_end),
  35888.  
  35889. (try_begin),
  35890. (eq, "$cheat_mode", 1),
  35891. (str_store_troop_name, s4, ":active_npc"),
  35892. (str_store_faction_name, s5, ":npc_faction"),
  35893. (display_message, "str_s4_of_the_s5_has_no_fiefs"),
  35894. (try_end),
  35895.  
  35896. (faction_get_slot, ":number_of_unassigned_centers_plus_landless_lords", ":npc_faction", slot_faction_temp_slot),
  35897. (val_add, ":number_of_unassigned_centers_plus_landless_lords", 1),
  35898. (faction_set_slot, ":npc_faction", slot_faction_temp_slot, ":number_of_unassigned_centers_plus_landless_lords"),
  35899. (try_end),
  35900.  
  35901. (try_begin),
  35902. (eq, "$cheat_mode", 1),
  35903. (try_for_range, ":faction", kingdoms_begin, kingdoms_end),
  35904. (faction_get_slot, reg4, ":faction", slot_faction_temp_slot),
  35905. (str_store_faction_name, s4, ":faction"),
  35906. (display_message, "str_s4_unassigned_centers_plus_landless_lords_=_reg4"),
  35907. (try_end),
  35908. (try_end),
  35909.  
  35910. (try_for_range, ":cur_center", centers_begin, centers_end),
  35911. (party_get_slot, ":center_lord", ":cur_center", slot_town_lord),
  35912. (this_or_next|eq, ":center_lord", stl_unassigned),
  35913. (eq, ":center_lord", stl_rejected_by_player),
  35914.  
  35915. (store_faction_of_party, ":center_faction", ":cur_center"),
  35916. (is_between, ":center_faction", kingdoms_begin, kingdoms_end),
  35917. (neg|faction_slot_eq, ":center_faction", slot_faction_leader, "trp_player"),
  35918.  
  35919. (try_begin),
  35920. (eq, "$cheat_mode", 1),
  35921. (str_store_party_name, s5, ":cur_center"),
  35922. (try_begin),
  35923. (neg|faction_slot_ge, ":center_faction", slot_faction_temp_slot, 2),
  35924. (str_store_faction_name, s4, ":center_faction"),
  35925. (display_message, "str_s4_holds_s5_in_reserve"),
  35926. (try_end),
  35927. (try_end),
  35928.  
  35929. (faction_slot_ge, ":center_faction", slot_faction_temp_slot, 2),
  35930.  
  35931. #(display_message, "@Considering grant of {s5}"),
  35932.  
  35933. (assign, ":best_lord", -1),
  35934. (assign, ":best_lord_score", -1),
  35935. (try_begin),
  35936. (eq, ":center_lord", stl_unassigned),
  35937. (try_begin),
  35938. (eq, "$players_kingdom", ":center_faction"),
  35939. (eq, "$player_has_homage", 1),
  35940. (assign, ":best_lord", stl_reserved_for_player),
  35941. (call_script, "script_calculate_troop_score_for_center", "trp_player", ":cur_center"),
  35942. (assign, ":best_lord_score", reg0),
  35943. (try_end),
  35944. (try_end),
  35945.  
  35946. (try_for_range, ":cur_troop", active_npcs_begin, active_npcs_end),
  35947. (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  35948. (store_troop_faction, ":troop_faction", ":cur_troop"),
  35949. (eq, ":troop_faction", ":center_faction"),
  35950.  
  35951. (call_script, "script_calculate_troop_score_for_center", ":cur_troop", ":cur_center"),
  35952. (assign, ":score", reg0),
  35953.  
  35954. #This prioritizes granting of centers for troops which do not already have one
  35955. (try_begin),
  35956. (troop_slot_eq, ":cur_troop", slot_troop_temp_slot, 0),
  35957. (is_between, ":cur_center", villages_begin, villages_end),
  35958. (val_mul, ":score", 10),
  35959. (try_end),
  35960.  
  35961. (gt, ":score", ":best_lord_score"),
  35962. (assign, ":best_lord_score", ":score"),
  35963. (assign, ":best_lord", ":cur_troop"),
  35964. (try_end),
  35965.  
  35966. #Adjust count of centers and lords
  35967. (try_begin),
  35968. (this_or_next|ge, ":best_lord", 0),
  35969. (eq, ":best_lord", stl_reserved_for_player),
  35970.  
  35971. (faction_get_slot, ":landless_lords_plus_unassigned_centers", ":center_faction", slot_faction_temp_slot),
  35972. (val_sub, ":landless_lords_plus_unassigned_centers", 1),
  35973.  
  35974. (try_begin),
  35975. (eq, ":best_lord", stl_reserved_for_player),
  35976. (troop_slot_eq, "trp_player", slot_troop_temp_slot, 0),
  35977. (troop_set_slot, "trp_player", slot_troop_temp_slot, 1),
  35978. (val_sub, ":landless_lords_plus_unassigned_centers", 1),
  35979. (else_try),
  35980. (troop_slot_eq, ":best_lord", slot_troop_temp_slot, 0),
  35981. (troop_set_slot, ":best_lord", slot_troop_temp_slot, 1),
  35982. (val_sub, ":landless_lords_plus_unassigned_centers", 1),
  35983. (try_end),
  35984.  
  35985. (faction_set_slot, ":center_faction", slot_faction_temp_slot, ":landless_lords_plus_unassigned_centers"),
  35986. (try_end),
  35987.  
  35988. #Give the center to the lord
  35989. (try_begin),
  35990. (ge, ":best_lord", 0),
  35991. (call_script, "script_give_center_to_lord", ":cur_center", ":best_lord", 1),
  35992. (else_try),
  35993. (eq, ":best_lord", stl_reserved_for_player),
  35994. (party_set_slot, ":cur_center", slot_town_lord, stl_reserved_for_player),
  35995. (try_begin), #grant bound villages to player, if granting a castle
  35996. (party_slot_eq, ":cur_center", slot_party_type, spt_castle),
  35997. # (assign, ":give_at_least_one_village", 0),
  35998. (try_for_range, ":cur_village", villages_begin, villages_end),
  35999. # (eq, ":give_at_least_one_village", 0),
  36000. (party_slot_eq, ":cur_village", slot_village_bound_center, ":cur_center"),
  36001. (party_slot_eq, ":cur_village", slot_town_lord, stl_unassigned),
  36002. (party_set_slot, ":cur_village", slot_town_lord, stl_reserved_for_player),
  36003. # (assign, ":give_at_least_one_village", 1),
  36004. (try_end),
  36005. (try_end),
  36006. (try_end),
  36007. (try_end),
  36008. ]),
  36009.  
  36010.  
  36011. # script_create_village_farmer_party
  36012. # Input: arg1 = village_no
  36013. # Output: reg0 = party_no
  36014. ("create_village_farmer_party",
  36015. [(store_script_param, ":village_no", 1),
  36016. (party_get_slot, ":town_no", ":village_no", slot_village_market_town),
  36017. (store_faction_of_party, ":party_faction", ":town_no"),
  36018.  
  36019.  
  36020. # (store_faction_of_party, ":town_faction", ":town_no"),
  36021. # (try_begin),
  36022. # (neq, ":town_faction", ":party_faction"),
  36023. # (assign, ":town_no", -1),
  36024. # (assign, ":score_to_beat", 9999),
  36025. # (try_for_range, ":other_town", towns_begin, towns_end),
  36026. # (store_faction_of_party, ":other_town_faction", ":town_no"),
  36027. # (store_relation, ":relation", ":other_town_faction", ":party_faction"),
  36028. # (ge, ":relation", 0),
  36029.  
  36030. # (store_distance_to_party_from_party, ":distance", ":village_no", ":other_town"),
  36031. # (lt, ":distance", ":score_to_beat"),
  36032. # (assign, ":town_no", ":other_town"),
  36033. # (assign, ":score_to_beat", ":distance"),
  36034. # (try_end),
  36035. # (try_end),
  36036.  
  36037. (try_begin),
  36038. (is_between, ":town_no", towns_begin, towns_end),
  36039. (set_spawn_radius, 0),
  36040. (spawn_around_party, ":village_no", "pt_village_farmers"),
  36041. (assign, ":new_party", reg0),
  36042.  
  36043. (party_set_faction, ":new_party", ":party_faction"),
  36044. (party_set_slot, ":new_party", slot_party_home_center, ":village_no"),
  36045. (party_set_slot, ":new_party", slot_party_last_traded_center, ":village_no"),
  36046.  
  36047. (party_set_slot, ":new_party", slot_party_type, spt_village_farmer),
  36048. (party_set_slot, ":new_party", slot_party_ai_state, spai_trading_with_town),
  36049. (party_set_slot, ":new_party", slot_party_ai_object, ":town_no"),
  36050. (party_set_ai_behavior, ":new_party", ai_bhvr_travel_to_party),
  36051. (party_set_ai_object, ":new_party", ":town_no"),
  36052. (party_set_flags, ":new_party", pf_default_behavior, 0),
  36053. (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  36054. (try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
  36055. (store_add, ":cur_good_price_slot", ":cur_goods", ":item_to_price_slot"),
  36056. (party_get_slot, ":cur_village_price", ":village_no", ":cur_good_price_slot"),
  36057. (party_set_slot, ":new_party", ":cur_good_price_slot", ":cur_village_price"),
  36058. (try_end),
  36059. (assign, reg0, ":new_party"),
  36060. (try_end),
  36061.  
  36062. ]),
  36063.  
  36064. #script_do_party_center_trade
  36065. # INPUT: arg1 = party_no, arg2 = center_no, arg3 = percentage_change_in_center
  36066. # OUTPUT: reg0 = total_change
  36067. ("do_party_center_trade",
  36068. [
  36069. (store_script_param, ":party_no", 1),
  36070. (store_script_param, ":center_no", 2),
  36071. (store_script_param, ":percentage_change", 3), #this should probably always be a constant. Currently it is 25
  36072. (assign, ":percentage_change", 30),
  36073. ##diplomacy start+
  36074. (party_get_slot, ":origin", ":party_no", slot_party_last_traded_center),
  36075. #If optional economic changes are enabled, reduce the percentage change in order
  36076. #to make prices feel less static.
  36077. (try_begin),
  36078. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  36079. #Only apply lessened price movements to towns.
  36080. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  36081. (is_between, ":center_no", towns_begin, towns_end),
  36082. #This halves the average impact as well as making it more variable.
  36083. (val_add, ":percentage_change", 1),
  36084. (store_random_in_range, ":percentage_change", 0, ":percentage_change"),
  36085. #Display economics diagnostic
  36086. (ge, "$cheat_mode", 3),
  36087. (str_store_party_name, s3, ":origin"),
  36088. (str_store_party_name, s4, ":center_no"),
  36089. (assign, reg4, ":percentage_change"),
  36090. (display_message, "@{!}DEBUG -- Trade from {s3} to {s4}: rolled random impact of {reg4}"),
  36091. (try_end),
  36092. ##diplomacy end+
  36093.  
  36094. (party_get_slot, ":origin", ":party_no", slot_party_last_traded_center),
  36095. (party_set_slot, ":party_no", slot_party_last_traded_center, ":center_no"),
  36096. ##diplomacy start+
  36097. #Update the record of trade route arrival times
  36098. (try_begin),
  36099. (ge, ":origin", centers_begin),
  36100. ##zerilius changes begin
  36101. # (this_or_next|party_slot_eq, ":origin", villages_begin, villages_end),
  36102. (this_or_next|party_slot_eq, ":origin", slot_party_type, spt_village),
  36103. ##zerilius changes end
  36104. (is_between, ":origin", villages_begin, villages_end),
  36105. (store_current_hours, ":cur_hours"),
  36106. (party_set_slot, ":origin", dplmc_slot_village_trade_last_arrived_to_market, ":cur_hours"),
  36107. (try_end),
  36108. (try_begin),
  36109. (ge, ":origin", centers_begin),
  36110. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  36111. (is_between, ":center_no", towns_begin, towns_end),
  36112. (store_current_hours, ":cur_hours"),
  36113. (try_for_range, ":trade_route_slot", slot_town_trade_routes_begin, slot_town_trade_routes_end),
  36114. (party_slot_eq, ":center_no", ":trade_route_slot", ":origin"),
  36115. (store_sub, ":trade_route_arrival_slot", ":trade_route_slot", slot_town_trade_routes_begin),
  36116. (val_add, ":trade_route_arrival_slot", dplmc_slot_town_trade_route_last_arrivals_begin),
  36117. (is_between, ":trade_route_arrival_slot", dplmc_slot_town_trade_route_last_arrivals_begin, dplmc_slot_town_trade_route_last_arrivals_end),#this will always be true unless a modder increased the number of trade route slots without increasing the number of last arrival slots
  36118. (party_set_slot, ":center_no", ":trade_route_arrival_slot", ":cur_hours"),
  36119. (try_end),
  36120. (else_try),
  36121. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_village),
  36122. (is_between, ":center_no", villages_begin, villages_end),
  36123. (store_current_hours, ":cur_hours"),
  36124. (party_set_slot, ":center_no", dplmc_slot_village_trade_last_returned_from_market, ":cur_hours"),
  36125. (try_end),
  36126. #SB : drop off prisoners
  36127. (try_begin),
  36128. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_HIGH),
  36129. (is_between, ":center_no", walled_centers_begin, walled_centers_end),
  36130. (store_faction_of_party, ":town_faction", ":center_no"),
  36131. (store_faction_of_party, ":party_faction", ":party_no"),
  36132. (eq, ":town_faction", ":party_faction"),
  36133. (call_script, "script_party_prisoners_add_party_prisoners", ":center_no", ":party_no"),
  36134. (call_script, "script_party_remove_all_prisoners", ":party_no"),
  36135. (else_try), #sell off looted items
  36136. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),
  36137. (is_between, ":center_no", towns_begin, towns_end),
  36138. (party_get_slot, ":num_items", ":party_no", slot_party_next_looted_item_slot),
  36139. (is_between, ":num_items", 1, num_party_loot_slots + 1), #has any loot
  36140. # (this_or_next|eq, ":num_items", 0),
  36141. (party_get_slot, ":town_merchant", ":center_no", slot_town_merchant),
  36142. (party_get_slot, ":town_weapon", ":center_no", slot_town_weaponsmith),
  36143. (party_get_slot, ":town_armor", ":center_no", slot_town_armorer),
  36144. (party_get_slot, ":town_horse", ":center_no", slot_town_horse_merchant),
  36145.  
  36146. #apply penalty with 0 trade skill for farmer, 2 for caravan masters
  36147. (assign, ":seller_troop", -1), #0 skill
  36148. (try_begin),
  36149. (party_get_slot, ":spt", ":party_no", slot_party_type),
  36150. # (eq, ":spt", spt_village_farmer),
  36151. # (assign, ":seller_troop", -1), #0 skill
  36152. # (else_try),
  36153. (eq, ":spt", spt_kingdom_caravan),
  36154. (assign, ":seller_troop", "trp_caravan_master"), #knows_common, 2 skill
  36155. (else_try),
  36156. (eq, ":spt", spt_kingdom_hero_party),
  36157. (party_stack_get_troop_id, ":seller_troop", ":party_no", 0),
  36158. (try_end),
  36159. (val_add, ":num_items", slot_party_looted_item_1),
  36160. (try_for_range, ":slot_no", slot_party_looted_item_1, ":num_items"),
  36161. (party_get_slot, ":item_no", ":party_no", ":slot_no"),
  36162. (gt, ":item_no", 0),
  36163. (item_get_type, ":itp", ":item_no"),
  36164. (store_add, ":imod_slot", ":slot_no", num_party_loot_slots),
  36165. (party_get_slot, ":imod_no", ":party_no", ":imod_slot"),
  36166. (item_get_type, ":itp", ":item_no"),
  36167. (try_begin),
  36168. (this_or_next|is_between, ":itp", itp_type_one_handed_wpn, itp_type_goods),
  36169. (is_between, ":itp", itp_type_pistol, itp_type_animal),
  36170. (assign, ":merchant", ":town_weapon"),
  36171. (else_try),
  36172. (is_between, ":itp", itp_type_head_armor, itp_type_pistol),
  36173. (assign, ":merchant", ":town_armor"),
  36174. (else_try),
  36175. (eq, ":itp", itp_type_horse),
  36176. (assign, ":merchant", ":town_horse"),
  36177. (else_try),
  36178. (assign, ":merchant", ":town_merchant"),
  36179. (try_end),
  36180. (gt, ":merchant", 0),
  36181. (store_troop_gold, ":merchant_gold", ":merchant"),
  36182. (call_script, "script_dplmc_get_item_value_with_imod", ":item_no", ":imod_no"),
  36183. (store_div, ":price", reg0, 4), #or some other factor
  36184.  
  36185. (call_script, "script_dplmc_get_trade_penalty", ":item_no", ":center_no", ":seller_troop", ":merchant"),
  36186. (val_mul, ":price", reg0),
  36187. (val_div, ":price", 100),
  36188. (val_max, ":price", 1),
  36189. (gt, ":merchant_gold", ":price"), #can afford
  36190. (troop_remove_gold, ":merchant", ":price"),
  36191. (troop_add_item, ":merchant", ":item_no", ":imod_no"),
  36192. # (party_set_slot, ":party_no", ":slot_no", -1), #clear off later
  36193. # (party_set_slot, ":party_no", ":imod_slot", -1),
  36194. (try_end),
  36195.  
  36196. #any unsold item at this point are cleared
  36197. (try_for_range, ":slot_no", slot_party_next_looted_item_slot, slot_party_looted_item_1_modifier + num_party_loot_slots),
  36198. (party_set_slot, ":party_no", ":slot_no", 0),
  36199. (try_end),
  36200.  
  36201. (try_end),
  36202. ##diplomacy end+
  36203.  
  36204. (assign, ":total_change", 0),
  36205. (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
  36206. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  36207. (store_add, ":cur_good_price_slot", ":cur_good", ":item_to_price_slot"),
  36208. (party_get_slot, ":cur_merchant_price", ":party_no", ":cur_good_price_slot"),
  36209. (party_get_slot, ":cur_center_price", ":center_no", ":cur_good_price_slot"),
  36210. (store_sub, ":price_dif", ":cur_merchant_price", ":cur_center_price"),
  36211. (assign, ":cur_change", ":price_dif"),
  36212. (val_abs, ":cur_change"),
  36213. (val_add, ":total_change", ":cur_change"),
  36214. (val_mul, ":cur_change", ":percentage_change"),
  36215. (val_div, ":cur_change", 100),
  36216.  
  36217. #This is to reconvert from absolute value
  36218. (try_begin),
  36219. (lt, ":price_dif", 0),
  36220. (val_mul, ":cur_change", -1),
  36221. (try_end),
  36222.  
  36223. (assign, ":initial_price", ":cur_center_price"),
  36224.  
  36225. #The new price for the caravan or peasant is set before the change, so the prices in the trading town have full effect on the next center
  36226. (party_set_slot, ":party_no", ":cur_good_price_slot", ":cur_center_price"),
  36227.  
  36228. (val_add, ":cur_center_price", ":cur_change"),
  36229. (party_set_slot, ":center_no", ":cur_good_price_slot", ":cur_center_price"),
  36230.  
  36231. (try_begin),
  36232. (eq, "$cheat_mode", 3),
  36233. (str_store_party_name, s3, ":origin"),
  36234. (str_store_party_name, s4, ":center_no"),
  36235. (str_store_item_name, s5, ":cur_good"),
  36236. (assign, reg4, ":initial_price"),
  36237. (assign, reg5, ":cur_center_price"),
  36238. (display_log_message, "@{!}DEBUG -- Trade of {s5} from {s3} to {s4} brings price from {reg4} to {reg5}"),
  36239. (try_end),
  36240.  
  36241. (try_end),
  36242. (assign, reg0, ":total_change"),
  36243. ]),
  36244.  
  36245. #script_player_join_faction
  36246. # INPUT: arg1 = faction_no
  36247. # OUTPUT: none
  36248. ("player_join_faction",
  36249. [
  36250. (store_script_param, ":faction_no", 1),
  36251. (assign,"$players_kingdom",":faction_no"),
  36252. (faction_set_slot, "fac_player_supporters_faction", slot_faction_ai_state, sfai_default),
  36253. (assign, "$players_oath_renounced_against_kingdom", 0),
  36254. (assign, "$players_oath_renounced_given_center", 0),
  36255. (assign, "$players_oath_renounced_begin_time", 0),
  36256.  
  36257. (try_for_range,":other_kingdom",kingdoms_begin,kingdoms_end),
  36258. (faction_slot_eq, ":other_kingdom", slot_faction_state, sfs_active),
  36259. (neq, ":other_kingdom", "fac_player_supporters_faction"),
  36260. (try_begin),
  36261. (neq, ":other_kingdom", ":faction_no"),
  36262. (store_relation, ":other_kingdom_reln", ":other_kingdom", ":faction_no"),
  36263. (else_try),
  36264. (store_relation, ":other_kingdom_reln", "fac_player_supporters_faction", ":other_kingdom"),
  36265. (val_max, ":other_kingdom_reln", 12),
  36266. (try_end),
  36267. (call_script, "script_set_player_relation_with_faction", ":other_kingdom", ":other_kingdom_reln"),
  36268. (try_end),
  36269.  
  36270. (try_for_range, ":cur_center", centers_begin, centers_end),
  36271. #Give center to kingdom if player is the owner
  36272. (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
  36273. (call_script, "script_give_center_to_faction_while_maintaining_lord", ":cur_center", ":faction_no"),
  36274. (else_try),
  36275. #Give center to kingdom if part of player faction
  36276. (store_faction_of_party, ":cur_center_faction", ":cur_center"),
  36277. (eq, ":cur_center_faction", "fac_player_supporters_faction"),
  36278. (call_script, "script_give_center_to_faction_while_maintaining_lord", ":cur_center", ":faction_no"),
  36279. (try_end),
  36280.  
  36281. (try_for_range, ":quest_no", lord_quests_begin, lord_quests_end),
  36282. (check_quest_active, ":quest_no"),
  36283. (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  36284. (store_troop_faction, ":quest_giver_faction", ":quest_giver_troop"),
  36285. (store_relation, ":quest_giver_faction_relation", "fac_player_supporters_faction", ":quest_giver_faction"),
  36286. (lt, ":quest_giver_faction_relation", 0),
  36287. (call_script, "script_abort_quest", ":quest_no", 0),
  36288. (try_end),
  36289. (try_for_range, ":quest_no", lord_quests_begin_2, lord_quests_end_2),
  36290. (check_quest_active, ":quest_no"),
  36291. (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  36292. (store_troop_faction, ":quest_giver_faction", ":quest_giver_troop"),
  36293. (store_relation, ":quest_giver_faction_relation", "fac_player_supporters_faction", ":quest_giver_faction"),
  36294. (lt, ":quest_giver_faction_relation", 0),
  36295. (call_script, "script_abort_quest", ":quest_no", 0),
  36296. (try_end),
  36297. (try_begin),
  36298. (neq, ":faction_no", "fac_player_supporters_faction"),
  36299. (faction_set_slot, "fac_player_supporters_faction", slot_faction_state, sfs_inactive),
  36300. (faction_set_slot, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
  36301. (try_end),
  36302.  
  36303. (try_begin),
  36304. (troop_get_slot, ":spouse", "trp_player", slot_troop_spouse),
  36305. (is_between, ":spouse", kingdom_ladies_begin, kingdom_ladies_end),
  36306.  
  36307. (try_begin),
  36308. (ge, "$cheat_mode", 1),
  36309. (str_store_troop_name, s4, ":spouse"),
  36310. (display_message, "@{!}DEBUG - {s4} faction changed by marriage, case 1"),
  36311. (try_end),
  36312.  
  36313. (troop_set_faction, ":spouse", "$players_kingdom"),
  36314. (try_end),
  36315. ##diplomacy start+
  36316. #Make other vassals follow the player.
  36317. ##(There are other possibilities that we might want to explore, but
  36318. ##what happens now is that they remain members of the defunct faction.)
  36319. (try_begin),
  36320. (neq, ":faction_no", "fac_player_supporters_faction"),
  36321. (try_for_range, ":troop_no", heroes_begin, heroes_end),
  36322. (store_troop_faction, ":other_troop_faction", ":troop_no"),
  36323. (eq, ":other_troop_faction", "fac_player_supporters_faction"),
  36324.  
  36325. (this_or_next|neg|is_between, ":troop_no", companions_begin, companions_end),
  36326. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  36327. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_granted_fief),
  36328. (troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_lord_rejoined),
  36329. (this_or_next|neq, ":troop_no", ":spouse"),
  36330. (neg|is_between, ":spouse", kingdom_ladies_begin, kingdom_ladies_end),
  36331. (try_begin),
  36332. (ge, "$cheat_mode", 1),
  36333. (str_store_troop_name, s4, ":troop_no"),
  36334. (display_message, "@{!} DEBUG - {s4} changed by player's defection"),
  36335. (try_end),
  36336. (troop_set_faction, ":troop_no", "$players_kingdom"),
  36337. #Clear troop slots
  36338. (troop_set_slot, ":troop_no", slot_troop_stance_on_faction_issue, -1),
  36339. (troop_set_slot, ":troop_no", slot_troop_recruitment_random, 0),
  36340. (troop_set_slot, ":troop_no", slot_lord_recruitment_argument, 0),
  36341. (troop_set_slot, ":troop_no", slot_lord_recruitment_candidate, 0),
  36342. (troop_set_slot, ":troop_no", slot_troop_promised_fief, 0),
  36343. #Give new title
  36344. (try_begin),
  36345. (this_or_next|neg|is_between,":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  36346. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  36347. (call_script, "script_troop_set_title_according_to_faction", ":troop_no", ":faction_no"),
  36348. (try_end),
  36349. #Change led party
  36350. (try_begin),
  36351. (troop_get_slot, ":troop_leaded_party", ":troop_no", slot_troop_leaded_party),
  36352. (gt, ":troop_leaded_party", 0),
  36353. (party_is_active, ":troop_leaded_party"),
  36354. (party_set_faction, ":troop_leaded_party", ":faction_no"),
  36355. (try_end),
  36356. (try_end),
  36357. (try_end),
  36358. ##diplomacy end+
  36359.  
  36360. # (try_for_range, ":center", centers_begin, centers_end),
  36361. # (store_faction_of_party, ":center_faction", ":faction_no"),
  36362. # (neq, ":center_faction", "$players_kingdom"),
  36363. # (party_slot_eq, ":center", slot_town_lord, stl_reserved_for_player),
  36364. # # (party_set_slot, ":center", slot_town_lord, stl_unassigned),
  36365. # (try_end),
  36366.  
  36367. (troop_set_slot, "trp_player", slot_troop_stance_on_faction_issue, -1),
  36368.  
  36369. #remove prisoners of player's faction if he was member of his own faction. And free companions which is prisoned in that faction.
  36370. (try_for_parties, ":party_no"),
  36371. (store_faction_of_party, ":party_faction", ":party_no"),
  36372. (eq, ":party_faction", ":faction_no"),
  36373.  
  36374. (party_get_num_prisoner_stacks, ":num_stacks", ":party_no"),
  36375. (try_for_range_backwards, ":troop_iterator", 0, ":num_stacks"),
  36376. (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":party_no", ":troop_iterator"),
  36377. (store_troop_faction, ":cur_faction", ":cur_troop_id"),
  36378.  
  36379. (this_or_next|eq, ":cur_faction", "fac_player_supporters_faction"),
  36380. (this_or_next|eq, ":cur_faction", ":faction_no"),
  36381. (is_between, ":cur_troop_id", companions_begin, companions_end),
  36382.  
  36383. (try_begin),
  36384. (troop_is_hero, ":cur_troop_id"),
  36385. (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
  36386. (try_end),
  36387.  
  36388. (party_prisoner_stack_get_size, ":stack_size", ":party_no", ":troop_iterator"),
  36389. (party_remove_prisoners, ":party_no", ":cur_troop_id", ":stack_size"),
  36390.  
  36391. (try_begin),
  36392. (is_between, ":cur_troop_id", companions_begin, companions_end),
  36393.  
  36394. (try_begin),
  36395. (is_between, ":party_no", towns_begin, towns_end),
  36396. (troop_set_slot, ":cur_troop_id", slot_troop_cur_center, ":party_no"),
  36397. (else_try),
  36398. (store_random_in_range, ":random_town_no", towns_begin, towns_end),
  36399. (troop_set_slot, ":cur_troop_id", slot_troop_cur_center, ":random_town_no"),
  36400. (try_end),
  36401. (try_end),
  36402. (try_end),
  36403. (try_end),
  36404. #remove prisoners end.
  36405.  
  36406. #(call_script, "script_store_average_center_value_per_faction"),
  36407. (call_script, "script_update_all_notes"),
  36408. (assign, "$g_recalculate_ais", 1),
  36409. ]),
  36410.  
  36411. #script_player_leave_faction
  36412. # INPUT: arg1 = give_back_fiefs
  36413. # OUTPUT: none
  36414. ("player_leave_faction",
  36415. [
  36416. (store_script_param, ":give_back_fiefs", 1),
  36417.  
  36418. (call_script, "script_check_and_finish_active_army_quests_for_faction", "$players_kingdom"),
  36419. (assign, ":old_kingdom", "$players_kingdom"),
  36420. (assign, ":old_has_homage", "$player_has_homage"),
  36421. (assign, "$players_kingdom", 0),
  36422. (assign, "$player_has_homage", 0),
  36423.  
  36424. (try_begin),
  36425. (neq, ":give_back_fiefs", 0), #ie, give back fiefs = 1, thereby do it
  36426. (try_for_range, ":cur_center", centers_begin, centers_end),
  36427. (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
  36428. ##diplomacy begin
  36429. #native bug fix when giving back fiefs
  36430. (call_script, "script_give_center_to_faction", ":cur_center", "fac_neutral"),
  36431. ##diplomacy end
  36432. (call_script, "script_give_center_to_faction", ":cur_center", ":old_kingdom"),
  36433.  
  36434. #The following line also occurs when a lord is stripped of his fiefs by an indictment
  36435. (party_set_slot, ":cur_center", slot_town_lord, stl_unassigned),
  36436. (try_end),
  36437. (else_try),
  36438. #If you retain the fiefs
  36439. (try_for_range, ":cur_center", centers_begin, centers_end),
  36440. (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
  36441. (call_script, "script_give_center_to_faction", ":cur_center", "fac_player_supporters_faction"),
  36442. (party_set_slot, ":cur_center", slot_town_lord, "trp_player"),
  36443. (troop_get_slot, ":cur_banner", "trp_player", slot_troop_banner_scene_prop),
  36444. (gt, ":cur_banner", 0),
  36445. (val_sub, ":cur_banner", banner_scene_props_begin),
  36446. (val_add, ":cur_banner", banner_map_icons_begin),
  36447. (party_set_banner_icon, ":cur_center", ":cur_banner"),
  36448. (try_end),
  36449.  
  36450. (try_for_range, ":cur_center", villages_begin, villages_end),
  36451. (party_get_slot, ":cur_bound_center", ":cur_center", slot_village_bound_center),
  36452. (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
  36453. (neg|party_slot_eq, ":cur_bound_center", slot_town_lord, "trp_player"),
  36454. (call_script, "script_give_center_to_faction", ":cur_center", ":old_kingdom"),
  36455. (try_end),
  36456.  
  36457. (is_between, ":old_kingdom", kingdoms_begin, kingdoms_end),
  36458. (neq, ":old_kingdom", "fac_player_supporters_faction"),
  36459. (store_relation, ":reln", "fac_player_supporters_faction", ":old_kingdom"),
  36460. (store_sub, ":req_dif", -40, ":reln"),
  36461. (call_script, "script_change_player_relation_with_faction", ":old_kingdom", ":req_dif"),
  36462. (try_end),
  36463.  
  36464. (try_begin),
  36465. (eq, ":old_has_homage", 1),
  36466. (faction_get_slot, ":faction_leader", ":old_kingdom", slot_faction_leader),
  36467. (call_script, "script_change_player_relation_with_troop", ":faction_leader", -20),
  36468. (try_end),
  36469.  
  36470. (try_begin),
  36471. (troop_get_slot, ":spouse", "trp_player", slot_troop_spouse),
  36472. (is_between, ":spouse", kingdom_ladies_begin, kingdom_ladies_end),
  36473.  
  36474. (try_begin),
  36475. (ge, "$cheat_mode", 1),
  36476. (str_store_troop_name, s4, ":spouse"),
  36477. (display_message, "@{!}DEBUG - {s4} faction changed by marriage, case 3"),
  36478. (try_end),
  36479.  
  36480.  
  36481. (troop_set_faction, ":spouse", "fac_player_supporters_faction"),
  36482. (try_end),
  36483.  
  36484. #Change relations with players_kingdom when player changes factions
  36485. (try_for_range, ":kingdom", kingdoms_begin, kingdoms_end),
  36486. (neq, ":kingdom", "fac_player_supporters_faction"),
  36487. (store_relation, ":relation_with_old_faction", ":old_kingdom", ":kingdom"),
  36488. (store_relation, ":relation_with_player_faction", "fac_player_faction", ":kingdom"),
  36489.  
  36490. (try_begin),
  36491. (eq, ":old_kingdom", ":kingdom"),
  36492. (val_min, ":relation_with_player_faction", 0),
  36493. (else_try),
  36494. (lt, ":relation_with_old_faction", 0),
  36495. (val_max, ":relation_with_player_faction", 0),
  36496. ##diplomacy start+ do not retain allies of former kingdom
  36497. (else_try),
  36498. (gt, ":relation_with_old_faction", 0),
  36499. (val_min, ":relation_with_player_faction", 0),
  36500. ##diplomacy end+
  36501. (try_end),
  36502. (set_relation, "fac_player_faction", ":kingdom", ":relation_with_player_faction"),
  36503. (set_relation, "fac_player_supporters_faction", ":kingdom", ":relation_with_player_faction"),
  36504. (try_end),
  36505.  
  36506. (call_script, "script_update_all_notes"),
  36507. (assign, "$g_recalculate_ais", 1),
  36508.  
  36509. ##diplomacy begin
  36510. ##disband player patrols
  36511. #SB : build one string instead of one for each party
  36512. (try_begin),
  36513. (str_clear, s6),
  36514. (assign, ":num_parties", 0),
  36515. # (ge, ":give_back_fiefs", 1),
  36516. (try_for_parties, ":party_no"),
  36517. (party_is_active, ":party_no"),
  36518. (party_slot_eq,":party_no", slot_party_type, spt_patrol),
  36519. #SB : add other checks such as faction and home center ownership
  36520. (store_faction_of_party, ":party_faction", ":party_no"),
  36521. (eq, ":party_faction", ":old_kingdom"),
  36522. (party_slot_eq, ":party_no", dplmc_slot_party_mission_diplomacy, "trp_player"),
  36523. # (party_slot_eq, ":home_center", slot_town_lord, "trp_player"), #this may no longer be true
  36524.  
  36525. #build string
  36526. (party_get_slot, ":target_party", ":party_no", slot_party_ai_object),
  36527. (str_store_party_name, s50, ":target_party"),
  36528. (try_begin),
  36529. (eq, ":num_parties", 0),
  36530. (str_store_string_reg, s51, s50),
  36531. (else_try),
  36532. (eq, ":num_parties", 1),
  36533. (str_store_string, s51, "str_s50_and_s51"),
  36534. (else_try),
  36535. (str_store_string, s51, "str_s50_comma_s51"),
  36536. (try_end),
  36537. # (display_log_message, "@Your soldiers patrolling {s6} disbanded because you left the faction!", message_defeated),
  36538. (try_begin), #do not give back fiefs, keep the patrols
  36539. (party_get_slot, ":home_center", ":party_no", slot_party_home_center),
  36540. # (eq, ":give_back_fiefs", 0),
  36541. (party_get_slot, ":town_lord", ":home_center", slot_town_lord),
  36542. (eq, ":town_lord", "trp_player"),
  36543. (party_set_faction, ":party_no", "fac_player_supporters_faction"),
  36544. # (remove_party, ":party_no"),
  36545. (else_try), #we assume ":give_back_fiefs" also returns patrols
  36546. (party_set_slot, ":party_no", dplmc_slot_party_mission_diplomacy, ":town_lord"),
  36547. (party_set_faction, ":party_no", ":old_kingdom"),
  36548. (party_set_flags, ":party_no", pf_default_behavior,1),
  36549. (try_end),
  36550. (try_end),
  36551. (try_begin),
  36552. (gt, ":num_parties", 0),
  36553. (faction_get_color, ":color", ":old_kingdom"),
  36554. (assign, reg6, ":give_back_fiefs"),
  36555. (display_log_message, "@Your soldiers patrolling {s51} {reg6?returned:disbanded} because you left the faction!", ":color"),
  36556. (try_end),
  36557. (try_end),
  36558. ##diplomacy end
  36559. ]),
  36560.  
  36561.  
  36562. ("deactivate_player_faction",
  36563. [
  36564. (faction_set_slot, "fac_player_supporters_faction", slot_faction_state, sfs_inactive),
  36565. (faction_set_slot, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
  36566. (assign, "$players_kingdom", 0),
  36567. (assign, "$players_oath_renounced_against_kingdom", 0),
  36568. (assign, "$players_oath_renounced_given_center", 0),
  36569. (assign, "$players_oath_renounced_begin_time", 0),
  36570. #(call_script, "script_store_average_center_value_per_faction"),
  36571. (call_script, "script_update_all_notes"),
  36572.  
  36573. (try_begin),
  36574. (is_between, "$g_player_minister", companions_begin, companions_end),
  36575. (assign, "$npc_to_rejoin_party", "$g_player_minister"),
  36576. (try_end),
  36577. (assign, "$g_player_minister", -1),
  36578.  
  36579. (call_script, "script_add_notification_menu", "mnu_notification_player_faction_deactive", 0, 0),
  36580. ]),
  36581.  
  36582.  
  36583. #script_activate_player_faction
  36584. # INPUT: arg1 = last_interaction_with_faction
  36585. # OUTPUT: none
  36586.  
  36587. #When a player convinces her husband to rebel
  36588. #When a player proclaims herself queen
  36589. #When a player seizes control of a center
  36590. #When a player recruits a lord through intrigue
  36591. #When a player
  36592. ("activate_player_faction",
  36593. [
  36594. (store_script_param, ":liege", 1),
  36595.  
  36596. #This moved to top, so that mnu_notification does not occur twice
  36597. (try_begin),
  36598. (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_inactive),
  36599. (neg|is_between, ":liege", pretenders_begin, pretenders_end),
  36600. (call_script, "script_add_notification_menu", "mnu_notification_player_faction_active", 0, 0),
  36601. ##diplomacy begin
  36602. (call_script, "script_add_notification_menu", "mnu_dplmc_domestic_policy", 0, 0),
  36603. ##diplomacy end
  36604. (try_end),
  36605.  
  36606.  
  36607. (faction_set_slot, "fac_player_supporters_faction", slot_faction_state, sfs_active),
  36608. (faction_set_slot, "fac_player_supporters_faction", slot_faction_leader, ":liege"),
  36609.  
  36610. (assign, ":original_kingdom", "$players_kingdom"),
  36611.  
  36612. (try_begin),
  36613. (is_between, ":original_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  36614. (call_script, "script_player_leave_faction", 0), #Ends quests, transfers control of centers
  36615. (try_end),
  36616.  
  36617. #Name faction
  36618. (try_begin),
  36619. (is_between, ":liege", active_npcs_begin, active_npcs_end),
  36620. (store_faction_of_troop, ":liege_faction"),
  36621. (is_between, ":liege_faction", npc_kingdoms_begin, npc_kingdoms_end),
  36622. (faction_get_slot, ":adjective_string", ":liege_faction", slot_faction_adjective),
  36623. (str_store_string, s1, ":adjective_string"),
  36624. (faction_set_name, "fac_player_supporters_faction", "@{s1} Rebels"),
  36625. #SB : opposite faction color
  36626. (faction_get_color, ":color", ":liege_faction"),
  36627. (store_sub, ":color", 0xFFFFFF, ":color"),#we get the opposite color
  36628. (faction_set_color, "fac_player_supporters_faction", ":color"),
  36629. (else_try),
  36630. (str_store_troop_name, s2, ":liege"),
  36631. (str_store_string, s1, "str_s2s_rebellion"),
  36632. (try_end),
  36633.  
  36634.  
  36635. (assign, "$players_kingdom", "fac_player_supporters_faction"),
  36636. (assign, "$g_player_banner_granted", 1),
  36637.  
  36638.  
  36639.  
  36640. #Any oaths renounced?
  36641. (try_begin),
  36642. (is_between, ":original_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  36643.  
  36644. (faction_get_slot, ":old_leader", ":original_kingdom", slot_faction_leader),
  36645. (call_script, "script_add_log_entry", logent_renounced_allegiance, "trp_player", -1, ":old_leader", "$players_kingdom"),
  36646.  
  36647. #Initializing renounce war variables
  36648. (assign, "$players_oath_renounced_against_kingdom", ":original_kingdom"),
  36649. (assign, "$players_oath_renounced_given_center", 0),
  36650. (store_current_hours, "$players_oath_renounced_begin_time"),
  36651.  
  36652. (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
  36653. (store_faction_of_party, ":cur_center_faction", ":cur_center"),
  36654. (party_set_slot, ":cur_center", slot_center_faction_when_oath_renounced, ":cur_center_faction"),
  36655. (try_end),
  36656. (party_set_slot, "$g_center_to_give_to_player", slot_center_faction_when_oath_renounced, "$players_oath_renounced_against_kingdom"),
  36657.  
  36658. (store_relation, ":relation", ":original_kingdom", "fac_player_supporters_faction"),
  36659. (ge, ":relation", 0),
  36660. (call_script, "script_diplomacy_start_war_between_kingdoms", ":original_kingdom", "fac_player_supporters_faction", 1),
  36661. (try_end),
  36662.  
  36663.  
  36664. (try_begin),
  36665. (troop_get_slot, ":spouse", "trp_player", slot_troop_spouse),
  36666. (is_between, ":spouse", kingdom_ladies_begin, kingdom_ladies_end),
  36667.  
  36668.  
  36669. (try_begin),
  36670. (ge, "$cheat_mode", 1),
  36671. (str_store_troop_name, s4, ":spouse"),
  36672. (display_message, "@{!}DEBUG - {s4} faction changed by marriage, case 2"),
  36673. (try_end),
  36674.  
  36675. (troop_set_faction, ":spouse", "fac_player_supporters_faction"),
  36676. (try_end),
  36677.  
  36678.  
  36679. #(call_script, "script_store_average_center_value_per_faction"),
  36680. (call_script, "script_update_all_notes"),
  36681. (assign, "$g_recalculate_ais", 1),
  36682.  
  36683. ]),
  36684.  
  36685.  
  36686.  
  36687. #script_agent_reassign_team
  36688. # INPUT: arg1 = agent_no
  36689. # OUTPUT: none
  36690. ("agent_reassign_team",
  36691. [
  36692. (store_script_param, ":agent_no", 1),
  36693. (get_player_agent_no, ":player_agent"),
  36694. (try_begin),
  36695. (ge, ":player_agent", 0),
  36696. (agent_is_human, ":agent_no"),
  36697. (agent_is_ally, ":agent_no"),
  36698. (agent_get_party_id, ":party_no", ":agent_no"),
  36699. #SB : pre-process this instead of calculating per agent
  36700. (party_slot_eq, ":party_no", slot_party_temp_slot_1, -1),
  36701. # (neq, ":party_no", "p_main_party"),
  36702. # (assign, ":continue", 1),
  36703. # (store_faction_of_party, ":party_faction", ":party_no"),
  36704. # (try_begin),
  36705. # (eq, ":party_faction", "$players_kingdom"),
  36706. # (is_between, "$players_kingdom", kingdoms_begin, kingdoms_end),
  36707. # (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
  36708. # (assign, ":continue", 0),
  36709. # (else_try),
  36710. # (party_stack_get_troop_id, ":leader_troop_id", ":party_no", 0),
  36711. # (neg|is_between, ":leader_troop_id", active_npcs_begin, active_npcs_end),
  36712. # (assign, ":continue", 0),
  36713. # (try_end),
  36714. # (eq, ":continue", 1),
  36715. (agent_get_team, ":player_team", ":player_agent"),
  36716. (val_add, ":player_team", 2),
  36717. (agent_set_team, ":agent_no", ":player_team"),
  36718. (try_end),
  36719. ]),
  36720.  
  36721. #script_start_quest
  36722. # INPUT: arg1 = quest_no, arg2 = giver_troop_no, s2 = description_text
  36723. # OUTPUT: none
  36724. ("start_quest",
  36725. [(store_script_param, ":quest_no", 1),
  36726. (store_script_param, ":giver_troop_no", 2),
  36727.  
  36728. (quest_set_slot, ":quest_no", slot_quest_giver_troop, ":giver_troop_no"),
  36729.  
  36730. (try_begin),
  36731. (eq, ":giver_troop_no", -1),
  36732. (str_store_string, s63, "str_political_suggestion"),
  36733. (else_try), #SB : extend range
  36734. (is_between, ":giver_troop_no", active_npcs_begin, heroes_end),
  36735. (str_store_troop_name_link, s62, ":giver_troop_no"),
  36736. (str_store_string, s63, "@Given by: {s62}"),
  36737. (else_try),
  36738. (str_store_troop_name, s62, ":giver_troop_no"),
  36739. (str_store_string, s63, "@Given by: {s62}"),
  36740. (try_end),
  36741. (store_current_hours, ":cur_hours"),
  36742. (str_store_date, s60, ":cur_hours"),
  36743. (str_store_string, s60, "@Given on: {s60}"),
  36744. (add_quest_note_from_sreg, ":quest_no", 0, s60, 0),
  36745. (add_quest_note_from_sreg, ":quest_no", 1, s63, 0),
  36746. (add_quest_note_from_sreg, ":quest_no", 2, s2, 0),
  36747.  
  36748. (try_begin),
  36749. (quest_slot_ge, ":quest_no", slot_quest_expiration_days, 1),
  36750. (quest_get_slot, reg0, ":quest_no", slot_quest_expiration_days),
  36751. (add_quest_note_from_sreg, ":quest_no", 7, "@You have {reg0} days to finish this quest.", 0),
  36752. (try_end),
  36753.  
  36754. #Adding dont_give_again_for_days value
  36755. (try_begin),
  36756. (quest_slot_ge, ":quest_no", slot_quest_dont_give_again_period, 1),
  36757. (quest_get_slot, ":dont_give_again_period", ":quest_no", slot_quest_dont_give_again_period),
  36758. (quest_set_slot, ":quest_no", slot_quest_dont_give_again_remaining_days, ":dont_give_again_period"),
  36759. (try_end),
  36760. (start_quest, ":quest_no", ":giver_troop_no"),
  36761.  
  36762. (try_begin),
  36763. (eq, ":quest_no", "qst_report_to_army"),
  36764. (assign, "$number_of_report_to_army_quest_notes", 8),
  36765. (faction_get_slot, ":faction_ai_state", "$players_kingdom", slot_faction_ai_state),
  36766. (call_script, "script_update_report_to_army_quest_note", "$players_kingdom", ":faction_ai_state", -1),
  36767. (try_end),
  36768.  
  36769. (display_message, "str_quest_log_updated"),
  36770. ]),
  36771.  
  36772. #script_conclude_quest
  36773. # INPUT: arg1 = quest_no
  36774. # OUTPUT: none
  36775. ("conclude_quest",
  36776. [
  36777. (store_script_param, ":quest_no", 1),
  36778. (conclude_quest, ":quest_no"),
  36779. (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  36780. (str_store_troop_name, s59, ":quest_giver_troop"),
  36781. (add_quest_note_from_sreg, ":quest_no", 7, "@This quest has been concluded. Talk to {s59} to finish it.", 0),
  36782. ]),
  36783.  
  36784. #script_succeed_quest
  36785. # INPUT: arg1 = quest_no
  36786. # OUTPUT: none
  36787. ("succeed_quest",
  36788. [
  36789. (store_script_param, ":quest_no", 1),
  36790. (succeed_quest, ":quest_no"),
  36791. (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  36792. (str_store_troop_name, s59, ":quest_giver_troop"),
  36793. (add_quest_note_from_sreg, ":quest_no", 7, "@This quest has been successfully completed. Talk to {s59} to claim your reward.", 0),
  36794. ]),
  36795.  
  36796. #script_fail_quest
  36797. # INPUT: arg1 = quest_no
  36798. # OUTPUT: none
  36799. ("fail_quest",
  36800. [
  36801. (store_script_param, ":quest_no", 1),
  36802. (fail_quest, ":quest_no"),
  36803. (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver_troop),
  36804. (str_store_troop_name, s59, ":quest_giver_troop"),
  36805. (add_quest_note_from_sreg, ":quest_no", 7, "@This quest has failed. Talk to {s59} to explain the situation.", 0),
  36806. ]),
  36807.  
  36808. #script_report_quest_troop_positions
  36809. # INPUT: arg1 = quest_no, arg2 = troop_no, arg3 = note_index
  36810. # OUTPUT: none
  36811. ("report_quest_troop_positions",
  36812. [
  36813. (store_script_param, ":quest_no", 1),
  36814. (store_script_param, ":troop_no", 2),
  36815. (store_script_param, ":note_index", 3),
  36816. (call_script, "script_get_information_about_troops_position", ":troop_no", 1),
  36817. (str_store_string, s5, "@At the time quest was given:^{s1}"),
  36818. (add_quest_note_from_sreg, ":quest_no", ":note_index", s5, 1),
  36819. (call_script, "script_update_troop_location_notes", ":troop_no", 1),
  36820. ]),
  36821.  
  36822. #script_end_quest
  36823. # INPUT: arg1 = quest_no
  36824. # OUTPUT: none
  36825. ("end_quest",
  36826. [
  36827. (store_script_param, ":quest_no", 1),
  36828. (str_clear, s1),
  36829. (add_quest_note_from_sreg, ":quest_no", 0, s1, 0),
  36830. (add_quest_note_from_sreg, ":quest_no", 1, s1, 0),
  36831. (add_quest_note_from_sreg, ":quest_no", 2, s1, 0),
  36832. (add_quest_note_from_sreg, ":quest_no", 3, s1, 0),
  36833. (add_quest_note_from_sreg, ":quest_no", 4, s1, 0),
  36834. (add_quest_note_from_sreg, ":quest_no", 5, s1, 0),
  36835. (add_quest_note_from_sreg, ":quest_no", 6, s1, 0),
  36836. (add_quest_note_from_sreg, ":quest_no", 7, s1, 0),
  36837. (try_begin),
  36838. (neg|check_quest_failed, ":quest_no"),
  36839. (val_add, "$g_total_quests_completed", 1),
  36840. (try_end),
  36841. (complete_quest, ":quest_no"),
  36842. (try_begin),
  36843. (eq, ":quest_no", "qst_consult_with_minister"),
  36844. (assign, "$g_minister_notification_quest", 0),
  36845. (else_try), #SB : finish clearing ransom debts
  36846. (eq, ":quest_no", "qst_rescue_prisoner"),
  36847. (try_for_range, ":troop_no", heroes_begin, heroes_end),
  36848. (troop_slot_ge, ":troop_no", slot_troop_player_debt, dplmc_ransom_debt_mask),
  36849. (troop_set_slot, ":troop_no", slot_troop_player_debt, 0),
  36850. (try_end),
  36851. # (else_try), #SB : clean up fugitive troop
  36852. # (eq, ":quest_no", "qst_hunt_down_fugitive"),
  36853. # (try_for_parties, ":party_no"),
  36854. # (party_is_active, ":party_no"),
  36855. # (party_remove_prisoners, ":party_no", "trp_fugitive", 1),
  36856. # (party_remove_members, ":party_no", "trp_fugitive", 1),
  36857. # (try_end),
  36858. (else_try),
  36859. (is_between, ":quest_no", mayor_quests_begin, mayor_quests_end),
  36860. (assign, "$merchant_quest_last_offerer", -1),
  36861. (assign, "$merchant_offered_quest", -1),
  36862. (try_end),
  36863. ]),
  36864.  
  36865. #script_cancel_quest
  36866. # INPUT: arg1 = quest_no
  36867. # OUTPUT: none
  36868. ("cancel_quest",
  36869. [(store_script_param, ":quest_no", 1),
  36870. (str_clear, s1),
  36871. (add_quest_note_from_sreg, ":quest_no", 0, s1, 0),
  36872. (add_quest_note_from_sreg, ":quest_no", 1, s1, 0),
  36873. (add_quest_note_from_sreg, ":quest_no", 2, s1, 0),
  36874. (add_quest_note_from_sreg, ":quest_no", 3, s1, 0),
  36875. (add_quest_note_from_sreg, ":quest_no", 4, s1, 0),
  36876. (add_quest_note_from_sreg, ":quest_no", 5, s1, 0),
  36877. (add_quest_note_from_sreg, ":quest_no", 6, s1, 0),
  36878. (add_quest_note_from_sreg, ":quest_no", 7, s1, 0),
  36879. (cancel_quest, ":quest_no"),
  36880. (try_begin),
  36881. (is_between, ":quest_no", mayor_quests_begin, mayor_quests_end),
  36882. (assign, "$merchant_quest_last_offerer", -1),
  36883. (assign, "$merchant_offered_quest", -1),
  36884. (try_end),
  36885. ]),
  36886.  
  36887. ## #script_get_available_mercenary_troop_and_amount_of_center
  36888. ## # INPUT: arg1 = center_no
  36889. ## # OUTPUT: reg0 = mercenary_troop_type, reg1 = amount
  36890. ## ("get_available_mercenary_troop_and_amount_of_center",
  36891. ## [(store_script_param, ":center_no", 1),
  36892. ## (party_get_slot, ":mercenary_troop", ":center_no", slot_center_mercenary_troop_type),
  36893. ## (party_get_slot, ":mercenary_amount", ":center_no", slot_center_mercenary_troop_amount),
  36894. ## (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
  36895. ## (val_min, ":mercenary_amount", ":free_capacity"),
  36896. ## (store_troop_gold, ":cur_gold", "trp_player"),
  36897. ## (call_script, "script_game_get_join_cost", ":mercenary_troop"),
  36898. ## (assign, ":join_cost", reg0),
  36899. ## (try_begin),
  36900. ## (gt, ":join_cost", 0),
  36901. ## (val_div, ":cur_gold", ":join_cost"),
  36902. ## (val_min, ":mercenary_amount", ":cur_gold"),
  36903. ## (try_end),
  36904. ## (assign, reg0, ":mercenary_troop"),
  36905. ## (assign, reg1, ":mercenary_amount"),
  36906. ## ]),
  36907. ##
  36908.  
  36909. #script_update_village_market_towns
  36910. # INPUT: none
  36911. # OUTPUT: none
  36912. ("update_village_market_towns",
  36913. [(try_for_range, ":cur_village", villages_begin, villages_end),
  36914. (store_faction_of_party, ":village_faction", ":cur_village"),
  36915. (assign, ":min_dist", 999999),
  36916. (assign, ":min_dist_town", -1),
  36917. (try_for_range, ":cur_town", towns_begin, towns_end),
  36918. (store_faction_of_party, ":town_faction", ":cur_town"),
  36919. (eq, ":town_faction", ":village_faction"),
  36920. (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_town"),
  36921. (lt, ":cur_dist", ":min_dist"),
  36922. (assign, ":min_dist", ":cur_dist"),
  36923. (assign, ":min_dist_town", ":cur_town"),
  36924. (try_end),
  36925.  
  36926. (try_begin),
  36927. (gt, ":min_dist_town", -1),
  36928. (party_set_slot, ":cur_village", slot_village_market_town, ":min_dist_town"),
  36929. (else_try),
  36930. (assign, ":min_dist", 999999),
  36931. (assign, ":min_dist_town", -1),
  36932. (try_for_range, ":cur_town", towns_begin, towns_end),
  36933. (store_faction_of_party, ":town_faction", ":cur_town"),
  36934. (store_relation, ":relation", ":town_faction", ":village_faction"),
  36935. (ge, ":relation", 0),
  36936. (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_town"),
  36937. (lt, ":cur_dist", ":min_dist"),
  36938. (assign, ":min_dist", ":cur_dist"),
  36939. (assign, ":min_dist_town", ":cur_town"),
  36940. (try_end),
  36941. (gt, ":min_dist_town", -1),
  36942. (party_set_slot, ":cur_village", slot_village_market_town, ":min_dist_town"),
  36943. (try_end),
  36944. (try_end),
  36945. ]),
  36946.  
  36947.  
  36948.  
  36949. #script_update_mercenary_units_of_towns
  36950. # INPUT: none
  36951. # OUTPUT: none
  36952. ("update_mercenary_units_of_towns",
  36953. [(try_for_range, ":town_no", towns_begin, towns_end),
  36954. (store_random_in_range, ":troop_no", mercenary_troops_begin, mercenary_troops_end),
  36955. (party_set_slot, ":town_no", slot_center_mercenary_troop_type, ":troop_no"),
  36956. (store_random_in_range, ":amount", 3, 8),
  36957. ##diplomacy start+
  36958. #OPTIONAL CHANGE: The same way that lord party sizes increase as the player
  36959. #progresses, also increase mercenary party sizes to maintain their relevance.
  36960. (try_begin),
  36961. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_HIGH),
  36962. (store_character_level, ":level", "trp_player"), #increase limits a little bit as the game progresses.
  36963. (store_add, ":level_factor", 80, ":level"),
  36964. (val_mul, ":amount", ":level_factor"),
  36965. (val_div, ":amount", 80),
  36966. (try_end),
  36967. ##diplomacy end+
  36968. (party_set_slot, ":town_no", slot_center_mercenary_troop_amount, ":amount"),
  36969. (try_end),
  36970. ]),
  36971.  
  36972. #script_update_volunteer_troops_in_village
  36973. # INPUT: arg1 = center_no
  36974. # OUTPUT: none
  36975. ("update_volunteer_troops_in_village",
  36976. [
  36977. (store_script_param, ":center_no", 1),
  36978. (party_get_slot, ":player_relation", ":center_no", slot_center_player_relation),
  36979. (party_get_slot, ":center_culture", ":center_no", slot_center_culture),
  36980.  
  36981.  
  36982. ## (try_begin),
  36983. ## (eq, "$cheat_mode", 2),
  36984. ## (str_store_party_name, s4, ":center_no"),
  36985. ## (str_store_faction_name, s5, ":center_culture"),
  36986. ## (display_message, "str_updating_volunteers_for_s4_faction_is_s5"),
  36987. ## (try_end),
  36988.  
  36989. (faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
  36990. (assign, ":volunteer_troop_tier", 1),
  36991. (store_div, ":tier_upgrades", ":player_relation", 10),
  36992. (try_for_range, ":unused", 0, ":tier_upgrades"),
  36993. (store_random_in_range, ":random_no", 0, 100),
  36994. (lt, ":random_no", 10),
  36995. (store_random_in_range, ":random_no", 0, 2),
  36996. (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", ":random_no"),
  36997. (try_begin),
  36998. (le, ":upgrade_troop_no", 0),
  36999. (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", 0),
  37000. (try_end),
  37001. (gt, ":upgrade_troop_no", 0),
  37002. (val_add, ":volunteer_troop_tier", 1),
  37003. (assign, ":volunteer_troop", ":upgrade_troop_no"),
  37004. (try_end),
  37005.  
  37006. (assign, ":upper_limit", 8),
  37007. (try_begin),
  37008. (ge, ":player_relation", 4),
  37009. (assign, ":upper_limit", ":player_relation"),
  37010. (val_div, ":upper_limit", 2),
  37011. (val_add, ":upper_limit", 6),
  37012. (else_try),
  37013. (lt, ":player_relation", 0),
  37014. (assign, ":upper_limit", 0),
  37015. (try_end),
  37016.  
  37017.  
  37018. ##diplomacy begin
  37019. (assign, ":percent", 100),
  37020. (try_begin), #-30% if not owner
  37021. (neg|party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  37022. (val_sub, ":percent", 30),
  37023. (try_end),
  37024. (try_begin), #1%/4 renown
  37025. (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
  37026. (val_div, ":player_renown", 4),
  37027. (val_add, ":percent", ":player_renown"),
  37028. (try_end),
  37029. (try_begin), #1%/3 honour
  37030. (assign, ":player_honour", "$player_honor"),
  37031. (val_div, ":player_honour", 3),
  37032. (val_add, ":percent", ":player_honour"),
  37033. (try_end),
  37034. (try_begin), #+5% if king
  37035. (faction_get_slot, ":faction_leader", "fac_player_supporters_faction", slot_faction_leader),
  37036. (eq, ":faction_leader", "trp_player"),
  37037. (val_add, ":percent", 5),
  37038.  
  37039. (try_begin), #-5% for each point of serfdom
  37040. (faction_get_slot, ":serfdom", "fac_player_supporters_faction", dplmc_slot_faction_serfdom),
  37041. (neq, ":serfdom", 0),
  37042. (val_mul, ":serfdom", 5),
  37043. (val_sub, ":percent", ":serfdom"),
  37044. (try_end),
  37045.  
  37046. (try_begin), #+5% if king of village
  37047. (store_faction_of_party, ":faction", ":center_no"),
  37048. (eq, ":faction", "fac_player_supporters_faction"),
  37049. (val_add, ":percent", 5),
  37050. (try_end),
  37051. (try_end),
  37052.  
  37053. (try_begin),
  37054. (gt, ":upper_limit", 0),
  37055. (val_clamp, ":percent", 0, 201),
  37056. (val_mul, ":upper_limit", ":percent"),
  37057. (val_div, ":upper_limit", 100),
  37058. (try_end),
  37059.  
  37060. ##diplomacy end
  37061.  
  37062.  
  37063. (val_mul, ":upper_limit", 3),
  37064. (store_add, ":amount_random_divider", 2, ":volunteer_troop_tier"),
  37065. (val_div, ":upper_limit", ":amount_random_divider"),
  37066.  
  37067. (store_random_in_range, ":amount", 0, ":upper_limit"),
  37068. (party_set_slot, ":center_no", slot_center_volunteer_troop_type, ":volunteer_troop"),
  37069. (party_set_slot, ":center_no", slot_center_volunteer_troop_amount, ":amount"),
  37070. ]),
  37071.  
  37072. #script_update_npc_volunteer_troops_in_village
  37073. # INPUT: arg1 = center_no
  37074. # OUTPUT: none
  37075. ("update_npc_volunteer_troops_in_village",
  37076. [
  37077. (store_script_param, ":center_no", 1),
  37078. (party_get_slot, ":center_culture", ":center_no", slot_center_culture),
  37079. (faction_get_slot, ":volunteer_troop", ":center_culture", slot_faction_tier_1_troop),
  37080. (assign, ":volunteer_troop_tier", 1),
  37081. (try_for_range, ":unused", 0, 5),
  37082. (store_random_in_range, ":random_no", 0, 100),
  37083. (lt, ":random_no", 10),
  37084. (store_random_in_range, ":random_no", 0, 2),
  37085. (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", ":random_no"),
  37086. (try_begin),
  37087. (le, ":upgrade_troop_no", 0),
  37088. (troop_get_upgrade_troop, ":upgrade_troop_no", ":volunteer_troop", 0),
  37089. (try_end),
  37090. (gt, ":upgrade_troop_no", 0),
  37091. (val_add, ":volunteer_troop_tier", 1),
  37092. (assign, ":volunteer_troop", ":upgrade_troop_no"),
  37093. (try_end),
  37094.  
  37095. (assign, ":upper_limit", 12),
  37096.  
  37097. (store_add, ":amount_random_divider", 2, ":volunteer_troop_tier"),
  37098. (val_div, ":upper_limit", ":amount_random_divider"),
  37099.  
  37100. (store_random_in_range, ":amount", 0, ":upper_limit"),
  37101. (party_set_slot, ":center_no", slot_center_npc_volunteer_troop_type, ":volunteer_troop"),
  37102. (party_set_slot, ":center_no", slot_center_npc_volunteer_troop_amount, ":amount"),
  37103. ]),
  37104.  
  37105. #script_update_companion_candidates_in_taverns
  37106. # INPUT: none
  37107. # OUTPUT: none
  37108. ("update_companion_candidates_in_taverns",
  37109. [
  37110. (try_begin),
  37111. (eq, "$cheat_mode", 1),
  37112. (display_message, "str_shuffling_companion_locations"),
  37113. (try_end),
  37114.  
  37115. (try_for_range, ":troop_no", companions_begin, companions_end),
  37116. ##diplomacy start+ Move this *after* the checks!
  37117. # (troop_set_slot, ":troop_no", slot_troop_cur_center, -1),
  37118. ##diplomacy end+
  37119. (troop_slot_eq, ":troop_no", slot_troop_days_on_mission, 0),
  37120. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive),
  37121.  
  37122. (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  37123. ##diplomacy start+
  37124. (troop_get_slot, ":town_no", ":troop_no", slot_troop_cur_center),
  37125. (try_begin),
  37126. (is_between, ":town_no", towns_begin, towns_end),
  37127. (party_get_slot, ":town_lord", ":town_no", slot_town_lord),
  37128. ##zerilius changes begin
  37129. ##bug fix for red text
  37130. (ge, ":town_lord", 0),
  37131. ##zerilius changes end
  37132. (this_or_next|eq, ":town_lord", "trp_player"),
  37133. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, ":town_lord"),
  37134. (troop_slot_eq, ":town_lord", slot_troop_spouse, "trp_player"),
  37135. (else_try),
  37136. #Moved from above:
  37137. (troop_set_slot, ":troop_no", slot_troop_cur_center, -1),
  37138. (try_end),
  37139. (neg|troop_slot_ge, ":troop_no", slot_troop_cur_center, 1),
  37140. ##diplomacy end+
  37141. (store_random_in_range, ":town_no", towns_begin, towns_end),
  37142. (try_begin),
  37143. ##diplomacy start+ Remove the "you can't go home again" condition if the player owns the town
  37144. (assign, ":veto", 0),
  37145. (try_begin),
  37146. (store_faction_of_party, ":town_faction", ":town_no"),
  37147. (eq, ":town_faction", "fac_player_supporters_faction"),
  37148. (else_try),
  37149. (party_get_slot, ":town_lord", ":town_no", slot_town_lord),
  37150. (ge, ":town_lord", 0),
  37151. (this_or_next|eq, ":town_lord", "trp_player"),
  37152. (this_or_next|troop_slot_eq, "trp_player", slot_troop_spouse, ":town_lord"),
  37153. (troop_slot_eq, ":town_lord", slot_troop_spouse, "trp_player"),
  37154. (else_try),
  37155. #Native veto:
  37156. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_home, ":town_no"),
  37157. (troop_slot_eq, ":troop_no", slot_troop_first_encountered, ":town_no"),
  37158. (assign, ":veto", 1),
  37159. (try_end),
  37160. (eq, ":veto", 0),
  37161. ##diplomacy end+
  37162. (troop_set_slot, ":troop_no", slot_troop_cur_center, ":town_no"),
  37163. (try_begin),
  37164. (eq, "$cheat_mode", 1),
  37165. (str_store_troop_name, 4, ":troop_no"),
  37166. (str_store_party_name, 5, ":town_no"),
  37167. (display_message, "@{!}{s4} is in {s5}"),
  37168. (try_end),
  37169. (try_end),
  37170. (try_end),
  37171. ]),
  37172.  
  37173. #script_update_ransom_brokers
  37174. # INPUT: none
  37175. # OUTPUT: none
  37176. ("update_ransom_brokers",
  37177. [(try_for_range, ":town_no", towns_begin, towns_end),
  37178. (party_set_slot, ":town_no", slot_center_ransom_broker, 0),
  37179. (try_end),
  37180.  
  37181. (try_for_range, ":troop_no", ransom_brokers_begin, ransom_brokers_end),
  37182. #SB : random-brokers prefer towns with actual prisoners
  37183. (assign, ":limit", 20),
  37184. (try_for_range, ":unused", 0, ":limit"), #also exclude Tihr since it has Ramun
  37185. (store_random_in_range, ":town_no", towns_begin, towns_end),
  37186. (neq, ":town_no", "p_town_2"),
  37187. #also exclude centers under siege
  37188. (neg|party_slot_ge, ":town_no", slot_center_is_besieged_by, 1),
  37189. (party_get_num_prisoners, ":prisoner_count", ":town_no"),
  37190. (gt, ":prisoner_count", 0),
  37191. (party_set_slot, ":town_no", slot_center_ransom_broker, ":troop_no"),
  37192. (assign, ":limit", 0), #loop breaker
  37193. (try_end),
  37194. (eq, ":limit", 20), #none found
  37195. (store_random_in_range, ":town_no", towns_begin, towns_end),
  37196. (party_set_slot, ":town_no", slot_center_ransom_broker, ":troop_no"),
  37197. (try_end),
  37198.  
  37199. (party_set_slot,"p_town_2",slot_center_ransom_broker,"trp_ramun_the_slave_trader"),
  37200. ]),
  37201.  
  37202. #script_update_tavern_travellers
  37203. # INPUT: none
  37204. # OUTPUT: none
  37205. ("update_tavern_travellers",
  37206. [
  37207. (try_for_range, ":town_no", towns_begin, towns_end),
  37208. (neg|party_slot_ge, ":town_no", slot_center_is_besieged_by, 1), #keep in center
  37209. (party_set_slot, ":town_no", slot_center_tavern_traveler, 0),
  37210. (try_end),
  37211.  
  37212. (try_for_range, ":troop_no", tavern_travelers_begin, tavern_travelers_end),
  37213. (store_random_in_range, ":town_no", towns_begin, towns_end),
  37214. (troop_get_slot, ":cur_center", ":troop_no", slot_troop_cur_center),
  37215. (assign, ":end_cond", 15), #default tries to set info faction slot
  37216. (try_begin), #not landed, skip condition
  37217. (le, ":cur_center", 0),
  37218. (party_set_slot, ":town_no", slot_center_tavern_traveler, ":troop_no"),
  37219. (troop_set_slot, ":troop_no", slot_troop_cur_center, ":town_no"),
  37220. (else_try),
  37221. (is_between, ":cur_center", walled_centers_begin, walled_centers_end),
  37222. (neg|party_slot_ge, ":cur_center", slot_center_is_besieged_by, 1), #can't travel
  37223. (party_set_slot, ":town_no", slot_center_tavern_traveler, ":troop_no"),
  37224. (troop_set_slot, ":troop_no", slot_troop_cur_center, ":town_no"), #SB : set troop slot
  37225. (store_faction_of_party, ":cur_faction", ":cur_center"),
  37226. (neq, ":cur_faction", "$players_kingdom"),
  37227. (party_set_slot, ":town_no", slot_center_traveler_info_faction, ":cur_faction"),
  37228. (assign, ":end_cond", 0), #we set this above
  37229. (try_end),
  37230.  
  37231. #info faction
  37232. (try_for_range, ":unused", 0, ":end_cond"),
  37233. (store_random_in_range, ":info_faction", npc_kingdoms_begin, kingdoms_end),
  37234. (faction_slot_eq, ":info_faction", slot_faction_state, sfs_active),
  37235. (neq, ":info_faction", "$players_kingdom"),
  37236. # (neq, ":info_faction", "fac_player_supporters_faction"),
  37237. (party_set_slot, ":town_no", slot_center_traveler_info_faction, ":info_faction"),
  37238. (assign, ":end_cond", 0),
  37239. (try_end),
  37240. (try_end),
  37241.  
  37242. #SB : let its own script update every 24 hours
  37243. # (troop_set_slot, "trp_belligerent_drunk", slot_troop_cur_center, "p_town_1"),
  37244. ]),
  37245.  
  37246. #script_update_villages_infested_by_bandits
  37247. # INPUT: none
  37248. # OUTPUT: none
  37249. ("update_villages_infested_by_bandits",
  37250. [
  37251. #SB : duration tweaks, remember that this is in a 72 hour slot
  37252. (options_get_campaign_ai, ":reduce"),
  37253. (val_add, ":reduce", 2), #default is 3
  37254. (try_for_range, ":village_no", villages_begin, villages_end),
  37255. (try_begin),
  37256. (check_quest_active, "qst_eliminate_bandits_infesting_village"),
  37257. (quest_slot_eq, "qst_eliminate_bandits_infesting_village", slot_quest_target_center, ":village_no"),
  37258. (quest_get_slot, ":cur_state", "qst_eliminate_bandits_infesting_village", slot_quest_current_state),
  37259. (val_add, ":cur_state", 1),
  37260. (try_begin),
  37261. (lt, ":cur_state", ":reduce"),
  37262. (quest_set_slot, "qst_eliminate_bandits_infesting_village", slot_quest_current_state, ":cur_state"),
  37263. (else_try),
  37264. (party_set_slot, ":village_no", slot_village_infested_by_bandits, 0),
  37265. (call_script, "script_abort_quest", "qst_eliminate_bandits_infesting_village", 2),
  37266. (try_end),
  37267. (else_try),
  37268. (check_quest_active, "qst_deal_with_bandits_at_lords_village"),
  37269. (quest_slot_eq, "qst_deal_with_bandits_at_lords_village", slot_quest_target_center, ":village_no"),
  37270. (quest_get_slot, ":cur_state", "qst_deal_with_bandits_at_lords_village", slot_quest_current_state),
  37271. (val_add, ":cur_state", 1),
  37272. (try_begin),
  37273. (lt, ":cur_state", ":reduce"),
  37274. (quest_set_slot, "qst_deal_with_bandits_at_lords_village", slot_quest_current_state, ":cur_state"),
  37275. (else_try),
  37276. (party_set_slot, ":village_no", slot_village_infested_by_bandits, 0),
  37277. (call_script, "script_abort_quest", "qst_deal_with_bandits_at_lords_village", 2),
  37278. (try_end),
  37279. (else_try),
  37280. (party_set_slot, ":village_no", slot_village_infested_by_bandits, 0),
  37281. #SB : prosperity linked infestation
  37282. (try_begin),
  37283. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),
  37284. (party_get_slot, ":prosperity", ":village_no", slot_town_prosperity),
  37285. (val_div, ":prosperity", 2), #0 to 50
  37286. (val_add, ":prosperity", 75), #75 to 125
  37287. (store_random_in_range, ":random_no", 0, ":prosperity"),
  37288. (else_try),
  37289. (store_random_in_range, ":random_no", 0, 100),
  37290. (try_end),
  37291. # (assign, ":continue", 1),
  37292. (try_begin),
  37293. (check_quest_active, "qst_collect_taxes"),
  37294. (quest_slot_eq, "qst_collect_taxes", slot_quest_target_center, ":village_no"),
  37295. (assign, ":random_no", 100),
  37296. (else_try),
  37297. (check_quest_active, "qst_train_peasants_against_bandits"),
  37298. (quest_slot_eq, "qst_train_peasants_against_bandits", slot_quest_target_center, ":village_no"),
  37299. (assign, ":random_no", 100),
  37300. (try_end),
  37301. # (eq, ":continue", 1),
  37302. ## SB : update bandit creation parameters
  37303. (lt, ":random_no", 3),
  37304. (call_script, "script_center_get_bandits", ":village_no", 0),
  37305. (assign, ":bandit_troop", reg0),
  37306. (party_set_slot, ":village_no", slot_village_infested_by_bandits, ":bandit_troop"),
  37307. #Reduce prosperity of the village by 3: reduce to -1
  37308. (call_script, "script_change_center_prosperity", ":village_no", -1),
  37309. (val_add, "$newglob_total_prosperity_from_bandits", -1),
  37310. (try_begin),
  37311. (eq, "$cheat_mode", 2),
  37312. (str_store_party_name, s1, ":village_no"),
  37313. (display_message, "@{!}DEBUG --{s1} is infested by bandits."),
  37314. (try_end),
  37315. (try_end),
  37316. (try_end),
  37317. ]),
  37318.  
  37319. #script_update_booksellers
  37320. # INPUT: none
  37321. # OUTPUT: none
  37322. ("update_booksellers",
  37323. [(try_for_range, ":town_no", towns_begin, towns_end),
  37324. (neg|party_slot_ge, ":town_no", slot_center_is_besieged_by, 1), #keep them there
  37325. (party_set_slot, ":town_no", slot_center_tavern_bookseller, 0),
  37326. (try_end),
  37327.  
  37328. (try_for_range, ":troop_no", tavern_booksellers_begin, tavern_booksellers_end),
  37329. (troop_get_slot, ":cur_center", ":troop_no", slot_troop_cur_center),
  37330. (neg|party_slot_ge, ":cur_center", slot_center_is_besieged_by, 1), #can't travel
  37331. (store_random_in_range, ":town_no", towns_begin, towns_end),
  37332. (party_set_slot, ":town_no", slot_center_tavern_bookseller, ":troop_no"),
  37333. (troop_set_slot, ":troop_no", slot_troop_cur_center, ":town_no"), #SB : set troop slot
  37334. (try_end),
  37335.  
  37336.  
  37337.  
  37338. ]),
  37339.  
  37340. #script_update_tavern_minstels
  37341. # INPUT: none
  37342. # OUTPUT: none
  37343. ("update_tavern_minstrels",
  37344. [(try_for_range, ":town_no", towns_begin, towns_end),
  37345. (party_set_slot, ":town_no", slot_center_tavern_minstrel, 0),
  37346. (try_end),
  37347.  
  37348. #SB : remove restriction on travel, add preference for feasts
  37349. (try_for_range, ":troop_no", tavern_minstrels_begin, tavern_minstrels_end),
  37350. (store_random_in_range, ":town_no", towns_begin, towns_end),
  37351. (store_faction_of_party, ":faction_no", ":town_no"),
  37352. #feasts can be in castles, we haven't added code to put minstrels in
  37353. (try_begin),
  37354. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_feast),
  37355. (faction_get_slot, ":center_no", ":faction_no", slot_faction_ai_object),
  37356. (is_between, ":center_no", towns_begin, towns_end),
  37357. (neg|party_slot_ge, ":center_no", slot_center_tavern_minstrel, tavern_minstrels_begin),
  37358. (assign, ":town_no", ":center_no"),
  37359. (try_end),
  37360. (party_set_slot, ":town_no", slot_center_tavern_minstrel, ":troop_no"),
  37361. (troop_set_slot, ":troop_no", slot_troop_cur_center, ":town_no"), #SB : set troop slot
  37362. (try_begin),
  37363. (eq, "$cheat_mode", 1),
  37364. (str_store_troop_name, s4, ":troop_no"),
  37365. (str_store_party_name, s5, ":town_no"),
  37366.  
  37367. (display_message, "str_s4_is_at_s5"),
  37368. (try_end),
  37369. (try_end),
  37370.  
  37371.  
  37372. ]),
  37373.  
  37374. ("update_other_taverngoers",
  37375. [
  37376. (store_random_in_range, ":fight_promoter_tavern", towns_begin, towns_end),
  37377. (troop_set_slot, "trp_fight_promoter", slot_troop_cur_center, ":fight_promoter_tavern"),
  37378.  
  37379. (store_random_in_range, ":belligerent_drunk_tavern", towns_begin, towns_end),
  37380. (troop_set_slot, "trp_belligerent_drunk", slot_troop_cur_center, ":belligerent_drunk_tavern"),
  37381. ]),
  37382.  
  37383.  
  37384. #script_update_faction_notes
  37385. # INPUT: faction_no
  37386. # OUTPUT: none
  37387. ("update_faction_notes",
  37388. [
  37389. (store_script_param, ":faction_no", 1),
  37390.  
  37391. (try_begin),
  37392. (this_or_next|faction_slot_eq, ":faction_no", slot_faction_state, sfs_inactive),
  37393. (eq, ":faction_no", "fac_player_faction"),
  37394. (faction_set_note_available, ":faction_no", 0),
  37395. (else_try),
  37396. (faction_set_note_available, ":faction_no", 1),
  37397. (try_end),
  37398. ##
  37399. ## (try_begin),
  37400. ## (eq, 2, 1),
  37401. ## (str_store_faction_name, s14, ":faction_no"),
  37402. ## (assign, reg4, "$temp"),
  37403. ## (display_message, "str_updating_faction_notes_for_s14_temp_=_reg4"),
  37404. ## (try_end),
  37405. ##
  37406. ## (try_begin),
  37407. ## (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  37408. ## (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  37409. ## (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  37410. ## (str_store_faction_name, s5, ":faction_no"),
  37411. ## (str_store_troop_name_link, s6, ":faction_leader"),
  37412. ## (assign, ":num_centers", 0),
  37413. ## (str_store_string, s8, "@nowhere"),
  37414. ## (try_for_range_backwards, ":cur_center", centers_begin, centers_end),
  37415. ## (store_faction_of_party, ":center_faction", ":cur_center"),
  37416. ## (eq, ":center_faction", ":faction_no"),
  37417. ## (try_begin),
  37418. ## (eq, ":num_centers", 0),
  37419. ## (str_store_party_name_link, s8, ":cur_center"),
  37420. ## (else_try),
  37421. ## (eq, ":num_centers", 1),
  37422. ## (str_store_party_name_link, s7, ":cur_center"),
  37423. ## (str_store_string, s8, "@{s7} and {s8}"),
  37424. ## (else_try),
  37425. ## (str_store_party_name_link, s7, ":cur_center"),
  37426. ## (str_store_string, s8, "@{!}{s7}, {s8}"),
  37427. ## (try_end),
  37428. ## (val_add, ":num_centers", 1),
  37429. ## (try_end),
  37430. ## (assign, ":num_members", 0),
  37431. ## (str_store_string, s10, "@noone"),
  37432. ## (try_for_range_backwards, ":loop_var", "trp_kingdom_heroes_including_player_begin", active_npcs_end),
  37433. ## (assign, ":cur_troop", ":loop_var"),
  37434. ## (try_begin),
  37435. ## (eq, ":loop_var", "trp_kingdom_heroes_including_player_begin"),
  37436. ## (assign, ":cur_troop", "trp_player"),
  37437. ## (assign, ":troop_faction", "$players_kingdom"),
  37438. ## (else_try),
  37439. ## (store_troop_faction, ":troop_faction", ":cur_troop"),
  37440. ## (try_end),
  37441. ## (eq, ":troop_faction", ":faction_no"),
  37442. ## (neq, ":cur_troop", ":faction_leader"),
  37443. ## (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  37444. ## (try_begin),
  37445. ## (eq, ":num_members", 0),
  37446. ## (str_store_troop_name_link, s10, ":cur_troop"),
  37447. ## (else_try),
  37448. ## (eq, ":num_members", 1),
  37449. ## (str_store_troop_name_link, s9, ":cur_troop"),
  37450. ## (str_store_string, s10, "@{s9} and {s10}"),
  37451. ## (else_try),
  37452. ## (str_store_troop_name_link, s9, ":cur_troop"),
  37453. ## (str_store_string, s10, "@{!}{s9}, {s10}"),
  37454. ## (try_end),
  37455. ## (val_add, ":num_members", 1),
  37456. ## (try_end),
  37457. ##
  37458. ## #wars
  37459. ## (str_store_string, s12, "@noone"),
  37460. ### (assign, ":num_enemies", 0),
  37461. ### (try_for_range_backwards, ":cur_faction", kingdoms_begin, kingdoms_end),
  37462. ### (faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
  37463. ### (store_relation, ":cur_relation", ":cur_faction", ":faction_no"),
  37464. ### (lt, ":cur_relation", 0),
  37465. ### (try_begin),
  37466. ### (eq, ":num_enemies", 0),
  37467. ### (str_store_faction_name_link, s12, ":cur_faction"),
  37468. ### (else_try),
  37469. ### (eq, ":num_enemies", 1),
  37470. ### (str_store_faction_name_link, s11, ":cur_faction"),
  37471. ### (str_store_string, s12, "@the {s11} and the {s12}"),
  37472. ### (else_try),
  37473. ### (str_store_faction_name_link, s11, ":cur_faction"),
  37474. ### (str_store_string, s12, "@the {s11}, the {s12}"),
  37475. ### (try_end),
  37476. ### (val_add, ":num_enemies", 1),
  37477. ### (try_end),
  37478. ##
  37479. ## (str_store_string, s21, "str_foreign_relations__"),
  37480. ##
  37481. ## #other foreign relations
  37482. ## (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  37483. ## (faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),
  37484. ## (neq, ":faction_no", ":cur_faction"),
  37485. ## (str_store_faction_name_link, s14, ":cur_faction"),
  37486. ## (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":faction_no", ":cur_faction"),
  37487. ## (assign, ":diplomatic_status", reg0),
  37488. ## (assign, reg2, reg1), #length of events
  37489. ## (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":cur_faction", ":faction_no"),
  37490. ## (assign, ":reverse_diplomatic_status", reg0),
  37491. ##
  37492. ##
  37493. ## (try_begin),
  37494. ## (eq, ":diplomatic_status", -2),
  37495. ## (str_store_string, s21, "str_s21__the_s5_is_at_war_with_the_s14"),
  37496. ##
  37497. ## (store_add, ":slot_war_damage_inflicted", ":cur_faction", slot_faction_war_damage_inflicted_on_factions_begin),
  37498. ## (val_sub, ":slot_war_damage_inflicted", kingdoms_begin),
  37499. ## (faction_get_slot, ":war_damage_inflicted", ":faction_no", ":slot_war_damage_inflicted"),
  37500. ## (store_mul, ":war_damage_inflicted_x_2", ":war_damage_inflicted", 2),
  37501. ##
  37502. ## (store_add, ":slot_war_damage_suffered", ":faction_no", slot_faction_war_damage_inflicted_on_factions_begin),
  37503. ## (val_sub, ":slot_war_damage_suffered", kingdoms_begin),
  37504. ## (faction_get_slot, ":war_damage_suffered", ":cur_faction", ":slot_war_damage_suffered"),
  37505. ## (store_mul, ":war_damage_suffered_x_2", ":war_damage_suffered", 2),
  37506. ##
  37507. ## (try_begin),
  37508. ## (gt, ":war_damage_inflicted", ":war_damage_suffered_x_2"),
  37509. ## (str_store_string, s21, "str_s21_the_s5_has_had_the_upper_hand_in_the_fighting"),
  37510. ## (else_try),
  37511. ## (gt, ":war_damage_suffered", ":war_damage_inflicted_x_2"),
  37512. ## (str_store_string, s21, "@{s21}. The {s14} has gotten the worst of the fighting."),
  37513. ## (else_try),
  37514. ## (gt, ":war_damage_inflicted", 100),
  37515. ## (gt, ":war_damage_inflicted", 100),
  37516. ## (str_store_string, s21, "str_s21_the_fighting_has_gone_on_for_some_time_and_the_war_may_end_soon_with_a_truce"),
  37517. ## (else_try),
  37518. ## (str_store_string, s21, "str_s21_the_fighting_has_begun_relatively_recently_and_the_war_may_continue_for_some_time"),
  37519. ## (try_end),
  37520. ##
  37521. ## (try_begin),
  37522. ## (eq, "$cheat_mode", 1),
  37523. ## (assign, reg4, ":war_damage_inflicted"),
  37524. ## (assign, reg5, ":war_damage_suffered"),
  37525. ## (str_store_string, s21, "str_s21_reg4reg5"),
  37526. ## (try_end),
  37527. ## (else_try),
  37528. ## (eq, ":diplomatic_status", 1),
  37529. ## (str_clear, s18),
  37530. ##
  37531. ## (try_begin),
  37532. ## (neq, reg0, 1),
  37533. ## (str_store_string, s18, "str__however_the_truce_is_no_longer_binding_on_the_s14"),
  37534. ## (try_end),
  37535. ## (str_store_string, s21, "str_s21__the_s5_is_bound_by_truce_not_to_attack_the_s14s18_the_truce_will_expire_in_reg1_days"),
  37536. ##
  37537. ## (else_try),
  37538. ## (eq, ":diplomatic_status", -1),
  37539. ## (str_store_string, s21, "str_s21__the_s5_has_recently_suffered_provocation_by_subjects_of_the_s14_and_there_is_a_risk_of_war"),
  37540. ## (else_try),
  37541. ## (eq, ":diplomatic_status", 0),
  37542. ## (str_store_string, s21, "str_s21__the_s5_has_no_outstanding_issues_with_the_s14"),
  37543. ## (try_end),
  37544. ##
  37545. ##
  37546. ## (try_begin),
  37547. ## (eq, ":reverse_diplomatic_status", -1),
  37548. ## (str_store_string, s21, "str_s21_the_s14_was_recently_provoked_by_subjects_of_the_s5_and_there_is_a_risk_of_war_"),
  37549. ## (try_end),
  37550. ##
  37551. ## (try_begin),
  37552. ## (eq, "$cheat_mode", 1),
  37553. ## (call_script, "script_diplomacy_faction_assess_faction_to_s14", ":faction_no", ":cur_faction", -1),
  37554. ## (str_store_string, s21, "str_s21_cheat_mode_assessment_s14_"),
  37555. ## (try_end),
  37556. ## (try_end),
  37557. ##
  37558. ##
  37559. ## (add_faction_note_from_sreg, ":faction_no", 0, "str_the_s5_is_ruled_by_s6_it_occupies_s8_its_vassals_are_s10__s21", 0),
  37560. ##
  37561. ##
  37562. ##
  37563. ## (else_try),
  37564. ## (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  37565. ## (faction_slot_eq, ":faction_no", slot_faction_state, sfs_defeated),
  37566. ## (str_store_faction_name, s5, ":faction_no"),
  37567. ## (add_faction_note_from_sreg, ":faction_no", 0, "@{s5} has been defeated!", 0),
  37568. ## (str_clear, s1),
  37569. ## (add_faction_note_from_sreg, ":faction_no", 1, s1, 0),
  37570. ## (else_try),
  37571. ## (str_clear, s1),
  37572. ## (add_faction_note_from_sreg, ":faction_no", 0, s1, 0),
  37573. ## (add_faction_note_from_sreg, ":faction_no", 1, s1, 0),
  37574. ## (try_end),
  37575. ##
  37576. ## (try_begin),
  37577. ## (is_between, ":faction_no", "fac_kingdom_1", kingdoms_end), #Excluding player kingdom
  37578. ## (add_faction_note_tableau_mesh, ":faction_no", "tableau_faction_note_mesh"),
  37579. ## (else_try),
  37580. ## (add_faction_note_tableau_mesh, ":faction_no", "tableau_faction_note_mesh_banner"),
  37581. ## (try_end),
  37582. ]),
  37583.  
  37584. ("update_faction_political_notes",
  37585. [(store_script_param, ":faction_no", 1),
  37586.  
  37587. (call_script, "script_evaluate_realm_stability", ":faction_no"),
  37588. (add_faction_note_from_sreg, ":faction_no", 2, "str_instability_reg0_of_lords_are_disgruntled_reg1_are_restless", 0),
  37589. ]),
  37590.  
  37591.  
  37592.  
  37593. #script_update_faction_traveler_notes
  37594. # INPUT: faction_no
  37595. # OUTPUT: none
  37596. ("update_faction_traveler_notes",
  37597. [(store_script_param, ":faction_no", 1),
  37598. (assign, ":total_men", 0),
  37599. (try_for_parties, ":cur_party"),
  37600. (store_faction_of_party, ":center_faction", ":cur_party"),
  37601. (eq, ":center_faction", ":faction_no"),
  37602. (party_get_num_companions, ":num_men", ":cur_party"),
  37603. (val_add, ":total_men", ":num_men"),
  37604. (try_end),
  37605. (str_store_faction_name, s5, ":faction_no"),
  37606. (assign, reg1, ":total_men"),
  37607. (add_faction_note_from_sreg, ":faction_no", 1, "@{s5} has a strength of {reg1} men in total.", 1),
  37608. ]),
  37609.  
  37610.  
  37611. #script_update_troop_notes
  37612. # INPUT: troop_no
  37613. # OUTPUT: none
  37614. ("update_troop_notes",
  37615. [
  37616. ## (store_script_param, ":troop_no", 1),
  37617. ## (str_store_troop_name, s54, ":troop_no"),
  37618. ## (try_begin),
  37619. ## (eq, ":troop_no", "trp_player"),
  37620. ## (this_or_next|eq, "$player_has_homage", 1),
  37621. ## (eq, "$players_kingdom", "fac_player_supporters_faction"),
  37622. ## (assign, ":troop_faction", "$players_kingdom"),
  37623. ## (else_try),
  37624. ## (store_troop_faction, ":troop_faction", ":troop_no"),
  37625. ## (try_end),
  37626. ##
  37627. ## (str_clear, s49),
  37628. ## (try_begin),
  37629. ## (is_between, ":troop_no", lords_begin, kingdom_ladies_end),
  37630. ## (troop_get_slot, reg1, ":troop_no", slot_troop_age),
  37631. ## (str_store_string, s49, "str__age_reg1_family_"),
  37632. ##
  37633. ## (try_for_range, ":aristocrat", lords_begin, kingdom_ladies_end),
  37634. ## (call_script, "script_troop_get_family_relation_to_troop", ":aristocrat", ":troop_no"),
  37635. ## (gt, reg0, 0),
  37636. ##
  37637. ## (try_begin),
  37638. ## (neg|is_between, ":aristocrat", kingdom_ladies_begin, kingdom_ladies_end),
  37639. ## (str_store_troop_name_link, s12, ":aristocrat"),
  37640. ## (call_script, "script_troop_get_relation_with_troop", ":aristocrat", ":troop_no"),
  37641. ## (str_store_string, s49, "str_s49_s12_s11_rel_reg0"),
  37642. ## (else_try),
  37643. ## (str_store_troop_name, s12, ":aristocrat"),
  37644. ## (str_store_string, s49, "str_s49_s12_s11"),
  37645. ## (try_end),
  37646. ##
  37647. ## (try_end),
  37648. ## (try_end),
  37649. ##
  37650. ## (try_begin),
  37651. ## (neq, ":troop_no", "trp_player"),
  37652. ## (neg|is_between, ":troop_faction", kingdoms_begin, kingdoms_end),
  37653. ## (str_clear, s54),
  37654. ## (add_troop_note_from_sreg, ":troop_no", 0, s54, 0),
  37655. ## (add_troop_note_from_sreg, ":troop_no", 1, s54, 0),
  37656. ## (add_troop_note_from_sreg, ":troop_no", 2, s54, 0),
  37657. ### (else_try),
  37658. ### (is_between, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  37659. ### (str_clear, s54),
  37660. ### (add_troop_note_from_sreg, ":troop_no", 0, s54, 0),
  37661. ### (add_troop_note_from_sreg, ":troop_no", 1, s54, 0),
  37662. ### (add_troop_note_from_sreg, ":troop_no", 2, s54, 0),
  37663. ## (else_try),
  37664. ## (is_between, ":troop_no", pretenders_begin, pretenders_end),
  37665. ## (neg|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  37666. ## (neq, ":troop_no", "$supported_pretender"),
  37667. ## (troop_get_slot, ":orig_faction", ":troop_no", slot_troop_original_faction),
  37668. ## (try_begin),
  37669. ## (faction_slot_eq, ":orig_faction", slot_faction_state, sfs_active),
  37670. ## (faction_slot_eq, ":orig_faction", slot_faction_has_rebellion_chance, 1),
  37671. ## (str_store_faction_name_link, s56, ":orig_faction"),
  37672. ## (add_troop_note_from_sreg, ":troop_no", 0, "@{s54} is a claimant to the throne of {s56}.", 0),
  37673. ## (add_troop_note_tableau_mesh, ":troop_no", "tableau_troop_note_mesh"),
  37674. ## (else_try),
  37675. ## (str_clear, s54),
  37676. ## (add_troop_note_from_sreg, ":troop_no", 0, s54, 0),
  37677. ## (add_troop_note_from_sreg, ":troop_no", 1, s54, 0),
  37678. ## (add_troop_note_from_sreg, ":troop_no", 2, s54, 0),
  37679. ## (try_end),
  37680. ## (else_try),
  37681. ## (faction_get_slot, ":faction_leader", ":troop_faction", slot_faction_leader),
  37682. ## (str_store_troop_name_link, s55, ":faction_leader"),
  37683. ## (str_store_faction_name_link, s56, ":troop_faction"),
  37684. ## (assign, ":troop_is_player_faction", 0),
  37685. ## (assign, ":troop_is_faction_leader", 0),
  37686. ## (try_begin),
  37687. ## (eq, ":troop_faction", "fac_player_faction"),
  37688. ## (assign, ":troop_is_player_faction", 1),
  37689. ## (else_try),
  37690. ## (eq, ":faction_leader", ":troop_no"),
  37691. ## (assign, ":troop_is_faction_leader", 1),
  37692. ## (try_end),
  37693. ## (assign, ":num_centers", 0),
  37694. ## (str_store_string, s58, "@nowhere"),
  37695. ## (try_for_range_backwards, ":cur_center", centers_begin, centers_end),
  37696. ## (party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
  37697. ## (try_begin),
  37698. ## (eq, ":num_centers", 0),
  37699. ## (str_store_party_name_link, s58, ":cur_center"),
  37700. ## (else_try),
  37701. ## (eq, ":num_centers", 1),
  37702. ## (str_store_party_name_link, s57, ":cur_center"),
  37703. ## (str_store_string, s58, "@{s57} and {s58}"),
  37704. ## (else_try),
  37705. ## (str_store_party_name_link, s57, ":cur_center"),
  37706. ## (str_store_string, s58, "@{!}{s57}, {s58}"),
  37707. ## (try_end),
  37708. ## (val_add, ":num_centers", 1),
  37709. ## (try_end),
  37710. ## (troop_get_type, reg3, ":troop_no"),
  37711. ## (troop_get_slot, reg5, ":troop_no", slot_troop_renown),
  37712. ## (str_clear, s59),
  37713. ## (try_begin),
  37714. ### (troop_get_slot, ":relation", ":troop_no", slot_troop_player_relation),
  37715. ## (call_script, "script_troop_get_player_relation", ":troop_no"),
  37716. ## (assign, ":relation", reg0),
  37717. ## (store_add, ":normalized_relation", ":relation", 100),
  37718. ## (val_add, ":normalized_relation", 5),
  37719. ## (store_div, ":str_offset", ":normalized_relation", 10),
  37720. ## (val_clamp, ":str_offset", 0, 20),
  37721. ## (store_add, ":str_id", "str_relation_mnus_100_ns", ":str_offset"),
  37722. ## (neq, ":str_id", "str_relation_plus_0_ns"),
  37723. ## (str_store_string, s60, "@{reg3?She:He}"),
  37724. ## (str_store_string, s59, ":str_id"),
  37725. ## (str_store_string, s59, "@{!}^{s59}"),
  37726. ## (try_end),
  37727. ##
  37728. ## #lord recruitment changes begin
  37729. ## #This sends a bunch of political information to s47.
  37730. ##
  37731. ##
  37732. ##
  37733. ##
  37734. ## #refresh registers
  37735. ## (assign, reg9, ":num_centers"),
  37736. ## (troop_get_type, reg3, ":troop_no"),
  37737. ## (troop_get_slot, reg5, ":troop_no", slot_troop_renown),
  37738. ## (assign, reg4, ":troop_is_faction_leader"),
  37739. ## (assign, reg6, ":troop_is_player_faction"),
  37740. ##
  37741. ## (add_troop_note_from_sreg, ":troop_no", 0, "str_reg6reg4s54_is_the_ruler_of_s56_s54_is_a_vassal_of_s55_of_s56_renown_reg5_reg9reg3shehe_is_the_reg3ladylord_of_s58reg3shehe_has_no_fiefss59_s49", 0),
  37742. ## #lord recruitment changes end
  37743. ##
  37744. ## (add_troop_note_tableau_mesh, ":troop_no", "tableau_troop_note_mesh"),
  37745. ## (try_end),
  37746. ]),
  37747.  
  37748. #script_update_troop_location_notes
  37749. # INPUT: troop_no
  37750. # OUTPUT: none
  37751. ("update_troop_location_notes",
  37752. [
  37753. (store_script_param, ":troop_no", 1),
  37754. (store_script_param, ":see_or_hear", 2),
  37755. (try_begin),
  37756. (call_script, "script_get_information_about_troops_position", ":troop_no", 1),
  37757. (neq, reg0, 0),
  37758.  
  37759. (call_script, "script_search_troop_prisoner_of_party", ":troop_no"),
  37760. (eq, reg0, -1),
  37761. ##diplomacy start+ use gender script
  37762. #(troop_get_type, reg1, ":troop_no"),
  37763. (call_script, "script_dplmc_store_troop_is_female", ":troop_no"),
  37764. (assign, reg1, reg0),
  37765. ##diplomacy end+
  37766. (try_begin),
  37767. (eq, ":see_or_hear", 0),
  37768. (add_troop_note_from_sreg, ":troop_no", 2, "@The last time you saw {reg1?her:him}, {s1}", 1),
  37769. (else_try),
  37770. (add_troop_note_from_sreg, ":troop_no", 2, "@The last time you heard about {reg1?her:him}, {s1}", 1),
  37771. (try_end),
  37772. (try_end),
  37773. ]),
  37774.  
  37775. #script_update_troop_location_notes_prisoned
  37776. # INPUT: troop_no
  37777. # OUTPUT: none
  37778. ("update_troop_location_notes_prisoned",
  37779. [
  37780. (store_script_param, ":troop_no", 1),
  37781. (store_script_param, ":capturer_faction_no", 2),
  37782. ##diplomacy start+ use gender script
  37783. #(troop_get_type, reg1, ":troop_no"),
  37784. (call_script, "script_dplmc_store_troop_is_female", ":troop_no"),
  37785. (assign, reg1, reg0),
  37786. ##diplomacy end+
  37787. (str_store_faction_name_link, s1, ":capturer_faction_no"),
  37788.  
  37789. (add_troop_note_from_sreg, ":troop_no", 2, "str_reg1shehe_is_prisoner_of_s1", 1),
  37790. ]),
  37791.  
  37792. ("update_troop_political_notes",
  37793. [
  37794. (store_script_param, ":troop_no", 1),
  37795. (try_begin),
  37796. (str_clear, s47),
  37797.  
  37798. (store_faction_of_troop, ":troop_faction", ":troop_no"),
  37799.  
  37800. (faction_get_slot, ":faction_leader", ":troop_faction", slot_faction_leader),
  37801.  
  37802. (str_clear, s40),
  37803. (assign, ":logged_a_rivalry", 0),
  37804. (try_for_range, ":kingdom_hero", active_npcs_begin, active_npcs_end),
  37805. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":kingdom_hero"),
  37806. (lt, reg0, -10),
  37807.  
  37808. (str_store_troop_name_link, s39, ":kingdom_hero"),
  37809. (try_begin),
  37810. (eq, ":logged_a_rivalry", 0),
  37811. (str_store_string, s40, "str_s39_rival"),
  37812. (assign, ":logged_a_rivalry", 1),
  37813. (else_try),
  37814. (str_store_string, s41, "str_s40"),
  37815. (str_store_string, s40, "str_s41_s39_rival"),
  37816. (try_end),
  37817.  
  37818. (try_end),
  37819.  
  37820. (str_clear, s46),
  37821. (try_begin),
  37822. (ge, "$cheat_mode", 1),
  37823. (try_begin),
  37824. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_martial),
  37825. (str_store_string, s46, "str_reputation_cheat_mode_only_martial_"),
  37826. (else_try),
  37827. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  37828. (str_store_string, s46, "str_reputation_cheat_mode_only_debauched_"),
  37829. (else_try),
  37830. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_selfrighteous),
  37831. (str_store_string, s46, "str_reputation_cheat_mode_only_pitiless_"),
  37832. (else_try),
  37833. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  37834. (str_store_string, s46, "str_reputation_cheat_mode_only_calculating_"),
  37835. (else_try),
  37836. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_quarrelsome),
  37837. (str_store_string, s46, "str_reputation_cheat_mode_only_quarrelsome_"),
  37838. (else_try),
  37839. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  37840. (str_store_string, s46, "str_reputation_cheat_mode_only_goodnatured_"),
  37841. (else_try),
  37842. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  37843. (str_store_string, s46, "str_reputation_cheat_mode_only_upstanding_"),
  37844. (else_try),
  37845. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_conventional),
  37846. (str_store_string, s46, "str_reputation_cheat_mode_only_conventional_"),
  37847. (else_try),
  37848. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_adventurous),
  37849. (str_store_string, s46, "str_reputation_cheat_mode_only_adventurous_"),
  37850. (else_try),
  37851. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_otherworldly),
  37852. (str_store_string, s46, "str_reputation_cheat_mode_only_romantic_"),
  37853. (else_try),
  37854. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_moralist),
  37855. (str_store_string, s46, "str_reputation_cheat_mode_only_moralist_"),
  37856. (else_try),
  37857. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_ambitious),
  37858. (str_store_string, s46, "str_reputation_cheat_mode_only_ambitious_"),
  37859. (else_try),
  37860. (troop_get_slot, reg11, ":troop_no", slot_lord_reputation_type),
  37861. (str_store_string, s46, "str_reputation_cheat_mode_only_reg11_"),
  37862. (try_end),
  37863.  
  37864. (try_begin),
  37865. (eq, "$cheat_mode", 1),
  37866. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  37867. (troop_get_slot, ":love_interest", ":troop_no", ":love_interest_slot"),
  37868. (is_between, ":love_interest", kingdom_ladies_begin, kingdom_ladies_end),
  37869. (str_store_troop_name_link, s39, ":love_interest"),
  37870. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":love_interest"),
  37871. (str_store_string, s2, "str_love_interest"),
  37872. (try_begin),
  37873. (troop_slot_eq, ":troop_no", slot_troop_betrothed, ":love_interest"),
  37874. (str_store_string, s2, "str_betrothed"),
  37875. (try_end),
  37876. (str_store_string, s40, "str_s40_s39_s2_reg0"),
  37877. (try_end),
  37878. (try_end),
  37879.  
  37880. (try_end),
  37881.  
  37882. (str_store_string, s45, "str_other_relations_s40_"),
  37883.  
  37884. (str_clear, s44),
  37885. (try_begin),
  37886. (neq, ":troop_no", ":faction_leader"),
  37887. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_leader"),
  37888. (str_store_string, s44, "str_relation_with_liege_reg0_"),
  37889. (try_end),
  37890.  
  37891. (str_clear, s48),
  37892.  
  37893. (try_begin),
  37894. (eq, "$cheat_mode", 1),
  37895. (store_current_hours, ":hours"),
  37896. (gt, ":hours", 0),
  37897. # (display_message, "@{!}Updating political factors"),
  37898. (call_script, "script_calculate_troop_political_factors_for_liege", ":troop_no", ":faction_leader"),
  37899. (str_store_string, s48, "str_sense_of_security_military_reg1_court_position_reg3_"),
  37900. (try_end),
  37901. (str_store_string, s47, "str_s46s45s44s48"),
  37902.  
  37903. (add_troop_note_from_sreg, ":troop_no", 3, "str_political_details_s47_", 1),
  37904.  
  37905. (try_end),
  37906. ]),
  37907.  
  37908. #script_update_center_notes
  37909. # INPUT: center_no
  37910. # OUTPUT: none
  37911. ("update_center_notes",
  37912. [
  37913. ## (store_script_param, ":center_no", 1),
  37914. ##
  37915. ## (party_get_slot, ":lord_troop", ":center_no", slot_town_lord),
  37916. ## (try_begin),
  37917. ## (ge, ":lord_troop", 0),
  37918. ## (store_troop_faction, ":lord_faction", ":lord_troop"),
  37919. ## (str_store_troop_name_link, s1, ":lord_troop"),
  37920. ## (try_begin),
  37921. ## (eq, ":lord_troop", "trp_player"),
  37922. ## (gt, "$players_kingdom", 0),
  37923. ## (str_store_faction_name_link, s2, "$players_kingdom"),
  37924. ## (else_try),
  37925. ## (str_store_faction_name_link, s2, ":lord_faction"),
  37926. ## (try_end),
  37927. ## (str_store_party_name, s50, ":center_no"),
  37928. ## (try_begin),
  37929. ## (party_slot_eq, ":center_no", slot_party_type, spt_town),
  37930. ## (str_store_string, s51, "@The town of {s50}"),
  37931. ## (else_try),
  37932. ## (party_slot_eq, ":center_no", slot_party_type, spt_village),
  37933. ## (party_get_slot, ":bound_center", ":center_no", slot_village_bound_center),
  37934. ## (str_store_party_name_link, s52, ":bound_center"),
  37935. ## (str_store_string, s51, "@The village of {s50} near {s52}"),
  37936. ## (else_try),
  37937. ## (str_store_string, s51, "@{!}{s50}"),
  37938. ## (try_end),
  37939. ## (str_store_string, s2, "@{s51} belongs to {s1} of {s2}.^"),
  37940. ## (else_try),
  37941. ## (str_clear, s2),
  37942. ## (try_end),
  37943. ## (try_begin),
  37944. ## (is_between, ":center_no", villages_begin, villages_end),
  37945. ## (else_try),
  37946. ## (assign, ":num_villages", 0),
  37947. ## (try_for_range_backwards, ":village_no", villages_begin, villages_end),
  37948. ## (party_slot_eq, ":village_no", slot_village_bound_center, ":center_no"),
  37949. ## (try_begin),
  37950. ## (eq, ":num_villages", 0),
  37951. ## (str_store_party_name_link, s8, ":village_no"),
  37952. ## (else_try),
  37953. ## (eq, ":num_villages", 1),
  37954. ## (str_store_party_name_link, s7, ":village_no"),
  37955. ## (str_store_string, s8, "@{s7} and {s8}"),
  37956. ## (else_try),
  37957. ## (str_store_party_name_link, s7, ":village_no"),
  37958. ## (str_store_string, s8, "@{!}{s7}, {s8}"),
  37959. ## (try_end),
  37960. ## (val_add, ":num_villages", 1),
  37961. ## (try_end),
  37962. ## (try_begin),
  37963. ## (eq, ":num_villages", 0),
  37964. ## (str_store_string, s2, "@{s2}It has no villages.^"),
  37965. ## (else_try),
  37966. ## (store_sub, reg0, ":num_villages", 1),
  37967. ## (str_store_string, s2, "@{s2}{reg0?Its villages are:Its village is} {s8}.^"),
  37968. ## (try_end),
  37969. ## (try_end),
  37970. ## (call_script, "script_get_prosperity_text_to_s50", ":center_no"),
  37971. ## (add_party_note_from_sreg, ":center_no", 0, "@{s2}Its prosperity is: {s50}", 0),
  37972. ## (add_party_note_tableau_mesh, ":center_no", "tableau_center_note_mesh"),
  37973. ]),
  37974.  
  37975.  
  37976. #script_update_center_recon_notes
  37977. # INPUT: center_no
  37978. # OUTPUT: none
  37979. ("update_center_recon_notes",
  37980. [(store_script_param, ":center_no", 1),
  37981. (try_begin),
  37982. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  37983. (is_between, ":center_no", castles_begin, castles_end),
  37984. (party_get_slot, ":center_food_store", ":center_no", slot_party_food_store),
  37985. (call_script, "script_center_get_food_consumption", ":center_no"),
  37986. (assign, ":food_consumption", reg0),
  37987. (store_div, reg6, ":center_food_store", ":food_consumption"),
  37988. (party_collect_attachments_to_party, ":center_no", "p_collective_ally"),
  37989. (party_get_num_companions, reg5, "p_collective_ally"),
  37990. (add_party_note_from_sreg, ":center_no", 1, "@Current garrison consists of {reg5} men.^Has food stock for {reg6} days.", 1),
  37991. (try_end),
  37992. ]),
  37993.  
  37994. #script_update_all_notes
  37995. # INPUT: none
  37996. # OUTPUT: none
  37997. ("update_all_notes",
  37998. [
  37999. (call_script, "script_update_troop_notes", "trp_player"),
  38000. (try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
  38001. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  38002. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_lady),
  38003. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive_pretender),
  38004. (call_script, "script_update_troop_notes", ":troop_no"),
  38005. (try_end),
  38006. (try_for_range, ":center_no", centers_begin, centers_end),
  38007. (call_script, "script_update_center_notes", ":center_no"),
  38008. (try_end),
  38009. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  38010. (call_script, "script_update_faction_notes", ":faction_no"),
  38011. (try_end),
  38012. ]),
  38013.  
  38014. #script_agent_troop_get_banner_mesh
  38015. # INPUT: agent_no, troop_no
  38016. # OUTPUT: banner_mesh
  38017. ("agent_troop_get_banner_mesh",
  38018. [
  38019. (store_script_param, ":agent_no", 1),
  38020. (store_script_param, ":troop_no", 2),
  38021. (assign, ":banner_troop", -1),
  38022. (assign, ":banner_mesh", "mesh_banners_default_b"),
  38023. (try_begin),
  38024. (lt, ":agent_no", 0),
  38025. (try_begin),
  38026. (ge, ":troop_no", 0),
  38027. (this_or_next|troop_slot_ge, ":troop_no", slot_troop_banner_scene_prop, 1),
  38028. (eq, ":troop_no", "trp_player"),
  38029. (assign, ":banner_troop", ":troop_no"),
  38030. (else_try),
  38031. (is_between, ":troop_no", companions_begin, companions_end),
  38032. (assign, ":banner_troop", "trp_player"),
  38033. (else_try),
  38034. (assign, ":banner_mesh", "mesh_banners_default_a"),
  38035. (try_end),
  38036. (else_try),
  38037. (eq, "$g_is_quick_battle", 1),
  38038. (agent_get_team, ":agent_team", ":agent_no"),
  38039. (try_begin),
  38040. (eq, ":agent_team", 0),
  38041. (assign, ":banner_mesh", "$g_quick_battle_team_0_banner"),
  38042. (else_try),
  38043. (assign, ":banner_mesh", "$g_quick_battle_team_1_banner"),
  38044. (try_end),
  38045. (else_try),
  38046. (game_in_multiplayer_mode),
  38047. (agent_get_group, ":agent_group", ":agent_no"),
  38048. (try_begin),
  38049. (neg|player_is_active, ":agent_group"),
  38050. (agent_get_player_id, ":agent_group", ":agent_no"),
  38051. (try_end),
  38052. (try_begin),
  38053. #if player banners are not allowed, use the default banner mesh
  38054. (eq, "$g_multiplayer_allow_player_banners", 1),
  38055. (player_is_active, ":agent_group"),
  38056. (player_get_banner_id, ":player_banner", ":agent_group"),
  38057. (ge, ":player_banner", 0),
  38058. (store_add, ":banner_mesh", ":player_banner", arms_meshes_begin),
  38059. (assign, ":already_used", 0),
  38060. (try_for_range, ":cur_faction", npc_kingdoms_begin, npc_kingdoms_end), #wrong client data check
  38061. (faction_slot_eq, ":cur_faction", slot_faction_banner, ":banner_mesh"),
  38062. (assign, ":already_used", 1),
  38063. (try_end),
  38064. (eq, ":already_used", 0), #otherwise use the default banner mesh
  38065. (else_try),
  38066. (agent_get_team, ":agent_team", ":agent_no"),
  38067. (team_get_faction, ":team_faction_no", ":agent_team"),
  38068.  
  38069. (try_begin),
  38070. (agent_is_human, ":agent_no"),
  38071. (faction_get_slot, ":banner_mesh", ":team_faction_no", slot_faction_banner),
  38072. (else_try),
  38073. (agent_get_rider, ":rider_agent_no", ":agent_no"),
  38074. #(agent_get_position, pos1, ":agent_no"),
  38075. #(position_get_x, ":pos_x", pos1),
  38076. #(position_get_y, ":pos_y", pos1),
  38077. #(assign, reg0, ":pos_x"),
  38078. #(assign, reg1, ":pos_y"),
  38079. #(assign, reg2, ":agent_no"),
  38080. #(display_message, "@{!}agent_no:{reg2}, pos_x:{reg0} , posy:{reg1}"),
  38081. (try_begin),
  38082. (ge, ":rider_agent_no", 0),
  38083. (agent_is_active, ":rider_agent_no"),
  38084. (agent_get_team, ":rider_agent_team", ":rider_agent_no"),
  38085. (team_get_faction, ":rider_team_faction_no", ":rider_agent_team"),
  38086. (faction_get_slot, ":banner_mesh", ":rider_team_faction_no", slot_faction_banner),
  38087. (else_try),
  38088. (assign, ":banner_mesh", "mesh_banners_default_c"),
  38089. (try_end),
  38090. (try_end),
  38091. (try_end),
  38092. (else_try),
  38093. (agent_get_troop_id, ":troop_id", ":agent_no"),
  38094. (this_or_next|troop_slot_ge, ":troop_id", slot_troop_banner_scene_prop, 1),
  38095. (eq, ":troop_no", "trp_player"),
  38096. (assign, ":banner_troop", ":troop_id"),
  38097. (else_try),
  38098. (agent_get_party_id, ":agent_party", ":agent_no"),
  38099. (try_begin),
  38100. (lt, ":agent_party", 0),
  38101. (is_between, ":troop_id", companions_begin, companions_end),
  38102. (main_party_has_troop, ":troop_id"),
  38103. (assign, ":agent_party", "p_main_party"),
  38104. (try_end),
  38105. (ge, ":agent_party", 0),
  38106. (party_get_template_id, ":party_template", ":agent_party"),
  38107. (try_begin),
  38108. (eq, ":party_template", "pt_deserters"),
  38109. (assign, ":banner_mesh", "mesh_banners_default_c"),
  38110. (else_try),
  38111. (is_between, ":agent_party", centers_begin, centers_end),
  38112. (is_between, ":troop_id", companions_begin, companions_end),
  38113. (neq, "$talk_context", tc_tavern_talk),
  38114. #this should be a captured companion in prison
  38115. (assign, ":banner_troop", "trp_player"),
  38116. (else_try),
  38117. (is_between, ":agent_party", centers_begin, centers_end),
  38118. (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
  38119. (ge, ":town_lord", 0),
  38120. (assign, ":banner_troop", ":town_lord"),
  38121. (else_try),
  38122. (this_or_next|party_slot_eq, ":agent_party", slot_party_type, spt_kingdom_hero_party),
  38123. (eq, ":agent_party", "p_main_party"),
  38124. (party_get_num_companion_stacks, ":num_stacks", ":agent_party"),
  38125. (gt, ":num_stacks", 0),
  38126. (party_stack_get_troop_id, ":leader_troop_id", ":agent_party", 0),
  38127. (this_or_next|troop_slot_ge, ":leader_troop_id", slot_troop_banner_scene_prop, 1),
  38128. (eq, ":leader_troop_id", "trp_player"),
  38129. (assign, ":banner_troop", ":leader_troop_id"),
  38130. (try_end),
  38131. (else_try), #Check if we are in a tavern
  38132. (eq, "$talk_context", tc_tavern_talk),
  38133. (neq, ":troop_no", "trp_player"),
  38134. (assign, ":banner_mesh", "mesh_banners_default_d"),
  38135. (else_try), #can't find party, this can be a town guard
  38136. (neq, ":troop_no", "trp_player"),
  38137. (is_between, "$g_encountered_party", walled_centers_begin, walled_centers_end),
  38138. (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
  38139. (ge, ":town_lord", 0),
  38140. (assign, ":banner_troop", ":town_lord"),
  38141. (try_end),
  38142. (try_begin),
  38143. (ge, ":banner_troop", 0),
  38144. (try_begin),
  38145. (neg|troop_slot_ge, ":banner_troop", slot_troop_banner_scene_prop, 1),
  38146. (assign, ":banner_mesh", "mesh_banners_default_b"),
  38147. (else_try),
  38148. (troop_get_slot, ":banner_spr", ":banner_troop", slot_troop_banner_scene_prop),
  38149. (store_add, ":banner_scene_props_end", banner_scene_props_end_minus_one, 1),
  38150. (is_between, ":banner_spr", banner_scene_props_begin, ":banner_scene_props_end"),
  38151. (val_sub, ":banner_spr", banner_scene_props_begin),
  38152. (store_add, ":banner_mesh", ":banner_spr", arms_meshes_begin),
  38153. (try_end),
  38154. (try_end),
  38155. (assign, reg0, ":banner_mesh"),
  38156. ]),
  38157. #script_shield_item_set_banner
  38158. # INPUT: agent_no
  38159. # OUTPUT: none
  38160. ("shield_item_set_banner",
  38161. [
  38162. (store_script_param, ":tableau_no",1),
  38163. (store_script_param, ":agent_no", 2),
  38164. (store_script_param, ":troop_no", 3),
  38165. (call_script, "script_agent_troop_get_banner_mesh", ":agent_no", ":troop_no"),
  38166. (cur_item_set_tableau_material, ":tableau_no", reg0),
  38167. ]),
  38168.  
  38169.  
  38170. #script_troop_agent_set_banner
  38171. # INPUT: agent_no
  38172. # OUTPUT: none
  38173. ("troop_agent_set_banner",
  38174. [
  38175. (store_script_param, ":tableau_no",1),
  38176. (store_script_param, ":agent_no", 2),
  38177. (store_script_param, ":troop_no", 3),
  38178. (call_script, "script_agent_troop_get_banner_mesh", ":agent_no", ":troop_no"),
  38179. (cur_agent_set_banner_tableau_material, ":tableau_no", reg0),
  38180. ]),
  38181.  
  38182. ## #script_shield_item_set_banner
  38183. ## # INPUT: agent_no
  38184. ## # OUTPUT: none
  38185. ## ("shield_item_set_banner",
  38186. ## [
  38187. ## (store_script_param, ":tableau_no",1),
  38188. ## (store_script_param, ":agent_no", 2),
  38189. ## (store_script_param, ":troop_no", 3),
  38190. ## (assign, ":banner_troop", -1),
  38191. ## (try_begin),
  38192. ## (lt, ":agent_no", 0),
  38193. ## (try_begin),
  38194. ## (ge, ":troop_no", 0),
  38195. ## (troop_slot_ge, ":troop_no", slot_troop_banner_scene_prop, 0),
  38196. ## (assign, ":banner_troop", ":troop_no"),
  38197. ## (else_try),
  38198. ## (assign, ":banner_troop", -2),
  38199. ## (try_end),
  38200. ## (else_try),
  38201. ## (agent_get_troop_id, ":troop_id", ":agent_no"),
  38202. ## (troop_slot_ge, ":troop_id", slot_troop_custom_banner_flag_type, 0),
  38203. ## (assign, ":banner_troop", ":troop_id"),
  38204. ## (else_try),
  38205. ## (agent_get_party_id, ":agent_party", ":agent_no"),
  38206. ## (try_begin),
  38207. ## (lt, ":agent_party", 0),
  38208. ## (is_between, ":troop_id", companions_begin, companions_end),
  38209. ## (main_party_has_troop, ":troop_id"),
  38210. ## (assign, ":agent_party", "p_main_party"),
  38211. ## (try_end),
  38212. ## (ge, ":agent_party", 0),
  38213. ## (party_get_template_id, ":party_template", ":agent_party"),
  38214. ## (try_begin),
  38215. ## (eq, ":party_template", "pt_deserters"),
  38216. ## (assign, ":banner_troop", -3),
  38217. ## (else_try),
  38218. ## (is_between, ":agent_party", centers_begin, centers_end),
  38219. ## (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
  38220. ## (ge, ":town_lord", 0),
  38221. ## (assign, ":banner_troop", ":town_lord"),
  38222. ## (else_try),
  38223. ## (this_or_next|party_slot_eq, ":agent_party", slot_party_type, spt_kingdom_hero_party),
  38224. ## ( eq, ":agent_party", "p_main_party"),
  38225. ## (party_get_num_companion_stacks, ":num_stacks", ":agent_party"),
  38226. ## (gt, ":num_stacks", 0),
  38227. ## (party_stack_get_troop_id, ":leader_troop_id", ":agent_party", 0),
  38228. ## (troop_slot_ge, ":leader_troop_id", slot_troop_banner_scene_prop, 1),
  38229. ## (assign, ":banner_troop", ":leader_troop_id"),
  38230. ## (try_end),
  38231. ## (else_try), #Check if we are in a tavern
  38232. ## (eq, "$talk_context", tc_tavern_talk),
  38233. ## (neq, ":troop_no", "trp_player"),
  38234. ## (assign, ":banner_troop", -4),
  38235. ## (else_try), #can't find party, this can be a town guard
  38236. ## (neq, ":troop_no", "trp_player"),
  38237. ## (is_between, "$g_encountered_party", walled_centers_begin, walled_centers_end),
  38238. ## (party_get_slot, ":town_lord", "$g_encountered_party", slot_town_lord),
  38239. ## (ge, ":town_lord", 0),
  38240. ## (assign, ":banner_troop", ":town_lord"),
  38241. ## (try_end),
  38242. ## (cur_item_set_tableau_material, ":tableau_no", ":banner_troop"),
  38243. ## ]),
  38244.  
  38245. #script_add_troop_to_cur_tableau
  38246. # INPUT: troop_no
  38247. # OUTPUT: none
  38248. ("add_troop_to_cur_tableau",
  38249. [
  38250. (store_script_param, ":troop_no",1),
  38251.  
  38252. (set_fixed_point_multiplier, 100),
  38253. (assign, ":banner_mesh", -1),
  38254. (troop_get_slot, ":banner_spr", ":troop_no", slot_troop_banner_scene_prop),
  38255. (store_add, ":banner_scene_props_end", banner_scene_props_end_minus_one, 1),
  38256. (try_begin),
  38257. (is_between, ":banner_spr", banner_scene_props_begin, ":banner_scene_props_end"),
  38258. (val_sub, ":banner_spr", banner_scene_props_begin),
  38259. (store_add, ":banner_mesh", ":banner_spr", banner_meshes_begin),
  38260. (try_end),
  38261.  
  38262. (cur_tableau_clear_override_items),
  38263.  
  38264. # (cur_tableau_set_override_flags, af_override_fullhelm),
  38265. (cur_tableau_set_override_flags, af_override_head|af_override_weapons),
  38266.  
  38267. (init_position, pos2),
  38268. (cur_tableau_set_camera_parameters, 1, 6, 6, 10, 10000),
  38269.  
  38270. (init_position, pos5),
  38271. (assign, ":eye_height", 162),
  38272. (store_mul, ":camera_distance", ":troop_no", 87323),
  38273. # (val_mod, ":camera_distance", 5),
  38274. (assign, ":camera_distance", 139),
  38275. (store_mul, ":camera_yaw", ":troop_no", 124337),
  38276. (val_mod, ":camera_yaw", 50),
  38277. (val_add, ":camera_yaw", -25),
  38278. (store_mul, ":camera_pitch", ":troop_no", 98123),
  38279. (val_mod, ":camera_pitch", 20),
  38280. (val_add, ":camera_pitch", -14),
  38281. (assign, ":animation", "anim_stand_man"),
  38282.  
  38283. ## (troop_get_inventory_slot, ":horse_item", ":troop_no", ek_horse),
  38284. ## (try_begin),
  38285. ## (gt, ":horse_item", 0),
  38286. ## (assign, ":eye_height", 210),
  38287. ## (cur_tableau_add_horse, ":horse_item", pos2, anim_horse_stand, 0),
  38288. ## (assign, ":animation", anim_ride_0),
  38289. ## (position_set_z, pos5, 125),
  38290. ## (try_begin),
  38291. ## (is_between, ":camera_yaw", -10, 10), #make sure horse head doesn't obstruct face.
  38292. ## (val_min, ":camera_pitch", -5),
  38293. ## (try_end),
  38294. ## (try_end),
  38295. (position_set_z, pos5, ":eye_height"),
  38296.  
  38297. # camera looks towards -z axis
  38298. (position_rotate_x, pos5, -90),
  38299. (position_rotate_z, pos5, 180),
  38300.  
  38301. # now apply yaw and pitch
  38302. (position_rotate_y, pos5, ":camera_yaw"),
  38303. (position_rotate_x, pos5, ":camera_pitch"),
  38304. (position_move_z, pos5, ":camera_distance", 0),
  38305. (position_move_x, pos5, 5, 0),
  38306.  
  38307. (try_begin),
  38308. (ge, ":banner_mesh", 0),
  38309.  
  38310. (init_position, pos1),
  38311. (position_set_z, pos1, -1500),
  38312. (position_set_x, pos1, 265),
  38313. (position_set_y, pos1, 400),
  38314. (position_transform_position_to_parent, pos3, pos5, pos1),
  38315. (cur_tableau_add_mesh, ":banner_mesh", pos3, 400, 0),
  38316. (try_end),
  38317. (cur_tableau_add_troop, ":troop_no", pos2, ":animation" , 0),
  38318.  
  38319. (cur_tableau_set_camera_position, pos5),
  38320.  
  38321. (copy_position, pos8, pos5),
  38322. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  38323. (position_rotate_z, pos8, 30),
  38324. (position_rotate_x, pos8, -60),
  38325. (cur_tableau_add_sun_light, pos8, 175,150,125),
  38326. ]),
  38327.  
  38328. #script_add_troop_to_cur_tableau_for_character
  38329. # INPUT: troop_no
  38330. # OUTPUT: none
  38331. ("add_troop_to_cur_tableau_for_character",
  38332. [
  38333. (store_script_param, ":troop_no",1),
  38334.  
  38335. (set_fixed_point_multiplier, 100),
  38336.  
  38337. (cur_tableau_clear_override_items),
  38338. (cur_tableau_set_override_flags, af_override_fullhelm),
  38339. ## (cur_tableau_set_override_flags, af_override_head|af_override_weapons),
  38340.  
  38341. (init_position, pos2),
  38342. (cur_tableau_set_camera_parameters, 1, 4, 8, 10, 10000),
  38343.  
  38344. (init_position, pos5),
  38345. (assign, ":cam_height", 150),
  38346. # (val_mod, ":camera_distance", 5),
  38347. (assign, ":camera_distance", 360),
  38348. (assign, ":camera_yaw", -15),
  38349. (assign, ":camera_pitch", -18),
  38350. (assign, ":animation", anim_stand_man),
  38351.  
  38352. (position_set_z, pos5, ":cam_height"),
  38353.  
  38354. # camera looks towards -z axis
  38355. (position_rotate_x, pos5, -90),
  38356. (position_rotate_z, pos5, 180),
  38357.  
  38358. # now apply yaw and pitch
  38359. (position_rotate_y, pos5, ":camera_yaw"),
  38360. (position_rotate_x, pos5, ":camera_pitch"),
  38361. (position_move_z, pos5, ":camera_distance", 0),
  38362. (position_move_x, pos5, 5, 0),
  38363.  
  38364. (try_begin),
  38365. (troop_is_hero, ":troop_no"),
  38366. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", -1),
  38367. (else_try),
  38368. (store_mul, ":random_seed", ":troop_no", 126233),
  38369. (val_mod, ":random_seed", 1000),
  38370. (val_add, ":random_seed", 1),
  38371. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", ":random_seed"),
  38372. (try_end),
  38373. (cur_tableau_set_camera_position, pos5),
  38374.  
  38375. (copy_position, pos8, pos5),
  38376. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  38377. (position_rotate_z, pos8, 30),
  38378. (position_rotate_x, pos8, -60),
  38379. (cur_tableau_add_sun_light, pos8, 175,150,125),
  38380. ]),
  38381.  
  38382. #script_add_troop_to_cur_tableau_for_inventory
  38383. # INPUT: troop_no
  38384. # OUTPUT: none
  38385. ("add_troop_to_cur_tableau_for_inventory",
  38386. [
  38387. (store_script_param, ":troop_no",1),
  38388. (store_mod, ":side", ":troop_no", 4), #side flag is inside troop_no value
  38389. (val_div, ":troop_no", 4), #removing the flag bit
  38390. (val_mul, ":side", 90), #to degrees
  38391.  
  38392. (set_fixed_point_multiplier, 100),
  38393.  
  38394. (cur_tableau_clear_override_items),
  38395. #SB : override appearance while disguised and buying stuff
  38396. (try_begin),
  38397. (gt, "$sneaked_into_town", disguise_none),
  38398. (cur_tableau_set_override_flags, af_override_everything),
  38399. (try_begin),
  38400. (eq, "$sneaked_into_town", disguise_pilgrim),
  38401. (cur_tableau_add_override_item, "itm_pilgrim_hood"),
  38402. (cur_tableau_add_override_item, "itm_pilgrim_disguise"),
  38403. (cur_tableau_add_override_item, "itm_wrapping_boots"),
  38404. (else_try),
  38405. (eq, "$sneaked_into_town", disguise_farmer),
  38406. (cur_tableau_add_override_item, "itm_felt_hat"),
  38407. (cur_tableau_add_override_item, "itm_coarse_tunic"),
  38408. (cur_tableau_add_override_item, "itm_nomad_boots"),
  38409. (else_try),
  38410. (eq, "$sneaked_into_town", disguise_hunter),
  38411. (cur_tableau_add_override_item, "itm_black_hood"),
  38412. (cur_tableau_add_override_item, "itm_leather_gloves"),
  38413. (cur_tableau_add_override_item, "itm_light_leather"),
  38414. (cur_tableau_add_override_item, "itm_light_leather_boots"),
  38415. (else_try),
  38416. (eq, "$sneaked_into_town", disguise_merchant),
  38417. (cur_tableau_add_override_item, "itm_leather_jacket"),
  38418. (cur_tableau_add_override_item, "itm_woolen_hose"),
  38419. (cur_tableau_add_override_item, "itm_felt_steppe_cap"),
  38420. (else_try),
  38421. (eq, "$sneaked_into_town", disguise_guard),
  38422. (cur_tableau_add_override_item, "itm_footman_helmet"),
  38423. (cur_tableau_add_override_item, "itm_mail_mittens"),
  38424. (cur_tableau_add_override_item, "itm_maiL_shirt"),
  38425. (cur_tableau_add_override_item, "itm_mail_chausses"),
  38426. (else_try),
  38427. (eq, "$sneaked_into_town", disguise_bard),
  38428. (cur_tableau_add_override_item, "itm_linen_tunic"),
  38429. (cur_tableau_add_override_item, "itm_leather_boots"),
  38430. (try_end),
  38431. (try_end),
  38432. (init_position, pos2),
  38433. (position_rotate_z, pos2, ":side"),
  38434. (cur_tableau_set_camera_parameters, 1, 4, 6, 10, 10000),
  38435.  
  38436. (init_position, pos5),
  38437. (assign, ":cam_height", 105),
  38438. # (val_mod, ":camera_distance", 5),
  38439. (assign, ":camera_distance", 380),
  38440. (assign, ":camera_yaw", -15),
  38441. (assign, ":camera_pitch", -18),
  38442. (assign, ":animation", anim_stand_man),
  38443.  
  38444. (position_set_z, pos5, ":cam_height"),
  38445.  
  38446. # camera looks towards -z axis
  38447. (position_rotate_x, pos5, -90),
  38448. (position_rotate_z, pos5, 180),
  38449.  
  38450. # now apply yaw and pitch
  38451. (position_rotate_y, pos5, ":camera_yaw"),
  38452. (position_rotate_x, pos5, ":camera_pitch"),
  38453. (position_move_z, pos5, ":camera_distance", 0),
  38454. (position_move_x, pos5, 5, 0),
  38455.  
  38456. (try_begin),
  38457. (troop_is_hero, ":troop_no"),
  38458. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", -1),
  38459. (else_try),
  38460. (store_mul, ":random_seed", ":troop_no", 126233),
  38461. (val_mod, ":random_seed", 1000),
  38462. (val_add, ":random_seed", 1),
  38463. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", ":random_seed"),
  38464. (try_end),
  38465. (cur_tableau_set_camera_position, pos5),
  38466.  
  38467. (copy_position, pos8, pos5),
  38468. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  38469. (position_rotate_z, pos8, 30),
  38470. (position_rotate_x, pos8, -60),
  38471. (cur_tableau_add_sun_light, pos8, 175,150,125),
  38472. ]),
  38473.  
  38474. #script_add_troop_to_cur_tableau_for_profile
  38475. # INPUT: troop_no
  38476. # OUTPUT: none
  38477. ("add_troop_to_cur_tableau_for_profile",
  38478. [
  38479. (store_script_param, ":troop_no",1),
  38480.  
  38481. (set_fixed_point_multiplier, 100),
  38482.  
  38483. (cur_tableau_clear_override_items),
  38484.  
  38485. (cur_tableau_set_camera_parameters, 1, 4, 6, 10, 10000),
  38486.  
  38487. (init_position, pos5),
  38488. (assign, ":cam_height", 105),
  38489. # (val_mod, ":camera_distance", 5),
  38490. (assign, ":camera_distance", 380),
  38491. (assign, ":camera_yaw", -15),
  38492. (assign, ":camera_pitch", -18),
  38493. (assign, ":animation", anim_stand_man),
  38494.  
  38495. (position_set_z, pos5, ":cam_height"),
  38496.  
  38497. # camera looks towards -z axis
  38498. (position_rotate_x, pos5, -90),
  38499. (position_rotate_z, pos5, 180),
  38500.  
  38501. # now apply yaw and pitch
  38502. (position_rotate_y, pos5, ":camera_yaw"),
  38503. (position_rotate_x, pos5, ":camera_pitch"),
  38504. (position_move_z, pos5, ":camera_distance", 0),
  38505. (position_move_x, pos5, 5, 0),
  38506.  
  38507. (profile_get_banner_id, ":profile_banner"),
  38508. (try_begin),
  38509. (ge, ":profile_banner", 0),
  38510. (init_position, pos2),
  38511. (val_add, ":profile_banner", banner_meshes_begin),
  38512. (position_set_x, pos2, -175),
  38513. (position_set_y, pos2, -300),
  38514. (position_set_z, pos2, 180),
  38515. (position_rotate_x, pos2, 90),
  38516. (position_rotate_y, pos2, -15),
  38517. (cur_tableau_add_mesh, ":profile_banner", pos2, 0, 0),
  38518. (try_end),
  38519.  
  38520. (init_position, pos2),
  38521. (try_begin),
  38522. (troop_is_hero, ":troop_no"),
  38523. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", -1),
  38524. (else_try),
  38525. (store_mul, ":random_seed", ":troop_no", 126233),
  38526. (val_mod, ":random_seed", 1000),
  38527. (val_add, ":random_seed", 1),
  38528. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", ":random_seed"),
  38529. (try_end),
  38530. (cur_tableau_set_camera_position, pos5),
  38531.  
  38532. (copy_position, pos8, pos5),
  38533. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  38534. (position_rotate_z, pos8, 30),
  38535. (position_rotate_x, pos8, -60),
  38536. (cur_tableau_add_sun_light, pos8, 175,150,125),
  38537. ]),
  38538.  
  38539. #SB : duplicate of script_add_troop_to_cur_tableau_for_profile for single-player kingdom heroes
  38540. #script_add_troop_to_cur_tableau_for_presentation
  38541. # INPUT: troop_no, kingdom hero or lady
  38542. # OUTPUT: none
  38543. ("add_troop_to_cur_tableau_for_presentation",
  38544. [
  38545. (store_script_param, ":troop_no",1),
  38546.  
  38547. (set_fixed_point_multiplier, 100),
  38548.  
  38549. (cur_tableau_clear_override_items),
  38550.  
  38551. (cur_tableau_set_camera_parameters, 1, 4, 6, 10, 10000),
  38552.  
  38553. (init_position, pos5),
  38554. (assign, ":cam_height", 105),
  38555. # (val_mod, ":camera_distance", 5),
  38556. (assign, ":camera_distance", 380),
  38557. (assign, ":camera_yaw", -15),
  38558. (assign, ":camera_pitch", -18),
  38559. #transient pose seeds
  38560. (troop_get_xp, ":random_seed", ":troop_no"),
  38561. (val_add, ":random_seed", ":troop_no"),
  38562. (val_mod, ":random_seed", 5),
  38563. (store_add, ":animation", "anim_pose_1", ":random_seed"),
  38564.  
  38565. (position_set_z, pos5, ":cam_height"),
  38566.  
  38567. # camera looks towards -z axis
  38568.  
  38569. (position_rotate_x, pos5, -90),
  38570. (position_rotate_z, pos5, 180),
  38571. # now apply yaw and pitch
  38572. (position_rotate_y, pos5, ":camera_yaw"),
  38573. (position_rotate_x, pos5, ":camera_pitch"),
  38574. (position_move_z, pos5, ":camera_distance", 0),
  38575. (position_move_x, pos5, 5, 0),
  38576.  
  38577. #honestly we can just draw this in the presentation
  38578. # (troop_get_slot, ":banner", ":troop_no", slot_troop_banner_scene_prop),
  38579. # (try_begin), #default slot val = 0, exclude placeholders since we don't want to touch their slots
  38580. # (ge, ":banner", 0),
  38581. # (is_between, ":troop_no", heroes_begin, heroes_end),
  38582. # (init_position, pos2),
  38583. # (val_sub, ":banner", banner_scene_props_begin),
  38584. # (val_add, ":banner", banner_meshes_begin),
  38585. # (position_set_x, pos2, -175),
  38586. # (position_set_y, pos2, -300),
  38587. # (position_set_z, pos2, 180),
  38588. # (position_rotate_x, pos2, 90),
  38589. # (position_rotate_y, pos2, -15),
  38590. # (cur_tableau_add_mesh, ":banner", pos2, 0, 0),
  38591. # (try_end),
  38592.  
  38593. (init_position, pos2),
  38594. (try_begin),
  38595. (troop_is_hero, ":troop_no"),
  38596. (try_begin), #rotate character, not flag
  38597. (call_script, "script_cf_dplmc_troop_is_female", ":troop_no"),
  38598. (position_rotate_z, pos2, -45),
  38599. (try_end),
  38600. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", -1),
  38601. (else_try),
  38602. (store_mul, ":random_seed", ":troop_no", 126233),
  38603. (val_mod, ":random_seed", 1000),
  38604. (val_add, ":random_seed", 1),
  38605. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", ":random_seed"),
  38606. (try_end),
  38607. (cur_tableau_set_camera_position, pos5),
  38608.  
  38609. (copy_position, pos8, pos5),
  38610. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  38611. (position_rotate_z, pos8, 30),
  38612. (position_rotate_x, pos8, -60),
  38613. (cur_tableau_add_sun_light, pos8, 175,150,125),
  38614. ]),
  38615.  
  38616.  
  38617. #script_add_troop_to_cur_tableau_for_retirement
  38618. # INPUT: type
  38619. # OUTPUT: none
  38620. ("add_troop_to_cur_tableau_for_retirement", [
  38621. (store_script_param, ":type", 1),
  38622. (try_begin),
  38623. (is_between, ":type", 0, 10),
  38624. (cur_tableau_set_override_flags, af_override_everything),
  38625. (try_end),
  38626.  
  38627. (try_begin),
  38628. (eq, ":type", 0),
  38629. (cur_tableau_add_override_item, "itm_pilgrim_hood"),
  38630. (cur_tableau_add_override_item, "itm_pilgrim_disguise"),
  38631. (cur_tableau_add_override_item, "itm_wrapping_boots"),
  38632. (assign, ":animation", "anim_pose_1"),
  38633. (else_try),
  38634. (eq, ":type", 1),
  38635. (cur_tableau_add_override_item, "itm_pilgrim_hood"),
  38636. (cur_tableau_add_override_item, "itm_red_tunic"),
  38637. (cur_tableau_add_override_item, "itm_wrapping_boots"),
  38638. (cur_tableau_add_override_item, "itm_dagger"),
  38639. (assign, ":animation", "anim_pose_1"),
  38640. (else_try),
  38641. (eq, ":type", 2),
  38642. (cur_tableau_add_override_item, "itm_linen_tunic"),
  38643. (cur_tableau_add_override_item, "itm_wrapping_boots"),
  38644. (assign, ":animation", "anim_pose_2"),
  38645. (else_try),
  38646. (eq, ":type", 3),
  38647. (cur_tableau_add_override_item, "itm_nomad_vest"),
  38648. (cur_tableau_add_override_item, "itm_nomad_boots"),
  38649. (assign, ":animation", "anim_pose_2"),
  38650. (else_try),
  38651. (eq, ":type", 4),
  38652. (cur_tableau_add_override_item, "itm_leather_apron"),
  38653. (cur_tableau_add_override_item, "itm_leather_boots"),
  38654. (assign, ":animation", "anim_pose_3"),
  38655. (else_try),
  38656. (eq, ":type", 5),
  38657. (cur_tableau_add_override_item, "itm_red_shirt"),
  38658. (cur_tableau_add_override_item, "itm_woolen_hose"),
  38659. (cur_tableau_add_override_item, "itm_fur_hat"),
  38660. (assign, ":animation", "anim_pose_3"),
  38661. (else_try),
  38662. (eq, ":type", 6),
  38663. (cur_tableau_add_override_item, "itm_red_gambeson"),
  38664. (cur_tableau_add_override_item, "itm_leather_boots"),
  38665. (cur_tableau_add_override_item, "itm_sword_medieval_c"),
  38666. (assign, ":animation", "anim_pose_4"),
  38667. (else_try),
  38668. (eq, ":type", 7),
  38669. (cur_tableau_add_override_item, "itm_nobleman_outfit"),
  38670. (cur_tableau_add_override_item, "itm_blue_hose"),
  38671. (cur_tableau_add_override_item, "itm_sword_medieval_c"),
  38672. (assign, ":animation", "anim_pose_4"),
  38673. (else_try),
  38674. (eq, ":type", 8),
  38675. (cur_tableau_add_override_item, "itm_courtly_outfit"),
  38676. (cur_tableau_add_override_item, "itm_woolen_hose"),
  38677. (cur_tableau_add_override_item, "itm_sword_medieval_c"),
  38678. (assign, ":animation", "anim_pose_4"),
  38679. (else_try),
  38680. (eq, ":type", 9),
  38681. (cur_tableau_add_override_item, "itm_heraldic_mail_with_surcoat_for_tableau"),
  38682. (cur_tableau_add_override_item, "itm_mail_boots_for_tableau"),
  38683. (cur_tableau_add_override_item, "itm_sword_medieval_c"),
  38684. (assign, ":animation", "anim_pose_5"),
  38685. (try_end),
  38686.  
  38687. ## (set_fixed_point_multiplier, 100),
  38688. ## (cur_tableau_set_background_color, 0x00000000),
  38689. ## (cur_tableau_set_ambient_light, 10,11,15),
  38690.  
  38691. ## (init_position, pos8),
  38692. ## (position_set_x, pos8, -210),
  38693. ## (position_set_y, pos8, 200),
  38694. ## (position_set_z, pos8, 300),
  38695. ## (cur_tableau_add_point_light, pos8, 550,500,450),
  38696.  
  38697.  
  38698. (set_fixed_point_multiplier, 100),
  38699. (cur_tableau_set_camera_parameters, 1, 6, 6, 10, 10000),
  38700. (assign, ":cam_height", 155),
  38701. (assign, ":camera_distance", 575),
  38702. (assign, ":camera_yaw", -5),
  38703. (assign, ":camera_pitch", 10),
  38704.  
  38705. (init_position, pos5),
  38706. (position_set_z, pos5, ":cam_height"),
  38707. # camera looks towards -z axis
  38708. (position_rotate_x, pos5, -90),
  38709. (position_rotate_z, pos5, 180),
  38710. # now apply yaw and pitch
  38711. (position_rotate_y, pos5, ":camera_yaw"),
  38712. (position_rotate_x, pos5, ":camera_pitch"),
  38713. (position_move_z, pos5, ":camera_distance", 0),
  38714. (position_move_x, pos5, 60, 0),
  38715.  
  38716. (init_position, pos2),
  38717. (cur_tableau_add_troop, "trp_player", pos2, ":animation", 0),
  38718. (cur_tableau_set_camera_position, pos5),
  38719.  
  38720. (copy_position, pos8, pos5),
  38721. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  38722. (position_rotate_z, pos8, 30),
  38723. (position_rotate_x, pos8, -60),
  38724. (cur_tableau_add_sun_light, pos8, 175,150,125),
  38725. ]),
  38726.  
  38727. #script_add_troop_to_cur_tableau_for_party
  38728. # INPUT: troop_no
  38729. # OUTPUT: none
  38730. ("add_troop_to_cur_tableau_for_party",
  38731. [
  38732. (store_script_param, ":troop_no",1),
  38733. (store_mod, ":hide_weapons", ":troop_no", 2), #hide_weapons flag is inside troop_no value
  38734. (val_div, ":troop_no", 2), #removing the flag bit
  38735.  
  38736. (set_fixed_point_multiplier, 100),
  38737.  
  38738. (cur_tableau_clear_override_items),
  38739. (try_begin),
  38740. (eq, ":hide_weapons", 1),
  38741. (cur_tableau_set_override_flags, af_override_fullhelm|af_override_head|af_override_weapons),
  38742. (try_end),
  38743.  
  38744. (init_position, pos2),
  38745. (cur_tableau_set_camera_parameters, 1, 6, 6, 10, 10000),
  38746.  
  38747. (init_position, pos5),
  38748. (assign, ":cam_height", 105),
  38749. # (val_mod, ":camera_distance", 5),
  38750. (assign, ":camera_distance", 450),
  38751. (assign, ":camera_yaw", 15),
  38752. (assign, ":camera_pitch", -18),
  38753. (assign, ":animation", anim_stand_man),
  38754.  
  38755. (troop_get_inventory_slot, ":horse_item", ":troop_no", ek_horse),
  38756. (try_begin),
  38757. (gt, ":horse_item", 0),
  38758. (eq, ":hide_weapons", 0),
  38759. (cur_tableau_add_horse, ":horse_item", pos2, "anim_horse_stand", 0),
  38760. (assign, ":animation", "anim_ride_0"),
  38761. (assign, ":camera_yaw", 23),
  38762. (assign, ":cam_height", 150),
  38763. (assign, ":camera_distance", 550),
  38764. (try_end),
  38765. (position_set_z, pos5, ":cam_height"),
  38766.  
  38767. # camera looks towards -z axis
  38768. (position_rotate_x, pos5, -90),
  38769. (position_rotate_z, pos5, 180),
  38770.  
  38771. # now apply yaw and pitch
  38772. (position_rotate_y, pos5, ":camera_yaw"),
  38773. (position_rotate_x, pos5, ":camera_pitch"),
  38774. (position_move_z, pos5, ":camera_distance", 0),
  38775. (position_move_x, pos5, 5, 0),
  38776.  
  38777. (try_begin),
  38778. (troop_is_hero, ":troop_no"),
  38779. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", -1),
  38780. (else_try),
  38781. (store_mul, ":random_seed", ":troop_no", 126233),
  38782. (val_mod, ":random_seed", 1000),
  38783. (val_add, ":random_seed", 1),
  38784. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", ":random_seed"),
  38785. (try_end),
  38786. (cur_tableau_set_camera_position, pos5),
  38787.  
  38788. (copy_position, pos8, pos5),
  38789. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  38790. (position_rotate_z, pos8, 30),
  38791. (position_rotate_x, pos8, -60),
  38792. (cur_tableau_add_sun_light, pos8, 175,150,125),
  38793. ]),
  38794.  
  38795. #script_get_prosperity_text_to_s50
  38796. # INPUT: center_no
  38797. # OUTPUT: none
  38798. ("get_prosperity_text_to_s50",
  38799. [(store_script_param, ":center_no", 1),
  38800. (party_get_slot, ":prosperity", ":center_no", slot_town_prosperity),
  38801. (val_div, ":prosperity", 20),
  38802. (try_begin),
  38803. (eq, ":prosperity", 0), #0..19
  38804. (str_store_string, s50, "@Very Poor"),
  38805. (else_try),
  38806. (eq, ":prosperity", 1), #20..39
  38807. (str_store_string, s50, "@Poor"),
  38808. (else_try),
  38809. (eq, ":prosperity", 2), #40..59
  38810. (str_store_string, s50, "@Average"),
  38811. (else_try),
  38812. (eq, ":prosperity", 3), #60..79
  38813. (str_store_string, s50, "@Rich"),
  38814. (else_try),
  38815. (str_store_string, s50, "@Very Rich"), #80..99
  38816. (try_end),
  38817. ]),
  38818.  
  38819. #script_spawn_bandits
  38820. # INPUT: none
  38821. # OUTPUT: none
  38822. ("spawn_bandits",
  38823. [
  38824. (set_spawn_radius,1),
  38825.  
  38826. (try_begin),
  38827. (eq, "$cheat_mode", 1),
  38828. (display_message, "@{!}DEBUG : Doing spawn bandit script"),
  38829. (try_end),
  38830.  
  38831. (party_template_set_slot, "pt_steppe_bandits", slot_party_template_lair_type, "pt_steppe_bandit_lair"),
  38832. (party_template_set_slot, "pt_taiga_bandits", slot_party_template_lair_type, "pt_taiga_bandit_lair"),
  38833. (party_template_set_slot, "pt_mountain_bandits", slot_party_template_lair_type, "pt_mountain_bandit_lair"),
  38834. (party_template_set_slot, "pt_forest_bandits", slot_party_template_lair_type, "pt_forest_bandit_lair"),
  38835. (party_template_set_slot, "pt_sea_raiders", slot_party_template_lair_type, "pt_sea_raider_lair"),
  38836. (party_template_set_slot, "pt_desert_bandits", slot_party_template_lair_type, "pt_desert_bandit_lair"),
  38837.  
  38838. (party_template_set_slot, "pt_steppe_bandits", slot_party_template_lair_spawnpoint, "p_steppe_bandit_spawn_point"),
  38839. (party_template_set_slot, "pt_taiga_bandits", slot_party_template_lair_spawnpoint, "p_taiga_bandit_spawn_point"),
  38840. (party_template_set_slot, "pt_mountain_bandits", slot_party_template_lair_spawnpoint, "p_mountain_bandit_spawn_point"),
  38841. (party_template_set_slot, "pt_forest_bandits", slot_party_template_lair_spawnpoint, "p_forest_bandit_spawn_point"),
  38842. (party_template_set_slot, "pt_sea_raiders", slot_party_template_lair_spawnpoint, "p_sea_raider_spawn_point_1"),
  38843. (party_template_set_slot, "pt_desert_bandits", slot_party_template_lair_spawnpoint, "p_desert_bandit_spawn_point"),
  38844.  
  38845. (try_begin),
  38846. (store_num_parties_of_template, ":num_parties", "pt_mountain_bandits"),
  38847. (lt,":num_parties",16), #was 14 at mount&blade, 18 in warband, 16 last decision
  38848. (store_random,":spawn_point",num_mountain_bandit_spawn_points),
  38849. (val_add,":spawn_point","p_mountain_bandit_spawn_point"),
  38850. (set_spawn_radius, 25),
  38851. (spawn_around_party,":spawn_point","pt_mountain_bandits"),
  38852. (try_end),
  38853. (try_begin),
  38854. (store_num_parties_of_template, ":num_parties", "pt_forest_bandits"),
  38855. (lt,":num_parties",16), #was 14 at mount&blade, 18 in warband, 16 last decision
  38856. (store_random,":spawn_point",num_forest_bandit_spawn_points),
  38857. (val_add,":spawn_point","p_forest_bandit_spawn_point"),
  38858. (set_spawn_radius, 25),
  38859. (spawn_around_party,":spawn_point","pt_forest_bandits"),
  38860. (try_end),
  38861. (try_begin),
  38862. (store_num_parties_of_template, ":num_parties", "pt_sea_raiders"),
  38863. (lt,":num_parties",16), #was 14 at mount&blade, 18 in warband, 16 last decision
  38864. (store_random,":spawn_point",num_sea_raider_spawn_points),
  38865. (val_add,":spawn_point","p_sea_raider_spawn_point_1"),
  38866. (set_spawn_radius, 25),
  38867. (spawn_around_party,":spawn_point","pt_sea_raiders"),
  38868. (try_end),
  38869. (try_begin),
  38870. (store_num_parties_of_template, ":num_parties", "pt_steppe_bandits"),
  38871. (lt,":num_parties",16), #was 14 at mount&blade, 18 in warband, 16 last decision
  38872. (store_random,":spawn_point",num_steppe_bandit_spawn_points),
  38873. (val_add,":spawn_point","p_steppe_bandit_spawn_point"),
  38874. (set_spawn_radius, 25),
  38875. (spawn_around_party,":spawn_point","pt_steppe_bandits"),
  38876. (try_end),
  38877. (try_begin),
  38878. (store_num_parties_of_template, ":num_parties", "pt_taiga_bandits"),
  38879. (lt,":num_parties",16), #was 14 at mount&blade, 18 in warband, 16 last decision
  38880. (store_random,":spawn_point",num_taiga_bandit_spawn_points),
  38881. (val_add,":spawn_point","p_taiga_bandit_spawn_point"),
  38882. (set_spawn_radius, 25),
  38883. (spawn_around_party,":spawn_point","pt_taiga_bandits"),
  38884. (try_end),
  38885. (try_begin),
  38886. (store_num_parties_of_template, ":num_parties", "pt_desert_bandits"),
  38887. (lt,":num_parties",16), #was 14 at mount&blade, 18 in warband, 16 last decision
  38888. (store_random,":spawn_point",num_desert_bandit_spawn_points),
  38889. (val_add,":spawn_point","p_desert_bandit_spawn_point"),
  38890. (set_spawn_radius, 25),
  38891. (spawn_around_party,":spawn_point","pt_desert_bandits"),
  38892. (try_end),
  38893. (try_begin),
  38894. (store_num_parties_of_template, ":num_parties", "pt_looters"),
  38895. (lt,":num_parties",42), #was 33 at mount&blade, 50 in warband, 42 last decision
  38896. (store_random_in_range,":spawn_point",villages_begin,villages_end), #spawn looters twice to have lots of them at the beginning
  38897. (set_spawn_radius, 25),
  38898. (spawn_around_party,":spawn_point","pt_looters"),
  38899. (assign, ":spawned_party_id", reg0),
  38900. (try_begin),
  38901. (check_quest_active, "qst_deal_with_looters"),
  38902. (party_set_flags, ":spawned_party_id", pf_quest_party, 1),
  38903. (else_try),
  38904. (party_set_flags, ":spawned_party_id", pf_quest_party, 0),
  38905. (try_end),
  38906. (try_end),
  38907. (try_begin),
  38908. (store_num_parties_of_template, ":num_parties", "pt_deserters"),
  38909. (lt,":num_parties",15),
  38910. (set_spawn_radius, 4),
  38911. (try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
  38912. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  38913. (store_random_in_range, ":random_no", 0, 100),
  38914. (lt, ":random_no", 5),
  38915. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  38916. (store_troop_faction, ":troop_faction", ":troop_no"),
  38917. (neq, ":troop_faction", "fac_player_supporters_faction"),
  38918. (gt, ":party_no", 0),
  38919. (neg|party_is_in_any_town, ":party_no"),
  38920. ## (party_get_attached_to, ":attached_party_no", ":party_no"),
  38921. ## (lt, ":attached_party_no", 0),#in wilderness
  38922. (spawn_around_party, ":party_no", "pt_deserters"),
  38923. (assign, ":new_party", reg0),
  38924. (store_troop_faction, ":faction_no", ":troop_no"),
  38925. (faction_get_slot, ":tier_1_troop", ":faction_no", slot_faction_tier_1_troop),
  38926. (store_character_level, ":level", "trp_player"),
  38927. (store_mul, ":max_number_to_add", ":level", 2),
  38928. (val_add, ":max_number_to_add", 11),
  38929. (store_random_in_range, ":number_to_add", 10, ":max_number_to_add"),
  38930. (party_add_members, ":new_party", ":tier_1_troop", ":number_to_add"),
  38931. (store_random_in_range, ":random_no", 1, 4),
  38932. (try_for_range, ":unused", 0, ":random_no"),
  38933. (party_upgrade_with_xp, ":new_party", 1000000, 0),
  38934. (try_end),
  38935. ## (str_store_party_name, s1, ":party_no"),
  38936. ## (call_script, "script_get_closest_center", ":party_no"),
  38937. ## (try_begin),
  38938. ## (gt, reg0, 0),
  38939. ## (str_store_party_name, s2, reg0),
  38940. ## (else_try),
  38941. ## (str_store_string, s2, "@unknown place"),
  38942. ## (try_end),
  38943. ## (assign, reg1, ":number_to_add"),
  38944. ## (display_message, "@{reg1} Deserters spawned from {s1}, near {s2}."),
  38945. (try_end),
  38946. (try_end), #deserters ends
  38947.  
  38948.  
  38949. #Spawn bandit lairs
  38950. (try_for_range, ":bandit_template", bandit_party_templates_begin, bandit_party_templates_end), #SB : template range
  38951. (party_template_get_slot, ":bandit_lair_party", ":bandit_template", slot_party_template_lair_party),
  38952. (le, ":bandit_lair_party", 1),
  38953.  
  38954. (party_template_get_slot, ":bandit_lair_template", ":bandit_template", slot_party_template_lair_type),
  38955. (party_template_get_slot, ":bandit_lair_template_spawnpoint", ":bandit_template", slot_party_template_lair_spawnpoint),
  38956.  
  38957. (set_spawn_radius, 20),
  38958.  
  38959. (spawn_around_party, ":bandit_lair_template_spawnpoint", ":bandit_lair_template"),
  38960. (assign, ":new_camp", reg0),
  38961.  
  38962. (party_set_slot, ":new_camp", slot_party_type, spt_bandit_lair),
  38963.  
  38964. (str_store_party_name, s4, ":new_camp"),
  38965.  
  38966. (party_get_position, pos4, ":new_camp"),
  38967. #(party_set_flags, ":new_camp", pf_icon_mask, 1),
  38968.  
  38969. (party_get_current_terrain, ":new_camp_terrain", ":new_camp"),
  38970. (position_get_z, ":elevation", pos4),
  38971. (position_get_y, ":lair_y", pos4),
  38972.  
  38973. (assign, ":center_too_close", 0),
  38974. (try_for_range, ":center", centers_begin, centers_end),
  38975. (eq, ":center_too_close", 0),
  38976. (store_distance_to_party_from_party, ":distance", ":new_camp", ":center"),
  38977. (lt, ":distance", 3),
  38978. (assign, ":center_too_close", 1),
  38979. (try_end),
  38980.  
  38981. (try_begin),
  38982. (eq, ":center_too_close", 1),
  38983. (party_is_active, ":new_camp"),
  38984. (remove_party, ":new_camp"),
  38985. (party_template_set_slot, ":bandit_template", slot_party_template_lair_party, 0),
  38986. (else_try),
  38987. (eq, ":bandit_template", "pt_sea_raiders"),
  38988. (eq, ":new_camp_terrain", 3),
  38989. (map_get_water_position_around_position, pos5, pos4, 4),
  38990. (party_template_set_slot, ":bandit_template", slot_party_template_lair_party, ":new_camp"),
  38991. (party_set_flags, ":new_camp", pf_disabled, 1),
  38992. (else_try),
  38993. (eq, ":bandit_template", "pt_mountain_bandits"),
  38994. (eq, ":new_camp_terrain", 3),
  38995. (gt, ":elevation", 250),
  38996. (party_template_set_slot, ":bandit_template", slot_party_template_lair_party, ":new_camp"),
  38997. (party_set_flags, ":new_camp", pf_disabled, 1),
  38998. (else_try),
  38999. (eq, ":bandit_template", "pt_desert_bandits"),
  39000. (eq, ":new_camp_terrain", 5),
  39001. (gt, ":lair_y", -9000),
  39002. (gt, ":elevation", 125),
  39003. (party_template_set_slot, ":bandit_template", slot_party_template_lair_party, ":new_camp"),
  39004. (party_set_flags, ":new_camp", pf_disabled, 1),
  39005. (else_try),
  39006. (eq, ":bandit_template", "pt_steppe_bandits"),
  39007. (this_or_next|eq, ":new_camp_terrain", 2),
  39008. (eq, ":new_camp_terrain", 10),
  39009. (this_or_next|eq, ":new_camp_terrain", 10),
  39010. (gt, ":elevation", 200),
  39011. (party_template_set_slot, ":bandit_template", slot_party_template_lair_party, ":new_camp"),
  39012. (party_set_flags, ":new_camp", pf_disabled, 1),
  39013. (else_try),
  39014. (eq, ":bandit_template", "pt_taiga_bandits"),
  39015. (eq, ":new_camp_terrain", 12),
  39016. (party_template_set_slot, ":bandit_template", slot_party_template_lair_party, ":new_camp"),
  39017. (party_set_flags, ":new_camp", pf_disabled, 1),
  39018. (else_try),
  39019. (eq, ":bandit_template", "pt_forest_bandits"),
  39020. (eq, ":new_camp_terrain", 11),
  39021. (party_template_set_slot, ":bandit_template", slot_party_template_lair_party, ":new_camp"),
  39022. (party_set_flags, ":new_camp", pf_disabled, 1),
  39023. (else_try),
  39024. (party_is_active, ":new_camp"),
  39025. (str_store_party_name, s4, ":new_camp"),
  39026. (remove_party, ":new_camp"),
  39027. (party_template_set_slot, ":bandit_template", slot_party_template_lair_party, 0),
  39028. (else_try),
  39029. (try_end),
  39030. (try_end),
  39031. ]),
  39032.  
  39033. #script_count_mission_casualties_from_agents
  39034. # INPUT: none
  39035. # OUTPUT: none
  39036. ("count_mission_casualties_from_agents",
  39037. [(party_clear, "p_player_casualties"),
  39038. (party_clear, "p_enemy_casualties"),
  39039. (party_clear, "p_ally_casualties"),
  39040. (assign, "$any_allies_at_the_last_battle", 0),
  39041. #(assign, "$num_routed_us", 0), #these should not assign to 0 here to protect routed agents to spawn again in next turns.
  39042. #(assign, "$num_routed_allies", 0),
  39043. #(assign, "$num_routed_enemies", 0),
  39044.  
  39045. #initialize all routed counts of troops
  39046. (try_for_agents, ":cur_agent"),
  39047. (agent_is_human, ":cur_agent"),
  39048. (agent_get_party_id, ":agent_party", ":cur_agent"),
  39049. (agent_get_troop_id, ":agent_troop_id", ":cur_agent"),
  39050. (troop_set_slot, ":agent_troop_id", slot_troop_player_routed_agents, 0),
  39051. (troop_set_slot, ":agent_troop_id", slot_troop_ally_routed_agents, 0),
  39052. (troop_set_slot, ":agent_troop_id", slot_troop_enemy_routed_agents, 0),
  39053. (try_end),
  39054.  
  39055. (try_for_agents, ":cur_agent"),
  39056. (agent_is_human, ":cur_agent"),
  39057. (agent_get_party_id, ":agent_party", ":cur_agent"),
  39058. (try_begin),
  39059. (neq, ":agent_party", "p_main_party"),
  39060. (agent_is_ally, ":cur_agent"),
  39061. (assign, "$any_allies_at_the_last_battle", 1),
  39062. (try_end),
  39063. #count routed agents in player party, ally parties and enemy parties
  39064. (try_begin),
  39065. (agent_is_routed, ":cur_agent"),
  39066. (agent_get_slot, ":agent_was_running_away", ":cur_agent", slot_agent_is_running_away),
  39067. (eq, ":agent_was_running_away", 1),
  39068. (try_begin),
  39069. (agent_get_troop_id, ":routed_ag_troop_id", ":cur_agent"),
  39070. (agent_get_party_id, ":routed_ag_party_id", ":cur_agent"),
  39071. #only enemies
  39072. #only regulars
  39073. (store_faction_of_party, ":faction_of_routed_agent_party", ":routed_ag_party_id"),
  39074.  
  39075. (try_begin),
  39076. (eq, ":agent_party", "p_main_party"),
  39077. (val_add, "$num_routed_us", 1),
  39078. (else_try),
  39079. (agent_is_ally, ":cur_agent"),
  39080. (val_add, "$num_routed_allies", 1),
  39081. (else_try),
  39082. #for now only count and include routed enemy agents in new routed party.
  39083. (val_add, "$num_routed_enemies", 1),
  39084. (faction_get_slot, ":num_routed_agents_in_this_faction", ":faction_of_routed_agent_party", slot_faction_num_routed_agents),
  39085. (val_add, ":num_routed_agents_in_this_faction", 1),
  39086. (faction_set_slot, ":faction_of_routed_agent_party", slot_faction_num_routed_agents, ":num_routed_agents_in_this_faction"),
  39087. (party_add_members, "p_routed_enemies", ":routed_ag_troop_id", 1),
  39088. (try_end),
  39089. (try_end),
  39090. (agent_get_troop_id, ":agent_troop_id", ":cur_agent"),
  39091. (try_begin),
  39092. (eq, ":agent_party", "p_main_party"),
  39093. (troop_get_slot, ":player_routed_agents", ":agent_troop_id", slot_troop_player_routed_agents),
  39094. (val_add, ":player_routed_agents", 1),
  39095. (troop_set_slot, ":agent_troop_id", slot_troop_player_routed_agents, ":player_routed_agents"),
  39096.  
  39097. (else_try),
  39098. (agent_is_ally, ":cur_agent"),
  39099. (troop_get_slot, ":ally_routed_agents", ":agent_troop_id", slot_troop_ally_routed_agents),
  39100. (val_add, ":ally_routed_agents", 1),
  39101. (troop_set_slot, ":agent_troop_id", slot_troop_ally_routed_agents, ":ally_routed_agents"),
  39102.  
  39103. (else_try),
  39104. (troop_get_slot, ":enemy_routed_agents", ":agent_troop_id", slot_troop_enemy_routed_agents),
  39105. (val_add, ":enemy_routed_agents", 1),
  39106. (troop_set_slot, ":agent_troop_id", slot_troop_enemy_routed_agents, ":enemy_routed_agents"),
  39107.  
  39108. (try_end),
  39109. (try_end),
  39110. #count and save killed agents in player party, ally parties and enemy parties
  39111. (neg|agent_is_alive, ":cur_agent"),
  39112. (agent_get_troop_id, ":agent_troop_id", ":cur_agent"),
  39113. (try_begin),
  39114. (eq, ":agent_party", "p_main_party"),
  39115. (party_add_members, "p_player_casualties", ":agent_troop_id", 1),
  39116. (try_begin),
  39117. (agent_is_wounded, ":cur_agent"),
  39118. (party_wound_members, "p_player_casualties", ":agent_troop_id", 1),
  39119. (try_end),
  39120. (else_try),
  39121. (agent_is_ally, ":cur_agent"),
  39122. (party_add_members, "p_ally_casualties", ":agent_troop_id", 1),
  39123. (try_begin),
  39124. (agent_is_wounded, ":cur_agent"),
  39125. (party_wound_members, "p_ally_casualties", ":agent_troop_id", 1),
  39126. (try_end),
  39127. (else_try),
  39128. (party_add_members, "p_enemy_casualties", ":agent_troop_id", 1),
  39129. (try_begin),
  39130. (agent_is_wounded, ":cur_agent"),
  39131. (party_wound_members, "p_enemy_casualties", ":agent_troop_id", 1),
  39132. (try_end),
  39133. (try_end),
  39134. (try_end),
  39135. ]),
  39136.  
  39137. #script_get_max_skill_of_player_party
  39138. # INPUT: arg1 = skill_no
  39139. # OUTPUT: reg0 = max_skill, reg1 = skill_owner_troop_no
  39140. ("get_max_skill_of_player_party",
  39141. [(store_script_param, ":skill_no", 1),
  39142. (party_get_num_companion_stacks, ":num_stacks","p_main_party"),
  39143. (store_skill_level, ":max_skill", ":skill_no", "trp_player"),
  39144. (assign, ":skill_owner", "trp_player"),
  39145. (try_for_range, ":i_stack", 0, ":num_stacks"),
  39146. (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
  39147. (troop_is_hero, ":stack_troop"),
  39148. (neg|troop_is_wounded, ":stack_troop"),
  39149. (store_skill_level, ":cur_skill", ":skill_no", ":stack_troop"),
  39150. (gt, ":cur_skill", ":max_skill"),
  39151. (assign, ":max_skill", ":cur_skill"),
  39152. (assign, ":skill_owner", ":stack_troop"),
  39153. (try_end),
  39154. (party_get_skill_level, reg0, "p_main_party", ":skill_no"),
  39155. ## (assign, reg0, ":max_skill"),
  39156. (assign, reg1, ":skill_owner"),
  39157. ]),
  39158.  
  39159. #script_upgrade_hero_party
  39160. # INPUT: arg1 = party_id, arg2 = xp_amount
  39161. ("upgrade_hero_party",
  39162. [
  39163. (store_script_param, ":party_no", 1),
  39164. (store_script_param, ":xp_amount", 2),
  39165. ##diplomacy start+
  39166. #Take into account faction quality/quantity settings. Do not apply this
  39167. #to the player party or to special parties.
  39168. (try_begin),
  39169. (ge, ":party_no", spawn_points_begin),
  39170. (store_faction_of_party, ":var1", ":party_no"),
  39171. (faction_get_slot, ":var1", ":var1", dplmc_slot_faction_quality),
  39172. (val_add, ":var1", 100),
  39173. (val_clamp, ":var1", 97, 104),#100 plus or minus three percent
  39174. (val_mul, ":xp_amount", ":var1"),
  39175. (val_div, ":xp_amount", 100),
  39176. (try_end),
  39177. ##diplomacy end+
  39178. (party_upgrade_with_xp, ":party_no", ":xp_amount", 0),
  39179. ]),
  39180.  
  39181. #script_get_improvement_details
  39182. # INPUT: arg1 = improvement
  39183. # OUTPUT: reg0 = base_cost
  39184. ("get_improvement_details",
  39185. [(store_script_param, ":improvement_no", 1),
  39186. (try_begin),
  39187. (eq, ":improvement_no", slot_center_has_manor),
  39188. (str_store_string, s0, "@Manor"),
  39189. (str_store_string, s1, "@A manor lets you rest at the village and pay your troops half wages while you rest."),
  39190. (assign, reg0, 8000),
  39191. (else_try),
  39192. (eq, ":improvement_no", slot_center_has_fish_pond),
  39193. (str_store_string, s0, "@Mill"),
  39194. (str_store_string, s1, "@A mill increases village prosperity by 5%."),
  39195. (assign, reg0, 6000),
  39196. (else_try),
  39197. (eq, ":improvement_no", slot_center_has_watch_tower),
  39198. (str_store_string, s0, "@Watch Tower"),
  39199. (str_store_string, s1, "@A watch tower lets the villagers raise alarm earlier. The time it takes for enemies to loot the village increases by 50%."),
  39200. (assign, reg0, 5000),
  39201. (else_try),
  39202. (eq, ":improvement_no", slot_center_has_school),
  39203. (str_store_string, s0, "@School"),
  39204. (str_store_string, s1, "@A shool increases the loyality of the villagers to you by +1 every month."),
  39205. (assign, reg0, 9000),
  39206. (else_try),
  39207. (eq, ":improvement_no", slot_center_has_messenger_post),
  39208. (str_store_string, s0, "@Messenger Post"),
  39209. (str_store_string, s1, "@A messenger post lets the inhabitants send you a message whenever enemies are nearby, even if you are far away from here."),
  39210. (assign, reg0, 4000),
  39211. (else_try),
  39212. (eq, ":improvement_no", slot_center_has_prisoner_tower),
  39213. (str_store_string, s0, "@Prison Tower"),
  39214. (str_store_string, s1, "@A prison tower reduces the chance of captives held here running away successfully."),
  39215. (assign, reg0, 7000),
  39216. (try_end),
  39217. ]),
  39218.  
  39219. #script_cf_troop_agent_is_alive
  39220. # INPUT: arg1 = troop_id
  39221. ("cf_troop_agent_is_alive",
  39222. [(store_script_param, ":troop_no", 1),
  39223. (assign, ":alive_count", 0),
  39224. (try_for_agents, ":cur_agent"),
  39225. (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
  39226. (eq, ":troop_no", ":cur_agent_troop"),
  39227. (agent_is_alive, ":cur_agent"),
  39228. (val_add, ":alive_count", 1),
  39229. (try_end),
  39230. (gt, ":alive_count", 0),
  39231. ]),
  39232.  
  39233. ("cf_village_recruit_volunteers_cond",
  39234. [
  39235.  
  39236. (try_begin),
  39237. (eq, "$cheat_mode", 1),
  39238. (display_message, "str_checking_volunteer_availability_script"),
  39239. (try_end),
  39240.  
  39241. # (neg|party_slot_eq, "$current_town", slot_village_state, svs_looted),
  39242. # (neg|party_slot_eq, "$current_town", slot_village_state, svs_deserted),
  39243. # (neg|party_slot_eq, "$current_town", slot_village_state, svs_being_raided),
  39244. # (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
  39245. (call_script, "script_cf_village_normal_cond", "$current_town"),
  39246. (store_faction_of_party, ":village_faction", "$current_town"),
  39247. (party_get_slot, ":center_relation", "$current_town", slot_center_player_relation),
  39248. (store_relation, ":village_faction_relation", ":village_faction", "fac_player_faction"),
  39249.  
  39250. (ge, ":center_relation", 0),
  39251. (try_begin),
  39252. (eq, "$cheat_mode", 1),
  39253. (display_message, "str_center_relation_at_least_zero"),
  39254. (try_end),
  39255.  
  39256.  
  39257.  
  39258.  
  39259. (this_or_next|ge, ":center_relation", 5),
  39260. (this_or_next|eq, ":village_faction", "$players_kingdom"),
  39261. (this_or_next|ge, ":village_faction_relation", 0),
  39262. (this_or_next|eq, ":village_faction", "$supported_pretender_old_faction"),
  39263. (eq, "$players_kingdom", 0),
  39264.  
  39265. (try_begin),
  39266. (eq, "$cheat_mode", 1),
  39267. (display_message, "str_relationfaction_conditions_met"),
  39268. (try_end),
  39269.  
  39270.  
  39271. (party_slot_ge, "$current_town", slot_center_volunteer_troop_amount, 1), #SB : ge 1, not 0
  39272. (party_slot_ge, "$current_town", slot_center_volunteer_troop_type, 1),
  39273.  
  39274. (try_begin),
  39275. (eq, "$cheat_mode", 1),
  39276. (display_message, "str_troops_available"),
  39277. (try_end),
  39278.  
  39279.  
  39280. (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
  39281. (ge, ":free_capacity", 1),
  39282.  
  39283. (try_begin),
  39284. (eq, "$cheat_mode", 1),
  39285. (display_message, "str_party_has_capacity"),
  39286. (try_end),
  39287.  
  39288.  
  39289. ]),
  39290.  
  39291. #script_village_recruit_volunteers_recruit
  39292. # INPUT: none
  39293. # OUTPUT: none
  39294. ("village_recruit_volunteers_recruit",
  39295. [(party_get_slot, ":volunteer_troop", "$current_town", slot_center_volunteer_troop_type),
  39296. (party_get_slot, ":volunteer_amount", "$current_town", slot_center_volunteer_troop_amount),
  39297. (party_get_free_companions_capacity, ":free_capacity", "p_main_party"),
  39298. (val_min, ":volunteer_amount", ":free_capacity"),
  39299. (store_troop_gold, ":gold", "trp_player"),
  39300. (store_div, ":gold_capacity", ":gold", 10),#10 denars per man
  39301. (val_min, ":volunteer_amount", ":gold_capacity"),
  39302. (party_add_members, "p_main_party", ":volunteer_troop", ":volunteer_amount"),
  39303. (party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
  39304. (store_mul, ":cost", ":volunteer_amount", 10),#10 denars per man
  39305. (troop_remove_gold, "trp_player", ":cost"),
  39306. ]),
  39307.  
  39308. #script_get_troop_item_amount
  39309. # INPUT: arg1 = troop_no, arg2 = item_no
  39310. # OUTPUT: reg0 = item_amount
  39311. ("get_troop_item_amount",
  39312. [(store_script_param, ":troop_no", 1),
  39313. (store_script_param, ":item_no", 2),
  39314. (troop_get_inventory_capacity, ":inv_cap", ":troop_no"),
  39315. (assign, ":count", 0),
  39316. (try_for_range, ":i_slot", 0, ":inv_cap"),
  39317. (troop_get_inventory_slot, ":cur_item", ":troop_no", ":i_slot"),
  39318. (eq, ":cur_item", ":item_no"),
  39319. (val_add, ":count", 1),
  39320. (try_end),
  39321. (assign, reg0, ":count"),
  39322. ]),
  39323.  
  39324. #script_get_name_from_dna_to_s50
  39325. # INPUT: arg1 = dna
  39326. # OUTPUT: s50 = name
  39327. ("get_name_from_dna_to_s50",
  39328. [(store_script_param, ":dna", 1),
  39329. (store_sub, ":num_names", names_end, names_begin),
  39330. (store_sub, ":num_surnames", surnames_end, surnames_begin),
  39331. (assign, ":selected_name", ":dna"),
  39332. (val_mod, ":selected_name", ":num_names"),
  39333. (assign, ":selected_surname", ":dna"),
  39334. (val_div, ":selected_surname", ":num_names"),
  39335. (val_mod, ":selected_surname", ":num_surnames"),
  39336. (val_add, ":selected_name", names_begin),
  39337. (val_add, ":selected_surname", surnames_begin),
  39338. (str_store_string, s50, ":selected_name"),
  39339. (str_store_string, s50, ":selected_surname"),
  39340. ]),
  39341.  
  39342. #script_change_center_prosperity
  39343. # INPUT: arg1 = center_no, arg2 = difference
  39344. # OUTPUT: none
  39345. ("change_center_prosperity",
  39346. [(store_script_param, ":center_no", 1),
  39347. (store_script_param, ":difference", 2),
  39348. (party_get_slot, ":old_prosperity", ":center_no", slot_town_prosperity),
  39349. (store_add, ":new_prosperity", ":old_prosperity", ":difference"),
  39350. (val_clamp, ":new_prosperity", 0, 100),
  39351. (store_div, ":old_state", ":old_prosperity", 20),
  39352. (store_div, ":new_state", ":new_prosperity", 20),
  39353.  
  39354. (try_begin),
  39355. (neq, ":old_state", ":new_state"),
  39356. (neg|is_between, ":center_no", castles_begin, castles_end),
  39357.  
  39358. (str_store_party_name_link, s2, ":center_no"),
  39359. (call_script, "script_get_prosperity_text_to_s50", ":center_no"),
  39360. (str_store_string, s3, s50),
  39361. (party_set_slot, ":center_no", slot_town_prosperity, ":new_prosperity"),
  39362. (call_script, "script_get_prosperity_text_to_s50", ":center_no"),
  39363. (str_store_string, s4, s50),
  39364. (try_begin),
  39365. (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  39366. (display_message, "@Prosperity of {s2} has changed from {s3} to {s4}."),
  39367. (try_end),
  39368. (call_script, "script_update_center_notes", ":center_no"),
  39369. (else_try),
  39370. (party_set_slot, ":center_no", slot_town_prosperity, ":new_prosperity"),
  39371. (try_end),
  39372.  
  39373. (try_begin),
  39374. (store_current_hours, ":hours"),
  39375. (gt, ":hours", 1),
  39376. (store_sub, ":actual_difference", ":new_prosperity", ":old_prosperity"),
  39377. (try_begin),
  39378. (lt, ":actual_difference", 0),
  39379. (val_add, "$newglob_total_prosperity_losses", ":actual_difference"),
  39380. (else_try),
  39381. (gt, ":actual_difference", 0),
  39382. (val_add, "$newglob_total_prosperity_gains", ":actual_difference"),
  39383. (try_end),
  39384. (try_end),
  39385.  
  39386. #This will add up all non-trade prosperity
  39387. (try_begin),
  39388. (eq, "$cheat_mode", 3),
  39389. (assign, reg4, "$newglob_total_prosperity_from_bandits"),
  39390. (assign, reg5, "$newglob_total_prosperity_from_caravan_trade"),
  39391. (assign, reg7, "$newglob_total_prosperity_from_villageloot"),
  39392. (assign, reg8, "$newglob_total_prosperity_from_townloot"),
  39393. (assign, reg9, "$newglob_total_prosperity_from_village_trade"),
  39394. (assign, reg10, "$newglob_total_prosperity_from_convergence"),
  39395. (assign, reg11, "$newglob_total_prosperity_losses"),
  39396. (assign, reg12, "$newglob_total_prosperity_gains"),
  39397. (display_message, "@{!}DEBUG: Total prosperity actual losses: {reg11}"),
  39398. (display_message, "@{!}DEBUG: Total prosperity actual gains: {reg12}"),
  39399.  
  39400. (display_message, "@{!}DEBUG: Prosperity changes from random bandits: {reg4}"),
  39401. (display_message, "@{!}DEBUG: Prosperity changes from caravan trades: {reg5}"),
  39402. (display_message, "@{!}DEBUG: Prosperity changes from farmer trades: {reg9}"),
  39403. (display_message, "@{!}DEBUG: Prosperity changes from looted villages: {reg7}"),
  39404. (display_message, "@{!}DEBUG: Prosperity changes from sieges: {reg8}"),
  39405. (display_message, "@{!}DEBUG: Theoretical prosperity changes from convergence: {reg10}"),
  39406. (try_end),
  39407.  
  39408. ]),
  39409.  
  39410. #script_get_center_ideal_prosperity
  39411. # INPUT: arg1 = center_no
  39412. # OUTPUT: reg0 = ideal_prosperity
  39413. ("get_center_ideal_prosperity",
  39414. [(store_script_param, ":center_no", 1),
  39415. (assign, ":ideal", 65),
  39416.  
  39417. (call_script, "script_center_get_goods_availability", ":center_no"),
  39418. (store_mul, ":hardship_index", reg0, 2),
  39419. (val_sub, ":ideal", ":hardship_index"),
  39420.  
  39421. (try_begin),
  39422. (is_between, ":center_no", villages_begin, villages_end),
  39423. (party_slot_eq, ":center_no", slot_center_has_fish_pond, 1),
  39424. (val_add, ":ideal", 5),
  39425. (try_end),
  39426.  
  39427. (val_max, ":ideal", 0),
  39428.  
  39429. (assign, reg0, ":ideal"),
  39430. ]),
  39431.  
  39432. ("good_price_affects_good_production",
  39433. [
  39434. (store_script_param, ":center", 1),
  39435. (store_script_param, ":input_item_no", 2),
  39436. (store_script_param, ":production", 3),
  39437. (store_script_param, ":impact_divisor", 4),
  39438.  
  39439. (assign, reg4, ":production"),
  39440.  
  39441. (try_begin),
  39442. (gt, ":production", 0), #let's take -20 as the zero production rate, although in actuality production can go lower, representing increased demand
  39443.  
  39444. (store_sub, ":input_good_price_slot", ":input_item_no", trade_goods_begin),
  39445. (val_add, ":input_good_price_slot", slot_town_trade_good_prices_begin),
  39446. (party_get_slot, ":input_price", ":center", ":input_good_price_slot"),
  39447.  
  39448. (try_begin),
  39449. (is_between, ":center", towns_begin, towns_end),
  39450.  
  39451. (val_mul, ":input_price", 4),
  39452. (assign, ":number_of_villages", 4),
  39453. (try_for_range, ":village_no", villages_begin, villages_end),
  39454. (party_slot_eq, ":village_no", slot_village_bound_center, ":center"),
  39455. (party_get_slot, ":input_price_at_village", ":village_no", ":input_good_price_slot"),
  39456. (val_add, ":input_price", ":input_price_at_village"),
  39457. (val_add, ":number_of_villages", 1),
  39458. (try_end),
  39459.  
  39460. (val_div, ":input_price", ":number_of_villages"),
  39461. (try_end),
  39462.  
  39463. (try_begin), #1/2 impact for low prices
  39464. ##diplomacy start+
  39465. (lt, ":input_price", average_price_factor),#Replace 1000 with average_price_factor
  39466. ##diplomacy end+
  39467. (val_mul, ":impact_divisor", 2),
  39468. (try_end),
  39469.  
  39470. (try_begin),
  39471. (gt, ":impact_divisor", 1),
  39472. ##diplomacy start+
  39473. (val_sub, ":input_price", average_price_factor),#Replace 1000 with average_price_factor
  39474. (val_div, ":input_price", ":impact_divisor"),#<- unchanged
  39475. (val_add, ":input_price", average_price_factor),#Replace 1000 with average_price_factor
  39476. ##diplomacy end+
  39477. (try_end),
  39478.  
  39479. ##diplomacy start+
  39480. (val_mul, ":production", average_price_factor),#Replace 1000 with average_price_factor
  39481. ##diplomacy end+
  39482. (val_div, ":production", ":input_price"),
  39483.  
  39484. # (assign, reg5, ":production"),
  39485. #(assign, reg3, ":input_price"),
  39486. # (str_store_item_name, s4, ":input_item_no"),
  39487. # (display_message, "@{s4} price of {reg3} reduces production from {reg4} to {reg5}"),
  39488.  
  39489. (try_end),
  39490.  
  39491.  
  39492. (assign, reg0, ":production"),
  39493.  
  39494. ]),
  39495.  
  39496.  
  39497.  
  39498.  
  39499. #script_get_poorest_village_of_faction
  39500. # INPUT: arg1 = center_no
  39501. # OUTPUT: reg0 = ideal_prosperity
  39502. ("get_poorest_village_of_faction",
  39503. [(store_script_param, ":faction_no", 1),
  39504. (assign, ":min_prosperity_village", -1),
  39505. (assign, ":min_prosperity", 101),
  39506. (try_for_range, ":village_no", villages_begin, villages_end),
  39507. (store_faction_of_party, ":village_faction", ":village_no"),
  39508. (eq, ":village_faction", ":faction_no"),
  39509. (party_get_slot, ":prosperity", ":village_no", slot_town_prosperity),
  39510. (lt, ":prosperity", ":min_prosperity"),
  39511. (assign, ":min_prosperity", ":prosperity"),
  39512. (assign, ":min_prosperity_village", ":village_no"),
  39513. (try_end),
  39514. (assign, reg0, ":min_prosperity_village"),
  39515. ]),
  39516.  
  39517. #script_troop_add_gold
  39518. # INPUT: arg1 = troop_no, arg2 = amount
  39519. # OUTPUT: none
  39520. ("troop_add_gold",
  39521. [
  39522. (store_script_param, ":troop_no", 1),
  39523. (store_script_param, ":amount", 2),
  39524.  
  39525. (troop_add_gold, ":troop_no", ":amount"),
  39526. (try_begin),
  39527. (eq, ":troop_no", "trp_player"),
  39528. (play_sound, "snd_money_received"),
  39529. (try_end),
  39530. ]),
  39531.  
  39532. #NPC companion changes begin
  39533. ("initialize_npcs",
  39534. [
  39535.  
  39536. # set strings
  39537.  
  39538. (troop_set_slot, "trp_npc1", slot_troop_morality_type, tmt_egalitarian), #borcha
  39539. (troop_set_slot, "trp_npc1", slot_troop_morality_value, 4), #borcha
  39540. (troop_set_slot, "trp_npc1", slot_troop_2ary_morality_type, tmt_aristocratic), #borcha
  39541. (troop_set_slot, "trp_npc1", slot_troop_2ary_morality_value, -1),
  39542. (troop_set_slot, "trp_npc1", slot_troop_personalityclash_object, "trp_npc7"), #borcha - deshavi
  39543. (troop_set_slot, "trp_npc1", slot_troop_personalityclash2_object, "trp_npc16"), #borcha - klethi
  39544. (troop_set_slot, "trp_npc1", slot_troop_personalitymatch_object, "trp_npc2"), #borcha - marnid
  39545. (troop_set_slot, "trp_npc1", slot_troop_home, "p_village_25"), #Dashbiga
  39546. (troop_set_slot, "trp_npc1", slot_troop_payment_request, 300),
  39547. (troop_set_slot, "trp_npc1", slot_troop_kingsupport_argument, argument_ruler),
  39548. (troop_set_slot, "trp_npc1", slot_troop_kingsupport_opponent, "trp_npc14"), #lezalit
  39549. (troop_set_slot, "trp_npc1", slot_troop_town_with_contacts, "p_town_17"),
  39550. (troop_set_slot, "trp_npc1", slot_troop_original_faction, 0),
  39551. (troop_set_slot, "trp_npc1", slot_lord_reputation_type, lrep_roguish), #
  39552.  
  39553.  
  39554.  
  39555. (troop_set_slot, "trp_npc2", slot_troop_morality_type, tmt_humanitarian), #marnid
  39556. (troop_set_slot, "trp_npc2", slot_troop_morality_value, 2),
  39557. (troop_set_slot, "trp_npc2", slot_troop_2ary_morality_type, tmt_honest),
  39558. (troop_set_slot, "trp_npc2", slot_troop_2ary_morality_value, 1),
  39559. (troop_set_slot, "trp_npc2", slot_troop_personalityclash_object, "trp_npc5"), #marnid - beheshtur
  39560. (troop_set_slot, "trp_npc2", slot_troop_personalityclash2_object, "trp_npc9"), #marnid - alayen
  39561. (troop_set_slot, "trp_npc2", slot_troop_personalitymatch_object, "trp_npc1"), #marnid - borcha
  39562. (troop_set_slot, "trp_npc2", slot_troop_home, "p_town_1"), #Sargoth
  39563. (troop_set_slot, "trp_npc2", slot_troop_payment_request, 0),
  39564. (troop_set_slot, "trp_npc2", slot_troop_kingsupport_argument, argument_victory),
  39565. (troop_set_slot, "trp_npc2", slot_troop_kingsupport_opponent, "trp_npc16"), #klethi
  39566. (troop_set_slot, "trp_npc2", slot_troop_town_with_contacts, "p_town_1"), #Sargoth
  39567. (troop_set_slot, "trp_npc2", slot_troop_original_faction, 0),
  39568. (troop_set_slot, "trp_npc2", slot_lord_reputation_type, lrep_custodian), #
  39569.  
  39570. #
  39571. (troop_set_slot, "trp_npc3", slot_troop_morality_type, tmt_humanitarian), #Ymira
  39572. (troop_set_slot, "trp_npc3", slot_troop_morality_value, 4),
  39573. (troop_set_slot, "trp_npc3", slot_troop_2ary_morality_type, tmt_aristocratic),
  39574. (troop_set_slot, "trp_npc3", slot_troop_2ary_morality_value, -1),
  39575. (troop_set_slot, "trp_npc3", slot_troop_personalityclash_object, "trp_npc14"), #Ymira - artimenner
  39576. (troop_set_slot, "trp_npc3", slot_troop_personalityclash2_object, "trp_npc8"), #Ymira - matheld
  39577. (troop_set_slot, "trp_npc3", slot_troop_personalitymatch_object, "trp_npc9"), #Ymira - alayen
  39578. (troop_set_slot, "trp_npc3", slot_troop_home, "p_town_3"), #Veluca
  39579. (troop_set_slot, "trp_npc3", slot_troop_payment_request, 0),
  39580. (troop_set_slot, "trp_npc3", slot_troop_kingsupport_argument, argument_lords),
  39581. (troop_set_slot, "trp_npc3", slot_troop_kingsupport_opponent, "trp_npc5"), #klethi
  39582. (troop_set_slot, "trp_npc3", slot_troop_town_with_contacts, "p_town_15"), #yalen
  39583. (troop_set_slot, "trp_npc3", slot_troop_original_faction, 0),
  39584. (troop_set_slot, "trp_npc3", slot_lord_reputation_type, lrep_benefactor), #
  39585.  
  39586.  
  39587.  
  39588. (troop_set_slot, "trp_npc4", slot_troop_morality_type, tmt_aristocratic), #Rolf
  39589. (troop_set_slot, "trp_npc4", slot_troop_morality_value, 4),
  39590. (troop_set_slot, "trp_npc4", slot_troop_2ary_morality_type, tmt_honest),
  39591. (troop_set_slot, "trp_npc4", slot_troop_2ary_morality_value, -1),
  39592. (troop_set_slot, "trp_npc4", slot_troop_personalityclash_object, "trp_npc10"), #Rolf - bunduk
  39593. (troop_set_slot, "trp_npc4", slot_troop_personalityclash2_object, "trp_npc7"), #Rolf - deshavi
  39594. (troop_set_slot, "trp_npc4", slot_troop_personalitymatch_object, "trp_npc5"), #Rolf - beheshtur
  39595. (troop_set_slot, "trp_npc4", slot_troop_home, "p_village_34"), #Ehlerdah
  39596. (troop_set_slot, "trp_npc4", slot_troop_payment_request, 300),
  39597. (troop_set_slot, "trp_npc4", slot_troop_renown, 100), #SB : renown
  39598. (troop_set_slot, "trp_npc4", slot_troop_kingsupport_argument, argument_claim),
  39599. (troop_set_slot, "trp_npc4", slot_troop_kingsupport_opponent, "trp_npc6"), #firentis
  39600. (troop_set_slot, "trp_npc4", slot_troop_town_with_contacts, "p_town_3"), #veluca
  39601. (troop_set_slot, "trp_npc4", slot_troop_original_faction, 0),
  39602. (troop_set_slot, "trp_npc4", slot_lord_reputation_type, lrep_cunning), #
  39603.  
  39604.  
  39605. (troop_set_slot, "trp_npc5", slot_troop_morality_type, tmt_egalitarian), #beheshtur
  39606. (troop_set_slot, "trp_npc5", slot_troop_morality_value, 3), #beheshtur
  39607. (troop_set_slot, "trp_npc5", slot_troop_2ary_morality_type, -1),
  39608. (troop_set_slot, "trp_npc5", slot_troop_2ary_morality_value, 0),
  39609. (troop_set_slot, "trp_npc5", slot_troop_personalityclash_object, "trp_npc2"), #beheshtur - marnid
  39610. (troop_set_slot, "trp_npc5", slot_troop_personalityclash2_object, "trp_npc11"), #beheshtur- katrin
  39611. (troop_set_slot, "trp_npc5", slot_troop_personalitymatch_object, "trp_npc4"), #beheshtur - rolf
  39612. (troop_set_slot, "trp_npc5", slot_troop_home, "p_town_14"), #Halmar
  39613. (troop_set_slot, "trp_npc5", slot_troop_payment_request, 400),
  39614. (troop_set_slot, "trp_npc5", slot_troop_renown, 100), #SB : renown
  39615. (troop_set_slot, "trp_npc5", slot_troop_kingsupport_argument, argument_ruler),
  39616. (troop_set_slot, "trp_npc5", slot_troop_kingsupport_opponent, "trp_npc9"), #firentis
  39617. (troop_set_slot, "trp_npc5", slot_troop_town_with_contacts, "p_town_10"), #tulga
  39618. (troop_set_slot, "trp_npc5", slot_troop_original_faction, "fac_kingdom_3"), #khergit
  39619. (troop_set_slot, "trp_npc5", slot_lord_reputation_type, lrep_cunning), #
  39620.  
  39621.  
  39622.  
  39623. (troop_set_slot, "trp_npc6", slot_troop_morality_type, tmt_humanitarian), #firenz
  39624. (troop_set_slot, "trp_npc6", slot_troop_morality_value, 2), #beheshtur
  39625. (troop_set_slot, "trp_npc6", slot_troop_2ary_morality_type, tmt_honest),
  39626. (troop_set_slot, "trp_npc6", slot_troop_2ary_morality_value, 1),
  39627. (troop_set_slot, "trp_npc6", slot_troop_personalityclash_object, "trp_npc11"), #firenz
  39628. (troop_set_slot, "trp_npc6", slot_troop_personalityclash2_object, "trp_npc13"), #firenz - nizar
  39629. (troop_set_slot, "trp_npc6", slot_troop_personalitymatch_object, "trp_npc12"), #firenz - jeremus
  39630. (troop_set_slot, "trp_npc6", slot_troop_home, "p_town_4"), #Suno
  39631. (troop_set_slot, "trp_npc6", slot_troop_payment_request, 0),
  39632. (troop_set_slot, "trp_npc6", slot_troop_renown, 50), #SB : renown
  39633. (troop_set_slot, "trp_npc6", slot_troop_kingsupport_argument, argument_victory),
  39634. (troop_set_slot, "trp_npc6", slot_troop_kingsupport_opponent, "trp_npc8"), #firentis
  39635. (troop_set_slot, "trp_npc6", slot_troop_town_with_contacts, "p_town_7"), #uxkhal
  39636. (troop_set_slot, "trp_npc6", slot_troop_original_faction, "fac_kingdom_1"), #swadia
  39637. (troop_set_slot, "trp_npc6", slot_lord_reputation_type, lrep_upstanding), #
  39638.  
  39639.  
  39640.  
  39641. (troop_set_slot, "trp_npc7", slot_troop_morality_type, tmt_egalitarian), #deshavi
  39642. (troop_set_slot, "trp_npc7", slot_troop_morality_value, 3), #beheshtur
  39643. (troop_set_slot, "trp_npc7", slot_troop_2ary_morality_type, -1),
  39644. (troop_set_slot, "trp_npc7", slot_troop_2ary_morality_value, 0),
  39645. (troop_set_slot, "trp_npc7", slot_troop_personalityclash_object, "trp_npc1"), #deshavi
  39646. (troop_set_slot, "trp_npc7", slot_troop_personalityclash2_object, "trp_npc4"), #deshavi - rolf
  39647. (troop_set_slot, "trp_npc7", slot_troop_personalitymatch_object, "trp_npc16"), #deshavi - klethi
  39648. (troop_set_slot, "trp_npc7", slot_troop_home, "p_village_5"), #Kulum
  39649. # (troop_set_slot, "trp_npc7", slot_troop_payment_request, 300),
  39650. (troop_set_slot, "trp_npc7", slot_troop_kingsupport_argument, argument_victory),
  39651. (troop_set_slot, "trp_npc7", slot_troop_kingsupport_opponent, "trp_npc3"), #ymira
  39652. (troop_set_slot, "trp_npc7", slot_troop_town_with_contacts, "p_town_2"), #tihr
  39653. (troop_set_slot, "trp_npc7", slot_troop_original_faction, 0), #swadia
  39654. (troop_set_slot, "trp_npc7", slot_lord_reputation_type, lrep_custodian), #
  39655.  
  39656.  
  39657.  
  39658. (troop_set_slot, "trp_npc8", slot_troop_morality_type, tmt_aristocratic), #matheld
  39659. (troop_set_slot, "trp_npc8", slot_troop_morality_value, 3), #beheshtur
  39660. (troop_set_slot, "trp_npc8", slot_troop_2ary_morality_type, -1),
  39661. (troop_set_slot, "trp_npc8", slot_troop_2ary_morality_value, 0),
  39662. (troop_set_slot, "trp_npc8", slot_troop_personalityclash_object, "trp_npc12"), #matheld
  39663. (troop_set_slot, "trp_npc8", slot_troop_personalityclash2_object, "trp_npc3"), #matheld - ymira
  39664. (troop_set_slot, "trp_npc8", slot_troop_personalitymatch_object, "trp_npc13"), #matheld - nizar
  39665. (troop_set_slot, "trp_npc8", slot_troop_home, "p_village_35"), #Fearichen
  39666. (troop_set_slot, "trp_npc8", slot_troop_payment_request, 500),
  39667. (troop_set_slot, "trp_npc8", slot_troop_renown, 75), #SB : renown
  39668. (troop_set_slot, "trp_npc8", slot_troop_kingsupport_argument, argument_lords),
  39669. (troop_set_slot, "trp_npc8", slot_troop_kingsupport_opponent, "trp_npc2"), #marnid
  39670. (troop_set_slot, "trp_npc8", slot_troop_town_with_contacts, "p_town_12"), #wercheg
  39671. (troop_set_slot, "trp_npc8", slot_troop_original_faction, "fac_kingdom_4"), #nords
  39672. (troop_set_slot, "trp_npc8", slot_lord_reputation_type, lrep_martial), #
  39673.  
  39674.  
  39675. (troop_set_slot, "trp_npc9", slot_troop_morality_type, tmt_aristocratic), #alayen
  39676. (troop_set_slot, "trp_npc9", slot_troop_morality_value, 2), #beheshtur
  39677. (troop_set_slot, "trp_npc9", slot_troop_2ary_morality_type, tmt_honest),
  39678. (troop_set_slot, "trp_npc9", slot_troop_2ary_morality_value, 1),
  39679. (troop_set_slot, "trp_npc9", slot_troop_personalityclash_object, "trp_npc13"), #alayen vs nizar
  39680. (troop_set_slot, "trp_npc9", slot_troop_personalityclash2_object, "trp_npc2"), #alayen vs marnid
  39681. (troop_set_slot, "trp_npc9", slot_troop_personalitymatch_object, "trp_npc3"), #alayen - ymira
  39682. (troop_set_slot, "trp_npc9", slot_troop_home, "p_town_13"), #Rivacheg
  39683. (troop_set_slot, "trp_npc9", slot_troop_payment_request, 300),
  39684. (troop_set_slot, "trp_npc9", slot_troop_renown, 100), #SB : renown
  39685. (troop_set_slot, "trp_npc9", slot_troop_kingsupport_argument, argument_lords),
  39686. (troop_set_slot, "trp_npc9", slot_troop_kingsupport_opponent, "trp_npc1"), #borcha
  39687. (troop_set_slot, "trp_npc9", slot_troop_town_with_contacts, "p_town_8"), #reyvadin
  39688. (troop_set_slot, "trp_npc9", slot_troop_original_faction, "fac_kingdom_2"), #vaegirs
  39689. (troop_set_slot, "trp_npc9", slot_lord_reputation_type, lrep_martial), #
  39690.  
  39691.  
  39692. (troop_set_slot, "trp_npc10", slot_troop_morality_type, tmt_humanitarian), #bunduk
  39693. (troop_set_slot, "trp_npc10", slot_troop_morality_value, 2),
  39694. (troop_set_slot, "trp_npc10", slot_troop_2ary_morality_type, tmt_egalitarian),
  39695. (troop_set_slot, "trp_npc10", slot_troop_2ary_morality_value, 1),
  39696. (troop_set_slot, "trp_npc10", slot_troop_personalityclash_object, "trp_npc4"), #bunduk vs rolf
  39697. (troop_set_slot, "trp_npc10", slot_troop_personalityclash2_object, "trp_npc14"), #bunduk vs lazalet
  39698. (troop_set_slot, "trp_npc10", slot_troop_personalitymatch_object, "trp_npc11"), #bunduk likes katrin
  39699. (troop_set_slot, "trp_npc10", slot_troop_home, "p_castle_28"), #Grunwalder Castle
  39700. (troop_set_slot, "trp_npc10", slot_troop_payment_request, 200),
  39701. (troop_set_slot, "trp_npc10", slot_troop_renown, 75), #SB : renown
  39702. (troop_set_slot, "trp_npc10", slot_troop_kingsupport_argument, argument_ruler),
  39703. (troop_set_slot, "trp_npc10", slot_troop_kingsupport_opponent, "trp_npc7"), #nizar
  39704. (troop_set_slot, "trp_npc10", slot_troop_town_with_contacts, "p_town_5"), #jelkala
  39705. (troop_set_slot, "trp_npc10", slot_troop_original_faction, "fac_kingdom_5"), #rhodoks
  39706. (troop_set_slot, "trp_npc10", slot_lord_reputation_type, lrep_benefactor), #
  39707.  
  39708.  
  39709.  
  39710. (troop_set_slot, "trp_npc11", slot_troop_morality_type, tmt_egalitarian), #katrin
  39711. (troop_set_slot, "trp_npc11", slot_troop_morality_value, 3),
  39712. (troop_set_slot, "trp_npc11", slot_troop_2ary_morality_type, -1),
  39713. (troop_set_slot, "trp_npc11", slot_troop_2ary_morality_value, 0),
  39714. (troop_set_slot, "trp_npc11", slot_troop_personalityclash_object, "trp_npc6"), #katrin vs firenz
  39715. (troop_set_slot, "trp_npc11", slot_troop_personalityclash2_object, "trp_npc5"), #katrin - beheshtur
  39716. (troop_set_slot, "trp_npc11", slot_troop_personalitymatch_object, "trp_npc10"), #katrin likes bunduk
  39717. (troop_set_slot, "trp_npc11", slot_troop_home, "p_town_6"), #Praven
  39718. (troop_set_slot, "trp_npc11", slot_troop_payment_request, 100),
  39719. (troop_set_slot, "trp_npc11", slot_troop_kingsupport_argument, argument_claim),
  39720. (troop_set_slot, "trp_npc11", slot_troop_kingsupport_opponent, "trp_npc15"), #borcha
  39721. (troop_set_slot, "trp_npc11", slot_troop_town_with_contacts, "p_town_6"), #praven
  39722. (troop_set_slot, "trp_npc11", slot_troop_original_faction, 0), #
  39723. (troop_set_slot, "trp_npc11", slot_lord_reputation_type, lrep_custodian), #
  39724.  
  39725.  
  39726. (troop_set_slot, "trp_npc12", slot_troop_morality_type, tmt_humanitarian), #jeremus
  39727. (troop_set_slot, "trp_npc12", slot_troop_morality_value, 3),
  39728. (troop_set_slot, "trp_npc12", slot_troop_2ary_morality_type, -1),
  39729. (troop_set_slot, "trp_npc12", slot_troop_2ary_morality_value, 0),
  39730. (troop_set_slot, "trp_npc12", slot_troop_personalityclash_object, "trp_npc8"), #jerem
  39731. (troop_set_slot, "trp_npc12", slot_troop_personalityclash2_object, "trp_npc15"), #jeremus - artimenner
  39732. (troop_set_slot, "trp_npc12", slot_troop_personalitymatch_object, "trp_npc6"), #jeremus - firenz
  39733. (troop_set_slot, "trp_npc12", slot_troop_home, "p_castle_16"), #undetermined #University
  39734. (troop_set_slot, "trp_npc12", slot_troop_payment_request, 0),
  39735. (troop_set_slot, "trp_npc12", slot_troop_renown, 100), #SB : renown
  39736. (troop_set_slot, "trp_npc12", slot_troop_kingsupport_argument, argument_claim),
  39737. (troop_set_slot, "trp_npc12", slot_troop_kingsupport_opponent, "trp_npc13"), #nizar
  39738. (troop_set_slot, "trp_npc12", slot_troop_town_with_contacts, "p_town_14"), #halmar
  39739. (troop_set_slot, "trp_npc12", slot_troop_original_faction, 0), #
  39740. (troop_set_slot, "trp_npc12", slot_lord_reputation_type, lrep_benefactor), #
  39741.  
  39742.  
  39743.  
  39744. (troop_set_slot, "trp_npc13", slot_troop_morality_type, tmt_aristocratic), #nizar
  39745. (troop_set_slot, "trp_npc13", slot_troop_morality_value, 3),
  39746. (troop_set_slot, "trp_npc13", slot_troop_2ary_morality_type, -1),
  39747. (troop_set_slot, "trp_npc13", slot_troop_2ary_morality_value, 0),
  39748. (troop_set_slot, "trp_npc13", slot_troop_personalityclash_object, "trp_npc9"), #nizar
  39749. (troop_set_slot, "trp_npc13", slot_troop_personalityclash2_object, "trp_npc6"), #nizar - firenz
  39750. (troop_set_slot, "trp_npc13", slot_troop_personalitymatch_object, "trp_npc8"), #nizar - matheld
  39751. (troop_set_slot, "trp_npc13", slot_troop_home, "p_castle_15"), #Ergellon Castle
  39752. (troop_set_slot, "trp_npc13", slot_troop_payment_request, 300),
  39753. (troop_set_slot, "trp_npc13", slot_troop_renown, 75), #SB : renown
  39754. (troop_set_slot, "trp_npc13", slot_troop_kingsupport_argument, argument_claim),
  39755. (troop_set_slot, "trp_npc13", slot_troop_kingsupport_opponent, "trp_npc10"), #nizar
  39756. (troop_set_slot, "trp_npc13", slot_troop_town_with_contacts, "p_town_4"), #suno
  39757. (troop_set_slot, "trp_npc13", slot_troop_original_faction, 0), #
  39758. (troop_set_slot, "trp_npc13", slot_lord_reputation_type, lrep_roguish), #
  39759.  
  39760.  
  39761.  
  39762. (troop_set_slot, "trp_npc14", slot_troop_morality_type, tmt_aristocratic), #lezalit
  39763. (troop_set_slot, "trp_npc14", slot_troop_morality_value, 4),
  39764. (troop_set_slot, "trp_npc14", slot_troop_2ary_morality_type, tmt_egalitarian),
  39765. (troop_set_slot, "trp_npc14", slot_troop_2ary_morality_value, -1),
  39766. (troop_set_slot, "trp_npc14", slot_troop_personalityclash_object, "trp_npc3"), #lezalit
  39767. (troop_set_slot, "trp_npc14", slot_troop_personalityclash2_object, "trp_npc10"), #lezalit - bunduk
  39768. (troop_set_slot, "trp_npc14", slot_troop_personalitymatch_object, "trp_npc15"), #lezalit - artimenner
  39769. (troop_set_slot, "trp_npc14", slot_troop_home, "p_castle_18"), #Ismirala Castle
  39770. (troop_set_slot, "trp_npc14", slot_troop_payment_request, 400),
  39771. (troop_set_slot, "trp_npc14", slot_troop_renown, 100), #SB : renown
  39772. (troop_set_slot, "trp_npc14", slot_troop_kingsupport_argument, argument_victory),
  39773. (troop_set_slot, "trp_npc14", slot_troop_kingsupport_opponent, "trp_npc11"), #nizar
  39774. (troop_set_slot, "trp_npc14", slot_troop_town_with_contacts, "p_town_16"), #dhirim
  39775. (troop_set_slot, "trp_npc14", slot_troop_original_faction, 0), #
  39776. (troop_set_slot, "trp_npc14", slot_lord_reputation_type, lrep_selfrighteous), #
  39777.  
  39778.  
  39779. (troop_set_slot, "trp_npc15", slot_troop_morality_type, tmt_egalitarian), #artimenner
  39780. (troop_set_slot, "trp_npc15", slot_troop_morality_value, 2),
  39781. (troop_set_slot, "trp_npc15", slot_troop_2ary_morality_type, tmt_honest),
  39782. (troop_set_slot, "trp_npc15", slot_troop_2ary_morality_value, 1),
  39783. (troop_set_slot, "trp_npc15", slot_troop_personalityclash_object, "trp_npc16"), #artimenner - klethi
  39784. (troop_set_slot, "trp_npc15", slot_troop_personalityclash2_object, "trp_npc12"), #artimenner - jeremus
  39785. (troop_set_slot, "trp_npc15", slot_troop_personalitymatch_object, "trp_npc14"), #lazalit - artimenner
  39786. (troop_set_slot, "trp_npc15", slot_troop_home, "p_castle_1"), #Culmarr Castle
  39787. (troop_set_slot, "trp_npc15", slot_troop_payment_request, 300),
  39788. (troop_set_slot, "trp_npc15", slot_troop_renown, 100), #SB : renown
  39789. (troop_set_slot, "trp_npc15", slot_troop_kingsupport_argument, argument_ruler),
  39790. (troop_set_slot, "trp_npc15", slot_troop_kingsupport_opponent, "trp_npc4"), #nizar
  39791. (troop_set_slot, "trp_npc15", slot_troop_town_with_contacts, "p_town_20"), #durquba
  39792. (troop_set_slot, "trp_npc15", slot_lord_reputation_type, lrep_custodian), #
  39793.  
  39794.  
  39795. (troop_set_slot, "trp_npc16", slot_troop_morality_type, tmt_aristocratic), #klethi
  39796. (troop_set_slot, "trp_npc16", slot_troop_morality_value, 4),
  39797. (troop_set_slot, "trp_npc16", slot_troop_2ary_morality_type, tmt_humanitarian),
  39798. (troop_set_slot, "trp_npc16", slot_troop_2ary_morality_value, -1),
  39799. (troop_set_slot, "trp_npc16", slot_troop_personalityclash_object, "trp_npc15"), #klethi
  39800. (troop_set_slot, "trp_npc16", slot_troop_personalityclash2_object, "trp_npc1"), #klethi - borcha
  39801. (troop_set_slot, "trp_npc16", slot_troop_personalitymatch_object, "trp_npc7"), #deshavi - klethi
  39802. (troop_set_slot, "trp_npc16", slot_troop_home, "p_village_20"), #Uslum
  39803. (troop_set_slot, "trp_npc16", slot_troop_payment_request, 200),
  39804. (troop_set_slot, "trp_npc16", slot_troop_kingsupport_argument, argument_lords),
  39805. (troop_set_slot, "trp_npc16", slot_troop_kingsupport_opponent, "trp_npc12"), #nizar
  39806. (troop_set_slot, "trp_npc16", slot_troop_town_with_contacts, "p_town_9"), #khudan
  39807. (troop_set_slot, "trp_npc16", slot_lord_reputation_type, lrep_roguish), #
  39808.  
  39809.  
  39810.  
  39811. (store_sub, "$number_of_npc_slots", slot_troop_strings_end, slot_troop_intro),
  39812.  
  39813. (try_for_range, ":npc", companions_begin, companions_end),
  39814.  
  39815.  
  39816. (try_for_range, ":slot_addition", 0, "$number_of_npc_slots"),
  39817. (store_add, ":slot", ":slot_addition", slot_troop_intro),
  39818.  
  39819. (store_mul, ":string_addition", ":slot_addition", 16),
  39820. (store_add, ":string", "str_npc1_intro", ":string_addition"),
  39821. (val_add, ":string", ":npc"),
  39822. (val_sub, ":string", companions_begin),
  39823.  
  39824. (troop_set_slot, ":npc", ":slot", ":string"),
  39825. (try_end),
  39826. (try_end),
  39827.  
  39828.  
  39829. #Post 0907 changes begin
  39830. (call_script, "script_add_log_entry", logent_game_start, "trp_player", -1, -1, -1),
  39831. #Post 0907 changes end
  39832.  
  39833. #Rebellion changes begin
  39834. (troop_set_slot, "trp_kingdom_1_pretender", slot_troop_original_faction, "fac_kingdom_1"),
  39835. (troop_set_slot, "trp_kingdom_2_pretender", slot_troop_original_faction, "fac_kingdom_2"),
  39836. (troop_set_slot, "trp_kingdom_3_pretender", slot_troop_original_faction, "fac_kingdom_3"),
  39837. (troop_set_slot, "trp_kingdom_4_pretender", slot_troop_original_faction, "fac_kingdom_4"),
  39838. (troop_set_slot, "trp_kingdom_5_pretender", slot_troop_original_faction, "fac_kingdom_5"),
  39839. (troop_set_slot, "trp_kingdom_6_pretender", slot_troop_original_faction, "fac_kingdom_6"),
  39840.  
  39841. # (troop_set_slot, "trp_kingdom_1_pretender", slot_troop_support_base, "p_town_4"), #suno
  39842. # (troop_set_slot, "trp_kingdom_2_pretender", slot_troop_support_base, "p_town_11"), #curaw
  39843. # (troop_set_slot, "trp_kingdom_3_pretender", slot_troop_support_base, "p_town_18"), #town_18
  39844. # (troop_set_slot, "trp_kingdom_4_pretender", slot_troop_support_base, "p_town_12"), #wercheg
  39845. # (troop_set_slot, "trp_kingdom_5_pretender", slot_troop_support_base, "p_town_3"), #veluca
  39846. ##diplomacy start+
  39847. (troop_set_slot, "trp_kingdom_1_pretender", slot_troop_home, "p_town_4"),#Lady Isolle - Suno
  39848. (troop_set_slot, "trp_kingdom_2_pretender", slot_troop_home, "p_town_11"),#Prince Valdym - Curaw
  39849. (troop_set_slot, "trp_kingdom_3_pretender", slot_troop_home, "p_town_18"),#Dustum Khan - Narra
  39850. (troop_set_slot, "trp_kingdom_4_pretender", slot_troop_home, "p_town_12"),#Lethwin Far-Seeker - Wercheg
  39851. (troop_set_slot, "trp_kingdom_5_pretender", slot_troop_home, "p_town_3"),#Lord Kastor - Veluca
  39852. (troop_set_slot, "trp_kingdom_6_pretender", slot_troop_home, "p_town_20"),#Arwa the Pearled One - Durquba
  39853. ##diplomacy end+
  39854. (try_for_range, ":pretender", pretenders_begin, pretenders_end),
  39855. (troop_set_slot, ":pretender", slot_lord_reputation_type, lrep_none),
  39856. ##diplomacy start+
  39857. (troop_get_slot, ":home", ":pretender", slot_troop_home),
  39858. (ge, ":home", 1),
  39859. (neg|party_slot_ge, ":home", dplmc_slot_center_original_lord, 1),
  39860. (party_set_slot, ":home", dplmc_slot_center_original_lord, ":pretender"),
  39861. ##diplomacy end+
  39862. (try_end),
  39863. #Rebellion changes end
  39864. ]),
  39865.  
  39866.  
  39867.  
  39868. ("objectionable_action",
  39869. [
  39870. (store_script_param_1, ":action_type"),
  39871. (store_script_param_2, ":action_string"),
  39872.  
  39873. (assign, ":grievance_minimum", -2),
  39874. (try_for_range, ":npc", companions_begin, companions_end),
  39875. (main_party_has_troop, ":npc"),
  39876.  
  39877. ###Primary morality check
  39878. (try_begin),
  39879. (troop_slot_eq, ":npc", slot_troop_morality_type, ":action_type"),
  39880. (troop_get_slot, ":value", ":npc", slot_troop_morality_value),
  39881. (try_begin),
  39882. (troop_slot_eq, ":npc", slot_troop_morality_state, tms_acknowledged),
  39883. # npc is betrayed, major penalty to player honor and morale
  39884. (troop_get_slot, ":grievance", ":npc", slot_troop_morality_penalties),
  39885. (val_mul, ":value", 2),
  39886. (val_add, ":grievance", ":value"),
  39887. (troop_set_slot, ":npc", slot_troop_morality_penalties, ":grievance"),
  39888. (else_try),
  39889. (this_or_next|troop_slot_eq, ":npc", slot_troop_morality_state, tms_dismissed),
  39890. (eq, "$disable_npc_complaints", 1),
  39891. # npc is quietly disappointed
  39892. (troop_get_slot, ":grievance", ":npc", slot_troop_morality_penalties),
  39893. (val_add, ":grievance", ":value"),
  39894. (troop_set_slot, ":npc", slot_troop_morality_penalties, ":grievance"),
  39895. (else_try),
  39896. # npc raises the issue for the first time
  39897. (troop_slot_eq, ":npc", slot_troop_morality_state, tms_no_problem),
  39898. (gt, ":value", ":grievance_minimum"),
  39899. (assign, "$npc_with_grievance", ":npc"),
  39900. (assign, "$npc_grievance_string", ":action_string"),
  39901. (assign, "$npc_grievance_slot", slot_troop_morality_state),
  39902. (assign, ":grievance_minimum", ":value"),
  39903. (assign, "$npc_praise_not_complaint", 0),
  39904. (try_begin),
  39905. (lt, ":value", 0),
  39906. (assign, "$npc_praise_not_complaint", 1),
  39907. (try_end),
  39908. (try_end),
  39909.  
  39910. ###Secondary morality check
  39911. (else_try),
  39912. (troop_slot_eq, ":npc", slot_troop_2ary_morality_type, ":action_type"),
  39913. (troop_get_slot, ":value", ":npc", slot_troop_2ary_morality_value),
  39914. (try_begin),
  39915. (troop_slot_eq, ":npc", slot_troop_2ary_morality_state, tms_acknowledged),
  39916. # npc is betrayed, major penalty to player honor and morale
  39917. (troop_get_slot, ":grievance", ":npc", slot_troop_morality_penalties),
  39918. (val_mul, ":value", 2),
  39919. (val_add, ":grievance", ":value"),
  39920. (troop_set_slot, ":npc", slot_troop_morality_penalties, ":grievance"),
  39921. (else_try),
  39922. (this_or_next|troop_slot_eq, ":npc", slot_troop_2ary_morality_state, tms_dismissed),
  39923. (eq, "$disable_npc_complaints", 1),
  39924. # npc is quietly disappointed
  39925. (troop_get_slot, ":grievance", ":npc", slot_troop_morality_penalties),
  39926. (val_add, ":grievance", ":value"),
  39927. (troop_set_slot, ":npc", slot_troop_morality_penalties, ":grievance"),
  39928. (else_try),
  39929. # npc raises the issue for the first time
  39930. (troop_slot_eq, ":npc", slot_troop_2ary_morality_state, tms_no_problem),
  39931. (gt, ":value", ":grievance_minimum"),
  39932. (assign, "$npc_with_grievance", ":npc"),
  39933. (assign, "$npc_grievance_string", ":action_string"),
  39934. (assign, "$npc_grievance_slot", slot_troop_2ary_morality_state),
  39935. (assign, ":grievance_minimum", ":value"),
  39936. (assign, "$npc_praise_not_complaint", 0),
  39937. (try_begin),
  39938. (lt, ":value", 0),
  39939. (assign, "$npc_praise_not_complaint", 1),
  39940. (try_end),
  39941. (try_end),
  39942. (try_end),
  39943.  
  39944. (try_begin),
  39945. (gt, "$npc_with_grievance", 0),
  39946. (eq, "$npc_praise_not_complaint", 0),
  39947. (str_store_troop_name, 4, "$npc_with_grievance"),
  39948. (display_message, "@{s4} looks upset.", message_alert),
  39949. (try_end),
  39950. (try_end),
  39951. ]),
  39952.  
  39953.  
  39954. ("post_battle_personality_clash_check",
  39955. [
  39956. (try_for_range, ":npc", companions_begin, companions_end),
  39957. (eq, "$disable_npc_complaints", 0),
  39958.  
  39959. (main_party_has_troop, ":npc"),
  39960. (neg|troop_is_wounded, ":npc"),
  39961.  
  39962. (troop_get_slot, ":other_npc", ":npc", slot_troop_personalityclash2_object),
  39963. (main_party_has_troop, ":other_npc"),
  39964. (neg|troop_is_wounded, ":other_npc"),
  39965.  
  39966. # (store_random_in_range, ":random", 0, 3),
  39967. (try_begin),
  39968. (troop_slot_eq, ":npc", slot_troop_personalityclash2_state, 0),
  39969. (try_begin),
  39970. # (eq, ":random", 0),
  39971. (assign, "$npc_with_personality_clash_2", ":npc"),
  39972. (try_end),
  39973. (try_end),
  39974.  
  39975. (try_end),
  39976.  
  39977. (try_for_range, ":npc", companions_begin, companions_end),
  39978. (troop_slot_eq, ":npc", slot_troop_personalitymatch_state, 0),
  39979. (eq, "$disable_npc_complaints", 0),
  39980.  
  39981. (main_party_has_troop, ":npc"),
  39982. (neg|troop_is_wounded, ":npc"),
  39983.  
  39984. (troop_get_slot, ":other_npc", ":npc", slot_troop_personalitymatch_object),
  39985. (main_party_has_troop, ":other_npc"),
  39986. (neg|troop_is_wounded, ":other_npc"),
  39987. (assign, "$npc_with_personality_match", ":npc"),
  39988. (try_end),
  39989.  
  39990.  
  39991. (try_begin),
  39992. (gt, "$npc_with_personality_clash_2", 0),
  39993. (try_begin),
  39994. (eq, "$cheat_mode", 1),
  39995. (display_message, "str_personality_clash_conversation_begins"),
  39996. (try_end),
  39997.  
  39998. (try_begin),
  39999. (main_party_has_troop, "$npc_with_personality_clash_2"),
  40000. (assign, "$npc_map_talk_context", slot_troop_personalityclash2_state),
  40001. (start_map_conversation, "$npc_with_personality_clash_2"),
  40002. (else_try),
  40003. (assign, "$npc_with_personality_clash_2", 0),
  40004. (try_end),
  40005. (else_try),
  40006. (gt, "$npc_with_personality_match", 0),
  40007. (try_begin),
  40008. (eq, "$cheat_mode", 1),
  40009. (display_message, "str_personality_match_conversation_begins"),
  40010. (try_end),
  40011.  
  40012. (try_begin),
  40013. (main_party_has_troop, "$npc_with_personality_match"),
  40014. (assign, "$npc_map_talk_context", slot_troop_personalitymatch_state),
  40015. (start_map_conversation, "$npc_with_personality_match"),
  40016. (else_try),
  40017. (assign, "$npc_with_personality_match", 0),
  40018. (try_end),
  40019. (try_end),
  40020. ]),
  40021.  
  40022. #script_event_player_defeated_enemy_party
  40023. # INPUT: none
  40024. # OUTPUT: none
  40025. ("event_player_defeated_enemy_party",
  40026. [(try_begin),
  40027. (check_quest_active, "qst_raid_caravan_to_start_war"),
  40028. (neg|check_quest_concluded, "qst_raid_caravan_to_start_war"),
  40029. (party_slot_eq, "$g_enemy_party", slot_party_type, spt_kingdom_caravan),
  40030. (store_faction_of_party, ":enemy_faction", "$g_enemy_party"),
  40031. (quest_slot_eq, "qst_raid_caravan_to_start_war", slot_quest_target_faction, ":enemy_faction"),
  40032. (quest_get_slot, ":cur_state", "qst_raid_caravan_to_start_war", slot_quest_current_state),
  40033. (quest_get_slot, ":quest_target_amount", "qst_raid_caravan_to_start_war", slot_quest_target_amount),
  40034. (val_add, ":cur_state", 1),
  40035. (quest_set_slot, "qst_raid_caravan_to_start_war", slot_quest_current_state, ":cur_state"),
  40036. (try_begin),
  40037. (ge, ":cur_state", ":quest_target_amount"),
  40038. (quest_get_slot, ":quest_target_faction", "qst_raid_caravan_to_start_war", slot_quest_target_faction),
  40039. (quest_get_slot, ":quest_giver_troop", "qst_raid_caravan_to_start_war", slot_quest_giver_troop),
  40040. (store_troop_faction, ":quest_giver_faction", ":quest_giver_troop"),
  40041. (call_script, "script_diplomacy_start_war_between_kingdoms", ":quest_target_faction", ":quest_giver_faction", 1),
  40042. (call_script, "script_succeed_quest", "qst_raid_caravan_to_start_war"),
  40043. (try_end),
  40044. (try_end),
  40045.  
  40046. ]),
  40047.  
  40048. #script_event_player_captured_as_prisoner
  40049. # INPUT: none
  40050. # OUTPUT: none
  40051. ("event_player_captured_as_prisoner",
  40052. [
  40053. (try_begin),
  40054. (check_quest_active, "qst_raid_caravan_to_start_war"),
  40055. (neg|check_quest_concluded, "qst_raid_caravan_to_start_war"),
  40056. (quest_get_slot, ":quest_target_faction", "qst_raid_caravan_to_start_war", slot_quest_target_faction),
  40057. (store_faction_of_party, ":capturer_faction", "$capturer_party"),
  40058. (eq, ":quest_target_faction", ":capturer_faction"),
  40059. (call_script, "script_fail_quest", "qst_raid_caravan_to_start_war"),
  40060. (try_end),
  40061. #Removing followers of the player
  40062. (try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
  40063. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  40064. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  40065. (gt, ":party_no", 0),
  40066. (party_is_active, ":party_no"),
  40067. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  40068. (party_slot_eq, ":party_no", slot_party_ai_object, "p_main_party"),
  40069. (call_script, "script_party_set_ai_state", ":party_no", spai_undefined, -1),
  40070. (assign, "$g_recalculate_ais", 1),
  40071. (try_end),
  40072. ]),
  40073.  
  40074. #NPC morale both returns a string and reg0 as the morale value
  40075. ("npc_morale",
  40076. [
  40077. (store_script_param_1, ":npc"),
  40078.  
  40079. (troop_get_slot, ":morality_grievances", ":npc", slot_troop_morality_penalties),
  40080. (troop_get_slot, ":personality_grievances", ":npc", slot_troop_personalityclash_penalties),
  40081. (party_get_morale, ":party_morale", "p_main_party"),
  40082.  
  40083. (store_sub, ":troop_morale", ":party_morale", ":morality_grievances"),
  40084. (val_sub, ":troop_morale", ":personality_grievances"),
  40085. (val_add, ":troop_morale", 50), #SB : this should scale from actual relation
  40086.  
  40087. (assign, reg8, ":troop_morale"),
  40088.  
  40089. (val_mul, ":troop_morale", 3),
  40090. (val_div, ":troop_morale", 4),
  40091. (val_clamp, ":troop_morale", 0, 100),
  40092.  
  40093. (assign, reg5, ":party_morale"),
  40094. (assign, reg6, ":morality_grievances"),
  40095. (assign, reg7, ":personality_grievances"),
  40096. (assign, reg9, ":troop_morale"),
  40097.  
  40098. # (str_store_troop_name, s11, ":npc"),
  40099. # (display_message, "@{!}{s11}'s morale = PM{reg5} + 50 - MG{reg6} - PG{reg7} = {reg8} x 0.75 = {reg9}"),
  40100.  
  40101. (try_begin),
  40102. (lt, ":morality_grievances", 3),
  40103. (str_store_string, 7, "str_happy"),
  40104. (else_try),
  40105. (lt, ":morality_grievances", 15),
  40106. (str_store_string, 7, "str_content"),
  40107. (else_try),
  40108. (lt, ":morality_grievances", 30),
  40109. (str_store_string, 7, "str_concerned"),
  40110. (else_try),
  40111. (lt, ":morality_grievances", 45),
  40112. (str_store_string, 7, "str_not_happy"),
  40113. (else_try),
  40114. (str_store_string, 7, "str_miserable"),
  40115. (try_end),
  40116.  
  40117.  
  40118. (try_begin),
  40119. (lt, ":personality_grievances", 3),
  40120. (str_store_string, 6, "str_happy"),
  40121. (else_try),
  40122. (lt, ":personality_grievances", 15),
  40123. (str_store_string, 6, "str_content"),
  40124. (else_try),
  40125. (lt, ":personality_grievances", 30),
  40126. (str_store_string, 6, "str_concerned"),
  40127. (else_try),
  40128. (lt, ":personality_grievances", 45),
  40129. (str_store_string, 6, "str_not_happy"),
  40130. (else_try),
  40131. (str_store_string, 6, "str_miserable"),
  40132. (try_end),
  40133.  
  40134.  
  40135. (try_begin),
  40136. (gt, ":troop_morale", 80),
  40137. (str_store_string, 8, "str_happy"),
  40138. (str_store_string, 63, "str_bar_enthusiastic"),
  40139. (else_try),
  40140. (gt, ":troop_morale", 60),
  40141. (str_store_string, 8, "str_content"),
  40142. (str_store_string, 63, "str_bar_content"),
  40143. (else_try),
  40144. (gt, ":troop_morale", 40),
  40145. (str_store_string, 8, "str_concerned"),
  40146. (str_store_string, 63, "str_bar_weary"),
  40147. (else_try),
  40148. (gt, ":troop_morale", 20),
  40149. (str_store_string, 8, "str_not_happy"),
  40150. (str_store_string, 63, "str_bar_disgruntled"),
  40151. (else_try),
  40152. (str_store_string, 8, "str_miserable"),
  40153. (str_store_string, 63, "str_bar_miserable"),
  40154. (try_end),
  40155.  
  40156.  
  40157. (str_store_string, 21, "str_npc_morale_report"),
  40158. (assign, reg0, ":troop_morale"),
  40159.  
  40160. ]),
  40161. #NPC morale both returns a string and reg0 as the morale value
  40162.  
  40163.  
  40164. #
  40165. ("retire_companion",
  40166. [
  40167. (store_script_param_1, ":npc"),
  40168. (store_script_param_2, ":length"),
  40169.  
  40170. (remove_member_from_party, ":npc", "p_main_party"),
  40171. (troop_set_slot, ":npc", slot_troop_personalityclash_penalties, 0),
  40172. (troop_set_slot, ":npc", slot_troop_morality_penalties, 0),
  40173. (troop_get_slot, ":renown", "trp_player", slot_troop_renown),
  40174. (store_add, ":return_renown", ":renown", ":length"),
  40175. (troop_set_slot, ":npc", slot_troop_occupation, slto_retirement),
  40176. (troop_set_slot, ":npc", slot_troop_return_renown, ":return_renown"),
  40177. ]),
  40178.  
  40179. #NPC companion changes end
  40180.  
  40181. #script_reduce_companion_morale_for_clash
  40182. # INPUT: arg1 = troop_no for companion1 arg2 = troop_no for companion2 arg3 = slot_for_clash_state
  40183. # slot_for_clash_state means: 1=give full penalty to companion1; 2=give full penalty to companion2; 3=give penalty equally
  40184. ("reduce_companion_morale_for_clash",
  40185. [
  40186. (store_script_param, ":companion_1", 1),
  40187. (store_script_param, ":companion_2", 2),
  40188. (store_script_param, ":slot_for_clash_state", 3),
  40189.  
  40190. (troop_get_slot, ":clash_state", ":companion_1", ":slot_for_clash_state"),
  40191. (troop_get_slot, ":grievance_1", ":companion_1", slot_troop_personalityclash_penalties),
  40192. (troop_get_slot, ":grievance_2", ":companion_2", slot_troop_personalityclash_penalties),
  40193. (try_begin),
  40194. (eq, ":clash_state", pclash_penalty_to_self),
  40195. (val_add, ":grievance_1", 5),
  40196. (else_try),
  40197. (eq, ":clash_state", pclash_penalty_to_other),
  40198. (val_add, ":grievance_2", 5),
  40199. (else_try),
  40200. (eq, ":clash_state", pclash_penalty_to_both),
  40201. (val_add, ":grievance_1", 3),
  40202. (val_add, ":grievance_2", 3),
  40203. (try_end),
  40204. (troop_set_slot, ":companion_1", slot_troop_personalityclash_penalties, ":grievance_1"),
  40205. (troop_set_slot, ":companion_2", slot_troop_personalityclash_penalties, ":grievance_2"),
  40206. ]),
  40207.  
  40208. #Hunting scripts end
  40209.  
  40210. #script_calculate_ransom_amount_for_troop
  40211. # INPUT: arg1 = troop_no
  40212. # OUTPUT: reg0 = ransom_amount
  40213. ("calculate_ransom_amount_for_troop",
  40214. [(store_script_param, ":troop_no", 1),
  40215. (store_troop_faction, ":faction_no", ":troop_no"),
  40216. (assign, ":ransom_amount", 400),
  40217.  
  40218. (assign, ":male_relative", -9), #for kingdom ladies, otherwise a number otherwise unused in slot_town_lord
  40219. (try_begin),
  40220. (faction_slot_eq, ":faction_no", slot_faction_leader, ":troop_no"),
  40221. (val_add, ":ransom_amount", 4000),
  40222. (else_try),
  40223. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_lady),
  40224. (val_add, ":ransom_amount", 2500), #as though a renown of 1250 -- therefore significantly higher than for roughly equivalent lords
  40225. (call_script, "script_get_kingdom_lady_social_determinants", ":troop_no"),
  40226. (assign, ":male_relative", reg0),
  40227. (try_end),
  40228.  
  40229. (assign, ":num_center_points", 0),
  40230. (try_for_range, ":cur_center", centers_begin, centers_end),
  40231. (this_or_next|party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
  40232. (party_slot_eq, ":cur_center", slot_town_lord, ":male_relative"),
  40233. (try_begin),
  40234. (party_slot_eq, ":cur_center", slot_party_type, spt_town),
  40235. (val_add, ":num_center_points", 4),
  40236. (else_try),
  40237. (party_slot_eq, ":cur_center", slot_party_type, spt_castle),
  40238. (val_add, ":num_center_points", 2),
  40239. (else_try),
  40240. (val_add, ":num_center_points", 1),
  40241. (try_end),
  40242. (try_end),
  40243. (val_mul, ":num_center_points", 500),
  40244. (val_add, ":ransom_amount", ":num_center_points"),
  40245. (troop_get_slot, ":renown", ":troop_no", slot_troop_renown),
  40246. (val_mul, ":renown", 2),
  40247. (val_add, ":ransom_amount", ":renown"),
  40248. (store_mul, ":ransom_max_amount", ":ransom_amount", 3),
  40249. (val_div, ":ransom_max_amount", 2),
  40250. (store_random_in_range, ":random_ransom_amount", ":ransom_amount", ":ransom_max_amount"),
  40251. (val_div, ":random_ransom_amount", 100),
  40252. (val_mul, ":random_ransom_amount", 100),
  40253. (assign, reg0, ":random_ransom_amount"),
  40254. ]),
  40255.  
  40256. #script_offer_ransom_amount_to_player_for_prisoners_in_party
  40257. # INPUT: arg1 = party_no
  40258. # OUTPUT: reg0 = result (1 = offered, 0 = not offered)
  40259. ("offer_ransom_amount_to_player_for_prisoners_in_party",
  40260. [(store_script_param, ":party_no", 1),
  40261. (assign, ":result", 0),
  40262. (party_get_num_prisoner_stacks, ":num_stacks", ":party_no"),
  40263. (try_for_range, ":i_stack", 0, ":num_stacks"),
  40264. (eq, ":result", 0),
  40265. (party_prisoner_stack_get_troop_id, ":stack_troop", ":party_no", ":i_stack"),
  40266. (troop_is_hero, ":stack_troop"),
  40267. (this_or_next|troop_slot_eq, ":stack_troop", slot_troop_occupation, slto_kingdom_hero),
  40268. (troop_slot_eq, ":stack_troop", slot_troop_occupation, slto_kingdom_lady),
  40269. (store_troop_faction, ":stack_troop_faction", ":stack_troop"),
  40270. (store_random_in_range, ":random_no", 0, 100),
  40271. (try_begin),
  40272. (faction_slot_eq, ":stack_troop_faction", slot_faction_state, sfs_active),
  40273. (le, ":random_no", 5),
  40274. (neq, "$g_ransom_offer_rejected", 1),
  40275. (assign, ":num_stacks", 0), #break
  40276. (assign, ":result", 1),
  40277. (assign, "$g_ransom_offer_troop", ":stack_troop"),
  40278. (assign, "$g_ransom_offer_party", ":party_no"),
  40279. (jump_to_menu, "mnu_enemy_offer_ransom_for_prisoner"),
  40280. (try_end),
  40281. (try_end),
  40282.  
  40283. #SB : offer ransom for kingdom ladies as per conditions in dialogues
  40284. (try_begin),
  40285. (is_between, ":party_no", walled_centers_begin, walled_centers_end),
  40286. (assign, ":end", kingdom_ladies_end),
  40287. (store_faction_of_party, ":faction_no", ":party_no"),
  40288. (try_for_range, ":heroes", kingdom_ladies_begin, ":end"),
  40289. (troop_slot_eq, ":heroes", slot_troop_cur_center, ":party_no"),
  40290. (troop_slot_eq, ":heroes", slot_troop_prisoner_of_party, ":party_no"),
  40291. (troop_slot_eq, ":heroes", slot_troop_occupation, slto_kingdom_lady),
  40292. (store_faction_of_troop, ":lady_faction", ":heroes"),
  40293. (neq, ":lady_faction", ":faction_no"),
  40294. (faction_slot_eq, ":lady_faction", slot_faction_state, sfs_active),
  40295. (store_random_in_range, ":random_no", 0, 100),
  40296. (le, ":random_no", 5),
  40297. (neq, "$g_ransom_offer_rejected", 1),
  40298. (assign, ":end", 0), #break
  40299. (assign, ":result", 1),
  40300. (assign, "$g_ransom_offer_troop", ":heroes"),
  40301. (assign, "$g_ransom_offer_party", ":party_no"),
  40302. (jump_to_menu, "mnu_enemy_offer_ransom_for_prisoner"),
  40303. (try_end),
  40304. (try_end),
  40305. (assign, reg0, ":result"),
  40306. ]),
  40307.  
  40308. # script_event_hero_taken_prisoner_by_player
  40309. # Input: arg1 = troop_no
  40310. # Output: none
  40311. ("event_hero_taken_prisoner_by_player",
  40312. [
  40313. (store_script_param_1, ":troop_no"),
  40314. (try_begin),
  40315. (check_quest_active, "qst_persuade_lords_to_make_peace"),
  40316. (try_begin),
  40317. (quest_slot_eq, "qst_persuade_lords_to_make_peace", slot_quest_target_troop, ":troop_no"),
  40318. (val_mul, ":troop_no", -1),
  40319. (quest_set_slot, "qst_persuade_lords_to_make_peace", slot_quest_target_troop, ":troop_no"),
  40320. (val_mul, ":troop_no", -1),
  40321. (else_try),
  40322. (quest_slot_eq, "qst_persuade_lords_to_make_peace", slot_quest_object_troop, ":troop_no"),
  40323. (val_mul, ":troop_no", -1),
  40324. (quest_set_slot, "qst_persuade_lords_to_make_peace", slot_quest_object_troop, ":troop_no"),
  40325. (val_mul, ":troop_no", -1),
  40326. (try_end),
  40327. (neg|check_quest_concluded, "qst_persuade_lords_to_make_peace"),
  40328. (neg|quest_slot_ge, "qst_persuade_lords_to_make_peace", slot_quest_target_troop, 0),
  40329. (neg|quest_slot_ge, "qst_persuade_lords_to_make_peace", slot_quest_object_troop, 0),
  40330. (call_script, "script_succeed_quest", "qst_persuade_lords_to_make_peace"),
  40331. (try_end),
  40332. (call_script, "script_update_troop_location_notes", ":troop_no", 0),
  40333. ]),
  40334.  
  40335. # script_cf_check_hero_can_escape_from_player
  40336. # Input: arg1 = troop_no
  40337. # Output: none (can fail)
  40338. ("cf_check_hero_can_escape_from_player",
  40339. [
  40340. (store_script_param_1, ":troop_no"),
  40341. (assign, ":quest_target", 0),
  40342. (try_begin),
  40343. (check_quest_active, "qst_persuade_lords_to_make_peace"),
  40344. (this_or_next|quest_slot_eq, "qst_persuade_lords_to_make_peace", slot_quest_target_troop, ":troop_no"),
  40345. (quest_slot_eq, "qst_persuade_lords_to_make_peace", slot_quest_object_troop, ":troop_no"),
  40346. (assign, ":quest_target", 1),
  40347. (else_try),
  40348. (ge, ":troop_no", "trp_sea_raider_leader"),
  40349. (lt, ":troop_no", "trp_bandit_leaders_end"),
  40350. (try_begin),
  40351. (check_quest_active, "qst_learn_where_merchant_brother_is"),
  40352. (assign, ":quest_target", 1), #always catched
  40353. (else_try),
  40354. (assign, ":quest_target", -1), #always run.
  40355. (try_end),
  40356. (try_end),
  40357.  
  40358. (assign, ":continue", 0),
  40359. (try_begin),
  40360. (eq, ":quest_target", 0), #if not quest target
  40361. (store_random_in_range, ":rand", 0, 100),
  40362. (lt, ":rand", hero_escape_after_defeat_chance),
  40363. (assign, ":continue", 1),
  40364. (else_try),
  40365. (eq, ":quest_target", -1), #if (always run) quest target
  40366. (assign, ":continue", 1),
  40367. (try_end),
  40368.  
  40369. (eq, ":continue", 1),
  40370. ]),
  40371.  
  40372. # script_cf_party_remove_random_regular_troop
  40373. # Input: arg1 = party_no
  40374. # Output: troop_id that has been removed (can fail)
  40375. ("cf_party_remove_random_regular_troop",
  40376. [(store_script_param_1, ":party_no"),
  40377. (party_get_num_companion_stacks, ":num_stacks", ":party_no"),
  40378. (assign, ":num_troops", 0),
  40379. (try_for_range, ":i_stack", 0, ":num_stacks"),
  40380. (party_stack_get_troop_id, ":stack_troop", ":party_no", ":i_stack"),
  40381. (neg|troop_is_hero, ":stack_troop"),
  40382. (party_stack_get_size, ":stack_size", ":party_no", ":i_stack"),
  40383. (val_add, ":num_troops", ":stack_size"),
  40384. (try_end),
  40385. (assign, reg0, -1),
  40386. (gt, ":num_troops", 0),
  40387. (store_random_in_range, ":random_troop", 0, ":num_troops"),
  40388. (try_for_range, ":i_stack", 0, ":num_stacks"),
  40389. (party_stack_get_troop_id, ":stack_troop", ":party_no", ":i_stack"),
  40390. (neg|troop_is_hero, ":stack_troop"),
  40391. (party_stack_get_size, ":stack_size", ":party_no", ":i_stack"),
  40392. (val_sub, ":random_troop", ":stack_size"),
  40393. (lt, ":random_troop", 0),
  40394. (assign, ":num_stacks", 0), #break
  40395. (party_remove_members, ":party_no", ":stack_troop", 1),
  40396. (assign, reg0, ":stack_troop"),
  40397. (try_end),
  40398. ]),
  40399.  
  40400. # script_place_player_banner_near_inventory
  40401. # Input: none
  40402. # Output: none
  40403. ("place_player_banner_near_inventory",
  40404. [
  40405. #normal_banner_begin
  40406. (troop_get_slot, ":troop_banner_object", "trp_player", slot_troop_banner_scene_prop),
  40407. #custom_banner_begin
  40408. # (troop_get_slot, ":flag_spr", "trp_player", slot_troop_custom_banner_flag_type),
  40409.  
  40410. (try_begin),
  40411. #normal_banner_begin
  40412. (gt, ":troop_banner_object", 0),
  40413. (scene_prop_get_instance, ":flag_object", ":troop_banner_object", 0),
  40414. #custom_banner_begin
  40415. # (ge, ":flag_spr", 0),
  40416. # (val_add, ":flag_spr", custom_banner_flag_scene_props_begin),
  40417. # (scene_prop_get_instance, ":flag_object", ":flag_spr", 0),
  40418. (try_begin),
  40419. (ge, ":flag_object", 0),
  40420. (get_player_agent_no, ":player_agent"),
  40421. (agent_get_look_position, pos1, ":player_agent"),
  40422. (position_move_y, pos1, -500),
  40423. (position_rotate_z, pos1, 180),
  40424. (position_set_z_to_ground_level, pos1),
  40425. (position_move_z, pos1, 300),
  40426. (prop_instance_set_position, ":flag_object", pos1),
  40427. (try_end),
  40428. (scene_prop_get_instance, ":pole_object", "spr_banner_pole", 0),
  40429. (try_begin),
  40430. (ge, ":pole_object", 0),
  40431. (position_move_z, pos1, -320),
  40432. (prop_instance_set_position, ":pole_object", pos1),
  40433. (try_end),
  40434. (else_try),
  40435. (init_position, pos1),
  40436. (position_move_z, pos1, -1000000),
  40437. (scene_prop_get_instance, ":flag_object", banner_scene_props_begin, 0),
  40438. (try_begin),
  40439. (ge, ":flag_object", 0),
  40440. (prop_instance_set_position, ":flag_object", pos1),
  40441. (try_end),
  40442. (scene_prop_get_instance, ":pole_object", "spr_banner_pole", 0),
  40443. (try_begin),
  40444. (ge, ":pole_object", 0),
  40445. (prop_instance_set_position, ":pole_object", pos1),
  40446. (try_end),
  40447. (try_end),
  40448. ]),
  40449.  
  40450. # script_place_player_banner_near_inventory_bms
  40451. # Input: none
  40452. # Output: none
  40453. ("place_player_banner_near_inventory_bms",
  40454. [
  40455. #normal_banner_begin
  40456. (troop_get_slot, ":troop_banner_object", "trp_player", slot_troop_banner_scene_prop),
  40457. #custom_banner_begin
  40458. # (troop_get_slot, ":flag_spr", "trp_player", slot_troop_custom_banner_flag_type),
  40459. (try_begin),
  40460. #normal_banner_begin
  40461. (gt, ":troop_banner_object", 0),
  40462. (replace_scene_props, banner_scene_props_begin, ":troop_banner_object"),
  40463. #custom_banner_begin
  40464. # (ge, ":flag_spr", 0),
  40465. # (val_add, ":flag_spr", custom_banner_flag_scene_props_begin),
  40466. # (replace_scene_props, banner_scene_props_begin, ":flag_spr"),
  40467. (try_end),
  40468. ]),
  40469.  
  40470. # script_stay_captive_for_hours
  40471. # Input: arg1 = num_hours
  40472. # Output: none
  40473. ("stay_captive_for_hours",
  40474. [
  40475. (store_script_param, ":num_hours", 1),
  40476. (store_current_hours, ":cur_hours"),
  40477. (val_add, ":cur_hours", ":num_hours"),
  40478. (val_max, "$g_check_autos_at_hour", ":cur_hours"),
  40479. (val_add, ":num_hours", 1),
  40480. (rest_for_hours, ":num_hours", 0, 0),
  40481. ]),
  40482.  
  40483. # script_set_parties_around_player_ignore_player
  40484. # Input: arg1 = ignore_range, arg2 = num_hours_to_ignore
  40485. # Output: none
  40486. ("set_parties_around_player_ignore_player",
  40487. [(store_script_param, ":ignore_range", 1),
  40488. (store_script_param, ":num_hours", 2),
  40489. (try_for_parties, ":party_no"),
  40490. (party_is_active, ":party_no"),
  40491. (store_distance_to_party_from_party, ":dist", "p_main_party", ":party_no"),
  40492. (lt, ":dist", ":ignore_range"),
  40493. (party_ignore_player, ":party_no", ":num_hours"),
  40494. (try_end),
  40495. ]),
  40496.  
  40497. # script_randomly_make_prisoner_heroes_escape_from_party
  40498. # Input: arg1 = party_no, arg2 = escape_chance_mul_1000
  40499. # Output: none
  40500. ("randomly_make_prisoner_heroes_escape_from_party",
  40501. [(store_script_param, ":party_no", 1),
  40502. (store_script_param, ":escape_chance", 2),
  40503. (assign, ":quest_troop_1", -1),
  40504. (assign, ":quest_troop_2", -1),
  40505. (try_begin),
  40506. (check_quest_active, "qst_rescue_lord_by_replace"),
  40507. (quest_get_slot, ":quest_troop_1", "qst_rescue_lord_by_replace", slot_quest_target_troop),
  40508. (try_end),
  40509. (try_begin),
  40510. (check_quest_active, "qst_deliver_message_to_prisoner_lord"),
  40511. (quest_get_slot, ":quest_troop_2", "qst_deliver_message_to_prisoner_lord", slot_quest_target_troop),
  40512. (try_end),
  40513. (party_get_num_prisoner_stacks, ":num_stacks", ":party_no"),
  40514. (try_for_range_backwards, ":i_stack", 0, ":num_stacks"),
  40515. (party_prisoner_stack_get_troop_id, ":stack_troop", ":party_no", ":i_stack"),
  40516. (troop_is_hero, ":stack_troop"),
  40517. (neq, ":stack_troop", ":quest_troop_1"),
  40518. (neq, ":stack_troop", ":quest_troop_2"),
  40519. (troop_slot_eq, ":stack_troop", slot_troop_occupation, slto_kingdom_hero),
  40520. (store_random_in_range, ":random_no", 0, 1000),
  40521. (lt, ":random_no", ":escape_chance"),
  40522. (party_remove_prisoners, ":party_no", ":stack_troop", 1),
  40523. (call_script, "script_remove_troop_from_prison", ":stack_troop"),
  40524. (str_store_troop_name_link, s1, ":stack_troop"),
  40525. (try_begin),
  40526. (eq, ":party_no", "p_main_party"),
  40527. (str_store_string, s2, "@your party"),
  40528. (else_try),
  40529. (str_store_party_name, s2, ":party_no"),
  40530. (try_end),
  40531. (assign, reg0, 0),
  40532. (try_begin),
  40533. (this_or_next|eq, ":party_no", "p_main_party"),
  40534. (party_slot_eq, ":party_no", slot_town_lord, "trp_player"),
  40535. (assign, reg0, 1),
  40536. (try_end),
  40537. (store_troop_faction, ":troop_faction", ":stack_troop"),
  40538. (str_store_faction_name_link, s3, ":troop_faction"),
  40539. (faction_get_color, ":color", ":troop_faction"),
  40540. #SB : factionalize color, set to log
  40541. (display_log_message, "@{reg0?One of your prisoners, :}{s1} of {s3} has escaped from captivity!", ":color"),
  40542. (try_end),
  40543. ]),
  40544.  
  40545.  
  40546. # script_fill_tournament_participants_troop
  40547. # Input: arg1 = center_no, arg2 = player_at_center
  40548. # Output: none (fills trp_tournament_participants)
  40549. ("fill_tournament_participants_troop",
  40550. [
  40551. (store_script_param, ":center_no", 1),
  40552. (store_script_param, ":player_at_center", 2),
  40553. (assign, ":cur_slot", 0),
  40554.  
  40555. (try_begin),
  40556. (eq, ":player_at_center", 1),
  40557. (troop_set_slot, "trp_tournament_participants", 0, "trp_player"), #we add the player
  40558. (val_add, ":cur_slot", 1),
  40559. (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  40560. (try_begin), #add adventuring spouse
  40561. (troop_get_slot, ":spouse", "trp_player", slot_troop_spouse),
  40562. (ge, ":spouse", active_npcs_begin),
  40563. (main_party_has_troop, ":spouse"),
  40564. (neg|troop_is_wounded, ":spouse"),
  40565. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":spouse"),
  40566. (val_add, ":cur_slot", 1),
  40567. (try_end),
  40568. #SB : add in companions
  40569. (try_for_range, ":companion_candidate", companions_begin, companions_end),
  40570.  
  40571. (assign, ":continue", 0),
  40572. (try_begin), #player pays entrance fee
  40573. (main_party_has_troop, ":companion_candidate"),
  40574. (assign, ":continue", 1),
  40575. (else_try), #same conditions as below
  40576. (troop_slot_eq, ":companion_candidate", slot_troop_cur_center, ":center_no"),
  40577. (troop_slot_ge, ":companion_candidate", slot_troop_renown, 100),
  40578. (assign, ":continue", 1),
  40579. (try_end),
  40580.  
  40581. (try_begin), #disqualify from health/imprisonment
  40582. (this_or_next|troop_is_wounded, ":companion_candidate"),
  40583. (troop_slot_ge, ":companion_candidate", slot_troop_prisoner_of_party, centers_begin),
  40584. (assign, ":continue", 0),
  40585. (try_end),
  40586. (eq, ":continue", 1),
  40587.  
  40588. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":companion_candidate"),
  40589. # (call_script, "script_join_tournament", ":companion_candidate"),
  40590. (val_add, ":cur_slot", 1),
  40591. (try_end),
  40592.  
  40593. # (try_for_range, ":stack_no", 0, ":num_stacks"),
  40594. # (party_stack_get_troop_id, ":cur_troop", "p_main_party", ":stack_no"),
  40595. # (troop_is_hero, ":cur_troop"),
  40596. # (neq, ":cur_troop", "trp_kidnapped_girl"),
  40597. # (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":cur_troop"),
  40598. # (val_add, ":cur_slot", 1),
  40599. # (try_end),
  40600. (else_try), #noble companions with starting renown > 100 can participate
  40601. (eq, ":player_at_center", 0),
  40602. (try_for_range, ":companion_candidate", companions_begin, companions_end),
  40603. #this is handled by having their parties be in town
  40604. (neg|troop_slot_eq, ":companion_candidate", slot_troop_occupation, slto_kingdom_hero),
  40605. (troop_slot_eq, ":companion_candidate", slot_troop_cur_center, ":center_no"),
  40606. (troop_slot_ge, ":companion_candidate", slot_troop_renown, 100), #rofl, alayen, etc
  40607. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":companion_candidate"),
  40608. (val_add, ":cur_slot", 1),
  40609. (try_end),
  40610.  
  40611. (try_end),
  40612.  
  40613. #SB : add in pretender who would want renown bonus
  40614. (try_begin),
  40615. (is_between, "$supported_pretender", pretenders_begin, pretenders_end),
  40616. (eq, ":player_at_center", 1),
  40617. (main_party_has_troop, "$supported_pretender"),
  40618. (troop_set_slot, "trp_tournament_participants", ":cur_slot", "$supported_pretender"),
  40619. (val_add, ":cur_slot", 1),
  40620. (try_end),
  40621. (try_for_range, ":pretender", pretenders_begin, pretenders_end),
  40622. # (neq, ":pretender", "$supported_pretender"),
  40623. # (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  40624. (troop_slot_eq, ":pretender", slot_troop_cur_center, ":center_no"),
  40625. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":pretender"),
  40626. (val_add, ":cur_slot", 1),
  40627. (try_end),
  40628. (party_collect_attachments_to_party, ":center_no", "p_temp_party"),
  40629. (party_get_num_companion_stacks, ":num_stacks", "p_temp_party"),
  40630. (try_for_range, ":stack_no", 0, ":num_stacks"),
  40631. (party_stack_get_troop_id, ":cur_troop", "p_temp_party", ":stack_no"),
  40632. (troop_is_hero, ":cur_troop"),
  40633. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":cur_troop"),
  40634. (val_add, ":cur_slot", 1),
  40635. (try_end),
  40636.  
  40637. # (try_begin),
  40638. # (store_random_in_range, ":random_no", 0, 100),
  40639. # (lt, ":random_no", 50),
  40640. # (troop_set_slot, "trp_tournament_participants", ":cur_slot", "trp_xerina"),
  40641. # (val_add, ":cur_slot", 1),
  40642. # (try_end),
  40643. # (try_begin),
  40644. # (store_random_in_range, ":random_no", 0, 100),
  40645. # (lt, ":random_no", 50),
  40646. # (troop_set_slot, "trp_tournament_participants", ":cur_slot", "trp_dranton"),
  40647. # (val_add, ":cur_slot", 1),
  40648. # (try_end),
  40649. # (try_begin),
  40650. # (store_random_in_range, ":random_no", 0, 100),
  40651. # (lt, ":random_no", 50),
  40652. # (troop_set_slot, "trp_tournament_participants", ":cur_slot", "trp_kradus"),
  40653. # (val_add, ":cur_slot", 1),
  40654. # (try_end),
  40655. #SB : recalculate chances
  40656. (store_add, ":heroes_limit", ":cur_slot", 5),
  40657. (val_min, ":heroes_limit", 64),
  40658. (try_for_range, ":hero", tournament_champions_begin, tournament_champions_end),
  40659. # (neg|troop_is_wounded, ":hero"),
  40660. (store_troop_health, ":health", ":hero", 0),
  40661. (gt, ":health", 10),
  40662. (store_random_in_range, ":random_no", 0, 6),
  40663. (troop_set_slot, ":hero", slot_troop_cur_center, -1),
  40664. (troop_set_slot, ":hero", slot_lady_used_tournament, -1),
  40665.  
  40666. (try_begin),
  40667. (lt, ":random_no", 2),
  40668. (lt, ":cur_slot", ":heroes_limit"),
  40669. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":hero"),
  40670. # (try_begin),
  40671. # (is_between, ":hero", quick_battle_troops_original_begin, quick_battle_troops_tournament_end),
  40672. # (troop_set_slot, ":hero", slot_troop_cur_center, ":center_no"),
  40673. # (try_end),
  40674. (val_add, ":cur_slot", 1),
  40675. #add some health too
  40676. (val_mul, ":random_no", 10),
  40677. (val_add, ":health", ":random_no"),
  40678. (troop_set_health, ":hero", ":health"),
  40679. (try_end),
  40680. (try_end),
  40681. ##SB : random quick-battle heroes (20% each x 11) at full health, capped to 5 per tourney to not saturate
  40682. (try_for_range, ":hero", quick_battle_troops_begin, quick_battle_troops_end),
  40683. (lt, ":cur_slot", ":heroes_limit"),
  40684. (store_random_in_range, ":random_no", 0, 5),
  40685. (try_begin),
  40686. (eq, ":random_no", 0),
  40687. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":hero"),
  40688. (troop_set_health, ":hero", ":health"),
  40689. (val_add, ":cur_slot", 1),
  40690. (try_end),
  40691. (try_end),
  40692. (assign, ":begin_slot", ":cur_slot"),
  40693.  
  40694. #SB : set up flavour troops (town mercenary, sword sister alternatives)
  40695. (party_get_slot, ":town_merc", ":center_no", slot_center_mercenary_troop_type),
  40696. (party_get_slot, ":merc_amount", ":center_no", slot_center_mercenary_troop_amount),
  40697. (val_mul, ":merc_amount", 2),
  40698. (val_div, ":merc_amount", 3),
  40699.  
  40700. (store_faction_of_party, ":town_faction", ":center_no"),
  40701. #alternatively check if other female heroes are present and allow sword sisters?
  40702.  
  40703. #might need to test for male prejudice against hired blades?
  40704. (try_begin),
  40705. (call_script, "script_cf_dplmc_faction_has_bias_against_gender", ":town_faction", tf_female),
  40706. (assign, ":sword_sister", -1),
  40707. (else_try),
  40708. (assign, ":sword_sister", "trp_sword_sister"),
  40709. (try_end),
  40710. (try_for_range, ":cur_slot", ":begin_slot", 64),
  40711. (store_random_in_range, ":random_no", 0, 6),
  40712. (try_begin),
  40713. (eq, ":random_no", 0),
  40714. (troop_set_slot, "trp_tournament_participants", ":cur_slot", "trp_regular_fighter"),
  40715. (else_try),
  40716. (eq, ":random_no", 1),
  40717. (troop_set_slot, "trp_tournament_participants", ":cur_slot", "trp_veteran_fighter"),
  40718. (else_try),
  40719. (eq, ":random_no", 2),
  40720. (troop_set_slot, "trp_tournament_participants", ":cur_slot", "trp_champion_fighter"),
  40721. (else_try),
  40722. (eq, ":random_no", 3),
  40723. (try_begin),
  40724. (eq, ":sword_sister", -1),
  40725. (store_random_in_range, ":slot_no", slot_faction_tier_2_troop, slot_faction_tier_5_troop + 1),
  40726. (faction_get_slot, ":troop_no", ":town_faction", ":slot_no"),
  40727. (gt, ":troop_no", 0),
  40728. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":troop_no"),
  40729. (else_try),
  40730. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":sword_sister"),
  40731. (try_end),
  40732. (else_try),
  40733. (eq, ":random_no", 4),
  40734. (troop_set_slot, "trp_tournament_participants", ":cur_slot", "trp_hired_blade"),
  40735. (else_try), #SB : use current town mercenary (if any remaining)
  40736. (eq, ":random_no", 5),
  40737. (gt, ":merc_amount", 0),
  40738. (val_sub, ":merc_amount", 1),
  40739. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":town_merc"),
  40740. (else_try), #otherwise fallback to random mercenary participant
  40741. (store_random_in_range, ":merc", mercenary_troops_begin, mercenary_troops_end),
  40742. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":merc"),
  40743. (try_end),
  40744. (try_end),
  40745. ]),
  40746.  
  40747. # script_get_num_tournament_participants
  40748. # Input: none
  40749. # Output: reg0 = num_participants
  40750. ("get_num_tournament_participants",
  40751. [(assign, ":num_participants", 0),
  40752. (try_for_range, ":cur_slot", 0, 64),
  40753. (troop_slot_ge, "trp_tournament_participants", ":cur_slot", 0),
  40754. (val_add, ":num_participants", 1),
  40755. (try_end),
  40756. (assign, reg0, ":num_participants"),
  40757. ]),
  40758.  
  40759. # script_get_random_tournament_participant
  40760. # Input: none
  40761. # Output: reg0 = troop_no
  40762. ("get_random_tournament_participant",
  40763. [(call_script, "script_get_num_tournament_participants"),
  40764. (assign, ":num_participants", reg0),
  40765. (store_random_in_range, ":random_troop", 0, ":num_participants"),
  40766. (assign, ":continue", 1),
  40767. (try_for_range, ":cur_slot", 0, 64),
  40768. (eq, ":continue", 1),
  40769. (troop_slot_ge, "trp_tournament_participants", ":cur_slot", 0),
  40770. (val_sub, ":random_troop", 1),
  40771. (lt, ":random_troop", 0),
  40772. (assign, ":continue", 0),
  40773. (troop_get_slot, ":troop_no", "trp_tournament_participants", ":cur_slot"),
  40774. (troop_set_slot, "trp_tournament_participants", ":cur_slot", -1),
  40775. (try_end),
  40776. (assign, reg0, ":troop_no"),
  40777. ]),
  40778.  
  40779. # script_add_tournament_participant
  40780. # Input: arg1 = troop_no
  40781. # Output: none
  40782. ("add_tournament_participant",
  40783. [(store_script_param, ":troop_no", 1),
  40784. (assign, ":continue", 1),
  40785. (try_for_range, ":cur_slot", 0, 64),
  40786. (eq, ":continue", 1),
  40787. (troop_slot_eq, "trp_tournament_participants", ":cur_slot", -1),
  40788. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":troop_no"),
  40789. (assign, ":continue", 0),
  40790. (try_end),
  40791. ]),
  40792.  
  40793. # script_get_random_tournament_team_amount_and_size
  40794. # Input: none
  40795. # Output: reg0 = number_of_teams, reg1 = team_size
  40796. ("get_random_tournament_team_amount_and_size",
  40797. [
  40798. (call_script, "script_get_num_tournament_participants"),
  40799. (assign, ":num_participants", reg0),
  40800. (party_get_slot, ":town_max_teams", "$current_town", slot_town_tournament_max_teams),
  40801. (val_add, ":town_max_teams", 1),
  40802. (party_get_slot, ":town_max_team_size", "$current_town", slot_town_tournament_max_team_size),
  40803. (val_add, ":town_max_team_size", 1),
  40804. (assign, ":max_teams", ":num_participants"),
  40805. (val_min, ":max_teams", ":town_max_teams"),
  40806. (assign, ":max_size", ":num_participants"),
  40807. (val_min, ":max_size", ":town_max_team_size"),
  40808. (assign, ":min_size", 1),
  40809. (try_begin),
  40810. (ge, ":num_participants", 32),
  40811. (assign, ":min_size", 2),
  40812. (val_min, ":min_size", ":town_max_team_size"),
  40813. (try_end),
  40814. (assign, ":end_cond", 500),
  40815. (try_for_range, ":unused", 0, ":end_cond"),
  40816. (store_random_in_range, ":random_teams", 2, ":max_teams"),
  40817. (store_random_in_range, ":random_size", ":min_size", ":max_size"),
  40818. (store_mul, ":total_men", ":random_teams", ":random_size"),
  40819. (le, ":total_men", ":num_participants"),
  40820. (store_sub, ":left_men", ":num_participants", ":total_men"),
  40821. (neq, ":left_men", 1),
  40822. (assign, ":end_cond", 0),
  40823. (try_end),
  40824. (try_begin),
  40825. (gt, ":end_cond", 0),
  40826. (assign, ":random_teams", 2),
  40827. (assign, ":random_size", 1),
  40828. (try_end),
  40829. (assign, reg0, ":random_teams"),
  40830. (assign, reg1, ":random_size"),
  40831. ]),
  40832.  
  40833. # script_get_troop_priority_point_for_tournament
  40834. # Input: arg1 = troop_no
  40835. # Output: reg0 = troop_point
  40836. ("get_troop_priority_point_for_tournament",
  40837. [(store_script_param, ":troop_no", 1),
  40838. (assign, ":troop_point", 0),
  40839. (try_begin),
  40840. (ge, ":troop_no", 0),
  40841. (val_add, ":troop_point", 40000),
  40842. (try_begin),
  40843. (eq, ":troop_no", "trp_player"),
  40844. (val_add, ":troop_point", 80000),
  40845. (try_end),
  40846. (try_begin),
  40847. (troop_is_hero, ":troop_no"),
  40848. (val_add, ":troop_point", 20000),
  40849. (try_end),
  40850. (try_begin),
  40851. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_player_companion),
  40852. (val_add, ":troop_point", 10000),
  40853. (else_try),
  40854. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  40855. (troop_get_slot, ":renown", ":troop_no", slot_troop_renown),
  40856. (val_add, ":troop_point", ":renown"),
  40857. (val_add, ":troop_point", 1000), #in order to make it more prior than tournament heroes with higher levels
  40858. (else_try),
  40859. (store_character_level, ":level", ":troop_no"),
  40860. (val_add, ":troop_point", ":level"),
  40861. (try_end),
  40862. (try_end),
  40863. (assign, reg0, ":troop_point"),
  40864. ]),
  40865.  
  40866. # script_sort_tournament_participant_troops
  40867. # Input: none
  40868. # Output: none (sorts trp_tournament_participants)
  40869. ("sort_tournament_participant_troops",
  40870. [(try_for_range, ":cur_slot", 0, 63),
  40871. (store_add, ":cur_slot_2_begin", ":cur_slot", 1),
  40872. (try_for_range, ":cur_slot_2", ":cur_slot_2_begin", 64),
  40873. (troop_get_slot, ":troop_1", "trp_tournament_participants", ":cur_slot"),
  40874. (troop_get_slot, ":troop_2", "trp_tournament_participants", ":cur_slot_2"),
  40875. (call_script, "script_get_troop_priority_point_for_tournament", ":troop_1"),
  40876. (assign, ":troop_1_point", reg0),
  40877. (call_script, "script_get_troop_priority_point_for_tournament", ":troop_2"),
  40878. (assign, ":troop_2_point", reg0),
  40879. (gt, ":troop_2_point", ":troop_1_point"),
  40880. (troop_set_slot, "trp_tournament_participants", ":cur_slot", ":troop_2"),
  40881. (troop_set_slot, "trp_tournament_participants", ":cur_slot_2", ":troop_1"),
  40882. (try_end),
  40883. (try_end),
  40884. ]),
  40885.  
  40886. # script_remove_tournament_participants_randomly
  40887. # Input: arg1 = number_to_be_removed
  40888. # Output: none
  40889. ("remove_tournament_participants_randomly",
  40890. [(store_script_param, ":number_to_be_removed", 1),
  40891. #SB : TODO simulate tournament fighting relationship changes
  40892. (try_for_range, ":unused", 0, ":number_to_be_removed"),
  40893. (assign, ":total_weight", 0),
  40894. (try_for_range, ":cur_slot", 0, 64),
  40895. (troop_get_slot, ":troop_no", "trp_tournament_participants", ":cur_slot"),
  40896. (ge, ":troop_no", 0),
  40897. (store_character_level, ":level", ":troop_no"),
  40898. (val_min, ":level", 38),
  40899. (store_sub, ":weight", 40, ":level"),
  40900. (val_add, ":total_weight", ":weight"),
  40901. (try_end),
  40902. (store_random_in_range, ":random_weight", 0, ":total_weight"),
  40903. (assign, ":continue", 1),
  40904. (try_for_range, ":cur_slot", 0, 64),
  40905. (eq, ":continue", 1),
  40906. (troop_get_slot, ":troop_no", "trp_tournament_participants", ":cur_slot"),
  40907. (ge, ":troop_no", 0),
  40908. (store_character_level, ":level", ":troop_no"),
  40909. (val_min, ":level", 38),
  40910. (store_sub, ":weight", 40, ":level"),
  40911. (val_sub, ":random_weight", ":weight"),
  40912. (lt, ":random_weight", 0),
  40913. (troop_set_slot, "trp_tournament_participants", ":cur_slot", -1),
  40914. (assign, ":continue", 0),
  40915. (try_end),
  40916. (try_end),
  40917. ]),
  40918.  
  40919. # script_end_tournament_fight
  40920. # Input: arg1 = player_team_won (1 or 0)
  40921. # Output: none
  40922. ("end_tournament_fight",
  40923. [
  40924. (store_script_param, ":player_team_won", 1),
  40925. (call_script, "script_get_num_tournament_participants"),
  40926. (assign, ":num_participants", reg0),
  40927. (store_div, ":needed_to_remove_randomly", ":num_participants", 2),
  40928. #Must remove other participants randomly earlier than adding the winners back to participants
  40929. (call_script, "script_remove_tournament_participants_randomly", ":needed_to_remove_randomly"),
  40930.  
  40931. #SB : because we've added relationship losses, we'll also add this here
  40932. (store_div, ":relation", "$g_tournament_cur_tier", 2),
  40933. (assign, ":num_needed", "$g_tournament_num_participants_for_fight"),
  40934. (val_div, ":num_needed", 2),
  40935. (get_player_agent_no, ":player_agent"),
  40936. (agent_get_team, ":player_team", ":player_agent"),
  40937. (try_for_agents, ":agent_no"),
  40938. (agent_is_human, ":agent_no"),
  40939. (agent_get_troop_id, ":troop_id", ":agent_no"),
  40940. (neg|is_between, ":troop_id", arena_masters_begin, arena_masters_end),#omit tournament master
  40941. (agent_get_team, ":agent_team", ":agent_no"),
  40942. (assign, ":cur_point", 0),
  40943. (try_begin),
  40944. (eq, ":player_team_won", 1),
  40945. (eq, ":agent_team", ":player_team"),
  40946. (val_add, ":cur_point", 5000000),#Make sure that team members are chosen
  40947. #SB : apply relationship bonus here
  40948. (agent_is_alive, ":agent_no"),
  40949. (troop_is_hero, ":troop_id"),
  40950. (try_begin), #player's companions, change their morale penalty
  40951. (troop_slot_eq, ":troop_id", slot_troop_occupation, slto_player_companion),
  40952. (troop_get_slot, ":grievance", ":troop_id", slot_troop_personalityclash_penalties),
  40953. (val_sub, ":grievance", "$g_tournament_cur_tier"),
  40954. (troop_set_slot, ":troop_id", slot_troop_personalityclash_penalties, ":grievance"),
  40955. (else_try), #friendly lords, less will have this bonus as the tiers increase
  40956. (call_script, "script_change_player_relation_with_troop", ":troop_id", ":relation"),
  40957. (try_end),
  40958. (try_end),
  40959. (agent_get_kill_count, ":kill_count", ":agent_no", 1), #everyone is knocked unconscious
  40960. (store_mul, ":kill_point", ":kill_count", 160000),#Make sure that kill count is the second most important variable
  40961. (val_add, ":cur_point", ":kill_point"),
  40962. (call_script, "script_get_troop_priority_point_for_tournament", ":troop_id"),
  40963. (val_add, ":cur_point", reg0),
  40964. (try_begin),#reset player's point if kill count is one after the first 2 rounds, or if it is zero
  40965. (eq, ":agent_no", ":player_agent"),
  40966. (eq, ":player_team_won", 0),
  40967. (assign, ":not_passed", 1),
  40968. (try_begin),
  40969. (ge, ":kill_count", 2),
  40970. (assign, ":not_passed", 0),
  40971. (else_try),
  40972. (eq, ":kill_count", 1),
  40973. (le, "$g_tournament_cur_tier", 1),
  40974. (assign, ":not_passed", 0),
  40975. (try_end),
  40976. (eq, ":not_passed", 1),
  40977. (assign, ":cur_point", 0),
  40978. (try_end),
  40979. (agent_set_slot, ":agent_no", slot_agent_tournament_point, ":cur_point"),
  40980. (try_end),
  40981. (try_for_range, ":unused", 0, ":num_needed"),
  40982. (assign, ":best_point", 0),
  40983. (assign, ":best_agent_no", -1),
  40984. (try_for_agents, ":agent_no"),
  40985. (agent_is_human, ":agent_no"),
  40986. (agent_get_slot, ":point", ":agent_no", slot_agent_tournament_point),
  40987. (gt, ":point", ":best_point"),
  40988. (assign, ":best_agent_no", ":agent_no"),
  40989. (assign, ":best_point", ":point"),
  40990. (try_end),
  40991. (agent_set_slot, ":best_agent_no", slot_agent_tournament_point, 0),#Do not select the same agent again
  40992. (agent_get_troop_id, ":troop_id", ":best_agent_no"),
  40993. (call_script, "script_add_tournament_participant", ":troop_id"),
  40994. (try_end),
  40995. (assign, "$g_tournament_player_team_won", ":player_team_won"),
  40996. (jump_to_menu, "mnu_town_tournament"),
  40997. ]),
  40998.  
  40999.  
  41000. # script_get_win_amount_for_tournament_bet
  41001. # Input: none
  41002. # Output: reg0 = win_amount_with_100_denars
  41003. ("get_win_amount_for_tournament_bet",
  41004. [
  41005. (party_get_slot, ":player_odds", "$current_town", slot_town_player_odds),
  41006. (try_begin),
  41007. (eq, "$g_tournament_cur_tier", 0),
  41008. (assign, ":win_amount", 120),
  41009. (else_try),
  41010. (eq, "$g_tournament_cur_tier", 1),
  41011. (assign, ":win_amount", 90),
  41012. (else_try),
  41013. (eq, "$g_tournament_cur_tier", 2),
  41014. (assign, ":win_amount", 60),
  41015. (else_try),
  41016. (eq, "$g_tournament_cur_tier", 3),
  41017. (assign, ":win_amount", 40),
  41018. (else_try),
  41019. (eq, "$g_tournament_cur_tier", 4),
  41020. (assign, ":win_amount", 20),
  41021. (else_try),
  41022. (assign, ":win_amount", 8),
  41023. (try_end),
  41024. (val_mul, ":win_amount", ":player_odds"),
  41025. (val_div, ":win_amount", 100),
  41026. (val_add, ":win_amount", 100), #win amount when 100 denars is placed
  41027. (assign, reg0, ":win_amount"),
  41028. ]),
  41029.  
  41030. # script_tournament_place_bet
  41031. # Input: arg1 = bet_amount
  41032. # Output: none
  41033. ("tournament_place_bet",
  41034. [
  41035. (store_script_param, ":bet_amount", 1),
  41036. (call_script, "script_get_win_amount_for_tournament_bet"),
  41037. (assign, ":win_amount", reg0),
  41038. (val_mul, ":win_amount", ":bet_amount"),
  41039. (val_div, ":win_amount", 100),
  41040. (val_sub, ":win_amount", ":bet_amount"),
  41041. (val_add, "$g_tournament_bet_placed", ":bet_amount"),
  41042. (val_add, "$g_tournament_bet_win_amount", ":win_amount"),
  41043. (troop_remove_gold, "trp_player", ":bet_amount"),
  41044. (assign, "$g_tournament_last_bet_tier", "$g_tournament_cur_tier"),
  41045. ]),
  41046.  
  41047. # script_calculate_amount_of_cattle_can_be_stolen
  41048. # Input: arg1 = village_no
  41049. # Output: reg0 = max_amount
  41050. ("calculate_amount_of_cattle_can_be_stolen",
  41051. [
  41052. (store_script_param, ":village_no", 1),
  41053. (call_script, "script_get_max_skill_of_player_party", "skl_looting"),
  41054. (assign, ":max_skill", reg0),
  41055. (store_mul, ":can_steal", ":max_skill", 2),
  41056. (call_script, "script_party_count_fit_for_battle", "p_main_party"),
  41057. (store_add, ":num_men_effect", reg0, 10),
  41058. (val_div, ":num_men_effect", 10),
  41059. (val_add, ":can_steal", ":num_men_effect"),
  41060. (party_get_slot, ":num_cattle", ":village_no", slot_village_number_of_cattle),
  41061. (val_min, ":can_steal", ":num_cattle"),
  41062. (assign, reg0, ":can_steal"),
  41063. ]),
  41064.  
  41065.  
  41066. # script_draw_banner_to_region
  41067. # Input: arg1 = troop_no, arg2 = center_pos_x, arg3 = center_pos_y, arg4 = width, arg5 = height, arg6 = stretch_width, arg7 = stretch_height, arg8 = default_scale, arg9 = max_charge_scale, arg10 = drawn_item_type
  41068. # drawn_item_type is 0 for banners, 1 for shields, 2 for heater shield, 3 for armor
  41069. # arguments will be used as fixed point values
  41070. # Output: none
  41071. ("draw_banner_to_region",
  41072. [
  41073. (store_script_param, ":troop_no", 1),
  41074. (store_script_param, ":center_pos_x", 2),
  41075. (store_script_param, ":center_pos_y", 3),
  41076. (store_script_param, ":width", 4),
  41077. (store_script_param, ":height", 5),
  41078. (store_script_param, ":stretch_width", 6),
  41079. (store_script_param, ":stretch_height", 7),
  41080. (store_script_param, ":default_scale", 8),
  41081. (store_script_param, ":max_charge_scale", 9),
  41082. (store_script_param, ":drawn_item_type", 10),
  41083.  
  41084. (troop_get_slot, ":bg_type", ":troop_no", slot_troop_custom_banner_bg_type),
  41085. (val_add, ":bg_type", custom_banner_backgrounds_begin),
  41086. (troop_get_slot, ":bg_color_1", ":troop_no", slot_troop_custom_banner_bg_color_1),
  41087. (troop_get_slot, ":bg_color_2", ":troop_no", slot_troop_custom_banner_bg_color_2),
  41088. (troop_get_slot, ":num_charges", ":troop_no", slot_troop_custom_banner_num_charges),
  41089. (troop_get_slot, ":positioning", ":troop_no", slot_troop_custom_banner_positioning),
  41090. (call_script, "script_get_troop_custom_banner_num_positionings", ":troop_no"),
  41091. (assign, ":num_positionings", reg0),
  41092. (val_mod, ":positioning", ":num_positionings"),
  41093.  
  41094. (init_position, pos2),
  41095. (position_set_x, pos2, ":width"),
  41096. (position_set_y, pos2, ":height"),
  41097. (assign, ":default_value", 1),
  41098. (convert_to_fixed_point, ":default_value"),
  41099. (position_set_z, pos2, ":default_value"),
  41100.  
  41101. (init_position, pos1),
  41102. (position_set_x, pos1, ":center_pos_x"),
  41103. (position_set_y, pos1, ":center_pos_y"),
  41104. (position_move_z, pos1, -20),
  41105.  
  41106. (init_position, pos3),
  41107. (position_set_x, pos3, ":default_scale"),
  41108. (position_set_y, pos3, ":default_scale"),
  41109. (position_set_z, pos3, ":default_value"),
  41110.  
  41111. (try_begin),
  41112. (this_or_next|eq, ":bg_type", "mesh_custom_banner_bg"),
  41113. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg01"),
  41114. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg02"),
  41115. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg03"),
  41116. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg08"),
  41117. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg09"),
  41118. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg10"),
  41119. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg11"),
  41120. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg12"),
  41121. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg13"),
  41122. (this_or_next|eq, ":bg_type", "mesh_custom_banner_fg16"),
  41123. (eq, ":bg_type", "mesh_custom_banner_fg17"),
  41124. (cur_tableau_add_mesh_with_scale_and_vertex_color, ":bg_type", pos1, pos2, 0, ":bg_color_1"),
  41125. (else_try),
  41126. (cur_tableau_add_mesh_with_scale_and_vertex_color, ":bg_type", pos1, pos3, 0, ":bg_color_1"),
  41127. (try_end),
  41128. (position_move_z, pos1, -20),
  41129. (position_move_x, pos2, ":width"),
  41130. (position_move_y, pos2, ":height"),
  41131. (cur_tableau_add_mesh_with_scale_and_vertex_color, "mesh_custom_banner_bg", pos1, pos2, 0, ":bg_color_2"),
  41132.  
  41133. (assign, ":charge_stretch", ":stretch_width"),
  41134. (val_min, ":charge_stretch", ":stretch_height"),
  41135. (val_min, ":charge_stretch", ":max_charge_scale"),
  41136. (call_script, "script_get_custom_banner_charge_type_position_scale_color", "trp_player", ":positioning"),
  41137.  
  41138. (try_begin),
  41139. (this_or_next|eq, ":drawn_item_type", 2), #heater shield
  41140. (eq, ":drawn_item_type", 3), #armor
  41141. (assign, ":change_center_pos", 0),
  41142. (try_begin),
  41143. (eq, ":num_charges", 1),
  41144. (assign, ":change_center_pos", 1),
  41145. (else_try),
  41146. (eq, ":num_charges", 2),
  41147. (eq, ":positioning", 1),
  41148. (assign, ":change_center_pos", 1),
  41149. (else_try),
  41150. (eq, ":num_charges", 3),
  41151. (eq, ":positioning", 1),
  41152. (assign, ":change_center_pos", 1),
  41153. (try_end),
  41154. (try_begin),
  41155. (eq, ":change_center_pos", 1),
  41156. (val_add, ":center_pos_y", 30),
  41157. (try_end),
  41158. (try_end),
  41159.  
  41160. (try_begin),
  41161. (ge, ":num_charges", 1),
  41162. (val_mul, reg1, ":charge_stretch"),
  41163. (val_div, reg1, 10000),
  41164. (position_get_x, ":x", pos0),
  41165. (position_get_y, ":y", pos0),
  41166. (val_mul, ":x", ":stretch_width"),
  41167. (val_mul, ":y", ":stretch_height"),
  41168. (val_div, ":x", 10000),
  41169. (val_div, ":y", 10000),
  41170. (val_add, ":x", ":center_pos_x"),
  41171. (val_add, ":y", ":center_pos_y"),
  41172. (position_set_x, pos0, ":x"),
  41173. (position_set_y, pos0, ":y"),
  41174. (assign, ":scale_value", reg1),
  41175. (convert_to_fixed_point, ":scale_value"),
  41176. (store_mul, ":scale_value_inverse", ":scale_value", -1),
  41177. (init_position, pos4),
  41178. (position_set_x, pos4, ":scale_value"),
  41179. (position_set_y, pos4, ":scale_value"),
  41180. (position_set_z, pos4, ":scale_value"),
  41181. (store_div, ":orientation", reg0, 256), #orientation flags
  41182. (try_begin),
  41183. (this_or_next|eq, ":orientation", 1),
  41184. (eq, ":orientation", 3),
  41185. (position_set_x, pos4, ":scale_value_inverse"),
  41186. (try_end),
  41187. (try_begin),
  41188. (this_or_next|eq, ":orientation", 2),
  41189. (eq, ":orientation", 3),
  41190. (position_set_y, pos4, ":scale_value_inverse"),
  41191. (try_end),
  41192. (val_mod, reg0, 256), #remove orientation flags
  41193. (cur_tableau_add_mesh_with_scale_and_vertex_color, reg0, pos0, pos4, 0, reg2),
  41194. (try_end),
  41195. (try_begin),
  41196. (ge, ":num_charges", 2),
  41197. (val_mul, reg4, ":charge_stretch"),
  41198. (val_div, reg4, 10000),
  41199. (position_get_x, ":x", pos1),
  41200. (position_get_y, ":y", pos1),
  41201. (val_mul, ":x", ":stretch_width"),
  41202. (val_mul, ":y", ":stretch_height"),
  41203. (val_div, ":x", 10000),
  41204. (val_div, ":y", 10000),
  41205. (val_add, ":x", ":center_pos_x"),
  41206. (val_add, ":y", ":center_pos_y"),
  41207. (position_set_x, pos1, ":x"),
  41208. (position_set_y, pos1, ":y"),
  41209.  
  41210. (assign, ":scale_value", reg4),
  41211. (convert_to_fixed_point, ":scale_value"),
  41212. (store_mul, ":scale_value_inverse", ":scale_value", -1),
  41213. (init_position, pos4),
  41214. (position_set_x, pos4, ":scale_value"),
  41215. (position_set_y, pos4, ":scale_value"),
  41216. (position_set_z, pos4, ":scale_value"),
  41217. (store_div, ":orientation", reg3, 256), #orientation flags
  41218. (try_begin),
  41219. (this_or_next|eq, ":orientation", 1),
  41220. (eq, ":orientation", 3),
  41221. (position_set_x, pos4, ":scale_value_inverse"),
  41222. (try_end),
  41223. (try_begin),
  41224. (this_or_next|eq, ":orientation", 2),
  41225. (eq, ":orientation", 3),
  41226. (position_set_y, pos4, ":scale_value_inverse"),
  41227. (try_end),
  41228. (val_mod, reg3, 256), #remove orientation flags
  41229.  
  41230. (cur_tableau_add_mesh_with_scale_and_vertex_color, reg3, pos1, pos4, 0, reg5),
  41231. (try_end),
  41232. (try_begin),
  41233. (ge, ":num_charges", 3),
  41234. (val_mul, reg7, ":charge_stretch"),
  41235. (val_div, reg7, 10000),
  41236. (position_get_x, ":x", pos2),
  41237. (position_get_y, ":y", pos2),
  41238. (val_mul, ":x", ":stretch_width"),
  41239. (val_mul, ":y", ":stretch_height"),
  41240. (val_div, ":x", 10000),
  41241. (val_div, ":y", 10000),
  41242. (val_add, ":x", ":center_pos_x"),
  41243. (val_add, ":y", ":center_pos_y"),
  41244. (position_set_x, pos2, ":x"),
  41245. (position_set_y, pos2, ":y"),
  41246.  
  41247. (assign, ":scale_value", reg7),
  41248. (convert_to_fixed_point, ":scale_value"),
  41249. (store_mul, ":scale_value_inverse", ":scale_value", -1),
  41250. (init_position, pos4),
  41251. (position_set_x, pos4, ":scale_value"),
  41252. (position_set_y, pos4, ":scale_value"),
  41253. (position_set_z, pos4, ":scale_value"),
  41254. (store_div, ":orientation", reg6, 256), #orientation flags
  41255. (try_begin),
  41256. (this_or_next|eq, ":orientation", 1),
  41257. (eq, ":orientation", 3),
  41258. (position_set_x, pos4, ":scale_value_inverse"),
  41259. (try_end),
  41260. (try_begin),
  41261. (this_or_next|eq, ":orientation", 2),
  41262. (eq, ":orientation", 3),
  41263. (position_set_y, pos4, ":scale_value_inverse"),
  41264. (try_end),
  41265. (val_mod, reg6, 256), #remove orientation flags
  41266.  
  41267. (cur_tableau_add_mesh_with_scale_and_vertex_color, reg6, pos2, pos4, 0, reg8),
  41268. (try_end),
  41269. (try_begin),
  41270. (ge, ":num_charges", 4),
  41271. (val_mul, reg10, ":charge_stretch"),
  41272. (val_div, reg10, 10000),
  41273. (position_get_x, ":x", pos3),
  41274. (position_get_y, ":y", pos3),
  41275. (val_mul, ":x", ":stretch_width"),
  41276. (val_mul, ":y", ":stretch_height"),
  41277. (val_div, ":x", 10000),
  41278. (val_div, ":y", 10000),
  41279. (val_add, ":x", ":center_pos_x"),
  41280. (val_add, ":y", ":center_pos_y"),
  41281. (position_set_x, pos3, ":x"),
  41282. (position_set_y, pos3, ":y"),
  41283.  
  41284. (assign, ":scale_value", reg10),
  41285. (convert_to_fixed_point, ":scale_value"),
  41286. (store_mul, ":scale_value_inverse", ":scale_value", -1),
  41287. (init_position, pos4),
  41288. (position_set_x, pos4, ":scale_value"),
  41289. (position_set_y, pos4, ":scale_value"),
  41290. (position_set_z, pos4, ":scale_value"),
  41291. (store_div, ":orientation", reg9, 256), #orientation flags
  41292. (try_begin),
  41293. (this_or_next|eq, ":orientation", 1),
  41294. (eq, ":orientation", 3),
  41295. (position_set_x, pos4, ":scale_value_inverse"),
  41296. (try_end),
  41297. (try_begin),
  41298. (this_or_next|eq, ":orientation", 2),
  41299. (eq, ":orientation", 3),
  41300. (position_set_y, pos4, ":scale_value_inverse"),
  41301. (try_end),
  41302. (val_mod, reg9, 256), #remove orientation flags
  41303.  
  41304. (cur_tableau_add_mesh_with_scale_and_vertex_color, reg9, pos3, pos4, 0, reg11),
  41305. (try_end),
  41306. ]),
  41307.  
  41308. # script_get_troop_custom_banner_num_positionings
  41309. # Input: arg1 = troop_no
  41310. # Output: reg0 = num_positionings
  41311. ("get_troop_custom_banner_num_positionings",
  41312. [
  41313. (store_script_param, ":troop_no", 1),
  41314. (troop_get_slot, ":num_charges", ":troop_no", slot_troop_custom_banner_num_charges),
  41315. (try_begin),
  41316. (eq, ":num_charges", 1),
  41317. (assign, ":num_positionings", 2),
  41318. (else_try),
  41319. (eq, ":num_charges", 2),
  41320. (assign, ":num_positionings", 4),
  41321. (else_try),
  41322. (eq, ":num_charges", 3),
  41323. (assign, ":num_positionings", 6),
  41324. (else_try),
  41325. (assign, ":num_positionings", 2),
  41326. (try_end),
  41327. (assign, reg0, ":num_positionings"),
  41328. ]),
  41329.  
  41330. # script_get_custom_banner_charge_type_position_scale_color
  41331. # Input: arg1 = troop_no, arg2 = positioning_index
  41332. # Output: reg0 = type_1
  41333. # reg1 = scale_1
  41334. # reg2 = color_1
  41335. # reg3 = type_2
  41336. # reg4 = scale_2
  41337. # reg5 = color_2
  41338. # reg6 = type_3
  41339. # reg7 = scale_3
  41340. # reg8 = color_3
  41341. # reg9 = type_4
  41342. # reg10 = scale_4
  41343. # reg11 = color_4
  41344. ("get_custom_banner_charge_type_position_scale_color",
  41345. [
  41346. (store_script_param, ":troop_no", 1),
  41347. (store_script_param, ":positioning", 2),
  41348. (troop_get_slot, ":num_charges", ":troop_no", slot_troop_custom_banner_num_charges),
  41349. (init_position, pos0),
  41350. (init_position, pos1),
  41351. (init_position, pos2),
  41352. (init_position, pos3),
  41353.  
  41354. (troop_get_slot, reg0, ":troop_no", slot_troop_custom_banner_charge_type_1),
  41355. (val_add, reg0, custom_banner_charges_begin),
  41356. (troop_get_slot, reg2, ":troop_no", slot_troop_custom_banner_charge_color_1),
  41357. (troop_get_slot, reg3, ":troop_no", slot_troop_custom_banner_charge_type_2),
  41358. (val_add, reg3, custom_banner_charges_begin),
  41359. (troop_get_slot, reg5, ":troop_no", slot_troop_custom_banner_charge_color_2),
  41360. (troop_get_slot, reg6, ":troop_no", slot_troop_custom_banner_charge_type_3),
  41361. (val_add, reg6, custom_banner_charges_begin),
  41362. (troop_get_slot, reg8, ":troop_no", slot_troop_custom_banner_charge_color_3),
  41363. (troop_get_slot, reg9, ":troop_no", slot_troop_custom_banner_charge_type_4),
  41364. (val_add, reg9, custom_banner_charges_begin),
  41365. (troop_get_slot, reg11, ":troop_no", slot_troop_custom_banner_charge_color_4),
  41366.  
  41367. (try_begin),
  41368. (eq, ":num_charges", 1),
  41369. (try_begin),
  41370. (eq, ":positioning", 0),
  41371. (assign, reg1, 100),
  41372. (else_try),
  41373. (assign, reg1, 50),
  41374. (try_end),
  41375. (else_try),
  41376. (eq, ":num_charges", 2),
  41377. (try_begin),
  41378. (eq, ":positioning", 0),
  41379. (position_set_y, pos0, 25),
  41380. (position_set_y, pos1, -25),
  41381. (assign, reg1, 40),
  41382. (assign, reg4, 40),
  41383. (else_try),
  41384. (eq, ":positioning", 1),
  41385. (position_set_x, pos0, -25),
  41386. (position_set_x, pos1, 25),
  41387. (assign, reg1, 40),
  41388. (assign, reg4, 40),
  41389. (else_try),
  41390. (eq, ":positioning", 2),
  41391. (position_set_x, pos0, -25),
  41392. (position_set_y, pos0, 25),
  41393. (position_set_x, pos1, 25),
  41394. (position_set_y, pos1, -25),
  41395. (assign, reg1, 50),
  41396. (assign, reg4, 50),
  41397. (else_try),
  41398. (position_set_x, pos0, -25),
  41399. (position_set_y, pos0, -25),
  41400. (position_set_x, pos1, 25),
  41401. (position_set_y, pos1, 25),
  41402. (assign, reg1, 50),
  41403. (assign, reg4, 50),
  41404. (try_end),
  41405. (else_try),
  41406. (eq, ":num_charges", 3),
  41407. (try_begin),
  41408. (eq, ":positioning", 0),
  41409. (position_set_y, pos0, 33),
  41410. (position_set_y, pos2, -33),
  41411. (assign, reg1, 30),
  41412. (assign, reg4, 30),
  41413. (assign, reg7, 30),
  41414. (else_try),
  41415. (eq, ":positioning", 1),
  41416. (position_set_x, pos0, -33),
  41417. (position_set_x, pos2, 33),
  41418. (assign, reg1, 30),
  41419. (assign, reg4, 30),
  41420. (assign, reg7, 30),
  41421. (else_try),
  41422. (eq, ":positioning", 2),
  41423. (position_set_x, pos0, -30),
  41424. (position_set_y, pos0, 30),
  41425. (position_set_x, pos2, 30),
  41426. (position_set_y, pos2, -30),
  41427. (assign, reg1, 35),
  41428. (assign, reg4, 35),
  41429. (assign, reg7, 35),
  41430. (else_try),
  41431. (eq, ":positioning", 3),
  41432. (position_set_x, pos0, -30),
  41433. (position_set_y, pos0, -30),
  41434. (position_set_x, pos2, 30),
  41435. (position_set_y, pos2, 30),
  41436. (assign, reg1, 35),
  41437. (assign, reg4, 35),
  41438. (assign, reg7, 35),
  41439. (else_try),
  41440. (eq, ":positioning", 4),
  41441. (position_set_x, pos0, -25),
  41442. (position_set_y, pos0, -25),
  41443. (position_set_y, pos1, 25),
  41444. (position_set_x, pos2, 25),
  41445. (position_set_y, pos2, -25),
  41446. (assign, reg1, 50),
  41447. (assign, reg4, 50),
  41448. (assign, reg7, 50),
  41449. (else_try),
  41450. (position_set_x, pos0, -25),
  41451. (position_set_y, pos0, 25),
  41452. (position_set_y, pos1, -25),
  41453. (position_set_x, pos2, 25),
  41454. (position_set_y, pos2, 25),
  41455. (assign, reg1, 50),
  41456. (assign, reg4, 50),
  41457. (assign, reg7, 50),
  41458. (try_end),
  41459. (else_try),
  41460. (try_begin),
  41461. (eq, ":positioning", 0),
  41462. (position_set_x, pos0, -25),
  41463. (position_set_y, pos0, 25),
  41464. (position_set_x, pos1, 25),
  41465. (position_set_y, pos1, 25),
  41466. (position_set_x, pos2, -25),
  41467. (position_set_y, pos2, -25),
  41468. (position_set_x, pos3, 25),
  41469. (position_set_y, pos3, -25),
  41470. (assign, reg1, 50),
  41471. (assign, reg4, 50),
  41472. (assign, reg7, 50),
  41473. (assign, reg10, 50),
  41474. (else_try),
  41475. (position_set_y, pos0, 30),
  41476. (position_set_x, pos1, -30),
  41477. (position_set_x, pos2, 30),
  41478. (position_set_y, pos3, -30),
  41479. (assign, reg1, 35),
  41480. (assign, reg4, 35),
  41481. (assign, reg7, 35),
  41482. (assign, reg10, 35),
  41483. (try_end),
  41484. (try_end),
  41485. ]),
  41486.  
  41487. # script_get_random_custom_banner
  41488. # Input: arg1 = troop_no
  41489. # Output: none
  41490. ("get_random_custom_banner",
  41491. [
  41492. (store_script_param, ":troop_no", 1),
  41493. (store_random_in_range, ":num_charges", 1, 5),
  41494. (troop_set_slot, ":troop_no", slot_troop_custom_banner_num_charges, ":num_charges"),
  41495. (store_random_in_range, ":random_color_index", 0, 42),
  41496. (call_script, "script_get_custom_banner_color_from_index", ":random_color_index"),
  41497. (assign, ":color_1", reg0),
  41498. (troop_set_slot, ":troop_no", slot_troop_custom_banner_bg_color_1, ":color_1"),
  41499. (assign, ":end_cond", 1),
  41500. (try_for_range, ":unused", 0, ":end_cond"),
  41501. (store_random_in_range, ":random_color_index", 0, 42),
  41502. (call_script, "script_get_custom_banner_color_from_index", ":random_color_index"),
  41503. (assign, ":color_2", reg0),
  41504. (try_begin),
  41505. (call_script, "script_cf_check_color_visibility", ":color_1", ":color_2"),
  41506. (troop_set_slot, ":troop_no", slot_troop_custom_banner_bg_color_2, ":color_2"),
  41507. (else_try),
  41508. (val_add, ":end_cond", 1),
  41509. (try_end),
  41510. (try_end),
  41511. (assign, ":end_cond", 4),
  41512. (assign, ":cur_charge", 0),
  41513. (try_for_range, ":unused", 0, ":end_cond"),
  41514. (store_random_in_range, ":random_color_index", 0, 42),
  41515. (call_script, "script_get_custom_banner_color_from_index", ":random_color_index"),
  41516. (assign, ":charge_color", reg0),
  41517. (try_begin),
  41518. (call_script, "script_cf_check_color_visibility", ":charge_color", ":color_1"),
  41519. (call_script, "script_cf_check_color_visibility", ":charge_color", ":color_2"),
  41520. (store_add, ":cur_slot", ":cur_charge", slot_troop_custom_banner_charge_color_1),
  41521. (troop_set_slot, ":troop_no", ":cur_slot", ":charge_color"),
  41522. (store_random_in_range, ":random_charge", custom_banner_charges_begin, custom_banner_charges_end),
  41523. (val_sub, ":random_charge", custom_banner_charges_begin),
  41524. (store_add, ":cur_slot", ":cur_charge", slot_troop_custom_banner_charge_type_1),
  41525. (troop_set_slot, ":troop_no", ":cur_slot", ":random_charge"),
  41526. (val_add, ":cur_charge", 1),
  41527. (else_try),
  41528. (val_add, ":end_cond", 1),
  41529. (try_end),
  41530. (try_end),
  41531. (store_random_in_range, ":random_bg", custom_banner_backgrounds_begin, custom_banner_backgrounds_end),
  41532. (val_sub, ":random_bg", custom_banner_backgrounds_begin),
  41533. (troop_set_slot, ":troop_no", slot_troop_custom_banner_bg_type, ":random_bg"),
  41534. (store_random_in_range, ":random_flag", custom_banner_flag_types_begin, custom_banner_flag_types_end),
  41535. (val_sub, ":random_flag", custom_banner_flag_types_begin),
  41536. (troop_set_slot, ":troop_no", slot_troop_custom_banner_flag_type, ":random_flag"),
  41537. (store_random_in_range, ":random_positioning", 0, 4),
  41538. (troop_set_slot, ":troop_no", slot_troop_custom_banner_positioning, ":random_positioning"),
  41539. ]),
  41540.  
  41541. # script_get_custom_banner_color_from_index
  41542. # Input: arg1 = color_index
  41543. # Output: reg0 = color
  41544. ("get_custom_banner_color_from_index",
  41545. [
  41546. (store_script_param, ":color_index", 1),
  41547.  
  41548. (assign, ":cur_color", 0xFF000000),
  41549. (assign, ":red", 0x00),
  41550. (assign, ":green", 0x00),
  41551. (assign, ":blue", 0x00),
  41552. (store_mod, ":mod_i_color", ":color_index", 7),
  41553. (try_begin),
  41554. (eq, ":mod_i_color", 0),
  41555. (assign, ":blue", 0xFF),
  41556. (else_try),
  41557. (eq, ":mod_i_color", 1),
  41558. (assign, ":red", 0xEE),
  41559. (else_try),
  41560. (eq, ":mod_i_color", 2),
  41561. (assign, ":red", 0xFB),
  41562. (assign, ":green", 0xAC),
  41563. (else_try),
  41564. (eq, ":mod_i_color", 3),
  41565. (assign, ":red", 0x5F),
  41566. (assign, ":blue", 0xFF),
  41567. (else_try),
  41568. (eq, ":mod_i_color", 4),
  41569. (assign, ":red", 0x05),
  41570. (assign, ":green", 0x44),
  41571. (else_try),
  41572. (eq, ":mod_i_color", 5),
  41573. (assign, ":red", 0xEE),
  41574. (assign, ":green", 0xEE),
  41575. (assign, ":blue", 0xEE),
  41576. (else_try),
  41577. (assign, ":red", 0x22),
  41578. (assign, ":green", 0x22),
  41579. (assign, ":blue", 0x22),
  41580. (try_end),
  41581. (store_div, ":cur_tone", ":color_index", 7),
  41582. (store_sub, ":cur_tone", 8, ":cur_tone"),
  41583. (val_mul, ":red", ":cur_tone"),
  41584. (val_div, ":red", 8),
  41585. (val_mul, ":green", ":cur_tone"),
  41586. (val_div, ":green", 8),
  41587. (val_mul, ":blue", ":cur_tone"),
  41588. (val_div, ":blue", 8),
  41589. (val_mul, ":green", 0x100),
  41590. (val_mul, ":red", 0x10000),
  41591. (val_add, ":cur_color", ":blue"),
  41592. (val_add, ":cur_color", ":green"),
  41593. (val_add, ":cur_color", ":red"),
  41594. (assign, reg0, ":cur_color"),
  41595. ]),
  41596.  
  41597. # script_cf_check_color_visibility
  41598. # Input: arg1 = color_1, arg2 = color_2
  41599. # Output: none
  41600. ("cf_check_color_visibility",
  41601. [
  41602. (store_script_param, ":color_1", 1),
  41603. (store_script_param, ":color_2", 2),
  41604. (store_mod, ":blue_1", ":color_1", 256),
  41605. (store_div, ":green_1", ":color_1", 256),
  41606. (val_mod, ":green_1", 256),
  41607. (store_div, ":red_1", ":color_1", 256 * 256),
  41608. (val_mod, ":red_1", 256),
  41609. (store_mod, ":blue_2", ":color_2", 256),
  41610. (store_div, ":green_2", ":color_2", 256),
  41611. (val_mod, ":green_2", 256),
  41612. (store_div, ":red_2", ":color_2", 256 * 256),
  41613. (val_mod, ":red_2", 256),
  41614. (store_sub, ":red_dif", ":red_1", ":red_2"),
  41615. (val_abs, ":red_dif"),
  41616. (store_sub, ":green_dif", ":green_1", ":green_2"),
  41617. (val_abs, ":green_dif"),
  41618. (store_sub, ":blue_dif", ":blue_1", ":blue_2"),
  41619. (val_abs, ":blue_dif"),
  41620. (assign, ":max_dif", 0),
  41621. (val_max, ":max_dif", ":red_dif"),
  41622. (val_max, ":max_dif", ":green_dif"),
  41623. (val_max, ":max_dif", ":blue_dif"),
  41624. (ge, ":max_dif", 64),
  41625. ]),
  41626.  
  41627. # script_get_next_active_kingdom
  41628. # Input: arg1 = faction_no
  41629. # Output: reg0 = faction_no (does not choose player faction)
  41630. ("get_next_active_kingdom",
  41631. [
  41632. (store_script_param, ":faction_no", 1),
  41633. (assign, ":end_cond", kingdoms_end),
  41634. (try_for_range, ":unused", kingdoms_begin, ":end_cond"),
  41635. (val_add, ":faction_no", 1),
  41636. (try_begin),
  41637. (ge, ":faction_no", kingdoms_end),
  41638. (assign, ":faction_no", kingdoms_begin),
  41639. (try_end),
  41640. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  41641. (neq, ":faction_no", "fac_player_supporters_faction"),
  41642. (assign, ":end_cond", 0),
  41643. (try_end),
  41644. (assign, reg0, ":faction_no"),
  41645. ]),
  41646.  
  41647. # # script_store_average_center_value_per_faction
  41648. # # Input: none
  41649. # # Output: none (sets $g_average_center_value_per_faction)
  41650. # ("store_average_center_value_per_faction",
  41651. # [
  41652. # (store_sub, ":num_towns", towns_end, towns_begin),
  41653. # (store_sub, ":num_castles", castles_end, castles_begin),
  41654. # (assign, ":num_factions", 0),
  41655. # (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  41656. # (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  41657. # (val_add, ":num_factions", 1),
  41658. # (try_end),
  41659. # (val_max, ":num_factions", 1),
  41660. # (store_mul, "$g_average_center_value_per_faction", ":num_towns", 2),
  41661. # (val_add, "$g_average_center_value_per_faction", ":num_castles"),
  41662. # (val_mul, "$g_average_center_value_per_faction", 10),
  41663. # (val_div, "$g_average_center_value_per_faction", ":num_factions"),
  41664. # ]),
  41665.  
  41666. # script_remove_cattles_if_herd_is_close_to_party
  41667. # Input: arg1 = party_no, arg2 = maximum_number_of_cattles_required
  41668. # Output: reg0 = number_of_cattles_removed
  41669. ("remove_cattles_if_herd_is_close_to_party",
  41670. [
  41671. (store_script_param, ":party_no", 1),
  41672. (store_script_param, ":max_req", 2),
  41673. (assign, ":cur_req", ":max_req"),
  41674. (try_for_parties, ":cur_party"),
  41675. (gt, ":cur_req", 0),
  41676. (party_slot_eq, ":cur_party", slot_party_type, spt_cattle_herd),
  41677. (store_distance_to_party_from_party, ":dist", ":cur_party", ":party_no"),
  41678. (lt, ":dist", 3),
  41679.  
  41680. #Do not use the quest herd for "move cattle herd"
  41681. (assign, ":subcontinue", 1),
  41682. (try_begin),
  41683. (check_quest_active, "qst_move_cattle_herd"),
  41684. (quest_slot_eq, "qst_move_cattle_herd", slot_quest_target_party, ":cur_party"),
  41685. (assign, ":subcontinue", 0),
  41686. (try_end),
  41687. (eq, ":subcontinue", 1),
  41688. #Do not use the quest herd for "move cattle herd" ends
  41689.  
  41690. (party_count_companions_of_type, ":num_cattle", ":cur_party", "trp_cattle"),
  41691. (try_begin),
  41692. (le, ":num_cattle", ":cur_req"),
  41693. (assign, ":num_added", ":num_cattle"),
  41694. (remove_party, ":cur_party"),
  41695. (else_try),
  41696. (assign, ":num_added", ":cur_req"),
  41697. (party_remove_members, ":cur_party", "trp_cattle", ":cur_req"),
  41698. (try_end),
  41699. (val_sub, ":cur_req", ":num_added"),
  41700.  
  41701.  
  41702. (try_begin),
  41703. (party_slot_eq, ":party_no", slot_party_type, spt_village),
  41704. (party_get_slot, ":village_cattle_amount", ":party_no", slot_village_number_of_cattle),
  41705. (val_add, ":village_cattle_amount", ":num_added"),
  41706. (party_set_slot, ":party_no", slot_village_number_of_cattle, ":village_cattle_amount"),
  41707. (try_end),
  41708.  
  41709. (assign, reg3, ":num_added"),
  41710. (str_store_party_name_link, s1, ":party_no"),
  41711. (display_message, "@You brought {reg3} heads of cattle to {s1}."),
  41712. (try_begin),
  41713. (gt, "$cheat_mode", 0),
  41714. (assign, reg4, ":village_cattle_amount"),
  41715. (display_message, "@{!}Village now has {reg4}"),
  41716. (try_end),
  41717. (try_end),
  41718. (store_sub, reg0, ":max_req", ":cur_req"),
  41719. ]),
  41720.  
  41721. # script_get_rumor_to_s61
  41722. # Input: rumor_id
  41723. # Output: reg0 = 1 if rumor found, 0 otherwise; s61 will contain rumor string if found
  41724. ("get_rumor_to_s61",
  41725. [
  41726. (store_script_param, ":base_rumor_id", 1), # the script returns the same rumor for the same rumor id, so that one cannot hear all rumors by
  41727. # speaking to a single person.
  41728. ##diplomacy start+ save reg4 in order to revert it at the end of the script
  41729. (assign, ":save_reg4", reg4),
  41730. ##diplomacy end+
  41731. (store_current_hours, ":cur_hours"),
  41732. (store_div, ":cur_day", ":cur_hours", 24),
  41733. (assign, ":rumor_found", 0),
  41734. (assign, ":num_tries", 3),
  41735. (try_for_range, ":try_no", 0, ":num_tries"),
  41736. (store_mul, ":rumor_id", ":try_no", 6781),
  41737. (val_add, ":rumor_id", ":base_rumor_id"),
  41738. (store_mod, ":rumor_type", ":rumor_id", 7),
  41739. (val_add, ":rumor_id", ":cur_hours"),
  41740. (try_begin),
  41741. (eq, ":rumor_type", 0),
  41742. (try_begin),
  41743. (store_sub, ":range", towns_end, towns_begin),
  41744. (store_mod, ":random_center", ":rumor_id", ":range"),
  41745. (val_add, ":random_center", towns_begin),
  41746. (party_slot_ge, ":random_center", slot_town_has_tournament, 1),
  41747. (neq, ":random_center", "$current_town"),
  41748. (str_store_party_name, s62, ":random_center"),
  41749. (str_store_string, s61, "@I heard that there will be a tournament in {s62} soon."),
  41750. (assign, ":rumor_found", 1),
  41751. (try_end),
  41752. (else_try),
  41753. (eq, ":rumor_type", 1),
  41754. (try_begin),
  41755. (store_sub, ":range", active_npcs_end, original_kingdom_heroes_begin), #was reversed
  41756. (store_mod, ":random_hero", ":rumor_id", ":range"),
  41757. (val_add, ":random_hero", original_kingdom_heroes_begin),
  41758. (is_between, ":random_hero", active_npcs_begin, active_npcs_end),
  41759. (troop_get_slot, ":personality", ":random_hero", slot_lord_reputation_type),
  41760. ##diplomacy start+ give rumors for non-noble personalities, and make pronouns gender-correct
  41761. (try_begin),
  41762. (ge, ":personality", lrep_roguish),
  41763. (try_begin),
  41764. (eq, ":personality", lrep_benefactor),#Ymira, Bunduk, Jeremus
  41765. (assign, ":personality", lrep_goodnatured),#treats people living in his lands decently
  41766. (else_try),
  41767. (eq, ":personality", lrep_custodian),#Marnid, Artimenner, Deshavi, Katrin
  41768. (assign, ":personality", lrep_goodnatured),#good to his followers, and rewards them if they work well
  41769. (else_try),
  41770. (call_script, "script_dplmc_get_troop_morality_value", ":random_hero", tmt_humanitarian),
  41771. (lt, reg0, 0),#Klethi
  41772. (assign, ":personality", lrep_debauched),#likes to torture his enemies
  41773. (try_end),
  41774. (ge, ":personality", lrep_roguish),
  41775. (assign, ":personality", 0),#zero out to avoid jumping to a nonsensical string
  41776. (try_end),
  41777. (call_script, "script_dplmc_store_troop_is_female_reg", ":random_hero", 4),#store gender to reg4 to make pronouns gender-correct
  41778. ##diplomacy end+
  41779. (gt, ":personality", 0),
  41780. (store_add, ":rumor_string", ":personality", "str_gossip_about_character_default"),
  41781. (str_store_troop_name, s6, ":random_hero"),
  41782. (str_store_string, s61, ":rumor_string"),
  41783. (assign, ":rumor_found", 1),
  41784. (try_end),
  41785. ##diplomacy start+ Change the rumor string in some circumstances to avoid implying the hero is currently ruling a fief
  41786. (try_begin),
  41787. (neg|is_between, ":random_hero", heroes_begin, heroes_end),
  41788. (else_try),
  41789. #Dead
  41790. (troop_slot_eq, ":random_hero", slot_troop_occupation, dplmc_slto_dead),
  41791. (str_store_troop_name, s6, ":random_hero"),
  41792. (str_store_string, s61, "@I heard some people say they don't believe {s6} is really dead."),#The doubters are wrong, like with Tupac or Elvis.
  41793. (assign, ":rumor_found", 1),
  41794. (else_try),
  41795. #In exile
  41796. (this_or_next|troop_slot_eq, ":random_hero", slot_troop_occupation, slto_retirement),
  41797. (troop_slot_eq, ":random_hero", slot_troop_occupation, dplmc_slto_exile),
  41798. (str_store_troop_name, s6, ":random_hero"),
  41799. (str_store_string, s61, "@I heard a traveller say that he came across {s6} while journeying outside these lands."),
  41800. (assign, ":rumor_found", 1),
  41801. (else_try),
  41802. #Inactive pretender
  41803. (troop_slot_eq, ":random_hero", slot_troop_occupation, slto_inactive_pretender),
  41804. (neq, ":random_hero", "$supported_pretender"),
  41805. (troop_get_slot, reg4, ":random_hero", slot_troop_original_faction),
  41806. (is_between, reg4, npc_kingdoms_begin, npc_kingdoms_end),
  41807. (faction_slot_eq, reg4, slot_faction_state, sfs_active),
  41808. (faction_get_slot, reg4, reg4, slot_faction_leader),
  41809. (gt, reg4, -1),
  41810. (str_store_troop_name, s61, reg4),
  41811. (str_store_string, s6, ":random_hero"),
  41812. (str_store_string, s61, "@I heard that {s6} intends to raise an army and seize the throne from {s61}."),
  41813. (assign, ":rumor_found", 1),
  41814. (try_end),
  41815. ##diplomacy end+
  41816. (else_try),
  41817. (eq, ":rumor_type", 2),
  41818. (try_begin),
  41819. (store_sub, ":range", trade_goods_end, trade_goods_begin),
  41820. (store_add, ":random_trade_good", ":rumor_id", ":cur_day"),
  41821. (store_mod, ":random_trade_good", ":random_trade_good", ":range"),
  41822. (store_add, ":random_trade_good_slot", ":random_trade_good", slot_town_trade_good_prices_begin),
  41823. (val_add, ":random_trade_good", trade_goods_begin),
  41824. (store_mul, ":min_price", average_price_factor, 3),
  41825. (val_div, ":min_price", 4),
  41826. (assign, ":min_price_center", -1),
  41827. (try_for_range, ":sub_try_no", 0, 10),
  41828. (store_sub, ":range", towns_end, towns_begin),
  41829. (store_add, ":center_rumor_id", ":rumor_id", ":sub_try_no"),
  41830. (store_mod, ":random_center", ":center_rumor_id", ":range"),
  41831. (val_add, ":random_center", towns_begin),
  41832. (neq, ":random_center", "$g_encountered_party"),
  41833. (party_get_slot, ":cur_price", ":random_center", ":random_trade_good_slot"),
  41834. (lt, ":cur_price", ":min_price"),
  41835. (assign, ":min_price", ":cur_price"),
  41836. (assign, ":min_price_center", ":random_center"),
  41837. (try_end),
  41838. (ge, ":min_price_center", 0),
  41839. (str_store_item_name, s62, ":random_trade_good"),
  41840. (str_store_party_name, s63, ":min_price_center"),
  41841. (str_store_string, s61, "@I heard that one can buy {s62} very cheap at {s63}."),
  41842. (assign, ":rumor_found", 1),
  41843. (try_end),
  41844. (else_try),
  41845. (eq, ":rumor_type", 3),
  41846. (try_begin),
  41847. (store_sub, ":range", trade_goods_end, trade_goods_begin),
  41848. (store_add, ":random_trade_good", ":rumor_id", ":cur_day"),
  41849. (store_mod, ":random_trade_good", ":random_trade_good", ":range"),
  41850. (store_add, ":random_trade_good_slot", ":random_trade_good", slot_town_trade_good_prices_begin),
  41851. (val_add, ":random_trade_good", trade_goods_begin),
  41852. (store_mul, ":max_price", average_price_factor, 5),
  41853. (val_div, ":max_price", 4),
  41854. (assign, ":max_price_center", -1),
  41855. (try_for_range, ":sub_try_no", 0, 10),
  41856. (store_sub, ":range", towns_end, towns_begin),
  41857. (store_add, ":center_rumor_id", ":rumor_id", ":sub_try_no"),
  41858. (store_mod, ":random_center", ":center_rumor_id", ":range"),
  41859. (val_add, ":random_center", towns_begin),
  41860. (neq, ":random_center", "$g_encountered_party"),
  41861. (party_get_slot, ":cur_price", ":random_center", ":random_trade_good_slot"),
  41862. (gt, ":cur_price", ":max_price"),
  41863. (assign, ":max_price", ":cur_price"),
  41864. (assign, ":max_price_center", ":random_center"),
  41865. (try_end),
  41866. (ge, ":max_price_center", 0),
  41867. (str_store_item_name, s62, ":random_trade_good"),
  41868. (str_store_party_name, s63, ":max_price_center"),
  41869. (str_store_string, s61, "@I heard that they pay a very high price for {s62} at {s63}."),
  41870. (assign, ":rumor_found", 1),
  41871. (try_end),
  41872. (try_end),
  41873. (try_begin),
  41874. (gt, ":rumor_found", 0),
  41875. (assign, ":num_tries", 0),
  41876. (try_end),
  41877. (try_end),
  41878. (assign, reg0, ":rumor_found"),
  41879. ##diplomacy start+ revert reg4
  41880. (assign, reg4, ":save_reg4"),
  41881. ##diplomacy end+
  41882. ]),
  41883.  
  41884. ("lord_comment_to_s43",
  41885. [(store_script_param, ":lord", 1),
  41886. (store_script_param, ":default_string", 2),
  41887.  
  41888. (troop_get_slot,":reputation", ":lord", slot_lord_reputation_type),
  41889.  
  41890. #some default strings will have added comments for the added commons reputation types
  41891. ##diplomacy start+
  41892. (try_begin),
  41893. #Don't reassign personalities of lords
  41894. (is_between, ":reputation", lrep_none, lrep_upstanding + 1),
  41895. (else_try),
  41896. #Special case for anti-humanitarians (Klethi in Native)
  41897. (neg|is_between, ":reputation", lrep_none, lrep_upstanding + 1),
  41898. (neq, ":reputation", lrep_benefactor),
  41899. (neq, ":reputation", lrep_moralist),
  41900. (neq, ":reputation", lrep_conventional),
  41901. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_humanitarian),
  41902. (lt, reg0, 0),#<- In Native, this only applies to Klethi
  41903. #Use lrep_debauched by default, and refine further below.
  41904. (assign, ":reputation", lrep_debauched),
  41905. (try_begin),
  41906. #If pious, anti-humanitarians use lrep_selfrighteous
  41907. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_pious),
  41908. (ge, reg0, 1),#<- Describes no one in Native
  41909. (assign, ":reputation", lrep_selfrighteous),
  41910. (else_try),
  41911. #If aggressive, anti-humanitarians use lrep_quarrelsome
  41912. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_aristocratic),
  41913. (this_or_next|eq, ":reputation", lrep_adventurous),
  41914. (ge, reg0, 1),#<- In Native describes Alayen, Matheld, Rolf, Nizar, Lezalit, Klethi (but only Klethi can even reach here)
  41915. (assign, ":reputation", lrep_quarrelsome),
  41916. (try_end),
  41917. (else_try),
  41918. #Special case for "pious" characters (no one in Native)
  41919. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_pious),
  41920. (ge, reg0, 1),
  41921. (try_begin),
  41922. #Handle these separately to prevent inappropriate reassignment
  41923. (this_or_next|eq, ":reputation", lrep_benefactor),
  41924. (eq, ":reputation", lrep_moralist),
  41925. (assign, ":reputation", lrep_upstanding),
  41926. (else_try),
  41927. #Ordinarily upstanding
  41928. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_humanitarian),
  41929. (ge, reg0, 0),#<- In Native describes all but Klethi
  41930. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_egalitarian),
  41931. (ge, reg0, 0),#<- In Native describes all but Lezalit
  41932. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_honest),
  41933. (ge, reg0, 0),#<- In Native describes all but Rolf
  41934. (assign, ":reputation", lrep_upstanding),
  41935. (else_try),
  41936. #If vicious, self-righteous is also a possibility
  41937. (assign, ":reputation", lrep_selfrighteous),
  41938. (try_end),
  41939. (else_try),
  41940. #Special case for dishonest commoners.
  41941. #Pragmatic-style amoral: lrep_cunning
  41942. #Jerk-style amoral: lrep_debauched
  41943. (neg|is_between, ":reputation", lrep_none, lrep_upstanding + 1),
  41944. (neq, ":reputation", lrep_moralist),
  41945. (neq, ":reputation", lrep_benefactor),
  41946. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_honest),
  41947. (lt, reg0, 0),#<- In Native only describes Rolf (who wouldn't reach here, since he is lrep_cunning)
  41948. (try_begin),
  41949. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_egalitarian),
  41950. (lt, reg0, 1),
  41951. (assign, ":egalitarian", reg0),
  41952. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_humanitarian),
  41953. (lt, reg0, 1),
  41954. (this_or_next|lt, reg0, 0),
  41955. (lt, ":egalitarian", 0),
  41956. (assign, ":reputation", lrep_debauched),
  41957. (else_try),
  41958. (assign, ":reputation", lrep_cunning),
  41959. (try_end),
  41960. (else_try),
  41961. (eq, ":reputation", lrep_roguish),
  41962. (assign, ":reputation", lrep_goodnatured),
  41963. (else_try),
  41964. (eq, ":reputation", lrep_custodian),
  41965. (assign, ":reputation", lrep_cunning),
  41966. (else_try),
  41967. (eq, ":reputation", lrep_benefactor),
  41968. (assign, ":reputation", lrep_goodnatured),
  41969. #add support for lady personalities
  41970. (else_try),
  41971. (eq, ":reputation", lrep_ambitious),
  41972. (assign, ":reputation", lrep_cunning),
  41973. (else_try),
  41974. (this_or_next|eq, ":reputation", lrep_conventional),
  41975. (eq, ":reputation", lrep_otherworldly),
  41976. (assign, ":reputation", lrep_goodnatured),
  41977. (else_try),
  41978. (eq, ":reputation", lrep_adventurous),
  41979. (assign, ":reputation", lrep_martial),
  41980. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_egalitarian),
  41981. (try_begin),
  41982. (lt, reg0, 0),#<- In Native describes no one
  41983. (assign, ":reputation", lrep_quarrelsome),
  41984. (try_end),
  41985. (else_try),
  41986. (eq, ":reputation", lrep_moralist),
  41987. (assign, ":reputation", lrep_upstanding),
  41988. (try_end),
  41989. ##diplomacy end+
  41990.  
  41991. ##diplomacy start+ Add some variability
  41992. #For non-companion, non-monarchs who don't have any tmt_* morality values, this
  41993. # just amounts to a 5% chance to use lrep_none instead of their real reputation
  41994. # (except where that would cause problems).
  41995. #Otherwise,
  41996. # 16,17:
  41997. # tmt_pious > 0, with lrep_debauched or lrep_quarrelsome or lrep_selfrighteous: lrep_selfrighteous
  41998. # tmt_pious > 0, with one of (tmt_egalitarian, tmt_honest, tmt_humanitarian) < 0 and none > 0: lrep_selfrighteous
  41999. # (tmt_pious >= 0 and tmt_honest >= 0) and (tmt_pious > 0 or tmt_honest > 0): lrep_upstanding
  42000. # tmt_honest < 0: lrep_cunning
  42001. # lrep_none and is a king or pretender: lrep_cunning
  42002. #
  42003. # 18,19:
  42004. # tmt_aristocratic > 0, with lrep_debauched or lrep_quarrelsome: lrep_quarrelsome
  42005. # lrep_martial, with (tmt_honest, tmt_egalitarian, tmt_humanitarian) all non-positive and
  42006. # at least one negative, and tmt_pious < 1 (so not to overlap with 16,17): lrep_quarrelsome
  42007. # tmt_aristocratic > 0: lrep_martial
  42008. # lrep_none and is a king or pretender: lrep_martial
  42009. (store_random_in_range, ":random_chance", 0, 20),
  42010. (assign, ":new_reputation", ":reputation"),
  42011. (try_begin),
  42012. (eq, 1, 1),#Disable this feature for now.
  42013. (else_try),
  42014. #Disable the first time you're talking to someone, or if you haven't
  42015. #spoken to this NPC recently.
  42016. (store_current_hours, ":recently"),
  42017. (val_sub, ":recently", 24),
  42018. (this_or_next|neq, "$g_talk_troop_met", 1),
  42019. (this_or_next|neg|troop_slot_ge, ":lord", slot_troop_met, 1),
  42020. (this_or_next|neg|troop_slot_ge, ":lord", slot_troop_last_talk_time, ":recently"),
  42021. #Disable for things that come in sequences
  42022. (this_or_next|eq, ":default_string", "str_rebellion_dilemma_default"),
  42023. (eq, ":default_string", "str_rebellion_dilemma_2_default"),
  42024. #Set this value to signal to the debug message at the end
  42025. (assign, ":random_chance", -1),
  42026. (else_try),
  42027. #10% chance of lrep_martial or lrep_quarrelsome if appropriate...
  42028. #if already lrep_martial, check separately here for possible conversion
  42029. #to lrep_quarrelsome
  42030. (is_between, ":random_chance", 18, 20),
  42031. (eq, ":reputation", lrep_martial),
  42032. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_egalitarian),
  42033. (lt, reg0, 1),
  42034. (assign, ":bad_sum", reg0),
  42035. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_humanitarian),
  42036. (lt, reg0, 1),
  42037. (val_add, ":bad_sum", reg0),
  42038. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_honest),
  42039. (lt, reg0, 1),
  42040. (val_add, ":bad_sum", reg0),
  42041. #at least one of tmt_egalitarian, tmt_humanitarian, and tmt_honest were negative (and none were positive)
  42042. (lt, ":bad_sum", 0),
  42043. #disable for positive tmt_pious, since that's handled separately as an alternative to lrep_upstanding for [16,17]
  42044. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_honest),
  42045. (lt, reg0, 1),
  42046. (assign, ":new_reputation", lrep_quarrelsome),
  42047. (else_try),
  42048. #10% chance of lrep_martial or lrep_quarrelsome if appropriate
  42049. #Applies to: Rolf, Nizar, Lezalit, Klethi
  42050. #(Also Alayen and Matheld, but they are already lrep_martial)
  42051. (is_between, ":random_chance", 18, 20),
  42052. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_aristocratic),
  42053. (ge, reg0, 1),
  42054. (try_begin),
  42055. #some personalities use lrep_quarrelsome (only Klethi in Native)
  42056. (this_or_next|eq, ":reputation", lrep_debauched),
  42057. (eq, ":reputation", lrep_quarrelsome),#<-- i.e. no change
  42058. (assign, ":new_reputation", lrep_quarrelsome),
  42059. (else_try),
  42060. #other personalities use lrep_martial
  42061. (assign, ":new_reputation", lrep_martial),
  42062. (try_end),
  42063. (else_try),
  42064. #10% chance of lrep_upstanding or lrep_selfrighteous if appropriate
  42065. #Applies to: Marnid, Alayen, Artimenner
  42066. #(Also Firentis, but he is already lrep_upstanding)
  42067. (is_between, ":random_chance", 16, 18),
  42068. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_honest),
  42069. (assign, ":honest", reg0),
  42070. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_pious),
  42071. (assign, ":pious", reg0),
  42072. (this_or_next|ge, ":honest", 1),#one or the other must be greater than zero
  42073. (ge, ":pious", 1),
  42074. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_egalitarian),
  42075. (assign, ":egalitarian", reg0),
  42076. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_humanitarian),
  42077. (assign, ":humanitarian", reg0),
  42078. (try_begin),
  42079. #Unpleasant personalities use "selfrighteous" instead
  42080. #(Applies to no one in Native)
  42081. (this_or_next|eq, ":reputation", lrep_debauched),
  42082. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42083. (this_or_next|eq, ":reputation", lrep_selfrighteous),#<- i.e. no change
  42084. (this_or_next|lt, ":honest", 0),
  42085. (this_or_next|lt, ":egalitarian", 0),
  42086. (lt, ":humanitarian", 0),
  42087. (assign, ":new_reputation", lrep_selfrighteous),
  42088. (else_try),
  42089. #Other personalities use upstanding
  42090. (assign, ":new_reputation", lrep_upstanding),
  42091. (try_end),
  42092. (else_try),
  42093. #10% chance of lrep_cunning if appropriate
  42094. (is_between, ":random_chance", 16, 18),
  42095. (lt, ":honest", 0),#<- In Native only Rolf satisfies this, but he is already lrep_cunning
  42096. (assign, ":reputation", lrep_cunning),
  42097. (else_try),
  42098. #Ruler, if personality triggers not met: 10% cunning, 10% martial
  42099. (is_between, ":random_chance", 16, 20),
  42100. (eq, ":reputation", lrep_none),
  42101. (this_or_next|is_between, ":lord", kings_begin, kings_end),
  42102. (is_between, ":lord", pretenders_begin, pretenders_end),
  42103. (try_begin),
  42104. (is_between, ":random_chance", 16, 18),
  42105. (assign, ":new_reputation", lrep_cunning),
  42106. (else_try),
  42107. (is_between, ":random_chance", 18, 20),
  42108. (call_script, "script_dplmc_get_troop_morality_value", ":lord", tmt_aristocratic),
  42109. (ge, reg0, 0),#Won't reach here if positive, so you could just check if it equals zero
  42110. (assign, ":new_reputation", lrep_martial),
  42111. (try_end),
  42112. (else_try),
  42113. #Others, if personality triggers not met: 5% chance of null
  42114. (is_between, ":random_chance", 16, 20),#base 20%
  42115. (store_mod, ":rand_mod", ":random_chance",4),
  42116. (troop_get_slot, reg0, ":lord", slot_troop_temp_decision_seed),
  42117. (val_mod, reg0, 4),
  42118. (eq, ":rand_mod", reg0),#1/4 of the time, 5%
  42119. #disable for things that don't have a "lrep_none" version defined
  42120. (neq, ":default_string", "str_rebellion_dilemma_default"),
  42121. (neq, ":default_string", "str_rebellion_dilemma_2_default"),
  42122. (neq, ":default_string", "str_changed_my_mind_default"),
  42123. (neq, ":default_string", "str_political_philosophy_default"),
  42124. (neq, ":default_string", "str_rebellion_rival_default"),
  42125. (neq, ":default_string", "str_rebellion_agree_default"),
  42126. (neq, ":default_string", "str_rebellion_refuse_default"),
  42127. (neq, ":default_string", "str_talk_later_default"),
  42128. (neq, ":default_string", "str_npc_claim_throne_liege"),
  42129. #use lrep_none
  42130. (assign, ":new_reputation", lrep_none),
  42131. (try_end),
  42132. (try_begin),
  42133. (eq, 1, 0),#Disable this feature for now.
  42134. (ge, "$cheat_mode", 1),
  42135. (assign, ":save_reg1", reg1),
  42136. (assign, ":save_reg2", reg2),
  42137. (assign, reg0, ":random_chance"),
  42138. (assign, reg1, ":reputation"),
  42139. (assign, reg2, ":new_reputation"),
  42140. (try_begin),
  42141. (neq, ":reputation", ":new_reputation"),
  42142. (display_message, "@{!} DEBUG - random {reg0} (0 to 20), used reputation {reg2} instead of {reg1}"),
  42143. (else_try),
  42144. (lt, ":random_chance", 0),
  42145. (display_message, "@{!} DEBUG - variable responses disabled, kept reputation {reg2}"),
  42146. (else_try),
  42147. (display_message, "@{!} DEBUG - random {reg0} (0 to 20), kept reputation {reg2}"),
  42148. (try_end),
  42149. (assign, reg1, ":save_reg1"),
  42150. (assign, reg2, ":save_reg2"),
  42151. (try_end),
  42152. (assign, ":reputation", ":new_reputation"),
  42153. ##diplomacy end+
  42154.  
  42155. (store_add, ":result", ":reputation", ":default_string"),
  42156.  
  42157. (str_store_string, 43, ":result"),
  42158. (assign, reg0, ":result"),
  42159.  
  42160.  
  42161. ]),
  42162.  
  42163. #Troop Commentaries begin
  42164.  
  42165. # script_add_log_entry
  42166. # Input: arg1 = entry_type, arg2 = event_actor, arg3 = center_object, arg4 = troop_object, arg5 = faction_object
  42167. # Output: none
  42168. ("add_log_entry",
  42169. [(store_script_param, ":entry_type", 1),
  42170. (store_script_param, ":actor", 2),
  42171. (store_script_param, ":center_object", 3),
  42172. (store_script_param, ":troop_object", 4),
  42173. (store_script_param, ":faction_object", 5),
  42174. (assign, ":center_object_lord", -1),
  42175. (assign, ":center_object_faction", -1),
  42176. (assign, ":troop_object_faction", -1),
  42177.  
  42178. (try_begin),
  42179. (party_is_active, ":center_object", 0),
  42180. (party_get_slot, ":center_object_lord", ":center_object", slot_town_lord),
  42181. (store_faction_of_party, ":center_object_faction", ":center_object"),
  42182. (else_try),
  42183. (assign, ":center_object_lord", 0),
  42184. (assign, ":center_object_faction", 0),
  42185. (try_end),
  42186.  
  42187. (try_begin),
  42188. (is_between, ":troop_object", 0, "trp_local_merchant"),
  42189. (store_troop_faction, ":troop_object_faction", ":troop_object"),
  42190. (else_try),
  42191. (assign, ":troop_object_faction", 0),
  42192. (try_end),
  42193.  
  42194. (val_add, "$num_log_entries", 1),
  42195.  
  42196. (store_current_hours, ":entry_time"),
  42197. (troop_set_slot, "trp_log_array_entry_type", "$num_log_entries", ":entry_type"),
  42198. (troop_set_slot, "trp_log_array_entry_time", "$num_log_entries", ":entry_time"),
  42199. (troop_set_slot, "trp_log_array_actor", "$num_log_entries", ":actor"),
  42200. (troop_set_slot, "trp_log_array_center_object", "$num_log_entries", ":center_object"),
  42201. (troop_set_slot, "trp_log_array_center_object_lord", "$num_log_entries", ":center_object_lord"),
  42202. (troop_set_slot, "trp_log_array_center_object_faction", "$num_log_entries", ":center_object_faction"),
  42203. (troop_set_slot, "trp_log_array_troop_object", "$num_log_entries", ":troop_object"),
  42204. (troop_set_slot, "trp_log_array_troop_object_faction", "$num_log_entries", ":troop_object_faction"),
  42205. (troop_set_slot, "trp_log_array_faction_object", "$num_log_entries", ":faction_object"),
  42206.  
  42207. (try_begin),
  42208. (eq, "$cheat_mode", 1),
  42209. (assign, reg3, "$num_log_entries"),
  42210. (assign, reg4, ":entry_type"),
  42211. (display_message, "@{!}Log entry {reg3}: type {reg4}"),
  42212. (try_begin),
  42213. (gt, ":center_object", 0),
  42214. (neq, ":entry_type", logent_traveller_attacked),
  42215. (neq, ":entry_type", logent_party_traded),
  42216. (party_is_active, ":center_object"), #sometimes is a troop
  42217.  
  42218. (str_store_party_name, s4, ":center_object"),
  42219. (display_message, "@{!}Center: {s4}"),
  42220. (try_end),
  42221. (try_begin),
  42222. (gt, ":troop_object", 0),
  42223. (neq, ":entry_type", logent_traveller_attacked),
  42224. (neq, ":entry_type", logent_party_traded),
  42225.  
  42226. (str_store_troop_name, s4, ":troop_object"),
  42227. (display_message, "@{!}Troop: {s4}"),
  42228. (try_end),
  42229. (try_begin),
  42230. (gt, ":center_object_lord", 0),
  42231. (neq, ":entry_type", logent_traveller_attacked),
  42232. (neq, ":entry_type", logent_party_traded),
  42233.  
  42234. (str_store_troop_name, s4, ":center_object_lord"),
  42235. (display_message, "@{!}Lord: {s4}"),
  42236. (try_end),
  42237. (try_end),
  42238.  
  42239.  
  42240. (try_begin),
  42241. (this_or_next|eq, ":entry_type", logent_lord_defeated_by_player),
  42242. (this_or_next|eq, ":entry_type", logent_player_participated_in_major_battle),
  42243. (eq, ":entry_type", logent_player_participated_in_siege),
  42244.  
  42245. (try_begin),
  42246. (eq, "$cheat_mode", 1),
  42247. (display_message, "@{!}Ally party is present"),
  42248. (try_end),
  42249. ##diplomacy start+ support kingdom ladies as well
  42250. #(try_for_range, ":hero", active_npcs_begin, active_npcs_end),
  42251. (try_for_range, ":hero", heroes_begin, heroes_end),
  42252. (this_or_next|is_between, ":hero", active_npcs_begin, active_npcs_end),
  42253. (this_or_next|troop_slot_eq, ":hero", slot_troop_occupation, slto_kingdom_hero),
  42254. (this_or_next|troop_slot_eq, ":hero", slot_troop_occupation, slto_player_companion),
  42255. (troop_slot_eq, ":hero", slot_troop_occupation, slto_kingdom_seneschal),
  42256. ##diplomacy end+
  42257. (party_count_companions_of_type, ":hero_present", "p_collective_friends", ":hero"),
  42258. (gt, ":hero_present", 0),
  42259. (troop_set_slot, ":hero", slot_troop_present_at_event, "$num_log_entries"),
  42260. # (store_sub, ":skip_up_to_here", "$num_log_entries", 1),
  42261. # (troop_set_slot, ":hero", slot_troop_last_comment_slot, ":skip_up_to_here"),
  42262. (try_begin),
  42263. (eq, "$cheat_mode", 1),
  42264. (str_store_troop_name, s4, ":hero"),
  42265. (display_message, "@{!}{s4} is present at event"),
  42266. (try_end),
  42267. (try_end),
  42268. (else_try), #SB : log kingdom policy changes as well
  42269. (eq, ":entry_type", logent_player_renamed_capital),
  42270. (party_clear, "p_temp_party"),
  42271. (call_script, "script_get_heroes_attached_to_center", ":center_object", "p_temp_party"),
  42272. (party_get_num_companion_stacks, ":num_stacks","p_temp_party"),
  42273. (try_for_range, ":stack", 0, ":num_stacks"),
  42274. (party_stack_get_troop_id, ":hero", "p_temp_party", ":stack"),
  42275. (troop_set_slot, ":hero", slot_troop_present_at_event, "$num_log_entries"), #need to check if this gets called before or after, add +1
  42276. (try_end),
  42277. #they can give their opinion in the feast, although comment strings aren't set up.
  42278. (try_end),
  42279. ]),
  42280.  
  42281.  
  42282. # script_get_relevant_comment_for_log_entry
  42283. # Input: arg1 = log_entry_no,
  42284. # Output: reg0 = comment_id; reg1 = relevance
  42285. # Notes: 50 is the default relevance.
  42286. # A comment with relevance less than 30 will always be skipped.
  42287. # A comment with relevance 75 or more will never be skipped.
  42288. # A comment with relevance 50 has about 50% chance to be skipped.
  42289. # If there is more than one comment that is not skipped, the system will randomize their relevance values, and then choose the highest one.
  42290. # Also note that the relevance of events decreases as time passes. After three months, relevance reduces to 50%, after 6 months, 25%, etc...
  42291. ##diplomacy start+
  42292. ##May also set reg4 or reg3 to correspond to gender
  42293. ##diplomac end+
  42294. ("get_relevant_comment_for_log_entry",
  42295. [(store_script_param, ":log_entry_no", 1),
  42296.  
  42297. (troop_get_slot, ":entry_type", "trp_log_array_entry_type", ":log_entry_no"),
  42298. (troop_get_slot, ":entry_time", "trp_log_array_entry_time", ":log_entry_no"),
  42299. (troop_get_slot, ":actor", "trp_log_array_actor", ":log_entry_no"),
  42300. (troop_get_slot, ":center_object", "trp_log_array_center_object", ":log_entry_no"),
  42301. (troop_get_slot, ":center_object_lord", "trp_log_array_center_object_lord", ":log_entry_no"),
  42302. (troop_get_slot, ":center_object_faction", "trp_log_array_center_object_faction", ":log_entry_no"),
  42303. (troop_get_slot, ":troop_object", "trp_log_array_troop_object", ":log_entry_no"),
  42304. (troop_get_slot, ":troop_object_faction", "trp_log_array_troop_object_faction", ":log_entry_no"),
  42305. (troop_get_slot, ":faction_object", "trp_log_array_faction_object", ":log_entry_no"),
  42306.  
  42307. (assign, ":relevance", 0),
  42308. (assign, ":comment", -1),
  42309. (assign, ":rejoinder", -1),
  42310. (assign, ":suggested_relation_change", 0),
  42311.  
  42312. (troop_get_slot, ":reputation", "$g_talk_troop", slot_lord_reputation_type),
  42313. ##diplomacy start+
  42314. (assign, ":return_reg4", reg4),
  42315. #Set an initial value for ":return_reg4", although further down
  42316. #some specific log types override this.
  42317. (try_begin),
  42318. (is_between, ":troop_object", heroes_begin, heroes_end),
  42319. (neq, ":troop_object", "$g_talk_troop"),
  42320. (assign, ":return_reg4", 0),
  42321. (try_begin),
  42322. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  42323. (assign, ":return_reg4", 1),
  42324. (try_end),
  42325. (else_try),
  42326. (is_between, ":actor", heroes_begin, heroes_end),
  42327. (neq, ":actor", "$g_talk_troop"),
  42328. (assign, ":return_reg4", 0),
  42329. (try_begin),
  42330. (call_script, "script_cf_dplmc_troop_is_female", ":actor"),
  42331. (assign, ":return_reg4", 1),
  42332. (try_end),
  42333. (try_end),
  42334.  
  42335.  
  42336. #add support for commoner/lady reputations
  42337. (troop_get_slot, ":true_reputation", "$g_talk_troop", slot_lord_reputation_type),#unmodified value
  42338. #(troop_get_type, ":talk_troop_gender", "$g_talk_troop"),
  42339. (call_script, "script_dplmc_store_troop_is_female", "$g_talk_troop"),
  42340. (assign, ":talk_troop_gender", reg0),
  42341. (try_begin),
  42342. (neg|is_between, ":reputation", lrep_none, lrep_upstanding + 1),#<-- no changes are required for standard lord personalities
  42343. (try_begin),
  42344. (eq, ":true_reputation", lrep_ambitious),
  42345. (assign, ":reputation", lrep_cunning),
  42346. (else_try),
  42347. (eq, ":true_reputation", lrep_moralist),
  42348. (assign, ":reputation", lrep_upstanding),
  42349. (else_try),
  42350. (this_or_next|eq, ":true_reputation", lrep_conventional),
  42351. (this_or_next|eq, ":true_reputation", lrep_otherworldly),
  42352. (eq, ":true_reputation", lrep_benefactor),
  42353. (assign, ":reputation", lrep_goodnatured),
  42354. (try_end),
  42355. (try_end),
  42356. ##diplomacy end+
  42357. (store_current_hours, ":current_time"),
  42358. (store_sub, ":entry_hours_elapsed", ":current_time", ":entry_time"),
  42359.  
  42360. #Post 0907 changes begin
  42361. (assign, ":players_kingdom_relation", 0), ##the below is so that lords will not congratulate player on attacking neutrals
  42362. (try_begin),
  42363. (gt, "$players_kingdom", 0),
  42364. (store_relation, ":players_kingdom_relation", "$players_kingdom", ":troop_object_faction"),
  42365. (try_end),
  42366.  
  42367. (try_begin),
  42368. (eq, "$cheat_mode", -1), #temporarily disabled
  42369. (try_begin),
  42370. (assign, reg5, ":log_entry_no"),
  42371. (assign, reg6, ":entry_type"),
  42372. (assign, reg8, ":entry_time"),
  42373.  
  42374. (gt, "$players_kingdom", 0),
  42375. (try_begin),
  42376. (gt, ":troop_object_faction", 0),
  42377. (assign, reg7, ":players_kingdom_relation"),
  42378. (display_message, "@{!}Event #{reg5}, type {reg6}, time {reg8}: player's kingdom relation to troop object = {reg7}"),
  42379. (else_try),
  42380. (gt, ":center_object_faction", 0),
  42381. (assign, reg7, ":players_kingdom_relation"),
  42382. (display_message, "@{!}Event #{reg5}, type {reg6}, time {reg8}: player's kingdom relation to center object faction = {reg7}"),
  42383. (else_try),
  42384. (gt, ":faction_object", 0),
  42385. (assign, reg7, ":players_kingdom_relation"),
  42386. (display_message, "@{!}Event #{reg5}, type {reg6}, time {reg8}: player's kingdom relation to faction object = {reg7}"),
  42387. (else_try),
  42388. (display_message, "@{!}Event #{reg5}, type {reg6}, time {reg8}. No relevant kingdom relation"),
  42389. (try_end),
  42390. (else_try),
  42391. (display_message, "@{!}Event #{reg5}, type {reg6}, time {reg8}. Player unaffiliated"),
  42392. (try_end),
  42393. (try_end),
  42394.  
  42395. ##diplomacy start+
  42396. #In Native, it's assumed that anyone with lrep_none is a liege, but that isn't alwasys true.
  42397. #(For example, it's possible in a Native game for a defeated pretender to end up as the vassal
  42398. #of an NPC lord (!), but still talk as if they're ruling a kingdom.)
  42399. # Instead of just relying on personality for this, explicily check if they're a liege.
  42400. (call_script, "script_dplmc_get_troop_standing_in_faction", "$g_talk_troop", "$g_talk_troop_faction"),
  42401. (try_begin),
  42402. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  42403. (assign, ":speaker_is_a_liege", 1),
  42404. (else_try),
  42405. (assign, ":speaker_is_a_liege", 0),
  42406. (try_end),
  42407. ##diplomacy end+
  42408. (try_begin),
  42409. (eq, ":entry_type", logent_game_start),
  42410. (eq, "$g_talk_troop_met", 0),
  42411. (is_between, "$g_talk_troop_faction_relation", -5, 5),
  42412. (is_between, "$g_talk_troop_relation", -5, 5),
  42413.  
  42414. (assign, ":relevance", 25),
  42415. (troop_get_slot, ":plyr_renown", "trp_player", slot_troop_renown),
  42416. ##diplomacy start+
  42417. (try_begin),
  42418. (lt, "$g_disable_condescending_comments", 0),#prejudice mode: high
  42419. (call_script, "script_cf_dplmc_faction_has_bias_against_gender", "$g_talk_troop_faction", "$character_gender"),#bias against gender
  42420. #80% renown
  42421. (val_mul, ":plyr_renown", 4),
  42422. (val_add, ":plyr_renown", 3),
  42423. (val_div, ":plyr_renown", 5),
  42424. (try_end),
  42425. ##diplomacy end+
  42426. #normal_banner_begin
  42427. (troop_get_slot, ":banner", "trp_player", slot_troop_banner_scene_prop),
  42428. #custom_banner_begin
  42429. # (troop_get_slot, ":banner", "trp_player", slot_troop_custom_banner_flag_type),
  42430. (store_random_in_range, ":renown_check", 100, 200),
  42431. (try_begin),
  42432. ##diplomacy start+
  42433. (gt, ":speaker_is_a_liege", 0),#Explicitly check if the speaker is a liege rather than relying solely on reputation
  42434. ##diplomacy end+
  42435. (eq, ":reputation", lrep_none),
  42436. (gt, "$players_kingdom", 0),
  42437. (assign, ":comment", "str_comment_intro_liege_affiliated"),
  42438. (try_begin),
  42439. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  42440. (assign, ":comment", "str_comment_intro_liege_affiliated_to_player"),
  42441. (try_end),
  42442. (else_try),
  42443. ##diplomacy start+
  42444. ##OLD:
  42445. #(eq, "$character_gender",tf_female),
  42446. ##NEW:
  42447. #Instead of assuming there's anti-female bias in all settings, check on a kingdom-by-kingdom basis.
  42448. (call_script, "script_cf_dplmc_faction_has_bias_against_gender", "$g_talk_troop_faction", "$character_gender"),
  42449. ##diplomacy end+
  42450.  
  42451. (call_script, "script_troop_get_romantic_chemistry_with_troop", "$g_talk_troop", "trp_player"),
  42452. (assign, ":attraction", reg0),
  42453. (store_random_in_range, ":random", 0, 2),
  42454. (this_or_next|eq, ":random", 0),
  42455. (gt, ":attraction", 10),
  42456. ##diplomacy start+ disable remarks about women if the speaker is a woman (or visa versa, for settings with biases against men)
  42457. (this_or_next|gt, ":attraction", 10),
  42458. (neq, ":talk_troop_gender", "$character_gender"),
  42459. ##diplomacy end+
  42460. (try_begin),
  42461. (this_or_next|gt, ":plyr_renown", ":renown_check"),
  42462. ##diplomacy start+
  42463. # (eq, "$g_disable_condescending_comments", 1),
  42464. (ge, "$g_disable_condescending_comments", 1),
  42465. ##diplomacy end+
  42466. (assign, ":comment", "str_comment_intro_female_famous_liege"),
  42467. (val_add, ":comment", ":reputation"),
  42468. (else_try),
  42469. (ge, ":attraction", 9),
  42470. (assign, ":comment", "str_comment_intro_female_admiring_liege"),
  42471. (val_add, ":comment", ":reputation"),
  42472. (else_try),
  42473. (gt, ":banner", 0),
  42474. (assign, ":comment", "str_comment_intro_female_noble_liege"),
  42475. (val_add, ":comment", ":reputation"),
  42476. (else_try),
  42477. (assign, ":comment", "str_comment_intro_female_common_liege"),
  42478. (val_add, ":comment", ":reputation"),
  42479. (try_end),
  42480.  
  42481. #Rejoinders for comments
  42482. (try_begin),
  42483. (eq, ":comment", "str_comment_intro_female_common_badtempered"),
  42484. (assign, ":rejoinder", "str_rejoinder_intro_female_common_badtempered"),
  42485. (else_try),
  42486. (eq, ":comment", "str_comment_intro_female_noble_pitiless"),
  42487. (assign, ":rejoinder", "str_rejoinder_intro_female_noble_pitiless"),
  42488. (else_try),
  42489. (eq, ":comment", "str_comment_intro_female_common_pitiless"),
  42490. (assign, ":rejoinder", "str_rejoinder_intro_female_common_pitiless"),
  42491. (else_try),
  42492. (eq, ":comment", "str_comment_intro_female_noble_sadistic"),
  42493. (assign, ":rejoinder", "str_rejoinder_intro_female_noble_sadistic"),
  42494. (else_try),
  42495. (eq, ":comment", "str_comment_intro_female_common_sadistic"),
  42496. (assign, ":rejoinder", "str_rejoinder_intro_female_common_sadistic"),
  42497. (else_try),
  42498. (eq, ":comment", "str_comment_intro_female_common_upstanding"),
  42499. (assign, ":rejoinder", "str_rejoinder_intro_female_common_upstanding"),
  42500. (else_try),
  42501. (eq, ":comment", "str_comment_intro_female_noble_upstanding"),
  42502. (assign, ":rejoinder", "str_rejoinder_intro_female_noble_upstanding"),
  42503. (else_try),
  42504. (eq, ":comment", "str_comment_intro_female_common_martial"),
  42505. (assign, ":rejoinder", "str_rejoinder_intro_female_common_martial"),
  42506. (else_try),
  42507. (eq, ":comment", "str_comment_intro_female_sadistic_admiring"),
  42508. (assign, ":rejoinder", "str_rejoinder_intro_female_sadistic_admiring"),
  42509. (else_try),
  42510. (eq, ":comment", "str_comment_intro_female_badtempered_admiring"),
  42511. (assign, ":rejoinder", "str_rejoinder_intro_female_badtempered_admiring"),
  42512. (else_try),
  42513. (eq, ":comment", "str_comment_intro_female_pitiless_admiring"),
  42514. (assign, ":rejoinder", "str_rejoinder_intro_female_pitiless_admiring"),
  42515. (try_end),
  42516.  
  42517. (else_try),
  42518. #Male character or non-gendered comment
  42519. (try_begin),
  42520. (gt, ":plyr_renown", ":renown_check"),
  42521. (assign, ":comment", "str_comment_intro_famous_liege"),
  42522. (val_add, ":comment", ":reputation"),
  42523. (else_try),
  42524. (gt, ":banner", 0),
  42525. (assign, ":comment", "str_comment_intro_noble_liege"),
  42526. (val_add, ":comment", ":reputation"),
  42527.  
  42528. (try_begin),
  42529. (eq, ":comment", "str_comment_intro_noble_sadistic"),
  42530. (assign, ":rejoinder", "str_rejoinder_intro_noble_sadistic"),
  42531. (try_end),
  42532.  
  42533. (else_try),
  42534. (assign, ":comment", "str_comment_intro_common_liege"),
  42535. (val_add, ":comment", ":reputation"),
  42536. (try_end),
  42537. (try_end),
  42538. #Post 0907 changes end
  42539.  
  42540. (else_try),
  42541. (eq, ":entry_type", logent_village_raided),
  42542. (eq, ":actor", "trp_player"),
  42543. (try_begin),
  42544. (eq, ":center_object_lord", "$g_talk_troop"),
  42545. (assign, ":relevance", 200),
  42546. (assign, ":suggested_relation_change", -1),
  42547. (assign, ":comment", "str_comment_you_raided_my_village_default"),
  42548. (try_begin),
  42549. (lt, "$g_talk_troop_faction_relation", -5),
  42550. (this_or_next|eq, ":reputation", lrep_goodnatured),
  42551. (eq, ":reputation", lrep_upstanding),
  42552. (assign, ":comment", "str_comment_you_raided_my_village_enemy_benevolent"),
  42553. (else_try),
  42554. (lt, "$g_talk_troop_faction_relation", -5),
  42555. (this_or_next|eq, ":reputation", lrep_cunning),
  42556. (eq, ":reputation", lrep_selfrighteous),
  42557. (assign, ":comment", "str_comment_you_raided_my_village_enemy_coldblooded"),
  42558. (else_try),
  42559. (lt, "$g_talk_troop_faction_relation", -5),
  42560. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42561. (eq, ":reputation", lrep_debauched),
  42562. (assign, ":comment", "str_comment_you_raided_my_village_enemy_spiteful"),
  42563. (else_try),
  42564. (lt, "$g_talk_troop_faction_relation", -5),
  42565. (assign, ":comment", "str_comment_you_raided_my_village_enemy"),
  42566. (else_try),
  42567. (lt, "$g_talk_troop_relation", -5),
  42568. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42569. (eq, ":reputation", lrep_debauched),
  42570. (assign, ":comment", "str_comment_you_raided_my_village_unfriendly_spiteful"),
  42571. (else_try),
  42572. (gt, "$g_talk_troop_relation", 5),
  42573. (assign, ":comment", "str_comment_you_raided_my_village_friendly"),
  42574. (try_end),
  42575. (try_end),
  42576.  
  42577. (else_try),
  42578. (eq, ":entry_type", logent_village_extorted),
  42579. (eq, ":actor", "trp_player"),
  42580. (try_begin),
  42581. (eq, ":center_object_lord", "$g_talk_troop"),
  42582. (assign, ":relevance", 30),
  42583. (assign, ":suggested_relation_change", -1),
  42584. (assign, ":comment", "str_comment_you_robbed_my_village_default"),
  42585. (try_begin),
  42586. (lt, "$g_talk_troop_faction_relation", -5),
  42587. (this_or_next|eq, ":reputation", lrep_cunning),
  42588. (eq, ":reputation", lrep_selfrighteous),
  42589. (assign, ":comment", "str_comment_you_robbed_my_village_enemy_coldblooded"),
  42590. (else_try),
  42591. (lt, "$g_talk_troop_faction_relation", -5),
  42592. (assign, ":comment", "str_comment_you_robbed_my_village_enemy"),
  42593. (else_try),
  42594. (gt, "$g_talk_troop_relation", 5),
  42595. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42596. (eq, ":reputation", lrep_debauched),
  42597. (assign, ":comment", "str_comment_you_robbed_my_village_friendly_spiteful"),
  42598. (else_try),
  42599. (gt, "$g_talk_troop_relation", 5),
  42600. (assign, ":comment", "str_comment_you_robbed_my_village_friendly"),
  42601. (try_end),
  42602. (try_end),
  42603.  
  42604. (else_try),
  42605. (eq, ":entry_type", logent_caravan_accosted),
  42606. (eq, ":actor", "trp_player"),
  42607. (eq, ":faction_object", "$g_talk_troop_faction"),
  42608. (eq, ":center_object", -1),
  42609. (eq, ":troop_object", -1),
  42610.  
  42611.  
  42612.  
  42613. (faction_slot_eq, "$g_talk_troop_faction", slot_faction_leader, "$g_talk_troop"),
  42614. (assign, ":relevance", 30),
  42615. (assign, ":suggested_relation_change", -1),
  42616. (assign, ":comment", "str_comment_you_accosted_my_caravan_default"),
  42617. (try_begin),
  42618. (lt, "$g_talk_troop_faction_relation", -5),
  42619. (assign, ":comment", "str_comment_you_accosted_my_caravan_enemy"),
  42620. (try_end),
  42621.  
  42622. (else_try),
  42623. (eq, ":entry_type", logent_helped_peasants),
  42624. (eq, ":actor", "trp_player"),
  42625. (try_begin),
  42626. (eq, ":center_object_lord", "$g_talk_troop"),
  42627. (assign, ":relevance", 40),
  42628. (assign, ":suggested_relation_change", 0),
  42629. (try_begin),
  42630. (this_or_next|eq, ":reputation", lrep_goodnatured),
  42631. (eq, ":reputation", lrep_upstanding),
  42632. (assign, ":comment", "str_comment_you_helped_villagers_benevolent"),
  42633. (assign, ":suggested_relation_change", 1),
  42634. (else_try),
  42635. (gt, "$g_talk_troop_relation", 5),
  42636. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42637. (eq, ":reputation", lrep_debauched),
  42638. (assign, ":comment", "str_comment_you_helped_villagers_friendly_cruel"),
  42639. (assign, ":suggested_relation_change", -1),
  42640. (else_try),
  42641. (lt, "$g_talk_troop_relation", -5),
  42642. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42643. (eq, ":reputation", lrep_debauched),
  42644. (assign, ":comment", "str_comment_you_helped_villagers_unfriendly_spiteful"),
  42645. (assign, ":suggested_relation_change", -1),
  42646. (else_try),
  42647. (gt, "$g_talk_troop_relation", 5),
  42648. (assign, ":comment", "str_comment_you_helped_villagers_friendly"),
  42649. (else_try),
  42650. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  42651. (eq, ":reputation", lrep_debauched),
  42652. (assign, ":comment", "str_comment_you_helped_villagers_cruel"),
  42653. (assign, ":suggested_relation_change", -1),
  42654. (else_try),
  42655. (assign, ":comment", "str_comment_you_helped_villagers_default"),
  42656. (try_end),
  42657. (try_end),
  42658.  
  42659. ###Combat events
  42660. (else_try),
  42661. (eq, ":entry_type", logent_castle_captured_by_player),
  42662.  
  42663. (try_begin),
  42664. (eq, ":center_object_lord", "$g_talk_troop"),
  42665. (store_faction_of_party, ":current_center_faction", ":center_object"),
  42666. (eq, ":current_center_faction", "$players_kingdom"),
  42667. (neq, "$g_talk_troop_faction", "$players_kingdom"),
  42668.  
  42669. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42670. (eq, ":reputation", lrep_debauched),
  42671.  
  42672. (assign, ":comment", "str_comment_you_captured_my_castle_enemy_spiteful"),
  42673. (assign, ":relevance", 200),
  42674. (else_try),
  42675. (eq, ":center_object_lord", "$g_talk_troop"),
  42676. (store_faction_of_party, ":current_center_faction", ":center_object"),
  42677. (eq, ":current_center_faction", "$players_kingdom"),
  42678. (neq, "$g_talk_troop_faction", "$players_kingdom"),
  42679.  
  42680. (this_or_next|eq, ":reputation", lrep_martial),
  42681. (eq, ":reputation", lrep_goodnatured),
  42682.  
  42683. (assign, ":comment", "str_comment_you_captured_my_castle_enemy_chivalrous"),
  42684. (assign, ":relevance", 200),
  42685. (else_try),
  42686. (eq, ":center_object_lord", "$g_talk_troop"),
  42687. (store_faction_of_party, ":current_center_faction", ":center_object"),
  42688. (eq, ":current_center_faction", "$players_kingdom"),
  42689. (neq, "$g_talk_troop_faction", "$players_kingdom"),
  42690.  
  42691. (assign, ":comment", "str_comment_you_captured_my_castle_enemy"),
  42692. (assign, ":relevance", 200),
  42693. (else_try),
  42694. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  42695. (lt, ":players_kingdom_relation", 0),
  42696. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42697. (eq, ":reputation", lrep_debauched),
  42698. (assign, ":comment", "str_comment_you_captured_a_castle_allied_spiteful"),
  42699. (assign, ":relevance", 75),
  42700. (else_try),
  42701. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  42702. (lt, ":players_kingdom_relation", 0),
  42703. (gt, "$g_talk_troop_relation", 5),
  42704. (assign, ":comment", "str_comment_you_captured_a_castle_allied_friendly"),
  42705. (assign, ":relevance", 75),
  42706. (else_try),
  42707. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  42708. (lt, ":players_kingdom_relation", 0),
  42709. (lt, "$g_talk_troop_relation", -5),
  42710. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42711. (eq, ":reputation", lrep_debauched),
  42712. (assign, ":comment", "str_comment_you_captured_a_castle_allied_unfriendly_spiteful"),
  42713. (assign, ":relevance", 75),
  42714. (else_try),
  42715. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  42716. (lt, ":players_kingdom_relation", 0),
  42717. (lt, "$g_talk_troop_relation", -5),
  42718. (assign, ":comment", "str_comment_you_captured_a_castle_allied_unfriendly"),
  42719. (assign, ":relevance", 75),
  42720. (else_try),
  42721. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  42722. (lt, ":players_kingdom_relation", 0),
  42723. (assign, ":comment", "str_comment_you_captured_a_castle_allied"),
  42724. (assign, ":relevance", 75),
  42725. (try_end),
  42726.  
  42727. (else_try),
  42728. (eq, ":entry_type", logent_player_claims_throne_1),
  42729. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  42730. (faction_slot_eq, "$g_talk_troop_faction", slot_faction_leader, "$g_talk_troop"),
  42731. (assign, ":comment", "str_comment_you_claimed_the_throne_1_player_liege"),
  42732. (assign, ":relevance", 500),
  42733. (lt, "$g_talk_troop_relation", -10),
  42734.  
  42735. (else_try),
  42736. (eq, ":entry_type", logent_player_claims_throne_2),
  42737. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  42738. (faction_slot_eq, "$g_talk_troop_faction", slot_faction_leader, "$g_talk_troop"),
  42739. (assign, ":comment", "str_comment_you_claimed_the_throne_2_player_liege"),
  42740. (assign, ":relevance", 500),
  42741. (lt, "$g_talk_troop_relation", -10),
  42742.  
  42743. (else_try), #player appointed a commoner
  42744. (eq, ":entry_type", logent_liege_grants_fief_to_vassal),
  42745. (eq, ":actor", "trp_player"),
  42746. (troop_slot_ge, ":troop_object", slot_lord_reputation_type, lrep_roguish),
  42747. ##diplomacy start+
  42748. (neq, ":troop_object", "trp_npc13"),#Nizar isn't a commoner
  42749. (neg|troop_slot_ge, ":troop_object", slot_lord_reputation_type, lrep_conventional),#ladies aren't commoners
  42750. (assign, ":return_reg4", 0),
  42751. (try_begin),
  42752. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  42753. (assign, ":return_reg4", 1),
  42754. (try_end),
  42755. ##diplomacy end+
  42756. (try_begin),
  42757. ##diplomacy start+
  42758. #Companions: make a supportive remark if the person is compatible with you
  42759. (is_between, "$g_talk_troop", companions_begin, companions_end),
  42760. (troop_slot_eq, "$g_talk_troop", slot_troop_personalitymatch_object, ":troop_object"),
  42761. (assign, ":comment", "str_dplmc_comment_you_enfiefed_a_commoner_supportive"),
  42762. (assign, ":relevance", 100),
  42763. (assign, ":suggested_relation_change", 0),
  42764. (else_try),
  42765. #Make a supportive remark if you like the person a lot (overrides objections)
  42766. (call_script, "script_troop_get_relation_with_troop", ":troop_object", "$g_talk_troop"),
  42767. (ge, reg0, 50),
  42768. (assign, ":comment", "str_dplmc_comment_you_enfiefed_a_commoner_supportive"),
  42769. (assign, ":relevance", 100),
  42770. (assign, ":suggested_relation_change", 0),
  42771. (else_try),
  42772. #Make a supportive remark if you like the person and wouldn't ordinarily object
  42773. (ge, reg0, 20),
  42774. (this_or_next|is_between, ":true_reputation", lrep_roguish, lrep_conventional),
  42775. (this_or_next|eq, ":reputation", lrep_cunning),
  42776. (eq, ":reputation", lrep_goodnatured),
  42777. (assign, ":comment", "str_dplmc_comment_you_enfiefed_a_commoner_supportive"),
  42778. (assign, ":relevance", 100),
  42779. (assign, ":suggested_relation_change", 0),
  42780. (else_try),
  42781. #Don't complain about your own spouse.
  42782. (troop_slot_eq, "$g_talk_troop", ":troop_object", slot_troop_spouse),
  42783. (else_try),
  42784. #Don't complain if you aren't actually a lord.
  42785. (is_between, ":true_reputation", lrep_roguish, lrep_conventional),
  42786. (else_try),
  42787. ##diplomacy end+
  42788. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42789. (eq, ":reputation", lrep_debauched),
  42790. (assign, ":comment", "str_comment_you_enfiefed_a_commoner_nasty"),##diplomacy start+ note: this line uses reg4 from above for gender-correct pronoun ##diplomacy end+
  42791. (assign, ":relevance", 100),
  42792. (assign, ":suggested_relation_change", -3),
  42793.  
  42794. (else_try),
  42795. (eq, ":reputation", lrep_upstanding),
  42796. (assign, ":comment", "str_comment_you_enfiefed_a_commoner_hesitant"),##diplomacy start+ note: next line uses reg4 from above for gender-correct pronoun ##diplomacy end+
  42797. (assign, ":relevance", 100),
  42798. (assign, ":suggested_relation_change", -2),
  42799.  
  42800. (else_try),
  42801. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  42802. (eq, ":reputation", lrep_martial),
  42803. (assign, ":comment", "str_comment_you_enfiefed_a_commoner_derisive"),##diplomacy start+ note: next line uses reg4 from above for gender-correct pronoun ##diplomacy end+
  42804. (assign, ":relevance", 100),
  42805. (assign, ":suggested_relation_change", -4),
  42806.  
  42807. (try_end),
  42808.  
  42809. #Post 0907 changes begin
  42810. (else_try),
  42811. (this_or_next|eq, ":entry_type", logent_lord_defeated_by_player),
  42812. (eq, ":entry_type", logent_lord_helped_by_player),
  42813. (troop_slot_eq, "$g_talk_troop", slot_troop_present_at_event, ":log_entry_no"),
  42814. (try_begin),
  42815. (lt, "$g_talk_troop_relation", -5),
  42816. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42817. (eq, ":reputation", lrep_debauched),
  42818. (assign, ":comment", "str_comment_we_defeated_a_lord_unfriendly_spiteful"),
  42819. (assign, ":relevance", 150),
  42820. (else_try),
  42821. (lt, "$g_talk_troop_relation", -5),
  42822. (assign, ":comment", "str_comment_we_defeated_a_lord_unfriendly"),
  42823. (assign, ":relevance", 150),
  42824. (else_try),
  42825. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  42826. (eq, ":reputation", lrep_debauched),
  42827. (assign, ":comment", "str_comment_we_defeated_a_lord_cruel"),
  42828. (assign, ":relevance", 150),
  42829. (else_try),
  42830. (eq, ":reputation", lrep_quarrelsome),
  42831. (assign, ":comment", "str_comment_we_defeated_a_lord_cruel"),
  42832. (assign, ":relevance", 150),
  42833. (else_try),
  42834. (eq, ":reputation", lrep_upstanding),
  42835. (assign, ":comment", "str_comment_we_defeated_a_lord_upstanding"),
  42836. (assign, ":relevance", 150),
  42837. (else_try),
  42838. (assign, ":comment", "str_comment_we_defeated_a_lord_default"),
  42839. (assign, ":relevance", 150),
  42840. (try_end),
  42841.  
  42842. (else_try),
  42843. (this_or_next|eq, ":entry_type", logent_castle_captured_by_player),
  42844. (eq, ":entry_type", logent_player_participated_in_siege),
  42845.  
  42846. (troop_slot_eq, "$g_talk_troop", slot_troop_present_at_event, ":log_entry_no"),
  42847.  
  42848. (try_begin),
  42849. (lt, "$g_talk_troop_relation", -5),
  42850. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42851. (eq, ":reputation", lrep_debauched),
  42852. (assign, ":comment", "str_comment_we_fought_in_siege_unfriendly_spiteful"),
  42853. (assign, ":relevance", 150),
  42854. (else_try),
  42855. (lt, "$g_talk_troop_relation", -5),
  42856. (assign, ":comment", "str_comment_we_fought_in_siege_unfriendly"),
  42857. (assign, ":relevance", 150),
  42858. (else_try),
  42859. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  42860. (eq, ":reputation", lrep_debauched),
  42861. (assign, ":comment", "str_comment_we_fought_in_siege_cruel"),
  42862. (assign, ":relevance", 150),
  42863. (assign, ":suggested_relation_change", 1),
  42864. (else_try),
  42865. (eq, ":reputation", lrep_quarrelsome),
  42866. (assign, ":comment", "str_comment_we_fought_in_siege_quarrelsome"),
  42867. (assign, ":relevance", 150),
  42868. (assign, ":suggested_relation_change", 1),
  42869. (else_try),
  42870. (eq, ":reputation", lrep_upstanding),
  42871. (assign, ":comment", "str_comment_we_fought_in_siege_upstanding"),
  42872. (assign, ":relevance", 150),
  42873. (assign, ":suggested_relation_change", 1),
  42874. (else_try),
  42875. (eq, ":reputation", lrep_martial),
  42876. (assign, ":comment", "str_comment_we_fought_in_siege_default"),
  42877. (assign, ":relevance", 150),
  42878. (assign, ":suggested_relation_change", 2),
  42879. (else_try),
  42880. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "$g_talk_troop"),
  42881. (assign, ":comment", "str_comment_we_fought_in_siege_default"),
  42882. (assign, ":relevance", 150),
  42883. (assign, ":suggested_relation_change", 1),
  42884. (else_try),
  42885. (assign, ":comment", "str_comment_we_fought_in_siege_default"),
  42886. (assign, ":relevance", 150),
  42887. (assign, ":suggested_relation_change", 1),
  42888. (try_end),
  42889.  
  42890. (else_try),
  42891. (eq, ":entry_type", logent_castle_given_to_lord_by_player),
  42892.  
  42893. (try_begin),
  42894. (eq, ":troop_object", "$g_talk_troop"),
  42895. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42896. (eq, ":reputation", lrep_debauched),
  42897. (assign, ":comment", "str_comment_you_give_castle_in_my_control"),
  42898. (assign, ":relevance", 200),
  42899. (else_try),
  42900. (eq, ":troop_object", "$g_talk_troop"),
  42901. (this_or_next|eq, ":reputation", lrep_martial),
  42902. (eq, ":reputation", lrep_goodnatured),
  42903. (assign, ":comment", "str_comment_you_give_castle_in_my_control"),
  42904. (assign, ":relevance", 200),
  42905. (else_try),
  42906. (eq, ":troop_object", "$g_talk_troop"),
  42907. (assign, ":comment", "str_comment_you_give_castle_in_my_control"),
  42908. (assign, ":relevance", 200),
  42909. (try_end),
  42910.  
  42911. (else_try),
  42912. (eq, ":entry_type", logent_player_participated_in_major_battle),
  42913. (troop_slot_eq, "$g_talk_troop", slot_troop_present_at_event, ":log_entry_no"),
  42914. (try_begin),
  42915. (lt, "$g_talk_troop_relation", -5),
  42916. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  42917. (eq, ":reputation", lrep_debauched),
  42918. (assign, ":comment", "str_comment_we_fought_in_major_battle_unfriendly_spiteful"),
  42919. (assign, ":relevance", 150),
  42920. (else_try),
  42921. (lt, "$g_talk_troop_relation", -5),
  42922. (assign, ":comment", "str_comment_we_fought_in_major_battle_unfriendly"),
  42923. (assign, ":relevance", 150),
  42924. (else_try),
  42925. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  42926. (eq, ":reputation", lrep_debauched),
  42927. (assign, ":comment", "str_comment_we_fought_in_major_battle_cruel"),
  42928. (assign, ":relevance", 150),
  42929. (assign, ":suggested_relation_change", 1),
  42930. (else_try),
  42931. (eq, ":reputation", lrep_quarrelsome),
  42932. (assign, ":comment", "str_comment_we_fought_in_major_battle_cruel"),
  42933. (assign, ":relevance", 150),
  42934. (assign, ":suggested_relation_change", 1),
  42935. (else_try),
  42936. (eq, ":reputation", lrep_upstanding),
  42937. (assign, ":comment", "str_comment_we_fought_in_major_battle_upstanding"),
  42938. (assign, ":relevance", 150),
  42939. (assign, ":suggested_relation_change", 1),
  42940. (else_try),
  42941. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "$g_talk_troop"),
  42942. (assign, ":comment", "str_comment_we_fought_in_major_battle_default"),
  42943. (assign, ":relevance", 150),
  42944. (assign, ":suggested_relation_change", 1),
  42945. (else_try),
  42946. (eq, ":reputation", lrep_martial),
  42947. (assign, ":comment", "str_comment_we_fought_in_major_battle_default"),
  42948. (assign, ":relevance", 150),
  42949. (assign, ":suggested_relation_change", 2),
  42950. (else_try),
  42951. (assign, ":comment", "str_comment_we_fought_in_major_battle_default"),
  42952. (assign, ":relevance", 150),
  42953. (assign, ":suggested_relation_change", 1),
  42954. (try_end),
  42955.  
  42956. (else_try),
  42957. (eq, ":entry_type", logent_player_suggestion_succeeded),
  42958. (try_begin),
  42959. (eq, ":troop_object", "$g_talk_troop"),
  42960. (assign, ":comment", "str_comment_player_suggestion_succeeded"),
  42961. (assign, ":relevance", 200),
  42962. (assign, ":suggested_relation_change", 3),
  42963.  
  42964. (try_end),
  42965. (else_try),
  42966. (eq, ":entry_type", logent_player_suggestion_failed),
  42967. (try_begin),
  42968. (eq, ":troop_object", "$g_talk_troop"),
  42969. (assign, ":comment", "str_comment_player_suggestion_failed"),
  42970. (assign, ":relevance", 200),
  42971. (assign, ":suggested_relation_change", -5),
  42972.  
  42973. (try_end),
  42974.  
  42975. #Post 0907 changes end
  42976.  
  42977. (else_try),
  42978. (eq, ":entry_type", logent_lord_defeated_by_player),
  42979. ##diplomacy start+ Set reg4 for calling scripts
  42980. (try_begin),
  42981. (neq, ":troop_object", "$g_talk_troop"),
  42982. (assign, ":return_reg4", 0),
  42983. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  42984. (assign, ":return_reg4", 1),
  42985. (try_end),
  42986. ##diplomacy end+
  42987. (try_begin),
  42988. (eq, ":troop_object", "$g_talk_troop"),
  42989. (this_or_next|eq, ":reputation", lrep_martial),
  42990. (eq, ":reputation", lrep_goodnatured),
  42991. (assign, ":comment", "str_comment_you_defeated_me_enemy_chivalrous"),
  42992. (assign, ":relevance", 200),
  42993. (else_try),
  42994. (eq, ":troop_object", "$g_talk_troop"),
  42995. (this_or_next|eq, ":reputation", lrep_debauched),
  42996. (eq, ":reputation", lrep_quarrelsome),
  42997. (assign, ":comment", "str_comment_you_defeated_me_enemy_spiteful"),
  42998. (assign, ":relevance", 200),
  42999. (else_try),
  43000. (eq, ":troop_object", "$g_talk_troop"),
  43001. (assign, ":comment", "str_comment_you_defeated_me_enemy"),
  43002. (assign, ":relevance", 200),
  43003. (else_try),
  43004. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43005. (this_or_next|eq, ":reputation", lrep_upstanding),
  43006. (eq, ":reputation", lrep_cunning),
  43007. (assign, ":comment", "str_comment_you_defeated_my_friend_enemy_pragmatic"),
  43008. (assign, ":relevance", 85),
  43009. (else_try),
  43010. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43011. (this_or_next|eq, ":reputation", lrep_martial),
  43012. (eq, ":reputation", lrep_goodnatured),
  43013. (assign, ":comment", "str_comment_you_defeated_my_friend_enemy_chivalrous"),
  43014. (assign, ":relevance", 85),
  43015. (else_try),
  43016. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43017. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43018. (eq, ":reputation", lrep_debauched),
  43019. (assign, ":comment", "str_comment_you_defeated_my_friend_enemy_spiteful"),
  43020. (assign, ":relevance", 85),
  43021. (else_try),
  43022. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43023. (assign, ":comment", "str_comment_you_defeated_my_friend_enemy"),
  43024. (assign, ":relevance", 85),
  43025. (else_try),
  43026. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43027. (lt, ":players_kingdom_relation", 0),
  43028. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "$g_talk_troop"),
  43029. (assign, ":comment", "str_comment_you_defeated_a_lord_allied_liege"),
  43030. (assign, ":relevance", 150),
  43031. (assign, ":suggested_relation_change", 1),
  43032.  
  43033. (else_try),
  43034. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43035. (lt, ":players_kingdom_relation", 0),
  43036. (lt, "$g_talk_troop_relation", -5),
  43037. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43038. (eq, ":reputation", lrep_debauched),
  43039. (assign, ":comment", "str_comment_you_defeated_a_lord_allied_unfriendly_spiteful"),
  43040. (assign, ":relevance", 65),
  43041. (else_try),
  43042. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43043. (lt, ":players_kingdom_relation", 0),
  43044. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43045. (eq, ":reputation", lrep_debauched),
  43046. (assign, ":comment", "str_comment_you_defeated_a_lord_allied_spiteful"),
  43047. (assign, ":relevance", 65),
  43048. (else_try),
  43049. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43050. (lt, ":players_kingdom_relation", 0),
  43051. (lt, "$g_talk_troop_relation", -5),
  43052. (this_or_next|eq, ":reputation", lrep_upstanding),
  43053. (eq, ":reputation", lrep_martial),
  43054. (assign, ":comment", "str_comment_you_defeated_a_lord_allied_unfriendly_chivalrous"),
  43055. (assign, ":relevance", 65),
  43056. (else_try),
  43057. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43058. (lt, ":players_kingdom_relation", 0),
  43059. (assign, ":comment", "str_comment_you_defeated_a_lord_allied"),
  43060. (assign, ":relevance", 65),
  43061. (try_end),
  43062.  
  43063. (else_try),
  43064. (eq, ":entry_type", logent_lord_defeated_by_player),
  43065. ##diplomacy start+ Set reg4 for calling scripts
  43066. (try_begin),
  43067. (neq, ":troop_object", "$g_talk_troop"),
  43068. (assign, ":return_reg4", 0),
  43069. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43070. (assign, ":return_reg4", 1),
  43071. (try_end),
  43072. ##diplomacy end+
  43073. (try_begin),
  43074. (eq, ":troop_object", "$g_talk_troop"),
  43075. (this_or_next|eq, ":reputation", lrep_martial),
  43076. (eq, ":reputation", lrep_goodnatured),
  43077. (assign, ":comment", "str_comment_you_defeated_me_enemy_chivalrous"),
  43078. (assign, ":relevance", 200),
  43079. (else_try),
  43080. (eq, ":troop_object", "$g_talk_troop"),
  43081. (this_or_next|eq, ":reputation", lrep_debauched),
  43082. (eq, ":reputation", lrep_quarrelsome),
  43083. (assign, ":comment", "str_comment_you_defeated_me_enemy_spiteful"),
  43084. (assign, ":relevance", 200),
  43085. (else_try),
  43086. (eq, ":troop_object", "$g_talk_troop"),
  43087. (assign, ":comment", "str_comment_you_defeated_me_enemy"),
  43088. (assign, ":relevance", 200),
  43089. (else_try),
  43090. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43091. (this_or_next|eq, ":reputation", lrep_upstanding),
  43092. (eq, ":reputation", lrep_cunning),
  43093. (assign, ":comment", "str_comment_you_defeated_my_friend_enemy_pragmatic"),
  43094. (assign, ":relevance", 85),
  43095. (else_try),
  43096. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43097. (this_or_next|eq, ":reputation", lrep_martial),
  43098. (eq, ":reputation", lrep_goodnatured),
  43099. (assign, ":comment", "str_comment_you_defeated_my_friend_enemy_chivalrous"),
  43100. (assign, ":relevance", 85),
  43101. (else_try),
  43102. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43103. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43104. (eq, ":reputation", lrep_debauched),
  43105. (assign, ":comment", "str_comment_you_defeated_my_friend_enemy_spiteful"),
  43106. (assign, ":relevance", 85),
  43107. (else_try),
  43108. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43109. (assign, ":comment", "str_comment_you_defeated_my_friend_enemy"),
  43110. (assign, ":relevance", 85),
  43111. (else_try),
  43112. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43113. (lt, ":players_kingdom_relation", 0),
  43114. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "$g_talk_troop"),
  43115. (assign, ":comment", "str_comment_you_defeated_a_lord_allied_liege"),
  43116. (assign, ":relevance", 70),
  43117. (else_try),
  43118. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43119. (lt, ":players_kingdom_relation", 0),
  43120. (lt, "$g_talk_troop_relation", -5),
  43121. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43122. (eq, ":reputation", lrep_debauched),
  43123. (assign, ":comment", "str_comment_you_defeated_a_lord_allied_unfriendly_spiteful"),
  43124. (assign, ":relevance", 65),
  43125. (else_try),
  43126. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43127. (lt, ":players_kingdom_relation", 0),
  43128. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43129. (eq, ":reputation", lrep_debauched),
  43130. (assign, ":comment", "str_comment_you_defeated_a_lord_allied_spiteful"),
  43131. (assign, ":relevance", 65),
  43132. (else_try),
  43133. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43134. (lt, ":players_kingdom_relation", 0),
  43135. (lt, "$g_talk_troop_relation", -5),
  43136. (this_or_next|eq, ":reputation", lrep_upstanding),
  43137. (eq, ":reputation", lrep_martial),
  43138. (assign, ":comment", "str_comment_you_defeated_a_lord_allied_unfriendly_chivalrous"),
  43139. (assign, ":relevance", 65),
  43140. (else_try),
  43141. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43142. (lt, ":players_kingdom_relation", 0),
  43143. (assign, ":comment", "str_comment_you_defeated_a_lord_allied"),
  43144. (assign, ":relevance", 65),
  43145. (try_end),
  43146.  
  43147. #Post 0907 changes begin
  43148. (else_try),
  43149. (eq, ":entry_type", logent_lord_helped_by_player),
  43150. (neq, ":troop_object", "$g_talk_troop"),
  43151. (eq, ":troop_object_faction", "$g_talk_troop_faction"),
  43152. ##diplomacy start+ Set reg4 for calling scripts
  43153. (assign, ":return_reg4", 0),
  43154. (try_begin),
  43155. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43156. (assign, ":return_reg4", 1),
  43157. (try_end),
  43158. ##diplomacy end+
  43159. (try_begin),
  43160. (lt, "$g_talk_troop_relation", -5),
  43161. (this_or_next|eq, ":reputation", lrep_upstanding),
  43162. (eq, ":reputation", lrep_martial),
  43163. (assign, ":comment", "str_comment_you_helped_my_ally_unfriendly_chivalrous"),
  43164. (assign, ":relevance", 65),
  43165. (assign, ":suggested_relation_change", 2),
  43166. (else_try),
  43167. (lt, "$g_talk_troop_relation", -5),
  43168. (assign, ":comment", "str_comment_you_helped_my_ally_unfriendly"),
  43169. (assign, ":relevance", 0),
  43170. (else_try),
  43171. ##diplomacy start+
  43172. (gt, ":speaker_is_a_liege", 0),#Explicitly check if the speaker is a liege rather than relying solely on reputation
  43173. ##diplomacy end+
  43174. (eq, ":reputation", lrep_none),
  43175. (assign, ":comment", "str_comment_you_helped_my_ally_liege"),
  43176. (assign, ":relevance", 65),
  43177. (assign, ":suggested_relation_change", 3),
  43178. (else_try),
  43179. (lt, "$g_talk_troop_relation", -5),
  43180. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43181. (eq, ":reputation", lrep_debauched),
  43182. (assign, ":comment", "str_comment_you_helped_my_ally_unfriendly_spiteful"),
  43183. (assign, ":relevance", 65),
  43184. (else_try),
  43185. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43186. (eq, ":reputation", lrep_debauched),
  43187. (assign, ":comment", "str_comment_you_helped_my_ally_spiteful"),
  43188. (assign, ":relevance", 65),
  43189. (else_try),
  43190. (this_or_next|eq, ":reputation", lrep_martial),
  43191. (eq, ":reputation", lrep_upstanding),
  43192. (assign, ":comment", "str_comment_you_helped_my_ally_chivalrous"),
  43193. (assign, ":relevance", 65),
  43194. (assign, ":suggested_relation_change", 2),
  43195. (else_try),
  43196. (eq, ":troop_object", "$g_talk_troop"),
  43197. (assign, ":comment", "str_comment_you_helped_my_ally_default"),
  43198. (try_end),
  43199.  
  43200. #Post 0907 changes begin
  43201. (else_try),
  43202. (eq, ":entry_type", logent_player_defeated_by_lord),
  43203. ##diplomacy start+ Set reg4 for calling scripts
  43204. (try_begin),
  43205. (neq, ":troop_object", "$g_talk_troop"),
  43206. (assign, ":return_reg4", 0),
  43207. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43208. (assign, ":return_reg4", 1),
  43209. (try_end),
  43210. ##diplomacy end+
  43211. (troop_slot_eq, "$g_talk_troop", slot_troop_present_at_event, ":log_entry_no"),
  43212. (try_begin),
  43213. (lt, "$g_talk_troop_relation", -5),
  43214. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43215. (eq, ":reputation", lrep_debauched),
  43216. (assign, ":comment", "str_comment_we_were_defeated_unfriendly_spiteful"),
  43217. (assign, ":relevance", 150),
  43218. (else_try),
  43219. (lt, "$g_talk_troop_relation", -5),
  43220. (assign, ":comment", "str_comment_we_were_defeated_unfriendly"),
  43221. (assign, ":relevance", 150),
  43222. (else_try),
  43223. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43224. (eq, ":reputation", lrep_debauched),
  43225. (assign, ":comment", "str_comment_we_were_defeated_cruel"),
  43226. (assign, ":relevance", 150),
  43227. (else_try),
  43228. (assign, ":comment", "str_comment_we_were_defeated_default"),
  43229. (assign, ":relevance", 150),
  43230. (try_end),
  43231.  
  43232. (else_try),
  43233. (eq, ":entry_type", logent_player_defeated_by_lord),
  43234. ##diplomacy start+ Set reg4 for calling scripts
  43235. (try_begin),
  43236. (neq, ":troop_object", "$g_talk_troop"),
  43237. (assign, ":return_reg4", 0),
  43238. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43239. (assign, ":return_reg4", 1),
  43240. (try_end),
  43241. ##diplomacy end+
  43242. (try_begin),
  43243. (eq, ":troop_object", "$g_talk_troop"),
  43244. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43245. (eq, ":reputation", lrep_debauched),
  43246. (assign, ":comment", "str_comment_I_defeated_you_enemy_spiteful"),
  43247. (assign, ":relevance", 200),
  43248. (else_try),
  43249. (eq, ":troop_object", "$g_talk_troop"),
  43250. (eq, ":reputation", lrep_martial),
  43251. (assign, ":comment", "str_comment_I_defeated_you_enemy_chivalrous"),
  43252. (assign, ":relevance", 200),
  43253. (else_try),
  43254. (eq, ":troop_object", "$g_talk_troop"),
  43255. (this_or_next|eq, ":reputation", lrep_goodnatured),
  43256. (eq, ":reputation", lrep_upstanding),
  43257. (assign, ":comment", "str_comment_I_defeated_you_enemy_benevolent"),
  43258. (assign, ":relevance", 200),
  43259. (else_try),
  43260. (eq, ":troop_object", "$g_talk_troop"),
  43261. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43262. (eq, ":reputation", lrep_cunning),
  43263. (assign, ":comment", "str_comment_I_defeated_you_enemy_coldblooded"),
  43264. (assign, ":relevance", 200),
  43265. (else_try),
  43266. (eq, ":troop_object", "$g_talk_troop"),
  43267. (assign, ":comment", "str_comment_I_defeated_you_enemy"),
  43268. (assign, ":relevance", 200),
  43269. (else_try),
  43270. (eq, ":troop_object", "$g_talk_troop"),
  43271. (assign, ":comment", "str_comment_I_defeated_you_enemy"),
  43272. (assign, ":relevance", 200),
  43273. (else_try),
  43274. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43275. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43276. (eq, ":reputation", lrep_debauched),
  43277. (gt, "$g_talk_troop_relation", 5),
  43278. (assign, ":comment", "str_comment_you_were_defeated_allied_friendly_spiteful"),
  43279. (assign, ":relevance", 80),
  43280. (else_try),
  43281. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43282. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43283. (eq, ":reputation", lrep_debauched),
  43284. (lt, "$g_talk_troop_relation", -5),
  43285. (assign, ":comment", "str_comment_you_were_defeated_allied_unfriendly_cruel"),
  43286. (assign, ":relevance", 80),
  43287. (else_try),
  43288. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43289. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43290. (eq, ":reputation", lrep_debauched),
  43291. (le, "$g_talk_troop_relation", 5),
  43292. (assign, ":comment", "str_comment_you_were_defeated_allied_spiteful"),
  43293. (assign, ":relevance", 80),
  43294. (else_try),
  43295. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43296. (eq, ":reputation", lrep_selfrighteous),
  43297. (assign, ":comment", "str_comment_you_were_defeated_allied_pitiless"),
  43298. (assign, ":relevance", 65),
  43299. (else_try),
  43300. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43301. (eq, ":reputation", lrep_upstanding),
  43302. (lt, "$g_talk_troop_relation", -15),
  43303. (assign, ":comment", "str_comment_you_were_defeated_allied_unfriendly_upstanding"),
  43304. (assign, ":relevance", 65),
  43305. (else_try),
  43306. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43307. (lt, "$g_talk_troop_relation", -10),
  43308. (assign, ":comment", "str_comment_you_were_defeated_allied_unfriendly"),
  43309. (assign, ":relevance", 65),
  43310. (else_try),
  43311. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43312. (assign, ":comment", "str_comment_you_were_defeated_allied"),
  43313. (assign, ":relevance", 65),
  43314. (try_end),
  43315. #Post 0907 changes end
  43316.  
  43317. #Post 0907 changes begin
  43318. (else_try),
  43319. (eq, ":entry_type", logent_player_retreated_from_lord),
  43320. (troop_slot_eq, "$g_talk_troop", slot_troop_present_at_event, ":log_entry_no"),
  43321. ##diplomacy start+ Set reg4 for calling scripts
  43322. (try_begin),
  43323. (neq, ":troop_object", "$g_talk_troop"),
  43324. (assign, ":return_reg4", 0),
  43325. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43326. (assign, ":return_reg4", 1),
  43327. (try_end),
  43328. ##diplomacy end+
  43329. (try_begin),
  43330. (lt, "$g_talk_troop_relation", -5),
  43331. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43332. (eq, ":reputation", lrep_debauched),
  43333. (assign, ":comment", "str_comment_you_abandoned_us_unfriendly_spiteful"),
  43334. (assign, ":relevance", 150),
  43335. (assign, ":suggested_relation_change", -5),
  43336. (else_try),
  43337. (lt, "$g_talk_troop_relation", -5),
  43338. (eq, ":reputation", lrep_selfrighteous),
  43339. (assign, ":comment", "str_comment_you_abandoned_us_unfriendly_pitiless"),
  43340. (assign, ":relevance", 150),
  43341. (assign, ":suggested_relation_change", -5),
  43342. (else_try),
  43343. (lt, "$g_talk_troop_relation", -5),
  43344. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43345. (eq, ":reputation", lrep_debauched),
  43346. (assign, ":comment", "str_comment_you_abandoned_us_spiteful"),
  43347. (assign, ":suggested_relation_change", -5),
  43348. (else_try),
  43349. (eq, ":reputation", lrep_martial),
  43350. (assign, ":comment", "str_comment_you_abandoned_us_chivalrous"),
  43351. (assign, ":relevance", 150),
  43352. (assign, ":suggested_relation_change", -2),
  43353. (else_try),
  43354. (this_or_next|eq, ":reputation", lrep_upstanding),
  43355. (eq, ":reputation", lrep_goodnatured),
  43356. (assign, ":comment", "str_comment_you_abandoned_us_benefitofdoubt"),
  43357. (assign, ":relevance", 150),
  43358. (assign, ":suggested_relation_change", -1),
  43359. (else_try),
  43360. (assign, ":comment", "str_comment_you_abandoned_us_default"),
  43361. (assign, ":relevance", 150),
  43362. (assign, ":suggested_relation_change", -2),
  43363. (try_end),
  43364.  
  43365.  
  43366. #Post 0907 changes end
  43367.  
  43368. (else_try),
  43369. (this_or_next|eq, ":entry_type", logent_player_retreated_from_lord),
  43370. (eq, ":entry_type", logent_player_retreated_from_lord_cowardly),
  43371.  
  43372. (eq, ":troop_object", "$g_talk_troop"),
  43373. (try_begin),
  43374. (eq, "$cheat_mode", 1),
  43375. (assign, reg7, ":entry_hours_elapsed"),
  43376. (display_message, "@{!}Elapsed hours: {reg7}"),
  43377. (try_end),
  43378. (gt, ":entry_hours_elapsed", 2),
  43379. (try_begin),
  43380. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43381. (eq, ":reputation", lrep_debauched),
  43382. (assign, ":comment", "str_comment_you_ran_from_me_enemy_spiteful"),
  43383. (assign, ":relevance", 25),
  43384. (else_try),
  43385. (eq, ":reputation", lrep_martial),
  43386. (assign, ":comment", "str_comment_you_ran_from_me_enemy_chivalrous"),
  43387. (assign, ":relevance", 25),
  43388. (else_try),
  43389. (this_or_next|eq, ":reputation", lrep_goodnatured),
  43390. (eq, ":reputation", lrep_upstanding),
  43391. (assign, ":comment", "str_comment_you_ran_from_me_enemy_benevolent"),
  43392. (assign, ":relevance", 25),
  43393. (else_try),
  43394. (eq, ":reputation", lrep_cunning),
  43395. (assign, ":comment", "str_comment_you_ran_from_me_enemy_coldblooded"),
  43396. (assign, ":relevance", 25),
  43397. (else_try),
  43398. (assign, ":comment", "str_comment_you_ran_from_me_enemy"),
  43399. (assign, ":relevance", 25),
  43400. (try_end),
  43401.  
  43402. (else_try),
  43403. (eq, ":entry_type", logent_player_retreated_from_lord_cowardly),
  43404. ##diplomacy start+ Set reg4 for calling scripts
  43405. (try_begin),
  43406. (neq, ":troop_object", "$g_talk_troop"),
  43407. (assign, ":return_reg4", 0),
  43408. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43409. (assign, ":return_reg4", 1),
  43410. (try_end),
  43411. ##diplomacy end+
  43412. (try_begin),
  43413. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43414. (neq, ":troop_object", "$g_talk_troop"),
  43415. (lt, "$g_talk_troop_relation", 5),
  43416. (eq, ":reputation", lrep_martial),
  43417. (assign, ":comment", "str_comment_you_ran_from_foe_allied_chivalrous"),
  43418. (assign, ":relevance", 80),
  43419. (assign, ":suggested_relation_change", -3),
  43420. (else_try),
  43421. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43422. (neq, ":troop_object", "$g_talk_troop"),
  43423. (eq, ":reputation", lrep_upstanding),
  43424. (assign, ":comment", "str_comment_you_ran_from_foe_allied_upstanding"),
  43425. (assign, ":relevance", 80),
  43426. (assign, ":suggested_relation_change", -1),
  43427. (else_try),
  43428. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43429. (neq, ":troop_object", "$g_talk_troop"),
  43430. (lt, "$g_talk_troop_relation", 5),
  43431. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43432. (eq, ":reputation", lrep_debauched),
  43433. (assign, ":comment", "str_comment_you_ran_from_foe_allied_spiteful"),
  43434. (assign, ":relevance", 80),
  43435. (try_end),
  43436.  
  43437. (else_try),
  43438. (eq, ":entry_type", logent_lord_defeated_but_let_go_by_player),
  43439. ##diplomacy start+ Set reg4 for calling scripts
  43440. (try_begin),
  43441. (neq, ":troop_object", "$g_talk_troop"),
  43442. (assign, ":return_reg4", 0),
  43443. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43444. (assign, ":return_reg4", 1),
  43445. (try_end),
  43446. ##diplomacy end+
  43447. (try_begin),
  43448. (eq, ":troop_object", "$g_talk_troop"),
  43449. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43450. (eq, ":reputation", lrep_debauched),
  43451. (assign, ":comment", "str_comment_you_let_me_go_spiteful"),
  43452. (assign, ":relevance", 300),
  43453. (assign, ":suggested_relation_change", -15),
  43454. (else_try),
  43455. (eq, ":troop_object", "$g_talk_troop"),
  43456. (ge, "$g_talk_troop_faction_relation", 0),
  43457. (assign, ":comment", "str_comment_you_let_me_go_default"),
  43458. (assign, ":relevance", 300),
  43459. (assign, ":suggested_relation_change", 2),
  43460. (else_try),
  43461. (eq, ":troop_object", "$g_talk_troop"),
  43462. (lt, "$g_talk_troop_faction_relation", 0),
  43463. (this_or_next|eq, ":reputation", lrep_martial),
  43464. (eq, ":reputation", lrep_upstanding),
  43465. (assign, ":suggested_relation_change", 5),
  43466. (assign, ":relevance", 300),
  43467. (assign, ":comment", "str_comment_you_let_me_go_enemy_chivalrous"),
  43468. (else_try),
  43469. (eq, ":troop_object", "$g_talk_troop"),
  43470. (lt, "$g_talk_troop_faction_relation", 0),
  43471. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43472. (eq, ":reputation", lrep_cunning),
  43473. (assign, ":relevance", 300),
  43474. (assign, ":comment", "str_comment_you_let_me_go_enemy_coldblooded"),
  43475. (else_try),
  43476. (eq, ":troop_object", "$g_talk_troop"),
  43477. (lt, "$g_talk_troop_faction_relation", 0),
  43478. (assign, ":relevance", 300),
  43479. (assign, ":comment", "str_comment_you_let_me_go_enemy"),
  43480. (assign, ":suggested_relation_change", 1),
  43481. (else_try),
  43482. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43483. (lt, ":players_kingdom_relation", 0),
  43484. (neq, ":troop_object", "$g_talk_troop"),
  43485. (this_or_next|eq, ":reputation", lrep_martial),
  43486. (eq, ":reputation", lrep_goodnatured),
  43487. (assign, ":comment", "str_comment_you_let_go_a_lord_allied_chivalrous"),
  43488. (assign, ":relevance", 80),
  43489. (else_try),
  43490. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43491. (lt, ":players_kingdom_relation", 0),
  43492. (neq, ":troop_object", "$g_talk_troop"),
  43493. (eq, ":reputation", lrep_upstanding),
  43494. (assign, ":comment", "str_comment_you_let_go_a_lord_allied_upstanding"),
  43495. (assign, ":relevance", 80),
  43496. (else_try),
  43497. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43498. (lt, ":players_kingdom_relation", 0),
  43499. (neq, ":troop_object", "$g_talk_troop"),
  43500. (this_or_next|eq, ":reputation", lrep_cunning),
  43501. (eq, ":reputation", lrep_selfrighteous),
  43502. (assign, ":comment", "str_comment_you_let_go_a_lord_allied_coldblooded"),
  43503. (assign, ":relevance", 80),
  43504. (else_try),
  43505. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43506. (lt, ":players_kingdom_relation", 0),
  43507. (neq, ":troop_object", "$g_talk_troop"),
  43508. (lt, "$g_talk_troop_relation", -5),
  43509. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43510. (eq, ":reputation", lrep_debauched),
  43511. (assign, ":comment", "str_comment_you_let_go_a_lord_allied_unfriendly_spiteful"),
  43512. (assign, ":relevance", 80),
  43513. (else_try),
  43514. (eq, "$players_kingdom", "$g_talk_troop_faction"),
  43515. (lt, ":players_kingdom_relation", 0),
  43516. (neq, ":troop_object", "$g_talk_troop"),
  43517. (assign, ":comment", "str_comment_you_let_go_a_lord_allied"),
  43518. (assign, ":relevance", 80),
  43519. (try_end),
  43520.  
  43521. #Internal faction relations
  43522.  
  43523. (else_try),
  43524. (eq, ":entry_type", logent_pledged_allegiance),
  43525. (eq, ":actor", "trp_player"),
  43526. (try_begin),
  43527. (eq, ":faction_object", "$g_talk_troop_faction"),
  43528. (neq, ":troop_object", "$g_talk_troop"),
  43529. (eq, ":faction_object", "$players_kingdom"), #Ie, no switch of kingdoms
  43530. (assign, ":relevance", 200),
  43531. (try_begin),
  43532. (lt, "$g_talk_troop_relation", -5),
  43533. (eq, ":reputation", lrep_martial),
  43534. (assign, ":comment", "str_comment_pledged_allegiance_allied_martial_unfriendly"),
  43535. (else_try),
  43536. (eq, ":reputation", lrep_martial),
  43537. (assign, ":comment", "str_comment_pledged_allegiance_allied_martial"),
  43538. (else_try),
  43539. (lt, "$g_talk_troop_relation", -5),
  43540. (eq, ":reputation", lrep_quarrelsome),
  43541. (assign, ":comment", "str_comment_pledged_allegiance_allied_quarrelsome_unfriendly"),
  43542. (else_try),
  43543. (eq, ":reputation", lrep_quarrelsome),
  43544. (assign, ":comment", "str_comment_pledged_allegiance_allied_quarrelsome"),
  43545. (else_try),
  43546. (lt, "$g_talk_troop_relation", -5),
  43547. (eq, ":reputation", lrep_selfrighteous),
  43548. (assign, ":comment", "str_comment_pledged_allegiance_allied_selfrighteous_unfriendly"),
  43549. (else_try),
  43550. (eq, ":reputation", lrep_selfrighteous),
  43551. (assign, ":comment", "str_comment_pledged_allegiance_allied_selfrighteous"),
  43552. (else_try),
  43553. (lt, "$g_talk_troop_relation", -5),
  43554. (eq, ":reputation", lrep_cunning),
  43555. (assign, ":comment", "str_comment_pledged_allegiance_allied_cunning_unfriendly"),
  43556. (else_try),
  43557. (eq, ":reputation", lrep_cunning),
  43558. (assign, ":comment", "str_comment_pledged_allegiance_allied_cunning"),
  43559. (else_try),
  43560. (lt, "$g_talk_troop_relation", -5),
  43561. (eq, ":reputation", lrep_debauched),
  43562. (assign, ":comment", "str_comment_pledged_allegiance_allied_debauched_unfriendly"),
  43563. (else_try),
  43564. (eq, ":reputation", lrep_debauched),
  43565. (assign, ":comment", "str_comment_pledged_allegiance_allied_debauched"),
  43566. (else_try),
  43567. (lt, "$g_talk_troop_relation", -5),
  43568. (eq, ":reputation", lrep_goodnatured),
  43569. (assign, ":comment", "str_comment_pledged_allegiance_allied_goodnatured_unfriendly"),
  43570. (else_try),
  43571. (eq, ":reputation", lrep_goodnatured),
  43572. (assign, ":comment", "str_comment_pledged_allegiance_allied_goodnatured"),
  43573. (else_try),
  43574. (lt, "$g_talk_troop_relation", -5),
  43575. (eq, ":reputation", lrep_upstanding),
  43576. (assign, ":comment", "str_comment_pledged_allegiance_allied_upstanding_unfriendly"),
  43577. (else_try),
  43578. (eq, ":reputation", lrep_upstanding),
  43579. (assign, ":comment", "str_comment_pledged_allegiance_allied_upstanding"),
  43580. (try_end),
  43581. (try_end),
  43582.  
  43583.  
  43584. (else_try),
  43585. (eq, ":entry_type", logent_liege_grants_fief_to_vassal),
  43586. (eq, ":troop_object", "trp_player"),
  43587. (try_begin),
  43588. (eq, ":faction_object", "$g_talk_troop_faction"),
  43589. (neq, ":actor", "$g_talk_troop"),
  43590. (eq, ":faction_object", "$players_kingdom"),
  43591. (assign, ":relevance", 110),
  43592. (try_begin),
  43593. (gt, "$g_talk_troop_relation", 5),
  43594. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43595. (eq, ":reputation", lrep_debauched),
  43596. (assign, ":comment", "str_comment_our_king_granted_you_a_fief_allied_friendly_cruel"),
  43597. (else_try),
  43598. (gt, "$g_talk_troop_relation", 5),
  43599. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43600. (eq, ":reputation", lrep_cunning),
  43601. (assign, ":comment", "str_comment_our_king_granted_you_a_fief_allied_friendly_cynical"),
  43602. (else_try),
  43603. (gt, "$g_talk_troop_relation", 5),
  43604. (assign, ":comment", "str_comment_our_king_granted_you_a_fief_allied_friendly"),
  43605. (else_try),
  43606. (is_between, "$g_talk_troop_relation", -5, 5),
  43607. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43608. (eq, ":reputation", lrep_debauched),
  43609. (assign, ":comment", "str_comment_our_king_granted_you_a_fief_allied_spiteful"),
  43610. (assign, ":suggested_relation_change", -2),
  43611. (else_try),
  43612. (lt, "$g_talk_troop_relation", -5),
  43613. (eq, ":reputation", lrep_upstanding),
  43614. (assign, ":comment", "str_comment_our_king_granted_you_a_fief_allied_unfriendly_upstanding"),
  43615. (else_try),
  43616. (lt, "$g_talk_troop_relation", -5),
  43617. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43618. (eq, ":reputation", lrep_debauched),
  43619. (assign, ":comment", "str_comment_our_king_granted_you_a_fief_allied_unfriendly_spiteful"),
  43620. (else_try),
  43621. (assign, ":comment", "str_comment_our_king_granted_you_a_fief_allied"),
  43622. (try_end),
  43623. (try_end),
  43624.  
  43625. (else_try),
  43626. (eq, ":entry_type", logent_renounced_allegiance),
  43627. (eq, ":actor", "trp_player"),
  43628. (try_begin),
  43629. (eq, ":faction_object", "$g_talk_troop_faction"),
  43630. (neq, ":troop_object", "$g_talk_troop"),
  43631. (try_begin),
  43632. (ge, "$g_talk_troop_faction_relation", 0),
  43633. (neq, "$g_talk_troop_faction", "$players_kingdom"),
  43634. (assign, ":relevance", 180),
  43635. (try_begin),
  43636. (gt, "$g_talk_troop_relation", 5),
  43637. (assign, ":comment", "str_comment_you_renounced_your_alliegance_friendly"),
  43638. (else_try),
  43639. (ge, "$g_talk_troop_relation", 0),
  43640. (eq, ":reputation", lrep_goodnatured),
  43641. (assign, ":comment", "str_comment_you_renounced_your_alliegance_friendly"),
  43642. (else_try),
  43643. (assign, ":comment", "str_comment_you_renounced_your_alliegance_default"),
  43644. (try_end),
  43645. (else_try),
  43646. (lt, "$g_talk_troop_faction_relation", 0),
  43647. (assign, ":relevance", 300),
  43648. (try_begin),
  43649. (ge, "$g_talk_troop_relation", 0),
  43650. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43651. (eq, ":reputation", lrep_debauched),
  43652. (assign, ":comment", "str_comment_you_renounced_your_alliegance_unfriendly_moralizing"),
  43653. (else_try),
  43654. (gt, "$g_talk_troop_relation", 5),
  43655. (this_or_next|eq, ":reputation", lrep_goodnatured),
  43656. (eq, ":reputation", lrep_upstanding),
  43657. (assign, ":comment", "str_comment_you_renounced_your_alliegance_enemy_friendly"),
  43658. (else_try),
  43659. (gt, "$g_talk_troop_relation", 5),
  43660. (assign, ":comment", "str_comment_you_renounced_your_alliegance_enemy"),
  43661. (else_try),
  43662. (is_between, "$g_talk_troop_relation", -5, 5),
  43663. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43664. (eq, ":reputation", lrep_debauched),
  43665. (assign, ":comment", "str_comment_you_renounced_your_alliegance_unfriendly_spiteful"),
  43666. (assign, ":suggested_relation_change", -2),
  43667. (else_try),
  43668. (lt, "$g_talk_troop_relation", -5),
  43669. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43670. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43671. (eq, ":reputation", lrep_debauched),
  43672. (assign, ":comment", "str_comment_you_renounced_your_alliegance_unfriendly_spiteful"),
  43673. (else_try),
  43674. (assign, ":comment", "str_comment_you_renounced_your_alliegance_default"),
  43675. (try_end),
  43676. (try_end),
  43677. (try_end),
  43678.  
  43679. (else_try),
  43680. (eq, ":entry_type", logent_lady_marries_lord),
  43681. (eq, ":troop_object", "trp_player"),
  43682. ##diplomacy start+ Set reg4 for calling scripts
  43683. (try_begin),
  43684. (neq, ":actor", "$g_talk_troop"),
  43685. (assign, ":return_reg4", 0),
  43686. (call_script, "script_cf_dplmc_troop_is_female", ":actor"),
  43687. (assign, ":return_reg4", 1),
  43688. (try_end),
  43689. ##diplomacy end+
  43690. (try_begin),
  43691. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43692. (eq, ":reputation", lrep_debauched),
  43693. (lt, "$g_talk_troop_relation", -5),
  43694. (assign, ":relevance", 200),
  43695. (assign, ":comment", "str_comment_marriage_normal_nasty"),
  43696. (else_try),
  43697. (call_script, "script_troop_get_family_relation_to_troop", ":actor", "$g_talk_troop"),
  43698. (ge, reg0, 5),
  43699. (assign, ":comment", "str_comment_marriage_normal_family"),
  43700. (assign, ":relevance", 300),
  43701. (assign, ":suggested_relation_change", reg0),
  43702. (val_div, ":suggested_relation_change", 3),
  43703. (else_try),
  43704. (store_faction_of_troop, ":bride_faction", ":actor"),
  43705. (eq, ":bride_faction", "$g_talk_troop_faction"),
  43706. (assign, ":comment", "str_comment_marriage_normal"),
  43707. (assign, ":relevance", 100),
  43708. (try_end),
  43709. (else_try),
  43710. (eq, ":entry_type", logent_lady_elopes_with_lord),
  43711. (eq, ":troop_object", "trp_player"),
  43712. ##diplomacy start+ Set reg4 for calling scripts
  43713. (try_begin),
  43714. (neq, ":actor", "$g_talk_troop"),
  43715. (assign, ":return_reg4", 0),
  43716. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43717. (assign, ":return_reg4", 1),
  43718. (try_end),
  43719. ##diplomacy end+
  43720. (try_begin),
  43721. (call_script, "script_troop_get_family_relation_to_troop", ":actor", "$g_talk_troop"),
  43722. (ge, reg0, 5),
  43723. (assign, ":comment", "str_comment_marriage_elopement_family"),
  43724. (assign, ":relevance", 300),
  43725. (store_sub, ":suggested_relation_change", 0, reg0),
  43726. (val_div, ":suggested_relation_change", 3),
  43727. (else_try),
  43728. (store_faction_of_troop, ":bride_faction", ":actor"),
  43729. (eq, ":bride_faction", "$g_talk_troop_faction"),
  43730. (faction_slot_eq, ":bride_faction", slot_faction_leader, "$g_talk_troop"),
  43731. (assign, ":comment", "str_comment_marriage_elopement_liege"),
  43732. (assign, ":relevance", 300),
  43733. (assign, ":suggested_relation_change", -10),
  43734. (try_end),
  43735. (else_try), #this is specific to quarrels with the player
  43736. (eq, ":entry_type", logent_lords_quarrel_over_woman),
  43737. (eq, ":actor", "$g_talk_troop"),
  43738. (eq, ":center_object", "trp_player"),
  43739.  
  43740. (neg|troop_slot_ge, ":troop_object", slot_troop_spouse, "trp_player"),
  43741.  
  43742. (str_store_troop_name, s54, ":troop_object"),
  43743. ##diplomacy start+ Set reg4 for calling scripts
  43744. (assign, ":return_reg4", 0),
  43745. (try_begin),
  43746. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43747. (assign, ":return_reg4", 1),
  43748. (try_end),
  43749. ##diplomacy end+
  43750. (try_begin),
  43751. (this_or_next|eq, ":reputation", lrep_selfrighteous),
  43752. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43753. (eq, ":reputation", lrep_debauched),
  43754.  
  43755. (assign, ":comment", "str_comment_i_quarreled_with_you_over_woman_derisive"),
  43756. (assign, ":relevance", 200),
  43757. (assign, ":suggested_relation_change", -20),
  43758. (else_try),
  43759. (assign, ":comment", "str_comment_i_quarreled_with_you_over_woman_default"),
  43760. (assign, ":relevance", 200),
  43761. (assign, ":suggested_relation_change", -20),
  43762. (try_end),
  43763.  
  43764. (else_try),
  43765. (eq, ":entry_type", logent_border_incident_troop_breaks_truce),
  43766. (eq, ":actor", "trp_player"),
  43767. (faction_slot_eq, ":faction_object", slot_faction_leader, "$g_talk_troop"),
  43768. (eq, "$players_kingdom", ":faction_object"),
  43769.  
  43770. (assign, ":suggested_relation_change", -10),
  43771. (assign, ":comment", "str_comment_you_broke_truce_as_my_vassal"),
  43772. (assign, ":relevance", 300),
  43773.  
  43774. (else_try),
  43775. (eq, ":entry_type", logent_border_incident_troop_attacks_neutral),
  43776. (eq, ":actor", "trp_player"),
  43777. (faction_slot_eq, ":faction_object", slot_faction_leader, "$g_talk_troop"),
  43778. (eq, "$players_kingdom", ":faction_object"),
  43779.  
  43780. (assign, ":suggested_relation_change", -3),
  43781. (assign, ":comment", "str_comment_you_attacked_neutral_as_my_vassal"),
  43782. (assign, ":relevance", 200),
  43783.  
  43784. #THE FOLLOWING ARE ALL COMPLAINTS SPOKEN BY LORDS WITHIN CONVERATIONS, RATHER THAN COMMENTS WHEN THE PLAYER FIRST SPEAKS TO A LORD
  43785. (else_try), #these need to have the actor and object strings added because they are used outside of "script_get_relevant_comment_to_s42"
  43786. (eq, ":entry_type", logent_ruler_intervenes_in_quarrel),
  43787. (eq, ":center_object", "$g_talk_troop"), #actor is liege lord, center object is loser lord, troop object is winner lord
  43788. (str_store_troop_name, s50, ":actor"),
  43789. (str_store_troop_name, s51, ":center_object"), #s50 is actor, s51 is center object, s54 is troop object
  43790. (str_store_troop_name, s54, ":troop_object"), #s50 is actor, s51 is center object, s54 is troop object
  43791. (assign, ":comment", "str_comment_lord_intervened_against_me"),
  43792. (assign, ":relevance", -1),
  43793.  
  43794. (else_try),
  43795. (eq, ":entry_type", logent_lord_protests_marshall_appointment),
  43796. (eq, ":actor", "$g_talk_troop"),
  43797.  
  43798. (str_store_troop_name, s51, ":center_object"), #s51 is center object (marshall), s54 is troop object (liege lord),
  43799. (str_store_troop_name, s54, ":troop_object"),
  43800.  
  43801. (assign, ":comment", "str_comment_i_protested_marshall_appointment"),
  43802. (assign, ":relevance", -1),
  43803.  
  43804. (else_try),
  43805. (eq, ":entry_type", logent_lord_blames_defeat),
  43806. (eq, ":actor", "$g_talk_troop"),
  43807.  
  43808. (str_store_troop_name, s51, ":center_object"), #s51 is center object (marshall), s54 is troop object (liege lord),
  43809. (str_store_troop_name, s54, ":troop_object"),
  43810. (str_store_troop_name, s56, ":faction_object"), #faction object is unusual in this circumstance
  43811.  
  43812. (assign, ":comment", "str_comment_i_blamed_defeat"),
  43813. (assign, ":relevance", -1),
  43814.  
  43815. (else_try),
  43816. (eq, ":entry_type", logent_troop_feels_cheated_by_troop_over_land),
  43817. (eq, ":actor", "$g_talk_troop"),
  43818.  
  43819. (str_store_party_name, s51, ":center_object"),
  43820. (str_store_troop_name, s54, ":troop_object"),
  43821. (str_store_troop_name, s56, ":faction_object"), #faction object is unusual in this circumstance
  43822.  
  43823. (assign, ":comment", "str_comment_i_was_entitled_to_fief"),
  43824. (assign, ":relevance", -1),
  43825.  
  43826. (else_try),
  43827. (eq, ":entry_type", logent_lords_quarrel_over_woman),
  43828. (eq, ":actor", "$g_talk_troop"),
  43829.  
  43830. (str_store_troop_name, s51, ":center_object"),
  43831. (str_store_troop_name, s54, ":troop_object"),
  43832. ##diplomacy start+ Set reg4 and reg3 for calling scripts
  43833. #(assign, reg3, 0),# #Exclude reg3, since it is used for output anyway
  43834. #(try_begin),
  43835. # (call_script, "script_cf_dplmc_troop_is_female", ":center_object"),
  43836. # (assign, reg3, 1),
  43837. #(try_end),
  43838. (assign, ":return_reg4", 0),
  43839. (try_begin),
  43840. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43841. (assign, ":return_reg4", 1),
  43842. (try_end),
  43843. ##diplomacy end+
  43844.  
  43845. (assign, ":comment", "str_comment_i_quarreled_with_troop_over_woman"),
  43846. (assign, ":relevance", -1),
  43847.  
  43848. (else_try),
  43849. (eq, ":entry_type", logent_lords_quarrel_over_woman),
  43850. (eq, ":center_object", "$g_talk_troop"),
  43851.  
  43852. (str_store_troop_name, s51, ":actor"),
  43853. (str_store_troop_name, s54, ":troop_object"),
  43854. ##diplomacy start+ Set reg4 and reg3 for calling scripts
  43855. #(assign, reg3, 0),#Exclude reg3, since it is used for output anyway
  43856. #(try_begin),
  43857. # (call_script, "script_cf_dplmc_troop_is_female", ":actor"),
  43858. # (assign, reg3, 1),
  43859. #(try_end),
  43860. (assign, ":return_reg4", 0),
  43861. (try_begin),
  43862. (call_script, "script_cf_dplmc_troop_is_female", ":troop_object"),
  43863. (assign, ":return_reg4", 1),
  43864. (try_end),
  43865. ##diplomacy end+
  43866.  
  43867. (assign, ":comment", "str_comment_i_quarreled_with_troop_over_woman"),
  43868. (assign, ":relevance", -1),
  43869.  
  43870. (else_try),
  43871. (eq, ":entry_type", logent_player_stole_cattles_from_village),
  43872.  
  43873. (eq, ":actor", "trp_player"),
  43874. (try_begin),
  43875. (eq, ":center_object_lord", "$g_talk_troop"),
  43876. (assign, ":relevance", 200),
  43877. (assign, ":suggested_relation_change", -1),
  43878. (assign, ":comment", "str_comment_you_stole_cattles_from_my_village_default"),
  43879. (try_begin),
  43880. (lt, "$g_talk_troop_faction_relation", -3),
  43881. (this_or_next|eq, ":reputation", lrep_goodnatured),
  43882. (eq, ":reputation", lrep_upstanding),
  43883. (assign, ":comment", "str_comment_you_stole_cattles_from_my_village_enemy_benevolent"),
  43884. (else_try),
  43885. (lt, "$g_talk_troop_faction_relation", -3),
  43886. (this_or_next|eq, ":reputation", lrep_cunning),
  43887. (eq, ":reputation", lrep_selfrighteous),
  43888. (assign, ":comment", "str_comment_you_stole_cattles_from_my_village_enemy_coldblooded"),
  43889. (else_try),
  43890. (lt, "$g_talk_troop_faction_relation", -3),
  43891. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43892. (eq, ":reputation", lrep_debauched),
  43893. (assign, ":comment", "str_comment_you_stole_cattles_from_my_village_enemy_spiteful"),
  43894. (else_try),
  43895. (lt, "$g_talk_troop_faction_relation", -3),
  43896. (assign, ":comment", "str_comment_you_stole_cattles_from_my_village_enemy"),
  43897. (else_try),
  43898. (lt, "$g_talk_troop_relation", -3),
  43899. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  43900. (eq, ":reputation", lrep_debauched),
  43901. (assign, ":comment", "str_comment_you_stole_cattles_from_my_village_unfriendly_spiteful"),
  43902. (else_try),
  43903. (gt, "$g_talk_troop_relation", 6),
  43904. (assign, ":comment", "str_comment_you_stole_cattles_from_my_village_friendly"),
  43905. (try_end),
  43906. (try_end),
  43907.  
  43908. (try_end),
  43909.  
  43910. (assign, reg0, ":comment"),
  43911. (assign, reg1, ":relevance"),
  43912. (assign, reg2, ":suggested_relation_change"),
  43913. (assign, reg3, ":rejoinder"),
  43914. ##diplomacy start+
  43915. (assign, reg4, ":return_reg4"),
  43916. ##diplomacy end+
  43917. ]),
  43918.  
  43919. # script_get_relevant_comment_to_s42
  43920. # Input: none
  43921. # Output: reg0 = 1 if comment found, 0 otherwise; s61 will contain comment string if found
  43922. ("get_relevant_comment_to_s42",
  43923. [
  43924.  
  43925. (troop_get_slot, ":reputation", "$g_talk_troop", slot_lord_reputation_type),
  43926. (try_begin),
  43927. (eq, "$cheat_mode", 1),
  43928. (store_add, ":rep_string", ":reputation", "str_personality_archetypes"),
  43929. (str_store_string, s15, ":rep_string"),
  43930. (display_message, "@{!}Reputation type: {s15}"),
  43931. (try_end),
  43932.  
  43933.  
  43934. (assign, ":highest_score_so_far", 50),
  43935. (assign, ":best_comment_so_far", -1),
  43936. (assign, ":rejoinder_to_best_comment_so_far", -1),
  43937. (assign, ":comment_found", 0),
  43938. (assign, ":best_log_entry", -1),
  43939. (assign, ":comment_relation_change", 0),
  43940. (store_current_hours, ":current_time"),
  43941. ##diplomacy start+
  43942. (assign, ":best_comment_reg4", 0),
  43943. ##diplomacy end+
  43944.  
  43945. #prevents multiple comments in conversations in same hour
  43946.  
  43947. # (troop_get_slot, ":talk_troop_last_comment_time", "$g_talk_troop", slot_troop_last_comment_time),
  43948. #"$num_log_entries should also be set to one, not zero. This is included in the initialize npcs script, although could be moved to game_start
  43949. (troop_get_slot, ":talk_troop_last_comment_slot", "$g_talk_troop", slot_troop_last_comment_slot),
  43950. (troop_set_slot, "$g_talk_troop", slot_troop_last_comment_slot, "$num_log_entries"),
  43951.  
  43952. (store_add, ":log_entries_plus_one", "$num_log_entries", 1),
  43953. (try_for_range, ":log_entry_no", 1, ":log_entries_plus_one"),
  43954. # It should be log entries plus one, so that the try_ sequence does not stop short of the last log entry
  43955. # $Num_log_entries is now the number of the last log entry, which begins at "1" rather than "0"
  43956. # This is so that (le, ":log_entry_no", ":talk_troop_last_comment_slot") works properly
  43957.  
  43958. (troop_get_slot, ":entry_time", "trp_log_array_entry_time", ":log_entry_no"),
  43959. # (val_max, ":entry_time", 1), #This is needed for pre-game events to be commented upon, if hours are used rather than the order of events
  43960. (store_sub, ":entry_hours_elapsed", ":current_time", ":entry_time"),
  43961. (try_begin),
  43962. (le, ":log_entry_no", ":talk_troop_last_comment_slot"),
  43963. # (le, ":entry_time", ":talk_troop_last_comment_time"),
  43964. (try_begin),
  43965. (eq, ":log_entry_no", ":talk_troop_last_comment_slot"),
  43966. (eq, "$cheat_mode", 1),
  43967. (assign, reg5, ":log_entry_no"),
  43968. (display_message, "@{!}Entries up to #{reg5} skipped"),
  43969. (try_end),
  43970. # I suggest using the log entry number as opposed to time so that events in the same hour can be commented upon
  43971. # This feels more natural, for example, if there are other lords in the court when the player pledges allegiance
  43972. (else_try),
  43973. # (le, ":entry_hours_elapsed", 3), #don't comment on really fresh events
  43974. # (else_try),
  43975. (call_script, "script_get_relevant_comment_for_log_entry", ":log_entry_no"),
  43976. (gt, reg1, 10),
  43977. (assign, ":score", reg1),
  43978. (assign, ":comment", reg0),
  43979. #reg2 is what
  43980. (assign, ":rejoinder", reg3),
  43981.  
  43982. (store_random_in_range, ":rand", 70, 140),
  43983. (val_mul, ":score", ":rand"),
  43984. (store_add, ":entry_time_score", ":entry_hours_elapsed", 500), #approx. one month
  43985. (val_mul, ":score", 1000),
  43986. (val_div, ":score", ":entry_time_score"), ###Relevance decreases over time - halved after one month, one-third after two, etc
  43987. (try_begin),
  43988. (gt, ":score", ":highest_score_so_far"),
  43989. (assign, ":highest_score_so_far", ":score"),
  43990. (assign, ":best_comment_so_far", ":comment"),
  43991. (assign, ":rejoinder_to_best_comment_so_far", ":rejoinder"),
  43992. (assign, ":best_log_entry", ":log_entry_no"),
  43993. (assign, ":comment_relation_change", reg2),
  43994. ##diplomacy start+
  43995. (assign, ":best_comment_reg4", reg4),
  43996. ##diplomacy end+
  43997. (try_end),
  43998. (try_end),
  43999. (try_end),
  44000.  
  44001. (try_begin),
  44002. (gt, ":best_comment_so_far", 0),
  44003. (assign, ":comment_found", 1), #comment found print it to s61 now.
  44004. (troop_get_slot, ":actor", "trp_log_array_actor", ":best_log_entry"),
  44005. (troop_get_slot, ":center_object", "trp_log_array_center_object", ":best_log_entry"),
  44006. (troop_get_slot, ":center_object_lord", "trp_log_array_center_object_lord", ":best_log_entry"),
  44007. (troop_get_slot, ":center_object_faction", "trp_log_array_center_object_faction", ":best_log_entry"),
  44008. (troop_get_slot, ":troop_object", "trp_log_array_troop_object", ":best_log_entry"),
  44009. (troop_get_slot, ":troop_object_faction", "trp_log_array_troop_object_faction", ":best_log_entry"),
  44010. (troop_get_slot, ":faction_object", "trp_log_array_faction_object", ":best_log_entry"),
  44011. ##diplomacy start+
  44012. (assign, reg4, ":best_comment_reg4"),
  44013. ##diplomacy end+
  44014. (try_begin),
  44015. (ge, ":actor", 0),
  44016. (str_store_troop_name, s50, ":actor"),
  44017. ##diplomacy start+
  44018. (eq, ":best_comment_so_far", "str_comment_i_quarreled_with_troop_over_woman"),
  44019. (neq, ":actor", "$g_talk_troop"),
  44020. (neq, ":actor", "trp_player"),
  44021. #SB : other script
  44022. (call_script, "script_dplmc_store_troop_is_female_reg", ":actor", 3),
  44023. ##diplomacy end+
  44024. (try_end),
  44025. (try_begin),
  44026. (ge, ":center_object", 0),
  44027. ##diplomacy start+
  44028. ##OLD:
  44029. #(str_store_party_name, s51, ":center_object"),
  44030. ##NEW:
  44031. #Alternate meaning (not usually called from this script, but just in case)
  44032. #In this case, s51 is actually a troop. Use reg3 for the gender.
  44033. (try_begin),
  44034. (eq, ":best_comment_so_far", "str_comment_i_quarreled_with_troop_over_woman"),
  44035. (str_store_troop_name, s51, ":center_object"),
  44036. (neq, ":center_object", "$g_talk_troop"),
  44037. (neq, ":center_object", "trp_player"),
  44038. (call_script, "script_dplmc_store_troop_is_female_reg", ":center_object", 3),
  44039. (else_try),
  44040. (neq, ":best_comment_so_far", "str_comment_i_quarreled_with_troop_over_woman"),
  44041. (str_store_party_name, s51, ":center_object"),#<- old behavior
  44042. (try_end),
  44043. ##diplomacy end+
  44044. (try_end),
  44045. (try_begin),
  44046. (ge, ":center_object_lord", 0),
  44047. (str_store_troop_name, s52, ":center_object_lord"),
  44048. (try_end),
  44049. (try_begin),
  44050. (ge, ":center_object_faction", 0),
  44051. (str_store_faction_name, s53, ":center_object_faction"),
  44052. (try_end),
  44053. (try_begin),
  44054. (ge, ":troop_object", 0),
  44055. (str_store_troop_name, s54, ":troop_object"),
  44056. (try_end),
  44057. (try_begin),
  44058. (is_between, ":troop_object_faction", kingdoms_begin, kingdoms_end),
  44059. (str_store_faction_name, s55, ":troop_object_faction"),
  44060. (str_store_string, s55, "str_the_s55"),
  44061. (else_try),
  44062. (is_between, ":troop_object", bandits_begin, bandits_end),
  44063. (str_store_string, s55, "str_bandits"),
  44064. (else_try),
  44065. (eq, ":troop_object_faction", "fac_deserters"),
  44066. (str_store_string, s55, "str_deserters"),
  44067. (else_try),
  44068. (str_store_string, s55, "str_travellers_on_the_road"),
  44069. (else_try),
  44070.  
  44071. (try_end),
  44072.  
  44073. (try_begin),
  44074. (ge, ":faction_object", 0),
  44075. (str_store_faction_name, s56, ":faction_object"),
  44076. (try_end),
  44077. (assign, "$g_last_comment_copied_to_s42", ":best_comment_so_far"), #maybe deprecate
  44078. (assign, "$g_rejoinder_to_last_comment", ":rejoinder_to_best_comment_so_far"),
  44079.  
  44080. (str_store_string, s42, ":best_comment_so_far"),
  44081. (try_end),
  44082.  
  44083. (assign, reg0, ":comment_found"),
  44084.  
  44085. (assign, "$log_comment_relation_change", ":comment_relation_change"),
  44086. ]),
  44087.  
  44088. #
  44089. ("merchant_road_info_to_s42", #also does itemss to s32
  44090. [
  44091. (store_script_param, ":center", 1),
  44092.  
  44093. (assign, ":last_bandit_party_found", -1),
  44094. (assign, ":last_bandit_party_origin", -1),
  44095. (assign, ":last_bandit_party_destination", -1),
  44096. (assign, ":last_bandit_party_hours_ago", -1),
  44097.  
  44098. (str_clear, s32),
  44099.  
  44100. (str_clear, s42),
  44101. (str_clear, s47), #safe roads
  44102.  
  44103. (try_for_range, ":center_to_reset", centers_begin, centers_end),
  44104. (party_set_slot, ":center_to_reset", slot_party_temp_slot_1, 0),
  44105. (try_end),
  44106.  
  44107. (assign, ":road_attacks", 0),
  44108. (assign, ":trades", 0),
  44109.  
  44110. #first mention all attacks
  44111. (try_for_range, ":log_entry_iterator", 0, "$num_log_entries"),
  44112. (store_sub, ":log_entry_no", "$num_log_entries", ":log_entry_iterator"),
  44113. #how long ago?
  44114. (this_or_next|troop_slot_eq, "trp_log_array_entry_type", ":log_entry_no", logent_traveller_attacked),
  44115. (troop_slot_eq, "trp_log_array_entry_type", ":log_entry_no", logent_party_traded),
  44116.  
  44117. # reference - (call_script, "script_add_log_entry", logent_traveller_attacked, ":winner_party" (actor), ":origin" (center object), ":destination" (troop_object), ":winner_faction"),
  44118.  
  44119. (troop_get_slot, ":origin", "trp_log_array_center_object", ":log_entry_no"),
  44120. (troop_get_slot, ":destination", "trp_log_array_troop_object", ":log_entry_no"),
  44121.  
  44122. (this_or_next|eq, ":origin", ":center"),
  44123. (eq, ":destination", ":center"),
  44124.  
  44125.  
  44126. (troop_get_slot, ":event_time", "trp_log_array_entry_time", ":log_entry_no"),
  44127. (store_current_hours, ":cur_hour"),
  44128. (store_sub, ":hours_ago", ":cur_hour", ":event_time"),
  44129. (assign, reg3, ":hours_ago"),
  44130.  
  44131. (lt, ":hours_ago", 672), #four weeks
  44132.  
  44133. (try_begin),
  44134. (eq, "$cheat_mode", 1),
  44135. (troop_slot_eq, "trp_log_array_entry_type", ":log_entry_no", logent_traveller_attacked),
  44136. (display_message, "str_attack_on_travellers_found_reg3_hours_ago"),
  44137. (else_try),
  44138. (eq, "$cheat_mode", 1),
  44139. (troop_slot_eq, "trp_log_array_entry_type", ":log_entry_no", logent_party_traded),
  44140. (display_message, "str_trade_event_found_reg3_hours_ago"),
  44141. (try_end),
  44142.  
  44143. (try_begin), #possibly make script -- get_colloquial_for_time
  44144. (lt, ":hours_ago", 24),
  44145. (str_store_string, s46, "str_a_short_while_ago"),
  44146. (else_try),
  44147. (lt, ":hours_ago", 48),
  44148. (str_store_string, s46, "str_one_day_ago"),
  44149. (else_try),
  44150. (lt, ":hours_ago", 72),
  44151. (str_store_string, s46, "@two days ago"),
  44152. (else_try),
  44153. (lt, ":hours_ago", 154),
  44154. (str_store_string, s46, "str_earlier_this_week"),
  44155. (else_try),
  44156. (lt, ":hours_ago", 240),
  44157. (str_store_string, s46, "str_about_a_week_ago"),
  44158. (else_try),
  44159. (lt, ":hours_ago", 480),
  44160. (str_store_string, s46, "str_about_two_weeks_ago"),
  44161. (else_try),
  44162. (str_store_string, s46, "str_several_weeks_ago"),
  44163. (try_end),
  44164.  
  44165.  
  44166.  
  44167. (troop_get_slot, ":actor", "trp_log_array_actor", ":log_entry_no"),
  44168. (troop_get_slot, ":faction_object", "trp_log_array_faction_object", ":log_entry_no"),
  44169.  
  44170. (str_store_string, s39, "str_unknown_assailants"),
  44171. (assign, ":assailants_known", -1),
  44172. (try_begin),
  44173. (party_is_active, ":actor"),
  44174. (store_faction_of_party, ":actor_faction", ":actor"),
  44175. (eq, ":faction_object", ":actor_faction"),
  44176. (assign, ":assailants_known", ":actor"),
  44177. (str_store_party_name, s39, ":assailants_known"),
  44178. (assign, "$g_bandit_party_for_bounty", -1),
  44179. (try_begin), #possibly make script -- get_colloquial_for_faction
  44180. (eq, ":faction_object", "fac_kingdom_1"),
  44181. (str_store_string, s39, "str_swadians"),
  44182. (else_try),
  44183. (eq, ":faction_object", "fac_kingdom_2"),
  44184. (str_store_string, s39, "str_vaegirs"),
  44185. (else_try),
  44186. (eq, ":faction_object", "fac_kingdom_3"),
  44187. (str_store_string, s39, "str_khergits"),
  44188. (else_try),
  44189. (eq, ":faction_object", "fac_kingdom_4"),
  44190. (str_store_string, s39, "str_nords"),
  44191. (else_try),
  44192. (eq, ":faction_object", "fac_kingdom_5"),
  44193. (str_store_string, s39, "str_rhodoks"),
  44194. (else_try),
  44195. (eq, ":faction_object", "fac_kingdom_6"),
  44196. (str_store_string, s39, "str_sarranids"),
  44197. (else_try),
  44198. (eq, ":faction_object", "fac_player_supporters_faction"),
  44199. (str_store_string, s39, "str_your_followers"),
  44200. (else_try), #bandits
  44201. (assign, ":last_bandit_party_found", ":assailants_known"),
  44202. (assign, ":last_bandit_party_origin", ":origin"),
  44203. (assign, ":last_bandit_party_destination", ":destination"),
  44204. (assign, ":last_bandit_party_hours_ago", ":hours_ago"),
  44205. (try_end),
  44206. (try_end),
  44207.  
  44208. (try_begin),
  44209. (eq, ":origin", ":center"),
  44210. (troop_slot_eq, "trp_log_array_entry_type", ":log_entry_no", logent_traveller_attacked),
  44211. (party_slot_eq, ":destination", slot_party_temp_slot_1, 0),
  44212.  
  44213. (party_set_slot, ":destination", slot_party_temp_slot_1, 1),
  44214. (str_store_party_name, s40, ":destination"),
  44215. (str_store_string, s44, "str_we_have_heard_that_travellers_heading_to_s40_were_attacked_on_the_road_s46_by_s39"),
  44216. (str_store_string, s43, "str_s42"),
  44217. (str_store_string, s42, "str_s43_s44"),
  44218.  
  44219. (val_add, ":road_attacks", 1),
  44220. #travellers were attacked on the road to...
  44221. (else_try),
  44222. (eq, ":destination", ":center"),
  44223. (troop_slot_eq, "trp_log_array_entry_type", ":log_entry_no", logent_traveller_attacked),
  44224. (party_slot_eq, ":origin", slot_party_temp_slot_1, 0),
  44225.  
  44226. (party_set_slot, ":origin", slot_party_temp_slot_1, 1),
  44227. (str_store_party_name, s40, ":origin"),
  44228. (str_store_string, s44, "str_we_have_heard_that_travellers_coming_from_s40_were_attacked_on_the_road_s46_by_s39"),
  44229.  
  44230. (str_store_string, s43, "str_s42"),
  44231. (str_store_string, s42, "str_s43_s44"),
  44232.  
  44233. (val_add, ":road_attacks", 1),
  44234.  
  44235. #travellers from here traded at...
  44236. # (else_try),
  44237. # (eq, ":origin", ":center"),
  44238. # (troop_slot_eq, "trp_log_array_entry_type", ":log_entry_no", logent_party_traded),
  44239. # (party_slot_eq, ":destination", slot_party_temp_slot_1, 0),
  44240.  
  44241. # (party_set_slot, ":destination", slot_party_temp_slot_1, 1),
  44242. # (str_store_party_name, s40, ":destination"),
  44243. # (str_store_string, s44, "@Travellers headed to {s40} traded there {s46}"),
  44244. # (str_store_string, s43, "@{s42"),
  44245. # (str_store_string, s42, "str_s43_s44"),
  44246.  
  44247. #caravan from traded at...
  44248. (else_try),
  44249. (eq, ":destination", ":center"),
  44250. (troop_slot_eq, "trp_log_array_entry_type", ":log_entry_no", logent_party_traded),
  44251. (party_slot_eq, ":origin", slot_party_temp_slot_1, 0),
  44252.  
  44253. (party_set_slot, ":origin", slot_party_temp_slot_1, 1),
  44254. (str_store_party_name, s40, ":origin"),
  44255. (str_store_string, s44, "str_travellers_coming_from_s40_traded_here_s46"),
  44256. (str_store_string, s43, "str_s42"),
  44257. (str_store_string, s42, "str_s43_s44"),
  44258.  
  44259. (val_add, ":trades", 1),
  44260.  
  44261. #caravan from traded at...
  44262. (try_end),
  44263.  
  44264. (try_end),
  44265.  
  44266.  
  44267. (try_begin),
  44268. (le, ":trades", 2),
  44269. (eq, ":road_attacks", 0),
  44270. (store_current_hours, ":hours"),
  44271. (lt, ":hours", 168),
  44272. (str_store_string, s42, "str_it_is_still_early_in_the_caravan_season_so_we_have_seen_little_tradings42"),
  44273. (else_try),
  44274. (eq, ":trades", 0),
  44275. (eq, ":road_attacks", 0),
  44276. (str_store_string, s42, "str_there_has_been_very_little_trading_activity_here_recentlys42"),
  44277. (else_try),
  44278. (le, ":trades", 2),
  44279. (eq, ":road_attacks", 0),
  44280. (str_store_string, s42, "str_there_has_some_trading_activity_here_recently_but_not_enoughs42"),
  44281. (else_try),
  44282. (le, ":trades", 2),
  44283. (le, ":road_attacks", 2),
  44284. (str_store_string, s42, "str_there_has_some_trading_activity_here_recently_but_the_roads_are_dangerouss42"),
  44285. (else_try),
  44286. (ge, ":road_attacks", 3),
  44287. (str_store_string, s42, "str_the_roads_around_here_are_very_dangerouss42"),
  44288. (else_try),
  44289. (ge, ":road_attacks", 1),
  44290. (str_store_string, s42, "str_we_have_received_many_traders_in_town_here_although_there_is_some_danger_on_the_roadss42"),
  44291. (else_try),
  44292. (str_store_string, s42, "str_we_have_received_many_traders_in_town_heres42"),
  44293. (try_end),
  44294.  
  44295. #do safe roads
  44296. (assign, ":unused_trade_route_found", 0),
  44297. (try_for_range, ":trade_route_slot", slot_town_trade_routes_begin, slot_town_trade_routes_end),
  44298. (party_get_slot, ":trade_center", ":center", ":trade_route_slot"),
  44299. (is_between, ":trade_center", centers_begin, centers_end),
  44300.  
  44301. (party_slot_eq, ":trade_center", slot_party_temp_slot_1, 0),
  44302.  
  44303. # (party_get_slot, ":town_lord", ":trade_center", slot_town_lord),
  44304.  
  44305. (str_store_party_name, s41, ":trade_center"),
  44306. (try_begin),
  44307. (eq, ":unused_trade_route_found", 1),
  44308. (str_store_string, s44, "str_s44_s41"),
  44309. (else_try),
  44310. (str_store_string, s44, "str_s41"),
  44311. (try_end),
  44312. (assign, ":unused_trade_route_found", 1),
  44313. (try_end),
  44314. (try_begin),
  44315. (eq, ":unused_trade_route_found", 1),
  44316. (str_store_string, s47, "str_there_is_little_news_about_the_caravan_routes_to_the_towns_of_s44_and_nearby_parts_but_no_news_is_good_news_and_those_are_therefore_considered_safe"),
  44317. (try_end),
  44318.  
  44319. (assign, ":safe_village_road_found", 0),
  44320. (try_for_range, ":village", villages_begin, villages_end),
  44321. (party_slot_eq, ":village", slot_village_market_town, ":center"),
  44322. (party_slot_eq, ":village", slot_party_temp_slot_1, 0),
  44323.  
  44324. # (party_get_slot, ":town_lord", ":village", slot_town_lord),
  44325. (str_store_party_name, s41, ":village"),
  44326. (try_begin),
  44327. (eq, ":safe_village_road_found", 1),
  44328. (str_store_string, s44, "str_s44_s41"),
  44329. (else_try),
  44330. (str_store_string, s44, "str_s41"),
  44331. (try_end),
  44332. (assign, ":safe_village_road_found", 1),
  44333. (try_end),
  44334.  
  44335. (try_begin),
  44336. (eq, ":safe_village_road_found", 1),
  44337. (eq, ":unused_trade_route_found", 1),
  44338. (str_store_string, s47, "str_s47_also_the_roads_to_the_villages_of_s44_and_other_outlying_hamlets_are_considered_safe"),
  44339. (else_try),
  44340. (eq, ":safe_village_road_found", 1),
  44341. (str_store_string, s47, "str_however_the_roads_to_the_villages_of_s44_and_other_outlying_hamlets_are_considered_safe"),
  44342. (try_end),
  44343.  
  44344. (str_store_string, s33, "str_we_have_shortages_of"),
  44345. (assign, ":some_shortages_found", 0),
  44346. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  44347. (store_sub, ":cur_good_price_slot", ":cur_good", trade_goods_begin),
  44348. (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
  44349. (party_get_slot, ":price", ":center", ":cur_good_price_slot"),
  44350. (gt, ":price", 1100),
  44351.  
  44352. (str_store_item_name, s34, ":cur_good"),
  44353. (assign, reg1, ":price"),
  44354. (str_store_string, s33, "str_s33_s34_reg1"),
  44355.  
  44356. (assign, ":some_shortages_found", 1),
  44357. (try_end),
  44358.  
  44359. (try_begin),
  44360. (eq, ":some_shortages_found", 0),
  44361. (str_store_string, s32, "str_we_have_adequate_stores_of_all_commodities"),
  44362. (else_try),
  44363. (str_store_string, s32, "str_s33_and_some_other_commodities"),
  44364. (try_end),
  44365.  
  44366. (assign, reg0, ":last_bandit_party_found"),
  44367. (assign, reg1, ":last_bandit_party_origin"),
  44368. (assign, reg2, ":last_bandit_party_destination"),
  44369. (assign, reg3, ":last_bandit_party_hours_ago"),
  44370.  
  44371.  
  44372. ]
  44373. ),
  44374.  
  44375. ("get_manhunt_information_to_s15",
  44376. [
  44377. (store_script_param, ":quest", 1),
  44378.  
  44379. (str_store_string, s15, "str_the_roads_are_full_of_brigands_friend_but_that_name_in_particular_does_not_sound_familiar_good_hunting_to_you_nonetheless"),
  44380. (quest_get_slot, ":quarry", ":quest", slot_quest_target_party),
  44381. (try_begin),
  44382. (is_between, "$g_talk_troop", active_npcs_begin, active_npcs_end),
  44383. (troop_get_slot, ":talk_party", "$g_talk_troop", slot_troop_leaded_party),
  44384. (else_try),
  44385. (gt, "$g_encountered_party", "p_spawn_points_end"),
  44386. (assign, ":talk_party", "$g_encountered_party"),
  44387. (else_try),
  44388. (assign, ":talk_party", -1),
  44389. (try_end),
  44390.  
  44391. (try_for_range, ":log_entry", 0, "$num_log_entries"),
  44392. (gt, ":talk_party", -1),
  44393. (troop_get_slot, ":party", "trp_log_array_actor", ":log_entry"),
  44394. (eq, ":party", ":talk_party"),
  44395. (troop_get_slot, ":bandit_party", "trp_log_array_troop_object", ":log_entry"),
  44396. (eq, ":bandit_party", ":quarry"),
  44397. (store_current_hours, ":hours_ago"),
  44398. (troop_get_slot, ":sighting_time", "trp_log_array_entry_time", ":log_entry"),
  44399. (val_sub, ":hours_ago", ":sighting_time"),
  44400. (try_begin),
  44401. (le, ":hours_ago", 1),
  44402. (str_store_string, s16, "str_less_than_an_hour_ago"),
  44403. (else_try),
  44404. (le, ":hours_ago", 48),
  44405. (assign, reg3, ":hours_ago"),
  44406. (str_store_string, s16, "str_maybe_reg3_hours_ago"),
  44407. (else_try),
  44408. (val_div, ":hours_ago", 24),
  44409. (assign, reg3, ":hours_ago"),
  44410. (str_store_string, s16, "str_reg3_days_ago"),
  44411. (try_end),
  44412.  
  44413. (troop_get_slot, ":center", "trp_log_array_center_object", ":log_entry"),
  44414. (str_store_party_name, s17, ":center"),
  44415. (troop_get_slot, ":entry_type", "trp_log_array_entry_type", ":log_entry"),
  44416. (eq, ":entry_type", logent_party_spots_wanted_bandits),
  44417. (str_store_string, s15, "str_youre_in_luck_we_sighted_those_bastards_s16_near_s17_hurry_and_you_might_be_able_to_pick_up_their_trail_while_its_still_hot"),
  44418.  
  44419. # (try_begin),
  44420. # (eq, ":entry_type", logent_party_chases_wanted_bandits),
  44421. # (str_store_string, s15, "@You're in luck. We gave chase to those bastards {s16} near {s17}. They have eluded us so far -- but perhaps you will do better..."),
  44422. # (else_try),
  44423. # (eq, ":entry_type", logent_party_runs_from_wanted_bandits),
  44424. # (str_store_string, s15, "@As it happens, they tried to run us down near {s17} {s16}. By the heavens, I hope you teach them a lesson."),
  44425. # (try_end),
  44426. (try_end),
  44427. ]),
  44428.  
  44429.  
  44430. #Troop Commentaries end
  44431.  
  44432.  
  44433.  
  44434. ("rebellion_arguments", #Right now, called only in one place. This is only used when for player overtures, and will need some changes if this script is called when NPCs try to suborn lords
  44435. [
  44436. (store_script_param, ":lord", 1),
  44437. (store_script_param, ":argument", 2),
  44438. (store_script_param, ":candidate", 3),
  44439.  
  44440. (assign, ":argument_appeal", 0),
  44441. (assign, ":argument_strength", 0),
  44442.  
  44443. (troop_get_slot, ":reputation", ":lord", slot_lord_reputation_type),
  44444.  
  44445. (store_faction_of_troop, ":lord_faction", ":candidate"),
  44446. (store_faction_of_troop, ":candidate_faction", ":candidate"),
  44447.  
  44448. (try_begin),
  44449. (eq, ":candidate", "trp_player"),
  44450. (assign, ":right_to_rule", "$player_right_to_rule"),
  44451. (else_try), #default right to rule of 75 for pretenders claiming throne
  44452. (is_between, ":candidate", pretenders_begin, pretenders_end),
  44453. (troop_slot_eq, ":candidate", slot_troop_original_faction, ":lord_faction"),
  44454. (assign, ":right_to_rule", 75),
  44455. (else_try), #default right to rule of 60 for all other lords
  44456. (assign, ":right_to_rule", 60),
  44457. (try_end),
  44458.  
  44459. (try_begin),
  44460. (eq, ":argument", argument_claim),
  44461. (store_sub, ":argument_strength", ":right_to_rule", 30),
  44462. (else_try),
  44463. (eq, ":argument", argument_ruler),
  44464. (store_sub, ":argument_strength", "$player_honor", 20),
  44465. (else_try),
  44466. (eq, ":argument", argument_lords),
  44467. (store_sub, ":argument_strength", "$player_honor", 20),
  44468. (else_try),
  44469. #argument_strength is ((5 * number of centers player have) - 40) if argument type is argument_victory
  44470. (eq, ":argument", argument_victory),
  44471. (assign, ":argument_strength", 0),
  44472. (try_for_range, ":center", centers_begin, centers_end),
  44473. (store_faction_of_party, ":center_faction", ":center"),
  44474. (assign, ":argument_strength", -40),
  44475. (try_begin),
  44476. (eq, "$players_kingdom", ":candidate_faction"),
  44477. ##diplomacy start+
  44478. (this_or_next|eq, ":center_faction", "$players_kingdom"),
  44479. ##diplomacy end+
  44480. (this_or_next|eq, ":center_faction", "fac_player_faction"),
  44481. (eq, ":center_faction", "fac_player_supporters_faction"),
  44482. (val_add, ":argument_strength", 5),
  44483. (else_try),
  44484. (eq, ":center_faction", ":candidate_faction"),
  44485. (val_add, ":argument_strength", 5),
  44486. (try_end),
  44487. (try_end),
  44488. (else_try),
  44489. #argument_strength is (20 - 20 * (number of lords in player's faction which not awareded fief by player although there is a fief awarding in future promise))
  44490. (eq, ":argument", argument_benefit),
  44491. (assign, ":argument_strength", 20),
  44492. (try_for_range, ":lord_promised_fief", active_npcs_begin, active_npcs_end),
  44493. (store_faction_of_troop, ":other_faction", ":lord_promised_fief"),
  44494. (neq, ":lord", "$g_talk_troop"),
  44495. (this_or_next|eq, ":other_faction", "fac_player_supporters_faction"),
  44496. (eq, ":other_faction", "$players_kingdom"),
  44497. (troop_slot_eq, ":lord_promised_fief", slot_troop_promised_fief, 1),
  44498. (val_sub, ":argument_strength", 20),
  44499. (try_end),
  44500. (try_end),
  44501. (val_clamp, ":argument_strength", -40, 41),
  44502.  
  44503. (try_begin),
  44504. (eq, ":reputation", lrep_martial),
  44505. (try_begin),
  44506. (eq, ":argument", argument_claim),
  44507. (assign, ":argument_appeal", 30),
  44508. (try_begin),
  44509. (gt, ":argument_strength", 0),
  44510. (str_store_string, s15, "str_you_speak_of_claims_to_the_throne_good_there_is_nothing_id_rather_do_than_fight_for_a_good_cause"),
  44511. (else_try),
  44512. (str_store_string, s15, "str_you_speak_of_claims_to_the_throne_well_there_is_nothing_id_rather_do_than_fight_for_a_good_cause_but_the_claim_you_make_seems_somewhat_weak"),
  44513. (try_end),
  44514. (else_try),
  44515. (eq, ":argument", argument_lords),
  44516. (assign, ":argument_appeal", 10),
  44517. (try_begin),
  44518. (gt, ":argument_strength", 0),
  44519. (str_store_string, s15, "str_i_am_pleased_that_you_speak_of_upholding_my_ancient_rights_which_are_sometimes_trod_upon_in_these_sorry_days"),
  44520. (else_try),
  44521. ##diplomacy start+ use culturally-approrpriate term
  44522. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 14),
  44523. ##diplomacy end+
  44524. (str_store_string, s15, "str_i_am_pleased_that_you_speak_of_upholding_my_ancient_rights_but_sometimes_men_make_pledges_before_they_are_king_which_they_cannot_keep_once_they_take_the_throne"),
  44525. (try_end),
  44526. (else_try),
  44527. (eq, ":argument", argument_ruler),
  44528. (assign, ":argument_appeal", 0),
  44529. (try_begin),
  44530. ##diplomacy start+: use culturally-approrpriate term
  44531. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_USE_MY_WEAPON, s14),
  44532. ##diplomacy end+
  44533. (str_store_string, s15, "str_you_speak_of_protecting_the_commons_well_i_supposed_thats_good_but_sometimes_the_commons_overstep_their_boundaries_im_more_concerned_that_your_claim_be_legal_so_i_can_swing_my_sword_with_a_good_conscience"),
  44534. (try_end),
  44535. (else_try),
  44536. (eq, ":argument", argument_benefit),
  44537. (assign, ":argument_appeal", -10),
  44538. (try_begin),
  44539. (gt, ":argument_strength", 0),
  44540. (str_store_string, s15, "str_you_speak_of_giving_me_land_good_i_ask_for_no_more_than_my_due"),
  44541. (else_try),
  44542. (str_store_string, s15, "str_you_speak_of_giving_me_land_unfortunately_you_are_not_wellknown_for_rewarding_those_to_whom_you_have_made_such_offers"),
  44543. (try_end),
  44544. (else_try),
  44545. (eq, ":argument", argument_victory),
  44546. (assign, ":argument_appeal", -30),
  44547. (str_store_string, s15, "str_you_speak_of_unifying_calradia_well_i_believe_that_well_always_be_fighting__its_important_that_we_fight_for_a_rightful_cause"),
  44548. (try_end),
  44549. (else_try),
  44550. (eq, ":reputation", lrep_quarrelsome),
  44551. (try_begin),
  44552. (eq, ":argument", argument_claim),
  44553. (assign, ":argument_appeal", -20),
  44554. (str_store_string, s15, "str_you_talk_of_claims_to_the_throne_but_i_leave_bickering_about_legalities_to_the_lawyers_and_clerks"),
  44555. (else_try),
  44556. (eq, ":argument", argument_ruler),
  44557. (assign, ":argument_appeal", -30),
  44558. ##diplomacy start+ use culturally-approrpriate term
  44559. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 14),
  44560. ##diplomacy end+
  44561. (str_store_string, s15, "str_you_speak_of_ruling_justly_hah_ill_believe_theres_such_a_thing_as_a_just_king_when_i_see_one"),
  44562. (else_try),
  44563. (eq, ":argument", argument_lords),
  44564. (assign, ":argument_appeal", 0),
  44565. ##diplomacy start+ use culturally-approrpriate term
  44566. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 14),
  44567. ##diplomacy end+
  44568. (str_store_string, s15, "str_you_spoke_of_protecting_the_rights_of_the_nobles_if_you_did_youd_be_the_first_king_to_do_so_in_a_very_long_time"),
  44569. (else_try),
  44570. (eq, ":argument", argument_benefit),
  44571. (assign, ":argument_appeal", 30),
  44572. (try_begin),
  44573. (gt, ":argument_strength", 0),
  44574. (str_store_string, s15, "str_you_speak_of_giving_me_land_ay_well_lets_see_if_you_deliver"),
  44575. (else_try),
  44576. (str_store_string, s15, "str_you_speak_of_giving_me_land_bah_youre_not_known_for_delivering_on_your_pledges"),
  44577. (try_end),
  44578. (else_try),
  44579. (eq, ":argument", argument_victory),
  44580. (assign, ":argument_appeal", 10),
  44581. (try_begin),
  44582. (gt, ":argument_strength", 0),
  44583. (str_store_string, s15, "str_you_speak_of_unifying_calradia_well_youve_done_a_good_job_at_making_calradia_bend_its_knee_to_you_so_maybe_thats_not_just_talk"),
  44584. (else_try),
  44585. (str_store_string, s15, "str_you_speak_of_unifying_calradia_id_be_impressed_if_i_thought_you_could_do_it_but_unfortunately_you_dont"),
  44586. (try_end),
  44587. (try_end),
  44588. (else_try),
  44589. (eq, ":reputation", lrep_selfrighteous),
  44590. (try_begin),
  44591. (eq, ":argument", argument_claim),
  44592. (assign, ":argument_appeal", -20),
  44593. (str_store_string, s15, "str_you_speak_of_claims_to_the_throne_well_any_peasant_can_claim_to_be_a_kings_bastard"),
  44594. (else_try),
  44595. (eq, ":argument", argument_ruler),
  44596. (assign, ":argument_appeal", -30),
  44597. (str_store_string, s15, "str_well_its_a_fine_thing_to_court_the_commons_with_promises_but_what_do_you_have_to_offer_me"),
  44598. (else_try),
  44599. (eq, ":argument", argument_lords),
  44600. (assign, ":argument_appeal", 0),
  44601. ##diplomacy start+ use culturally-approrpriate term
  44602. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_LORD_PLURAL, 15),
  44603. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_LORD, 14),
  44604. ##diplomacy end+
  44605. (try_begin),
  44606. (gt, ":argument_strength", 0),
  44607. (str_store_string, s15, "str_you_speak_of_protecting_the_rights_of_lords_that_would_make_a_fine_change_if_my_rights_as_lord_would_be_respected"),
  44608. (else_try),
  44609. (str_store_string, s15, "str_you_speak_of_protecting_the_rights_of_lords_that_would_make_a_fine_change_if_my_rights_as_lord_would_be_respected_however_it_is_easy_for_you_to_make_promises_while_you_are_weak_that_you_have_no_intention_of_keeping_when_you_are_strong"),
  44610. (try_end),
  44611. (else_try),
  44612. (eq, ":argument", argument_benefit),
  44613. (assign, ":argument_appeal", 20),
  44614. (try_begin),
  44615. (gt, ":argument_strength", 0),
  44616. (str_store_string, s15, "str_you_speak_of_giving_me_land_well_my_family_is_of_ancient_and_noble_lineage_so_you_promise_me_no_more_than_my_due_still_your_gesture_is_appreciated"),
  44617. (else_try),
  44618. (str_store_string, s15, "str_you_speak_of_giving_me_land_well_you_make_that_pledge_but_i_am_not_impressed"),
  44619. (try_end),
  44620. (else_try),
  44621. (eq, ":argument", argument_victory),
  44622. (assign, ":argument_appeal", 20),
  44623. (try_begin),
  44624. (gt, ":argument_strength", 0),
  44625. (str_store_string, s15, "str_you_speak_of_unifying_calradia_well_much_of_this_land_now_bends_its_knee_to_you_so_perhaps_that_is_not_just_talk"),
  44626. (else_try),
  44627. (str_store_string, s15, "str_you_speak_of_unifying_calradia_but_right_now_yours_is_just_one_squabbling_faction_among_many"),
  44628. (try_end),
  44629. (try_end),
  44630. (else_try),
  44631. (eq, ":reputation", lrep_cunning),
  44632. (try_begin),
  44633. (eq, ":argument", argument_claim),
  44634. (assign, ":argument_appeal", -30),
  44635. (str_store_string, s15, "str_you_speak_of_claims_well_no_offense_but_a_claim_unsupported_by_might_rarely_prospers"),
  44636. (else_try),
  44637. (eq, ":argument", argument_ruler),
  44638. (assign, ":argument_appeal", 10),
  44639. (try_begin),
  44640. (gt, ":argument_strength", 0),
  44641. (str_store_string, s15, "str_you_speak_of_protecting_the_commons_well_i_suppose_that_will_make_for_a_more_prosperous_realm_ive_always_tried_to_treat_my_peasants_decently_saves_going_to_bed_worrying_about_whether_youll_wake_up_with_the_roof_on_fire"),
  44642. (else_try),
  44643. (str_store_string, s15, "str_you_speak_of_protecting_the_commons_very_well_but_remember_that_peasants_are_more_likely_to_cause_trouble_if_you_make_promises_then_dont_deliver_than_if_you_never_made_the_promise_in_the_first_place"),
  44644. (try_end),
  44645. (else_try),
  44646. (eq, ":argument", argument_lords),
  44647. (assign, ":argument_appeal", 15),
  44648. ##diplomacy start+ use culturally-approrpriate term
  44649. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 15),
  44650. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_LORD_PLURAL, 14),
  44651. ##diplomacy end+
  44652. (try_begin),
  44653. (gt, ":argument_strength", 0),
  44654. (str_store_string, s15, "str_you_speak_of_protecting_the_rights_of_lords_good_youd_be_well_advised_to_do_that__men_fight_better_for_a_king_wholl_respect_their_rights"),
  44655. (else_try),
  44656. (str_store_string, s15, "str_you_speak_of_protecting_the_rights_of_lords_very_well_but_remember__failing_to_keep_promises_which_you_made_while_scrambling_up_the_throne_is_the_quickest_way_to_topple_off_of_it_once_you_get_there"),
  44657. (try_end),
  44658. (else_try),
  44659. (eq, ":argument", argument_benefit),
  44660. (assign, ":argument_appeal", -20),
  44661. (str_store_string, s15, "str_you_speak_of_giving_me_land_very_good_but_often_i_find_that_when_a_man_makes_too_many_promises_trying_to_get_to_the_top_he_has_trouble_keeping_them_once_he_reaches_it"),
  44662. (else_try),
  44663. (eq, ":argument", argument_victory),
  44664. (assign, ":argument_appeal", 20),
  44665. (try_begin),
  44666. (gt, ":argument_strength", 0),
  44667. (str_store_string, s15, "str_you_speak_of_unifying_calradia_well_many_have_said_that_you_might_very_well_be_the_one_to_do_it"),
  44668. (else_try),
  44669. (str_store_string, s15, "str_you_speak_of_unifying_calradia_well_all_the_kings_say_that_im_not_sure_that_you_will_succeed_while_they_fail"),
  44670. (try_end),
  44671. (try_end),
  44672. (else_try),
  44673. (eq, ":reputation", lrep_debauched),
  44674. (try_begin),
  44675. (eq, ":argument", argument_claim),
  44676. (assign, ":argument_appeal", -20),
  44677. (str_store_string, s15, "str_you_speak_of_claims_do_you_think_i_care_for_the_nattering_of_lawyers"),
  44678. (else_try),
  44679. (eq, ":argument", argument_ruler),
  44680. (assign, ":argument_appeal", -20),
  44681. ##diplomacy start+ replace "swineherd" with culturally-appropriate term
  44682. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_SWINEHERD, 14),
  44683. ##diplomacy end+
  44684. (str_store_string, s15, "str_you_speak_of_protecting_the_commons_how_kind_of_you_i_shall_tell_my_swineherd_all_about_your_sweet_promises_no_doubt_he_will_become_your_most_faithful_vassal"),
  44685. (else_try),
  44686. (eq, ":argument", argument_lords),
  44687. (assign, ":argument_appeal", -10),
  44688. ##diplomacy start+ replace "lords" with culturally-appropriate term
  44689. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_LORD_PLURAL, 14),
  44690. ##diplomacy end+
  44691. (str_store_string, s15, "str_you_speak_of_protecing_the_rights_of_lords_such_sweet_words_but_ill_tell_you_this__the_only_rights_that_are_respected_in_this_world_are_the_rights_to_dominate_whoever_is_weaker_and_to_submit_to_whoever_is_stronger"),
  44692. (else_try),
  44693. (eq, ":argument", argument_benefit),
  44694. (assign, ":argument_appeal", 20),
  44695. (try_begin),
  44696. (gt, ":argument_strength", 0),
  44697. (str_store_string, s15, "str_you_speak_of_giving_me_land_yes_very_good__but_you_had_best_deliver"),
  44698. (else_try),
  44699. (str_store_string, s15, "str_you_speak_of_giving_me_land_hah_perhaps_all_those_others_to_whom_you_promised_lands_will_simply_step_aside"),
  44700. (try_end),
  44701. (else_try),
  44702. (eq, ":argument", argument_victory),
  44703. (assign, ":argument_appeal", 10),
  44704. (try_begin),
  44705. (gt, ":argument_strength", 0),
  44706. (str_store_string, s15, "str_you_speak_of_unifying_calradia_you_may_indeed_humble_the_other_kings_of_this_land_and_in_that_case_i_would_hope_that_you_would_remember_me_as_your_faithful_servant"),
  44707. (else_try),
  44708. (str_store_string, s15, "str_you_speak_of_unifying_calradia_but_you_are_weak_and_i_think_that_you_will_remain_weak"),
  44709. (try_end),
  44710. (try_end),
  44711. (else_try),
  44712. (eq, ":reputation", lrep_goodnatured),
  44713. (try_begin),
  44714. (eq, ":argument", argument_claim),
  44715. (assign, ":argument_appeal", 10),
  44716. ##diplomacy start+ replace "king" with culturally-appropriate term
  44717. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 14),
  44718. ##diplomacy end+
  44719. (try_begin),
  44720. (gt, ":argument_strength", 0),
  44721. (str_store_string, s15, "str_you_speak_of_claims_its_good_for_a_king_to_have_a_strong_claim_although_admittedly_im_more_concerned_that_he_rules_just_ly_than_with_legalities_anyway_your_claim_seems_wellfounded_to_me"),
  44722. (else_try),
  44723. (str_store_string, s15, "str_you_speak_of_claims_but_your_claim_seems_a_bit_weak_to_me"),
  44724. (try_end),
  44725. (else_try),
  44726. (eq, ":argument", argument_ruler),
  44727. (assign, ":argument_appeal", 20),
  44728. (try_begin),
  44729. (gt, ":argument_strength", 0),
  44730. (str_store_string, s15, "str_you_speak_of_protecting_the_commons_i_like_that_my_tenants_are_a_happy_lot_i_think_but_i_hear_of_others_in_other_estates_that_arent_so_fortunate"),
  44731. (else_try),
  44732. (str_store_string, s15, "str_you_speak_of_protecting_the_commons_im_glad_to_hear_you_say_that_but_do_me_a_favor__dont_promise_the_commons_anything_you_cant_deliver_thats_a_sure_way_to_get_them_to_rebel_and_it_breaks_my_heart_to_have_to_put_them_down"),
  44733. (try_end),
  44734. (else_try),
  44735. (eq, ":argument", argument_lords),
  44736. (assign, ":argument_appeal", 0),
  44737. ##diplomacy start+ use culturally-approrpriate term
  44738. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 15),
  44739. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_LORD_PLURAL, 14),
  44740. ##diplomacy end+
  44741. (str_store_string, s15, "str_you_speak_of_protecting_the_rights_of_lords_well_very_good_i_suppose_but_you_know__we_lords_can_take_of_ourselves_its_the_common_folk_who_need_a_strong_king_to_look_out_for_them_to_my_mind"),
  44742. (else_try),
  44743. (eq, ":argument", argument_benefit),
  44744. (assign, ":argument_appeal", -15),
  44745. (str_store_string, s15, "str_you_speak_of_giving_me_land_its_kind_of_you_really_though_that_is_not_necessary"),
  44746. (else_try),
  44747. (eq, ":argument", argument_victory),
  44748. (assign, ":argument_appeal", -25),
  44749. ##diplomacy start+
  44750. #Save culturally-appropriate variant of "sword" (as in "by the sword") to s14
  44751. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_WEAPON, 14),
  44752. ##diplomacy end+
  44753. (str_store_string, s15, "str_you_speak_of_unifying_calradia_well_maybe_you_can_unite_this_land_by_the_sword_but_im_not_sure_that_this_will_make_you_a_good_ruler"),
  44754. (try_end),
  44755. (else_try),
  44756. (eq, ":reputation", lrep_upstanding),
  44757. (try_begin),
  44758. (eq, ":argument", argument_claim),
  44759. (assign, ":argument_appeal", 10),
  44760. ##diplomacy start+ use culturally-approrpriate term
  44761. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 14),
  44762. ##diplomacy end+
  44763. (try_begin),
  44764. (gt, ":argument_strength", 0),
  44765. (str_store_string, s15, "str_you_speak_of_claims_a_king_must_have_a_strong_legal_claim_for_there_not_to_be_chaos_in_the_realm_and_yours_is_wellestablished"),
  44766. (else_try),
  44767. (str_store_string, s15, "str_you_speak_of_claims_a_king_must_have_a_strong_legal_claim_for_there_not_to_be_chaos_in_the_realm_but_your_claim_is_not_so_strong"),
  44768. (try_end),
  44769. (else_try),
  44770. (eq, ":argument", argument_lords),
  44771. (assign, ":argument_appeal", -5),
  44772. ##diplomacy start+ use culturally-approrpriate term
  44773. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 14),
  44774. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_LORD_PLURAL, 15),
  44775. ##diplomacy end+
  44776. (try_begin),
  44777. (gt, ":argument_strength", 0),
  44778. (str_store_string, s15, "str_you_speak_of_protecting_the_rights_of_lords_it_is_of_course_important_that_a_king_respect_the_rights_of_his_vassals_although_i_worry_that_a_king_who_took_a_throne_without_proper_cause_would_not_rule_with_justice"),
  44779. (else_try),
  44780. (str_store_string, s15, "str_you_speak_of_protecting_the_rights_of_lords_it_is_of_course_important_that_a_king_respect_the_rights_of_his_vassals_however_i_would_like_to_know_that_you_would_indeed_deliver_on_your_promises"),
  44781. (try_end),
  44782. (else_try),
  44783. (eq, ":argument", argument_ruler),
  44784. (assign, ":argument_appeal", 5),
  44785. ##diplomacy start+ use culturally-approrpriate term
  44786. (call_script, "script_dplmc_print_cultural_word_to_sreg", ":lord", DPLMC_CULTURAL_TERM_KING, 14),
  44787. ##diplomacy end+
  44788. (try_begin),
  44789. (gt, ":argument_strength", 0),
  44790. (str_store_string, s15, "str_you_speak_of_protecting_the_commons_i_would_be_pleased_to_serve_a_king_who_respected_the_rights_of_his_subjects_although_i_worry_that_a_king_who_took_a_throne_without_proper_cause_would_not_rule_with_justice"),
  44791. (else_try),
  44792. (str_store_string, s15, "str_you_speak_of_protecting_the_commons_i_would_be_pleased_to_serve_a_king_who_respected_the_rights_of_his_subjects_however_i_would_like_to_know_that_you_would_indeed_deliver_on_your_promises"),
  44793. (try_end),
  44794. (else_try),
  44795. (eq, ":argument", argument_benefit),
  44796. (assign, ":argument_appeal", -40),
  44797. (str_store_string, s15, "str_i_am_not_swayed_by_promises_of_reward"),
  44798. (else_try),
  44799. (eq, ":argument", argument_victory),
  44800. (assign, ":argument_appeal", 10),
  44801. (try_begin),
  44802. (gt, ":argument_strength", 0),
  44803. (str_store_string, s15, "str_you_speak_of_unifying_calradia_it_would_be_good_to_bring_peace_to_the_realm_and_i_believe_that_you_are_strong_enough_to_do_so"),
  44804. (else_try),
  44805. (str_store_string, s15, "str_you_speak_of_unifying_calradia_it_would_be_good_to_bring_peace_the_realm_but_with_your_kingdom_in_its_current_state_i_worry_that_you_are_just_bringing_more_discord"),
  44806. (try_end),
  44807. (try_end),
  44808. (try_end),
  44809.  
  44810. (str_store_string, s14, "str_s15"),
  44811.  
  44812. (assign, reg0, ":argument_appeal"),
  44813. (assign, reg1, ":argument_strength"),
  44814. ]),
  44815.  
  44816.  
  44817.  
  44818. #Rebellion changes end
  44819.  
  44820. # script_get_culture_with_party_faction_for_music
  44821. # Input: arg1 = party_no
  44822. # Output: reg0 = culture
  44823. ("get_culture_with_party_faction_for_music",
  44824. [
  44825. (store_script_param, ":party_no", 1),
  44826. (store_faction_of_party, ":faction_no", ":party_no"),
  44827. (try_begin),
  44828. (this_or_next|eq, ":faction_no", "fac_player_faction"),
  44829. (eq, ":faction_no", "fac_player_supporters_faction"),
  44830. (assign, ":faction_no", "$players_kingdom"),
  44831. (try_end),
  44832. (try_begin),
  44833. (is_between, ":party_no", centers_begin, centers_end),
  44834. (this_or_next|eq, ":faction_no", "fac_player_supporters_faction"),
  44835. (neg|is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  44836. (party_get_slot, ":faction_no", ":party_no", slot_center_original_faction),
  44837. (try_end),
  44838. (call_script, "script_get_culture_with_faction_for_music", ":faction_no"),
  44839. ]),
  44840.  
  44841. # script_get_culture_with_faction_for_music
  44842. # Input: arg1 = party_no
  44843. # Output: reg0 = culture
  44844. ("get_culture_with_faction_for_music",
  44845. [
  44846. (store_script_param, ":faction_no", 1),
  44847. (try_begin),
  44848. (eq, ":faction_no", "fac_kingdom_1"),
  44849. (assign, ":result", mtf_culture_1),
  44850. (else_try),
  44851. (eq, ":faction_no", "fac_kingdom_2"),
  44852. (assign, ":result", mtf_culture_2),
  44853. (else_try),
  44854. (eq, ":faction_no", "fac_kingdom_3"),
  44855. (assign, ":result", mtf_culture_3),
  44856. (else_try),
  44857. (eq, ":faction_no", "fac_kingdom_4"),
  44858. (assign, ":result", mtf_culture_4),
  44859. (else_try),
  44860. (eq, ":faction_no", "fac_kingdom_5"),
  44861. (assign, ":result", mtf_culture_5),
  44862. (else_try),
  44863. (eq, ":faction_no", "fac_kingdom_6"),
  44864. (assign, ":result", mtf_culture_6),
  44865. (else_try),
  44866. (this_or_next|eq, ":faction_no", "fac_outlaws"),
  44867. (this_or_next|eq, ":faction_no", "fac_peasant_rebels"),
  44868. (this_or_next|eq, ":faction_no", "fac_deserters"),
  44869. (this_or_next|eq, ":faction_no", "fac_mountain_bandits"),
  44870. (eq, ":faction_no", "fac_forest_bandits"),
  44871. (assign, ":result", mtf_culture_6),
  44872. (else_try),
  44873. (assign, ":result", 0), #no culture, including player with no bindings to another kingdom
  44874. (try_end),
  44875. (assign, reg0, ":result"),
  44876. ]),
  44877.  
  44878. # script_music_set_situation_with_culture
  44879. # Input: arg1 = music_situation
  44880. # Output: none
  44881. ("music_set_situation_with_culture",
  44882. [
  44883. (store_script_param, ":situation", 1),
  44884. (assign, ":culture", 0), #no culture
  44885. (try_begin),
  44886. (this_or_next|eq, ":situation", mtf_sit_town),
  44887. (this_or_next|eq, ":situation", mtf_sit_day),
  44888. (this_or_next|eq, ":situation", mtf_sit_night),
  44889. (this_or_next|eq, ":situation", mtf_sit_town_infiltrate),
  44890. (eq, ":situation", mtf_sit_encounter_hostile),
  44891. (call_script, "script_get_culture_with_party_faction_for_music", "$g_encountered_party"),
  44892. (val_or, ":culture", reg0),
  44893. (else_try),
  44894. (this_or_next|eq, ":situation", mtf_sit_ambushed),
  44895. (eq, ":situation", mtf_sit_fight),
  44896. (call_script, "script_get_culture_with_party_faction_for_music", "$g_encountered_party"),
  44897. (val_or, ":culture", reg0),
  44898. (call_script, "script_get_culture_with_party_faction_for_music", "p_main_party"),
  44899. (val_or, ":culture", reg0),
  44900. (call_script, "script_get_closest_center", "p_main_party"),
  44901. (call_script, "script_get_culture_with_party_faction_for_music", reg0),
  44902. (val_or, ":culture", reg0),
  44903. (else_try),
  44904. (eq, ":situation", mtf_sit_multiplayer_fight),
  44905. (call_script, "script_get_culture_with_faction_for_music", "$g_multiplayer_team_1_faction"),
  44906. (val_or, ":culture", reg0),
  44907. (call_script, "script_get_culture_with_faction_for_music", "$g_multiplayer_team_2_faction"),
  44908. (val_or, ":culture", reg0),
  44909. (else_try),
  44910. (eq, ":situation", mtf_sit_travel),
  44911. (call_script, "script_get_culture_with_party_faction_for_music", "p_main_party"),
  44912. (val_or, ":culture", reg0),
  44913. (call_script, "script_get_closest_center", "p_main_party"),
  44914. (call_script, "script_get_culture_with_party_faction_for_music", reg0),
  44915. (val_or, ":culture", reg0),
  44916. (else_try),
  44917. (eq, ":situation", mtf_sit_victorious),
  44918. (call_script, "script_get_culture_with_party_faction_for_music", "p_main_party"),
  44919. (val_or, ":culture", reg0),
  44920. (else_try),
  44921. (eq, ":situation", mtf_sit_killed),
  44922. (call_script, "script_get_culture_with_party_faction_for_music", "$g_encountered_party"),
  44923. (val_or, ":culture", reg0),
  44924. (try_end),
  44925. (try_begin),
  44926. (this_or_next|eq, ":situation", mtf_sit_town),
  44927. (eq, ":situation", mtf_sit_day),
  44928. (try_begin),
  44929. (is_currently_night),
  44930. (assign, ":situation", mtf_sit_night),
  44931. (try_end),
  44932. (try_end),
  44933. (music_set_situation, ":situation"),
  44934. (music_set_culture, ":culture"),
  44935. ]),
  44936.  
  44937.  
  44938. # script_combat_music_set_situation_with_culture
  44939. # Input: none
  44940. # Output: none
  44941. ("combat_music_set_situation_with_culture",
  44942. [
  44943. (assign, ":situation", mtf_sit_fight),
  44944. (assign, ":num_allies", 0),
  44945. (assign, ":num_enemies", 0),
  44946. (try_for_agents, ":agent_no"),
  44947. (agent_is_alive, ":agent_no"),
  44948. (agent_is_human, ":agent_no"),
  44949. (agent_get_troop_id, ":agent_troop_id", ":agent_no"),
  44950. (store_character_level, ":troop_level", ":agent_troop_id"),
  44951. (val_add, ":troop_level", 10),
  44952. (val_mul, ":troop_level", ":troop_level"),
  44953. (try_begin),
  44954. (agent_is_ally, ":agent_no"),
  44955. (val_add, ":num_allies", ":troop_level"),
  44956. (else_try),
  44957. (val_add, ":num_enemies", ":troop_level"),
  44958. (try_end),
  44959. (try_end),
  44960. (val_mul, ":num_allies", 4), #play ambushed music if we are 2 times outnumbered.
  44961. (val_div, ":num_allies", 3),
  44962. (try_begin),
  44963. (lt, ":num_allies", ":num_enemies"),
  44964. (assign, ":situation", mtf_sit_ambushed),
  44965. (try_end),
  44966. (call_script, "script_music_set_situation_with_culture", ":situation"),
  44967. ]),
  44968.  
  44969. # script_play_victorious_sound
  44970. # Input: none
  44971. # Output: none
  44972. ("play_victorious_sound",
  44973. [
  44974. (call_script, "script_music_set_situation_with_culture", mtf_sit_victorious),
  44975. # (play_cue_track, "track_victorious_neutral_1"),
  44976. # (play_track, "track_victorious_neutral_1", 1),
  44977. ]),
  44978.  
  44979. # script_set_items_for_tournament
  44980. # Input: arg1 = horse_chance, arg2 = lance_chance (with horse only), arg3 = sword_chance, arg4 = axe_chance, arg5 = bow_chance (without horse only), arg6 = javelin_chance (with horse only), arg7 = mounted_bow_chance (with horse only), arg8 = crossbow_sword_chance, arg9 = armor_item_begin, arg10 = helm_item_begin
  44981. # Output: none (sets mt_arena_melee_fight items)
  44982. ("set_items_for_tournament",
  44983. [
  44984. (store_script_param, ":horse_chance", 1),
  44985. (store_script_param, ":lance_chance", 2),
  44986. (store_script_param, ":sword_chance", 3),
  44987. (store_script_param, ":axe_chance", 4),
  44988. (store_script_param, ":bow_chance", 5),
  44989. (store_script_param, ":javelin_chance", 6),
  44990. (store_script_param, ":mounted_bow_chance", 7),
  44991. (store_script_param, ":crossbow_sword_chance", 8),
  44992. (store_script_param, ":armor_item_begin", 9),
  44993. (store_script_param, ":helm_item_begin", 10),
  44994. (store_add, ":total_chance", ":sword_chance", ":axe_chance"),
  44995. (val_add, ":total_chance", ":crossbow_sword_chance"),
  44996.  
  44997.  
  44998. #SB : move shield/team calculations up top, start off by one since we'll increment immediately
  44999. (assign, ":cur_team", -1),
  45000. (store_sub, ":cur_shield_item", "itm_arena_shield_red", 1),
  45001. (try_begin),
  45002. (ge, ":armor_item_begin", 0),
  45003. (store_sub, ":cur_armor_item", ":armor_item_begin", 1),
  45004. (else_try), #doesn't matter, we're checking parameter not this value
  45005. (assign, ":cur_armor_item", -999),
  45006. (try_end),
  45007. (try_begin),
  45008. (ge, ":helm_item_begin", 0),
  45009. (store_sub, ":cur_helm_item", ":helm_item_begin", 1),
  45010. (else_try),
  45011. (assign, ":cur_helm_item", -999),
  45012. (try_end),
  45013.  
  45014. (try_for_range, ":i_ep", 0, 32),
  45015. (mission_tpl_entry_clear_override_items, "mt_arena_melee_fight", ":i_ep"),
  45016. (assign, ":has_horse", 0),
  45017. # (store_div, ":cur_team", ":i_ep", 8),
  45018. (try_begin), #SB : incrementing at same rate
  45019. (store_mod, ":entry", ":i_ep", 8),
  45020. (eq, ":entry", 0),
  45021. (val_add, ":cur_team", 1),
  45022. (val_add, ":cur_shield_item", 1),
  45023. (val_add, ":cur_armor_item", 1),
  45024. (val_add, ":cur_helm_item", 1),
  45025. (try_end),
  45026. (try_begin),
  45027. (store_random_in_range, ":random_no", 0, 100),
  45028. (lt, ":random_no", ":horse_chance"),
  45029. (assign, ":has_horse", 1),
  45030. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_horse"),
  45031. (try_end),
  45032. (try_begin),
  45033. (eq, ":has_horse", 1),
  45034. (store_add, ":cur_total_chance", ":total_chance", ":lance_chance"),
  45035. (val_add, ":cur_total_chance", ":javelin_chance"),
  45036. (val_add, ":cur_total_chance", ":mounted_bow_chance"),
  45037. (else_try),
  45038. (store_add, ":cur_total_chance", ":total_chance", ":bow_chance"),
  45039. (try_end),
  45040. (store_random_in_range, ":random_no", 0, ":cur_total_chance"),
  45041. # (store_add, ":cur_shield_item", "itm_arena_shield_red", ":cur_team"),
  45042.  
  45043. #SB : deal with player entry here
  45044. (try_begin),
  45045. (eq, "$g_player_entry_point", ":i_ep"),
  45046. (assign, ":continue", -1),
  45047. (assign, ":proficiency", -1), #this checks if ranged proficiency are lower than
  45048. #first check ranged weapon preference
  45049. (store_proficiency_level, ":bow_prof", "trp_player", wpt_archery),
  45050. (store_proficiency_level, ":xbow_prof", "trp_player", wpt_crossbow),
  45051. (store_proficiency_level, ":throw_prof", "trp_player", wpt_throwing),
  45052.  
  45053. #check parameters to disallow weapon types
  45054. (try_begin),
  45055. (le, ":bow_chance", 0),
  45056. (le, ":mounted_bow_chance", 0),
  45057. (assign, ":bow_prof", -1),
  45058. (try_end),
  45059. (try_begin),
  45060. (this_or_next|le, ":crossbow_sword_chance", 0),
  45061. (eq, ":has_horse", 1), #Native disallows mounted crossbow
  45062. (assign, ":xbow_prof", -1),
  45063. (try_end),
  45064. (try_begin),
  45065. (le, ":javelin_chance", 0),
  45066. (assign, ":throw_prof", -1),
  45067. (try_end),
  45068.  
  45069. (try_begin), #do a gt check here to ensure it's not set to -1
  45070. (gt, ":bow_prof", ":proficiency"),
  45071. (ge, ":bow_prof", ":xbow_prof"),
  45072. (ge, ":bow_prof", ":throw_prof"),
  45073. (assign, ":continue", wpt_archery),
  45074. (assign, ":proficiency", ":bow_prof"),
  45075. (else_try),
  45076. (gt, ":xbow_prof", ":proficiency"),
  45077. (ge, ":xbow_prof", ":bow_prof"),
  45078. (ge, ":xbow_prof", ":throw_prof"),
  45079. (assign, ":continue", wpt_crossbow),
  45080. (assign, ":proficiency", ":xbow_prof"),
  45081. (else_try),
  45082. (gt, ":throw_prof", ":proficiency"),
  45083. (ge, ":throw_prof", ":bow_prof"),
  45084. (ge, ":throw_prof", ":xbow_prof"),
  45085. (assign, ":continue", wpt_throwing),
  45086. (assign, ":proficiency", ":throw_prof"),
  45087. (try_end),
  45088. #then check melee preference
  45089. (store_proficiency_level, ":onehands", "trp_player", wpt_one_handed_weapon),
  45090. (store_proficiency_level, ":twohands", "trp_player", wpt_two_handed_weapon),
  45091. (store_proficiency_level, ":polearms", "trp_player", wpt_polearm),
  45092. (try_begin),
  45093. (le, ":sword_chance", 0),
  45094. (le, ":axe_chance", 0),
  45095. (assign, ":onehands", -1),
  45096. (try_end),
  45097. (try_begin),
  45098. (le, ":sword_chance", 0),
  45099. (assign, ":twohands", -1),
  45100. (try_end),
  45101. (try_begin),
  45102. (this_or_next|le, ":lance_chance", 0),
  45103. (eq, ":has_horse", 0),
  45104. (assign, ":polearms", -1),
  45105. (try_end),
  45106.  
  45107. (try_begin),
  45108. (gt, ":onehands", ":proficiency"),
  45109. (ge, ":onehands", ":twohands"),
  45110. (ge, ":onehands", ":polearms"),
  45111. (assign, ":continue", wpt_one_handed_weapon),
  45112. (assign, ":proficiency", ":onehands"),
  45113. (else_try),
  45114. (gt, ":twohands", ":proficiency"),
  45115. (ge, ":twohands", ":onehands"),
  45116. (ge, ":twohands", ":polearms"),
  45117. (assign, ":continue", wpt_two_handed_weapon),
  45118. (assign, ":proficiency", ":twohands"),
  45119. (else_try), #do not allow staves when dismounted
  45120. (gt, ":polearms", ":proficiency"),
  45121. (ge, ":polearms", ":onehands"),
  45122. (ge, ":polearms", ":twohands"),
  45123. (assign, ":continue", wpt_polearm),
  45124. (assign, ":proficiency", ":polearms"),
  45125. (try_end),
  45126.  
  45127. #finally add items
  45128. (try_begin),
  45129. (eq, ":continue", wpt_polearm),
  45130. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_lance"),
  45131. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_shield_item"),
  45132. (else_try),
  45133. (eq, ":continue", wpt_two_handed_weapon),
  45134. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_heavy_practice_sword"),
  45135. (else_try),
  45136. (eq, ":continue", wpt_one_handed_weapon),
  45137. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_shield_item"),
  45138. (try_begin),
  45139. (ge, ":sword_chance", ":axe_chance"),
  45140. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_sword"),
  45141. (else_try),
  45142. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_axe"),
  45143. (try_end),
  45144. (else_try),
  45145. (eq, ":continue", wpt_throwing),
  45146. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_javelin"),
  45147. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_shield_item"),
  45148. (else_try),
  45149. (eq, ":continue", wpt_crossbow),
  45150. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_sword"), #do not replace with axe
  45151. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_crossbow"),
  45152. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_bolts"),
  45153. (else_try),
  45154. (eq, ":continue", wpt_archery),
  45155. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_bow"),
  45156. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_arrows"),
  45157. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_dagger"), #keep this
  45158. (try_end),
  45159. #otherwise fall through to default randomization
  45160. (neq, ":continue", -1), #no wpt chosen
  45161. # (assign, reg1, ":continue"),
  45162. # (assign, reg2, ":proficiency"),
  45163. # (display_message, "@final type {reg1} at prof {reg2}"),
  45164. (else_try),
  45165. (try_begin),
  45166. (val_sub, ":random_no", ":sword_chance"),
  45167. (lt, ":random_no", 0),
  45168. (try_begin),
  45169. (store_random_in_range, ":sub_random_no", 0, 100),
  45170. (lt, ":sub_random_no", 50),
  45171. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_sword"),
  45172. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_shield_item"),
  45173. # (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_shield"),
  45174. (else_try),
  45175. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_heavy_practice_sword"),
  45176. (try_end),
  45177. (else_try),
  45178. (val_sub, ":random_no", ":axe_chance"),
  45179. (lt, ":random_no", 0),
  45180. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_axe"),
  45181. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_shield_item"),
  45182. # (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_shield"),
  45183. (else_try),
  45184. (val_sub, ":random_no", ":crossbow_sword_chance"),
  45185. (lt, ":random_no", 0),
  45186. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_sword"),
  45187. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_crossbow"),
  45188. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_bolts"),
  45189. (else_try),
  45190. (eq, ":has_horse", 0),
  45191. (val_sub, ":random_no", ":bow_chance"),
  45192. (lt, ":random_no", 0),
  45193. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_bow"),
  45194. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_arrows"),
  45195. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_dagger"),
  45196. (else_try),
  45197. (eq, ":has_horse", 1),
  45198. (val_sub, ":random_no", ":lance_chance"),
  45199. (lt, ":random_no", 0),
  45200. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_lance"),
  45201. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_shield_item"),
  45202. # (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_shield"),
  45203. (else_try),
  45204. (eq, ":has_horse", 1),
  45205. (val_sub, ":random_no", ":javelin_chance"),
  45206. (lt, ":random_no", 0),
  45207. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_javelin"),
  45208. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_shield_item"),
  45209. # (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_shield"),
  45210. (else_try),
  45211. (eq, ":has_horse", 1),
  45212. (val_sub, ":random_no", ":mounted_bow_chance"),
  45213. (lt, ":random_no", 0),
  45214. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_bow"),
  45215. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_arrows"),
  45216. #SB : change this to a weapon that's actually usable
  45217. (try_begin),
  45218. (ge, ":sword_chance", ":axe_chance"),
  45219. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_sword"),
  45220. (else_try),
  45221. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_axe"),
  45222. (try_end),
  45223. # (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", "itm_practice_dagger"),
  45224. (try_end),
  45225. (try_end),
  45226. (try_begin),
  45227. (ge, ":armor_item_begin", 0),
  45228. # (store_add, ":cur_armor_item", ":armor_item_begin", ":cur_team"), #SB : moved to top
  45229. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_armor_item"),
  45230. (try_end),
  45231. (try_begin),
  45232. (ge, ":helm_item_begin", 0),
  45233. # (store_add, ":cur_helm_item", ":helm_item_begin", ":cur_team"), #SB : moved to top
  45234. (mission_tpl_entry_add_override_item, "mt_arena_melee_fight", ":i_ep", ":cur_helm_item"),
  45235. (try_end),
  45236. (try_end),
  45237. ]),
  45238.  
  45239.  
  45240. # script_custom_battle_end
  45241. # Input: none
  45242. # Output: none
  45243. ("custom_battle_end",
  45244. [
  45245. (assign, "$g_custom_battle_team1_death_count", 0),
  45246. (assign, "$g_custom_battle_team2_death_count", 0),
  45247. (get_player_agent_no, ":player_agent"),
  45248. (agent_get_team, ":player_team", ":player_agent"),
  45249. (try_for_agents, ":cur_agent"),
  45250. (agent_is_human, ":cur_agent"),
  45251. (neg|agent_is_alive, ":cur_agent"),
  45252. (agent_get_team, ":cur_team", ":cur_agent"),
  45253. (try_begin),
  45254. (eq, ":cur_team", ":player_team"),
  45255. (val_add, "$g_custom_battle_team1_death_count", 1),
  45256. (else_try),
  45257. (val_add, "$g_custom_battle_team2_death_count", 1),
  45258. (try_end),
  45259. (try_end),
  45260. ]),
  45261.  
  45262. # script_remove_troop_from_prison
  45263. # Input: troop_no
  45264. # Output: none
  45265. #Other search terms: release, peace
  45266.  
  45267. ("remove_troop_from_prison",
  45268. [
  45269. (store_script_param, ":troop_no", 1),
  45270. (troop_set_slot, ":troop_no", slot_troop_prisoner_of_party, -1),
  45271. (try_begin),
  45272. (eq, "$do_not_cancel_quest", 0),
  45273. (check_quest_active, "qst_rescue_lord_by_replace"),
  45274. (quest_slot_eq, "qst_rescue_lord_by_replace", slot_quest_target_troop, ":troop_no"),
  45275. (call_script, "script_cancel_quest", "qst_rescue_lord_by_replace"),
  45276. (try_end),
  45277. (try_begin),
  45278. (eq, "$do_not_cancel_quest", 0),
  45279. (check_quest_active, "qst_rescue_prisoner"),
  45280. (quest_slot_eq, "qst_rescue_prisoner", slot_quest_target_troop, ":troop_no"),
  45281. (call_script, "script_cancel_quest", "qst_rescue_prisoner"),
  45282. #SB : cancel companion missions
  45283. (try_for_range, ":companions", companions_begin, companions_end),
  45284. (troop_slot_eq, ":companions", slot_troop_current_mission, dplmc_npc_mission_rescue_prisoner),
  45285. (troop_slot_eq, ":companions", slot_troop_mission_object, ":troop_no"),
  45286. (troop_set_slot, ":companions", slot_troop_current_mission, npc_mission_rejoin_when_possible),
  45287. (troop_set_slot, ":companions", slot_troop_days_on_mission, 1),
  45288. (try_end),
  45289. # also accrues debts
  45290. (try_for_range, ":troop_no", heroes_begin, heroes_end),
  45291. # (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  45292. (troop_get_slot, ":cur_debt", ":troop_no", slot_troop_player_debt),
  45293. (gt, ":cur_debt", dplmc_ransom_debt_mask),
  45294. (val_mod, ":cur_debt", dplmc_ransom_debt_mask),
  45295. (troop_set_slot, ":troop_no", slot_troop_player_debt, ":cur_debt"),
  45296. (try_end),
  45297. (try_end),
  45298. (try_begin),
  45299. (check_quest_active, "qst_deliver_message_to_prisoner_lord"),
  45300. (quest_slot_eq, "qst_deliver_message_to_prisoner_lord", slot_quest_target_troop, ":troop_no"),
  45301. (call_script, "script_cancel_quest", "qst_deliver_message_to_prisoner_lord"),
  45302. (try_end),
  45303. ]),
  45304.  
  45305. # script_debug_variables
  45306. # Input: two variables which will be examined by coder, this script is only for debugging.
  45307. # Output: none
  45308. ("debug_variables",
  45309. [
  45310. (store_script_param, ":unused", 1),
  45311. (store_script_param, ":unused_2", 2),
  45312. ]),
  45313.  
  45314. #lord recruitment scripts begin
  45315. ("troop_describes_troop_to_s15",
  45316. [
  45317. (store_script_param, ":troop_1", 1),
  45318. (store_script_param, ":troop_2", 2),
  45319.  
  45320.  
  45321. (str_store_troop_name, s15, ":troop_2"),
  45322.  
  45323. (try_begin),
  45324. (eq, ":troop_2", "trp_player"),
  45325. (str_store_string, s15, "str_you"),
  45326. (else_try),
  45327. (eq, ":troop_2", ":troop_1"),
  45328. (str_store_string, s15, "str_myself"),
  45329. (else_try),
  45330. (call_script, "script_troop_get_family_relation_to_troop", ":troop_2", ":troop_1"),
  45331. (gt, reg0, 0),
  45332. (str_store_string, s15, "str_my_s11_s15"),
  45333. (else_try),
  45334. (call_script, "script_troop_get_relation_with_troop", ":troop_2", ":troop_1"),
  45335. (ge, reg0, 20),
  45336. (str_store_string, s15, "str_my_friend_s15"),
  45337. (try_end),
  45338.  
  45339. ]),
  45340.  
  45341. ("troop_describes_quarrel_with_troop_to_s14",
  45342. #perhaps replace this with get_relevant_comment at a later date
  45343. [
  45344. (store_script_param, ":troop", 1),
  45345. (store_script_param, ":troop_2", 2),
  45346.  
  45347. (str_store_troop_name, s15, ":troop"),
  45348. (str_store_troop_name, s16, ":troop_2"),
  45349.  
  45350. (str_store_string, s14, "str_stop_gap__s15_is_the_rival_of_s16"),
  45351.  
  45352. (try_begin),
  45353. (eq, ":troop", "$g_talk_troop"),
  45354. (call_script, "script_cf_test_lord_incompatibility_to_s17", ":troop", ":troop_2"),
  45355. (str_store_string, s14, s17),
  45356. (else_try),
  45357. (eq, ":troop_2", "$g_talk_troop"),
  45358. (call_script, "script_cf_test_lord_incompatibility_to_s17", ":troop_2", ":troop"),
  45359. (str_store_string, s14, s17),
  45360. (else_try),
  45361. (str_store_string, s14, "str_general_quarrel"),
  45362. (try_end),
  45363.  
  45364. ]),
  45365.  
  45366. ("cf_test_lord_incompatibility_to_s17", #writes rivalry chance to reg0
  45367. [
  45368.  
  45369. (store_script_param, ":source_lord", 1),
  45370. (store_script_param, ":target_lord", 2),
  45371.  
  45372.  
  45373. (assign, ":chance_of_rivalry", 0),
  45374.  
  45375. (troop_get_slot, ":source_reputation", ":source_lord", slot_lord_reputation_type),
  45376. (troop_get_slot, ":target_reputation", ":target_lord", slot_lord_reputation_type),
  45377.  
  45378. ##diplomacy start+ Note: the next line is in native, but as far as I can discern the register value wasn't actually used.
  45379. (troop_get_type, reg15, ":target_lord"),
  45380. ##diplomacy end+
  45381.  
  45382. (str_store_troop_name, s18, ":target_lord"),
  45383.  
  45384. (assign, ":divisor", 1),
  45385.  
  45386. (call_script, "script_troop_get_family_relation_to_troop", ":target_lord", ":source_lord"),
  45387. (assign, ":family_relationship", reg0),
  45388.  
  45389. (try_begin),
  45390. (gt, ":family_relationship", 0),
  45391. (store_div, ":family_divisor", reg0, 5),
  45392. (val_add, ":divisor", ":family_divisor"),
  45393. (str_store_string, s18, "str_my_s11_s18"),
  45394. (else_try),
  45395. (gt, ":target_reputation", lrep_upstanding),
  45396. (this_or_next|eq, ":source_reputation", lrep_debauched),
  45397. (eq, ":source_reputation", lrep_selfrighteous),
  45398. (str_store_string, s18, "str_the_socalled_s11_s18"),
  45399. (try_end),
  45400.  
  45401. ##diplomacy start+ get gender types
  45402. (assign, ":save_reg65", reg65),#save register values to revert at end of script
  45403. (assign, ":save_reg3", reg3),
  45404. (call_script, "script_dplmc_store_troop_is_female_reg", ":target_lord", 3),#reg3 used below for gender-correct pronouns
  45405. (call_script, "script_dplmc_store_troop_is_female", ":source_lord"),
  45406. (assign, reg65, reg0),#used below in some situations for speaker
  45407. (assign, reg0, ":family_relationship"),#revert register to value before this section
  45408. ##diplomacy end+
  45409. (try_begin), #test if reps are compatible
  45410. (eq, ":source_reputation", lrep_martial),
  45411. (is_between, ":family_relationship", 1, 5), #uncles and cousins
  45412.  
  45413. (assign, ":chance_of_rivalry", 100),
  45414. (str_store_string, s17, "str_s18_would_cheat_me_of_my_inheritance_by_heaven_i_know_my_rights_and_im_not_going_to_back_down"),
  45415. (else_try),
  45416. (eq, ":source_reputation", lrep_martial),
  45417. (eq, ":target_reputation", lrep_quarrelsome),
  45418. (str_store_string, s17, "str_s18_once_questioned_my_honour_and_my_bravery_i_long_for_the_day_when_i_can_meet_him_in_battle_and_make_him_retract_his_statement"),
  45419. (assign, ":chance_of_rivalry", 50),
  45420.  
  45421. (else_try),
  45422. (eq, ":source_reputation", lrep_martial),
  45423. (eq, ":target_reputation", lrep_upstanding),
  45424. (str_store_string, s17, "str_s18_once_questioned_my_judgment_in_battle_by_heaven_would_he_have_us_shirk_our_duty_to_smite_our_sovereigns_foes"),
  45425. (assign, ":chance_of_rivalry", 50),
  45426.  
  45427. (else_try),
  45428. (eq, ":target_reputation", lrep_martial),
  45429. (is_between, ":family_relationship", 1, 5),
  45430.  
  45431. (assign, ":chance_of_rivalry", 100),
  45432. (str_store_string, s17, "str_s18_seems_to_think_he_has_the_right_to_some_of_my_property_well_he_does_not"),
  45433.  
  45434. (else_try),
  45435. (eq, ":source_reputation", lrep_quarrelsome),
  45436. (eq, ":target_reputation", lrep_martial),
  45437. (str_store_string, s17, "str_s18_once_took_something_i_said_amiss_stubborn_bastard_wont_give_it_up_and_keeps_trying_to_get_me_to_recant_my_words"),
  45438. (assign, ":chance_of_rivalry", 50),
  45439.  
  45440. (else_try),
  45441. (eq, ":source_reputation", lrep_quarrelsome),
  45442. (eq, ":target_reputation", lrep_cunning),
  45443. (str_store_string, s17, "str_s18_is_a_crafty_weasel_and_i_dont_trust_him_one_bit"),
  45444. (assign, ":chance_of_rivalry", 100),
  45445.  
  45446.  
  45447. (else_try),
  45448. (eq, ":source_reputation", lrep_debauched),
  45449. (eq, ":target_reputation", lrep_upstanding),
  45450. (str_store_string, s17, "str_s18_i_despite_him_he_puts_on_such_a_nauseating_display_of_virtue_and_thinks_nothing_of_insulting_his_betters"),
  45451. (assign, ":chance_of_rivalry", 100),
  45452.  
  45453. #debauched insults upstanding
  45454.  
  45455. (else_try),
  45456. (eq, ":source_reputation", lrep_debauched),
  45457. (eq, ":target_reputation", lrep_selfrighteous),
  45458. (str_store_string, s17, "str_s18_entered_into_a_little_deal_with_me_and_is_now_trying_to_wriggle_out_of_it"),
  45459. (assign, ":chance_of_rivalry", 100),
  45460.  
  45461. #debauched insults selfrighteous
  45462.  
  45463.  
  45464.  
  45465. (else_try),
  45466. (eq, ":source_reputation", lrep_selfrighteous),
  45467. (eq, ":target_reputation", lrep_debauched),
  45468. (str_store_string, s17, "str_s18_once_ran_an_errand_for_me_and_now_thinks_i_owe_him_something_i_owe_his_ilk_nothing"),
  45469. (assign, ":chance_of_rivalry", 100),
  45470. #selfrighteous dismisses debauched
  45471.  
  45472. (else_try),
  45473. (eq, ":source_reputation", lrep_selfrighteous),
  45474. (eq, ":target_reputation", lrep_goodnatured),
  45475. (str_store_string, s17, "str_s18_is_soft_and_weak_and_not_fit_to_govern_a_fief_and_i_have_always_detested_him"),
  45476. (assign, ":chance_of_rivalry", 100),
  45477.  
  45478.  
  45479.  
  45480. (else_try),
  45481. (eq, ":source_reputation", lrep_cunning),
  45482. (eq, ":target_reputation", lrep_quarrelsome),
  45483. (str_store_string, s17, "str_s18_is_a_quarrelsome_oaf_and_a_liability_in_my_opinion_and_ive_let_him_know_as_much"),
  45484. (assign, ":chance_of_rivalry", 100),
  45485. #cunning insults quarrelsome
  45486.  
  45487. (else_try),
  45488. (eq, ":source_reputation", lrep_cunning),
  45489. (eq, ":target_reputation", lrep_goodnatured),
  45490. (str_store_string, s17, "str_s18_i_am_sorry_to_say_is_far_too_softhearted_a_man_to_be_given_any_kind_of_responsibility_his_chivalry_will_allow_the_enemy_to_flee_to_fight_another_day_and_will_cost_the_lives_of_my_own_faithful_men"),
  45491. (assign, ":chance_of_rivalry", 100),
  45492.  
  45493.  
  45494. (else_try),
  45495. (eq, ":source_reputation", lrep_goodnatured),
  45496. (eq, ":target_reputation", lrep_cunning),
  45497. (str_store_string, s17, "str_s18_seems_to_have_something_against_me_for_some_reason_i_dont_like_to_talk_ill_of_people_but_i_think_hes_can_be_a_bit_of_a_cad_sometimes"),
  45498. (assign, ":chance_of_rivalry", 100),
  45499.  
  45500. (else_try),
  45501. (eq, ":source_reputation", lrep_goodnatured),
  45502. (eq, ":target_reputation", lrep_selfrighteous),
  45503. (str_store_string, s17, "str_s18_has_always_treated_me_contemptuously_although_i_have_done_him_no_wrong"),
  45504. (assign, ":chance_of_rivalry", 100),
  45505.  
  45506.  
  45507.  
  45508. (else_try),
  45509. (eq, ":source_reputation", lrep_upstanding),
  45510. (eq, ":target_reputation", lrep_debauched),
  45511. (str_store_string, s17, "str_s18_is_thoroughly_dishonorable_and_a_compulsive_spinner_of_intrigues_which_i_fear_will_drag_us_into_wars_or_incite_rebellions"),
  45512. (assign, ":chance_of_rivalry", 50),
  45513.  
  45514. (else_try),
  45515. (eq, ":source_reputation", lrep_upstanding),
  45516. (eq, ":target_reputation", lrep_martial),
  45517. (str_store_string, s17, "str_s18_disappoints_me_i_once_scolded_for_his_rashness_in_battle_and_he_took_offense_i_do_not_care_to_apologize_for_my_efforts_to_save_his_life_and_the_lives_of_his_men"),
  45518. (assign, ":chance_of_rivalry", 50),
  45519.  
  45520. #for commons
  45521. (else_try),
  45522. (this_or_next|eq, ":source_reputation", lrep_upstanding),
  45523. (this_or_next|eq, ":source_reputation", lrep_martial),
  45524. (eq, ":source_reputation", lrep_selfrighteous),
  45525. (eq, ":target_reputation", lrep_roguish),
  45526. (str_store_string, s17, "str_s18_squanders_money_and_carouses_in_a_way_most_unbefitting_a_noble_by_doing_so_he_disgraces_us_all"),
  45527. (assign, ":chance_of_rivalry", 100),
  45528.  
  45529.  
  45530. (else_try),
  45531. (eq, ":source_reputation", lrep_roguish),
  45532. (this_or_next|eq, ":target_reputation", lrep_upstanding),
  45533. (this_or_next|eq, ":target_reputation", lrep_martial),
  45534. (eq, ":target_reputation", lrep_selfrighteous),
  45535. (str_store_string, s17, "str_s18_has_been_speaking_ill_of_me_behind_my_back_or_so_they_say"),
  45536. (assign, ":chance_of_rivalry", 100),
  45537.  
  45538.  
  45539. (else_try),
  45540. (this_or_next|eq, ":source_reputation", lrep_quarrelsome),
  45541. (this_or_next|eq, ":source_reputation", lrep_martial),
  45542. (eq, ":source_reputation", lrep_selfrighteous),
  45543. (eq, ":target_reputation", lrep_custodian),
  45544. (str_store_string, s17, "str_s18_is_a_disgrace_reg3shehe_consorts_with_merchants_lends_money_at_interest_uses_coarse_language_and_shows_no_attempt_to_uphold_the_dignity_of_the_honor_bestowed_upon_reg3herhim"),
  45545. (assign, ":chance_of_rivalry", 100),
  45546.  
  45547. (else_try),
  45548. (eq, ":source_reputation", lrep_custodian),
  45549. (this_or_next|eq, ":target_reputation", lrep_quarrelsome),
  45550. (this_or_next|eq, ":target_reputation", lrep_martial),
  45551. (eq, ":target_reputation", lrep_selfrighteous),
  45552. (str_store_string, s17, "str_s18_has_condemned_me_for_engaging_in_commerce_what_could_possibly_be_wrong_with_that"),
  45553. (assign, ":chance_of_rivalry", 100),
  45554.  
  45555.  
  45556. (else_try),
  45557. (this_or_next|eq, ":source_reputation", lrep_debauched),
  45558. (this_or_next|eq, ":source_reputation", lrep_martial),
  45559. (eq, ":source_reputation", lrep_selfrighteous),
  45560. (eq, ":target_reputation", lrep_benefactor),
  45561. (str_store_string, s17, "str_s18_i_have_heard_has_been_encouraging_seditious_ideas_among_the_peasantry__a_foolish_move_which_endangers_us_all"),
  45562. (assign, ":chance_of_rivalry", 100),
  45563.  
  45564.  
  45565. (else_try),
  45566. (eq, ":source_reputation", lrep_benefactor),
  45567. (this_or_next|eq, ":target_reputation", lrep_debauched),
  45568. (this_or_next|eq, ":target_reputation", lrep_martial),
  45569. (eq, ":target_reputation", lrep_selfrighteous),
  45570. (str_store_string, s17, "str_s18_has_called_me_out_for_the_way_i_deal_with_my_tenants_well_so_be_it_if_i_teach_them_that_they_are_the_equal_of_anyone_with_socalled_gentle_blood_what_is_it_to_reg3herhim"),
  45571. (assign, ":chance_of_rivalry", 100),
  45572.  
  45573.  
  45574. #lady incompatibilities
  45575. (else_try),
  45576. (eq, ":source_reputation", lrep_conventional),
  45577. (this_or_next|eq, ":target_reputation", lrep_martial),
  45578. (eq, ":target_reputation", lrep_selfrighteous),
  45579. (str_store_string, s17, "str_a_most_gallant_gentleman_who_knows_how_to_treat_a_lady"),
  45580. (assign, ":chance_of_rivalry", -50),
  45581.  
  45582. (else_try),
  45583. (eq, ":source_reputation", lrep_conventional),
  45584. (eq, ":target_reputation", lrep_quarrelsome),
  45585. (str_store_string, s17, "str_a_base_cad"),
  45586. (assign, ":chance_of_rivalry", 50),
  45587.  
  45588.  
  45589. (else_try),
  45590. (eq, ":source_reputation", lrep_adventurous),
  45591. (eq, ":target_reputation", lrep_cunning),
  45592. (str_store_string, s17, "str_a_man_who_treats_me_as_his_equal_which_is_rare"),
  45593. (assign, ":chance_of_rivalry", -50),
  45594.  
  45595. (else_try),
  45596. (eq, ":source_reputation", lrep_adventurous),
  45597. (this_or_next|eq, ":target_reputation", lrep_martial),
  45598. (eq, ":target_reputation", lrep_debauched),
  45599. (str_store_string, s17, "str_appears_to_value_me_with_his_estate_and_his_horse_as_prizes_worth_having"),
  45600. (assign, ":chance_of_rivalry", 50),
  45601.  
  45602. (else_try),
  45603. (eq, ":source_reputation", lrep_adventurous),
  45604. (neq, ":target_reputation", lrep_goodnatured),
  45605.  
  45606. (str_store_string, s17, "str_a_bit_dull_but_what_can_you_expect"),
  45607. (assign, ":chance_of_rivalry", 10),
  45608.  
  45609. (else_try),
  45610. (eq, ":source_reputation", lrep_otherworldly),
  45611. (call_script, "script_troop_get_romantic_chemistry_with_troop", ":source_lord", ":target_lord"),
  45612. (ge, reg0, 10),
  45613. (str_store_string, s17, "str_the_man_whom_destiny_intends_for_me"),
  45614. (assign, ":chance_of_rivalry", -50),
  45615.  
  45616. (else_try),
  45617. (eq, ":source_reputation", lrep_otherworldly),
  45618. (lt, reg0, 0),
  45619.  
  45620. (str_store_string, s17, "str_is_not_right_for_me__i_cannot_say_why_but_he_makes_my_skin_crawl"),
  45621. (assign, ":chance_of_rivalry", 50),
  45622.  
  45623.  
  45624. (else_try),
  45625. (eq, ":source_reputation", lrep_ambitious),
  45626. (this_or_next|eq, ":target_reputation", lrep_selfrighteous),
  45627. (eq, ":target_reputation", lrep_cunning),
  45628. (str_store_string, s17, "str_is_a_man_who_clearly_intends_to_make_his_mark_in_the_world"),
  45629. (assign, ":chance_of_rivalry", -20),
  45630.  
  45631. (else_try),
  45632. (eq, ":source_reputation", lrep_ambitious),
  45633. (eq, ":target_reputation", lrep_goodnatured),
  45634.  
  45635. (str_store_string, s17, "str_is_a_layabout_a_naif_prey_for_others_who_are_cleverer_than_he"),
  45636. (assign, ":chance_of_rivalry", 30),
  45637.  
  45638.  
  45639. (else_try),
  45640. (eq, ":source_reputation", lrep_moralist),
  45641. (eq, ":target_reputation", lrep_upstanding),
  45642.  
  45643. (str_store_string, s17, "str_is_a_man_of_stalwart_character"),
  45644. (assign, ":chance_of_rivalry", -50),
  45645.  
  45646. (else_try),
  45647. (eq, ":source_reputation", lrep_moralist),
  45648. (this_or_next|eq, ":target_reputation", lrep_debauched),
  45649. (eq, ":target_reputation", lrep_cunning),
  45650.  
  45651. (str_store_string, s17, "str_appears_to_be_a_man_of_low_morals"),
  45652. (assign, ":chance_of_rivalry", 50),
  45653.  
  45654. (else_try),
  45655. (eq, ":source_reputation", lrep_moralist),
  45656. (eq, ":target_reputation", lrep_quarrelsome),
  45657.  
  45658. (str_store_string, s17, "str_appears_to_be_a_man_who_lacks_selfdiscipline"),
  45659. (assign, ":chance_of_rivalry", 50),
  45660. ##diplomacy start+ Support for promoted ladies:
  45661. (else_try),
  45662. #Ambitious vs otherworldly
  45663. (eq, ":source_reputation", lrep_ambitious),
  45664. (troop_slot_eq, ":source_lord", slot_troop_occupation, slto_kingdom_hero),
  45665. (eq, ":target_reputation", lrep_otherworldly),
  45666. (troop_slot_eq, ":target_lord", slot_troop_occupation, slto_kingdom_hero),
  45667. (str_store_string, s17, "str_s18_is_soft_and_weak_and_not_fit_to_govern_a_fief_and_i_have_always_detested_him"),
  45668. (str_store_string, s17, "str_s18_has_always_treated_me_contemptuously_although_i_have_done_him_no_wrong"),
  45669. (assign, ":chance_of_rivalry", 100),
  45670. (else_try),
  45671. #Otherworldly vs ambitious
  45672. (eq, ":source_reputation", lrep_otherworldly),
  45673. (troop_slot_eq, ":source_lord", slot_troop_occupation, slto_kingdom_hero),
  45674. (eq, ":target_reputation", lrep_ambitious),
  45675. (troop_slot_eq, ":target_lord", slot_troop_occupation, slto_kingdom_hero),
  45676. (str_store_string, s17, "str_s18_has_always_treated_me_contemptuously_although_i_have_done_him_no_wrong"),
  45677. (assign, ":chance_of_rivalry", 100),
  45678. (else_try),
  45679. #Quarrelsome quarrels with conventional and moralist
  45680. (eq, ":source_reputation", lrep_quarrelsome),
  45681. (troop_slot_eq, ":target_lord", slot_troop_occupation, slto_kingdom_hero),
  45682. (this_or_next|eq, ":target_reputation", lrep_moralist),
  45683. (eq, ":target_reputation", lrep_conventional),
  45684. (str_store_string, s17, "str_s18_once_took_something_i_said_amiss_stubborn_bastard_wont_give_it_up_and_keeps_trying_to_get_me_to_recant_my_words"),
  45685. (assign, ":chance_of_rivalry", 50),
  45686. (else_try),
  45687. #Cunning conflicts with moralist
  45688. (eq, ":source_reputation", lrep_cunning),
  45689. (eq, ":target_reputation", lrep_moralist),
  45690. (troop_slot_eq, ":target_lord", slot_troop_occupation, slto_kingdom_hero),
  45691. (str_store_string, s17, "str_s18_i_am_sorry_to_say_is_far_too_softhearted_a_man_to_be_given_any_kind_of_responsibility_his_chivalry_will_allow_the_enemy_to_flee_to_fight_another_day_and_will_cost_the_lives_of_my_own_faithful_men"),
  45692. (assign, ":chance_of_rivalry", 50),
  45693. (else_try),
  45694. #Debauched conflicts with moralist
  45695. (eq, ":source_reputation", lrep_debauched),
  45696. (troop_slot_eq, ":target_lord", slot_troop_occupation, slto_kingdom_hero),
  45697. (eq, ":target_reputation", lrep_moralist),
  45698. (str_store_string, s17, "str_s18_i_despite_him_he_puts_on_such_a_nauseating_display_of_virtue_and_thinks_nothing_of_insulting_his_betters"),
  45699. (assign, ":chance_of_rivalry", 50),
  45700. (else_try),
  45701. #Martial or debauched conflicts with adventurous
  45702. (this_or_next|eq, ":source_reputation", lrep_martial),
  45703. (eq, ":source_reputation", lrep_debauched),
  45704. (troop_slot_eq, ":target_lord", slot_troop_occupation, slto_kingdom_hero),
  45705. (eq, ":target_reputation", lrep_adventurous),
  45706. (str_store_string, s17, "str_s18_once_took_something_i_said_amiss_stubborn_bastard_wont_give_it_up_and_keeps_trying_to_get_me_to_recant_my_words"),
  45707. (assign, ":chance_of_rivalry", 50),
  45708. (else_try),
  45709. (eq, ":source_reputation", lrep_goodnatured),
  45710. (troop_slot_eq, ":target_lord", slot_troop_occupation, slto_kingdom_hero),
  45711. (eq, ":target_reputation", lrep_ambitious),
  45712. (str_store_string, s17, "str_s18_seems_to_have_something_against_me_for_some_reason_i_dont_like_to_talk_ill_of_people_but_i_think_hes_can_be_a_bit_of_a_cad_sometimes"),
  45713. (assign, ":chance_of_rivalry", 30),
  45714. ##Add support for secondary morality types
  45715. (else_try),
  45716. (call_script, "script_dplmc_get_troop_morality_value", ":target_lord", tmt_honest),
  45717. (ge, reg0, 1),#This would apply (if no previous condition was reached) to Marnid, Rolf, Firentis, Alayan, and Jeremus.
  45718. (eq, ":source_reputation", lrep_moralist),
  45719. (str_store_string, s17, "str_is_a_man_of_stalwart_character"),#<- (does not apply to Rolf, since he is Cunning)
  45720. (assign, ":chance_of_rivalry", -50),
  45721. (else_try),
  45722. (call_script, "script_dplmc_get_troop_morality_value", ":target_lord", tmt_pious),
  45723. (ge, reg0, 1),#This doesn't apply to anyone at the moment.
  45724. (eq, ":source_reputation", lrep_moralist),
  45725. (str_store_string, s17, "str_is_a_man_of_stalwart_character"),
  45726. (assign, ":chance_of_rivalry", -50),
  45727. (try_end),
  45728.  
  45729. ##diplomacy end+
  45730.  
  45731. (val_div, ":chance_of_rivalry", ":divisor"),
  45732. ##diplomacy start+ for companions, use compatability information
  45733. (try_begin),
  45734. (is_between, ":source_lord", companions_begin, companions_end),
  45735. (troop_slot_eq, ":source_lord", slot_troop_personalitymatch_object, ":target_lord"),
  45736. (val_min, ":chance_of_rivalry", -100),
  45737. (else_try),
  45738. (is_between, ":source_lord", companions_begin, companions_end),
  45739. (this_or_next|troop_slot_eq, ":source_lord", slot_troop_personalityclash_object, ":target_lord"),
  45740. (troop_slot_eq, ":source_lord", slot_troop_personalityclash2_object, ":target_lord"),
  45741. (try_begin),
  45742. (le, ":chance_of_rivalry", 0),
  45743. (str_store_string, s17, "str_general_quarrel"),
  45744. (try_end),
  45745. (val_max, ":chance_of_rivalry", 100),
  45746. (try_end),
  45747. (assign, reg3, ":save_reg3"),#revert reg3
  45748. (assign, reg65, ":save_reg65"),#revert reg65
  45749. ##diplomacy end+
  45750. (assign, reg0, ":chance_of_rivalry"),
  45751.  
  45752. (neq, ":chance_of_rivalry", 0),
  45753. # (eq, ":incompatibility_found", 1), #cf can be removed with this
  45754.  
  45755. ]),
  45756.  
  45757. ("troop_get_romantic_chemistry_with_troop", #source is lady, target is man
  45758. [
  45759. ##diplomacy start+ (players of either gender may marry opposite-gender lords)
  45760. #Note: the above is misleading even in Native, since when target_lord is the player,
  45761. #target_lord can be female and source_lady can be male.
  45762. (assign, ":save_reg1", reg1),
  45763. ##diplomacy end+
  45764. (store_script_param, ":source_lady", 1),
  45765. (store_script_param, ":target_lord", 2),
  45766.  
  45767. (store_add, ":chemistry_sum", ":source_lady", ":target_lord"),
  45768. (val_add, ":chemistry_sum", "$romantic_attraction_seed"),
  45769.  
  45770. #This calculates (modula ^ 2) * 3
  45771. (store_mod, ":chemistry_remainder", ":chemistry_sum", 5),
  45772. (val_mul, ":chemistry_remainder", ":chemistry_remainder"), #0, 1, 4, 9, 16
  45773. (val_mul, ":chemistry_remainder", 3), #0, 3, 12, 27, 48
  45774.  
  45775. (store_attribute_level, ":romantic_chemistry", ":target_lord", ca_charisma),
  45776. (val_sub, ":romantic_chemistry", ":chemistry_remainder"),
  45777.  
  45778. (val_mul, ":romantic_chemistry", 2),
  45779. ##diplomacy start+ ensure companion compatability
  45780. (try_begin),
  45781. (is_between, ":source_lady", companions_begin, companions_end),
  45782. (troop_slot_eq, ":source_lady", slot_troop_personalitymatch_object, ":target_lord"),
  45783. (val_max, ":romantic_chemistry", 15),
  45784. (else_try),
  45785. (is_between, ":target_lord", companions_begin, companions_end),
  45786. (troop_slot_eq, ":target_lord", slot_troop_personalitymatch_object, ":source_lady"),
  45787. (val_max, ":romantic_chemistry", 15),
  45788. #...and companion incompatibility.
  45789. (else_try),
  45790. (is_between, ":source_lady", companions_begin, companions_end),
  45791. (this_or_next|troop_slot_eq, ":source_lady", slot_troop_personalityclash_object, ":target_lord"),
  45792. (troop_slot_eq, ":source_lady", slot_troop_personalityclash2_object, ":target_lord"),
  45793. (val_min, ":romantic_chemistry", -15),
  45794. (else_try),
  45795. (is_between, ":target_lord", companions_begin, companions_end),
  45796. (this_or_next|troop_slot_eq, ":target_lord", slot_troop_personalityclash_object, ":source_lady"),
  45797. (troop_slot_eq, ":target_lord", slot_troop_personalityclash2_object, ":source_lady"),
  45798. (val_min, ":romantic_chemistry", -15),
  45799. #Prevent glitches. This can be enabled explicitly if intentional.
  45800. (else_try),
  45801. (call_script, "script_dplmc_store_is_female_troop_1_troop_2", ":source_lady", ":target_lord"),
  45802. (eq, reg0, reg1),#different genders
  45803. (val_min, ":romantic_chemistry", -15),
  45804. (try_end),
  45805. (assign, reg1, ":save_reg1"),
  45806. ##diplomacy end+
  45807. (assign, reg0, ":romantic_chemistry"),
  45808.  
  45809. #examples :
  45810. #For a charisma of 18, yields (18 - 0) * 2 = 36, (18 - 3) * 2 = 30, (18 - 12) * 2 = 12, (18 - 27) * 2 = -18, (18 - 48) * 2 = -60
  45811. #For a charisma of 10, yields (10 - 0) * 2 = 20, (10 - 3) * 2 = 14, (10 - 12) * 2 = -4, (10 - 27) * 2 = -34, (10 - 48) * 2 = -76
  45812. #For a charisma of 7, yields (7 - 0) * 2 = 14, (7 - 3) * 2 = 8, (7 - 12) * 2 = -10, (7 - 27) * 2 = -40, (7 - 48) * 2 = -82
  45813.  
  45814. #15 is high attraction, 0 is moderate attraction, -76 is lowest attraction
  45815. ]),
  45816.  
  45817.  
  45818. ("cf_troop_get_romantic_attraction_to_troop", #source is lady, target is man
  45819. [
  45820.  
  45821. (store_script_param, ":source_lady", 1),
  45822. (store_script_param, ":target_lord", 2),
  45823.  
  45824. (assign, ":weighted_romantic_assessment", 0),
  45825. ##diplomacy start+
  45826. (assign, ":save_reg1", reg1),
  45827. #Use gender script
  45828. #(troop_get_type, ":source_is_female", ":source_lady"),
  45829. #(eq, ":source_is_female", 1),
  45830. #(troop_get_type, ":target_is_female", ":target_lord"),
  45831. #(eq, ":target_is_female", 0),
  45832. (call_script, "script_dplmc_store_is_female_troop_1_troop_2", ":source_lady", ":target_lord"),
  45833. (assign, ":source_is_female", reg0),
  45834. (assign, ":target_is_female", reg1),
  45835. (assign, reg1, ":save_reg1"),
  45836. (assign, reg0, -15),
  45837. (neq, ":source_is_female", ":target_is_female"),
  45838. ##diplomacy end+
  45839.  
  45840. (call_script, "script_troop_get_romantic_chemistry_with_troop", ":source_lady", ":target_lord"),
  45841. (assign, ":romantic_chemistry", reg0),
  45842.  
  45843.  
  45844. #objective attraction - average renown
  45845. (troop_get_slot, ":modified_renown", ":target_lord", slot_troop_renown),
  45846. (assign, ":lady_status", 60),
  45847. ##diplomacy start+ adjust status based on who they are
  45848. (try_begin),
  45849. #The renown bonus is decreased the more important the lady's relatives are.
  45850. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_HIGH),
  45851. (troop_get_slot, ":best_renown", ":source_lady", slot_troop_renown),
  45852. (try_begin),
  45853. (troop_get_slot, ":relative", ":source_lady", slot_troop_father),
  45854. (ge, ":relative", 0),
  45855. (troop_get_slot, ":other_renown", ":relative", slot_troop_renown),
  45856. (val_max, ":best_renown", ":other_renown"),
  45857. (try_end),
  45858. (try_begin),
  45859. (troop_get_slot, ":relative", ":source_lady", slot_troop_guardian),
  45860. (ge, ":relative", 0),
  45861. (troop_get_slot, ":other_renown", ":relative", slot_troop_renown),
  45862. (val_max, ":best_renown", ":other_renown"),
  45863. (try_end),
  45864. (try_begin),
  45865. (troop_get_slot, ":relative", ":source_lady", slot_troop_mother),
  45866. (ge, ":relative", 0),
  45867. (troop_get_slot, ":other_renown", ":relative", slot_troop_renown),
  45868. (val_max, ":best_renown", ":other_renown"),
  45869. (try_end),
  45870. (try_begin),
  45871. (ge, ":best_renown", 600),
  45872. (store_div, ":lady_status", ":best_renown", 10),
  45873. (else_try),
  45874. (lt, ":best_renown", 400),
  45875. (store_div, ":lady_status", ":best_renown", 10),
  45876. (val_add, ":lady_status", 20),
  45877. (try_end),
  45878. (val_clamp, ":lady_status", 30, 90),
  45879. (try_end),
  45880. ##diplomacy end+
  45881. (val_div, ":modified_renown", 5),
  45882. (val_sub, ":modified_renown", ":lady_status"),
  45883. (val_min, ":modified_renown", 60),
  45884.  
  45885.  
  45886.  
  45887. #weight values
  45888. (try_begin),
  45889. (assign, ":personality_match", 0),
  45890. (call_script, "script_cf_test_lord_incompatibility_to_s17", ":source_lady", ":target_lord"),
  45891. (store_sub, ":personality_match", 0, reg0),
  45892. (try_end),
  45893.  
  45894. (troop_get_slot, ":lady_reputation", ":source_lady", slot_lord_reputation_type),
  45895. (try_begin),
  45896. (eq, ":lady_reputation", lrep_ambitious),
  45897. (val_mul, ":modified_renown", 2),
  45898. (val_div, ":romantic_chemistry", 2),
  45899. (else_try),
  45900. (eq, ":lady_reputation", lrep_otherworldly),
  45901. (val_div, ":modified_renown", 2),
  45902. (val_mul, ":romantic_chemistry", 2),
  45903. (else_try),
  45904. (eq, ":lady_reputation", lrep_adventurous),
  45905. (val_div, ":modified_renown", 2),
  45906. (else_try),
  45907. (eq, ":lady_reputation", lrep_moralist),
  45908. (val_div, ":modified_renown", 2),
  45909. (val_div, ":romantic_chemistry", 2),
  45910. (try_end),
  45911.  
  45912. (val_add, ":weighted_romantic_assessment", ":romantic_chemistry"),
  45913. (val_add, ":weighted_romantic_assessment", ":personality_match"),
  45914. (val_add, ":weighted_romantic_assessment", ":modified_renown"),
  45915.  
  45916. (assign, reg0, ":weighted_romantic_assessment"),
  45917.  
  45918. ]),
  45919.  
  45920.  
  45921. ("cf_random_political_event", #right now, just enmities
  45922. [
  45923.  
  45924. ##diplomacy start+ Lay more groundwork for heroes other than active-npcs being lords
  45925. ##OLD:
  45926. #(store_random_in_range, ":lord_1", active_npcs_begin, active_npcs_end),
  45927. #(store_random_in_range, ":lord_2", active_npcs_begin, active_npcs_end),
  45928. ##NEW:
  45929. (store_random_in_range, ":lord_1", heroes_begin, heroes_end),
  45930. (try_begin),
  45931. (neg|is_between, ":lord_1", active_npcs_begin, active_npcs_end),
  45932. (neg|troop_slot_eq, ":lord_1", slot_troop_occupation, slto_kingdom_hero),
  45933. (store_random_in_range, ":lord_1", active_npcs_begin, active_npcs_end),
  45934. (try_end),
  45935. (store_random_in_range, ":lord_2", heroes_begin, heroes_end),
  45936. (try_begin),
  45937. (neg|is_between, ":lord_2", active_npcs_begin, active_npcs_end),
  45938. (neg|troop_slot_eq, ":lord_2", slot_troop_occupation, slto_kingdom_hero),
  45939. (store_random_in_range, ":lord_2", active_npcs_begin, active_npcs_end),
  45940. (try_end),
  45941. ##diplomacy end+
  45942.  
  45943. (troop_slot_eq, ":lord_1", slot_troop_occupation, slto_kingdom_hero),
  45944. (troop_slot_eq, ":lord_2", slot_troop_occupation, slto_kingdom_hero),
  45945.  
  45946. (neq, ":lord_1", ":lord_2"),
  45947.  
  45948. (val_add, "$total_political_events", 1),
  45949.  
  45950. (store_troop_faction, ":lord_1_faction", ":lord_1"),
  45951. (store_troop_faction, ":lord_2_faction", ":lord_2"),
  45952.  
  45953. (assign, reg8, "$total_political_events"),
  45954.  
  45955.  
  45956. (faction_get_slot, ":faction_1_leader", ":lord_1_faction", slot_faction_leader),
  45957. (faction_get_slot, ":faction_2_leader", ":lord_2_faction", slot_faction_leader),
  45958.  
  45959. (this_or_next|eq, ":lord_1_faction", ":lord_2_faction"),
  45960. (this_or_next|eq, ":lord_1", ":faction_1_leader"),
  45961. (eq, ":lord_2", ":faction_2_leader"),
  45962.  
  45963.  
  45964. (call_script, "script_troop_get_relation_with_troop", ":lord_1", ":lord_2"),
  45965. (assign, ":relation", reg0),
  45966.  
  45967.  
  45968. (store_random_in_range, ":random", 0, 100),
  45969.  
  45970. (try_begin),
  45971. #reconciliation
  45972. #The chance of a liege reconciling two quarreling vassals is equal to (relationship with lord 1 x relationship with lord 2) / 4
  45973.  
  45974. (eq, ":lord_1_faction", ":lord_2_faction"),
  45975. (neq, ":faction_1_leader", "trp_player"),
  45976.  
  45977. (le, ":relation", -10),
  45978.  
  45979. # (ge, "$total_political_events", 5000),
  45980.  
  45981. (call_script, "script_troop_get_relation_with_troop", ":lord_1", ":faction_1_leader"),
  45982. (gt, reg0, 0),
  45983. (assign, ":lord_1_leader_rel", reg0),
  45984.  
  45985. (call_script, "script_troop_get_relation_with_troop", ":lord_2", ":faction_1_leader"),
  45986. (gt, reg0, 0),
  45987. (store_mul, ":reconciliation_chance", ":lord_1_leader_rel", reg0),
  45988. (val_div, ":reconciliation_chance", 4), #was 2 before
  45989.  
  45990. (le, ":random", ":reconciliation_chance"),
  45991.  
  45992. (str_store_troop_name, s4, ":faction_1_leader"),
  45993. (str_store_troop_name, s5, ":lord_1"),
  45994. (str_store_troop_name, s6, ":lord_2"),
  45995. (try_begin),
  45996. (eq, "$cheat_mode", 1),
  45997. (display_message, "str_check_reg8_s4_reconciles_s5_and_s6_"),
  45998. (try_end),
  45999.  
  46000. (call_script, "script_troop_change_relation_with_troop", ":lord_1", ":lord_2", 20),
  46001. (val_add, "$total_random_quarrel_changes", 20),
  46002. (else_try), #lord intervenes in quarrel
  46003. (eq, ":lord_1_faction", ":lord_2_faction"),
  46004.  
  46005. (le, ":relation", -10),
  46006. # (ge, ":random", 50),
  46007. (try_begin),
  46008. (eq, ":faction_1_leader", "trp_player"),
  46009. (try_begin),
  46010. (eq, "$cheat_mode", 1),
  46011. (display_message, "str_diagnostic__player_should_receive_consultation_quest_here_if_not_already_active"),
  46012. (try_end),
  46013. (neg|check_quest_active, "qst_consult_with_minister"),
  46014. (neg|check_quest_active, "qst_resolve_dispute"),
  46015. (eq, "$g_minister_notification_quest", 0),
  46016. (assign, "$g_minister_notification_quest", "qst_resolve_dispute"),
  46017. (quest_set_slot, "qst_resolve_dispute", slot_quest_target_troop, ":lord_1"),
  46018. (quest_set_slot, "qst_resolve_dispute", slot_quest_object_troop, ":lord_2"),
  46019.  
  46020. (call_script, "script_add_notification_menu", "mnu_notification_player_should_consult", 0, 0),
  46021.  
  46022.  
  46023. (else_try),
  46024. (call_script, "script_troop_get_relation_with_troop", ":lord_1", ":faction_1_leader"),
  46025. (assign, ":lord_1_rel_w_leader", reg0),
  46026.  
  46027. (call_script, "script_troop_get_relation_with_troop", ":lord_2", ":faction_1_leader"),
  46028. (assign, ":lord_2_rel_w_leader", reg0),
  46029.  
  46030. (store_random_in_range, ":another_random", -5, 5),
  46031.  
  46032. (val_add, ":lord_1_rel_w_leader", ":another_random"),
  46033.  
  46034. (try_begin),
  46035. (ge, ":lord_1_rel_w_leader", ":lord_2_rel_w_leader"),
  46036. (assign, ":winner_lord", ":lord_1"),
  46037. (assign, ":loser_lord", ":lord_2"),
  46038. (else_try),
  46039. (assign, ":loser_lord", ":lord_1"),
  46040. (assign, ":winner_lord", ":lord_2"),
  46041. (try_end),
  46042.  
  46043. (str_store_troop_name, s4, ":faction_1_leader"),
  46044. (str_store_troop_name, s5, ":winner_lord"),
  46045. (str_store_troop_name, s6, ":loser_lord"),
  46046.  
  46047. (try_begin),
  46048. (eq, "$cheat_mode", 1),
  46049. (display_message, "str_check_reg8_s4_rules_in_s5s_favor_in_quarrel_with_s6_"),
  46050. (try_end),
  46051.  
  46052. (call_script, "script_add_log_entry", logent_ruler_intervenes_in_quarrel, ":faction_1_leader", ":loser_lord", ":winner_lord", ":lord_1_faction"), #faction leader is actor, loser lord is center object, winner lord is troop_object
  46053.  
  46054. (call_script, "script_troop_change_relation_with_troop", ":winner_lord", ":faction_1_leader", 10),
  46055. (call_script, "script_troop_change_relation_with_troop", ":loser_lord", ":faction_1_leader", -20),
  46056. (val_add, "$total_random_quarrel_changes", -10),
  46057.  
  46058. (try_end),
  46059.  
  46060.  
  46061. (else_try), #new quarrel - companions
  46062. (is_between, ":lord_1", companions_begin, companions_end),
  46063. (is_between, ":lord_2", companions_begin, companions_end),
  46064.  
  46065. (ge, ":relation", -10),
  46066. (this_or_next|troop_slot_eq, ":lord_1", slot_troop_personalityclash_object, ":lord_2"),
  46067. (troop_slot_eq, ":lord_1", slot_troop_personalityclash2_object, ":lord_2"),
  46068.  
  46069. (str_store_troop_name, s5, ":lord_1"),
  46070. (str_store_troop_name, s6, ":lord_2"),
  46071.  
  46072. (try_begin),
  46073. (eq, "$cheat_mode", 1),
  46074. (display_message, "str_check_reg8_new_rivalry_generated_between_s5_and_s6"),
  46075. (try_end),
  46076.  
  46077. (call_script, "script_troop_change_relation_with_troop", ":lord_1", ":lord_2", -30),
  46078. (val_add, "$total_random_quarrel_changes", -30),
  46079.  
  46080.  
  46081. (else_try), #new quarrel - others
  46082. (eq, ":lord_1_faction", ":lord_2_faction"),
  46083.  
  46084. (ge, ":relation", -10), #can have two quarrels
  46085.  
  46086. (call_script, "script_cf_test_lord_incompatibility_to_s17", ":lord_1", ":lord_2"),
  46087. (assign, ":chance_of_enmity", reg0),
  46088. (gt, ":chance_of_enmity", 0),
  46089.  
  46090.  
  46091. (lt, ":random", ":chance_of_enmity"), #50 or 100 percent, usually
  46092.  
  46093.  
  46094. (str_store_troop_name, s5, ":lord_1"),
  46095. (str_store_troop_name, s6, ":lord_2"),
  46096. (try_begin),
  46097. (eq, "$cheat_mode", 1),
  46098. (display_message, "str_check_reg8_new_rivalry_generated_between_s5_and_s6"),
  46099. (try_end),
  46100.  
  46101. (call_script, "script_troop_change_relation_with_troop", ":lord_1", ":lord_2", -30),
  46102. (val_add, "$total_random_quarrel_changes", -30),
  46103.  
  46104. # (call_script, "script_update_troop_notes", ":lord_1"),
  46105. # (call_script, "script_update_troop_notes", ":lord_2"),
  46106. (else_try), #a lord attempts to suborn a character
  46107. (store_current_hours, ":hours"),
  46108. (ge, ":hours", 24),
  46109.  
  46110. (neq, ":lord_1_faction", ":lord_2_faction"),
  46111. # (eq, ":lord_1", ":faction_1_leader"),
  46112. (is_between, ":lord_1_faction", kingdoms_begin, kingdoms_end),
  46113.  
  46114. (call_script, "script_cf_troop_can_intrigue", ":lord_2", 0),
  46115. (neq, ":lord_2", ":faction_2_leader"),
  46116. (neq, ":lord_2", ":faction_1_leader"),
  46117.  
  46118. (str_store_troop_name, s5, ":faction_1_leader"),
  46119. (str_store_troop_name, s6, ":lord_2"),
  46120.  
  46121. (try_begin),
  46122. (ge, "$cheat_mode", 1),
  46123. (display_message, "str_check_reg8_s5_attempts_to_win_over_s6"),
  46124. (try_end),
  46125.  
  46126. (call_script, "script_calculate_troop_political_factors_for_liege", ":lord_2", ":faction_1_leader"),
  46127. (assign, ":lord_1_score", reg0),
  46128.  
  46129. (call_script, "script_calculate_troop_political_factors_for_liege", ":lord_2", ":faction_2_leader"),
  46130. (assign, ":faction_2_leader_score", reg0),
  46131.  
  46132. (try_begin),
  46133. (gt, ":lord_1_score", ":faction_2_leader_score"),
  46134.  
  46135.  
  46136. (try_begin),
  46137. (ge, "$cheat_mode", 1),
  46138. (str_store_troop_name, s4, ":lord_2"),
  46139. (display_message, "@{!}DEBUG - {s4} faction changed in subornment"),
  46140. (try_end),
  46141.  
  46142. (call_script, "script_change_troop_faction", ":lord_2", ":lord_1_faction"),
  46143. (try_end),
  46144. (try_end),
  46145.  
  46146.  
  46147.  
  46148. ]),
  46149.  
  46150.  
  46151. #this calculates the average number of rivalries per lord, giving a rough indication of how easily a faction may be divided
  46152. #fairly expensive in terms of CPU
  46153. ("evaluate_realm_stability",
  46154.  
  46155. [
  46156. (store_script_param, ":realm", 1),
  46157.  
  46158. (assign, ":total_lords", 0),
  46159. (assign, ":total_restless_lords", 0),
  46160. (assign, ":total_disgruntled_lords", 0),
  46161.  
  46162. (faction_get_slot, ":liege", ":realm", slot_faction_leader),
  46163.  
  46164. (try_for_range, ":lord", active_npcs_begin, active_npcs_end),
  46165. (troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  46166. (store_troop_faction, ":lord_faction", ":lord"),
  46167. (eq, ":lord_faction", ":realm"),
  46168. (val_add, ":total_lords", 1),
  46169.  
  46170. (call_script, "script_calculate_troop_political_factors_for_liege", ":lord", ":liege"),
  46171. (try_begin),
  46172. (le, reg3, -10),
  46173. (val_add, ":total_disgruntled_lords", 1),
  46174. (else_try),
  46175. (le, reg3, 10),
  46176. (val_add, ":total_restless_lords", 1),
  46177. (try_end),
  46178. (try_end),
  46179.  
  46180. (try_begin),
  46181. (gt, ":total_lords", 0),
  46182. (store_mul, ":instability_quotient", ":total_disgruntled_lords", 100),
  46183. (val_div, ":instability_quotient", ":total_lords"),
  46184.  
  46185. (store_mul, ":restless_quotient", ":total_restless_lords", 100),
  46186. (val_div, ":restless_quotient", ":total_lords"),
  46187.  
  46188. (store_mul, ":combined_quotient", ":instability_quotient", 2),
  46189. (val_add, ":combined_quotient", ":restless_quotient"),
  46190. (faction_set_slot, ":realm", slot_faction_instability, ":combined_quotient"),
  46191.  
  46192. (assign, reg0, ":instability_quotient"),
  46193. # (assign, reg1, ":restless_quotient"),
  46194. (assign, reg1, ":restless_quotient"),
  46195. (else_try),
  46196. (try_begin),
  46197. (eq, "$cheat_mode", 1),
  46198. (str_store_faction_name, s1, ":realm"),
  46199. (display_message, "str_s1_has_no_lords"),
  46200. (try_end),
  46201. (assign, reg0, 0),
  46202. (assign, reg1, 0),
  46203. (try_end),
  46204.  
  46205. ]),
  46206.  
  46207.  
  46208.  
  46209. #lord recruitment scripts end
  46210.  
  46211. #called from game_event_simulate_battle
  46212. #Includes a number of consequences that follow on battles, mostly affecting relations between different NPCs
  46213. #This only fires from complete victories
  46214. ("battle_political_consequences",
  46215. [
  46216. (store_script_param, ":defeated_party", 1),
  46217. (store_script_param, ":winner_party", 2),
  46218.  
  46219. (try_begin),
  46220. (eq, "$cheat_mode", 1),
  46221. (str_store_party_name, s4, ":winner_party"),
  46222. (str_store_party_name, s5, ":defeated_party"),
  46223. (display_message, "str_do_political_consequences_for_s4_victory_over_s5"),
  46224. (try_end),
  46225.  
  46226. (store_faction_of_party, ":winner_faction", ":winner_party"),
  46227. (try_begin),
  46228. (eq, ":winner_party", "p_main_party"),
  46229. (assign, ":winner_faction", "$players_kingdom"),
  46230. (try_end),
  46231.  
  46232. (party_get_template_id, ":defeated_party_template", ":defeated_party"),
  46233.  
  46234. #did the battle involve travellers?
  46235. (try_begin),
  46236. (this_or_next|eq, ":defeated_party_template", "pt_village_farmers"),
  46237. (eq, ":defeated_party_template", "pt_kingdom_caravan_party"),
  46238.  
  46239.  
  46240. (party_get_slot, ":destination", ":defeated_party", slot_party_ai_object),
  46241. (party_get_slot, ":origin", ":defeated_party", slot_party_last_traded_center),
  46242.  
  46243. (call_script, "script_add_log_entry", logent_traveller_attacked, ":winner_party", ":origin", ":destination", ":winner_faction"),
  46244.  
  46245. (try_begin),
  46246. (eq, "$cheat_mode", 2),
  46247. (neg|is_between, ":winner_faction", kingdoms_begin, kingdoms_end),
  46248. (str_store_string, s65, "str_bandits_attacked_a_party_on_the_roads_so_a_bounty_is_probably_available"),
  46249. (call_script, "script_add_notification_menu", "mnu_debug_alert_from_s65", 0, 0),
  46250.  
  46251. (str_store_party_name, s15, ":origin"),
  46252. (str_store_party_name, s16, ":destination"),
  46253. (display_message, "str_travellers_attacked_on_road_from_s15_to_s16"),
  46254. (try_end),
  46255.  
  46256.  
  46257. #by logging the faction and the party, we can verify that the party number is unlikely to have been reassigned - or at any rate, that the factions have not changed
  46258. (try_end),
  46259.  
  46260. #winner consequences:
  46261. #1) leader improves relations with other leaders
  46262. #2) Player given credit for victory if the victorious party is following the player's advice
  46263. (try_begin),
  46264. (party_get_template_id, ":winner_party_template", ":winner_party"),
  46265. (eq, ":winner_party_template", "pt_kingdom_hero_party"),
  46266. (neq, ":winner_party", "p_main_party"),
  46267. #Do not do for player party, as is included in post-battle dialogs
  46268.  
  46269. (party_stack_get_troop_id, ":winner_leader", ":winner_party", 0),
  46270. ##diplomacy start+ Support additional types
  46271. (troop_is_hero, ":winner_leader"),
  46272. (this_or_next|troop_slot_eq, ":winner_leader", slot_troop_occupation, slto_kingdom_hero),
  46273. ##diplomacy end+
  46274. (is_between, ":winner_leader", active_npcs_begin, active_npcs_end),
  46275.  
  46276. (store_faction_of_party, ":winner_faction", ":winner_party"),
  46277.  
  46278. (party_collect_attachments_to_party, ":winner_party", "p_temp_party_2"),
  46279. (party_get_num_companion_stacks, ":num_stacks", "p_temp_party_2"),
  46280. (try_for_range, ":troop_iterator", 0, ":num_stacks"),
  46281. (party_stack_get_troop_id, ":cur_troop_id", "p_temp_party_2", ":troop_iterator"),
  46282. ##diplomacy start+ support promoted kingdom ladies
  46283. (is_between, ":cur_troop_id", heroes_begin, heroes_end),
  46284. (this_or_next|troop_slot_eq, ":cur_troop_id", slot_troop_occupation, slto_kingdom_hero),
  46285. ##diplomacy end+
  46286. (is_between, ":cur_troop_id", active_npcs_begin, active_npcs_end),
  46287.  
  46288. (try_begin),
  46289. (troop_get_slot, ":winner_lord_party", ":cur_troop_id", slot_troop_leaded_party),
  46290. (party_is_active, ":winner_lord_party"),
  46291. (call_script, "script_cf_party_under_player_suggestion", ":winner_lord_party"),
  46292. (call_script, "script_add_log_entry", logent_player_suggestion_succeeded, "trp_player", -1, ":cur_troop_id", -1),
  46293. (try_end),
  46294.  
  46295.  
  46296. (store_faction_of_troop, ":troop_faction", ":cur_troop_id"),
  46297. (eq, ":troop_faction", ":winner_faction"),
  46298. (neq, ":cur_troop_id", ":winner_leader"),
  46299.  
  46300. (try_begin),
  46301. (eq, "$cheat_mode", 4),
  46302. (str_store_troop_name, s15, ":cur_troop_id"),
  46303. (str_store_troop_name, s16, ":winner_leader"),
  46304. (display_message, "str_s15_shares_joy_of_victory_with_s16"),
  46305. (try_end),
  46306.  
  46307. (call_script, "script_troop_change_relation_with_troop", ":cur_troop_id", ":winner_leader", 3),
  46308. (val_add, "$total_battle_ally_changes", 3),
  46309.  
  46310. (try_end),
  46311. (party_clear, "p_temp_party_2"),
  46312. (try_end),
  46313.  
  46314. #consequences of defeat,
  46315. #1) -1 relation with lord per lord, plus -15 if there is an incompatible marshal
  46316. #2) losers under player suggestion blame the player
  46317. #3) Some losers resent the victor lord
  46318. #4) Possible quarrels over defeat
  46319. (try_begin),
  46320. (party_collect_attachments_to_party, ":defeated_party", "p_temp_party_2"),
  46321. (party_get_num_companion_stacks, ":num_stacks", "p_temp_party_2"),
  46322.  
  46323. (try_begin),
  46324. (gt, "$marshall_defeated_in_battle", 0),
  46325. (str_store_troop_name, s15, "$marshall_defeated_in_battle"),
  46326. (store_faction_of_troop, ":defeated_marshall_faction", "$marshall_defeated_in_battle"),
  46327. (try_begin),
  46328. (eq, "$cheat_mode", 1),
  46329. (display_message, "str_faction_marshall_s15_involved_in_defeat"),
  46330. (try_end),
  46331. (else_try),
  46332. (eq, "$marshall_defeated_in_battle", "trp_player"),
  46333. (eq, ":defeated_party", "p_main_party"),
  46334. (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_active),
  46335. (try_begin),
  46336. (eq, "$cheat_mode", 1),
  46337. (display_message, "str_player_faction_marshall_involved_in_defeat"),
  46338. (try_end),
  46339. (else_try),
  46340. (assign, "$marshall_defeated_in_battle", -1),
  46341. (try_end),
  46342.  
  46343. (try_for_range, ":troop_iterator", 0, ":num_stacks"),
  46344. (party_stack_get_troop_id, ":cur_troop_id", "p_temp_party_2", ":troop_iterator"),
  46345. (troop_slot_eq, ":cur_troop_id", slot_troop_occupation, slto_kingdom_hero),
  46346.  
  46347. (try_begin), #is party under suggestion?
  46348. (troop_get_slot, ":defeated_lord_party", ":cur_troop_id", slot_troop_leaded_party),
  46349. (party_is_active, ":defeated_lord_party"),
  46350.  
  46351. #is party under suggestion?
  46352. (call_script, "script_cf_party_under_player_suggestion", ":defeated_lord_party"),
  46353. (call_script, "script_add_log_entry", logent_player_suggestion_failed, "trp_player", -1, ":cur_troop_id", -1),
  46354. (try_end),
  46355.  
  46356.  
  46357. (store_faction_of_troop, ":troop_faction", ":cur_troop_id"),
  46358.  
  46359. (faction_get_slot, ":faction_leader", ":troop_faction", slot_faction_leader),
  46360. (neq, ":cur_troop_id", ":faction_leader"),
  46361.  
  46362. #Lose one point relation with liege
  46363. (try_begin),
  46364. (eq, "$cheat_mode", 1),
  46365. (str_store_troop_name, s14, ":cur_troop_id"),
  46366. (str_store_faction_name, s15, ":troop_faction"),
  46367.  
  46368. (display_message, "str_s14_of_s15_defeated_in_battle_loses_one_point_relation_with_liege"),
  46369. (try_end),
  46370.  
  46371. (try_begin),
  46372. (this_or_next|neq, ":faction_leader", "trp_player"), #if leader is zero at beginning of game. I'm not entirely sure how this could happen...
  46373. (eq, "$players_kingdom", ":troop_faction"),
  46374.  
  46375. (call_script, "script_troop_change_relation_with_troop", ":cur_troop_id", ":faction_leader", -1),
  46376. (val_add, "$total_battle_ally_changes", -1),
  46377. (try_end),
  46378.  
  46379.  
  46380. (call_script, "script_faction_inflict_war_damage_on_faction", ":winner_faction", ":troop_faction", 10),
  46381.  
  46382.  
  46383. (try_begin),
  46384. (this_or_next|is_between, ":winner_leader", active_npcs_begin, active_npcs_end),
  46385. (eq, ":winner_leader", "trp_player"),
  46386.  
  46387. (this_or_next|neq, ":winner_leader", "trp_player"), #prevents winner leader being zero, for whatever reason
  46388. (eq, ":winner_party", "p_main_party"),
  46389.  
  46390. (this_or_next|troop_slot_eq, ":cur_troop_id", slot_lord_reputation_type, lrep_quarrelsome),
  46391. (this_or_next|troop_slot_eq, ":cur_troop_id", slot_lord_reputation_type, lrep_selfrighteous),
  46392. (troop_slot_eq, ":cur_troop_id", slot_lord_reputation_type, lrep_debauched),
  46393.  
  46394. (call_script, "script_troop_change_relation_with_troop", ":cur_troop_id", ":winner_leader", -1),
  46395. (val_add, "$total_battle_enemy_changes", -1),
  46396.  
  46397. (try_begin),
  46398. (eq, "$cheat_mode", 1),
  46399. (str_store_troop_name, s14, ":cur_troop_id"),
  46400. (str_store_troop_name, s15, ":winner_leader"),
  46401.  
  46402. (display_message, "str_s14_defeated_in_battle_by_s15_loses_one_point_relation"),
  46403. (try_end),
  46404.  
  46405.  
  46406. (try_end),
  46407.  
  46408. (gt, "$marshall_defeated_in_battle", -1),
  46409. (eq, ":troop_faction", ":defeated_marshall_faction"),
  46410. (str_store_troop_name, s14, ":cur_troop_id"),
  46411.  
  46412. (call_script, "script_cf_test_lord_incompatibility_to_s17", ":cur_troop_id", "$marshall_defeated_in_battle"),
  46413. (try_begin),
  46414. (eq, "$cheat_mode", 1),
  46415. (display_message, "str_s14_blames_s15_for_defeat"),
  46416. (try_end),
  46417.  
  46418. (call_script, "script_add_log_entry", logent_lord_blames_defeat, ":cur_troop_id", "$marshall_defeated_in_battle", ":faction_leader", ":winner_faction"),
  46419.  
  46420. (call_script, "script_troop_change_relation_with_troop", ":cur_troop_id", ":faction_leader", -15),
  46421. (val_add, "$total_battle_ally_changes", -15),
  46422.  
  46423. (neq, "$marshall_defeated_in_battle", ":faction_leader"),
  46424. (call_script, "script_troop_change_relation_with_troop", ":cur_troop_id", "$marshall_defeated_in_battle", -15),
  46425. (val_add, "$total_battle_ally_changes", -15),
  46426.  
  46427. (try_end),
  46428.  
  46429. (party_clear, "p_temp_party_2"),
  46430. (try_end),
  46431. ]),
  46432.  
  46433. #SB : possibly lower controversy of attacker npc?
  46434. ("faction_inflict_war_damage_on_faction",
  46435. [
  46436. (store_script_param, ":actor_faction", 1),
  46437. (store_script_param, ":target_faction", 2),
  46438. (store_script_param, ":amount", 3),
  46439.  
  46440.  
  46441. (store_add, ":slot_war_damage", ":target_faction", slot_faction_war_damage_inflicted_on_factions_begin),
  46442. (val_sub, ":slot_war_damage", kingdoms_begin),
  46443. ##diplomacy start+ Due to aberrant behavior, non-standard kingdoms
  46444. ##like fac_commoners can end up with parties on the map, and possibly
  46445. ##could end up inflicting or receiving war damage. Guard against this.
  46446. (try_begin),
  46447. (is_between, ":slot_war_damage", slot_faction_war_damage_inflicted_on_factions_begin, slot_faction_war_damage_inflicted_on_factions_end),
  46448. (gt, ":actor_faction", 0),
  46449. ##diplomacy end+
  46450. (faction_get_slot, ":cur_war_damage", ":actor_faction", ":slot_war_damage"),
  46451.  
  46452. (val_add, ":cur_war_damage", ":amount"),
  46453. (faction_set_slot, ":actor_faction", ":slot_war_damage", ":cur_war_damage"),
  46454. ##diplomacy start+ Close added if-statement
  46455. (else_try),
  46456. #For use in cheat-mode below
  46457. (assign, ":cur_war_damage", 0),
  46458. (try_end),
  46459. ##diplomacy end+
  46460.  
  46461.  
  46462. (try_begin),
  46463. (ge, "$cheat_mode", 1),
  46464. (str_store_faction_name, s4, ":actor_faction"),
  46465. (str_store_faction_name, s5, ":target_faction"),
  46466. (assign, reg3, ":cur_war_damage"),
  46467. (assign, reg4, ":amount"),
  46468. (display_message, "@{!}{s4} inflicts {reg4} damage on {s5}, raising total inflicted to {reg3}"),
  46469. (try_end),
  46470.  
  46471.  
  46472. (faction_get_slot, ":faction_marshal", ":target_faction", slot_faction_marshall),
  46473. (try_begin),
  46474. (ge, ":faction_marshal", 0),
  46475. (gt, ":amount", 0),
  46476.  
  46477. (troop_get_slot, ":controversy", ":faction_marshal", slot_troop_controversy),
  46478. (val_add, ":controversy", ":amount"),
  46479. (val_min, ":controversy", 100),
  46480. (troop_set_slot, ":faction_marshal", slot_troop_controversy, ":controversy"),
  46481.  
  46482. (try_begin),
  46483. (ge, "$cheat_mode", 1),
  46484. (str_store_troop_name, s4, ":faction_marshal"),
  46485. (assign, reg4, ":amount"),
  46486. (assign, reg5, ":controversy"),
  46487. (display_message, "@{!}War damage raises {s4}'s controversy by {reg4} to {reg5}"),
  46488. (try_end),
  46489. (try_end),
  46490.  
  46491. (faction_get_slot, ":faction_marshal", ":actor_faction", slot_faction_marshall),
  46492. (try_begin),
  46493. (ge, ":faction_marshal", 0),
  46494. (val_div, ":amount", 3),
  46495. (gt, ":amount", 0),
  46496.  
  46497.  
  46498. (troop_get_slot, ":controversy", ":faction_marshal", slot_troop_controversy),
  46499. (val_sub, ":controversy", ":amount"),
  46500. (val_max, ":controversy", 0),
  46501. (troop_set_slot, ":faction_marshal", slot_troop_controversy, ":controversy"),
  46502.  
  46503. (try_begin),
  46504. (ge, "$cheat_mode", 1),
  46505. (str_store_troop_name, s4, ":faction_marshal"),
  46506. (assign, reg4, ":amount"),
  46507. (assign, reg5, ":controversy"),
  46508. (display_message, "@{!}War damage lowers {s4}'s controversy by {reg4} to {reg5}"),
  46509. (try_end),
  46510. (try_end),
  46511.  
  46512.  
  46513.  
  46514. ]),
  46515.  
  46516. ("calculate_troop_political_factors_for_liege",
  46517. [
  46518. (store_script_param, ":troop", 1),
  46519. (store_script_param, ":liege", 2),
  46520.  
  46521. (troop_get_slot, ":lord_reputation", ":troop", slot_lord_reputation_type),
  46522.  
  46523. ##diplomacy start+ Work correctly in certain situations where this can be called w/o a liege.
  46524. ##OLD:
  46525. #(store_faction_of_troop, ":faction", ":liege"),
  46526. ##NEW:
  46527. (try_begin),
  46528. (eq, ":liege", "trp_player"),
  46529. (assign, ":faction", "fac_player_supporters_faction"),
  46530. (try_begin),
  46531. #Handle "player is co-ruler of NPC faction"
  46532. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  46533. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  46534. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  46535. (assign, ":faction", "$players_kingdom"),
  46536. (faction_get_slot, reg0, ":faction", slot_faction_leader),
  46537. (gt, reg0, 0),
  46538. (assign, ":liege", reg0),
  46539. (try_end),
  46540. (else_try),
  46541. #Ordinary case
  46542. (ge, ":liege", 0),
  46543. (store_faction_of_troop, ":faction", ":liege"),
  46544. (else_try),
  46545. (store_faction_of_troop, reg0, ":troop"),
  46546. (faction_slot_eq, reg0, slot_faction_leader, ":liege"),
  46547. (assign, ":faction", reg0),
  46548. (else_try),
  46549. (assign, ":faction", kingdoms_end),
  46550. (try_for_range, reg0, kingdoms_begin, ":faction"),
  46551. (faction_slot_eq, reg0, slot_faction_leader, ":liege"),
  46552. (assign, ":faction", reg0),
  46553. (try_end),
  46554. (neg|is_between, ":faction", kingdoms_begin, kingdoms_end),
  46555. (assign, ":faction", "fac_no_faction"),
  46556. (try_end),
  46557. ##diplomacy end+
  46558.  
  46559.  
  46560. (try_begin),
  46561. (eq, ":faction", "fac_player_faction"),
  46562. (assign, ":faction", "fac_player_supporters_faction"),
  46563. (try_end),
  46564.  
  46565. (assign, ":liege_is_undeclared_rebel", 0),
  46566. (try_begin),
  46567. (neg|faction_slot_eq, ":faction", slot_faction_leader, ":liege"),
  46568. #the liege is a rebel
  46569. (assign, ":liege_is_undeclared_rebel", 1),
  46570. (try_begin),
  46571. (eq, "$cheat_mode", 1),
  46572. ##diplomacy start+ Guard against bad liege
  46573. (ge, ":liege", 0),
  46574. ##diplomacy end+
  46575. (str_store_troop_name, s32, ":liege"),
  46576. (display_message, "str_s32_is_undeclared_rebel"),
  46577. (try_end),
  46578. (try_end),
  46579.  
  46580. (assign, ":result_for_material", 0),
  46581. (assign, ":penalty_for_changing_sides", 0),
  46582.  
  46583.  
  46584.  
  46585. #FACTOR 1 - MILITARY SECURITY
  46586. (assign, ":result_for_security", 0),
  46587.  
  46588. #find the lord's home
  46589. (assign, ":base_center", -1),
  46590. (try_begin),
  46591. ##diplomacy start+ add support for promoted kingdom ladies
  46592. (is_between, ":troop", heroes_begin, heroes_end),
  46593. (this_or_next|troop_slot_eq, ":troop", slot_troop_occupation, slto_kingdom_hero),
  46594. ##diplomacy end+
  46595. (is_between, ":troop", active_npcs_begin, active_npcs_end),
  46596. (try_for_range, ":center", centers_begin, centers_end),
  46597. (eq, ":base_center", -1),
  46598. (party_slot_eq, ":center", slot_town_lord, ":troop"),
  46599. (assign, ":base_center", ":center"),
  46600. (try_end),
  46601. (try_end),
  46602.  
  46603. (assign, ":faction_has_base", 0),
  46604.  
  46605. #add up all other centers for the security value
  46606. (try_for_range, ":center", centers_begin, centers_end),
  46607. (neq, ":center", ":base_center"),
  46608. (gt, ":base_center", 0),
  46609.  
  46610. (try_begin),
  46611. (is_between, ":center", towns_begin, towns_end),
  46612. (assign, ":weight", 9000),
  46613. (else_try),
  46614. (is_between, ":center", castles_begin, castles_end),
  46615. (assign, ":weight", 6000),
  46616. (else_try),
  46617. (assign, ":weight", 1000),
  46618. (try_end),
  46619.  
  46620. (store_distance_to_party_from_party, ":distance", ":base_center", ":center"),
  46621. (val_add, ":distance", 10),
  46622. (val_div, ":weight", ":distance"),
  46623. (val_div, ":weight", ":distance"),
  46624.  
  46625. (store_faction_of_party, ":center_faction", ":center"),
  46626.  
  46627. (try_begin),
  46628. (eq, ":center_faction", ":faction"),
  46629.  
  46630. (assign, ":faction_has_base", 1),
  46631. (val_add, ":result_for_security", ":weight"),
  46632. (else_try),
  46633. (neq, ":center_faction", ":faction"),
  46634. (store_relation, ":center_relation", ":center_faction", ":faction"),
  46635.  
  46636. (try_begin), #potentially hostile center
  46637. (this_or_next|eq, ":liege_is_undeclared_rebel", 1),
  46638. (lt, ":center_relation", 0),
  46639. (val_div, ":weight", 2),
  46640. (else_try), #neutral center
  46641. (val_div, ":weight", 4),
  46642. (try_end),
  46643.  
  46644. (val_sub, ":result_for_security", ":weight"),
  46645. (try_end),
  46646. (try_end),
  46647.  
  46648.  
  46649. #if a faction controls no other centers, then there is a small bonus
  46650. (try_begin),
  46651. (eq, ":faction_has_base", 0),
  46652. (val_add, ":result_for_security", 20),
  46653. (try_begin),
  46654. (eq, "$cheat_mode", 2),
  46655. (display_message, "str_small_bonus_for_no_base"),
  46656. (try_end),
  46657. (try_end),
  46658. (val_clamp, ":result_for_security", -100, 100),
  46659.  
  46660.  
  46661. (assign, ":result_for_security_weighted", ":result_for_security"),
  46662. ##diplomacy start+
  46663. #ADDED TO THIS, SEE BELOW
  46664. #(try_begin),
  46665. # (eq, ":lord_reputation", lrep_cunning),
  46666. # (val_mul, ":result_for_security_weighted", 2),
  46667. #(else_try),
  46668. # (eq, ":lord_reputation", lrep_martial),
  46669. # (val_div, ":result_for_security_weighted", 2),
  46670. #(try_end),
  46671. #
  46672. ##Use companion morality type "tmt_aristocratic" as a synonym/antonym for bold
  46673. (call_script, "script_dplmc_get_troop_morality_value", ":troop", tmt_aristocratic),
  46674. (assign, ":lord_tmt_aristocratic", reg0),
  46675. (try_begin),
  46676. (lt, ":lord_tmt_aristocratic", 1),
  46677. (this_or_next|lt, ":lord_tmt_aristocratic", 0),
  46678. (eq, ":lord_reputation", lrep_cunning),
  46679. (val_mul, ":result_for_security_weighted", 2),
  46680. (else_try),
  46681. (ge, ":lord_tmt_aristocratic", 0),
  46682. (this_or_next|ge, ":lord_tmt_aristocratic", 1),
  46683. (eq, ":lord_reputation", lrep_martial),
  46684. (val_div, ":result_for_security_weighted", 2),
  46685. (try_end),
  46686. ##diplomacy end+
  46687.  
  46688. #FACTOR 2 - INTERNAL FACTION POLITICS
  46689. #this is a calculation of how much influence the lord believes he will have in each faction
  46690. (assign, ":result_for_political", 0),
  46691.  
  46692. (try_for_range, ":loop_var", "trp_kingdom_heroes_including_player_begin", active_npcs_end),
  46693. (assign, ":kingdom_hero", ":loop_var"),
  46694. ##diplomacy start+ Skip what follows when there is no liege
  46695. (ge, ":liege", 0),
  46696. ##diplomacy end+
  46697.  
  46698. (this_or_next|troop_slot_eq, ":kingdom_hero", slot_troop_occupation, slto_kingdom_hero),
  46699. (this_or_next|eq, ":kingdom_hero", "trp_kingdom_heroes_including_player_begin"),
  46700. (is_between, ":kingdom_hero", pretenders_begin, pretenders_end),
  46701.  
  46702. (store_faction_of_troop, ":kingdom_hero_faction", ":kingdom_hero"),
  46703.  
  46704. (try_begin),
  46705. (eq, ":loop_var", "trp_kingdom_heroes_including_player_begin"),
  46706. (assign, ":kingdom_hero", "trp_player"),
  46707. (assign, ":kingdom_hero_faction", "$players_kingdom"),
  46708. (try_begin), #do not count player relation if the player is trying to suborn the character. this has the slight potential for a miscalculation, if the script is called from outside dialogs and $g_talk_troop has not been reset
  46709. (eq, "$g_talk_troop", ":troop"),
  46710. (store_faction_of_troop, ":cur_faction", ":troop"),
  46711. (eq, ":cur_faction", ":faction"),
  46712. (assign, ":kingdom_hero_faction", 0),
  46713. (try_end),
  46714. (try_end),
  46715.  
  46716. (eq, ":kingdom_hero_faction", ":faction"),
  46717. (neg|faction_slot_eq, ":kingdom_hero_faction", slot_faction_leader, ":kingdom_hero"),
  46718. (neq, ":liege_is_undeclared_rebel", 1),
  46719. (neg|is_between, ":kingdom_hero", pretenders_begin, pretenders_end),
  46720.  
  46721.  
  46722. (call_script, "script_troop_get_relation_with_troop", ":troop", ":kingdom_hero"),
  46723. (assign, ":troop_rel_w_hero", reg0),
  46724.  
  46725. (call_script, "script_troop_get_relation_with_troop", ":kingdom_hero", ":liege"),
  46726. (assign, ":hero_rel_w_liege", reg0),
  46727.  
  46728. (store_mul, ":lord_political_weight", ":troop_rel_w_hero", ":hero_rel_w_liege"),
  46729. (val_div, ":lord_political_weight", 100),
  46730.  
  46731. (try_begin),
  46732. (eq, "$cheat_mode", 2), #disabled
  46733. (eq, "$g_talk_troop", ":troop"),
  46734. (str_store_faction_name, s20, ":kingdom_hero_faction"),
  46735. (str_store_troop_name, s15, ":kingdom_hero"),
  46736. (assign, reg15, ":lord_political_weight"),
  46737. (display_message, "str_s15_considered_member_of_faction_s20_weight_of_reg15"),
  46738. (try_end),
  46739.  
  46740. (val_add, ":result_for_political", ":lord_political_weight"),
  46741. (try_end),
  46742.  
  46743. (val_clamp, ":result_for_political", -100, 101), #lords portion represents half
  46744.  
  46745. (try_begin),
  46746. ##diplomacy start+ When there isn't a liege, use 0
  46747. (assign, ":liege_relation", 0),
  46748. (ge, ":liege", 0),
  46749. ##diplomacy end+
  46750. (call_script, "script_troop_get_relation_with_troop", ":troop", ":liege"),
  46751. (assign, ":liege_relation", reg0),
  46752. (val_add, ":result_for_political", ":liege_relation"),
  46753. (try_end),
  46754.  
  46755. (val_div, ":result_for_political", 2),
  46756.  
  46757. (val_clamp, ":result_for_political", -100, 101), #liege portion represents half
  46758.  
  46759. (assign, ":result_for_political_weighted", ":result_for_political"),
  46760.  
  46761. (try_begin),
  46762. (this_or_next|eq, ":lord_reputation", lrep_goodnatured),
  46763. (eq, ":lord_reputation", lrep_quarrelsome),
  46764. (val_mul, ":result_for_political_weighted", 2),
  46765. (try_end),
  46766.  
  46767. #FACTOR 3 - PROMISES AND OTHER ANTICIPATED GAINS
  46768. #lord's calculation of anticipated gains
  46769. (assign, ":result_for_material", 0),
  46770. (assign, ":result_for_material_weighted", ":result_for_material"),
  46771.  
  46772.  
  46773. #FACTOR 4 - IDEOLOGY
  46774. #lord's calculation of ideological comfort
  46775. (try_begin),
  46776. #Originally, the argument section was not used for a non-player liege. Actually, it can be used
  46777. (eq, 1, 0),
  46778. (neq, ":liege", "trp_player"),
  46779. (neq, ":liege", "$supported_pretender"), #player is advocate for pretender
  46780. (assign, ":argument_strength", 0),
  46781. (assign, ":argument_appeal", 0),
  46782. (assign, ":result_for_argument", 0),
  46783. (else_try), #only if the recruitment candidate is either the player, or a supported pretender
  46784. (troop_get_slot, ":recruitment_argument", ":troop", slot_lord_recruitment_argument),
  46785.  
  46786. (call_script, "script_rebellion_arguments", ":troop", ":recruitment_argument", ":liege"),
  46787. (assign, ":argument_appeal", reg0),
  46788. (assign, ":argument_strength", reg1),
  46789.  
  46790. (store_add, ":result_for_argument", ":argument_appeal", ":argument_strength"),
  46791.  
  46792. (store_skill_level, ":player_persuasion_skill", "skl_persuasion", "trp_player"),
  46793. (try_begin),
  46794. (gt, ":result_for_argument", 0),
  46795. #make sure player is the one making the overture
  46796.  
  46797. #if player has 0 persuasion, ":result_for_argument" will be multiplied by 3/10.
  46798. (store_add, ":player_persuasion_skill_plus_5_mul_066", ":player_persuasion_skill", 5),
  46799. (val_mul, ":player_persuasion_skill_plus_5_mul_066", 2),
  46800. (val_div, ":player_persuasion_skill_plus_5_mul_066", 3),
  46801.  
  46802. (val_mul, ":result_for_argument", ":player_persuasion_skill_plus_5_mul_066"),
  46803. (val_div, ":result_for_argument", 10),
  46804. (else_try),
  46805. (lt, ":result_for_argument", 0),
  46806. (store_sub, ":ten_minus_player_persuasion_skill", 10, ":player_persuasion_skill"),
  46807. (val_mul, ":result_for_argument", ":ten_minus_player_persuasion_skill"),
  46808. (val_div, ":result_for_argument", 10),
  46809. (try_end),
  46810.  
  46811. (try_begin),
  46812. (neq, ":liege", "trp_player"),
  46813. (neq, ":liege", "$supported_pretender"), #player is advocate for pretender
  46814. (val_div, ":argument_strength", 2),
  46815. (val_div, ":argument_appeal", 2),
  46816. (val_div, ":result_for_argument", 2),
  46817. (try_end),
  46818.  
  46819. (try_end),
  46820.  
  46821. # (try_begin),
  46822. # (eq, ":lord_reputation", lrep_cunning),
  46823. # (val_div, ":result_for_ideological_weighted", 2),
  46824. # (else_try),
  46825. # (eq, ":lord_reputation", lrep_upstanding),
  46826. # (val_mul, ":result_for_ideological_weighted", 2),
  46827. # (try_end),
  46828.  
  46829.  
  46830. #FACTOR 5 - PENALTY FOR CHANGING SIDES
  46831. (try_begin), #no penalty for the incumbent
  46832. (store_faction_of_troop, ":cur_faction", ":troop"),
  46833. (eq, ":cur_faction", ":faction"),
  46834. (assign, ":penalty_for_changing_sides", 0),
  46835. (else_try), #penalty for the player
  46836. (eq, ":liege", "trp_player"),
  46837. (store_sub, ":penalty_for_changing_sides", 60, "$player_right_to_rule"),
  46838. (else_try), #same culture, such as a pretender
  46839. ##diplomacy start+ skip when there is no liege
  46840. (ge, ":liege", 0),
  46841. ##diplomacy end+
  46842. (troop_get_slot, ":orig_faction_of_lord", ":troop", slot_troop_original_faction),
  46843. (troop_get_slot, ":orig_faction_of_liege", ":liege", slot_troop_original_faction),
  46844. (eq, ":orig_faction_of_lord", ":orig_faction_of_liege"),
  46845. (assign, ":penalty_for_changing_sides", 10),
  46846. ##diplomacy start+
  46847. #"same culture, such as a pretender" pt. 2
  46848. (else_try),
  46849. (troop_slot_eq, ":troop", slot_troop_original_faction, ":faction"),
  46850. (assign, ":penalty_for_changing_sides", 10),
  46851. ##diplomacy end+
  46852. (else_try), #a liege from a different culture
  46853. (assign, ":penalty_for_changing_sides", 50),
  46854. (try_end),
  46855. (val_clamp, ":penalty_for_changing_sides", 0, 101),
  46856.  
  46857. (assign, ":penalty_for_changing_sides_weighted", ":penalty_for_changing_sides"),
  46858. ##diplomacy start+
  46859. #(try_begin),
  46860. # (eq, ":lord_reputation", lrep_debauched),
  46861. # (val_div, ":penalty_for_changing_sides_weighted", 2),
  46862. #(else_try),
  46863. # (eq, ":lord_reputation", lrep_upstanding),
  46864. # (val_mul, ":penalty_for_changing_sides_weighted", 2),
  46865. #(try_end),
  46866. #
  46867. ##Use companion morality type "tmt_honest" as a synonym/antonym for deal-keeping
  46868. (call_script, "script_dplmc_get_troop_morality_value", ":troop", tmt_honest),
  46869. (assign, ":lord_tmt_honest", reg0),
  46870. (try_begin),
  46871. (this_or_next|lt, ":lord_tmt_honest", 0),
  46872. (eq, ":lord_reputation", lrep_debauched),
  46873. (val_div, ":penalty_for_changing_sides_weighted", 2),
  46874. (else_try),
  46875. (this_or_next|ge, ":lord_tmt_honest", 1),
  46876. (eq, ":lord_reputation", lrep_upstanding),
  46877. (val_mul, ":penalty_for_changing_sides_weighted", 2),
  46878. (try_end),
  46879. ##diplomacy end+
  46880.  
  46881.  
  46882.  
  46883. (assign, reg1, ":result_for_security"),
  46884. (assign, reg2, ":result_for_security_weighted"),
  46885. (assign, reg3, ":result_for_political"),
  46886. (assign, reg4, ":result_for_political_weighted"),
  46887. (assign, reg5, ":result_for_material"),
  46888. (assign, reg6, ":result_for_material_weighted"),
  46889. (assign, reg7, ":argument_strength"),
  46890. (assign, reg17, ":argument_appeal"),
  46891.  
  46892. (assign, reg8, ":result_for_argument"),
  46893. (assign, reg9, ":penalty_for_changing_sides"),
  46894. (assign, reg10, ":penalty_for_changing_sides_weighted"),
  46895.  
  46896.  
  46897. (try_begin),
  46898. (eq, "$cheat_mode", 1),
  46899. (eq, "$g_talk_troop", ":troop"),
  46900. (str_store_troop_name, s20, ":troop"),
  46901. (str_store_faction_name, s21, ":faction"),
  46902. ##diplomacy start+
  46903. ##OLD:
  46904. #(str_store_troop_name, s22, ":liege"),
  46905. ##NEW:
  46906. (try_begin),
  46907. (gt, ":liege", -1),
  46908. (str_store_troop_name, s22, ":liege"),
  46909. (else_try),
  46910. (str_store_string, s22, "str_noone"),
  46911. (try_end),
  46912. ##diplomacy end+
  46913.  
  46914. (display_message, "@{!}G_talk_troop {s20} evaluates being vassal to {s22} of {s21}"),
  46915.  
  46916. (display_message, "str_base_result_for_security_reg1"),
  46917. (display_message, "str_result_for_security_weighted_by_personality_reg2"),
  46918. (display_message, "str_base_result_for_political_connections_reg3"),
  46919. (display_message, "str_result_for_political_connections_weighted_by_personality_reg4"),
  46920. # (display_message, "@{!}Result for anticipated_gains: {reg5}"),
  46921. # (display_message, "@{!}Result for anticipated_gains weighted by personality: {reg6}"),
  46922.  
  46923. (try_begin),
  46924. (this_or_next|eq, ":liege", "trp_player"),
  46925. (eq, ":liege", "$supported_pretender"), #player is advocate for pretender
  46926. (display_message, "str_result_for_argument_strength_reg7"),
  46927. (display_message, "str_result_for_argument_appeal_reg17"),
  46928. (display_message, "str_combined_result_for_argument_modified_by_persuasion_reg8"),
  46929. (try_end),
  46930. (display_message, "str_base_changing_sides_penalty_reg9"),
  46931. (display_message, "str_changing_sides_penalty_weighted_by_personality_reg10"),
  46932. (try_end),
  46933.  
  46934. (store_add, ":total", ":result_for_security_weighted", ":result_for_political_weighted"),
  46935. (val_add, ":total", ":result_for_material_weighted"),
  46936. (val_add, ":total", ":result_for_argument"),
  46937. (val_sub, ":total", ":penalty_for_changing_sides_weighted"),
  46938.  
  46939.  
  46940. (assign, reg0, ":total"),
  46941.  
  46942. (try_begin),
  46943. (eq, "$cheat_mode", 2),
  46944. (display_message, "@{!}DEBUG -- Analyzing lord allegiances, combined bonuses and penalties = {reg0}"),
  46945. #(display_message, "str_combined_bonuses_and_penalties_=_reg0"),
  46946. (try_end),
  46947. ]),
  46948.  
  46949.  
  46950.  
  46951. ("cf_troop_can_intrigue",
  46952. #This script should be called from dialogs, and also prior to any event which might result in a lord changing sides
  46953. [
  46954. (store_script_param, ":troop", 1),
  46955. (store_script_param, ":skip_player_party", 2),
  46956.  
  46957. ##diplomacy start+
  46958. #Use this to filter out lords who are supposed to be "off the board"
  46959. (assign, ":bad_occupation", 0),
  46960. (try_begin),
  46961. (gt, ":troop", 0),
  46962. (troop_is_hero, ":troop"),
  46963. (troop_slot_eq, ":troop", slot_lord_reputation_type, dplmc_slto_dead),
  46964. (assign, ":bad_occupation", 1),#altered 2011-06-08
  46965. (try_end),
  46966. (eq, ":bad_occupation", 0),
  46967. ##diplomacy end+
  46968.  
  46969. (troop_get_slot, ":led_party_1", ":troop", slot_troop_leaded_party),
  46970. (party_is_active, ":led_party_1"),
  46971.  
  46972. (try_begin),
  46973. (eq, "$cheat_mode", 1),
  46974. (eq, ":troop", "$g_talk_troop"),
  46975. (display_message, "str_intrigue_test_troop_party_is_active"),
  46976. (try_end),
  46977.  
  46978. (party_get_battle_opponent, ":battle_opponent", ":led_party_1"),
  46979. (le, ":battle_opponent", 0), #battle opponent can be 0 for an attached party?
  46980.  
  46981. (try_begin),
  46982. (eq, "$cheat_mode", 1),
  46983. (eq, ":troop", "$g_talk_troop"),
  46984. (display_message, "str_intrigue_test_troop_party_is_not_in_battle"),
  46985. (try_end),
  46986.  
  46987. (troop_slot_eq, ":troop", slot_troop_prisoner_of_party, -1),
  46988.  
  46989. (try_begin),
  46990. (eq, "$cheat_mode", 1),
  46991. (eq, ":troop", "$g_talk_troop"),
  46992. (display_message, "str_intrigue_test_troop_is_not_prisoner"),
  46993. (try_end),
  46994.  
  46995. (party_get_attached_to, ":led_party_1_attached", ":led_party_1"),
  46996.  
  46997. (store_faction_of_party, ":led_party_1_faction", ":led_party_1"),
  46998.  
  46999. (assign, ":other_lords_nearby", 0),
  47000. (try_for_range, ":troop_2", active_npcs_begin, active_npcs_end),
  47001. (neq, ":troop", ":troop_2"),
  47002. (eq, ":other_lords_nearby", 0),
  47003.  
  47004. (troop_slot_eq, ":troop_2", slot_troop_occupation, slto_kingdom_hero),
  47005.  
  47006. (troop_get_slot, ":led_party_2", ":troop_2", slot_troop_leaded_party),
  47007. (party_is_active, ":led_party_2"),
  47008. (neq, ":led_party_1", ":led_party_2"),
  47009.  
  47010. (store_faction_of_party, ":led_party_2_faction", ":led_party_2"),
  47011. (eq, ":led_party_1_faction", ":led_party_2_faction"),
  47012.  
  47013. (try_begin),
  47014. (eq, ":led_party_1_attached", -1),
  47015. (store_distance_to_party_from_party, ":distance", ":led_party_1", ":led_party_2"),
  47016. (lt, ":distance", 3),
  47017. (assign, ":other_lords_nearby", 1),
  47018. (else_try),
  47019. (is_between, ":led_party_1_attached", walled_centers_begin, walled_centers_end),
  47020. (party_get_attached_to, ":led_party_2_attached", ":led_party_2"),
  47021. (eq, ":led_party_1_attached", ":led_party_2_attached"),
  47022. (assign, ":other_lords_nearby", 1),
  47023. (try_end),
  47024. (try_end),
  47025.  
  47026. (try_begin),
  47027. (eq, "$cheat_mode", 1),
  47028. (eq, ":troop", "$g_talk_troop"),
  47029. (display_message, "str_intrigue_test_troop_is_nearby"),
  47030. (try_end),
  47031.  
  47032. (try_begin),
  47033. (eq, ":skip_player_party", 0),
  47034. #temporary spot
  47035. (try_end),
  47036.  
  47037. (eq, ":other_lords_nearby", 0),
  47038. ]),
  47039.  
  47040.  
  47041. ("troop_change_relation_with_troop",
  47042. [
  47043. (store_script_param, ":troop1", 1),
  47044. (store_script_param, ":troop2", 2),
  47045. (store_script_param, ":amount", 3),
  47046.  
  47047. (try_begin),
  47048. (eq, ":troop1", "trp_player"),
  47049. (call_script, "script_change_player_relation_with_troop", ":troop2", ":amount"),
  47050. (else_try),
  47051. (eq, ":troop2", "trp_player"),
  47052. (call_script, "script_change_player_relation_with_troop", ":troop1", ":amount"),
  47053. (else_try),
  47054. ##diplomacy start+ Cancel the result for bad troop values
  47055. (this_or_next|lt, ":troop1", 0),
  47056. (this_or_next|lt, ":troop2", 0),
  47057. ##diplomacy end+
  47058. (eq, ":troop1", ":troop2"),
  47059. ##diplomacy start+ Do this to avoid the controversy check further below
  47060. (assign, ":amount", 0),
  47061. ##diplomacy end+
  47062. (else_try),
  47063. (call_script, "script_troop_get_relation_with_troop", ":troop1", ":troop2"),
  47064. (store_add, ":new_relation", reg0, ":amount"),
  47065.  
  47066. (val_clamp, ":new_relation", -100, 101),
  47067.  
  47068. (try_begin),
  47069. (eq, ":new_relation", 0),
  47070. (assign, ":new_relation", 1), #this removes the need for a separate "met" slot - any non-zero relation will be a met
  47071. (try_end),
  47072.  
  47073. (store_add, ":troop1_slot_for_troop2", ":troop2", slot_troop_relations_begin),
  47074. (troop_set_slot, ":troop1", ":troop1_slot_for_troop2", ":new_relation"),
  47075.  
  47076. (store_add, ":troop2_slot_for_troop1", ":troop1", slot_troop_relations_begin),
  47077. (troop_set_slot, ":troop2", ":troop2_slot_for_troop1", ":new_relation"),
  47078. (try_end),
  47079.  
  47080.  
  47081. (try_begin), #generate controversy if troops are in the same faciton
  47082. (lt, ":amount", -5),
  47083. (try_begin),
  47084. (eq, ":troop1", "trp_player"),
  47085. (assign, ":faction1", "$players_kingdom"),
  47086. (else_try),
  47087. (store_faction_of_troop, ":faction1", ":troop1"),
  47088. (try_end),
  47089. (try_begin),
  47090. (eq, ":troop2", "trp_player"),
  47091. (assign, ":faction2", "$players_kingdom"),
  47092. (else_try),
  47093. (store_faction_of_troop, ":faction2", ":troop2"),
  47094. (try_end),
  47095. (eq, ":faction1", ":faction2"),
  47096. (is_between, ":faction1", kingdoms_begin, kingdoms_end),
  47097.  
  47098. (store_mul, ":controversy_generated", ":amount", -1),
  47099.  
  47100. (troop_get_slot, ":controversy1", ":troop1", slot_troop_controversy),
  47101. (val_add, ":controversy1", ":controversy_generated"),
  47102. (val_min, ":controversy1", 100),
  47103. (troop_set_slot, ":troop1", slot_troop_controversy, ":controversy1"),
  47104.  
  47105. (troop_get_slot, ":controversy2", ":troop2", slot_troop_controversy),
  47106. (val_add, ":controversy2", ":controversy_generated"),
  47107. (val_min, ":controversy2", 100),
  47108. (troop_set_slot, ":troop2", slot_troop_controversy, ":controversy2"),
  47109.  
  47110. (try_end),
  47111.  
  47112. (try_begin),
  47113. ##diplomacy start+ Also enable messages for promoted kingdom ladies
  47114. #OLD:
  47115. #(is_between, ":troop1", active_npcs_begin, active_npcs_end),
  47116. #(is_between, ":troop2", active_npcs_begin, active_npcs_end),
  47117. #
  47118. #NEW:
  47119. (is_between, ":troop1", heroes_begin, heroes_end),
  47120. (this_or_next|troop_slot_eq, ":troop1", slot_troop_occupation, slto_kingdom_hero),
  47121. (is_between, ":troop1", active_npcs_begin, active_npcs_end),
  47122.  
  47123. (is_between, ":troop2", heroes_begin, heroes_end),
  47124. (this_or_next|troop_slot_eq, ":troop2", slot_troop_occupation, slto_kingdom_hero),
  47125. (is_between, ":troop2", active_npcs_begin, active_npcs_end),
  47126. ##diplomacy end+
  47127. (neq, ":troop1", ":troop2"),
  47128.  
  47129. (try_begin),
  47130. (gt, ":amount", 0),
  47131. (val_add, "$total_relation_adds", ":amount"),
  47132. (else_try),
  47133. (val_sub, "$total_relation_subs", ":amount"),
  47134. (try_end),
  47135. (try_end),
  47136.  
  47137. (try_begin),
  47138. (eq, "$cheat_mode", 4), #change back to 4
  47139. ##diplomacy start+ Also enable messages for promoted kingdom ladies
  47140. #OLD:
  47141. # (is_between, ":troop1", active_npcs_begin, active_npcs_end),
  47142. # (is_between, ":troop2", active_npcs_begin, active_npcs_end),
  47143. #
  47144. #NEW:
  47145. (is_between, ":troop1", heroes_begin, heroes_end),
  47146. (this_or_next|troop_slot_eq, ":troop1", slot_troop_occupation, slto_kingdom_hero),
  47147. (is_between, ":troop1", active_npcs_begin, active_npcs_end),
  47148.  
  47149. (is_between, ":troop2", heroes_begin, heroes_end),
  47150. (this_or_next|troop_slot_eq, ":troop2", slot_troop_occupation, slto_kingdom_hero),
  47151. (is_between, ":troop2", active_npcs_begin, active_npcs_end),
  47152. ##diplomacy end+
  47153. (neq, ":troop1", ":troop2"),
  47154.  
  47155. (str_store_troop_name, s20, ":troop1"),
  47156. (str_store_troop_name, s15, ":troop2"),
  47157. (assign, reg4, ":amount"),
  47158. (assign, reg14, ":new_relation"),
  47159. (display_message, "str_s20_relation_with_s15_changed_by_reg4_to_reg14"),
  47160.  
  47161. (assign, reg4, "$total_relation_adds"),
  47162. (display_message, "str_total_additions_reg4"),
  47163. (assign, reg4, "$total_relation_subs"),
  47164. (display_message, "str_total_subtractions_reg4"),
  47165.  
  47166. (assign, reg4, "$total_courtship_quarrel_changes"),
  47167. (display_message, "@{!}DEBUG -- Total courtship quarrel changes: {reg4}"),
  47168.  
  47169. (assign, reg4, "$total_random_quarrel_changes"),
  47170. (display_message, "@{!}DEBUG -- Total random quarrel changes: {reg4}"),
  47171.  
  47172. (assign, reg4, "$total_battle_ally_changes"),
  47173. (display_message, "@{!}DEBUG -- Total battle changes for allies: {reg4}"),
  47174.  
  47175. (assign, reg4, "$total_battle_enemy_changes"),
  47176. (display_message, "@{!}DEBUG -- Total battle changes for enemies: {reg4}"),
  47177.  
  47178. (assign, reg4, "$total_promotion_changes"),
  47179. (display_message, "@{!}DEBUG -- Total promotion changes: {reg4}"),
  47180.  
  47181. (assign, reg4, "$total_feast_changes"),
  47182. (display_message, "@{!}DEBUG -- Total feast changes: {reg4}"),
  47183.  
  47184. (assign, reg4, "$total_policy_dispute_changes"),
  47185. (assign, reg5, "$number_of_controversial_policy_decisions"),
  47186. (display_message, "@{!}DEBUG -- Total policy dispute changes: {reg4} from {reg5} decisions"),
  47187.  
  47188. (assign, reg4, "$total_indictment_changes"),
  47189. (display_message, "@{!}DEBUG -- Total faction switch changes: {reg4}"),
  47190.  
  47191. (assign, reg4, "$total_no_fief_changes"),
  47192. (display_message, "@{!}DEBUG -- Total no fief changes: {reg4}"),
  47193.  
  47194. (assign, reg4, "$total_relation_changes_through_convergence"),
  47195. (display_message, "@{!}DEBUG -- Total changes through convergence: {reg4}"),
  47196.  
  47197. (assign, reg4, "$total_vassal_days_responding_to_campaign"),
  47198. (display_message, "@{!}DEBUG -- Total vassal responses to campaign: {reg4}"),
  47199.  
  47200. (assign, reg4, "$total_vassal_days_on_campaign"),
  47201. (display_message, "@{!}DEBUG -- Total vassal campaign days: {reg4}"),
  47202.  
  47203. (val_max, "$total_vassal_days_on_campaign", 1),
  47204. (store_mul, ":response_rate", "$total_vassal_days_responding_to_campaign", 100),
  47205. (val_div, ":response_rate", "$total_vassal_days_on_campaign"),
  47206. (assign, reg4, ":response_rate"),
  47207. (display_message, "@{!}DEBUG -- Vassal response rate: {reg4}"),
  47208.  
  47209.  
  47210.  
  47211. # (assign, reg4, "$total_joy_battle_changes"),
  47212. # (display_message, "@{!}DEBUG -- Total joy of battle changes"),
  47213.  
  47214. (try_end),
  47215.  
  47216. ]),
  47217.  
  47218.  
  47219. ("troop_get_relation_with_troop",
  47220. [
  47221. (store_script_param, ":troop1", 1),
  47222. (store_script_param, ":troop2", 2),
  47223.  
  47224. (assign, ":relation", 0),
  47225. (try_begin),
  47226. ##diplomacy start+
  47227. #Change "eq -1", to "lt 0"
  47228. (this_or_next|lt, ":troop1", 0),
  47229. (lt, ":troop2", 0),
  47230. ##diplomacy end+
  47231.  
  47232. #Possibly switch to relation with liege
  47233. (assign, ":relation", 0),
  47234. (else_try),
  47235. (eq, ":troop1", "trp_player"),
  47236. (call_script, "script_troop_get_player_relation", ":troop2"),
  47237. (assign, ":relation", reg0),
  47238. (else_try),
  47239. (eq, ":troop2", "trp_player"),
  47240. (call_script, "script_troop_get_player_relation", ":troop1"),
  47241. (assign, ":relation", reg0),
  47242. (else_try),
  47243. (store_add, ":troop1_slot_for_troop2", ":troop2", slot_troop_relations_begin),
  47244. (troop_get_slot, ":relation", ":troop1", ":troop1_slot_for_troop2"),
  47245. (try_end),
  47246.  
  47247.  
  47248. (val_clamp, ":relation", -100, 101),
  47249. (assign, reg0, ":relation"),
  47250.  
  47251. ]),
  47252.  
  47253.  
  47254.  
  47255. ("appoint_faction_marshall",
  47256. [
  47257. (store_script_param, ":faction_no", 1),
  47258. (store_script_param, ":faction_marshall", 2),
  47259.  
  47260.  
  47261. (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  47262. (faction_get_slot, ":old_marshall", ":faction_no", slot_faction_marshall),
  47263.  
  47264. (faction_set_slot, ":faction_no", slot_faction_marshall, ":faction_marshall"),
  47265.  
  47266. (try_begin),
  47267. (ge, ":old_marshall", 0),
  47268. (troop_get_slot, ":old_marshall_party", ":old_marshall", slot_troop_leaded_party),
  47269. (party_is_active, ":old_marshall_party"),
  47270. (party_set_marshal, ":old_marshall_party", 0),
  47271. (try_end),
  47272.  
  47273.  
  47274. (try_begin),
  47275. (ge, ":faction_marshall", 0),
  47276. (troop_get_slot, ":new_marshall_party", ":faction_marshall", slot_troop_leaded_party),
  47277. (party_is_active, ":new_marshall_party"),
  47278. (party_set_marshal,":new_marshall_party", 1),
  47279. (try_end),
  47280.  
  47281.  
  47282. (try_begin),
  47283. (neq, ":faction_marshall", ":faction_leader"),
  47284. (neq, ":faction_marshall", ":old_marshall"),
  47285. ##diplomacy start+ Support promoted kingdom ladies
  47286. (this_or_next|eq, ":faction_marshall", "trp_player"),
  47287. (is_between, ":faction_marshall", heroes_begin, heroes_end),
  47288. (this_or_next|troop_slot_eq, ":faction_marshall", slot_troop_occupation, slto_kingdom_hero),
  47289. ##diplomacy end+
  47290. (this_or_next|eq, ":faction_marshall", "trp_player"),
  47291. (is_between, ":faction_marshall", active_npcs_begin, active_npcs_end),
  47292.  
  47293. (this_or_next|neq, ":faction_no", "fac_player_supporters_faction"),
  47294. (neg|check_quest_active, "qst_rebel_against_kingdom"),
  47295.  
  47296. (try_begin),
  47297. (eq, "$cheat_mode", 1),
  47298. (str_store_faction_name, s15, ":faction_no"),
  47299. (display_message, "str_checking_lord_reactions_in_s15"),
  47300. (try_end),
  47301.  
  47302.  
  47303. (call_script, "script_troop_change_relation_with_troop", ":faction_marshall", ":faction_leader", 5),
  47304. (val_add, "$total_promotion_changes", 5),
  47305.  
  47306. ##diplomacy start+
  47307. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", ":faction_no"),
  47308. (assign, ":player_standing_in_faction", reg0),
  47309. #(ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  47310.  
  47311. #Support promoted kingdom ladies
  47312. ##OLD:
  47313. #(try_for_range, ":lord", active_npcs_begin, active_npcs_end),
  47314. ##NEW:
  47315. (try_for_range, ":lord", heroes_begin, heroes_end),
  47316. ##diplomacy end+
  47317. (troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  47318. (store_faction_of_troop, ":lord_faction", ":lord"),
  47319. (eq, ":lord_faction", ":faction_no"),
  47320.  
  47321. (neq, ":lord", ":faction_marshall"),
  47322. (neq, ":lord", ":faction_leader"),
  47323.  
  47324. (call_script, "script_troop_get_relation_with_troop", ":faction_marshall", ":lord"),
  47325. # (try_begin),
  47326. # (eq, "$cheat_mode", 1),
  47327. # (str_store_troop_name, s14, ":lord"),
  47328. # (str_store_troop_name, s17, ":faction_marshall"),
  47329. # (display_message, "@{!}{s14}'s relation with {s17} is {reg0}"),
  47330. # (try_end),
  47331. (store_sub, ":adjust_relations", reg0, 10),
  47332. (val_div, ":adjust_relations", 15),
  47333. ##diplomacy start+
  47334. #In some situtations the player can set the marshall freely even though he isn't the faction leader.
  47335. (try_begin),
  47336. (eq, ":faction_marshall", "trp_player"),
  47337. (ge, ":player_standing_in_faction", DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  47338. #Still allow a relation gain below if the lord had actively supported the player
  47339. #(which doesn't happen now if the player is the ruler, but could).
  47340. (val_min, ":adjust_relations", 0),
  47341. (try_end),
  47342. ##diplomacy end+
  47343. (neq, ":adjust_relations", 0),
  47344.  
  47345. #Not negatively affected if they favored the lord
  47346. (try_begin),
  47347. (troop_slot_eq, ":lord", slot_troop_stance_on_faction_issue, ":faction_marshall"),
  47348. (val_add, ":adjust_relations", 1),
  47349. (val_max, ":adjust_relations", 0),
  47350. (try_end),
  47351.  
  47352. (call_script, "script_troop_change_relation_with_troop", ":faction_leader", ":lord", ":adjust_relations"),
  47353. (val_add, "$total_promotion_changes", ":adjust_relations"),
  47354.  
  47355. (lt, ":adjust_relations", -2),
  47356. (store_random_in_range, ":random", 1, 10),
  47357.  
  47358. (val_add, ":adjust_relations", ":random"),
  47359.  
  47360. (lt, ":adjust_relations", 0),
  47361.  
  47362. (str_store_troop_name, s14, ":lord"),
  47363. (str_store_troop_name, s15, ":faction_marshall"),
  47364.  
  47365. (try_begin),
  47366. ##diplomacy start+ Show protest information for your own kingdom if you have a chancellor or are the ruler
  47367. (ge, ":player_standing_in_faction", DPLMC_FACTION_STANDING_MEMBER),
  47368. (this_or_next|ge, ":player_standing_in_faction", DPLMC_FACTION_STANDING_LEADER_SPOUSE),#<- via the minister, or just hearing about it
  47369. (gt, "$g_player_chancellor", 0),#<- via your chancellor
  47370. (neg|troop_slot_eq, ":lord", slot_troop_met, 0),
  47371. (display_message, "str_s14_protests_the_appointment_of_s15_as_marshall"),
  47372. (else_try),
  47373. (call_script, "script_dplmc_store_troop_is_eligible_for_affiliate_messages", ":lord"),
  47374. (this_or_next|gt, reg0, 0),
  47375. ##diplomacy end+
  47376. (eq, "$cheat_mode", 1),
  47377. (display_message, "str_s14_protests_the_appointment_of_s15_as_marshall"),
  47378. (try_end),
  47379.  
  47380. (call_script, "script_troop_change_relation_with_troop", ":faction_leader", ":lord", -10),
  47381. (call_script, "script_troop_change_relation_with_troop", ":faction_marshall", ":lord", -5),
  47382. (val_add, "$total_promotion_changes", -15),
  47383.  
  47384. (call_script, "script_add_log_entry", logent_lord_protests_marshall_appointment, ":lord", ":faction_marshall", ":faction_leader", "$g_encountered_party_faction"),
  47385.  
  47386. (try_end),
  47387. (try_end),
  47388.  
  47389. ]),
  47390.  
  47391. #it might be easier to monitor whether prices are following an intuitive pattern if we separate production from consumption
  47392. #the current system still works very well, however
  47393. ("center_get_item_consumption",
  47394. [
  47395. ]),
  47396.  
  47397. ("locate_player_minister", #maybe deprecate this
  47398. [
  47399. ##diplomacy start+ Handle player is co-ruler of NPC faction
  47400. (assign, ":alt_faction", "fac_player_supporters_faction"),
  47401. (try_begin),
  47402. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  47403. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  47404. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  47405. (assign, ":alt_faction", "$players_kingdom"),
  47406. (try_end),
  47407. ##diplomacy end+
  47408. (assign, ":walled_center_found", 0),
  47409. (try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
  47410. (lt, ":walled_center_found", centers_begin),
  47411. (store_faction_of_party, ":walled_center_faction", ":walled_center"),
  47412. ##diplomacy start+
  47413. (this_or_next|eq, ":walled_center_faction", ":alt_faction"),
  47414. ##diplomacy end+
  47415. (eq, ":walled_center_faction", "fac_player_supporters_faction"),
  47416. (neg|party_slot_ge, ":walled_center", slot_town_lord, active_npcs_begin), #ie, player or a reserved slot
  47417. (assign, ":walled_center_found", ":walled_center"),
  47418. (try_end),
  47419.  
  47420. (troop_get_slot, ":old_location", "$g_player_minister", slot_troop_cur_center),
  47421. (troop_set_slot, "$g_player_minister", slot_troop_cur_center, ":walled_center_found"),
  47422.  
  47423. (try_begin),
  47424. (neq, ":old_location", ":walled_center"),
  47425. (str_store_party_name, s10, ":walled_center"),
  47426. (str_store_troop_name, s11, "$g_player_minister"),
  47427. (display_message, "str_s11_relocates_to_s10"),
  47428. (try_end),
  47429.  
  47430. ]),
  47431.  
  47432.  
  47433. ("lord_get_home_center",
  47434. [
  47435. (store_script_param, ":troop_no", 1),
  47436. (assign, ":result", -1),
  47437.  
  47438. ##diplomacy start+
  47439. (assign, ":best_score", -1),
  47440. (troop_get_slot, ":troop_original_faction", ":troop_no", slot_troop_original_faction),
  47441. #The default script prefers towns to castles, but aside from that is
  47442. #fairly arbitrary. Add scores that take into account original faction
  47443. #and so forth.
  47444. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  47445. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  47446. (assign, ":center_score", 10),#10 for castles, 20 for towns
  47447. (try_begin),
  47448. (is_between, ":center_no", towns_begin, towns_end),
  47449. (assign, ":center_score", 20),
  47450. (try_end),
  47451. (try_begin),
  47452. (troop_slot_eq, ":troop_no", slot_troop_home, ":center_no"),
  47453. (val_add, ":center_score", 6),
  47454. (else_try),
  47455. (party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":troop_no"),
  47456. (val_add, ":center_score", 5),
  47457. (else_try),
  47458. (is_between, ":troop_original_faction", kingdoms_begin, kingdoms_end),
  47459. (party_slot_eq, ":center_no", slot_center_original_faction, ":troop_original_faction"),
  47460. (val_add, ":center_score", 4),
  47461. (try_end),
  47462. (gt, ":center_score", ":best_score"),
  47463. (assign, ":result", ":center_no"),
  47464. (assign, ":best_score", ":center_score"),
  47465. (try_end),
  47466. ##diplomacy end+
  47467.  
  47468. #SB : add loop breaks
  47469. (try_begin),
  47470. (eq, ":result", -1),
  47471. (assign, ":limit", walled_centers_end),
  47472. (try_for_range, ":center_no", walled_centers_begin, ":limit"),
  47473. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  47474. (assign, ":result", ":center_no"),
  47475. (assign, ":limit", walled_centers_begin),
  47476. (try_end),
  47477. (try_end),
  47478.  
  47479. #NOTE : In old code if a lord has no walled center then home city of this lord is assigning to
  47480. #faction leader's home city. Now I changed this to assign home cities more logical and homogeneous.
  47481. #In new code if a lord has no walled center then his home city becomes his village's border_city.
  47482. #This means his home city becomes owner city of his village. If he has no village then as last change
  47483. #his home city become faction leader's home city.
  47484. (try_begin),
  47485. (eq, ":result", -1),
  47486.  
  47487. #SB : add loop breaks
  47488. (assign, ":limit", villages_end),
  47489. (try_for_range, ":center_no", villages_begin, ":limit"),
  47490. (eq, ":result", -1),
  47491. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  47492.  
  47493. # (try_begin),
  47494. # (neg|is_between, ":center_no", walled_centers_begin, walled_centers_end),
  47495. (party_get_slot, ":bound_center", ":center_no", slot_village_bound_center),
  47496. (assign, ":result", ":bound_center"),
  47497. (assign, ":limit", villages_begin),
  47498. # (try_end),
  47499. (try_end),
  47500. (try_end),
  47501.  
  47502. #If lord has no walled center and is player faction, then assign player court
  47503. (try_begin),
  47504. (eq, ":result", -1),
  47505. (store_faction_of_troop, ":faction_no", ":troop_no"),
  47506. (eq, ":faction_no", "fac_player_supporters_faction"),
  47507. (is_between, "$g_player_court", walled_centers_begin, walled_centers_end),
  47508. (store_faction_of_party, ":player_court_faction", "$g_player_court"),
  47509. (eq, ":player_court_faction", "fac_player_supporters_faction"),
  47510.  
  47511. (assign, ":result", "$g_player_court"),
  47512. (try_end),
  47513.  
  47514. #If lord has no walled center and any not walled village then assign faction capital
  47515. (try_begin),
  47516. (eq, ":result", -1),
  47517. (store_faction_of_troop, ":faction_no", ":troop_no"),
  47518. (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  47519. (neq, ":troop_no", ":faction_leader"),
  47520. (ge, ":faction_leader", 0),#<- Fix for ticket 36.
  47521. ##By the way, if this was Native, the following two lines would fix
  47522. ##the weird bug where relatives of exiled lords start accumulating
  47523. ##in the player's court:
  47524. #(this_or_next|neq, ":faction_leader", ":troop_no"),
  47525. #(eq, "$players_kingdom", ":faction_no"),
  47526. ##This is unnecessary in Diplomacy, though, since I initialize slot_faction_leader to -1
  47527. ##to distinguish factions led by the player from factions without actual leaders.
  47528. (call_script, "script_lord_get_home_center", ":faction_leader"),
  47529. (gt, reg0, -1),
  47530. (assign, ":result", reg0),
  47531. (try_end),
  47532.  
  47533. #Any center of the faction
  47534. (try_begin),
  47535. (eq, ":result", -1),
  47536. (store_faction_of_troop, ":faction_no", ":troop_no"),
  47537.  
  47538. (try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
  47539. (eq, ":result", -1),
  47540.  
  47541. (store_faction_of_party, ":center_faction", ":walled_center"),
  47542. (eq, ":faction_no", ":center_faction"),
  47543. (assign, ":result", ":walled_center"),
  47544. (try_end),
  47545. (try_end),
  47546.  
  47547.  
  47548.  
  47549. (assign, reg0, ":result"),
  47550. ]),
  47551.  
  47552.  
  47553.  
  47554.  
  47555. ("get_kingdom_lady_social_determinants", #Calradian society is rather patriarchal, at least among the upper classes
  47556. [
  47557. (store_script_param, ":kingdom_lady", 1),
  47558.  
  47559. (store_faction_of_troop, ":faction_of_lady", ":kingdom_lady"),
  47560. (assign, ":center", -1),
  47561. (assign, ":closest_male_relative", -1),
  47562. (assign, ":best_center_score", 0),
  47563.  
  47564. ##diplomacy start+
  47565. ##TODO: Re-implement, disabled for now. "Don't get stuck attached to a MIA relative"
  47566. (try_begin),
  47567. (troop_slot_ge, ":kingdom_lady", slot_troop_spouse, 0),
  47568. (troop_get_slot, ":closest_male_relative", ":kingdom_lady", slot_troop_spouse),
  47569. #(neg|troop_slot_ge, ":closest_male_relative", slot_troop_occupation, slto_retirement),#added: has not been removed from play
  47570. (else_try),
  47571. (troop_slot_ge, ":kingdom_lady", slot_troop_father, 0),
  47572. (troop_get_slot, ":closest_male_relative", ":kingdom_lady", slot_troop_father),
  47573. #(neg|troop_slot_ge, ":closest_male_relative", slot_troop_occupation, slto_retirement),#added: has not been removed from play
  47574. (else_try),
  47575. #added
  47576. (troop_slot_ge, ":kingdom_lady", slot_troop_mother, 0),
  47577. (troop_get_slot, ":closest_male_relative", ":kingdom_lady", slot_troop_mother),
  47578. (troop_slot_eq, ":closest_male_relative", slot_troop_occupation, slto_kingdom_hero),
  47579. (else_try),
  47580. (troop_slot_ge, ":kingdom_lady", slot_troop_guardian, 0),
  47581. (troop_get_slot, ":closest_male_relative", ":kingdom_lady", slot_troop_guardian),
  47582. #(neg|troop_slot_ge, ":closest_male_relative", slot_troop_occupation, slto_retirement),#added: has not been removed from play
  47583. (try_end),
  47584. ##diplomacy end+
  47585.  
  47586. ##diplomacy start+
  47587. #Avoid strange problems if the argument is not a kingdom lady.
  47588. (try_begin),
  47589. (this_or_next|is_between, ":kingdom_lady", kingdom_ladies_begin, kingdom_ladies_end),
  47590. (troop_slot_eq, ":kingdom_lady", slot_troop_occupation, slto_kingdom_lady),
  47591. (neg|troop_slot_eq, ":kingdom_lady", slot_troop_occupation, slto_kingdom_hero),
  47592. (assign, ":is_lady", 1),
  47593. (else_try),
  47594. (assign, ":is_lady", 0),
  47595. (assign, ":closest_male_relative", ":kingdom_lady"),# is doing this useful for the way this script is used, or should we just set it to -1?
  47596. (try_end),
  47597.  
  47598. ##OLD:
  47599. #(try_begin), #if ongoing social event (maybe add if not besieged)
  47600. ##NEW:
  47601. (try_begin),
  47602. (eq, ":is_lady", 0),
  47603. (call_script, "script_lord_get_home_center", ":kingdom_lady"),
  47604. (assign, ":center", reg0),
  47605. (is_between, ":center", walled_centers_begin, walled_centers_end),
  47606. (else_try), #if ongoing social event (maybe add if not besieged)
  47607. ##diplomacy end+
  47608. (faction_slot_eq, ":faction_of_lady", slot_faction_ai_state, sfai_feast),
  47609. (faction_get_slot, ":feast_center", ":faction_of_lady", slot_faction_ai_object),
  47610.  
  47611. (gt, ":closest_male_relative", -1),
  47612. (troop_get_slot, ":closest_male_party", ":closest_male_relative", slot_troop_leaded_party),
  47613. (party_is_active, ":closest_male_party"),
  47614. (party_get_attached_to, ":closest_male_cur_location", ":closest_male_party"),
  47615.  
  47616. (eq, ":closest_male_cur_location", ":feast_center"),
  47617. (is_between, ":feast_center", walled_centers_begin, walled_centers_end),
  47618.  
  47619. (assign, ":center", ":feast_center"),
  47620.  
  47621. (else_try),
  47622. (troop_slot_eq, "trp_player", slot_troop_spouse, ":kingdom_lady"),
  47623. ###diplomacy begin
  47624. (try_begin),
  47625. ##diplomacy end
  47626. (is_between, "$g_player_court", walled_centers_begin, walled_centers_end),
  47627. (assign, ":center", "$g_player_court"),
  47628. ##diplomacy begin
  47629. (else_try),
  47630. (troop_get_slot, ":cur_residence", ":kingdom_lady", slot_troop_cur_center),
  47631. (is_between, ":cur_residence", walled_centers_begin, walled_centers_end),
  47632. (party_slot_eq, ":cur_residence", slot_town_lord, "trp_player"),
  47633. (assign, ":center", ":cur_residence"),
  47634. (try_end),
  47635. (is_between, ":center", walled_centers_begin, walled_centers_end),
  47636. ##diplomacy end
  47637. (else_try),
  47638. (try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
  47639. (store_faction_of_party, ":walled_center_faction", ":walled_center"),
  47640. (this_or_next|eq, ":faction_of_lady", ":walled_center_faction"),
  47641. (neg|is_between, ":faction_of_lady", kingdoms_begin, kingdoms_end), #lady married to a player without a faction
  47642.  
  47643. (party_get_slot, ":castle_lord", ":walled_center", slot_town_lord),
  47644.  
  47645. (gt, ":castle_lord", -1),
  47646.  
  47647. (call_script, "script_troop_get_family_relation_to_troop", ":kingdom_lady", ":castle_lord"),
  47648. ##diplomacy start+
  47649. (try_begin),
  47650. (eq, ":is_lady", 0),
  47651. (eq, ":castle_lord", ":kingdom_lady"),
  47652. (val_max, reg0, 16),
  47653. (try_end),
  47654. ##diplomacy end+
  47655.  
  47656. (try_begin),
  47657. (this_or_next|is_between, ":faction_of_lady", kingdoms_begin, kingdoms_end),
  47658. (troop_slot_eq, "trp_player", slot_troop_spouse, ":kingdom_lady"),
  47659.  
  47660. (faction_slot_eq, ":faction_of_lady", slot_faction_leader, ":castle_lord"),
  47661. (val_max, reg0, 1),
  47662. (try_end),
  47663.  
  47664. (try_begin),
  47665. (eq, "$cheat_mode", 2),
  47666. (str_store_troop_name, s3, ":kingdom_lady"),
  47667. (str_store_troop_name, s4, ":castle_lord"),
  47668. (str_store_party_name, s5, ":walled_center"),
  47669. (display_message, "str_checking_s3_at_s5_with_s11_relationship_with_s4_score_reg0"),
  47670. (str_clear, s11),
  47671. (try_end),
  47672.  
  47673. (gt, reg0, ":best_center_score"),
  47674.  
  47675. (assign, ":best_center_score", reg0),
  47676. (assign, ":center", ":walled_center"),
  47677.  
  47678.  
  47679. (try_end),
  47680. (try_end),
  47681.  
  47682. (assign, reg0, ":closest_male_relative"),
  47683. (assign, reg1, ":center"),
  47684.  
  47685.  
  47686. ]),
  47687.  
  47688.  
  47689. #This is probably unnecessarily complicated, but can support a multi-generational mod
  47690. ("age_troop_one_year",
  47691. [
  47692. (store_script_param, ":troop_no", 1),
  47693. ##diplomacy start+ use gender script
  47694. #(troop_get_type, ":is_female", ":troop_no"),
  47695. (assign, ":save_reg0", reg0),
  47696. (call_script, "script_dplmc_store_troop_is_female", ":troop_no"),
  47697. (assign, ":is_female", reg0),
  47698. (assign, reg0, ":save_reg0"),
  47699. ##diplomacy end+
  47700.  
  47701. (troop_get_slot, ":age", ":troop_no", slot_troop_age),
  47702. (troop_get_slot, ":appearance", ":troop_no", slot_troop_age_appearance),
  47703.  
  47704. (val_add, ":age", 1),
  47705. (store_random_in_range, ":addition", 1, 5),
  47706.  
  47707. (try_begin),
  47708. (eq, ":is_female", 1),
  47709. # (val_add, ":addition", 2), #the women's age slider seems to produce less change than the male one - commented out: makes women look too old.
  47710. (try_end),
  47711.  
  47712. (val_add, ":appearance", ":addition"),
  47713. (try_begin),
  47714. (gt, ":age", 45),
  47715. (store_attribute_level, ":strength", ":troop_no", ca_strength),
  47716. (store_attribute_level, ":agility", ":troop_no", ca_agility),
  47717. (store_random_in_range, ":random", 0, 50), #2% loss brings it down to about 36% by age 90, but of course can be counteracted by new level gain
  47718. (try_begin),
  47719. (lt, ":random", ":strength"),
  47720. (troop_raise_attribute, ":troop_no", ca_strength, -1),
  47721. (try_end),
  47722. (try_begin),
  47723. (lt, ":random", ":agility"),
  47724. (troop_raise_attribute, ":troop_no", ca_agility, -1),
  47725. (try_end),
  47726. (try_end),
  47727.  
  47728. (val_clamp, ":appearance", 1, 100),
  47729.  
  47730. (troop_set_slot, ":troop_no", slot_troop_age, ":age"),
  47731. (troop_set_slot, ":troop_no", slot_troop_age_appearance, ":appearance"),
  47732. (troop_set_age, ":troop_no", ":appearance"),
  47733. ]),
  47734.  
  47735.  
  47736. ("add_lady_items",
  47737. [
  47738. (store_script_param, ":lady_no", 1),
  47739. (troop_equip_items, ":lady_no"),
  47740.  
  47741. (store_faction_of_troop, ":faction_no", ":lady_no"),
  47742.  
  47743. (store_random_in_range, ":random", 0, 6),
  47744.  
  47745. (try_begin), #assign clothes
  47746. (this_or_next|troop_slot_eq, ":lady_no", slot_lord_reputation_type, lrep_adventurous),
  47747. (troop_slot_eq, ":lady_no", slot_lord_reputation_type, lrep_ambitious),
  47748.  
  47749. (this_or_next|troop_slot_eq, ":lady_no", slot_lord_reputation_type, lrep_adventurous),
  47750. (lt, ":random", 2),
  47751.  
  47752. (neg|troop_slot_ge, ":lady_no", slot_troop_age, 40),
  47753. (try_begin),
  47754. (eq, ":faction_no", "fac_kingdom_2"),
  47755. (lt, ":random", 4),
  47756. (troop_add_item, ":lady_no", "itm_fur_coat", 0),
  47757. (else_try),
  47758. (eq, ":faction_no", "fac_kingdom_3"),
  47759. (lt, ":random", 3),
  47760. (troop_add_item, ":lady_no", "itm_nomad_robe", 0),
  47761. (else_try),
  47762. (troop_add_item, ":lady_no", "itm_nomad_vest", 0),
  47763. (try_end),
  47764. (else_try),
  47765. (eq, ":faction_no", "fac_kingdom_1"),
  47766. (try_begin),
  47767. (lt, ":random", 2),
  47768. (troop_add_item, ":lady_no", "itm_lady_dress_ruby", 0),
  47769. (else_try),
  47770. (lt, ":random", 4),
  47771. (troop_add_item, ":lady_no", "itm_lady_dress_green", 0),
  47772. (else_try),
  47773. (troop_add_item, ":lady_no", "itm_lady_dress_blue", 0),
  47774. (try_end),
  47775. (else_try),
  47776. (eq, ":faction_no", "fac_kingdom_2"),
  47777. (try_begin),
  47778. (eq, ":random", 0),
  47779. (troop_add_item, ":lady_no", "itm_blue_dress", 0),
  47780. (else_try),
  47781. (eq, ":random", 1),
  47782. (troop_add_item, ":lady_no", "itm_lady_dress_green", 0),
  47783. (else_try),
  47784. (eq, ":random", 2),
  47785. (troop_add_item, ":lady_no", "itm_lady_dress_blue", 0),
  47786. (else_try),
  47787. (lt, ":random", 5),
  47788. (neg|troop_slot_eq, ":lady_no", slot_lord_reputation_type, lrep_conventional),
  47789. (neg|troop_slot_eq, ":lady_no", slot_lord_reputation_type, lrep_ambitious),
  47790. (troop_add_item, ":lady_no", "itm_peasant_dress", 0),
  47791. (else_try),
  47792. (lt, ":random", 5),
  47793. (troop_add_item, ":lady_no", "itm_lady_dress_ruby", 0),
  47794. (else_try),
  47795. (troop_add_item, ":lady_no", "itm_court_dress", 0),
  47796. (try_end),
  47797.  
  47798. (else_try),
  47799. (eq, ":faction_no", "fac_kingdom_3"),
  47800. (troop_add_item, ":lady_no", "itm_khergit_lady_dress", 0),
  47801.  
  47802. (else_try),
  47803. (eq, ":faction_no", "fac_kingdom_4"),
  47804.  
  47805. (else_try),
  47806. (eq, ":faction_no", "fac_kingdom_5"),
  47807.  
  47808.  
  47809. (try_end),
  47810. (troop_equip_items, ":lady_no"),
  47811.  
  47812. #also available:
  47813. #itm_blue_dress
  47814. #itm_court_dress
  47815.  
  47816. #to add for khergits -- salwar/shalvar?
  47817. #western tang costume (p105, china's golden age)
  47818. #kipchak woman from russia book
  47819.  
  47820. (try_begin), #assign headguear matched to item
  47821. (this_or_next|troop_has_item_equipped, ":lady_no", "itm_nomad_vest"),
  47822. (this_or_next|troop_has_item_equipped, ":lady_no", "itm_fur_coat"),
  47823. (troop_has_item_equipped, ":lady_no", "itm_nomad_robe"),
  47824.  
  47825. #assign no headgear
  47826. (else_try),
  47827. (this_or_next|troop_slot_eq, ":lady_no", slot_lord_reputation_type, lrep_moralist),
  47828. (this_or_next|troop_slot_eq, ":lady_no", slot_lord_reputation_type, lrep_conventional),
  47829. (lt, ":random", 2),
  47830.  
  47831.  
  47832. (try_begin),
  47833. (troop_has_item_equipped, ":lady_no", "itm_khergit_lady_dress"),
  47834. (troop_add_item, ":lady_no", "itm_khergit_lady_hat", 0),
  47835.  
  47836. (else_try),
  47837. (troop_has_item_equipped, ":lady_no", "itm_lady_dress_ruby"),
  47838. (troop_add_item, ":lady_no", "itm_turret_hat_ruby", 0),
  47839.  
  47840. (str_store_troop_name, s4, ":lady_no"),
  47841. # (display_message, "@Giving ruby turret hat to {s4}"),
  47842. (else_try),
  47843. (troop_has_item_equipped, ":lady_no", "itm_lady_dress_blue"),
  47844. (troop_add_item, ":lady_no", "itm_turret_hat_blue", 0),
  47845.  
  47846. (str_store_troop_name, s4, ":lady_no"),
  47847. # (display_message, "@Giving blue turret hat to {s4}"),
  47848. (else_try),
  47849. (troop_has_item_equipped, ":lady_no", "itm_lady_dress_green"),
  47850. (troop_add_item, ":lady_no", "itm_turret_hat_green", 0),
  47851.  
  47852. (str_store_troop_name, s4, ":lady_no"),
  47853. # (display_message, "@Giving green turret hat to {s4}"),
  47854. (else_try),
  47855. (troop_has_item_equipped, ":lady_no", "itm_green_dress"),
  47856. (troop_add_item, ":lady_no", "itm_wimple_with_veil", 0),
  47857.  
  47858. (str_store_troop_name, s4, ":lady_no"),
  47859. # (display_message, "@Giving green-lined wimple to {s4}"),
  47860. (else_try),
  47861. (neq, ":faction_no", "fac_kingdom_3"),
  47862. (neq, ":faction_no", "fac_kingdom_6"),
  47863. (troop_add_item, ":lady_no", "itm_wimple_a", 0),
  47864.  
  47865. (str_store_troop_name, s4, ":lady_no"),
  47866. # (display_message, "@Giving red-lined wimple to {s4}"),
  47867. (else_try),
  47868. (eq, ":faction_no", "fac_kingdom_6"),
  47869. (try_begin),
  47870. (troop_has_item_equipped, ":lady_no", "itm_sarranid_lady_dress"),
  47871. (troop_add_item, ":lady_no", "itm_sarranid_head_cloth", 0),
  47872. (else_try),
  47873. (troop_add_item, ":lady_no", "itm_sarranid_head_cloth_b", 0),
  47874. (try_end),
  47875. (try_end),
  47876. (try_end),
  47877. (troop_equip_items, ":lady_no"),
  47878. ##diplomacy start+
  47879. ##Save personal items of kingdom ladies
  47880. (call_script, "script_dplmc_save_civilian_clothing", ":lady_no"),
  47881. ##diplomacy end+
  47882. ]
  47883. ),
  47884.  
  47885. ("init_troop_age",
  47886. [
  47887. (store_script_param, ":troop_no", 1),
  47888. (store_script_param, ":age", 2), #minimum 20
  47889.  
  47890. (try_begin),
  47891. (gt, ":age", 20),
  47892. (troop_set_slot, ":troop_no", slot_troop_age, 20),
  47893. (else_try),
  47894. (troop_set_slot, ":troop_no", slot_troop_age, ":age"),
  47895. (try_end),
  47896.  
  47897. (store_sub, ":years_to_age", ":age", 20),
  47898. (troop_set_age, ":troop_no", 0),
  47899.  
  47900. (try_begin),
  47901. (gt, ":years_to_age", 0),
  47902. (try_for_range, ":unused", 0, ":years_to_age"),
  47903. (call_script, "script_age_troop_one_year", ":troop_no"),
  47904. (try_end),
  47905. (try_end),
  47906.  
  47907. ]),
  47908.  
  47909.  
  47910. ("assign_troop_love_interests", #Called at the beginning, or whenever a lord is spurned
  47911. [
  47912. (store_script_param, ":cur_troop", 1),
  47913. ##diplomacy start+
  47914. #wrap the entire thing in a try-statement: do nothing when called erroneously
  47915. (assign, ":save_reg0", reg0),
  47916. (assign, ":save_reg1", reg1),
  47917. (try_begin),
  47918. (this_or_next|is_between, ":cur_troop", lords_begin, lords_end),
  47919. (this_or_next|is_between, ":cur_troop", companions_begin, companions_end),
  47920. (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),#kingdom heroes only
  47921. (troop_slot_eq, ":cur_troop", slot_troop_spouse, -1),#not married, engaged
  47922. (troop_slot_eq, ":cur_troop", slot_troop_betrothed, -1),
  47923.  
  47924. #avoid unintentional erroneous pairings (intentional exceptions can be added)
  47925. #(troop_get_type, ":troop_type", ":cur_troop"),
  47926. (call_script, "script_dplmc_store_troop_is_female", ":cur_troop"),
  47927. (assign, ":troop_type", reg0),
  47928.  
  47929. (try_begin),
  47930. #Certain personality types don't care about flouting convention.
  47931. (this_or_next|troop_slot_eq, ":cur_troop", slot_lord_reputation_type, lrep_debauched),
  47932. (this_or_next|troop_slot_eq, ":cur_troop", slot_lord_reputation_type, lrep_roguish),
  47933. (troop_slot_eq, ":cur_troop", slot_lord_reputation_type, lrep_adventurous),
  47934. (assign, ":troop_type", abs(tf_male) + abs(tf_female) + 1),#guaranteed not to equal tf_male or tf_female
  47935. (try_end),
  47936. (store_faction_of_troop, ":troop_faction", ":cur_troop"),
  47937. #assign default initial courtships for companions
  47938. (try_begin),
  47939. (is_between, ":cur_troop", companions_begin, companions_end),
  47940. (troop_get_slot, ":cur_lady", ":cur_troop", slot_troop_personalitymatch_object),
  47941. (is_between, ":cur_lady", heroes_begin, heroes_end),
  47942.  
  47943. (store_faction_of_troop, ":lady_faction", ":cur_lady"),
  47944. (eq, ":troop_faction", ":lady_faction"),
  47945. #(call_script, "script_troop_get_family_relation_to_troop", ":cur_troop", ":cur_lady"),
  47946. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":cur_troop", ":cur_lady"),
  47947. (lt, reg0, 2),#check not a close relative
  47948. #(troop_get_type, reg0, ":cur_lady"),
  47949. (call_script, "script_dplmc_store_troop_is_female", ":cur_lady"),
  47950. (neq, ":troop_type", reg0),#check gender compatability
  47951. (neq, ":cur_lady", ":cur_troop"),#check not yourself
  47952. (neg|troop_slot_ge, ":cur_lady", slot_troop_occupation, slto_retirement),#check in the game and not retired, exiled, dead, etc.
  47953. (troop_slot_ge, ":cur_lady", slot_troop_occupation, slto_kingdom_hero),
  47954. (call_script, "script_troop_get_relation_with_troop", ":cur_troop", ":cur_lady"),
  47955. (ge, reg0, 0), #do not develop love interest if already spurned (but DO allow re-courting)
  47956.  
  47957. (neg|troop_slot_eq, ":cur_troop", slot_troop_love_interest_1, ":cur_lady"),
  47958. (neg|troop_slot_eq, ":cur_troop", slot_troop_love_interest_2, ":cur_lady"),
  47959. (neg|troop_slot_eq, ":cur_troop", slot_troop_love_interest_3, ":cur_lady"),
  47960. (try_begin),
  47961. (this_or_next|troop_slot_eq, ":cur_troop", slot_troop_love_interest_1, -1),
  47962. (troop_slot_eq, ":cur_troop", slot_troop_love_interest_1, 0),
  47963. (troop_set_slot, ":cur_troop", slot_troop_love_interest_1, ":cur_lady"),
  47964. (else_try),
  47965. (this_or_next|troop_slot_eq, ":cur_troop", slot_troop_love_interest_2, -1),
  47966. (troop_slot_eq, ":cur_troop", slot_troop_love_interest_2, 0),
  47967. (troop_set_slot, ":cur_troop", slot_troop_love_interest_2, ":cur_lady"),
  47968. (else_try),
  47969. (this_or_next|troop_slot_eq, ":cur_troop", slot_troop_love_interest_3, -1),
  47970. (troop_slot_eq, ":cur_troop", slot_troop_love_interest_3, 0),
  47971. (troop_set_slot, ":cur_troop", slot_troop_love_interest_3, ":cur_lady"),
  47972. (try_end),
  47973. (try_end),
  47974. ##diplomacy end+
  47975. (try_for_range, ":unused", 0, 50),
  47976. (store_random_in_range, ":cur_lady", kingdom_ladies_begin, kingdom_ladies_end),
  47977. (troop_slot_eq, ":cur_lady", slot_troop_spouse, -1),
  47978. (store_faction_of_troop, ":lady_faction", ":cur_lady"),
  47979. (eq, ":troop_faction", ":lady_faction"),
  47980. ##diplomacy start+
  47981. ##(call_script, "script_troop_get_family_relation_to_troop", ":cur_troop", ":cur_lady"),
  47982. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":cur_troop", ":cur_lady"),
  47983. #(eq, reg0, 0),
  47984. #right now nothing gives a value of 1, but change this check in case more distant relations are reported
  47985. (lt, reg0, 2),#check not a close relative
  47986. #(troop_get_type, reg0, ":cur_lady"),
  47987. (call_script, "script_dplmc_store_troop_is_female", ":cur_lady"),
  47988. (neq, ":troop_type", reg0),#check gender compatability
  47989. (neq, ":cur_lady", ":cur_troop"),#check not yourself
  47990. (neg|troop_slot_ge, ":cur_lady", slot_troop_occupation, slto_retirement),#check in the game and not retired, exiled, dead, etc.
  47991. (troop_slot_ge, ":cur_lady", slot_troop_occupation, slto_kingdom_hero),
  47992. ##diplomacy end+
  47993. (call_script, "script_troop_get_relation_with_troop", ":cur_troop", ":cur_lady"),
  47994.  
  47995. (eq, reg0, 0), #do not develop love interest if already spurned or courted
  47996.  
  47997. (neg|troop_slot_eq, ":cur_troop", slot_troop_love_interest_1, ":cur_lady"),
  47998. (neg|troop_slot_eq, ":cur_troop", slot_troop_love_interest_2, ":cur_lady"),
  47999. (neg|troop_slot_eq, ":cur_troop", slot_troop_love_interest_3, ":cur_lady"),
  48000. ##diplomacy start+ also allow -1 to signify no-one courted
  48001. (try_begin),
  48002. (this_or_next|troop_slot_eq, ":cur_troop", slot_troop_love_interest_1, -1),#< added
  48003. (troop_slot_eq, ":cur_troop", slot_troop_love_interest_1, 0),
  48004. (troop_set_slot, ":cur_troop", slot_troop_love_interest_1, ":cur_lady"),
  48005. (else_try),
  48006. (this_or_next|troop_slot_eq, ":cur_troop", slot_troop_love_interest_2, -1),#< added
  48007. (troop_slot_eq, ":cur_troop", slot_troop_love_interest_2, 0),
  48008. (troop_set_slot, ":cur_troop", slot_troop_love_interest_2, ":cur_lady"),
  48009. (else_try),
  48010. (this_or_next|troop_slot_eq, ":cur_troop", slot_troop_love_interest_3, -1),#< added
  48011. (troop_slot_eq, ":cur_troop", slot_troop_love_interest_3, 0),
  48012. (troop_set_slot, ":cur_troop", slot_troop_love_interest_3, ":cur_lady"),
  48013. (try_end),
  48014. (try_end),
  48015. (try_end),
  48016. (assign, reg1, ":save_reg1"),
  48017. (assign, reg0, ":save_reg0"),#revert register
  48018. ##diplomacy end+
  48019. ]),
  48020.  
  48021. ("faction_conclude_feast",
  48022. [
  48023. (store_script_param, ":faction_no", 1),
  48024. (store_script_param, ":venue", 2),
  48025.  
  48026. (str_store_faction_name, s3, ":faction_no"),
  48027. (str_store_party_name, s4, ":venue"),
  48028.  
  48029. (try_begin),
  48030. (eq, "$cheat_mode", 1),
  48031. (display_message, "str_s3_feast_concludes_at_s4"),
  48032. (try_end),
  48033.  
  48034. (try_begin),
  48035. (eq, ":faction_no", "fac_player_faction"),
  48036. (assign, ":faction_no", "$players_kingdom"),
  48037. (try_end),
  48038.  
  48039. (party_set_slot, ":venue", slot_town_has_tournament, 0),
  48040.  
  48041. #markspot
  48042.  
  48043. (assign, ":nobility_in_faction", 0),
  48044. (assign, ":nobility_in_attendance", 0),
  48045.  
  48046. (try_for_range, ":troop_no", active_npcs_begin, kingdom_ladies_end),
  48047. (store_faction_of_troop, ":troop_faction", ":troop_no"),
  48048. (eq, ":faction_no", ":troop_faction"),
  48049.  
  48050. (val_add, ":nobility_in_faction", 1),
  48051.  
  48052. #CHECK -- is the troop there?
  48053. (troop_slot_eq, ":troop_no", slot_troop_cur_center, ":venue"),
  48054. (val_add, ":nobility_in_attendance", 1),
  48055.  
  48056. #check for marriages
  48057. ##diplomacy start+ enable marriages for non-kingdom ladies (for example, between two companions)
  48058. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_robber_knight),
  48059. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  48060. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_seneschal),
  48061. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_player_companion),
  48062. ##diplomacy end+
  48063. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_lady),
  48064. (troop_get_slot, ":groom", ":troop_no", slot_troop_betrothed),
  48065. (gt, ":groom", 0),
  48066.  
  48067. (troop_get_slot, ":groom_party", ":groom", slot_troop_leaded_party),
  48068. (party_is_active, ":groom_party"),
  48069. (party_get_attached_to, ":groom_party_attached", ":groom_party"),
  48070. (eq, ":groom_party_attached", ":venue"),
  48071.  
  48072. (store_faction_of_troop, ":lady_faction", ":troop_no"),
  48073. (store_faction_of_troop, ":groom_faction", ":groom"),
  48074.  
  48075. (eq, ":groom_faction", ":lady_faction"),
  48076. (eq, ":lady_faction", ":faction_no"),
  48077. (store_current_hours, ":hours_since_betrothal"),
  48078. (troop_get_slot, ":betrothal_time", ":troop_no", slot_troop_betrothal_time),
  48079. (val_sub, ":hours_since_betrothal", ":betrothal_time"),
  48080. (ge, ":hours_since_betrothal", 144), #6 days, should perhaps eventually be 29 days, or 696 yours
  48081.  
  48082. (call_script, "script_get_kingdom_lady_social_determinants", ":troop_no"),
  48083. (assign, ":wedding_venue", reg1),
  48084. ##diplomacy start+ be less picky about where to hold the feast as time goes on
  48085. #(eq, ":venue", ":wedding_venue"),
  48086. (neq, ":troop_no", "trp_player"),
  48087. (neq, ":groom", "trp_player"),
  48088. (party_get_slot, ":town_lord", ":venue", slot_town_lord),
  48089. (assign, ":hold_the_wedding", 0),
  48090. (try_begin),
  48091. #after 6 days, will be held if the venue is the ideal one
  48092. (eq, ":venue", ":wedding_venue"),
  48093. (assign, ":hold_the_wedding", 1),
  48094. (else_try),
  48095. #after 6 days, will be held if the bride's father/guardian holds a feast
  48096. (ge, ":town_lord", 0),
  48097. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_father, ":town_lord"),
  48098. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_mother, ":town_lord"),
  48099. (troop_slot_eq, ":troop_no", slot_troop_guardian, ":town_lord"),
  48100. (assign, ":hold_the_wedding", 1),
  48101. (else_try),
  48102. #after 20 days, will be held if the bride, the groom, or either of their
  48103. #parents hold a feast
  48104. (ge, ":hours_since_betrothal", 24 * 20),
  48105. (ge, ":town_lord", 0),
  48106. (this_or_next|eq, ":troop_no", ":town_lord"),
  48107. (this_or_next|eq, ":groom", ":town_lord"),
  48108. (this_or_next|troop_slot_eq, ":groom", slot_troop_father, ":town_lord"),
  48109. (troop_slot_eq, ":groom", slot_troop_mother, ":town_lord"),
  48110. (assign, ":hold_the_wedding", 1),
  48111. (else_try),
  48112. #after 60 days, if against all odds the engagement hasn't been called off,
  48113. #the faction leader qualifies, as does any relative
  48114. (ge, ":hours_since_betrothal", 24 * 60),
  48115. (ge, ":town_lord", 0),
  48116. #(call_script, "script_troop_get_family_relation_to_troop", ":town_lord", ":troop_no"),
  48117. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":town_lord", ":troop_no"),
  48118. (assign, ":bride_relation", reg0),
  48119. #(call_script, "script_troop_get_family_relation_to_troop", ":town_lord", ":groom"),
  48120. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":town_lord", ":groom"),
  48121. (this_or_next|faction_slot_eq, ":troop_faction", slot_faction_leader, ":town_lord"),
  48122. (this_or_next|ge, reg0, 1),
  48123. (ge, ":bride_relation", 1),
  48124. (assign, ":hold_the_wedding", 1),
  48125. (try_end),
  48126. (eq, ":hold_the_wedding", 1),
  48127. ##diplomacy end+
  48128. (call_script, "script_courtship_event_bride_marry_groom", ":troop_no", ":groom", 0), #parameters from dialog
  48129. (try_end),
  48130.  
  48131.  
  48132. #ssss (assign, ":placeholder_reminder_to_calculate_effect_for_player_feast", 1),
  48133.  
  48134.  
  48135.  
  48136. (party_get_slot, ":feast_host", ":venue", slot_town_lord),
  48137. (assign, ":quality_of_feast", 0),
  48138.  
  48139. (try_begin),
  48140. (check_quest_active, "qst_organize_feast"),
  48141. (quest_slot_eq, "qst_organize_feast", slot_quest_target_center, ":venue"),
  48142. (assign, ":feast_host", "trp_player"),
  48143.  
  48144. (assign, ":total_guests", 400),
  48145.  
  48146. (call_script, "script_succeed_quest", "qst_organize_feast"),
  48147. (call_script, "script_end_quest", "qst_organize_feast"),
  48148.  
  48149. (call_script, "script_internal_politics_rate_feast_to_s9", "trp_household_possessions", ":total_guests", "$players_kingdom", 1),
  48150. (assign, ":quality_of_feast", reg0),
  48151. (else_try),
  48152. (assign, ":quality_of_feast", 60),
  48153. (try_end),
  48154.  
  48155.  
  48156. (try_begin),
  48157. (ge, "$cheat_mode", 1),
  48158. (str_store_troop_name, s4, ":feast_host"),
  48159. (assign, reg4, ":quality_of_feast"),
  48160. (display_message, "@{!}DEBUG - {s4}'s feast has rating of {reg4}"),
  48161. (try_end),
  48162.  
  48163.  
  48164. (try_begin),
  48165. (ge, ":feast_host", 0),
  48166. (store_div, ":renown_boost", ":quality_of_feast", 3),
  48167. (call_script, "script_change_troop_renown", ":feast_host", ":renown_boost"),
  48168.  
  48169. (try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
  48170. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  48171. (troop_get_slot, ":leaded_party", ":troop_no", slot_troop_leaded_party),
  48172. (party_is_active, ":leaded_party"),
  48173. (party_get_attached_to, ":leaded_party_attached", ":leaded_party"),
  48174. (eq, ":leaded_party_attached", ":venue"),
  48175.  
  48176. (assign, ":relation_booster", ":quality_of_feast"),
  48177. (val_div, ":relation_booster", 20),
  48178.  
  48179. (try_begin),
  48180. (eq, ":feast_host", "trp_player"),
  48181. (val_sub, ":relation_booster", 1),
  48182. (val_max, ":relation_booster", 0),
  48183. (try_end),
  48184. (call_script, "script_troop_change_relation_with_troop", ":feast_host", ":troop_no", ":relation_booster"),
  48185. (val_add, "$total_feast_changes", ":relation_booster"),
  48186. (try_end),
  48187. (try_end),
  48188.  
  48189.  
  48190. (assign, reg3, ":nobility_in_attendance"),
  48191. (assign, reg4, ":nobility_in_faction"),
  48192.  
  48193. (try_begin),
  48194. (eq, "$cheat_mode", 1),
  48195. (display_message, "str_attendance_reg3_nobles_out_of_reg4"),
  48196. (try_end),
  48197. ]),
  48198.  
  48199. ("lady_evaluate_troop_as_suitor",
  48200. [
  48201. (store_script_param, ":lady", 1),
  48202. (store_script_param, ":suitor", 2),
  48203.  
  48204. (call_script, "script_troop_get_romantic_chemistry_with_troop", ":lady", ":suitor"),
  48205. (assign, ":romantic_chemistry", reg0),
  48206.  
  48207. (try_begin),
  48208. (call_script, "script_cf_test_lord_incompatibility_to_s17", ":lady", ":suitor"),
  48209. (try_end),
  48210.  
  48211. (store_sub, ":personality_modifier", 0, reg0),
  48212. (assign, reg2, ":personality_modifier"),
  48213.  
  48214. (try_begin),
  48215. (troop_get_slot, ":renown_modifier", ":suitor", slot_troop_renown),
  48216. (val_div, ":renown_modifier", 20),
  48217. (try_begin),
  48218. (this_or_next|troop_slot_eq, ":lady", slot_lord_reputation_type, lrep_conventional),
  48219. (troop_slot_eq, ":lady", slot_lord_reputation_type, lrep_ambitious),
  48220. (val_mul, ":renown_modifier", 2),
  48221. (val_sub, ":renown_modifier", 15),
  48222. (try_end),
  48223. (try_end),
  48224.  
  48225. (store_add, ":final_score", ":renown_modifier", ":personality_modifier"),
  48226. (val_add, ":final_score", ":romantic_chemistry"),
  48227. (assign, reg0, ":final_score"),
  48228. ]),
  48229.  
  48230. ("courtship_event_troop_court_lady",
  48231. [
  48232. (store_script_param, ":suitor", 1),
  48233. (store_script_param, ":lady", 2),
  48234.  
  48235.  
  48236. #(try_begin),
  48237. #(eq, "$cheat_mode", 1),
  48238. #(str_store_troop_name, s4, ":suitor"),
  48239. #(str_store_troop_name, s5, ":lady"),
  48240. #(troop_get_slot, ":lady_location", ":lady", slot_troop_cur_center),
  48241. #(str_store_party_name, s7, ":lady_location"),
  48242. #(display_message, "str_s4_pursues_suit_with_s5_in_s7"),
  48243. #(try_end),
  48244.  
  48245. (troop_get_slot, ":previous_suitor", ":lady", slot_lady_last_suitor),
  48246. (troop_set_slot, ":lady", slot_lady_last_suitor, ":suitor"), #can determine quarrels
  48247.  
  48248. (try_begin),
  48249. (eq, ":previous_suitor", "trp_player"),
  48250.  
  48251. (troop_slot_ge, ":lady", slot_troop_met, 2),
  48252. (call_script, "script_troop_get_relation_with_troop", ":suitor", "trp_player"), #add this to list of quarrels
  48253. (assign, ":suitor_relation_w_player", reg0),
  48254.  
  48255. (try_begin),
  48256. (this_or_next|troop_slot_eq, ":suitor", slot_lord_reputation_type, lrep_selfrighteous),
  48257. (this_or_next|troop_slot_eq, ":suitor", slot_lord_reputation_type, lrep_quarrelsome),
  48258. (troop_slot_eq, ":suitor", slot_lord_reputation_type, lrep_debauched),
  48259. (gt, ":suitor_relation_w_player", -20),
  48260. (call_script, "script_add_log_entry", logent_lords_quarrel_over_woman, ":suitor", "trp_player", ":lady", 0),
  48261. (else_try),
  48262. (is_between, ":suitor_relation_w_player", -5, -25),
  48263. (call_script, "script_add_log_entry", logent_lords_quarrel_over_woman, ":suitor", "trp_player", ":lady", 0),
  48264. (try_end),
  48265. (else_try),
  48266. (neq, ":previous_suitor", "trp_player"), #not the player
  48267.  
  48268. (neq, ":suitor", ":previous_suitor"),
  48269. (ge, ":previous_suitor", active_npcs_begin),
  48270.  
  48271. (call_script, "script_cf_test_lord_incompatibility_to_s17", ":suitor", ":previous_suitor"),
  48272. (call_script, "script_add_log_entry", logent_lords_quarrel_over_woman, ":suitor", ":previous_suitor", ":lady", 0),
  48273.  
  48274. (call_script, "script_troop_get_relation_with_troop", ":suitor", ":previous_suitor"), #add this to list of quarrels
  48275. (ge, reg0, 0),
  48276. (call_script, "script_troop_change_relation_with_troop", ":suitor", ":previous_suitor", -20),
  48277. (val_add, "$total_courtship_quarrel_changes", -20),
  48278. (else_try), #quarrelsome lords quarrel anyway
  48279. (troop_slot_eq, ":suitor", slot_lord_reputation_type, lrep_quarrelsome),
  48280. (neq, ":suitor", ":previous_suitor"),
  48281. (ge, ":previous_suitor", active_npcs_begin),
  48282.  
  48283. # (neq, ":previous_suitor", "trp_player"),
  48284.  
  48285. (call_script, "script_troop_get_relation_with_troop", ":suitor", ":previous_suitor"), #add this to list of quarrels
  48286. (lt, reg0, 10),
  48287. (call_script, "script_add_log_entry", logent_lords_quarrel_over_woman, ":suitor", ":previous_suitor", ":lady", 0),
  48288. (ge, reg0, 0),
  48289. (call_script, "script_troop_change_relation_with_troop", ":suitor", ":previous_suitor", -20),
  48290. (val_add, "$total_courtship_quarrel_changes", -20),
  48291.  
  48292. (try_end),
  48293.  
  48294.  
  48295. # (call_script, "script_troop_get_relation_with_troop", ":lady", ":suitor"),
  48296. # (assign, ":orig_relation", reg0),
  48297.  
  48298. (call_script, "script_lady_evaluate_troop_as_suitor", ":lady", ":suitor"),
  48299.  
  48300. (store_random_in_range, ":random", 5, 16),
  48301. (store_div, ":relationship_change", reg0, ":random"),
  48302.  
  48303. (call_script, "script_troop_get_relation_with_troop", ":lady", ":suitor"),
  48304. (assign, ":orig_relation", reg0),
  48305.  
  48306. (call_script, "script_troop_change_relation_with_troop", ":lady", ":suitor", ":relationship_change"),
  48307.  
  48308. (call_script, "script_troop_get_relation_with_troop", ":lady", ":suitor"),
  48309. (assign, ":lady_suitor_relation", reg0),
  48310.  
  48311. (try_begin),
  48312. (ge, ":lady_suitor_relation", 10),
  48313. (lt, ":orig_relation", 10),
  48314. (call_script, "script_add_log_entry", logent_lady_favors_suitor, ":lady", 0, ":suitor", 0),
  48315.  
  48316. (try_begin),
  48317. (eq, "$cheat_mode", 1),
  48318. (display_message, "str_note__favor_event_logged"),
  48319. (try_end),
  48320.  
  48321. (else_try),
  48322. (this_or_next|lt, ":lady_suitor_relation", -20),
  48323. (ge, ":lady_suitor_relation", 20),
  48324.  
  48325. (call_script, "script_get_kingdom_lady_social_determinants", ":lady"),
  48326. (assign, ":guardian", reg0),
  48327. (call_script, "script_troop_get_relation_with_troop", ":suitor", ":guardian"),
  48328. (assign, ":suitor_guardian_relation", reg0),
  48329. #things come to a head, one way or another
  48330.  
  48331. (assign, ":highest_competitor_lady_score", -1),
  48332. (assign, ":competitor_preferred_by_lady", -1),
  48333.  
  48334. (assign, ":highest_competitor_guardian_score", ":suitor_guardian_relation"),
  48335. (assign, ":competitor_preferred_by_guardian", -1),
  48336.  
  48337. #log potential competitors
  48338. (try_for_range, ":possible_competitor", lords_begin, lords_end),
  48339. (neq, ":possible_competitor", ":suitor"),
  48340.  
  48341. (this_or_next|troop_slot_eq, ":possible_competitor", slot_troop_love_interest_1, ":lady"),
  48342. (this_or_next|troop_slot_eq, ":possible_competitor", slot_troop_love_interest_2, ":lady"),
  48343. (troop_slot_eq, ":possible_competitor", slot_troop_love_interest_3, ":lady"),
  48344.  
  48345. (try_begin),
  48346. (call_script, "script_troop_get_relation_with_troop", ":possible_competitor", ":lady"),
  48347. (gt, reg0, ":highest_competitor_lady_score"),
  48348. (assign, ":competitor_preferred_by_lady", ":possible_competitor"),
  48349. (assign, ":highest_competitor_lady_score", reg0),
  48350. (try_end),
  48351.  
  48352. (try_begin),
  48353. (call_script, "script_troop_get_relation_with_troop", ":possible_competitor", ":guardian"),
  48354. (gt, reg0, ":highest_competitor_guardian_score"),
  48355. (assign, ":competitor_preferred_by_guardian", ":possible_competitor"),
  48356. (assign, ":highest_competitor_guardian_score", reg0),
  48357. (try_end),
  48358. (try_end),
  48359.  
  48360. #RESULTS
  48361. #Guardian forces lady to be betrothed to suitor now
  48362. (try_begin),
  48363. (lt, ":lady_suitor_relation", -20),
  48364. (this_or_next|troop_slot_eq, ":guardian", slot_lord_reputation_type, lrep_selfrighteous),
  48365. (this_or_next|troop_slot_eq, ":guardian", slot_lord_reputation_type, lrep_debauched),
  48366. (troop_slot_eq, ":guardian", slot_lord_reputation_type, lrep_quarrelsome),
  48367. (eq, ":competitor_preferred_by_guardian", -1),
  48368.  
  48369. (this_or_next|troop_slot_eq, ":suitor", slot_lord_reputation_type, lrep_selfrighteous),
  48370. (this_or_next|troop_slot_eq, ":suitor", slot_lord_reputation_type, lrep_debauched),
  48371. (troop_slot_eq, ":suitor", slot_lord_reputation_type, lrep_quarrelsome),
  48372.  
  48373. (troop_slot_eq, ":suitor", slot_troop_betrothed, -1),
  48374. (troop_slot_eq, ":lady", slot_troop_betrothed, -1),
  48375.  
  48376. (call_script, "script_add_log_entry", logent_lady_betrothed_to_suitor_by_family, ":lady", 0, ":suitor", 0),
  48377. (troop_set_slot, ":suitor", slot_troop_betrothed, ":lady"),
  48378. (troop_set_slot, ":lady", slot_troop_betrothed, ":suitor"),
  48379. (store_current_hours, ":hours"),
  48380. (troop_set_slot, ":lady", slot_troop_betrothal_time, ":hours"),
  48381. (troop_set_slot, ":suitor", slot_troop_betrothal_time, ":hours"),
  48382. (try_begin),
  48383. (eq, "$cheat_mode", 1),
  48384. (display_message, "str_result_lady_forced_to_agree_to_engagement"),
  48385. (try_end),
  48386.  
  48387. #Lady rejects the suitor
  48388. (else_try),
  48389. (lt, ":lady_suitor_relation", -20),
  48390.  
  48391. (call_script, "script_add_log_entry", logent_lady_rejects_suitor, ":lady", 0, ":suitor", 0),
  48392. (call_script, "script_courtship_event_lady_break_relation_with_suitor", ":lady", ":suitor"),
  48393. (try_begin),
  48394. (eq, "$cheat_mode", 1),
  48395. (display_message, "str_result_lady_rejects_suitor"),
  48396. (try_end),
  48397.  
  48398. #A happy engagement, with parental blessing
  48399. (else_try),
  48400. (gt, ":lady_suitor_relation", 20),
  48401. (gt, ":suitor_guardian_relation", 0),
  48402. (eq, ":competitor_preferred_by_lady", -1),
  48403.  
  48404. (troop_slot_eq, ":suitor", slot_troop_betrothed, -1),
  48405. (troop_slot_eq, ":lady", slot_troop_betrothed, -1),
  48406.  
  48407. (call_script, "script_add_log_entry", logent_lady_betrothed_to_suitor_by_choice, ":lady", 0, ":suitor", 0),
  48408. (troop_set_slot, ":suitor", slot_troop_betrothed, ":lady"),
  48409. (troop_set_slot, ":lady", slot_troop_betrothed, ":suitor"),
  48410. (store_current_hours, ":hours"),
  48411. (troop_set_slot, ":lady", slot_troop_betrothal_time, ":hours"),
  48412. (troop_set_slot, ":suitor", slot_troop_betrothal_time, ":hours"),
  48413.  
  48414. (try_begin),
  48415. (eq, "$cheat_mode", 1),
  48416. (str_store_troop_name, s4, ":lady"),
  48417. (str_store_troop_name, s5, ":suitor"),
  48418. (display_message, "str_result_happy_engagement_between_s4_and_s5"),
  48419. (try_end),
  48420.  
  48421. #Lady elopes
  48422. (else_try),
  48423. (gt, ":lady_suitor_relation", 20),
  48424.  
  48425. (eq, ":competitor_preferred_by_lady", -1),
  48426. ##diplomacy start+
  48427. ##Fix Native bug, the following line should be checking ":lady", not ":guardian"
  48428. ##OLD:
  48429. #(this_or_next|troop_slot_eq, ":guardian", slot_lord_reputation_type, lrep_adventurous),
  48430. # (troop_slot_eq, ":guardian", slot_lord_reputation_type, lrep_ambitious),
  48431. ##NEW:
  48432. (this_or_next|troop_slot_eq, ":lady", slot_lord_reputation_type, lrep_adventurous),
  48433. (troop_slot_eq, ":lady", slot_lord_reputation_type, lrep_ambitious),
  48434. ##diplomacy end+
  48435.  
  48436. (troop_slot_eq, ":suitor", slot_troop_betrothed, -1),
  48437. (troop_slot_eq, ":lady", slot_troop_betrothed, -1),
  48438.  
  48439. #lady elopes
  48440. (call_script, "script_courtship_event_bride_marry_groom", ":lady", ":suitor", 1),
  48441. #add elopements to quarrel descriptions
  48442.  
  48443. (try_begin),
  48444. (eq, "$cheat_mode", 1),
  48445. (str_store_troop_name, s4, ":lady"),
  48446. (str_store_troop_name, s5, ":suitor"),
  48447. (display_message, "str_result_s4_elopes_with_s5"),
  48448. (try_end),
  48449.  
  48450. #Lady reluctantly agrees to marry under pressure from family
  48451. (else_try),
  48452. (troop_slot_eq, ":lady", slot_lord_reputation_type, lrep_conventional),
  48453. (eq, ":competitor_preferred_by_guardian", -1),
  48454. (gt, ":suitor_guardian_relation", 4),
  48455.  
  48456. (store_random_in_range, ":random", 0, 5),
  48457. (eq, ":random", 0),
  48458.  
  48459. (troop_slot_eq, ":suitor", slot_troop_betrothed, -1),
  48460. (troop_slot_eq, ":lady", slot_troop_betrothed, -1),
  48461.  
  48462. (call_script, "script_add_log_entry", logent_lady_betrothed_to_suitor_by_pressure, ":lady", 0, ":suitor", 0),
  48463. (troop_set_slot, ":suitor", slot_troop_betrothed, ":lady"),
  48464. (troop_set_slot, ":lady", slot_troop_betrothed, ":suitor"),
  48465. (store_current_hours, ":hours"),
  48466. (troop_set_slot, ":lady", slot_troop_betrothal_time, ":hours"),
  48467. (troop_set_slot, ":suitor", slot_troop_betrothal_time, ":hours"),
  48468. (try_begin),
  48469. (eq, "$cheat_mode", 1),
  48470. (str_store_troop_name, s4, ":lady"),
  48471. (str_store_troop_name, s5, ":suitor"),
  48472. (display_message, "str_result_s4_reluctantly_agrees_to_engagement_with_s5"),
  48473. (try_end),
  48474.  
  48475. #Stalemate -- make patience roll
  48476. (else_try),
  48477. (gt, ":lady_suitor_relation", 20),
  48478.  
  48479. (store_random_in_range, reg3, 0, 3),
  48480. (try_begin),
  48481. (eq, "$cheat_mode", 1),
  48482. (display_message, "str_result_stalemate_patience_roll_=_reg3"),
  48483. (try_end),
  48484.  
  48485. (eq, reg3, 0),
  48486. (call_script, "script_add_log_entry", logent_lady_rejected_by_suitor, ":lady", 0, ":suitor", 0),
  48487. (call_script, "script_courtship_event_lady_break_relation_with_suitor", ":lady", ":suitor"),
  48488. (try_end),
  48489.  
  48490. (try_end),
  48491.  
  48492. ]),
  48493.  
  48494.  
  48495.  
  48496. ("courtship_event_lady_break_relation_with_suitor", #parameters from dialog
  48497. [
  48498. (store_script_param, ":lady", 1),
  48499. (store_script_param, ":suitor", 2),
  48500.  
  48501. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  48502. (troop_slot_eq, ":suitor", ":love_interest_slot", ":lady"),
  48503. ##diplomacy start+ set to -1 instead, since 0 is the player (how annoying)
  48504. #(troop_set_slot, ":suitor", ":love_interest_slot", 0),
  48505. (troop_set_slot, ":suitor", ":love_interest_slot", -1),
  48506. ##diplomacy end+
  48507. (try_end),
  48508. (call_script, "script_assign_troop_love_interests", ":suitor"),
  48509.  
  48510. (try_begin),
  48511. (troop_slot_eq, ":lady", slot_troop_betrothed, ":suitor"),
  48512.  
  48513.  
  48514. (troop_set_slot, ":lady", slot_troop_betrothed, -1),
  48515. ##diplomacy start+ perform the same check for the suitor that was done,
  48516. #for the lady, so this script has no unfortunate consequences even if
  48517. #called inappropriately.
  48518. (try_end),
  48519. (try_begin),
  48520. (troop_slot_eq, ":suitor", slot_troop_betrothed, ":lady"),
  48521. (troop_set_slot, ":suitor", slot_troop_betrothed, -1),
  48522. ##diplomacy end+
  48523. (try_end),
  48524.  
  48525.  
  48526. ]),
  48527.  
  48528.  
  48529. ("courtship_event_bride_marry_groom", #parameters from dialog or scripts
  48530. [
  48531. (store_script_param, ":bride", 1),
  48532. (store_script_param, ":groom", 2),
  48533. (store_script_param, ":elopement", 3),
  48534.  
  48535. (try_begin),
  48536. (eq, ":bride", "trp_player"),
  48537. (assign, ":venue", "$g_encountered_party"),
  48538. (else_try),
  48539. (troop_get_slot, ":venue", ":bride", slot_troop_cur_center),
  48540. ##diplomacy start+
  48541. #Ensure there is a venue.
  48542. (lt, ":venue", 1),
  48543. (troop_get_slot, ":venue", ":groom", slot_troop_cur_center),
  48544. ##diplomacy end+
  48545. (try_end),
  48546.  
  48547. (store_faction_of_troop, ":groom_faction", ":groom"),
  48548.  
  48549.  
  48550. (try_begin),
  48551. (eq, ":elopement", 0),
  48552. (call_script, "script_add_log_entry", logent_lady_marries_suitor, ":bride", ":venue", ":groom", 0),
  48553. (else_try),
  48554. (call_script, "script_add_log_entry", logent_lady_elopes_with_lord, ":bride", ":venue", ":groom", 0),
  48555. (try_end),
  48556.  
  48557. (str_store_troop_name, s3, ":bride"),
  48558. (str_store_troop_name, s4, ":groom"),
  48559. (str_store_party_name, s5, ":venue"),
  48560.  
  48561. (try_begin),
  48562. ##diplomacy start+ this should be globally-visible for notable personages
  48563. # (this_or_next|is_between, ":groom_faction", kingdoms_begin, kingdoms_end),
  48564. # (this_or_next|troop_slot_ge, ":groom", slot_troop_met, 1),
  48565. # (troop_slot_ge, ":bride", slot_troop_met, 1),
  48566. (display_log_message, "str_s3_marries_s4_at_s5"),
  48567. #(else_try),
  48568. # (eq, "$cheat_mode", 1),
  48569. # (display_message, "str_s3_marries_s4_at_s5"),
  48570. ##diplomacy end+
  48571. (try_end),
  48572.  
  48573. (troop_set_slot, ":bride", slot_troop_spouse, ":groom"),
  48574. (troop_set_slot, ":groom", slot_troop_spouse, ":bride"),
  48575.  
  48576. #Break groom's romantic relations
  48577. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  48578. (troop_set_slot, ":groom", ":love_interest_slot", 0),
  48579. (try_end),
  48580.  
  48581. #Break bride's romantic relations
  48582. (try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
  48583. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  48584. (troop_slot_eq, ":active_npc", ":love_interest_slot", ":bride"),
  48585. (call_script, "script_courtship_event_lady_break_relation_with_suitor", ":bride", ":active_npc"),
  48586. (try_end),
  48587. (try_end),
  48588.  
  48589.  
  48590.  
  48591. (troop_set_slot, ":bride", slot_troop_betrothed, -1),
  48592. (troop_set_slot, ":groom", slot_troop_betrothed, -1),
  48593.  
  48594.  
  48595.  
  48596. #change relations with family
  48597. ##diplomacy start+ Include kingdom ladies
  48598. #(try_for_range, ":family_member", lords_begin, lords_end),
  48599. (try_for_range, ":family_member", heroes_begin, heroes_end),
  48600. (neq, ":family_member", ":bride"),
  48601. (neq, ":family_member", ":groom"),
  48602. ##diplomacy end+
  48603. (call_script, "script_troop_get_family_relation_to_troop", ":bride", ":family_member"),
  48604. (gt, reg0, 0),
  48605. (store_div, ":family_relation_boost", reg0, 3),
  48606. (try_begin),
  48607. (eq, ":elopement", 1),
  48608. (val_mul, ":family_relation_boost", -2),
  48609. (try_end),
  48610. ##diplomacy start+ Fix error! Change relation between groom and family member, not groom and bride.
  48611. #(call_script, "script_troop_change_relation_with_troop", ":groom", ":bride", ":family_relation_boost"),
  48612. (call_script, "script_troop_change_relation_with_troop", ":groom", ":family_member", ":family_relation_boost"),
  48613. ##diplomacy end+
  48614. (val_add, "$total_courtship_quarrel_changes", ":family_relation_boost"),
  48615. (try_end),
  48616.  
  48617. (try_begin),
  48618. (this_or_next|eq, ":groom", "trp_player"),
  48619. (eq, ":bride", "trp_player"),
  48620. ##diplomacy start+ fix bug where player didn't get right to rule
  48621. (call_script, "script_change_player_right_to_rule", 15),##one argument, not two
  48622. ##diplomacy end+
  48623. (try_end),
  48624.  
  48625.  
  48626. (try_begin),
  48627. (eq, ":groom", "trp_player"),
  48628. (check_quest_active, "qst_wed_betrothed"),
  48629. (call_script, "script_succeed_quest", "qst_wed_betrothed"),
  48630. (call_script, "script_end_quest", "qst_wed_betrothed"),
  48631. (try_end),
  48632.  
  48633.  
  48634. (try_begin),
  48635. (check_quest_active, "qst_visit_lady"),
  48636. (quest_slot_eq, "qst_visit_lady", slot_quest_giver_troop, ":bride"),
  48637. (call_script, "script_abort_quest", "qst_visit_lady", 0),
  48638. (try_end),
  48639.  
  48640.  
  48641. (try_begin),
  48642. (eq, ":groom", "trp_player"),
  48643. (check_quest_active, "qst_visit_lady"),
  48644. (call_script, "script_abort_quest", "qst_visit_lady", 0),
  48645. (try_end),
  48646. (try_begin),
  48647. (eq, ":groom", "trp_player"),
  48648. (check_quest_active, "qst_duel_courtship_rival"),
  48649. (call_script, "script_abort_quest", "qst_duel_courtship_rival", 0),
  48650. (try_end),
  48651.  
  48652.  
  48653. (try_begin),
  48654. (eq, ":bride", "trp_player"),
  48655. (call_script, "script_player_join_faction", ":groom_faction"),
  48656. (assign, "$player_has_homage", 1),
  48657. (else_try),
  48658. (eq, ":groom", "trp_player"),
  48659.  
  48660. (try_begin),
  48661. (ge, "$cheat_mode", 1),
  48662. (str_store_troop_name, s4, ":bride"),
  48663. (display_message, "@{!} DEBUG - {s4} faction change in marriage case 5"),
  48664. (try_end),
  48665. (troop_set_faction, ":bride", "$players_kingdom"),
  48666. (else_try),
  48667.  
  48668. (try_begin),
  48669. (ge, "$cheat_mode", 1),
  48670. (str_store_troop_name, s4, ":bride"),
  48671. (display_message, "@{!}DEBUG - {s4} faction changed by marriage, case 6"),
  48672. (try_end),
  48673.  
  48674. (troop_set_faction, ":bride", ":groom_faction"),
  48675. (try_end),
  48676.  
  48677. (try_begin),
  48678. (this_or_next|eq, ":groom", "trp_player"),
  48679. (eq, ":bride", "trp_player"),
  48680. (unlock_achievement, ACHIEVEMENT_HAPPILY_EVER_AFTER),
  48681. (try_begin),
  48682. (eq, ":elopement", 1),
  48683. (unlock_achievement, ACHIEVEMENT_HEART_BREAKER),
  48684. (try_end),
  48685. (try_end),
  48686.  
  48687.  
  48688.  
  48689. (try_begin),
  48690. (this_or_next|eq, ":groom", "trp_player"),
  48691. (eq, ":bride", "trp_player"),
  48692. #(eq, ":elopement", 0),
  48693. (call_script, "script_start_wedding_cutscene", ":groom", ":bride"),
  48694. (try_end),
  48695. ]),
  48696.  
  48697.  
  48698. #script_npc_decision_checklist_party_ai
  48699. # DECISION CHECKLISTS (OCT 14)
  48700. # I was thinking of trying to convert as much AI decision-making as possible to the checklist format
  48701. # While outcomes are not as nuanced and varied as a random decision using weighted chances for each outcoms,
  48702. # the checklist has the advantage of being much more transparent, both to developers and to players
  48703. # The checklist can yield a string (standardized to s14) which explains the rationale for the decision
  48704. # When the script yields a yes/no/maybe result, than that is standardized from -3 to +3
  48705. # INPUT: troop_no
  48706. # OUTPUT: none
  48707. ("npc_decision_checklist_party_ai",
  48708. [
  48709. #this script can replace decide_kingdom_hero_ai and decide_kingdom_hero_ai_follow_or_not
  48710. #However, it does not contain script_party_set_ai_state
  48711.  
  48712. (store_script_param, ":troop_no", 1),
  48713.  
  48714. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  48715. #(party_get_slot, ":our_strength", ":party_no", slot_party_cached_strength),
  48716. #(store_div, ":min_strength_behind", ":our_strength", 2),
  48717. #(party_get_slot, ":our_follower_strength", ":party_no", slot_party_follower_strength),
  48718.  
  48719. (try_begin),
  48720. (eq, "$cheat_mode", 1),
  48721. (assign, "$g_talk_troop", ":troop_no"),
  48722. (try_end),
  48723.  
  48724. (store_troop_faction, ":faction_no", ":troop_no"),
  48725. ##diplomacy start+
  48726. #Get the centralization value for use below. It should be a value in [-3,3].
  48727. #A centralization value of 0 should not result in any behavior change.
  48728. (try_begin),
  48729. #If the player altered the kingdom policy, always apply its effects to
  48730. #the AI of his kingdom's lords.
  48731. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", ":faction_no"),
  48732. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  48733. (faction_get_slot, ":centralization", ":faction_no", dplmc_slot_faction_centralization),
  48734. (val_clamp, ":centralization", -3, 4),
  48735. (else_try),
  48736. #Currently, do not apply centralization to the AI for NPC kingdoms, since
  48737. #NPC rulers set their policies randomly and do not gain the same monthly
  48738. #relation bonuses/penalties from centralization that the player does.
  48739. (assign, ":centralization", 0),
  48740. (try_end),
  48741. ##diplomacy end+
  48742.  
  48743. (try_begin),
  48744. (eq, ":troop_no", "$g_talk_troop"),
  48745. (str_store_string, s15, "str__i_must_attend_to_this_matter_before_i_worry_about_the_affairs_of_the_realm"),
  48746. (try_end),
  48747.  
  48748. #find current center
  48749. (party_get_attached_to, ":cur_center_no", ":party_no"),
  48750. (try_begin),
  48751. (lt, ":cur_center_no", 0),
  48752. (party_get_cur_town, ":cur_center_no", ":party_no"),
  48753. (try_end),
  48754. (assign, ":besieger_party", -1),
  48755. (try_begin),
  48756. (neg|is_between, ":cur_center_no", centers_begin, centers_end),
  48757. (assign, ":cur_center_no", -1),
  48758. (else_try),
  48759. (party_get_slot, ":besieger_party", ":cur_center_no", slot_center_is_besieged_by),
  48760. (try_begin),
  48761. (neg|party_is_active, ":besieger_party"),
  48762. (assign, ":besieger_party", -1),
  48763. (try_end),
  48764. (try_end),
  48765.  
  48766. #party_count
  48767. (call_script, "script_party_count_fit_for_battle", ":party_no"),
  48768. (assign, ":party_fit_for_battle", reg0),
  48769. (call_script, "script_party_get_ideal_size", ":party_no"),
  48770. (assign, ":ideal_size", reg0),
  48771. (store_mul, ":party_strength_as_percentage_of_ideal", ":party_fit_for_battle", 100),
  48772. (val_div, ":party_strength_as_percentage_of_ideal", ":ideal_size"),
  48773. (try_begin),
  48774. (faction_slot_eq, ":faction_no", slot_faction_num_towns, 0),
  48775. (faction_slot_eq, ":faction_no", slot_faction_num_castles, 0),
  48776. (assign, ":party_ratio_of_prisoners", 0), #do not let prisoners have an effect on ai calculation
  48777. (else_try),
  48778. (party_get_num_prisoners, ":num_prisoners", ":party_no"),
  48779. (val_max, ":party_fit_for_battle", 1), #avoid division by zero error
  48780. (store_div, ":party_ratio_of_prisoners", ":num_prisoners", ":party_fit_for_battle"),
  48781. (try_end),
  48782.  
  48783. (assign, ":faction_is_at_war", 0),
  48784. (try_for_range, ":kingdom", kingdoms_begin, kingdoms_end),
  48785. (faction_slot_eq, ":kingdom", slot_faction_state, sfs_active),
  48786. (store_relation, ":relation", ":faction_no", ":kingdom"),
  48787. (lt, ":relation", 0),
  48788. (assign, ":faction_is_at_war", 1),
  48789. (try_end),
  48790.  
  48791. (assign, ":operation_in_progress", 0),
  48792. (try_begin),
  48793. (this_or_next|party_slot_eq, ":party_no", slot_party_ai_state, spai_raiding_around_center),
  48794. (party_slot_eq, ":party_no", slot_party_ai_state, spai_besieging_center),
  48795.  
  48796. (party_get_slot, ":target_center", ":party_no", slot_party_ai_object),
  48797. (is_between, ":target_center", centers_begin, centers_end),
  48798.  
  48799. (store_faction_of_party, ":target_center_faction", ":target_center"),
  48800. (store_relation, ":relation", ":faction_no", ":target_center_faction"),
  48801. (lt, ":relation", 0),
  48802.  
  48803. (store_distance_to_party_from_party, ":distance", ":party_no", ":target_center"),
  48804. (lt, ":distance", 10),
  48805. (this_or_next|party_slot_eq, ":target_center", slot_village_state, svs_under_siege),
  48806. (this_or_next|party_slot_eq, ":target_center", slot_village_state, svs_normal),
  48807. (party_slot_eq, ":target_center", slot_village_state, svs_being_raided),
  48808.  
  48809. (assign, ":operation_in_progress", 1),
  48810. (try_end),
  48811.  
  48812. (troop_get_slot, ":troop_reputation", ":troop_no", slot_lord_reputation_type),
  48813.  
  48814. (party_get_slot, ":old_ai_state", ":party_no", slot_party_ai_state),
  48815. (party_get_slot, ":old_ai_object", ":party_no", slot_party_ai_object),
  48816.  
  48817. (party_get_slot, ":party_cached_strength", ":party_no", slot_party_cached_strength),
  48818.  
  48819. (store_current_hours, ":hours_since_last_rest"),
  48820. (party_get_slot, ":last_rest_time", ":party_no", slot_party_last_in_any_center),
  48821. (val_sub, ":hours_since_last_rest", ":last_rest_time"),
  48822.  
  48823. (store_current_hours, ":hours_since_last_home"),
  48824. (party_get_slot, ":last_home_time", ":party_no", slot_party_last_in_home_center),
  48825. (val_sub, ":hours_since_last_home", ":last_home_time"),
  48826.  
  48827. (store_current_hours, ":hours_since_last_combat"),
  48828. (party_get_slot, ":last_combat_time", ":party_no", slot_party_last_in_combat),
  48829. (val_sub, ":hours_since_last_combat", ":last_combat_time"),
  48830.  
  48831. (store_current_hours, ":hours_since_last_courtship"),
  48832. (party_get_slot, ":last_courtship_time", ":party_no", slot_party_leader_last_courted),
  48833. (val_sub, ":hours_since_last_courtship", ":last_courtship_time"),
  48834.  
  48835. (troop_get_slot, ":temp_ai_seed", ":troop_no", slot_troop_temp_decision_seed),
  48836. (store_mod, ":aggressiveness", ":temp_ai_seed", 73), #To derive the
  48837. (try_begin),
  48838. (eq, ":troop_reputation", lrep_martial),
  48839. (val_add, ":aggressiveness", 27),
  48840. (else_try),
  48841. (neq, ":troop_reputation", lrep_debauched),
  48842. (neq, ":troop_reputation", lrep_quarrelsome),
  48843. (val_add, ":aggressiveness", 14),
  48844. (try_end),
  48845.  
  48846. (try_begin),
  48847. (gt, ":aggressiveness", ":hours_since_last_combat"),
  48848. (val_add, ":aggressiveness", ":hours_since_last_combat"),
  48849. (val_div, ":aggressiveness", 2),
  48850. (try_end),
  48851.  
  48852. (try_begin),
  48853. (eq, "$cheat_mode", 1), #100
  48854. (eq, ":troop_no", "$g_talk_troop"),
  48855. (str_store_troop_name, s4, ":troop_no"),
  48856. (assign, reg3, ":hours_since_last_rest"),
  48857. (assign, reg4, ":hours_since_last_courtship"),
  48858. (assign, reg5, ":hours_since_last_combat"),
  48859. (assign, reg6, ":hours_since_last_home"),
  48860. (assign, reg7, ":aggressiveness"),
  48861. #(display_message, "@{!}{s4}: hours since rest {reg3}, courtship {reg4}, combat {reg5}, home {reg6}, aggressiveness {reg7}"),
  48862. (try_end),
  48863.  
  48864. ##I am inspecting an estate (use slot_center_npc_volunteer_troop_amount)
  48865.  
  48866. (str_store_string, s17, "str_the_other_matter_took_precedence"),
  48867.  
  48868. (assign, ":do_only_collecting_rents", 0),
  48869.  
  48870. #Wait in current city (dangerous to travel with less (<=10) men)
  48871. (try_begin),
  48872. #NOTE : I added also this condition to very top of list. Because if this condition does not exists in top then a bug happens.
  48873. #Bug is about alone wounded lords without any troop near him travels between cities, sometimes it want to return his home city
  48874. #to collect reinforcements, sometimes it want to patrol ext, but his party is so weak even without anyone. So we sometimes see
  48875. #(0/1) parties in map with only one wounded lord inside. Because after wars completely defeated lords spawn again in a walled center
  48876. #in 48 hours periods (by codes in module_simple_trigers). He spawns with only wounded himself. Then he should wait in there for
  48877. #a time to collect new men to his (0/1) party. If a lord is the only one in his party and if he is at any walled center already then he
  48878. #should stay where he is. He should not travel to anywhere because of any reason. If he is the only one and he is wounded and
  48879. #he is not in any walled center this means this situation happens because of one another bug, because any lord cannot be out of
  48880. #walled centers with wounded himself only. So I am adding this condition below.
  48881.  
  48882. #SUMMARY : If lord has not got enought troops (<10 || <10%) with himself and he is currently at a walled center he should not leave
  48883. #his current center because of any reason.
  48884.  
  48885. (ge, ":cur_center_no", 0),
  48886.  
  48887. (this_or_next|le, ":party_fit_for_battle", 10),
  48888. (le, ":party_strength_as_percentage_of_ideal", 30),
  48889.  
  48890. (assign, ":action", spai_holding_center),
  48891. (assign, ":object", ":cur_center_no"),
  48892.  
  48893. (try_begin),
  48894. (eq, ":troop_no", "$g_talk_troop"),
  48895. (str_store_string, s14, "str_i_need_to_raise_some_men_before_attempting_anything_else"),
  48896. (str_store_string, s16, "str_i_need_to_raise_some_men_before_attempting_anything_else"),
  48897. (try_end),
  48898.  
  48899. #Stand in a siege
  48900. (else_try),
  48901. (gt, ":besieger_party", -1),
  48902.  
  48903. (assign, ":action", spai_holding_center),
  48904. (assign, ":object", ":cur_center_no"),
  48905.  
  48906. (try_begin),
  48907. (eq, ":troop_no", "$g_talk_troop"),
  48908. (str_store_string, s14, "str_i_cannot_leave_this_fortress_now_as_it_is_under_siege"),
  48909. (str_store_string, s16, "str_after_all_we_are_under_siege"),
  48910. (try_end),
  48911.  
  48912. #Continue retreat to walled center
  48913. (else_try),
  48914. (eq, ":old_ai_state", spai_retreating_to_center),
  48915. (neg|party_is_in_any_town, ":party_no"),
  48916.  
  48917. (ge, ":old_ai_object", 0),
  48918. (party_is_active, ":old_ai_object"),
  48919.  
  48920. (store_faction_of_party, ":retreat_center_faction", ":old_ai_object"),
  48921. (eq, ":faction_no", ":retreat_center_faction"),
  48922.  
  48923. (assign, ":action", spai_retreating_to_center),
  48924. (assign, ":object", ":old_ai_object"),
  48925.  
  48926. (try_begin),
  48927. (eq, ":troop_no", "$g_talk_troop"),
  48928. (str_store_string, s14, "str_we_are_not_strong_enough_to_face_the_enemy_out_in_the_open"),
  48929. (str_store_string, s16, "str_i_should_probably_seek_shelter_behind_some_stout_walls"),
  48930. (try_end),
  48931.  
  48932. #Stand by in current center against enemies
  48933. (else_try),
  48934. (is_between, ":cur_center_no", walled_centers_begin, walled_centers_end),
  48935.  
  48936. (party_get_slot, ":enemy_strength_in_area", ":cur_center_no", slot_center_sortie_enemy_strength),
  48937. (party_get_slot, ":enemy_strength_in_area", ":cur_center_no", slot_center_sortie_enemy_strength),
  48938. (ge, ":enemy_strength_in_area", 50),
  48939.  
  48940. (assign, ":action", spai_holding_center),
  48941. (assign, ":object", ":cur_center_no"),
  48942. (try_begin),
  48943. (eq, ":troop_no", "$g_talk_troop"),
  48944. (str_store_string, s14, "str_enemies_are_reported_to_be_nearby_and_we_should_stand_ready_to_either_man_the_walls_or_sortie_out_to_do_battle"),
  48945. (str_store_string, s16, "str_the_enemy_is_nearby"),
  48946. (try_end),
  48947.  
  48948. #As the marshall, lead faction campaign
  48949. (else_try),
  48950. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  48951. (str_clear, s15), #Does not say that overrides faction orders
  48952. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_gathering_army),
  48953.  
  48954. (party_set_ai_initiative, ":party_no", 10),
  48955.  
  48956. #new ozan added - active gathering
  48957. #this code will allow marshal to travel around cities while gathering army if currently collected are less than 60%.
  48958. #By ratio increases travel distances become less. Travels will be only points around walled centers.
  48959. (party_get_slot, ":old_ai_object", ":party_no", slot_party_ai_object),
  48960. (assign, ":travel_target", ":old_ai_object"),
  48961.  
  48962. (call_script, "script_find_center_to_defend", ":troop_no"),
  48963. (assign, ":most_threatened_center", reg0),
  48964. (assign, ":travel_target_new_assigned", 0),
  48965.  
  48966. (try_begin),
  48967. (lt, ":old_ai_object", 0),
  48968.  
  48969. (store_random_in_range, ":random_value", 0, 8), #to eanble marshal to wait sometime during active gathering
  48970. (this_or_next|eq, "$g_gathering_new_started", 1),
  48971. (eq, ":random_value", 0),
  48972.  
  48973. (assign, ":vassals_already_assembled", 0),
  48974. (assign, ":total_vassals", 0),
  48975. (try_for_range, ":lord", active_npcs_begin, active_npcs_end),
  48976. (store_faction_of_troop, ":lord_faction", ":lord"),
  48977. (eq, ":lord_faction", ":faction_no"),
  48978. (troop_get_slot, ":led_party", ":lord", slot_troop_leaded_party),
  48979. (party_is_active, ":led_party"),
  48980. (val_add, ":total_vassals", 1),
  48981.  
  48982. (party_slot_eq, ":led_party", slot_party_ai_state, spai_accompanying_army),
  48983. (party_slot_eq, ":led_party", slot_party_ai_object, ":party_no"),
  48984.  
  48985. (party_is_active, ":party_no"),
  48986. (store_distance_to_party_from_party, ":distance_to_marshal", ":led_party", ":party_no"),
  48987. (lt, ":distance_to_marshal", 15),
  48988. (val_add, ":vassals_already_assembled", 1),
  48989. (try_end),
  48990.  
  48991. (assign, ":ratio_of_vassals_assembled", -1),
  48992. (try_begin),
  48993. (gt, ":total_vassals", 0),
  48994. (store_mul, ":ratio_of_vassals_assembled", ":vassals_already_assembled", 100),
  48995. (val_div, ":ratio_of_vassals_assembled", ":total_vassals"),
  48996. (try_end),
  48997.  
  48998. (try_begin),
  48999. #if more than 35% of vassals already collected do not make any more active gathering, just hold and wait last vassals to participate.
  49000. (le, ":ratio_of_vassals_assembled", 35),
  49001.  
  49002. (assign, ":best_center_to_travel", ":most_threatened_center"),
  49003.  
  49004. (try_begin),
  49005. (eq, "$g_gathering_new_started", 1),
  49006.  
  49007. (assign, ":minimum_distance", 100000),
  49008. (try_for_range, ":center_no", centers_begin, centers_end),
  49009. (store_faction_of_party, ":center_faction", ":center_no"),
  49010. (eq, ":center_faction", ":faction_no"), #200
  49011. (try_begin),
  49012. (neq, ":center_no", ":most_threatened_center"),
  49013. (store_distance_to_party_from_party, ":dist", ":party_no", ":center_no"),
  49014. (lt, ":dist", ":minimum_distance"),
  49015. (assign, ":minimum_distance", ":dist"),
  49016. (assign, ":best_center_to_travel", ":center_no"),
  49017. (try_end),
  49018. (try_end),
  49019. (else_try),
  49020. #active gathering
  49021. (assign, ":max_travel_distance", 150),
  49022. (try_begin),
  49023. (ge, ":ratio_of_vassals_assembled",15),
  49024. (store_sub, ":max_travel_distance", 35, ":ratio_of_vassals_assembled"),
  49025. (val_add, ":max_travel_distance", 5), #5..25
  49026. (val_mul, ":max_travel_distance", 6), #30..150
  49027. (try_end),
  49028.  
  49029. (try_begin),
  49030. (ge, ":most_threatened_center", 0),
  49031. (store_distance_to_party_from_party, reg12, ":party_no", ":most_threatened_center"),
  49032. (else_try),
  49033. (assign, reg12, 0),
  49034. (try_end),
  49035.  
  49036. (assign, ":num_centers", 0),
  49037. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  49038. (store_faction_of_party, ":center_faction", ":center_no"),
  49039. (eq, ":center_faction", ":faction_no"),
  49040. (try_begin),
  49041. #(ge, ":max_travel_distance", 0),
  49042. (store_distance_to_party_from_party, ":dist", ":party_no", ":center_no"),
  49043.  
  49044. (try_begin),
  49045. (ge, ":most_threatened_center", 0),
  49046. (store_distance_to_party_from_party, reg13, ":center_no", ":most_threatened_center"),
  49047. (else_try),
  49048. (assign, reg13, 0),
  49049. (try_end),
  49050.  
  49051. (store_sub, reg11, reg13, reg12),
  49052.  
  49053. (this_or_next|ge, reg11, 40),
  49054. (this_or_next|ge, ":dist", ":max_travel_distance"),
  49055. (eq, ":center_no", ":most_threatened_center"),
  49056. (else_try),
  49057. #this center is a candidate so increase num_centers by one.
  49058. (val_add, ":num_centers", 1),
  49059. (try_end),
  49060. (try_end),
  49061.  
  49062. (try_begin),
  49063. (ge, ":num_centers", 0),
  49064. (store_random_in_range, ":random_center_no", 0, ":num_centers"),
  49065. (val_add, ":random_center_no", 1),
  49066. (assign, ":num_centers", 0),
  49067. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  49068. (store_faction_of_party, ":center_faction", ":center_no"),
  49069. (eq, ":center_faction", ":faction_no"),
  49070. (try_begin),
  49071. (neq, ":center_no", ":most_threatened_center"),
  49072. (store_distance_to_party_from_party, ":dist", ":party_no", ":center_no"),
  49073. (lt, ":dist", ":max_travel_distance"),
  49074.  
  49075. (try_begin),
  49076. (ge, ":most_threatened_center", 0),
  49077. (store_distance_to_party_from_party, reg13, ":center_no", ":most_threatened_center"),
  49078. (else_try),
  49079. (assign, reg13, 0),
  49080. (try_end),
  49081.  
  49082. (store_sub, reg11, reg13, reg12),
  49083. (lt, reg11, 40),
  49084.  
  49085. (val_sub, ":random_center_no", 1),
  49086. (eq, ":random_center_no", 0),
  49087. (assign, ":best_center_to_travel", ":center_no"),
  49088. (try_end),
  49089. (try_end),
  49090. (try_end),
  49091. (try_end),
  49092.  
  49093. (assign, ":travel_target", ":best_center_to_travel"),
  49094. (assign, ":travel_target_new_assigned", 1),
  49095. (try_end),
  49096. (else_try),
  49097. #if party has an ai object and they are close to that object while gathering army,
  49098. #forget that ai object so they will select a new ai object next.
  49099. (is_between, ":old_ai_object", centers_begin, centers_end),
  49100. (party_get_position, pos1, ":party_no"),
  49101. (party_get_position, pos2, ":old_ai_object"),
  49102. (get_distance_between_positions, ":dist", pos1, pos2),
  49103. (le, ":dist", 3),
  49104. (assign, ":travel_target", -1),
  49105. (try_end),
  49106. #end ozan
  49107.  
  49108. (try_begin),
  49109. (eq, ":travel_target", -1),
  49110. (assign, ":action", spai_undefined),
  49111. (else_try),
  49112. (assign, ":action", spai_visiting_village),
  49113. (try_end),
  49114.  
  49115. (assign, ":object", ":travel_target"),
  49116.  
  49117. (try_begin),
  49118. (eq, ":troop_no", "$g_talk_troop"),
  49119. (try_begin),
  49120. (eq, ":travel_target", -1),
  49121. (str_store_string, s14, "str_as_the_marshall_i_am_assembling_the_army_of_the_realm"),
  49122. (else_try),
  49123. (try_begin),
  49124. (eq, ":faction_no", "$players_kingdom"),
  49125. (eq, ":travel_target_new_assigned", 1),
  49126. (le, "$number_of_report_to_army_quest_notes", 13),
  49127. (check_quest_active, "qst_report_to_army"),
  49128. (str_store_party_name_link, s10, ":travel_target"),
  49129.  
  49130. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall), #300
  49131.  
  49132. (str_store_troop_name_link, s11, ":faction_marshal"),
  49133. (store_current_hours, ":hours"),
  49134. (call_script, "script_game_get_date_text", 0, ":hours"),
  49135.  
  49136. (str_store_string, s14, "str_as_the_marshall_i_am_assembling_the_army_of_the_realm_and_travel_to_lands_near_s10_to_inform_more_vassals"),
  49137. (str_store_string, s14, "@({s1}) {s11}: {s14}"),
  49138. (add_quest_note_from_sreg, "qst_report_to_army", "$number_of_report_to_army_quest_notes", s14, 0),
  49139. (val_add, "$number_of_report_to_army_quest_notes", 1),
  49140. (try_end),
  49141.  
  49142. (assign, reg0, ":travel_target"),
  49143. (str_store_party_name, s10, ":travel_target"),
  49144. (str_store_string, s14, "str_as_the_marshall_i_am_assembling_the_army_of_the_realm_and_travel_to_lands_near_s10_to_inform_more_vassals"),
  49145. (try_end),
  49146. (str_store_string, s16, "str_i_intend_to_assemble_the_army_of_the_realm"),
  49147. (try_end),
  49148. (else_try),
  49149. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  49150. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_center),
  49151. (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
  49152.  
  49153. (assign, ":action", spai_besieging_center),
  49154. (assign, ":object", ":faction_object"),
  49155. (try_begin),
  49156. (eq, ":troop_no", "$g_talk_troop"),
  49157. (str_store_string, s14, "str_as_the_marshall_i_am_leading_the_siege"),
  49158. (str_store_string, s16, "str_i_intend_to_begin_the_siege"),
  49159. (try_end),
  49160.  
  49161. (else_try),
  49162. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  49163. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_raiding_village),
  49164. (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
  49165.  
  49166. (assign, ":action", spai_raiding_around_center),
  49167. (assign, ":object", ":faction_object"),
  49168. (try_begin),
  49169. (eq, ":troop_no", "$g_talk_troop"),
  49170. (str_store_string, s14, "str_as_the_marshall_i_am_leading_our_raid"),
  49171. (str_store_string, s16, "str_i_intend_to_start_our_raid"),
  49172. (try_end),
  49173.  
  49174. (else_try),
  49175. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  49176. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemies_around_center),
  49177. (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
  49178. (party_is_active, ":faction_object"),
  49179.  
  49180. #moved (party_set_ai_initiative, ":party_no", 10), #new to avoid losing time of marshal with attacking unimportant targets while there is a threat in our centers.
  49181.  
  49182. (party_get_battle_opponent, ":besieger_party", ":faction_object"),
  49183.  
  49184. (try_begin),
  49185. (gt, ":besieger_party", 0),
  49186. (party_is_active, ":besieger_party"),
  49187.  
  49188. (assign, ":action", spai_engaging_army),
  49189. (assign, ":object", ":besieger_party"),
  49190. (try_begin),
  49191. (eq, ":troop_no", "$g_talk_troop"),
  49192. (str_store_string, s14, "str_as_the_marshall_i_am_leading_our_forces_to_engage_the_enemy_in_battle"),
  49193. (str_store_string, s16, "str_i_intend_to_lead_our_forces_out_to_engage_the_enemy"),
  49194. (try_end),
  49195. (else_try),
  49196. (assign, ":action", spai_patrolling_around_center),
  49197. (assign, ":object", ":faction_object"),
  49198. (try_begin),
  49199. (eq, ":troop_no", "$g_talk_troop"),
  49200. (str_store_string, s14, "str_as_the_marshall_i_am_leading_our_forces_in_search_of_the_enemy"),
  49201. (str_store_string, s16, "str_i_intend_to_lead_our_forces_out_to_find_the_enemy"),
  49202. (try_end),
  49203. (try_end),
  49204.  
  49205. (else_try),
  49206. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  49207. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemy_army),
  49208. (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
  49209. (party_is_active, ":faction_object"),
  49210.  
  49211. (assign, ":action", spai_engaging_army),
  49212. (assign, ":object", ":faction_object"),
  49213. (try_begin),
  49214. (eq, ":troop_no", "$g_talk_troop"),
  49215. (str_store_string, s14, "str_as_the_marshall_i_am_leading_our_forces_to_engage_the_enemy_in_battle"),
  49216. (str_store_string, s16, "str_i_intend_to_lead_our_forces_out_to_engage_the_enemy"),
  49217. (try_end),
  49218.  
  49219. #Get reinforcements
  49220. (else_try),
  49221. (assign, ":lowest_acceptable_strength_percentage", 30),
  49222.  
  49223. #if troop has enought gold then increase by 10%
  49224. #(troop_get_slot, ":cur_wealth", ":troop_no", slot_troop_wealth),
  49225. #(try_begin),
  49226. # (ge, ":cur_wealth", 2000),
  49227. # (assign, ":wealth_addition", 10),
  49228. #(else_try),
  49229. # (store_div, ":wealth_addition", ":cur_wealth", 200),
  49230. #(try_end),
  49231. #(val_add, ":lowest_acceptable_strength_percentage", ":wealth_addition"),
  49232.  
  49233. (call_script, "script_lord_get_home_center", ":troop_no"),
  49234. (assign, ":home_center", reg0),
  49235. (gt, ":home_center", -1),
  49236. (party_slot_eq, ":home_center", slot_town_lord, ":troop_no"), #newly added
  49237.  
  49238. #if troop is very close to its home center increase by 20%
  49239. (assign, ":distance_addition", 0),
  49240. (party_get_position, pos0, ":home_center"),
  49241. (party_get_position, pos1, ":party_no"),
  49242. (get_distance_between_positions, ":dist", pos0, pos1),
  49243.  
  49244. (try_begin),
  49245. (le, ":dist", 9000),
  49246. (store_div, ":distance_addition", ":dist", 600),
  49247. (store_sub, ":distance_addition", 15, ":distance_addition"),
  49248. (else_try),
  49249. (assign, ":distance_addition", 0),
  49250. (try_end),
  49251. (val_add, ":lowest_acceptable_strength_percentage", ":distance_addition"),
  49252.  
  49253. #if there is no campaign for faction increase by 35%
  49254. (assign, ":no_campaign_addition", 35),
  49255. (try_begin),
  49256. (this_or_next|faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemy_army),
  49257. (this_or_next|faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemies_around_center),
  49258. (this_or_next|faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_raiding_village),
  49259. (this_or_next|faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_center),
  49260. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_gathering_army),
  49261. (assign, ":no_campaign_addition", 0),
  49262.  
  49263. #If marshal is player itself and if there is a campaign then lower lowest_acceptable_strength_percentage by 10 instead of not changing it.
  49264. #Because players become confused when they see very less participation from AI lords to their campaigns.
  49265. (try_begin), #400
  49266. (faction_slot_eq, ":faction_no", slot_faction_marshall, "trp_player"),
  49267. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  49268. (try_begin),
  49269. (eq, ":reduce_campaign_ai", 0), #hard
  49270. (assign, ":no_campaign_addition", 0),
  49271. (else_try),
  49272. (eq, ":reduce_campaign_ai", 1), #medium
  49273. (assign, ":no_campaign_addition", -10),
  49274. (else_try),
  49275. (eq, ":reduce_campaign_ai", 2), #easy
  49276. (assign, ":no_campaign_addition", -15),
  49277. (try_end),
  49278. (try_end),
  49279. (try_end),
  49280. (val_add, ":lowest_acceptable_strength_percentage", ":no_campaign_addition"),
  49281. (val_max, ":lowest_acceptable_strength_percentage", 25),
  49282.  
  49283. #max : 30%+15%+35% = 80% (happens when there is no campaign and player is near to its home center.)
  49284. (lt, ":party_strength_as_percentage_of_ideal", ":lowest_acceptable_strength_percentage"),
  49285.  
  49286. (try_begin),
  49287. (store_div, ":lowest_acceptable_strength_percentage_div_3", ":lowest_acceptable_strength_percentage", 3),
  49288. (ge, ":party_strength_as_percentage_of_ideal", ":lowest_acceptable_strength_percentage_div_3"),
  49289. (troop_get_slot, ":troop_wealth", ":troop_no", slot_troop_wealth),
  49290. (le, ":troop_wealth", 1800),
  49291. (assign, ":do_only_collecting_rents", 1),
  49292. (try_end),
  49293.  
  49294. (assign, ":action", spai_holding_center),
  49295. (assign, ":object", ":home_center"),
  49296.  
  49297. (try_begin),
  49298. (eq, ":troop_no", "$g_talk_troop"),
  49299. (str_store_string, s14, "str_i_dont_have_enough_troops_and_i_need_to_get_some_more"),
  49300.  
  49301. (str_store_string, s16, "str_i_am_running_low_on_troops"),
  49302. (try_end),
  49303.  
  49304. (eq, ":do_only_collecting_rents", 0),
  49305.  
  49306. #follow player orders
  49307. (else_try),
  49308. (eq, ":do_only_collecting_rents", 0),
  49309. (party_slot_ge, ":party_no", slot_party_following_orders_of_troop, "trp_kingdom_heroes_including_player_begin"),
  49310.  
  49311. (party_get_slot, ":orders_type", ":party_no", slot_party_orders_type),
  49312. (party_get_slot, ":orders_object", ":party_no", slot_party_orders_object),
  49313. (party_get_slot, ":orders_time", ":party_no", slot_party_orders_time),
  49314.  
  49315. (ge, ":orders_object", 0),
  49316.  
  49317. (store_current_hours, ":hours_since_orders_given"),
  49318. (val_sub, ":hours_since_orders_given", ":orders_time"),
  49319. ##diplomacy start+ If the player set the Centralization value, modify the
  49320. #maximum time vassals will follow commands by a maximum of +/- 25%
  49321. #(normally the maximum is 48 hours, so that would be +/- 12 hours).
  49322. (store_mul, reg0, ":centralization", 4),
  49323. (val_clamp, reg0, -12, 12),#<-- This should be unnecessary
  49324. (val_sub, ":hours_since_orders_given", reg0),
  49325. ##diplomacy end+
  49326.  
  49327. (party_is_active, ":orders_object"),
  49328. (party_get_slot, ":object_state", ":orders_object", slot_village_state),
  49329. (store_faction_of_party, ":object_faction", ":orders_object"),
  49330. (store_relation, ":relation_with_object", ":faction_no", ":object_faction"),
  49331.  
  49332. (assign, ":orders_are_appropriate", 1),
  49333. (try_begin),
  49334. (gt, ":hours_since_orders_given", 48),
  49335. (assign, ":orders_are_appropriate", 0),
  49336. (else_try),
  49337. (eq, ":orders_type", spai_raiding_around_center),
  49338. (this_or_next|ge, ":relation_with_object", 0),
  49339. (ge, ":object_state", 2),
  49340. (assign, ":orders_are_appropriate", 0),
  49341. (else_try),
  49342. (eq, ":orders_type", spai_besieging_center),
  49343. (ge, ":relation_with_object", 0),
  49344. (assign, ":orders_are_appropriate", 0),
  49345. (else_try),
  49346. (this_or_next|eq, ":orders_type", spai_holding_center),
  49347. (this_or_next|eq, ":orders_type", spai_retreating_to_center),
  49348. (this_or_next|eq, ":orders_type", spai_accompanying_army),
  49349. (eq, ":orders_type", spai_visiting_village),
  49350. (le, ":relation_with_object", 0),
  49351. (assign, ":orders_are_appropriate", 0),
  49352. (try_end),
  49353.  
  49354. (eq, ":orders_are_appropriate", 1),
  49355.  
  49356. (assign, ":action", ":orders_type"),
  49357. (assign, ":object", ":orders_object"),
  49358. (try_begin),
  49359. (eq, ":troop_no", "$g_talk_troop"),
  49360. (str_store_string, s14, "str_we_are_following_your_direction"),
  49361. (try_end),
  49362.  
  49363. #Host of player wedding
  49364. (else_try),
  49365. (eq, ":do_only_collecting_rents", 0),
  49366. (eq, ":operation_in_progress", 0),
  49367. (check_quest_active, "qst_wed_betrothed"),
  49368. (quest_slot_eq, "qst_wed_betrothed", slot_quest_giver_troop, ":troop_no"),
  49369. (quest_get_slot, ":bride", "qst_wed_betrothed", slot_quest_target_troop),
  49370. (call_script, "script_get_kingdom_lady_social_determinants", ":bride"),
  49371. (assign, ":wedding_venue", reg1),
  49372.  
  49373. (assign, ":action", spai_holding_center),
  49374. (assign, ":object", ":wedding_venue"),
  49375.  
  49376. (try_begin),
  49377. (eq, ":troop_no", "$g_talk_troop"),
  49378. (str_store_string, s14, "str_i_need_to_make_preparations_for_your_wedding"),
  49379. (str_store_string, s16, "str_after_all_i_need_to_make_preparations_for_your_wedding"),
  49380. (try_end),
  49381.  
  49382. #Bridegroom at player wedding
  49383. (else_try),
  49384. (eq, ":do_only_collecting_rents", 0),
  49385. (eq, ":operation_in_progress", 0),
  49386. (check_quest_active, "qst_wed_betrothed_female"),
  49387. (quest_slot_eq, "qst_wed_betrothed_female", slot_quest_giver_troop, ":troop_no"),
  49388.  
  49389. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_feast),
  49390. (faction_get_slot, ":feast_venue", ":faction_no", slot_faction_ai_object),
  49391.  
  49392. (assign, ":action", spai_holding_center),
  49393. (assign, ":object", ":feast_venue"),
  49394.  
  49395. (try_begin),
  49396. (eq, ":troop_no", "$g_talk_troop"),
  49397. (str_store_string, s14, "str_i_am_heading_to_the_site_of_our_wedding"), #500
  49398. (str_store_string, s16, "str_after_all_we_are_soon_to_be_wed"),
  49399. (try_end),
  49400.  
  49401. #Host of other feast
  49402. (else_try),
  49403. (eq, ":do_only_collecting_rents", 0),
  49404. (eq, ":operation_in_progress", 0),
  49405. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_feast),
  49406. (faction_get_slot, ":feast_venue", ":faction_no", slot_faction_ai_object),
  49407. (party_slot_eq, ":feast_venue", slot_town_lord, ":troop_no"),
  49408.  
  49409. (assign, ":action", spai_holding_center),
  49410. (assign, ":object", ":feast_venue"),
  49411.  
  49412. (try_begin),
  49413. (eq, ":troop_no", "$g_talk_troop"),
  49414. (str_store_string, s14, "str_i_am_hosting_a_feast_there"),
  49415. (str_store_string, s16, "str_i_have_a_feast_to_host"),
  49416. (try_end),
  49417.  
  49418. #I am the bridegroom at a feast
  49419. (else_try),
  49420. (eq, ":do_only_collecting_rents", 0),
  49421. (eq, ":operation_in_progress", 0),
  49422. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_feast),
  49423. (troop_get_slot, ":troop_betrothed", ":troop_no", slot_troop_betrothed),
  49424. (is_between, ":troop_betrothed", kingdom_ladies_begin, kingdom_ladies_end),
  49425.  
  49426. (faction_get_slot, ":feast_venue", ":faction_no", slot_faction_ai_object),
  49427.  
  49428. (assign, ":action", spai_holding_center),
  49429. (assign, ":object", ":feast_venue"),
  49430.  
  49431. (try_begin),
  49432. (eq, ":troop_no", "$g_talk_troop"),
  49433. (str_store_string, s14, "str_i_am_to_be_the_bridegroom_there"),
  49434. (str_store_string, s16, "str_my_wedding_day_draws_near"),
  49435. (try_end),
  49436.  
  49437. #Drop off prisoners
  49438. (else_try),
  49439. (eq, ":do_only_collecting_rents", 0),
  49440. (gt, ":party_ratio_of_prisoners", 35),
  49441. (eq, ":operation_in_progress", 0),
  49442.  
  49443. (call_script, "script_lord_get_home_center", ":troop_no"),
  49444. (assign, ":home_center", reg0),
  49445.  
  49446. (gt, ":home_center", -1),
  49447.  
  49448. (assign, ":action", spai_holding_center),
  49449. (assign, ":object", ":home_center"),
  49450.  
  49451. (try_begin),
  49452. (eq, ":troop_no", "$g_talk_troop"),
  49453. (str_store_string, s14, "str_i_have_too_much_loot_and_too_many_prisoners_and_need_to_secure_them"),
  49454. (str_store_string, s16, "str_i_should_think_of_dropping_off_some_of_my_prisoners"),
  49455. (try_end),
  49456.  
  49457. #Reinforce a weak center
  49458. (else_try),
  49459. (eq, ":do_only_collecting_rents", 0),
  49460. (assign, ":center_to_reinforce", -1),
  49461. (assign, ":center_reinforce_score", 100),
  49462. (eq, ":operation_in_progress", 0),
  49463.  
  49464. (try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
  49465. (party_slot_eq, ":walled_center", slot_town_lord, ":troop_no"),
  49466. (party_get_slot, ":center_strength", ":walled_center", slot_party_cached_strength),
  49467. (lt, ":center_strength", ":center_reinforce_score"),
  49468. (assign, ":center_to_reinforce", ":walled_center"),
  49469. (assign, ":center_reinforce_score", ":center_strength"),
  49470. (try_end),
  49471.  
  49472. (gt, ":center_to_reinforce", -1),
  49473.  
  49474. (assign, ":action", spai_holding_center),
  49475. (assign, ":object", ":center_to_reinforce"),
  49476. (try_begin),
  49477. (eq, ":troop_no", "$g_talk_troop"),
  49478. (str_store_string, s14, "str_i_need_to_reinforce_it_as_it_is_poorly_garrisoned"),
  49479. (str_store_string, s16, "str_there_is_a_hole_in_our_defenses"),
  49480. (try_end),
  49481.  
  49482. #Continue screening, if already doing so
  49483. (else_try),
  49484. (eq, ":do_only_collecting_rents", 0),
  49485. (eq, ":old_ai_state", spai_screening_army), #566
  49486.  
  49487. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  49488. (ge, ":faction_marshal", 0),
  49489. (troop_get_slot, ":marshal_party", ":faction_marshal", slot_troop_leaded_party),
  49490. (party_is_active, ":marshal_party"),
  49491.  
  49492. (call_script, "script_npc_decision_checklist_troop_follow_or_not", ":troop_no"),
  49493. (eq, reg0, 1),
  49494.  
  49495. (assign, ":action", spai_screening_army),
  49496. (assign, ":object", ":marshal_party"),
  49497. (try_begin),
  49498. (eq, "$g_talk_troop", ":troop_no"),
  49499. (str_store_string, s14, "str_i_am_following_the_marshals_orders"),
  49500. (str_store_string, s16, "str_the_marshal_has_given_me_this_command"),
  49501. (try_end),
  49502.  
  49503. (else_try), #special case for sfai_attacking_enemies_around_center for village raids
  49504. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemies_around_center),
  49505. (is_between, ":faction_object", villages_begin, villages_end),
  49506.  
  49507. (call_script, "script_npc_decision_checklist_troop_follow_or_not", ":troop_no"),
  49508. (eq, reg0, 1),
  49509.  
  49510. (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
  49511. (party_get_slot, ":raider_party", ":faction_object", slot_village_raided_by),
  49512. (party_is_active, ":raider_party"),
  49513.  
  49514. #think about adding one more condition here, what if raider army is so powerfull, again lords will go and engage enemy one by one?
  49515. (party_get_slot, ":enemy_strength_nearby", ":faction_object", slot_center_sortie_enemy_strength),
  49516. (lt, ":enemy_strength_nearby", 4000),
  49517. #end think
  49518.  
  49519. (assign, ":action", spai_engaging_army),
  49520. (assign, ":object", ":raider_party"),
  49521. (try_begin),
  49522. (eq, ":troop_no", "$g_talk_troop"),
  49523. (str_store_string, s14, "str_our_realm_needs_my_support_there_is_enemy_raiding_one_of_our_villages_which_is_not_to_far_from_here_i_am_going_there"),
  49524. (str_store_string, s16, "str_the_marshal_has_issued_a_summons"),
  49525. (try_end),
  49526.  
  49527. #Follow the marshall's orders - if on the offensive, and the campaign has not lasted too long. Readiness is currently randomly set
  49528. (else_try),
  49529. (eq, ":do_only_collecting_rents", 0),
  49530. (call_script, "script_npc_decision_checklist_troop_follow_or_not", ":troop_no"),
  49531. (eq, reg0, 1),
  49532.  
  49533. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  49534. (ge, ":faction_marshal", 0),
  49535. (troop_get_slot, ":marshal_party", ":faction_marshal", slot_troop_leaded_party),
  49536.  
  49537. (assign, ":action", spai_accompanying_army),
  49538. (assign, ":object", ":marshal_party"),
  49539.  
  49540. (try_begin),
  49541. (eq, "$g_talk_troop", ":troop_no"),
  49542. (str_store_string, s14, "str_i_am_answering_the_marshals_summons"),
  49543. (str_store_string, s16, "str_the_marshal_has_issued_a_summons"),
  49544. (try_end),
  49545.  
  49546. #Support a nearby ally who is on the offensive
  49547. (else_try),
  49548. (eq, ":do_only_collecting_rents", 0),
  49549. (eq, ":faction_is_at_war", 1),
  49550.  
  49551. (assign, ":party_to_support", -1),
  49552. (try_for_range, ":allied_hero", active_npcs_begin, active_npcs_end),
  49553. (troop_slot_eq, ":allied_hero", slot_troop_occupation, slto_kingdom_hero),
  49554. (store_faction_of_troop, ":allied_hero_faction", ":allied_hero"),
  49555. (eq, ":allied_hero_faction", ":faction_no"),
  49556.  
  49557. (neq, ":allied_hero", ":troop_no"),
  49558.  
  49559. (troop_get_slot, ":allied_hero_party", ":allied_hero", slot_troop_leaded_party),
  49560. (gt, ":allied_hero_party", 1),
  49561. (party_is_active, ":allied_hero_party"),
  49562.  
  49563.  
  49564. (this_or_next|party_slot_eq, ":allied_hero_party", slot_party_ai_state, spai_raiding_around_center),
  49565. (party_slot_eq, ":allied_hero_party", slot_party_ai_state, spai_besieging_center),
  49566.  
  49567. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":allied_hero"),
  49568. (gt, reg0, 4),
  49569.  
  49570. (troop_get_slot, ":troop_renown", ":troop_no", slot_troop_renown),
  49571. (troop_get_slot, ":ally_renown", ":allied_hero", slot_troop_renown),
  49572. (le, ":troop_renown", ":ally_renown"), #Ally to support must have higher renown
  49573.  
  49574. (store_distance_to_party_from_party, ":distance", ":party_no", ":allied_hero_party"),
  49575.  
  49576. (lt, ":distance", 5),
  49577.  
  49578. (assign, ":party_to_support", ":allied_hero_party"),
  49579. (try_end),
  49580. (gt, ":party_to_support", 0),
  49581.  
  49582. (assign, ":action", spai_accompanying_army),
  49583. (assign, ":object", ":party_to_support"),
  49584. (try_begin),
  49585. (eq, ":troop_no", "$g_talk_troop"),
  49586. (party_stack_get_troop_id, ":leader", ":object", 0),
  49587. (str_store_troop_name, s10, ":leader"),
  49588.  
  49589. (call_script, "script_troop_get_family_relation_to_troop", ":leader", "$g_talk_troop"),
  49590. (try_begin),
  49591. (eq, reg0, 0),
  49592. (str_store_string, s11, "str_comradeinarms"),
  49593. (try_end),
  49594. (str_store_string, s14, "str_i_am_supporting_my_s11_s10"),
  49595. (str_store_string, s16, "str_i_believe_that_one_of_my_comrades_is_in_need"),
  49596. (try_end),
  49597. #I have decided to attack a vulnerable fortress
  49598. (else_try),
  49599. (eq, ":do_only_collecting_rents", 0),
  49600. (eq, ":faction_is_at_war", 1),
  49601. (eq, ":operation_in_progress", 0),
  49602.  
  49603. (assign, ":walled_center_to_attack", -1),
  49604. (assign, ":walled_center_score", 50),
  49605.  
  49606. (try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
  49607. (store_faction_of_party, ":walled_center_faction", ":walled_center"),
  49608. (store_relation, ":relation", ":faction_no", ":walled_center_faction"),
  49609. (lt, ":relation", 0),
  49610.  
  49611. (party_get_slot, ":center_cached_strength", ":walled_center", slot_party_cached_strength),
  49612. (val_mul, ":center_cached_strength", 3),
  49613. (val_mul, ":center_cached_strength", 2),
  49614.  
  49615. (lt, ":center_cached_strength", ":party_cached_strength"),
  49616. (lt, ":center_cached_strength", 750),
  49617.  
  49618. (party_slot_eq, ":walled_center", slot_village_state, svs_normal),
  49619. (store_distance_to_party_from_party, ":distance", ":walled_center", ":party_no"),
  49620. (lt, ":distance", ":walled_center_score"),
  49621.  
  49622. (assign, ":walled_center_to_attack", ":walled_center"),
  49623. (assign, ":walled_center_score", ":distance"),
  49624. (try_end),
  49625.  
  49626. (is_between, ":walled_center_to_attack", centers_begin, centers_end),
  49627.  
  49628. (assign, ":action", spai_besieging_center),
  49629. (assign, ":object", ":walled_center_to_attack"),
  49630. (try_begin),
  49631. (eq, "$cheat_mode", 1),
  49632. (str_store_faction_name, s20, ":faction_no"),
  49633. (str_store_party_name, s21, ":object"),
  49634. (display_message, "str_s20_decided_to_attack_s21"),
  49635. (try_end),
  49636.  
  49637. (try_begin),
  49638. (eq, ":troop_no", "$g_talk_troop"),
  49639. (str_store_string, s14, "str_a_fortress_is_vulnerable"),
  49640. (str_store_string, s16, "str_i_believe_that_the_enemy_may_be_vulnerable"),
  49641. (try_end),
  49642.  
  49643. #I am visiting an estate
  49644. (else_try),
  49645. (assign, ":center_to_visit", -1),
  49646. (assign, ":score_to_beat", 300), #at least 300 gold to pick up
  49647. (troop_get_slot, ":troop_wealth", ":troop_no", slot_troop_wealth), #average troop wealth is 2000
  49648. (val_div, ":troop_wealth", 10), #average troop wealth 10% is is 200
  49649. (val_add, ":score_to_beat", ":troop_wealth"), #average score to beat is 500
  49650. (eq, ":operation_in_progress", 0),
  49651.  
  49652. (try_begin),
  49653. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  49654.  
  49655. (assign, reg17, 0),
  49656. (try_begin),
  49657. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  49658. (party_slot_eq, ":party_no", slot_party_ai_object, ":faction_marshal"),
  49659. (assign, reg17, 1),
  49660. (else_try),
  49661. (party_slot_eq, ":party_no", slot_party_following_player, 1),
  49662. (assign, reg17, 1),
  49663. (try_end),
  49664. (eq, reg17, 1),
  49665.  
  49666. (try_begin),
  49667. (neq, ":faction_marshal", "trp_player"),
  49668. (neg|party_slot_eq, ":party_no", slot_party_following_player, 1),
  49669. (val_add, ":score_to_beat", 125),
  49670. (else_try),
  49671. (val_add, ":score_to_beat", 250),
  49672. (try_end),
  49673. (try_end),
  49674.  
  49675. (try_for_range, ":center_no", centers_begin, centers_end),
  49676. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  49677.  
  49678. (assign, reg17, 0),
  49679. (try_begin),
  49680. (is_between, ":center_no", villages_begin, villages_end),
  49681. (party_slot_eq, ":center_no", slot_village_state, svs_normal),
  49682. (assign, reg17, 1),
  49683. (else_try),
  49684. (party_slot_eq, ":center_no", slot_center_is_besieged_by, -1),
  49685. (assign, reg17, 1),
  49686. (try_end),
  49687. (eq, reg17, 1),
  49688.  
  49689. (party_get_slot, ":tariffs_available", ":center_no", slot_center_accumulated_tariffs),
  49690. (party_get_slot, ":rents_available", ":center_no", slot_center_accumulated_rents),
  49691. (store_add, ":money_available", ":rents_available", ":tariffs_available"),
  49692.  
  49693. (gt, ":money_available", ":score_to_beat"),
  49694. (assign, ":center_to_visit", ":center_no"),
  49695. (assign, ":score_to_beat", ":money_available"),
  49696. (try_end),
  49697.  
  49698. (is_between, ":center_to_visit", centers_begin, centers_end),
  49699.  
  49700. (try_begin),
  49701. (is_between, ":center_to_visit", walled_centers_begin, walled_centers_end),
  49702. (assign, ":action", spai_holding_center),
  49703. (assign, ":object", ":center_to_visit"),
  49704. (else_try),
  49705. (assign, ":action", spai_visiting_village),
  49706. (assign, ":object", ":center_to_visit"),
  49707. (try_end),
  49708.  
  49709. (try_begin),
  49710. (eq, ":troop_no", "$g_talk_troop"),
  49711. (str_store_string, s14, "str_i_need_to_inspect_my_properties_and_collect_my_dues"),
  49712. (str_store_string, s16, "str_it_has_been_too_long_since_i_have_inspected_my_estates"),
  49713. (try_end),
  49714.  
  49715. #My men are weary, and I wish to return home
  49716. (else_try),
  49717. (eq, ":do_only_collecting_rents", 0),
  49718. (this_or_next|gt, ":hours_since_last_rest", 504), #Three weeks
  49719. (lt, ":aggressiveness", 25),
  49720. (gt, ":hours_since_last_rest", 168), #one week if aggressiveness < 25
  49721. (eq, ":operation_in_progress", 0),
  49722.  
  49723. (call_script, "script_lord_get_home_center", ":troop_no"),
  49724. (assign, ":home_center", reg0),
  49725.  
  49726. (gt, ":home_center", -1),
  49727. (assign, ":action", spai_holding_center),
  49728. (assign, ":object", ":home_center"),
  49729.  
  49730. (try_begin),
  49731. (eq, ":troop_no", "$g_talk_troop"),
  49732. (str_store_string, s14, "str_my_men_are_weary_so_we_are_returning_home"),
  49733. (str_store_string, s16, "str_my_men_are_becoming_weary"),
  49734. (try_end),
  49735.  
  49736. #I have a score to settle with the enemy
  49737. (else_try),
  49738. (eq, ":do_only_collecting_rents", 0),
  49739. (this_or_next|gt, ":hours_since_last_combat", 12),
  49740. (lt, ":hours_since_last_rest", 96),
  49741. (eq, ":operation_in_progress", 0),
  49742.  
  49743. (eq, ":faction_is_at_war", 1),
  49744. ##diplomacy start+ roguish lords can also do this, but humanitarian lords of any kind won't
  49745. (call_script, "script_dplmc_get_troop_morality_value", ":troop_no", tmt_humanitarian),
  49746. (lt, reg0, 1),
  49747. (this_or_next|eq, ":troop_reputation", lrep_roguish),
  49748. ##diplomacy end+
  49749. (this_or_next|eq, ":troop_reputation", lrep_debauched),
  49750. (eq, ":troop_reputation", lrep_quarrelsome),
  49751.  
  49752. (assign, ":target_village", -1),
  49753. (assign, ":score_to_beat", 0), #based on relation
  49754.  
  49755. (try_for_range, ":possible_target", villages_begin, villages_end),
  49756. (store_faction_of_party, ":village_faction", ":possible_target"),
  49757. (store_relation, ":relation", ":village_faction", ":faction_no"),
  49758. (lt, ":relation", 0),
  49759.  
  49760. (neg|party_slot_ge, ":possible_target", slot_village_state, svs_looted),
  49761. (party_get_slot, ":town_lord", ":possible_target", slot_town_lord),
  49762. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":town_lord"),
  49763. (assign, ":village_score", reg0),
  49764.  
  49765. (lt, ":village_score", ":score_to_beat"),
  49766. (assign, ":score_to_beat", ":village_score"),
  49767. (assign, ":target_village", ":possible_target"),
  49768. (try_end),
  49769.  
  49770. (is_between, ":target_village", centers_begin, centers_end),
  49771. (assign, ":action", spai_raiding_around_center),
  49772. (assign, ":object", ":target_village"),
  49773.  
  49774. (try_begin),
  49775. (eq, ":troop_no", "$g_talk_troop"),
  49776. (str_store_string, s14, "str_i_have_a_score_to_settle_with_the_lord_there"),
  49777. (str_store_string, s16, "str_i_am_thinking_of_settling_an_old_score"),
  49778. (try_end),
  49779.  
  49780. #I need money, so I am raiding where the money is
  49781. (else_try),
  49782. (eq, ":do_only_collecting_rents", 0),
  49783. (eq, ":faction_is_at_war", 1),
  49784. (eq, ":operation_in_progress", 0),
  49785.  
  49786. (this_or_next|gt, ":hours_since_last_combat", 12),
  49787. (lt, ":hours_since_last_rest", 96),
  49788. (gt, ":aggressiveness", 40),
  49789.  
  49790. ##diplomacy start+
  49791. #Roguish lords can also do this. Humanitarian companions will never
  49792. #do this, even if they otherwise have an eligible reputation. Companions
  49793. #who actively enjoy raiding can also do this, regardless of whether they
  49794. #have an eligible reputation.
  49795. (call_script, "script_dplmc_get_troop_morality_value", ":troop_no", tmt_humanitarian),
  49796. (lt, reg0, 1),
  49797. (this_or_next|lt, reg0, 0),
  49798. (this_or_next|eq, ":troop_reputation", lrep_roguish),
  49799. ##diplomacy end+
  49800. (this_or_next|eq, ":troop_reputation", lrep_debauched),
  49801. (this_or_next|eq, ":troop_reputation", lrep_selfrighteous),
  49802. (this_or_next|eq, ":troop_reputation", lrep_cunning),
  49803. (eq, ":troop_reputation", lrep_quarrelsome),
  49804.  
  49805. (troop_get_slot, ":wealth", ":troop_no", slot_troop_wealth),
  49806. (lt, ":wealth", 500),
  49807.  
  49808. (assign, ":score_to_beat", 0),
  49809. (assign, ":target_village", -1),
  49810.  
  49811. (try_for_range, ":possible_target", villages_begin, villages_end),
  49812. (store_faction_of_party, ":village_faction", ":possible_target"),
  49813. (store_relation, ":relation", ":village_faction", ":faction_no"),
  49814. (lt, ":relation", 0),
  49815.  
  49816. (this_or_next|party_slot_eq, ":possible_target", slot_village_state, svs_normal),
  49817. (party_slot_eq, ":possible_target", slot_village_state, svs_being_raided),
  49818.  
  49819. (party_get_slot, reg17, ":possible_target", slot_town_prosperity),
  49820. (store_distance_to_party_from_party, ":distance", ":party_no", ":possible_target"),
  49821. (val_sub, reg17, ":distance"),
  49822.  
  49823. (gt, reg17, ":score_to_beat"),
  49824. (assign, ":score_to_beat", reg17),
  49825. (assign, ":target_village", ":possible_target"),
  49826. (try_end),
  49827.  
  49828. (gt, ":target_village", -1),
  49829.  
  49830. (assign, ":action", spai_raiding_around_center),
  49831. (assign, ":object", ":target_village"),
  49832.  
  49833. (try_begin),
  49834. (eq, ":troop_no", "$g_talk_troop"),
  49835. (str_store_string, s14, "str_i_am_short_of_money_and_i_hear_that_there_is_much_wealth_there"),
  49836. (str_store_string, s16, "str_i_need_to_refill_my_purse_preferably_with_the_enemys_money"),
  49837. (try_end),
  49838.  
  49839. #Attacking wealthiest lands
  49840. (else_try),
  49841. (eq, ":do_only_collecting_rents", 0),
  49842. (eq, ":faction_is_at_war", 1),
  49843. (eq, ":operation_in_progress", 0),
  49844. (gt, ":aggressiveness", 65),
  49845.  
  49846. (assign, ":score_to_beat", 0),
  49847. (assign, ":target_village", -1),
  49848.  
  49849. (try_for_range, ":possible_target", villages_begin, villages_end),
  49850. (store_faction_of_party, ":village_faction", ":possible_target"),
  49851. (store_relation, ":relation", ":village_faction", ":faction_no"),
  49852. (lt, ":relation", 0),
  49853. (neg|party_slot_eq, ":possible_target", slot_village_state, svs_looted),
  49854. (party_get_slot, ":village_prosperity", ":possible_target", slot_town_prosperity),
  49855. (val_mul, ":village_prosperity", 2),
  49856.  
  49857. (store_distance_to_party_from_party, ":distance", ":party_no", ":possible_target"),
  49858. (val_sub, ":village_prosperity", ":distance"),
  49859. (gt, ":village_prosperity", ":score_to_beat"),
  49860.  
  49861. (assign, ":score_to_beat", ":village_prosperity"),
  49862. (assign, ":target_village", ":possible_target"),
  49863. (try_end),
  49864.  
  49865. ##diplomacy start+ companions who hate raiding will not raid
  49866. (call_script, "script_dplmc_get_troop_morality_value", ":troop_no", tmt_humanitarian),
  49867. (lt, reg0, 1),
  49868. ##diplomacy end+
  49869. (gt, ":target_village", -1),
  49870.  
  49871. (assign, ":action", spai_raiding_around_center),
  49872. (assign, ":object", ":target_village"),
  49873.  
  49874. (try_begin),
  49875. (eq, ":troop_no", "$g_talk_troop"),
  49876. (str_store_string, s14, "str_by_striking_at_the_enemys_richest_lands_perhaps_i_can_draw_them_out_to_battle"),
  49877. (str_store_string, s16, "str_i_am_thinking_of_going_on_the_attack"),
  49878. (try_end),
  49879.  
  49880. #End the war
  49881. (else_try),
  49882. (eq, ":do_only_collecting_rents", 0),
  49883. ##diplomacy start+
  49884. (assign, reg0, 0),
  49885. (try_begin),
  49886. #A liege in service to another lord or allied with the player can do this.
  49887. (this_or_next|eq, ":troop_reputation", lrep_none),
  49888. (this_or_next|is_between, ":troop_no", kings_begin, kings_end),
  49889. (is_between, ":troop_no", pretenders_begin, pretenders_end),
  49890. (this_or_next|neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":troop_no"),
  49891. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_spouse, "trp_player"),
  49892. (troop_slot_eq, "trp_player", slot_troop_spouse, ":troop_no"),
  49893. (assign, reg0, 0),
  49894. (else_try),
  49895. #Lords who are simulatenously Martial and tmt_honest (such as Alayen),
  49896. #or Custodian and tmt_honest (such as Artimenner) can also do this.
  49897. (this_or_next|eq, ":troop_reputation", lrep_martial),
  49898. (eq, ":troop_reputation", lrep_custodian),
  49899. (call_script, "script_dplmc_get_troop_morality_value", ":troop_no", tmt_honest),
  49900. (try_end),
  49901. (this_or_next|ge, reg0, 1),
  49902. ##diplomacy end+
  49903. (eq, ":troop_reputation", lrep_upstanding),
  49904. (eq, ":faction_is_at_war", 1),
  49905. (eq, ":operation_in_progress", 0),
  49906.  
  49907. (assign, ":faction_to_attack", -1),
  49908. (try_for_range, ":possible_faction_to_attack", kingdoms_begin, kingdoms_end),
  49909. (store_relation, ":relation", ":faction_no", ":possible_faction_to_attack"),
  49910. (lt, ":relation", 0),
  49911. (faction_slot_eq, ":possible_faction_to_attack", slot_faction_state, sfs_active),
  49912.  
  49913. (store_add, ":war_damage_inflicted_slot", ":possible_faction_to_attack", slot_faction_war_damage_inflicted_on_factions_begin),
  49914. (val_sub, ":war_damage_inflicted_slot", kingdoms_begin),
  49915. (faction_get_slot, ":war_damage_inflicted", ":faction_no", ":war_damage_inflicted_slot"),
  49916.  
  49917. (store_add, ":war_damage_suffered_slot", ":faction_no", slot_faction_war_damage_inflicted_on_factions_begin),
  49918. (val_sub, ":war_damage_suffered_slot", kingdoms_begin),
  49919. (faction_get_slot, ":war_damage_suffered", ":possible_faction_to_attack", ":war_damage_suffered_slot"),
  49920.  
  49921. (gt, ":war_damage_inflicted", 80),
  49922. (lt, ":war_damage_inflicted", ":war_damage_suffered"),
  49923. (assign, ":faction_to_attack", ":possible_faction_to_attack"),
  49924. (try_end),
  49925.  
  49926. (gt, ":faction_to_attack", -1),
  49927.  
  49928. (assign, ":target_village", -1),
  49929. (assign, ":score_to_beat", 50),
  49930.  
  49931. (try_for_range, ":possible_target_village", villages_begin, villages_end),
  49932. (store_faction_of_party, ":village_faction", ":possible_target_village"),
  49933. (eq, ":village_faction", ":faction_to_attack"),
  49934. (neg|party_slot_eq, ":possible_target_village", slot_village_state, svs_looted),
  49935. (store_distance_to_party_from_party, ":distance", ":party_no", ":possible_target_village"),
  49936. (lt, ":distance", ":score_to_beat"),
  49937.  
  49938. (assign, ":score_to_beat", ":distance"),
  49939. (assign, ":target_village", ":possible_target_village"),
  49940. (try_end),
  49941.  
  49942. (gt, ":target_village", -1),
  49943.  
  49944. (assign, ":action", spai_raiding_around_center),
  49945. (assign, ":object", ":target_village"),
  49946.  
  49947. (try_begin),
  49948. (eq, ":troop_no", "$g_talk_troop"),
  49949. (str_store_string, s14, "str_perhaps_if_i_strike_one_more_blow_we_may_end_this_war_on_our_terms_"),
  49950. (str_store_string, s16, "str_we_may_be_able_to_bring_this_war_to_a_close_with_a_few_more_blows"),
  49951. (try_end),
  49952.  
  49953. #I have a feast to attend
  49954. (else_try),
  49955. (eq, ":do_only_collecting_rents", 0),
  49956. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_feast),
  49957. (faction_get_slot, ":feast_venue", ":faction_no", slot_faction_ai_object),
  49958. (party_get_slot, ":feast_host", ":feast_venue", slot_town_lord),
  49959. (eq, ":operation_in_progress", 0),
  49960.  
  49961. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":feast_host"),
  49962. (assign, ":relation_with_host", reg0),
  49963.  
  49964. (ge, ":relation_with_host", 0),
  49965.  
  49966. (assign, ":action", spai_holding_center),
  49967. (assign, ":object", ":feast_venue"),
  49968.  
  49969. (try_begin),
  49970. (eq, ":troop_no", "$g_talk_troop"),
  49971. (str_store_string, s14, "str_i_wish_to_attend_the_feast_there"),
  49972. (str_store_string, s16, "str_there_is_a_feast_which_i_wish_to_attend"),
  49973. (try_end),
  49974. #A lady to court
  49975. (else_try),
  49976. (eq, ":do_only_collecting_rents", 0),
  49977. (neg|troop_slot_eq, "trp_player", slot_troop_betrothed, ":troop_no"),
  49978. (troop_slot_eq, ":troop_no", slot_troop_spouse, -1),
  49979. (neg|is_between, ":troop_no", kings_begin, kings_end),
  49980. (neg|is_between, ":troop_no", pretenders_begin, pretenders_end),
  49981.  
  49982.  
  49983. (gt, ":hours_since_last_courtship", 72),
  49984. (eq, ":operation_in_progress", 0),
  49985.  
  49986. (assign, ":center_to_visit", -1),
  49987. (assign, ":score_to_beat", 150),
  49988.  
  49989. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  49990. (troop_get_slot, ":love_interest", ":troop_no", ":love_interest_slot"),
  49991. (is_between, ":love_interest", kingdom_ladies_begin, kingdom_ladies_end),
  49992. (troop_get_slot, ":love_interest_center", ":love_interest", slot_troop_cur_center),
  49993. (is_between, ":love_interest_center", centers_begin, centers_end),
  49994. (store_faction_of_party, ":love_interest_faction_no", ":love_interest_center"),
  49995. (eq, ":faction_no", ":love_interest_faction_no"),
  49996. #(store_relation, ":relation", ":faction_no", ":love_interest_faction_no"),
  49997. #(ge, ":relation", 0),
  49998.  
  49999. (store_distance_to_party_from_party, ":distance", ":party_no", ":love_interest_center"),
  50000.  
  50001. (lt, ":distance", ":score_to_beat"),
  50002. (assign, ":center_to_visit", ":love_interest_center"),
  50003. (assign, ":score_to_beat", ":distance"),
  50004. (try_end),
  50005.  
  50006. (gt, ":center_to_visit", -1),
  50007.  
  50008. (assign, ":action", spai_holding_center),
  50009. (assign, ":object", ":center_to_visit"),
  50010.  
  50011. (try_begin),
  50012. (eq, ":troop_no", "$g_talk_troop"),
  50013. (str_store_string, s14, "str_there_is_a_fair_lady_there_whom_i_wish_to_court"),
  50014. (str_store_string, s16, "str_i_have_the_inclination_to_pay_court_to_a_fair_lady"),
  50015. (try_end),
  50016.  
  50017. #Patrolling an alarmed center
  50018. (else_try),
  50019. (eq, ":do_only_collecting_rents", 0),
  50020. (assign, ":target_center", -1),
  50021. (assign, ":score_to_beat", 60),
  50022. (eq, ":operation_in_progress", 0),
  50023. (gt, ":aggressiveness", 40),
  50024.  
  50025. (try_for_range, ":center_to_patrol", centers_begin, centers_end), #find closest center that has spotted enemies.
  50026. (store_faction_of_party, ":center_faction", ":center_to_patrol"),
  50027. (eq, ":center_faction", ":faction_no"),
  50028. (party_slot_ge, ":center_to_patrol", slot_center_last_spotted_enemy, 0),
  50029.  
  50030. #new - begin
  50031. (party_get_slot, ":sortie_strength", ":center_to_patrol", slot_center_sortie_strength),
  50032. (party_get_slot, ":enemy_strength", ":center_to_patrol", slot_center_sortie_enemy_strength),
  50033. (store_mul, ":enemy_strength_mul_14_div_10", ":enemy_strength", 14),
  50034. (val_div, ":enemy_strength_mul_14_div_10", 10),
  50035. (party_get_slot, ":party_strength", ":party_no", slot_party_cached_strength),
  50036.  
  50037. (this_or_next|neg|party_is_in_town, ":party_no", ":center_to_patrol"),
  50038. (gt, ":sortie_strength", ":enemy_strength_mul_14_div_10"),
  50039.  
  50040. (ge, ":party_strength", 100),
  50041. #new - end
  50042.  
  50043. (party_get_slot, reg17, ":center_to_patrol", slot_town_lord),
  50044. (call_script, "script_troop_get_relation_with_troop", reg17, ":troop_no"),
  50045.  
  50046. (this_or_next|eq, ":troop_reputation", lrep_upstanding),
  50047. (gt, reg0, -5),
  50048.  
  50049. (store_distance_to_party_from_party, ":distance", ":party_no", ":center_to_patrol"),
  50050. (lt, ":distance", ":score_to_beat"),
  50051.  
  50052. (assign, ":target_center", ":center_to_patrol"),
  50053. (assign, ":score_to_beat", ":distance"),
  50054. (try_end),
  50055.  
  50056. (is_between, ":target_center", centers_begin, centers_end),
  50057.  
  50058. (assign, ":action", spai_patrolling_around_center),
  50059. (assign, ":object", ":target_center"),
  50060.  
  50061. (try_begin),
  50062. (eq, ":troop_no", "$g_talk_troop"),
  50063. (str_store_string, s14, "str_we_have_heard_reports_that_the_enemy_is_in_the_area"),
  50064. (str_store_string, s16, "str_i_have_heard_reports_of_enemy_incursions_into_our_territory"),
  50065. (try_end),
  50066.  
  50067. #Time in household
  50068. (else_try),
  50069. (eq, ":do_only_collecting_rents", 0),
  50070. (gt, ":hours_since_last_home", 168),
  50071. (eq, ":operation_in_progress", 0),
  50072.  
  50073. (call_script, "script_lord_get_home_center", ":troop_no"),
  50074. (assign, ":home_center", reg0),
  50075. (gt, ":home_center", -1),
  50076.  
  50077. (assign, ":action", spai_holding_center),
  50078. (assign, ":object", ":home_center"),
  50079.  
  50080. (try_begin),
  50081. (eq, ":troop_no", "$g_talk_troop"),
  50082. (str_store_string, s14, "str_i_need_to_spend_some_time_with_my_household"),
  50083. (str_store_string, s16, "str_it_has_been_a_long_time_since_i_have_been_able_to_spend_time_with_my_household"),
  50084. (try_end),
  50085.  
  50086. #Patrolling the borders
  50087. (else_try),
  50088. (eq, ":do_only_collecting_rents", 0),
  50089. (eq, ":faction_is_at_war", 1),
  50090. (gt, ":aggressiveness", 65),
  50091. (eq, ":operation_in_progress", 0),
  50092.  
  50093. (assign, ":center_to_patrol", -1),
  50094. (assign, ":score_to_beat", 75),
  50095.  
  50096. (try_for_range, ":village", villages_begin, villages_end),
  50097. (store_faction_of_party, ":village_faction", ":village"),
  50098. (store_relation, ":relation", ":village_faction", ":faction_no"),
  50099. (lt, ":relation", 0),
  50100.  
  50101. (store_distance_to_party_from_party, ":distance", ":village", ":party_no"),
  50102. (lt, ":distance", ":score_to_beat"),
  50103.  
  50104. (assign, ":score_to_beat", ":distance"),
  50105. (assign, ":center_to_patrol", ":village"),
  50106. (try_end),
  50107.  
  50108. (is_between, ":center_to_patrol", villages_begin, villages_end),
  50109.  
  50110. (assign, ":action", spai_patrolling_around_center),
  50111. (assign, ":object", ":center_to_patrol"),
  50112.  
  50113. (try_begin),
  50114. (eq, ":troop_no", "$g_talk_troop"),
  50115. (str_store_string, s14, "str_i_am_watching_the_borders"),
  50116. (str_store_string, s16, "str_i_may_be_needed_to_watch_the_borders"),
  50117. (try_end),
  50118.  
  50119. #Visiting a friend - temporarily disabled
  50120. (else_try),
  50121. (eq, 1, 0),
  50122.  
  50123. #Patrolling home
  50124. (else_try),
  50125. (eq, ":do_only_collecting_rents", 0),
  50126. (call_script, "script_lord_get_home_center", ":troop_no"),
  50127. (assign, ":home_center", reg0),
  50128.  
  50129. (is_between, ":home_center", centers_begin, centers_end),
  50130. (eq, ":operation_in_progress", 0),
  50131.  
  50132. (assign, ":action", spai_patrolling_around_center),
  50133. (assign, ":object", ":home_center"),
  50134.  
  50135. (try_begin),
  50136. (eq, ":troop_no", "$g_talk_troop"),
  50137. (str_store_string, s14, "str_i_will_guard_the_areas_near_my_home"),
  50138. (str_store_string, s16, "str_i_am_perhaps_needed_most_at_home"),
  50139. (try_end),
  50140.  
  50141. #Default end
  50142. (else_try),
  50143. (eq, ":do_only_collecting_rents", 0),
  50144. (eq, ":operation_in_progress", 0),
  50145.  
  50146. (call_script, "script_lord_get_home_center", ":troop_no"),
  50147. (assign, ":home_center", reg0),
  50148. (is_between, ":home_center", walled_centers_begin, walled_centers_end),
  50149.  
  50150. (assign, ":action", spai_holding_center),
  50151. (assign, ":object", ":home_center"),
  50152.  
  50153. (try_begin),
  50154. (eq, ":troop_no", "$g_talk_troop"),
  50155. (str_store_string, s14, "str_i_cant_think_of_anything_better_to_do"),
  50156. (try_end),
  50157. (else_try),
  50158. (eq, ":do_only_collecting_rents", 0),
  50159. (eq, ":operation_in_progress", 1),
  50160.  
  50161. (party_get_slot, ":action", ":party_no", slot_party_ai_state),
  50162. (party_get_slot, ":object", ":party_no", slot_party_ai_object),
  50163.  
  50164. (try_begin),
  50165. (eq, ":troop_no", "$g_talk_troop"),
  50166. (str_store_string, s14, "str_i_am_completing_what_i_have_already_begun"),
  50167. (try_end),
  50168. (else_try),
  50169. (eq, ":do_only_collecting_rents", 0),
  50170. (assign, ":action", spai_undefined),
  50171. (assign, ":object", -1),
  50172.  
  50173. (try_begin),
  50174. (eq, ":troop_no", "$g_talk_troop"),
  50175. (str_store_string, s14, "str_i_dont_even_have_a_home_to_which_to_return"),
  50176. (try_end),
  50177. (try_end),
  50178.  
  50179. (try_begin),
  50180. (eq, "$cheat_mode", 2),
  50181. (str_store_troop_name, s10, ":troop_no"),
  50182. (display_message, "str_debug__s10_decides_s14_faction_ai_s15"),
  50183. (try_end),
  50184.  
  50185. (assign, reg0, ":action"),
  50186. (assign, reg1, ":object"),
  50187. ]),
  50188.  
  50189. #script_npc_decision_checklist_troop_follow_or_not
  50190. # INPUT: troop_no
  50191. # OUTPUT: reg0
  50192. (
  50193. "npc_decision_checklist_troop_follow_or_not", [
  50194.  
  50195. (store_script_param, ":troop_no", 1),
  50196. (store_faction_of_troop, ":faction_no", ":troop_no"),
  50197. (faction_get_slot, ":faction_ai_state", ":faction_no", slot_faction_ai_state),
  50198.  
  50199. (troop_get_slot, ":troop_reputation", ":troop_no", slot_lord_reputation_type),
  50200. (faction_get_slot, ":faction_marshall", ":faction_no", slot_faction_marshall),
  50201. ##diplomacy start+
  50202. #Get the centralization value for use below. It should be a value in [-3,3].
  50203. #A centralization value of 0 should not result in any behavior change.
  50204. (try_begin),
  50205. #If the player altered the kingdom policy, always apply its effects to
  50206. #the AI of his kingdom's lords.
  50207. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", ":faction_no"),
  50208. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  50209. (faction_get_slot, ":centralization", ":faction_no", dplmc_slot_faction_centralization),
  50210. (val_clamp, ":centralization", -3, 4),
  50211. (else_try),
  50212. #Currently, do not apply centralization to the AI for NPC kingdoms, since
  50213. #NPC rulers set their policies randomly and do not gain the same monthly
  50214. #relation bonuses/penalties from centralization that the player does.
  50215. (assign, ":centralization", 0),
  50216. (try_end),
  50217. ##diplomacy end+
  50218.  
  50219. (assign, ":result", 0),
  50220. (try_begin),
  50221. ##diplomacy start+ add another check
  50222. (this_or_next|lt, ":faction_marshall", 0),
  50223. ##diplomacy end+
  50224. (eq, ":faction_marshall", -1),
  50225.  
  50226. (try_begin),
  50227. (eq, ":troop_no", "$g_talk_troop"),
  50228. (str_store_string, s15, "str__i_am_acting_independently_because_no_marshal_is_appointed"),
  50229. (try_end),
  50230. (else_try),
  50231. (troop_get_slot, ":faction_marshall_party", ":faction_marshall", slot_troop_leaded_party),
  50232. (neg|party_is_active, ":faction_marshall_party"),
  50233.  
  50234. #Not doing an offensive
  50235. (try_begin),
  50236. (eq, ":troop_no", "$g_talk_troop"),
  50237. (str_store_string, s15, "str__i_am_acting_independently_because_our_marshal_is_currently_indisposed"),
  50238. (try_end),
  50239. (else_try),
  50240. (neq, ":faction_ai_state", sfai_attacking_center),
  50241. (neq, ":faction_ai_state", sfai_raiding_village),
  50242. (neq, ":faction_ai_state", sfai_attacking_enemies_around_center),
  50243. (neq, ":faction_ai_state", sfai_attacking_enemy_army),
  50244. (neq, ":faction_ai_state", sfai_gathering_army),
  50245.  
  50246. #Not doing an offensive
  50247. (try_begin),
  50248. (eq, ":troop_no", "$g_talk_troop"),
  50249. (str_store_string, s15, "str__i_am_acting_independently_because_our_realm_is_currently_not_on_campaign"),
  50250. (try_end),
  50251. (else_try),
  50252. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_marshall"),
  50253. (assign, ":relation_with_marshall", reg0),
  50254.  
  50255. (try_begin),
  50256. (le, ":relation_with_marshall", -10),
  50257. (assign, ":acceptance_level", 10000),
  50258. (else_try),
  50259. (store_mul, ":acceptance_level", ":relation_with_marshall", -1000),
  50260. (try_end),
  50261.  
  50262. (val_add, ":acceptance_level", 1500),
  50263.  
  50264. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  50265. (try_begin),
  50266. (neq, ":faction_no", "$players_kingdom"),
  50267. (try_begin),
  50268. (eq, ":reduce_campaign_ai", 0), #hard
  50269. (val_add, ":acceptance_level", -1250),
  50270. (else_try),
  50271. (eq, ":reduce_campaign_ai", 1), #moderate
  50272. (else_try),
  50273. (eq, ":reduce_campaign_ai", 2), #easy
  50274. (val_add, ":acceptance_level", 1250),
  50275. (try_end),
  50276. (else_try),
  50277. (faction_slot_eq, ":faction_no", slot_faction_marshall, "trp_player"),
  50278. (try_begin),
  50279. (eq, ":reduce_campaign_ai", 0), #hard/player's faction
  50280. (val_add, ":acceptance_level", -1000),
  50281. (else_try),
  50282. (eq, ":reduce_campaign_ai", 1), #moderate/player's faction
  50283. (val_add, ":acceptance_level", -1500),
  50284. (else_try),
  50285. (eq, ":reduce_campaign_ai", 2), #easy/player's faction
  50286. (val_add, ":acceptance_level", -2000),
  50287. (try_end),
  50288. (try_end),
  50289.  
  50290. (troop_get_slot, ":temp_ai_seed", ":troop_no", slot_troop_temp_decision_seed),
  50291.  
  50292. (le, ":temp_ai_seed", ":acceptance_level"),
  50293.  
  50294. #Very low opinion of marshall
  50295. (try_begin),
  50296. (eq, ":troop_no", "$g_talk_troop"),
  50297. (str_store_string, s15, "str__i_am_not_accompanying_the_marshal_because_i_fear_that_he_may_lead_us_into_disaster"),
  50298. (try_end),
  50299. #Make nuanced, depending on personality type
  50300. (else_try),
  50301. (troop_get_slot, ":marshal_controversy", ":faction_marshall", slot_faction_marshall),
  50302.  
  50303. (lt, ":relation_with_marshall", 0),
  50304. (ge, ":marshal_controversy", 50),
  50305.  
  50306. (try_begin),
  50307. (eq, ":troop_no", "$g_talk_troop"),
  50308. (str_store_string, s15, "str_i_am_not_accompanying_the_marshal_because_i_question_his_judgment"),
  50309. (try_end),
  50310. (else_try),
  50311. (troop_get_slot, ":marshal_controversy", ":faction_marshall", slot_faction_marshall),
  50312. (neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":faction_marshall"),
  50313.  
  50314. (lt, ":relation_with_marshall", 5),
  50315. (ge, ":marshal_controversy", 80),
  50316.  
  50317. (try_begin),
  50318. (eq, ":troop_no", "$g_talk_troop"),
  50319. (str_store_string, s15, "str_i_am_not_accompanying_the_marshal_because_will_be_reappointment"),
  50320. (try_end),
  50321. (else_try),
  50322. #(lt, ":relation_with_marshall", 45),
  50323. #(eq, ":faction_marshall", "trp_player"), #moved below as only effector. Search "think about this".
  50324.  
  50325. (store_sub, ":relation_with_marshal_difference", 50, ":relation_with_marshall"),
  50326.  
  50327. #for 50 relation with marshal ":acceptance_level" will be 0
  50328. #for 20 relation with marshal ":acceptance_level" will be 2100
  50329. #for 10 relation with marshal ":acceptance_level" will be 2800
  50330. #for 0 relation with marshal ":acceptance_level" will be 3500
  50331. #for -10 relation with marshal ":acceptance_level" will be 4200
  50332. #average is about 2500
  50333. (store_mul, ":acceptance_level", ":relation_with_marshal_difference", 70),
  50334.  
  50335. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  50336. (try_begin),
  50337. (neq, ":faction_no", "$players_kingdom"),
  50338.  
  50339. (try_begin),
  50340. (eq, ":reduce_campaign_ai", 0), #hard
  50341. (val_add, ":acceptance_level", -1200),
  50342. (else_try),
  50343. (eq, ":reduce_campaign_ai", 1), #moderate
  50344. (else_try),
  50345. (eq, ":reduce_campaign_ai", 2), #easy
  50346. (val_add, ":acceptance_level", 1200),
  50347. (try_end),
  50348. (else_try),
  50349. (eq, ":faction_marshall", "trp_player"),
  50350.  
  50351. (try_begin),
  50352. (eq, ":reduce_campaign_ai", 0), #hard
  50353. (val_add, ":acceptance_level", -1000),
  50354. (else_try),
  50355. (eq, ":reduce_campaign_ai", 1), #moderate
  50356. (val_add, ":acceptance_level", -1500),
  50357. (else_try),
  50358. (eq, ":reduce_campaign_ai", 2), #easy
  50359. (val_add, ":acceptance_level", -2000),
  50360. (try_end),
  50361. (try_end),
  50362.  
  50363. (try_begin),
  50364. (eq, ":troop_reputation", lrep_selfrighteous),
  50365. (val_add, ":acceptance_level", 1500),
  50366. (else_try),
  50367. (this_or_next|eq, ":troop_reputation", lrep_martial),
  50368. (this_or_next|eq, ":troop_reputation", lrep_roguish),
  50369. (eq, ":troop_reputation", lrep_quarrelsome),
  50370. (val_add, ":acceptance_level", 1000),
  50371. (else_try),
  50372. (eq, ":troop_reputation", lrep_cunning),
  50373. (val_add, ":acceptance_level", 500),
  50374. (else_try),
  50375. (eq, ":troop_reputation", lrep_upstanding), #neutral
  50376. (else_try),
  50377. (this_or_next|eq, ":troop_reputation", lrep_benefactor), #helper
  50378. (eq, ":troop_reputation", lrep_goodnatured),
  50379. (val_add, ":acceptance_level", -500),
  50380. (else_try),
  50381. (eq, ":troop_reputation", lrep_custodian), #very helper
  50382. (val_add, ":acceptance_level", -1000),
  50383. (try_end),
  50384.  
  50385. (try_begin),
  50386. (troop_slot_eq, ":faction_marshall", slot_lord_reputation_type, lrep_quarrelsome),
  50387. (val_add, ":acceptance_level", -750),
  50388. (else_try),
  50389. (this_or_next|troop_slot_eq, ":faction_marshall", slot_lord_reputation_type, lrep_martial),
  50390. (troop_slot_eq, ":faction_marshall", slot_lord_reputation_type, lrep_upstanding),
  50391. (val_add, ":acceptance_level", -250),
  50392. (try_end),
  50393.  
  50394. (val_add, ":acceptance_level", 2000),
  50395. #average become 2500 + 2000 = 4500, (45% of lords will not join campaign because of this reason. (33% for hard, 57% for easy, 30% for marshal player))
  50396.  
  50397. ##diplomacy start+ Apply centralization.
  50398. #Adjusting acceptance level seems a natural place to represent this.
  50399. (store_mul, reg0, ":centralization", 100),
  50400. (val_clamp, reg0, -300, 301),#should be unnecessary
  50401. (val_sub, ":acceptance_level", reg0),#adjust the chance of following the marshall by +/- 1% for every step of centralization
  50402. ##diplomacy end+
  50403. (troop_get_slot, ":temp_ai_seed", ":troop_no", slot_troop_temp_decision_seed),
  50404.  
  50405. (le, ":temp_ai_seed", ":acceptance_level"),
  50406.  
  50407. (try_begin),
  50408. (eq, ":troop_no", "$g_talk_troop"),
  50409. (str_store_string, s15, "str_i_am_not_accompanying_the_marshal_because_i_can_do_greater_deeds"),
  50410. (try_end),
  50411.  
  50412. #(try_begin),
  50413. # (ge, "$cheat_mode", 1),
  50414. # (assign, reg7, ":acceptance_level"),
  50415. # (assign, reg8, ":relation_with_marshall"),
  50416. # (display_message, "@{!}DEBUGS : acceptance level : {reg7}, relation with marshal : {reg8}"),
  50417. #(try_end),
  50418. (else_try),
  50419. (store_current_hours, ":hours_since_last_faction_rest"),
  50420. (faction_get_slot, ":last_rest_time", ":faction_no", slot_faction_ai_last_rest_time),
  50421. (val_sub, ":hours_since_last_faction_rest", ":last_rest_time"),
  50422.  
  50423. #nine days on average, marshal will usually end after 10 days
  50424. #ozan changed, 360 hours (15 days) in average, marshal cannot end it during a siege attack/defence anymore.
  50425. (assign, ":troop_campaign_limit", 360),
  50426. (store_mul, ":marshal_relation_modifier", ":relation_with_marshall", 6), #ozan changed 4 to 6.
  50427. (val_add, ":troop_campaign_limit", ":marshal_relation_modifier"),
  50428.  
  50429. (try_begin),
  50430. (eq, ":troop_reputation", lrep_upstanding),
  50431. (val_mul, ":troop_campaign_limit", 4),
  50432. (val_div, ":troop_campaign_limit", 3),
  50433. (try_end),
  50434.  
  50435. (str_store_troop_name, s16, ":faction_marshall"),
  50436.  
  50437. (gt, ":hours_since_last_faction_rest", ":troop_campaign_limit"),
  50438.  
  50439. #Too long a campaign
  50440. (try_begin),
  50441. (eq, ":troop_no", "$g_talk_troop"),
  50442. (str_store_string, s15, "str__s16_has_kept_us_on_campaign_on_far_too_long_and_there_are_other_pressing_matters_to_which_i_must_attend"),
  50443. (try_end),
  50444. #Also make nuanced, depending on personality type
  50445. (else_try),
  50446. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  50447. (neg|party_is_active, ":party_no"),
  50448. #This string should not occur, as it will only happen if a lord is contemplating following the player
  50449. (else_try),
  50450. (troop_get_slot, ":marshal_party", ":faction_marshall", slot_troop_leaded_party),
  50451.  
  50452. (assign, ":information_radius", 40),
  50453. (try_begin),
  50454. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_gathering_army),
  50455. (assign, ":information_radius", 50),
  50456. (try_end),
  50457.  
  50458. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  50459. (try_begin),
  50460. (neq, ":faction_no", "fac_player_supporters_faction"),
  50461. (neq, ":faction_no", "$players_kingdom"),
  50462. ##diplomacy start+ the player may be able to become leader in other situations
  50463. (neg|faction_slot_eq, ":faction_no", slot_faction_leader, "trp_player"),
  50464. ##diplomacy end+
  50465. (try_begin),
  50466. (eq, ":reduce_campaign_ai", 2), #easy
  50467. (try_begin),
  50468. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_gathering_army),
  50469. (val_add, ":information_radius", -10),
  50470. (else_try),
  50471. (val_add, ":information_radius", -8),
  50472. (try_end),
  50473. (else_try),
  50474. (eq, ":reduce_campaign_ai", 1), #moderate
  50475. (try_begin),
  50476. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_gathering_army),
  50477. (val_add, ":information_radius", -5),
  50478. (else_try),
  50479. (val_add, ":information_radius", -4),
  50480. (try_end),
  50481. (try_end),
  50482. (else_try),
  50483. (try_begin),
  50484. (eq, ":reduce_campaign_ai", 2), #easy
  50485. (try_begin),
  50486. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_gathering_army),
  50487. (val_add, ":information_radius", 25),
  50488. (else_try),
  50489. (val_add, ":information_radius", 20),
  50490. (try_end),
  50491. (else_try),
  50492. (eq, ":reduce_campaign_ai", 1), #moderate
  50493. (try_begin),
  50494. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_gathering_army),
  50495. (val_add, ":information_radius", 15),
  50496. (else_try),
  50497. (val_add, ":information_radius", 12),
  50498. (try_end),
  50499. (else_try),
  50500. (eq, ":reduce_campaign_ai", 0), #hard
  50501. (try_begin),
  50502. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_gathering_army),
  50503. (val_add, ":information_radius", 5),
  50504. (else_try),
  50505. (val_add, ":information_radius", 4),
  50506. (try_end),
  50507. (try_end),
  50508. (try_end),
  50509. ##diplomacy start+ Apply centralization to the AI here.
  50510. (store_add, reg0, 10, ":centralization"),
  50511. (val_clamp, reg0, 7, 14),#should be unnecessary
  50512. (val_mul, ":information_radius", reg0),
  50513. (val_add, ":information_radius", 5),
  50514. (val_div, ":information_radius", 10),#Adjust +/- 10% for every level of centralization
  50515. ##diplomacy end+
  50516.  
  50517. (faction_get_slot, ":faction_object", ":faction_no", slot_faction_ai_object),
  50518. (assign, reg17, 0),
  50519. (try_begin),
  50520. (try_begin),
  50521. (neg|is_between, ":faction_object", villages_begin, villages_end),
  50522. (assign, reg17, 1),
  50523. (try_end),
  50524. (try_begin),
  50525. (neg|faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_attacking_enemies_around_center),
  50526. (assign, reg17, 1),
  50527. (try_end),
  50528. (eq, reg17, 1),
  50529.  
  50530. (store_distance_to_party_from_party, ":distance", ":marshal_party", ":party_no"),
  50531.  
  50532. (gt, ":distance", ":information_radius"),
  50533.  
  50534. (try_begin),
  50535. (eq, ":troop_no", "$g_talk_troop"),
  50536. (str_store_string, s15, "str__i_am_not_participating_in_the_marshals_campaign_because_i_do_not_know_where_to_find_our_main_army"),
  50537. (try_end),
  50538. (else_try),
  50539. (eq, reg17, 0),
  50540.  
  50541. (assign, reg17, 1),
  50542. (try_begin),
  50543. #if we are already accompanying marshal forget below.
  50544. (party_slot_eq, ":party_no", slot_party_ai_state, spai_accompanying_army),
  50545. (party_slot_eq, ":party_no", slot_party_ai_object, ":marshal_party"),
  50546. (assign, reg17, 0),
  50547. (try_end),
  50548. (eq, reg17, 1),
  50549.  
  50550. #if faction ai is "attacking enemies around a center" is then do not find and compare distance to marshal, find and compare distance to "attacked village"
  50551. (party_get_slot, ":enemy_strength_nearby", ":faction_object", slot_center_sortie_enemy_strength),
  50552.  
  50553. (try_begin), #changes between 70..x (as ":enemy_strength_nearby" increases, ":information_radius" increases too.),
  50554. (ge, ":enemy_strength_nearby", 4000),
  50555. (val_sub, ":enemy_strength_nearby", 4000),
  50556. (store_div, ":information_radius", ":enemy_strength_nearby", 200),
  50557. (val_add, ":information_radius", 70),
  50558. (else_try), #changes between 30..70
  50559. (store_div, ":information_radius", ":enemy_strength_nearby", 100),
  50560. (val_add, ":information_radius", 30),
  50561. (try_end),
  50562.  
  50563. (store_distance_to_party_from_party, ":distance", ":faction_object", ":party_no"),
  50564.  
  50565. (gt, ":distance", ":information_radius"),
  50566.  
  50567. (try_begin),
  50568. (eq, ":troop_no", "$g_talk_troop"),
  50569. (str_store_string, s15, "str__i_am_acting_independently_although_some_enemies_have_been_spotted_within_our_borders_they_havent_come_in_force_and_the_local_troops_should_be_able_to_dispatch_them"),
  50570. (try_end),
  50571. (try_end),
  50572.  
  50573. (gt, ":distance", ":information_radius"),
  50574. (else_try),
  50575. (try_begin),
  50576. (eq, ":troop_no", "$g_talk_troop"),
  50577. (str_store_string, s15, "str__the_needs_of_the_realm_must_come_first"),
  50578. (try_end),
  50579. (assign, ":result", 1),
  50580. (try_end),
  50581.  
  50582. (assign, reg0, ":result"),
  50583. ]),
  50584.  
  50585. #script_find_total_prosperity_score
  50586. # INPUT: center_no
  50587. # OUTPUT: reg0 = total_prosperity_score
  50588. (
  50589. "find_total_prosperity_score",
  50590. [
  50591. (store_script_param, ":center_no", 1),
  50592.  
  50593. (try_begin), #":total_prosperity_score" changes between 10..100
  50594. (is_between, ":center_no", walled_centers_begin, walled_centers_end),
  50595.  
  50596. (party_get_slot, ":center_prosperity", ":center_no", slot_town_prosperity),
  50597. (store_add, ":center_prosperity_add_200_div_10", ":center_prosperity", 200),
  50598. (val_div, ":center_prosperity_add_200_div_10", 10),
  50599. (try_begin),
  50600. (is_between, ":center_no", towns_begin, towns_end),
  50601. (store_mul, ":this_center_score", ":center_prosperity_add_200_div_10", 15),
  50602. (else_try),
  50603. (store_mul, ":this_center_score", ":center_prosperity_add_200_div_10", 5),
  50604. (try_end),
  50605. (assign, ":total_prosperity_score", ":this_center_score"),
  50606.  
  50607. (try_for_range_backwards, ":village_no", villages_begin, villages_end),
  50608. (party_slot_eq, ":village_no", slot_village_bound_center, ":center_no"),
  50609.  
  50610. (party_get_slot, ":village_prosperity", ":village_no", slot_town_prosperity),
  50611. (store_add, ":village_prosperity_add_200_div_10", ":village_prosperity", 200),
  50612. (val_div, ":village_prosperity_add_200_div_10", 10),
  50613. (store_mul, ":this_village_score", ":village_prosperity_add_200_div_10", 5),
  50614.  
  50615. (val_add, ":total_prosperity_score", ":this_village_score"),
  50616. (try_end),
  50617. (else_try),
  50618. (party_get_slot, ":center_prosperity", ":center_no", slot_town_prosperity),
  50619. (store_add, ":center_prosperity_add_200_div_10", ":center_prosperity", 200),
  50620. (val_div, ":center_prosperity_add_200_div_10", 10),
  50621. (store_mul, ":this_center_score", ":center_prosperity_add_200_div_10", 5),
  50622. (assign, ":total_prosperity_score", ":this_center_score"),
  50623. (try_end),
  50624. (val_div, ":total_prosperity_score", 10),
  50625.  
  50626. (assign, reg0, ":total_prosperity_score"),
  50627. ]),
  50628.  
  50629. #script_calculate_center_assailability_score
  50630. # INPUT: faction_no
  50631. # param1: faction_no
  50632. # param2: all_vassals_included, (becomes 1 if we want to find attackable center if we collected 20% of vassals during gathering army phase)
  50633. # OUTPUT:
  50634. # reg0 = center_to_attack (-1 if none is logical)
  50635. # reg1 = maximum_attack_score
  50636. (
  50637. "calculate_center_assailability_score",
  50638. [
  50639. (store_script_param, ":troop_no", 1),
  50640. (store_script_param, ":potential_target", 2),
  50641. (store_script_param, ":all_vassals_included", 3),
  50642.  
  50643. (assign, ":target_score", -1),
  50644.  
  50645. (store_faction_of_troop, ":faction_no", ":troop_no"),
  50646.  
  50647. (store_current_hours, ":hours_since_last_offensive"),
  50648. (faction_get_slot, ":last_offensive_time", ":faction_no", slot_faction_last_offensive_concluded),
  50649. (val_sub, ":hours_since_last_offensive", ":last_offensive_time"),
  50650.  
  50651. (store_div, ":last_offensive_time_score", ":hours_since_last_offensive", 12), #30..50
  50652. (val_add, ":last_offensive_time_score", 30),
  50653. (val_min, ":last_offensive_time_score", 100),
  50654.  
  50655. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  50656.  
  50657. (assign, ":marshal_party", -1),
  50658. (assign, ":marshal_strength", 0),
  50659. #(assign, ":strength_of_nearby_friend", 0),
  50660.  
  50661. (try_begin),
  50662. (gt, ":faction_marshal", 0),
  50663. (troop_get_slot, ":marshal_party", ":faction_marshal", slot_troop_leaded_party),
  50664. (party_is_active, ":marshal_party"),
  50665. (party_get_slot, ":marshal_strength", ":marshal_party", slot_party_cached_strength),
  50666. #(eq, ":all_vassals_included", 0),
  50667. (party_get_slot, ":strength_of_current_followers", ":marshal_party", slot_party_follower_strength),
  50668. #(party_get_slot, ":strength_of_nearby_friend", ":marshal_party", slot_party_nearby_friend_strength),
  50669. (try_end),
  50670.  
  50671. #(try_begin),
  50672. # (eq, ":all_vassals_included", 0),
  50673. #
  50674. # (try_begin),
  50675. # (gt, ":faction_marshal", 0),
  50676. # (troop_get_slot, ":marshal_party", ":faction_marshal", slot_troop_leaded_party),
  50677. # (party_is_active, ":marshal_party"),
  50678. # (party_get_slot, ":strength_of_potential_followers", ":marshal_party", slot_party_follower_strength),
  50679. # (try_end),
  50680. #(else_try),
  50681. # (eq, ":all_vassals_included", 1),
  50682. #
  50683. # (assign, ":strength_of_potential_followers", 0),
  50684. #
  50685. # (try_for_parties, ":party_no"),
  50686. # (store_faction_of_party, ":party_faction", ":party_no"),
  50687. # (eq, ":party_faction", ":faction_no"),
  50688. # (neq, ":party_no", ":marshal_party"),
  50689. # (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_hero_party),
  50690. # (call_script, "script_party_calculate_strength", ":party_no", 0),
  50691. # (val_add, ":strength_of_potential_followers", reg0),
  50692. # (try_end),
  50693. #
  50694. # (val_div, ":strength_of_potential_followers", 2), #Ozan - Think about this, will you divide strength_of_potential_followers to 3 or 2.5 or 2
  50695. #(else_try),
  50696. # (assign, ":strength_of_potential_followers", 0),
  50697. #(try_end),
  50698.  
  50699. (faction_get_slot, ":last_attacked_center", ":faction_no", slot_faction_last_attacked_center),
  50700. (faction_get_slot, ":last_attacked_hours", ":faction_no", slot_faction_last_attacked_hours),
  50701.  
  50702. (try_begin),
  50703. (store_current_hours, ":hours"),
  50704. (store_add, ":last_attacked_hours_plus_24", ":last_attacked_hours", 24),
  50705. (gt, ":hours", ":last_attacked_hours_plus_24"),
  50706. (faction_set_slot, ":faction_no", slot_faction_last_attacked_center, 0),
  50707. (assign, ":last_attacked_center", 0),
  50708. (try_end),
  50709.  
  50710. (try_begin),
  50711. (this_or_next|eq, ":last_attacked_center", 0),
  50712. (this_or_next|eq, ":last_attacked_center", ":potential_target"),
  50713. (this_or_next|eq, "$g_do_not_skip_other_than_current_ai_object", 1),
  50714. (neg|faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  50715.  
  50716. (party_is_active, ":potential_target"),
  50717. (store_faction_of_party, ":potential_target_faction", ":potential_target"),
  50718.  
  50719. (store_relation, ":relation", ":potential_target_faction", ":faction_no"),
  50720. (lt, ":relation", 0),
  50721.  
  50722. #attack if and only if we are already besieging that center or anybody do not making besiege.
  50723. (assign, ":faction_of_besieger_party", -1),
  50724. (try_begin),
  50725. (is_between, ":potential_target", walled_centers_begin, walled_centers_end),
  50726. (neg|party_slot_eq, ":potential_target", slot_center_is_besieged_by, -1),
  50727. (party_get_slot, ":besieger_party", ":potential_target", slot_center_is_besieged_by),
  50728. (party_is_active, ":besieger_party"),
  50729. (store_faction_of_party, ":faction_of_besieger_party", ":besieger_party"),
  50730. (try_end),
  50731.  
  50732. (this_or_next|eq, ":faction_of_besieger_party", -1),
  50733. (eq, ":faction_of_besieger_party", ":faction_no"),
  50734.  
  50735. #attack if and only if this center is not a village or if it is village it should not be raided or looted
  50736. (assign, ":village_is_looted_or_raided_already", 0),
  50737. (try_begin),
  50738. (is_between, ":potential_target", villages_begin, villages_end),
  50739. (try_begin),
  50740. (party_slot_eq, ":potential_target", slot_village_state, svs_being_raided),
  50741. (party_get_slot, ":raider_party", ":potential_target", slot_village_raided_by),
  50742. (party_is_active, ":raider_party"),
  50743.  
  50744. (store_faction_of_party, ":raider_faction", ":raider_party"),
  50745. (neq, ":raider_faction", ":faction_no"),
  50746. (assign, ":raiding_by_one_other_faction", 1),
  50747. (else_try),
  50748. (assign, ":raiding_by_one_other_faction", 0),
  50749. (try_end),
  50750. (this_or_next|party_slot_eq, ":potential_target", slot_village_state, svs_looted),
  50751. (eq, ":raiding_by_one_other_faction", 1),
  50752. (assign, ":village_is_looted_or_raided_already", 1),
  50753. (try_end),
  50754. (eq, ":village_is_looted_or_raided_already", 0),
  50755.  
  50756. #if ":potential_target" is faction object of some other faction which is enemy to owner of
  50757. #":potential_target" then this target cannot be new target we are looking for.
  50758. (assign, ":this_potantial_target_is_target_of_some_other_faction", 0),
  50759. (try_for_range, ":cur_faction", kingdoms_begin, kingdoms_end),
  50760. (is_between, ":cur_faction", "fac_kingdom_1", kingdoms_end), #Excluding player kingdom
  50761. (neq, ":cur_faction", ":faction_no"),
  50762. (faction_get_slot, ":faction_object", ":cur_faction", slot_faction_ai_object),
  50763. (eq, ":faction_object", ":potential_target"),
  50764. (store_relation, ":rel", ":potential_target_faction", ":cur_faction"),
  50765. (lt, ":rel", 0),
  50766. (assign, ":this_potantial_target_is_target_of_some_other_faction", 1),
  50767. (try_end),
  50768. (eq, ":this_potantial_target_is_target_of_some_other_faction", 0),
  50769.  
  50770. (try_begin),
  50771. (is_between, ":potential_target", walled_centers_begin, walled_centers_end),
  50772. (party_get_slot, ":potential_target_inside_strength", ":potential_target", slot_party_cached_strength),
  50773. (party_get_slot, ":potential_target_nearby_enemy_strength", ":potential_target", slot_party_nearby_friend_strength),
  50774. (val_div, ":potential_target_nearby_enemy_strength", 2),
  50775. (store_add, ":potential_target_strength", ":potential_target_inside_strength", ":potential_target_nearby_enemy_strength"),
  50776.  
  50777. #(try_begin),
  50778. #(eq, ":faction_no", "fac_kingdom_4"),
  50779. #(assign, reg0, ":potential_target_inside_strength"),
  50780. #(assign, reg1, ":potential_target_nearby_enemy_strength"),
  50781. #(assign, reg2, ":marshal_strength"),
  50782. #(assign, reg3, ":strength_of_potential_followers"),
  50783. #(assign, reg4, ":strength_of_nearby_friend"),
  50784. #(assign, reg6, ":marshal_party"),
  50785. #(str_store_party_name, s8, ":potential_target"),
  50786. #(eq, ":all_vassals_included", 0),
  50787. #(display_message, "@DEBUG : {s8}:{reg0}, neare {reg1}, our {reg2}, follow {reg3}, nearf {reg4}"),
  50788. #(try_end),
  50789.  
  50790. (val_mul, ":potential_target_strength", 4), #in walled centers defenders have advantage.
  50791. (val_div, ":potential_target_strength", 3),
  50792.  
  50793. #(store_add, ":army_strength", ":marshal_strength", ":strength_of_potential_followers"),
  50794. (assign, ":army_strength", ":marshal_strength"),
  50795. (val_add, ":army_strength", ":strength_of_current_followers"),
  50796. (store_mul, ":power_ratio", ":army_strength", 100),
  50797.  
  50798. #this ratio ":power_ratio" shows (our total army power) / (their total army power)
  50799. (try_begin),
  50800. (gt, ":potential_target_strength", 0),
  50801. (val_div, ":power_ratio", ":potential_target_strength"),
  50802. (else_try),
  50803. (assign, ":power_ratio", 1000),
  50804. (try_end),
  50805. (else_try),
  50806. (party_get_slot, ":potential_target_nearby_enemy_strength", ":potential_target", slot_party_nearby_friend_strength),
  50807. (assign, ":potential_target_strength", 1000),
  50808.  
  50809. #(store_add, ":army_strength", ":marshal_strength", ":strength_of_potential_followers"),
  50810. (assign, ":army_strength", ":marshal_strength"),
  50811. (val_add, ":army_strength", ":strength_of_current_followers"),
  50812. (store_mul, ":power_ratio", ":army_strength", 100),
  50813.  
  50814. (try_begin),
  50815. (gt, ":potential_target_strength", 0),
  50816. (val_div, ":power_ratio", ":potential_target_strength"),
  50817. (else_try),
  50818. (assign, ":power_ratio", 1000),
  50819. (try_end),
  50820. (try_end),
  50821.  
  50822. (ge, ":power_ratio", 120), #attack if and only if our army is at least 1.2 times powerfull
  50823. (store_sub, ":power_ratio_sub_120", ":power_ratio", 120),
  50824.  
  50825. (try_begin),
  50826. (lt, ":power_ratio_sub_120", 100), #changes between 20..120
  50827. (store_add, ":power_ratio_score", ":power_ratio_sub_120", 20),
  50828. (else_try),
  50829. (lt, ":power_ratio_sub_120", 200), #changes between 120..170
  50830. (store_sub, ":power_ratio_score", ":power_ratio_sub_120", 100),
  50831. (val_div, ":power_ratio_score", 2),
  50832. (val_add, ":power_ratio_score", 120),
  50833. (else_try),
  50834. (lt, ":power_ratio_sub_120", 400), #changes between 170..210
  50835. (store_sub, ":power_ratio_score", ":power_ratio_sub_120", 200),
  50836. (val_div, ":power_ratio_score", 5),
  50837. (val_add, ":power_ratio_score", 170),
  50838. (else_try),
  50839. (lt, ":power_ratio_sub_120", 800), #changes between 210..250
  50840. (store_sub, ":power_ratio_score", ":power_ratio_sub_120", 400),
  50841. (val_div, ":power_ratio_score", 10),
  50842. (val_add, ":power_ratio_score", 210),
  50843. (else_try),
  50844. (assign, ":power_ratio_score", 250),
  50845. (try_end),
  50846.  
  50847. (assign, ":number_of_walled_centers", 0),
  50848. (assign, ":total_distance", 0),
  50849. (try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
  50850. (store_faction_of_party, ":walled_center_faction", ":walled_center"),
  50851. (eq, ":walled_center_faction", ":faction_no"),
  50852.  
  50853. (store_distance_to_party_from_party, ":dist", ":walled_center", ":potential_target"),
  50854. (val_add, ":total_distance", ":dist"),
  50855.  
  50856. (val_add, ":number_of_walled_centers", 1),
  50857. (try_end),
  50858.  
  50859. (try_begin),
  50860. (gt, ":number_of_walled_centers", 0),
  50861. (store_div, ":average_distance", ":total_distance", ":number_of_walled_centers"),
  50862. #(assign, reg0, ":average_distance"),
  50863. #(str_store_faction_name, s7, ":faction_no"),
  50864. #(str_store_party_name, s8, ":potential_target"),
  50865. #(display_message, "@average distance for {s7} for {s8} is {reg0}"),
  50866.  
  50867. (try_begin),
  50868. (ge, ":marshal_party", 0),
  50869. (party_is_active, ":marshal_party"),
  50870. (store_distance_to_party_from_party, ":marshal_dist_to_potential_target", ":marshal_party", ":potential_target"),
  50871. (else_try),
  50872. (assign, ":marshal_dist_to_potential_target", 100),
  50873. (try_end),
  50874.  
  50875. (try_begin),
  50876. #if currently main aim of our faction is attacking to an enemy center and that center is already besieged/raided by one of
  50877. #our parties then divide marshal_dist_to_potential_target_div_x score for current center to "3/2" instead of "3" and this
  50878. #result in decrease at distance_score, and also decrease some scores from power_ratio_score in order to avoid frequently
  50879. #changes at main aimed target city of our faction during sieges.
  50880.  
  50881. (faction_get_slot, ":current_ai_state", ":faction_no", slot_faction_ai_state),
  50882. (eq, ":current_ai_state", sfai_attacking_center),
  50883. (faction_get_slot, ":current_ai_object", ":faction_no", slot_faction_ai_object),
  50884.  
  50885. (ge, ":current_ai_object", 0),
  50886. (neq, ":current_ai_object", ":potential_target"),
  50887.  
  50888. (try_begin),
  50889. (ge, ":power_ratio_score", 300), #200 max
  50890. (assign, ":power_ratio_score", 200),
  50891. (else_try),
  50892. (ge, ":power_ratio_score", 100), #100..200
  50893. (val_sub, ":power_ratio_score", 100),
  50894. (val_div, ":power_ratio_score", 2),
  50895. (val_add, ":power_ratio_score", 100),
  50896. (try_end),
  50897.  
  50898. (try_begin),
  50899. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  50900. (eq, "$g_do_not_skip_other_than_current_ai_object", 0),
  50901. (assign, ":power_ratio_score", 0), #lets completely forget all other choices if we are already besieging one center.
  50902. (try_end),
  50903.  
  50904. (faction_set_slot, ":faction_no", slot_faction_last_attacked_center, ":current_ai_object"),
  50905. (store_current_hours, ":hours"),
  50906. (faction_set_slot, ":faction_no", slot_faction_last_attacked_hours, ":hours"),
  50907.  
  50908. (eq, ":all_vassals_included", 0),
  50909.  
  50910. (store_mul, ":marshal_dist_to_potential_target_div_x", ":marshal_dist_to_potential_target", 2),
  50911. (val_div, ":marshal_dist_to_potential_target_div_x", 3),
  50912. (else_try),
  50913. (store_div, ":marshal_dist_to_potential_target_div_x", ":marshal_dist_to_potential_target", 3),
  50914. (try_end),
  50915.  
  50916. (store_add, ":total_distance", ":average_distance", ":marshal_dist_to_potential_target_div_x"), #in average ":total_distance" is about 150, min : 0, max : 1000
  50917. (else_try),
  50918. (assign, ":total_distance", 100),
  50919. (try_end),
  50920.  
  50921. (try_begin),
  50922. #according to cautious troop distance is more important
  50923. ##diplomacy start+ Take into account lady & companion personality types
  50924. ##OLD:
  50925. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  50926. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  50927. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  50928. #(troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  50929. #
  50930. ##NEW:
  50931. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  50932. (assign, ":troop_caution", reg0),
  50933. (gt, ":troop_caution", 0),
  50934. ##diplomacy end+
  50935.  
  50936. (try_begin),
  50937. (lt, ":total_distance", 30), #very close (100p)
  50938. (assign, ":distance_score", 100),
  50939. (else_try),
  50940. (lt, ":total_distance", 80), #close (50p-100p)
  50941. (store_sub, ":distance_score", ":total_distance", 30),
  50942. (val_div, ":distance_score", 1),
  50943. (store_sub, ":distance_score", 100, ":distance_score"),
  50944. (else_try),
  50945. (lt, ":total_distance", 160), #far (10p-50p)
  50946. (store_sub, ":distance_score", ":total_distance", 80),
  50947. (val_div, ":distance_score", 2),
  50948. (store_sub, ":distance_score", 50, ":distance_score"),
  50949. (else_try),
  50950. (assign, ":distance_score", 10), #very far
  50951. (try_end),
  50952. (else_try),
  50953. #according to agressive troop distance is less important
  50954.  
  50955. (try_begin),
  50956. (lt, ":total_distance", 40), #very close (100p)
  50957. (assign, ":distance_score", 100),
  50958. (else_try),
  50959. (lt, ":total_distance", 140), #close (50p-100p)
  50960. (store_sub, ":distance_score", ":total_distance", 40),
  50961. (val_div, ":distance_score", 2),
  50962. (store_sub, ":distance_score", 100, ":distance_score"),
  50963. (else_try),
  50964. (lt, ":total_distance", 300), #far (10p-50p)
  50965. (store_sub, ":distance_score", ":total_distance", 140),
  50966. (val_div, ":distance_score", 4),
  50967. (store_sub, ":distance_score", 50, ":distance_score"),
  50968. (else_try),
  50969. (assign, ":distance_score", 10), #very far
  50970. (try_end),
  50971. (try_end),
  50972. ##diplomacy start+ If AI changes are enabled, reduce distance penalty (increase score)
  50973. ##for recently-lost fiefs.
  50974. (try_begin),
  50975. (lt, ":distance_score", 100),
  50976. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  50977. (party_slot_eq, ":potential_target", slot_center_ex_faction, ":faction_no"),
  50978. (party_get_slot, reg0, ":potential_target", dplmc_slot_center_last_transfer_time),
  50979. (gt, reg0, 0),#0 means the slot was uninitialized. A negative number would be before the start of the game.
  50980. (store_current_hours, ":hours_since_transfer"),
  50981. (val_sub, ":hours_since_transfer", reg0),
  50982. (try_begin),
  50983. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_HIGH),
  50984. (assign, reg0, 24 * 21),#within last three weeks
  50985. (else_try),
  50986. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  50987. (assign, reg0, 24 * 14),#within last two weeks
  50988. (else_try),
  50989. (assign, reg0, 24 * 7),#within last week
  50990. (try_end),
  50991. (lt, ":hours_since_transfer", reg0),
  50992. (val_add, ":distance_score", 100),
  50993. (val_div, ":distance_score", 2),
  50994. (try_end),
  50995. ##diplomacy end+
  50996.  
  50997. (store_mul, ":target_score", ":distance_score", ":power_ratio_score"),
  50998. (val_mul, ":target_score", ":last_offensive_time_score"),
  50999. (val_div, ":target_score", 100), #target score is between 0..10000 generally here
  51000.  
  51001. (call_script, "script_find_total_prosperity_score", ":potential_target"),
  51002. (assign, ":total_prosperity_score", reg0),
  51003.  
  51004. #(try_begin), #new for increase attackability of villages by ai
  51005. #(is_between, ":potential_target", villages_begin, villages_end),
  51006. (val_mul, ":total_prosperity_score", 3),
  51007. (val_div, ":total_prosperity_score", 2),
  51008. #(try_end),
  51009.  
  51010. (val_mul, ":target_score", ":total_prosperity_score"),
  51011.  
  51012. (try_begin), #if both that center was our (original center) and (ex center) than bonus is 1.2x
  51013. (party_slot_eq, ":potential_target", slot_center_ex_faction, ":faction_no"),
  51014. (party_slot_eq, ":potential_target", slot_center_original_faction, ":faction_no"),
  51015. (val_mul, ":target_score", 12),
  51016. (val_div, ":target_score", 10),
  51017. (else_try), #if either that center was our (original center) or (ex center) than bonus is 1.1x
  51018. (this_or_next|party_slot_eq, ":potential_target", slot_center_ex_faction, ":faction_no"),
  51019. (party_slot_eq, ":potential_target", slot_center_original_faction, ":faction_no"),
  51020. (val_mul, ":target_score", 11),
  51021. (val_div, ":target_score", 10),
  51022. (try_end),
  51023.  
  51024. (val_div, ":target_score", 1000), #target score is between 0..1000 generally here
  51025.  
  51026. (try_begin),
  51027. (eq, ":potential_target_faction", "fac_player_supporters_faction"),
  51028. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  51029.  
  51030. (assign, ":number_of_walled_centers_player_have", 0),
  51031. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  51032. (store_faction_of_party, ":center_faction", ":center_no"),
  51033. (eq, ":center_faction", "fac_player_supporters_faction"),
  51034. (val_add, ":number_of_walled_centers_player_have", 1),
  51035. (try_end),
  51036.  
  51037. (try_begin),
  51038. (eq, ":reduce_campaign_ai", 2), #easy
  51039.  
  51040. (try_begin),
  51041. (le, ":number_of_walled_centers_player_have", 2),
  51042. (assign, ":hardness_score", 0),
  51043. (else_try),
  51044. (eq, ":number_of_walled_centers_player_have", 3),
  51045. (assign, ":hardness_score", 20),
  51046. (else_try),
  51047. (eq, ":number_of_walled_centers_player_have", 4),
  51048. (assign, ":hardness_score", 40),
  51049. (else_try),
  51050. (eq, ":number_of_walled_centers_player_have", 5),
  51051. (eq, ":number_of_walled_centers_player_have", 6),
  51052. (assign, ":hardness_score", 55),
  51053. (else_try),
  51054. (eq, ":number_of_walled_centers_player_have", 7),
  51055. (eq, ":number_of_walled_centers_player_have", 8),
  51056. (eq, ":number_of_walled_centers_player_have", 9),
  51057. (assign, ":hardness_score", 70),
  51058. (else_try),
  51059. (assign, ":hardness_score", 85),
  51060. (try_end),
  51061. (else_try),
  51062. (eq, ":reduce_campaign_ai", 1), #medium
  51063.  
  51064. (try_begin),
  51065. (le, ":number_of_walled_centers_player_have", 1),
  51066. (assign, ":hardness_score", 25),
  51067. (else_try),
  51068. (eq, ":number_of_walled_centers_player_have", 2),
  51069. (assign, ":hardness_score", 45),
  51070. (else_try),
  51071. (eq, ":number_of_walled_centers_player_have", 3),
  51072. (assign, ":hardness_score", 60),
  51073. (else_try),
  51074. (eq, ":number_of_walled_centers_player_have", 4),
  51075. (eq, ":number_of_walled_centers_player_have", 5),
  51076. (assign, ":hardness_score", 75),
  51077. (else_try),
  51078. (eq, ":number_of_walled_centers_player_have", 6),
  51079. (eq, ":number_of_walled_centers_player_have", 7),
  51080. (eq, ":number_of_walled_centers_player_have", 8),
  51081. (assign, ":hardness_score", 85),
  51082. (else_try),
  51083. (assign, ":hardness_score", 92),
  51084. (try_end),
  51085. (else_try), #hard
  51086. (assign, ":hardness_score", 100),
  51087. (try_end),
  51088.  
  51089. (val_mul, ":target_score", ":hardness_score"),
  51090. (val_div, ":target_score", 100),
  51091. (try_end),
  51092.  
  51093. (try_begin),
  51094. (ge, "$cheat_mode", 1),
  51095. (eq, ":faction_no", "fac_kingdom_4"),
  51096. (ge, ":target_score", -1),
  51097. (assign, reg0, ":target_score"),
  51098. (assign, reg7, ":total_prosperity_score"),
  51099. (assign, reg8, ":power_ratio_score"),
  51100. (assign, reg9, ":distance_score"),
  51101. (assign, reg10, ":last_offensive_time_score"),
  51102. (str_store_party_name, s8, ":potential_target"),
  51103. #(eq, ":all_vassals_included", 0),
  51104. (assign, reg11, ":all_vassals_included"),
  51105. #(display_message, "@DEBUG : attack of {s8} is {reg0}({reg11}), prs:{reg7}, pow:{reg8}, dis:{reg9}, lst:{reg10}"),
  51106. (try_end),
  51107. (try_end),
  51108.  
  51109. (assign, reg0, ":target_score"),
  51110. (assign, reg1, ":power_ratio"),
  51111. (assign, reg2, ":distance_score"),
  51112. (assign, reg3, ":total_prosperity_score"),
  51113. ]),
  51114.  
  51115. #script_find_center_to_defend
  51116. # INPUT:
  51117. # param1: faction_no
  51118. # OUTPUT:
  51119. # reg0 = center_to_defend (-1 if none is logical)
  51120. # reg1 = maximum_defend_score
  51121. # reg3 = enemy_strength_near_most_threatened_center
  51122. (
  51123. "find_center_to_defend",
  51124. [
  51125. (store_script_param, ":troop_no", 1),
  51126.  
  51127. (store_faction_of_troop, ":faction_no", ":troop_no"),
  51128.  
  51129. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  51130. (faction_get_slot, ":current_ai_state", ":faction_no", slot_faction_ai_state),
  51131. (assign, ":marshal_party", -1),
  51132. (try_begin),
  51133. (gt, ":faction_marshal", 0),
  51134. (troop_get_slot, ":marshal_party", ":faction_marshal", slot_troop_leaded_party),
  51135. (try_end),
  51136.  
  51137. (assign, ":most_threatened_center", -1),
  51138. (assign, ":maximum_threat_score", 0),
  51139. (try_for_range, ":cur_center", centers_begin, centers_end),
  51140. (store_faction_of_party, ":center_faction", ":cur_center"),
  51141. (eq, ":center_faction", ":faction_no"),
  51142.  
  51143. (party_get_slot, ":exact_enemy_strength", ":cur_center", slot_center_sortie_enemy_strength),
  51144. #Distort this to account for questionable intelligence
  51145. #(call_script, "script_reduce_exact_number_to_estimate", ":exact_enemy_strength"),
  51146. #(assign, ":enemy_strength_nearby", reg0),
  51147. (assign, ":enemy_strength_nearby", ":exact_enemy_strength"),
  51148.  
  51149. (assign, ":threat_importance", 0),
  51150. (try_begin),
  51151. (is_between, ":cur_center", walled_centers_begin, walled_centers_end),
  51152. (party_slot_ge, ":cur_center", slot_center_is_besieged_by, 0),
  51153.  
  51154. (call_script, "script_find_total_prosperity_score", ":cur_center"),
  51155. (assign, ":total_prosperity_score", reg0),
  51156.  
  51157. (party_get_slot, ":cur_center_strength", ":cur_center", slot_party_cached_strength),
  51158. (val_mul, ":cur_center_strength", 4),
  51159. (val_div, ":cur_center_strength", 3), #give 33% bonus to insiders because they are inside a castle
  51160.  
  51161. #I removed below line and assigned ":cur_center_nearby_strength" to 0, because if not when defender army comes to help
  51162. #threat become less because of high defence power but not yet enemy cleared.
  51163. #(party_get_slot, ":cur_center_nearby_strength", ":cur_center", slot_party_nearby_friend_strength),
  51164. (assign, ":cur_center_nearby_strength", 0),
  51165.  
  51166. (val_add, ":cur_center_strength", ":cur_center_nearby_strength"), #add nearby friends and find ":cur_center_strength"
  51167.  
  51168. (store_mul, ":power_ratio", ":enemy_strength_nearby", 100),
  51169. (val_add, ":cur_center_strength", 1),
  51170. (val_max, ":cur_center_strength", 1),
  51171. (val_div, ":power_ratio", ":cur_center_strength"),
  51172.  
  51173. (assign, ":player_is_attacking", 0),
  51174. (party_get_slot, ":besieger_party", ":cur_center", slot_center_is_besieged_by),
  51175. (try_begin),
  51176. (party_is_active, ":besieger_party"),
  51177. (try_begin),
  51178. (eq, ":besieger_party", "p_main_party"),
  51179. (assign, ":player_is_attacking", 1),
  51180. #(display_message, "@{!}DEBUG : player is attacking a center (1)"),
  51181. (else_try),
  51182. (store_faction_of_party, ":besieger_faction", ":besieger_party"),
  51183. (eq, ":besieger_faction", "fac_player_faction"),
  51184. (assign, ":player_is_attacking", 1),
  51185. #(display_message, "@{!}DEBUG : player is attacking a center (2)"),
  51186. (else_try),
  51187. (party_get_attached_to, ":player_is_attached_to", "p_main_party"),
  51188. (ge, ":player_is_attached_to", 0),
  51189. (eq, ":player_is_attached_to", ":besieger_party"),
  51190. (assign, ":player_is_attacking", 1),
  51191. #(display_message, "@{!}DEBUG : player is attacking a center (3)"),
  51192. (try_end),
  51193. (try_end),
  51194.  
  51195. (try_begin),
  51196. (eq, ":player_is_attacking", 0),
  51197.  
  51198. (try_begin),
  51199. (lt, ":power_ratio", 40), #changes between 1..1
  51200. (assign, ":threat_importance", 1),
  51201. (else_try),
  51202. (lt, ":power_ratio", 80), #changes between 1..7
  51203. (store_sub, ":threat_importance", ":power_ratio", 40),
  51204. (val_div, ":threat_importance", 5),
  51205. (val_add, ":threat_importance", 1), #1
  51206. (else_try),
  51207. (lt, ":power_ratio", 120), #changes between 7..17
  51208. (store_sub, ":threat_importance", ":power_ratio", 80),
  51209. (val_div, ":threat_importance", 4),
  51210. (val_add, ":threat_importance", 7), #1 + 6
  51211. (else_try),
  51212. (lt, ":power_ratio", 200),
  51213. (store_sub, ":threat_importance", ":power_ratio", 120),
  51214. (val_div, ":threat_importance", 10),
  51215. (val_add, ":threat_importance", 17), #1 + 6 + 10
  51216. (else_try),
  51217. (assign, ":threat_importance", 25),
  51218. (try_end),
  51219. (else_try),
  51220. (try_begin),
  51221. (lt, ":power_ratio", 200), #changes between 5..25
  51222. (store_div, ":threat_importance", ":power_ratio", 10), #MOTO correction (thanks MOTO:) (mexxico))
  51223. (val_add, ":threat_importance", 6 ),
  51224. (else_try),
  51225. (assign, ":threat_importance", 26),
  51226. (try_end),
  51227. (try_end),
  51228. (else_try),
  51229. (is_between, ":cur_center", villages_begin, villages_end),
  51230. (party_slot_eq, ":cur_center", slot_village_state, svs_being_raided),
  51231.  
  51232. (gt, ":enemy_strength_nearby", 0),
  51233.  
  51234. (call_script, "script_find_total_prosperity_score", ":cur_center"),
  51235. (assign, ":power_ratio", 100), #useless
  51236. (assign, ":total_prosperity_score", reg0),
  51237. (assign, ":threat_importance", 10), #if faction village is looted they lose money for shorter time period. So importance is something low (6-8).
  51238. (try_end),
  51239.  
  51240. (gt, ":threat_importance", 0),
  51241.  
  51242. (try_begin),
  51243. (is_between, ":cur_center", walled_centers_begin, walled_centers_end),
  51244. (assign, ":enemy_strength_nearby_score", 120),
  51245.  
  51246. (try_begin),
  51247. (ge, ":marshal_party", 0),
  51248. (party_is_active, ":marshal_party"),
  51249. (store_distance_to_party_from_party, ":marshal_dist_to_cur_center", ":marshal_party", ":cur_center"),
  51250. (else_try),
  51251. (assign, ":marshal_dist_to_cur_center", 100),
  51252. (try_end),
  51253.  
  51254. (try_begin),
  51255. #if currently our target is ride to break a siege then
  51256. #divide marshal_distance for other center's to "2" instead of "4" and add some small more distance to avoid easily
  51257. #changing mind during siege because of small score differences.
  51258.  
  51259. #(faction_get_slot, ":current_ai_state", ":faction_no", slot_faction_ai_state),
  51260. (eq, ":current_ai_state", sfai_attacking_enemies_around_center),
  51261. (faction_get_slot, ":current_ai_object", ":faction_no", slot_faction_ai_object),
  51262. (is_between, ":current_ai_object", walled_centers_begin, walled_centers_end),
  51263. (neq, ":current_ai_object", ":cur_center"),
  51264. (val_mul, ":marshal_dist_to_cur_center", 2),
  51265. (val_add, ":marshal_dist_to_cur_center", 20),
  51266. (try_end),
  51267.  
  51268. (val_mul, ":marshal_dist_to_cur_center", 2), #standard multipication (1.5x) to adjust distance scoring same with formula at find_center_to_attack
  51269. #(val_div, ":marshal_dist_to_cur_center", 2),
  51270.  
  51271. (try_begin),
  51272. (lt, ":marshal_dist_to_cur_center", 10), #very close (100p)
  51273. (assign, ":distance_score", 100),
  51274. (else_try),
  51275. (lt, ":marshal_dist_to_cur_center", 160), #close (50p-100p)
  51276. (store_sub, ":distance_score", ":marshal_dist_to_cur_center", 10),
  51277. (val_div, ":distance_score", 3),
  51278. (store_sub, ":distance_score", 100, ":distance_score"),
  51279. (else_try),
  51280. (lt, ":marshal_dist_to_cur_center", 360), #far (10p-50p)
  51281. (store_sub, ":distance_score", ":marshal_dist_to_cur_center", 250),
  51282. (val_div, ":distance_score", 5),
  51283. (store_sub, ":distance_score", 50, ":distance_score"),
  51284. (else_try),
  51285. (assign, ":distance_score", 10), #very far
  51286. (try_end),
  51287. (else_try),
  51288. (store_add, ":enemy_strength_nearby_score", ":enemy_strength_nearby", 20000),
  51289. (val_div, ":enemy_strength_nearby_score", 200),
  51290. (assign, ":distance_score", 70), #not related to marshal's position, because everybody is going same place (no gathering in most village raids)
  51291. (try_end),
  51292.  
  51293. ##diplomacy start+
  51294. (try_begin),
  51295. #AI changes LOW: Give priority to defending centers with lords
  51296. (le, DPLMC_AI_CHANGES_LOW, "$g_dplmc_ai_changes"),
  51297. (party_slot_ge, ":cur_center", slot_town_lord, 0),
  51298. (val_mul, ":threat_importance", 120),
  51299. (val_div, ":threat_importance", 100),
  51300. (try_end),
  51301. ##diplomacy end+
  51302. (store_mul, ":threat_score", ":enemy_strength_nearby_score", ":total_prosperity_score"),
  51303. (val_mul, ":threat_score", ":threat_importance"),
  51304. (val_mul, ":threat_score", ":distance_score"),
  51305. (val_div, ":threat_score", 10000),
  51306.  
  51307. (try_begin),
  51308. (ge, "$cheat_mode", 1),
  51309. (gt, ":threat_score", 0),
  51310. (eq, ":faction_no", "fac_kingdom_6"),
  51311. (assign, reg0, ":threat_score"),
  51312. (str_store_party_name, s32, ":cur_center"),
  51313. (assign, reg1, ":total_prosperity_score"),
  51314. (assign, reg2, ":enemy_strength_nearby_score"),
  51315. (assign, reg3, ":threat_importance"),
  51316. (assign, reg4, ":distance_score"),
  51317. #(display_message, "@{!}DEBUG : defend of {s32} is {reg0}, prosperity:{reg1}, enemy nearby:{reg2}, threat importance:{reg3}, distance: {reg4}"),
  51318. (try_end),
  51319.  
  51320. (gt, ":threat_score", ":maximum_threat_score"),
  51321.  
  51322. (assign, ":most_threatened_center", ":cur_center"),
  51323. (assign, ":maximum_threat_score", ":threat_score"),
  51324. (assign, ":enemy_strength_near_most_threatened_center", ":enemy_strength_nearby"),
  51325. (try_end),
  51326.  
  51327. (val_mul, ":maximum_threat_score", 3),
  51328. (val_div, ":maximum_threat_score", 2),
  51329.  
  51330. (assign, reg0, ":most_threatened_center"),
  51331. (assign, reg1, ":maximum_threat_score"),
  51332. (assign, reg2, ":enemy_strength_near_most_threatened_center"),
  51333. ]),
  51334.  
  51335.  
  51336. #script_npc_decision_checklist_peace_or_war
  51337. ##diplomacy start+
  51338. #Modified this to return additional information.
  51339. ##diplomacy end+
  51340. (
  51341. "npc_decision_checklist_peace_or_war",
  51342. #this script is used to add a bit more color to diplomacy, particularly with regards to the player
  51343.  
  51344. [
  51345. (store_script_param, ":actor_faction", 1),
  51346. (store_script_param, ":target_faction", 2),
  51347. (store_script_param, ":envoy", 3),
  51348.  
  51349. ##diplomacy start+
  51350. #Since "fac_player_supporters_faction" is used as a synonym for "the faction led by the player"
  51351. #in many places, correct this here.
  51352. (call_script, "script_dplmc_translate_inactive_player_supporter_faction_2", ":actor_faction", ":target_faction"),
  51353. (assign, ":actor_faction", reg0),
  51354. (assign, ":target_faction", reg1),
  51355. ##diplomacy end+
  51356.  
  51357. (assign, ":actor_strength", 0),
  51358. (assign, ":target_strength", 0),
  51359. (assign, ":actor_centers_held_by_target", 0),
  51360.  
  51361. # (assign, ":two_factions_share_border", 0),
  51362. (assign, ":third_party_war", 0),
  51363. (assign, ":num_third_party_wars", 0),
  51364.  
  51365. (assign, ":active_mutual_enemy", 0), #an active enemy with which the target is at war
  51366. (assign, "$g_concession_demanded", 0),
  51367. ##diplomacy start+
  51368. (assign, ":last_center_lost", 0),# last center lost to the target faction
  51369. (assign, ":last_center_lost_time", 0),# time the last center was lost to the target faction
  51370.  
  51371. #"Third party" after taking into account alliances
  51372. #(assign, ":actual_third_party_war", 0),
  51373. (assign, ":num_actual_third_party_wars", 0),
  51374. ##diplomacy end+
  51375.  
  51376. (store_relation, ":current_faction_relation", ":actor_faction", ":target_faction"),
  51377.  
  51378. (try_begin),
  51379. (eq, ":target_faction", "fac_player_supporters_faction"),
  51380. (assign, ":modified_honor_and_relation", "$player_honor"), #this can be affected by the emissary's skill
  51381.  
  51382. (val_add, ":target_strength", 2), #for player party
  51383. (else_try),
  51384. (assign, ":modified_honor_and_relation", 0), #this can be affected by the emissary's skill
  51385. (try_end),
  51386.  
  51387. (faction_get_slot, ":actor_leader", ":actor_faction", slot_faction_leader),
  51388. (faction_get_slot, ":target_leader", ":target_faction", slot_faction_leader),
  51389.  
  51390. (call_script, "script_troop_get_relation_with_troop", ":actor_leader", ":target_leader"),
  51391.  
  51392. (assign, ":relation_bonus", reg0),
  51393. (val_min, ":relation_bonus", 10),
  51394. (val_add, ":modified_honor_and_relation", ":relation_bonus"),
  51395.  
  51396. (str_store_troop_name, s15, ":actor_leader"),
  51397. (str_store_troop_name, s16, ":target_leader"),
  51398.  
  51399.  
  51400. (assign, ":war_damage_suffered", 0),
  51401. (assign, ":war_damage_inflicted", 0),
  51402.  
  51403. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction", ":actor_faction", ":target_faction"),
  51404. (assign, ":war_peace_truce_status", reg0),
  51405. (str_clear, s12),
  51406. (try_begin),
  51407. (eq, ":war_peace_truce_status", -2),
  51408. (str_store_string, s12, "str_s15_is_at_war_with_s16_"),
  51409.  
  51410. (store_add, ":war_damage_inflicted_slot", ":target_faction", slot_faction_war_damage_inflicted_on_factions_begin),
  51411. (val_sub, ":war_damage_inflicted_slot", kingdoms_begin),
  51412. (faction_get_slot, ":war_damage_inflicted", ":actor_faction", ":war_damage_inflicted_slot"),
  51413.  
  51414. (store_add, ":war_damage_suffered_slot", ":actor_faction", slot_faction_war_damage_inflicted_on_factions_begin),
  51415. (val_sub, ":war_damage_suffered_slot", kingdoms_begin),
  51416. (faction_get_slot, ":war_damage_suffered", ":target_faction", ":war_damage_suffered_slot"),
  51417.  
  51418.  
  51419. (else_try),
  51420. #truce in effect
  51421. (eq, ":war_peace_truce_status", 1),
  51422. (str_store_string, s12, "str_in_the_short_term_s15_has_a_truce_with_s16_as_a_matter_of_general_policy_"),
  51423. (else_try),
  51424. #provocation noted
  51425. (eq, ":war_peace_truce_status", -1),
  51426. (str_store_string, s12, "str_in_the_short_term_s15_was_recently_provoked_by_s16_and_is_under_pressure_to_declare_war_as_a_matter_of_general_policy_"),
  51427. (try_end),
  51428.  
  51429. #clear for dialog with lords
  51430. (try_begin),
  51431. (is_between, "$g_talk_troop", active_npcs_begin, active_npcs_end),
  51432. (str_clear, s12),
  51433. (try_end),
  51434.  
  51435. (try_begin),
  51436. (gt, ":envoy", -1),
  51437. (store_skill_level, ":persuasion_x_2", "skl_persuasion", ":envoy"),
  51438. (val_mul, ":persuasion_x_2", 2),
  51439. (val_add, ":modified_honor_and_relation", ":persuasion_x_2"),
  51440.  
  51441. (try_begin),
  51442. (eq, "$cheat_mode", 1),
  51443. (assign, reg4, ":modified_honor_and_relation"),
  51444. (display_message, "str_envoymodified_diplomacy_score_honor_plus_relation_plus_envoy_persuasion_=_reg4"),
  51445. (try_end),
  51446.  
  51447. (try_end),
  51448.  
  51449.  
  51450. (try_for_range, ":kingdom_to_reset", kingdoms_begin, kingdoms_end),
  51451. (faction_set_slot, ":kingdom_to_reset", slot_faction_temp_slot, 0),
  51452. (try_end),
  51453.  
  51454. (try_for_parties, ":party_no"),
  51455. (assign, ":party_value", 0),
  51456. (try_begin),
  51457. (is_between, ":party_no", towns_begin, towns_end),
  51458. (assign, ":party_value", 3),
  51459. (else_try),
  51460. (is_between, ":party_no", castles_begin, castles_end),
  51461. (assign, ":party_value", 2),
  51462. (else_try),
  51463. (is_between, ":party_no", villages_begin, villages_end),
  51464. (assign, ":party_value", 1),
  51465. (else_try),
  51466. (party_get_template_id, ":template", ":party_no"),
  51467. (eq, ":template", "pt_kingdom_hero_party"),
  51468. (assign, ":party_value", 2),
  51469. (try_end),
  51470.  
  51471.  
  51472. (store_faction_of_party, ":party_current_faction", ":party_no"),
  51473. (party_get_slot, ":party_original_faction", ":party_no", slot_center_original_faction),
  51474. (party_get_slot, ":party_ex_faction", ":party_no", slot_center_ex_faction),
  51475.  
  51476.  
  51477. #total strengths
  51478. (try_begin),
  51479. (is_between, ":party_current_faction", kingdoms_begin, kingdoms_end),
  51480. (faction_get_slot, ":faction_strength", ":party_current_faction", slot_faction_temp_slot),
  51481. (val_add, ":faction_strength", ":party_value"),
  51482. (faction_set_slot, ":party_current_faction", slot_faction_temp_slot, ":faction_strength"),
  51483. (try_end),
  51484.  
  51485.  
  51486. (try_begin),
  51487. (eq, ":party_current_faction", ":target_faction"),
  51488. (val_add, ":target_strength", ":party_value"),
  51489.  
  51490. (try_begin),
  51491. (this_or_next|eq, ":party_original_faction", ":actor_faction"),
  51492. (eq, ":party_ex_faction", ":actor_faction"),
  51493. (val_add, ":actor_centers_held_by_target", 1),
  51494. (try_begin),
  51495. (is_between, ":party_no", walled_centers_begin, walled_centers_end),
  51496. (assign, "$g_concession_demanded", ":party_no"),
  51497. (str_store_party_name, s18, "$g_concession_demanded"),
  51498. ##diplomacy start+ Also track the most recently taken walled center
  51499. (eq, ":party_ex_faction", ":actor_faction"),
  51500. (this_or_next|lt, ":last_center_lost", 1),
  51501. (party_slot_ge, ":party_no", dplmc_slot_center_last_transfer_time, ":last_center_lost_time"),
  51502. (assign, ":last_center_lost", ":party_no"),
  51503. (party_get_slot, ":last_center_lost_time", ":party_no", dplmc_slot_center_last_transfer_time),
  51504. ##diplomacy end+
  51505. (try_end),
  51506. (try_end),
  51507.  
  51508. # Could include two factions share border, but war is unlikely to break out in the first place unless there is a common border
  51509.  
  51510. # (try_begin),
  51511. # (is_between, ":party_no", walled_centers_begin, walled_centers_end),
  51512. # (try_for_range, ":other_center", walled_centers_begin, walled_centers_end),
  51513. # (assign, ":two_factions_share_border", 0),
  51514. # (store_faction_of_party, ":other_faction", ":other_center"),
  51515. # (eq, ":other_faction", ":actor_faction"),
  51516. # (store_distance_to_party_from_party, ":distance", ":party_no", ":other_center"),
  51517. # (le, ":distance", 15),
  51518. # (assign, ":two_factions_share_border", 1),
  51519. # (try_end),
  51520. # (try_end),
  51521. (else_try),
  51522. (eq, ":party_current_faction", ":actor_faction"),
  51523. (val_add, ":actor_strength", ":party_value"),
  51524. (try_end),
  51525. (try_end),
  51526.  
  51527. #Total Calradia strength = 110 x 1 (villages,), 48? x 2 castles, 22 x 3 towns, 88 x 2 lord parties = 272 + 176 = 448
  51528. (assign, ":strongest_kingdom", -1),
  51529. (assign, ":score_to_beat", 60), #Maybe raise once it works
  51530. ##diplomacy start+
  51531. #Take into account alliances
  51532. (assign, ":strongest_kingdom_offensive", -1),
  51533. (assign, ":strongest_kingdom_offensive_score", -1),
  51534.  
  51535. (assign, ":strongest_kingdom_defensive", -1),
  51536. (assign, ":strongest_kingdom_defensive_score", -1),
  51537.  
  51538. (faction_get_slot, ":actor_offensive_score", ":actor_faction", slot_faction_temp_slot),
  51539. (faction_get_slot, ":actor_defensive_score", ":actor_faction", slot_faction_temp_slot),
  51540.  
  51541. #(faction_get_slot, ":target_offensive_score", ":target_faction", slot_faction_temp_slot),
  51542. (faction_get_slot, ":target_defensive_score", ":target_faction", slot_faction_temp_slot),
  51543.  
  51544. #Use these instead of just counting the number of factions
  51545. (assign, ":strength_against_actor", 0),
  51546. (assign, ":strength_against_target", 0),
  51547.  
  51548. ##diplomacy end+
  51549. (try_for_range, ":strongest_kingdom_candidate", kingdoms_begin, kingdoms_end),
  51550. (faction_get_slot, ":candidate_strength", ":strongest_kingdom_candidate", slot_faction_temp_slot),
  51551. ##diplomacy start+
  51552. #Take into account allies
  51553. (assign, ":candidate_offensive_score", ":candidate_strength"),
  51554. (assign, ":candidate_defensive_score", ":candidate_strength"),
  51555. (try_for_range, ":other_kingdom", kingdoms_begin, kingdoms_end),
  51556. (neq, ":other_kingdom", ":strongest_kingdom_candidate"),
  51557. (faction_get_slot, ":other_kingdom_strength", ":other_kingdom", slot_faction_temp_slot),
  51558. (call_script, "script_dplmc_get_faction_truce_length_with_faction", ":strongest_kingdom_candidate", ":other_kingdom"),
  51559. #Add 90% rather than 100%, because otherwise, if several kingdoms are
  51560. #allied all of them will have the same strength by this measurement.
  51561. (try_begin),
  51562. #Full alliance
  51563. (gt, reg0, dplmc_treaty_alliance_days_expire),
  51564. (store_mul, reg0, ":other_kingdom_strength", 9),
  51565. (val_div, reg0, 10),
  51566. (val_add, ":candidate_offensive_score", reg0),
  51567. (val_add, ":candidate_defensive_score", reg0),
  51568. (else_try),
  51569. #Defensive alliance
  51570. (gt, reg0, dplmc_treaty_defense_days_expire),
  51571. (store_mul, reg0, ":other_kingdom_strength", 9),
  51572. (val_div, reg0, 10),
  51573. (val_add, ":candidate_defensive_score", reg0),
  51574. (try_end),
  51575. (try_end),
  51576. #Update actor/target strengths with alliances, and "strength against"
  51577. (try_begin),
  51578. (eq, ":strongest_kingdom_candidate", ":actor_faction"),
  51579. (assign, ":actor_offensive_score", ":candidate_offensive_score"),
  51580. (assign, ":actor_defensive_score", ":candidate_defensive_score"),
  51581. (else_try),
  51582. (store_relation, ":relation", ":strongest_kingdom_candidate", ":actor_faction"),
  51583. (lt, ":relation", 0),
  51584. (val_add, ":strength_against_actor", ":other_kingdom_strength"),
  51585. (try_end),
  51586. (try_begin),
  51587. (eq, ":strongest_kingdom_candidate", ":target_faction"),
  51588. #(assign, ":target_offensive_score", ":candidate_offensive_score"),
  51589. (assign, ":target_defensive_score", ":candidate_defensive_score"),
  51590. (else_try),
  51591. (store_relation, ":relation", ":strongest_kingdom_candidate", ":target_faction"),
  51592. (lt, ":relation", 0),
  51593. (val_add, ":strength_against_target", ":other_kingdom_strength"),
  51594. (try_end),
  51595. #Update global max/min
  51596. (try_begin),
  51597. (gt, ":candidate_offensive_score", ":strongest_kingdom_offensive_score"),
  51598. (assign, ":strongest_kingdom_offensive", ":strongest_kingdom_candidate"),
  51599. (assign, ":strongest_kingdom_offensive_score", ":candidate_offensive_score"),
  51600. (try_end),
  51601. (try_begin),
  51602. (gt, ":candidate_defensive_score", ":strongest_kingdom_defensive_score"),
  51603. (assign, ":strongest_kingdom_defensive", ":strongest_kingdom_candidate"),
  51604. (assign, ":strongest_kingdom_defensive_score", ":candidate_defensive_score"),
  51605. (try_end),
  51606. ##diplomacy end+
  51607. (gt, ":candidate_strength", ":score_to_beat"),
  51608. (assign, ":strongest_kingdom", ":strongest_kingdom_candidate"),
  51609. (assign, ":score_to_beat", ":candidate_strength"),
  51610. (try_end),
  51611.  
  51612.  
  51613. (try_begin),
  51614. (eq, "$cheat_mode", 2),
  51615. (gt, ":strongest_kingdom", 1),
  51616. (str_store_faction_name, s4, ":strongest_kingdom"),
  51617. (assign, reg3, ":score_to_beat"),
  51618. (display_message, "@{!}DEBUG - {s4} strongest kingdom with {reg3} strength"),
  51619. ##diplomacy start+ Show strongest counting alliances if it's different
  51620. (try_begin),
  51621. (gt, ":strongest_kingdom_offensive", 0),
  51622. (neq, ":strongest_kingdom_offensive", ":strongest_kingdom"),
  51623. (str_store_faction_name, s4, ":strongest_kingdom_offensive"),
  51624. (assign, reg3, ":strongest_kingdom_offensive_score"),
  51625. (display_message, "@{!}DEBUG - including offensive and defensive alliances {s4} strongest kingdom with {reg3} strength"),
  51626. (try_end),
  51627. (try_begin),
  51628. (gt, ":strongest_kingdom_defensive", 0),
  51629. (neq, ":strongest_kingdom_defensive", ":strongest_kingdom"),
  51630. (neq, ":strongest_kingdom_defensive", ":strongest_kingdom_offensive"),
  51631. (str_store_faction_name, s4, ":strongest_kingdom_defensive"),
  51632. (assign, reg3, ":strongest_kingdom_defensive_score"),
  51633. (display_message, "@{!}DEBUG - including only defensive alliances {s4} strongest kingdom with {reg3} strength"),
  51634. (try_end),
  51635. #Revert values
  51636. (assign, reg3, ":score_to_beat"),
  51637. (str_store_faction_name, s4, ":strongest_kingdom"),
  51638. ##diplomacy end+
  51639. (try_end),
  51640.  
  51641.  
  51642. (assign, ":strength_ratio", 1),
  51643. (try_begin),
  51644. (gt, ":actor_strength", 0),
  51645. (store_mul, ":strength_ratio", ":target_strength", 100),
  51646. (val_div, ":strength_ratio", ":actor_strength"),
  51647. (try_end),
  51648. ##diplomacy start+
  51649. #Other strength ratios using strengths counting alliances
  51650. (assign, ":strength_ratio_new_attack", 1),
  51651. (try_begin),
  51652. (gt, ":actor_offensive_score", 0),
  51653. (store_mul, ":strength_ratio_new_attack", ":target_defensive_score", 100),
  51654. (val_div, ":strength_ratio_new_attack", ":actor_offensive_score"),
  51655. (try_end),
  51656. (assign, ":strength_ratio_current_war", 1),
  51657. (try_begin),
  51658. (gt, ":actor_defensive_score", 0),
  51659. (store_mul, ":strength_ratio_current_war", ":target_defensive_score", 100),
  51660. (val_div, ":strength_ratio_current_war", ":actor_defensive_score"),
  51661. (try_end),
  51662. #Calculate the total magnitude of the forces hostile to the faction versus its allies
  51663. (assign, ":strength_ratio_all_enemies_actor", 1),
  51664. (try_begin),
  51665. (gt, ":actor_defensive_score", 0),
  51666. (store_mul, ":strength_ratio_all_enemies_actor", ":strength_against_actor", 100),
  51667. (val_div, ":strength_ratio_all_enemies_actor", ":actor_defensive_score"),
  51668. (try_end),
  51669. ##diplomacy end+
  51670.  
  51671. (try_for_range, ":possible_mutual_enemy", kingdoms_begin, kingdoms_end),
  51672. (neq, ":possible_mutual_enemy", ":target_faction"),
  51673. (neq, ":possible_mutual_enemy", ":actor_faction"),
  51674. (faction_slot_eq, ":possible_mutual_enemy", slot_faction_state, sfs_active),
  51675.  
  51676. (store_relation, ":relation", ":possible_mutual_enemy", ":actor_faction"),
  51677. (lt, ":relation", 0),
  51678. (assign, ":third_party_war", ":possible_mutual_enemy"),
  51679. (val_add, ":num_third_party_wars", 1),
  51680.  
  51681. ##diplomacy start+
  51682. ##ACTUAL third-party wars (i.e. not allied to the target faction)
  51683. (call_script, "script_dplmc_get_faction_truce_length_with_faction", ":target_faction", ":possible_mutual_enemy"),
  51684. (try_begin),
  51685. (neg|gt, reg0, dplmc_treaty_defense_days_expire),
  51686. #(assign, ":actual_third_party_war", ":possible_mutual_enemy"),
  51687. (val_add, ":num_actual_third_party_wars", 1),
  51688. (try_end),
  51689. ##diplomacy end+
  51690.  
  51691. (store_relation, ":relation", ":possible_mutual_enemy", ":target_faction"),
  51692. (lt, ":relation", 0),
  51693. (assign, ":active_mutual_enemy", ":possible_mutual_enemy"),
  51694. (try_end),
  51695.  
  51696. (store_current_hours, ":cur_hours"),
  51697. (faction_get_slot, ":faction_ai_last_decisive_event", ":actor_faction", slot_faction_ai_last_decisive_event),
  51698. (store_sub, ":hours_since_last_decisive_event", ":cur_hours", ":faction_ai_last_decisive_event"),
  51699.  
  51700. ##diplomacy start+ use gender script
  51701. (call_script, "script_dplmc_store_troop_is_female_reg", ":actor_leader", 4),
  51702. ##diplomacy end+
  51703.  
  51704. (try_begin),
  51705. (gt, "$supported_pretender", 0),
  51706. (this_or_next|eq, "$supported_pretender", ":actor_leader"),
  51707. (eq, "$supported_pretender", ":target_leader"),
  51708. (this_or_next|eq, ":actor_faction", "$supported_pretender_old_faction"),
  51709. (eq, ":target_faction", "$supported_pretender_old_faction"),
  51710.  
  51711. (assign, ":result", -3),
  51712. ##diplomacy start+
  51713. #(troop_get_type, reg4, ":actor_leader"),#<- commented out
  51714. ##diplomacy end+
  51715. (assign, ":explainer_string", "str_s12s15_cannot_negotiate_with_s16_as_to_do_so_would_undermine_reg4herhis_own_claim_to_the_throne_this_civil_war_must_almost_certainly_end_with_the_defeat_of_one_side_or_another"),
  51716. (else_try),
  51717. (lt, ":modified_honor_and_relation", -20),
  51718. ##diplomacy start+ Take into account strengths including alliances
  51719. (this_or_next|lt, ":strength_ratio_current_war", 125),
  51720. ##diplomacy end+
  51721. (lt, ":strength_ratio", 125),
  51722. (lt, ":war_damage_suffered", 400),
  51723. (this_or_next|neq, ":war_peace_truce_status", -2),
  51724. (lt, ":hours_since_last_decisive_event", 720),
  51725. ##diplomacy start+ Examine strength of enemies versus allies
  51726. (this_or_next|lt, ":strength_ratio_all_enemies_actor", 125),
  51727. ##diplomacy end+
  51728. (eq, ":num_third_party_wars", 0),
  51729.  
  51730. (assign, ":result", -3),
  51731. ##diplomacy start+
  51732. #(troop_get_type, reg4, ":actor_leader"),#<- commented out
  51733. ##diplomacy end+
  51734. (assign, ":explainer_string", "str_s12s15_considers_s16_to_be_dangerous_and_untrustworthy_and_shehe_wants_to_bring_s16_down"),
  51735. (else_try),
  51736. (gt, ":actor_centers_held_by_target", 0),
  51737. (try_begin),
  51738. (eq, "$cheat_mode", 1),
  51739. (display_message, "@{!}Actor centers held by target noted"),
  51740. (try_end),
  51741.  
  51742. (lt, ":war_damage_suffered", 200),
  51743. (try_begin),
  51744. (eq, "$cheat_mode", 1),
  51745. (display_message, "@{!}War damage under minimum"),
  51746. (try_end),
  51747.  
  51748. ##diplomacy start+ Take into account strengths including alliances
  51749. (this_or_next|lt, ":strength_ratio_current_war", 125),
  51750. ##diplomacy end+
  51751. (lt, ":strength_ratio", 125),
  51752. (try_begin),
  51753. (eq, "$cheat_mode", 1),
  51754. (display_message, "@{!}Strength ratio correct"),
  51755. (try_end),
  51756. ##diplomacy start+ Examine strength of enemies versus allies
  51757. (this_or_next|lt, ":strength_ratio_all_enemies_actor", 125),
  51758. ##diplomacy end+
  51759. (eq, ":num_third_party_wars", 0),
  51760. (try_begin),
  51761. (eq, "$cheat_mode", 1),
  51762. (display_message, "@{!}Third party wars"),
  51763. (try_end),
  51764.  
  51765. (assign, ":result", -2),
  51766. (assign, ":explainer_string", "str_s12s15_is_anxious_to_reclaim_old_lands_such_as_s18_now_held_by_s16"),
  51767. (else_try),
  51768. (eq, ":war_peace_truce_status", -2),
  51769. ##diplomacy start+ Take into account strengths including alliances
  51770. (this_or_next|lt, ":strength_ratio_current_war", 125),
  51771. ##diplomacy end+
  51772. (lt, ":strength_ratio", 125),
  51773. (le, ":num_third_party_wars", 1),
  51774. (ge, ":war_damage_inflicted", 5),
  51775. (this_or_next|neq, ":war_peace_truce_status", -2),
  51776. (lt, ":hours_since_last_decisive_event", 720),
  51777.  
  51778. (store_mul, ":war_damage_suffered_x_2", ":war_damage_suffered", 2),
  51779. (gt, ":war_damage_inflicted", ":war_damage_suffered_x_2"),
  51780.  
  51781. (assign, ":result", -2),
  51782. ##diplomacy start+
  51783. #(troop_get_type, reg4, ":actor_leader"),#<- commented out
  51784. ##diplomacy end+
  51785. (assign, ":explainer_string", "str_s12s15_feels_that_reg4shehe_is_winning_the_war_against_s16_and_sees_no_reason_not_to_continue"),
  51786. (else_try),
  51787. (le, ":war_peace_truce_status", -1),
  51788.  
  51789. (this_or_next|eq, ":war_peace_truce_status", -1), #either a war is just beginning, or there is a provocation
  51790. (le, ":war_damage_inflicted", 1),
  51791. ##diplomacy start+ Take into account strengths including alliances
  51792. (this_or_next|lt, ":strength_ratio_new_attack", 150),
  51793. ##diplomacy end+
  51794. (lt, ":strength_ratio", 150),
  51795. ##diplomacy start+ Examine strength of enemies versus allies
  51796. (this_or_next|lt, ":strength_ratio_all_enemies_actor", 150),
  51797. ##diplomacy end+
  51798. (eq, ":num_third_party_wars", 0),
  51799.  
  51800. (faction_slot_ge, ":actor_faction", slot_faction_instability, 60),
  51801.  
  51802. (assign, ":result", -1),
  51803. (assign, ":explainer_string", "str_s12s15_faces_too_much_internal_discontent_to_feel_comfortable_ignoring_recent_provocations_by_s16s_subjects"),
  51804. (else_try),
  51805. (eq, ":war_peace_truce_status", -2),
  51806. (lt, ":war_damage_inflicted", 100),
  51807. (eq, ":num_third_party_wars", 1),
  51808.  
  51809. (assign, ":result", -1),
  51810. ##diplomacy start+
  51811. #(troop_get_type, reg4, ":actor_leader"),#<- commented out
  51812. ##diplomacy end+
  51813. (assign, ":explainer_string", "str_s12even_though_reg4shehe_is_fighting_on_two_fronts_s15_is_inclined_to_continue_the_war_against_s16_for_a_little_while_longer_for_the_sake_of_honor"),
  51814.  
  51815. (else_try),
  51816. (eq, ":war_peace_truce_status", -2),
  51817. (lt, ":war_damage_inflicted", 100),
  51818. (eq, ":num_third_party_wars", 0),
  51819.  
  51820. (assign, ":result", -1),
  51821. ##diplomacy start+
  51822. #(troop_get_type, reg4, ":actor_leader"),#<- commented out
  51823. ##diplomacy end+
  51824. (assign, ":explainer_string", "str_s12s15_feels_that_reg4shehe_must_pursue_the_war_against_s16_for_a_little_while_longer_for_the_sake_of_honor"),
  51825. (else_try),
  51826. (this_or_next|faction_slot_eq, ":actor_faction", slot_faction_ai_state, sfai_attacking_center),
  51827. (this_or_next|faction_slot_eq, ":actor_faction", slot_faction_ai_state, sfai_raiding_village),
  51828. (faction_slot_eq, ":actor_faction", slot_faction_ai_state, sfai_attacking_enemy_army),
  51829. (faction_get_slot, ":offensive_object", ":actor_faction", slot_faction_ai_object),
  51830. (party_is_active, ":offensive_object"),
  51831. (store_faction_of_party, ":offensive_object_faction", ":offensive_object"),
  51832. (eq, ":offensive_object_faction", ":target_faction"),
  51833. (str_store_party_name, s17, ":offensive_object"),
  51834.  
  51835. (assign, ":result", -1),
  51836. (assign, ":explainer_string", "str_s12s15_is_currently_on_the_offensive_against_s17_now_held_by_s16_and_reluctant_to_negotiate"),
  51837.  
  51838.  
  51839. (else_try),
  51840. #Attack strongest kingdom, if it is also at war
  51841. ##diplomacy start+ Take into account strengths including alliances
  51842. (this_or_next|eq, ":strongest_kingdom_offensive", ":target_faction"),
  51843. ##diplomacy end+
  51844. (eq, ":strongest_kingdom", ":target_faction"),
  51845. (eq, ":num_third_party_wars", 0),
  51846.  
  51847. #Either not at war, or at war for two months
  51848. (this_or_next|ge, ":war_peace_truce_status", -1),
  51849. (lt, ":hours_since_last_decisive_event", 1440),
  51850.  
  51851. # (eq, ":two_factions_share_border", 0),
  51852.  
  51853. (assign, ":at_least_one_other_faction_at_war_with_strongest", 0),
  51854. (try_for_range, ":kingdom_to_check", kingdoms_begin, kingdoms_end),
  51855. (neq, ":kingdom_to_check", ":actor_faction"),
  51856. (neq, ":kingdom_to_check", ":target_faction"),
  51857. (faction_slot_eq, ":kingdom_to_check", slot_faction_state, sfs_active),
  51858. (store_relation, ":relation_of_factions", ":kingdom_to_check", ":target_faction"),
  51859. (lt, ":relation_of_factions", 0),
  51860. (assign, ":at_least_one_other_faction_at_war_with_strongest", 1),
  51861. (try_end),
  51862. (eq, ":at_least_one_other_faction_at_war_with_strongest", 1),
  51863.  
  51864.  
  51865. (assign, ":result", -1),
  51866. (assign, ":explainer_string", "str_s12s15_is_alarmed_by_the_growing_power_of_s16"),
  51867.  
  51868. #bid to conquer all Calradia
  51869. (else_try),
  51870. (eq, ":num_third_party_wars", 0),
  51871. (try_begin),
  51872. (ge, "$cheat_mode", 1),
  51873. (display_message, "@{!}DEBUG -- No third party wars for {s15}"),
  51874. (try_end),
  51875. (eq, ":actor_faction", ":strongest_kingdom"),
  51876. #peace with no truce or provocation
  51877.  
  51878. (try_begin),
  51879. (ge, "$cheat_mode", 1),
  51880. (display_message, "@{!}DEBUG -- {s15} is strongest kingdom"),
  51881. (try_end),
  51882.  
  51883.  
  51884. (faction_get_slot, ":actor_strength", ":actor_faction", slot_faction_temp_slot),
  51885. (faction_get_slot, ":target_strength", ":target_faction", slot_faction_temp_slot),
  51886. (store_sub, ":strength_difference", ":actor_strength", ":target_strength"),
  51887. ##diplomacy start+ Include bonus from alliance
  51888. (store_sub, reg0, ":actor_offensive_score", ":target_defensive_score"),
  51889. (this_or_next|ge, reg0, 30),
  51890. ##diplomacy end+
  51891. (ge, ":strength_difference", 30),
  51892.  
  51893. (try_begin),
  51894. (ge, "$cheat_mode", 1),
  51895. (display_message, "@{!}DEBUG -- {s15} has 30 point advantage over {s16}"),
  51896. (try_end),
  51897.  
  51898.  
  51899. (assign, ":nearby_center_found", 0),
  51900. (try_for_range, ":actor_faction_walled_center", walled_centers_begin, walled_centers_end),
  51901. (store_faction_of_party, ":walled_center_faction_1", ":actor_faction_walled_center"),
  51902. (eq, ":walled_center_faction_1", ":actor_faction"),
  51903. (try_for_range, ":target_faction_walled_center", walled_centers_begin, walled_centers_end),
  51904. (store_faction_of_party, ":walled_center_faction_2", ":target_faction_walled_center"),
  51905. (eq, ":walled_center_faction_2", ":target_faction"),
  51906. (store_distance_to_party_from_party, ":distance", ":target_faction_walled_center", ":actor_faction_walled_center"),
  51907. (lt, ":distance", 25),
  51908. (assign, ":nearby_center_found", 1),
  51909. (try_end),
  51910. (try_end),
  51911. (eq, ":nearby_center_found", 1),
  51912.  
  51913.  
  51914. (try_begin),
  51915. (ge, "$cheat_mode", 1),
  51916. (display_message, "@{!}DEBUG -- {s15} has proximity to {s16}"),
  51917. (try_end),
  51918.  
  51919. (assign, ":result", -1),
  51920. (assign, ":explainer_string", "str_s12s15_declared_war_to_control_calradia"),
  51921.  
  51922. (else_try),
  51923. (lt, ":modified_honor_and_relation", -20),
  51924.  
  51925. (assign, ":result", 0),
  51926. (assign, ":explainer_string", "str_s12s15_distrusts_s16_and_fears_that_any_deals_struck_between_the_two_realms_will_not_be_kept"),
  51927.  
  51928.  
  51929. #wishes to deal
  51930. (else_try),
  51931. (lt, ":current_faction_relation", 0),
  51932. (ge, ":num_third_party_wars", 2),
  51933. (assign, ":result", 3),
  51934.  
  51935. (assign, ":explainer_string", "str_s12s15_is_at_war_on_too_many_fronts_and_eager_to_make_peace_with_s16"),
  51936. (else_try),
  51937. (gt, ":active_mutual_enemy", 0),
  51938. (eq, ":actor_centers_held_by_target", 0),
  51939. (this_or_next|ge, ":current_faction_relation", 0),
  51940. # (eq, ":two_factions_share_border", 0),
  51941. (eq, 1, 1),
  51942.  
  51943. (assign, ":result", 3),
  51944. (str_store_faction_name, s17, ":active_mutual_enemy"),
  51945. ##diplomacy start+
  51946. #(troop_get_type, reg4, ":actor_leader"),#<- commented out
  51947. ##diplomacy end+
  51948. (assign, ":explainer_string", "str_s12s15_seems_to_think_that_s16_and_reg4shehe_have_a_common_enemy_in_the_s17"),
  51949.  
  51950. (else_try),
  51951. (eq, ":war_peace_truce_status", -2),
  51952. (ge, ":hours_since_last_decisive_event", 720),
  51953.  
  51954. ##diplomacy start+
  51955. #(troop_get_type, reg4, ":actor_leader"),#<- commented out
  51956. ##diplomacy end+
  51957.  
  51958. (assign, ":result", 2),
  51959. (assign, ":explainer_string", "str_s12s15_feels_frustrated_by_reg4herhis_inability_to_strike_a_decisive_blow_against_s16"),
  51960.  
  51961.  
  51962. (else_try),
  51963. (lt, ":current_faction_relation", 0),
  51964. (gt, ":war_damage_suffered", 100),
  51965.  
  51966. (val_mul, ":war_damage_suffered_x_2", 2),
  51967. (lt, ":war_damage_inflicted", ":war_damage_suffered_x_2"),
  51968.  
  51969. (assign, ":result", 2),
  51970. (assign, ":explainer_string", "str_s12s15_has_suffered_enough_in_the_war_with_s16_for_too_little_gain_and_is_ready_to_pursue_a_peace"),
  51971.  
  51972. (else_try),
  51973. (gt, ":third_party_war", 0),
  51974. (ge, ":modified_honor_and_relation", 0),
  51975. (lt, ":current_faction_relation", 0),
  51976.  
  51977. (assign, ":result", 1),
  51978. (str_store_faction_name, s17, ":third_party_war"),
  51979. (assign, ":explainer_string", "str_s12s15_would_like_to_firm_up_a_truce_with_s16_to_respond_to_the_threat_from_the_s17"),
  51980. (else_try),
  51981. (gt, ":third_party_war", 0),
  51982. (ge, ":modified_honor_and_relation", 0),
  51983.  
  51984. (assign, ":result", 1),
  51985. (str_store_faction_name, s17, ":third_party_war"),
  51986. (assign, ":explainer_string", "str_s12s15_wishes_to_be_at_peace_with_s16_so_as_to_pursue_the_war_against_the_s17"),
  51987. (else_try),
  51988. (gt, ":strength_ratio", 175),
  51989. # (eq, ":two_factions_share_border", 1),
  51990.  
  51991. (assign, ":result", 1),
  51992. (assign, ":explainer_string", "str_s12s15_seems_to_be_intimidated_by_s16_and_would_like_to_avoid_hostilities"),
  51993. (else_try),
  51994. (lt, ":current_faction_relation", 0),
  51995.  
  51996. (assign, ":result", 1),
  51997. (assign, ":explainer_string", "str_s12s15_has_no_particular_reason_to_continue_the_war_with_s16_and_would_probably_make_peace_if_given_the_opportunity"),
  51998. (else_try),
  51999. (assign, ":result", 1),
  52000. (assign, ":explainer_string", "str_s12s15_seems_to_be_willing_to_improve_relations_with_s16"),
  52001. (try_end),
  52002. ##diplomacy start+
  52003. #Possibly change the concession demanded
  52004. (try_begin),
  52005. (gt, "$g_concession_demanded", 0),
  52006. (gt, ":last_center_lost", 0),
  52007. (neq, "$g_concession_demanded", ":last_center_lost"),
  52008. (try_begin),
  52009. #This logically can't happen due to the order centers appear in
  52010. (is_between, "$g_concession_demanded", towns_begin, towns_end),
  52011. (neg|is_between, ":last_center_lost", towns_begin, towns_end),#Do not replace
  52012. (else_try),
  52013. (is_between, ":last_center_lost", towns_begin, towns_end),
  52014. (neg|is_between, "$g_concession_demanded", towns_begin, towns_end),
  52015. (assign, "$g_concession_demanded", ":last_center_lost"),
  52016. (else_try),
  52017. (party_slot_eq, ":last_center_lost", slot_center_original_faction, ":actor_faction"),
  52018. (neg|party_slot_eq, "$g_concession_demanded", slot_center_original_faction, ":actor_faction"),
  52019. (assign, "$g_concession_demanded", ":last_center_lost"),
  52020. (try_end),
  52021. (eq, "$g_concession_demanded", ":last_center_lost"),
  52022. (str_store_party_name, s18, "$g_concession_demanded"),#change s18 to match
  52023. (try_end),
  52024. ##diplomacy end+
  52025. (str_store_string, s14, ":explainer_string"),
  52026. (assign, reg0, ":result"),
  52027. (assign, reg1, ":explainer_string"),
  52028.  
  52029. ]),
  52030.  
  52031. ("npc_decision_checklist_male_guardian_assess_suitor", #parameters from dialog
  52032. [
  52033. (store_script_param, ":lord", 1),
  52034. (store_script_param, ":suitor", 2),
  52035.  
  52036. (troop_get_slot, ":lord_reputation", ":lord", slot_lord_reputation_type),
  52037. (store_faction_of_troop, ":lord_faction", ":lord"),
  52038.  
  52039. (try_begin),
  52040. (eq, ":suitor", "trp_player"),
  52041. (assign, ":suitor_faction", "$players_kingdom"),
  52042. (else_try),
  52043. (store_faction_of_troop, ":suitor_faction", ":suitor"),
  52044. (try_end),
  52045. (store_relation, ":faction_relation_with_suitor", ":lord_faction", ":suitor_faction"),
  52046.  
  52047. (call_script, "script_troop_get_relation_with_troop", ":lord", ":suitor"),
  52048. (assign, ":lord_suitor_relation", reg0),
  52049.  
  52050.  
  52051.  
  52052. (troop_get_slot, ":suitor_renown", ":suitor", slot_troop_renown),
  52053.  
  52054.  
  52055. (assign, ":competitor_found", -1),
  52056.  
  52057. (try_begin),
  52058. (eq, ":suitor", "trp_player"),
  52059. (gt, "$marriage_candidate", 0),
  52060.  
  52061. (try_for_range, ":competitor", lords_begin, lords_end),
  52062. (store_faction_of_troop, ":competitor_faction", ":competitor"),
  52063. (eq, ":competitor_faction", ":lord_faction"),
  52064. (this_or_next|troop_slot_eq, ":competitor", slot_troop_love_interest_1, "$marriage_candidate"),
  52065. (this_or_next|troop_slot_eq, ":competitor", slot_troop_love_interest_2, "$marriage_candidate"),
  52066. (troop_slot_eq, ":competitor", slot_troop_love_interest_3, "$marriage_candidate"),
  52067.  
  52068. (call_script, "script_troop_get_relation_with_troop", ":competitor", ":lord"),
  52069. (gt, reg0, 5),
  52070.  
  52071. (troop_slot_ge, ":competitor", slot_troop_renown, ":suitor_renown"), #higher renown than player
  52072.  
  52073. (assign, ":competitor_found", ":competitor"),
  52074. (str_store_troop_name, s14, ":competitor"),
  52075. (str_store_troop_name, s16, "$marriage_candidate"),
  52076. (try_end),
  52077. (try_end),
  52078.  
  52079. #renown
  52080. (try_begin),
  52081. (lt, ":suitor_renown", 50),
  52082. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_quarrelsome),
  52083. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_debauched),
  52084. (troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_selfrighteous),
  52085. (assign, ":explainer_string", "str_excuse_me_how_can_you_possibly_imagine_yourself_worthy_to_marry_into_our_family"),
  52086. (assign, ":result", -3),
  52087. (else_try),
  52088. (lt, ":suitor_renown", 50),
  52089. (troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_goodnatured),
  52090.  
  52091. (assign, ":explainer_string", "str_em_with_regard_to_her_ladyship_we_were_looking_specifically_for_a_groom_of_some_distinction_fight_hard_count_your_dinars_and_perhaps_some_day_in_the_future_we_may_speak_of_such_things_my_good_man"),
  52092. (assign, ":result", -1),
  52093. (else_try),
  52094. (lt, ":suitor_renown", 50),
  52095.  
  52096. (assign, ":explainer_string", "str_em_with_regard_to_her_ladyship_we_were_looking_specifically_for_a_groom_of_some_distinction"),
  52097. (assign, ":result", -2),
  52098.  
  52099. (else_try),
  52100. (lt, ":suitor_renown", 200),
  52101. (neg|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_goodnatured),
  52102. (assign, ":explainer_string", "str_it_is_too_early_for_you_to_be_speaking_of_such_things_you_are_still_making_your_mark_in_the_world"),
  52103.  
  52104. (assign, ":result", -1),
  52105.  
  52106. (else_try), #wrong faction
  52107. (eq, ":suitor", "trp_player"),
  52108. (neq, ":suitor_faction", "$players_kingdom"),
  52109. (str_store_faction_name, s4, ":lord_faction"),
  52110. (this_or_next|eq, ":lord_reputation", lrep_quarrelsome),
  52111. (eq, ":lord_reputation", lrep_debauched),
  52112. (assign, ":explainer_string", "str_you_dont_serve_the_s4_so_id_say_no_one_day_we_may_be_at_war_and_i_prefer_not_to_have_to_kill_my_inlaws_if_at_all_possible"),
  52113.  
  52114. (assign, ":result", -1),
  52115.  
  52116. (else_try),
  52117. (eq, ":suitor", "trp_player"),
  52118. (neq, ":suitor_faction", "$players_kingdom"),
  52119. (neq, ":lord_reputation", lrep_goodnatured),
  52120. (neq, ":lord_reputation", lrep_cunning),
  52121.  
  52122. (assign, ":explainer_string", "str_as_you_are_not_a_vassal_of_the_s4_i_must_decline_your_request_the_twists_of_fate_may_mean_that_we_will_one_day_cross_swords_and_i_would_hope_not_to_make_a_widow_of_a_lady_whom_i_am_obligated_to_protect"),
  52123.  
  52124. (assign, ":result", -1),
  52125. (else_try),
  52126. (eq, ":suitor", "trp_player"),
  52127. (lt, ":faction_relation_with_suitor", 0),
  52128.  
  52129. (assign, ":explainer_string", "str_as_you_are_not_a_vassal_of_the_s4_i_must_decline_your_request_the_twists_of_fate_may_mean_that_we_will_one_day_cross_swords_and_i_would_hope_not_to_make_a_widow_of_a_lady_whom_i_am_obligated_to_protect"),
  52130.  
  52131. (assign, ":result", -1),
  52132.  
  52133. (else_try),
  52134. (eq, ":suitor", "trp_player"),
  52135. (neq, "$player_has_homage", 1),
  52136. (neg|faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_active),
  52137.  
  52138. (assign, ":explainer_string", "str_as_you_are_not_a_pledged_vassal_of_our_liege_with_the_right_to_hold_land_i_must_refuse_your_request_to_marry_into_our_family"),
  52139.  
  52140. (assign, ":result", -1),
  52141. (else_try),
  52142. (gt, ":competitor_found", -1),
  52143.  
  52144. (this_or_next|eq, ":lord_reputation", lrep_selfrighteous),
  52145. (this_or_next|eq, ":lord_reputation", lrep_debauched),
  52146. (this_or_next|eq, ":lord_reputation", lrep_martial),
  52147. (eq, ":lord_reputation", lrep_quarrelsome),
  52148.  
  52149. (assign, ":explainer_string", "str_look_here_lad__the_young_s14_has_been_paying_court_to_s16_and_youll_have_to_admit__hes_a_finer_catch_for_her_than_you_so_lets_have_no_more_of_this_talk_shall_we"),
  52150. (assign, ":result", -1),
  52151.  
  52152. (else_try),
  52153. (lt, ":lord_suitor_relation", -4),
  52154.  
  52155.  
  52156.  
  52157. (assign, ":explainer_string", "str_i_do_not_care_for_you_sir_and_i_consider_it_my_duty_to_protect_the_ladies_of_my_household_from_undesirable_suitors"),
  52158. (assign, ":result", -3),
  52159. (else_try),
  52160. (lt, ":lord_suitor_relation", 5),
  52161.  
  52162. (assign, ":explainer_string", "str_hmm_young_girls_may_easily_be_led_astray_so_out_of_a_sense_of_duty_to_the_ladies_of_my_household_i_think_i_would_like_to_get_to_know_you_a_bit_better_we_may_speak_of_this_at_a_later_date"),
  52163. (assign, ":result", -1),
  52164. (else_try),
  52165.  
  52166. (assign, ":explainer_string", "str_you_may_indeed_make_a_fine_match_for_the_young_mistress"),
  52167. (assign, ":result", 1),
  52168. (try_end),
  52169.  
  52170. (assign, reg0, ":result"),
  52171. (assign, reg1, ":explainer_string"),
  52172.  
  52173. ]),
  52174.  
  52175. ("npc_decision_checklist_marry_female_pc", #
  52176. [
  52177. (store_script_param, ":npc", 1),
  52178. #diplomacy start+ (players of either gender may marry opposite-gender lords)
  52179. # Note that many of the strings used here have been altered to change based on the player's gender.
  52180. # Also, it should be mention that reason is written to s14.
  52181. (assign, ":save_reg1", reg1),
  52182. #Use gender script
  52183. (call_script, "script_dplmc_store_is_female_troop_1_troop_2", "trp_player", ":npc"),
  52184. (assign, ":is_female", reg0),
  52185. (assign, ":npc_female", reg1),
  52186. #diplomacy end+
  52187.  
  52188. (troop_get_slot, ":npc_reputation_type", ":npc", slot_lord_reputation_type),
  52189.  
  52190. (call_script, "script_troop_get_romantic_chemistry_with_troop", ":npc", "trp_player"),
  52191. (assign, ":romantic_chemistry", reg0),
  52192.  
  52193. (call_script, "script_troop_get_relation_with_troop", ":npc", "trp_player"),
  52194. (assign, ":relation_with_player", reg0),
  52195.  
  52196. (assign, ":competitor", -1),
  52197. (try_for_range, ":competitor_candidate", kingdom_ladies_begin, kingdom_ladies_end),
  52198. (this_or_next|troop_slot_eq, ":npc", slot_troop_love_interest_1, ":competitor_candidate"),
  52199. (this_or_next|troop_slot_eq, ":npc", slot_troop_love_interest_2, ":competitor_candidate"),
  52200. (troop_slot_eq, ":npc", slot_troop_love_interest_3, ":competitor_candidate"),
  52201. (call_script, "script_troop_get_relation_with_troop", ":npc", ":competitor"),
  52202. (assign, ":competitor_relation", reg0),
  52203.  
  52204. (gt, ":competitor_relation", ":relation_with_player"),
  52205. (assign, ":competitor", ":competitor_candidate"),
  52206. (try_end),
  52207.  
  52208. (assign, ":player_possessions", 0),
  52209. (try_for_range, ":center", centers_begin, centers_end),
  52210. (troop_slot_eq, ":center", slot_town_lord, "trp_player"),
  52211. (val_add, ":player_possessions", 1),
  52212. (try_end),
  52213.  
  52214. (assign, ":lord_agrees", 0),
  52215. #reasons for refusal
  52216. (try_begin),
  52217. (troop_slot_ge, "trp_player", slot_troop_betrothed, active_npcs_begin),
  52218. (neg|troop_slot_eq, "trp_player", slot_troop_betrothed, ":npc"),
  52219.  
  52220. (str_store_string, s14, "str_my_lady_engaged_to_another"),
  52221. (else_try),
  52222. #bad relationship - minor
  52223. (lt, ":relation_with_player", -3),
  52224. (this_or_next|eq, ":npc_reputation_type", lrep_upstanding),
  52225. (this_or_next|eq, ":npc_reputation_type", lrep_cunning),
  52226. ##diplomacy start+ also test commoner types
  52227. (this_or_next|eq, ":npc_reputation_type", lrep_roguish),
  52228. (this_or_next|eq, ":npc_reputation_type", lrep_custodian),
  52229. (this_or_next|eq, ":npc_reputation_type", lrep_benefactor),
  52230. #And certain lady types?
  52231. (this_or_next|eq, ":npc_reputation_type", lrep_ambitious),
  52232. (this_or_next|eq, ":npc_reputation_type", lrep_moralist),
  52233. ##diplomacy end+
  52234. (eq, ":npc_reputation_type", lrep_goodnatured),
  52235.  
  52236. (str_store_string, s14, "str_madame__given_our_relations_in_the_past_this_proposal_is_most_surprising_i_do_not_think_that_you_are_the_kind_of_woman_who_can_be_bent_to_a_hushands_will_and_i_would_prefer_not_to_have_our_married_life_be_a_source_of_constant_acrimony"),
  52237.  
  52238. (else_try), #really bad relationship
  52239. (lt, ":relation_with_player", -10),
  52240.  
  52241. (this_or_next|eq, ":npc_reputation_type", lrep_quarrelsome),
  52242. (this_or_next|eq, ":npc_reputation_type", lrep_debauched),
  52243. (eq, ":npc_reputation_type", lrep_selfrighteous),
  52244.  
  52245. (str_store_string, s14, "str_i_would_prefer_to_marry_a_proper_maiden_who_will_obey_her_husband_and_is_not_likely_to_split_his_head_with_a_sword"),
  52246. (else_try),
  52247. (lt, ":romantic_chemistry", 5),
  52248.  
  52249. (str_store_string, s14, "str_my_lady_not_sufficient_chemistry"),
  52250.  
  52251. (else_try), #would prefer someone more ladylike
  52252. (this_or_next|eq, ":npc_reputation_type", lrep_upstanding),
  52253. (eq, ":npc_reputation_type", lrep_martial),
  52254. #diplomacy start+ (players of either gender may marry opposite-gender lords)
  52255. #I tried to keep this as symmetric as possible, but this sentence is ridiculous with reversed genders
  52256. (neq, ":npc_female", 1),
  52257. (eq, ":is_female", 1),
  52258. #To reduce annoyance, I've changed this away from an absolute prohibition.
  52259. (troop_get_slot, ":veto", ":npc", slot_troop_set_decision_seed),
  52260. (val_add, ":veto", "$romantic_attraction_seed"),
  52261. (val_mod, ":veto", 5),#4 out of 5 will still automatically refuse
  52262. (try_begin),#make an exception for companions
  52263. (is_between, ":npc", companions_begin, companions_end),
  52264. (assign, ":veto", 0),
  52265. (else_try),
  52266. #On diminished prejudice mode, get rid of the "80% automatically refuse" condition.
  52267. (ge, "$g_disable_condescending_comments", 2),
  52268. (assign, ":veto", 0),
  52269. (try_end),
  52270. (try_begin),
  52271. #Skip the subsequent checks if there's no way for them to pass
  52272. (neq, ":veto", 0),
  52273. (else_try),
  52274. #Requires high chemistry, high relation, and positive honor
  52275. (this_or_next|lt, ":romantic_chemistry", 15),
  52276. (this_or_next|lt, ":relation_with_player", 30),
  52277. (lt, "$player_honor", 10),
  52278. (assign, ":veto", 1),
  52279. (else_try),
  52280. #Relation must be above some arbitrary threshold (only if prejudice settings are not "low")
  52281. (lt, "$g_disable_condescending_comments", 2),
  52282. (store_sub, reg0, 100, ":romantic_chemistry"),
  52283. (lt, ":relation_with_player", reg0),
  52284. (assign, ":veto", 1),
  52285. (else_try),
  52286. #The lord's level must not be less than 75% of the player's (only if prejudice settings are not "low")
  52287. (lt, "$g_disable_condescending_comments", 2),
  52288. (store_character_level, reg0, "trp_player"),
  52289. (val_mul, reg0, 3),
  52290. (val_div, reg0, 4),
  52291. (store_character_level, reg1, ":npc"),
  52292. (lt, reg1, reg0),
  52293. (assign, ":veto", 1),
  52294. (else_try),
  52295. #One of the lord's female relatives must like the player, if any such lords exist.
  52296. (lt, "$g_disable_condescending_comments", 2),
  52297. (troop_get_slot, ":npc_mother", ":npc", slot_troop_mother),
  52298. (assign, reg1, 0),#3 = some disapproved, 2 = some approved, 1 = some existed and had no opinion, 0 = there were none
  52299. (try_for_range, ":kingdom_lady", kingdom_ladies_begin, kingdom_ladies_end),
  52300. (neg|troop_slot_ge, ":kingdom_lady", slot_troop_occupation, slto_retirement),
  52301. (assign, reg0, 0),
  52302. (try_begin),
  52303. (troop_slot_eq, ":kingdom_lady", slot_troop_guardian, ":npc"),
  52304. (assign, reg0, 1),
  52305. (else_try),
  52306. (is_between, ":npc_mother", heroes_begin, heroes_end),
  52307. (this_or_next|eq, ":kingdom_lady", ":npc_mother"),
  52308. (troop_slot_eq, ":kingdom_lady", slot_troop_mother, ":npc_mother"),
  52309. (assign, reg0, 1),
  52310. (try_end),
  52311. (neq, reg0, 0),
  52312. (call_script, "script_troop_get_player_relation", ":kingdom_lady"),
  52313. (try_begin),#some were found and like the player
  52314. (ge, reg0, 1),
  52315. (val_max, reg1, 2),
  52316. (else_try),#some were found and have no opinion
  52317. (eq, reg0, 0),
  52318. (val_max, reg1, 1),
  52319. (else_try),#some were found and dislike the player
  52320. (val_max, reg1, 3),
  52321. (try_end),
  52322. (try_end),
  52323. (neq, reg0, 0),
  52324. (neq, reg0, 2),
  52325. (assign, ":veto", 1),
  52326. (try_end),
  52327. #Check if the veto holds
  52328. (neq, ":veto", 0),
  52329. #diplomacy end+
  52330.  
  52331. (str_store_string, s14, "str_my_lady_while_i_admire_your_valor_you_will_forgive_me_if_i_tell_you_that_a_woman_like_you_does_not_uphold_to_my_ideal_of_the_feminine_of_the_delicate_and_of_the_pure"),
  52332. (else_try),
  52333. (eq, ":npc_reputation_type", lrep_quarrelsome),
  52334. (lt, ":romantic_chemistry", 15),
  52335.  
  52336. (str_store_string, s14, "str_nah_i_want_a_woman_wholl_keep_quiet_and_do_what_shes_told_i_dont_think_thats_you"),
  52337. (else_try), #no properties
  52338. (this_or_next|eq, ":npc_reputation_type", lrep_selfrighteous),
  52339. (eq, ":npc_reputation_type", lrep_debauched),
  52340.  
  52341. (ge, ":romantic_chemistry", 10),
  52342. (eq, ":player_possessions", 0),
  52343.  
  52344. (str_store_string, s14, "str_my_lady_you_are_possessed_of_great_charms_but_no_properties_until_you_obtain_some_to_marry_you_would_be_an_act_of_ingratitude_towards_my_ancestors_and_my_lineage"),
  52345.  
  52346. (else_try), #you're a nobody - I can do better
  52347. (this_or_next|eq, ":npc_reputation_type", lrep_selfrighteous),
  52348. (eq, ":npc_reputation_type", lrep_debauched),
  52349.  
  52350. (eq, ":player_possessions", 0),
  52351.  
  52352. (str_store_string, s14, "str_my_lady_you_are_a_woman_of_no_known_family_of_no_possessions__in_short_a_nobody_do_you_think_that_you_are_fit_to_marry_into_may_family"),
  52353. (else_try), #just not that into you
  52354. (lt, ":romantic_chemistry", 5),
  52355. (lt, ":relation_with_player", 20),
  52356.  
  52357. (neq, ":npc_reputation_type", lrep_debauched),
  52358. (neq, ":npc_reputation_type", lrep_selfrighteous),
  52359.  
  52360. (str_store_string, s14, "str_my_lady__forgive_me__the_quality_of_our_bond_is_not_of_the_sort_which_the_poets_tell_us_is_necessary_to_sustain_a_happy_marriage"),
  52361.  
  52362. (else_try), #you're a liability, given your relation with the liege
  52363. (eq, ":npc_reputation_type", lrep_cunning),
  52364. (faction_get_slot, ":leader", slot_faction_leader, "$g_talk_troop_faction"),
  52365. (str_store_troop_name, s4, ":leader"),
  52366. (call_script, "script_troop_get_relation_with_troop", ":leader", "trp_player"),
  52367. (lt, reg0, -10),
  52368.  
  52369. (str_store_string, s14, "str_um_i_think_that_if_i_want_to_stay_on_s4s_good_side_id_best_not_marry_you"),
  52370. (else_try), #part of another faction
  52371. (gt, "$players_kingdom", 0),
  52372. (neq, "$players_kingdom", "$g_talk_troop_faction"),
  52373. (faction_get_slot, ":leader", slot_faction_leader, "$g_talk_troop_faction"),
  52374. ##diplomacy start+ use gender script
  52375. #(troop_get_type, reg4, ":leader"),
  52376. (call_script, "script_dplmc_store_troop_is_female_reg", ":leader", 4),
  52377. ##diplomacy end+
  52378.  
  52379. (str_store_string, s14, "str_you_serve_another_realm_i_dont_see_s4_granting_reg4herhis_blessing_to_our_union"),
  52380. (else_try), #there's a competitor
  52381. (gt, ":competitor", -1),
  52382. (str_store_troop_name, s4, ":competitor"),
  52383.  
  52384. (str_store_string, s14, "str_madame_my_heart_currently_belongs_to_s4"),
  52385. ##diplomacy start+
  52386. #By default these should not be reachable, but future changes may expose them
  52387. #unintentionally.
  52388. (else_try),#redundant: shouldn't be called for betrothed lords
  52389. (troop_slot_ge, ":npc", slot_troop_betrothed, 1),
  52390. (troop_get_slot, ":competitor", ":npc", slot_troop_betrothed),
  52391. (str_store_troop_name, s4, ":competitor"),
  52392. (str_store_string, s14, "str_madame_my_heart_currently_belongs_to_s4"),
  52393. (else_try),#redundant: shouldn't be called for married lords
  52394. (troop_slot_ge, ":npc", slot_troop_spouse, 1),
  52395. (troop_get_slot, ":competitor", ":npc", slot_troop_spouse),
  52396. (str_store_troop_name, s4, ":competitor"),
  52397. (str_store_string, s14, "str_madame_my_heart_currently_belongs_to_s4"),
  52398. (else_try),#redundant: shouldn't be called for claimants or kings
  52399. (this_or_next|is_between, ":npc", kings_begin, kings_end),
  52400. (is_between, ":npc", pretenders_begin, pretenders_end),
  52401. #This probably wouldn't ever occur, but put a string here just in case.
  52402. #The male version is ridiculous.
  52403. (str_store_string, s14, "str_my_lady_while_i_admire_your_valor_you_will_forgive_me_if_i_tell_you_that_a_woman_like_you_does_not_uphold_to_my_ideal_of_the_feminine_of_the_delicate_and_of_the_pure"),
  52404. ##diplomacy end+
  52405. (else_try),
  52406. (lt, ":relation_with_player", 10),
  52407. (assign, ":lord_agrees", 2),
  52408.  
  52409. (str_store_string, s14, "str_my_lady_you_are_a_woman_of_great_spirit_and_bravery_possessed_of_beauty_grace_and_wit_i_shall_give_your_proposal_consideration"),
  52410. (else_try),
  52411. (assign, ":lord_agrees", 1),
  52412.  
  52413. (str_store_string, s14, "str_my_lady_you_are_a_woman_of_great_spirit_and_bravery_possessed_of_beauty_grace_and_wit_i_would_be_most_honored_were_you_to_become_my_wife"),
  52414. (try_end),
  52415.  
  52416. ##diplomacy start+ revert register
  52417. (assign, reg1, ":save_reg1"),
  52418. ##diplomacy end+
  52419. (assign, reg0, ":lord_agrees"),
  52420.  
  52421. ]
  52422. ),
  52423.  
  52424.  
  52425. # (
  52426. # "npc_decision_checklist_king_chooses_lord_for_center",
  52427. # [
  52428. # (store_script_param, ":center", 1),
  52429.  
  52430. # (store_faction_of_party, ":faction", ":center"),
  52431. # (faction_get_slot, ":king", ":faction", slot_faction_leader),
  52432.  
  52433. # (assign, ":total_renown_in_faction"),
  52434. # (try_for_range, ":lord_iterator", active_npcs_including_player_begin, active_npcs_end),
  52435. # (assign, ":lord", ":lord_iterator"),
  52436. # (store_faction_of_troop, ":lord_faction", ":lord"),
  52437. # (try_begin),
  52438. # (eq, ":lord_iterator", "trp_kingdom_heroes_including_player_begin"),
  52439. # (assign, ":lord", "trp_player"),
  52440. # (assign, ":lord_faction", "$players_kingdom"),
  52441. # (try_end),
  52442. # (troop_get_slot, ":renown", ":lord", slot_troop_renown),
  52443. # (val_add, ":total_renown_in_faction", ":renown"),
  52444.  
  52445. # (troop_set_slot, ":lord", slot_troop_temp_slot, 0),
  52446. # (try_end),
  52447.  
  52448. # (assign, ":total_property_points_in_faction"),
  52449. # (try_for_range, ":village", villages_begin, villages_end),
  52450.  
  52451. # (try_end),
  52452.  
  52453.  
  52454.  
  52455. # (try_begin),
  52456.  
  52457. #I needed it for myself
  52458.  
  52459. #The one who captured it was suitably deserving
  52460.  
  52461. #I had not sufficiently recognized Lord X for his service
  52462.  
  52463. # (try_end),
  52464.  
  52465.  
  52466. # ]),
  52467.  
  52468.  
  52469.  
  52470. ("courtship_poem_reactions", #parameters from dialog
  52471. [
  52472. (store_script_param, ":lady", 1),
  52473. (store_script_param, ":poem", 2),
  52474.  
  52475. (troop_get_slot, ":lady_reputation", ":lady", slot_lord_reputation_type),
  52476.  
  52477. (try_begin),
  52478. (eq, "$cheat_mode", 1),
  52479. (assign, reg4, ":poem"),
  52480. (assign, reg5, ":lady_reputation"),
  52481. (display_message, "str_poem_choice_reg4_lady_rep_reg5"),
  52482. (try_end),
  52483.  
  52484. (try_begin), #conventional ++, ambitious -, adventurous -
  52485. (eq, ":poem", courtship_poem_tragic),
  52486. (eq, ":lady_reputation", lrep_conventional),
  52487. (str_store_string, s11, "str_ah__kais_and_layali__such_a_sad_tale_many_a_time_has_it_been_recounted_for_my_family_by_the_wandering_poets_who_come_to_our_home_and_it_has_never_failed_to_bring_tears_to_our_eyes"),
  52488. (assign, ":result", 5),
  52489. (else_try),
  52490. (eq, ":poem", courtship_poem_tragic),
  52491. (eq, ":lady_reputation", lrep_ambitious),
  52492. (str_store_string, s11, "str_kais_and_layali_three_hundred_stanzas_of_pathetic_sniveling_if_you_ask_me_if_kais_wanted_to_escape_heartbreak_he_should_have_learned_to_live_within_his_station_and_not_yearn_for_what_he_cannot_have"),
  52493. (assign, ":result", 0),
  52494. (else_try),
  52495. (eq, ":poem", courtship_poem_tragic),
  52496. (eq, ":lady_reputation", lrep_otherworldly),
  52497. (str_store_string, s11, "str_kais_and_layali_no_one_should_ever_have_written_such_a_sad_poem_if_it_was_the_destiny_of_kais_and_layali_to_be_together_than_their_love_should_have_conquered_all_obstacles"),
  52498. (assign, ":result", 1),
  52499. (else_try),
  52500. (eq, ":poem", courtship_poem_tragic),
  52501. # moralizing and adventurous
  52502. (str_store_string, s11, "str_ah_kais_and_layali_a_very_old_standby_but_moving_in_its_way"),
  52503. (assign, ":result", 3),
  52504. #Heroic
  52505. (else_try), #adventurous ++, conventional -1, moralizing -1
  52506. (eq, ":poem", courtship_poem_heroic),
  52507. (eq, ":lady_reputation", lrep_adventurous),
  52508. (str_store_string, s11, "str_the_saga_of_helgered_and_kara_such_happy_times_in_which_our_ancestors_lived_women_like_kara_could_venture_out_into_the_world_like_men_win_a_name_for_themselves_and_not_linger_in_their_husbands_shadow"),
  52509. (assign, ":result", 5),
  52510. (else_try), #adventurous ++, conventional -1, moralizing -1
  52511. (eq, ":poem", courtship_poem_heroic),
  52512. (eq, ":lady_reputation", lrep_ambitious),
  52513. (str_store_string, s11, "str_ah_the_saga_of_helgered_and_kara_now_there_was_a_lady_who_knew_what_she_wanted_and_was_not_afraid_to_obtain_it"),
  52514. (assign, ":result", 2),
  52515. (else_try), #adventurous ++, conventional -1, moralizing -1
  52516. (eq, ":poem", courtship_poem_heroic),
  52517. (eq, ":lady_reputation", lrep_otherworldly),
  52518. (str_store_string, s11, "str_the_saga_of_helgered_and_kara_a_terrible_tale__but_it_speaks_of_a_very_great_love_if_she_were_willing_to_make_war_on_her_own_family"),
  52519. (assign, ":result", 2),
  52520. (else_try), #adventurous ++, conventional -1, moralizing -1
  52521. (eq, ":poem", courtship_poem_heroic),
  52522. (eq, ":lady_reputation", lrep_moralist),
  52523. (str_store_string, s11, "str_the_saga_of_helgered_and_kara_as_i_recall_kara_valued_her_own_base_passions_over_duty_to_her_family_that_she_made_war_on_her_own_father_i_have_no_time_for_a_poem_which_praises_such_a_woman"),
  52524. (assign, ":result", 0),
  52525. (else_try), #adventurous ++, conventional -1, moralizing -1
  52526. (eq, ":poem", courtship_poem_heroic),
  52527. (eq, ":lady_reputation", lrep_conventional),
  52528. (str_store_string, s11, "str_the_saga_of_helgered_and_kara_how_could_a_woman_don_armor_and_carry_a_sword_how_could_a_man_love_so_ungentle_a_creature"),
  52529. (assign, ":result", 0),
  52530. #Comic
  52531. (else_try), #ambitious ++, romantic -, moralizing 0
  52532. (eq, ":poem", courtship_poem_comic),
  52533. (eq, ":lady_reputation", lrep_otherworldly),
  52534. (str_store_string, s11, "str_a_conversation_in_the_garden_i_cannot_understand_the_lady_in_that_poem_if_she_loves_the_man_why_does_she_tease_him_so"),
  52535. (assign, ":result", 0),
  52536. (else_try), #ambitious ++, romantic -, moralizing 0
  52537. (eq, ":poem", courtship_poem_comic),
  52538. (eq, ":lady_reputation", lrep_moralist),
  52539. (str_store_string, s11, "str_a_conversation_in_the_garden_let_us_see__it_is_morally_unedifying_it_exalts_deception_it_ends_with_a_maiden_surrendering_to_her_base_passions_and_yet_i_cannot_help_but_find_it_charming_perhaps_because_it_tells_us_that_love_need_not_be_tragic_to_be_memorable"),
  52540. (assign, ":result", 1),
  52541. (else_try), #ambitious ++, romantic -, moralizing 0
  52542. (eq, ":poem", courtship_poem_comic),
  52543. (eq, ":lady_reputation", lrep_ambitious),
  52544. (str_store_string, s11, "str_a_conversation_in_the_garden_now_that_is_a_tale_every_lady_should_know_by_heart_to_learn_the_subtleties_of_the_politics_she_must_practice"),
  52545. (assign, ":result", 5),
  52546. (else_try), #ambitious ++, romantic -, moralizing 0
  52547. (eq, ":poem", courtship_poem_comic),
  52548. #adventurous, conventional
  52549. (str_store_string, s11, "str_a_conversation_in_the_garden_it_is_droll_i_suppose__although_there_is_nothing_there_that_truly_stirs_my_soul"),
  52550. (assign, ":result", 3),
  52551.  
  52552. #Allegoric
  52553. (else_try), #moralizing ++, adventurous -, romantic -
  52554. (eq, ":poem", courtship_poem_allegoric),
  52555. (eq, ":lady_reputation", lrep_adventurous),
  52556. (str_store_string, s11, "str_storming_the_fortress_of_love_ah_yes_the_lady_sits_within_doing_nothing_while_the_man_is_the_one_who_strives_and_achieves_i_have_enough_of_that_in_my_daily_life_why_listen_to_poems_about_it"),
  52557. (assign, ":result", 0),
  52558. (else_try), #moralizing ++, adventurous -, romantic -
  52559. (eq, ":poem", courtship_poem_allegoric),
  52560. (this_or_next|eq, ":lady_reputation", lrep_conventional),
  52561. (eq, ":lady_reputation", lrep_moralist),
  52562. (str_store_string, s11, "str_storming_the_fortress_of_love_ah_yes_an_uplifting_tribute_to_the_separate_virtues_of_man_and_woman"),
  52563. (assign, ":result", 3),
  52564. (else_try), #moralizing ++, adventurous -, romantic -
  52565. (eq, ":poem", courtship_poem_allegoric),
  52566. (eq, ":lady_reputation", lrep_otherworldly),
  52567. (str_store_string, s11, "str_storming_the_fortress_of_love_ah_yes_but_although_it_is_a_fine_tale_of_virtues_it_speaks_nothing_of_passion"),
  52568. (assign, ":result", 1),
  52569. (else_try), #moralizing ++, adventurous -, romantic -
  52570. (eq, ":poem", courtship_poem_allegoric),
  52571. (eq, ":lady_reputation", lrep_ambitious),
  52572. (str_store_string, s11, "str_storming_the_fortress_of_love_ah_a_sermon_dressed_up_as_a_love_poem_if_you_ask_me"),
  52573. (assign, ":result", 1),
  52574.  
  52575. (else_try), #romantic ++, moralizing 0, ambitious -
  52576. (eq, ":poem", courtship_poem_mystic),
  52577. (eq, ":lady_reputation", lrep_otherworldly),
  52578. (str_store_string, s11, "str_a_hearts_desire_ah_such_a_beautiful_account_of_the_perfect_perfect_love_to_love_like_that_must_be_to_truly_know_rapture"),
  52579. (assign, ":result", 4),
  52580.  
  52581. (else_try), #romantic ++, moralizing 0, ambitious -
  52582. (eq, ":poem", courtship_poem_mystic),
  52583. (eq, ":lady_reputation", lrep_ambitious),
  52584. (str_store_string, s11, "str_a_hearts_desire_silly_if_you_ask_me_if_the_poet_desires_a_lady_then_he_should_endeavor_to_win_her__and_not_dress_up_his_desire_with_a_pretense_of_piety"),
  52585. (assign, ":result", 0),
  52586.  
  52587. (else_try), #romantic ++, moralizing 0, ambitious -
  52588. (eq, ":poem", courtship_poem_mystic),
  52589. (eq, ":lady_reputation", lrep_moralist),
  52590. (str_store_string, s11, "str_a_hearts_desire_hmm__it_is_an_interesting_exploration_of_earthly_and_divine_love_it_does_speak_of_the_spiritual_quest_which_brings_out_the_best_in_man_but_i_wonder_if_the_poet_has_not_confused_his_yearning_for_higher_things_with_his_baser_passions"),
  52591. (assign, ":result", 2),
  52592.  
  52593. (else_try), #romantic ++, moralizing 0, ambitious -
  52594. (eq, ":poem", courtship_poem_mystic),
  52595. (str_store_string, s11, "str_a_hearts_desire_oh_yes__it_is_very_worthy_and_philosophical_but_if_i_am_to_listen_to_a_bard_strum_a_lute_for_three_hours_i_personally_prefer_there_to_be_a_bit_of_a_story"),
  52596. (assign, ":result", 1),
  52597. (try_end),
  52598.  
  52599.  
  52600. (try_begin),
  52601. (eq, "$cheat_mode", 1),
  52602. (assign, reg4, ":result"),
  52603. (display_message, "str_result_reg4_string_s11"),
  52604. (try_end),
  52605.  
  52606.  
  52607. (assign, reg0, ":result"),
  52608.  
  52609. ]),
  52610.  
  52611. (
  52612. "diplomacy_faction_get_diplomatic_status_with_faction",
  52613. #result: -1 faction_1 has a casus belli against faction_2. 1, faction_1 has a truce with faction_2, -2, the two factions are at war
  52614. [
  52615. (store_script_param, ":actor_faction", 1),
  52616. (store_script_param, ":target_faction", 2),
  52617. ##diplomacy start+
  52618. #Since "fac_player_supporters_faction" is used as a shorthand for the faction
  52619. #run by the player, intercept that here instead of the various places this is
  52620. #called from.
  52621. (call_script, "script_dplmc_translate_inactive_player_supporter_faction_2", ":actor_faction", ":target_faction"),
  52622. (assign, ":actor_faction", reg0),
  52623. (assign, ":target_faction", reg1),
  52624. ##diplomacy end+
  52625.  
  52626. (store_add, ":truce_slot", ":target_faction", slot_faction_truce_days_with_factions_begin),
  52627. (store_add, ":provocation_slot", ":target_faction", slot_faction_provocation_days_with_factions_begin),
  52628. (val_sub, ":truce_slot", kingdoms_begin),
  52629. (val_sub, ":provocation_slot", kingdoms_begin),
  52630.  
  52631. (assign, ":result", 0),
  52632. (assign, ":duration", 0),
  52633.  
  52634. (try_begin),
  52635. (store_relation, ":relation", ":actor_faction", ":target_faction"),
  52636. (lt, ":relation", 0),
  52637. (assign, ":result", -2),
  52638. (else_try),
  52639. (faction_slot_ge, ":actor_faction", ":truce_slot", 1),
  52640. (assign, ":result", 1),
  52641.  
  52642. (faction_get_slot, ":duration", ":actor_faction", ":truce_slot"),
  52643. (else_try),
  52644. (faction_slot_ge, ":actor_faction", ":provocation_slot", 1),
  52645. (assign, ":result", -1),
  52646.  
  52647. (faction_get_slot, ":duration", ":actor_faction", ":provocation_slot"),
  52648. (try_end),
  52649.  
  52650. (assign, reg0, ":result"),
  52651. (assign, reg1, ":duration"),
  52652. ]),
  52653.  
  52654. ("faction_follows_controversial_policy",
  52655. [
  52656. (store_script_param, ":faction_no", 1),
  52657. (store_script_param, ":policy_type", 2),
  52658.  
  52659. (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  52660.  
  52661. (try_begin),
  52662. (ge, "$cheat_mode", 1),
  52663. (str_store_faction_name, s3, ":faction_no"),
  52664. (display_message, "str_calculating_effect_for_policy_for_s3"),
  52665.  
  52666. (val_add, "$number_of_controversial_policy_decisions", 1),
  52667. (try_end),
  52668.  
  52669. (try_begin),
  52670. (eq, ":policy_type", logent_policy_ruler_attacks_without_provocation),
  52671. (assign, ":hawk_relation_effect", 0),
  52672. (assign, ":honorable_relation_effect", -2),
  52673. (assign, ":honor_change", -1),
  52674.  
  52675. (else_try),
  52676. (eq, ":policy_type", logent_policy_ruler_ignores_provocation),
  52677. (assign, ":hawk_relation_effect", -3),
  52678. (assign, ":honorable_relation_effect", 0),
  52679. (assign, ":honor_change", 0),
  52680.  
  52681. (else_try),
  52682. (eq, ":policy_type", logent_policy_ruler_declares_war_with_justification),
  52683. (assign, ":hawk_relation_effect", 3),
  52684. (assign, ":honorable_relation_effect", 1),
  52685. (assign, ":honor_change", 0),
  52686.  
  52687. (else_try),
  52688. (eq, ":policy_type", logent_policy_ruler_breaks_truce),
  52689. (assign, ":hawk_relation_effect", 0),
  52690. (assign, ":honorable_relation_effect", -3),
  52691. (assign, ":honor_change", -5),
  52692.  
  52693. (else_try),
  52694. (eq, ":policy_type", logent_policy_ruler_makes_peace_too_soon),
  52695. (assign, ":hawk_relation_effect", -5),
  52696. (assign, ":honorable_relation_effect", 0),
  52697. (assign, ":honor_change", 0),
  52698.  
  52699. ##diplomacy start+ If none of the preceeding match, don't use random memory
  52700. (else_try),
  52701. (assign, ":hawk_relation_effect", 0),
  52702. (assign, ":honorable_relation_effect", 0),
  52703. (assign, ":honor_change", 0),
  52704. ##diplomacy end+
  52705. (try_end),
  52706.  
  52707. (try_begin),
  52708. (eq, ":faction_leader", "trp_player"),
  52709. (call_script, "script_change_player_honor", ":honor_change"),
  52710. (try_end),
  52711.  
  52712. ##diplomacy start+ add support for promoted kingdom ladies
  52713. #(try_for_range, ":lord", active_npcs_begin, active_npcs_end),
  52714. (try_for_range, ":lord", heroes_begin, heroes_end),
  52715. ##diplomacy end+
  52716. (troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  52717. (store_faction_of_troop, ":lord_faction", ":lord"),
  52718. (eq, ":lord_faction", ":faction_no"),
  52719. (neq, ":lord", ":faction_leader"),
  52720.  
  52721. (try_begin),
  52722. ##diplomacy start+ Add support for lady personality type
  52723. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_adventurous),
  52724. ##diplomacy end+
  52725. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_martial),
  52726. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_quarrelsome),
  52727. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_selfrighteous),
  52728. (troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_debauched),
  52729. (call_script, "script_troop_change_relation_with_troop", ":faction_leader", ":lord", ":hawk_relation_effect"),
  52730. (val_add, "$total_policy_dispute_changes", ":hawk_relation_effect"),
  52731. (try_end),
  52732.  
  52733. (try_begin),
  52734. ##diplomacy start+ Add support for lady personality type
  52735. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_moralist),
  52736. ##diplomacy end+
  52737. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_martial),
  52738. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_goodnatured),
  52739. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_selfrighteous),
  52740. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_benefactor), #new for enfiefed commoners
  52741. (this_or_next|troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_custodian), #new for enfiefed commoners
  52742. (troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_upstanding),
  52743. (call_script, "script_troop_change_relation_with_troop", ":faction_leader", ":lord", ":honorable_relation_effect"),
  52744. (val_add, "$total_policy_dispute_changes", ":honorable_relation_effect"),
  52745.  
  52746. (try_end),
  52747.  
  52748. (try_end),
  52749.  
  52750. ]),
  52751.  
  52752.  
  52753. ("internal_politics_rate_feast_to_s9",
  52754. [
  52755. (store_script_param, ":householder", 1),
  52756. (store_script_param, ":num_servings", 2),
  52757. # (store_script_param, ":faction", 3),
  52758. (store_script_param, ":consume_items", 4),
  52759.  
  52760. (val_max, ":num_servings", 1),
  52761.  
  52762. (try_for_range, ":item", trade_goods_begin, trade_goods_end),
  52763. (item_set_slot, ":item", slot_item_amount_available, 0), #had no "item"
  52764. (try_end),
  52765.  
  52766. (troop_get_inventory_capacity, ":capacity", ":householder"),
  52767. (try_for_range, ":inventory_slot", ek_food + 1, ":capacity"), #SB : skip equipment
  52768. (troop_get_inventory_slot, ":item", ":householder", ":inventory_slot"),
  52769. (is_between, ":item", trade_goods_begin, trade_goods_end),
  52770. (troop_inventory_slot_get_item_amount, ":slot_amount", ":householder", ":inventory_slot"),
  52771. #SB : TODO : evaluate quality of food, for now just make sure it's not rotten
  52772. (troop_get_inventory_slot_modifier, ":imod", ":householder", ":inventory_slot"),
  52773. (neq, ":imod", imod_rotten),
  52774. (item_get_slot, ":item_amount", ":item", slot_item_amount_available),
  52775. (val_add, ":item_amount", ":slot_amount"),
  52776. (item_set_slot, ":item", slot_item_amount_available, ":item_amount"),
  52777. (try_end),
  52778. #food
  52779. (assign, ":food_amount", 0),
  52780. (assign, ":food_variety", 0),
  52781.  
  52782. (store_div, ":servings_div_by_12", ":num_servings", 12),
  52783. (try_for_range, ":food_item", food_begin, food_end),
  52784. (item_get_slot, ":food_in_slot", ":food_item", slot_item_amount_available),
  52785. (val_add, ":food_amount", ":food_in_slot"),
  52786.  
  52787.  
  52788. ## (str_store_item_name, s4, ":food_item"),
  52789. ## (assign, reg3, ":food_in_slot"),
  52790. ## (assign, reg5, ":servings_div_by_12"),
  52791. ## (display_message, "str_reg3_units_of_s4_for_reg5_guests_and_retinue"),
  52792.  
  52793.  
  52794. (ge, ":food_in_slot", ":servings_div_by_12"),
  52795. (val_add, ":food_variety", 1),
  52796. (try_end),
  52797.  
  52798. (val_mul, ":food_amount", 100),
  52799. (val_div, ":food_amount", ":num_servings"), #1 to 100 for each
  52800. (val_min, ":food_amount", 100),
  52801.  
  52802. (val_mul, ":food_variety", 85), #1 to 100 for each
  52803. (val_div, ":food_variety", 10),
  52804. (val_min, ":food_variety", 100),
  52805.  
  52806. #drink
  52807. (assign, ":drink_amount", 0),
  52808. (assign, ":drink_variety", 0),
  52809. (store_div, ":servings_div_by_4", ":num_servings", 4),
  52810. (try_for_range, ":drink_iterator", "itm_wine", "itm_smoked_fish"),
  52811. (assign, ":drink_item", ":drink_iterator"),
  52812. (item_get_slot, ":drink_in_slot", ":drink_item", slot_item_amount_available),
  52813.  
  52814. (val_add, ":drink_amount", ":drink_in_slot"),
  52815.  
  52816. (ge, ":drink_in_slot", ":servings_div_by_4"),
  52817. (val_add, ":drink_variety", 1),
  52818. (try_end),
  52819.  
  52820. (val_mul, ":drink_amount", 200), #amount needed is 50% of the number of guests
  52821. (val_max, ":num_servings", 1),
  52822.  
  52823. (val_div, ":drink_amount", ":num_servings"), #1 to 100 for each
  52824. (val_min, ":drink_amount", 100),
  52825. (val_mul, ":drink_variety", 50), #1 to 100 for each
  52826.  
  52827. #in the future, it might be worthwhile to add different varieties of spices
  52828. (item_get_slot, ":spice_amount", "itm_spice", slot_item_amount_available),
  52829. (store_mul, ":spice_percentage", ":spice_amount", 100),
  52830. (val_max, ":servings_div_by_12", 1),
  52831. (val_div, ":spice_amount", ":servings_div_by_12"),
  52832. (val_min, ":spice_percentage", 100),
  52833. ## (assign, reg3, ":spice_amount"),
  52834. ## (assign, reg5, ":servings_div_by_12"),
  52835. ## (assign, reg6, ":spice_percentage"),
  52836. ## (display_message, "str_reg3_units_of_spice_of_reg5_to_be_consumed"),
  52837.  
  52838. #oil availability. In the future, this may become an "atmospherics" category, including incenses
  52839. (item_get_slot, ":oil_amount", "itm_oil", slot_item_amount_available),
  52840. (store_mul, ":oil_percentage", ":oil_amount", 100),
  52841. (val_max, ":servings_div_by_12", 1),
  52842. (val_div, ":oil_amount", ":servings_div_by_12"),
  52843. (val_min, ":oil_percentage", 100),
  52844. ## (assign, reg3, ":oil_amount"),
  52845. ## (assign, reg5, ":servings_div_by_12"),
  52846. ## (assign, reg6, ":oil_percentage"),
  52847. ## (display_message, "str_reg3_units_of_oil_of_reg5_to_be_consumed"),
  52848.  
  52849. #SB : salt + date fruit probably useful too
  52850. (store_div, ":food_amount_string", ":food_amount", 20),
  52851. (val_add, ":food_amount_string", "str_feast_description"),
  52852. (str_store_string, s8, ":food_amount_string"),
  52853. (str_store_string, s9, "str_of_food_which_must_come_before_everything_else_the_amount_is_s8"),
  52854.  
  52855. (store_div, ":food_variety_string", ":food_variety", 20),
  52856. (val_add, ":food_variety_string", "str_feast_description"),
  52857. (str_store_string, s8, ":food_variety_string"),
  52858. (str_store_string, s9, "str_s9_and_the_variety_is_s8_"),
  52859.  
  52860. (store_div, ":drink_amount_string", ":drink_amount", 20),
  52861. (val_add, ":drink_amount_string", "str_feast_description"),
  52862. (str_store_string, s8, ":drink_amount_string"),
  52863. (str_store_string, s9, "str_s9_of_drink_which_guests_will_expect_in_great_abundance_the_amount_is_s8"),
  52864.  
  52865. (store_div, ":drink_variety_string", ":drink_variety", 20),
  52866. (val_add, ":drink_variety_string", "str_feast_description"),
  52867. (str_store_string, s8, ":drink_variety_string"),
  52868. (str_store_string, s9, "str_s9_and_the_variety_is_s8_"),
  52869.  
  52870. (store_div, ":spice_string", ":spice_percentage", 20),
  52871. (val_add, ":spice_string", "str_feast_description"),
  52872. (str_store_string, s8, ":spice_string"),
  52873. (str_store_string, s9, "str_s9_of_spice_which_is_essential_to_demonstrate_that_we_spare_no_expense_as_hosts_the_amount_is_s8_"),
  52874.  
  52875. (store_div, ":oil_string", ":oil_percentage", 20),
  52876. (val_add, ":oil_string", "str_feast_description"),
  52877. (str_store_string, s8, ":oil_string"),
  52878. (str_store_string, s9, "str_s9_of_oil_which_we_shall_require_to_light_the_lamps_the_amount_is_s8"),
  52879.  
  52880. (store_mul, ":food_amount_cap", ":food_amount", 8),
  52881. (store_add, ":total", ":food_amount", ":food_variety"),
  52882. (val_mul, ":total", 2), #x4
  52883. (val_add, ":total", ":drink_variety"),
  52884. (val_add, ":total", ":drink_amount"), #x6
  52885. (val_add, ":total", ":spice_amount"), #x7
  52886. (val_add, ":total", ":oil_amount"), #x8
  52887. (val_min, ":total", ":food_amount_cap"),
  52888. (val_div, ":total", 8),
  52889. (val_clamp, ":total", 1, 101),
  52890. (store_div, ":total_string", ":total", 20),
  52891. (val_add, ":total_string", "str_feast_description"),
  52892. (str_store_string, s8, ":total_string"),
  52893. (str_store_string, s9, "str_s9_overall_our_table_will_be_considered_s8"),
  52894.  
  52895. (assign, reg0, ":total"), #zero to 100
  52896.  
  52897.  
  52898.  
  52899. (try_begin),
  52900. (eq, ":consume_items", 1),
  52901.  
  52902. (assign, ":num_of_servings_to_serve", ":num_servings"),
  52903. (try_for_range, ":unused", 0, 1999),
  52904. (gt, ":num_of_servings_to_serve", 0),
  52905.  
  52906. (try_for_range, ":item", trade_goods_begin, trade_goods_end),
  52907. (item_set_slot, ":item", slot_item_is_checked, 0),
  52908. (try_end),
  52909.  
  52910. (troop_get_inventory_capacity, ":inv_size", ":householder"),
  52911. (try_for_range, ":i_slot", 0, ":inv_size"),
  52912. (troop_get_inventory_slot, ":item", ":householder", ":i_slot"),
  52913. (this_or_next|eq, ":item", "itm_spice"),
  52914. (this_or_next|eq, ":item", "itm_oil"),
  52915. (this_or_next|eq, ":item", "itm_wine"),
  52916. (this_or_next|eq, ":item", "itm_ale"),
  52917. (is_between, ":item", food_begin, food_end),
  52918. (item_slot_eq, ":item", slot_item_is_checked, 0),
  52919. (troop_inventory_slot_get_item_amount, ":cur_amount", ":householder", ":i_slot"),
  52920. (gt, ":cur_amount", 0),
  52921.  
  52922. (val_sub, ":cur_amount", 1),
  52923. (troop_inventory_slot_set_item_amount, ":householder", ":i_slot", ":cur_amount"),
  52924. (val_sub, ":num_of_servings_to_serve", 1),
  52925. (item_set_slot, ":item", slot_item_is_checked, 1),
  52926. (try_end),
  52927. ##diplomacy start+ Fix Native bug: "try_begin" to "try_end"
  52928. #(try_begin),
  52929. (try_end),
  52930. ##diplomacy end+
  52931. (try_end),
  52932. ]),
  52933.  
  52934.  
  52935. ("faction_get_adjective_to_s10",
  52936. [
  52937. (store_script_param, ":faction_no", 1),
  52938.  
  52939. (try_begin),
  52940. (eq, ":faction_no", "fac_player_faction"),
  52941. (assign, ":faction_no", "$players_kingdom"),
  52942. (try_end),
  52943.  
  52944.  
  52945. (try_begin),
  52946. (eq, ":faction_no", "fac_player_supporters_faction"),
  52947. (str_store_string, s10, "str_rebel"),
  52948. (else_try),
  52949. (this_or_next|eq, ":faction_no", "fac_outlaws"),
  52950. (this_or_next|eq, ":faction_no", "fac_mountain_bandits"),
  52951. (this_or_next|eq, ":faction_no", "fac_forest_bandits"),
  52952. (eq, ":faction_no", "fac_deserters"),
  52953. (str_store_string, s10, "str_bandit"),
  52954. (else_try),
  52955. (faction_get_slot, ":adjective_string", ":faction_no", slot_faction_adjective),
  52956. (str_store_string, s10, ":adjective_string"),
  52957. (try_end),
  52958. ]),
  52959.  
  52960. ("setup_tavern_attacker",
  52961. [
  52962. (store_script_param, ":cur_entry", 1),
  52963.  
  52964. (try_begin),
  52965. (neg|troop_slot_eq, "trp_hired_assassin", slot_troop_cur_center, "$g_encountered_party"),
  52966. (troop_slot_eq, "trp_belligerent_drunk", slot_troop_cur_center, "$g_encountered_party"),
  52967. (set_visitor, ":cur_entry", "trp_belligerent_drunk"),
  52968. (try_end),
  52969.  
  52970. (try_begin),
  52971. (troop_slot_eq, "trp_hired_assassin", slot_troop_cur_center, "$g_encountered_party"),
  52972. (set_visitor, ":cur_entry", "trp_hired_assassin"),
  52973. (try_end),
  52974. ]),
  52975.  
  52976. ("activate_tavern_attackers",
  52977. [
  52978. (set_party_battle_mode),
  52979. (try_for_agents, ":cur_agent"),
  52980. (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
  52981. (this_or_next|eq, ":cur_agent_troop", "trp_fugitive"),
  52982. (this_or_next|eq, ":cur_agent_troop", "trp_belligerent_drunk"),
  52983. (eq, ":cur_agent_troop", "trp_hired_assassin"),
  52984. (agent_set_team, ":cur_agent", 1),
  52985. (assign, "$g_main_attacker_agent", ":cur_agent"),
  52986. (agent_ai_set_aggressiveness, ":cur_agent", 199),
  52987. (try_end),
  52988. ]),
  52989.  
  52990. ("deactivate_tavern_attackers",
  52991. [
  52992. (finish_party_battle_mode),
  52993. (try_for_agents, ":cur_agent"),
  52994. (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
  52995. (this_or_next|eq, ":cur_agent_troop", "trp_fugitive"),
  52996. (this_or_next|eq, ":cur_agent_troop", "trp_belligerent_drunk"),
  52997. (eq, ":cur_agent_troop", "trp_hired_assassin"),
  52998. (agent_set_team, ":cur_agent", 0),
  52999. (agent_ai_set_aggressiveness, ":cur_agent", 0),
  53000. (try_end),
  53001. ]),
  53002.  
  53003. ("activate_town_guard",
  53004. [
  53005. (set_party_battle_mode),
  53006. #(get_player_agent_no, ":player_agent"),
  53007. #(agent_get_team, ":player_team", ":player_agent"),
  53008.  
  53009. (try_for_agents, ":cur_agent"),
  53010. (agent_get_troop_id, ":troop_type", ":cur_agent"),
  53011. (is_between, ":troop_type", "trp_swadian_recruit", "trp_looter"),
  53012. (agent_set_team, ":cur_agent", 1),
  53013. #(team_give_order, 1, grc_everyone, mordr_charge), - for some reason, this freezes everyone if the player is not yet spawned
  53014. #(try_begin),
  53015. # (eq, "$g_main_attacker_agent", 0),
  53016. # (assign, "$g_main_attacker_agent", ":cur_agent"),
  53017. #(try_end),
  53018. (else_try),
  53019. (this_or_next|is_between, ":cur_agent", walkers_begin, walkers_end),
  53020. (is_between, ":cur_agent", armor_merchants_begin, mayors_end),
  53021.  
  53022. (agent_clear_scripted_mode, ":cur_agent"),
  53023. (agent_set_team, ":cur_agent", 2),
  53024. (try_end),
  53025. ]),
  53026.  
  53027.  
  53028. #this determines whether or not a lord is thrown into a dungeon by his captor, or is kept out on parole
  53029. #Not currently used (ie, it always fails)
  53030. ("cf_prisoner_offered_parole",
  53031. [
  53032. (store_script_param, ":prisoner", 1),
  53033.  
  53034. (eq, 1, 0), #disabled, this will always return false
  53035.  
  53036. (troop_get_slot, ":captor_party", ":prisoner", slot_troop_prisoner_of_party),
  53037. (party_is_active, ":captor_party"),
  53038. (is_between, ":captor_party", walled_centers_begin, walled_centers_end),
  53039. (party_get_slot, ":captor", ":captor_party", slot_town_lord),
  53040.  
  53041. (troop_get_slot, ":prisoner_rep", ":prisoner", slot_lord_reputation_type),
  53042. (troop_get_slot, ":captor_rep", ":captor", slot_lord_reputation_type),
  53043.  
  53044. (neq, ":prisoner_rep", lrep_debauched),
  53045. (neq, ":captor_rep", lrep_debauched),
  53046. (neq, ":captor_rep", lrep_quarrelsome),
  53047.  
  53048. #Prisoner is a noble, or lord is goodnatured
  53049. (this_or_next|eq, ":captor_rep", lrep_goodnatured),
  53050. (this_or_next|troop_slot_eq, ":prisoner", slot_troop_occupation, slto_kingdom_hero),
  53051. (troop_slot_eq, ":prisoner", slot_troop_occupation, slto_kingdom_lady),
  53052.  
  53053. (call_script, "script_troop_get_relation_with_troop", ":captor", ":prisoner"),
  53054. ## (display_message, "str_relation_of_prisoner_with_captor_is_reg0"),
  53055. (ge, reg0, -10),
  53056. ]),
  53057.  
  53058. ("neutral_behavior_in_fight",
  53059. [
  53060. (get_player_agent_no, ":player_agent"),
  53061. (agent_get_position, pos3, ":player_agent"),
  53062. (agent_get_team, ":player_team", ":player_agent"),
  53063.  
  53064. (try_begin),
  53065. (gt, "$g_main_attacker_agent", 0),
  53066. (agent_get_team, ":attacker_team_no", "$g_main_attacker_agent"),
  53067. (agent_get_position, pos5, "$g_main_attacker_agent"),
  53068. (else_try),
  53069. (eq, ":attacker_team_no", -1),
  53070. (agent_get_position, pos5, ":player_agent"),
  53071. (try_end),
  53072.  
  53073. (set_fixed_point_multiplier, 100),
  53074.  
  53075. (try_for_agents, ":agent"),
  53076. (agent_get_team, ":other_team", ":agent"),
  53077. (neq, ":other_team", ":attacker_team_no"),
  53078. (neq, ":other_team", ":player_team"),
  53079.  
  53080. (agent_get_troop_id, ":troop_id", ":agent"),
  53081. #SB : better range checks
  53082. (this_or_next|eq, ":troop_id", "trp_farmer"), #farmers are "neutral"
  53083. (neg|is_between, ":troop_id", soldiers_begin, soldiers_end), #but lie within this range
  53084. (troop_slot_eq, ":troop_id", slot_troop_mission_participation, mp_unaware), #neutral prisoners?
  53085.  
  53086. (agent_get_position, pos4, ":agent"),
  53087.  
  53088. (assign, ":best_position_score", 0),
  53089. (assign, ":best_position", -1),
  53090.  
  53091. (try_begin),
  53092. (neg|agent_slot_eq, ":agent", slot_agent_is_running_away, 0), #if agent is running away
  53093. (agent_get_slot, ":target_entry_point_plus_one", ":agent", slot_agent_is_running_away),
  53094. (store_sub, ":target_entry_point", ":target_entry_point_plus_one", 1),
  53095. (entry_point_get_position, pos6, ":target_entry_point"),
  53096. (get_distance_between_positions, ":agent_distance_to_target", pos6, pos4),
  53097. (lt, ":agent_distance_to_target", 100),
  53098. (agent_set_slot, ":agent", slot_agent_is_running_away, 0),
  53099. (try_end),
  53100.  
  53101. (agent_slot_eq, ":agent", slot_agent_is_running_away, 0), #if agent is not already running away
  53102.  
  53103. (try_begin), #stand in place
  53104. (get_distance_between_positions, ":distance", pos4, pos5),
  53105. (get_distance_between_positions, ":distance_to_player", pos4, pos3),
  53106.  
  53107. (val_min, ":distance", ":distance_to_player"),
  53108.  
  53109. (this_or_next|gt, ":distance", 700), #7 meters away from main belligerents
  53110. (main_hero_fallen),
  53111.  
  53112. (agent_set_scripted_destination, ":agent", pos4),
  53113. (else_try), #get out of the way
  53114. (try_for_range, ":target_entry_point", 0, 64),
  53115. (neg|entry_point_is_auto_generated, ":target_entry_point"),
  53116. (entry_point_get_position, pos6, ":target_entry_point"),
  53117. (get_distance_between_positions, ":agent_distance_to_target", pos6, pos4),
  53118. (get_distance_between_positions, ":player_distance_to_target", pos6, pos3),
  53119. (store_sub, ":position_score", ":player_distance_to_target", ":agent_distance_to_target"),
  53120. (ge, ":position_score", 0),
  53121. (try_begin),
  53122. (ge, ":agent_distance_to_target", 2000),
  53123. (store_sub, ":extra_distance", ":agent_distance_to_target", 2000),
  53124. (val_min, ":extra_distance", 1000),
  53125. (val_min, ":agent_distance_to_target", 2000), #if more than 10 meters assume it is 10 meters far while calculating best run away target
  53126. (val_sub, ":agent_distance_to_target", ":extra_distance"),
  53127. (try_end),
  53128. (val_mul, ":position_score", ":agent_distance_to_target"),
  53129. (try_begin),
  53130. (ge, ":position_score", ":best_position_score"),
  53131. (assign, ":best_position_score", ":position_score"),
  53132. (assign, ":best_position", ":target_entry_point"),
  53133. (try_end),
  53134. (try_end),
  53135.  
  53136. (try_begin),
  53137. (ge, ":best_position", 0),
  53138. (entry_point_get_position, pos6, ":best_position"),
  53139. (agent_set_speed_limit, ":agent", 10),
  53140. (agent_set_scripted_destination, ":agent", pos6),
  53141. (store_add, ":best_position_plus_one", ":best_position", 1),
  53142. (agent_set_slot, ":agent", slot_agent_is_running_away, ":best_position_plus_one"),
  53143. (try_end),
  53144. (try_end),
  53145. (try_end),
  53146. ]),
  53147.  
  53148. ("party_inflict_attrition", #parameters from dialog
  53149. [
  53150. (store_script_param, ":party", 1),
  53151. (store_script_param, ":attrition_rate", 2),
  53152. # (store_script_param, ":attrition_type", 3), #1 = desertion, 2 = sickness
  53153. ##diplomacy start+
  53154. (store_script_param, ":unused", 3), #1 = desertion, 2 = sickness
  53155. ##diplomacy end+
  53156.  
  53157. (party_clear, "p_temp_casualties"),
  53158.  
  53159. (party_get_num_companion_stacks, ":num_stacks", ":party"),
  53160.  
  53161. #add to temp casualties
  53162. (try_for_range, ":stack", 0, ":num_stacks"),
  53163. (party_stack_get_troop_id, ":troop_type", ":party", ":stack"),
  53164. (neg|troop_is_hero, ":troop_type"),
  53165. (party_stack_get_size, ":size", ":party", ":stack"),
  53166. (store_mul, ":casualties_x_100", ":attrition_rate", ":size"),
  53167. (store_div, ":casualties", ":casualties_x_100", 100),
  53168. (party_add_members, "p_temp_casualties", ":troop_type", ":casualties"),
  53169.  
  53170. (store_mul, ":subtractor", ":casualties", 100),
  53171. (store_sub, ":chance_of_additional_casualty", ":casualties_x_100", ":subtractor"),
  53172.  
  53173. (try_begin),
  53174. (gt, ":chance_of_additional_casualty", 0),
  53175. (store_random_in_range, ":random", 0, 100),
  53176. (lt, ":random", ":chance_of_additional_casualty"),
  53177. (party_add_members, "p_temp_casualties", ":troop_type", ":casualties"),
  53178. (try_end),
  53179.  
  53180. # (try_begin),
  53181. # (eq, "$cheat_mode", 1),
  53182. # (str_store_party_name, s7, ":party"),
  53183. # ...
  53184. # (try_end),
  53185. (try_end),
  53186.  
  53187. #take temp casualties from main party
  53188. (party_get_num_companion_stacks, ":num_stacks", "p_temp_casualties"),
  53189.  
  53190. #add to temp casualties
  53191. (try_for_range, ":stack", 0, ":num_stacks"),
  53192. (party_stack_get_troop_id, ":troop_type", "p_temp_casualties", ":stack"),
  53193. (party_stack_get_size, ":size", "p_temp_casualties", ":stack"),
  53194. (party_remove_members, ":party", ":troop_type", ":size"),
  53195.  
  53196. (eq, "$cheat_mode", 1),
  53197. (assign, reg3, ":size"),
  53198. (str_store_troop_name, s4, ":troop_type"),
  53199. (str_store_party_name, s5, ":party"),
  53200. # (display_message, "str_s5_suffers_attrition_reg3_x_s4"),
  53201. (str_store_string, s65, "str_s5_suffers_attrition_reg3_x_s4"),
  53202. (display_message, "str_s65"),
  53203. (try_begin),
  53204. (eq, "$debug_message_in_queue", 0),
  53205. (call_script, "script_add_notification_menu", "mnu_debug_alert_from_s65", 0, 0),
  53206. (assign, "$debug_message_in_queue", 1),
  53207. (try_end),
  53208. (try_end),
  53209.  
  53210. ]),
  53211.  
  53212.  
  53213. ##diplomacy start+ (documentation only)
  53214. #
  53215. # Registers changed:
  53216. # reg4 - (sometimes, cheat only) current troop rumor of :object_1 or :object_2
  53217. #
  53218. # String registers changed:
  53219. # s10 - speaker name
  53220. # s11 - the third argument
  53221. # s1 - the date
  53222. # s5 - str_s10_said_on_s1_s11__
  53223. # s3 - (sometimes, cheat only) the troop name of :object_1 or :object_2
  53224. #
  53225. #
  53226. # Diplomacy+ mod change:
  53227. # - Use reg4 to contain the gender of the subject of a rumor string
  53228. ##diplomacy end+ (documentation only)
  53229. ("add_rumor_string_to_troop_notes", #parameters from dialog
  53230. [
  53231. (store_script_param, ":object_1", 1),
  53232. (store_script_param, ":object_2", 2),
  53233. (store_script_param, ":string", 3),
  53234.  
  53235. (str_store_troop_name, s10, "$g_talk_troop"),
  53236. (str_store_string_reg, s11, ":string"),
  53237.  
  53238. (store_current_hours, ":hours"),
  53239. (call_script, "script_game_get_date_text", 0, ":hours"),
  53240.  
  53241. (str_store_string, s5, "str_s10_said_on_s1_s11__"),
  53242.  
  53243. (try_begin),
  53244. (is_between, ":object_1", active_npcs_begin, kingdom_ladies_end),
  53245. (troop_get_slot, ":current_rumor_note", ":object_1", slot_troop_current_rumor),
  53246. (val_add, ":current_rumor_note", 1),
  53247. (try_begin),
  53248. (neg|is_between, ":current_rumor_note", 3, 16),
  53249. (assign, ":current_rumor_note", 3),
  53250. (try_end),
  53251. (troop_set_slot, ":object_1", slot_troop_current_rumor, ":current_rumor_note"),
  53252.  
  53253. (add_troop_note_from_sreg, ":object_1", ":current_rumor_note", s5, 0), #troop, note slot, string, show
  53254.  
  53255. (try_begin),
  53256. (eq, "$cheat_mode", 1),
  53257. (str_store_troop_name, s3, ":object_1"),
  53258. (assign, reg4, ":current_rumor_note"),
  53259. (display_message, "str_rumor_note_to_s3s_slot_reg4_s5"),
  53260. (try_end),
  53261. (try_end),
  53262.  
  53263. (try_begin),
  53264. (is_between, ":object_2", active_npcs_begin, kingdom_ladies_end),
  53265. (troop_get_slot, ":current_rumor_note", ":object_2", slot_troop_current_rumor),
  53266. (val_add, ":current_rumor_note", 1),
  53267. (try_begin),
  53268. (neg|is_between, ":current_rumor_note", 3, 16),
  53269. (assign, ":current_rumor_note", 3),
  53270. (try_end),
  53271. (troop_set_slot, ":object_2", slot_troop_current_rumor, ":current_rumor_note"),
  53272.  
  53273. (add_troop_note_from_sreg, ":object_2", ":current_rumor_note", s5, 0), #troop, note slot, string, show
  53274.  
  53275. (try_begin),
  53276. (eq, "$cheat_mode", 1),
  53277. (str_store_troop_name, s3, ":object_2"),
  53278. (assign, reg4, ":current_rumor_note"),
  53279. (display_message, "str_rumor_note_to_s3s_slot_reg4_s5"),
  53280. (try_end),
  53281. (try_end),
  53282. ]),
  53283.  
  53284. ("character_can_wed_character", #empty now, but might want to add mid-game
  53285. [
  53286. ]),
  53287.  
  53288. ("troop_change_career", #empty now, but might want to add mid-game
  53289. [
  53290. ]),
  53291.  
  53292. ("center_get_goods_availability",
  53293. [
  53294. (store_script_param, ":center_no", 1),
  53295.  
  53296. (str_store_party_name, s4, ":center_no"),
  53297. ##diplomacy start+ Determine whether the center should use "desert" consumption values.
  53298. #Native uses the following logic:
  53299. # (this_or_next|is_between, ":center_no", "p_town_19", "p_castle_1"),
  53300. # (ge, ":center_no", "p_village_91"),
  53301. ##This is very vulnerable to map changes, though, so I would prefer to check the terrain type.
  53302. (party_get_current_terrain, ":terrain_type", ":center_no"),
  53303. (try_begin),
  53304. (eq, reg0, rt_desert_forest),
  53305. (assign, ":terrain_type", rt_desert),
  53306. (try_end),
  53307. (try_begin),
  53308. (lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  53309. #To be consistent with script_center_get_consumption and script_initialize_economic_information
  53310. #use the Native desert-determination scheme when economic changes are disabled.
  53311. (assign, ":terrain_type", rt_plain),
  53312. (this_or_next|is_between, ":center_no", "p_town_19", "p_castle_1"),
  53313. (ge, ":center_no", "p_village_91"),
  53314. (assign, ":terrain_type", rt_desert),
  53315. (try_end),
  53316. ##diplomacy end+
  53317.  
  53318. (assign, ":hardship_index", 0),
  53319. (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
  53320.  
  53321. #Must have consumption of at least 4 to be relevant
  53322. #This prevents perishables and raw materials from having a major impact
  53323. (try_begin),
  53324. ##diplomacy start+ Use the "desert" slot when applicable
  53325. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  53326. (eq, ":terrain_type", rt_desert),
  53327. (item_slot_ge, ":cur_good", slot_item_desert_demand, 0), #Otherwise use rural or urban
  53328. (item_get_slot, ":consumer_consumption", ":cur_good", slot_item_desert_demand),
  53329. (else_try),
  53330. ##diplomacy end+
  53331. (is_between, ":center_no", villages_begin, villages_end),
  53332. (item_get_slot, ":consumer_consumption", ":cur_good", slot_item_rural_demand),
  53333. (else_try),
  53334. (item_get_slot, ":consumer_consumption", ":cur_good", slot_item_urban_demand),
  53335. (try_end),
  53336. (gt, ":consumer_consumption", 2),
  53337.  
  53338. (store_div, ":max_impact", ":consumer_consumption", 4), #was 4, dropped 3 again 4 now
  53339.  
  53340. #High-demand items like grain tend to have much more dramatic price differentiation, so they yield substantially higher results than low-demand items
  53341.  
  53342. (store_sub, ":cur_good_price_slot", ":cur_good", trade_goods_begin),
  53343. (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
  53344. (party_get_slot, ":price", ":center_no", ":cur_good_price_slot"),
  53345.  
  53346. (store_sub, ":price_differential", ":price", 1000),
  53347. (gt, ":price_differential", 200), #was 100
  53348.  
  53349. (val_div, ":price_differential", 200),
  53350. (val_min, ":price_differential", ":max_impact"),
  53351.  
  53352. (val_add, ":hardship_index", ":price_differential"),
  53353. (try_end),
  53354.  
  53355. (assign, reg0, ":hardship_index"),
  53356.  
  53357. (try_begin),
  53358. (eq, "$cheat_mode", 1),
  53359. (display_message, "@{!}DEBUG -- hardship index for {s4} = {reg0}"),
  53360. (try_end),
  53361. ]),
  53362.  
  53363. ("lord_find_alternative_faction", #Also, make it so that lords will try to keep at least one center unassigned
  53364. [
  53365. (store_script_param, ":troop_no", 1),
  53366. (store_faction_of_troop, ":orig_faction", ":troop_no"),
  53367.  
  53368. (assign, ":new_faction", -1),
  53369. (assign, ":score_to_beat", -5),
  53370. ##diplomacy start+
  53371. (troop_get_slot, ":true_original_faction", ":troop_no", slot_troop_original_faction),#not necessarily ":orig_faction"
  53372. (try_begin),
  53373. (neg|is_between, ":true_original_faction", kingdoms_begin, kingdoms_end),
  53374. (troop_get_slot, reg0, ":troop_no", slot_troop_home),
  53375. (is_between, reg0, centers_begin, centers_end),
  53376. (party_get_slot, reg0, reg0, slot_center_original_faction),
  53377. (gt, reg0, 0),
  53378. (assign, ":true_original_faction", reg0),
  53379. (try_end),
  53380. (assign, ":original_culture", -2),
  53381. (try_begin),
  53382. (gt, ":true_original_faction", 0),
  53383. (faction_get_slot, ":original_culture", ":true_original_faction", slot_faction_culture),
  53384. (lt, ":original_culture", 1),
  53385. (assign, ":original_culture", ":true_original_faction"),
  53386. (try_end),
  53387. ##diplomacy end+
  53388.  
  53389. #Factions with an available center
  53390. (try_for_range, ":center_no", centers_begin, centers_end),
  53391. (this_or_next|party_slot_eq, ":center_no", slot_town_lord, stl_unassigned),
  53392. (party_slot_eq, ":center_no", slot_town_lord, stl_rejected_by_player),
  53393. (store_faction_of_party, ":center_faction", ":center_no"),
  53394. ##diplomacy start+ In Warband 1.142 / 1.143, this variable was added.
  53395. #To make certain kinds of mistakes or saved-game issues less likely,
  53396. #instead of checking for value 1 I'll check if the value matches the troop.
  53397. (this_or_next|eq, "$g_give_advantage_to_original_faction", ":troop_no"),
  53398. ##diplomacy end+
  53399. (neq, ":center_faction", ":orig_faction"),
  53400. (faction_get_slot, ":liege", ":center_faction", slot_faction_leader),
  53401. (this_or_next|neq, ":liege", "trp_player"),
  53402. (ge, "$player_right_to_rule", 25),
  53403. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":liege"),
  53404. (assign, ":liege_relation", reg0),
  53405.  
  53406. ##diplomacy start+
  53407. (try_begin),
  53408. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  53409. #If behavioral changes are enabled, bias heavily towards joining the
  53410. #faction that contains your home (if you have one), or that has the
  53411. #greatest cultural similarity.
  53412. (ge, reg0, 0),
  53413. (try_begin),
  53414. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_original_faction, ":center_faction"),
  53415. (this_or_next|party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":troop_no"),
  53416. (troop_slot_eq, ":troop_no", slot_troop_home, ":center_no"),
  53417. (val_add, ":liege_relation", 20),
  53418. (else_try),
  53419. (gt, ":true_original_faction", 0),
  53420. (party_slot_eq, ":center_no", slot_center_original_faction, ":true_original_faction"),
  53421. (val_add, ":liege_relation", 5),
  53422. (else_try),
  53423. (gt, ":original_culture", 0),
  53424. (faction_slot_eq, ":center_faction", slot_faction_culture, ":original_culture"),
  53425. (val_add, ":liege_relation", 5),
  53426. (try_end),
  53427. (try_end),
  53428. ##diplomacy end+
  53429.  
  53430. (gt, ":liege_relation", ":score_to_beat"),
  53431. (assign, ":new_faction", ":center_faction"),
  53432. (assign, ":score_to_beat", ":liege_relation"),
  53433. (try_end),
  53434.  
  53435. #Factions without an available center
  53436. (try_begin),
  53437. (eq, ":new_faction", -1),
  53438. (assign, ":score_to_beat", 0),
  53439. #diplomacy start+
  53440. #If AI changes are explicitly enabled, slightly ease the requirements for entry.
  53441. (try_begin),
  53442. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  53443. (assign, ":score_to_beat", -5),
  53444. (try_end),
  53445. (store_add, ":min_acceptable_score", ":score_to_beat", 1),#used below
  53446. ##diplomacy end+
  53447.  
  53448. (try_for_range, ":kingdom", kingdoms_begin, kingdoms_end),
  53449. (faction_slot_eq, ":kingdom", slot_faction_state, sfs_active),
  53450. (faction_get_slot, ":liege", ":kingdom", slot_faction_leader),
  53451. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":liege"),
  53452. (assign, ":liege_relation", reg0),
  53453.  
  53454. ##diplomacy start+
  53455. (try_begin),
  53456. #In Warband 1.142 / 1.143, this variable was added.
  53457. #To make certain kinds of mistakes or saved-game issues less likely,
  53458. #instead of checking for value 1 I'll check if the value matches the troop.
  53459. (this_or_next|eq, "$g_give_advantage_to_original_faction", ":troop_no"),
  53460. (neq, ":kingdom", ":orig_faction"),
  53461. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  53462. #If behavioral changes are enabled, base your decision in part
  53463. #on how many friends you have in the faction.
  53464. (ge, reg0, ":min_acceptable_score"),
  53465. (try_for_range, ":lord", heroes_begin, heroes_end),
  53466. (troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  53467. (neq, ":lord", ":troop_no"),
  53468. (neq, ":lord", ":liege"),
  53469. (store_faction_of_troop, ":lord_faction", ":lord"),
  53470. (eq, ":lord_faction", ":kingdom"),
  53471. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":lord"),
  53472. (try_begin),
  53473. (ge, reg0, 20),
  53474. (val_add, ":liege_relation", 1),
  53475. (else_try),
  53476. (lt, reg0, -19),
  53477. (val_sub, ":liege_relation", 1),
  53478. (try_end),
  53479. (try_end),
  53480. #Also give a bonus towards rejoining the lord's original faction.
  53481. #if it isn't the one the lord has just left.
  53482. (try_begin),
  53483. (eq, ":true_original_faction", ":kingdom"),
  53484. (val_add, ":liege_relation", 5),
  53485. (else_try),
  53486. #Not the same but similar
  53487. (gt, ":original_culture", 0),
  53488. (faction_slot_eq, ":kingdom", slot_faction_culture, ":original_culture"),
  53489. (val_add, ":liege_relation", 2),
  53490. (try_end),
  53491. #The next bit is to prevent this change from increasing the number of
  53492. #lords who find all kingdoms unacceptable.
  53493. (val_max, ":liege_relation", ":min_acceptable_score"),
  53494. (try_end),
  53495. ##diplomacy end+
  53496.  
  53497. (gt, ":liege_relation", ":score_to_beat"),
  53498.  
  53499. (assign, ":new_faction", ":kingdom"),
  53500. (assign, ":score_to_beat", ":liege_relation"),
  53501. (try_end),
  53502. (try_end),
  53503.  
  53504. (assign, reg0, ":new_faction"),
  53505. ]),
  53506.  
  53507. ("set_up_duel_with_troop", #now the setup is handled through the menu
  53508. [
  53509. (store_script_param, "$g_duel_troop", 1),
  53510. #SB : change by parameter instead of always one
  53511. (store_script_param, "$g_start_arena_fight_at_nearest_town", 2),
  53512. (store_faction_of_troop, ":troop_faction", "$g_duel_troop"),
  53513. (try_begin),
  53514. (eq, "$g_start_arena_fight_at_nearest_town", 1),
  53515. # (assign, ":closest_town", -1),
  53516. (assign, ":minimum_dist", 500),
  53517. (try_for_range, ":cur_town", walled_centers_begin, walled_centers_end),
  53518. (store_distance_to_party_from_party, ":dist", ":cur_town", "$g_encountered_party"),
  53519. (lt, ":dist", ":minimum_dist"),
  53520. #make sure it's at least neutral, so we don't fight in an enemy town's arena
  53521. (store_faction_of_party, ":center_faction", ":cur_town"),
  53522. (store_relation, ":relation", ":troop_faction", ":center_faction"),
  53523. (ge, ":relation", 0),
  53524. (assign, ":minimum_dist", ":dist"),
  53525. (assign, "$g_start_arena_fight_at_nearest_town", ":cur_town"),
  53526. (try_end),
  53527. (try_end),
  53528. (unlock_achievement, ACHIEVEMENT_PUGNACIOUS_D),
  53529. (jump_to_menu, "mnu_arena_duel_fight"),
  53530. (finish_mission),
  53531.  
  53532. ]),
  53533.  
  53534. ("test_player_for_career_and_marriage_incompatability", #empty now, but might want to add mid-game
  53535. [
  53536. #Married to a lord of one faction, while fighting for another
  53537. #Married to one lord while holding a stipend from the king
  53538. ]),
  53539.  
  53540. ("deduct_casualties_from_garrison", #after a battle in a center, deducts any casualties from "$g_encountered_party"
  53541. [
  53542. ##(display_message, "str_totalling_casualties_caused_during_mission"),
  53543.  
  53544. (try_for_agents, ":agent"),
  53545. (agent_get_troop_id, ":troop_type", ":agent"),
  53546. (is_between, ":troop_type", regular_troops_begin, regular_troops_end),
  53547.  
  53548. (neg|agent_is_alive, ":agent"),
  53549.  
  53550. (try_begin), #if troop not present, search for another type which is
  53551. (store_troop_count_companions, ":number", ":troop_type", "$g_encountered_party"),
  53552. (eq, ":number", 0),
  53553. (assign, ":troop_type", 0),
  53554. (try_for_range, ":new_tier", slot_faction_tier_1_troop, slot_faction_tier_5_troop),
  53555. (faction_get_slot, ":troop_type", "$g_encountered_party_faction", ":new_tier"),
  53556. (faction_get_slot, ":new_troop_type", "$g_encountered_party_faction", ":new_tier"),
  53557. (store_troop_count_companions, ":number", ":new_troop_type", "$g_encountered_party"),
  53558. (gt, ":number", 0),
  53559. (assign, ":troop_type", ":new_troop_type"),
  53560. (try_end),
  53561. (try_end),
  53562.  
  53563. (gt, ":troop_type", 0),
  53564.  
  53565. (party_remove_members, "$g_encountered_party", ":troop_type", 1),
  53566. (str_store_troop_name, s4, ":troop_type"),
  53567. (str_store_party_name, s5, "$g_encountered_party"),
  53568. (try_end),
  53569. ]),
  53570.  
  53571. ("npc_decision_checklist_take_stand_on_issue",
  53572. #Called from dialogs, and from simple_triggers
  53573.  
  53574. #This a very inefficient checklist, and if I did it again, I would score for each troop. That way the troop could answer "why not" to an individual lord
  53575. [
  53576. (store_script_param, ":troop_no", 1),
  53577. (store_faction_of_troop, ":troop_faction", ":troop_no"),
  53578.  
  53579. (assign, ":result", -1),
  53580. (faction_get_slot, ":faction_issue", ":troop_faction", slot_faction_political_issue),
  53581.  
  53582. (assign, ":player_declines_honor", 0),
  53583. (try_begin),
  53584. (is_between, ":faction_issue", centers_begin, centers_end),
  53585. (gt, "$g_dont_give_fief_to_player_days", 1),
  53586. (assign, ":player_declines_honor", 1),
  53587. (else_try),
  53588. (gt, "$g_dont_give_marshalship_to_player_days", 1),
  53589. (assign, ":player_declines_honor", 1),
  53590. (try_end),
  53591.  
  53592. ##diplomacy start+
  53593. (faction_get_slot, ":faction_leader", ":troop_faction", slot_faction_leader),
  53594. (call_script, "script_dplmc_is_affiliated_family_member", ":troop_no"),
  53595. (assign, ":affiliated_with_player", reg0),
  53596.  
  53597. (assign, ":subaltern_gender", -1),#The gender subject to sexism (as far as leadership is concerned).
  53598. (try_begin),
  53599. (lt, "$g_disable_condescending_comments", 2),#Prejudice not disabled
  53600. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),#Don't bother with the rest of the check
  53601. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),#if the lord has an unbiased outlook.
  53602. (neg|troop_slot_ge, ":troop_no", slot_lord_reputation_type, lrep_roguish),
  53603. (call_script, "script_dplmc_store_troop_is_female", ":troop_no"),
  53604. (store_sub, ":subaltern_gender", 1, reg0),
  53605. (try_begin),
  53606. (call_script, "script_cf_dplmc_faction_has_bias_against_gender", ":troop_faction", ":subaltern_gender"),
  53607. (else_try),
  53608. (assign, ":subaltern_gender", -1),
  53609. (try_end),
  53610. (try_end),
  53611.  
  53612. (assign, ":faction_lord_count", 0),#Keep track of the number of lords in the faction
  53613. ##diplomacy end+
  53614.  
  53615. (assign, ":total_faction_renown", 0),
  53616. (troop_set_slot, "trp_player", slot_troop_temp_slot, 0),
  53617. (try_begin),
  53618. (eq, "$players_kingdom", ":troop_faction"),
  53619. (eq, "$player_has_homage", 1),
  53620. (troop_get_slot, ":total_faction_renown", "trp_player", slot_troop_renown),
  53621. ##diplomacy start+
  53622. #Increment the faction lord count
  53623. (val_add, ":faction_lord_count", 1),
  53624.  
  53625. (try_begin),
  53626. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  53627. (eq, ":subaltern_gender", "$character_gender"),
  53628. (val_mul, ":total_faction_renown", 4),
  53629. (val_add, ":total_faction_renown", 3),
  53630. (val_div, ":total_faction_renown", 5),
  53631. (try_end),
  53632. ##diplomacy end+
  53633. (try_end),
  53634.  
  53635. ##diplomacy start+
  53636. (try_for_range, ":active_npc", heroes_begin, heroes_end),#Changed range to include kingdom ladies
  53637. (troop_set_slot, ":active_npc", dplmc_slot_troop_temp_slot, 0), #this will hold distance to closest owned fief
  53638. ##diplomacy end+
  53639. (troop_set_slot, ":active_npc", slot_troop_temp_slot, 0), #reset to zero
  53640.  
  53641. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  53642. (eq, ":active_npc_faction", ":troop_faction"),
  53643. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  53644.  
  53645. (troop_get_slot, ":renown", ":active_npc", slot_troop_renown),
  53646. ##diplomacy start+
  53647. #Increment the faction lord count
  53648. (val_add, ":faction_lord_count", 1),
  53649.  
  53650. (try_begin),#If the player has set the prejudice mode to "high".
  53651. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  53652. (call_script, "script_dplmc_store_troop_is_female", ":active_npc"),
  53653. (eq, reg0, ":subaltern_gender"),
  53654. (val_mul, ":renown", 4),
  53655. (val_add, ":renown", 3),
  53656. (val_div, ":renown", 5),
  53657. (try_end),
  53658. ##diplomacy end+
  53659. (val_add, ":total_faction_renown", ":renown"),
  53660. (try_end),
  53661.  
  53662.  
  53663. (assign, ":total_faction_center_value", 0),
  53664. (try_for_range, ":center", centers_begin, centers_end),
  53665. (store_faction_of_party, ":center_faction", ":center"),
  53666. (eq, ":center_faction", ":troop_faction"),
  53667.  
  53668. (assign, ":center_value", 1),
  53669. (try_begin),
  53670. ##diplomacy start+
  53671. #Use different scoring scheme
  53672. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  53673. (try_begin),
  53674. (party_slot_eq, ":center", slot_party_type, spt_town),
  53675. (assign, ":center_value", 3),
  53676. (else_try),
  53677. (neg|party_slot_eq, ":center", slot_party_type, spt_village),
  53678. (this_or_next|party_slot_eq, ":center", slot_party_type, spt_castle),
  53679. (is_between, ":center", walled_centers_begin, walled_centers_end),
  53680. (assign, ":center_value", 2),
  53681. (try_end),
  53682. #Otherwise fall through to old behavior
  53683. (else_try),
  53684. ##diplomacy end+
  53685. (is_between, ":center", towns_begin, towns_end),
  53686. (assign, ":center_value", 2),
  53687. (try_end),
  53688.  
  53689. (val_add, ":total_faction_center_value", ":center_value"),
  53690.  
  53691. (party_get_slot, ":town_lord", ":center", slot_town_lord),
  53692. ##diplomacy start+
  53693. #The rest of the script assumes that non-player lords are heroes,
  53694. #so add that condition here to get the count right.
  53695. #(gt, ":town_lord", -1),
  53696. (this_or_next|eq, ":town_lord", "trp_player"),
  53697. (is_between, ":town_lord", heroes_begin, heroes_end),
  53698.  
  53699. #Calculate distance for alternate scoring if the issue is a center
  53700. (try_begin),
  53701. (is_between, ":faction_issue", centers_begin, centers_end),
  53702. (neq, ":center", ":faction_issue"),
  53703. (troop_get_slot, ":dplmc_temp_slot", ":town_lord", dplmc_slot_troop_temp_slot),
  53704. (store_distance_to_party_from_party, reg0, ":center", ":faction_issue"),
  53705. (gt, reg0, 0),
  53706. (try_begin),
  53707. (eq, ":dplmc_temp_slot", 0),
  53708. (assign, ":dplmc_temp_slot", reg0),
  53709. (else_try),
  53710. (val_min, ":dplmc_temp_slot", reg0),
  53711. (try_end),
  53712. (troop_set_slot, ":town_lord", dplmc_slot_troop_temp_slot, ":dplmc_temp_slot"),
  53713. (try_end),
  53714. ##diplomacy end+
  53715.  
  53716. (troop_get_slot, ":temp_slot", ":town_lord", slot_troop_temp_slot),
  53717. (val_add, ":temp_slot", ":center_value"),
  53718. (troop_set_slot, ":town_lord", slot_troop_temp_slot, ":temp_slot"),
  53719. (try_end),
  53720. (val_max, ":total_faction_center_value", 1),
  53721.  
  53722. (store_div, ":average_renown_per_center_point", ":total_faction_renown", ":total_faction_center_value"),
  53723. ##diplomacy start+
  53724. (val_max, ":faction_lord_count", 1),
  53725.  
  53726. # (store_mul, ":avg_renown_plus_500_per_cp", ":faction_lord_count", 500),
  53727. # (val_add, ":avg_renown_plus_500_per_cp", ":total_faction_renown"),
  53728. # (store_add, reg0, ":total_faction_center_value", ":faction_lord_count"),
  53729. # (val_div, ":avg_renown_plus_500_per_cp", reg0),
  53730.  
  53731. #Get the standard deviation of renown per center point
  53732. (assign, ":renown_per_center_point_variance", 0),
  53733. # (assign, ":renown_plus_500_per_center_point_variance", 0),
  53734.  
  53735. (try_for_range, ":active_npc", active_npcs_including_player_begin, heroes_end),
  53736. (store_sub, ":active_npc_faction", ":troop_faction", 1),#guaranteed not to equal
  53737. (try_begin),
  53738. #handle player
  53739. (eq, ":active_npc", active_npcs_including_player_begin),
  53740. (assign, ":active_npc", "trp_player"),
  53741. (eq, "$players_kingdom", ":troop_faction"),
  53742. (eq, "$player_has_homage", 1),
  53743. (assign, ":active_npc_faction", ":troop_faction"),
  53744. (else_try),
  53745. #handle kingdom heroes
  53746. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  53747. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  53748. (try_end),
  53749.  
  53750. (eq, ":active_npc_faction", ":troop_faction"),
  53751.  
  53752. (troop_get_slot, ":renown", ":active_npc", slot_troop_renown),
  53753. (try_begin),
  53754. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  53755. (call_script, "script_dplmc_store_troop_is_female", ":active_npc"),
  53756. (eq, reg0, ":subaltern_gender"),
  53757. (val_mul, ":renown", 4),
  53758. (val_add, ":renown", 3),
  53759. (val_div, ":renown", 5),
  53760. (try_end),
  53761. (troop_get_slot, ":center_points", ":active_npc", slot_troop_temp_slot),
  53762. #Variance for renown / center points
  53763. (val_max, ":center_points", 1),
  53764. (store_div, reg0, ":renown", ":center_points"),
  53765. (val_sub, reg0, ":average_renown_per_center_point"),
  53766. (val_mul, reg0, reg0),
  53767. (val_add, ":renown_per_center_point_variance", reg0),
  53768.  
  53769. # #Variance for renown + 500 / center points + 1
  53770. # (troop_get_slot, ":center_points", ":active_npc", slot_troop_temp_slot),
  53771. # (val_add, ":center_points", 1),
  53772. # (store_add, reg0, ":renown", 500),
  53773. # (val_div, reg0, ":center_points"),
  53774. # (val_sub, reg0, ":avg_renown_plus_500_per_cp"),
  53775. # (val_mul, reg0, reg0),
  53776. # (val_add, ":renown_plus_500_per_center_point_variance", reg0),
  53777. (try_end),
  53778.  
  53779. #Get renown per center point standard deviation, or 10%, whichever is greater
  53780. (store_div, reg0, ":faction_lord_count", 2),#for rounding
  53781. (val_add, ":renown_per_center_point_variance", reg0),
  53782. (val_div, ":renown_per_center_point_variance", ":faction_lord_count"),
  53783.  
  53784. (assign, reg0, ":renown_per_center_point_variance"),
  53785. (convert_to_fixed_point, reg0),
  53786. (store_sqrt, reg0, reg0),
  53787. (convert_from_fixed_point, reg0),
  53788. (assign, ":renown_per_center_point_standard_deviation", reg0),
  53789. (val_add, reg0, 5),
  53790. (val_div, reg0, 10),
  53791. (val_max, ":renown_per_center_point_standard_deviation", reg0),
  53792. (store_sub, ":renown_low_target", ":average_renown_per_center_point", ":renown_per_center_point_standard_deviation"),
  53793. (val_max, ":renown_low_target", 0),
  53794.  
  53795. # #Get (renown + 500) per (center point plus one) standard deviation, or 10%, whichever is greater
  53796. # (store_div, reg0, ":faction_lord_count", 2),#for rounding
  53797. # (val_add, ":renown_plus_500_per_center_point_variance", reg0),
  53798. # (val_div, ":renown_plus_500_per_center_point_variance", ":faction_lord_count"),
  53799. #
  53800. # (assign, reg0, ":renown_plus_500_per_center_point_variance"),
  53801. # (convert_to_fixed_point, reg0),
  53802. # (store_sqrt, reg0, reg0),
  53803. # (convert_from_fixed_point, reg0),
  53804. # (assign, ":renown_plus_500_per_center_point_standard_deviation", reg0),
  53805. # (val_add, reg0, 5),
  53806. # (val_div, reg0, 10),
  53807. # (val_max, ":renown_plus_500_per_center_point_standard_deviation", reg0),
  53808. # (store_sub, ":renown_500_low_target", ":avg_renown_plus_500_per_cp", ":renown_plus_500_per_center_point_standard_deviation"),
  53809. # (val_max, ":renown_500_low_target", 0),
  53810. ##diplomacy end+
  53811.  
  53812. (try_begin),
  53813. (is_between, ":faction_issue", centers_begin, centers_end),
  53814. #NOTE -- The algorithms here might seem a bit repetitive, but are designed that way to create internal cliques among the lords in a faction.
  53815.  
  53816.  
  53817.  
  53818. (try_begin),#If the center is a village, and a lord has no fief, choose him
  53819. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  53820. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_selfrighteous),
  53821. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_quarrelsome),
  53822.  
  53823. (is_between, ":faction_issue", villages_begin, villages_end),
  53824. (assign, ":favorite_lord_without_center", -1),
  53825. (assign, ":score_to_beat", -1),
  53826. ##diplomacy start+
  53827. (try_begin),
  53828. #With changes enabled, widen the range of scores to check for certain personality types
  53829. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  53830. (try_begin),
  53831. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  53832. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  53833. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_benefactor),
  53834. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_conventional),
  53835. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_moralist),
  53836. (this_or_next|is_between, ":troop_no", kings_begin, kings_end),
  53837. (is_between, ":troop_no", pretenders_begin, pretenders_end),
  53838. (assign, ":score_to_beat", -6),#-5 or better is indifferent
  53839. (else_try),
  53840. (ge, ":faction_leader", 0),
  53841. (this_or_next|eq, ":faction_leader", ":troop_no"),
  53842. (this_or_next|troop_slot_eq, ":faction_leader", slot_troop_spouse, ":troop_no"),
  53843. (troop_slot_eq, ":troop_no", slot_troop_spouse, ":faction_leader"),
  53844. (assign, ":score_to_beat", -6),#-5 or better is indifferent
  53845. (try_end),
  53846. (try_end),
  53847. ##diplomacy end+
  53848.  
  53849. (try_begin),
  53850. (eq, "$players_kingdom", ":troop_faction"),
  53851. (eq, "$player_has_homage", 1),
  53852. (eq, ":player_declines_honor", 0),
  53853.  
  53854. (troop_slot_eq, "trp_player", slot_troop_temp_slot, 0),
  53855. (call_script, "script_troop_get_relation_with_troop", "trp_player", ":troop_no"),
  53856. (assign, ":relation", reg0),
  53857. ##diplomacy start+
  53858. #If the player doesn't have prejudice disabled, don't automatically support for a first fief
  53859. (try_begin),
  53860. (this_or_next|neq, ":subaltern_gender", "$character_gender"),
  53861. (this_or_next|is_between, ":troop_no", companions_begin, companions_end),#Former companions will support the player
  53862. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_spouse, "trp_player"),#Spouses will support the player
  53863. (troop_slot_eq, "trp_player", slot_troop_spouse, ":troop_no"),
  53864. (else_try),
  53865. (val_sub, ":relation", 20),
  53866. (try_end),
  53867. ##diplomacy end+
  53868.  
  53869. (gt, ":relation", ":score_to_beat"),
  53870. (neg|troop_slot_ge, "trp_player", slot_troop_controversy, 75),
  53871. (assign, ":favorite_lord_without_center", "trp_player"),
  53872. (assign, ":score_to_beat", ":relation"),
  53873. (try_end),
  53874. ##diplomacy start+ Support promoted kingdom ladise
  53875. #(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end), #<-- replace this
  53876. (try_for_range, ":active_npc", heroes_begin, heroes_end),
  53877. ##diplomacy end+
  53878. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  53879. (eq, ":active_npc_faction", ":troop_faction"),
  53880. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  53881.  
  53882. (troop_slot_eq, ":active_npc", slot_troop_temp_slot, 0),
  53883. (try_begin),
  53884. (eq, ":active_npc", ":troop_no"),
  53885. (assign, ":relation", 50),
  53886. (else_try),
  53887. (call_script, "script_troop_get_relation_with_troop", ":active_npc", ":troop_no"),
  53888. (assign, ":relation", reg0),
  53889. (try_end),
  53890. ##diplomacy start+ Disadvantage the subaltern gender
  53891. (call_script, "script_dplmc_store_troop_is_female", ":troop_no"),
  53892. (try_begin),
  53893. (eq, reg0, ":subaltern_gender"),
  53894. (val_sub, ":relation", 20),
  53895. (try_end),
  53896. ##diplomacy end+
  53897. (neg|troop_slot_ge, ":active_npc", slot_troop_controversy, 75),
  53898.  
  53899. (gt, ":relation", ":score_to_beat"),
  53900. (assign, ":favorite_lord_without_center", ":active_npc"),
  53901. (assign, ":score_to_beat", ":relation"),
  53902. (try_end),
  53903.  
  53904. (gt, ":favorite_lord_without_center", -1),
  53905. (assign, ":result", ":favorite_lord_without_center"),
  53906. (assign, ":result_explainer", "str_political_explanation_lord_lacks_center"),
  53907. ##diplomacy start+
  53908. ##Faction leaders are more rational about whom they support.
  53909. (else_try),
  53910. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  53911. (call_script, "script_dplmc_get_troop_standing_in_faction", ":troop_no", ":troop_faction"),
  53912. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  53913. (assign, ":best_candidate", -1),
  53914. (assign, ":best_score", -1),
  53915. (assign, ":explanation", 0),
  53916. (try_begin),
  53917. (eq,"$players_kingdom", ":troop_faction"),
  53918. (eq, "$player_has_homage", 1),
  53919. (eq, ":player_declines_honor", 0),
  53920. (call_script, "script_dplmc_calculate_troop_score_for_center_aux", ":troop_no", "trp_player", ":faction_issue"),#reg0 = score, reg1 = explanation
  53921. (assign, ":best_candidate", "trp_player"),
  53922. (assign, ":best_score", reg0),
  53923. (assign, ":explanation", reg1),
  53924. (try_end),
  53925. (try_for_range, ":active_npc", heroes_begin, heroes_end),
  53926. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  53927. (eq, ":active_npc_faction", ":troop_faction"),
  53928. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  53929. (call_script, "script_dplmc_calculate_troop_score_for_center_aux", ":troop_no", ":active_npc", ":faction_issue"),#reg0 = score, reg1 = explanation
  53930. (this_or_next|eq, ":best_candidate", -1),
  53931. (gt, reg0, ":best_score"),
  53932. (assign, ":best_candidate", ":active_npc"),
  53933. (assign, ":best_score", reg0),
  53934. (assign, ":explanation", reg1),
  53935. (try_end),
  53936. (gt, ":best_candidate", -1),
  53937. (assign, ":result", ":best_candidate"),
  53938. (assign, ":result_explainer", ":explanation"),
  53939. ##diplomacy end+
  53940. (else_try), #taken by troop
  53941. (is_between, ":faction_issue", walled_centers_begin, walled_centers_end),
  53942. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  53943. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_selfrighteous),
  53944. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  53945.  
  53946. (party_get_slot, ":last_taken_by_troop", ":faction_issue", slot_center_last_taken_by_troop),
  53947. (try_begin),
  53948. (try_begin),
  53949. (neq, ":troop_faction", "$players_kingdom"),
  53950. (assign, ":last_taken_by_troop", -1),
  53951. (else_try),
  53952. (eq, "$player_has_homage", 0),
  53953. (assign, ":last_taken_by_troop", -1),
  53954. (else_try),
  53955. (eq, ":faction_issue", "$g_castle_requested_by_player"),
  53956. (assign, ":last_taken_by_troop", "trp_player"),
  53957. (else_try),
  53958. (eq, ":faction_issue", "$g_castle_requested_for_troop"),
  53959. (assign, ":last_taken_by_troop", "trp_player"),
  53960. (else_try), #ie, the fellow who took it is no longer in the faction
  53961. (gt, ":last_taken_by_troop", -1),
  53962. (store_faction_of_troop, ":last_take_by_troop_faction", ":last_taken_by_troop"),
  53963. (neq, ":last_take_by_troop_faction", ":troop_faction"),
  53964. (assign, ":last_taken_by_troop", -1),
  53965. (try_end),
  53966. (try_end),
  53967. (gt, ":last_taken_by_troop", -1),
  53968.  
  53969. (try_begin),
  53970. (eq, "$cheat_mode", 1),
  53971. (gt, ":last_taken_by_troop", -1),
  53972. (str_store_troop_name, s3, ":last_taken_by_troop"),
  53973. (display_message, "@{!}Castle taken by {s3}"),
  53974. (try_end),
  53975.  
  53976.  
  53977. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":last_taken_by_troop"),
  53978. ##diplomacy start+
  53979. #If behavior changes are enabled, increase the accepted range for certain personality types.
  53980. (assign, ":relation", reg0),
  53981. (try_begin),
  53982. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  53983. (try_begin),
  53984. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_martial),
  53985. (val_add, reg0, 5),#i.e. accept at -5 (indifferent) or higher
  53986. (else_try),
  53987. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  53988. (val_add, reg0, 5),#i.e. accept at -5 (indifferent) or higher
  53989. (try_end),
  53990. (try_end),
  53991. ##diplomacy end+
  53992. (ge, reg0, 0),
  53993.  
  53994. (neg|troop_slot_ge, ":last_taken_by_troop", slot_troop_controversy, 25),
  53995.  
  53996. (troop_get_slot, ":renown", ":last_taken_by_troop", slot_troop_renown),
  53997. ##diplomacy start+
  53998. (try_begin),
  53999. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  54000. (call_script, "script_dplmc_store_troop_is_female", ":last_taken_by_troop"),
  54001. (eq, reg0, ":subaltern_gender"),
  54002. (val_mul, ":renown", 4),
  54003. (val_add, ":renown", 3),
  54004. (val_div, ":renown", 5),
  54005. (try_end),
  54006. ##diplomacy end+
  54007. (troop_get_slot, ":center_points", ":last_taken_by_troop", slot_troop_temp_slot),
  54008. (val_max, ":center_points", 1),
  54009. (store_div, ":renown_divided_by_center_points", ":renown", ":center_points"),
  54010. (val_mul, ":renown_divided_by_center_points", 6), #was five
  54011. (val_div, ":renown_divided_by_center_points", 4),
  54012.  
  54013. ##diplomacy start+
  54014. (try_begin),
  54015. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  54016. #Possibly raise renown_divided_by_center_points
  54017. (store_div, reg0, ":renown", ":center_points"),
  54018. (val_add, reg0, ":renown_per_center_point_standard_deviation"),
  54019. (val_max, ":renown_divided_by_center_points", reg0),
  54020. (try_end),
  54021. ##diplomacy end+
  54022. (ge, ":renown_divided_by_center_points", ":average_renown_per_center_point"),
  54023.  
  54024.  
  54025. (assign, ":result", ":last_taken_by_troop"),
  54026. (assign, ":result_explainer", "str_political_explanation_lord_took_center"),
  54027.  
  54028.  
  54029. #Check self, immediate family
  54030. #This is done instead of a single weighted score to create cliques -- groups of NPCs who support one another
  54031. (else_try),
  54032. (assign, ":most_deserving_close_friend", -1),
  54033. (assign, ":score_to_beat", ":average_renown_per_center_point"),
  54034. (val_div, ":score_to_beat", 3),
  54035. (val_mul, ":score_to_beat", 2),
  54036.  
  54037. (try_begin),
  54038. (eq, "$cheat_mode", 1),
  54039. (assign, reg3, ":score_to_beat"),
  54040. (display_message, "@{!}Two-thirds average_renown = {reg3}"),
  54041. (try_end),
  54042.  
  54043. ###diplomacy start+
  54044. #(try_begin),
  54045. # (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  54046. # (try_begin),
  54047. # (eq, "$cheat_mode", 1),
  54048. # (assign, reg3, ":renown_low_target"),
  54049. # (display_message, "@{!}Average renown per center minus one standard deviation = {reg3}"),
  54050. # (try_end),
  54051. #(try_end),
  54052. ###diplomacy end+
  54053.  
  54054. (try_begin),
  54055. (eq, "$players_kingdom", ":troop_faction"),
  54056. (eq, "$player_has_homage", 1),
  54057. (eq, ":player_declines_honor", 0),
  54058.  
  54059. (call_script, "script_troop_get_relation_with_troop", "trp_player", ":troop_no"),
  54060. (assign, ":relation", reg0),
  54061. ##diplomacy start+
  54062. #If affiliated with player
  54063. (this_or_next|gt, ":affiliated_with_player", 0),
  54064. ##diplomacy end+
  54065. (ge, ":relation", 20),
  54066. (neg|troop_slot_ge, "trp_player", slot_troop_controversy, 50),
  54067.  
  54068. (troop_get_slot, ":renown", "trp_player", slot_troop_renown),
  54069. ##diplomacy start+
  54070. (try_begin),
  54071. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  54072. (eq, ":subaltern_gender", "$character_gender"),
  54073. (val_mul, ":renown", 4),
  54074. (val_add, ":renown", 3),
  54075. (val_div, ":renown", 5),
  54076. (try_end),
  54077. (troop_get_slot, ":center_points", "trp_player", slot_troop_temp_slot),
  54078. (val_max, ":center_points", 1),
  54079. (store_div, ":renown_divided_by_center_points", ":renown", ":center_points"),
  54080.  
  54081.  
  54082. (assign, ":most_deserving_close_friend", "trp_player"),
  54083. (assign, ":score_to_beat", ":renown_divided_by_center_points"),
  54084. (try_end),
  54085. ##diplomacy start+ Support promoted kingdom ladies
  54086. #(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end), #<- replace
  54087. (try_for_range, ":active_npc", heroes_begin, heroes_end),
  54088. ##diplomacy end+
  54089. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  54090. (eq, ":active_npc_faction", ":troop_faction"),
  54091. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  54092.  
  54093. (call_script, "script_troop_get_relation_with_troop", ":active_npc", ":troop_no"),
  54094. (assign, ":relation", reg0),
  54095. ##diplomacy start+
  54096. (assign, reg0, 0),
  54097. #If affiliated with player
  54098. (try_begin),
  54099. (lt, ":relation", 20),
  54100. (gt, ":affiliated_with_player", 0),
  54101. (neq, ":active_npc", ":troop_no"),
  54102. (call_script, "script_dplmc_is_affiliated_family_member", ":troop_no"),
  54103. (try_end),
  54104. (this_or_next|gt, reg0, 0),#<-- both affiliated
  54105. ##diplomacy end+
  54106. (this_or_next|eq, ":active_npc", ":troop_no"),
  54107. (ge, ":relation", 20),
  54108. (neg|troop_slot_ge, ":active_npc", slot_troop_controversy, 50),
  54109.  
  54110. (troop_get_slot, ":renown", ":active_npc", slot_troop_renown),
  54111. ##diplomacy start+
  54112. (try_begin),
  54113. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  54114. (call_script, "script_dplmc_store_troop_is_female", ":active_npc"),
  54115. (eq, reg0, ":subaltern_gender"),
  54116. (val_mul, ":renown", 4),
  54117. (val_add, ":renown", 3),
  54118. (val_div, ":renown", 5),
  54119. (try_end),
  54120. ##diplomacy end+
  54121. (troop_get_slot, ":center_points", ":active_npc", slot_troop_temp_slot),
  54122. (val_max, ":center_points", 1),
  54123. (store_div, ":renown_divided_by_center_points", ":renown", ":center_points"),
  54124.  
  54125.  
  54126. (try_begin),
  54127. (eq, "$cheat_mode", 1),
  54128. (str_store_troop_name, s10, ":active_npc"),
  54129. (assign, reg3, ":renown_divided_by_center_points"),
  54130. (display_message, "@{!}DEBUG -- Colleague test: score for {s10} = {reg3}"),
  54131. (try_end),
  54132.  
  54133.  
  54134. (gt, ":renown_divided_by_center_points", ":score_to_beat"),
  54135.  
  54136. (assign, ":most_deserving_close_friend", ":active_npc"),
  54137. (assign, ":score_to_beat", ":renown_divided_by_center_points"),
  54138. (try_end),
  54139.  
  54140. (gt, ":most_deserving_close_friend", -1),
  54141.  
  54142.  
  54143. (assign, ":result", ":most_deserving_close_friend"),
  54144. (assign, ":result_explainer", "str_political_explanation_most_deserving_friend"),
  54145.  
  54146.  
  54147.  
  54148. (else_try),
  54149. #Most deserving in entire faction, minus those with no relation
  54150. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  54151. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_selfrighteous),
  54152. (neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_quarrelsome),
  54153.  
  54154. (assign, ":most_deserving_in_faction", -1),
  54155. (assign, ":score_to_beat", 0),
  54156.  
  54157. (try_begin),
  54158. (eq, "$players_kingdom", ":troop_faction"),
  54159. (eq, "$player_has_homage", 1),
  54160. (eq, ":player_declines_honor", 0),
  54161.  
  54162. (call_script, "script_troop_get_relation_with_troop", "trp_player", ":troop_no"),
  54163. (assign, ":relation", reg0),
  54164. (ge, ":relation", 0),
  54165. (troop_get_slot, ":renown", "trp_player", slot_troop_renown),
  54166. ##diplomacy start+
  54167. (try_begin),
  54168. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  54169. (eq, ":subaltern_gender", "$character_gender"),
  54170. (val_mul, ":renown", 4),
  54171. (val_add, ":renown", 3),
  54172. (val_div, ":renown", 5),
  54173. (try_end),
  54174. ##diplomacy end+
  54175. (troop_get_slot, ":center_points", "trp_player", slot_troop_temp_slot),
  54176. (neg|troop_slot_ge, "trp_player", slot_troop_controversy, 25),
  54177.  
  54178. (val_max, ":center_points", 1),
  54179. (store_div, ":renown_divided_by_center_points", ":renown", ":center_points"),
  54180.  
  54181. (assign, ":most_deserving_in_faction", "trp_player"),
  54182. (assign, ":score_to_beat", ":renown_divided_by_center_points"),
  54183. (try_end),
  54184. ##diplomacy start+ add support for promoted kingdom ladies
  54185. #(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
  54186. (try_for_range, ":active_npc", heroes_begin, heroes_end),
  54187. (this_or_next|is_between, ":active_npc", active_npcs_begin, active_npcs_end),
  54188. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  54189. ##diplomacy end+
  54190. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  54191. (eq, ":active_npc_faction", ":troop_faction"),
  54192. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  54193.  
  54194. (call_script, "script_troop_get_relation_with_troop", ":active_npc", ":troop_no"),
  54195. (assign, ":relation", reg0),
  54196. (this_or_next|eq, ":active_npc", ":troop_no"),
  54197. (ge, ":relation", 0),
  54198. (neg|troop_slot_ge, ":active_npc", slot_troop_controversy, 25),
  54199.  
  54200. (troop_get_slot, ":renown", ":active_npc", slot_troop_renown),
  54201. ##diplomacy start+
  54202. (try_begin),
  54203. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  54204. (call_script, "script_dplmc_store_troop_is_female", ":active_npc"),
  54205. (eq, reg0, ":subaltern_gender"),
  54206. (val_mul, ":renown", 4),
  54207. (val_add, ":renown", 3),
  54208. (val_div, ":renown", 5),
  54209. (try_end),
  54210. ##diplomacy end+
  54211. (troop_get_slot, ":center_points", ":active_npc", slot_troop_temp_slot),
  54212. (val_max, ":center_points", 1),
  54213.  
  54214. (store_div, ":renown_divided_by_center_points", ":renown", ":center_points"),
  54215. (gt, ":renown_divided_by_center_points", ":score_to_beat"),
  54216.  
  54217. (try_begin),
  54218. (eq, "$cheat_mode", 1),
  54219. (str_store_string, s10, ":active_npc"),
  54220. (assign, reg3, ":renown_divided_by_center_points"),
  54221. (display_message, "@{!}DEBUG -- Open test: score for {s10} = {reg3}"),
  54222. (try_end),
  54223.  
  54224.  
  54225. (assign, ":most_deserving_in_faction", ":active_npc"),
  54226. (assign, ":score_to_beat", ":renown_divided_by_center_points"),
  54227. (try_end),
  54228.  
  54229.  
  54230. (gt, ":most_deserving_in_faction", -1),
  54231. (assign, ":result", ":most_deserving_in_faction"),
  54232. (assign, ":result_explainer", "str_political_explanation_most_deserving_in_faction"),
  54233. ##diplomacy start+
  54234. (else_try),
  54235. #The lord wasn't able to find any suitable candidates,
  54236. #so now we perform the evaluation from another perspective.
  54237. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  54238. #DPLMC_AI_CHANGES >= LOW
  54239. #DPLMC_AI_CHANGES >= MEDIUM XOR status >= DPLMC_FACTION_STANDING_LEADER_SPOUSE
  54240. (call_script, "script_dplmc_get_troop_standing_in_faction", ":troop_no", ":troop_faction"),
  54241. (this_or_next|ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  54242. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  54243. (this_or_next|lt, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  54244. (lt, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  54245. (assign, ":save_reg1", reg1),
  54246.  
  54247. (assign, ":score_to_beat", 0),
  54248. (assign, ":most_deserving_in_faction", -1),
  54249. #(assign, ":tmp_explanation", 0),
  54250.  
  54251. (try_for_range, ":active_npc", active_npcs_including_player_begin, heroes_end),
  54252. (store_sub, ":active_npc_faction", ":troop_faction", 1),
  54253. (try_begin),
  54254. (eq, ":active_npc", active_npcs_including_player_begin),
  54255. (assign, ":active_npc", "trp_player"),
  54256. (eq, "$players_kingdom", ":troop_faction"),
  54257. (eq, "$player_has_homage", 1),
  54258. (assign, ":active_npc_faction", ":troop_faction"),
  54259. (else_try),
  54260. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  54261. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  54262. (try_end),
  54263. (eq, ":active_npc_faction", ":troop_faction"),
  54264.  
  54265. #(call_script, "script_dplmc_aux_troop_evaluate_troop_for_center", ":troop_no", ":active_npc", ":faction_issue"),#reg0 = score, reg1 = explanation
  54266. (call_script, "script_dplmc_calculate_troop_score_for_center_aux", ":troop_no", ":active_npc", ":faction_issue"),#reg0 = score, reg1 = explanation
  54267.  
  54268. (this_or_next|eq, ":most_deserving_in_faction", -1),
  54269. (ge, reg0, ":score_to_beat"),
  54270. (assign, ":score_to_beat", reg0),
  54271. (assign, ":result_explainer", reg1),
  54272. (assign, ":most_deserving_in_faction", ":active_npc"),
  54273. (try_end),
  54274.  
  54275. (gt, ":most_deserving_in_faction", -1),
  54276. (assign, ":result", ":most_deserving_in_faction"),
  54277. #(assign, ":result_explainer", ":result_explainer"),#unneeded
  54278. (assign, reg1, ":save_reg1"),
  54279. ##diplomacy end+
  54280. (else_try),
  54281. (assign, ":result", ":troop_no"),
  54282. (assign, ":result_explainer", "str_political_explanation_self"),
  54283. (try_end),
  54284.  
  54285.  
  54286. (else_try),
  54287. (eq, ":faction_issue", 1),
  54288.  
  54289. (assign, ":relationship_threshhold", 15),
  54290. (try_begin),
  54291. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  54292. (assign, ":relationship_threshhold", 5),
  54293. (else_try),
  54294. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  54295. (assign, ":relationship_threshhold", 25),
  54296. (try_end),
  54297.  
  54298. #For marshals, score marshals according to renown divided by controversy - first for friends and family, then for everyone
  54299. (assign, ":marshal_candidate", -1),
  54300. (assign, ":score_to_beat", 0),
  54301. (try_begin),
  54302. (eq, "$players_kingdom", ":troop_faction"),
  54303. (eq, "$player_has_homage", 1),
  54304. (eq, "$g_player_is_captive", 0),
  54305. (eq, ":player_declines_honor", 0),
  54306.  
  54307.  
  54308. (call_script, "script_troop_get_relation_with_troop", "trp_player", ":troop_no"),
  54309. (ge, reg0, ":relationship_threshhold"),
  54310. (assign, ":marshal_candidate", "trp_player"),
  54311. (troop_get_slot, ":renown", "trp_player", slot_troop_renown),
  54312. ##diplomacy start+
  54313. (try_begin),
  54314. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  54315. (eq, ":subaltern_gender", "$character_gender"),
  54316. (val_mul, ":renown", 4),
  54317. (val_add, ":renown", 3),
  54318. (val_div, ":renown", 5),
  54319. (try_end),
  54320. ##diplomacy end+
  54321. (troop_get_slot, ":controversy_divisor", "trp_player", slot_troop_controversy),
  54322. (val_add, ":controversy_divisor", 50),
  54323. (store_div, ":score_to_beat", ":renown", ":controversy_divisor"),
  54324. (try_end),
  54325.  
  54326. ##diplomacy start+ Support promoted ladies
  54327. #(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
  54328. (try_for_range, ":active_npc", heroes_begin, heroes_end),
  54329. ##diplomacy end+
  54330. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  54331. (eq, ":active_npc_faction", ":troop_faction"),
  54332. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  54333. (troop_slot_eq, ":active_npc", slot_troop_prisoner_of_party, -1),
  54334.  
  54335. (neg|faction_slot_eq, ":troop_faction", slot_faction_leader, ":active_npc"),
  54336.  
  54337. (call_script, "script_troop_get_relation_with_troop", ":active_npc", ":troop_no"),
  54338. (assign, ":relation", reg0),
  54339. (this_or_next|eq, ":active_npc", ":troop_no"),
  54340. (ge, ":relation", ":relationship_threshhold"),
  54341.  
  54342. (troop_get_slot, ":renown", ":active_npc", slot_troop_renown),
  54343. ##diplomacy start+
  54344. (try_begin),
  54345. (lt, "$g_disable_condescending_comments", 0),#If the player has set the prejudice mode to "high"
  54346. (call_script, "script_dplmc_store_troop_is_female", ":troop_no"),
  54347. (eq, reg0, ":subaltern_gender"),
  54348. (val_mul, ":renown", 4),
  54349. (val_add, ":renown", 3),
  54350. (val_div, ":renown", 5),
  54351. (try_end),
  54352. ##diplomacy end+
  54353. (troop_get_slot, ":controversy_divisor", ":active_npc", slot_troop_controversy),
  54354. (val_add, ":controversy_divisor", 50),
  54355. (store_div, ":score", ":renown", ":controversy_divisor"),
  54356.  
  54357. (gt, ":score", ":score_to_beat"),
  54358.  
  54359. (assign, ":marshal_candidate", ":active_npc"),
  54360. (assign, ":score_to_beat", ":score"),
  54361.  
  54362. (try_end),
  54363.  
  54364. (assign, ":result", ":marshal_candidate"),
  54365. (assign, ":result_explainer", "str_political_explanation_marshal"),
  54366. (try_end),
  54367.  
  54368. (try_begin),
  54369. (eq, "$cheat_mode", 1),
  54370. (gt, ":result", -1),
  54371. (str_store_troop_name, s8, ":troop_no"),
  54372. (str_store_troop_name, s9, ":result"),
  54373. (str_store_string, s10, ":result_explainer"),
  54374. (display_message, "@{!}DEBUG -- {s8} backs {s9}:{s10}"),
  54375. (try_end),
  54376.  
  54377. (assign, reg0, ":result"),
  54378. (assign, reg1, ":result_explainer"),
  54379.  
  54380. ]),
  54381.  
  54382.  
  54383. ("npc_decision_checklist_evaluate_faction_strategy",
  54384. [
  54385. #Decides whether the strategy is good or bad -- to be added
  54386. ]),
  54387.  
  54388.  
  54389. ("process_player_enterprise",
  54390. #reg0: Profit per cycle
  54391. ##diplomacy start+
  54392. #Actual documentation of original parameters and outputs.
  54393. # INPUTS:
  54394. # arg1: item_type
  54395. # arg2: center
  54396. # OUTPUTS:
  54397. # reg0: profit_per_cycle"),
  54398. # reg1: final_price_for_total_produced_goods"),
  54399. # reg2: final_price_for_total_inputs"),
  54400. # reg3: price_of_labor"),
  54401. # reg4: final_price_for_single_produced_good"),
  54402. # reg5: final_price_for_single_input"),
  54403. # reg10: final_price_for_secondary_input"),
  54404. #
  54405. # Further, if experimental changes are enabled, modify the price.
  54406. ##diplomacy end+
  54407. [
  54408. (store_script_param, ":item_type", 1),
  54409. (store_script_param, ":center", 2),
  54410.  
  54411. (item_get_slot, ":price_of_labor", ":item_type", slot_item_overhead_per_run),
  54412.  
  54413. (item_get_slot, ":base_price", ":item_type", slot_item_base_price),
  54414. (store_sub, ":cur_good_price_slot", ":item_type", trade_goods_begin),
  54415. (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
  54416. (party_get_slot, ":cur_price_modifier", ":center", ":cur_good_price_slot"),
  54417. ##diplomacy start+
  54418. (val_clamp, ":cur_price_modifier", minimum_price_factor, maximum_price_factor + 1),#Added enforcement of minimum/maximum
  54419. (store_mul, ":final_price_for_single_produced_good", ":base_price", ":cur_price_modifier"),#<- (Unchanged)
  54420. (val_div, ":final_price_for_single_produced_good", average_price_factor),#Replaced "1000" with "average_price_factor"
  54421. ##diplomacy end+
  54422. (item_get_slot, ":number_of_outputs_produced", ":item_type", slot_item_output_per_run),
  54423. (store_mul, ":final_price_for_total_produced_goods", ":number_of_outputs_produced", ":final_price_for_single_produced_good"),
  54424.  
  54425. (item_get_slot, ":primary_raw_material", ":item_type", slot_item_primary_raw_material),
  54426. (item_get_slot, ":base_price", ":primary_raw_material", slot_item_base_price),
  54427. (store_sub, ":cur_good_price_slot", ":primary_raw_material", trade_goods_begin),
  54428. (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
  54429. (party_get_slot, ":cur_price_modifier", ":center", ":cur_good_price_slot"),
  54430. ##diplomacy start+
  54431. (try_begin),
  54432. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),#<-- experimental changes must be enabled
  54433. (call_script, "script_dplmc_assess_ability_to_purchase_good_from_center", ":primary_raw_material", ":center"),
  54434. (val_max, ":cur_price_modifier", reg0),
  54435. (try_end),
  54436. (val_clamp, ":cur_price_modifier", minimum_price_factor, maximum_price_factor + 1),#Added enforcement of minimum/maximum
  54437. (store_mul, ":final_price_for_single_input", ":base_price", ":cur_price_modifier"),#<- (Unchanged)
  54438. (val_div, ":final_price_for_single_input", average_price_factor),#Replaced "1000" with "average_price_factor"
  54439. ##diplomacy end+
  54440. (item_get_slot, ":number_of_inputs_required", ":item_type", slot_item_input_number),
  54441. (try_begin),
  54442. (lt, ":number_of_inputs_required", 0),
  54443. (store_div, ":final_price_for_total_inputs", ":final_price_for_single_input", 2),
  54444. (else_try),
  54445. (store_mul, ":final_price_for_total_inputs", ":final_price_for_single_input", ":number_of_inputs_required"),
  54446. (try_end),
  54447.  
  54448. (try_begin),
  54449. (item_slot_ge, ":item_type", slot_item_secondary_raw_material, 1),
  54450. (item_get_slot, ":secondary_raw_material", ":item_type", slot_item_secondary_raw_material),
  54451. (item_get_slot, ":base_price", ":secondary_raw_material", slot_item_base_price),
  54452. (store_sub, ":cur_good_price_slot", ":secondary_raw_material", trade_goods_begin),
  54453. (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
  54454. (party_get_slot, ":cur_price_modifier", ":center", ":cur_good_price_slot"),
  54455. ##diplomacy start+
  54456. (try_begin),
  54457. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_MEDIUM),#<-- experimental changes must be enabled
  54458. (call_script, "script_dplmc_assess_ability_to_purchase_good_from_center", ":secondary_raw_material", ":center"),
  54459. (val_max, ":cur_price_modifier", reg0),
  54460. (try_end),
  54461. (val_clamp, ":cur_price_modifier", minimum_price_factor, maximum_price_factor + 1),#Added enforcement of minimum/maximum
  54462. ##diplomacy end+
  54463. (store_mul, ":final_price_for_secondary_input", ":base_price", ":cur_price_modifier"),#fixes
  54464. (try_begin),
  54465. (lt, ":number_of_inputs_required", 0),
  54466. (val_div, ":final_price_for_secondary_input", 2),
  54467. (else_try),
  54468. (val_mul, ":final_price_for_secondary_input", ":number_of_inputs_required"),
  54469. (try_end),
  54470.  
  54471. ##diplomacy start+
  54472. (val_div, ":final_price_for_secondary_input", average_price_factor),#Replaced "1000" with "average_price_factor"
  54473. ##diplomacy end+
  54474. (else_try),
  54475. (assign, ":final_price_for_secondary_input", 0),
  54476. (try_end),
  54477.  
  54478. (store_sub, ":profit_per_cycle", ":final_price_for_total_produced_goods", ":final_price_for_total_inputs"),
  54479. (val_sub, ":profit_per_cycle", ":price_of_labor"),
  54480. (val_sub, ":profit_per_cycle", ":final_price_for_secondary_input"),
  54481.  
  54482. (assign, reg0, ":profit_per_cycle"),
  54483. (assign, reg1, ":final_price_for_total_produced_goods"),
  54484. (assign, reg2, ":final_price_for_total_inputs"),
  54485. (assign, reg3, ":price_of_labor"),
  54486. (assign, reg4, ":final_price_for_single_produced_good"),
  54487. (assign, reg5, ":final_price_for_single_input"),
  54488. (assign, reg10, ":final_price_for_secondary_input"),
  54489. ]),
  54490.  
  54491. # script_replace_scene_items_with_spawn_items_before_ms
  54492. # Input: none
  54493. # Output: none
  54494. ("replace_scene_items_with_spawn_items_before_ms",
  54495. [
  54496. (try_for_range, ":item_no", all_items_begin, all_items_end),
  54497. (scene_item_get_num_instances, ":num_instances", ":item_no"),
  54498. (item_set_slot, ":item_no", slot_item_num_positions, 0),
  54499. (assign, ":num_positions", 0),
  54500. (try_for_range, ":cur_instance", 0, ":num_instances"),
  54501. (scene_item_get_instance, ":scene_item", ":item_no", ":cur_instance"),
  54502. (prop_instance_get_position, "$g_position_to_use_for_replacing_scene_items", ":scene_item"),
  54503. (store_add, ":cur_slot", slot_item_positions_begin, ":num_positions"),
  54504. (item_set_slot, ":item_no", ":cur_slot", "$g_position_to_use_for_replacing_scene_items"),
  54505. (val_add, ":num_positions", 1),
  54506. (val_add, "$g_position_to_use_for_replacing_scene_items", 1),
  54507. (item_set_slot, ":item_no", slot_item_num_positions, ":num_positions"),
  54508. (try_end),
  54509. (replace_scene_items_with_scene_props, ":item_no", "spr_empty"),
  54510. (try_end),
  54511. ]),
  54512.  
  54513. # script_replace_scene_items_with_spawn_items_after_ms
  54514. # Input: none
  54515. # Output: none
  54516. ("replace_scene_items_with_spawn_items_after_ms",
  54517. [
  54518. (try_for_range, ":item_no", all_items_begin, all_items_end),
  54519. (item_get_slot, ":num_positions", ":item_no", slot_item_num_positions),
  54520. (try_for_range, ":cur_position", 0, ":num_positions"),
  54521. (store_add, ":cur_slot", slot_item_positions_begin, ":cur_position"),
  54522. (item_get_slot, ":pos_no", ":item_no", ":cur_slot"),
  54523. (set_spawn_position, ":pos_no"),
  54524. (spawn_item, ":item_no", 0),
  54525. (try_end),
  54526. (try_end),
  54527. ]),
  54528.  
  54529. # script_cf_is_melee_weapon_for_tutorial
  54530. # Input: arg1 = item_no
  54531. # Output: none (can fail)
  54532. ("cf_is_melee_weapon_for_tutorial",
  54533. [
  54534. (store_script_param, ":item_no", 1),
  54535. (assign, ":result", 0),
  54536. (try_begin),
  54537. (this_or_next|eq, ":item_no", "itm_quarter_staff"),
  54538. (eq, ":item_no", "itm_practice_sword"),
  54539. (assign, ":result", 1),
  54540. (try_end),
  54541. (eq, ":result", 1),
  54542. ]),
  54543.  
  54544. # script_iterate_pointer_arrow
  54545. # Input: none
  54546. # Output: none
  54547. ("iterate_pointer_arrow",
  54548. [
  54549. (store_mission_timer_a_msec, ":cur_time"),
  54550. (try_begin),
  54551. (assign, ":up_down", ":cur_time"),
  54552. (assign, ":turn_around", ":cur_time"),
  54553. (val_mod, ":up_down", 1080),
  54554. (val_div, ":up_down", 3),
  54555. (scene_prop_get_instance, ":prop_instance", "spr_pointer_arrow", 0),
  54556. (prop_instance_get_position, pos0, ":prop_instance"),
  54557. (position_set_z_to_ground_level, pos0),
  54558. (position_move_z, pos0, "$g_pointer_arrow_height_adder", 1),
  54559. (set_fixed_point_multiplier, 100),
  54560. (val_mul, ":up_down", 100),
  54561. (store_sin, ":up_down_sin", ":up_down"),
  54562. (position_move_z, pos0, ":up_down_sin", 1),
  54563. (position_move_z, pos0, 100, 1),
  54564. (val_mod, ":turn_around", 2880),
  54565. (val_div, ":turn_around", 8),
  54566. (init_position, pos1),
  54567. (position_rotate_z, pos1, ":turn_around"),
  54568. (position_copy_rotation, pos0, pos1),
  54569. (prop_instance_set_position, ":prop_instance", pos0),
  54570. (try_end),
  54571. ]),
  54572.  
  54573. ("find_center_to_attack_alt",
  54574. [
  54575. (store_script_param, ":troop_no", 1),
  54576. (store_script_param, ":attack_by_faction", 2),
  54577. (store_script_param, ":all_vassals_included", 3),
  54578.  
  54579. (assign, ":result", -1),
  54580. (assign, ":score_to_beat", 0),
  54581.  
  54582. (try_for_range, ":center_no", centers_begin, centers_end),
  54583. (call_script, "script_npc_decision_checklist_evaluate_enemy_center_for_attack", ":troop_no", ":center_no", ":attack_by_faction", ":all_vassals_included"),
  54584. (assign, ":score", reg0),
  54585.  
  54586. (gt, ":score", ":score_to_beat"),
  54587.  
  54588. (assign, ":result", ":center_no"),
  54589. (assign, ":score_to_beat", ":score"),
  54590. (try_end),
  54591.  
  54592. (assign, reg0, ":result"),
  54593. (assign, reg1, ":score_to_beat"),
  54594. ]),
  54595.  
  54596. ("npc_decision_checklist_evaluate_enemy_center_for_attack",
  54597. [
  54598. #NOTES -- LAST OFFENSIVE TIME SCORE IS NOT USED
  54599.  
  54600. (store_script_param, ":troop_no", 1),
  54601. (store_script_param, ":potential_target", 2),
  54602. (store_script_param, ":attack_by_faction", 3),
  54603. (store_script_param, ":all_vassals_included", 4),
  54604.  
  54605. (assign, ":result", -1),
  54606. (assign, ":explainer_string", -1),
  54607. #(assign, ":reason_is_obvious", 0),
  54608. (assign, ":power_ratio", 0),
  54609. #(assign, ":hours_since_last_recce", -1),
  54610.  
  54611. #(assign, ":value_of_target", 0),
  54612. #(assign, ":difficulty_of_capture", 0),
  54613. (store_faction_of_troop, ":faction_no", ":troop_no"),
  54614.  
  54615. (try_begin),
  54616. (eq, ":attack_by_faction", 1),
  54617. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  54618. (ge, ":faction_marshal", 0), #STEVE ADDITION TO AVOID MESSAGE SPAM
  54619. (troop_get_slot, ":party_no", ":faction_marshal", slot_troop_leaded_party),
  54620. (else_try),
  54621. (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
  54622. (try_end),
  54623.  
  54624. (assign, "$g_use_current_ai_object_as_s8", 0),
  54625. ##diplomacy start+ Use this if AI changes are enabled.
  54626. (party_get_slot, ":hours_since_capture", ":potential_target", dplmc_slot_center_last_transfer_time),
  54627. (try_begin),
  54628. #If the slot was uninitialized, set it to negative to indicate invalid.
  54629. (eq, ":hours_since_capture", 0),
  54630. (assign, ":hours_since_capture", -1),
  54631. (else_try),
  54632. (store_current_hours, reg0),
  54633. (val_sub, ":hours_since_capture", reg0),
  54634. (try_end),
  54635. #How recent counts as "recent" depends on the AI settings.
  54636. (try_begin),
  54637. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_HIGH),
  54638. (assign, ":recency_maximum", 24 * 21),#The last three weeks
  54639. (else_try),
  54640. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_MEDIUM),
  54641. (assign, ":recency_maximum", 24 * 14),#The last two weeks
  54642. (else_try),
  54643. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  54644. (assign, ":recency_maximum", 24 * 7),#The last week
  54645. (else_try),
  54646. (assign, ":recency_maximum", 0),
  54647. (try_end),
  54648. ##diplomacy end+
  54649.  
  54650. #THE FIRST BATCH OF DISQUALIFYING CONDITIONS DO NOT REQUIRE THE ATTACKING PARTY TO HAVE CURRENT INTELLIGENCE ON THE TARGET
  54651. (try_begin),
  54652. (neg|party_is_active, ":party_no"),
  54653.  
  54654. (assign, ":result", -1),
  54655. (assign, ":explainer_string", "str_center_party_not_active"),
  54656. #(assign, ":reason_is_obvious", 1),
  54657. (else_try),
  54658. (store_faction_of_party, ":potential_target_faction", ":potential_target"),
  54659. (store_relation, ":relation", ":potential_target_faction", ":faction_no"),
  54660. (ge, ":relation", 0),
  54661.  
  54662. (assign, ":result", -1),
  54663. (assign, ":explainer_string", "str_center_is_friendly"),
  54664. #(assign, ":reason_is_obvious", 1),
  54665. (else_try),
  54666. (is_between, ":potential_target", walled_centers_begin, walled_centers_end),
  54667. (assign, ":faction_of_besieger_party", -1),
  54668. (try_begin),
  54669. (neg|party_slot_eq, ":potential_target", slot_center_is_besieged_by, -1),
  54670. (party_get_slot, ":besieger_party", ":potential_target", slot_center_is_besieged_by),
  54671. (party_is_active, ":besieger_party"),
  54672. (store_faction_of_party, ":faction_of_besieger_party", ":besieger_party"),
  54673. (try_end),
  54674.  
  54675. (neq, ":faction_of_besieger_party", -1),
  54676. (neq, ":faction_of_besieger_party", ":faction_no"),
  54677.  
  54678. (assign, ":result", -1),
  54679. (assign, ":explainer_string", "str_center_is_already_besieged"),
  54680. #(assign, ":reason_is_obvious", 1),
  54681. (else_try),
  54682. (is_between, ":potential_target", villages_begin, villages_end),
  54683. (assign, ":village_is_looted_or_raided_already", 0),
  54684. (try_begin),
  54685. (party_slot_eq, ":potential_target", slot_village_state, svs_being_raided),
  54686. (party_get_slot, ":raider_party", ":potential_target", slot_village_raided_by),
  54687. (party_is_active, ":raider_party"),
  54688. (store_faction_of_party, ":raider_faction", ":raider_party"),
  54689. (neq, ":raider_faction", ":faction_no"),
  54690. (assign, ":raiding_by_one_other_faction", 1),
  54691. (else_try),
  54692. (assign, ":raiding_by_one_other_faction", 0),
  54693. (try_end),
  54694.  
  54695. (try_begin),
  54696. (this_or_next|party_slot_eq, ":potential_target", slot_village_state, svs_looted),
  54697. (eq, ":raiding_by_one_other_faction", 1),
  54698. (assign, ":village_is_looted_or_raided_already", 1),
  54699. (try_end),
  54700.  
  54701. (eq, ":village_is_looted_or_raided_already", 1),
  54702.  
  54703. (assign, ":result", -1),
  54704. (assign, ":explainer_string", "str_center_is_looted_or_raided_already"),
  54705. #(assign, ":reason_is_obvious", 1),
  54706. (else_try),
  54707. ##diplomacy start+ Add support for companion / lady personality types: does not want to attack innocents
  54708. (call_script, "script_dplmc_get_troop_morality_value", ":troop_no", tmt_humanitarian),
  54709. (this_or_next|gt, reg0, 0),
  54710. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_benefactor),
  54711. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_moralist),
  54712. #diplomacy end+
  54713. (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  54714. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  54715.  
  54716. (is_between, ":potential_target", villages_begin, villages_end),
  54717. (assign, ":result", -1),
  54718. (assign, ":explainer_string", "str_center_marshal_does_not_want_to_attack_innocents"),
  54719. (else_try),
  54720. (assign, ":distance_from_our_closest_walled_center", 1000),
  54721. (try_for_range, ":cur_center", walled_centers_begin, walled_centers_end),
  54722. (store_faction_of_party, ":cur_center_faction", ":cur_center"),
  54723. (eq, ":cur_center_faction", ":faction_no"),
  54724. (store_distance_to_party_from_party, ":distance_from_cur_center", ":cur_center", ":potential_target"),
  54725. (lt, ":distance_from_cur_center", ":distance_from_our_closest_walled_center"),
  54726. (assign, ":distance_from_our_closest_walled_center", ":distance_from_cur_center"),
  54727. (try_end),
  54728.  
  54729. (gt, ":distance_from_our_closest_walled_center", 75),
  54730. ##diplomacy start+ Add support for companion / lady personality types: cautious
  54731. ##OLD:
  54732. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  54733. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  54734. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  54735. #(troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  54736. ##NEW:
  54737. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  54738. (gt, reg0, 0),
  54739. ##Do not apply the check to recently-lost centers if AI changes are on.
  54740. (this_or_next|lt, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  54741. (this_or_next|neg|party_slot_eq,":potential_target", slot_center_ex_faction, ":faction_no"),
  54742. (this_or_next|lt, ":hours_since_capture", 0), #i.e. invalid
  54743. (ge, ":hours_since_capture", ":recency_maximum"),#hasn't been taken recently
  54744. ##diplomacy end+
  54745.  
  54746. (assign, ":result", -1),
  54747. (assign, ":explainer_string", "str_center_far_away_our_cautious_marshal_does_not_wish_to_reconnoiter"),
  54748. #RECONNOITERING BEGINS HERE - VALUE WILL BE TEN OR LESS
  54749. (else_try),
  54750. (gt, ":distance_from_our_closest_walled_center", 90),
  54751. ##diplomacy start+ Do not apply the check to recently-lost centers if AI changes are on.
  54752. (this_or_next|lt, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  54753. (this_or_next|neg|party_slot_eq,":potential_target", slot_center_ex_faction, ":faction_no"),
  54754. (this_or_next|lt, ":hours_since_capture", 0), #i.e. invalid
  54755. (ge, ":hours_since_capture", ":recency_maximum"),#hasn't been taken recently
  54756. ##diplomacy end+
  54757.  
  54758. (assign, ":result", -1),
  54759. (assign, ":explainer_string", "str_center_far_away_even_for_our_aggressive_marshal_to_reconnoiter"),
  54760. #(assign, ":reason_is_obvious", 1),
  54761. (else_try),
  54762. (is_between, ":potential_target", walled_centers_begin, walled_centers_end),
  54763. ##diplomacy start+ Add support for companion / lady personality types: aggessive
  54764. ##OLD:
  54765. #(neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_martial),
  54766. #(neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_quarrelsome),
  54767. #(neg|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_selfrighteous),
  54768. ##NEW:
  54769. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  54770. (lt, reg0, 0),
  54771. ##Do not apply the check to recently-lost centers if AI changes are on.
  54772. (this_or_next|lt, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_LOW),
  54773. (this_or_next|neg|party_slot_eq,":potential_target", slot_center_ex_faction, ":faction_no"),
  54774. (this_or_next|lt, ":hours_since_capture", 0), #i.e. invalid
  54775. (ge, ":hours_since_capture", ":recency_maximum"),#hasn't been taken recently
  54776. ##diplomacy end+
  54777.  
  54778. (assign, ":close_center_found", 0),
  54779. (try_for_range, ":friendly_walled_center", walled_centers_begin, walled_centers_end),
  54780. (eq, ":close_center_found", 0),
  54781. (store_faction_of_party, ":friendly_walled_center_faction", ":friendly_walled_center"),
  54782. (eq, ":friendly_walled_center_faction", ":faction_no"),
  54783. (store_distance_to_party_from_party, ":distance_from_walled_center", ":potential_target", ":friendly_walled_center"),
  54784. (lt, ":distance_from_walled_center", 60),
  54785. (assign, ":close_center_found", 1),
  54786. (try_end),
  54787. (eq, ":close_center_found", 0),
  54788.  
  54789. (assign, ":result", -1),
  54790. (assign, ":explainer_string", "str_center_is_indefensible"),
  54791. #(else_try),
  54792. #For now it is removed as Armagan's decision, we can add this option in later patchs. I and Armagan accept it has good potential. But this system needs also
  54793. #scouting quests and scouting AI added together. If we only add this then we limit AI very much, it can attack only very few of centers, this damages
  54794. #variability of game and surprise attacks of AI. Player can predict where AI will attack and he can full garnisons of only this center.
  54795. #We can add asking travellers about how good defended center X by paying 100 denars for example to equalize situations of AI and human player.
  54796. #But these needs much work and detailed AI tests so Armagan decided to skip this for now.
  54797.  
  54798. #(store_sub, ":faction_recce_slot", ":faction_no", kingdoms_begin),
  54799. #(val_add, ":faction_recce_slot", slot_center_last_reconnoitered_by_faction_time),
  54800. #(party_get_slot, ":last_recce_time", ":potential_target", ":faction_recce_slot"),
  54801. #(store_current_hours, ":hours_since_last_recce"),
  54802. #(val_sub, ":hours_since_last_recce", ":last_recce_time"),
  54803.  
  54804. #(this_or_next|eq, ":last_recce_time", 0),
  54805. #(gt, ":hours_since_last_recce", 96), #Information is presumed to be accurate for four days
  54806.  
  54807. #(store_sub, ":150_minus_distance_div_by_10", 150, ":distance_from_party"),
  54808. #(val_div, ":150_minus_distance_div_by_10", 10),
  54809.  
  54810. #(assign, ":result", ":150_minus_distance_div_by_10"),
  54811. #(assign, ":explainer_string", "str_center_has_not_been_scouted"),
  54812. #DECISIONS BASED ON ENEMY STRENGTH BEGIN HERE
  54813. (else_try),
  54814. (party_get_slot, ":party_strength", ":party_no", slot_party_cached_strength),
  54815. (party_get_slot, ":follower_strength", ":party_no", slot_party_follower_strength),
  54816. (party_get_slot, ":strength_of_nearby_friend", ":party_no", slot_party_nearby_friend_strength),
  54817.  
  54818. (store_add, ":total_strength", ":party_strength", ":follower_strength"),
  54819. (val_add, ":total_strength", ":strength_of_nearby_friend"),
  54820.  
  54821. #(party_get_slot, ":potential_target_nearby_enemy_exact_strength", ":potential_target", slot_party_nearby_friend_strength),
  54822. #(assign, ":potential_target_nearby_enemy_strength", ":potential_target_nearby_enemy_exact_strength"),
  54823. (try_begin),
  54824. (is_between, ":potential_target", villages_begin, villages_end),
  54825. (assign, ":enemy_strength", 10),
  54826. (else_try),
  54827. (party_get_slot, ":enemy_strength", ":potential_target", slot_party_cached_strength),
  54828. (party_get_slot, ":enemy_strength_nearby", ":potential_target", slot_party_nearby_friend_strength),
  54829. (val_add, ":enemy_strength", ":enemy_strength_nearby"),
  54830. (try_end),
  54831. (val_max, ":enemy_strength", 1),
  54832. ##diplomacy start+ Add support for lady/companion personalities: aggressive
  54833. ##OLD:
  54834. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_martial),
  54835. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_quarrelsome),
  54836. #(troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_selfrighteous),
  54837. ##NEW:
  54838. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  54839. (lt, reg0, 0),
  54840. ###xxx yyy zzz TODO: The logic here seems backwards!
  54841. ###Later look at this and verify that it's what we want.
  54842. ##diplomacy end+
  54843.  
  54844. (store_mul, ":power_ratio", ":total_strength", 100),
  54845. (val_div, ":power_ratio", ":enemy_strength"),
  54846. (lt, ":power_ratio", 150),
  54847.  
  54848. (assign, ":result", -1),
  54849. (assign, ":explainer_string", "str_center_protected_by_enemy_army_aggressive"),
  54850. (else_try),
  54851. (ge, ":enemy_strength", ":total_strength"), #if enemy is powerful
  54852.  
  54853. (assign, ":result", -1),
  54854. (assign, ":explainer_string", "str_center_protected_by_enemy_army_cautious"),
  54855. (else_try),
  54856. (store_mul, ":power_ratio", ":total_strength", 100),
  54857. (val_div, ":power_ratio", ":enemy_strength"),
  54858. (lt, ":power_ratio", 185),
  54859. ##diplomacy start+ Add support for companion/lady personalities: cautious
  54860. ##OLD:
  54861. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  54862. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  54863. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  54864. #(troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  54865. ##NEW:
  54866. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  54867. (gt, reg0, 0),
  54868. ##diplomacy end+
  54869.  
  54870. #equations here
  54871. (assign, ":result", -1),
  54872. (assign, ":explainer_string", "str_center_cautious_marshal_believes_center_too_difficult_to_capture"),
  54873. (else_try),
  54874. (lt, ":power_ratio", 140), #it was 140
  54875.  
  54876. (assign, ":result", -1),
  54877. (assign, ":explainer_string", "str_center_even_aggressive_marshal_believes_center_too_difficult_to_capture"),
  54878. #To Steve - I moved below two if statement here from upper places, to enable in answering different different answers even
  54879. #if we are close to an unlooted enemy village. For example now it can say "center X" is too far too while our army is
  54880. #looting a village because of its closeness.
  54881. (else_try),
  54882. #if the party has already started the siege
  54883. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_raiding_village),
  54884. (faction_get_slot, ":current_object", ":faction_no", slot_faction_ai_object),
  54885. (is_between, ":current_object", villages_begin, villages_end),
  54886. (neq, ":potential_target", ":current_object"),
  54887. (party_slot_eq, ":current_object", slot_village_state, svs_under_siege),
  54888.  
  54889. (store_current_hours, ":hours_since_siege_began"),
  54890. (party_get_slot, ":hour_that_siege_began", ":current_object", slot_center_siege_begin_hours),
  54891. (val_sub, ":hours_since_siege_began", ":hour_that_siege_began"),
  54892. (gt, ":hours_since_siege_began", 4),
  54893.  
  54894. (call_script, "script_npc_decision_checklist_evaluate_enemy_center_for_attack", ":troop_no", ":current_object", ":attack_by_faction", 0),
  54895. (gt, reg0, -1),
  54896.  
  54897. (assign, ":result", -1),
  54898. (assign, ":explainer_string", "str_center_we_have_already_committed_too_much_time_to_our_present_siege_to_move_elsewhere"),
  54899. (else_try),
  54900. #If the party is close to an unlooted village
  54901. (faction_slot_eq, ":faction_no", slot_faction_ai_state, sfai_raiding_village),
  54902. (faction_get_slot, ":current_object", ":faction_no", slot_faction_ai_object),
  54903. (neq, ":potential_target", ":current_object"),
  54904. (is_between, ":current_object", villages_begin, villages_end),
  54905. (store_distance_to_party_from_party, ":distance_to_cur_object", ":party_no", ":current_object"),
  54906. (lt, ":distance_to_cur_object", 10),
  54907.  
  54908. (call_script, "script_npc_decision_checklist_evaluate_enemy_center_for_attack", ":troop_no", ":current_object", ":attack_by_faction", 0),
  54909. (gt, reg0, -1),
  54910.  
  54911. (assign, "$g_use_current_ai_object_as_s8", 1),
  54912.  
  54913. (assign, ":result", -1),
  54914. (assign, ":explainer_string", "str_center_we_are_already_here_we_should_at_least_loot_the_village"),
  54915. #DECISION TO ATTACK IS HERE
  54916. #(else_try),
  54917. #To Steve - I removed below lines, as here decided. We will use pre-function to evaluate assailability scores for centers rather than below lines to make AI
  54918. #selecting better targets. If you want to make some marshals to select not-best options I can add that option into script_calculate_center_assailability_score,
  54919. #for that we can need seed values for each center and for each lord, so we can add these seed values to create variability, clever marshals have seeds with less
  54920. #standard deviation and less values and less-clever marshals have bigger seeds. Then probability of some lords to disagree marshal increases because their seed
  54921. #values will be different from marshal's. If Steve wants it from me to implement I can add this.
  54922.  
  54923. #(try_begin),
  54924. # (is_between, ":potential_target", villages_begin, villages_end),
  54925. # (party_get_slot, ":score", ":potential_target", slot_town_prosperity),
  54926. # (val_add, ":score", 50), #average 100
  54927. #(else_try),
  54928. # (is_between, ":potential_target", castles_begin, castles_end),
  54929. # (assign, ":score", ":power_ratio"), #ie, at least 140
  54930. #(else_try),
  54931. # (party_get_slot, ":score", ":potential_target", slot_town_prosperity),
  54932. # (val_add, ":score", 75),
  54933. # (val_mul, ":score", ":power_ratio"),
  54934. # (val_div, ":score", 100), #ie, at least about 200
  54935. #(try_end),
  54936. #
  54937. #(val_sub, ":score", ":distance_from_party"),
  54938. #(lt, ":score", -1),
  54939.  
  54940. #(assign, ":result", -1),
  54941. #(assign, ":explainer_string", "str_center_value_outweighed_by_difficulty_of_capture"),
  54942. (else_try),
  54943. (try_begin),
  54944. (eq, "$cheat_mode", 1),
  54945. (eq, ":faction_no", "fac_kingdom_3"),
  54946. (store_faction_of_party, ":potential_target_faction", ":potential_target"),
  54947. (store_relation, ":relation", ":potential_target_faction", ":faction_no"),
  54948. (lt, ":relation", 0),
  54949. (try_end),
  54950.  
  54951. (call_script, "script_calculate_center_assailability_score", ":troop_no", ":potential_target", ":all_vassals_included"),
  54952. (assign, ":score", reg0),
  54953. (assign, ":power_ratio", reg1),
  54954. #(assign, ":distance_score", reg2),
  54955.  
  54956. (assign, ":result", ":score"),
  54957.  
  54958. (try_begin),
  54959. (le, ":power_ratio", 100),
  54960. (try_begin),
  54961. ##diplomacy start+ Add support for companion / lady personalities: cautious
  54962. ##OLD:
  54963. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  54964. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  54965. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  54966. #(troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  54967. ##NEW:
  54968. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  54969. (gt, reg0, 0),
  54970. ##diplomacy end+
  54971. (assign, ":explainer_string", "str_center_cautious_marshal_believes_center_too_difficult_to_capture"),
  54972. (else_try),
  54973. (assign, ":explainer_string", "str_center_even_aggressive_marshal_believes_center_too_difficult_to_capture"),
  54974. (try_end),
  54975. (else_try),
  54976. (le, ":power_ratio", 150),
  54977.  
  54978. (try_begin),
  54979. ##diplomacy start+ Add support for companion / lady personalities: cautious
  54980. ##OLD
  54981. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  54982. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  54983. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  54984. #(troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  54985. ##NEW:
  54986. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  54987. (lt, reg0, 0),
  54988. ##diplomacy end+
  54989. (assign, ":explainer_string", "str_center_protected_by_enemy_army_cautious"),
  54990. (else_try),
  54991. (assign, ":explainer_string", "str_center_protected_by_enemy_army_aggressive"),
  54992. (try_end),
  54993. (else_try),
  54994. (try_begin),
  54995. (le, ":score", "$g_faction_object_score"),
  54996. (assign, ":explainer_string", "str_center_value_outweighed_by_difficulty_of_capture"),
  54997. (else_try),
  54998. #To Steve, does not this sentence needs to explain why we are not attacking that city?
  54999. #This sentence says it justifies, so why we are not attacking?
  55000. (assign, ":explainer_string", "str_center_value_justifies_the_difficulty_of_capture"),
  55001. (try_end),
  55002. (try_end),
  55003. (try_end),
  55004.  
  55005. (assign, reg0, ":result"),
  55006. (assign, reg1, ":explainer_string"),
  55007. (assign, reg2, ":power_ratio"),
  55008. ]),
  55009.  
  55010. (
  55011. "npc_decision_checklist_faction_ai_alt", #This is called from within decide_faction_ai, or from
  55012. [
  55013. (store_script_param, ":troop_no", 1),
  55014.  
  55015. (store_faction_of_troop, ":faction_no", ":troop_no"),
  55016.  
  55017. (str_store_troop_name, s4, ":troop_no"),
  55018. (str_store_faction_name, s33, ":faction_no"),
  55019. (try_begin),
  55020. (eq, "$cheat_mode", 1),
  55021. (display_message, "@{!}DEBUG -- {s4} produces a faction strategy for {s33}"),
  55022. (try_end),
  55023.  
  55024. #INFORMATIONS COLLECTING STEP 0: Here we obtain general information about current faction like how much parties that faction has, which lord is the marshall, current ai state and current ai target object
  55025. #(faction_get_slot, ":faction_strength", ":faction_no", slot_faction_number_of_parties),
  55026. (faction_get_slot, ":faction_marshal", ":faction_no", slot_faction_marshall),
  55027. (faction_get_slot, ":current_ai_state", ":faction_no", slot_faction_ai_state),
  55028. (faction_get_slot, ":current_ai_object", ":faction_no", slot_faction_ai_object),
  55029.  
  55030. (assign, ":marshal_party", -1),
  55031. (assign, ":marshal_party_strength", 0),
  55032.  
  55033. (try_begin),
  55034. (gt, ":faction_marshal", 0),
  55035. (troop_get_slot, ":marshal_party", ":faction_marshal", slot_troop_leaded_party),
  55036. (party_is_active, ":marshal_party"),
  55037. (party_get_slot, ":marshal_party_itself_strength", ":marshal_party", slot_party_cached_strength),
  55038. (party_get_slot, ":marshal_party_follower_strength", ":marshal_party", slot_party_follower_strength),
  55039. (store_add, ":marshal_party_strength", ":marshal_party_itself_strength", ":marshal_party_follower_strength"),
  55040. (try_end),
  55041.  
  55042. #INFORMATIONS COLLECTING STEP 1: Here we are learning how much hours past from last offensive situation/feast concluded/current state started
  55043. (store_current_hours, ":hours_since_last_offensive"),
  55044. (faction_get_slot, ":last_offensive_time", ":faction_no", slot_faction_last_offensive_concluded),
  55045. (val_sub, ":hours_since_last_offensive", ":last_offensive_time"),
  55046.  
  55047. (store_current_hours, ":hours_since_last_feast_start"),
  55048. (faction_get_slot, ":last_feast_time", ":faction_no", slot_faction_last_feast_start_time),
  55049. (val_sub, ":hours_since_last_feast_start", ":last_feast_time"),
  55050.  
  55051. (store_current_hours, ":hours_at_current_state"),
  55052. (faction_get_slot, ":current_state_started", ":faction_no", slot_faction_ai_current_state_started),
  55053. (val_sub, ":hours_at_current_state", ":current_state_started"),
  55054.  
  55055. (store_current_hours, ":hours_since_last_faction_rest"),
  55056. (faction_get_slot, ":last_rest_time", ":faction_no", slot_faction_ai_last_rest_time),
  55057. (val_sub, ":hours_since_last_faction_rest", ":last_rest_time"),
  55058.  
  55059. (try_begin), #calculating ":last_offensive_time_score", this will be used in #11 and #12
  55060. (ge, ":hours_since_last_offensive", 1080), #more than 45 days (100p)
  55061. (assign, ":last_offensive_time_score", 100),
  55062. (else_try),
  55063. (ge, ":hours_since_last_offensive", 480), #more than 20 days (65p..99p)
  55064. (store_sub, ":last_offensive_time_score", ":hours_since_last_offensive", 480),
  55065. (val_div, ":last_offensive_time_score", 20),
  55066. (val_add, ":last_offensive_time_score", 64),
  55067. (else_try),
  55068. (ge, ":hours_since_last_offensive", 240), #more than 10 days (41p..64p)
  55069. (store_sub, ":last_offensive_time_score", ":hours_since_last_offensive", 240),
  55070. (val_div, ":last_offensive_time_score", 10),
  55071. (val_add, ":last_offensive_time_score", 40),
  55072. (else_try), #less than 10 days (0p..40p)
  55073. (store_div, ":last_offensive_time_score", ":hours_since_last_offensive", 6), #0..40
  55074. (try_end),
  55075.  
  55076. #INFORMATION COLLECTING STEP 3: Here we are finding the most threatened center
  55077. (call_script, "script_find_center_to_defend", ":troop_no"),
  55078. (assign, ":most_threatened_center", reg0),
  55079. (assign, ":threat_danger_level", reg1),
  55080. (assign, ":enemy_strength_near_most_threatened_center", reg2), #NOTE! This will be off by as much as 50%
  55081.  
  55082. #INFORMATION COLLECTING STEP 4: Here we are finding number of vassals who are already following the marshal, and the assigned vassal ratio of current faction.
  55083. (assign, ":vassals_already_assembled", 0),
  55084. (assign, ":total_vassals", 0),
  55085. ##diplomacy start+ add support for promoted kingdom ladies
  55086. #(try_for_range, ":lord", active_npcs_begin, active_npcs_end),
  55087. (try_for_range, ":lord", heroes_begin, heroes_end),
  55088. (this_or_next|is_between, ":lord", active_npcs_begin, active_npcs_end),
  55089. (troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  55090. ##diplomacy end+
  55091. (store_faction_of_troop, ":lord_faction", ":lord"),
  55092. (eq, ":lord_faction", ":faction_no"),
  55093. (troop_get_slot, ":led_party", ":lord", slot_troop_leaded_party),
  55094. (party_is_active, ":led_party"),
  55095. (val_add, ":total_vassals", 1),
  55096.  
  55097. (party_slot_eq, ":led_party", slot_party_ai_state, spai_accompanying_army),
  55098. (party_slot_eq, ":led_party", slot_party_ai_object, ":marshal_party"),
  55099.  
  55100. (party_is_active, ":marshal_party"),
  55101. (store_distance_to_party_from_party, ":distance_to_marshal", ":led_party", ":marshal_party"),
  55102. (lt, ":distance_to_marshal", 15),
  55103. (val_add, ":vassals_already_assembled", 1),
  55104. (try_end),
  55105. (assign, ":ratio_of_vassals_assembled", -1),
  55106. (try_begin),
  55107. (gt, ":total_vassals", 0),
  55108. (store_mul, ":ratio_of_vassals_assembled", ":vassals_already_assembled", 100),
  55109. (val_div, ":ratio_of_vassals_assembled", ":total_vassals"),
  55110. (try_end),
  55111.  
  55112. #50% of vassals means that the campaign hour limit is ten days
  55113. (store_mul, ":campaign_hour_limit", ":ratio_of_vassals_assembled", 3),
  55114. (val_add, ":campaign_hour_limit", 90),
  55115.  
  55116. #To Steve - I understand your concern about some marshals will gather army and some will not be able to find any valueable center to attack after gathering,
  55117. #and these marshals will be questioned by other marshals ext. This is ok but if we search for a target without adding all other vassals what if
  55118. #AI cannot find any target for long time because of its low power ratio if enemy cities are equal defended? Do not forget if we do not count other vassals in
  55119. #faction while making target search we can only add marshal army's power and vassals around him. And if there is any threat in our centers even it is smaller,
  55120. #its threat_danger_level will be more than target_value_level if marshal new started gathering for ofensive. Because we only assume marshal and around vassals
  55121. #will join attack. And in our scenarios currently there are less vassals are around him. So power ratio will be low and any small threat will be enought to stop
  55122. #an offensive. Then when players finds out this they periodically will take under siege to enemy's any center and they will be saved from any kind of newly started
  55123. #offensive they will be faced. So we have to calculate both attack levels and select highest one to compare with threat level. Please do not change this part.
  55124.  
  55125. (try_begin),
  55126. (ge, ":faction_marshal", 0),
  55127. (ge, ":marshal_party", 0),
  55128. (party_is_active, ":marshal_party"),
  55129.  
  55130. (call_script, "script_party_count_fit_for_battle", ":marshal_party"),
  55131. (assign, ":number_of_fit_soldiers_in_marshal_party", reg0),
  55132. (ge, ":number_of_fit_soldiers_in_marshal_party", 40),
  55133.  
  55134. (call_script, "script_find_center_to_attack_alt", ":troop_no", 1, 0),
  55135. (assign, ":center_to_attack_all_vassals_included", reg0),
  55136. (assign, ":target_value_level_all_vassals_included", reg1),
  55137.  
  55138. (call_script, "script_find_center_to_attack_alt", ":troop_no", 1, 1),
  55139. (assign, ":center_to_attack_only_marshal_and_followers", reg0),
  55140. (assign, ":target_value_level_only_marshal_and_followers", reg1),
  55141. (else_try),
  55142. (assign, ":target_value_level_all_vassals_included", 0),
  55143. (assign, ":target_value_level_only_marshal_and_followers", 0),
  55144. (assign, ":center_to_attack_all_vassals_included", -1),
  55145. (assign, ":center_to_attack_only_marshal_and_followers", -1),
  55146. (try_end),
  55147.  
  55148. (try_begin),
  55149. (ge, ":target_value_level_all_vassals_included", ":center_to_attack_only_marshal_and_followers"),
  55150. (assign, ":center_to_attack", ":center_to_attack_all_vassals_included"),
  55151. (assign, ":target_value_level", ":target_value_level_all_vassals_included"),
  55152. (else_try),
  55153. (assign, ":center_to_attack", ":center_to_attack_only_marshal_and_followers"),
  55154. (assign, ":target_value_level", ":target_value_level_only_marshal_and_followers"),
  55155. (try_end),
  55156.  
  55157. (try_begin),
  55158. (eq, ":current_ai_state", sfai_attacking_center),
  55159. (val_mul, ":target_value_level", 3),
  55160. (val_div, ":target_value_level", 2),
  55161. (try_end),
  55162.  
  55163. (try_begin),
  55164. (eq, "$cheat_mode", 1),
  55165. (try_begin),
  55166. (is_between, ":center_to_attack", centers_begin, centers_end),
  55167. (str_store_party_name, s4, ":center_to_attack"),
  55168. (display_message, "@{!}Best offensive target {s4} has value level of {reg1}"),
  55169. (else_try),
  55170. (display_message, "@{!}No center found to attack"),
  55171. (try_end),
  55172.  
  55173. (try_begin),
  55174. (is_between, ":most_threatened_center", centers_begin, centers_end),
  55175. (str_store_party_name, s4, ":most_threatened_center"),
  55176. (assign, reg1, ":threat_danger_level"),
  55177. (display_message, "@{!}Best threat of {s4} has value level of {reg1}"),
  55178. (else_try),
  55179. (display_message, "@{!}No center found to defend"),
  55180. (try_end),
  55181. (try_end),
  55182.  
  55183. (try_begin),
  55184. (eq, "$cheat_mode", 1),
  55185.  
  55186. (try_begin),
  55187. (is_between, ":most_threatened_center", centers_begin, centers_end),
  55188. (str_store_party_name, s4, ":most_threatened_center"),
  55189. (assign, reg1, ":threat_danger_level"),
  55190. (display_message, "@Best threat of {s4} has value level of {reg1}"),
  55191. (else_try),
  55192. (display_message, "@No center found to defend"),
  55193. (try_end),
  55194. (try_end),
  55195.  
  55196. (assign, "$g_target_after_gathering", -1),
  55197.  
  55198. (store_current_hours, ":hours"),
  55199. (try_begin),
  55200. (ge, ":target_value_level", ":threat_danger_level"),
  55201. (faction_set_slot, ":faction_no", slot_faction_last_safe_hours, ":hours"),
  55202. (try_end),
  55203. (faction_get_slot, ":last_safe_hours", ":faction_no", slot_faction_last_safe_hours),
  55204. (try_begin),
  55205. (eq, ":last_safe_hours", 0),
  55206. (faction_set_slot, ":faction_no", slot_faction_last_safe_hours, ":hours"),
  55207. (try_end),
  55208. (faction_get_slot, ":last_safe_hours", ":faction_no", slot_faction_last_safe_hours),
  55209. (store_sub, ":hours_since_days_defensive_started", ":hours", ":last_safe_hours"),
  55210. (str_store_faction_name, s7, ":faction_no"),
  55211.  
  55212. (assign, ":at_peace_with_everyone", 1),
  55213. (try_for_range, ":faction_at_war", kingdoms_begin, kingdoms_end),
  55214. (store_relation, ":relation", ":faction_no", ":faction_at_war"),
  55215. (lt, ":relation", 0),
  55216. (assign, ":at_peace_with_everyone", 0),
  55217. (try_end),
  55218.  
  55219.  
  55220. #INFORMATIONS ARE COLLECTED, NOW CHECK ALL POSSIBLE ACTIONS AND DECIDE WHAT TO DO NEXT
  55221. #Player marshal
  55222. (try_begin), # a special case to end long-running feasts
  55223. (eq, ":troop_no", "trp_player"),
  55224.  
  55225. (eq, ":current_ai_state", sfai_feast),
  55226. (ge, ":hours_at_current_state", 72),
  55227.  
  55228. (assign, ":action", sfai_default),
  55229. (assign, ":object", -1),
  55230.  
  55231. #Normally you are not supposed to set permanent values in this state, but this is a special case to end player-called feasts
  55232. (assign, "$player_marshal_ai_state", sfai_default),
  55233. (assign, "$player_marshal_ai_object", -1),
  55234. (else_try), #another special state, to make player-called feasts last for a while when the player is the leader of the faction, but not the marshal
  55235. (eq, "$players_kingdom", "fac_player_supporters_faction"),
  55236. (faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  55237. (neq, ":troop_no", "trp_player"),
  55238.  
  55239. (eq, ":current_ai_state", sfai_feast),
  55240. (le, ":hours_at_current_state", 48),
  55241.  
  55242. (party_slot_eq, ":current_ai_object", slot_town_lord, "trp_player"),
  55243. (store_faction_of_party, ":current_ai_object_faction", ":current_ai_object"),
  55244. (eq, ":current_ai_object_faction", "$players_kingdom"),
  55245.  
  55246. (assign, ":action", sfai_feast),
  55247. (assign, ":object", ":current_ai_object"),
  55248.  
  55249.  
  55250. (else_try), #this is the main player marshal state
  55251. (eq, ":troop_no", "trp_player"),
  55252.  
  55253. (str_clear, s14),
  55254. (assign, ":action", "$player_marshal_ai_state"),
  55255. (assign, ":object", "$player_marshal_ai_object"),
  55256.  
  55257. #1-RESTING IF NEEDED
  55258. #If not currently attacking a besieging a center and vassals did not rest for long time, let them rest.
  55259. #If we do not take this part to toppest level, tired vassals already did not accept any order, so that
  55260. #faction cannot do anything already. So first let vassals rest if they need. Thats why it should be toppest.
  55261. (else_try),
  55262. (neq, ":current_ai_state", sfai_default),
  55263. (neq, ":current_ai_state", sfai_feast),
  55264. (party_is_active, ":marshal_party"),
  55265.  
  55266. (party_slot_eq, ":marshal_party", slot_party_ai_state, spai_retreating_to_center),
  55267.  
  55268. (assign, ":action", sfai_default),
  55269. (assign, ":object", -1),
  55270. (str_store_string, s14, "str_the_enemy_temporarily_has_the_field"),
  55271.  
  55272. (else_try),
  55273. (neq, ":current_ai_state", sfai_feast),
  55274.  
  55275. (assign, ":currently_besieging", 0),
  55276. (try_begin),
  55277. (eq, ":current_ai_state", sfai_attacking_center),
  55278. (is_between, ":current_ai_object", walled_centers_begin, walled_centers_end),
  55279. (party_get_slot, ":besieger_party", ":current_ai_object", slot_center_is_besieged_by),
  55280. (party_is_active, ":besieger_party"),
  55281. (store_faction_of_party, ":besieger_faction", ":besieger_party"),
  55282. (eq, ":besieger_faction", ":faction_no"),
  55283. (assign, ":currently_besieging", 1),
  55284. (try_end),
  55285.  
  55286. (assign, ":currently_defending_center", 0),
  55287. (try_begin),
  55288. (eq, ":current_ai_state", sfai_attacking_enemies_around_center),
  55289. (gt, ":marshal_party", 0),
  55290. (party_is_active, ":marshal_party"),
  55291.  
  55292. (assign, ":besieged_center", -1),
  55293. (try_begin),
  55294. (party_slot_eq, ":marshal_party", slot_party_ai_state, spai_holding_center), #if commander is holding a center
  55295. (party_get_slot, ":marshal_object", ":marshal_party", slot_party_ai_object), #get commander's ai object (center they are holding)
  55296. (party_get_battle_opponent, ":besieger_enemy", ":marshal_object"), #get this object's battle opponent
  55297. (ge, ":besieger_enemy", 0),
  55298. (assign, ":besieged_center", ":marshal_object"),
  55299. (else_try),
  55300. (party_slot_eq, ":marshal_party", slot_party_ai_state, spai_engaging_army), #if commander is engaging an army
  55301. (party_get_slot, ":marshal_object", ":marshal_party", slot_party_ai_object), #get commander's ai object (army which they engaded)
  55302. (ge, ":marshal_object", 0), #if commander has an object
  55303. (neg|is_between, ":marshal_object", centers_begin, centers_end), #if this object is not a center, so it is a party
  55304. (party_is_active, ":marshal_object"),
  55305. (party_get_battle_opponent, ":besieged_center", ":marshal_object"), #get this object's battle opponent
  55306. (try_end),
  55307.  
  55308. (eq, ":besieged_center", ":current_ai_object"),
  55309. (assign, ":currently_defending_center", 1),
  55310. (try_end),
  55311.  
  55312. (eq, ":currently_besieging", 0),
  55313. (eq, ":currently_defending_center", 0),
  55314. (ge, ":hours_since_last_faction_rest", 1240),
  55315.  
  55316. (assign, ":action", sfai_default),
  55317. (assign, ":object", -1),
  55318. (str_store_string, s14, "str_the_vassals_are_tired_we_let_them_rest_for_some_time"),
  55319.  
  55320. #2-DEFENSIVE ACTIONS : GATHERING ARMY FOR DEFENDING
  55321. (else_try),
  55322. (party_is_active, ":marshal_party"),
  55323. (eq, ":at_peace_with_everyone", 0),
  55324.  
  55325. (is_between, ":most_threatened_center", centers_begin, centers_end),
  55326. (this_or_next|eq, ":current_ai_state", sfai_default), #MOTO not going to attack anyway
  55327. (this_or_next|eq, ":current_ai_state", sfai_feast), #MOTO not going to attack anyway (THIS is the emergency to stop feast)
  55328. (gt, ":threat_danger_level", ":target_value_level"),
  55329.  
  55330. (assign, ":continue_gathering", 0),
  55331. (assign, ":start_gathering", 0),
  55332.  
  55333. (try_begin),
  55334. (is_between, ":most_threatened_center", villages_begin, villages_end),
  55335.  
  55336. (assign, ":continue_gathering", 0),
  55337. (else_try),
  55338. (try_begin),
  55339. (lt, ":hours_since_days_defensive_started", 3),
  55340. (assign, ":multiplier", 150),
  55341. (else_try),
  55342. (lt, ":hours_since_days_defensive_started", 6),
  55343. (assign, ":multiplier", 140),
  55344. (else_try),
  55345. (lt, ":hours_since_days_defensive_started", 9),
  55346. (assign, ":multiplier", 132),
  55347. (else_try),
  55348. (lt, ":hours_since_days_defensive_started", 12),
  55349. (assign, ":multiplier", 124),
  55350. (else_try),
  55351. (lt, ":hours_since_days_defensive_started", 15),
  55352. (assign, ":multiplier", 118),
  55353. (else_try),
  55354. (lt, ":hours_since_days_defensive_started", 18),
  55355. (assign, ":multiplier", 114),
  55356. (else_try),
  55357. (lt, ":hours_since_days_defensive_started", 21),
  55358. (assign, ":multiplier", 110),
  55359. (else_try),
  55360. (lt, ":hours_since_days_defensive_started", 24),
  55361. (assign, ":multiplier", 106),
  55362. (else_try),
  55363. (lt, ":hours_since_days_defensive_started", 27),
  55364. (assign, ":multiplier", 102),
  55365. (else_try),
  55366. (lt, ":hours_since_days_defensive_started", 31),
  55367. (assign, ":multiplier", 98),
  55368. (else_try),
  55369. (lt, ":hours_since_days_defensive_started", 34),
  55370. (assign, ":multiplier", 94),
  55371. (else_try),
  55372. (lt, ":hours_since_days_defensive_started", 37),
  55373. (assign, ":multiplier", 90),
  55374. (else_try),
  55375. (lt, ":hours_since_days_defensive_started", 40),
  55376. (assign, ":multiplier", 86),
  55377. (else_try),
  55378. (lt, ":hours_since_days_defensive_started", 43),
  55379. (assign, ":multiplier", 82),
  55380. (else_try),
  55381. (lt, ":hours_since_days_defensive_started", 46),
  55382. (assign, ":multiplier", 79),
  55383. (else_try),
  55384. (lt, ":hours_since_days_defensive_started", 49),
  55385. (assign, ":multiplier", 76),
  55386. (else_try),
  55387. (lt, ":hours_since_days_defensive_started", 52),
  55388. (assign, ":multiplier", 73),
  55389. (else_try),
  55390. (lt, ":hours_since_days_defensive_started", 56),
  55391. (assign, ":multiplier", 70),
  55392. (else_try),
  55393. (lt, ":hours_since_days_defensive_started", 60),
  55394. (assign, ":multiplier", 68),
  55395. (else_try),
  55396. (lt, ":hours_since_days_defensive_started", 66),
  55397. (assign, ":multiplier", 66),
  55398. (else_try),
  55399. (lt, ":hours_since_days_defensive_started", 72),
  55400. (assign, ":multiplier", 64),
  55401. (else_try),
  55402. (lt, ":hours_since_days_defensive_started", 80),
  55403. (assign, ":multiplier", 62),
  55404. (else_try),
  55405. (lt, ":hours_since_days_defensive_started", 90),
  55406. (assign, ":multiplier", 60),
  55407. (else_try),
  55408. (lt, ":hours_since_days_defensive_started", 100),
  55409. (assign, ":multiplier", 58),
  55410. (else_try),
  55411. (assign, ":multiplier", 56),
  55412. (try_end),
  55413.  
  55414. (store_mul, ":enemy_strength_multiplied", ":enemy_strength_near_most_threatened_center", ":multiplier"),
  55415. (val_div, ":enemy_strength_multiplied", 100),
  55416.  
  55417. (try_begin),
  55418. (lt, ":marshal_party_strength", ":enemy_strength_multiplied"),
  55419. (assign, ":continue_gathering", 1),
  55420. (try_end),
  55421. (else_try),
  55422. (eq, ":current_ai_state", sfai_attacking_enemies_around_center),
  55423. (neq, ":most_threatened_center", ":current_ai_object"),
  55424.  
  55425. (assign, ":marshal_is_already_defending_a_center", 0),
  55426. (try_begin),
  55427. (gt, ":marshal_party", 0),
  55428. (party_is_active, ":marshal_party"),
  55429.  
  55430. (assign, ":besieged_center", -1),
  55431. (try_begin),
  55432. (party_slot_eq, ":marshal_party", slot_party_ai_state, spai_holding_center), #if commander is holding a center
  55433. (party_get_slot, ":marshal_object", ":marshal_party", slot_party_ai_object), #get commander's ai object (center they are holding)
  55434. (party_get_battle_opponent, ":besieger_enemy", ":marshal_object"), #get this object's battle opponent
  55435. (ge, ":besieger_enemy", 0),
  55436. (assign, ":besieged_center", ":marshal_object"),
  55437. (else_try),
  55438. (party_slot_eq, ":marshal_party", slot_party_ai_state, spai_engaging_army), #if commander is engaging an army
  55439. (party_get_slot, ":marshal_object", ":marshal_party", slot_party_ai_object), #get commander's ai object (army which they engaded)
  55440. (ge, ":marshal_object", 0), #if commander has an object
  55441. (neg|is_between, ":marshal_object", centers_begin, centers_end), #if this object is not a center, so it is a party
  55442. (party_is_active, ":marshal_object"),
  55443. (party_get_battle_opponent, ":besieged_center", ":marshal_object"), #get this object's battle opponent
  55444. (try_end),
  55445.  
  55446. (eq, ":besieged_center", ":current_ai_object"),
  55447.  
  55448. (assign, ":marshal_is_already_defending_a_center", 1),
  55449. (try_end),
  55450.  
  55451. (eq, ":marshal_is_already_defending_a_center", 0),
  55452.  
  55453. (store_mul, ":enemy_strength_multiplied", ":enemy_strength_near_most_threatened_center", 80),
  55454. (val_div, ":enemy_strength_multiplied", 100),
  55455. (lt, ":marshal_party_strength", ":enemy_strength_multiplied"),
  55456.  
  55457. (this_or_next|is_between, ":most_threatened_center", walled_centers_begin, walled_centers_end),
  55458. (neq, ":faction_no", "$players_kingdom"),
  55459.  
  55460. (assign, ":start_gathering", 1),
  55461. (try_end),
  55462.  
  55463. (this_or_next|eq, ":continue_gathering", 1),
  55464. (eq, ":start_gathering", 1),
  55465.  
  55466. (assign, ":action", sfai_gathering_army),
  55467. (assign, ":object", -1),
  55468. (str_store_party_name, s21, ":most_threatened_center"),
  55469. (str_store_string, s14, "str_we_should_prepare_to_defend_s21_but_we_should_gather_our_forces_until_we_are_strong_enough_to_engage_them"),
  55470.  
  55471. (try_begin),
  55472. (eq, ":faction_no", "$players_kingdom"),
  55473. (assign, "$g_gathering_reason", ":most_threatened_center"),
  55474. (try_end),
  55475.  
  55476. #3-DEFENSIVE ACTIONS : RIDE TO BREAK ENEMY SIEGE / DEFEAT ENEMIES NEAR OUR CENTER
  55477. (else_try),
  55478. (party_is_active, ":marshal_party"),
  55479. (is_between, ":most_threatened_center", walled_centers_begin, walled_centers_end),
  55480. (this_or_next|eq, ":current_ai_state", sfai_default), #MOTO not going to attack anyway
  55481. (this_or_next|eq, ":current_ai_state", sfai_feast), #MOTO not going to attack anyway (THIS is the emergency to stop feast)
  55482. (ge, ":threat_danger_level", ":target_value_level"),
  55483. (party_slot_ge, ":most_threatened_center", slot_center_is_besieged_by, 0),
  55484.  
  55485. (assign, ":action", sfai_attacking_enemies_around_center),
  55486. (assign, ":object", ":most_threatened_center"),
  55487.  
  55488. (str_store_party_name, s21, ":most_threatened_center"),
  55489. (str_store_string, s14, "str_we_should_ride_to_break_the_siege_of_s21"),
  55490.  
  55491. #3b - DEFEAT ENEMIES NEAR CENTER - similar to above, but a different string
  55492. (else_try),
  55493. (party_is_active, ":marshal_party"),
  55494. (this_or_next|eq, ":current_ai_state", sfai_default), #MOTO not going to attack anyway
  55495. (this_or_next|eq, ":current_ai_state", sfai_feast), #MOTO not going to attack anyway (THIS is the emergency to stop feast)
  55496. (ge, ":threat_danger_level", ":target_value_level"),
  55497. (is_between, ":most_threatened_center", villages_begin, villages_end),
  55498.  
  55499. (assign, ":action", sfai_attacking_enemies_around_center),
  55500. (assign, ":object", ":most_threatened_center"),
  55501. (str_store_party_name, s21, ":most_threatened_center"),
  55502. (str_store_string, s14, "str_we_should_ride_to_defeat_the_enemy_gathered_near_s21"),
  55503.  
  55504. #4-DEMOBILIZATION
  55505. #Let vassals attend their own business
  55506. (else_try),
  55507. (this_or_next|eq, ":current_ai_state", sfai_gathering_army),
  55508. (this_or_next|eq, ":current_ai_state", sfai_attacking_center),
  55509. (eq, ":current_ai_state", sfai_raiding_village),
  55510.  
  55511. (ge, ":hours_since_last_faction_rest", ":campaign_hour_limit"), #Effected by ratio of vassals
  55512. (ge, ":hours_at_current_state", 24),
  55513.  
  55514. #Ozan : I am adding some codes here because sometimes armies demobilize during last seconds of an important event like taking a castle, ext.
  55515. (assign, ":there_is_an_important_situation", 0),
  55516. (try_begin), #do not demobilize during taking a castle/town (fighting in the castle)
  55517. (is_between, ":current_ai_object", walled_centers_begin, walled_centers_end),
  55518. (party_get_battle_opponent, ":besieger_party", ":current_ai_object"),
  55519. (party_is_active, ":besieger_party"),
  55520. (store_faction_of_party, ":besieger_faction", ":besieger_party"),
  55521. (this_or_next|eq, ":besieger_faction", ":faction_no"),
  55522. (eq, ":besieger_faction", "fac_player_faction"),
  55523. (assign, ":there_is_an_important_situation", 1),
  55524. (else_try), #do not demobilize during besieging a siege (holding around castle)
  55525. (is_between, ":current_ai_object", walled_centers_begin, walled_centers_end),
  55526. (party_get_slot, ":besieger_party", ":current_ai_object", slot_center_is_besieged_by),
  55527. (party_is_active, ":besieger_party"),
  55528. (store_faction_of_party, ":besieger_faction", ":besieger_party"),
  55529. (this_or_next|eq, ":besieger_faction", ":faction_no"),
  55530. (eq, ":besieger_faction", "fac_player_faction"),
  55531. (assign, ":there_is_an_important_situation", 1),
  55532. (else_try), #do not demobilize during raiding a village (holding around village)
  55533. (is_between, ":current_ai_object", centers_begin, centers_end),
  55534. (neg|is_between, ":current_ai_object", walled_centers_begin, walled_centers_end),
  55535. (party_slot_eq, ":current_ai_object", slot_village_state, svs_being_raided),
  55536. (assign, ":there_is_an_important_situation", 1),
  55537. (try_end),
  55538.  
  55539. (eq, ":there_is_an_important_situation", 0),
  55540. #end addition ozan
  55541.  
  55542. (assign, reg7, ":hours_since_last_faction_rest"),
  55543. (assign, reg8, ":campaign_hour_limit"),
  55544.  
  55545. (str_store_string, s14, "str_this_offensive_needs_to_wind_down_soon_so_the_vassals_can_attend_to_their_own_business"),
  55546. (assign, ":action", sfai_default),
  55547. (assign, ":object", -1),
  55548.  
  55549. #6-GATHERING BECAUSE OF NO REASON
  55550. #Start to gather the army
  55551. (else_try),
  55552. (party_is_active, ":marshal_party"),
  55553. (eq, ":at_peace_with_everyone", 0),
  55554.  
  55555.  
  55556. (eq, ":current_ai_state", sfai_default),
  55557. (ge, ":hours_since_last_offensive", 60),
  55558. (lt, ":hours_since_last_faction_rest", 120),
  55559.  
  55560. #There should not be a center as a precondition for attack
  55561. #Otherwise, we are unlikely to have a situation in which the army gathers, but does nothing -- which is important to have for role-playing purposes
  55562.  
  55563. (assign, ":action", sfai_gathering_army),
  55564. (assign, ":object", -1),
  55565. (str_store_string, s14, "str_it_is_time_to_go_on_the_offensive_and_we_must_first_assemble_the_army"),
  55566.  
  55567. (try_begin),
  55568. (eq, ":faction_no", "$players_kingdom"),
  55569. (assign, "$g_gathering_reason", -1),
  55570. (try_end),
  55571.  
  55572. #7-OFFENSIVE ACTIONS : CONTINUE GATHERING
  55573. (else_try),
  55574. (party_is_active, ":marshal_party"),
  55575. (eq, ":current_ai_state", sfai_gathering_army),
  55576. (eq, ":at_peace_with_everyone", 0),
  55577.  
  55578. (lt, ":hours_at_current_state", 54), #gather army for 54 hours
  55579.  
  55580. (lt, ":ratio_of_vassals_assembled", 12),
  55581.  
  55582. (str_store_string, s14, "str_we_must_continue_to_gather_the_army_before_we_ride_forth_on_an_offensive_operation"),
  55583. (assign, ":action", sfai_gathering_army),
  55584. (assign, ":object", -1),
  55585.  
  55586. #7-OFFENSIVE ACTIONS PART 2 : CONTINUE GATHERING
  55587. (else_try),
  55588. (assign, ":minimum_possible_attackable_target_value_level", 50),
  55589. (eq, ":at_peace_with_everyone", 0),
  55590.  
  55591. (try_begin), #agressive marshal
  55592. ##diplomacy start+
  55593. ##OLD:
  55594. #(troop_get_slot, ":reputation", ":troop_no", slot_lord_reputation_type),
  55595. #(this_or_next|eq, ":reputation", lrep_martial),
  55596. #(this_or_next|eq, ":reputation", lrep_quarrelsome),
  55597. #(eq, ":reputation", lrep_selfrighteous),
  55598. ##NEW:
  55599. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  55600. (lt, reg0, 0),
  55601. ##diplomacy end+
  55602. (val_mul, ":minimum_possible_attackable_target_value_level", 9),
  55603. (val_div, ":minimum_possible_attackable_target_value_level", 10),
  55604. (try_end),
  55605.  
  55606. (party_is_active, ":marshal_party"),
  55607. (eq, ":current_ai_state", sfai_gathering_army),
  55608.  
  55609. (try_begin),
  55610. (lt, ":hours_at_current_state", 6),
  55611. (assign, ":minimum_needed_target_value_level", 1500),
  55612. (else_try),
  55613. (lt, ":hours_at_current_state", 10),
  55614. (assign, ":minimum_needed_target_value_level", 1000),
  55615. (else_try),
  55616. (lt, ":hours_at_current_state", 14),
  55617. (assign, ":minimum_needed_target_value_level", 720),
  55618. (else_try),
  55619. (lt, ":hours_at_current_state", 18),
  55620. (assign, ":minimum_needed_target_value_level", 480),
  55621. (else_try),
  55622. (lt, ":hours_at_current_state", 22),
  55623. (assign, ":minimum_needed_target_value_level", 360),
  55624. (else_try),
  55625. (lt, ":hours_at_current_state", 26),
  55626. (assign, ":minimum_needed_target_value_level", 240),
  55627. (else_try),
  55628. (lt, ":hours_at_current_state", 30),
  55629. (assign, ":minimum_needed_target_value_level", 180),
  55630. (else_try),
  55631. (lt, ":hours_at_current_state", 34),
  55632. (assign, ":minimum_needed_target_value_level", 120),
  55633. (else_try),
  55634. (lt, ":hours_at_current_state", 38),
  55635. (assign, ":minimum_needed_target_value_level", 100),
  55636. (else_try),
  55637. (lt, ":hours_at_current_state", 42),
  55638. (assign, ":minimum_needed_target_value_level", 80),
  55639. (else_try),
  55640. (lt, ":hours_at_current_state", 46),
  55641. (assign, ":minimum_needed_target_value_level", 65),
  55642. (else_try),
  55643. (lt, ":hours_at_current_state", 50),
  55644. (assign, ":minimum_needed_target_value_level", 55),
  55645. (else_try),
  55646. (assign, ":minimum_needed_target_value_level", ":minimum_possible_attackable_target_value_level"),
  55647. (try_end),
  55648.  
  55649. (try_begin), #agressive marshal
  55650. ##diplomacy start+
  55651. ##OLD:
  55652. #(troop_get_slot, ":reputation", ":troop_no", slot_lord_reputation_type),
  55653. #(this_or_next|eq, ":reputation", lrep_martial),
  55654. #(this_or_next|eq, ":reputation", lrep_quarrelsome),
  55655. #(eq, ":reputation", lrep_selfrighteous),
  55656. ##NEW:
  55657. (call_script, "script_dplmc_store_troop_personality_caution_level", ":troop_no"),
  55658. (lt, reg0, 0),
  55659. ##diplomacy end+
  55660. (val_mul, ":minimum_needed_target_value_level", 9),
  55661. (val_div, ":minimum_needed_target_value_level", 10),
  55662. (try_end),
  55663.  
  55664. (le, ":target_value_level", ":minimum_needed_target_value_level"),
  55665. (le, ":hours_at_current_state", 54),
  55666.  
  55667. (str_store_string, s14, "str_we_have_assembled_some_vassals"),
  55668. (assign, ":action", sfai_gathering_army),
  55669. (assign, ":object", -1),
  55670.  
  55671. #8-ATTACK AN ENEMY CENTER case 1, reconnaissance against walled center
  55672. #(else_try),
  55673. #(party_is_active, ":marshal_party"),
  55674. #(neq, ":current_ai_state", sfai_default),
  55675. #(neq, ":current_ai_state", sfai_feast),
  55676. #(is_between, ":center_to_attack", walled_centers_begin, walled_centers_end),
  55677.  
  55678. #(store_sub, ":faction_recce_slot", ":faction_no", kingdoms_begin),
  55679. #(val_add, ":faction_recce_slot", slot_center_last_reconnoitered_by_faction_time),
  55680. #(store_current_hours, ":hours_since_last_recon"),
  55681. #(party_get_slot, ":last_recon_time", ":center_to_attack", ":faction_recce_slot"),
  55682. #(val_sub, ":hours_since_last_recon", ":last_recon_time"),
  55683. #(this_or_next|eq, ":last_recon_time", 0),
  55684. #(gt, ":hours_since_last_recon", 96),
  55685.  
  55686. #(assign, ":action", sfai_attacking_center),
  55687. #(assign, ":object", ":center_to_attack"),
  55688. #(str_store_string, s14, "str_we_are_conducting_recce"),
  55689.  
  55690. #8-ATTACK AN ENEMY CENTER case 2, reconnaissance against village
  55691. #(else_try),
  55692. #(party_is_active, ":marshal_party"),
  55693. #(neq, ":current_ai_state", sfai_default),
  55694. #(neq, ":current_ai_state", sfai_feast),
  55695. #(is_between, ":center_to_attack", villages_begin, villages_end),
  55696.  
  55697. #(store_sub, ":faction_recce_slot", ":faction_no", kingdoms_begin),
  55698. #(val_add, ":faction_recce_slot", slot_center_last_reconnoitered_by_faction_time),
  55699. #(store_current_hours, ":hours_since_last_recon"),
  55700. #(party_get_slot, ":last_recon_time", ":center_to_attack", ":faction_recce_slot"),
  55701. #(val_sub, ":hours_since_last_recon", ":last_recon_time"),
  55702. #(this_or_next|eq, ":last_recon_time", 0),
  55703. #(gt, ":hours_since_last_recon", 96),
  55704.  
  55705.  
  55706. #(assign, ":action", sfai_raiding_village),
  55707. #(assign, ":object", ":center_to_attack"),
  55708. #(str_store_string, s14, "str_we_are_conducting_recce"),
  55709. (else_try),
  55710. (party_is_active, ":marshal_party"),
  55711. (neq, ":current_ai_state", sfai_default),
  55712. (neq, ":current_ai_state", sfai_feast),
  55713.  
  55714. (assign, ":center_to_attack", ":center_to_attack_only_marshal_and_followers"),
  55715.  
  55716. (is_between, ":center_to_attack", walled_centers_begin, walled_centers_end),
  55717.  
  55718. (ge, ":target_value_level", ":minimum_possible_attackable_target_value_level"),
  55719.  
  55720. (assign, ":action", sfai_attacking_center),
  55721. (assign, ":object", ":center_to_attack"),
  55722. (str_store_string, s14, "str_we_believe_the_fortress_will_be_worth_the_effort_to_take_it"),
  55723. (else_try),
  55724. (party_is_active, ":marshal_party"),
  55725. (neq, ":current_ai_state", sfai_default),
  55726. (neq, ":current_ai_state", sfai_feast),
  55727.  
  55728. (assign, ":center_to_attack", ":center_to_attack_only_marshal_and_followers"),
  55729.  
  55730. (is_between, ":center_to_attack", villages_begin, villages_end),
  55731.  
  55732. (ge, ":target_value_level", ":minimum_possible_attackable_target_value_level"),
  55733.  
  55734. (assign, ":action", sfai_raiding_village),
  55735. (assign, ":object", ":center_to_attack"),
  55736. (str_store_string, s14, "str_we_shall_leave_a_fiery_trail_through_the_heart_of_the_enemys_lands_targeting_the_wealthy_settlements_if_we_can"),
  55737.  
  55738. #9 -- DISBAND THE ARMY
  55739. (else_try),
  55740. (eq, ":current_ai_state", sfai_gathering_army),
  55741.  
  55742. (str_store_string, s14, "str_the_army_will_be_disbanded_because_we_have_been_waiting_too_long_without_a_target"),
  55743.  
  55744. (assign, ":action", sfai_default),
  55745. (assign, ":object", -1),
  55746. #OFFENSIVE OPERATIONS END
  55747.  
  55748. #FEAST-RELATED OPERATIONS BEGIN
  55749. #10-CONCLUDE CURRENT FEAST
  55750. (else_try),
  55751. (eq, ":current_ai_state", sfai_feast),
  55752. (gt, ":hours_at_current_state", 72),
  55753.  
  55754. (assign, ":action", sfai_default),
  55755. (assign, ":object", -1),
  55756. (str_store_string, s14, "str_it_is_time_for_the_feast_to_conclude"),
  55757.  
  55758. #11-CONTINE FEAST UNLESS THERE IS AN EMERGENCY
  55759. (else_try),
  55760. (eq, ":current_ai_state", sfai_feast),
  55761. (le, ":hours_at_current_state", 72),
  55762.  
  55763. (assign, ":action", sfai_feast),
  55764. (assign, ":object", ":current_ai_object"),
  55765. (str_store_string, s14, "str_we_should_continue_the_feast_unless_there_is_an_emergency"),
  55766.  
  55767. #12-HOLD A FEAST BECAUSE THE PLAYER WANTS TO ORGANIZE ONE
  55768. (else_try),
  55769. (check_quest_active, "qst_organize_feast"),
  55770. (eq, "$players_kingdom", ":faction_no"),
  55771.  
  55772. (quest_get_slot, ":target_center", "qst_organize_feast", slot_quest_target_center),
  55773.  
  55774. (assign, ":action", sfai_feast),
  55775. (assign, ":object", ":target_center"),
  55776. (str_store_string, s14, "str_you_had_wished_to_hold_a_feast"),
  55777.  
  55778. #13-HOLD A FEAST BECAUSE FEMALE PLAYER SCHEDULED TO GET MARRIED
  55779. (else_try),
  55780. (check_quest_active, "qst_wed_betrothed_female"),
  55781.  
  55782. (quest_get_slot, ":groom", "qst_wed_betrothed_female", slot_quest_giver_troop),
  55783. (troop_slot_eq, ":groom", slot_troop_prisoner_of_party, -1),
  55784.  
  55785. (store_faction_of_troop, ":groom_faction", ":groom"),
  55786. (eq, ":groom_faction", ":faction_no"),
  55787.  
  55788. (faction_get_slot, ":faction_leader", ":groom_faction", slot_faction_leader),
  55789.  
  55790. (assign, ":location_feast", -1),
  55791. (try_for_range, ":possible_location", walled_centers_begin, walled_centers_end),
  55792. (eq, ":location_feast", -1),
  55793. (party_slot_eq, ":possible_location", slot_town_lord, ":groom"),
  55794. (party_slot_ge, ":possible_location", slot_center_is_besieged_by, 0),
  55795. (assign, ":location_feast", ":possible_location"),
  55796. (try_end),
  55797.  
  55798. (try_for_range, ":possible_location", walled_centers_begin, walled_centers_end),
  55799. (eq, ":location_feast", -1),
  55800. (party_slot_eq, ":possible_location", slot_town_lord, ":faction_leader"),
  55801. (party_slot_ge, ":possible_location", slot_center_is_besieged_by, 0),
  55802. (assign, ":location_feast", ":possible_location"),
  55803. (try_end),
  55804.  
  55805. (is_between, ":location_feast", walled_centers_begin, walled_centers_end),
  55806.  
  55807. (assign, ":action", sfai_feast),
  55808. (assign, ":object", ":location_feast"),
  55809. (str_store_string, s14, "str_your_wedding_day_approaches_my_lady"),
  55810.  
  55811. #14-HOLD A FEAST BECAUSE A MALE CHARACTER WANTS TO GET MARRIED
  55812. (else_try),
  55813. (check_quest_active, "qst_wed_betrothed"),
  55814. (neg|quest_slot_ge, "qst_wed_betrothed", slot_quest_expiration_days, 362),
  55815.  
  55816. (quest_get_slot, ":bride", "qst_wed_betrothed", slot_quest_target_troop),
  55817. (call_script, "script_get_kingdom_lady_social_determinants", ":bride"),
  55818. (assign, ":feast_host", reg0),
  55819. (store_faction_of_troop, ":feast_host_faction", ":feast_host"),
  55820. (eq, ":feast_host_faction", ":faction_no"),
  55821.  
  55822. (troop_slot_eq, ":feast_host", slot_troop_prisoner_of_party, -1),
  55823. (assign, ":wedding_venue", reg1),
  55824.  
  55825. (is_between, ":wedding_venue", centers_begin, centers_end),
  55826. (party_slot_eq, ":wedding_venue", slot_center_is_besieged_by, -1),
  55827.  
  55828. (assign, ":action", sfai_feast),
  55829. (assign, ":object", ":wedding_venue"),
  55830. (str_store_string, s14, "str_your_wedding_day_approaches"),
  55831.  
  55832. #15-HOLD A FEAST BECAUSE AN NPC WANTS TO GET MARRIED
  55833. (else_try),
  55834. (ge, ":hours_since_last_feast_start", 192), #If at least eight days past last feast start time
  55835.  
  55836. (assign, ":location_feast", -1),
  55837.  
  55838. (try_for_range, ":kingdom_lady", kingdom_ladies_begin, kingdom_ladies_end),
  55839. (troop_get_slot, ":groom", ":kingdom_lady", slot_troop_betrothed),
  55840. (gt, ":groom", 0), #not the player
  55841.  
  55842. (store_faction_of_troop, ":lady_faction", ":kingdom_lady"),
  55843. (store_faction_of_troop, ":groom_faction", ":groom"),
  55844.  
  55845. (try_begin), #The groom checks if he wants to continue or break off relations. This causes actions, rather than just returns a value, so it probably should be moved elsewhere
  55846. (troop_slot_ge, ":groom", slot_troop_prisoner_of_party, 0),
  55847. (else_try),
  55848. (neq, ":groom_faction", ":lady_faction"),
  55849. (neq, ":groom_faction", "fac_player_faction"),
  55850. (call_script, "script_courtship_event_lady_break_relation_with_suitor", ":kingdom_lady", ":groom"),
  55851. (else_try),
  55852. (eq, ":lady_faction", ":faction_no"),
  55853. ##diplomacy start+
  55854. #neither the bride nor the groom is in retirement, dead, etc.
  55855. (neg|troop_slot_ge, ":groom", slot_troop_occupation, slto_retirement),
  55856. (neg|troop_slot_ge, ":kingdom_lady", slot_troop_occupation, slto_retirement),
  55857. ##diplomacy end+
  55858. (store_current_hours, ":hours_since_betrothal"),
  55859. (troop_get_slot, ":betrothal_time", ":kingdom_lady", slot_troop_betrothal_time),
  55860. (val_sub, ":hours_since_betrothal", ":betrothal_time"),
  55861. (ge, ":hours_since_betrothal", 719), #30 days
  55862.  
  55863. (call_script, "script_get_kingdom_lady_social_determinants", ":kingdom_lady"),
  55864. (assign, ":wedding_venue", reg1),
  55865.  
  55866. (assign, ":location_feast", ":wedding_venue"),
  55867. (assign, ":final_bride", ":kingdom_lady"),
  55868. (assign, ":final_groom", ":groom"),
  55869. (try_end),
  55870. (try_end),
  55871.  
  55872. (ge, ":location_feast", centers_begin),
  55873.  
  55874. (assign, ":action", sfai_feast),
  55875. (assign, ":object", ":location_feast"),
  55876.  
  55877. (str_store_troop_name, s22, ":final_bride"),
  55878. (str_store_troop_name, s23, ":final_groom"),
  55879. (str_store_string, s14, "str_s22_and_s23_wish_to_marry"),
  55880.  
  55881. #16-HOLD A FEAST ANYWAY
  55882. (else_try),
  55883. (eq, ":current_ai_state", sfai_default),
  55884. (gt, ":hours_since_last_feast_start", 240), #If at least 10 days past after last feast. (added by ozan)
  55885.  
  55886. (assign, ":location_high_score", 0),
  55887. (assign, ":location_feast", -1),
  55888.  
  55889. (try_for_range, ":location", walled_centers_begin, walled_centers_end),
  55890. (store_faction_of_party, ":location_faction", ":location"),
  55891. (eq, ":location_faction", ":faction_no"),
  55892.  
  55893. (try_begin),
  55894. (neg|party_slot_eq, ":location", slot_village_state, svs_under_siege),
  55895. (party_get_slot, ":location_lord", ":location", slot_town_lord),
  55896. (is_between, ":location_lord", active_npcs_begin, active_npcs_end),
  55897. (troop_get_slot, ":location_score", ":location_lord", slot_troop_renown),
  55898. (store_random_in_range, ":random", 0, 1000), #will probably be king or senior lord
  55899. (val_add, ":location_score", ":random"),
  55900. (gt, ":location_score", ":location_high_score"),
  55901. (assign, ":location_high_score", ":location_score"),
  55902. (assign, ":location_feast", ":location"),
  55903. (else_try), #do not start new feasts if any place is under siege or being raided
  55904. (this_or_next|party_slot_eq, ":location", slot_village_state, svs_under_siege),
  55905. (party_slot_eq, ":location", slot_village_state, svs_being_raided),
  55906. (assign, ":location_high_score", 9999),
  55907. (assign, ":location_feast", -1),
  55908. (try_end),
  55909. (try_end),
  55910.  
  55911. (is_between, ":location_feast", walled_centers_begin, walled_centers_end),
  55912. (party_get_slot, ":feast_host", ":location_feast", slot_town_lord),
  55913. (troop_slot_eq, ":feast_host", slot_troop_prisoner_of_party, -1),
  55914.  
  55915. (assign, ":action", sfai_feast),
  55916. (assign, ":object", ":location_feast"),
  55917. (str_store_string, s14, "str_it_has_been_a_long_time_since_the_lords_of_the_realm_gathered_for_a_feast"),
  55918.  
  55919. #17-DO NOTHING
  55920. (else_try),
  55921. (neq, ":current_ai_state", sfai_default),
  55922.  
  55923. (assign, ":action", sfai_default),
  55924. (assign, ":object", -1),
  55925. (str_store_string, s14, "str_the_circumstances_which_led_to_this_decision_no_longer_apply_so_we_should_stop_and_reconsider_shortly"),
  55926.  
  55927. #18-DO NOTHING
  55928. (else_try),
  55929. (eq, ":current_ai_state", sfai_default),
  55930.  
  55931. (eq, ":at_peace_with_everyone", 1),
  55932.  
  55933. (assign, ":action", sfai_default),
  55934. (assign, ":object", -1),
  55935. (str_store_string, s14, "str_we_are_currently_at_peace"),
  55936. (else_try),
  55937. (eq, ":current_ai_state", sfai_default),
  55938. (faction_slot_eq, ":faction_no", slot_faction_marshall, -1),
  55939. (assign, ":action", sfai_default),
  55940. (assign, ":object", -1),
  55941. (str_store_string, s14, "str_we_are_waiting_for_selection_of_marshal"),
  55942.  
  55943. (else_try),
  55944. (eq, ":current_ai_state", sfai_default),
  55945.  
  55946. (assign, ":action", sfai_default),
  55947. (assign, ":object", -1),
  55948. (str_store_string, s14, "str_the_vassals_still_need_time_to_attend_to_their_own_business"),
  55949. (try_end),
  55950.  
  55951. (assign, reg0, ":action"),
  55952. (assign, reg1, ":object"),
  55953. ]),
  55954.  
  55955. (
  55956. "faction_last_reconnoitered_center", #This is called from within decide_faction_ai, or from
  55957. [
  55958. (store_script_param, ":faction_no", 1),
  55959. (store_script_param, ":center_no", 2),
  55960.  
  55961. (store_sub, ":faction_recce_slot", ":faction_no", kingdoms_begin),
  55962. (val_add, ":faction_recce_slot", slot_center_last_reconnoitered_by_faction_time),
  55963. (store_current_hours, ":hours_since_last_recon"),
  55964. (party_get_slot, ":last_recon_time", ":center_no", ":faction_recce_slot"),
  55965.  
  55966. (try_begin),
  55967. (lt, ":last_recon_time", 1),
  55968. (assign, ":hours_since_last_recon", 1000),
  55969. (else_try),
  55970. (val_sub, ":hours_since_last_recon", ":last_recon_time"),
  55971. (try_end),
  55972.  
  55973. (assign, reg0, ":hours_since_last_recon"),
  55974. (assign, reg1, ":last_recon_time"),
  55975. ]),
  55976.  
  55977. (
  55978. "reduce_exact_number_to_estimate",
  55979. #This is used to simulate limited intelligence
  55980. #It is roughly analogous to the descriptive strings which the player will receive from alarms
  55981. #Information is presumed to be accurate for four days
  55982. #This is obviously cheating for the AI, as the AI will have exact info for four days, and no info at all after that.
  55983. #It would be fairly easy to log the strength at a center when it is scouted, if we want, but I have not done that at this point,
  55984. #The AI also has a hive mind -- ie, each party knows what its allies are thinking. In this, AI factions have an advantage over the player
  55985. #It would be a simple matter to create a set of arrays in which each party's knowledge is individually updated, but that would also take up a lot of data space
  55986.  
  55987. [
  55988. (store_script_param, ":exact_number", 1),
  55989.  
  55990. (try_begin),
  55991. (lt, ":exact_number", 500),
  55992. (assign, ":estimate", 0),
  55993. (else_try),
  55994. (lt, ":exact_number", 1000),
  55995. (assign, ":estimate", 750),
  55996. (else_try),
  55997. (lt, ":exact_number", 2000),
  55998. (assign, ":estimate", 1500),
  55999. (else_try),
  56000. (lt, ":exact_number", 4000),
  56001. (assign, ":estimate", 3000),
  56002. (else_try),
  56003. (lt, ":exact_number", 8000),
  56004. (assign, ":estimate", 6000),
  56005. (else_try),
  56006. (lt, ":exact_number", 16000),
  56007. (assign, ":estimate", 12000),
  56008. (else_try),
  56009. (assign, ":estimate", 24000),
  56010. (try_end),
  56011. ##diplomacy start+
  56012. #This currently isn't used anywhere, but modify it if we're thinking about changing that.
  56013. #Take into account campaign AI difficulty -- assume that the difference is either a good
  56014. #spy network or intelligent inference.
  56015. (game_get_reduce_campaign_ai, reg0),
  56016. (try_begin),
  56017. (lt, reg0, 1),#Hard mode
  56018. (assign, ":estimate", ":exact_number"),
  56019. (else_try),
  56020. (eq, reg0, 1),#Medium Mode
  56021. (val_add, ":estimate", ":exact_number"),
  56022. (val_div, ":estimate", 2),
  56023. (try_end),
  56024. ##diplomacy end+
  56025.  
  56026. (assign, reg0, ":estimate"),
  56027. ]),
  56028.  
  56029. #script_calculate_castle_prosperities_by_using_its_villages
  56030. (
  56031. "calculate_castle_prosperities_by_using_its_villages", #This is called from within decide_faction_ai, or from
  56032. [
  56033. (try_for_range, ":cur_castle", castles_begin, castles_end),
  56034. (assign, ":total_prosperity", 0),
  56035. (assign, ":total_villages", 0),
  56036.  
  56037. (try_for_range, ":cur_village", villages_begin, villages_end),
  56038. (party_get_slot, ":bound_center", ":cur_village", slot_village_bound_center),
  56039. (eq, ":cur_castle", ":bound_center"),
  56040.  
  56041. (party_get_slot, ":village_prosperity", ":cur_village", slot_town_prosperity),
  56042.  
  56043. (val_add, ":total_prosperity", ":village_prosperity"),
  56044. (val_add, ":total_villages", 1),
  56045. (try_end),
  56046.  
  56047. (try_begin),
  56048. (store_div, ":castle_prosperity", ":total_prosperity", ":total_villages"),
  56049. (else_try),
  56050. (assign, ":castle_prosperity", 50),
  56051. (try_end),
  56052.  
  56053. (party_set_slot, ":cur_castle", slot_town_prosperity, ":castle_prosperity"),
  56054. (try_end),
  56055. ]),
  56056.  
  56057. #script_initialize_tavern_variables
  56058. (
  56059. "initialize_tavern_variables",
  56060. [
  56061. (assign, "$g_main_attacker_agent", 0),
  56062. (assign, "$g_attacker_drawn_weapon", 0),
  56063. (assign, "$g_start_belligerent_drunk_fight", 0),
  56064. (assign, "$g_start_hired_assassin_fight", 0),
  56065. (assign, "$g_belligerent_drunk_leaving", 0),
  56066. ]),
  56067.  
  56068. #script_prepare_alley_to_fight
  56069. (
  56070. "prepare_alley_to_fight",
  56071. [
  56072. (party_get_slot, ":scene_no", "$current_town", slot_town_alley),
  56073.  
  56074. #(store_faction_of_party, ":faction_no", "$current_town"),
  56075.  
  56076. (modify_visitors_at_site, ":scene_no"),
  56077.  
  56078. (reset_visitors),
  56079. (set_visitor, 0, "trp_player"),
  56080.  
  56081. #(set_visitor, 3, ":bandit_troop"),
  56082. (set_visitor, 3, "trp_bandit"),
  56083.  
  56084. (assign, "$talked_with_merchant", 0),
  56085. (set_jump_mission, "mt_alley_fight"),
  56086. (jump_to_scene, ":scene_no"),
  56087. (change_screen_mission),
  56088. ]),
  56089.  
  56090. #script_prepare_town_to_fight
  56091. (
  56092. "prepare_town_to_fight",
  56093. [
  56094. (str_store_party_name_link, s9, "$g_starting_town"),
  56095. (str_store_string, s2, "str_save_town_from_bandits"),
  56096. (call_script, "script_start_quest", "qst_save_town_from_bandits", "$g_talk_troop"),
  56097.  
  56098. (assign, "$g_mt_mode", tcm_default),
  56099. (store_faction_of_party, ":town_faction", "$current_town"),
  56100. (faction_get_slot, ":tier_2_troop", ":town_faction", slot_faction_tier_3_troop),
  56101. (faction_get_slot, ":tier_3_troop", ":town_faction", slot_faction_tier_3_troop),
  56102. (faction_get_slot, ":tier_4_troop", ":town_faction", slot_faction_tier_4_troop),
  56103.  
  56104. (party_get_slot, ":town_scene", "$current_town", slot_town_center),
  56105. (modify_visitors_at_site, ":town_scene"),
  56106. (reset_visitors),
  56107.  
  56108. #people spawned at #32, #33, #34, #35, #36, #37, #38 and #39 are town walkers.
  56109. (try_begin),
  56110. #(eq, "$town_nighttime", 0),
  56111. (try_for_range, ":walker_no", 0, num_town_walkers),
  56112. (store_add, ":troop_slot", slot_center_walker_0_troop, ":walker_no"),
  56113. (party_get_slot, ":walker_troop_id", "$current_town", ":troop_slot"),
  56114. (gt, ":walker_troop_id", 0),
  56115. (store_add, ":entry_no", town_walker_entries_start, ":walker_no"),
  56116. (set_visitor, ":entry_no", ":walker_troop_id"),
  56117. (try_end),
  56118. (try_end),
  56119.  
  56120. #guards will be spawned at #25, #26 and #27
  56121. (set_visitors, 25, ":tier_2_troop", 1),
  56122. (set_visitors, 26, ":tier_3_troop", 1),
  56123. (set_visitors, 27, ":tier_4_troop", 1),
  56124.  
  56125. (set_visitors, 10, "trp_looter", 1),
  56126. (set_visitors, 11, "trp_bandit", 1),
  56127. (set_visitors, 12, "trp_looter", 1),
  56128.  
  56129. # (store_faction_of_party, ":starting_town_faction", "$g_starting_town"),
  56130. #SB : add a few bandits alongside the looters
  56131. (call_script, "script_center_get_bandits", "$g_starting_town", 0),
  56132. (assign, ":bandit_troop", reg0),
  56133. (call_script, "script_get_troop_of_merchant"),
  56134. (assign, ":troop_of_merchant", reg0),
  56135. (str_store_troop_name, s10, ":troop_of_merchant"),
  56136.  
  56137. (set_visitors, 24, "trp_looter", 1),
  56138. (set_visitors, 2, ":bandit_troop", 2),
  56139. (set_visitors, 4, "trp_looter", 1),
  56140. (set_visitors, 5, "trp_looter", 2),
  56141. (set_visitors, 6, "trp_looter", 1),
  56142. (set_visitors, 7, ":bandit_troop", 1),
  56143.  
  56144. (set_visitors, 3, ":troop_of_merchant", 1),
  56145.  
  56146. (set_jump_mission,"mt_town_fight"),
  56147. (jump_to_scene, ":town_scene"),
  56148. (change_screen_mission),
  56149. ]),
  56150.  
  56151. (
  56152. "change_player_right_to_rule",
  56153. [
  56154. (store_script_param_1, ":right_to_rule_dif"),
  56155. (val_add, "$player_right_to_rule", ":right_to_rule_dif"),
  56156. (val_clamp, "$player_right_to_rule", 0, 100),
  56157. (try_begin),
  56158. (gt, ":right_to_rule_dif", 0),
  56159. (display_message, "@You gain right to rule.", message_positive),
  56160. (else_try),
  56161. (lt, ":right_to_rule_dif", 0),
  56162. (display_message, "@You lose right to rule.", message_negative),
  56163. (try_end),
  56164. ]),
  56165.  
  56166. ("indict_lord_for_treason",#originally included in simple_triggers. Needed to be moved here to allow player to indict
  56167. [
  56168. (store_script_param, ":troop_no", 1),
  56169. (store_script_param, ":faction", 2),
  56170.  
  56171. ##diplomacy start+ use gender script
  56172. #(troop_get_type, reg4, ":troop_no"),
  56173. (assign, ":save_reg0", reg0),
  56174. (assign, ":save_reg3", reg3),
  56175. (assign, ":save_reg4", reg4),
  56176. ##diplomacy end+
  56177.  
  56178. (try_for_range, ":center", centers_begin, centers_end), #transfer properties to liege
  56179. (party_slot_eq, ":center", slot_town_lord, ":troop_no"),
  56180. (party_set_slot, ":center", slot_town_lord, stl_unassigned),
  56181. (try_end),
  56182.  
  56183. (faction_get_slot, ":faction_leader", ":faction", slot_faction_leader),
  56184. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_leader"),
  56185. (assign, ":liege_to_lord_relation", reg0),
  56186. (store_sub, ":base_relation_modifier", -150, ":liege_to_lord_relation"),
  56187. (val_div, ":base_relation_modifier", 40),#-1 at -100, -2 at -70, -3 at -30,etc.
  56188. (val_min, ":base_relation_modifier", -1),
  56189.  
  56190. # #SB : redistribute wealth to faction ruler
  56191. (try_begin),
  56192. (ge, "$g_dplmc_ai_changes", DPLMC_AI_CHANGES_HIGH),
  56193. # (troop_get_slot, ":cur_wealth", ":troop_no", slot_troop_wealth),
  56194. # (troop_set_slot, ":troop_no", slot_troop_wealth, 0),
  56195. # (call_script, "script_dplmc_distribute_gold_to_lord_and_holdings", ":cur_wealth", ":faction_leader"), #add to ruler
  56196. (try_end),
  56197. #Indictments, cont: Influence relations
  56198. ##diplomacy start+ Alter to include promoted ladies
  56199. ##OLD:
  56200. #(try_for_range, ":active_npc", active_npcs_begin, active_npcs_end), #this effects all lords in all factions
  56201. ##NEW:
  56202. (try_for_range, ":active_npc", heroes_begin, heroes_end), #this effects all lords in all factions
  56203. (this_or_next|is_between, ":active_npc", active_npcs_begin, active_npcs_end),
  56204. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  56205. ##diplomacy end+
  56206. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  56207. (eq, ":faction", ":active_npc_faction"),
  56208.  
  56209. (call_script, "script_troop_get_family_relation_to_troop", ":troop_no", ":active_npc"),
  56210. (assign, ":family_relation", reg0),
  56211.  
  56212. ##diplomacy start+
  56213. (val_max, ":family_relation", 0),
  56214. #Take into account friendship or enmity
  56215. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_leader"),
  56216. (assign, ":liking_relation", reg0),
  56217. (try_begin),
  56218. (ge, ":liking_relation", 20),
  56219. (store_div, reg0, ":liking_relation", 20),
  56220. (val_add, ":family_relation", reg0),
  56221. (else_try),
  56222. (lt, ":liking_relation", 0),
  56223. (store_div, reg0, ":liking_relation", 20),
  56224. (val_sub, reg0, 1),
  56225. (val_add, ":family_relation", reg0),
  56226. (try_end),
  56227. (store_random_in_range, reg0, 0, 3),#+0, +1, or +2 (because below we divide by three...)
  56228. (val_add, ":family_relation", reg0),
  56229. (assign, reg0, ":family_relation"),
  56230. ##diplomacy end+
  56231. (assign, ":relation_modifier", ":base_relation_modifier"),
  56232. (try_begin),
  56233. ##diplomacy start+
  56234. #(gt, ":family_relation", 1),##OLD
  56235. (neq, ":family_relation", 0),##NEW (allow lessening penalty for hated characters)
  56236. ##diplomacy end+
  56237. (store_div, ":family_multiplier", reg0, 3),
  56238. (val_sub, ":relation_modifier", ":family_multiplier"),
  56239. (try_end),
  56240.  
  56241. (lt, ":relation_modifier", 0),
  56242.  
  56243. (call_script, "script_troop_change_relation_with_troop", ":faction_leader", ":active_npc", ":relation_modifier"),
  56244. (val_add, "$total_indictment_changes", ":relation_modifier"),
  56245. (try_begin),
  56246. (eq, "$cheat_mode", 1),
  56247. (str_store_troop_name, s17, ":active_npc"),
  56248. (str_store_troop_name, s18, ":faction_leader"),
  56249.  
  56250. (assign, reg3, ":relation_modifier"),
  56251. (display_message, "str_trial_influences_s17s_relation_with_s18_by_reg3"),
  56252. (try_end),
  56253. (try_end),
  56254.  
  56255. #Indictments, cont: Check for other factions
  56256. (assign, ":new_faction", "fac_outlaws"),
  56257. (try_begin),
  56258. (eq, ":troop_no", "trp_player"),
  56259. (assign, ":new_faction", 0), #kicked out of faction
  56260. (else_try),
  56261. (call_script, "script_lord_find_alternative_faction", ":troop_no"),
  56262. (assign, ":new_faction", reg0),
  56263. (try_end),
  56264.  
  56265. #Indictments, cont: Finalize where the lord goes
  56266. (try_begin),
  56267. (is_between, ":new_faction", kingdoms_begin, kingdoms_end),
  56268.  
  56269.  
  56270. (try_begin),
  56271. (ge, "$cheat_mode", 1),
  56272. (str_store_troop_name, s4, ":troop_no"),
  56273. (display_message, "@{!}DEBUG - {s4} faction changed in indictment"),
  56274. (try_end),
  56275.  
  56276. (call_script, "script_change_troop_faction", ":troop_no", ":new_faction"),
  56277. (try_begin), #new-begin
  56278. (neq, ":new_faction", "fac_player_supporters_faction"),
  56279. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive),
  56280. (troop_set_slot, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  56281. (try_end), #new-end
  56282. (str_store_faction_name_link, s10, ":new_faction"),
  56283. (str_store_string, s11, "str_with_the_s10"),
  56284. (else_try),
  56285. (neq, ":troop_no", "trp_player"),
  56286. ##diplomacy start+
  56287. #Set "exile" occupation to differentiate between someone outside of Calradia
  56288. #and an outlaw lord leading a party of bandits.
  56289. (troop_set_slot, ":troop_no", slot_troop_occupation, dplmc_slto_exile),
  56290. ##diplomacy end+
  56291. (call_script, "script_change_troop_faction", ":troop_no", "fac_outlaws"),
  56292. (str_store_string, s11, "str_outside_calradia"),
  56293. (else_try),
  56294. (eq, ":troop_no", "trp_player"),
  56295. (call_script, "script_player_leave_faction", 1),
  56296. (try_end),
  56297.  
  56298. #Indictments, cont: Set up string
  56299. (try_begin),
  56300. (eq, ":troop_no", "trp_player"),
  56301. (str_store_string, s9, "str_you_have_been_indicted_for_treason_to_s7_your_properties_have_been_confiscated_and_you_would_be_well_advised_to_flee_for_your_life"),
  56302. (else_try),
  56303. # (str_store_troop_name_plural, s4, ":troop_no"), #this now holds the new faction title, need to be changed
  56304. (str_store_faction_name_link, s5, ":faction"),
  56305. (str_store_troop_name_link, s6, ":faction_leader"),
  56306.  
  56307. ##diplomacy start+
  56308. #(troop_get_type, reg4, ":troop_no"),
  56309. (call_script, "script_dplmc_store_troop_is_female", ":troop_no"),
  56310. (assign, reg4, reg0),
  56311. (store_sub, ":title", ":faction", kingdoms_begin),
  56312. (try_begin),
  56313. (eq, reg4, tf_male),
  56314. (val_add, ":title", kingdom_titles_male_begin),
  56315. (else_try),
  56316. (eq, reg4, tf_female),
  56317. (val_add, ":title", kingdom_titles_female_begin),
  56318. (else_try), #default to lord
  56319. (assign, ":title", kingdom_titles_male_begin),
  56320. (try_end),
  56321. (str_store_troop_name_plural, s0, ":troop_no"),
  56322. (str_store_string, s4, ":title"),
  56323. ##diplomacy end+
  56324. (str_store_string, s9, "str_by_order_of_s6_s4_of_the_s5_has_been_indicted_for_treason_the_lord_has_been_stripped_of_all_reg4herhis_properties_and_has_fled_for_reg4herhis_life_he_is_rumored_to_have_gone_into_exile_s11"),
  56325. (try_end),
  56326. ##diplomacy start+ important political events should be in the log
  56327. #SB : colorize with former faction
  56328. (faction_get_color, ":color", s9),
  56329. (display_log_message, s9, ":color"),#display_message changed to display_log_message
  56330. ##diplomacy end+
  56331.  
  56332. #Indictments, cont: Remove party
  56333. (troop_get_slot, ":led_party", ":troop_no", slot_troop_leaded_party),
  56334. (try_begin),
  56335. (party_is_active, ":led_party"),
  56336. (neq, ":led_party", "p_main_party"),
  56337. (remove_party, ":led_party"),
  56338. (troop_set_slot, ":troop_no", slot_troop_leaded_party, -1),
  56339. (try_end),
  56340.  
  56341. (try_begin),
  56342. (eq, "$cheat_mode", 1),
  56343. ##diplomacy start+
  56344. (this_or_next|eq, ":faction", "fac_player_supporters_faction"),
  56345. (this_or_next|eq, ":new_faction", "fac_player_supporters_faction"),
  56346. ##diplomacy end+
  56347. (this_or_next|eq, ":faction", "$players_kingdom"),
  56348. (eq, ":new_faction", "$players_kingdom"),
  56349. (call_script, "script_add_notification_menu", "mnu_notification_treason_indictment", ":troop_no", ":faction"),
  56350. (try_end),
  56351. ##diplomacy start+
  56352. (assign, reg0, ":save_reg0"),
  56353. (assign, reg3, ":save_reg3"),
  56354. (assign, reg4, ":save_reg4"),
  56355. ##diplomacy end+
  56356. ]),
  56357.  
  56358.  
  56359. # script_give_center_to_faction_while_maintaining_lord
  56360. # Input: arg1 = center_no, arg2 = faction
  56361. ("give_center_to_faction_while_maintaining_lord",
  56362. [
  56363. (store_script_param_1, ":center_no"),
  56364. (store_script_param_2, ":faction_no"),
  56365.  
  56366. (store_faction_of_party, ":old_faction", ":center_no"),
  56367. ##diplomacy start+
  56368. #If the player, previously the head of his own faction, is now joining
  56369. #an NPC faction, don't reset the "last taken" time or the "ex faction"
  56370. #slots.
  56371. (try_begin),
  56372. #Friendly transfer: don't update transfer time or ex-faction
  56373. (eq, ":old_faction", "fac_player_supporters_faction"),
  56374. (eq, ":faction_no", "$players_kingdom"),
  56375. (else_try),
  56376. #Defection: update transfer time and ex-faction
  56377. (party_set_slot, ":center_no", slot_center_ex_faction, ":old_faction"),
  56378. (store_current_hours, ":cur_hours"),
  56379. (party_set_slot, ":center_no", dplmc_slot_center_last_transfer_time, ":cur_hours"),
  56380. (try_end),
  56381. ##diplomacy end+
  56382. (party_set_faction, ":center_no", ":faction_no"),
  56383.  
  56384. (try_begin),
  56385. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  56386. #SB : reinforcement
  56387. (try_begin),
  56388. (party_get_slot, ":farmer_party", ":center_no", slot_village_farmer_party),
  56389. (gt, ":farmer_party", 0),
  56390. (party_is_active, ":farmer_party"),
  56391. (party_set_faction, ":farmer_party", ":faction_no"),
  56392. (try_end),
  56393. (try_begin),
  56394. (party_get_slot, ":reinf_party", ":center_no", slot_village_reinforcement_party),
  56395. (gt, ":reinf_party", 0),
  56396. (party_is_active, ":reinf_party"),
  56397. (party_set_faction, ":reinf_party", ":faction_no"),
  56398. (try_end),
  56399. (try_end),
  56400.  
  56401. (call_script, "script_update_faction_notes", ":faction_no"),
  56402. (call_script, "script_update_center_notes", ":center_no"),
  56403.  
  56404. (try_for_range, ":other_center", centers_begin, centers_end),
  56405. (party_slot_eq, ":other_center", slot_village_bound_center, ":center_no"),
  56406. (call_script, "script_give_center_to_faction_while_maintaining_lord", ":other_center", ":faction_no"),
  56407. (try_end),
  56408. ]),
  56409.  
  56410. # script_check_concilio_calradi_achievement
  56411. ("check_concilio_calradi_achievement",
  56412. [
  56413. (try_begin),
  56414. (eq, "$players_kingdom", "fac_player_supporters_faction"),
  56415. (faction_get_slot, ":player_faction_king", "fac_player_supporters_faction", slot_faction_leader),
  56416. (eq, ":player_faction_king", "trp_player"),
  56417. (assign, ":number_of_vassals", 0),
  56418. (try_for_range, ":cur_troop", active_npcs_begin, active_npcs_end),
  56419. (troop_slot_eq, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
  56420. (store_faction_of_troop, ":cur_faction", ":cur_troop"),
  56421. (eq, ":cur_faction", "fac_player_supporters_faction"),
  56422. (val_add, ":number_of_vassals", 1),
  56423. (try_end),
  56424. (ge, ":number_of_vassals", 3),
  56425. (unlock_achievement, ACHIEVEMENT_CONCILIO_CALRADI),
  56426. (try_end),
  56427. ]),
  56428.  
  56429. # script_refresh_center_inventories
  56430. ("refresh_center_inventories",
  56431. [
  56432. (set_merchandise_modifier_quality,150),
  56433. (reset_item_probabilities,100),
  56434.  
  56435. # Add trade goods to merchant inventories
  56436. (try_for_range,":cur_center",towns_begin,towns_end),
  56437. (party_get_slot,":cur_merchant",":cur_center",slot_town_merchant),
  56438. (reset_item_probabilities,100),
  56439. (assign, ":total_production", 0),
  56440. (try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
  56441. (call_script, "script_center_get_production", ":cur_center", ":cur_goods"),
  56442. (assign, ":cur_production", reg0),
  56443.  
  56444. (try_for_range, ":cur_village", villages_begin, villages_end),
  56445. (party_slot_eq, ":cur_village", slot_village_bound_center, ":cur_center"),
  56446. (call_script, "script_center_get_production", ":cur_village", ":cur_goods"),
  56447. (val_div, reg0, 3),
  56448. (val_add, ":cur_production", reg0),
  56449. (try_end),
  56450.  
  56451. (val_max, ":cur_production", 1),
  56452. (val_mul, ":cur_production", 4),
  56453.  
  56454. (val_add, ":total_production", ":cur_production"),
  56455. (try_end),
  56456.  
  56457. (party_get_slot, ":town_prosperity", ":cur_center", slot_town_prosperity),
  56458. (assign, ":number_of_items_in_town", 25),
  56459.  
  56460. (try_begin), #1.0x - 2.0x (50 - 100 prosperity)
  56461. (ge, ":town_prosperity", 50),
  56462. (store_sub, ":ratio", ":town_prosperity", 50),
  56463. (val_mul, ":ratio", 2),
  56464. (val_add, ":ratio", 100),
  56465. (val_mul, ":number_of_items_in_town", ":ratio"),
  56466. (val_div, ":number_of_items_in_town", 100),
  56467. (else_try), #0.5x - 1.0x (0 - 50 prosperity)
  56468. (store_sub, ":ratio", ":town_prosperity", 50),
  56469. (val_add, ":ratio", 100),
  56470. (val_mul, ":number_of_items_in_town", ":ratio"),
  56471. (val_div, ":number_of_items_in_town", 100),
  56472. (try_end),
  56473.  
  56474. (val_clamp, ":number_of_items_in_town", 10, 40),
  56475.  
  56476. (try_begin),
  56477. (is_between, ":cur_center", castles_begin, castles_end),
  56478. (val_div, ":number_of_items_in_town", 2),
  56479. (try_end),
  56480.  
  56481. (try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
  56482. (call_script, "script_center_get_production", ":cur_center", ":cur_goods"),
  56483. (assign, ":cur_production", reg0),
  56484.  
  56485. (try_for_range, ":cur_village", villages_begin, villages_end),
  56486. (party_slot_eq, ":cur_village", slot_village_bound_center, ":cur_center"),
  56487. (call_script, "script_center_get_production", ":cur_village", ":cur_goods"),
  56488. (val_div, reg0, 3),
  56489. (val_add, ":cur_production", reg0),
  56490. (try_end),
  56491.  
  56492. (val_max, ":cur_production", 1),
  56493. (val_mul, ":cur_production", 4),
  56494.  
  56495. (val_mul, ":cur_production", ":number_of_items_in_town"),
  56496. (val_mul, ":cur_production", 100),
  56497. (val_div, ":cur_production", ":total_production"),
  56498. (set_item_probability_in_merchandise, ":cur_goods", ":cur_production"),
  56499. (try_end),
  56500.  
  56501. (troop_clear_inventory, ":cur_merchant"),
  56502. (troop_add_merchandise, ":cur_merchant", itp_type_goods, ":number_of_items_in_town"),
  56503.  
  56504. (troop_ensure_inventory_space, ":cur_merchant", 20),
  56505. (troop_sort_inventory, ":cur_merchant"),
  56506. (store_troop_gold, ":cur_gold",":cur_merchant"),
  56507. ##diplomacy start+
  56508. #Option: scaling gold additions by the prosperity of the town.
  56509. (try_begin),
  56510. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),#this must be explicitly enabled
  56511. (party_get_slot, ":prosperity_75", ":cur_center", slot_town_prosperity),
  56512. (val_add, ":prosperity_75", 75),
  56513. (store_mul, ":target_gold", ":prosperity_75", 1500),
  56514. (val_add, ":target_gold", 62),
  56515. (val_div, ":target_gold", 125),#average 1500
  56516. (lt, ":cur_gold", ":target_gold"),
  56517. (store_random_in_range,":new_gold",500,1000),
  56518. (val_mul, ":new_gold", ":prosperity_75"),
  56519. (val_add, ":new_gold", 62),
  56520. (val_div, ":new_gold", 125),
  56521. (call_script, "script_troop_add_gold", ":cur_merchant", ":new_gold"),
  56522. (else_try),
  56523. (lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  56524. #fall through to default behavior
  56525. ##diplomacy end+
  56526. (lt,":cur_gold",1500),
  56527. (store_random_in_range,":new_gold",500,1000),
  56528. (call_script, "script_troop_add_gold", ":cur_merchant", ":new_gold"),
  56529. ##diplomacy start+
  56530. (try_end),
  56531. ##diplomacy end+
  56532. (try_end),
  56533. ]),
  56534.  
  56535. # script_refresh_center_armories
  56536. ("refresh_center_armories",
  56537. [
  56538. (reset_item_probabilities,100),
  56539. (set_merchandise_modifier_quality,150),
  56540. (try_for_range, ":cur_merchant", armor_merchants_begin, armor_merchants_end),
  56541. (store_sub, ":cur_town", ":cur_merchant", armor_merchants_begin),
  56542. (val_add, ":cur_town", towns_begin),
  56543. (troop_clear_inventory, ":cur_merchant"),
  56544. (party_get_slot, ":cur_faction", ":cur_town", slot_center_original_faction),
  56545. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_body_armor, 16),
  56546. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_head_armor, 16),
  56547. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_foot_armor, 8),
  56548. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_hand_armor, 4),
  56549. (troop_ensure_inventory_space, ":cur_merchant", merchant_inventory_space),
  56550. (troop_sort_inventory, ":cur_merchant"),
  56551. (store_troop_gold, reg6, ":cur_merchant"),
  56552.  
  56553. ##diplomacy start+
  56554. #Option: scaling gold additions by the prosperity of the town.
  56555. (try_begin),
  56556. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),#this must be explicitly enabled
  56557. (party_get_slot, ":prosperity_75", ":cur_town", slot_town_prosperity),
  56558. (val_add, ":prosperity_75", 75),
  56559. (store_mul, ":target_gold", ":prosperity_75", 900),
  56560. (val_add, ":target_gold", 62),
  56561. (val_div, ":target_gold", 125),#average 900
  56562. (lt, reg(6), ":target_gold"),
  56563. (store_random_in_range,":new_gold",200,400),
  56564. (val_mul, ":new_gold", ":prosperity_75"),
  56565. (val_add, ":new_gold", 62),
  56566. (val_div, ":new_gold", 125),
  56567. (call_script, "script_troop_add_gold", ":cur_merchant", ":new_gold"),
  56568. (else_try),
  56569. (lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  56570. #fall through to default behavior
  56571. ##diplomacy end+
  56572. (lt,reg6,1000),
  56573. (store_random_in_range,":new_gold",250,500),
  56574. (call_script, "script_troop_add_gold", ":cur_merchant", ":new_gold"),
  56575. ##diplomacy start+
  56576. (try_end),
  56577. ##diplomacy end+
  56578. (end_try),
  56579. ]),
  56580.  
  56581. # script_refresh_center_weaponsmiths
  56582. ("refresh_center_weaponsmiths",
  56583. [
  56584. (reset_item_probabilities,100),
  56585. (set_merchandise_modifier_quality,150),
  56586. (try_for_range, ":cur_merchant", weapon_merchants_begin, weapon_merchants_end),
  56587. (store_sub, ":cur_town", ":cur_merchant", weapon_merchants_begin),
  56588. (val_add, ":cur_town", towns_begin),
  56589. (troop_clear_inventory, ":cur_merchant"),
  56590. (party_get_slot, ":cur_faction", ":cur_town", slot_center_original_faction),
  56591. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_one_handed_wpn, 5),
  56592. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_two_handed_wpn, 5),
  56593. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_polearm, 5),
  56594. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_shield, 6),
  56595. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_bow, 4),
  56596. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_crossbow, 3),
  56597. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_thrown, 5),
  56598. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_arrows, 2),
  56599. (troop_add_merchandise_with_faction, ":cur_merchant", ":cur_faction", itp_type_bolts, 2),
  56600. (troop_ensure_inventory_space, ":cur_merchant", merchant_inventory_space),
  56601. (troop_sort_inventory, ":cur_merchant"),
  56602. (store_troop_gold, reg6, ":cur_merchant"),
  56603.  
  56604. ##diplomacy start+
  56605. #Option: scaling gold additions by the prosperity of the town.
  56606. (try_begin),
  56607. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),#this must be explicitly enabled
  56608. (party_get_slot, ":prosperity_75", ":cur_town", slot_town_prosperity),
  56609. (val_add, ":prosperity_75", 75),
  56610. (store_mul, ":target_gold", ":prosperity_75", 900),
  56611. (val_add, ":target_gold", 62),
  56612. (val_div, ":target_gold", 125),#average 900
  56613. (lt, reg6, ":target_gold"),
  56614. (store_random_in_range,":new_gold",200,400),
  56615. (val_mul, ":new_gold", ":prosperity_75"),
  56616. (val_add, ":new_gold", 62),
  56617. (val_div, ":new_gold", 125),
  56618. (call_script, "script_troop_add_gold", ":cur_merchant", ":new_gold"),
  56619. (else_try),
  56620. (lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  56621. #fall through to default behavior
  56622. ##diplomacy end+
  56623. (lt,reg6,1000),
  56624. (store_random_in_range,":new_gold",250,500),
  56625. (call_script, "script_troop_add_gold", ":cur_merchant", ":new_gold"),
  56626. ##diplomacy start+
  56627. (try_end),
  56628. ##diplomacy end+
  56629. (try_end),
  56630. ]),
  56631.  
  56632. # script_refresh_center_stables
  56633. ("refresh_center_stables",
  56634. [
  56635. (reset_item_probabilities,100),
  56636. (set_merchandise_modifier_quality,150),
  56637. (try_for_range,":cur_merchant",horse_merchants_begin,horse_merchants_end),
  56638. (troop_clear_inventory, ":cur_merchant"),
  56639. (store_sub, ":cur_town", ":cur_merchant", horse_merchants_begin),
  56640. (val_add, ":cur_town", towns_begin),
  56641. (party_get_slot, ":cur_faction", ":cur_town", slot_center_original_faction),
  56642. (troop_add_merchandise_with_faction,":cur_merchant", ":cur_faction",itp_type_horse,5),
  56643. (troop_ensure_inventory_space,":cur_merchant",65),
  56644. (troop_sort_inventory, ":cur_merchant"),
  56645. (store_troop_gold, ":cur_gold",":cur_merchant"),
  56646. ##diplomacy start+
  56647. #Option: scaling gold additions by the prosperity of the town.
  56648. (try_begin),
  56649. (ge, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),#this must be explicitly enabled
  56650. (party_get_slot, ":prosperity_75", ":cur_town", slot_town_prosperity),
  56651. (val_add, ":prosperity_75", 75),
  56652. (store_mul, ":target_gold", ":prosperity_75", 600),
  56653. (val_add, ":target_gold", 62),
  56654. (val_div, ":target_gold", 125),#average 600
  56655. (lt, ":cur_gold", ":target_gold"),
  56656. (store_random_in_range,":new_gold",200,400),
  56657. (val_mul, ":new_gold", ":prosperity_75"),
  56658. (val_add, ":new_gold", 62),
  56659. (val_div, ":new_gold", 125),
  56660. (call_script, "script_troop_add_gold", ":cur_merchant", ":new_gold"),
  56661. (else_try),
  56662. (lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  56663. #fall through to default behavior
  56664. ##diplomacy end+
  56665. (lt,":cur_gold",600),
  56666. (store_random_in_range, ":new_gold", 250, 500),
  56667. (call_script, "script_troop_add_gold", ":cur_merchant", ":new_gold"),
  56668. ##diplomacy start+
  56669. (try_end),
  56670. ##diplomacy end+
  56671. (try_end),
  56672. ]),
  56673.  
  56674. ##diplomacy begin
  56675. #recruiter kit begin
  56676. ("dplmc_send_recruiter",
  56677. [
  56678. (store_script_param, ":number_of_recruits", 1),
  56679. #daedalus begin
  56680. (store_script_param, ":faction_of_recruits", 2),
  56681. #daedalus end
  56682. (assign, ":expenses", ":number_of_recruits"),
  56683. (val_mul, ":expenses", 20),
  56684. (val_add, ":expenses", 10),
  56685. (call_script, "script_dplmc_withdraw_from_treasury", ":expenses"),
  56686. (set_spawn_radius, 1),
  56687. (spawn_around_party, "$current_town", "pt_dplmc_recruiter"),
  56688. (assign,":spawned_party",reg0),
  56689. (party_set_ai_behavior, ":spawned_party", ai_bhvr_hold),
  56690. (party_set_slot, ":spawned_party", slot_party_type, dplmc_spt_recruiter),
  56691. (party_set_slot, ":spawned_party", dplmc_slot_party_recruiter_needed_recruits, ":number_of_recruits"),
  56692. #daedalus begin
  56693. (party_set_slot, ":spawned_party", dplmc_slot_party_recruiter_needed_recruits_faction, ":faction_of_recruits"),
  56694. #daedalus end
  56695. (party_set_slot, ":spawned_party", dplmc_slot_party_recruiter_origin, "$current_town"),
  56696. (assign, ":faction", "$players_kingdom"),
  56697. (party_set_faction, ":spawned_party", ":faction"),
  56698. ]),
  56699. #recruiter kit end
  56700.  
  56701. ####################################################################################
  56702. #
  56703. # Autoloot Scripts begin
  56704. # ---------------------------------------------------
  56705. ####################################################################################
  56706.  
  56707. #### Autoloot improved by rubik begin
  56708. # ("dplmc_init_item_difficulties", set_item_difficulty()),
  56709. #### Autoloot improved by rubik end
  56710.  
  56711.  
  56712. ###################################
  56713. # Can a troop qualify to use this item?
  56714. # Returns 1 = yes, 0 = no.
  56715. ("dplmc_troop_can_use_item",
  56716. [
  56717. (store_script_param, ":troop", 1),
  56718. (store_script_param, ":item", 2),
  56719. (store_script_param, ":item_modifier", 3),
  56720.  
  56721. # (item_get_slot, ":difficulty", ":item", dplmc_slot_item_difficulty),
  56722. (item_get_difficulty, ":difficulty", ":item"),
  56723. (item_get_type, ":type", ":item"),
  56724. (try_begin),
  56725. (eq, ":difficulty", 0), # don't apply imod modifiers if item has no requirement
  56726. (else_try),
  56727. (eq, ":item_modifier", imod_stubborn),
  56728. (val_add, ":difficulty", 1),
  56729. (else_try),
  56730. (eq, ":item_modifier", imod_timid),
  56731. (val_sub, ":difficulty", 1),
  56732. (else_try),
  56733. (eq, ":item_modifier", imod_heavy),
  56734. (neq, ":type", itp_type_horse), #heavy horses don't increase difficulty
  56735. (val_add, ":difficulty", 1),
  56736. (else_try),
  56737. (eq, ":item_modifier", imod_strong),
  56738. (val_add, ":difficulty", 2),
  56739. (else_try),
  56740. (eq, ":item_modifier", imod_masterwork),
  56741. (val_add, ":difficulty", 4),
  56742. (try_end),
  56743.  
  56744. (item_get_type, ":type", ":item"),
  56745. (try_begin),
  56746. (eq, ":type", itp_type_horse),
  56747. (store_skill_level, ":skill", skl_riding, ":troop"),
  56748. (else_try),
  56749. (this_or_next|eq, ":type", itp_type_crossbow),
  56750. (this_or_next|eq, ":type", itp_type_one_handed_wpn),
  56751. (this_or_next|eq, ":type", itp_type_two_handed_wpn),
  56752. (this_or_next|eq, ":type", itp_type_polearm),
  56753. (this_or_next|eq, ":type", itp_type_head_armor),
  56754. (this_or_next|eq, ":type", itp_type_body_armor),
  56755. (this_or_next|eq, ":type", itp_type_foot_armor),
  56756. (eq, ":type", itp_type_hand_armor),
  56757. (store_attribute_level, ":skill", ":troop", ca_strength),
  56758. (else_try),
  56759. (eq, ":type", itp_type_shield),
  56760. (store_skill_level, ":skill", skl_shield, ":troop"),
  56761. (else_try),
  56762. (eq, ":type", itp_type_bow),
  56763. (store_skill_level, ":skill", skl_power_draw, ":troop"),
  56764. (else_try),
  56765. (eq, ":type", itp_type_thrown),
  56766. (store_skill_level, ":skill", skl_power_throw, ":troop"),
  56767. (try_end),
  56768.  
  56769. (try_begin),
  56770. (lt, ":skill", ":difficulty"),
  56771. (assign, reg0, 0),
  56772. (else_try),
  56773. (assign, reg0, 1),
  56774. (try_end),
  56775. ]),
  56776.  
  56777. #####################################################################
  56778. # gets an item's value
  56779. # Param1: item ID
  56780. # Param2: item modifier
  56781. #####################################################################
  56782. ("dplmc_get_item_value_with_imod", [ # returns the sell price based on the item's money value and its imod
  56783. (store_script_param, ":item", 1),
  56784. (store_script_param, ":imod", 2),
  56785. (store_item_value, ":score", ":item"),
  56786. (try_begin),
  56787. (eq, ":imod", imod_plain),
  56788. (val_mul, ":score", 100),
  56789. (else_try),
  56790. (eq, ":imod", imod_cracked),
  56791. (val_mul, ":score", 50),
  56792. (else_try),
  56793. (eq, ":imod", imod_rusty),
  56794. (val_mul, ":score", 55),
  56795. (else_try),
  56796. (eq, ":imod", imod_bent),
  56797. (val_mul, ":score", 65),
  56798. (else_try),
  56799. (eq, ":imod", imod_chipped),
  56800. (val_mul, ":score", 72),
  56801. (else_try),
  56802. (eq, ":imod", imod_battered),
  56803. (val_mul, ":score", 75),
  56804. (else_try),
  56805. (eq, ":imod", imod_poor),
  56806. (val_mul, ":score", 80),
  56807. (else_try),
  56808. (eq, ":imod", imod_crude),
  56809. (val_mul, ":score", 83),
  56810. (else_try),
  56811. (eq, ":imod", imod_old),
  56812. (val_mul, ":score", 86),
  56813. (else_try),
  56814. (eq, ":imod", imod_cheap),
  56815. (val_mul, ":score", 90),
  56816. (else_try),
  56817. (eq, ":imod", imod_fine),
  56818. (val_mul, ":score", 190),
  56819. (else_try),
  56820. (eq, ":imod", imod_well_made),
  56821. (val_mul, ":score", 250),
  56822. (else_try),
  56823. (eq, ":imod", imod_sharp),
  56824. (val_mul, ":score", 160),
  56825. (else_try),
  56826. (eq, ":imod", imod_balanced),
  56827. (val_mul, ":score", 350),
  56828. (else_try),
  56829. (eq, ":imod", imod_tempered),
  56830. (val_mul, ":score", 670),
  56831. (else_try),
  56832. (eq, ":imod", imod_deadly),
  56833. (val_mul, ":score", 850),
  56834. (else_try),
  56835. (eq, ":imod", imod_exquisite),
  56836. (val_mul, ":score", 1450),
  56837. (else_try),
  56838. (eq, ":imod", imod_masterwork),
  56839. (val_mul, ":score", 1750),
  56840. (else_try),
  56841. (eq, ":imod", imod_heavy),
  56842. (val_mul, ":score", 190),
  56843. (else_try),
  56844. (eq, ":imod", imod_strong),
  56845. (val_mul, ":score", 490),
  56846. (else_try),
  56847. (eq, ":imod", imod_powerful),
  56848. (val_mul, ":score", 320),
  56849. (else_try),
  56850. (eq, ":imod", imod_tattered),
  56851. (val_mul, ":score", 50),
  56852. (else_try),
  56853. (eq, ":imod", imod_ragged),
  56854. (val_mul, ":score", 70),
  56855. (else_try),
  56856. (eq, ":imod", imod_rough),
  56857. (val_mul, ":score", 60),
  56858. (else_try),
  56859. (eq, ":imod", imod_sturdy),
  56860. (val_mul, ":score", 170),
  56861. (else_try),
  56862. (eq, ":imod", imod_thick),
  56863. (val_mul, ":score", 260),
  56864. (else_try),
  56865. (eq, ":imod", imod_hardened),
  56866. (val_mul, ":score", 390),
  56867. (else_try),
  56868. (eq, ":imod", imod_reinforced),
  56869. (val_mul, ":score", 650),
  56870. (else_try),
  56871. (eq, ":imod", imod_superb),
  56872. (val_mul, ":score", 250),
  56873. (else_try),
  56874. (eq, ":imod", imod_lordly),
  56875. (val_mul, ":score", 1150),
  56876. (else_try),
  56877. (eq, ":imod", imod_lame),
  56878. (val_mul, ":score", 40),
  56879. (else_try),
  56880. (eq, ":imod", imod_swaybacked),
  56881. (val_mul, ":score", 60),
  56882. (else_try),
  56883. (eq, ":imod", imod_stubborn),
  56884. (val_mul, ":score", 90),
  56885. (else_try),
  56886. (eq, ":imod", imod_timid),
  56887. (val_mul, ":score", 180),
  56888. (else_try),
  56889. (eq, ":imod", imod_meek),
  56890. (val_mul, ":score", 180),
  56891. (else_try),
  56892. (eq, ":imod", imod_spirited),
  56893. (val_mul, ":score", 650),
  56894. (else_try),
  56895. (eq, ":imod", imod_champion),
  56896. (val_mul, ":score", 1450),
  56897. (else_try),
  56898. (eq, ":imod", imod_fresh),
  56899. (val_mul, ":score", 100),
  56900. (else_try),
  56901. (eq, ":imod", imod_day_old),
  56902. (val_mul, ":score", 100),
  56903. (else_try),
  56904. (eq, ":imod", imod_two_day_old),
  56905. (val_mul, ":score", 90),
  56906. (else_try),
  56907. (eq, ":imod", imod_smelling),
  56908. (val_mul, ":score", 40),
  56909. (else_try),
  56910. (eq, ":imod", imod_rotten),
  56911. (val_mul, ":score", 5),
  56912. (else_try),
  56913. (eq, ":imod", imod_large_bag),
  56914. (val_mul, ":score", 190),
  56915. (try_end),
  56916.  
  56917. (assign, reg0, ":score"),
  56918. ]),
  56919.  
  56920. #### Autoloot improved by rubik begin
  56921. # ("dplmc_init_item_base_score", set_item_base_score()),
  56922.  
  56923. ("dplmc_get_item_score_with_imod",
  56924. [# returns the score on the item's base score and its imod
  56925. (store_script_param, ":item", 1),
  56926. (store_script_param, ":imod", 2),
  56927.  
  56928. (item_get_type, ":type", ":item"),
  56929. (assign, ":imod_effect", 0), #default modifier
  56930. (try_begin),
  56931. # horse score = horse_speed*horse_armor*horse_sell_price
  56932. (eq, ":type", itp_type_horse),
  56933. # (item_get_slot, ":horse_speed", ":item", dplmc_slot_item_horse_speed),
  56934. # (item_get_slot, ":horse_armor", ":item", dplmc_slot_item_horse_armor),
  56935. (item_get_horse_speed, ":horse_speed", ":item"),
  56936. (item_get_body_armor, ":horse_armor", ":item"),
  56937. # (call_script, "script_dplmc_get_item_value_with_imod", ":item", ":imod"),
  56938. (item_get_value, ":i_score", ":item"),
  56939. # (assign, ":i_score", reg0),
  56940.  
  56941. ## SB : price now secondary (additive) instead of multiplicative with actual attributes
  56942. (item_get_horse_speed, ":horse_speed", ":item"),
  56943. (item_get_horse_maneuver, ":horse_manu", ":item"),
  56944. (item_get_body_armor, ":horse_armor", ":item"),
  56945. (item_get_horse_charge_damage, ":horse_charge", ":item"),
  56946. (item_get_hit_points, ":horse_health", ":item"),
  56947.  
  56948. #imodbits_horse_basic = imodbit_swaybacked|imodbit_lame|imodbit_spirited|imodbit_heavy|imodbit_stubborn
  56949. #imodbits_horse_good = imodbit_spirited|imodbit_heavy
  56950. (try_begin),
  56951. (eq, ":imod", imod_swaybacked),
  56952. (val_sub, ":horse_speed", 2),
  56953. (val_sub, ":horse_manu", 2),
  56954. (else_try), #do not pick lame horses at all other than last resort
  56955. (eq, ":imod", imod_lame),
  56956. (assign, ":horse_speed", 0),
  56957. (else_try),
  56958. (eq, ":imod", imod_heavy),
  56959. (val_add, ":horse_armor", 3),
  56960. (val_add, ":horse_charge", 4),
  56961. (val_add, ":horse_health", 10),
  56962. (else_try),
  56963. (eq, ":imod", imod_stubborn),
  56964. (val_add, ":horse_health", 5),
  56965. (else_try),
  56966. (eq, ":imod", imod_spirited),
  56967. (val_add, ":horse_speed", 1),
  56968. (val_add, ":horse_manu", 1),
  56969. (val_add, ":horse_armor", 1),
  56970. (val_add, ":horse_charge", 1),
  56971. (else_try),
  56972. (eq, ":imod", imod_champion),
  56973. (val_add, ":horse_speed", 2),
  56974. (val_add, ":horse_manu", 2),
  56975. (val_add, ":horse_armor", 2),
  56976. (val_add, ":horse_charge", 2),
  56977. (try_end),
  56978.  
  56979. (val_mul, ":horse_speed", ":horse_manu"),
  56980. (val_add, ":i_score", ":horse_speed"),
  56981.  
  56982. (val_mul, ":horse_charge", ":horse_armor"),
  56983. (val_mul, ":horse_charge", ":horse_health"),
  56984. (val_div, ":horse_charge", 100),#baseline hp
  56985. (val_add, ":i_score", ":horse_charge"),
  56986. (else_try),
  56987. # shield score = shield_size*shield_armor
  56988. (eq, ":type", itp_type_shield),
  56989. # (item_get_slot, ":shield_size", ":item", dplmc_slot_item_shield_size),
  56990. # (item_get_slot, ":shield_armor", ":item", dplmc_slot_item_shield_armor),
  56991.  
  56992. ## SB : factor in speed and height
  56993. (item_get_shield_height, ":shield_height", ":item"),
  56994. (item_get_weapon_length, ":shield_width", ":item"),
  56995. (item_get_body_armor, ":shield_armor", ":item"),
  56996. (item_get_speed_rating, ":shield_speed", ":item"),
  56997. (item_get_hit_points, ":shield_health", ":item"),
  56998.  
  56999. (try_begin),
  57000. (gt, ":shield_height", 0),
  57001. (val_mul, ":shield_width", ":shield_height"),
  57002. (set_fixed_point_multiplier, 100),
  57003. (store_mul, ":i_score", ":shield_width", 100),
  57004. (store_sqrt, ":i_score", ":i_score"),
  57005. (val_div, ":i_score", 100),
  57006. (else_try),
  57007. # (val_mul, ":shield_width", ":shield_width"),
  57008. (assign, ":i_score", ":shield_width"),
  57009. (try_end),
  57010.  
  57011.  
  57012. #imodbits_shield = imodbit_cracked | imodbit_battered |imodbit_thick | imodbit_reinforced
  57013. (try_begin),
  57014. # (eq, ":imod", imod_plain),
  57015. # (assign, ":imod_effect", 0),
  57016. # (else_try),
  57017. (eq, ":imod", imod_cracked),
  57018. (assign, ":imod_effect", -4),
  57019. (val_sub, ":shield_health", 56),
  57020. (else_try),
  57021. (eq, ":imod", imod_battered),
  57022. (assign, ":imod_effect", -2),
  57023. (val_sub, ":shield_health", 26),
  57024. (else_try),
  57025. (eq, ":imod", imod_hardened),
  57026. (assign, ":imod_effect", 3),
  57027. (else_try),
  57028. (eq, ":imod", imod_heavy),
  57029. (assign, ":imod_effect", 3),
  57030. (val_add, ":shield_health", 10),
  57031. (else_try),
  57032. (eq, ":imod", imod_thick),
  57033. (assign, ":imod_effect", 2),
  57034. (val_add, ":shield_health", 47),
  57035. (else_try),
  57036. (eq, ":imod", imod_reinforced),
  57037. (assign, ":imod_effect", 4),
  57038. (val_add, ":shield_health", 83),
  57039. (else_try),
  57040. (eq, ":imod", imod_lordly),
  57041. (assign, ":imod_effect", 6),
  57042. (val_add, ":shield_health", 155),
  57043. (try_end),
  57044.  
  57045. (val_add, ":shield_armor", ":imod_effect"),
  57046. (val_add, ":shield_armor", 5), # add 5 to make sure shield_armor greater than 0
  57047. (val_mul, ":i_score", ":shield_armor"),
  57048. (val_mul, ":i_score", ":shield_speed"),
  57049. (val_div, ":i_score", 92), #average speed of all Native's tableau
  57050. (val_add, ":i_score", ":shield_health"), #tie-breaker
  57051. (else_try),
  57052. # armor score = head_armor + body_armor + foot_armor
  57053. (this_or_next|eq, ":type", itp_type_head_armor),
  57054. (this_or_next|eq, ":type", itp_type_body_armor),
  57055. (this_or_next|eq, ":type", itp_type_foot_armor),
  57056. (eq, ":type", itp_type_hand_armor),
  57057. # (item_get_slot, ":head_armor", ":item", dplmc_slot_item_head_armor),
  57058. # (item_get_slot, ":body_armor", ":item", dplmc_slot_item_body_armor),
  57059. # (item_get_slot, ":leg_armor", ":item", dplmc_slot_item_leg_armor),
  57060. (item_get_head_armor, ":head_armor", ":item"),
  57061. (item_get_body_armor, ":body_armor", ":item"),
  57062. (item_get_leg_armor, ":leg_armor", ":item"),
  57063. (store_add, ":i_score", ":head_armor", ":body_armor"),
  57064. (val_add, ":i_score", ":leg_armor"), # get total base score
  57065.  
  57066. (try_begin),
  57067. # (eq, ":imod", imod_plain),
  57068. # (assign, ":imod_effect", 0),
  57069. # (else_try),
  57070. (eq, ":imod", imod_cracked),
  57071. (assign, ":imod_effect", -4),
  57072. (else_try),
  57073. (eq, ":imod", imod_rusty),
  57074. (assign, ":imod_effect", -3),
  57075. (else_try),
  57076. (eq, ":imod", imod_battered),
  57077. (assign, ":imod_effect", -2),
  57078. (else_try),
  57079. (eq, ":imod", imod_crude),
  57080. (assign, ":imod_effect", -1),
  57081. (else_try),
  57082. (eq, ":imod", imod_tattered),
  57083. (assign, ":imod_effect", -3),
  57084. (else_try),
  57085. (eq, ":imod", imod_ragged),
  57086. (assign, ":imod_effect", -2),
  57087. (else_try),
  57088. (eq, ":imod", imod_sturdy),
  57089. (assign, ":imod_effect", 1),
  57090. (else_try),
  57091. (eq, ":imod", imod_thick),
  57092. (assign, ":imod_effect", 2),
  57093. (else_try),
  57094. (eq, ":imod", imod_hardened),
  57095. (assign, ":imod_effect", 3),
  57096. (else_try),
  57097. (eq, ":imod", imod_reinforced),
  57098. (assign, ":imod_effect", 4),
  57099. (else_try),
  57100. (eq, ":imod", imod_lordly),
  57101. (assign, ":imod_effect", 6),
  57102. (try_end),
  57103.  
  57104. (try_begin), # for armors have 2 or 3 defence of different part
  57105. (neq, ":imod_effect", 0), # and item modifers that matter
  57106. (assign, ":imod_effect_mul", 0),
  57107. (try_begin), #do nothing if no armor part at all
  57108. (gt, ":head_armor", 0),
  57109. (store_add, ":temp_armor", ":head_armor", ":imod_effect"),
  57110. (try_begin), #only calculate if imod degrades item's rating
  57111. (gt, ":temp_armor", 0),
  57112. (val_add, ":imod_effect_mul", 1),
  57113. (else_try), #downgrade armor rating to 0 from bad armor instead of going negative
  57114. (val_sub, ":i_score", ":head_armor"),
  57115. (try_end),
  57116. (try_end),
  57117. (try_begin),
  57118. (gt, ":body_armor", 0),
  57119. (store_add, ":temp_armor", ":body_armor", ":imod_effect"),
  57120. (try_begin),
  57121. (gt, ":temp_armor", 0),
  57122. (val_add, ":imod_effect_mul", 1),
  57123. (else_try),
  57124. (val_sub, ":i_score", ":body_armor"),
  57125. (try_end),
  57126. (try_end),
  57127. (try_begin),
  57128. (gt, ":leg_armor", 0),
  57129. (store_add, ":temp_armor", ":leg_armor", ":imod_effect"),
  57130. (try_begin),
  57131. (gt, ":temp_armor", 0),
  57132. (val_add, ":imod_effect_mul", 1),
  57133. (else_try),
  57134. (val_sub, ":i_score", ":leg_armor"),
  57135. (try_end),
  57136. (try_end),
  57137.  
  57138. (val_mul, ":imod_effect", ":imod_effect_mul"),
  57139. (val_add, ":i_score", ":imod_effect"),
  57140. (try_end),
  57141. (else_try),
  57142. # weapon score = max(swing_damage , thrust_damage)
  57143. (this_or_next|eq, ":type", itp_type_one_handed_wpn),
  57144. (this_or_next|eq, ":type", itp_type_two_handed_wpn),
  57145. (this_or_next|eq, ":type", itp_type_bow),
  57146. (this_or_next|eq, ":type", itp_type_crossbow),
  57147. ##diplomacy start+ add extra types
  57148. #(this_or_next|eq, ":type", itp_type_pistol),
  57149. #(this_or_next|eq, ":type", itp_type_musket),
  57150. ##diplomacy end+
  57151. (eq, ":type", itp_type_polearm),
  57152. (item_get_swing_damage, ":swing_damage", ":item"),
  57153. (item_get_thrust_damage, ":thrust_damage", ":item"),
  57154. (assign, reg1, ":swing_damage"), #sb : debug
  57155. (assign, reg2, ":thrust_damage"), #sb : debug
  57156. # (item_get_slot, ":swing_damage", ":item", dplmc_slot_item_swing_damage),
  57157. # (item_get_slot, ":thrust_damage", ":item", dplmc_slot_item_thrust_damage),
  57158. (val_mod, ":swing_damage", 256), # get actual damage value
  57159. (val_mod, ":thrust_damage", 256),
  57160. (assign, ":i_score", ":swing_damage"),
  57161. (val_max, ":i_score", ":thrust_damage"),
  57162.  
  57163. ##SB : get additional parameters
  57164. (item_get_speed_rating, ":item_speed", ":item"),
  57165. (item_get_weapon_length, ":item_length", ":item"),
  57166. #shootspeed?
  57167.  
  57168. (try_begin),
  57169. # (eq, ":imod", imod_plain),
  57170. # (assign, ":imod_effect", 0),
  57171. # (else_try),
  57172. (eq, ":imod", imod_cracked),
  57173. (assign, ":imod_effect", -5),
  57174. (else_try),
  57175. (eq, ":imod", imod_rusty),
  57176. (assign, ":imod_effect", -3),
  57177. (else_try),
  57178. (eq, ":imod", imod_bent),
  57179. (assign, ":imod_effect", -3),
  57180. (val_sub, ":item_speed", 3),
  57181. (else_try),
  57182. (eq, ":imod", imod_chipped),
  57183. (assign, ":imod_effect", -1),
  57184. (else_try), #SB : add fine
  57185. (eq, ":imod", imod_fine),
  57186. (assign, ":imod_effect", 1),
  57187. (else_try),
  57188. (eq, ":imod", imod_balanced),
  57189. (assign, ":imod_effect", 3),
  57190. (val_add, ":item_speed", 3),
  57191. (else_try),
  57192. (eq, ":imod", imod_tempered),
  57193. (assign, ":imod_effect", 4),
  57194. (else_try),
  57195. (eq, ":imod", imod_masterwork),
  57196. (assign, ":imod_effect", 5),
  57197. (val_add, ":item_speed", 1),
  57198. (else_try),
  57199. (eq, ":imod", imod_heavy),
  57200. (assign, ":imod_effect", 2),
  57201. (val_sub, ":item_speed", 2),
  57202. (else_try),
  57203. (eq, ":imod", imod_strong),
  57204. (assign, ":imod_effect", 3),
  57205. (val_sub, ":item_speed", 3),
  57206. (try_end),
  57207.  
  57208. (val_add, ":i_score", ":imod_effect"),
  57209. (try_begin), #try to pre-filter civilian weapons that are improvised from being looted (clubs, scythes, etc that should be passed over)
  57210. (call_script, "script_cf_melee_weapon_is_civilian", ":item"),
  57211. (val_div, ":i_score", 3),
  57212. (try_end),
  57213. (try_begin), #item_get_missile_speed is technically an important rating for ranged weapons, but we'll pretend NPCs can't math
  57214. (this_or_next|is_between, ":type", itp_type_bow, itp_type_thrown),
  57215. (is_between, ":type", itp_type_pistol, itp_type_bullets),
  57216. (val_mul, ":i_score", ":item_speed"),
  57217. (else_try), #assume base of 100 speed, 100 length
  57218. (this_or_next|eq, ":type", itp_type_one_handed_wpn),
  57219. (eq, ":type", itp_type_two_handed_wpn),
  57220. (val_mul, ":item_length", ":item_speed"),
  57221. (val_mul, ":i_score", ":item_length"),
  57222. (else_try), #length priority over speed
  57223. (eq, ":type", itp_type_polearm),
  57224. (try_begin), #unless they're slashing
  57225. (gt, ":thrust_damage", ":swing_damage"),
  57226. (item_has_property, ":item", itp_couchable),
  57227. # (item_has_property, ":item", itp_cant_use_on_horseback),
  57228. (ge, ":item_length", dplmc_pike_length_cutoff),
  57229. (val_sub, ":item_length", 50), #offset
  57230. #no penalty for war spear range
  57231. (val_max, ":item_length", 100),
  57232. (val_mul, ":item_length", 4),
  57233. #item speed rounded off when we couch
  57234. (val_add, ":item_speed", 25),
  57235. (val_div, ":item_speed", 10),
  57236. # (val_mul, ":item_speed", 2),
  57237. (try_end),
  57238. (val_mul, ":item_length", ":item_speed"),
  57239. (val_mul, ":i_score", ":item_length"),
  57240. (try_end),
  57241. (else_try),
  57242. # ammo score = (thrust_damage + imod_effect)*2
  57243. # a_large_bag will make score added by 1 to discriminate the same ammo with the plain modifier
  57244. (this_or_next|eq, ":type", itp_type_arrows),
  57245. (this_or_next|eq, ":type", itp_type_bolts),
  57246. (eq, ":type", itp_type_thrown),
  57247. (item_get_thrust_damage, ":thrust_damage", ":item"),
  57248. (val_mod, ":thrust_damage", 256), # get actual damage value
  57249. (store_add, ":i_score", ":thrust_damage", 3), # SB : make sure imods do not reduce damage to 0
  57250.  
  57251. #imodbits_missile = imodbit_bent | imodbit_large_bag
  57252. #imodbits_thrown = imodbit_bent | imodbit_heavy| imodbit_balanced| imodbit_large_bag
  57253. (try_begin),
  57254. (eq, ":imod", imod_plain),
  57255. (val_mul, ":i_score", 2),
  57256. (else_try),
  57257. (eq, ":imod", imod_large_bag),
  57258. (val_mul, ":i_score", 2),
  57259. (val_add, ":i_score", 1),
  57260. (else_try),
  57261. (eq, ":imod", imod_bent),
  57262. (val_sub, ":i_score", 3),
  57263. (val_mul, ":i_score", 2),
  57264. (else_try),
  57265. (eq, ":imod", imod_heavy),
  57266. (val_add, ":i_score", 2),
  57267. (val_mul, ":i_score", 2),
  57268. (else_try),
  57269. (eq, ":imod", imod_balanced),
  57270. (val_add, ":i_score", 3),
  57271. (val_mul, ":i_score", 2),
  57272. (try_end),
  57273. (try_end),
  57274.  
  57275. (assign, reg0, ":i_score"),
  57276. ]),
  57277. #### Autoloot improved by rubik end
  57278.  
  57279. ###################
  57280. # Used in conversations
  57281.  
  57282. ("dplmc_print_wpn_upgrades_to_s0", [
  57283. (store_script_param_1, ":troop"),
  57284.  
  57285. (str_store_string, s0, "str_empty_string"),
  57286. (troop_get_slot, ":upg", ":troop", dplmc_slot_upgrade_wpn_0),
  57287. (troop_get_inventory_slot, ":item", ":troop", 0),
  57288. (try_begin),
  57289. (ge, ":item", 0),
  57290. (str_store_item_name, s10, ":item"),
  57291. (else_try),
  57292. (str_store_string, s10, "str_dplmc_none"),
  57293. (try_end),
  57294. (val_add, ":upg", "str_dplmc_hero_wpn_slot_none"),
  57295. (str_store_string, s1, ":upg"),
  57296. (str_store_string, s0, "@{s0}^{s1}"),
  57297. (troop_get_slot, ":upg", ":troop", dplmc_slot_upgrade_wpn_1),
  57298. (troop_get_inventory_slot, ":item", ":troop", 1),
  57299. (try_begin),
  57300. (ge, ":item", 0),
  57301. (str_store_item_name, s10, ":item"),
  57302. (else_try),
  57303. (str_store_string, s10, "str_dplmc_none"),
  57304. (try_end),
  57305. (val_add, ":upg", "str_dplmc_hero_wpn_slot_none"),
  57306. (str_store_string, s1, ":upg"),
  57307. (str_store_string, s0, "@{s0}^{s1}"),
  57308. (troop_get_slot, ":upg", ":troop", dplmc_slot_upgrade_wpn_2),
  57309. (troop_get_inventory_slot, ":item", ":troop", 2),
  57310. (try_begin),
  57311. (ge, ":item", 0),
  57312. (str_store_item_name, s10, ":item"),
  57313. (else_try),
  57314. (str_store_string, s10, "str_dplmc_none"),
  57315. (try_end),
  57316. (val_add, ":upg", "str_dplmc_hero_wpn_slot_none"),
  57317. (str_store_string, s1, ":upg"),
  57318. (str_store_string, s0, "@{s0}^{s1}"),
  57319. (troop_get_slot, ":upg", ":troop", dplmc_slot_upgrade_wpn_3),
  57320. (troop_get_inventory_slot, ":item", ":troop", 3),
  57321. (try_begin),
  57322. (ge, ":item", 0),
  57323. (str_store_item_name, s10, ":item"),
  57324. (else_try),
  57325. (str_store_string, s10, "str_dplmc_none"),
  57326. (try_end),
  57327. (val_add, ":upg", "str_dplmc_hero_wpn_slot_none"),
  57328. (str_store_string, s1, ":upg"),
  57329. (str_store_string, s0, "@{s0}^{s1}"),
  57330. ]),
  57331.  
  57332. ################################
  57333. # Copy this troop's upgrade options to everyone
  57334.  
  57335. # ("dplmc_copy_upgrade_to_all_heroes", [
  57336. # (store_script_param_1, ":troop"),
  57337.  
  57338. # (troop_get_slot,":upg_armor", ":troop",dplmc_slot_upgrade_armor),
  57339. # (troop_get_slot,":upg_horse",":troop",dplmc_slot_upgrade_horse),
  57340. # (troop_get_slot,":upg_wpn0",":troop",dplmc_slot_upgrade_wpn_0),
  57341. # (troop_get_slot,":upg_wpn1",":troop",dplmc_slot_upgrade_wpn_1),
  57342. # (troop_get_slot,":upg_wpn2",":troop",dplmc_slot_upgrade_wpn_2),
  57343. # (troop_get_slot,":upg_wpn3",":troop",dplmc_slot_upgrade_wpn_3),
  57344.  
  57345. # (try_for_range, ":hero", companions_begin, companions_end),
  57346. # (troop_set_slot,":hero",dplmc_slot_upgrade_armor,":upg_armor"),
  57347. # (troop_set_slot,":hero",dplmc_slot_upgrade_horse,":upg_horse"),
  57348. # (troop_set_slot,":hero",dplmc_slot_upgrade_wpn_0,":upg_wpn0"),
  57349. # (troop_set_slot,":hero",dplmc_slot_upgrade_wpn_1,":upg_wpn1"),
  57350. # (troop_set_slot,":hero",dplmc_slot_upgrade_wpn_2,":upg_wpn2"),
  57351. # (troop_set_slot,":hero",dplmc_slot_upgrade_wpn_3,":upg_wpn3"),
  57352. # (try_end),
  57353. # ]),
  57354.  
  57355. ####################################
  57356. # Let each hero loot from the pool
  57357.  
  57358. ("dplmc_auto_loot_all", [
  57359. (store_script_param_1, ":pool_troop"),
  57360. (store_script_param_2, ":sreg"),
  57361. # for all the NPCs, in order of party listing
  57362.  
  57363. (party_get_num_companion_stacks, ":num_stacks","p_main_party"),
  57364. (try_for_range, ":i_stack", 0, ":num_stacks"),
  57365. (party_stack_get_troop_id, ":this_hero","p_main_party",":i_stack"),
  57366. (is_between, ":this_hero", companions_begin, companions_end),
  57367. #SB : show strings for first iteration
  57368. (call_script, "script_dplmc_auto_loot_troop", ":this_hero", ":pool_troop", ":sreg"),
  57369. (val_add, ":sreg", 1),
  57370. (try_end),
  57371.  
  57372. #SB : get starting index once again
  57373. (store_script_param_2, ":sreg"),
  57374. # pick up any discards and format string
  57375. (try_for_range, ":i_stack", 0, ":num_stacks"),
  57376. (party_stack_get_troop_id, ":this_hero","p_main_party",":i_stack"),
  57377. (is_between, ":this_hero", companions_begin, companions_end),
  57378. (try_begin), #if first iteration picked up nothing
  57379. (str_is_empty, ":sreg"),
  57380. (call_script, "script_dplmc_auto_loot_troop", ":this_hero", ":pool_troop", ":sreg"),
  57381. (else_try), #do not overwrite string from first iteration
  57382. (call_script, "script_dplmc_auto_loot_troop", ":this_hero", ":pool_troop", -1),
  57383. (try_end),
  57384. (try_begin), #skip the first one
  57385. (gt, ":sreg", dplmc_loot_string),
  57386. (neg|str_is_empty, ":sreg"), # in case second hasn't picked up changes either
  57387. (str_store_string_reg, s1, ":sreg"),
  57388. (str_store_string_reg, s0, dplmc_loot_string),
  57389. (str_store_string, dplmc_loot_string, "str_dplmc_s0_newline_s1"),
  57390. (try_end),
  57391. (val_add, ":sreg", 1), #go to next string register
  57392. (try_end),
  57393.  
  57394. #Done. Now sort the remainder
  57395. (troop_sort_inventory, ":pool_troop"),
  57396.  
  57397. ]),
  57398.  
  57399.  
  57400. ####################################
  57401. # let this troop take its pick from the loot pool
  57402.  
  57403. ("dplmc_auto_loot_troop", [
  57404. # (try_begin),
  57405. (store_script_param, ":troop", 1),
  57406. (store_script_param, ":pool", 2),
  57407. (store_script_param, ":sreg", 3), #SB : new param for storing changes
  57408.  
  57409. (troop_get_slot,":upg_armor", ":troop",dplmc_slot_upgrade_armor),
  57410. (troop_get_slot,":upg_horses",":troop",dplmc_slot_upgrade_horse),
  57411.  
  57412. # dump whatever rubbish is in the main inventory
  57413. (troop_get_inventory_capacity, ":inv_cap", ":troop"),
  57414. (try_for_range, ":i_slot", dplmc_ek_alt_items_end, ":inv_cap"), #SB raise from 10, skip over civilian stuff
  57415. (troop_get_inventory_slot, ":item", ":troop", ":i_slot"),
  57416. (ge, ":item", 0),
  57417. (troop_get_inventory_slot_modifier, ":imod", ":troop", ":i_slot"),
  57418. (troop_add_item, ":pool", ":item", ":imod"), #put it back in the pool
  57419. (troop_set_inventory_slot, ":troop", ":i_slot", -1), # delete it
  57420. (try_end),
  57421.  
  57422. #clear slot
  57423. # (try_for_range, ":slot_no", dplmc_slot_upgrade_wpn_0, dplmc_slot_upgrade_wpn_3 + 1),
  57424. # (troop_slot_eq, ":troop", ":slot_no", 0), #0 is keep
  57425. # (troop_set_slot, "trp_heroes_end", ":slot_no", 999999),
  57426. # (else_try), #otherwise we reset to default
  57427. # (troop_set_slot, "trp_heroes_end", ":slot_no", -1),
  57428. # (try_end),
  57429.  
  57430. #SB : loop, calculate current item's score
  57431. # (assign, ":slot_no", dplmc_slot_upgrade_wpn_0 - 1),
  57432. (try_for_range, ":item_slot", ek_item_0, ek_head),
  57433. #SB : clear the pool troop's ek_slots
  57434. (troop_set_inventory_slot, ":pool", ":item_slot", -1), #delete it
  57435. (store_add, ":slot_no", dplmc_slot_upgrade_wpn_0, ":item_slot"), #pre-increment
  57436. (troop_get_slot, ":item_preference", ":troop", ":slot_no"),
  57437. (gt, ":item_preference", 0), #0 is keep
  57438. (troop_get_inventory_slot, ":item", ":troop", ":item_slot"),
  57439. (ge, ":item", 0), #initial item check
  57440. (troop_get_inventory_slot_modifier, ":imod", ":troop", ":item_slot"),
  57441.  
  57442. (try_begin),
  57443. (store_mod, ":item_type", ":item_preference", meta_itp_mask),
  57444. (item_get_type, ":itp", ":item"),
  57445. (neq, ":itp", ":item_type"),
  57446. (troop_set_inventory_slot, ":troop", ":item_slot", -1), #delete it
  57447. (troop_add_item, ":pool", ":item", ":imod"), # chuck it in the pool
  57448. (assign, ":item", -1), #so we fail this loop
  57449. (try_end),
  57450. (ge, ":item", 0),
  57451. #SB : cache the original equipment to see changes
  57452. (troop_set_inventory_slot, ":pool", ":item_slot", ":item"),
  57453. (troop_set_inventory_slot_modifier, ":pool", ":item_slot", ":imod"),
  57454.  
  57455. (call_script, "script_dplmc_get_item_score_with_imod", ":item", ":imod"),
  57456. (assign, ":cur_value", reg0),
  57457. #check to see whether damage is preferred
  57458. (try_begin),
  57459. (call_script, "script_cf_item_type_has_advanced_autoloot", ":item_type"),
  57460. (store_div, ":dmg_type", ":item_preference", meta_dmg_mask),
  57461. (neq, ":dmg_type", 0),
  57462. (item_get_swing_damage, ":swing_damage", ":item"),
  57463. (item_get_thrust_damage, ":thrust_damage", ":item"),
  57464. (try_begin),
  57465. (ge, ":swing_damage", ":thrust_damage"),
  57466. (item_get_swing_damage_type, ":item_dmg_type", ":item"),
  57467. (else_try),
  57468. (lt, ":swing_damage", ":thrust_damage"),
  57469. (item_get_thrust_damage_type, ":item_dmg_type", ":item"),
  57470. (try_end),
  57471. #check if it matches preference
  57472. (val_add, ":item_dmg_type", 1),
  57473. (eq, ":dmg_type", ":item_dmg_type"),
  57474. (val_mul, ":cur_value", 4),
  57475. (try_end),
  57476. (troop_set_slot, "trp_heroes_end", ":slot_no", ":cur_value"),
  57477. (else_try),
  57478. (eq, ":item_preference", 0), #0 is keep
  57479. (troop_set_slot, "trp_heroes_end", ":slot_no", 999999),
  57480. (else_try), #whether no item or discarded
  57481. (lt, ":item", 0),
  57482. (troop_set_slot, "trp_heroes_end", ":slot_no", 0),
  57483. (try_end),
  57484.  
  57485. # (try_for_range, ":slot_no", dplmc_slot_upgrade_wpn_0, dplmc_slot_upgrade_wpn_3 + 1),
  57486. # (troop_get_slot, reg0, ":troop", ":slot_no"),
  57487. # (troop_get_slot, reg1, "trp_heroes_end", ":slot_no"),
  57488. # (store_sub, reg2, ":slot_no", dplmc_slot_upgrade_wpn_0),
  57489. # (troop_get_inventory_slot, ":item", ":troop", reg2),
  57490. # (try_begin),
  57491. # (eq, ":item", -1),
  57492. # (str_store_string, s1, "str_dplmc_none"),
  57493. # (else_try),
  57494. # (str_store_item_name, s1, ":item"),
  57495. # (try_end),
  57496.  
  57497. # (display_message, "@upgrading slot {reg2} with {reg0}, cur score for {s1}: {reg1}"),
  57498. # (try_end),
  57499.  
  57500. (try_for_range, ":i_slot", ek_head, ek_food),
  57501. (troop_get_inventory_slot, ":item", ":troop", ":i_slot"),
  57502. (troop_set_inventory_slot, ":pool", ":i_slot", -1), #delete it
  57503. (ge, ":item", 0),
  57504. (troop_set_inventory_slot, ":pool", ":i_slot", ":item"), #store it
  57505. (troop_get_inventory_slot_modifier, ":imod", ":troop", ":i_slot"),
  57506. (troop_set_inventory_slot_modifier, ":pool", ":i_slot", ":imod"), #store it
  57507. (try_begin),
  57508. (neq, ":upg_armor", 0), # we're upgrading armors
  57509. (is_between, ":i_slot", ek_head, ek_horse), # it's an armor slot
  57510. (troop_set_inventory_slot, ":troop", ":i_slot", -1), #delete it
  57511. (troop_add_item, ":pool", ":item", ":imod"), # chuck it in the pool
  57512. (else_try),
  57513. (neq, ":upg_horses", 0), # we're upgrading horses
  57514. (eq, ":i_slot", ek_horse), # it's a horse slot
  57515. (troop_set_inventory_slot, ":troop", ":i_slot", -1), #delete it
  57516. (troop_add_item, ":pool", ":item", ":imod"), # chuck it in the pool
  57517. (try_end),
  57518. (try_end),
  57519.  
  57520. # clear best matches
  57521. (assign, ":best_helmet_slot", -1),
  57522. (assign, ":best_helmet_val", 0),
  57523. (assign, ":best_body_slot", -1),
  57524. (assign, ":best_body_val", 0),
  57525. (assign, ":best_boots_slot", -1),
  57526. (assign, ":best_boots_val", 0),
  57527. (assign, ":best_gloves_slot", -1),
  57528. (assign, ":best_gloves_val", 0),
  57529. (assign, ":best_horse_slot", -1),
  57530. (assign, ":best_horse_val", 0),
  57531.  
  57532. # Now search through the pool for the best items
  57533. (troop_get_inventory_capacity, ":inv_cap", ":pool"),
  57534. (try_for_range, ":i_slot", ek_food + 1, ":inv_cap"), #SB: skip cached items
  57535. (troop_get_inventory_slot, ":item", ":pool", ":i_slot"),
  57536. (ge, ":item", 0),
  57537. (troop_get_inventory_slot_modifier, ":imod", ":pool", ":i_slot"),
  57538. (call_script, "script_dplmc_troop_can_use_item", ":troop", ":item", ":imod"),
  57539. (eq, reg0, 1), # can use
  57540. #(call_script, "script_get_item_value_with_imod", ":item", ":imod"), # use the following instead
  57541.  
  57542. #### Autoloot improved by rubik begin
  57543. # get item_score instead of price
  57544. (call_script, "script_dplmc_get_item_score_with_imod", ":item", ":imod"),
  57545. #### Autoloot improved by rubik end
  57546. (assign, ":score", reg0),
  57547. (item_get_type, ":item_type", ":item"),
  57548.  
  57549. (try_begin),
  57550. (eq, ":item_type", itp_type_horse), #it's a horse
  57551. (eq, ":upg_horses", 1), # we're upgrading horses
  57552. (gt, ":score", ":best_horse_val"),
  57553. (assign, ":best_horse_slot", ":i_slot"),
  57554. (assign, ":best_horse_val", ":score"),
  57555. (else_try), #SB : move armor checks here
  57556. (is_between, ":item_type", itp_type_head_armor, itp_type_hand_armor + 1), # we're checking armor
  57557. (eq, ":upg_armor", 1), # we're upgrading armor
  57558. (try_begin),
  57559. (eq, ":item_type", itp_type_head_armor),
  57560. (gt, ":score", ":best_helmet_val"),
  57561. (assign, ":best_helmet_slot", ":i_slot"),
  57562. (assign, ":best_helmet_val", ":score"),
  57563. (else_try),
  57564. (eq, ":item_type", itp_type_body_armor),
  57565. (gt, ":score", ":best_body_val"),
  57566. (assign, ":best_body_slot", ":i_slot"),
  57567. (assign, ":best_body_val", ":score"),
  57568. (else_try),
  57569. (eq, ":item_type", itp_type_foot_armor),
  57570. (gt, ":score", ":best_boots_val"),
  57571. (assign, ":best_boots_slot", ":i_slot"),
  57572. (assign, ":best_boots_val", ":score"),
  57573. (else_try),
  57574. (eq, ":item_type", itp_type_hand_armor),
  57575. (gt, ":score", ":best_gloves_val"),
  57576. (assign, ":best_gloves_slot", ":i_slot"),
  57577. (assign, ":best_gloves_val", ":score"),
  57578. (try_end),
  57579. (else_try), #SB : move weapon checks back here
  57580. (assign, ":limit", dplmc_slot_upgrade_wpn_3 + 1),
  57581. (try_begin), #check for denying use on horseback
  57582. (this_or_next|gt, ":best_horse_val", 0),
  57583. (eq, ":upg_horses", 1), # we're upgrading horses
  57584. (this_or_next|item_has_property, ":item", itp_cant_use_on_horseback),
  57585. (this_or_next|item_has_property, ":item", itp_cant_reload_on_horseback),
  57586. (item_has_property, ":item", itp_cant_reload_while_moving_mounted),
  57587. (assign, ":limit", 0),
  57588. (try_end),
  57589. (try_for_range, ":slot_no", dplmc_slot_upgrade_wpn_0, ":limit"),
  57590. (troop_get_slot, ":item_preference", ":troop", ":slot_no"),
  57591. (neq, ":item_preference", 0), #not keep current
  57592. (store_div, ":damage_type", ":item_preference", meta_dmg_mask),
  57593. (val_mod, ":item_preference", meta_dmg_mask), #get the itp + meta
  57594. (call_script, "script_item_get_type_aux", ":item"),
  57595. (this_or_next|eq, ":item_preference", reg0), #either same meta-type
  57596. (eq, ":item_preference", ":item_type"), #or matching base itp
  57597.  
  57598. #check to see whether damage is preferred
  57599. (try_begin),
  57600. (neq, ":damage_type", 0),
  57601. (item_get_swing_damage, ":swing_damage", ":item"),
  57602. (item_get_thrust_damage, ":thrust_damage", ":item"),
  57603. (try_begin),
  57604. (ge, ":swing_damage", ":thrust_damage"),
  57605. (item_get_swing_damage_type, ":item_dmg_type", ":item"),
  57606. (else_try),
  57607. (lt, ":swing_damage", ":thrust_damage"),
  57608. (item_get_thrust_damage_type, ":item_dmg_type", ":item"),
  57609. (try_end),
  57610. #check if it matches preference
  57611. (val_add, ":item_dmg_type", 1),
  57612. (eq, ":damage_type", ":item_dmg_type"),
  57613. (val_mul, ":score", 4),
  57614. (try_end),
  57615. #if current score is not ge, replace item and score
  57616. (neg|troop_slot_ge, "trp_heroes_end", ":slot_no", ":score"),
  57617. (troop_set_slot, "trp_heroes_end", ":slot_no", ":score"),
  57618. (assign, ":limit", -1), #loop break
  57619. (store_sub, ":item_slot", ":slot_no", dplmc_slot_upgrade_wpn_0), #ek item slots
  57620. (troop_get_inventory_slot, ":item_no", ":troop", ":item_slot"),
  57621. (try_begin),
  57622. (eq, ":item_no", -1),
  57623. (troop_set_inventory_slot, ":pool", ":i_slot", -1),
  57624. (else_try), #replace into pool
  57625. (troop_get_inventory_slot_modifier, ":imod_no", ":troop", ":item_slot"),
  57626. (troop_set_inventory_slot, ":pool", ":i_slot", ":item_no"),
  57627. (troop_set_inventory_slot_modifier, ":pool", ":i_slot", ":imod_no"),
  57628. (try_end),
  57629. (troop_set_inventory_slot, ":troop", ":item_slot", ":item"),
  57630. (troop_set_inventory_slot_modifier, ":troop", ":item_slot", ":imod"),
  57631. # (try_begin),
  57632. # (str_store_item_name, s1, ":item"),
  57633. # (try_begin),
  57634. # (eq, ":item_no", -1),
  57635. # (str_store_string, s2, "str_dplmc_none"),
  57636. # (else_try),
  57637. # (str_store_item_name, s2, ":item_no"),
  57638. # (try_end),
  57639. # (assign, reg1, ":score"),
  57640. # (display_message, "@{s1} better than {s2}, score of {reg1}"),
  57641. # (try_end),
  57642. (try_end),
  57643. (try_end),
  57644. (try_end),
  57645.  
  57646. # Now we know which ones are the best. Give them to the troop.
  57647. (try_begin),
  57648. (assign, ":best_slot", ":best_helmet_slot"),
  57649. (ge, ":best_slot", 0),
  57650. (troop_get_inventory_slot, ":item", ":pool", ":best_slot"),
  57651. (ge, ":item", 0),
  57652. (troop_get_inventory_slot_modifier, ":imod", ":pool", ":best_slot"),
  57653. (troop_set_inventory_slot, ":troop", ek_head, ":item"),
  57654. (troop_set_inventory_slot_modifier, ":troop", ek_head, ":imod"),
  57655. (troop_set_inventory_slot, ":pool", ":best_slot", -1),
  57656. (try_end),
  57657.  
  57658. (try_begin),
  57659. (assign, ":best_slot", ":best_body_slot"),
  57660. (ge, ":best_slot", 0),
  57661. (troop_get_inventory_slot, ":item", ":pool", ":best_slot"),
  57662. (ge, ":item", 0),
  57663. (troop_get_inventory_slot_modifier, ":imod", ":pool", ":best_slot"),
  57664. (troop_set_inventory_slot, ":troop", ek_body, ":item"),
  57665. (troop_set_inventory_slot_modifier, ":troop", ek_body, ":imod"),
  57666. (troop_set_inventory_slot, ":pool", ":best_slot", -1),
  57667. (try_end),
  57668.  
  57669. (try_begin),
  57670. (assign, ":best_slot", ":best_boots_slot"),
  57671. (ge, ":best_slot", 0),
  57672. (troop_get_inventory_slot, ":item", ":pool", ":best_slot"),
  57673. (ge, ":item", 0),
  57674. (troop_get_inventory_slot_modifier, ":imod", ":pool", ":best_slot"),
  57675. (troop_set_inventory_slot, ":troop", ek_foot, ":item"),
  57676. (troop_set_inventory_slot_modifier, ":troop", ek_foot, ":imod"),
  57677. (troop_set_inventory_slot, ":pool", ":best_slot", -1),
  57678. (try_end),
  57679.  
  57680. (try_begin),
  57681. (assign, ":best_slot", ":best_gloves_slot"),
  57682. (ge, ":best_slot", 0),
  57683. (troop_get_inventory_slot, ":item", ":pool", ":best_slot"),
  57684. (ge, ":item", 0),
  57685. (troop_get_inventory_slot_modifier, ":imod", ":pool", ":best_slot"),
  57686. (troop_set_inventory_slot, ":troop", ek_gloves, ":item"),
  57687. (troop_set_inventory_slot_modifier, ":troop", ek_gloves, ":imod"),
  57688. (troop_set_inventory_slot, ":pool", ":best_slot", -1),
  57689. (try_end),
  57690.  
  57691. (try_begin),
  57692. (assign, ":best_slot", ":best_horse_slot"),
  57693. (ge, ":best_slot", 0),
  57694. (troop_get_inventory_slot, ":item", ":pool", ":best_slot"),
  57695. (ge, ":item", 0),
  57696. (troop_get_inventory_slot_modifier, ":imod", ":pool", ":best_slot"),
  57697. (troop_set_inventory_slot, ":troop", ek_horse, ":item"),
  57698. (troop_set_inventory_slot_modifier, ":troop", ek_horse, ":imod"),
  57699. (troop_set_inventory_slot, ":pool", ":best_slot", -1),
  57700. (try_end),
  57701.  
  57702. # (try_for_range, ":i_slot", ek_item_0, ek_head),
  57703. # (store_add, ":trp_slot", ":i_slot", dplmc_slot_upgrade_wpn_0),
  57704. # (troop_get_slot, ":type", ":troop", ":trp_slot"),
  57705. # (gt, ":type", 0), #we're upgrading for this slot
  57706. # (call_script, "script_dplmc_scan_for_best_item_of_type", ":pool", ":type", ":troop"), #search for the best
  57707. # (assign, ":best_slot", reg0),
  57708. # (neq, ":best_slot", -1), #got something
  57709. # (troop_get_inventory_slot, ":item", ":pool", ":best_slot"), #get it
  57710. # (ge, ":item", 0),
  57711. # (troop_get_inventory_slot_modifier, ":imod", ":pool", ":best_slot"),
  57712. # (troop_set_inventory_slot, ":pool", ":best_slot", -1), #remove from pool
  57713. # (troop_set_inventory_slot, ":troop", ":i_slot", ":item"), #add to slot
  57714. # (troop_set_inventory_slot_modifier, ":troop", ":i_slot", ":imod"),
  57715. # (try_end),
  57716.  
  57717. #SB : string storage
  57718. (try_begin),
  57719. (neq, ":sreg", -1),
  57720. (str_store_troop_name, ":sreg", ":troop"),
  57721. (assign, ":num_changes", 0),
  57722. (assign, ":last_change", 0),
  57723. #three cases : discarded item -1, no change 0, change 1 (upgraded/swapped depending on item flags)
  57724. (try_for_range, ":i_slot", ek_item_0, ek_food),
  57725. (troop_get_inventory_slot, ":old_item", ":pool", ":i_slot"),
  57726. (troop_get_inventory_slot, ":new_item", ":troop", ":i_slot"),
  57727. (try_begin),
  57728. (gt, ":old_item", -1),
  57729. (troop_get_inventory_slot_modifier, ":old_imod", ":pool", ":i_slot"),
  57730. (store_add, ":imod_no", ":old_imod", "str_imod_plain"),
  57731. # (str_store_string, s10, ":imod_no"),
  57732. # (str_store_item_name, s20, ":old_item"),
  57733. # (display_message, "@old:{s10}{s20}"),
  57734. (else_try),
  57735. (assign, ":old_imod", imod_plain),
  57736. (try_end),
  57737. (try_begin),
  57738. (gt, ":new_item", -1),
  57739. (troop_get_inventory_slot_modifier, ":new_imod", ":troop", ":i_slot"),
  57740. (store_add, ":imod_no", ":new_imod", "str_imod_plain"),
  57741. # (str_store_string, s10, ":imod_no"),
  57742. # (str_store_item_name, s20, ":new_item"),
  57743. # (display_message, "@new:{s10}{s20}"),
  57744. (else_try),
  57745. (assign, ":new_imod", imod_plain),
  57746. (try_end),
  57747.  
  57748. # #placeholder swap strings
  57749. # (str_clear, s0), #sreg
  57750. # (str_clear, s1), #new string
  57751. # (str_clear, s10), #imod
  57752. # (str_clear, s20), #item
  57753.  
  57754. (try_begin), #keep current
  57755. (is_between, ":i_slot", ek_item_0, ek_head),
  57756. (store_add, ":upgrade_slot", ":i_slot", dplmc_slot_upgrade_wpn_0),
  57757. (troop_slot_eq, ":troop", ":upgrade_slot", 0),
  57758. (assign, ":item_changed", 0),
  57759. (else_try), #same
  57760. (eq, ":new_item", ":old_item"),
  57761. (eq, ":old_imod", ":new_imod"),
  57762. (assign, ":item_changed", 0),
  57763. (else_try), #discarded
  57764. (eq, ":new_item", -1),
  57765. (gt, ":old_item", -1),
  57766. (assign, ":item_changed", 2),
  57767. (assign, ":item_no", ":old_item"),
  57768. (assign, ":imod_no", ":old_imod"),
  57769. (else_try), #swapped/equipped
  57770. (gt, ":new_item", -1),
  57771. (assign, ":item_changed", 1),
  57772. (assign, ":item_no", ":new_item"),
  57773. (assign, ":imod_no", ":new_imod"),
  57774. (try_end),
  57775.  
  57776. #build string
  57777. (try_begin),
  57778. (gt, ":item_changed", 0),
  57779. (val_add, ":imod_no", "str_imod_plain"),
  57780. (str_store_string, s10, ":imod_no"), #this comes with a space
  57781. (str_store_item_name, s20, ":item_no"),
  57782.  
  57783. (try_begin),
  57784. (neq, ":last_change", 1),
  57785. (eq, ":item_changed", 1),
  57786. (str_store_string, s1, "@equipped {s10}{s20}"),
  57787. (else_try),
  57788. (neq, ":last_change", 2),
  57789. (eq, ":item_changed", 2),
  57790. (str_store_string, s1, "@discarded {s10}{s20}"),
  57791. (else_try), #same as before, no need to qualify
  57792. (str_store_string, s1, "@{s10}{s20}"),
  57793. (try_end),
  57794. (str_store_string_reg, s0, ":sreg"),
  57795. (try_begin), #no comma for first part
  57796. (eq, ":num_changes", 0),
  57797. (str_store_string, ":sreg", "str_s0_s1"),
  57798. (else_try),
  57799. (str_store_string, ":sreg", "str_dplmc_s0_comma_s1"),
  57800. (try_end),
  57801. # (assign, reg1, ":num_changes"),
  57802. # (display_message, "@{reg1} : {s1}"),
  57803. (val_add, ":num_changes", ":item_changed"),
  57804. (assign, ":last_change", ":item_changed"),
  57805. (try_end),
  57806. (try_end),
  57807. (try_begin), #discard if we didn't touch the inventory at all
  57808. (le, ":num_changes", 0), #this is a flag, not a count
  57809. (str_clear, ":sreg"),
  57810. (try_end),
  57811. (try_end),
  57812.  
  57813. # (try_end),
  57814. ]),
  57815.  
  57816. #######################
  57817. # Search for the most expensive item of a specified type
  57818.  
  57819. ##diplomacy start+
  57820. #"script_dplmc_scan_for_best_item_of_type"
  57821. #
  57822. #INPUT:
  57823. # arg1 :troop
  57824. # arg2 :item_type
  57825. # arg3 :troop_using
  57826. #
  57827. #OUTPUT:
  57828. # reg0 index of best item (-1 if not found)
  57829. ##diplomacy end+
  57830. ("dplmc_scan_for_best_item_of_type", [
  57831. (store_script_param, ":troop",1),
  57832. (store_script_param, ":item_type",2),
  57833. (store_script_param, ":troop_using", 3),
  57834.  
  57835.  
  57836. #SB : parse damage type and meta type (if any)
  57837. # (store_div, ":dmg_type", ":item_type", meta_dmg_mask),
  57838. (store_mod, ":meta_type", ":item_type", meta_dmg_mask), #use this instead
  57839. (store_mod, ":item_type", ":meta_type", meta_itp_mask), #base type
  57840.  
  57841. (assign, ":best_slot", -1),
  57842. (assign, ":best_value", -1),
  57843. # iterate through the list of items
  57844. (troop_get_inventory_capacity, ":inv_cap", ":troop"),
  57845. (try_for_range, ":i_slot", 0, ":inv_cap"),
  57846. (troop_get_inventory_slot, ":item", ":troop", ":i_slot"),
  57847. (ge, ":item", 0),
  57848. (troop_get_inventory_slot_modifier, ":imod", ":troop", ":i_slot"),
  57849. #(item_get_type, ":this_item_type", ":item"), use the following instead
  57850.  
  57851. # #### Autoloot improved by rubik begin
  57852. # (try_begin),
  57853. # # (item_slot_eq, ":item", dplmc_slot_two_handed_one_handed, 1),
  57854. # (item_has_property, ":item", itp_type_two_handed_wpn),
  57855. # (neg|item_has_property, ":item", itp_two_handed),
  57856. # (assign, ":this_item_type", 11), # type 11 = two-handed/one-handed
  57857. # (else_try),
  57858. # (item_get_type, ":this_item_type", ":item"),
  57859. # (try_end),
  57860. # #### Autoloot improved by rubik end
  57861. (call_script, "script_item_get_type_aux", ":item"), #SB : compare metatype
  57862. (eq, ":meta_type", reg0), # it's one of the kind we're looking for (meta-type holds itp if none exists)
  57863. (call_script, "script_dplmc_troop_can_use_item", ":troop_using", ":item", ":imod"),
  57864. (eq, reg0, 1), # can use
  57865. #(call_script, "script_get_item_value_with_imod", ":item", ":imod"), # use the following instead
  57866.  
  57867. #### Autoloot improved by rubik begin
  57868. # get item_score instead of price
  57869. (call_script, "script_dplmc_get_item_score_with_imod", ":item", ":imod"),
  57870. #### Autoloot improved by rubik end
  57871. (assign, ":cur_value", reg0),
  57872. #SB : adjust value here for damage preference
  57873. # (try_begin),
  57874. # (call_script, "script_cf_item_type_has_advanced_autoloot", ":item_type"),
  57875. # (item_get_swing_damage, ":swing_damage", ":item"),
  57876. # (item_get_thrust_damage, ":thrust_damage", ":item"),
  57877. # (try_begin),
  57878. # (ge, ":swing_damage", ":thrust_damage"),
  57879. # (item_get_swing_damage_type, ":item_dmg_type", ":item"),
  57880. # (else_try),
  57881. # (lt, ":swing_damage", ":thrust_damage"),
  57882. # (item_get_thrust_damage_type, ":item_dmg_type", ":item"),
  57883. # (try_end),
  57884. # #check if it matches preference
  57885. # (eq, ":dmg_type", ":item_dmg_type"),
  57886. # (val_mul, ":cur_value", 3),
  57887. # (try_end),
  57888. (gt, ":cur_value", ":best_value"), # best one we've seen yet
  57889. (assign, ":best_slot", ":i_slot"),
  57890. (assign, ":best_value", ":cur_value"),
  57891. (try_end),
  57892.  
  57893.  
  57894.  
  57895. # return the slot of the best one
  57896. (assign, reg0, ":best_slot"),
  57897. ]),
  57898.  
  57899. ##diplomacy start+
  57900. #"script_dplmc_count_better_items_of_same_type"
  57901. #
  57902. #INPUT:
  57903. # arg1 :inventory_troop
  57904. # arg2 :item
  57905. # arg2 :item_imod
  57906. # arg3 :troop_using
  57907. #
  57908. #OUTPUT:
  57909. # reg0 number of items of same type
  57910. ("dplmc_count_better_items_of_same_type", [
  57911. (store_script_param, ":inventory_troop",1),
  57912. (store_script_param, ":base_item",2),
  57913. (store_script_param, ":base_imod",3),
  57914. (store_script_param, ":troop_using", 4),
  57915.  
  57916. (assign, ":number_better_of_type", 0),
  57917. #(assign, ":total_items_of_type", 0),
  57918.  
  57919. # (item_get_type, ":main_item_type", ":base_item"),
  57920. # (try_begin),
  57921. # (item_has_property, ":item", itp_type_two_handed_wpn),
  57922. # (neg|item_has_property, ":item", itp_two_handed),
  57923. # (assign, ":main_item_type", 11), # type 11 = two-handed/one-handed
  57924. # (try_end),
  57925. #SB : metatype
  57926. (call_script, "script_item_get_type_aux", ":base_item"),
  57927. (assign, ":main_item_type", reg0),
  57928.  
  57929. (call_script, "script_dplmc_get_item_score_with_imod", ":base_item", ":base_imod"),
  57930. (assign, ":primary_score", reg0),
  57931.  
  57932. (call_script, "script_dplmc_troop_can_use_item", ":troop_using", ":base_item", ":base_imod"),
  57933. (assign, ":can_use", 1),
  57934. (try_begin),
  57935. (neq, reg0, 1),
  57936. (assign, ":primary_score", -1000),
  57937. (assign, ":can_use", 0),
  57938. (try_end),
  57939. (assign, ":exact_matches_found", 0),
  57940.  
  57941. (troop_get_inventory_capacity, ":inv_cap", ":inventory_troop"),
  57942. (try_for_range, ":i_slot", 0, ":inv_cap"),
  57943. (troop_get_inventory_slot, ":item", ":inventory_troop", ":i_slot"),
  57944. (ge, ":item", 0),
  57945. # SB : metatype
  57946. (call_script, "script_item_get_type_aux", ":item"),
  57947. (eq, ":main_item_type", reg0),
  57948. #(val_add, ":total_items_of_type", 1),
  57949. (troop_get_inventory_slot_modifier, ":imod", ":inventory_troop", ":i_slot"),
  57950. (call_script, "script_dplmc_troop_can_use_item", ":troop_using", ":item", ":imod"),
  57951. (this_or_next|eq, ":can_use", 0),
  57952. (ge, reg0, 1),
  57953. (try_begin),
  57954. (eq, ":item", ":base_item"),
  57955. (eq, ":imod", ":base_imod"),
  57956. (val_add, ":exact_matches_found", 1),
  57957. (try_end),
  57958. (this_or_next|neq, ":item", ":base_item"),
  57959. (this_or_next|neq, ":imod", ":base_imod"),
  57960. (ge, ":exact_matches_found", 2),
  57961. (call_script, "script_dplmc_get_item_score_with_imod", ":item", ":imod"),
  57962. (ge, reg0, ":primary_score"),#deliberately ge instead of gt because of what I want this for
  57963. (val_add, ":number_better_of_type", 1),
  57964. (try_end),
  57965.  
  57966. (assign, reg0, ":number_better_of_type"),
  57967. #(assign, reg1, ":total_items_of_type"),
  57968. ]),
  57969. ##diplomacy end+
  57970.  
  57971. ("dplmc_copy_upgrade_to_all_heroes",
  57972. [
  57973. (store_script_param_1, ":troop"),
  57974. (store_script_param_2, ":type"),
  57975.  
  57976. (try_begin),
  57977. (eq, ":type", dplmc_wpn_setting_1),
  57978. (troop_get_slot,":upg_wpn0", ":troop",dplmc_slot_upgrade_wpn_0),
  57979. (troop_get_slot,":upg_wpn1", ":troop",dplmc_slot_upgrade_wpn_1),
  57980. (troop_get_slot,":upg_wpn2", ":troop",dplmc_slot_upgrade_wpn_2),
  57981. (troop_get_slot,":upg_wpn3", ":troop",dplmc_slot_upgrade_wpn_3),
  57982. (try_for_range, ":hero", companions_begin, companions_end),
  57983. (troop_set_slot,":hero",dplmc_slot_upgrade_wpn_0,":upg_wpn0"),
  57984. (troop_set_slot,":hero",dplmc_slot_upgrade_wpn_1,":upg_wpn1"),
  57985. (troop_set_slot,":hero",dplmc_slot_upgrade_wpn_2,":upg_wpn2"),
  57986. (troop_set_slot,":hero",dplmc_slot_upgrade_wpn_3,":upg_wpn3"),
  57987. (try_end),
  57988. (else_try),
  57989. (eq, ":type", dplmc_armor_setting),
  57990. (troop_get_slot,":upg_armor", ":troop",dplmc_slot_upgrade_armor),
  57991. (try_for_range, ":hero", companions_begin, companions_end),
  57992. (troop_set_slot,":hero",dplmc_slot_upgrade_armor,":upg_armor"),
  57993. (try_end),
  57994. (else_try),
  57995. (eq, ":type", dplmc_horse_setting),
  57996. (troop_get_slot,":upg_horse", ":troop",dplmc_slot_upgrade_horse),
  57997. (try_for_range, ":hero", companions_begin, companions_end),
  57998. (troop_set_slot,":hero",dplmc_slot_upgrade_horse,":upg_horse"),
  57999. (try_end),
  58000. (try_end),
  58001. ]),
  58002.  
  58003. ("dplmc_get_current_item_for_autoloot",
  58004. [
  58005. (store_script_param_1, ":slot_no"),
  58006.  
  58007. #(try_begin),
  58008. (assign, ":dest_slot", ":slot_no"),
  58009. (troop_get_inventory_slot, ":item", "$temp", ":dest_slot"),
  58010. #(else_try),
  58011. # (store_sub, ":dest_slot", "$temp", companions_begin),
  58012. # (val_mul, ":dest_slot", 4),
  58013. # (val_add, ":dest_slot", 10),
  58014. # (val_add, ":dest_slot", ":slot_no"),
  58015. # (troop_get_inventory_slot, ":item", "trp_merchants_end", ":dest_slot"),
  58016. #(try_end),
  58017. (try_begin),
  58018. (ge, ":item", 0),
  58019. (str_store_item_name, s10, ":item"),
  58020. (else_try),
  58021. (str_store_string, s10, "str_dplmc_none"),
  58022. (try_end),
  58023. ]),
  58024.  
  58025. ("dplmc_get_troop_max_hp",
  58026. [
  58027. (store_script_param_1, ":troop"),
  58028.  
  58029. (store_skill_level, ":skill", skl_ironflesh, ":troop"),
  58030. (store_attribute_level, ":attrib", ":troop", ca_strength),
  58031. (val_mul, ":skill", 2),
  58032. (val_add, ":skill", ":attrib"),
  58033. (val_add, ":skill", 35),
  58034. (assign, reg0, ":skill"),
  58035. ]),
  58036. #cc end
  58037.  
  58038. ("dplmc_describe_prosperity_to_s4",
  58039. [
  58040. (store_script_param_1, ":center_no"),
  58041.  
  58042. (str_store_party_name, s60,":center_no"),
  58043. (party_get_slot, ":prosperity", ":center_no", slot_town_prosperity),
  58044. (str_store_string, s4, "str_empty_string"),
  58045. (try_begin),
  58046. (is_between, ":center_no", towns_begin, towns_end),
  58047. (try_begin),
  58048. (eq, ":prosperity", 0),
  58049. (str_store_string, s4, "str_town_prosperity_0"),
  58050. (else_try),
  58051. (is_between, ":prosperity", 1, 11),
  58052. (str_store_string, s4, "str_town_prosperity_10"),
  58053. (else_try),
  58054. (is_between, ":prosperity", 11, 21),
  58055. (str_store_string, s4, "str_town_prosperity_20"),
  58056. (else_try),
  58057. (is_between, ":prosperity", 21, 31),
  58058. (str_store_string, s4, "str_town_prosperity_30"),
  58059. (else_try),
  58060. (is_between, ":prosperity", 31, 41),
  58061. (str_store_string, s4, "str_town_prosperity_40"),
  58062. (else_try),
  58063. (is_between, ":prosperity", 41, 51),
  58064. (str_store_string, s4, "str_town_prosperity_50"),
  58065. (else_try),
  58066. (is_between, ":prosperity", 51, 61),
  58067. (str_store_string, s4, "str_town_prosperity_60"),
  58068. (else_try),
  58069. (is_between, ":prosperity", 61, 71),
  58070. (str_store_string, s4, "str_town_prosperity_70"),
  58071. (else_try),
  58072. (is_between, ":prosperity", 71, 81),
  58073. (str_store_string, s4, "str_town_prosperity_80"),
  58074. (else_try),
  58075. (is_between, ":prosperity", 81, 91),
  58076. (str_store_string, s4, "str_town_prosperity_90"),
  58077. (else_try),
  58078. (is_between, ":prosperity", 91, 101),
  58079. (str_store_string, s4, "str_town_prosperity_100"),
  58080. (try_end),
  58081. (else_try),
  58082. (is_between, ":center_no", villages_begin, villages_end),
  58083. (try_begin),
  58084. (eq, ":prosperity", 0),
  58085. (str_store_string, s4, "str_village_prosperity_0"),
  58086. (else_try),
  58087. (is_between, ":prosperity", 1, 11),
  58088. (str_store_string, s4, "str_village_prosperity_10"),
  58089. (else_try),
  58090. (is_between, ":prosperity", 11, 21),
  58091. (str_store_string, s4, "str_village_prosperity_20"),
  58092. (else_try),
  58093. (is_between, ":prosperity", 21, 31),
  58094. (str_store_string, s4, "str_village_prosperity_30"),
  58095. (else_try),
  58096. (is_between, ":prosperity", 31, 41),
  58097. (str_store_string, s4, "str_village_prosperity_40"),
  58098. (else_try),
  58099. (is_between, ":prosperity", 41, 51),
  58100. (str_store_string, s4, "str_village_prosperity_50"),
  58101. (else_try),
  58102. (is_between, ":prosperity", 51, 61),
  58103. (str_store_string, s4, "str_village_prosperity_60"),
  58104. (else_try),
  58105. (is_between, ":prosperity", 61, 71),
  58106. (str_store_string, s4, "str_village_prosperity_70"),
  58107. (else_try),
  58108. (is_between, ":prosperity", 71, 81),
  58109. (str_store_string, s4, "str_village_prosperity_80"),
  58110. (else_try),
  58111. (is_between, ":prosperity", 81, 91),
  58112. (str_store_string, s4, "str_village_prosperity_90"),
  58113. (else_try),
  58114. (is_between, ":prosperity", 91, 101),
  58115. (str_store_string, s4, "str_village_prosperity_100"),
  58116. (try_end),
  58117. (try_end),
  58118. ]),
  58119.  
  58120. ("dplmc_pay_into_treasury",
  58121. [
  58122. (store_script_param_1, ":amount"),
  58123. (troop_add_gold, "trp_household_possessions", ":amount"),
  58124. (assign, reg0, ":amount"),
  58125. (play_sound, "snd_money_received"),
  58126. (display_message, "@{reg0} denars added to treasury."),
  58127. ]),
  58128.  
  58129. ("dplmc_withdraw_from_treasury",
  58130. [
  58131. (store_script_param_1, ":amount"),
  58132. (troop_remove_gold, "trp_household_possessions", ":amount"),
  58133. (assign, reg0, ":amount"),
  58134. (play_sound, "snd_money_paid"),
  58135. (display_message, "@{reg0} denars removed from treasury."),
  58136. ]),
  58137.  
  58138. ("dplmc_describe_tax_rate_to_s50",
  58139. [
  58140. (store_script_param_1, ":tax_rate"),
  58141. (val_div, ":tax_rate", 25),
  58142. (store_add, ":str_id","str_dplmc_tax_normal", ":tax_rate"),
  58143. (str_store_string, s50, ":str_id"),
  58144. ]),
  58145.  
  58146.  
  58147. ("dplmc_player_troops_leave",
  58148. [
  58149. (store_script_param_1, ":percent"),
  58150.  
  58151. (try_begin),#debug
  58152. (eq, "$cheat_mode", 1),
  58153. (assign, reg0, ":percent"),
  58154. (display_message, "@{!}DEBUG : removing player troops: {reg0}%"),
  58155. (try_end),
  58156.  
  58157. (assign, ":deserters", 0),
  58158. (try_for_parties, ":party_no"),
  58159. (assign, ":remove_troops", 0),
  58160. (try_begin),
  58161. (this_or_next|party_slot_eq, ":party_no", slot_party_type, spt_town),
  58162. (party_slot_eq, ":party_no", slot_party_type, spt_castle),
  58163. (party_slot_eq, ":party_no", slot_town_lord, "trp_player"),
  58164. (assign, ":remove_troops", 1),
  58165. (else_try),
  58166. (eq, "p_main_party", ":party_no"),
  58167. (assign, ":remove_troops", 1),
  58168. (try_end),
  58169.  
  58170. (eq, ":remove_troops", 1),
  58171. (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  58172. (try_for_range, ":i_stack", 0, ":num_stacks"),
  58173. (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  58174. (val_mul, ":stack_size", ":percent"),
  58175. (val_div, ":stack_size", 100),
  58176. (party_stack_get_troop_id, ":troop_id", ":party_no", ":i_stack"),
  58177. (party_remove_members, ":party_no", ":troop_id", ":stack_size"),
  58178. (val_add, ":deserters", ":stack_size"),
  58179. (try_end),
  58180. (try_end),
  58181. (assign, reg0, ":deserters"),
  58182. ]
  58183. ),
  58184.  
  58185. ("dplmc_get_item_buy_price_factor",
  58186. [
  58187. ##nested diplomacy start+
  58188. #(store_script_param_1, ":item_kind_id"),
  58189. #(store_script_param_2, ":center_no"),
  58190. #Add two parameters
  58191. (store_script_param, ":item_kind_id", 1),
  58192. (store_script_param, ":center_no", 2),
  58193. (store_script_param, ":customer_no", 3),
  58194. (store_script_param, ":merchant_no", 4),
  58195. ##nested diplomacy start+
  58196. (assign, ":price_factor", 100),
  58197.  
  58198. ##nested diplomacy start+
  58199. #(call_script, "script_get_trade_penalty", ":item_kind_id"),
  58200. (call_script, "script_dplmc_get_trade_penalty", ":item_kind_id", ":center_no", ":customer_no", ":merchant_no"),
  58201. ##nested diplomacy end+
  58202. (assign, ":trade_penalty", reg0),
  58203.  
  58204. (try_begin),
  58205. ##nested diplomacy start+
  58206. (gt, ":center_no", 0),
  58207. (this_or_next|is_between, ":center_no", centers_begin, centers_end),
  58208. (party_is_active, ":center_no"),
  58209.  
  58210. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  58211. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_village),
  58212. ##nested diplomacy end+
  58213. (is_between, ":center_no", centers_begin, centers_end),
  58214. (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  58215. (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
  58216. (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
  58217. (party_get_slot, ":price_factor", ":center_no", ":item_slot_no"),
  58218.  
  58219. (try_begin),
  58220. ##nested diplomacy start+
  58221. #OLD:
  58222. #(is_between, ":center_no", villages_begin, villages_end),
  58223. #(party_get_slot, ":market_town", ":center_no", slot_village_market_town),
  58224. ##NEW:
  58225. (gt, ":center_no", 0),
  58226. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_village),
  58227. (is_between, ":center_no", villages_begin, villages_end),
  58228. (party_get_slot, ":market_town", ":center_no", slot_village_market_town),
  58229.  
  58230. (ge, ":market_town", centers_begin),
  58231. (this_or_next|party_slot_eq, ":market_town", slot_party_type, spt_town),
  58232. (this_or_next|party_slot_eq, ":market_town", slot_party_type, spt_village),
  58233. (is_between, ":market_town", centers_begin, centers_end),
  58234. ##nested diplomacy end+
  58235. (party_get_slot, ":price_in_market_town", ":market_town", ":item_slot_no"),
  58236. (val_max, ":price_factor", ":price_in_market_town"),
  58237. (try_end),
  58238. ##nested diplomacy start+
  58239. #Enforce constraints
  58240. (val_clamp, ":price_factor", minimum_price_factor, maximum_price_factor + 1),
  58241. ##nested diplomacy end+
  58242.  
  58243. #For villages, the good will be sold no cheaper than in the market town
  58244. #This represents the absence of a permanent market -- ie, the peasants retain goods to sell on their journeys to town, and are not about to do giveaway deals with passing adventurers
  58245.  
  58246. (val_mul, ":price_factor", 100), #normalize price factor to range 0..100
  58247. (val_div, ":price_factor", average_price_factor),
  58248. (try_end),
  58249.  
  58250. (store_add, ":penalty_factor", 100, ":trade_penalty"),
  58251.  
  58252. (val_mul, ":price_factor", ":penalty_factor"),
  58253. (val_div, ":price_factor", 100),
  58254.  
  58255. (assign, reg0, ":price_factor"),
  58256. (set_trigger_result, reg0),
  58257. ]),
  58258.  
  58259. ("dplmc_party_calculate_strength",
  58260. [
  58261. (store_script_param_1, ":party"), #Party_id
  58262. (store_script_param_2, ":exclude_leader"), #Party_id
  58263.  
  58264. (assign, reg0,0),
  58265. (party_get_num_companion_stacks, ":num_stacks", ":party"),
  58266. (assign, ":first_stack", 0),
  58267. (try_begin),
  58268. (neq, ":exclude_leader", 0),
  58269. (assign, ":first_stack", 1),
  58270. (try_end),
  58271.  
  58272. (assign, ":sum", 0),
  58273. (try_for_range, ":i_stack", ":first_stack", ":num_stacks"),
  58274. (party_stack_get_troop_id, ":stack_troop",":party", ":i_stack"),
  58275.  
  58276. (try_begin),
  58277. (neg|troop_is_hero, ":stack_troop"),
  58278. (party_stack_get_size, ":stack_size",":party",":i_stack"),
  58279. (try_end),
  58280. (val_add, ":sum", ":stack_size"),
  58281. (try_end),
  58282. (assign, reg0, ":sum"),
  58283.  
  58284. (try_begin), #debug
  58285. (eq, "$cheat_mode", 1),
  58286. (display_message, "@{!}DEBUG : sum: {reg0}"),
  58287. (try_end),
  58288. ]),
  58289.  
  58290. #script_dplmc_start_alliance_between_kingdoms, 20 days alliance, 40 days truce after that
  58291. # Input: arg1 = kingdom_1, arg2 = kingdom_2, arg3 = initializing_war_peace_cond
  58292. # Output: none
  58293. ("dplmc_start_alliance_between_kingdoms", #sets relations between two kingdoms
  58294. [
  58295. (store_script_param, ":kingdom_a", 1),
  58296. (store_script_param, ":kingdom_b", 2),
  58297. (store_script_param, ":initializing_war_peace_cond", 3),
  58298. ##diplomacy start+
  58299. #Since "fac_player_supporters_faction" is used as a shorthand for the faction
  58300. #run by the player, intercept that here instead of the various places this is
  58301. #called from.
  58302. (assign, ":save_reg1", reg1),
  58303. (call_script, "script_dplmc_translate_inactive_player_supporter_faction_2", ":kingdom_a", ":kingdom_b"),
  58304. (assign, ":kingdom_a", reg0),
  58305. (assign, ":kingdom_b", reg1),
  58306. (assign, reg1, ":save_reg1"),
  58307. ##diplomacy end+
  58308.  
  58309. (store_relation, ":relation", ":kingdom_a", ":kingdom_b"),
  58310. (val_add, ":relation", 15),
  58311. (val_max, ":relation", 40),
  58312. (set_relation, ":kingdom_a", ":kingdom_b", ":relation"),
  58313. (call_script, "script_exchange_prisoners_between_factions", ":kingdom_a", ":kingdom_b"),
  58314.  
  58315. (try_begin),
  58316. (eq, "$players_kingdom", ":kingdom_a"),
  58317. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_b"),
  58318. (val_add, ":relation", 15),
  58319. (val_max, ":relation", 40),
  58320. (call_script, "script_set_player_relation_with_faction", ":kingdom_b", ":relation"),
  58321. #(call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", "fac_player_supporters_faction"), #event cancels certain quests
  58322. (else_try),
  58323. (eq, "$players_kingdom", ":kingdom_b"),
  58324. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_a"),
  58325. (val_add, ":relation", 15),
  58326. (val_max, ":relation", 40),
  58327. (call_script, "script_set_player_relation_with_faction", ":kingdom_a", ":relation"),
  58328. #(call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", "fac_player_supporters_faction"), #event cancels certain quests
  58329. (try_end),
  58330.  
  58331. (try_begin),
  58332. (eq, ":initializing_war_peace_cond", 1),
  58333. (str_store_faction_name_link, s1, ":kingdom_a"),
  58334. (str_store_faction_name_link, s2, ":kingdom_b"),
  58335. ##diplomacy start+ #Due to complaints about the wording
  58336. #(display_log_message, "@{s1} and {s2} have concluded an alliance with each other."),
  58337. (display_log_message, "@{s1} and {s2} have entered into an alliance with each other."),
  58338. ##diplomacy end+
  58339.  
  58340. (call_script, "script_add_notification_menu", "mnu_dplmc_notification_alliance_declared", ":kingdom_a", ":kingdom_b"), #stability penalty for early peace is in the menu
  58341.  
  58342. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", ":kingdom_b"), #cancels quests
  58343. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", ":kingdom_a"), #cancels quests
  58344. (assign, "$g_recalculate_ais", 1),
  58345.  
  58346.  
  58347. (try_end),
  58348.  
  58349. (try_begin), #add truce
  58350. (store_add, ":truce_slot", ":kingdom_a", slot_faction_truce_days_with_factions_begin),
  58351. (val_sub, ":truce_slot", kingdoms_begin),
  58352. ##nested diplomacy start+ replace 80 with a named constant
  58353. #(faction_set_slot, ":kingdom_b", ":truce_slot", 80),
  58354. (faction_set_slot, ":kingdom_b", ":truce_slot", dplmc_treaty_alliance_days_initial),
  58355. ##nested diplomacy end+
  58356.  
  58357. (store_add, ":truce_slot", ":kingdom_b", slot_faction_truce_days_with_factions_begin),
  58358. (val_sub, ":truce_slot", kingdoms_begin),
  58359. ##nested diplomacy start+ replace 80 with a named constant
  58360. #(faction_set_slot, ":kingdom_a", ":truce_slot", 80),
  58361. (faction_set_slot, ":kingdom_a", ":truce_slot", dplmc_treaty_alliance_days_initial),
  58362. ##nested diplomacy end+
  58363.  
  58364. (store_add, ":slot_war_damage_inflicted_on_b", ":kingdom_b", slot_faction_war_damage_inflicted_on_factions_begin),
  58365. (val_sub, ":slot_war_damage_inflicted_on_b", kingdoms_begin),
  58366. (faction_get_slot, ":damage_inflicted_by_a", ":kingdom_a", ":slot_war_damage_inflicted_on_b"),
  58367. (try_begin),
  58368. (lt, ":damage_inflicted_by_a", 100),
  58369. #controversial policy
  58370. (try_end),
  58371. (faction_set_slot, ":kingdom_a", ":slot_war_damage_inflicted_on_b", 0),
  58372.  
  58373. (store_add, ":slot_war_damage_inflicted_on_a", ":kingdom_a", slot_faction_war_damage_inflicted_on_factions_begin),
  58374. (val_sub, ":slot_war_damage_inflicted_on_a", kingdoms_begin),
  58375. (faction_get_slot, ":damage_inflicted_by_b", ":kingdom_b", ":slot_war_damage_inflicted_on_a"),
  58376. (try_begin),
  58377. (lt, ":damage_inflicted_by_b", 100),
  58378. #controversial policy
  58379. (try_end),
  58380. (faction_set_slot, ":kingdom_b", ":slot_war_damage_inflicted_on_a", 0),
  58381.  
  58382. (try_end),
  58383.  
  58384. # share wars
  58385. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  58386. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  58387. (neq, ":kingdom_a", ":faction_no"),
  58388. (neq, ":kingdom_b", ":faction_no"),
  58389. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction",":kingdom_a", ":faction_no"),
  58390. #result: -1 faction_1 has a casus belli against faction_2. 1, faction_1 has a truce with faction_2, -2, the two factions are at war
  58391. (eq, reg0, -2),
  58392. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction",":kingdom_b", ":faction_no"),
  58393. (ge, reg0, -1),
  58394. (call_script, "script_diplomacy_start_war_between_kingdoms", ":kingdom_b", ":faction_no", 2),
  58395. (try_end),
  58396. (try_for_range, ":faction_no", kingdoms_begin, kingdoms_end),
  58397. (faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  58398. (neq, ":kingdom_a", ":faction_no"),
  58399. (neq, ":kingdom_b", ":faction_no"),
  58400. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction",":kingdom_b", ":faction_no"),
  58401. #result: -1 faction_1 has a casus belli against faction_2. 1, faction_1 has a truce with faction_2, -2, the two factions are at war
  58402. (eq, reg0, -2),
  58403. (call_script, "script_diplomacy_faction_get_diplomatic_status_with_faction",":kingdom_a", ":faction_no"),
  58404. (ge, reg0, -1),
  58405. (call_script, "script_diplomacy_start_war_between_kingdoms", ":kingdom_a", ":faction_no", 2),
  58406. (try_end),
  58407. ]),
  58408.  
  58409. #script_dplmc_start_defensive_between_kingdoms, 20 days defensive: 20 days trade aggreement, 20 days non-aggression after that
  58410. # Input: arg1 = kingdom_1, arg2 = kingdom_2, arg3 = initializing_war_peace_cond
  58411. # Output: none
  58412. ("dplmc_start_defensive_between_kingdoms", #sets relations between two kingdoms
  58413. [
  58414. (store_script_param, ":kingdom_a", 1),
  58415. (store_script_param, ":kingdom_b", 2),
  58416. (store_script_param, ":initializing_war_peace_cond", 3),
  58417. ##diplomacy start+
  58418. #Since "fac_player_supporters_faction" is used as a shorthand for the faction
  58419. #run by the player, intercept that here instead of the various places this is
  58420. #called from.
  58421. (assign, ":save_reg1", reg1),
  58422. (call_script, "script_dplmc_translate_inactive_player_supporter_faction_2", ":kingdom_a", ":kingdom_b"),
  58423. (assign, ":kingdom_a", reg0),
  58424. (assign, ":kingdom_b", reg1),
  58425. (assign, reg1, ":save_reg1"),
  58426. ##diplomacy end+
  58427.  
  58428. (store_relation, ":relation", ":kingdom_a", ":kingdom_b"),
  58429. (val_add, ":relation", 10),
  58430. (val_max, ":relation", 30),
  58431. (set_relation, ":kingdom_a", ":kingdom_b", ":relation"),
  58432. (call_script, "script_exchange_prisoners_between_factions", ":kingdom_a", ":kingdom_b"),
  58433.  
  58434. (try_begin),
  58435. (eq, "$players_kingdom", ":kingdom_a"),
  58436. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_b"),
  58437. (val_add, ":relation", 10),
  58438. (val_max, ":relation", 30),
  58439. (call_script, "script_set_player_relation_with_faction", ":kingdom_b", ":relation"),
  58440. #(call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", "fac_player_supporters_faction"), #event cancels certain quests
  58441. (else_try),
  58442. (eq, "$players_kingdom", ":kingdom_b"),
  58443. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_a"),
  58444. (val_add, ":relation", 10),
  58445. (val_max, ":relation", 30),
  58446. (call_script, "script_set_player_relation_with_faction", ":kingdom_a", ":relation"),
  58447. #(call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", "fac_player_supporters_faction"), #event cancels certain quests
  58448. (try_end),
  58449.  
  58450. (try_begin),
  58451. (eq, ":initializing_war_peace_cond", 1),
  58452. (str_store_faction_name_link, s1, ":kingdom_a"),
  58453. (str_store_faction_name_link, s2, ":kingdom_b"),
  58454. (display_log_message, "@{s1} and {s2} have concluded a defensive pact with each other."),
  58455.  
  58456. (call_script, "script_add_notification_menu", "mnu_dplmc_notification_defensive_declared", ":kingdom_a", ":kingdom_b"), #stability penalty for early peace is in the menu
  58457.  
  58458. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", ":kingdom_b"), #cancels quests
  58459. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", ":kingdom_a"), #cancels quests
  58460. (assign, "$g_recalculate_ais", 1),
  58461.  
  58462.  
  58463. (try_end),
  58464.  
  58465. (try_begin), #add truce
  58466. (store_add, ":truce_slot", ":kingdom_a", slot_faction_truce_days_with_factions_begin),
  58467. (val_sub, ":truce_slot", kingdoms_begin),
  58468. ##diplomacy start+ replace 60 with named variable
  58469. #(faction_set_slot, ":kingdom_b", ":truce_slot", 60),
  58470. (faction_set_slot, ":kingdom_b", ":truce_slot", dplmc_treaty_defense_days_initial),
  58471. ##diplomacy end+
  58472.  
  58473. (store_add, ":truce_slot", ":kingdom_b", slot_faction_truce_days_with_factions_begin),
  58474. (val_sub, ":truce_slot", kingdoms_begin),
  58475. ##diplomacy start+ replace 60 with named variable
  58476. #(faction_set_slot, ":kingdom_a", ":truce_slot", 60),
  58477. (faction_set_slot, ":kingdom_a", ":truce_slot", dplmc_treaty_defense_days_initial),
  58478. ##diplomacy end+
  58479.  
  58480. (store_add, ":slot_war_damage_inflicted_on_b", ":kingdom_b", slot_faction_war_damage_inflicted_on_factions_begin),
  58481. (val_sub, ":slot_war_damage_inflicted_on_b", kingdoms_begin),
  58482. (faction_get_slot, ":damage_inflicted_by_a", ":kingdom_a", ":slot_war_damage_inflicted_on_b"),
  58483. (try_begin),
  58484. (lt, ":damage_inflicted_by_a", 100),
  58485. #controversial policy
  58486. (try_end),
  58487. (faction_set_slot, ":kingdom_a", ":slot_war_damage_inflicted_on_b", 0),
  58488.  
  58489. (store_add, ":slot_war_damage_inflicted_on_a", ":kingdom_a", slot_faction_war_damage_inflicted_on_factions_begin),
  58490. (val_sub, ":slot_war_damage_inflicted_on_a", kingdoms_begin),
  58491. (faction_get_slot, ":damage_inflicted_by_b", ":kingdom_b", ":slot_war_damage_inflicted_on_a"),
  58492. (try_begin),
  58493. (lt, ":damage_inflicted_by_b", 100),
  58494. #controversial policy
  58495. (try_end),
  58496. (faction_set_slot, ":kingdom_b", ":slot_war_damage_inflicted_on_a", 0),
  58497.  
  58498. (try_end),
  58499. ]),
  58500.  
  58501. #script_dplmc_start_trade_between_kingdoms, 20 days trade aggreement, 20 days non-aggression after that
  58502. # Input: arg1 = kingdom_1, arg2 = kingdom_2, arg3 = initializing_war_peace_cond
  58503. # Output: none
  58504. ("dplmc_start_trade_between_kingdoms", #sets relations between two kingdoms
  58505. [
  58506. (store_script_param, ":kingdom_a", 1),
  58507. (store_script_param, ":kingdom_b", 2),
  58508. (store_script_param, ":initializing_war_peace_cond", 3),
  58509. ##diplomacy start+
  58510. #Since "fac_player_supporters_faction" is used as a shorthand for the faction
  58511. #run by the player, intercept that here instead of the various places this is
  58512. #called from.
  58513. (assign, ":save_reg1", reg1),
  58514. (call_script, "script_dplmc_translate_inactive_player_supporter_faction_2", ":kingdom_a", ":kingdom_b"),
  58515. (assign, ":kingdom_a", reg0),
  58516. (assign, ":kingdom_b", reg1),
  58517. (assign, reg1, ":save_reg1"),
  58518. ##diplomacy end+
  58519.  
  58520. (store_relation, ":relation", ":kingdom_a", ":kingdom_b"),
  58521. (val_add, ":relation", 5),
  58522. (val_max, ":relation", 20),
  58523. (set_relation, ":kingdom_a", ":kingdom_b", ":relation"),
  58524. (call_script, "script_exchange_prisoners_between_factions", ":kingdom_a", ":kingdom_b"),
  58525.  
  58526. (try_begin),
  58527. (eq, "$players_kingdom", ":kingdom_a"),
  58528. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_b"),
  58529. (val_add, ":relation", 5),
  58530. (val_max, ":relation", 20),
  58531. (call_script, "script_set_player_relation_with_faction", ":kingdom_b", ":relation"),
  58532. #(call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", "fac_player_supporters_faction"), #event cancels certain quests
  58533. (else_try),
  58534. (eq, "$players_kingdom", ":kingdom_b"),
  58535. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_a"),
  58536. (val_add, ":relation", 5),
  58537. (val_max, ":relation", 20),
  58538. (call_script, "script_set_player_relation_with_faction", ":kingdom_a", ":relation"),
  58539. #(call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", "fac_player_supporters_faction"), #event cancels certain quests
  58540. (try_end),
  58541.  
  58542. (try_begin),
  58543. (eq, ":initializing_war_peace_cond", 1),
  58544. (str_store_faction_name_link, s1, ":kingdom_a"),
  58545. (str_store_faction_name_link, s2, ":kingdom_b"),
  58546. (display_log_message, "@{s1} and {s2} have concluded a trade agreement with each other."),
  58547.  
  58548. (call_script, "script_add_notification_menu", "mnu_dplmc_notification_trade_declared", ":kingdom_a", ":kingdom_b"), #stability penalty for early peace is in the menu
  58549.  
  58550. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", ":kingdom_b"), #cancels quests
  58551. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", ":kingdom_a"), #cancels quests
  58552. (assign, "$g_recalculate_ais", 1),
  58553.  
  58554.  
  58555. (try_end),
  58556.  
  58557. (try_begin), #add truce
  58558. (store_add, ":truce_slot", ":kingdom_a", slot_faction_truce_days_with_factions_begin),
  58559. (val_sub, ":truce_slot", kingdoms_begin),
  58560. ##nested diplomacy start+ replace hardcoded number of days with a variable
  58561. #(faction_set_slot, ":kingdom_b", ":truce_slot", 40),
  58562. (faction_set_slot, ":kingdom_b", ":truce_slot", dplmc_treaty_trade_days_initial),
  58563. ##nested diplomacy end+
  58564.  
  58565. (store_add, ":truce_slot", ":kingdom_b", slot_faction_truce_days_with_factions_begin),
  58566. (val_sub, ":truce_slot", kingdoms_begin),
  58567. ##nested diplomacy start+ replace hardcoded number of days with a variable
  58568. #(faction_set_slot, ":kingdom_a", ":truce_slot", 40),
  58569. (faction_set_slot, ":kingdom_a", ":truce_slot", dplmc_treaty_trade_days_initial),
  58570. ##nested diplomacy end+
  58571.  
  58572. (store_add, ":slot_war_damage_inflicted_on_b", ":kingdom_b", slot_faction_war_damage_inflicted_on_factions_begin),
  58573. (val_sub, ":slot_war_damage_inflicted_on_b", kingdoms_begin),
  58574. (faction_get_slot, ":damage_inflicted_by_a", ":kingdom_a", ":slot_war_damage_inflicted_on_b"),
  58575. (try_begin),
  58576. (lt, ":damage_inflicted_by_a", 100),
  58577. #controversial policy
  58578. (try_end),
  58579. (faction_set_slot, ":kingdom_a", ":slot_war_damage_inflicted_on_b", 0),
  58580.  
  58581. (store_add, ":slot_war_damage_inflicted_on_a", ":kingdom_a", slot_faction_war_damage_inflicted_on_factions_begin),
  58582. (val_sub, ":slot_war_damage_inflicted_on_a", kingdoms_begin),
  58583. (faction_get_slot, ":damage_inflicted_by_b", ":kingdom_b", ":slot_war_damage_inflicted_on_a"),
  58584. (try_begin),
  58585. (lt, ":damage_inflicted_by_b", 100),
  58586. #controversial policy
  58587. (try_end),
  58588. (faction_set_slot, ":kingdom_b", ":slot_war_damage_inflicted_on_a", 0),
  58589.  
  58590. (try_end),
  58591. ]),
  58592.  
  58593. #script_dplmc_start_nonaggression_between_kingdoms, 20 days non-aggression
  58594. # Input: arg1 = kingdom_1, arg2 = kingdom_2, arg3 = initializing_war_peace_cond
  58595. # Output: none
  58596. ("dplmc_start_nonaggression_between_kingdoms", #sets relations between two kingdoms
  58597. [
  58598. (store_script_param, ":kingdom_a", 1),
  58599. (store_script_param, ":kingdom_b", 2),
  58600. (store_script_param, ":initializing_war_peace_cond", 3),
  58601. ##diplomacy start+
  58602. #Since "fac_player_supporters_faction" is used as a shorthand for the faction
  58603. #run by the player, intercept that here instead of the various places this is
  58604. #called from.
  58605. (assign, ":save_reg1", reg1),
  58606. (call_script, "script_dplmc_translate_inactive_player_supporter_faction_2", ":kingdom_a", ":kingdom_b"),
  58607. (assign, ":kingdom_a", reg0),
  58608. (assign, ":kingdom_b", reg1),
  58609. (assign, reg1, ":save_reg1"),
  58610. ##diplomacy end+
  58611.  
  58612. (store_relation, ":relation", ":kingdom_a", ":kingdom_b"),
  58613. (val_add, ":relation", 3),
  58614. (val_max, ":relation", 10),
  58615. (set_relation, ":kingdom_a", ":kingdom_b", ":relation"),
  58616. (call_script, "script_exchange_prisoners_between_factions", ":kingdom_a", ":kingdom_b"),
  58617.  
  58618. (try_begin),
  58619. (eq, "$players_kingdom", ":kingdom_a"),
  58620. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_b"),
  58621. (val_add, ":relation", 3),
  58622. (val_max, ":relation", 10),
  58623. (call_script, "script_set_player_relation_with_faction", ":kingdom_b", ":relation"),
  58624. #(call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", "fac_player_supporters_faction"), #event cancels certain quests
  58625. (else_try),
  58626. (eq, "$players_kingdom", ":kingdom_b"),
  58627. (store_relation, ":relation", "fac_player_supporters_faction", ":kingdom_a"),
  58628. (val_add, ":relation", 3),
  58629. (val_max, ":relation", 10),
  58630. (call_script, "script_set_player_relation_with_faction", ":kingdom_a", ":relation"),
  58631. #(call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", "fac_player_supporters_faction"), #event cancels certain quests
  58632. (try_end),
  58633.  
  58634. (try_begin),
  58635. (eq, ":initializing_war_peace_cond", 1),
  58636. (str_store_faction_name_link, s1, ":kingdom_a"),
  58637. (str_store_faction_name_link, s2, ":kingdom_b"),
  58638. (display_log_message, "@{s1} and {s2} have concluded a non aggression pact with each other."),
  58639.  
  58640. (call_script, "script_add_notification_menu", "mnu_dplmc_notification_nonaggression_declared", ":kingdom_a", ":kingdom_b"), #stability penalty for early peace is in the menu
  58641.  
  58642. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_a", ":kingdom_b"), #cancels quests
  58643. (call_script, "script_event_kingdom_make_peace_with_kingdom", ":kingdom_b", ":kingdom_a"), #cancels quests
  58644. (assign, "$g_recalculate_ais", 1),
  58645.  
  58646.  
  58647. (try_end),
  58648.  
  58649. (try_begin), #add truce
  58650. (store_add, ":truce_slot", ":kingdom_a", slot_faction_truce_days_with_factions_begin),
  58651. (val_sub, ":truce_slot", kingdoms_begin),
  58652. ##nested diplomacy start+ replace hardcoded number with a variable
  58653. #(faction_set_slot, ":kingdom_b", ":truce_slot", 20),
  58654. (faction_set_slot, ":kingdom_b", ":truce_slot", dplmc_treaty_truce_days_initial),
  58655. ##nested diplomacy end+
  58656.  
  58657. (store_add, ":truce_slot", ":kingdom_b", slot_faction_truce_days_with_factions_begin),
  58658. (val_sub, ":truce_slot", kingdoms_begin),
  58659. ##nested diplomacy start+ replace hardcoded number with a variable
  58660. #(faction_set_slot, ":kingdom_a", ":truce_slot", 20),
  58661. (faction_set_slot, ":kingdom_a", ":truce_slot", dplmc_treaty_truce_days_initial),
  58662. ##nested diplomacy end+
  58663.  
  58664. (store_add, ":slot_war_damage_inflicted_on_b", ":kingdom_b", slot_faction_war_damage_inflicted_on_factions_begin),
  58665. (val_sub, ":slot_war_damage_inflicted_on_b", kingdoms_begin),
  58666. (faction_get_slot, ":damage_inflicted_by_a", ":kingdom_a", ":slot_war_damage_inflicted_on_b"),
  58667. (try_begin),
  58668. (lt, ":damage_inflicted_by_a", 100),
  58669. #controversial policy
  58670. (try_end),
  58671. (faction_set_slot, ":kingdom_a", ":slot_war_damage_inflicted_on_b", 0),
  58672.  
  58673. (store_add, ":slot_war_damage_inflicted_on_a", ":kingdom_a", slot_faction_war_damage_inflicted_on_factions_begin),
  58674. (val_sub, ":slot_war_damage_inflicted_on_a", kingdoms_begin),
  58675. (faction_get_slot, ":damage_inflicted_by_b", ":kingdom_b", ":slot_war_damage_inflicted_on_a"),
  58676. (try_begin),
  58677. (lt, ":damage_inflicted_by_b", 100),
  58678. #controversial policy
  58679. (try_end),
  58680. (faction_set_slot, ":kingdom_b", ":slot_war_damage_inflicted_on_a", 0),
  58681.  
  58682. (try_end),
  58683. ]),
  58684.  
  58685.  
  58686.  
  58687. # Input: arg1 = faction_no_1, arg2 = faction_no_2
  58688. ("dplmc_get_prisoners_value_between_factions",
  58689. [
  58690. (store_script_param, ":faction_no_1", 1),
  58691. (store_script_param, ":faction_no_2", 2),
  58692.  
  58693. (assign, ":faction_no_1_value", 0),
  58694. (assign, ":faction_no_2_value", 0),
  58695.  
  58696. (try_for_parties, ":party_no"),
  58697. (store_faction_of_party, ":party_faction", ":party_no"),
  58698. (try_begin),
  58699. (eq, ":party_faction", ":faction_no_1"),
  58700. (party_get_num_prisoner_stacks, ":num_stacks", ":party_no"),
  58701. (try_for_range_backwards, ":troop_iterator", 0, ":num_stacks"),
  58702. (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":party_no", ":troop_iterator"),
  58703. (store_troop_faction, ":cur_faction", ":cur_troop_id"),
  58704.  
  58705. (eq, ":cur_faction", ":faction_no_2"),
  58706. (try_begin),
  58707. (troop_is_hero, ":cur_troop_id"),
  58708. (call_script, "script_calculate_ransom_amount_for_troop", ":cur_troop_id"),
  58709. (val_add, ":faction_no_1_value", reg0),
  58710.  
  58711. (try_begin),#debug
  58712. (eq, "$cheat_mode", 1),
  58713. (assign, reg0, ":faction_no_1_value"),
  58714. (display_message, "@{!}DEBUG : faction_no_1_value: {reg0}"),
  58715. (try_end),
  58716.  
  58717. (try_end),
  58718. (try_end),
  58719. (else_try),
  58720. (eq, ":party_faction", ":faction_no_2"),
  58721. (party_get_num_prisoner_stacks, ":num_stacks", ":party_no"),
  58722. (try_for_range_backwards, ":troop_iterator", 0, ":num_stacks"),
  58723. (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":party_no", ":troop_iterator"),
  58724. (store_troop_faction, ":cur_faction", ":cur_troop_id"),
  58725.  
  58726. (eq, ":cur_faction", ":faction_no_1"),
  58727. (try_begin),
  58728. (troop_is_hero, ":cur_troop_id"),
  58729. (call_script, "script_calculate_ransom_amount_for_troop", ":cur_troop_id"),
  58730. (val_add, ":faction_no_2_value", reg0),
  58731.  
  58732. (try_begin), #debug
  58733. (eq, "$cheat_mode", 1),
  58734. (assign, reg0, ":faction_no_2_value"),
  58735. (display_message, "@{!}DEBUG : faction_no_2_value: {reg0}"),
  58736. (try_end),
  58737.  
  58738. (try_end),
  58739. (try_end),
  58740. (try_end),
  58741. (try_end),
  58742. (store_sub, reg0, ":faction_no_1_value", ":faction_no_2_value"),
  58743. ]),
  58744.  
  58745. # Input: arg1 = faction_no_1, arg2 = faction_no_2
  58746. ("dplmc_get_truce_pay_amount",
  58747. [
  58748. (store_script_param, ":faction_no_1", 1),
  58749. (store_script_param, ":faction_no_2", 2),
  58750. (store_script_param, ":check_peace_war_result", 3),
  58751. ##diplomacy start+
  58752. #Since "fac_player_supporters_faction" is used as a shorthand for the faction
  58753. #run by the player, intercept that here instead of the various places this is
  58754. #called from.
  58755. (call_script, "script_dplmc_translate_inactive_player_supporter_faction_2", ":faction_no_1", ":faction_no_2"),
  58756. (assign, ":faction_no_1", reg0),
  58757. (assign, ":faction_no_2", reg1),
  58758. ##diplomacy end+
  58759.  
  58760. (try_begin),
  58761. (eq, "$cheat_mode", 1),
  58762. (assign, reg0, ":check_peace_war_result"), #debug
  58763. (display_message, "@{!}DEBUG : peace_war_result: {reg0}"),#debug
  58764. (try_end),
  58765.  
  58766. ##nested diplomacy start+
  58767. #Improve this script; costs were too low befow.
  58768. #faction_no_1 is player faction asking for peace
  58769. #faction_no_2 is NPC faction that already considered peace and considers
  58770. # it a bad idea, so the price should not be nominal.
  58771.  
  58772. #(Also, a sign error meant that the amount asked was almost always
  58773. #zero.)
  58774.  
  58775. #Because the PC wants peace and the NPC doesn't, we aren't going to
  58776. #bother calculating relative strength or the like. Instead, we are
  58777. #going to assume the NPC can achieve his strategic objectives if he
  58778. #does not make peace, and set the price accordingly.
  58779.  
  58780. #Add a generic cost for check_peace_war_result
  58781. #These are the same as in Wahiti's original script.
  58782. (assign, ":base_cost", 4000),
  58783. (try_begin),
  58784. #It's dubious that this is ever currently called if the check-peace-war
  58785. #result was >= 0, but include this for completeness.
  58786. (ge, ":check_peace_war_result", 0),
  58787. (assign, ":base_cost", 4000),
  58788. (else_try),
  58789. (ge, ":check_peace_war_result", -1),
  58790. (assign, ":base_cost", 8000),
  58791. (else_try),
  58792. (ge, ":check_peace_war_result", -2),
  58793. (assign, ":base_cost", 12000),
  58794. (else_try),
  58795. #It shouldn't be used with this parameter; this is for the
  58796. #sake of completeness.
  58797. (le, ":check_peace_war_result", -3),
  58798. (store_mul, ":base_cost", -6000, ":check_peace_war_result"),
  58799. (try_end),
  58800.  
  58801. #Get reparations for held centers. A truce lasts 20 days, so the
  58802. #value "lost" in rents and tarriffs by declaring peace now cannot be
  58803. #is not greater than 3 times the weekly average (that upper bound is
  58804. #if the NPC is in a position to immediately recapture all of them).
  58805.  
  58806. #If the NPC kingdom is currently attacking a specific village or walled
  58807. #center, even if it isn't an ex-possession it effectively becomes one.
  58808. #(Also, assign it or its center as a demanded fief if there wasn't one
  58809. #already.)
  58810. (assign, ":target_fief", -1),
  58811. (try_begin),
  58812. (lt, ":check_peace_war_result", 1),#This should always be true anyway, but still.
  58813. (this_or_next|faction_slot_eq, ":faction_no_2", slot_faction_ai_state, sfai_attacking_center),
  58814. (faction_slot_eq, ":faction_no_2", slot_faction_ai_state, sfai_raiding_village),
  58815. (faction_get_slot, reg0, ":faction_no_2", slot_faction_ai_object),
  58816. (is_between, reg0, centers_begin, centers_end),
  58817. (assign, ":target_fief", reg0),
  58818. (try_end),
  58819.  
  58820. (assign, ":center_cost", 0),
  58821. (assign, ":concession_value", 0),
  58822. #This this old are newer are considered "recently conquered", meaning that
  58823. #faction_no_2 thinks there's a good chance they could reclaim them if the
  58824. #fighting continued.
  58825. (store_current_hours, ":recently_conquered"),
  58826. (try_begin),
  58827. (ge, ":check_peace_war_result", 1),#ordinarily this should not be true
  58828. (val_sub, ":recently_conquered", 24 * 2),#only the last two days
  58829. (else_try),
  58830. (eq, ":check_peace_war_result", 0),
  58831. (val_sub, ":recently_conquered", 24 * 15),#last 15 days
  58832. (else_try),
  58833. (eq, ":check_peace_war_result", -1),
  58834. (val_sub, ":recently_conquered", 24 * 20),#last 20 days
  58835. (else_try),
  58836. (eq, ":check_peace_war_result", -2),
  58837. (val_sub, ":recently_conquered", 24 * 30),#last 30 days
  58838. (else_try),
  58839. (val_sub, ":recently_conquered", 24 * 60),#last 60 days
  58840. (try_end),
  58841.  
  58842. (try_for_range, ":party_no", centers_begin, centers_end),
  58843. (store_faction_of_party, ":party_current_faction", ":party_no"),
  58844. (eq, ":party_current_faction", ":faction_no_1"),
  58845.  
  58846. #party_value is the estimated weekly income of the fief,
  58847. #applied three times and time discounted
  58848. (call_script, "script_dplmc_estimate_center_weekly_income", ":party_no"),
  58849. (store_mul, ":party_value", reg0, 3),
  58850.  
  58851. (try_begin),
  58852. (ge, "$g_concession_demanded", spawn_points_begin),
  58853. (this_or_next|eq, "$g_concession_demanded", ":party_no"),
  58854. (party_slot_eq, ":party_no", slot_village_bound_center, "$g_concession_demanded"),
  58855. (val_add, ":concession_value", ":party_value"),
  58856. (try_end),
  58857.  
  58858. (assign, ":continue", 0),
  58859.  
  58860. (try_begin),
  58861. #A former possession of faction 2 (must have recently changed hands, or
  58862. #faction 2 must be enthusiastic about the war)
  58863. (party_slot_eq, ":party_no", slot_center_original_faction, ":faction_no_2"),
  58864. (party_slot_ge, ":party_no", dplmc_slot_center_last_transfer_time, ":recently_conquered"),
  58865. (assign, ":continue", 1),
  58866. (else_try),
  58867. #A former possession of faction 2 (must have recently changed hands, or
  58868. #faction 2 must be enthusiastic about the war)
  58869. (party_slot_eq, ":party_no", slot_center_ex_faction, ":faction_no_2"),
  58870. (party_slot_ge, ":party_no", dplmc_slot_center_last_transfer_time, ":recently_conquered"),
  58871. (assign, ":continue", 1),
  58872. (else_try),
  58873. #The center is being attacked by faction 2, or is a village whose castle
  58874. #or town is being attacked by faction 2.
  58875. (ge, ":target_fief", centers_begin),
  58876. (this_or_next|eq, ":party_no", ":target_fief"),
  58877. (party_slot_eq, ":party_no", slot_village_bound_center, ":target_fief"),
  58878. (assign, ":continue", 1),
  58879. (else_try),
  58880. #The center is under siege by faction 2.
  58881. (party_get_slot, reg0, ":party_no", slot_center_is_besieged_by),
  58882. (gt, reg0, 0),
  58883. (party_is_active, reg0),
  58884. (store_faction_of_party, reg0, reg0),
  58885. (eq, reg0, ":faction_no_2"),
  58886. (assign, ":continue", 1),
  58887. (else_try),
  58888. #The center is a village, and the castle or town it is bound to
  58889. #is under siege by faction 2.
  58890. (is_between, ":party_no", villages_begin, villages_end),
  58891. (party_get_slot, reg0, ":party_no", slot_village_bound_center),
  58892. (is_between, reg0, centers_begin, centers_end),
  58893. (party_get_slot, reg0, reg0, slot_center_is_besieged_by),
  58894. (gt, reg0, -1),
  58895. (party_is_active, reg0),
  58896. (store_faction_of_party, reg0, reg0),
  58897. (eq, reg0, ":faction_no_2"),
  58898. (assign, ":continue", 1),
  58899. (try_end),
  58900.  
  58901. (gt, ":continue", 0),
  58902.  
  58903. (val_add, ":center_cost", ":party_value"),
  58904. (try_end),
  58905.  
  58906. #If no held centers were found, assume the campaign objective is to
  58907. #conquer territory rather than recover lost territory, if the
  58908. #NPC is sufficiently enthusiastic about the war.
  58909. (try_begin),
  58910. #Equivalent of a castle and a village
  58911. (eq, ":check_peace_war_result", -1),
  58912. (val_max, ":center_cost", (1500 + 750) * 3),
  58913. (else_try),
  58914. #Equivalent of two castles with two villages
  58915. (le, ":check_peace_war_result", -2),
  58916. (val_max, ":center_cost", (1500 + 750) * 3 * 2),
  58917. (try_end),
  58918.  
  58919. #If the war started very recently, or a center changed hands very recently,
  58920. #increase the cost. The reasoning behind this is to make the AI less prone
  58921. #to whipsawing.
  58922. #
  58923. #The multiplier is 2x for the first 48 hours, then decreases linearly from
  58924. #the two-day mark until it reaches zero at the 8-day mark.
  58925. #
  58926. #As an example, here is how a cost of 10,000 would scale over this time:
  58927. # 1 day - 20000
  58928. # 2 days - 20000
  58929. # 3 days - 18333
  58930. # 4 days - 16667
  58931. # 5 days - 15000
  58932. # 6 days - 13333
  58933. # 7 days - 11667
  58934. # 8 days - 10000
  58935. # 9 days - 10000
  58936. (store_current_hours, ":cur_hours"),
  58937. (faction_get_slot, ":faction_ai_last_decisive_event", ":faction_no_2", slot_faction_ai_last_decisive_event),
  58938. (store_sub, ":hours_since_last_decisive_event", ":cur_hours", ":faction_ai_last_decisive_event"),
  58939. (val_max, ":hours_since_last_decisive_event", 0),
  58940. (try_begin),
  58941. #First 48 hours, the base & center costs are doubled.
  58942. (lt, ":hours_since_last_decisive_event", 48 + 1),
  58943. (val_mul, ":base_cost", 2),
  58944. (val_mul, ":center_cost", 2),
  58945. (else_try),
  58946. #From 2 days to 8 days, the cost multiplier goes from 2 to 1
  58947. (lt, ":hours_since_last_decisive_event", 24 * 8),
  58948. (store_sub, reg0, 24 * 2, ":hours_since_last_decisive_event"),#0 to 6 days
  58949. (store_sub, ":multiplier", 24 * 12, reg0),# 6 to 12 days
  58950.  
  58951. (val_mul, ":base_cost", ":multiplier"),
  58952. (val_add, ":base_cost", (24 * 6) // 2),
  58953. (val_div, ":base_cost", 24 * 6),
  58954.  
  58955. (val_mul, ":center_cost", ":multiplier"),
  58956. (val_add, ":center_cost", (24 * 6) // 2),
  58957. (val_div, ":center_cost", 24 * 6),
  58958. (try_end),
  58959.  
  58960. #Get (value of ransoms held by faction #1) - (value of ransoms held by faction #2)
  58961. (call_script, "script_dplmc_get_prisoners_value_between_factions", ":faction_no_1", ":faction_no_2"),
  58962.  
  58963. (try_begin),
  58964. (eq, "$cheat_mode", 1),
  58965. (display_message, "@{!}DEBUG : prisoner_value: {reg0}"),#debug
  58966. (try_end),
  58967. (assign, ":prisoner_value", reg0),
  58968.  
  58969. #Write result to reg0
  58970. (store_add, reg0, ":base_cost", ":center_cost"),
  58971.  
  58972. #Scale for the player's wealth, to partially mitigate the problem
  58973. #of the cost becoming meaningless as the player's wealth increases.
  58974. #(Scale less than 1-to-1, so it is possible to become richer in real
  58975. #terms.) This is also aimed at reducing the necessity of replacing
  58976. #the values in mods that alter gold scarcity.
  58977. (store_troop_gold, ":player_gold", "trp_household_possessions"),
  58978. (store_troop_gold, reg1, "trp_player"),
  58979. (val_add, ":player_gold", reg1),
  58980. (try_begin),
  58981. #Arbitrarily pick 100,000 as the target wealth, since that's when
  58982. #you get the Steam "gold farmer" achievement.
  58983. (gt, ":player_gold", 100000),
  58984. (store_div, reg1, ":player_gold", 1000),
  58985. (val_mul, reg1, reg0),
  58986. (val_div, reg1, 100),
  58987.  
  58988. (val_add, reg0, reg1),
  58989. (val_div, reg0, 2),
  58990.  
  58991. #Apply the same scaling to the concession value
  58992. (store_div, reg1, ":player_gold", 1000),
  58993. (val_mul, reg1, ":concession_value"),
  58994. (val_div, reg1, 100),
  58995.  
  58996. (val_add, ":concession_value", reg1),
  58997. (val_div, ":concession_value", 2),
  58998. (try_end),
  58999.  
  59000. #Take into account campaign difficulty
  59001. (assign, ":min_cost", reg0),
  59002. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  59003. (try_begin),
  59004. (eq, ":reduce_campaign_ai", 0), #hard (1.5x)
  59005. (val_mul, reg0, 3),
  59006. (val_div, reg0, 2),
  59007. (val_mul, ":min_cost", 87),#set min_cost to 87% of the original base_cost + center_cost
  59008. (val_div, ":min_cost", 100),
  59009. (else_try),
  59010. (eq, ":reduce_campaign_ai", 1), #moderate (1.0x)
  59011. (val_mul, ":min_cost", 3),
  59012. (val_div, ":min_cost", 4),#set min_cost to 75% (base cost + center cost)
  59013. (else_try),
  59014. (eq, ":reduce_campaign_ai", 2), #easy (0.75x)
  59015. (val_mul, reg0, 3),
  59016. (val_div, reg0, 4),
  59017. (val_mul, ":min_cost", 9),
  59018. (val_div, ":min_cost", 16),#set min_cost to (75% squared) of (base cost + center cost)
  59019. (try_end),
  59020.  
  59021. (val_sub, reg0, ":prisoner_value"),
  59022.  
  59023. #Because the NPC kingdom doesn't want peace, it will not agree to peace
  59024. #for free, as that would be a contradiction.
  59025. (val_max, reg0, ":min_cost"),
  59026.  
  59027. (try_begin),
  59028. (eq, "$cheat_mode", 1),
  59029. (display_message, "@{!}DEBUG : peace_war_result after prisoners: {reg0}"),#debug
  59030. (try_end),
  59031.  
  59032. #The value of the concession (if any) was already calculated above
  59033. (assign, reg1, -1),
  59034. (try_begin),
  59035. (gt, "$g_concession_demanded", 0),
  59036. (gt, ":concession_value", 0),
  59037. (store_sub, reg1, reg0, ":concession_value"),
  59038. (val_max, reg1, 0),
  59039. #Only accept cash alone in lieu of a fief if you don't partcularly
  59040. #want war, or if the AI is on "easy".
  59041. (try_begin),
  59042. (neq, ":reduce_campaign_ai", 2),#hard or medium
  59043. (lt, ":check_peace_war_result", 0),
  59044. (assign, reg0, -1),
  59045. (try_end),
  59046. (try_end),
  59047.  
  59048. (try_begin), #debug
  59049. (eq, "$cheat_mode", 1),
  59050. (display_message, "@{!}DEBUG : truce_pay_amount0: {reg0}"),
  59051. (display_message, "@{!}DEBUG : truce_pay_amount1: {reg1}"),
  59052. (try_end),
  59053. ##nested diplomacy end+
  59054. ]),
  59055.  
  59056. ("dplmc_player_center_surrender",
  59057. [
  59058. (store_script_param, ":center_no", 1),
  59059.  
  59060. #protect player for 24 hours
  59061. (store_current_hours,":protected_until"),
  59062. (val_add, ":protected_until", 48),
  59063. (party_get_slot, ":besieger", ":center_no", slot_center_is_besieged_by),
  59064. (store_faction_of_party, ":besieger_faction",":besieger"),
  59065. ##nested diplomacy start+
  59066. #In this version this variable currently isn't used for anything
  59067. #(party_stack_get_troop_id, ":enemy_party_leader", ":besieger", 0),
  59068. ##nested diplomacy end+
  59069.  
  59070. (party_set_slot,":besieger",slot_party_ignore_player_until,":protected_until"),
  59071. (party_ignore_player, ":besieger", 48),
  59072. ##nested diplomacy start+
  59073. #Add support for promoted kingdom ladies
  59074. #(try_for_range, ":lord", active_npcs_begin, active_npcs_end),
  59075. (try_for_range, ":lord", heroes_begin, heroes_end),
  59076. (this_or_next|is_between, ":lord", active_npcs_begin, active_npcs_end),
  59077. (troop_slot_eq, ":lord", slot_troop_occupation, slto_kingdom_hero),
  59078. ##nested diplomacy end+
  59079. (store_faction_of_troop, ":lord_faction", ":lord"),
  59080. (eq, ":lord_faction", ":besieger_faction"),
  59081. (troop_get_slot, ":led_party", ":lord", slot_troop_leaded_party),
  59082. (party_is_active, ":led_party"),
  59083.  
  59084. (party_slot_eq, ":led_party", slot_party_ai_state, spai_accompanying_army),
  59085. (party_slot_eq, ":led_party", slot_party_ai_object, ":besieger"),
  59086.  
  59087. (party_is_active, ":besieger"),
  59088. (store_distance_to_party_from_party, ":distance_to_marshal", ":led_party", ":besieger"),
  59089. (lt, ":distance_to_marshal", 20),
  59090.  
  59091. (party_set_slot,":led_party",slot_party_ignore_player_until,":protected_until"),
  59092. (party_ignore_player, ":led_party", 48),
  59093. (try_end),
  59094.  
  59095. (party_set_faction,"$current_town","fac_neutral"), #temporarily erase faction so that it is not the closest town
  59096. (party_get_num_attached_parties, ":num_attached_parties_to_castle",":center_no"),
  59097. (try_for_range_backwards, ":iap", 0, ":num_attached_parties_to_castle"),
  59098. (party_get_attached_party_with_rank, ":attached_party", ":center_no", ":iap"),
  59099. (party_detach, ":attached_party"),
  59100. (party_get_slot, ":attached_party_type", ":attached_party", slot_party_type),
  59101. (eq, ":attached_party_type", spt_kingdom_hero_party),
  59102. (neq, ":attached_party_type", "p_main_party"),
  59103. (store_faction_of_party, ":attached_party_faction", ":attached_party"),
  59104. (call_script, "script_get_closest_walled_center_of_faction", ":attached_party", ":attached_party_faction"),
  59105. (try_begin),
  59106. (gt, reg0, 0),
  59107. (call_script, "script_party_set_ai_state", ":attached_party", spai_holding_center, reg0),
  59108. (else_try),
  59109. (call_script, "script_party_set_ai_state", ":attached_party", spai_patrolling_around_center, ":center_no"),
  59110. (try_end),
  59111. (try_end),
  59112. (call_script, "script_party_remove_all_companions", ":center_no"),
  59113. (change_screen_return),
  59114. (party_collect_attachments_to_party, ":center_no", "p_collective_enemy"), #recalculate so that
  59115. (call_script, "script_party_copy", "p_encountered_party_backup", "p_collective_enemy"), #leaving troops will not be considered as captured
  59116.  
  59117. ##nested diplomacy start+
  59118. #Anyone who lost a fief due to your surrender will be irritated
  59119. (try_for_range, ":village_no", centers_begin, centers_end),
  59120. (party_slot_eq, ":village_no", slot_village_bound_center, ":center_no"),
  59121. (party_get_slot, ":village_lord", ":village_no", slot_town_lord),
  59122. (neq, ":village_lord", "trp_player"),
  59123. (is_between, ":village_lord", heroes_begin, heroes_end),
  59124. (call_script, "script_change_player_relation_with_troop", ":village_lord", -1),
  59125. (try_end),
  59126. ##nested diplomacy end+
  59127. ##diplomacy
  59128. (call_script, "script_give_center_to_faction", "$current_town", ":besieger_faction"),
  59129. (call_script, "script_order_best_besieger_party_to_guard_center", ":center_no", ":besieger_faction"),
  59130.  
  59131. #relation and controversy
  59132. ##nested diplomacy start+, There should be no relation bonus with the enemy lord
  59133. #(call_script, "script_change_player_relation_with_troop", ":enemy_party_leader", 2),
  59134. ##nested diplomacy end+
  59135. (try_begin),
  59136. (gt, "$players_kingdom", 0),
  59137. (neq, "$players_kingdom", "fac_player_supporters_faction"),
  59138. (neq, "$players_kingdom", "fac_player_faction"),
  59139. (faction_get_slot, ":faction_leader", "$players_kingdom", slot_faction_leader),
  59140. ##diplomacy start+
  59141. ##OLD:
  59142. #(neq, ":faction_leader", "trp_player"),
  59143. ##NEW:
  59144. #Also guard against faction leader being some invalid negative number
  59145. (gt, ":faction_leader", "trp_player"),
  59146. ##diplomacy end+
  59147. (call_script, "script_change_player_relation_with_troop", ":faction_leader", -2),
  59148. (try_end),
  59149.  
  59150. (troop_get_slot, ":controversy", "trp_player", slot_troop_controversy),
  59151. (val_add, ":controversy", 4),
  59152. (val_min, ":controversy", 100),
  59153. (troop_set_slot, "trp_player", slot_troop_controversy, ":controversy"),
  59154. ##nested diplmacy start+ add garrison to fief
  59155. #The average # of troops added by script_cf_reinforce_party is 11.5.
  59156. (assign, ":garrison_strength", 3),#easy: 34.5 for a castle
  59157. (try_begin),
  59158. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  59159. (assign, ":garrison_strength", 9),#easy: 103.5 for a town
  59160. (try_end),
  59161. #Take into account campaign difficulty.
  59162. (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
  59163. (try_begin),
  59164. (eq, ":reduce_campaign_ai", 0), #hard 166% + 3 waves
  59165. (val_mul, ":garrison_strength", 5),
  59166. (val_div, ":garrison_strength", 3),
  59167. (val_add, ":garrison_strength", 3),
  59168. (else_try),
  59169. (eq, ":reduce_campaign_ai", 1), #moderate 166%
  59170. (val_mul, ":garrison_strength", 5),
  59171. (val_div, ":garrison_strength", 3),
  59172. #(else_try),
  59173. # (eq, ":reduce_campaign_ai", 2), #easy 100%
  59174. # (store_mul, ":garrison_strength", 1),
  59175. (try_end),
  59176.  
  59177. (try_for_range, ":unused", 0, ":garrison_strength"),
  59178. (call_script, "script_cf_reinforce_party", ":center_no"),
  59179. (try_end),
  59180. (try_for_range, ":unused", 0, 7),# ADD some XP initially
  59181. (store_mul, ":xp_range_min", 150, ":garrison_strength"),
  59182. (store_mul, ":xp_range_max", 200, ":garrison_strength"),
  59183. (store_random_in_range, ":xp", ":xp_range_min", ":xp_range_max"),
  59184. (party_upgrade_with_xp, ":center_no", ":xp", 0),
  59185. (try_end),
  59186. ##nested diplomacy end+
  59187. ]),
  59188.  
  59189.  
  59190. ("dplmc_send_messenger_to_troop",
  59191. [
  59192. (store_script_param, ":target_troop", 1),
  59193. (store_script_param, ":message", 2),
  59194. (store_script_param, ":orders_object", 3),
  59195.  
  59196. #SB : correcting destination for lords waiting to respawn
  59197. (troop_get_slot, ":target_party", ":target_troop", slot_troop_leaded_party),
  59198. (try_begin),
  59199. (le, ":target_party", 0),
  59200. (call_script, "script_lord_get_home_center", ":target_troop"),
  59201. (assign, ":target_party", reg0),
  59202. (try_end),
  59203.  
  59204. (set_spawn_radius, 1),
  59205. (spawn_around_party, "$current_town", "pt_messenger_party"),
  59206. (assign,":spawned_party",reg0),
  59207. #SB : factionalized messenger
  59208. (store_faction_of_party, ":faction_no", ":target_party"),
  59209. (try_begin),
  59210. (eq, ":faction_no", "fac_player_supporters_faction"),
  59211. (is_between, "$g_player_culture", npc_kingdoms_begin, kingdoms_end),
  59212. (assign, ":faction_no", "$g_player_culture"),
  59213. (try_end),
  59214. (try_begin),
  59215. (is_between, ":faction_no", npc_kingdoms_begin, kingdoms_end),
  59216. (faction_get_slot, ":messenger_troop", ":faction_no", slot_faction_messenger_troop),
  59217. (else_try),
  59218. (assign, ":messenger_troop", "trp_dplmc_messenger"),
  59219. (try_end),
  59220. (party_add_members, ":spawned_party", ":messenger_troop", 1),
  59221.  
  59222.  
  59223. (try_begin),
  59224. (eq, ":message", spai_accompanying_army),
  59225. (assign, ":orders_object", "p_main_party"),
  59226. (try_end),
  59227.  
  59228. # (party_add_members, ":spawned_party", "trp_dplmc_messenger", 1),
  59229. (store_faction_of_troop, ":player_faction", "trp_player"),
  59230. (party_set_faction, ":spawned_party", ":player_faction"),
  59231. (party_set_slot, ":spawned_party", slot_party_type, spt_messenger),
  59232. (party_set_slot, ":spawned_party", dplmc_slot_party_mission_diplomacy, ":message"),
  59233. (party_set_slot, ":spawned_party", slot_party_home_center, "$current_town"),
  59234.  
  59235. (party_set_ai_behavior, ":spawned_party", ai_bhvr_travel_to_party),
  59236. (party_set_ai_object, ":spawned_party", ":target_party"),
  59237. (party_set_slot, ":spawned_party", slot_party_ai_object, ":target_party"),
  59238. (party_set_slot, ":spawned_party", slot_party_orders_object, ":orders_object"),
  59239. #SB : cache the actual troop while going towards known center
  59240. (party_set_slot, ":spawned_party", dplmc_slot_party_origin, ":target_troop"),
  59241.  
  59242. (try_begin), #debug
  59243. (eq, "$cheat_mode", 1),
  59244. (str_store_party_name, s13, ":target_party"),
  59245. (display_message, "@{!}DEBUG - Send message to {s13}"),
  59246. (try_end),
  59247. ]
  59248. ),
  59249.  
  59250. ("dplmc_send_messenger_to_party",
  59251. [
  59252. (store_script_param, ":target_party", 1),
  59253. (store_script_param, ":message", 2),
  59254. (store_script_param, ":orders_object", 3),
  59255.  
  59256. (set_spawn_radius, 1),
  59257. (spawn_around_party, "$current_town", "pt_messenger_party"),
  59258. (assign, ":spawned_party", reg0),
  59259.  
  59260. #SB : factionalized messenger
  59261. (store_faction_of_party, ":faction_no", ":target_party"),
  59262. (try_begin),
  59263. (eq, ":faction_no", "fac_player_supporters_faction"),
  59264. (is_between, "$g_player_culture", npc_kingdoms_begin, kingdoms_end),
  59265. (assign, ":faction_no", "$g_player_culture"),
  59266. (try_end),
  59267.  
  59268. (try_begin),
  59269. (is_between, ":faction_no", npc_kingdoms_begin, kingdoms_end),
  59270. (faction_get_slot, ":messenger_troop", ":faction_no", slot_faction_messenger_troop),
  59271. (else_try),
  59272. (assign, ":messenger_troop", "trp_dplmc_messenger"),
  59273. (try_end),
  59274. (party_add_members, ":spawned_party", ":messenger_troop", 1),
  59275. (party_set_faction, ":spawned_party", "fac_player_faction"),
  59276. (party_set_slot, ":spawned_party", slot_party_type, spt_messenger),
  59277. (party_set_slot, ":spawned_party", dplmc_slot_party_mission_diplomacy, ":message"),
  59278. (party_set_slot, ":spawned_party", slot_party_home_center, "$current_town"),
  59279.  
  59280. (party_set_ai_behavior, ":spawned_party", ai_bhvr_travel_to_party),
  59281. (party_set_ai_object, ":spawned_party", ":target_party"),
  59282. (party_set_slot, ":spawned_party", slot_party_ai_object, ":target_party"),
  59283. (party_set_slot, ":spawned_party", slot_party_orders_object, ":orders_object"),
  59284.  
  59285. (try_begin), #debug
  59286. (eq, "$cheat_mode", 1),
  59287. (str_store_party_name, s13, ":target_party"),
  59288. (display_message, "@{!}DEBUG - Send message to {s13}"),
  59289. (try_end),
  59290. ]
  59291. ),
  59292.  
  59293. ("dplmc_send_gift",
  59294. [
  59295. (store_script_param, ":target_troop", 1),
  59296. (store_script_param, ":gift", 2),
  59297. (store_script_param, ":amount", 3),
  59298.  
  59299. (try_begin),
  59300. (troop_slot_eq, ":target_troop", slot_troop_occupation, slto_kingdom_hero),
  59301. (troop_get_slot, ":target_party", ":target_troop", slot_troop_leaded_party),
  59302. (else_try),
  59303. (troop_slot_eq, ":target_troop", slot_troop_occupation, slto_kingdom_lady),
  59304. (troop_get_slot, ":target_party", ":target_troop", slot_troop_cur_center),
  59305. (try_end),
  59306.  
  59307.  
  59308. (try_begin), #debug
  59309. (eq, "$cheat_mode", 1),
  59310. (str_store_item_name, s12, ":gift"),
  59311. (str_store_party_name, s13, ":target_party"),
  59312. (display_message, "@{!}DEBUG - Bring {s12} to {s13}"),
  59313. (try_end),
  59314.  
  59315. (try_begin),
  59316. #Guard against this being called without an explicit amount
  59317. (lt, ":amount", 1),
  59318. (display_message, "@{!} ERROR: Bad gift amount {reg0}. (Tell the mod writer he needs to update his code.) Using a safe default."),
  59319. (assign, ":amount", 1),
  59320. (troop_slot_eq, ":target_troop", slot_troop_occupation, slto_kingdom_hero),
  59321. (assign, ":amount", 150),
  59322. (try_end),
  59323. (assign, ":original_amount", ":amount"),#Save this here because amount gets modified below!
  59324.  
  59325. (call_script, "script_dplmc_withdraw_from_treasury", 50),
  59326. (troop_get_inventory_capacity, ":capacity", "trp_household_possessions"),
  59327.  
  59328. (try_for_range, ":inventory_slot", 0, ":capacity"),
  59329. (gt, ":amount", 0),
  59330. (troop_get_inventory_slot, ":item", "trp_household_possessions", ":inventory_slot"),
  59331. (eq, ":item", ":gift"),
  59332. (troop_inventory_slot_get_item_amount, ":tmp_amount", "trp_household_possessions", ":inventory_slot"),
  59333. (try_begin),
  59334. (le, ":tmp_amount", ":amount"),
  59335. (troop_inventory_slot_set_item_amount, "trp_household_possessions", ":inventory_slot", 0),
  59336. (val_sub, ":amount", ":tmp_amount"),
  59337. (else_try),
  59338. (val_sub, ":tmp_amount", ":amount"),
  59339. (troop_inventory_slot_set_item_amount, "trp_household_possessions", ":inventory_slot", ":tmp_amount"),
  59340. (assign, ":amount", 0),
  59341. (try_end),
  59342. (try_end),
  59343.  
  59344. (set_spawn_radius, 1),
  59345. (spawn_around_party, "$current_town", "pt_dplmc_gift_caravan"),
  59346. (assign,":spawned_party",reg0),
  59347. (party_set_slot, ":spawned_party", slot_party_type, dplmc_spt_gift_caravan),
  59348. (party_set_slot, ":spawned_party", dplmc_slot_party_mission_diplomacy, ":gift"),
  59349. (party_set_slot, ":spawned_party", slot_party_orders_object, ":target_troop"),
  59350.  
  59351. (party_set_ai_behavior, ":spawned_party", ai_bhvr_travel_to_party),
  59352. (party_set_ai_object, ":spawned_party", ":target_party"),
  59353. (party_set_slot, ":spawned_party", slot_party_ai_object, ":target_party"),
  59354. (party_stack_get_troop_id, ":caravan_master", ":spawned_party", 0),
  59355. (troop_set_slot, ":caravan_master", slot_troop_leaded_party, ":spawned_party"),
  59356. (party_set_slot, ":spawned_party", dplmc_slot_party_mission_parameter_1, ":original_amount"),
  59357. ]),
  59358.  
  59359. ("dplmc_send_gift_to_center",
  59360. [
  59361. (store_script_param, ":target_party", 1),
  59362. (store_script_param, ":gift", 2),
  59363. (store_script_param, ":amount", 3),
  59364.  
  59365. (try_begin), #debug
  59366. (eq, "$cheat_mode", 1),
  59367. (str_store_item_name, s12, ":gift"),
  59368. (str_store_party_name, s13, ":target_party"),
  59369. (display_message, "@{!}DEBUG - Bring {s12} to {s13}"),
  59370. (try_end),
  59371.  
  59372. (try_begin),
  59373. #Guard against this being called without an explicit amount
  59374. (lt, ":amount", 1),
  59375. (display_message, "@{!} ERROR: Bad gift amount {reg0}. (Tell the mod writer he needs to update his code.) Using a safe default."),
  59376. (assign, ":amount", 300),
  59377. (try_end),
  59378. (assign, ":original_amount", ":amount"),#Save this here because amount gets modified below!
  59379.  
  59380. (call_script, "script_dplmc_withdraw_from_treasury", 50),
  59381. (troop_get_inventory_capacity, ":capacity", "trp_household_possessions"),
  59382. (try_for_range, ":inventory_slot", 0, ":capacity"),
  59383. (gt, ":amount", 0),
  59384. (troop_get_inventory_slot, ":item", "trp_household_possessions", ":inventory_slot"),
  59385. (eq, ":item", ":gift"),
  59386. (troop_inventory_slot_get_item_amount, ":tmp_amount", "trp_household_possessions", ":inventory_slot"),
  59387. (try_begin),
  59388. (le, ":tmp_amount", ":amount"),
  59389. (troop_inventory_slot_set_item_amount, "trp_household_possessions", ":inventory_slot", 0),
  59390. (val_sub, ":amount", ":tmp_amount"),
  59391. (else_try),
  59392. (val_sub, ":tmp_amount", ":amount"),
  59393. (troop_inventory_slot_set_item_amount, "trp_household_possessions", ":inventory_slot", ":tmp_amount"),
  59394. (assign, ":amount", 0),
  59395. (try_end),
  59396. (try_end),
  59397.  
  59398. (set_spawn_radius, 1),
  59399. (spawn_around_party, "$current_town", "pt_dplmc_gift_caravan"),
  59400. (assign,":spawned_party",reg0),
  59401. (party_set_slot, ":spawned_party", slot_party_type, dplmc_spt_gift_caravan),
  59402. (party_set_slot, ":spawned_party", dplmc_slot_party_mission_diplomacy, ":gift"),
  59403. (party_set_slot, ":spawned_party", slot_party_orders_object, 0),
  59404.  
  59405. (party_set_ai_behavior, ":spawned_party", ai_bhvr_travel_to_party),
  59406. (party_set_ai_object, ":spawned_party", ":target_party"),
  59407. (party_set_slot, ":spawned_party", slot_party_ai_object, ":target_party"),
  59408. (party_stack_get_troop_id, ":caravan_master", ":spawned_party", 0),
  59409. (troop_set_slot, ":caravan_master", slot_troop_leaded_party, ":spawned_party"),
  59410. (troop_set_slot, ":caravan_master", slot_troop_leaded_party, ":spawned_party"),
  59411. (party_set_slot, ":spawned_party", dplmc_slot_party_mission_parameter_1, ":original_amount"),
  59412. ]),
  59413.  
  59414. ("dplmc_troop_political_notes_to_s47",
  59415. [
  59416. (store_script_param, ":troop_no", 1),
  59417. ##diplomacy start+
  59418. (assign, ":save_reg1", reg1),#save to revert
  59419. (assign, ":save_reg4", reg4),#save to revert
  59420.  
  59421. (try_begin),
  59422. (eq, 0, 1),#Always disable this right now
  59423. (is_between, "$g_talk_troop", heroes_begin, heroes_end),#i.e. not your chancellor
  59424. (assign, ":troop_speaker", "$g_talk_troop"),
  59425. (call_script, "script_troop_get_player_relation", ":troop_speaker"),
  59426. (assign, ":speaker_player_relation", reg0),
  59427. (else_try),
  59428. (assign, ":troop_speaker", -1),
  59429. (assign, ":speaker_player_relation", 100),
  59430. (try_end),
  59431. ##diplomacy end+
  59432.  
  59433. (try_begin),
  59434. (str_clear, s47),
  59435.  
  59436. (store_faction_of_troop, ":troop_faction", ":troop_no"),
  59437.  
  59438. (faction_get_slot, ":faction_leader", ":troop_faction", slot_faction_leader),
  59439.  
  59440. (str_clear, s40),
  59441. (assign, ":logged_a_rivalry", 0),
  59442. ##nested diplomacy start+
  59443. (str_clear, s41),
  59444. #lord can be married or related to player
  59445. #(try_for_range, ":kingdom_hero", active_npcs_begin, active_npcs_end),
  59446. (try_for_range, ":kingdom_hero", active_npcs_including_player_begin, active_npcs_end),
  59447. #Also, don't include rivalries with retired (or dead) characters
  59448. (neg|troop_slot_ge, ":troop_no", slot_troop_occupation, slto_retirement),
  59449. ##nested diplomacy end+
  59450. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":kingdom_hero"),
  59451. (lt, reg0, -10),
  59452.  
  59453. (str_store_troop_name_link, s39, ":kingdom_hero"),
  59454. ##nested diplomacy start+ use second person
  59455. (try_begin),
  59456. (eq, ":kingdom_hero", "trp_player"),
  59457. (str_store_string, s39, "str_you"),
  59458. (try_end),
  59459. ##nested diplomacy end+
  59460. (try_begin),
  59461. (eq, ":logged_a_rivalry", 0),
  59462. ##nested diplomacy start+
  59463. (call_script, "script_dplmc_store_troop_is_female_reg", ":troop_no", 4),#use reg4 for gender-correct pronoun
  59464. ##nested diplomacy end+
  59465. (str_store_string, s40, "str_dplmc_s39_rival"),
  59466. (assign, ":logged_a_rivalry", 1),
  59467. (else_try),
  59468. (str_store_string, s41, "str_s40"),
  59469. (str_store_string, s40, "str_dplmc_s41_s39_rival"),
  59470. (try_end),
  59471.  
  59472. (try_end),
  59473.  
  59474. (str_clear, s46),
  59475. ##nested diplomacy start+
  59476. #(troop_get_type, reg4, ":troop_no"),#use for gender-correct pronoun
  59477. (call_script, "script_dplmc_store_troop_is_female_reg", ":troop_no", 4),
  59478. (str_store_troop_name, s46,":troop_no"),
  59479. (assign, ":details_available", 0),
  59480. (try_begin),
  59481. #Enable details for lords you have met
  59482. (neg|troop_slot_eq, ":troop_no", slot_troop_met, 0),
  59483. (assign, ":details_available", 1),
  59484. (else_try),
  59485. #Enable details when using an "omniscient" or non-specific speaker
  59486. (neg|is_between, ":troop_speaker", heroes_begin, heroes_end),
  59487. (assign, ":details_available", 1),
  59488. (else_try),
  59489. #Enable details for NPCs that aren't standard heroes, because the following checks don't apply
  59490. (neg|is_between, ":troop_no", heroes_begin, heroes_end),
  59491. (assign, ":details_available", 1),
  59492. (else_try),
  59493. #Enable details for lords the speaker has met
  59494. (is_between, ":troop_speaker", heroes_begin, heroes_end),
  59495. (is_between, ":troop_no", heroes_begin, heroes_end),
  59496. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":troop_speaker"),
  59497. (neq, reg0, 0),#between NPCs, relation 0 means "have not met"
  59498. (assign, ":details_available", 1),
  59499. (else_try),
  59500. #Enable details for v. notable lords (based on renown)
  59501. (troop_slot_ge, ":troop_no", slot_troop_renown, 500),
  59502. (assign, ":details_available", 1),
  59503. (else_try),
  59504. #Enable details for v. notable lords (based on fiefs)
  59505. (assign, reg0, 0),
  59506. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  59507. (this_or_next|party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  59508. (this_or_next|party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":troop_no"),
  59509. (troop_slot_eq, ":troop_no", slot_troop_home, ":center_no"),
  59510. (val_add, reg0, 2),
  59511. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  59512. (val_add, reg0, 2),
  59513. (try_end),
  59514. (ge, reg0, 4),#one town, or 2+ castles
  59515. (assign, ":details_available", 1),
  59516. (try_end),
  59517. #xxx TODO: Make a full implementation of the above that takes into account the time of the last spy report.
  59518. (try_begin),
  59519. (eq, ":details_available", 0),
  59520. (troop_get_slot, reg11, ":troop_no", slot_lord_reputation_type),
  59521. (str_store_string, s46, "str_dplmc_reputation_unknown"),
  59522. (else_try),
  59523. ##nested diplomacy end+
  59524. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_martial),
  59525. (str_store_string, s46, "str_dplmc_reputation_martial"),
  59526. (else_try),
  59527. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  59528. (str_store_string, s46, "str_dplmc_reputation_debauched"),
  59529. (else_try),
  59530. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_selfrighteous),
  59531. (str_store_string, s46, "str_dplmc_reputation_pitiless"),
  59532. (else_try),
  59533. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  59534. (str_store_string, s46, "str_dplmc_reputation_calculating"),
  59535. (else_try),
  59536. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_quarrelsome),
  59537. (str_store_string, s46, "str_dplmc_reputation_quarrelsome"),
  59538. (else_try),
  59539. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  59540. (str_store_string, s46, "str_dplmc_reputation_goodnatured"),
  59541. (else_try),
  59542. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  59543. (str_store_string, s46, "str_dplmc_reputation_upstanding"),
  59544. (else_try),
  59545. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_conventional),
  59546. (str_store_string, s46, "str_dplmc_reputation_conventional"),
  59547. (else_try),
  59548. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_adventurous),
  59549. (str_store_string, s46, "str_dplmc_reputation_adventurous"),
  59550. (else_try),
  59551. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_otherworldly),
  59552. (str_store_string, s46, "str_dplmc_reputation_romantic"),
  59553. (else_try),
  59554. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_moralist),
  59555. (str_store_string, s46, "str_dplmc_reputation_moralist"),
  59556. (else_try),
  59557. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_ambitious),
  59558. (str_store_string, s46, "str_dplmc_reputation_ambitious"),
  59559. (else_try),
  59560. (troop_get_slot, reg11, ":troop_no", slot_lord_reputation_type),
  59561. (str_store_string, s46, "str_dplmc_reputation_unknown"),
  59562. (try_end),
  59563.  
  59564. ##diplomacy start+
  59565. (str_clear, s39),#remove annoying bug
  59566. (str_clear, s45),#remove annoying bug
  59567.  
  59568. #Special-case spouse into showing up if it doesn't get added below
  59569. (try_begin),
  59570. (troop_get_slot, ":spouse", ":troop_no", slot_troop_spouse),
  59571. (ge, ":spouse", 0),
  59572.  
  59573. #Because blank memory is initially zero, enforce this
  59574. (this_or_next|is_between, ":troop_no", heroes_begin, heroes_end),
  59575. (neq, ":spouse", "trp_player"),
  59576. #Initialize s45
  59577. (str_store_troop_name, s39, ":spouse"),
  59578. (try_begin),
  59579. (eq, ":spouse", "trp_player"),
  59580. (str_store_string, s39, "str_you"),##<-- dplmc+ note, this was s59 before, probably an accidental bug
  59581. (else_try), #SB : speaker
  59582. (eq, ":spouse", ":troop_speaker"),
  59583. (str_store_string, s39, "str_me"),
  59584. (try_end),
  59585. (str_store_string, s45, "str_dplmc_s40_married_s39"),
  59586. (try_end),
  59587. ##diplomacy end+
  59588.  
  59589. (try_for_range, ":love_interest_slot", slot_troop_love_interest_1, slot_troop_love_interests_end),
  59590. (troop_get_slot, ":love_interest", ":troop_no", ":love_interest_slot"),
  59591. ##nested diplomacy start+ ; some lords could romance opposite-gender lords
  59592. #(is_between, ":love_interest", kingdom_ladies_begin, kingdom_ladies_end),
  59593. (is_between, ":love_interest", active_npcs_begin, kingdom_ladies_end),
  59594. #Also prevent a bug for companions / claimants who are lords
  59595. (neq, ":love_interest", "trp_knight_1_1_wife"),#<- should not appear in the game
  59596. #Also prevent bad messages for married/betrothed lords
  59597. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_spouse, ":love_interest"),
  59598. (troop_slot_eq, ":troop_no", slot_troop_spouse, -1),
  59599. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_betrothed, ":love_interest"),
  59600. (troop_slot_eq, ":troop_no", slot_troop_betrothed, -1),
  59601. ##nested diplomacy end+
  59602. (str_store_troop_name, s39, ":love_interest"),
  59603. ##nested diplomacy start+ Use second person properly
  59604. (try_begin),
  59605. (eq, ":love_interest", "trp_player"),
  59606. (str_store_string, s39, "str_you"),
  59607. (else_try), #SB : speaker
  59608. (eq, ":love_interest", ":troop_speaker"),
  59609. (str_store_string, s39, "str_me"),
  59610. (try_end),
  59611. ##nested diplomacy start+
  59612. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":love_interest"),
  59613. ##nested diplomacy start+
  59614. (call_script, "script_dplmc_store_troop_is_female_reg", ":troop_no", 4),#use reg4 for gender-correct pronoun
  59615. ##nested diplomacy end+
  59616. (str_store_string, s45, "str_dplmc_s40_love_interest_s39"),
  59617. (try_begin),
  59618. (troop_slot_eq, ":troop_no", slot_troop_spouse, ":love_interest"),
  59619. (str_store_string, s45, "str_dplmc_s40_married_s39"),
  59620. (else_try),
  59621. (troop_slot_eq, ":troop_no", slot_troop_betrothed, ":love_interest"),
  59622. (str_store_string, s45, "str_dplmc_s40_betrothed_s39"),
  59623. (try_end),
  59624. (try_end),
  59625.  
  59626. (str_clear, s44),
  59627. (try_begin),
  59628. (neq, ":troop_no", ":faction_leader"),
  59629. ##nested diplomacy start+
  59630. (gt, ":details_available", 0),
  59631. #Ensure leader is valid
  59632. (assign, reg0, 0),#continue if 0
  59633. (try_begin),
  59634. (neq, ":troop_no", "trp_player"),
  59635. (neq, ":faction_leader", "trp_player"),
  59636. (this_or_next|neg|is_between, ":troop_no", heroes_begin, heroes_end),
  59637. (neg|is_between, ":faction_leader", heroes_begin, heroes_end),
  59638. (assign, reg0, 1),
  59639. (try_end),
  59640. (eq, reg0, 0),
  59641.  
  59642. (try_begin),
  59643. (gt, ":troop_speaker", 0),
  59644. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":troop_no", ":troop_speaker"),
  59645. #(val_min, reg0, 20),
  59646. #(neq, ":faction_leader", "trp_player"),
  59647. #(val_div, reg0, 2),
  59648. (try_end),
  59649. (this_or_next|lt, reg0, 1),
  59650. (ge, ":speaker_player_relation", 1),
  59651. ##nested diplomacy end+
  59652. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_leader"),
  59653.  
  59654. (assign, ":relation", reg0),
  59655. ##diplomacy start+ Don't mention anything for kingdom ladies at the beginning; it doesn't add information.
  59656. (this_or_next|lt, reg0, 0),
  59657. (this_or_next|gt, reg0, 1),#Remember that relation 1 is neutral (it just means "met") between NPCs
  59658. (this_or_next|neg|is_between, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  59659. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  59660. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_granted_fief),
  59661. (troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_lord_rejoined),
  59662. ##diplomacy end+
  59663. (store_add, ":normalized_relation", ":relation", 100),
  59664. (val_add, ":normalized_relation", 5),
  59665. (store_div, ":str_offset", ":normalized_relation", 10),
  59666. (val_clamp, ":str_offset", 0, 20),
  59667. ##nested diplomacy start+
  59668. #(troop_get_type, reg4, ":troop_no"),#use for gender-correct pronoun
  59669. (call_script, "script_dplmc_store_troop_is_female_reg", ":troop_no", 4),
  59670. #TODO: Come back and add this (take into account spying)
  59671. #(neq, ":details_available", 0),#don't show unless more details are available
  59672. ##nested diplomacy end+
  59673. (store_add, ":str_id", "str_dplmc_relation_mnus_100_ns", ":str_offset"),
  59674. (try_begin),
  59675. (eq, ":faction_leader", "trp_player"),
  59676. ##nested diplomacy start+ "str_you" exists, so we might as well use it
  59677. #(str_store_string, s59, "@you"),
  59678. (str_store_string, s59, "str_you"),
  59679. ##diplomacy end+
  59680. (else_try),
  59681. (str_store_troop_name, s59, ":faction_leader"),
  59682. (try_end),
  59683. (str_store_string, s59, ":str_id"),
  59684. (str_store_string, s44, "@{!}^{s59}"),
  59685. (try_end),
  59686.  
  59687. (str_clear, s48),
  59688.  
  59689. (try_begin),
  59690. (eq, "$cheat_mode", 1),
  59691. (store_current_hours, ":hours"),
  59692. (gt, ":hours", 0),
  59693. (call_script, "script_calculate_troop_political_factors_for_liege", ":troop_no", ":faction_leader"),
  59694. (str_store_string, s48, "str_sense_of_security_military_reg1_court_position_reg3_"),
  59695. (try_end),
  59696.  
  59697. (str_store_string, s47, "str_s46s45s44s48"),
  59698.  
  59699. (try_end),
  59700. ##diplomacy start+
  59701. (assign, reg1, ":save_reg1"),#revert register
  59702. (assign, reg4, ":save_reg4"),#revert register to avoid clobbering
  59703. ##diplomacy end+
  59704. ]),
  59705.  
  59706. ("dplmc_send_patrol",
  59707. [
  59708. (store_script_param, ":start_party", 1),
  59709. (store_script_param, ":target_party", 2),
  59710. (store_script_param, ":size", 3), #0 small, 1 medium, 2, big, 3 elite
  59711. (store_script_param, ":template_faction", 4),
  59712. (store_script_param, ":order_troop", 5),
  59713.  
  59714. (set_spawn_radius, 1),
  59715. (spawn_around_party, ":start_party", "pt_patrol_party"),
  59716. (assign,":spawned_party",reg0),
  59717. (party_set_faction, ":spawned_party", ":template_faction"),
  59718. (party_set_slot, ":spawned_party", slot_party_type, spt_patrol),
  59719. (party_set_slot, ":spawned_party", slot_party_home_center, ":start_party"),
  59720. (party_set_slot, ":spawned_party", dplmc_slot_party_mission_diplomacy, ":order_troop"),
  59721. (str_store_party_name, s5, ":target_party"),
  59722. (party_set_name, ":spawned_party", "str_s5_patrol"),
  59723.  
  59724. (party_set_ai_behavior, ":spawned_party", ai_bhvr_travel_to_party),
  59725. (party_set_ai_object, ":spawned_party", ":target_party"),
  59726. (party_set_slot, ":spawned_party", slot_party_ai_object, ":target_party"),
  59727. (party_set_slot, ":spawned_party", slot_party_ai_state, spai_patrolling_around_center),
  59728.  
  59729. (try_begin),
  59730. (neg|is_between, ":template_faction", npc_kingdoms_begin, npc_kingdoms_end),
  59731.  
  59732. (party_get_slot, ":template_faction", ":start_party", slot_center_original_faction),
  59733. (try_begin),
  59734. (is_between, "$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  59735. (assign, ":template_faction", "$g_player_culture"),
  59736. (else_try),
  59737. (party_get_slot, ":town_lord", ":start_party", slot_town_lord),
  59738. (gt, ":town_lord", 0),
  59739. (troop_get_slot, ":template_faction", ":town_lord", slot_troop_original_faction),
  59740. (try_end),
  59741.  
  59742. (try_begin),
  59743. (eq, ":size", 0),
  59744. (call_script, "script_dplmc_withdraw_from_treasury", 1000),
  59745. (else_try),
  59746. (this_or_next|eq, ":size", 1),
  59747. (eq, ":size", 3),
  59748. (call_script, "script_dplmc_withdraw_from_treasury", 2000),
  59749. (else_try),
  59750. (eq, ":size", 2),
  59751. (call_script, "script_dplmc_withdraw_from_treasury", 3000),
  59752. (try_end),
  59753. (try_end),
  59754.  
  59755. (faction_get_slot, ":party_template_a", ":template_faction", slot_faction_reinforcements_a),
  59756. (faction_get_slot, ":party_template_b", ":template_faction", slot_faction_reinforcements_b),
  59757. (faction_get_slot, ":party_template_c", ":template_faction", slot_faction_reinforcements_c),
  59758.  
  59759. (try_begin),
  59760. (eq, ":size", 3),
  59761. (party_add_template, ":spawned_party", ":party_template_c"),
  59762. (party_add_template, ":spawned_party", ":party_template_c"),
  59763. (else_try),
  59764. (val_add, ":size", 1),
  59765. (val_mul, ":size", 2),
  59766. (try_for_range, ":cur_i", 0, ":size"),
  59767. (store_random_in_range, ":random", 0, 3),
  59768. (try_begin),
  59769. (eq, ":random", 0),
  59770. (party_add_template, ":spawned_party", ":party_template_a"),
  59771. (else_try),
  59772. (eq, ":random", 1),
  59773. (party_add_template, ":spawned_party", ":party_template_b"),
  59774. (else_try),
  59775. (party_add_template, ":spawned_party", ":party_template_c"),
  59776. (try_end),
  59777.  
  59778. (try_begin), #debug
  59779. (eq, "$cheat_mode", 1),
  59780. (assign, reg0, ":cur_i"),
  59781. (str_store_faction_name, s7, ":template_faction"),
  59782. (display_message, "@{!}DEBUG - Added {reg0}.template of faction {s7} to patrol."),
  59783. (try_end),
  59784. (try_end),
  59785. (try_end),
  59786.  
  59787.  
  59788. (try_begin), #debug
  59789. (eq, "$cheat_mode", 1),
  59790. (str_store_party_name, s13, ":target_party"),
  59791. (str_store_faction_name, s14, ":template_faction"),
  59792. (str_store_party_name, s15, ":start_party"),
  59793. (display_message, "@{!}DEBUG - Send {s14} patrol from {s15} to {s13}"),
  59794. (try_end),
  59795. ]),
  59796.  
  59797. ("dplmc_send_patrol_party",
  59798. [
  59799. (store_script_param, ":start_party", 1),
  59800. (store_script_param, ":target_party", 2),
  59801. (store_script_param, ":party_no", 3),
  59802. (store_script_param, ":template_faction", 4),
  59803.  
  59804. (set_spawn_radius, 1),
  59805. (spawn_around_party, ":start_party", "pt_patrol_party"),
  59806. (assign,":spawned_party",reg0),
  59807. (party_set_faction, ":spawned_party", ":template_faction"),
  59808. (party_set_slot, ":spawned_party", slot_party_type, spt_patrol),
  59809. (party_set_slot, ":spawned_party", slot_party_home_center, ":start_party"),
  59810. (str_store_party_name, s5, ":target_party"),
  59811. (party_set_name, ":spawned_party", "str_s5_patrol"),
  59812.  
  59813. (party_set_ai_behavior, ":spawned_party", ai_bhvr_travel_to_party),
  59814. (party_set_ai_object, ":spawned_party", ":target_party"),
  59815. (party_set_slot, ":spawned_party", slot_party_ai_object, ":target_party"),
  59816. (party_set_slot, ":spawned_party", slot_party_ai_state, spai_patrolling_around_center),
  59817.  
  59818. (call_script, "script_party_add_party", ":spawned_party", ":party_no"),
  59819. ]),
  59820.  
  59821. ("dplmc_move_troops_party",
  59822. [
  59823. (store_script_param, ":start_party", 1),
  59824. (store_script_param, ":target_party", 2),
  59825. (store_script_param, ":party_no", 3),
  59826. (store_script_param, ":template_faction", 4),
  59827.  
  59828. (set_spawn_radius, 1),
  59829. (spawn_around_party, ":start_party", "pt_patrol_party"),
  59830. (assign,":spawned_party",reg0),
  59831. (party_set_faction, ":spawned_party", ":template_faction"),
  59832. (party_set_slot, ":spawned_party", slot_party_type, spt_patrol),
  59833. (party_set_slot, ":spawned_party", slot_party_home_center, ":start_party"),
  59834. (str_store_party_name, s5, ":target_party"),
  59835. #SB : fixed string
  59836. (party_set_name, ":spawned_party", "str_s5_transfer"),
  59837.  
  59838. (party_set_ai_behavior, ":spawned_party", ai_bhvr_travel_to_party),
  59839. (party_set_ai_object, ":spawned_party", ":target_party"),
  59840. (party_set_slot, ":spawned_party", slot_party_ai_object, ":target_party"),
  59841. (party_set_slot, ":spawned_party", slot_party_ai_state, spai_retreating_to_center),
  59842. (party_set_aggressiveness, ":spawned_party", 0),
  59843. (party_set_courage, ":spawned_party", 3),
  59844. (party_set_ai_initiative, ":spawned_party", 100),
  59845.  
  59846. (call_script, "script_party_add_party", ":spawned_party", ":party_no"),
  59847. ]),
  59848.  
  59849. ("dplmc_send_scout_party",
  59850. [
  59851. (store_script_param, ":start_party", 1),
  59852. (store_script_param, ":target_party", 2),
  59853. (store_script_param, ":faction", 3),
  59854.  
  59855. (set_spawn_radius, 1),
  59856. (spawn_around_party, ":start_party", "pt_scout_party"),
  59857. (assign,":spawned_party",reg0),
  59858. (party_set_faction, ":spawned_party", ":faction"),
  59859. (party_set_slot, ":spawned_party", slot_party_type, spt_scout),
  59860. (party_set_slot, ":spawned_party", slot_party_home_center, ":start_party"),
  59861. (str_store_party_name, s5, ":target_party"),
  59862. (party_set_name, ":spawned_party", "str_s5_scout"),
  59863.  
  59864. (party_add_members, ":spawned_party", "trp_dplmc_scout", 1),
  59865.  
  59866. (party_get_position, pos1, ":target_party"),
  59867. (map_get_random_position_around_position, pos2, pos1, 1),
  59868. (party_set_ai_behavior, ":spawned_party", ai_bhvr_travel_to_point),
  59869. (party_set_ai_target_position, ":spawned_party", pos2),
  59870. (party_set_slot, ":spawned_party", slot_party_ai_object, ":target_party"),
  59871. (party_set_slot, ":spawned_party", slot_party_orders_object, ":target_party"),
  59872. (party_set_aggressiveness, ":spawned_party", 0),
  59873. (party_set_courage, ":spawned_party", 3),
  59874. (party_set_ai_initiative, ":spawned_party", 100),
  59875. ]),
  59876.  
  59877. ("dplmc_init_domestic_policy",
  59878. [
  59879. (try_for_range, ":kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  59880. (try_begin),
  59881. (store_random_in_range, ":random", -3, 4),
  59882. (faction_set_slot, ":kingdom", dplmc_slot_faction_centralization, ":random"),
  59883. (store_random_in_range, ":random", -3, 4),
  59884. (faction_set_slot, ":kingdom", dplmc_slot_faction_aristocracy, ":random"),
  59885. (store_random_in_range, ":random", -3, 4),
  59886. (faction_set_slot, ":kingdom", dplmc_slot_faction_quality, ":random"),
  59887. (store_random_in_range, ":random", -3, 4),
  59888. (faction_set_slot, ":kingdom", dplmc_slot_faction_serfdom, ":random"),
  59889. (try_end),
  59890. (try_end),
  59891. ]),
  59892.  
  59893. #SB : add this to allow randomization of a single faction (see prsnt_dplmc_policy_management)
  59894. ("dplmc_randomize_faction_domestic_policy",
  59895. [
  59896. (store_script_param, ":kingdom", 1),
  59897. (try_for_range, ":slot", dplmc_slot_faction_centralization, dplmc_slot_faction_mercantilism + 1),
  59898. (store_random_in_range, ":random", -3, 4),
  59899. (faction_set_slot, ":kingdom", ":slot", ":random"),
  59900. (try_end),
  59901. ]),
  59902.  
  59903. ("dplmc_is_affiliated_family_member",
  59904. [
  59905. (store_script_param, ":troop_id", 1),
  59906.  
  59907. (assign, ":is_affiliated_family_member", 0),
  59908. ##nested diplomacy start+
  59909. (assign, ":save_reg1", reg1),#<- Save reg1 which gets overwritten by script_dplmc_troop_get_family_relation_to_troop
  59910. ##nested diplomacy end+
  59911. (try_begin),
  59912. (is_between, "$g_player_affiliated_troop", lords_begin, kingdom_ladies_end),
  59913. (try_begin),
  59914. ##nested diplomacy start+ add use of dplmc_slot_troop_affiliated
  59915. (this_or_next|troop_slot_eq, ":troop_id", dplmc_slot_troop_affiliated, 3),
  59916. ##diplomacy end+
  59917. (eq, "$g_player_affiliated_troop", ":troop_id"),
  59918. (assign, ":is_affiliated_family_member", 1),
  59919. (else_try),
  59920. (is_between, ":troop_id", lords_begin, kingdom_ladies_end),
  59921. ##nested diplomacy start+
  59922. #(call_script, "script_troop_get_family_relation_to_troop", ":troop_id", "$g_player_affiliated_troop"),
  59923. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":troop_id", "$g_player_affiliated_troop"),
  59924. ##nested diplomacy end+
  59925. (gt, reg0, 0),
  59926. (call_script, "script_troop_get_relation_with_troop", "$g_player_affiliated_troop", ":troop_id"),
  59927. (ge, reg0, -10),
  59928. (assign, ":is_affiliated_family_member", 1),
  59929. (try_end),
  59930. (try_end),
  59931. ##nested diplomacy start+
  59932. (assign, reg1, ":save_reg1"),#revert register
  59933. ##nested diplomacy end+
  59934. (assign, reg0, ":is_affiliated_family_member"),
  59935. ]),
  59936.  
  59937. ("dplmc_affiliate_end",
  59938. [
  59939. (store_script_param, ":cause", 1),
  59940.  
  59941. (assign, "$g_player_affiliated_troop", 0),
  59942.  
  59943. (try_begin),
  59944. (eq, ":cause", 1),
  59945. (assign, ":max_penalty", -16),
  59946. (assign, ":term", 20),
  59947. (assign, ":honor_val", 10),
  59948. (else_try),
  59949. (assign, ":max_penalty", -12),
  59950. (assign, ":honor_val", 5),
  59951. (assign, ":term", 15),
  59952. (try_end),
  59953.  
  59954. (try_for_range, ":family_member", lords_begin, kingdom_ladies_end),
  59955. (call_script, "script_dplmc_is_affiliated_family_member", ":family_member"),
  59956. (gt, reg0, 0),
  59957.  
  59958. (store_skill_level, ":value", "skl_persuasion", "trp_player"),
  59959. (store_random_in_range, ":value", 0, ":value"),
  59960. ##nested diplomacy start+ Fix mistake.
  59961. ##
  59962. ##OLD:
  59963. #(val_add, ":value", ":max_penalty", ":value"),
  59964. #
  59965. #NEW:
  59966. #I'm pretty sure this is what was intended.
  59967. (val_add, ":value", ":max_penalty"),
  59968. ##nested diplomacy end+
  59969. (val_min, ":value", 0),
  59970. (call_script, "script_change_player_relation_with_troop", ":family_member", ":value"),
  59971. (try_end),
  59972.  
  59973. (try_begin),
  59974. (gt, "$player_honor", ":honor_val"),
  59975. (val_add, ":term", ":honor_val"),
  59976. (else_try),
  59977. (val_add, ":term", "$player_honor"),
  59978. (try_end),
  59979.  
  59980. (store_current_hours, ":cur_hours"),
  59981. (store_sub, ":affiliated_hours", ":cur_hours", "$g_player_affiliated_time"),
  59982. (store_div, ":affiliated_days", ":affiliated_hours", 24),
  59983. (val_sub, ":term", ":affiliated_days"),
  59984. (val_max, ":term", 0),
  59985. (val_min, ":term", 40),
  59986.  
  59987.  
  59988. (troop_get_slot, ":controversy", "trp_player", slot_troop_controversy),
  59989. (val_add, ":controversy", ":term"),
  59990. (val_min, ":controversy", 100),
  59991. (troop_set_slot, "trp_player", slot_troop_controversy, ":controversy"),
  59992.  
  59993. ]),
  59994.  
  59995. ("dplmc_appoint_chamberlain",
  59996. [
  59997. (troop_set_auto_equip, "trp_dplmc_chamberlain", 0),
  59998. (troop_set_inventory_slot, "trp_dplmc_chamberlain", ek_body, "itm_tabard"),
  59999. (troop_set_inventory_slot, "trp_dplmc_chamberlain", ek_foot, "itm_leather_boots"),
  60000. (assign, "$g_player_chamberlain", "trp_dplmc_chamberlain"),
  60001. #SB : grab all gold from chest troops (seneschals)
  60002. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  60003. (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  60004. (store_sub, ":chest_troop", ":center_no", towns_begin),
  60005. (val_add, ":chest_troop", "trp_town_1_seneschal"),
  60006. (store_troop_gold, ":cur_gold", ":chest_troop"),
  60007. (troop_remove_gold, ":chest_troop", ":cur_gold"),
  60008. (troop_add_gold, "trp_household_possessions", ":cur_gold"), #no script call
  60009. (try_end),
  60010. ]),
  60011.  
  60012. ("dplmc_appoint_chancellor",
  60013. [
  60014. (troop_set_auto_equip, "trp_dplmc_chancellor", 0),
  60015. (troop_set_inventory_slot, "trp_dplmc_chancellor", ek_body, "itm_nobleman_outfit"),
  60016. (troop_set_inventory_slot, "trp_dplmc_chancellor", ek_foot, "itm_leather_boots"),
  60017. (assign, "$g_player_chancellor", "trp_dplmc_chancellor"),
  60018. ]),
  60019.  
  60020. ("dplmc_appoint_constable",
  60021. [
  60022. (troop_set_auto_equip, "trp_dplmc_constable", 0),
  60023. (troop_set_inventory_slot, "trp_dplmc_constable", ek_body, "itm_dplmc_coat_of_plates_red_constable"),
  60024. (troop_set_inventory_slot, "trp_dplmc_constable", ek_foot, "itm_leather_boots"),
  60025. (assign, "$g_player_constable", "trp_dplmc_constable"),
  60026. ]),
  60027.  
  60028. ##diplomacy end
  60029.  
  60030. ##diplomacy start+
  60031. #Importing a script used in Custom Commander. The inventory copying is used
  60032. #as a clever way to make "unmodifiable" views of others' equipment (both the
  60033. #PC and NPC have their inventory copied before viewing, and after the window
  60034. #closes the copies are written back over the originals).
  60035. ("dplmc_copy_inventory",
  60036. [
  60037. (store_script_param_1, ":source"),
  60038. (store_script_param_2, ":target"),
  60039.  
  60040. (troop_clear_inventory, ":target"),
  60041. (troop_get_inventory_capacity, ":inv_cap", ":source"),
  60042. (try_for_range, ":i_slot", 0, ":inv_cap"),
  60043. (troop_get_inventory_slot, ":item", ":source", ":i_slot"),
  60044. (troop_set_inventory_slot, ":target", ":i_slot", ":item"),
  60045. (troop_get_inventory_slot_modifier, ":imod", ":source", ":i_slot"),
  60046. (troop_set_inventory_slot_modifier, ":target", ":i_slot", ":imod"),
  60047. (troop_inventory_slot_get_item_amount, ":amount", ":source", ":i_slot"),
  60048. (gt, ":amount", 0),
  60049. (troop_inventory_slot_set_item_amount, ":target", ":i_slot", ":amount"),
  60050. (try_end),
  60051. ]),
  60052.  
  60053.  
  60054. #Decide whether an NPC wants to exchange a fief or not.
  60055. #
  60056. # param#1 is NPC being asked
  60057. # param#2 is that NPC's fief being asked for
  60058. # param#3 is the one asking (usually the player)
  60059. # param#4 is the fief being offered in exchange
  60060. #
  60061. # Result is returned in reg0. Negative means "no", zero means "yes",
  60062. # positive means "yes but you have to pay me this amount".
  60063. # If the result is negative, the response string is stored in s14.
  60064. ("dplmc_evaluate_fief_exchange",
  60065. [
  60066. (store_script_param, ":target_npc", 1),
  60067. (store_script_param, ":target_fief", 2),
  60068. (store_script_param, ":asker", 3),
  60069. (store_script_param, ":offered_fief", 4),
  60070.  
  60071. (assign, ":result", -1),
  60072. (assign, reg0, ":result"),
  60073. (str_store_string, s14, "str_ERROR_string"),
  60074.  
  60075. (try_begin),
  60076. #Both NPCs are valid, and are not same character. One can be the player.
  60077. (neq, ":target_npc", ":asker"),
  60078. (is_between, ":target_npc", heroes_begin, heroes_end),
  60079. (this_or_next|is_between, ":asker", heroes_begin, heroes_end),
  60080. (eq,":asker","trp_player"),
  60081. #Both fiefs are valid and owned by the lords in the arguments
  60082. (is_between, ":target_fief", centers_begin, centers_end),
  60083. (party_slot_eq, ":target_fief", slot_town_lord, ":target_npc"),
  60084. (is_between, ":offered_fief", centers_begin, centers_end),
  60085. (party_slot_eq, ":offered_fief", slot_town_lord, ":asker"),
  60086. #The lords are in the same faction
  60087. (store_troop_faction, ":target_faction", ":target_npc"),
  60088. (store_troop_faction, ":asker_faction", ":asker"),
  60089. (try_begin),
  60090. #Special handling needed for player faction
  60091. (eq, ":asker", "trp_player"),
  60092. (neg|eq, ":target_faction", ":asker_faction"),
  60093. (assign, ":asker_faction", "$players_kingdom"),
  60094. (try_end),
  60095. (this_or_next|eq, ":target_faction", ":asker_faction"),
  60096. (this_or_next|faction_slot_eq,":target_faction",slot_faction_leader,":asker"),
  60097. (faction_slot_eq,":asker_faction",slot_faction_leader,":target_npc"),
  60098. #Get prosperity for use in later tests
  60099. (party_get_slot, ":target_prosperity", ":target_fief", slot_town_prosperity),
  60100. (party_get_slot, ":offered_prosperity", ":offered_fief", slot_town_prosperity),
  60101. (store_div, ":min_prosperity", ":target_prosperity", 10),
  60102. (val_mul, ":min_prosperity", 10),
  60103. #...take into account relation
  60104. (call_script, "script_troop_get_relation_with_troop", ":target_npc", ":asker"),
  60105. (store_div, ":relation_div_10", reg0, 10),
  60106. (val_sub, ":min_prosperity", ":relation_div_10"),
  60107. #...take into account persuasion
  60108. (store_skill_level, ":asker_persuasion", "skl_persuasion", ":asker"),
  60109. (val_sub, ":min_prosperity", ":asker_persuasion"),
  60110. #...take into account personal (not party) trade skill
  60111. (store_skill_level, ":asker_trade", "skl_trade", ":asker"),
  60112. (val_sub, ":min_prosperity", ":asker_trade"),
  60113. #...don't let it rise above original's prosperity.
  60114. (val_min, ":min_prosperity", ":target_prosperity"),
  60115. #target_type 1 = village, 2 = castle, 3 = town
  60116. (assign, ":target_type", 0),
  60117. (try_begin),
  60118. (party_slot_eq, ":target_fief", slot_party_type, spt_town),
  60119. (assign, ":target_type", 3),
  60120. (else_try),
  60121. (party_slot_eq, ":target_fief", slot_party_type, spt_castle),
  60122. (assign, ":target_type", 2),
  60123. (else_try),
  60124. (party_slot_eq, ":target_fief", slot_party_type, spt_village),
  60125. (assign, ":target_type", 1),
  60126. (try_end),
  60127. (ge, ":target_type", 1),#break with error if the type was bad
  60128. #offered_type: 1 = village, 2 = castle, 3 = town
  60129. (assign, ":offered_type", 0),
  60130. (try_begin),
  60131. (party_slot_eq, ":offered_fief", slot_party_type, spt_town),
  60132. (assign, ":offered_type", 3),
  60133. (else_try),
  60134. (party_slot_eq, ":offered_fief", slot_party_type, spt_castle),
  60135. (assign, ":offered_type", 2),
  60136. (else_try),
  60137. (party_slot_eq, ":offered_fief", slot_party_type, spt_village),
  60138. (assign, ":offered_type", 1),
  60139. (try_end),
  60140. (ge, ":offered_type", 1),#break with error if the type was bad
  60141. #Now execute comparison logic:
  60142. (try_begin),
  60143. #refuse to trade town for a castle or village
  60144. (lt, ":offered_type", ":target_type"),
  60145. (eq, ":target_type", 3),
  60146. (str_store_string, s14, "str_dplmc_fief_exchange_refuse_town"),
  60147. (else_try),
  60148. #refuse to trade any better type for a worse type
  60149. (lt, ":offered_type", ":target_type"),
  60150. (str_store_string, s14, "str_dplmc_fief_exchange_refuse_castle"),
  60151. (else_try),
  60152. #refuse to trade for something under siege or being raided
  60153. (this_or_next|party_slot_eq, ":offered_fief", slot_village_state, svs_under_siege),
  60154. (party_slot_eq, ":offered_fief", slot_village_state, svs_being_raided),
  60155. (str_store_party_name, s14, ":offered_fief"),
  60156. (str_store_string, s14, "str_dplmc_fief_exchange_refuse_s14_attack"),
  60157. (else_try),
  60158. #accept a trade if the offered type is better
  60159. (lt, ":target_type", ":offered_type"),
  60160. (str_store_string, s14, "str_dplmc_fief_exchange_accept"),
  60161. (assign, ":result", 0),
  60162. (else_try),
  60163. #refuse to trade away home center (unless trading up for a better type)
  60164. #Target fief is home of NPC...
  60165. (this_or_next|party_slot_eq, ":target_fief", dplmc_slot_center_original_lord, ":target_npc"),
  60166. (troop_slot_eq, ":target_npc", slot_troop_home, ":target_fief"),
  60167. (neg|party_slot_eq, ":offered_fief", dplmc_slot_center_original_lord, ":target_npc"),
  60168. #...and offered fief is not.
  60169. (neg|troop_slot_eq, ":target_npc", slot_troop_home, ":offered_fief"),
  60170. (this_or_next|neg|is_between, ":target_npc", companions_begin, companions_end),
  60171. (neg|troop_slot_eq, ":target_npc", slot_troop_town_with_contacts, ":offered_fief"),
  60172. (str_store_party_name, s14, ":target_fief"), #Line added by zerilius
  60173. (str_store_string, s14, "str_dplmc_fief_exchange_refuse_home"),
  60174. (else_try),
  60175. #refuse trade if prosperity is too low
  60176. (lt, ":offered_prosperity", ":min_prosperity"),
  60177. (str_store_string, s14, "str_dplmc_fief_exchange_refuse_rich"),
  60178. (else_try),
  60179. #accept trade for 0 or more denars
  60180. (store_sub, ":result", ":target_prosperity", ":offered_prosperity"),
  60181. (val_mul, ":result", ":target_type"),
  60182. (val_mul, ":result", 36),#Should probably be 60 instead
  60183. #(val_div, ":result", 100),
  60184. (val_add, ":result", 2000),
  60185. (val_max, ":result", 0),
  60186. (try_begin),
  60187. (ge, ":result", 1),
  60188. (assign, reg3, ":result"),
  60189. (str_store_string, s14, "str_dplmc_fief_exchange_accept_reg3_denars"),
  60190. (else_try),
  60191. (str_store_string, s14, "str_dplmc_fief_exchange_accept"),
  60192. (try_end),
  60193. (try_end),
  60194. (try_end),
  60195. (assign, reg0, ":result"),
  60196. ]),
  60197.  
  60198. # script_dplmc_time_sorted_heroes_for_center_aux
  60199. # For internal use only
  60200. # param 1: center no
  60201. # param 2: party_no_to_collect_heroes
  60202. # param 3: minimum time since last met (inclusive), or negative for no restriction
  60203. # param 4: maximum time since last met (exclusive), or negative for no restriction
  60204. ("dplmc_time_sorted_heroes_for_center_aux",
  60205. [
  60206. (store_script_param_1, ":center_no"),
  60207. (store_script_param_2, ":party_no_to_collect_heroes"),
  60208. (store_script_param, ":min_time", 3),
  60209. (store_script_param, ":max_time", 4),
  60210.  
  60211. (store_current_hours, ":current_hours"),
  60212.  
  60213. (party_get_num_companion_stacks, ":num_stacks",":center_no"),
  60214. (try_for_range, ":i_stack", 0, ":num_stacks"),
  60215. (party_stack_get_troop_id, ":stack_troop",":center_no",":i_stack"),
  60216. (troop_is_hero, ":stack_troop"),
  60217. #get time since last talk
  60218. (troop_get_slot, ":troop_last_talk_time", ":stack_troop", slot_troop_last_talk_time),
  60219. (store_sub, ":time_since_last_talk", ":current_hours", ":troop_last_talk_time"),
  60220. #add if time meets constraints
  60221. (this_or_next|ge, ":time_since_last_talk", ":min_time"),
  60222. (lt, ":min_time", 0),
  60223. (this_or_next|lt, ":time_since_last_talk", ":max_time"),
  60224. (lt, ":max_time", 0),
  60225. (party_add_members, ":party_no_to_collect_heroes", ":stack_troop", 1),
  60226. (try_end),
  60227. (party_get_num_attached_parties, ":num_attached_parties", ":center_no"),
  60228. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  60229. (party_get_attached_party_with_rank, ":attached_party", ":center_no", ":attached_party_rank"),
  60230. (call_script, "script_dplmc_time_sorted_heroes_for_center_aux", ":attached_party", ":party_no_to_collect_heroes",":min_time",":max_time"),
  60231. (try_end),
  60232. ]),
  60233.  
  60234. # script_dplmc_time_sorted_heroes_for_center
  60235. # Input: arg1 = center_no, arg2 = party_no_to_collect_heroes
  60236. # Output: none, adds heroes to the party_no_to_collect_heroes party
  60237. # The catch is that it returns heroes who haven't been met in a day
  60238. # or more before others, for greater use in feasts.
  60239. ("dplmc_time_sorted_heroes_for_center",
  60240. [
  60241. (store_script_param_1, ":center_no"),
  60242. (store_script_param_2, ":party_no_to_collect_heroes"),
  60243. (party_clear, ":party_no_to_collect_heroes"),
  60244.  
  60245. #SB: include these heroes in sorting
  60246. (try_begin),
  60247. (eq, "$g_player_court", ":center_no"),
  60248. (store_faction_of_party, ":center_faction", ":center_no"),
  60249. (faction_slot_eq, ":center_faction", slot_faction_leader, "trp_player"),
  60250. ##diplomacy start+
  60251. #It's not exactly clear if this would work for kingdom ladies. If they
  60252. #can go from slto_kingdom_lady to slto_inactive, this could take them
  60253. #from there to slto_kingdom_hero unintentionally.
  60254. #
  60255. #Because of this, don't enable this for now. Elsewhere (where defections
  60256. #occur) add alternate behavior for promoted kingdom ladies.
  60257. #
  60258. #TODO: Later, make sure that kingdom ladies are never inactive normally,
  60259. #so this loop can be expanded to work with them.
  60260. ##diplomacy end+
  60261. (try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
  60262. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  60263. (eq, ":active_npc_faction", "fac_player_supporters_faction"),
  60264. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_inactive),
  60265. (neg|troop_slot_ge, ":active_npc", slot_troop_prisoner_of_party, 0), #if he/she is not prisoner in any center.
  60266. (neg|troop_slot_ge, ":active_npc", slot_troop_prisoner_of_party, 0), #if he/she does not have a party
  60267. (neq, ":active_npc", "$g_player_minister"),
  60268. (party_add_members, ":party_no_to_collect_heroes", ":active_npc"),
  60269. # (set_visitor, ":cur_pos", ":active_npc"),
  60270. # (val_add,":cur_pos", 1),
  60271. (try_end),
  60272. (try_end),
  60273.  
  60274. #Non-attached pretenders (make sure they're not thrown under the bus)
  60275. (try_for_range, ":pretender", pretenders_begin, pretenders_end),
  60276. (neq, ":pretender", "$supported_pretender"),
  60277. (troop_slot_eq, ":pretender", slot_troop_cur_center, ":center_no"),
  60278. (party_add_members, ":party_no_to_collect_heroes", ":pretender", 1),
  60279. (try_end),
  60280.  
  60281. #Heroes you haven't spoken to in 24+ hours
  60282. (call_script, "script_dplmc_time_sorted_heroes_for_center_aux",
  60283. ":center_no", ":party_no_to_collect_heroes", 24, -1),
  60284.  
  60285. #Heroes you haven't spoken to in 12 to 24 hours
  60286. (call_script, "script_dplmc_time_sorted_heroes_for_center_aux",
  60287. ":center_no", ":party_no_to_collect_heroes", 12, 24),
  60288.  
  60289. #Everyone else
  60290. (call_script, "script_dplmc_time_sorted_heroes_for_center_aux",
  60291. ":center_no", ":party_no_to_collect_heroes", -1, 12),
  60292. ]),
  60293.  
  60294. # script_script_dplmc_faction_leader_splits_gold
  60295. # INPUT: arg1 = troop_id, arg2 = new faction_no
  60296. # OUTPUT: none
  60297. ("dplmc_faction_leader_splits_gold",
  60298. [
  60299. (store_script_param_1, ":faction_no"),
  60300. (store_script_param_2, ":king_gold"),
  60301. (assign, ":push_reg0", reg0),#revert register value at end of script
  60302. (assign, ":push_reg1", reg1),#revert register value at end of script
  60303.  
  60304. (faction_get_slot, ":faction_liege", ":faction_no", slot_faction_leader),
  60305. (faction_get_slot, reg0, ":faction_no", dplmc_slot_faction_centralization),
  60306. (val_clamp, reg0, -3, 4),
  60307. (val_mul, reg0, -5),
  60308. (try_begin),
  60309. (troop_slot_ge, ":faction_liege", slot_troop_wealth, 20000),
  60310. (val_add, reg0, 20),#20% if the king is at or above his starting gold
  60311. (else_try),
  60312. (val_add, reg0, 50),#50% otherwise
  60313. (try_end),
  60314. (val_add, reg0, 50),
  60315. (store_mul, ":lord_gold", ":king_gold", reg0),#king splits other half among lords
  60316. (val_div, ":lord_gold", 100),
  60317. (val_sub, ":king_gold", ":lord_gold"),
  60318. (try_begin),
  60319. #If there's enough gold to give a meaningful amount to everyone, do so.
  60320. #(This accomplishes two things. It makes the distribution more even, and
  60321. #it prevents this script from taking an unreasonably long time for very
  60322. #large amounts of gold.)
  60323. #
  60324. #"Meaningful" is at least 300, because that's the minimum amount of gold a
  60325. #lord will to to a fief to collect (it is also the AI recruitment cost on
  60326. #hard).
  60327. (assign, ":num_lords", 0),#<-- number of lords in faction, not including faction leader
  60328. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  60329. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  60330. (eq, ":faction_no", ":lord_faction_no"),
  60331. (troop_set_slot, ":lord_no", slot_troop_temp_slot, 0),
  60332. (neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":lord_no"),
  60333. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  60334. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  60335. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  60336. (ge, ":lord_party", 0),
  60337. (val_add, ":num_lords", 1),
  60338. (try_end),
  60339. (try_begin),
  60340. #handle player
  60341. (eq, "$players_kingdom", ":faction_no"),
  60342. (neq, "trp_player", ":faction_liege"),
  60343. (neg|troop_slot_ge, "trp_player", slot_troop_prisoner_of_party, 0),
  60344. (val_add, ":num_lords", 1),
  60345. (try_end),
  60346. (gt, ":num_lords", 0),#<-- can fail
  60347. (store_div, ":gold_to_each", ":lord_gold", ":num_lords"),
  60348. (ge, ":gold_to_each", 300),
  60349. (val_div, ":gold_to_each", 150),#regularize (standard reinforcement costs for easy/medium/hard are 600/450/300, which are multiples of 150)
  60350. (val_mul, ":gold_to_each", 150),
  60351.  
  60352. #(try_begin),
  60353. # (ge, "$cheat_mode", 1),
  60354. # (assign, reg0, ":num_lords"),
  60355. # (assign, reg1, ":gold_to_each"),
  60356. # (str_store_faction_name, s5, ":faction_no"),
  60357. # (display_message, "@ {reg0} vassals of the {s5} receive {reg1} denars each (dplmc_faction_leader_splits_gold)"),
  60358. #(try_end),
  60359.  
  60360. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  60361. (ge, ":lord_gold", ":gold_to_each"),
  60362. #verify lord is vassal of kingdom
  60363. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  60364. (eq, ":faction_no", ":lord_faction_no"),
  60365. (neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":lord_no"),
  60366. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  60367. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  60368. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  60369. (ge, ":lord_party", 0),
  60370. #give gold to lord
  60371. (val_sub, ":lord_gold", ":gold_to_each"),
  60372. #(troop_get_slot, reg0, ":lord_no", slot_troop_temp_slot),
  60373. #(val_add, reg0, ":gold_to_each"),
  60374. #(troop_set_slot, ":lord_no", slot_troop_temp_slot, reg0),
  60375. ##(call_script, "script_troop_add_gold", ":lord_no", ":gold_to_each"),
  60376. (call_script, "script_dplmc_distribute_gold_to_lord_and_holdings", ":gold_to_each", ":lord_no"),
  60377. (try_end),
  60378. (try_begin),
  60379. (ge, ":lord_gold", ":gold_to_each"),
  60380. #give gold to player if player is vassal of kingdom
  60381. (eq, "$players_kingdom", ":faction_no"),
  60382. (neq, "trp_player", ":faction_liege"),
  60383. (neg|troop_slot_ge, "trp_player", slot_troop_prisoner_of_party, 0),
  60384. (val_sub, ":lord_gold", ":gold_to_each"),
  60385. (troop_get_slot, reg0, "trp_player", slot_troop_temp_slot),
  60386. (val_add, reg0, ":gold_to_each"),
  60387. (troop_set_slot, "trp_player", slot_troop_temp_slot, reg0),
  60388. ##(call_script, "script_troop_add_gold", ":lord_no", ":gold_to_each"),
  60389. (try_end),
  60390. (try_end),
  60391. #Now, distribute the remaining gold. Assign gold in increments of 300,
  60392. #because that's the minimum amount of gold a lord will go to a fief for
  60393. #(also the AI recruitment cost on hard).
  60394. (store_div, ":count", ":lord_gold", 300),
  60395. (val_max, ":count", 1),
  60396. (try_for_range, ":unused", 0, ":count"),
  60397. (ge, ":lord_gold", 300),
  60398. (call_script, "script_cf_get_random_lord_except_king_with_faction", ":faction_no"),
  60399. (is_between, reg0, heroes_begin, heroes_end),
  60400. (assign, ":troop_no", reg0),
  60401. (val_sub, ":lord_gold", 300),
  60402. (troop_get_slot, reg0, ":troop_no", slot_troop_temp_slot),
  60403. (val_add, reg0, 300),
  60404. (troop_set_slot, ":troop_no", slot_troop_temp_slot, reg0),
  60405. #(call_script, "script_troop_add_gold", ":troop_no", 300),
  60406. (try_end),
  60407.  
  60408. #Now the distribution is set. Give each one his allotment.
  60409. (try_for_range, ":lord_no", heroes_begin, heroes_end),
  60410. (ge, ":lord_gold", ":gold_to_each"),
  60411. #verify lord is vassal of kingdom
  60412. (store_troop_faction, ":lord_faction_no", ":lord_no"),
  60413. (eq, ":faction_no", ":lord_faction_no"),
  60414. (neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":lord_no"),
  60415. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  60416. (neg|troop_slot_ge, ":lord_no", slot_troop_prisoner_of_party, 0),
  60417. (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  60418. (ge, ":lord_party", 0),
  60419. #get promised gold
  60420. (troop_get_slot, reg0, ":lord_no", slot_troop_temp_slot),
  60421. (neq, reg0, 0),
  60422. #(try_begin),
  60423. # (ge, "$cheat_mode", 1),
  60424. # (str_store_troop_name, s4, ":lord_no"),
  60425. # (str_store_faction_name, s5, ":faction_no"),
  60426. # (str_store_troop_name, s6, ":faction_liege"),
  60427. # (display_message, "@{!}{s4} of the {s5} receives {reg0} denars (dplmc_faction_leader_splits_gold)"),
  60428. #(try_end),
  60429. (call_script, "script_dplmc_distribute_gold_to_lord_and_holdings", reg0, ":lord_no"),
  60430. (troop_set_slot, ":lord_no", slot_troop_temp_slot, 0),
  60431. (try_end),
  60432.  
  60433. (val_add, ":king_gold", ":lord_gold"),#Give remaining gold to king
  60434. (try_begin),
  60435. (ge, "$cheat_mode", 1),
  60436. (str_store_troop_name, s4, ":troop_no"),
  60437. (str_store_faction_name, s5, ":faction_no"),
  60438. (str_store_troop_name, s6, ":faction_liege"),
  60439. (display_message, "@{!}{s6} of the {s5} retains the remaining {reg0} denars (dplmc_faction_leader_splits_gold)"),
  60440. (try_end),
  60441.  
  60442. #(call_script, "script_troop_add_gold", ":faction_liege", ":king_gold"),
  60443. (call_script, "script_dplmc_distribute_gold_to_lord_and_holdings", ":king_gold", ":faction_liege"),
  60444. (assign, reg0, ":push_reg0"),#revert register value
  60445. (assign, reg1, ":push_reg1"),#revert register value
  60446. ]),
  60447.  
  60448.  
  60449. #script_dplmc_lord_return_from_exile
  60450. # INPUT: arg1 = troop_id, arg2 = new faction_no
  60451. # OUTPUT: none
  60452. ("dplmc_lord_return_from_exile",
  60453. [
  60454. (store_script_param_1, ":troop_no"),
  60455. (store_script_param_2, ":faction_no"),
  60456. #Check validity
  60457. (try_begin),
  60458. (is_between, ":troop_no", heroes_begin, heroes_end),
  60459. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  60460. (neq, ":troop_no", "trp_player"),
  60461. (faction_get_slot, ":faction_liege", ":faction_no", slot_faction_leader),
  60462. #The lord definitely should not already belong to a kingdom
  60463. (store_troop_faction, ":old_faction", ":troop_no"),
  60464. (neg|is_between, ":old_faction", kingdoms_begin, kingdoms_end),
  60465. (try_begin),
  60466. #Handle separately for adding to the player's faction
  60467. #The player may decide to accept or reject the return
  60468. (this_or_next|eq, ":faction_liege", "trp_player"),
  60469. (eq, ":faction_no", "fac_player_supporters_faction"),
  60470. #(eq, 1, 0),#<-- temporarily disable
  60471. #Lord comes to petition the player instead of automatically returning
  60472. (call_script, "script_change_troop_faction", ":troop_no", ":faction_no"),
  60473. (troop_set_slot, ":troop_no", slot_troop_occupation, slto_inactive),
  60474. #Show event (no log without actual faction change)
  60475. (str_store_troop_name_link, s4, ":troop_no"),
  60476. (str_store_faction_name_link, s5, ":faction_no"),
  60477. (faction_get_color, ":color", ":faction_no"), #SB : store colour for logs
  60478. (str_store_troop_name_link, s6, ":faction_liege"),
  60479. (display_message, "@{s4} has returned from exile, seeking refuge with {s6} of {s5}.", ":color"),
  60480. #Remove party
  60481. (troop_get_slot, ":led_party", ":troop_no", slot_troop_leaded_party),
  60482. (try_begin),
  60483. (party_is_active, ":led_party"),
  60484. (neq, ":led_party", "p_main_party"),
  60485. (remove_party, ":led_party"),
  60486. (troop_set_slot, ":troop_no", slot_troop_leaded_party, -1),
  60487. (try_end),
  60488. #
  60489. (else_try),
  60490. #NPC king auto-accepts
  60491. #Normalize relation between NPC and king
  60492. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_liege"),
  60493. (store_sub, ":relation_change", 0, reg0),#enough to increase to 0 if negative
  60494. (val_max, ":relation_change", 5),
  60495. (call_script, "script_troop_change_relation_with_troop", ":troop_no", ":faction_liege", ":relation_change"),
  60496. #Perform reverse of relation change for exile
  60497. (try_for_range, ":active_npc", active_npcs_begin, active_npcs_end), #all lords in own faction, and relatives regardless of faction
  60498. (assign, ":relation_change", 0),#no change for non-relatives in other factions
  60499. (try_begin),
  60500. (store_faction_of_troop, ":active_npc_faction", ":active_npc"),
  60501. (eq, ":faction_no", ":active_npc_faction"),
  60502. #Auto-exiling someone at -75 relation to his liege gives a -1 base
  60503. #relation penalty from other lords, so the gain is 1 by default.
  60504. (assign, ":relation_change", 1),
  60505. (try_end),
  60506. ##(call_script, "script_troop_get_family_relation_to_troop", ":troop_no", ":active_npc"),
  60507. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":troop_no", ":active_npc"),
  60508. (assign, ":family_relation", reg0),
  60509. (try_begin),
  60510. (gt, ":family_relation", 1),
  60511. (store_div, ":family_modifier", reg0, 3),
  60512. (val_add, ":relation_change", ":family_modifier"),
  60513. (try_end),
  60514.  
  60515. (neq, ":relation_change", 0),
  60516.  
  60517. (call_script, "script_troop_change_relation_with_troop", ":faction_liege", ":active_npc", ":relation_change"),
  60518. (try_begin),
  60519. (eq, "$cheat_mode", 1),
  60520. (str_store_troop_name, s17, ":active_npc"),
  60521. (str_store_troop_name, s18, ":faction_liege"),
  60522. (assign, reg3, ":relation_change"),
  60523. (display_message, "str_trial_influences_s17s_relation_with_s18_by_reg3"),
  60524. (try_end),
  60525. (try_end),#end try for range :active_npc
  60526.  
  60527. #Now actually change the faction
  60528. (call_script, "script_change_troop_faction", ":troop_no", ":faction_no"),
  60529. (try_begin), #new-begin
  60530. (neq, ":faction_no", "fac_player_supporters_faction"),
  60531. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive),
  60532. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_retirement),
  60533. (troop_slot_eq, ":troop_no", slot_troop_occupation, dplmc_slto_exile), #SB : revoke exile
  60534. (troop_set_slot, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  60535. (try_end), #new-end
  60536.  
  60537. #Log event
  60538. (str_store_troop_name_link, s4, ":troop_no"),
  60539. (str_store_faction_name_link, s5, ":faction_no"),
  60540. (str_store_troop_name_link, s6, ":faction_liege"),
  60541. (faction_get_color, ":color", ":faction_no"), #SB : store colour for logs
  60542. (display_log_message, "@{s4} has been granted a pardon by {s6} of {s5} and has returned from exile.", ":color"),
  60543.  
  60544. #SB : spawn full army
  60545. (troop_set_slot, ":troop_no", slot_troop_spawned_before, 0),
  60546. (troop_get_slot, ":led_party", ":troop_no", slot_troop_leaded_party),
  60547. (try_begin),
  60548. (party_is_active, ":led_party"),
  60549. (neq, ":led_party", "p_main_party"),
  60550. (remove_party, ":led_party"),
  60551. (troop_set_slot, ":troop_no", slot_troop_leaded_party, -1),
  60552. (try_end),
  60553. (try_end),#end NPC king auto-accepts
  60554. (else_try),
  60555. #Failure. Perform string register assignment first to avoid differences
  60556. #between debug and non-debug behavior.
  60557. (str_store_troop_name, s5, ":troop_no"),
  60558. (str_store_faction_name, s7, ":faction_no"),
  60559. #(ge, "$cheat_mode", 1),#<-- always show this
  60560. (display_message, "@{!}DEBUG : failure in dplmc_lord_return_from_exile((s5}, {s7})"),
  60561. (try_end),
  60562. ]),
  60563.  
  60564. #script_dplmc_get_troop_morality_value
  60565. # INPUT: arg1 = troop_id, arg2 = morality type
  60566. # OUTPUT: reg0 has morality value, or 0 if inapplicable
  60567. ("dplmc_get_troop_morality_value",
  60568. [
  60569. (store_script_param, ":troop_id", 1),
  60570. (store_script_param, ":morality_type", 2),
  60571.  
  60572. (assign, reg0, 0),
  60573. (try_begin),
  60574. (neg|is_between, ":troop_id", companions_begin, companions_end),#<-- result is 0 for non-companions
  60575. (else_try),
  60576. (troop_slot_eq, ":troop_id", slot_troop_morality_type, ":morality_type"),
  60577. (troop_get_slot, reg0, ":troop_id", slot_troop_morality_value),
  60578. (else_try),
  60579. (troop_slot_eq, ":troop_id", slot_troop_2ary_morality_type, ":morality_type"),
  60580. (troop_get_slot, reg0, ":troop_id", slot_troop_2ary_morality_value),
  60581. (try_end),
  60582.  
  60583. ]),
  60584.  
  60585. #script_dplmc_print_subordinate_says_sir_madame_to_s0
  60586. #
  60587. #In a number of circumstances a subordinate (a soldier in the player's employ) will refer
  60588. #to him as "sir" or "madame". This is intended as a sign of respect, but becomes
  60589. #unintentionally disrespectful if the player would ordinarily merit a higher title.
  60590. #
  60591. #This function does not take into account the personal characteristics of the speaker in
  60592. #any way. That logic should occur elsewhere.
  60593. #
  60594. #input: none
  60595. #output: reg0 gets a number corresponding to the title used
  60596. ("dplmc_print_subordinate_says_sir_madame_to_s0",
  60597. [
  60598. (assign, ":highest_honor", 1),#{sir/madame}
  60599. #1: str_dplmc_sirmadame
  60600. #2: str_dplmc_my_lordlady
  60601. #3: str_dplmc_your_highness
  60602. (try_begin),
  60603. #disable extra honors when the player is not recognized
  60604. (gt, "$sneaked_into_town", disguise_none),
  60605. (assign, ":highest_honor", 1),
  60606. (else_try),
  60607. #initialize variables for following steps
  60608. (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
  60609. (troop_get_slot, ":player_spouse", "trp_player", slot_troop_spouse),
  60610. #check if the player is the spouse of one of a widely recognized monarch,
  60611. #or if the player is the ruler of one of the starting kingdoms (this can't happen but check anyway)
  60612. (ge, ":player_spouse", 1),
  60613. (try_for_range, ":faction_no", npc_kingdoms_begin, npc_kingdoms_end),
  60614. (this_or_next|faction_slot_eq, ":faction_no", slot_faction_leader, "trp_player"),
  60615. (faction_slot_eq, ":faction_no", slot_faction_leader, ":player_spouse"),
  60616. (val_max, ":highest_honor", 3),
  60617. (try_end),
  60618. (this_or_next|is_between, ":player_spouse", kings_begin, kings_end),
  60619. (this_or_next|is_between, ":player_spouse", pretenders_begin, pretenders_end),
  60620. (ge, ":highest_honor", 3),
  60621. (val_max, ":highest_honor", 3),
  60622. #Do not continue, since you've already used the highest available honor.
  60623. (else_try),
  60624. #the player is head of his own faction
  60625. (ge, "$players_kingdom", 0),
  60626. #faction leader is player, or faction leader is spouse and spouse is valid
  60627. (this_or_next|faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  60628. (faction_slot_eq, "$players_kingdom", slot_faction_leader, ":player_spouse"),
  60629. (this_or_next|faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
  60630. (ge, ":player_spouse", 1),
  60631.  
  60632. (faction_slot_eq, "$players_kingdom", slot_faction_state, sfs_active),
  60633. (try_begin),
  60634. #If you have sufficient right-to-rule and renown, your subjects
  60635. #will call you "highness".
  60636. (ge, "$player_right_to_rule", 10),
  60637. (store_sub, reg0, 75 + 75, "$player_right_to_rule"),
  60638. (val_mul, reg0, 1200 // 75),#minimum required renown (as an aside, 1200 is evenly divisibly by 75)
  60639. #examples: at right to rule 50, renown must be at least 1600
  60640. # at right to rule 99, renown must be at least 816
  60641. # at right to rule 10, renown must be at least 2240
  60642. (ge, ":player_renown", reg0),
  60643. (val_max, ":highest_honor", 3),
  60644. (else_try),
  60645. #"Highness" is also used if the player's kingdom holds meaningful territory.
  60646. (try_begin),
  60647. #Recalculate the cached value if it's suspicious
  60648. (faction_slot_eq, "$players_kingdom", slot_faction_num_castles, 0),
  60649. (faction_slot_eq, "$players_kingdom", slot_faction_num_towns, 0),
  60650. (call_script, "script_faction_recalculate_strength", "$players_kingdom"),
  60651. (else_try),
  60652. #Recalculate the cached value if it's obviously wrong
  60653. (this_or_next|neg|faction_slot_ge, "$players_kingdom", slot_faction_num_castles, 0),
  60654. (neg|faction_slot_ge, "$players_kingdom", slot_faction_num_towns, 0),
  60655. (call_script, "script_faction_recalculate_strength", "$players_kingdom"),
  60656. (try_end),
  60657. #Territory points: castles = 2, towns = 3 (ignore villages)
  60658. (faction_get_slot, ":territory_points", "$players_kingdom", slot_faction_num_towns),
  60659. (val_mul, ":territory_points", 3),
  60660. (faction_get_slot, reg0, "$players_kingdom", slot_faction_num_castles),
  60661. (val_add, ":territory_points", reg0),
  60662. (val_add, ":territory_points", reg0),
  60663. #If the player owns even a single center, that's worth at least "my lord" from his followers
  60664. (ge, ":territory_points", 1),
  60665. (val_max, ":highest_honor", 2),
  60666. #By default there are around 48 castles and 22 towns on the map, for a total of 70
  60667. #centers, and 162 "points" if weighting castles = 2 and towns = 3.
  60668. (store_sub, ":global_points", towns_end, towns_begin),
  60669. (val_mul, ":global_points", 3),
  60670. (store_sub, reg0, castles_end, castles_begin),
  60671. (val_add, ":global_points", reg0),
  60672. (val_add, ":global_points", reg0),
  60673. #By default there are 6 NPC kingdoms, averaging 8 castles and 3.66... towns or
  60674. #27 points each (although the initial distribution of territory is not even).
  60675. (store_sub, ":number_kingdoms", npc_kingdoms_end, npc_kingdoms_begin),
  60676. (val_max, ":number_kingdoms", 1),
  60677. #Territory must be at least 3/4 the total points divided by number of initial kingdoms.
  60678. #Right to rule applied as a percentage bonus, scaled so that you gain recognition with
  60679. #75% right to rule and a 50% size kingdom.
  60680.  
  60681. #What I want is: ( (RtR * 2/3) + 100 ) * territory * kingdoms >= globe * 3/4
  60682. #This is equivalent to: (RtR * 2 + 300) * territory * kingdoms * 4 >= globe * 9
  60683. #The re-ordering is because of rounding.
  60684. (store_mul, ":target_points", ":global_points", 9),
  60685. (store_mul, reg0, "$player_right_to_rule", 2),
  60686. (val_add, reg0, 300),
  60687. (val_mul, reg0, ":territory_points"),
  60688. (val_mul, reg0, ":number_kingdoms"),
  60689. (val_mul, reg0, 4),
  60690. (ge, reg0, ":target_points"),
  60691. (val_max, ":highest_honor", 3),
  60692. (try_end),
  60693. #stop evaluation if you reached highest honor
  60694. (ge, ":highest_honor", 3),
  60695. (else_try),
  60696. #the player is a vassal of one of the initial kingdoms
  60697. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  60698. (val_max, ":highest_honor", 1),
  60699. (eq, "$player_has_homage", 1),#<- can fail
  60700. (val_max, ":highest_honor", 2),
  60701. (try_end),
  60702.  
  60703. (try_begin),
  60704. (ge, ":highest_honor", 3),
  60705. (str_store_string, s0, "str_dplmc_your_highness"),
  60706. (else_try),
  60707. (eq, ":highest_honor", 2),
  60708. (str_store_string, s0, "str_dplmc_my_lordlady"),
  60709. (else_try),
  60710. (str_store_string, s0, "str_dplmc_sirmadam"),
  60711. (try_end),
  60712.  
  60713. ##Special cases
  60714. (try_begin),
  60715. (eq, "$sneaked_into_town", disguise_none),
  60716. (is_between, "$g_talk_troop", companions_begin, companions_end),
  60717. (ge, ":highest_honor", 1),
  60718. (neg|troop_slot_eq, "$g_talk_troop", slot_troop_met, 0),
  60719. (this_or_next|neg|troop_slot_eq, "$g_talk_troop", slot_troop_occupation, slto_inactive),
  60720. (neg|troop_slot_eq, "$g_talk_troop", slot_troop_playerparty_history, 0),
  60721. (neg|troop_slot_eq, "$g_talk_troop", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  60722. (troop_get_slot, ":honorific", "$g_talk_troop", slot_troop_honorific),
  60723. (ge, ":honorific", "str_npc1_honorific"),
  60724. (str_store_string, s0, ":honorific"),
  60725. (else_try),
  60726. (eq, ":highest_honor", 1),
  60727. (is_between, "$g_talk_troop", heroes_begin, heroes_end),
  60728. (str_store_string, s0, "str_dplmc_sirmadame"),
  60729. (try_end),
  60730.  
  60731. (assign, reg0, ":highest_honor"),
  60732. ]),
  60733.  
  60734.  
  60735. #"script_dplmc_print_commoner_at_arg1_says_sir_madame_to_s0"
  60736. #
  60737. #In a number of circumstances a commoner, who might or might not be a subject of
  60738. #the player, will refer to him as "sir" or "madame." This script determines whether
  60739. #a different title would be warranted.
  60740. #
  60741. #input: party_no (usually a village or town)
  60742. #output: reg0 gets a number corresponding to the title used
  60743. ("dplmc_print_commoner_at_arg1_says_sir_madame_to_s0", [
  60744. (store_script_param_1, ":party_no"),
  60745.  
  60746. (assign, ":title_level", 1),
  60747. (str_store_string, s0, "str_dplmc_sirmadam"),
  60748. (store_faction_of_party, ":party_faction"),
  60749.  
  60750. (try_begin),
  60751. (eq, "$sneaked_into_town", disguise_none),#disable extra honors when the player is not recognized
  60752. (ge, ":party_no", 0),
  60753.  
  60754. #This is used in various conditions below, so I am calling it once
  60755. #for simplicity.
  60756. (assign, ":save_g_talk_troop", "$g_talk_troop"),
  60757. (assign, ":save_g_encountered_party", "$g_encountered_party"),
  60758. (try_begin),
  60759. (neq, ":party_no", "$g_encountered_party"),
  60760. (assign, "$g_encountered_party", -1),
  60761. (assign, "$g_talk_troop", -1),
  60762. (try_end),
  60763. (call_script, "script_dplmc_print_subordinate_says_sir_madame_to_s0"),
  60764. (assign, ":title_level", reg0),
  60765. (assign, "$g_encountered_party", ":save_g_encountered_party"),
  60766. (assign, "$g_talk_troop", ":save_g_talk_troop"),
  60767.  
  60768. (try_begin),
  60769. #The player is a full member of the faction: use full honors
  60770. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", ":party_faction"),
  60771. (ge, reg0, DPLMC_FACTION_STANDING_DEPENDENT),
  60772. #(nothing more needs to be done)
  60773. (else_try),
  60774. #the faction has recognized him formally: use full honors
  60775. (this_or_next|eq, ":party_no", "p_main_party"),
  60776. (this_or_next|eq, ":party_faction", "fac_player_supporters_faction"),
  60777. (faction_slot_ge, ":party_faction", slot_faction_recognized_player, 1),
  60778. #(nothing more needs to be done)
  60779. (else_try),
  60780. #The player is the lord of the town: keep result from script_dplmc_print_subordinate_says_sir_madame_to_s0
  60781. (is_between, ":party_no", centers_begin, centers_end),
  60782. (party_slot_eq, ":party_no", slot_town_lord, "trp_player"),
  60783. #(nothing more needs to be done)
  60784. (else_try),
  60785. #Subjects of neutral kingdoms will use titles up to "my lord".
  60786. (store_relation, ":relation", "fac_player_supporters_faction", ":party_faction"),
  60787. (ge, ":relation", 0),
  60788. (try_begin),
  60789. (ge, ":title_level", 3),
  60790. (assign, ":title_level", 2),
  60791. (str_store_string, s0, "str_dplmc_my_lordlady"),
  60792. (try_end),
  60793. (else_try),
  60794. #Subjects of kingdoms at war (that do not recognize the player) and all cases not
  60795. #yet mentioned will reduce the "level" of the title awarded to the player by 1, to
  60796. #a minimum of 1.
  60797. (try_begin),
  60798. (ge, ":title_level", 3),
  60799. (assign, ":title_level", 2),
  60800. (str_store_string, s0, "str_dplmc_my_lordlady"),
  60801. (else_try),
  60802. (eq, ":title_level", 2),
  60803. (assign, ":title_level", 1),
  60804. (str_store_string, s0, "str_dplmc_sirmadam"),
  60805. (try_end),
  60806. (try_end),
  60807. (try_end),
  60808.  
  60809. ##Special cases
  60810. (try_begin),
  60811. (neq, ":party_no", "$g_encountered_party"),
  60812. (else_try),
  60813. (eq, "$sneaked_into_town", disguise_none),
  60814. (ge, ":title_level", 1),
  60815. (is_between, "$g_talk_troop", companions_begin, companions_end),
  60816. (neg|troop_slot_eq, "$g_talk_troop", slot_troop_met, 0),
  60817. (this_or_next|neg|troop_slot_eq, "$g_talk_troop", slot_troop_occupation, slto_inactive),
  60818. (neg|troop_slot_eq, "$g_talk_troop", slot_troop_playerparty_history, 0),
  60819. (neg|troop_slot_eq, "$g_talk_troop", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  60820. (troop_get_slot, ":honorific", "$g_talk_troop", slot_troop_honorific),
  60821. (ge, ":honorific", "str_npc1_honorific"),
  60822. (str_store_string, s0, ":honorific"),
  60823. (else_try),
  60824. (eq, ":title_level", 1),
  60825. (is_between, "$g_talk_troop", heroes_begin, heroes_end),
  60826. (assign, ":title_level", "str_dplmc_sirmadame"),
  60827. (try_end),
  60828.  
  60829. (assign, reg0, ":title_level"),
  60830.  
  60831. ##Switch to cultural equivalents
  60832. #(try_begin),
  60833. # (eq, ":party_no", "$g_encountered_party"),
  60834. # (is_between, "$g_talk_troop", heroes_begin, heroes_end),
  60835. # (troop_get_slot, ":culture_faction", "$g_talk_troop", slot_troop_original_faction),
  60836. # (is_between, ":culture_faction", npc_kingdoms_begin, npc_kingdoms_end),
  60837. #(else_try),
  60838. # (eq, ":party_no", "$g_encountered_party"),
  60839. # (ge, "$g_talk_troop", soldiers_begin),
  60840. # (store_faction_of_troop, ":culture_faction", "$g_talk_troop"),
  60841. # (is_between, ":culture_faction", npc_kingdoms_begin, npc_kingdoms_end),
  60842. #(else_try),
  60843. # (is_between, ":party_no", centers_begin, centers_end),
  60844. # (party_get_slot, ":culture_faction", ":party_no", slot_center_original_faction),
  60845. # (is_between, ":culture_faction", npc_kingdoms_begin, npc_kingdoms_end),
  60846. #(else_try),
  60847. # (assign, ":culture_faction", ":party_faction"),
  60848. #(try_end),
  60849. #(try_begin),
  60850. # (is_between, "$g_talk_troop", companions_begin, companions_end),#do not switch
  60851. #(else_try),
  60852. # (eq, ":title_level", 1),
  60853. # (eq, ":culture_faction", "fac_kingdom_6"),
  60854. # (str_store_string, s0, "@{!}{sahib/sahiba}"),
  60855. #(try_end),
  60856. ]),
  60857.  
  60858. ##script_cf_dplmc_troop_is_female
  60859. #
  60860. #This exists to make it easy to modify this to work with mods that redefine the troop types.
  60861. #See script_dplmc_store_troop_is_female
  60862. #
  60863. #INPUT: arg1: troop_no
  60864. #OUTPUT: none
  60865. ("cf_dplmc_troop_is_female",
  60866. [
  60867. (store_script_param_1, ":troop_no"),
  60868. (assign, ":is_female", 0),
  60869. (ge, ":troop_no", 0),#Undefined behavior when the arguments are invalid.
  60870. (try_begin),
  60871. (eq, ":troop_no", active_npcs_including_player_begin),
  60872. (assign, ":troop_no", "trp_player"),
  60873. (try_end),
  60874. (troop_get_type, ":is_female", ":troop_no"),
  60875. #The following will make it so, for example, tf_undead does not appear to be female.
  60876. #Mods where this is relevant will likely want to tweak it, but this will work in at
  60877. #least one that I know of that has non-human lords.
  60878. (eq, ":is_female", tf_female),
  60879. ]),
  60880.  
  60881. ##script_dplmc_store_troop_is_female
  60882. #
  60883. #This exists to make it easy to modify this to work with mods that redefine the troop types.
  60884. #
  60885. #If you change this, remember to also change script_cf_dplmc_troop_is_female and
  60886. #script_dplmc_store_is_female_troop_1_troop_2
  60887. #
  60888. #INPUT: arg1: troop_no
  60889. #
  60890. #OUTPUT:
  60891. # reg0: 1 is yes, 0 is no
  60892. ("dplmc_store_troop_is_female",
  60893. [
  60894. (store_script_param_1, ":troop_no"),
  60895. (try_begin),
  60896. (eq, ":troop_no", active_npcs_including_player_begin),
  60897. (assign, ":troop_no", "trp_player"),
  60898. (try_end),
  60899. (troop_get_type, reg0, ":troop_no"),
  60900. (try_begin),
  60901. (neq, reg0, 0),
  60902. (neq, reg0, 1),
  60903. (assign, reg0, 0),#e.g. this would apply to tf_undead
  60904. (try_end),
  60905. ]),
  60906.  
  60907. ("dplmc_store_troop_is_female_reg",
  60908. [
  60909. (store_script_param_1, ":troop_no"),
  60910. (store_script_param_2, ":reg_no"),
  60911. (troop_get_type, ":is_female", ":troop_no"),
  60912. #The following will make it so, for example, tf_undead does not appear to be female.
  60913. #Mods where this is relevant will likely want to tweak it, but this will work in at
  60914. #least one that I know of that has non-human lords.
  60915. (try_begin),
  60916. (neq, ":is_female", 0),
  60917. (neq, ":is_female", 1),
  60918. (assign, ":is_female", 0),
  60919. (try_end),
  60920. ##Can asign to registers 0,1,2,3, 65, or 4
  60921. (try_begin),
  60922. (eq, ":reg_no", 4),
  60923. (assign, reg4, ":is_female"),
  60924. (else_try),
  60925. (eq, ":reg_no", 3),
  60926. (assign, reg3, ":is_female"),
  60927. (else_try),
  60928. (eq, ":reg_no", 2),
  60929. (assign, reg2, ":is_female"),
  60930. (else_try),
  60931. (eq, ":reg_no", 1),
  60932. (assign, reg1, ":is_female"),
  60933. (else_try),
  60934. (eq, ":reg_no", 0),
  60935. (assign, reg0, ":is_female"),
  60936. (else_try),
  60937. (eq, ":reg_no", 65),
  60938. (assign, reg65, ":is_female"),
  60939. (else_try),
  60940. ##default to reg4
  60941. (assign, reg4, ":reg_no"),
  60942. (display_message, "@{!} ERROR: called script dplmc-store-troop-is-female-reg with bad argument {reg4}"),
  60943. (assign, reg4, ":is_female"),
  60944. (try_end),
  60945. ]),
  60946.  
  60947. ##script_dplmc_store_is_female_troop_1_troop_2
  60948. #
  60949. #This exists to make it easy to modify this to work with mods that redefine the troop types.
  60950. #See script_dplmc_store_troop_is_female
  60951. #
  60952. #INPUT:
  60953. # arg1: troop_1
  60954. # arg2: troop_2
  60955. #OUTPUT:
  60956. # reg0: 0 for not female, 1 for female
  60957. # reg1: 0 for not female, 1 for female
  60958. ("dplmc_store_is_female_troop_1_troop_2",
  60959. [
  60960. (store_script_param_1, ":troop_1"),
  60961. (store_script_param_2, ":troop_2"),
  60962. (troop_get_type, ":is_female_1", ":troop_1"),
  60963. (troop_get_type, ":is_female_2", ":troop_2"),
  60964. #The following will make it so, for example, tf_undead does not appear to be female.
  60965. #Mods where this is relevant will likely want to tweak it, but this will work in at
  60966. #least one that I know of that has non-human lords.
  60967. (try_begin),
  60968. (neq, ":is_female_1", 0),
  60969. (neq, ":is_female_1", 1),
  60970. (assign, ":is_female_1", 0),
  60971. (try_end),
  60972. (try_begin),
  60973. (neq, ":is_female_2", 0),
  60974. (neq, ":is_female_2", 1),
  60975. (assign, ":is_female_2", 0),
  60976. (try_end),
  60977. (assign, reg0, ":is_female_1"),
  60978. (assign, reg1, ":is_female_2"),
  60979. ]),
  60980.  
  60981. #script_cf_dplmc_evaluate_pretender_proposal
  60982. # INPUT: arg1 = troop_id for pretender
  60983. # OUTPUT: reg0 = answer
  60984. #
  60985. # Writes reason to s14
  60986. # May clobber s0, s1
  60987. #
  60988. ("cf_dplmc_evaluate_pretender_proposal",
  60989. [
  60990. (store_script_param_1, ":pretender"),
  60991. (assign, ":answer", -1),
  60992. (assign, ":save_reg1", reg1),
  60993. (assign, ":save_reg65", reg65),
  60994. (call_script, "script_dplmc_store_troop_is_female", ":pretender"),
  60995. (assign, reg65, reg0),
  60996.  
  60997. (str_store_string, s14, "str_ERROR_string"),
  60998.  
  60999. (is_between, ":pretender", pretenders_begin, pretenders_end),
  61000. (troop_slot_eq, ":pretender", slot_troop_occupation, slto_kingdom_hero),
  61001.  
  61002. (store_troop_faction, ":pretender_faction", ":pretender"),
  61003. (is_between, ":pretender_faction", npc_kingdoms_begin, npc_kingdoms_end),
  61004. (troop_slot_eq, ":pretender", slot_troop_original_faction, ":pretender_faction"),
  61005. (faction_slot_eq, ":pretender_faction", slot_faction_leader, ":pretender"),
  61006. (faction_slot_eq, ":pretender_faction", slot_faction_state, sfs_active),
  61007.  
  61008. (troop_slot_eq, ":pretender", slot_troop_spouse, -1),
  61009. (troop_slot_eq, ":pretender", slot_troop_betrothed, -1),
  61010.  
  61011. (troop_get_slot, ":pretender_renown", ":pretender", slot_troop_renown),
  61012. (val_max, ":pretender_renown", 1),
  61013.  
  61014. #There, we've covered the preliminaries: this should be a standard post-rebellion
  61015. #setup. Now verify that the player is in a correct state.
  61016.  
  61017. (eq, "$players_kingdom", ":pretender_faction"),
  61018. (eq, "$player_has_homage", 1),
  61019. (troop_slot_eq, "trp_player", slot_troop_spouse, -1),
  61020. (troop_slot_eq, "trp_player", slot_troop_betrothed, -1),
  61021.  
  61022. (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
  61023. (call_script, "script_troop_get_player_relation", ":pretender"),
  61024. (assign, ":player_relation", reg0),
  61025.  
  61026. #Find competitors
  61027. (assign, ":b", -1),
  61028. (assign, ":b_relation", -101),
  61029. (assign, ":c", -1),
  61030. (assign, ":c_renown", -1),
  61031.  
  61032. (store_add, ":faction_renown", ":pretender_renown", ":player_renown"),
  61033. (assign, ":faction_lords", 2),#the player and the pretender
  61034.  
  61035. (troop_set_slot, ":pretender", slot_troop_temp_slot, 0),#clear
  61036. (troop_set_slot, "trp_player", slot_troop_temp_slot, 0),#clear
  61037.  
  61038. (try_for_range_backwards, ":competitor", heroes_begin, heroes_end),
  61039. (troop_slot_eq, ":competitor", slot_troop_occupation, slto_kingdom_hero),
  61040. (store_faction_of_troop, ":competitor_faction", ":competitor"),
  61041. (eq, ":competitor_faction", ":pretender_faction"),
  61042. (try_begin),
  61043. (is_between, ":competitor", kings_begin, kings_end), #SB : exclude former monarchs
  61044. (troop_slot_eq, ":competitor", slot_troop_original_faction, ":pretender_faction"),
  61045. (troop_set_slot, ":competitor", slot_troop_temp_slot, -99999),#low value
  61046. (assign, ":competitor_renown", 0), #do not factor in
  61047. (else_try),
  61048. (troop_set_slot, ":competitor", slot_troop_temp_slot, 0),#clear
  61049. (troop_get_slot, ":competitor_renown", ":competitor", slot_troop_renown),
  61050. (try_end),
  61051.  
  61052. (neq, ":competitor", active_npcs_including_player_begin),
  61053. (neq, ":competitor", ":pretender"),
  61054.  
  61055. (call_script, "script_troop_get_relation_with_troop", ":competitor", ":pretender"),
  61056. (assign, ":competitor_relation", reg0),
  61057.  
  61058. (val_add, ":faction_renown", ":competitor_renown"),
  61059. (val_add, ":faction_lords", 1),
  61060.  
  61061. (try_begin),
  61062. (ge, ":competitor_relation", ":b_relation"),
  61063. (neg|troop_slot_eq, ":competitor", slot_troop_spouse, "trp_player"),
  61064. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, ":competitor"),
  61065. (assign, ":b", ":competitor"),
  61066. (assign, ":b_relation", ":competitor_relation"),
  61067. (try_end),
  61068. (try_begin),
  61069. (ge, ":competitor_renown", ":c_renown"),
  61070. (assign, ":c", ":competitor"),
  61071. (assign, ":c_renown", ":competitor_renown"),
  61072. (try_end),
  61073. (try_end),
  61074.  
  61075. (assign, ":pretender_towns", 0),
  61076. (assign, ":pretender_castles", 0),
  61077. (assign, ":pretender_villages", 0),
  61078.  
  61079. (assign, ":player_towns", 0),
  61080. (assign, ":player_castles", 0),
  61081. (assign, ":player_villages", 0),
  61082.  
  61083. (assign, ":faction_towns", 0),
  61084. (assign, ":faction_castles", 0),
  61085. (assign, ":faction_villages", 0),
  61086.  
  61087. (assign, ":original_towns", 0),
  61088. (assign, ":original_castles", 0),
  61089. (assign, ":original_villages", 0),
  61090.  
  61091. #(store_sub, ":global_towns", towns_end, towns_begin),
  61092. #(store_sub, ":global_castles", castles_end, castles_begin),
  61093. #(store_sub, ":global_villages", villages_end, villages_begin),
  61094.  
  61095. (assign, ":highest_score", -1),
  61096. (assign, ":highest_score_lord", -1),
  61097.  
  61098. (try_for_range, ":center_no", towns_begin, towns_end),
  61099. (store_faction_of_party, ":center_faction", ":center_no"),
  61100. (try_begin),
  61101. (party_slot_eq, ":center_no", slot_town_lord, ":pretender"),
  61102. (val_add, ":pretender_towns", 1),
  61103. (val_add, ":faction_towns", 1),
  61104. (else_try),
  61105. (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  61106. (val_add, ":player_towns", 1),
  61107. (val_add, ":faction_towns", 1),
  61108. (else_try),
  61109. (this_or_next|eq, ":center_faction", ":pretender_faction"),
  61110. (eq, ":center_faction", "fac_player_supporters_faction"),
  61111. (val_add, ":faction_towns", 1),
  61112. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  61113. (this_or_next|eq, ":town_lord", "trp_player"),
  61114. (is_between, ":town_lord", heroes_begin, heroes_end),
  61115. (troop_get_slot, ":local_temp", ":town_lord", slot_troop_temp_slot),
  61116. (val_add, ":local_temp", 3),
  61117. (troop_set_slot, ":town_lord", slot_troop_temp_slot, ":local_temp"),
  61118. (ge, ":local_temp", ":highest_score"),
  61119. (assign, ":highest_score", ":local_temp"),
  61120. (assign, ":highest_score_lord", ":town_lord"),
  61121. (try_end),
  61122. (try_begin),
  61123. (party_slot_eq, ":center_no", slot_center_original_faction, ":pretender_faction"),
  61124. (val_add, ":original_towns", 1),
  61125. (try_end),
  61126. (try_end),
  61127.  
  61128. (try_for_range, ":center_no", castles_begin, castles_end),
  61129. (store_faction_of_party, ":center_faction", ":center_no"),
  61130. (try_begin),
  61131. (party_slot_eq, ":center_no", slot_town_lord, ":pretender"),
  61132. (val_add, ":pretender_castles", 1),
  61133. (val_add, ":faction_castles", 1),
  61134. (else_try),
  61135. (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  61136. (val_add, ":player_castles", 1),
  61137. (val_add, ":faction_castles", 1),
  61138. (else_try),
  61139. (this_or_next|eq, ":center_faction", ":pretender_faction"),
  61140. (eq, ":center_faction", "fac_player_supporters_faction"),
  61141. (val_add, ":faction_castles", 1),
  61142. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  61143. (this_or_next|eq, ":town_lord", "trp_player"),
  61144. (is_between, ":town_lord", heroes_begin, heroes_end),
  61145. (troop_get_slot, ":local_temp", ":town_lord", slot_troop_temp_slot),
  61146. (val_add, ":local_temp", 2),
  61147. (troop_set_slot, ":town_lord", slot_troop_temp_slot, ":local_temp"),
  61148. (ge, ":local_temp", ":highest_score"),
  61149. (assign, ":highest_score", ":local_temp"),
  61150. (assign, ":highest_score_lord", ":town_lord"),
  61151. (try_end),
  61152. (try_begin),
  61153. (party_slot_eq, ":center_no", slot_center_original_faction, ":pretender_faction"),
  61154. (val_add, ":original_castles", 1),
  61155. (try_end),
  61156. (try_end),
  61157.  
  61158. (try_for_range, ":center_no", villages_begin, villages_end),
  61159. (store_faction_of_party, ":center_faction", ":center_no"),
  61160. (try_begin),
  61161. (party_slot_eq, ":center_no", slot_town_lord, ":pretender"),
  61162. (val_add, ":pretender_villages", 1),
  61163. (val_add, ":faction_villages", 1),
  61164. (else_try),
  61165. (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  61166. (val_add, ":player_villages", 1),
  61167. (val_add, ":faction_villages", 1),
  61168. (else_try),
  61169. (this_or_next|eq, ":center_faction", ":pretender_faction"),
  61170. (eq, ":center_faction", "fac_player_supporters_faction"),
  61171. (val_add, ":faction_villages", 1),
  61172. (party_get_slot, ":town_lord", ":center_no", slot_town_lord),
  61173. (this_or_next|eq, ":town_lord", "trp_player"),
  61174. (is_between, ":town_lord", heroes_begin, heroes_end),
  61175. (troop_get_slot, ":local_temp", ":town_lord", slot_troop_temp_slot),
  61176. (val_add, ":local_temp", 1),
  61177. (troop_set_slot, ":town_lord", slot_troop_temp_slot, ":local_temp"),
  61178. (ge, ":local_temp", ":highest_score"),
  61179. (assign, ":highest_score", ":local_temp"),
  61180. (assign, ":highest_score_lord", ":town_lord"),
  61181. (try_end),
  61182. (try_begin),
  61183. (party_slot_eq, ":center_no", slot_center_original_faction, ":pretender_faction"),
  61184. (val_add, ":original_villages", 1),
  61185. (try_end),
  61186. (try_end),
  61187.  
  61188. #Update stats
  61189. (faction_set_slot, ":pretender_faction", slot_faction_num_castles, ":faction_castles"),
  61190. (faction_set_slot, ":pretender_faction", slot_faction_num_towns, ":faction_towns"),
  61191.  
  61192. #Point totals used below
  61193. #Faction Score A: (4 * towns) + (2 * castles) + villages
  61194. (store_mul, ":faction_score_a", ":faction_towns", 4),
  61195. (val_add, ":faction_score_a", ":faction_castles"),
  61196. (val_add, ":faction_score_a", ":faction_castles"),
  61197. (val_add, ":faction_score_a", ":faction_villages"),
  61198.  
  61199. #Faction Score B: (3 * towns) + (2 * castles) + villages
  61200. (store_sub, ":faction_score_b", ":faction_score_a", ":faction_towns"),
  61201.  
  61202. #Original Score A: (4 * towns) + (2 * castles) + villages
  61203. (store_mul, ":original_score_a", ":original_towns", 4),
  61204. (val_add, ":original_score_a", ":original_castles"),
  61205. (val_add, ":original_score_a", ":original_castles"),
  61206. (val_add, ":original_score_a", ":original_villages"),
  61207.  
  61208. #Original Score B: (3 * towns) + (2 * castles) + villages
  61209. (store_sub, ":original_score_b", ":faction_score_b", ":faction_towns"),
  61210.  
  61211. #The first fail-condition encountered will be the explanation used,
  61212. #so make sure the most pressing ones go first.
  61213. (try_begin),
  61214. #relation low: using the same cutoff normally used for becoming a vassal
  61215. (lt, ":player_relation", 0),
  61216. (assign, ":answer", -1),
  61217. (str_store_string, s14, "@Given the way things stand between us at the moment, {playername}, I would not consider it prudent to enter into such an arrangement."),
  61218. (else_try),
  61219. #check player right to rule
  61220. (store_add, ":player_score", "$player_right_to_rule", ":player_relation"),
  61221. (this_or_next|lt, "$player_right_to_rule", 20),#the level required for your spouse to join a rebellion
  61222. (lt, ":player_score", 100),
  61223. (assign, ":answer", -1),
  61224. (str_store_string, s14, "@{playername}, I am grateful to you, but in the eyes of the people you do not have sufficient legitimacy as a potential co-ruler. Marrying you would undermine my own claim to the throne."),
  61225. (else_try),
  61226. #check player renown
  61227. (store_mul, ":min_score", ":pretender_renown", 2),
  61228. (val_div, ":min_score", 3),#2/3 pretender renown, 750 by default
  61229. (val_clamp, ":min_score", 500, 1200),#500 is the minimum to begin the claimant quest; 1200 is the initial value for original lords #SB fixed comment
  61230.  
  61231. (lt, ":player_renown", ":min_score"),
  61232. (assign, ":answer", -1),
  61233. (try_begin),
  61234. (ge, "$cheat_mode", 1),
  61235. (assign, reg0, ":player_renown"),
  61236. (assign, reg1, ":min_score"),
  61237. (display_message, "@{!}DEBUG - player renown {reg0}, required renown {reg1}"),
  61238. (try_end),
  61239. (str_store_string, s14, "@{playername}, I know that if it were not for you I would not sit on this throne, but your name is little renowned in Calradia. Marrying you would be perceived as an uneven match and would call into question my own claim to the throne."),
  61240. (else_try),
  61241. #check player has sufficient fiefs
  61242. (store_mul, ":player_score", ":player_towns", 3),
  61243. (val_add, ":player_score", ":player_castles"),
  61244. (val_add, ":player_score", ":player_castles"),
  61245. (val_add, ":player_score", ":player_villages"),# player_score = (3 * towns) + (2 * castles) + villages
  61246.  
  61247. (assign, ":min_score", 6),#A town, a castle, and a village; two towns; three castles; six villages; etc...
  61248.  
  61249. (try_begin),
  61250. #Ensure the minimum is not unreasonable on small maps.
  61251. (lt, ":original_score_b", 18),
  61252. (lt, ":faction_score_b", 18),
  61253. (assign, reg0, ":original_score_b"),
  61254. (val_max, reg0, ":faction_score_b"),
  61255. (store_div, ":min_score", reg0, 3),
  61256. (try_end),
  61257.  
  61258. (troop_get_slot, ":two_thirds_pretender_score", ":pretender", slot_troop_temp_slot),
  61259. (val_mul, ":two_thirds_pretender_score", 2),
  61260. (val_add, ":two_thirds_pretender_score", 1),
  61261. (val_div, ":two_thirds_pretender_score", 3),
  61262. (val_max, ":min_score", ":two_thirds_pretender_score"),
  61263.  
  61264. (lt, ":player_score", ":min_score"),
  61265. (assign, ":answer", -1),
  61266. (try_begin),
  61267. (ge, "$cheat_mode", 1),
  61268. (assign, reg0, ":player_score"),
  61269. (assign, reg1, ":min_score"),
  61270. (display_message, "@{!}DEBUG - player score {reg0} out of a required {reg1}"),
  61271. (try_end),
  61272. (str_store_string, s14, "@{playername}, I am grateful for your assistance in regaining my rightful throne, but you do not have sufficient personal holdings to be a suitable match for me. It would be an uneven partnership."),
  61273. (else_try),
  61274. #does the player have as much renown as competitors?
  61275. (lt, ":player_renown", ":c_renown"),
  61276. (assign, ":answer", -1),
  61277. (str_store_troop_name, s14, ":c"),
  61278. (try_begin),
  61279. (ge, "$cheat_mode", 1),
  61280. (assign, reg0, ":player_renown"),
  61281. (assign, reg1, ":c_renown"),
  61282. (display_message, "@{!}DEBUG - player score {reg0}, competitor score {reg1}"),
  61283. (try_end),
  61284. (str_store_string_reg, s0, s15),#clobber s0, save s15
  61285. (call_script, "script_troop_describes_troop_to_s15", ":pretender", ":c"),
  61286. (str_store_string, s14, "@{playername}, I am grateful to you, but if I were to accept at this time I would risk offending powerful lords such as {s15}, who may consider themselves to have honor equal to or greater than your own."),
  61287. (str_store_string_reg, s15, s0),#revert s15
  61288. (else_try),
  61289. #is the player outfieffed by a competitor?
  61290. (gt, ":highest_score_lord", "trp_player"),
  61291. (neq, ":highest_score_lord", ":pretender"),
  61292.  
  61293. (store_mul, ":player_score", ":player_towns", 3),
  61294. (val_add, ":player_score", ":player_castles"),
  61295. (val_add, ":player_score", ":player_castles"),
  61296. (val_add, ":player_score", ":player_villages"),# player_score = (3 * towns) + (2 * castles) + villages
  61297. (lt, ":player_score", ":highest_score"),
  61298.  
  61299. (store_mul, reg0, ":highest_score", 3),#allow small differences
  61300. (val_add, reg0, 2),
  61301. (val_div, reg0, 4),
  61302. (gt, reg0, ":player_score"),
  61303.  
  61304. (assign, ":answer", -1),
  61305. (str_store_troop_name, s14, ":highest_score_lord"),
  61306. (try_begin),
  61307. (ge, "$cheat_mode", 1),
  61308. (assign, reg0, ":player_score"),
  61309. (assign, reg1, ":highest_score"),
  61310. (display_message, "@{!}DEBUG - player score {reg0}, competitor score {reg1}"),
  61311. (try_end),
  61312. (str_store_string_reg, s0, s15),#clobber s0, save s15
  61313. (call_script, "script_troop_describes_troop_to_s15", ":pretender", ":highest_score_lord"),
  61314. (str_store_string, s14, "@{playername}, I am grateful to you, but if I were to accept at this time I would risk offending great lords such as {s15}, who may consider themselves to have honor equal to or greater than your own."),
  61315. (str_store_string_reg, s15, s0),#revert s15
  61316. (else_try),
  61317. #does the player have as much relation as competitors?
  61318. (lt, ":player_relation", ":b_relation"),
  61319. (ge, ":b_relation", 5),
  61320. (assign, ":answer", -1),
  61321. (try_begin),
  61322. (ge, "$cheat_mode", 1),
  61323. (assign, reg0, ":player_relation"),
  61324. (assign, reg1, ":b_relation"),
  61325. (display_message, "@{!}DEBUG - player relation {reg0}, rival relation {reg1}"),
  61326. (try_end),
  61327. (str_store_string_reg, s0, s15),#clobber s0, save s15
  61328. (call_script, "script_troop_describes_troop_to_s15", ":pretender", ":b"),
  61329. (str_store_string, s14, "@{playername}, while I am grateful to you, I must confess I am fond of {s15}."),
  61330. (str_store_string_reg, s15, s0),#revert s15
  61331. (else_try),
  61332. #check: sufficient lords?
  61333. (assign, ":needed_lords", 1),
  61334. (try_for_range, ":troop_no", lords_begin, lords_end),
  61335. (troop_slot_eq, ":troop_no", slot_troop_original_faction, ":pretender_faction"),
  61336. (val_add, ":needed_lords", 1),
  61337. (try_end),
  61338. #Must be at least 75% of original size
  61339. (val_mul, ":needed_lords", 3),
  61340. (val_div, ":needed_lords", 4),
  61341.  
  61342. (lt, ":faction_lords", ":needed_lords"),
  61343. (assign, ":answer", -1),
  61344. (try_begin),
  61345. (ge, "$cheat_mode", 1),
  61346. (assign, reg0, ":faction_lords"),
  61347. (assign, reg1, ":needed_lords"),
  61348. (display_message, "@{!}DEBUG - lords in faction {reg0}, required lords {reg1}"),
  61349. (try_end),
  61350.  
  61351. (str_store_string, s14, "@Our realm has too few vassals. In the current precarious state of the affairs I must use the lure of a potential political alliance to attract new vassals, and cannot yet be seen to commit to any single {reg65?suitor:candidate}."),
  61352. (else_try),
  61353. #check: pretender has enough fiefs?
  61354. #Must not be exceeded in fiefs by anyone in the faction.
  61355. (store_mul, ":pretender_score", ":pretender_towns", 3),
  61356. (val_add, ":pretender_score", ":pretender_castles"),
  61357. (val_add, ":pretender_score", ":pretender_castles"),
  61358. (val_add, ":pretender_score", ":pretender_villages"),
  61359. (troop_set_slot, ":pretender", slot_troop_temp_slot, ":pretender_score"),
  61360.  
  61361. (store_mul, reg0, ":highest_score", 3),#allow small differences
  61362. (val_add, reg0, 2),
  61363. (val_div, reg0, 4),
  61364.  
  61365. (gt, reg0, ":pretender_score"),
  61366.  
  61367. (assign, ":answer", -1),
  61368. (try_begin),
  61369. (ge, "$cheat_mode", 1),
  61370. (assign, reg1, reg0),
  61371. (assign, reg0, ":pretender_score"),
  61372. (display_message, "@{!}DEBUG - liege has {reg0} center points, needs at least {reg1}"),
  61373. (try_end),
  61374. (str_store_string_reg, s0, s15),#clobber s0, save s15
  61375. (call_script, "script_troop_describes_troop_to_s15", ":pretender", ":highest_score_lord"),
  61376. (str_store_string, s14, "@Because I have insufficient personal holdings compared to {s15}, if I entered into such an arrangement I would risk appearing to be a puppet, throwing the stability of the realm into jeopardy."),
  61377. (str_store_string_reg, s15, s0),#revert s15
  61378. (else_try),
  61379. #Check if pretender has enough fiefs, part 2.
  61380. #Must not have fewer fief points than the number of faction points divided by the
  61381. #number of lords (so this condition can't be bypassed by just failing to assign
  61382. #centers to anyone during the rebellion)
  61383. (store_mul, ":points_per_lord", ":faction_towns", 3),
  61384. (val_add, ":points_per_lord", ":faction_castles"),
  61385. (val_add, ":points_per_lord", ":faction_castles"),
  61386. (val_add, ":points_per_lord", ":faction_villages"),
  61387. (val_div, ":points_per_lord", ":faction_lords"),#includes pretender so cannot be zero
  61388.  
  61389. (gt, ":points_per_lord", ":pretender_score"),
  61390.  
  61391. (assign, ":answer", -1),
  61392. (try_begin),
  61393. (ge, "$cheat_mode", 1),
  61394. (assign, reg0, ":pretender_score"),
  61395. (assign, reg1, ":points_per_lord"),
  61396. (display_message, "@{!}DEBUG - liege has {reg0} center points, needs at least {reg1}"),
  61397. (try_end),
  61398. (str_store_faction_name, s14, ":pretender_faction"),
  61399. (str_store_string, s14, "@Because my personal holdings are insufficiently large compared to other lords of the {s14}, if I entered into such an arrangement I would risk appearing to be a puppet, throwing the stability of the realm into jeopardy."),
  61400. (else_try),
  61401. #check if player is widely hated in faction
  61402. (assign, ":total_negative", 0),
  61403. (assign, ":total_enemies", 0),
  61404. (assign, ":total_positive", 0),
  61405. (assign, ":total_friends", 0),
  61406. (try_for_range, ":troop_no", heroes_begin, heroes_end),
  61407. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  61408. (store_troop_faction, reg0, ":troop_no"),
  61409. (eq, reg0, ":pretender_faction"),
  61410. (call_script, "script_troop_get_player_relation", ":troop_no"),
  61411. (try_begin),
  61412. (lt, reg0, 0),
  61413. (val_add, ":total_negative", 1),
  61414. (lt, reg0, -19),
  61415. (val_add, ":total_enemies", 1),
  61416. (else_try),
  61417. (gt, reg0, 0),
  61418. (val_add, ":total_positive", 1),
  61419. (gt, reg0, 19),
  61420. (val_add, ":total_friends", 1),
  61421. (try_end),
  61422. (try_end),
  61423. #Must not have a "disapproval rating" of over 33%
  61424. (val_mul, ":total_enemies", 2),
  61425. (val_mul, ":total_negative", 2),
  61426. (this_or_next|gt, ":total_enemies", ":total_friends"),
  61427. (gt, ":total_negative", ":total_positive"),
  61428.  
  61429. (assign, ":answer", -1),
  61430. (str_store_faction_name, s14, ":pretender_faction"),
  61431. (str_store_string, s14, "@I am grateful to you, {playername}, but you have too many enemies among the lords of the {s14} for your proposal to be politically viable. If I were to accept, there might be a revolt."),
  61432. (else_try),
  61433. #controversy must be less than 25, and less than half the relation with the liege
  61434. (troop_get_slot, ":controversy_2", "trp_player", slot_troop_controversy),
  61435. (ge, ":controversy_2", 1),
  61436. (val_mul, ":controversy_2", 2),
  61437. (this_or_next|ge, ":controversy_2", 50),
  61438. (ge, ":controversy_2", ":player_relation"),
  61439. (assign, ":answer", -1),
  61440. (str_store_faction_name, s14, ":pretender_faction"),
  61441. (str_store_string, s14, "@You have engendered too much controversy recently, {playername} . If I were to accept at this time, there might be a revolt among the lords of the {s14}. Let us speak of this later when the furor has died down."),
  61442. (else_try),
  61443. #check is marshall
  61444. (neg|faction_slot_eq, ":pretender_faction", slot_faction_marshall, "trp_player"),
  61445. (assign, ":answer", -2),#<-- negative two, not -1
  61446. (str_store_faction_name, s14, ":pretender_faction"),
  61447. (str_store_string, s14, "@If you desire to lead the {s14} alongside me, gather support among my vassals to become marshall, and demonstrate to them your abilities as a war leader."),
  61448. (else_try),
  61449. #player is marshall: is the territory sufficient?
  61450.  
  61451. #The faction must have at least 80% of its former territory under scoring system A or scoring system B.
  61452. (store_mul, ":four_fifths_original_score_a", ":original_score_a", 4),
  61453. (val_div, ":four_fifths_original_score_a", 5),
  61454.  
  61455. (store_mul, ":four_fifths_original_score_b", ":original_score_b", 4),
  61456. (val_div, ":four_fifths_original_score_b", 5),
  61457.  
  61458. (lt, ":faction_score_a", ":four_fifths_original_score_a"),
  61459. (lt, ":faction_score_b", ":four_fifths_original_score_b"),
  61460. (assign, ":answer", -3),
  61461.  
  61462. (call_script, "script_dplmc_print_centers_in_numbers_to_s0", ":original_towns", ":original_castles", ":original_villages"),
  61463. (str_store_string_reg, s1, s0),
  61464. (call_script, "script_dplmc_print_centers_in_numbers_to_s0", ":faction_towns", ":faction_castles", ":faction_villages"),
  61465.  
  61466. (str_store_faction_name, s14, ":pretender_faction"),
  61467. (str_store_string, s14, "@Our realm has lost too much territory. We once held {s1} but now only hold {s0}. In the current precarious state of affairs I must retain the possibility of a political alliance to use as a bargaining chip with the other sovereigns, so I yet be seen to commit to any single {reg65?suitor:candidate}. Restore the {s14} to its former glory, and I will gladly have you rule beside me as my {husband/wife}."),
  61468. (else_try),
  61469. #player is marshall: are any native centers lost?
  61470.  
  61471. (str_clear, s0),
  61472. (str_clear, s1),
  61473. (assign, ":num_lost_towns_and_castles", 0),
  61474.  
  61475. (try_for_range, ":center_no", centers_begin, centers_end),
  61476. (party_slot_eq, ":center_no", slot_center_original_faction, ":pretender_faction"),
  61477. (store_faction_of_party, ":center_faction", ":center_no"),
  61478. (neq, ":center_faction", ":pretender_faction"),
  61479. (neq, ":center_faction", "fac_player_supporters_faction"),
  61480. (try_begin),
  61481. (eq, ":num_lost_towns_and_castles", 0),
  61482. (str_store_party_name, s0, ":center_no"),
  61483. (else_try),
  61484. (eq, ":num_lost_towns_and_castles", 1),
  61485. (str_store_party_name, s1, ":center_no"),
  61486. (else_try),
  61487. (str_store_string, s0, "str_dplmc_s0_comma_s1"),
  61488. (str_store_party_name, s1, ":center_no"),
  61489. (try_end),
  61490. (val_add, ":num_lost_towns_and_castles", 1),
  61491. (try_end),
  61492. #post-loop cleanup
  61493. (try_begin),
  61494. (ge, ":num_lost_towns_and_castles", 2),
  61495. (str_store_string, s0, "str_dplmc_s0_and_s1"),
  61496. (try_end),
  61497. #native towns lost
  61498. (ge, ":num_lost_towns_and_castles", 1),
  61499. (store_sub, reg0, ":num_lost_towns_and_castles", 1),
  61500. (str_store_faction_name, s14, ":pretender_faction"),
  61501. (str_store_string, s14, "@{s0} {reg0?have:has} been lost to foreign hands. Restore the {s14} to its rightful boundaries, and I will gladly have you rule beside me as my {husband/wife}."),
  61502. (assign, ":answer", -3),
  61503. (else_try),
  61504. #Timer answer
  61505. (lt, "$g_player_days_as_marshal", 14),
  61506. (assign, reg0, "$g_player_days_as_marshal"),
  61507. (store_sub, reg1, reg0, 1),
  61508. (str_store_faction_name, s14, ":pretender_faction"),
  61509. (str_store_string, s14, "@You have only been marshall for {reg0} {reg1?days:day}. Let us speak of this after you have held the post for at least two weeks."),
  61510. (assign, ":answer", -4),
  61511. (else_try),
  61512. #In the future we may need a proper quest of some kind, or at least a timer, but this will do for now.
  61513. (assign, ":answer", 1),
  61514. (str_store_faction_name, s14, ":pretender_faction"),
  61515. (str_store_string, s14, "@If not for you I would not sit on this throne, {playername}. When we started our long walk, few people had the courage to support me. And fewer still would be willing to put their lives at risk for my cause. But you didn't hesitate for a moment in throwing yourself at my enemies. We have gone through a lot together, and with God's help, we prevailed. I will gladly accept you as both my {husband/wife} and co-ruler of the {s14}."),
  61516. (try_end),
  61517.  
  61518. (assign, reg65, ":save_reg65"),
  61519. (assign, reg1, ":save_reg1"),
  61520. (assign, reg0, ":answer"),
  61521. ]),
  61522.  
  61523. #script_dplmc_center_point_calc
  61524. # INPUT: arg1 = faction_id
  61525. # arg2 = troop_1
  61526. # arg2 = troop_2
  61527. # arg3 = town_point_value (see explanation below)
  61528. #
  61529. # OUTPUT:
  61530. # reg0 = total renown / total faction points (or 0 if no centers held)
  61531. # reg1 = troop_1 total (not divided)
  61532. # reg2 = troop_2 total (not divided)
  61533. # reg3 = faction average lord renown (or 0 if no lords)
  61534. #
  61535. #In various places the game tallies center points differently. The values of
  61536. #villages/castles/fiefs, respectively, in some places are 1/2/2, in other
  61537. #places are 1/2/3, and in others are 1/3/4.
  61538. #Specifying the town point value determines which scheme will be used to
  61539. #determine ceter points:
  61540. # arg3 = 2 gives 1/2/2
  61541. # arg3 = 3 gives 1/2/3
  61542. # arg3 = 4 gives 1/2/4
  61543. #
  61544. #If the specified town_point_value is not 2,3, or 4, the script is allowed to
  61545. #clamp the value or substitute a default.
  61546. ("dplmc_center_point_calc",
  61547. [
  61548. (store_script_param, ":faction_id", 1),
  61549. (store_script_param, ":troop_1", 2),
  61550. (store_script_param, ":troop_2", 3),
  61551. (store_script_param, ":town_point_value", 4),
  61552.  
  61553. (val_clamp, ":town_point_value", 2, 5),
  61554.  
  61555. #The outputs
  61556. (assign, ":faction_score", 0),
  61557. (assign, ":troop_1_score", 0),
  61558. (assign, ":troop_2_score", 0),
  61559. #(assign, ":average_renown", 0),
  61560.  
  61561. #Intermediate values we use for computing outputs
  61562. (assign, ":total_renown", 0),
  61563. (assign, ":num_lords", 0),
  61564.  
  61565. #Handle the player first
  61566. #(assign, ":player_in_faction", 0),
  61567. (assign, ":faction_alias", ":faction_id"),
  61568. (try_begin),
  61569. (this_or_next|eq, ":faction_id", "$players_kingdom"),
  61570. (eq, ":faction_id", "fac_player_supporters_faction"),
  61571. (val_add, ":num_lords", 1),
  61572. (troop_get_slot, ":total_renown", "trp_player", slot_troop_renown),
  61573. #(assign, ":player_in_faction", 1),
  61574. (assign, ":faction_alias", "fac_player_supporters_faction"),
  61575. (eq, ":faction_id", "fac_player_supporters_faction"),
  61576. (assign, ":faction_alias", "$players_kingdom"),
  61577. (try_end),
  61578.  
  61579. #Get lords in faction
  61580. (try_for_range, ":troop_no", heroes_begin, heroes_end),
  61581. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  61582. (neq, ":troop_no", "trp_kingdom_heroes_including_player_begin"),
  61583. (store_troop_faction, ":faction_no", ":troop_no"),
  61584. (this_or_next|eq, ":faction_no", ":faction_id"),
  61585. (eq, ":faction_no", ":faction_alias"),
  61586.  
  61587. (val_add, ":num_lords", 1),
  61588. (troop_get_slot, ":renown", ":troop_no", slot_troop_renown),
  61589. (val_max, ":renown", 0),
  61590. (val_add, ":total_renown", ":renown"),
  61591. (try_end),
  61592.  
  61593. #Get stats for centers
  61594. (try_for_parties, ":center_no"),
  61595. (assign, ":points", 0),
  61596. (try_begin),
  61597. #Towns are 2, 3, or 4 points
  61598. (this_or_next|is_between, ":center_no", towns_begin, towns_end),
  61599. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  61600. (assign, ":points", ":town_point_value"),
  61601. (else_try),
  61602. #Castles are always 2 points
  61603. (this_or_next|is_between, ":center_no", castles_begin, castles_end),
  61604. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  61605. (assign, ":points", 2),#castles are always 2
  61606. (else_try),
  61607. #Villages are always 1 point
  61608. (this_or_next|is_between, ":center_no", villages_begin, villages_end),
  61609. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  61610. (try_end),
  61611.  
  61612. #Don't process parties that aren't centers.
  61613. (ge, ":points", 1),
  61614.  
  61615. #NB: We don't know for sure that troop_1 and troop_2 aren't the
  61616. #same value, and we don't even necessarily know that they're part
  61617. #of the specified faction.
  61618. (try_begin),
  61619. (party_slot_eq, ":center_no", slot_town_lord, ":troop_1"),
  61620. (val_add, ":troop_1_score", ":points"),
  61621. (try_end),
  61622.  
  61623. (try_begin),
  61624. (party_slot_eq, ":center_no", slot_town_lord, ":troop_2"),
  61625. (val_add, ":troop_2_score", ":points"),
  61626. (try_end),
  61627.  
  61628. (store_faction_of_party, ":faction_no", ":center_no"),
  61629. (this_or_next|eq, ":faction_no", ":faction_id"),
  61630. (eq, ":faction_no", ":faction_alias"),
  61631. (val_add, ":faction_score", ":points"),
  61632. (try_end),
  61633.  
  61634. # OUTPUT:
  61635. # reg0 = faction renown / faction points (or 0 if faction has no centers)
  61636. # reg1 = troop_1 total (not divided)
  61637. # reg2 = troop_2 total (not divided)
  61638. # reg3 = faction average lord renown (or 0 if no lords)
  61639. (assign, reg0, 0),
  61640. (try_begin),
  61641. (neq, ":faction_score", 0),
  61642. (store_div, reg0, ":total_renown", ":faction_score"),
  61643. (try_end),
  61644. (assign, reg1, ":troop_1_score"),
  61645. (assign, reg2, ":troop_2_score"),
  61646. (assign, reg3, 0),
  61647. (try_begin),
  61648. (neq, ":num_lords", 0),
  61649. (store_div, reg0, ":total_renown", ":num_lords"),
  61650. (try_end),
  61651. ]),
  61652.  
  61653.  
  61654. #script_dplmc_good_produced_at_center_or_its_villages
  61655. # For towns, also includes the villages that attach to it
  61656. #
  61657. # INPUT: arg1 = good_no
  61658. # arg2 = center_no
  61659. # OUTPUT:
  61660. # reg0 = 0 if no, 1 if yes
  61661. ("dplmc_good_produced_at_center_or_its_villages",
  61662. [
  61663. (store_script_param, ":good_no", 1),
  61664. (store_script_param, ":center_no", 2),
  61665.  
  61666. (assign, ":has_good", 0),
  61667. (assign, ":save_reg1", reg1),
  61668. (assign, ":save_reg2", reg2),
  61669. (store_current_hours, ":cur_hours"),
  61670. (store_sub, ":recent_time", ":cur_hours", 3 * 24),
  61671.  
  61672.  
  61673. (try_begin),
  61674. (is_between, ":good_no", trade_goods_begin, trade_goods_end),
  61675. (ge, ":center_no", 1),
  61676. (this_or_next|is_between, ":center_no", centers_begin, centers_end),
  61677. (party_is_active, ":center_no"),
  61678. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  61679. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_castle),
  61680. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_village),
  61681. (is_between, ":center_no", centers_begin, centers_end),
  61682. (call_script, "script_center_get_production", ":center_no", ":good_no"),
  61683. (try_begin),
  61684. #Positive production
  61685. (ge, reg0, 1),
  61686. (assign, ":has_good", 1),
  61687. (else_try),
  61688. #Is a town or a castle, and one of its villages has positive prodution
  61689. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  61690. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  61691. (try_for_range, ":cur_village", villages_begin, villages_end),
  61692. (eq, ":has_good", 0),
  61693. #is bound to center
  61694. (this_or_next|party_slot_eq, ":cur_village", slot_village_market_town, ":center_no"),
  61695. (party_slot_eq, ":cur_village", slot_village_bound_center, ":center_no"),#for castles
  61696. (assign, reg0, 0),
  61697. (try_begin),
  61698. #If a trading party from the village reached the town recently, its goods are
  61699. #available.
  61700. (party_slot_ge, ":cur_village", dplmc_slot_village_trade_last_arrived_to_market, ":recent_time"),
  61701. (assign, reg0, 1),
  61702. (else_try),
  61703. #If the village is not looted and this center is not under siege, the
  61704. #goods from the village could be acquired if they were needed.
  61705. (neg|party_slot_eq, ":cur_village", slot_village_state, svs_looted),
  61706. (neg|party_slot_eq, ":cur_village", slot_village_state, svs_deserted),
  61707. (neg|party_slot_eq, ":center_no", slot_village_state, svs_under_siege),
  61708. (assign, reg0, 1),
  61709. (try_end),
  61710. (eq, reg0, 1),
  61711. #If an eligible village has positive production, set "has_good" to true.
  61712. (call_script, "script_center_get_production", ":cur_village", ":good_no"),
  61713. (ge, reg0, 1),
  61714. (assign, ":has_good", 1),
  61715. (try_end),
  61716. (try_end),
  61717. (try_end),
  61718.  
  61719. (assign, reg0, ":has_good"),
  61720. (assign, reg1, ":save_reg1"),
  61721. (assign, reg2, ":save_reg2"),
  61722. ]),
  61723.  
  61724. #script_dplmc_assess_ability_to_purchase_good_from_center
  61725. # INPUT: arg1 = good_no
  61726. # arg2 = center_no
  61727. # OUTPUT:
  61728. # reg0 = actual price (may be theoretical if unavailable)
  61729. # reg1 = 1 if available, 0 if unavailable
  61730. ("dplmc_assess_ability_to_purchase_good_from_center",
  61731. [
  61732. (store_script_param, ":good_no", 1),
  61733. (store_script_param, ":center_no", 2),
  61734.  
  61735. #This is still quite experimental. This is a work in progress
  61736. #rather than a finished formula.
  61737. (assign, ":price_factor", average_price_factor),
  61738. (assign, ":has_good", 0),
  61739.  
  61740. (try_begin),
  61741. (is_between, ":center_no", centers_begin, centers_end),
  61742. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_village),
  61743. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  61744.  
  61745. (is_between, ":good_no", trade_goods_begin, trade_goods_end),
  61746.  
  61747. (store_sub, ":item_slot_no", ":good_no", trade_goods_begin),
  61748. (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
  61749. (party_get_slot, ":price_factor", ":center_no", ":item_slot_no"),
  61750.  
  61751. (call_script, "script_dplmc_good_produced_at_center_or_its_villages", ":good_no", ":center_no"),
  61752. (assign, ":has_good", reg0),
  61753. #abort if good is found
  61754. (lt, ":has_good", 1),
  61755.  
  61756. (store_faction_of_party, ":center_faction", ":center_no"),
  61757. (faction_get_slot, ":mercantilism", ":center_faction", dplmc_slot_faction_mercantilism),
  61758. (val_clamp, ":mercantilism", -3, 4),
  61759.  
  61760. #For towns, check trade centers.
  61761. (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
  61762. (is_between, ":center_no", towns_begin, towns_end),
  61763.  
  61764. (store_current_hours, ":cur_hours"),
  61765. (assign, ":best_foreign_price", maximum_price_factor),
  61766. (assign, ":worst_price_seen", ":price_factor"),
  61767.  
  61768. (try_for_range, ":trade_town_index", slot_town_trade_routes_begin, slot_town_trade_routes_end),
  61769. (party_get_slot, ":trade_town", ":center_no", ":trade_town_index"),
  61770. (is_between, ":trade_town", centers_begin, centers_end),
  61771.  
  61772. (party_get_slot, ":price_factor_2", ":trade_town", ":item_slot_no"),
  61773. (val_max, ":worst_price_seen", ":price_factor_2"),
  61774.  
  61775. (party_slot_eq, ":trade_town", slot_party_type, spt_town),
  61776. (call_script, "script_dplmc_good_produced_at_center_or_its_villages", ":good_no", ":trade_town"),
  61777. #The town has or produces the item
  61778. (ge, reg0, 1),
  61779.  
  61780. #Get the number of hours since the last caravan arrival, and set the penalty accordingly.
  61781. (assign, ":hours_since", 0),
  61782. #The slot storing the arrival time. This may be uninitialized for old saved games used
  61783. #with this mod.
  61784. (store_sub, ":arrival_slot", ":trade_town_index", slot_town_trade_routes_begin),
  61785. (val_add, ":arrival_slot", dplmc_slot_town_trade_route_last_arrivals_begin),
  61786. (try_begin),
  61787. #This condition can only occur if the number of trade route slots was increased
  61788. #but the number of trade arrival time slots was not. Check just in case, to avoid
  61789. #strange errors.
  61790. (neg|is_between, ":arrival_slot", dplmc_slot_town_trade_route_last_arrivals_begin, dplmc_slot_town_trade_route_last_arrivals_end),
  61791. #Set "hours-since" to one week.
  61792. (assign, ":hours_since", 7 * 24),
  61793. (else_try),
  61794. #If the slot is uninitialized, give it a random plausible value.
  61795. (party_slot_eq, ":center_no", ":arrival_slot", 0),#Uninitialzed memory!
  61796. (store_random_in_range, ":hours_since", 1, (24 * 7 * 5) + 1),#random time in last five weeks
  61797. (party_get_slot, ":prosperity_factor", ":center_no", slot_town_prosperity),
  61798. (val_clamp, ":prosperity_factor", 0, 101),
  61799. (val_add, ":prosperity_factor", 75),
  61800. (val_mul, ":hours_since", 125),
  61801. (val_div, ":hours_since", ":prosperity_factor"),#last arrival some time in the last five weeks, plus or minus up to 40% based on prosperity
  61802. (store_sub, ":last_arrival", ":cur_hours", ":hours_since"),
  61803. (party_set_slot, ":center_no", ":arrival_slot", ":last_arrival"),
  61804. (else_try),
  61805. (party_get_slot, ":last_arrival", ":center_no", ":arrival_slot"),
  61806. (store_sub, ":hours_since", ":cur_hours", ":last_arrival"),
  61807. (val_max, ":hours_since", 0),
  61808. (try_end),
  61809.  
  61810.  
  61811. #Base penalty is 5%. It stays at a flat 5% for the first week, then begins rising
  61812. #at a rate of 5% per week afterwards (incremented continuously).
  61813. #Clamp the maximum penalty at 50%.
  61814. (store_mul, ":penalty", ":hours_since", 5),
  61815. (val_add, ":penalty", (24 * 7) // 2),
  61816. (val_div, ":penalty", 24 * 7),
  61817. (val_max, ":penalty", 5),#required for the first week
  61818. (val_min, ":penalty", 50),#don't increase above 50%
  61819.  
  61820. #Apply mercantilism
  61821. (store_faction_of_party, ":other_faction", ":trade_town"),
  61822. (try_begin),
  61823. #Decrease penalty for mercantilism, increase for free trade
  61824. (eq, ":other_faction", ":center_faction"),
  61825. (val_sub, ":penalty", ":mercantilism"),
  61826. (else_try),
  61827. #Increase penalty for mercantilism, decrease for free trade
  61828. (val_add, ":penalty", ":mercantilism"),
  61829. (try_end),
  61830.  
  61831. (try_begin),
  61832. (ge, ":price_factor_2", average_price_factor),
  61833. (val_mul, ":price_factor_2", ":penalty"),
  61834. (val_add, ":price_factor_2", 50),
  61835. (val_div, ":price_factor_2", 100),
  61836. (else_try),
  61837. (store_add, reg0, 100, ":penalty"),
  61838. (val_mul, reg0, average_price_factor),
  61839. (val_add, reg0, 50),
  61840. (val_div, reg0, 100),
  61841. (val_add, ":price_factor_2", reg0),
  61842. (try_end),
  61843. #Make use of the source
  61844. (assign, ":has_good", 1),
  61845. (val_min, ":best_foreign_price", ":price_factor_2"),
  61846. (try_end),
  61847. (try_begin),
  61848. (ge, ":has_good", 1),
  61849. (val_max, ":price_factor", ":best_foreign_price"),
  61850. (else_try),
  61851. #Make it so that lack of supply will not make the price lower
  61852. (lt, ":has_good", 1),
  61853. (val_max, ":price_factor", ":worst_price_seen"),
  61854. (try_end),
  61855. (try_end),
  61856.  
  61857. (try_begin),
  61858. (lt, ":has_good", 1),
  61859. (val_max, ":price_factor", average_price_factor),#don't give bargains if there is no supply
  61860. (val_mul, ":price_factor", 8),#sixty percent penalty
  61861. (val_div, ":price_factor", 5),
  61862. (try_end),
  61863.  
  61864. #Apply constraints at the last step
  61865. (val_clamp, ":price_factor", minimum_price_factor, maximum_price_factor),
  61866.  
  61867. (assign, reg0, ":price_factor"),
  61868. (assign, reg1, ":has_good"),
  61869. ]),
  61870.  
  61871. # script_dplmc_get_faction_truce_length_with_faction
  61872. # INPUT
  61873. # arg1: faction_1
  61874. # arg2: faction_2
  61875. # OUTPUT
  61876. # reg0: The length in days of faction_1's truce with faction_2, if any.
  61877. # If no truce exists, the appropriate value to return is zero.
  61878. ("dplmc_get_faction_truce_length_with_faction",
  61879. [
  61880. (store_script_param, ":faction_1", 1),
  61881. (store_script_param, ":faction_2", 2),
  61882.  
  61883. (assign, ":truce_length", 0),
  61884.  
  61885. (try_begin),
  61886. (is_between, ":faction_1", kingdoms_begin, kingdoms_end),
  61887. (is_between, ":faction_2", kingdoms_begin, kingdoms_end),
  61888. (neq, ":faction_1", ":faction_2"),
  61889. (store_add, ":truce_slot", ":faction_2", slot_faction_truce_days_with_factions_begin),
  61890. (val_sub, ":truce_slot", kingdoms_begin),
  61891. (faction_get_slot, ":truce_length", ":faction_1", ":truce_slot"),
  61892. (try_end),
  61893. (assign, reg0, ":truce_length"),
  61894. ]),
  61895.  
  61896. #script_dplmc_get_terrain_code_for_battle
  61897. #
  61898. # Gets the terrain code for a battle between two parties, which
  61899. # is usually a value like rt_desert, but can instead be two
  61900. # special values: -1 for
  61901. #
  61902. # INPUT: arg1 = attacker_party
  61903. # arg2 = defender_party
  61904. # OUTPUT: reg0 = terrain code (-1 for invalid, -2 for siege)
  61905. ("dplmc_get_terrain_code_for_battle",
  61906. [
  61907. (store_script_param, ":attacker_party", 1),
  61908. (store_script_param, ":defender_party", 2),
  61909.  
  61910. (assign, reg0, dplmc_terrain_code_unknown), #Terrain code, defined in header_terrain_types.py
  61911.  
  61912. (try_begin),
  61913. #Check for village missions
  61914. (this_or_next|eq, ":attacker_party", "p_main_party"),
  61915. (eq, ":defender_party", "p_main_party"),
  61916. (ge, "$g_encounter_is_in_village", 1),
  61917. (assign, reg0, dplmc_terrain_code_village),#defined in header_terrain_types.py
  61918. (else_try),
  61919. #If the attacker party is a town, a castle, a village, a bandit lair, or a ship,
  61920. #set the terrain code to "none" since we don't have any specific ideas for modifying
  61921. #the unit-type performance in scenarios of that type (whatever they are).
  61922. (ge, ":attacker_party", 0),
  61923. (this_or_next|party_slot_eq, ":attacker_party", slot_party_type, spt_town),#no modifier for being attacked by garrisoned troops
  61924. (this_or_next|party_slot_eq, ":attacker_party", slot_party_type, spt_castle),
  61925. (this_or_next|party_slot_eq, ":attacker_party", slot_party_type, spt_village),
  61926. (this_or_next|party_slot_eq, ":attacker_party", slot_party_type, spt_bandit_lair),
  61927. (party_slot_eq, ":attacker_party", slot_party_type, spt_ship),#no modifier for being attacked by a ship
  61928. (assign, reg0, dplmc_terrain_code_unknown),#no terrain options, defined in header_terrain_types.py
  61929. (else_try),
  61930. #If the attacker party is *attached* to a town/castle/village, a bandit lair, or a ship,
  61931. #set the terrain code to "none" since we don't have any specific ideas for modifying
  61932. #the unit-type performance in scenarios of that type (whatever they are).
  61933. (ge, ":attacker_party", 0),
  61934. (party_get_attached_to, ":attachment", ":attacker_party"),
  61935. (ge, ":attachment", 0),
  61936. (party_is_active, ":attachment"),
  61937. (this_or_next|party_slot_eq, ":attachment", slot_party_type, spt_town),#no modifier for being attacked by garrisoned troops
  61938. (this_or_next|party_slot_eq, ":attachment", slot_party_type, spt_castle),
  61939. (this_or_next|party_slot_eq, ":attachment", slot_party_type, spt_village),
  61940. (this_or_next|party_slot_eq, ":attachment", slot_party_type, spt_bandit_lair),
  61941. (party_slot_eq, ":attachment", slot_party_type, spt_ship),#no modifier for being attacked by a ship
  61942. (assign, reg0, dplmc_terrain_code_unknown),#no terrain modifiers
  61943. (else_try),
  61944. #If the attacker party isn't a weird type, the terrain is entirely based on the
  61945. #defender (unless the defender is invalid).
  61946. (ge, ":defender_party", 0),
  61947. (try_begin),
  61948. #If the defender is a walled center, use siege mode.
  61949. (this_or_next|party_slot_eq, ":defender_party", slot_party_type, spt_town),
  61950. (party_slot_eq, ":defender_party", slot_party_type, spt_castle),
  61951. (assign, reg0, dplmc_terrain_code_siege),#siege mode, defined in header_terrain_types.py
  61952. (else_try),
  61953. #If the defender is a village
  61954. (party_slot_eq, ":defender_party", slot_party_type, spt_village),
  61955. (assign, reg0, dplmc_terrain_code_village),
  61956. (else_try),
  61957. #If the defender is a bandit lair or a ship, use no terrain modifier.
  61958. (this_or_next|party_slot_eq, ":defender_party", slot_party_type, spt_bandit_lair),
  61959. (party_slot_eq, ":defender_party", slot_party_type, spt_ship),
  61960. (assign, reg0, dplmc_terrain_code_unknown),#no terrain modifiers
  61961. (else_try),
  61962. #If the defender is attached, do the same checks but for the attachment.
  61963. (party_get_attached_to, ":attachment", ":defender_party"),
  61964. (ge, ":attachment", 0),
  61965. (party_is_active, ":attachment"),
  61966. (assign, ":attachment_value", -100),
  61967. (try_begin),
  61968. #Walled centers use siege modifiers
  61969. (this_or_next|party_slot_eq, ":attachment", slot_party_type, spt_town),
  61970. (party_slot_eq, ":attachment", slot_party_type, spt_castle),
  61971. (assign, ":attachment_value", dplmc_terrain_code_siege),
  61972. (else_try),
  61973. #Villages
  61974. (party_slot_eq, ":attachment", slot_party_type, spt_village),
  61975. (assign, ":attachment_value", dplmc_terrain_code_village),
  61976. (else_try),
  61977. #bandit-lairs and ships have no modifiers currently
  61978. (this_or_next|party_slot_eq, ":attachment", slot_party_type, spt_bandit_lair),
  61979. (party_slot_eq, ":attachment", slot_party_type, spt_ship),
  61980. (assign, ":attachment_value", dplmc_terrain_code_unknown),#no terrain modifiers
  61981. (try_end),
  61982. #If neither of the above apply, fall through to the next condition.
  61983. (neq, ":attachment_value", -100),
  61984. (assign, reg0, ":attachment_value"),
  61985. (else_try),
  61986. #Use the terrain under the defender.
  61987. #In the future I might want to change this so there's a tactics contest
  61988. #between the attacker and defender to choose the more favorable ground
  61989. #from their immediate surroundings. I would also have to change the actual
  61990. #terrain-type code.
  61991. (party_get_current_terrain, reg0, ":defender_party"),
  61992. (try_end),
  61993. (else_try),
  61994. #If we get here, it means the defender was invalid, so use the terrain under
  61995. #the attacker.
  61996. (ge, ":attacker_party", 0),
  61997. (party_get_current_terrain, reg0, ":attacker_party"),#terrain under attacker
  61998. (try_end),
  61999. ]),
  62000.  
  62001. #script_dplmc_party_calculate_strength_in_terrain
  62002. # INPUT: arg1 = party_id
  62003. # arg2 = terrain (from header_terrain_types.py)
  62004. # arg3 = exclude leader (0 for do-not-exclude, 1 for exclude)
  62005. # arg4 = cache policy (1 is use terrain, 2 is use non-terrain, 0 is do not use)
  62006. # OUTPUT: reg0 = strength with terrain
  62007. # reg1 = strength ignoring terrain
  62008. ("dplmc_party_calculate_strength_in_terrain",
  62009. [
  62010. (store_script_param, ":party", 1), #Party_id
  62011. (store_script_param, ":terrain_type", 2),#a value from header_terrain_types.py
  62012. (store_script_param, ":exclude_leader", 3),#(0 for do-not-exclude, 1 for exclude)
  62013. (store_script_param, ":cache_policy", 4),#1 is use terrain, 2 is use non-terrain, 0 is do not use)
  62014.  
  62015. (assign, ":total_strength_terrain", 0),
  62016. (assign, ":total_strength_no_terrain", 0),
  62017.  
  62018. (party_get_num_companion_stacks, ":num_stacks", ":party"),
  62019. (assign, ":first_stack", 0),
  62020. (try_begin),
  62021. (neq, ":exclude_leader", 0),
  62022. (assign, ":first_stack", 1),
  62023. (try_end),
  62024. #Bonus for heroes on top of the rest
  62025. (assign, ":hero_percent", 110),
  62026. ##Moved setting the multipliers out of the loop...
  62027. (assign, ":guaranteed_horse_percent", 100),
  62028. (assign, ":guaranteed_ranged_percent", 100),
  62029. (assign, ":guaranteed_neither_percent", 100),
  62030. #First, test for some special codes:
  62031. (try_begin),
  62032. (eq, ":terrain_type", dplmc_terrain_code_none),#Apply no modifiers
  62033. (assign, ":hero_percent", 100),
  62034. (else_try),
  62035. (eq, ":terrain_type", dplmc_terrain_code_village),#A dismounted fight at a village (apply hero modifier, nothing else)
  62036. (else_try),
  62037. (eq, ":terrain_type", dplmc_terrain_code_siege),#A siege battle, not including sorties.
  62038. (assign, ":guaranteed_ranged_percent", 120),
  62039. #The rest are ordinary rt_* codes.
  62040. #I changed the balance of these to make the variations less extreme (e.g. 150% mounted strength on rt_steppe).
  62041. #I believe that the version from ArcherOS is trying to create certain map results, rather than solely
  62042. #make autocalc strength more accurate in terms of "what would happen if they fought the player".
  62043. (else_try),
  62044. (eq, ":terrain_type", rt_steppe),
  62045. #The 150% increase in the steppe strikes me as excessive.
  62046. #Since the NPC cost increase for mounted troops is 20%, and the PC cost is 65%,
  62047. #it isn't entirely implausible.
  62048. #(assign, ":guaranteed_horse_percent", 150),
  62049. #Archer uses 150%, Custom Commander uses a flat 125%.
  62050. (assign, ":guaranteed_horse_percent", 120),
  62051. (else_try),
  62052. #I am unaware of any game mechanic in live battles that gives any disadvantage
  62053. #to horses on snow or sand as opposed to a plain.
  62054. (this_or_next|eq, ":terrain_type", rt_snow),
  62055. (this_or_next|eq, ":terrain_type", rt_desert),
  62056. (eq, ":terrain_type", rt_plain),
  62057. (assign, ":guaranteed_horse_percent", 120),
  62058. (else_try),
  62059. #I suspect that the 120% mounted bonus for steppe forests is inaccurate,
  62060. #but I haven't checked it out yet.
  62061. (eq, ":terrain_type", rt_steppe_forest),
  62062. (assign, ":guaranteed_horse_percent", 120),
  62063. (else_try),
  62064. (this_or_next|eq, ":terrain_type", rt_forest),
  62065. (this_or_next|eq, ":terrain_type", rt_mountain_forest),
  62066. (eq, ":terrain_type", rt_snow_forest),
  62067. #(assign, ":guaranteed_neither_percent", 120),
  62068. (assign, ":guaranteed_neither_percent", 110),
  62069. (try_end),
  62070.  
  62071. (try_for_range, ":i_stack", ":first_stack", ":num_stacks"),
  62072. (party_stack_get_troop_id, ":stack_troop",":party", ":i_stack"),
  62073. (store_character_level, ":stack_strength", ":stack_troop"),
  62074. (val_add, ":stack_strength", 4), #new was 12 (patch 1.125)
  62075. (val_mul, ":stack_strength", ":stack_strength"),
  62076. (val_mul, ":stack_strength", 2), #new (patch 1.125)
  62077. #move the next two lines to after terrain advantage
  62078. #(val_div, ":stack_strength", 100),
  62079. #(val_max, ":stack_strength", 1), #new (patch 1.125)
  62080. (assign, ":terrain_free_strength", ":stack_strength"),
  62081. ##use Arch3r's terrain advantage code (bug-fix changes 2011-04-13; other changes 2011-04-25)
  62082. (try_begin),
  62083. ##AotE terrain advantages
  62084. (assign, ":hero_horse", 0),#added for heroes (any positive number = has a horse)
  62085. (try_begin),
  62086. (this_or_next|eq, "trp_player", ":stack_troop"),
  62087. (troop_is_hero, ":stack_troop"),
  62088. (gt, ":guaranteed_horse_percent", ":hero_percent"),#don't bother if we wouldn't use the result
  62089. (neg|troop_is_guarantee_horse, ":stack_troop"),#don't bother if we already know the troop has a horse
  62090. (store_skill_level, reg0, "skl_riding", ":stack_troop"),
  62091. (ge, reg0, 2),#don't bother if the troop has no/minimal riding skill
  62092. #Just checking ek_horse may not work for non-companions, so check the inventory
  62093. (troop_get_inventory_capacity, ":inv_cap", ":stack_troop"),
  62094. (ge, ":inv_cap", 1),
  62095. (val_min, ":inv_cap", dplmc_ek_alt_items_begin + 8),#Don't check too much of the inventory
  62096. (try_for_range, ":inv_slot", 0, ":inv_cap"),
  62097. (troop_inventory_slot_get_item_amount, reg1, ":stack_troop", ":inv_slot"),
  62098. (ge, reg1, 1),#quantity must be greater than zero
  62099. (troop_get_inventory_slot, reg0, ":stack_troop", ":inv_slot"),
  62100. (ge, reg0, 1),#must be a valid item
  62101. (item_get_type, reg1, reg0),#check if the item is a horse
  62102. (eq, reg1, itp_type_horse),
  62103. (assign, ":inv_cap", ":inv_slot"),#break loop
  62104. (try_end),
  62105. #If no horse found, set to zero
  62106. (neg|is_between, ":hero_horse", horses_begin, horses_end),
  62107. (assign, ":hero_horse", 0),
  62108. (try_end),
  62109. (assign, ":stack_strength_multiplier", 100),#<-- percent multiplier
  62110. (try_begin),#Mounted troops
  62111. (this_or_next|ge, ":hero_horse", 1),
  62112. (troop_is_guarantee_horse, ":stack_troop"),
  62113. (assign, ":stack_strength_multiplier", ":guaranteed_horse_percent"),
  62114. (else_try),#Ranged troops
  62115. (troop_is_guarantee_ranged, ":stack_troop"),
  62116. (assign, ":stack_strength_multiplier", ":guaranteed_ranged_percent"),
  62117. (else_try),#Infantry
  62118. (assign, ":stack_strength_multiplier", ":guaranteed_neither_percent"),
  62119. (try_end),
  62120.  
  62121. #Use hero/player modifiers if a better one didn't apply
  62122. (try_begin),
  62123. (this_or_next|eq, ":stack_troop", "trp_player"),
  62124. (troop_is_hero, ":stack_troop"),
  62125. (val_max, ":stack_strength_multiplier", ":hero_percent"),#hero bonus
  62126. (try_end),
  62127.  
  62128. (val_mul, ":stack_strength", ":stack_strength_multiplier"),
  62129. (val_add, ":stack_strength", 50),#add this before division for correct rounding
  62130. (val_div, ":stack_strength", 100),
  62131. ##AotE terrain advantages
  62132. (try_end),
  62133. #moved the next two lines here from above
  62134. (val_div, ":stack_strength", 100),#<- moved here from above
  62135. (val_max, ":stack_strength", 1), #new (patch 1.125) #<- moved here from above
  62136. (val_div, ":terrain_free_strength", 100),
  62137. (val_max, ":terrain_free_strength", 1),
  62138. (try_begin),
  62139. (neg|troop_is_hero, ":stack_troop"),
  62140. (party_stack_get_size, ":stack_size",":party",":i_stack"),
  62141. (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
  62142. (val_sub, ":stack_size", ":num_wounded"),
  62143. (val_mul, ":stack_strength", ":stack_size"),
  62144. (val_mul, ":terrain_free_strength", ":stack_size"),
  62145. (else_try),
  62146. (troop_is_wounded, ":stack_troop"), #hero & wounded
  62147. (assign, ":stack_strength", 0),
  62148. (assign, ":terrain_free_strength", 0),
  62149. (try_end),
  62150. (val_add, ":total_strength_terrain", ":stack_strength"),
  62151. (val_add, ":total_strength_no_terrain", ":terrain_free_strength"),
  62152. (try_end),
  62153. #Load results into registers and cache if appropriate
  62154. (assign, reg0, ":total_strength_terrain"),
  62155. (assign, reg1, ":total_strength_no_terrain"),
  62156. (try_begin),
  62157. (eq, ":cache_policy", 1),
  62158. (party_set_slot, ":party", slot_party_cached_strength, reg0),
  62159. (else_try),
  62160. (eq, ":cache_policy", 2),
  62161. (party_set_slot, ":party", slot_party_cached_strength, reg1),
  62162. (try_end),
  62163. ]),
  62164.  
  62165.  
  62166. #script_dplmc_player_can_give_troops_to_troop (Warning, clobbers {s11}!)
  62167. #
  62168. # INPUT: arg1 = troop_id
  62169. # OUTPUT: reg0 = 1 or more is yes, 0 or less is no
  62170. #
  62171. # This script does not take into account things like whether the troop
  62172. # is a prisoner of a party, so it can be used for checking whether troops
  62173. # can be added to a garrison.
  62174. #
  62175. # The general logic is that you can give troops to a member of your
  62176. # own faction if any of the following are true:
  62177. # - You are the faction leader or marshall
  62178. # - You are the spouse of the faction leader, and the faction
  62179. # leader is not on bad terms with you
  62180. # - The troop is an affiliated family member
  62181. # - The troop is your spouse, and is either pliable or not on bad terms
  62182. # - The troop is a former companion with whom you are on good terms
  62183. # - The troop is related to you by marriage and you are on good terms
  62184. #
  62185. # For allied factions, the conditions are similar to the above.
  62186. # However, being the marshall or leader of your own faction does not
  62187. # guarantee cooperation from lords who dislike you.
  62188. #
  62189. # For non-allied other factions, the check for faction leader or
  62190. # marshall are not relevant, and the faction must not be at war
  62191. # with the player's faction.
  62192. ("dplmc_player_can_give_troops_to_troop",
  62193. [
  62194. (store_script_param, ":troop_id", 1), #Party_id
  62195. (assign, ":can_give_troops", 0),
  62196. (assign, ":save_reg1", reg1),
  62197.  
  62198. (try_begin),
  62199. (this_or_next|eq, ":troop_id", "trp_kingdom_heroes_including_player_begin"),
  62200. (eq, ":troop_id", "trp_player"),
  62201. (assign, ":can_give_troops", 1),
  62202. (else_try),
  62203. (lt, ":troop_id", 1),
  62204. (assign, ":can_give_troops", 0),
  62205. (else_try),
  62206. (store_faction_of_troop, ":troop_faction", ":troop_id"),
  62207.  
  62208. (call_script, "script_troop_get_player_relation", ":troop_id"),
  62209. (assign, ":troop_relation", reg0),
  62210. (troop_get_slot, ":troop_reputation", ":troop_id", slot_lord_reputation_type),
  62211.  
  62212. (try_begin),
  62213. #Troop is member of player supporters faction
  62214. (eq, ":troop_faction", "fac_player_supporters_faction"),
  62215. ##Always yes in Native, but if centralization is negative allow non-compliance
  62216. (faction_get_slot, reg0, ":troop_faction", dplmc_slot_faction_centralization),
  62217. (try_begin),
  62218. (ge, reg0, 0),
  62219. (assign, reg0, -200),
  62220. (else_try),
  62221. (val_mul, reg0, -10),
  62222. (val_add, reg0, -35),#Centralization -1 has -25, -2 has -15, and -3 has -5
  62223. (try_end),
  62224. (gt, ":troop_relation", reg0),
  62225. (assign, ":can_give_troops", 1),
  62226. (else_try),
  62227. #Troop is a member of the same faction as the player
  62228. (eq, ":troop_faction", "$players_kingdom"),
  62229. (faction_get_slot, ":troop_faction_leader", ":troop_faction", slot_faction_leader),
  62230. (try_begin),
  62231. #Leader or marshall
  62232. (this_or_next|eq, ":troop_faction_leader", "trp_player"),
  62233. (faction_slot_eq, ":troop_faction", slot_faction_marshall, "trp_player"),
  62234. #If centralization is negative allow non-compliance
  62235. (faction_get_slot, reg0, ":troop_faction", dplmc_slot_faction_centralization),
  62236. (try_begin),
  62237. (ge, reg0, 0),
  62238. (assign, reg0, -200),
  62239. (else_try),
  62240. (val_mul, reg0, -10),
  62241. (val_add, reg0, -35),#Centralization -1 has -25, -2 has -15, and -3 has -5
  62242. (try_end),
  62243. (gt, ":troop_relation", reg0),
  62244. (assign, ":can_give_troops", 1),
  62245. (else_try),
  62246. #Spouse of leader
  62247. (gt, ":troop_faction_leader", 1),
  62248. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, -1),
  62249. (this_or_next|troop_slot_eq, ":troop_faction_leader", slot_troop_spouse, "trp_player"),
  62250. (troop_slot_eq, "trp_player", slot_troop_spouse, ":troop_faction_leader"),
  62251. (call_script, "script_troop_get_player_relation", ":troop_faction_leader"),
  62252. (ge, reg0, 0),
  62253. #If centralization is negative allow non-compliance
  62254. (faction_get_slot, reg0, ":troop_faction", dplmc_slot_faction_centralization),
  62255. (try_begin),
  62256. (ge, reg0, 0),
  62257. (assign, reg0, -200),
  62258. (else_try),
  62259. (val_mul, reg0, -10),
  62260. (val_add, reg0, -35),#Centralization -1 has -25, -2 has -15, and -3 has -5
  62261. (try_end),
  62262. (gt, ":troop_relation", reg0),
  62263. (assign, ":can_give_troops", 1),
  62264. (else_try),
  62265. #Spouse of troop
  62266. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, -1),
  62267. (this_or_next|troop_slot_eq, ":troop_id", slot_troop_spouse, "trp_player"),
  62268. (troop_slot_eq, "trp_player", slot_troop_spouse, ":troop_id"),
  62269. (this_or_next|ge, ":troop_relation", 0),
  62270. (this_or_next|eq, ":troop_reputation", lrep_conventional),
  62271. (this_or_next|eq, ":troop_reputation", lrep_moralist),
  62272. (eq, ":troop_reputation", lrep_otherworldly),
  62273. (assign, ":can_give_troops", 1),
  62274. (else_try),
  62275. #Affiliated family member
  62276. (call_script, "script_dplmc_is_affiliated_family_member", ":troop_id"),
  62277. (ge, reg0, 1),
  62278. (assign, ":can_give_troops", 1),
  62279. (else_try),
  62280. #Close companion previously under arms
  62281. (this_or_next|is_between, ":troop_id", companions_begin, companions_end),
  62282. (is_between, ":troop_id", pretenders_begin, pretenders_end),
  62283. (neg|troop_slot_eq, ":troop_id", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  62284. (ge, ":troop_relation", 20),
  62285. (assign, ":can_give_troops", 1),
  62286. (else_try),
  62287. #In-law (or hypothetically a blood relative) who is close with the player
  62288. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":troop_id", "trp_player"),
  62289. (ge, reg0, 2),#<-- deliberately set the cutoff to 2, not 1
  62290. (ge, ":troop_relation", 14),
  62291. (this_or_next|ge, reg0, 10),
  62292. (ge, ":troop_relation", 20),
  62293. (assign, ":can_give_troops", 1),
  62294. (try_end),
  62295. (else_try),
  62296. #Troop is member of a faction allied with the player's
  62297. (call_script, "script_dplmc_get_faction_truce_length_with_faction", "$players_kingdom", ":troop_faction"),
  62298. (gt, reg0, dplmc_treaty_defense_days_expire),
  62299. (faction_get_slot, ":player_faction_leader", "$players_kingdom", slot_faction_leader),
  62300. (try_begin),
  62301. #Leader or marshall
  62302. (this_or_next|eq, ":player_faction_leader", "trp_player"),
  62303. (faction_slot_eq, "$players_kingdom", slot_faction_marshall, "trp_player"),
  62304. (ge, ":troop_relation", 0),#only for allied factions, not for the player's own faction
  62305. (assign, ":can_give_troops", 1),
  62306. (else_try),
  62307. #Spouse of leader
  62308. (gt, ":player_faction_leader", 1),
  62309. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, -1),
  62310. (this_or_next|troop_slot_eq, ":player_faction_leader", slot_troop_spouse, "trp_player"),
  62311. (troop_slot_eq, "trp_player", slot_troop_spouse, ":player_faction_leader"),
  62312. (ge, ":troop_relation", 0),#only for allied factions, not for the player's own faction
  62313. (call_script, "script_troop_get_player_relation", ":player_faction_leader"),
  62314. (ge, reg0, 0),
  62315. (assign, ":can_give_troops", 1),
  62316. (else_try),
  62317. #Spouse of troop
  62318. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, -1),
  62319. (this_or_next|troop_slot_eq, ":troop_id", slot_troop_spouse, "trp_player"),
  62320. (troop_slot_eq, "trp_player", slot_troop_spouse, ":troop_id"),
  62321. (this_or_next|ge, ":troop_relation", 0),
  62322. (this_or_next|eq, ":troop_reputation", lrep_conventional),
  62323. (this_or_next|eq, ":troop_reputation", lrep_moralist),
  62324. (eq, ":troop_reputation", lrep_otherworldly),
  62325. (assign, ":can_give_troops", 1),
  62326. (else_try),
  62327. #Affiliated family member
  62328. (call_script, "script_dplmc_is_affiliated_family_member", ":troop_id"),
  62329. (ge, reg0, 1),
  62330. (assign, ":can_give_troops", 1),
  62331. (else_try),
  62332. #Close companion previously under arms
  62333. (this_or_next|is_between, ":troop_id", companions_begin, companions_end),
  62334. (is_between, ":troop_id", pretenders_begin, pretenders_end),
  62335. (neg|troop_slot_eq, ":troop_id", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  62336. (ge, ":troop_relation", 20),
  62337. (assign, ":can_give_troops", 1),
  62338. (else_try),
  62339. #In-law (or hypothetically a blood relative) who is close with the player
  62340. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":troop_id", "trp_player"),
  62341. (ge, reg0, 2),#<-- deliberately set the cutoff to 2, not 1
  62342. (ge, ":troop_relation", 14),
  62343. (this_or_next|ge, reg0, 10),
  62344. (ge, ":troop_relation", 20),
  62345. (assign, ":can_give_troops", 1),
  62346. (try_end),
  62347. (else_try),
  62348. #Troop is a member of a faction that isn't hostile to the player's
  62349. (store_relation, reg0, ":troop_faction", "fac_player_faction"),
  62350. (ge, reg0, 0),
  62351. (store_relation, reg0, ":troop_faction", "$players_kingdom"),
  62352. (ge, reg0, 0),
  62353. (try_begin),
  62354. #Spouse of troop
  62355. (neg|troop_slot_eq, "trp_player", slot_troop_spouse, -1),
  62356. (this_or_next|troop_slot_eq, ":troop_id", slot_troop_spouse, "trp_player"),
  62357. (troop_slot_eq, "trp_player", slot_troop_spouse, ":troop_id"),
  62358. (this_or_next|ge, ":troop_relation", 0),
  62359. (this_or_next|eq, ":troop_reputation", lrep_conventional),
  62360. (this_or_next|eq, ":troop_reputation", lrep_moralist),
  62361. (eq, ":troop_reputation", lrep_otherworldly),
  62362. (assign, ":can_give_troops", 1),
  62363. (else_try),
  62364. #Affiliated family member
  62365. (call_script, "script_dplmc_is_affiliated_family_member", ":troop_id"),
  62366. (ge, reg0, 1),
  62367. (assign, ":can_give_troops", 1),
  62368. (else_try),
  62369. #Close companion previously under arms
  62370. (this_or_next|is_between, ":troop_id", companions_begin, companions_end),
  62371. (is_between, ":troop_id", pretenders_begin, pretenders_end),
  62372. (neg|troop_slot_eq, ":troop_id", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  62373. (ge, ":troop_relation", 20),
  62374. (assign, ":can_give_troops", 1),
  62375. (else_try),
  62376. #In-law (or hypothetically a blood relative) who is close with the player
  62377. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":troop_id", "trp_player"),
  62378. (ge, reg0, 2),#<-- deliberately set the cutoff to 2, not 1
  62379. (ge, ":troop_relation", 14),
  62380. (this_or_next|ge, reg0, 10),
  62381. (ge, ":troop_relation", 20),
  62382. (assign, ":can_give_troops", 1),
  62383. (try_end),
  62384. (try_end),
  62385. (try_end),
  62386.  
  62387. (assign, reg1, ":save_reg1"),
  62388. (assign, reg0, ":can_give_troops"),
  62389. ]),
  62390.  
  62391. #script_dplmc_print_centers_in_numbers_to_s0
  62392. #
  62393. #similar to script_print_troop_owned_centers_in_numbers_to_s0
  62394. #
  62395. #INPUT:
  62396. # arg1: owned_towns
  62397. # arg2: owned_castles
  62398. # arg3: owned_villages
  62399. #
  62400. #OUTPUT:
  62401. # reg0: owned_towns + owned_castles + owned_villages
  62402. # s0: a string describing the numbers of centers
  62403. ("dplmc_print_centers_in_numbers_to_s0",
  62404. [
  62405. (store_script_param_1, ":owned_towns"),
  62406. (store_script_param_2, ":owned_castles"),
  62407. (store_script_param, ":owned_villages", 3),
  62408. (str_store_string, s0, "@nothing"),
  62409.  
  62410. (assign, ":num_types", 0),
  62411. (try_begin),
  62412. (gt, ":owned_villages", 0),
  62413. (assign, reg0, ":owned_villages"),
  62414. (store_sub, reg1, reg0, 1),
  62415. (str_store_string, s0, "@{reg0} village{reg1?s:}"),
  62416. (val_add, ":num_types", 1),
  62417. (try_end),
  62418.  
  62419. (try_begin),
  62420. (gt, ":owned_castles", 0),
  62421. (assign, reg0, ":owned_castles"),
  62422. (store_sub, reg1, reg0, 1),
  62423. (try_begin),
  62424. (eq, ":num_types", 0),
  62425. (str_store_string, s0, "@{reg0} castle{reg1?s:}"),
  62426. (else_try),
  62427. (str_store_string, s0, "@{reg0} castle{reg1?s:} and {s0}"),
  62428. (try_end),
  62429. (val_add, ":num_types", 1),
  62430. (try_end),
  62431.  
  62432. (try_begin),
  62433. (gt, ":owned_towns", 0),
  62434. (assign, reg0, ":owned_towns"),
  62435. (store_sub, reg1, reg0, 1),
  62436. (try_begin),
  62437. (eq, ":num_types", 0),
  62438. (str_store_string, s0, "@{reg0} town{reg1?s:}"),
  62439. (else_try),
  62440. (eq, ":num_types", 1),
  62441. (str_store_string, s0, "@{reg0} town{reg1?s:} and {s0}"),
  62442. (else_try),
  62443. (str_store_string, s0, "@{reg0} town{reg1?s:}, {s0}"),
  62444. (try_end),
  62445. (try_end),
  62446.  
  62447. (store_add, reg0, ":owned_villages", ":owned_castles"),
  62448. (val_add, reg0, ":owned_towns"),
  62449. ]),
  62450.  
  62451. #"script_dplmc_distribute_gold_to_lord_and_holdings"
  62452. #
  62453. #Related to script_dplmc_remove_gold_from_lord_and_holdings, divides the gold
  62454. #between the lord and his fortresses in a semi-intelligent way.
  62455. #
  62456. #INPUT:
  62457. # arg1: the amount of gold
  62458. # arg2: the lord's ID
  62459. ("dplmc_distribute_gold_to_lord_and_holdings",
  62460. [
  62461. (store_script_param_1, ":gold_left"),
  62462. (store_script_param_2, ":lord_no"),
  62463.  
  62464. (try_begin),
  62465. (lt, ":lord_no", 0),#Invalid ID
  62466. (else_try),
  62467. #If the number is negative, handle this using script_dplmc_remove_gold_from_lord_and_holdings
  62468. (lt, ":gold_left", 0),
  62469. (val_mul, ":gold_left", -1),
  62470. (call_script, "script_dplmc_remove_gold_from_lord_and_holdings", ":gold_left", ":lord_no"),
  62471. (assign, ":gold_left", 0),
  62472. (else_try),
  62473. (neq, ":lord_no", "trp_player"),
  62474. (neg|troop_is_hero, ":lord_no"),#Not hero or player
  62475. (troop_add_gold, ":lord_no", ":gold_left"),
  62476. (assign, ":gold_left", 0),
  62477. (else_try),
  62478. #The player doesn't use center wealth to pay garrison wages, so just
  62479. #give it directly.
  62480. (eq, ":lord_no", "trp_player"),
  62481. (troop_add_gold, "trp_player", ":gold_left"),
  62482. (assign, ":gold_left", 0),
  62483. (else_try),
  62484. (neg|troop_is_hero, ":lord_no"),#If the lord isn't the player, and isn't a hero, do nothing
  62485. (else_try),
  62486. (troop_get_slot, ":target_gold", ":lord_no", slot_troop_wealth),
  62487. (val_max, ":target_gold", 0),
  62488. #If the lord is low on gold, first he takes enough gold so he isn't low on funds,
  62489. #or all of the gold, whichever is less.
  62490. (store_sub, ":gold_to_give", 6000, ":target_gold"),#6000 is the standard starting gold for lords (kings start with more, but don't increase this for them, since I'm using this number as a "low on gold" threshold)
  62491. (val_max, ":gold_to_give", 0),
  62492. (val_min, ":gold_to_give", ":gold_left"),
  62493.  
  62494. (val_add, ":target_gold", ":gold_to_give"),
  62495. (troop_set_slot, ":lord_no", slot_troop_wealth, ":target_gold"),
  62496. (val_sub, ":gold_left", ":gold_to_give"),
  62497. #If gold remains, the lord gives some to any castles or towns he owns that have
  62498. #low wealth. Note that iterating in this order means that towns get checked
  62499. #before castles do.
  62500. (gt, ":gold_left", 0),
  62501. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  62502. (party_slot_eq, ":center_no", slot_town_lord, ":lord_no"),
  62503. (party_get_slot, ":target_gold", ":center_no", slot_town_wealth),
  62504. #Don't give gold to centers with garrisons more than 50% above the ideal size
  62505. (store_party_size_wo_prisoners, ":garrison_size", ":center_no"),
  62506. (call_script, "script_party_get_ideal_size", ":center_no"),#This script has been modified to support this use
  62507. (val_mul, reg0, 3),
  62508. (val_div, reg0, 2),
  62509. (ge, reg0, ":garrison_size"),
  62510.  
  62511. (try_begin),
  62512. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  62513. (store_sub, ":gold_to_give", 4000, ":target_gold"),#4000 is the standard starting gold for towns
  62514. (else_try),
  62515. (store_sub, ":gold_to_give", 2000, ":target_gold"),#2000 is the standard starting gold for castles
  62516. (try_end),
  62517.  
  62518. (val_max, ":gold_to_give", 0),
  62519. (val_min, ":gold_to_give", ":gold_left"),
  62520. (gt, ":gold_to_give", 0),
  62521. (val_add, ":target_gold", ":gold_to_give"),
  62522. (party_set_slot, ":center_no", slot_town_wealth, ":target_gold"),
  62523. (val_sub, ":gold_left", ":gold_to_give"),
  62524. (try_end),
  62525. #If gold is left -- the lord isn't low on gold, and none of his walled centers are --
  62526. #he pockets the remainder.
  62527. (gt, ":gold_left", 0),
  62528. (troop_get_slot, ":target_gold", ":lord_no", slot_troop_wealth),
  62529. (val_add, ":target_gold", ":gold_left"),
  62530. (val_max, ":target_gold", 0),
  62531. (troop_set_slot, ":lord_no", slot_troop_wealth, ":target_gold"),
  62532. (assign, ":gold_left", 0),
  62533. (try_end),
  62534. ]),
  62535.  
  62536.  
  62537. #"script_dplmc_remove_gold_from_lord_and_holdings"
  62538. #
  62539. #
  62540. #INPUT:
  62541. # arg1: the amount of money to remove (greater than zero)
  62542. # arg2: the ID of the lord spending the money
  62543. #
  62544. #OUTPUT:
  62545. # None
  62546. ("dplmc_remove_gold_from_lord_and_holdings",
  62547. [
  62548. (store_script_param_1, ":gold_cost"),
  62549. (store_script_param_2, ":lord_no"),
  62550.  
  62551. (try_begin),
  62552. (lt, ":lord_no", 0),#Invalid ID
  62553. (else_try),
  62554. (neq, ":lord_no", "trp_player"),
  62555. (neg|troop_is_hero, ":lord_no"),#Not player or hero
  62556. (else_try),
  62557. #If the number is negative, give gold instead of taking it.
  62558. #Handle this using script_dplmc_distribute_gold_to_lord_and_holdings
  62559. (lt, ":gold_cost", 0),
  62560. (val_mul, ":gold_cost", -1),
  62561. (call_script, "script_dplmc_distribute_gold_to_lord_and_holdings", ":gold_cost", ":lord_no"),
  62562. (assign, ":gold_cost", 0),
  62563. (else_try),
  62564. #For the player, first subtract the gold from his treasury (if any).
  62565. (eq, ":lord_no", "trp_player"),
  62566. (store_troop_gold, ":treasury", "trp_household_possessions"),
  62567. (try_begin),
  62568. (ge, ":treasury", 1),
  62569. (val_min, ":treasury", ":gold_cost"),
  62570. (call_script, "script_dplmc_withdraw_from_treasury", ":treasury"),
  62571. (val_sub, ":gold_cost", ":treasury"),
  62572. (try_end),
  62573. (store_troop_gold, ":treasury", "trp_player"),
  62574. (try_begin),
  62575. (ge, ":treasury", 1),
  62576. (val_min, ":treasury", ":gold_cost"),
  62577. (troop_remove_gold, "trp_player", ":treasury"),
  62578. (val_sub, ":gold_cost", ":treasury"),
  62579. (try_end),
  62580. #Fall through to the next section if the treasury didn't cover it.
  62581. (lt, ":gold_cost", 1),
  62582. (else_try),
  62583. #Remove the gold directly from the lord's wealth slot
  62584. (ge, ":gold_cost", 1),
  62585. (ge, ":lord_no", 1),#not the player
  62586. (troop_get_slot, ":treasure", ":lord_no", slot_troop_wealth),
  62587. (ge, ":treasure", 1),
  62588. (try_begin),
  62589. (ge, ":treasure", ":gold_cost"),
  62590. (val_sub, ":treasure", ":gold_cost"),
  62591. (assign, ":gold_cost", 0),
  62592. (else_try),
  62593. (val_sub, ":gold_cost", ":treasure"),
  62594. (assign, ":treasure", 0),
  62595. (try_end),
  62596. (troop_set_slot, ":lord_no", slot_troop_wealth, ":treasure"),
  62597. #Fall through to the next section if his personal wealth didn't cover it.
  62598. (lt, ":gold_cost", 1),
  62599. (else_try),
  62600. #Remove remaining gold from uncollected taxes.
  62601. #We iterate backwards in order to remove from villages before castles and towns.
  62602. (ge, ":gold_cost", 1),
  62603. (try_for_range_backwards, ":center_no", centers_begin, centers_end),
  62604. (ge, ":gold_cost", 1),
  62605. (party_slot_eq, ":center_no", slot_town_lord, ":lord_no"),
  62606. (party_get_slot, ":treasure", ":center_no", slot_center_accumulated_rents),
  62607. (try_begin),
  62608. (gt, ":treasure", 0),
  62609. (ge, ":treasure", ":gold_cost"),
  62610. (val_sub, ":treasure", ":gold_cost"),
  62611. (assign, ":gold_cost", 0),
  62612. (else_try),
  62613. (gt, ":treasure", 0),
  62614. (val_sub, ":gold_cost", ":treasure"),
  62615. (assign, ":treasure", 0),
  62616. (try_end),
  62617. (party_set_slot, ":center_no", slot_center_accumulated_rents, ":treasure"),
  62618.  
  62619. (ge, ":gold_cost", 1),
  62620. (party_get_slot, ":treasure", ":center_no", slot_center_accumulated_tariffs),
  62621. (try_begin),
  62622. (gt, ":treasure", 0),
  62623. (ge, ":treasure", ":gold_cost"),
  62624. (val_sub, ":treasure", ":gold_cost"),
  62625. (assign, ":gold_cost", 0),
  62626. (else_try),
  62627. (gt, ":treasure", 0),
  62628. (val_sub, ":gold_cost", ":treasure"),
  62629. (assign, ":treasure", 0),
  62630. (try_end),
  62631. (party_set_slot, ":center_no", slot_center_accumulated_tariffs, ":treasure"),
  62632. (try_end),
  62633. #Fall through to the next section if the uncollected taxes didn't cover it.
  62634. (lt, ":gold_cost", 1),
  62635. (else_try),
  62636. #Remove remaining gold from center wealth. We iterate backwards to remove from
  62637. #castles before towns.
  62638. (ge, ":gold_cost", 1),
  62639. (try_for_range_backwards, ":center_no", centers_begin, centers_end),
  62640. (ge, ":gold_cost", 1),
  62641. (party_slot_eq, ":center_no", slot_town_lord, ":lord_no"),
  62642. (party_get_slot, ":treasure", ":center_no", slot_town_wealth),
  62643. (ge, ":treasure", 1),
  62644. (try_begin),
  62645. (ge, ":treasure", ":gold_cost"),
  62646. (val_sub, ":treasure", ":gold_cost"),
  62647. (assign, ":gold_cost", 0),
  62648. (else_try),
  62649. (val_sub, ":gold_cost", ":treasure"),
  62650. (assign, ":treasure", 0),
  62651. (try_end),
  62652. (party_set_slot, ":center_no", slot_town_wealth, ":treasure"),
  62653. (try_end),
  62654. (lt, ":gold_cost", 1),
  62655. (else_try),
  62656. #Try to remove the gold from the hero himself
  62657. (store_troop_gold, ":treasure", ":lord_no"),
  62658. (gt, ":treasure", 0),
  62659. (try_begin),
  62660. (ge, ":treasure", ":gold_cost"),
  62661. (troop_remove_gold, ":lord_no", ":gold_cost"),
  62662. (assign, ":gold_cost", 0),
  62663. (else_try),
  62664. (troop_remove_gold, ":treasure"),
  62665. (val_sub, ":gold_cost", ":treasure"),
  62666. (try_end),
  62667. (try_end),
  62668.  
  62669. ]),
  62670.  
  62671. # "script_dplmc_prepare_hero_center_points_ignoring_center"
  62672. #
  62673. # Input: arg1 = target_center
  62674. ("dplmc_prepare_hero_center_points_ignoring_center",[
  62675. (store_script_param, ":target_center", 1),
  62676.  
  62677. (troop_set_slot, "trp_player", slot_troop_temp_slot, 0),
  62678. (troop_set_slot, "trp_player", dplmc_slot_troop_temp_slot, 0),
  62679.  
  62680. (try_for_range, ":troop_no", heroes_begin, heroes_end),
  62681. (troop_set_slot, ":troop_no", slot_troop_temp_slot, 0),
  62682. (troop_set_slot, ":troop_no", dplmc_slot_troop_temp_slot, 0),
  62683. (try_end),
  62684.  
  62685. (try_for_range, ":center_no", centers_begin, centers_end),
  62686. #Skip "target center"
  62687. (neq, ":center_no", ":target_center"),
  62688.  
  62689. #Lord is player or a hero
  62690. (party_get_slot, ":troop_no", ":center_no", slot_town_lord),
  62691. (this_or_next|eq, ":troop_no", "trp_player"),
  62692. (is_between, ":troop_no", heroes_begin, heroes_end),
  62693.  
  62694. #Update lord point total
  62695. (assign, ":center_points", 1),
  62696. (try_begin),
  62697. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  62698. (assign, ":center_points", 3),
  62699. (else_try),
  62700. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  62701. (assign, ":center_points", 2),
  62702. (try_end),
  62703.  
  62704. (troop_get_slot, ":slot_value", ":troop_no", slot_troop_temp_slot),
  62705. (val_add, ":slot_value", ":center_points"),
  62706. (troop_set_slot, ":troop_no", slot_troop_temp_slot, ":slot_value"),
  62707.  
  62708. #Update distance from closest owned center to target
  62709. (is_between, ":target_center", centers_begin, centers_end),
  62710. (troop_get_slot, ":slot_value", ":troop_no", dplmc_slot_troop_temp_slot),
  62711. (store_distance_to_party_from_party, ":cur_distance", ":target_center", ":center_no"),
  62712. (val_max, ":cur_distance", 1),
  62713. (try_begin),
  62714. (eq, ":slot_value", 0),
  62715. (assign, ":slot_value", ":cur_distance"),
  62716. (try_end),
  62717. (val_min, ":slot_value", ":cur_distance"),
  62718. (troop_set_slot, ":troop_no", dplmc_slot_troop_temp_slot, ":slot_value"),
  62719. (try_end),
  62720. ##Update cached totals
  62721. (try_for_range, ":troop_no", heroes_begin, heroes_end),
  62722. (troop_get_slot, reg0, ":troop_no", slot_troop_temp_slot),
  62723. (val_add, reg0, 1),
  62724. (troop_set_slot, ":troop_no", dplmc_slot_troop_center_points_plus_one, reg0),
  62725. (try_end),
  62726. (troop_get_slot, reg0, "trp_player", slot_troop_temp_slot),
  62727. (val_add, reg0, 1),
  62728. (troop_set_slot, "trp_player", dplmc_slot_troop_center_points_plus_one, reg0),
  62729. #Since the target center was omitted from the point totals, handle it here
  62730. (try_begin),
  62731. (is_between, ":target_center", centers_begin, centers_end),
  62732. (party_get_slot, ":troop_no", ":target_center", slot_town_lord),
  62733. #Only perform this update for a troop whose center point value was updated above
  62734. (this_or_next|is_between, ":troop_no", heroes_begin, heroes_end),
  62735. (eq, ":troop_no", "trp_player"),
  62736. (troop_get_slot, reg0, ":troop_no", dplmc_slot_troop_center_points_plus_one),
  62737. (val_add, reg0, 1),#1 point for villages
  62738. (try_begin),
  62739. (is_between, ":target_center", walled_centers_begin, walled_centers_end),
  62740. (val_add, reg0, 1),#2 points for castles
  62741. (is_between, ":target_center", towns_begin, towns_end),
  62742. (val_add, reg0, 1),#3 points for towns
  62743. (try_end),
  62744. (troop_set_slot, ":troop_no", dplmc_slot_troop_center_points_plus_one, reg0),
  62745. (try_end),
  62746. ]),
  62747.  
  62748.  
  62749. # script_dplmc_calculate_troop_score_for_center_aux
  62750. # Similar to script_calculate_troop_score_for_center
  62751. #
  62752. # slot_troop_temp_slot must already be loaded with center points;
  62753. # dplmc_slot_troop_temp_slot must already be loaded with distance.
  62754. #
  62755. # Input: arg1 = evaluator
  62756. # arg2 = troop_no
  62757. # arg3 = center_no
  62758. # Output: reg0 = score
  62759. # reg1 = explanation string
  62760. ("dplmc_calculate_troop_score_for_center_aux",
  62761. [(store_script_param, ":troop_1", 1),
  62762. (store_script_param, ":troop_2", 2),
  62763. (store_script_param, ":center_no", 3),
  62764.  
  62765. (assign, ":explanation", "str_political_explanation_most_deserving_in_faction"),
  62766. (assign, ":explanation_priority", -1),
  62767.  
  62768. (try_begin),
  62769. (lt, ":troop_1", 0),
  62770. (assign, ":relation", 0),
  62771. (assign, ":reputation", lrep_none),
  62772. (else_try),
  62773. (eq, ":troop_1", ":troop_2"),
  62774. (assign, ":relation", 50),
  62775. (troop_get_slot, ":reputation", ":troop_1", slot_lord_reputation_type),
  62776. (else_try),
  62777. (call_script, "script_troop_get_relation_with_troop", ":troop_1", ":troop_2"),
  62778. (assign, ":relation", reg0),
  62779. (troop_get_slot, ":reputation", ":troop_1", slot_lord_reputation_type),
  62780. (try_end),
  62781. (val_clamp, ":relation", -100, 101),
  62782.  
  62783. (troop_get_slot, reg0, ":troop_2", slot_troop_renown),
  62784. (val_max, reg0, 0),
  62785. (store_add, ":score", 500, reg0),
  62786. (troop_get_slot, ":num_center_points", ":troop_2", slot_troop_temp_slot),
  62787. (val_max, ":num_center_points", 0),
  62788. (val_add, ":num_center_points", 1),
  62789.  
  62790. #Subtract distance from closest other fief owned, except when
  62791. #considering the lord's original holdings.
  62792. (try_begin),
  62793. (troop_slot_ge, ":troop_2", slot_troop_temp_slot, 1),
  62794. (neg|troop_slot_eq, ":troop_2", slot_troop_home, ":center_no"),
  62795. (neg|party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":troop_2"),
  62796.  
  62797. (troop_get_slot, reg0, ":troop_2", dplmc_slot_troop_temp_slot),
  62798. (gt, reg0, 1),
  62799. (val_min, reg0, 250),#upper cap on distance effect (bear in mind that this is subtracted from 500 + troop renown)
  62800. (val_sub, ":score", reg0),
  62801. (try_end),
  62802.  
  62803. #(store_random_in_range, ":random", 50, 100),
  62804. #(val_mul, ":score", ":random"),
  62805. (val_mul, ":score", 75),
  62806. (val_div, ":score", ":num_center_points"),
  62807.  
  62808. (assign, ":fiefless_bonus_used", 0),
  62809. (try_begin),
  62810. #Bonus for lords with no other fiefs when a village is being considered.
  62811. (lt, ":num_center_points", 2),
  62812. (party_slot_eq, ":center_no", slot_party_type, spt_village),
  62813. (neq, ":reputation", lrep_debauched),
  62814. (neq, ":reputation", lrep_selfrighteous),
  62815. (neq, ":reputation", lrep_quarrelsome),
  62816. (val_mul, ":score", 2),
  62817. (try_begin),
  62818. (lt, ":explanation_priority", 100),
  62819. (assign, ":explanation_priority", 100),
  62820. (assign, ":explanation", "str_political_explanation_lord_lacks_center"),
  62821. (try_end),
  62822. (assign, ":fiefless_bonus_used", 1),#because it has already been applied
  62823. (try_end),
  62824.  
  62825. (assign, ":troop_2_slot_alias", ":troop_2"),
  62826. (try_begin),
  62827. (eq, ":troop_2", "trp_player"),
  62828. (assign, ":troop_2_slot_alias", "trp_kingdom_heroes_including_player_begin"),
  62829. (try_end),
  62830.  
  62831. (try_begin),
  62832. #Bonus for conquerer
  62833. (neq, ":reputation", lrep_debauched),
  62834. (this_or_next|neq, ":reputation", lrep_selfrighteous),
  62835. (eq, ":troop_1", ":troop_2"),
  62836. (neq, ":reputation", lrep_cunning),
  62837. (neg|party_slot_eq, ":center_no", slot_party_type, spt_village),
  62838. (party_slot_eq, ":center_no", slot_center_last_taken_by_troop, ":troop_2_slot_alias"),
  62839. (try_begin),
  62840. (lt, ":num_center_points", 2),
  62841. (eq, ":fiefless_bonus_used", 0),
  62842. (assign, reg1, 50),#50% increase
  62843. (else_try),
  62844. (this_or_next|troop_slot_eq, ":troop_2", slot_troop_home, ":center_no"),
  62845. (this_or_next|party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":troop_2_slot_alias"),
  62846. (this_or_next|party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, ":troop_2_slot_alias"),
  62847. (eq, ":reputation", lrep_martial),
  62848. (assign, reg1, 50),#50% increase
  62849. (else_try),
  62850. (assign, reg1, 25),#25% increase
  62851. (try_end),
  62852. (store_add, reg0, 100, reg1),
  62853. (val_mul, ":score", reg0),
  62854. (val_div, ":score", 100),
  62855. (try_begin),
  62856. (ge, reg1, ":explanation_priority"),
  62857. (assign, ":explanation_priority", reg1),
  62858. (assign, ":explanation", "str_political_explanation_lord_took_center"),
  62859. (try_end),
  62860. (else_try),
  62861. #Bonus for original owner
  62862. (gt, ":troop_2", 0),
  62863. (party_slot_eq, ":center_no", dplmc_slot_center_original_lord, ":troop_2_slot_alias"),
  62864. (try_begin),
  62865. (lt, ":num_center_points", 2),
  62866. (eq, ":fiefless_bonus_used", 0),
  62867. (assign, reg1, 50),#50% increase
  62868. (else_try),
  62869. (this_or_next|eq, ":troop_2", ":troop_1"),
  62870. (this_or_next|troop_slot_eq, ":troop_2", slot_troop_home, ":center_no"),
  62871. (party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, ":troop_2_slot_alias"),
  62872. (assign, reg1, 50),#50% increase
  62873. (else_try),
  62874. (assign, reg1, 25),#25% increase
  62875. (try_end),
  62876. (store_add, reg0, 100, reg1),
  62877. (val_mul, ":score", reg0),
  62878. (val_div, ":score", 100),
  62879. (try_begin),
  62880. (ge, reg1, ":explanation_priority"),
  62881. (assign, ":explanation_priority", reg1),
  62882. (assign, ":explanation", "str_dplmc_political_explanation_original_lord"),
  62883. (try_end),
  62884. (else_try),
  62885. #Bonus for previous owner, lord
  62886. (gt, ":troop_2", 0),
  62887. (party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, ":troop_2_slot_alias"),
  62888. (try_begin),
  62889. (lt, ":num_center_points", 2),
  62890. (eq, ":fiefless_bonus_used", 0),
  62891. (assign, reg1, 50),#50% increase
  62892. (else_try),
  62893. (troop_slot_eq, ":troop_2", slot_troop_home, ":center_no"),
  62894. (assign, reg1, 50),
  62895. (else_try),
  62896. (assign, reg1, 25),#25% increase
  62897. (try_end),
  62898. (store_add, reg0, 100, reg1),
  62899. (val_mul, ":score", reg0),
  62900. (val_div, ":score", 100),
  62901. (try_begin),
  62902. (ge, reg1, ":explanation_priority"),
  62903. (assign, ":explanation_priority", reg1),
  62904. (assign, ":explanation", "str_dplmc_political_explanation_original_lord"),
  62905. (try_end),
  62906. (else_try),
  62907. #Bonus for lord claiming the center as home
  62908. (troop_slot_eq, ":troop_2", slot_troop_home, ":center_no"),
  62909. (val_mul, ":score", 5),
  62910. (val_div, ":score", 4),
  62911. (try_begin),
  62912. (ge, 25, ":explanation_priority"),
  62913. (assign, ":explanation_priority", 25),
  62914. (assign, ":explanation", "str_dplmc_political_explanation_original_lord"),
  62915. (try_end),
  62916. (else_try),
  62917. #Aesthetic penalty (doesn't apply when there was a bonus)
  62918. #To try to make the late game less mixed, have a preference towards
  62919. #assigning lords to their own faction types.
  62920. (troop_get_slot, reg0, ":troop_2", slot_troop_original_faction),
  62921. (party_get_slot, reg1, ":center_no", slot_center_original_faction),
  62922. (neq, reg0, reg1),
  62923. #These extra checks are to avoid penalizing the player or promoted companions
  62924. #unintentionally.
  62925. (is_between, reg0, npc_kingdoms_begin, npc_kingdoms_end),
  62926. (is_between, reg1, npc_kingdoms_begin, npc_kingdoms_end),
  62927. #Take 95% of score
  62928. (val_mul, ":score", 19),
  62929. (val_add, ":score", 10),
  62930. (val_div, ":score", 20),
  62931. (try_end),
  62932.  
  62933. #add 2 x relation (minus controversy) to score
  62934. (troop_get_slot, ":controversy", ":troop_2", slot_troop_controversy),
  62935. (val_clamp, ":controversy", 0, 101),
  62936. (store_mul, ":relation_mod", ":relation", 2),
  62937. (val_sub, ":relation_mod", ":controversy"),
  62938. #this modifier will not raise the score by more than 50%
  62939. (store_add, reg0, ":score", 1),
  62940. (val_div, reg0, 2),
  62941. (val_max, reg0, 1),
  62942. (val_min, ":relation_mod", reg0),
  62943.  
  62944. (store_mul, reg0, ":score", 100),#rego has pre-relationship modified score
  62945. (val_add, ":score", ":relation_mod"),
  62946. (val_div, reg0, ":score"),
  62947. (store_sub, reg1, ":score", 100),#reg1 has percentage change (i.e. 1.5 times becomes 50% change) from relation/controversy
  62948.  
  62949. (try_begin),
  62950. (ge, reg1, 0),
  62951. (ge, reg1, ":explanation_priority"),
  62952. (ge, ":relation", 15),
  62953. (assign, ":explanation_priority", reg1),
  62954. (assign, ":explanation", "str_political_explanation_most_deserving_friend"),
  62955. (try_end),
  62956.  
  62957. (assign, reg0, ":score"),
  62958. (assign, reg1, ":explanation"),
  62959. ]),
  62960.  
  62961.  
  62962. #Adapted "auto-sell" from rubik's Custom Commander
  62963. #auto sell credit rubik (CC) begin:
  62964. #
  62965. # script_dplmc_auto_sell
  62966. # INPUTS:
  62967. # arg1 :customer (the one selling the stuff)
  62968. # arg2 :merchant (the one buying the stuff)
  62969. # arg3 :auto_sell_price_limit (only sell stuff less expensive than this)
  62970. # arg4 :valid_items_begin (use this to only sell a limited range of things)
  62971. # arg5 :valid_items_end (use this to only sell a limited range of things)
  62972. # arg6 :actually_sell_items (set to 0 for a "dry run"; set to 2 to print a descriptive message)
  62973. #
  62974. # OUTPUTS:
  62975. # reg0 amount of gold gained by customer (not actually gained if this was a dry run)
  62976. # reg1 number of items sold by customer (not actually sold if this was a dry run)
  62977. ("dplmc_auto_sell", [
  62978. #This script has various changes from the CC version.
  62979. #In particular, all parameters other than "customer" and "merchant",
  62980. #and reporting the number of items & gold change.
  62981. (store_script_param, ":customer", 1),
  62982. (store_script_param, ":merchant", 2),
  62983. #dplmc+ start added parameters
  62984. (store_script_param, ":auto_sell_price_limit", 3),
  62985. (store_script_param, ":valid_items_begin", 4),
  62986. (store_script_param, ":valid_items_end", 5),
  62987. (store_script_param, ":actually_sell_items", 6),
  62988. #dplmc+ end added parameters
  62989.  
  62990. #dplmc+ added section begin
  62991. (assign, ":save_reg2", reg2),
  62992. (assign, ":save_reg3", reg3),
  62993. (assign, ":save_reg65", reg65),
  62994. (assign, ":save_talk_troop", "$g_talk_troop"),
  62995. #The talk troop is used for price information, but it's possible for this to be called
  62996. #from other contexts (like a menu).
  62997. (assign, "$g_talk_troop", ":merchant"),
  62998.  
  62999. (assign, ":gold_gained", 0),
  63000. (assign, ":items_sold", 0),
  63001. #(assign, ":most_expensive_sold_item", -1),
  63002. #(assign, ":most_expensive_sold_imod", -1),
  63003. #(assign, ":most_expensive_sold_price", -1),
  63004. #dplmc+ added section end
  63005.  
  63006. (store_free_inventory_capacity, ":space", ":merchant"),
  63007. (troop_get_inventory_capacity, ":inv_cap", ":customer"),
  63008. (set_show_messages, 0),#<-dplmc+ added
  63009. (store_troop_gold, ":m_gold", ":merchant"),#dplmc+: to support "dry runs", move this out of the loop
  63010. (try_for_range_backwards, ":i_slot", dplmc_ek_alt_items_end, ":inv_cap"),#we're reserving several "safe" slots in the beginning of the inventory
  63011. (troop_get_inventory_slot, ":item", ":customer", ":i_slot"),
  63012. (troop_get_inventory_slot_modifier, ":imod", ":customer", ":i_slot"),
  63013. (gt, ":item", -1),
  63014. (item_get_type, ":type", ":item"),
  63015. (item_slot_eq, ":type", dplmc_slot_item_type_not_for_sell, 0),
  63016. #dplmc+ begin added constraints
  63017. (is_between, ":item", ":valid_items_begin", ":valid_items_end"),
  63018. (neg|is_between, ":type", books_begin, books_end),
  63019. (this_or_next|neg|is_between, ":type", food_begin, food_end),
  63020. (eq, ":imod", imod_rotten),
  63021. (neg|is_between, ":type", trade_goods_begin, trade_goods_end),
  63022. (neq, ":imod", imod_lordly),#dplmc+: never sell "lordly" items
  63023. #dplmc+ end added constraints
  63024.  
  63025. (call_script, "script_dplmc_get_item_value_with_imod", ":item", ":imod"),
  63026. (assign, ":score", reg0),
  63027. (val_div, ":score", 100),
  63028. (call_script, "script_game_get_item_sell_price_factor", ":item"),
  63029. (assign, ":sell_price_factor", reg0),
  63030. (val_mul, ":score", ":sell_price_factor"),
  63031. (val_div, ":score", 100),
  63032. (val_max, ":score",1),
  63033.  
  63034. #dplmc+ start changed section
  63035. (le, ":score", ":auto_sell_price_limit"),
  63036. (le, ":score", ":m_gold"),
  63037. (gt, ":space", 0),
  63038.  
  63039. #For equipment, in general don't sell the item unless you have a better one,
  63040. #or the item is useless to you. (The idea is to stop from accidentally
  63041. #selling the player's own equipment.)
  63042. (item_get_type, ":this_item_type", ":item"),
  63043.  
  63044. #Normally, we would do the following:
  63045.  
  63046. #(try_begin),
  63047. # (item_slot_eq, ":item", dplmc_slot_two_handed_one_handed, 1),
  63048. # (assign, ":this_item_type", 11), # type 11 = two-handed/one-handed
  63049. #(try_end),
  63050.  
  63051. #However, we are delaying that step until later, because type 11 is the
  63052. #same as itp_type_goods.
  63053.  
  63054.  
  63055. #Don't sell items if there's a reasonable chance that they might
  63056. #be the player's alternate personal equipment. It goes without saying
  63057. #that items the player can't use aren't counted.
  63058. #
  63059. #(Items the player has equipped will not even be considered for sale,
  63060. #but it is common for players to have a variety of items they use in
  63061. #different circumstances, which might not all be equipped.)
  63062. #
  63063. #For melee weapons: don't sell the best weapon or the second-best of a type
  63064. # (it might be a backup, or there might be a variety of weapons of
  63065. # the same type in situational use)
  63066. #For shields: don't sell the best or second-best shield
  63067. #For thrown weapons: don't sell the best three thrown weapons
  63068. #For ammunition: don't sell the best three of the ammunition kind (arrows,
  63069. # bolts) unless you lack a weapon that uses the ammunition.
  63070. #For armor: don't sell the best armor of a kind.
  63071. #For horses: don't sell the best or second-best horse
  63072. #For bows and crossbows: don't sell the best item of a kind (all bows are
  63073. # very similar, so there's little chance someone would carry an alternate)
  63074. #For muskets and pistols: don't sell the best or second-best weapon of
  63075. # a kind.
  63076.  
  63077. (assign, ":can_sell", 1),
  63078.  
  63079. (try_begin),
  63080. #Ammunition type: arrows (if you have a bow you can use, don't sell the best 3 arrow packs you have)
  63081. (eq, ":this_item_type", itp_type_arrows),
  63082. (call_script, "script_dplmc_scan_for_best_item_of_type", ":customer", itp_type_bow, ":customer"),
  63083. (try_begin),
  63084. (ge, reg0, 0),
  63085. (call_script, "script_dplmc_count_better_items_of_same_type", ":customer", ":item", ":imod", ":customer"),
  63086. (lt, reg0, 3),#must not be best (0), second-best (1), or third-best (2)
  63087. (assign, ":can_sell", 0),
  63088. (try_end),
  63089. (else_try),
  63090. #Ammunition type: bolts (if you have a crossbow you can use, don't sell the best 3 bolt packs you have)
  63091. (eq, ":this_item_type", itp_type_bolts),
  63092. (call_script, "script_dplmc_scan_for_best_item_of_type", ":customer", itp_type_crossbow, ":customer"),
  63093. (try_begin),
  63094. (ge, reg0, 0),
  63095. (call_script, "script_dplmc_count_better_items_of_same_type", ":customer", ":item", ":imod", ":customer"),
  63096. (lt, reg0, 3),#must not be best (0), second-best (1), or third-best (2)
  63097. (assign, ":can_sell", 0),
  63098. (try_end),
  63099. (else_try),
  63100. #Ammunition type: bullets (if you have a pistol or musket you can use, don't sell the best 3 bullet packs you have)
  63101. (eq, ":this_item_type", itp_type_bullets),
  63102. #Do muskets and pistols both use bullets? I'll assume so.
  63103. (call_script, "script_dplmc_scan_for_best_item_of_type", ":customer", itp_type_musket, ":customer"),
  63104. (assign, reg1, reg0),
  63105. (call_script, "script_dplmc_scan_for_best_item_of_type", ":customer", itp_type_pistol, ":customer"),
  63106. (try_begin),
  63107. (this_or_next|ge, reg0, 0),
  63108. (ge, reg1, 0),
  63109. (call_script, "script_dplmc_count_better_items_of_same_type", ":customer", ":item", ":imod", ":customer"),
  63110. (lt, reg0, 3),
  63111. (assign, ":can_sell", 0),
  63112. (try_end),
  63113. (else_try),
  63114. #Catch: all non-usable equipment
  63115. (is_between, ":this_item_type", itp_type_horse, itp_type_musket + 1),
  63116. (neq, ":this_item_type", itp_type_goods),
  63117. (call_script, "script_dplmc_troop_can_use_item", ":customer", ":item", ":imod"),
  63118. (eq, reg0, 0),#Past here, we don't have to check for usability
  63119. (else_try),
  63120. #Thrown weapons: don't sell best 3 you can use
  63121. (eq, ":this_item_type", itp_type_thrown),
  63122. (call_script, "script_dplmc_count_better_items_of_same_type", ":customer", ":item", ":imod", ":customer"),
  63123. (store_sub, ":can_sell", reg0, 2),#must not be best (0) or second-best (1) or third-best (2)
  63124. (else_try),
  63125. #Types where both the best and the second-best aren't sold
  63126. #Horses, shields, melee weapons, and firearms
  63127. (this_or_next|is_between, ":this_item_type", itp_type_horse, itp_type_polearm + 1),
  63128. (this_or_next|eq, ":this_item_type", itp_type_shield),
  63129. (this_or_next|eq, ":this_item_type", itp_type_pistol),
  63130. (eq, ":this_item_type", itp_type_musket),
  63131. (call_script, "script_dplmc_count_better_items_of_same_type", ":customer", ":item", ":imod", ":customer"),
  63132. (store_sub, ":can_sell", reg0, 1),#must not be best (0) or second best (1)
  63133. (else_try),
  63134. #Types where the best isn't sold (armor, not including shields)
  63135. (is_between, ":this_item_type", itp_type_head_armor, itp_type_hand_armor + 1),
  63136. (call_script, "script_dplmc_count_better_items_of_same_type", ":customer", ":item", ":imod", ":customer"),
  63137. (assign, ":can_sell", reg0),#must not be best (0)
  63138. (try_end),
  63139.  
  63140. #(try_begin),
  63141. # (lt, ":can_sell", 1),
  63142. # (gt, "$cheat_mode", 0),
  63143. # (call_script, "script_dplmc_count_better_items_of_same_type", ":customer", ":item", ":imod", ":customer"),
  63144. # (assign, reg1, ":i_slot"),
  63145. # (str_store_item_name, s0, ":item"),
  63146. # (display_message, "@{!} DEBUG - Will not sell item {s0} at slot {reg1}. Better items of same kind: {reg0}"),
  63147. #(try_end),
  63148.  
  63149. (ge, ":can_sell", 1),
  63150.  
  63151. #(try_begin),
  63152. # (ge, ":score", ":most_expensive_sold_price"),
  63153. # (assign, ":most_expensive_sold_item", ":item"),
  63154. # (assign, ":most_expensive_sold_imod", ":imod"),
  63155. # (assign, ":most_expensive_sold_price", ":score"),
  63156. #(try_end),
  63157.  
  63158. #Log the transaction even if in dry run mode
  63159. (val_sub, ":m_gold", ":score"),
  63160. (val_add, ":gold_gained", ":score"),
  63161. (val_add, ":items_sold", 1),
  63162. (val_sub, ":space", 1),
  63163.  
  63164. #If not a dry run, apply the transaction
  63165. (neq, ":actually_sell_items", 0),
  63166. (troop_add_item, ":merchant", ":item", ":imod"),
  63167. (troop_set_inventory_slot, ":customer", ":i_slot", -1),
  63168. (troop_remove_gold, ":merchant", ":score"),
  63169. (troop_add_gold, ":customer", ":score"),
  63170. #dplmc+ end changed section
  63171. (try_end),
  63172.  
  63173. (set_show_messages, 1),#<- dplmc+ added
  63174.  
  63175. #dplmc+ added section begin
  63176. #Print a message if appropriate
  63177. (try_begin),
  63178. (is_between, ":actually_sell_items", 2, 4),#2 or 3
  63179. (this_or_next|ge, ":items_sold", 1),
  63180. (eq, ":actually_sell_items", 3),
  63181. (assign, reg0, ":gold_gained"),
  63182. (assign, reg1, ":items_sold"),
  63183. (store_sub, reg3, reg1, 1),
  63184. (str_store_troop_name, s0, ":merchant"),
  63185. (try_begin),
  63186. (this_or_next|is_between, ":merchant", quick_battle_troops_begin, quick_battle_troops_end),
  63187. (this_or_next|is_between, ":merchant", heroes_begin, heroes_end),
  63188. (this_or_next|is_between, ":merchant", dplmc_employees_begin, dplmc_employees_end),
  63189. (is_between, ":merchant", walkers_end, tournament_champions_end),
  63190. (display_message, "@You sold {reg1} {reg3?items:item} to {s0} and gained {reg0} {reg3?denars:denar}."),
  63191. (else_try),
  63192. (display_message, "@You sold {reg1} {reg3?items:item} to the {s0} and gained {reg0} {reg3?denars:denar}."),
  63193. (try_end),
  63194. (try_end),
  63195.  
  63196. #Revert variables
  63197. (assign, reg2, ":save_reg2"),
  63198. (assign, reg3, ":save_reg3"),
  63199. (assign, reg65, ":save_reg65"),
  63200. (assign, "$g_talk_troop", ":save_talk_troop"),
  63201.  
  63202. #Return diagnostics
  63203. (assign, reg0, ":gold_gained"),
  63204. (assign, reg1, ":items_sold"),
  63205. #dplmc+ added section end
  63206. ]),
  63207. #auto sell credit rubik (CC) end
  63208.  
  63209. ##For use with autosell
  63210. #Input: center_no
  63211. #Output: none
  63212. ("dplmc_player_auto_sell_at_center", [
  63213. (store_script_param, ":center_no", 1),
  63214. (assign, ":save_reg0", reg0),
  63215. (assign, ":save_reg1", reg1),
  63216. (try_begin),
  63217. ##For Towns:
  63218. (is_between, ":center_no", towns_begin, towns_end),
  63219. (try_begin),
  63220. #1. Selling weapons, shields, and ranged weapons to the weaponsmith
  63221. (party_get_slot, ":merchant_troop", ":center_no", slot_town_weaponsmith),
  63222. (ge, ":merchant_troop", 1),
  63223. (call_script, "script_dplmc_auto_sell", "trp_player", ":merchant_troop", "$g_dplmc_auto_sell_price_limit", weapons_begin, ranged_weapons_end, 2),
  63224. (try_end),
  63225. (try_begin),
  63226. #2. Selling armor to the armorer
  63227. (party_get_slot, ":merchant_troop", ":center_no", slot_town_armorer),
  63228. (ge, ":merchant_troop", 1),
  63229. (call_script, "script_dplmc_auto_sell", "trp_player", ":merchant_troop", "$g_dplmc_auto_sell_price_limit", armors_begin, armors_end, 2),
  63230. (try_end),
  63231. (try_begin),
  63232. #3. Selling horses to the horse merchant
  63233. (party_get_slot, ":merchant_troop", ":center_no", slot_town_horse_merchant),
  63234. (ge, ":merchant_troop", 1),
  63235. (call_script, "script_dplmc_auto_sell", "trp_player", ":merchant_troop", "$g_dplmc_auto_sell_price_limit", horses_begin, horses_end, 2),
  63236. (try_end),
  63237. (try_begin),
  63238. #4. Selling whatever may remain to the general merchant
  63239. (party_get_slot, ":merchant_troop", ":center_no", slot_town_merchant),
  63240. (ge, ":merchant_troop", 1),
  63241. (call_script, "script_dplmc_auto_sell", "trp_player", ":merchant_troop", "$g_dplmc_auto_sell_price_limit", all_items_begin, all_items_end, 2),
  63242. (try_end),
  63243. (else_try),
  63244. ##For Villages:
  63245. (is_between, ":center_no", villages_begin, villages_end),
  63246. (party_get_slot, ":merchant_troop", ":center_no", slot_town_elder),
  63247. (ge, ":merchant_troop", 1),
  63248. (call_script, "script_dplmc_auto_sell", "trp_player", ":merchant_troop", "$g_dplmc_auto_sell_price_limit", all_items_begin, all_items_end, 2),
  63249. (else_try),
  63250. ##Error
  63251. (assign, reg0, ":center_no"),
  63252. (display_message, "@{!} ERROR FOR AUTOSELL for town ID {reg0}: Bad town or merchant was missing"),
  63253. (try_end),
  63254. (assign, reg0, ":save_reg0"),
  63255. (assign, reg1, ":save_reg1"),
  63256. ]),
  63257.  
  63258. ##Adapted Auto-Buy-Food from rubik's Custom Commander
  63259. #Changed to parameterize merchant and customer, but did not finish expanding
  63260. #the script to work with non-player arguments. (There is currently no need,
  63261. #but I can imagine using it for NPCs sent on item-purchasing missions, or if
  63262. #NPC parties had to buy food.)
  63263. #
  63264. ##OLD: Overwrites: reg1, reg2, reg3, reg4
  63265. ##NEW: Overwrite reg0
  63266. #
  63267. #INPUT:
  63268. # arg1 :customer
  63269. # arg2 :merchant_troop
  63270. ("dplmc_auto_buy_food", [
  63271. (store_script_param, ":customer", 1),
  63272. (store_script_param, ":merchant_troop", 2),
  63273. ##added section begin, preserve registers
  63274. (assign, ":save_reg1", reg1),
  63275. (assign, ":save_reg2", reg2),
  63276. (assign, ":save_reg3", reg3),
  63277. (assign, ":save_reg4", reg4),
  63278. ##added section end
  63279.  
  63280. (assign, ":customer_in_player_party", 0),#Always assumed true... re-write if you need to use for others
  63281.  
  63282. (store_troop_gold, ":begin_gold", ":customer"),
  63283. (store_free_inventory_capacity, ":begin_space", ":customer"),
  63284. (troop_get_inventory_capacity, ":inv_cap", ":merchant_troop"),
  63285. (set_show_messages, 0),
  63286. (try_for_range, ":i_slot", 10, ":inv_cap"),
  63287. (troop_get_inventory_slot, ":item", ":merchant_troop", ":i_slot"),
  63288. (gt, ":item", -1),
  63289. (is_between, ":item", food_begin, food_end),
  63290. (troop_inventory_slot_get_item_amount, ":amount", ":merchant_troop", ":i_slot"),
  63291. ##dplmc+: The next line required making a change to header_operations.py
  63292. (troop_inventory_slot_get_item_max_amount, ":max_amount", ":merchant_troop", ":i_slot"),
  63293. (eq, ":amount", ":max_amount"),
  63294.  
  63295. (item_get_slot, ":food_portion", ":item", dplmc_slot_item_food_portion),
  63296. (val_max, ":food_portion", 0),#dplmc+ added
  63297. (store_item_kind_count, ":food_count", ":item", ":customer"),
  63298. (lt, ":food_count", ":food_portion"),
  63299. (store_free_inventory_capacity, ":free_inv_cap", ":customer"),
  63300. (gt, ":free_inv_cap", 0),
  63301.  
  63302. (call_script, "script_game_get_item_buy_price_factor", ":item"),
  63303. (assign, ":buy_price_factor", reg0),
  63304. (store_item_value,":score",":item"),
  63305. (val_mul, ":score", ":buy_price_factor"),
  63306. (val_div, ":score", 100),
  63307. (val_max, ":score",1),
  63308. (store_troop_gold, ":customer_gold", ":customer"),
  63309. (ge, ":customer_gold", ":score"),
  63310.  
  63311. (troop_add_item, ":customer", ":item"),
  63312. (troop_set_inventory_slot, ":merchant_troop", ":i_slot", -1),
  63313. (troop_remove_gold, ":customer", ":score"),
  63314. (troop_add_gold, ":merchant_troop", ":score"),
  63315. (try_end),
  63316. (set_show_messages, 1),
  63317. (store_troop_gold, ":end_gold", ":customer"),
  63318. (store_free_inventory_capacity, ":end_space", ":customer"),
  63319. (try_begin),
  63320. (neq, ":end_gold", ":begin_gold"),
  63321. (store_sub, reg1, ":begin_gold", ":end_gold"),
  63322. (store_sub, reg2, ":begin_space", ":end_space"),
  63323. (store_sub, reg3, reg1, 1),
  63324. (store_sub, reg4, reg2, 1),
  63325. (eq, ":customer_in_player_party", 1),#<- added
  63326. (display_message, "@You have bought {reg2} {reg4?kinds:kind} of food and lost {reg1} {reg3?denars:denar}."),
  63327. (try_end),
  63328.  
  63329. # sell rotten food
  63330. (store_troop_gold, ":begin_gold", ":customer"),
  63331. (store_free_inventory_capacity, ":begin_space", ":customer"),
  63332. (troop_get_inventory_capacity, ":inv_cap", ":customer"),
  63333. (set_show_messages, 0),
  63334. (try_for_range, ":i_slot", 10, ":inv_cap"),
  63335. (troop_get_inventory_slot, ":item", ":customer", ":i_slot"),
  63336. (gt, ":item", -1),
  63337. (is_between, ":item", food_begin, food_end),
  63338. (troop_get_inventory_slot_modifier, ":imod", ":customer", ":i_slot"),
  63339. (eq, ":imod", imod_rotten),
  63340. (store_free_inventory_capacity, ":free_inv_cap", ":merchant_troop"),
  63341. (gt, ":free_inv_cap", 0),
  63342.  
  63343. (call_script, "script_dplmc_get_item_value_with_imod", ":item", ":imod"),
  63344. (assign, ":score", reg0),
  63345. (val_div, ":score", 100),
  63346. (call_script, "script_game_get_item_sell_price_factor", ":item"),
  63347. (assign, ":sell_price_factor", reg0),
  63348. (val_mul, ":score", ":sell_price_factor"),
  63349. (troop_inventory_slot_get_item_amount, ":amount", ":customer", ":i_slot"),
  63350. (troop_inventory_slot_get_item_max_amount, ":max_amount", ":customer", ":i_slot"),
  63351. (val_mul, ":score", ":amount"),
  63352. (val_div, ":score", ":max_amount"),
  63353. (val_div, ":score", 100),
  63354. (val_max, ":score",1),
  63355. (store_troop_gold, ":merchant_gold", ":merchant_troop"),
  63356. (ge, ":merchant_gold", ":score"),
  63357.  
  63358. #(troop_add_item, ":merchant_troop", ":item", ":imod"),
  63359. (troop_set_inventory_slot, ":customer", ":i_slot", -1),
  63360. (troop_remove_gold, ":merchant_troop", ":score"),
  63361. (troop_add_gold, ":customer", ":score"),
  63362. (try_end),
  63363. (set_show_messages, 1),
  63364. (store_troop_gold, ":end_gold", ":customer"),
  63365. (store_free_inventory_capacity, ":end_space", ":customer"),
  63366. (try_begin),
  63367. (neq, ":end_gold", ":begin_gold"),
  63368. (store_sub, reg1, ":end_gold", ":begin_gold"),
  63369. (store_sub, reg2, ":end_space", ":begin_space"),
  63370. (store_sub, reg3, reg1, 1),
  63371. (store_sub, reg4, reg2, 1),
  63372. (eq, ":customer_in_player_party", 1), #<- added
  63373. (display_message, "@You sold {reg2} {reg4?kinds:kind} of rotten food and gained {reg1} {reg3?denars:denar}."),
  63374. (try_end),
  63375. ##added section begin, preserve registers
  63376. (assign, reg1, ":save_reg1"),
  63377. (assign, reg2, ":save_reg2"),
  63378. (assign, reg3, ":save_reg3"),
  63379. (assign, reg4, ":save_reg4"),
  63380. ##added section end
  63381. ]),
  63382. ##Auto-Buy-Food from rubik's Custom Commander end
  63383.  
  63384. # script_dplmc_get_trade_penalty
  63385. #
  63386. #This is similar to the old script_get_trade_penalty,
  63387. #except it uses parameters instead of relying on global variables.
  63388. #
  63389. # Input:
  63390. # param1: item_kind_id
  63391. # param2: market center
  63392. # param3: customer troop (-1 for a non-troop-specific answer, -2 to notify the script that this is being used to evaluate a gift)
  63393. # param4: merchant troop (-1 for a non-troop-specific answer)
  63394. # Output: reg0
  63395.  
  63396. ("dplmc_get_trade_penalty",
  63397. [
  63398. #Additions begin:
  63399. (store_script_param, ":item_kind_id", 1),
  63400. (store_script_param, ":market_center", 2),
  63401. (store_script_param, ":customer_troop", 3),
  63402. (store_script_param, ":merchant_troop", 4),
  63403. #End Additions
  63404. (assign, ":penalty",0),
  63405.  
  63406. ##Change this to support alternative customers
  63407. ##(party_get_skill_level, ":trade_skill", "p_main_party", skl_trade),
  63408. (try_begin),
  63409. #Player: use skill of player party
  63410. (eq, ":customer_troop", "trp_player"),
  63411. (party_get_skill_level, ":trade_skill", "p_main_party", skl_trade),
  63412. (else_try),
  63413. #Hero leading a party: use skill of led party
  63414. (gt, ":customer_troop", -1),
  63415. (troop_is_hero, ":customer_troop"),
  63416. (troop_get_slot, ":customer_party", ":customer_troop", slot_troop_leaded_party),
  63417. (gt, ":customer_party", 0),
  63418. (party_is_active, ":customer_party"),
  63419. (party_get_skill_level, ":trade_skill", ":customer_party", skl_trade),
  63420. (else_try),
  63421. #Troop: use troop skill
  63422. (gt, ":customer_troop", -1),
  63423. (store_skill_level, ":trade_skill", ":customer_troop"),
  63424. (else_try),
  63425. (assign, ":trade_skill", 0),
  63426. (try_end),
  63427. ##End Change
  63428. (try_begin),
  63429. (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  63430. (assign, ":penalty",15), #reduced slightly
  63431. (store_mul, ":skill_bonus", ":trade_skill", 1),
  63432. (val_sub, ":penalty", ":skill_bonus"),
  63433. (else_try),
  63434. (assign, ":penalty",100),
  63435. (store_mul, ":skill_bonus", ":trade_skill", 5),
  63436. (val_sub, ":penalty", ":skill_bonus"),
  63437. (try_end),
  63438.  
  63439. (assign, ":penalty_multiplier", average_price_factor),#<-- replaced 1000 with average_price_factor
  63440. ## # Apply penalty if player is hostile to merchants faction
  63441. ## (store_relation, ":merchants_reln", "fac_merchants", "fac_player_supporters_faction"),
  63442. ## (try_begin),
  63443. ## (lt, ":merchants_reln", 0),
  63444. ## (store_sub, ":merchants_reln_dif", 10, ":merchants_reln"),
  63445. ## (store_mul, ":merchants_relation_penalty", ":merchants_reln_dif", 20),
  63446. ## (val_add, ":penalty_multiplier", ":merchants_relation_penalty"),
  63447. ## (try_end),
  63448.  
  63449. # Apply penalty if player is on bad terms with the town
  63450. (try_begin),
  63451. (eq, ":customer_troop", "trp_player"),#added
  63452. (is_between, ":market_center", centers_begin, centers_end),#changed $g_encountered_party to :market_center
  63453. (party_get_slot, ":center_relation", ":market_center", slot_center_player_relation),#changed $g_encountered_party to :market_center
  63454. (store_mul, ":center_relation_penalty", ":center_relation", -3),
  63455. (val_add, ":penalty_multiplier", ":center_relation_penalty"),
  63456. (try_begin),
  63457. (lt, ":center_relation", 0),
  63458. (store_sub, ":center_penalty_multiplier", 100, ":center_relation"),
  63459. (val_mul, ":penalty_multiplier", ":center_penalty_multiplier"),
  63460. (val_div, ":penalty_multiplier", 100),
  63461. (try_end),
  63462. (try_end),
  63463.  
  63464. # Apply penalty if player is on bad terms with the merchant (not currently used)
  63465. ##Begin Change
  63466. #(call_script, "script_troop_get_player_relation", "$g_talk_troop"),
  63467. #(assign, ":troop_reln", reg0),
  63468. (try_begin),
  63469. (this_or_next|eq, ":merchant_troop", "trp_player"),
  63470. (eq, ":customer_troop", "trp_player"),
  63471. (gt, ":merchant_troop", -1),
  63472. (gt, ":customer_troop", -1),
  63473. (call_script, "script_troop_get_player_relation", ":merchant_troop"),
  63474. (assign, ":troop_reln", reg0),
  63475. (else_try),
  63476. (is_between, ":merchant_troop", heroes_begin, heroes_end),
  63477. (is_between, ":customer_troop", heroes_begin, heroes_end),
  63478. (call_script, "script_troop_get_relation_with_troop", ":merchant_troop", ":customer_troop"),
  63479. (assign, ":troop_reln", reg0),
  63480. (else_try),
  63481. (assign, ":troop_reln", 0),
  63482. (try_end),
  63483. ##End Change
  63484. #(troop_get_slot, ":troop_reln", "$g_talk_troop", slot_troop_player_relation),
  63485. (try_begin),
  63486. (lt, ":troop_reln", 0),
  63487. (store_sub, ":troop_reln_dif", 0, ":troop_reln"),
  63488. (store_mul, ":troop_relation_penalty", ":troop_reln_dif", 20),
  63489. (val_add, ":penalty_multiplier", ":troop_relation_penalty"),
  63490. (try_end),
  63491.  
  63492.  
  63493. (try_begin),
  63494. ##Begin Change
  63495. #(is_between, "$g_encountered_party", villages_begin, villages_end),
  63496. (is_between, ":market_center", centers_begin, centers_end),
  63497. (party_slot_eq, ":market_center", slot_party_type, spt_village),
  63498. ##End Change
  63499. (val_mul, ":penalty", 2),
  63500. (try_end),
  63501.  
  63502. (try_begin),
  63503. (is_between, ":market_center", centers_begin, centers_end),#changed $g_encountered_party to :market_center
  63504. #Double trade penalty if no local production or consumption
  63505. (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
  63506. ##Begin Change
  63507. #(OPTIONAL CHANGE: Do not apply this to food)
  63508. (this_or_next|eq, ":customer_troop", -2),
  63509. (this_or_next|lt, "$g_dplmc_gold_changes", DPLMC_GOLD_CHANGES_LOW),
  63510. (neg|is_between, ":item_kind_id", food_begin, food_end),
  63511.  
  63512. (assign, ":save_reg1", reg1),
  63513. (assign, ":save_reg2", reg2),
  63514. ##End Change
  63515. (call_script, "script_center_get_production", ":market_center", ":item_kind_id"),#changed $g_encountered_party to :market_center
  63516. (eq, reg0, 0),
  63517. (call_script, "script_center_get_consumption", ":market_center", ":item_kind_id"),#changed $g_encountered_party to :market_center
  63518. (eq, reg0, 0),
  63519. (val_mul, ":penalty", 2),
  63520. ##Begin Change
  63521. (assign, reg1, ":save_reg1"),
  63522. (assign, reg2, ":save_reg2"),
  63523. ##End Change
  63524. (try_end),
  63525.  
  63526. (val_mul, ":penalty", ":penalty_multiplier"),
  63527. ##Begin Change
  63528. (val_add, ":penalty", average_price_factor // 2),#round in the correct direction (we don't need to worry about penalty < 0)
  63529. (val_div, ":penalty", average_price_factor),#replace the hardcoded constant 1000 with average_price_factor
  63530. ##End Change
  63531. (val_max, ":penalty", 1),
  63532. (assign, reg0, ":penalty"),
  63533. ]),
  63534.  
  63535.  
  63536. ##"script_dplmc_print_cultural_word_to_sreg"
  63537. ##INPUTS:
  63538. # arg1 - speaker troop
  63539. # arg2 - which word/phrase to retrieve (arbitrary code)
  63540. # arg3 - string register
  63541. #OUTPUTS:
  63542. # writes result to string register
  63543. ("dplmc_print_cultural_word_to_sreg", [
  63544. (store_script_param, ":speaker", 1),
  63545. (store_script_param, ":context", 2),
  63546. (store_script_param, ":string_register", 3),
  63547.  
  63548. #Right now this is entirely faction-based, but you could give different
  63549. #results for individual lords.
  63550. #(Note: Now certain parts of it do vary for heroes, to mimic the behavior in Native
  63551. #feast dialogs for the word for wine.)
  63552.  
  63553. (assign, ":speaker_faction", -1),
  63554. (try_begin),
  63555. #Player faction
  63556. (this_or_next|eq, ":speaker", "trp_player"),
  63557. (eq, ":speaker", "trp_kingdom_heroes_including_player_begin"),
  63558. (assign, ":speaker_faction", "fac_player_supporters_faction"),#<- This will potentially get translated later
  63559. (else_try),
  63560. #Hero original faction
  63561. (is_between, ":speaker", heroes_begin, heroes_end),
  63562. (troop_get_slot, ":speaker_faction", ":speaker", slot_troop_original_faction),
  63563. (else_try),
  63564. #Hero original faction
  63565. (gt, ":speaker", -1),
  63566. (troop_is_hero, ":speaker"),
  63567. (troop_slot_ge, ":speaker", slot_troop_original_faction, npc_kingdoms_begin),
  63568. (neg|troop_slot_ge, ":speaker", slot_troop_original_faction, npc_kingdoms_end),
  63569. (troop_get_slot, ":speaker_faction", ":speaker", slot_troop_original_faction),
  63570. (else_try),
  63571. #Troop current faction
  63572. (gt, ":speaker", -1),
  63573. (store_troop_faction, ":speaker_faction", ":speaker"),
  63574. (try_end),
  63575.  
  63576. (try_begin),
  63577. (lt, ":speaker", 1),
  63578. (else_try),
  63579. ##Only continue if the current faction isn't associated with a distinctive culture
  63580. (lt, ":speaker_faction", dplmc_non_generic_factions_begin),
  63581. ##This will work unless the order of the first factions gets changed
  63582. (else_try),
  63583. #Translate raiders into the equivalent kingdoms
  63584. (is_between, ":speaker", bandits_begin, bandits_end),
  63585. (try_begin),
  63586. (eq, ":speaker", "trp_mountain_bandit"),#Mountain bandits
  63587. (assign, ":speaker_faction", "fac_kingdom_5"),#Rhodoks
  63588. (else_try),
  63589. (eq, ":speaker", "trp_forest_bandit"),#Forest bandits
  63590. (assign, ":speaker_faction", "fac_kingdom_1"),#Swadian
  63591. (else_try),
  63592. (eq, ":speaker", "trp_sea_raider"),#Sea raiders
  63593. (assign, ":speaker_faction", "fac_kingdom_4"),#Nords
  63594. (else_try),
  63595. (eq, ":speaker", "trp_steppe_bandit"),#Steppe bandits
  63596. (assign, ":speaker_faction", "fac_kingdom_3"),#Khergits
  63597. (else_try),
  63598. (eq, ":speaker", "trp_taiga_bandit"),#Taiga bandits
  63599. (assign, ":speaker_faction", "fac_kingdom_2"),#Vaegir
  63600. (else_try),
  63601. (eq, ":speaker", "trp_desert_bandit"),#Desert bandits
  63602. (assign, ":speaker_faction", "fac_kingdom_6"),#Sarranid
  63603. (try_end),
  63604. (ge, ":speaker_faction", dplmc_non_generic_factions_begin),
  63605. (else_try),
  63606. #For companions without default initial cultures, infer one from their home.
  63607. #(Actually, don't limit this to companions, since there's a chance that others
  63608. #could have a valid home slot.)
  63609. #(is_between, ":speaker", companions_begin, companions_end),
  63610. #(is_between, ":speaker", heroes_begin, heroes_end),
  63611. (troop_is_hero, ":speaker"),
  63612. (troop_get_slot, ":home_center", ":speaker", slot_troop_home),
  63613. (is_between, ":home_center", centers_begin, centers_end),
  63614. (party_get_slot, ":speaker_faction", ":home_center", slot_center_original_faction),
  63615. (else_try),
  63616. #For villagers, merchants, etc.
  63617. (eq, ":speaker", "$g_talk_troop"),
  63618. (neg|is_between, ":speaker", heroes_begin, heroes_end),#Not a character that might have an explicitly-set faction
  63619. (neg|is_between, ":speaker", training_ground_trainers_begin, tavern_minstrels_end),#Not a trainer, ransom broker, traveler, bookseller, or minstrel
  63620. (ge, "$g_encountered_party", 0),
  63621. (try_begin),
  63622. #For towns / castles / villages, use the original faction
  63623. (is_between, "$g_encountered_party", centers_begin, centers_end),
  63624. (party_get_slot, ":speaker_faction", "$g_encountered_party", slot_center_original_faction),
  63625. (else_try),
  63626. #Use faction of encountered party
  63627. (party_is_active, "$g_encountered_party"),
  63628. (store_faction_of_party, ":speaker_faction", "$g_encountered_party"),
  63629. #For generic factions, use the closest center
  63630. (lt, ":speaker_faction", dplmc_non_generic_factions_begin),
  63631. (assign, ":speaker_faction", reg0),#save register
  63632. (call_script, "script_get_closest_center", "$g_encountered_party"),
  63633. (assign, ":home_center", reg0),
  63634. (assign, reg0, ":speaker_faction"),#revert register
  63635. (party_get_slot, ":speaker_faction", ":home_center", slot_center_original_faction),
  63636. (try_end),
  63637. (try_end),
  63638.  
  63639. #Translate for player's kingdom
  63640. (try_begin),
  63641. (ge, "$players_kingdom", dplmc_non_generic_factions_begin),
  63642. (this_or_next|eq, ":speaker_faction", "fac_player_faction"),
  63643. (this_or_next|eq, ":speaker_faction", "fac_player_supporters_faction"),
  63644. (eq, ":speaker_faction", "$players_kingdom"),
  63645. (assign, ":speaker_faction", "$players_kingdom"),
  63646. (neg|is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  63647. (this_or_next|is_between, "$g_player_culture", cultures_begin, cultures_end),
  63648. (is_between,"$g_player_culture", npc_kingdoms_begin, npc_kingdoms_end),
  63649. (assign, ":speaker_faction", "$g_player_culture"),
  63650. (try_end),
  63651.  
  63652. #Store variant
  63653. (try_begin),
  63654. #Iconic cultural weapon that can be used metonymously for force of arms.
  63655. #Native equivalent is "sword".
  63656. #Non-Warband example: "He who lives by the {sword}, dies by the {sword}."
  63657. #Example usage: "My {sword} is at the disposal of my liege."
  63658. (eq, ":context", DPLMC_CULTURAL_TERM_WEAPON),
  63659. (try_begin),
  63660. (this_or_next|eq, ":speaker_faction", "fac_kingdom_4"),#Nords
  63661. (eq, ":speaker_faction", "fac_kingdom_2"),#Vaegirs
  63662. (str_store_string, ":string_register", "@axe"),
  63663. (else_try),
  63664. (eq, ":speaker_faction", "fac_kingdom_5"),#Rhodoks
  63665. (str_store_string, ":string_register", "@spear"),
  63666. (else_try),
  63667. (eq, ":speaker_faction", "fac_kingdom_3"),#Khergits
  63668. (str_store_string, ":string_register", "@bow"),
  63669. (else_try),
  63670. #Default: Swadia, Sarranid, others
  63671. (str_store_string, ":string_register", "@sword"),
  63672. (try_end),
  63673. (else_try),
  63674. #Plural version of iconic cultural weapon that can be used metonymously for force of arms.
  63675. #Native equivalent is "swords".
  63676. (eq, ":context", DPLMC_CULTURAL_TERM_WEAPON_PLURAL),
  63677. (try_begin),
  63678. (this_or_next|eq, ":speaker_faction", "fac_kingdom_4"),#Nords
  63679. (eq, ":speaker_faction", "fac_kingdom_2"),#Vaegirs
  63680. (str_store_string, ":string_register", "@axes"),
  63681. (else_try),
  63682. (eq, ":speaker_faction", "fac_kingdom_5"),#Rhodoks
  63683. (str_store_string, ":string_register", "@spears"),
  63684. (else_try),
  63685. (eq, ":speaker_faction", "fac_kingdom_3"),#Khergits
  63686. (str_store_string, ":string_register", "@bows"),
  63687. (else_try),
  63688. #Default: Swadia, Sarranid, others
  63689. (str_store_string, ":string_register", "@swords"),
  63690. (try_end),
  63691. (else_try),
  63692. #Cultural phrase that means "fight" (first person singular)
  63693. #Native equivalent is "swing my sword."
  63694. #Example usage: "I want to be able to {swing my sword} with a good conscience."
  63695. (eq, ":context", DPLMC_CULTURAL_TERM_USE_MY_WEAPON),
  63696. (try_begin),
  63697. (eq, ":speaker_faction", "fac_kingdom_4"),#Nords
  63698. (eq, ":speaker_faction", "fac_kingdom_2"),#Vaegirs
  63699. (str_store_string, ":string_register", "@swing my axe"),
  63700. (else_try),
  63701. (eq, ":speaker_faction", "fac_kingdom_5"),#Rhodoks
  63702. (str_store_string, ":string_register", "@lift my spear"),
  63703. (else_try),
  63704. (eq, ":speaker_faction", "fac_kingdom_3"),#Khergits
  63705. (str_store_string, ":string_register", "@loose my arrows"),
  63706. (else_try),
  63707. #Default: Swadia, Sarranid, others
  63708. (str_store_string, ":string_register", "@swing my sword"),
  63709. (try_end),
  63710. (else_try),
  63711. #equivalent to lowercase "king" or "queen"
  63712. (this_or_next|eq, ":context", DPLMC_CULTURAL_TERM_KING_FEMALE),
  63713. (eq, ":context", DPLMC_CULTURAL_TERM_KING),
  63714. (try_begin),
  63715. (eq, ":speaker_faction", "fac_kingdom_3"),#Khergit
  63716. (str_store_string, ":string_register", "str_khan"),
  63717. (else_try),
  63718. (eq, ":speaker_faction", "fac_kingdom_6"),#Sarranid
  63719. (str_store_string, ":string_register", "@sultan"),
  63720. (else_try),
  63721. #Default: Swadia, Rhodok, Nord, Vaegir, others
  63722. (str_store_string, ":string_register", "str_king"),
  63723. (eq, ":context", DPLMC_CULTURAL_TERM_KING_FEMALE),
  63724. (str_store_string, ":string_register", "str_queen"),
  63725. (try_end),
  63726. (else_try),
  63727. #equivalent to lowercase "kings"
  63728. (eq, ":context", DPLMC_CULTURAL_TERM_KING_PLURAL),
  63729. (try_begin),
  63730. (eq, ":speaker_faction", "fac_kingdom_3"),#Khergit
  63731. (str_store_string, ":string_register", "@khans"),
  63732. (else_try),
  63733. (eq, ":speaker_faction", "fac_kingdom_6"),#Sarranid
  63734. (str_store_string, ":string_register", "@sultans"),
  63735. (else_try),
  63736. #Default: Swadia, Rhodok, Nord, Vaegir, others
  63737. (str_store_string, ":string_register", "@kings"),
  63738. (try_end),
  63739. (else_try),
  63740. #equivalent to lowercase "lord"
  63741. (eq, ":context", DPLMC_CULTURAL_TERM_LORD),
  63742. (str_store_string, ":string_register", "@lord"),
  63743. (else_try),
  63744. #equivalent to lowercase "lords"
  63745. (eq, ":context", DPLMC_CULTURAL_TERM_LORD_PLURAL),
  63746. (str_store_string, ":string_register", "@lords"),
  63747. (else_try),
  63748. #As in, "I shall tell my {swineherd} about your sweet promises" or "Any {swineherd} can claim to be king".
  63749. (eq, ":context", DPLMC_CULTURAL_TERM_SWINEHERD),
  63750. (assign, ":mode", ":speaker"),
  63751. (try_begin),
  63752. (gt, ":speaker", 0),
  63753. (neg|troop_is_hero, ":speaker"),
  63754. (store_current_hours, ":mode"),
  63755. (val_add, ":mode", "$g_encountered_party"),
  63756. (try_end),
  63757. (val_max, ":mode", 0),#Default to mode 0 for negative speakers
  63758. (val_mod, ":mode", 2),
  63759. (try_begin),
  63760. (eq, ":speaker_faction", "fac_kingdom_2"),#Vaegirs
  63761. (try_begin),
  63762. (eq, ":mode", 0),
  63763. (str_store_string, ":string_register", "@goatherd"),
  63764. (else_try),
  63765. (str_store_string, ":string_register", "@swineherd"),
  63766. (try_end),
  63767. (else_try),
  63768. (eq, ":speaker_faction", "fac_kingdom_3"),#Khergits
  63769. (try_begin),
  63770. (eq, ":mode", 0),
  63771. (str_store_string, ":string_register", "@stable {boy/girl}"),
  63772. (else_try),
  63773. (str_store_string, ":string_register", "@shepherd {boy/girl}"),
  63774. (try_end),
  63775. (else_try),
  63776. (eq, ":speaker_faction", "fac_kingdom_6"),#Sarranids
  63777. (try_begin),
  63778. (eq, ":mode", 0),
  63779. (str_store_string, ":string_register", "@goatherd"),
  63780. (else_try),
  63781. (str_store_string, ":string_register", "@shepherd {boy/girl}"),
  63782. (try_end),
  63783. (else_try),
  63784. #Swadia, Rhodok, Nord, others
  63785. (str_store_string, ":string_register", "@swineherd"),
  63786. (try_end),
  63787. (else_try),
  63788. #As in, "I'd like to buy every man who comes in here tonight a jar of your best wine."
  63789. (this_or_next|eq, ":context", DPLMC_CULTURAL_TERM_TAVERNWINE),
  63790. #Follow the pattern used in Native for lords in feasts
  63791. #(c.f. "str_flagon_of_mead", "str_skin_of_kumis", "str_mug_of_kvass", "str_cup_of_wine")
  63792.  
  63793. (try_begin),
  63794. #For lords, use "mode" so it works the same as in feast dialogs
  63795. (is_between, ":speaker", heroes_begin, heroes_end),
  63796. (this_or_next|neg|is_between, ":speaker", companions_begin, companions_end),
  63797. (neg|troop_slot_eq, ":speaker", slot_troop_original_faction, ":speaker_faction"),
  63798. (store_mod, ":mode", ":speaker", 2),
  63799. (else_try),
  63800. #Otherwise set mode to 0, to always use the cultural alternative
  63801. (assign, ":mode", 0),
  63802. (try_end),
  63803.  
  63804. (try_begin),
  63805. (eq, ":speaker_faction", "fac_kingdom_2"),
  63806. (eq, ":mode", 0),#From feast: 50% chance of falling through to "wine"
  63807. (str_store_string, ":string_register", "@kvass"),#Vaegirs: kvass
  63808. (else_try),
  63809. (eq, ":speaker_faction", "fac_kingdom_3"),
  63810. (eq, ":mode", 0),#From feast: 50% chance of falling through to "wine"
  63811. (str_store_string, ":string_register", "@kumis"),#Khergits: kumis
  63812. (else_try),
  63813. (eq, ":speaker_faction", "fac_kingdom_4"),
  63814. (str_store_string, ":string_register", "@mead"),#Nords: mead
  63815. (else_try),
  63816. (str_store_string, ":string_register", "@wine"),#Default: wine
  63817. (try_end),
  63818. (else_try),
  63819. #Error string
  63820. (assign, ":save_reg0", reg0),
  63821. (assign, reg0, ":context"),
  63822. (display_message, "@{!}ERROR - dplmc_print_cultural_word_to_sreg called for bad context {reg0}"),
  63823. (str_store_string, ":string_register", "str_ERROR_string"),
  63824. (assign, reg0, ":save_reg0"),
  63825. (try_end),
  63826.  
  63827. ]),
  63828.  
  63829.  
  63830. #script_dplmc_print_player_spouse_says_my_husband_wife_to_s0
  63831. #
  63832. #INPUT:
  63833. # arg1: troop_no
  63834. # arg2: whether the first letter must be capitalized
  63835. #
  63836. #OUTPUT:
  63837. # s0: a string that can be substituted for "my {husband/wife}" or "my love"
  63838. ("dplmc_print_player_spouse_says_my_husband_wife_to_s0",
  63839. [
  63840. (store_script_param_1, ":troop_no"),
  63841. (store_script_param_2, ":capitalized"),
  63842.  
  63843. (assign, ":save_reg0", reg0),
  63844. (assign, ":save_reg6", reg6),
  63845. (assign, ":save_reg7", reg7),
  63846. #(assign, reg6, ":capitalized"),
  63847. (assign, reg7, 0),
  63848.  
  63849. #Base switch is 50 (i.e. where the "brave champion" greeting starts)
  63850. (try_begin),
  63851. (lt, ":troop_no", 1),#bad value
  63852. (assign, reg0, 0),
  63853. (assign, reg6, lrep_none),
  63854. (else_try),
  63855. (call_script, "script_troop_get_player_relation", ":troop_no"),#write relation to reg0
  63856. (troop_get_slot, reg6, ":troop_no", slot_lord_reputation_type),#write relation to reg6
  63857. (eq, reg6, lrep_conventional),#...jumps to next branch (keeping reg0 and reg6) if this isn't true
  63858. (val_add, reg0, 25),#from 25+
  63859. (else_try),
  63860. (eq, reg6, lrep_otherworldly),
  63861. (val_add, reg0, 30),#from 20+
  63862. (else_try),
  63863. (eq, reg6, lrep_moralist),
  63864. (store_sub, reg7, "$player_honor", 10),
  63865. (val_clamp, reg7, -40, 31),
  63866. (val_add, reg0, reg7),
  63867. (assign, reg7, 0),
  63868. (else_try),
  63869. (eq, reg6, lrep_ambitious),
  63870. (assign, reg7, -10),
  63871. (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
  63872. (this_or_next|party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  63873. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  63874. (val_add, reg7, 10),
  63875. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  63876. (val_add, reg7, 10),
  63877. (try_end),
  63878. (val_clamp, reg7, -10, 30),
  63879. (val_add, reg0, reg7),
  63880. (assign, reg7, 0),
  63881. (else_try),
  63882. (eq, reg6, lrep_adventurous),
  63883. (val_add, reg7, 20),#from 30+
  63884. (else_try),
  63885. (eq, reg6, lrep_none),
  63886. (is_between, reg6, heroes_begin, heroes_end),
  63887. (val_sub, reg0, 20),#from 70+
  63888. (else_try),
  63889. (eq, reg6, lrep_cunning),
  63890. (val_sub, reg0, 20),#from 70+
  63891. (else_try),
  63892. (this_or_next|eq, reg6, lrep_debauched),
  63893. (this_or_next|eq, reg6, lrep_quarrelsome),
  63894. (this_or_next|eq, reg6, lrep_selfrighteous),
  63895. (val_sub, reg0, 30),#from 80+
  63896. (try_end),
  63897.  
  63898. (try_begin),
  63899. (ge, reg0, 50),
  63900. (assign, reg7, 1),
  63901. (try_end),
  63902.  
  63903. (try_begin),
  63904. #Embellishment: diminuitive pet-names
  63905. (eq, reg6, lrep_debauched),
  63906. (gt, ":troop_no", 0),
  63907. (store_character_level, ":player_level", "trp_player"),
  63908. (store_character_level, ":troop_level", ":troop_no"),
  63909. (troop_get_slot, ":player_renown", "trp_player", slot_troop_renown),
  63910. (this_or_next|ge, ":troop_level", ":player_level"),
  63911. (this_or_next|troop_slot_ge, ":troop_no", slot_troop_renown, ":player_renown"),
  63912. (lt, reg0, 50),
  63913. (assign, reg6, ":capitalized"),#Whether the first letter needs to be upper case
  63914. (str_store_string, s0, "@{reg6?M:m}y poppet"),
  63915. (else_try),
  63916. #The basic idea. Further embellishments may come.
  63917. (assign, reg6, ":capitalized"),#Whether the first letter needs to be upper case
  63918. (str_store_string, s0, "str_dplmc_reg6my_reg7spouse"),
  63919. (try_end),
  63920.  
  63921. #Revert registers
  63922. (assign, reg0, ":save_reg0"),
  63923. (assign, reg6, ":save_reg6"),
  63924. (assign, reg7, ":save_reg7"),
  63925. ]),
  63926.  
  63927. ##"script_dplmc_initialize_autoloot"
  63928. ##
  63929. ##Only needs to be called once, but it's safe to call multiple times
  63930. ##(it uses "$g_autoloot" to store the version)
  63931. ##
  63932. ##Inputs: arg1: 1 to force this to run
  63933. ##Outputs: None
  63934. ("dplmc_initialize_autoloot",
  63935. [
  63936. (store_script_param_1, ":force_to_run"),
  63937.  
  63938. (try_begin),
  63939. #Check if there is anything to do
  63940. (this_or_next|eq, ":force_to_run", 1),
  63941. (neq, "$g_autoloot", 2),
  63942. (try_begin),
  63943. #Print a message to make it obvious when this is happening more than it should.
  63944. (ge, "$cheat_mode", 1),
  63945. (store_current_hours, ":hours"),
  63946. (gt, ":hours", 0),
  63947. (display_message, "@{!}Initializing auto-loot. This message should not appear more than once."),
  63948. (try_end),
  63949. #Initialize
  63950. (try_for_range, ":cur_food", food_begin, food_end),
  63951. (item_set_slot, ":cur_food", dplmc_slot_item_food_portion, 1),
  63952. (try_end),
  63953.  
  63954. # #deprecated due to 1.165 operations
  63955. # (call_script, "script_dplmc_init_item_difficulties"),
  63956. # (call_script, "script_dplmc_init_item_base_score"),
  63957.  
  63958. (assign, "$g_dplmc_auto_sell_price_limit", 50),
  63959. (assign, "$g_dplmc_sell_items_when_leaving", 0),
  63960. (assign, "$g_dplmc_buy_food_when_leaving", 0),
  63961.  
  63962. (item_set_slot, itp_type_book, dplmc_slot_item_type_not_for_sell, 1),
  63963. (item_set_slot, itp_type_goods, dplmc_slot_item_type_not_for_sell, 1),
  63964. (item_set_slot, itp_type_animal, dplmc_slot_item_type_not_for_sell, 1),
  63965.  
  63966. (assign, "$g_autoloot", 2),
  63967. (try_end),
  63968. ]),
  63969.  
  63970.  
  63971. ##"script_dplmc_get_troop_standing_in_faction"
  63972. #
  63973. #INPUT: arg1 :troop_no
  63974. # arg2 :faction_no
  63975. #
  63976. #OUTPUT:
  63977. # reg0 A constant with the value DPLMC_FACTION_STANDING_<something>
  63978. #
  63979. ## Constants defined in module_constants.py
  63980. #DPLMC_FACTION_STANDING_LEADER = 60
  63981. #DPLMC_FACTION_STANDING_LEADER_SPOUSE = 50
  63982. #DPLMC_FACTION_STANDING_MARSHALL = 40
  63983. #DPLMC_FACTION_STANDING_LORD = 30
  63984. #DPLMC_FACTION_STANDING_DEPENDENT = 20
  63985. #DPLMC_FACTION_STANDING_MEMBER = 10#includes mercenaries
  63986. #DPLMC_FACTION_STANDING_PETITIONER = 5
  63987. #DPLMC_FACTION_STANDING_UNAFFILIATED = 0
  63988. ##diplomacy end+
  63989. ("dplmc_get_troop_standing_in_faction",
  63990. [
  63991. (store_script_param_1, ":troop_no"),
  63992. (store_script_param_2, ":faction_no"),
  63993.  
  63994. (assign, ":standing", DPLMC_FACTION_STANDING_UNAFFILIATED),
  63995. (assign, ":original_faction_no", ":faction_no"),
  63996. (try_begin),
  63997. #Translate fac_player_faction
  63998. (eq, ":faction_no", "fac_player_faction"),
  63999. (assign, ":faction_no", "fac_player_supporters_faction"),
  64000. (try_end),
  64001.  
  64002. (try_begin),
  64003. (this_or_next|lt, ":troop_no", 0),#Do nothing, bad troop ID
  64004. (lt, ":faction_no", 0),#Do nothing, bad faction
  64005. (else_try),
  64006. #Because of how this script is used, if fac_player_supporters_faction is active,
  64007. # this always reports that the player is its leader (even though that is sometimes
  64008. # untrue, for example in a claimant quest)
  64009. (eq, ":troop_no", "trp_player"),#Short-circuit the remainder if these are true
  64010. (eq, ":faction_no", "fac_player_supporters_faction"),
  64011. (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_active),
  64012. # (neg|is_between, "$supported_pretender", pretenders_begin, pretenders_end), #SB : claimant exception
  64013. (assign, ":standing", DPLMC_FACTION_STANDING_LEADER),
  64014. (else_try),
  64015. (try_begin),
  64016. #Translate fac_player_supporters_faction
  64017. (eq, ":faction_no", "fac_player_supporters_faction"),
  64018. (gt, "$players_kingdom", 0),
  64019. (assign, ":faction_no", "$players_kingdom"),
  64020. (try_end),
  64021.  
  64022. (store_faction_of_troop, ":troop_faction", ":troop_no"),
  64023. (try_begin),
  64024. #Translate fac_player_supporters_faction
  64025. (this_or_next|eq, ":troop_no", "trp_player"),
  64026. (this_or_next|eq, ":troop_faction", "fac_player_faction"),
  64027. (eq, ":troop_faction", "fac_player_supporters_faction"),
  64028. (assign, ":troop_faction", "fac_player_supporters_faction"),
  64029. (gt, "$players_kingdom", 0),
  64030. (assign, ":troop_faction", "$players_kingdom"),
  64031. (try_end),
  64032. (eq, ":troop_faction", ":faction_no"),#<- Short-circuit the remainder if this is false
  64033. (assign, ":standing", DPLMC_FACTION_STANDING_MEMBER),
  64034.  
  64035. (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
  64036. (try_begin),
  64037. #Faction leader
  64038. (eq, ":faction_leader", ":troop_no"),
  64039. (assign, ":standing", DPLMC_FACTION_STANDING_LEADER),
  64040. (else_try),
  64041. #Spouse of faction leader
  64042. (gt, ":faction_leader", -1),
  64043. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_spouse, ":faction_leader"),
  64044. (troop_slot_eq, ":faction_leader", slot_troop_spouse, ":troop_no"),
  64045. #Deal with possible uninitialized slot
  64046. (this_or_next|troop_slot_eq, ":faction_leader", slot_troop_spouse, ":troop_no"),
  64047. (this_or_next|neq, ":faction_leader", 0),
  64048. (is_between, ":troop_no", heroes_begin, heroes_end),
  64049. (assign, ":standing", DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  64050. (else_try),
  64051. #Faction marshall
  64052. (faction_slot_eq, ":faction_no", slot_faction_marshall, ":troop_no"),
  64053. (assign, ":standing", DPLMC_FACTION_STANDING_MARSHALL),
  64054. (else_try),
  64055. #If the troop is the player, if he has homage he is a lord.
  64056. #Otherwise he is a mercenary.
  64057. (eq, ":troop_no", "trp_player"),
  64058. (try_begin),
  64059. (this_or_next|eq, ":faction_no", "fac_player_supporters_faction"),
  64060. (ge, "$player_has_homage", 1),
  64061. (assign, ":standing", DPLMC_FACTION_STANDING_LORD),
  64062. (else_try),
  64063. #If the player is married to a lord/lady in the faction, the
  64064. #homage variable should always be set to 1+, but add a separate
  64065. #check just in case.
  64066. (troop_get_slot, reg0, "trp_player", slot_troop_spouse),
  64067. (is_between, reg0, heroes_begin, heroes_end),
  64068. (store_faction_of_troop, reg0, reg0),
  64069. (this_or_next|eq, reg0, "fac_player_supporters_faction"),
  64070. (eq, reg0, ":faction_no"),
  64071. (assign, ":standing", DPLMC_FACTION_STANDING_LORD),
  64072. (try_end),
  64073. (else_try),
  64074. #None of the following conditions apply for non-heroes
  64075. (this_or_next|lt, ":troop_no", heroes_begin),
  64076. (neg|troop_is_hero, ":troop_no"),
  64077. (else_try),
  64078. #For kingdom heroes, part 1 (check lordship based on occupation)
  64079. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_granted_fief),
  64080. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_lord_rejoined),
  64081. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  64082. (assign, ":standing", DPLMC_FACTION_STANDING_LORD),
  64083. (else_try),
  64084. #For kingdom ladies
  64085. (this_or_next|is_between, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  64086. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_lady),
  64087. (assign, ":standing", DPLMC_FACTION_STANDING_DEPENDENT),
  64088. (else_try),
  64089. #For petitioners
  64090. (eq, ":original_faction_no", "fac_player_supporters_faction"),
  64091. (is_between, ":troop_no", lords_begin, lords_end),
  64092. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive),
  64093. (neg|troop_slot_ge, ":troop_no", slot_troop_leaded_party, 0),
  64094. (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  64095. (assign, ":standing", DPLMC_FACTION_STANDING_PETITIONER),
  64096. (else_try),
  64097. #For kingdom heroes, part 2 (all non-companion active NPCs)
  64098. (is_between, ":troop_no", active_npcs_begin, active_npcs_end),
  64099. (neg|is_between, ":troop_no", companions_begin, companions_end),
  64100. (assign, ":standing", DPLMC_FACTION_STANDING_LORD),
  64101. (try_end),
  64102. (try_end),
  64103.  
  64104. (assign, reg0, ":standing"),
  64105. ]),
  64106.  
  64107. ## "script_dplmc_store_troop_is_eligible_for_affiliate_messages"
  64108. ("dplmc_store_troop_is_eligible_for_affiliate_messages",
  64109. [
  64110. (store_script_param_1, ":troop_no"),
  64111. (assign, ":is_eligible", 0),
  64112. (assign, ":save_reg1", reg1),
  64113. (try_begin),
  64114. (lt, ":troop_no", 1),
  64115. (else_try),
  64116. (neg|troop_is_hero, ":troop_no"),
  64117. (else_try),
  64118. #Initialize :faction_no and :faction_relation
  64119. (store_faction_of_troop, ":faction_no", ":troop_no"),
  64120. (store_relation, ":faction_relation", ":faction_no", "fac_player_supporters_faction"),
  64121. (try_begin),
  64122. (eq, ":faction_no", "$players_kingdom"),
  64123. (val_max, ":faction_relation", 1),
  64124. (try_end),
  64125. #Companion
  64126. (gt, ":faction_relation", -1),
  64127. (is_between, ":troop_no", companions_begin, companions_end),
  64128. (neg|troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  64129. (troop_slot_ge, ":troop_no", slot_troop_player_relation, 20),
  64130. (assign, ":is_eligible", 1),
  64131. (else_try),
  64132. #Faction marshall (if the player is the faction leader)
  64133. #Faction leader (if the player is the faction marshall)
  64134. (eq, ":faction_no", "$players_kingdom"),
  64135. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  64136. (ge, reg0, DPLMC_FACTION_STANDING_MARSHALL),
  64137. (call_script, "script_dplmc_get_troop_standing_in_faction", ":troop_no", "$players_kingdom"),
  64138. (ge, reg0, DPLMC_FACTION_STANDING_MARSHALL),
  64139. (assign, ":is_eligible", 1),
  64140. (else_try),
  64141. #Spouse / relatives / in-laws
  64142. (gt, ":faction_relation", -1),
  64143. #(is_between, ":troop_no", heroes_begin, heroes_end),## should be safe even for non-heroes
  64144. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":troop_no", "trp_player"),
  64145. (ge, reg0, 2),
  64146. (troop_get_slot, reg1, ":troop_no", slot_troop_player_relation),
  64147. (val_add, reg0, reg1),
  64148. (ge, reg0, 20),
  64149. (assign, ":is_eligible", 1),
  64150. (else_try),
  64151. #Affiliates
  64152. (call_script, "script_dplmc_is_affiliated_family_member", ":troop_no"),
  64153. (ge, reg0, 1),
  64154. (assign, ":is_eligible", 1),
  64155. (else_try),
  64156. #Cheat mode: add faction leaders to test this out
  64157. (gt, "$cheat_mode", 0),
  64158. (is_between, ":faction_no", kingdoms_begin, kingdoms_end),
  64159. (faction_slot_eq, ":faction_no", slot_faction_leader, ":troop_no"),
  64160. (assign, ":is_eligible", 1),
  64161. (try_end),
  64162. (assign, reg1, ":save_reg1"),
  64163. (assign, reg0, ":is_eligible"),
  64164. ]),
  64165.  
  64166. # "script_dplmc_sell_all_prisoners"
  64167. #
  64168. # Taken from rubik's Custom Commander, and altered to have parameters
  64169. # and return feedback.
  64170. #
  64171. #INPUT:
  64172. #Arg 1: actually remove (positive for yes, zero or negative for no)
  64173. #Arg 2: if positive, use this as a fixed price instead of calculating dynamically
  64174. #OUTPUT:
  64175. #reg0: amount of gold gained (or would have been gained if the sale occurred)
  64176. #reg1: number of prisoners sold (or would have been sold if the sale occurred)
  64177. ("dplmc_sell_all_prisoners",
  64178. [
  64179. (store_script_param_1, ":actually_remove"),
  64180. (store_script_param_2, ":fixed_price"),
  64181.  
  64182. (assign, ":total_removed", 0),
  64183. (assign, ":total_income", 0),
  64184. (party_get_num_prisoner_stacks, ":num_stacks", "p_main_party"),
  64185. (try_for_range_backwards, ":i_stack", 0, ":num_stacks"),
  64186. (party_prisoner_stack_get_troop_id, ":troop_no", "p_main_party", ":i_stack"),
  64187. #SB : correction to use game script
  64188. (call_script, "script_game_check_prisoner_can_be_sold", ":troop_no"),
  64189. (eq, reg0, 1),
  64190. # (neg|troop_is_hero, ":troop_no"),
  64191. (party_prisoner_stack_get_size, ":stack_size", "p_main_party", ":i_stack"),
  64192. (try_begin),
  64193. (gt, ":fixed_price", 0),
  64194. (assign, ":sell_price", ":fixed_price"),
  64195. (else_try),
  64196. (call_script, "script_game_get_prisoner_price", ":troop_no"),
  64197. (assign, ":sell_price", reg0),
  64198. (try_end),
  64199. (store_mul, ":stack_total_price", ":sell_price", ":stack_size"),
  64200. (val_add, ":total_income", ":stack_total_price"),
  64201. (val_add, ":total_removed", ":stack_size"),
  64202. (gt, ":actually_remove", 0),#Stop short if this is a dry run
  64203. (party_remove_prisoners, "p_main_party", ":troop_no", ":stack_size"),
  64204. (try_end),
  64205. (try_begin),
  64206. (gt, ":actually_remove", 0),#Stop short if this is a dry run
  64207. (troop_add_gold, "trp_player", ":total_income"),
  64208. (try_end),
  64209. (assign, reg0, ":total_income"),
  64210. (assign, reg1, ":total_removed"),
  64211. ]),
  64212.  
  64213. #"script_dplmc_translate_inactive_player_supporter_faction_2"
  64214. #
  64215. #Since "fac_player_supporters_faction" is often used as a parameter when what
  64216. #is really meant is "the faction led by the player" (which is never a different
  64217. #faction in Native), there are many calls we want to change. Another solution
  64218. #is to approach the problem from the other side, and "correct" the arguments.
  64219. #
  64220. #If exactly one argument is equal to fac_player_supporters_faction, and fac_player_supporters_faction
  64221. #is not sfs_active, and $players_kingdom is an NPC kingdom of which the player is ruler or co-ruler,
  64222. #and the other argument is not equal to $players_kingdom, then the argument equal to fac_player_supporters_faction
  64223. #will be replaced with $players_kingdom.
  64224. #
  64225. #INPUT:
  64226. # arg1 - faction_1
  64227. # arg2 - faction_2
  64228. #OUTPUT:
  64229. # reg0 - faction_1, possibly replacing fac_player_supporters_faction with $players_kingdom (see above)
  64230. # reg1 - faction_2, possibly replacing fac_player_supporters_faction with $players_kingdom (see above)
  64231. ("dplmc_translate_inactive_player_supporter_faction_2",
  64232. [
  64233. (store_script_param_1, ":faction_1"),
  64234. (store_script_param_2, ":faction_2"),
  64235.  
  64236. (try_begin),
  64237. (this_or_next|faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, sfs_active),
  64238. (this_or_next|neg|is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  64239. (this_or_next|eq, ":faction_1", "$players_kingdom"),
  64240. (this_or_next|eq, ":faction_2", "$players_kingdom"),
  64241. (eq, ":faction_1", ":faction_2"),
  64242. #Do nothing
  64243. (else_try),
  64244. (eq, ":faction_1", "fac_player_supporters_faction"),
  64245. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  64246. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  64247. (assign, ":faction_1", "$players_kingdom"),
  64248. (else_try),
  64249. (eq, ":faction_2", "fac_player_supporters_faction"),
  64250. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", "$players_kingdom"),
  64251. (ge, reg0, DPLMC_FACTION_STANDING_LEADER_SPOUSE),
  64252. (assign, ":faction_2", "$players_kingdom"),
  64253. (try_end),
  64254.  
  64255. (assign, reg0, ":faction_1"),
  64256. (assign, reg1, ":faction_2"),
  64257. ]),
  64258.  
  64259. ##"script_cf_dplmc_player_party_meets_autoloot_conditions"
  64260. ##
  64261. #
  64262. #INPUT:
  64263. # None
  64264. #OUTPUT:
  64265. # reg0 -1 means there are no companions and skill is too low
  64266. # 0 means there are companions and skill is too low
  64267. # 1 means skill is high enough but there are no companions
  64268. # 2 means skill is high enough and there are companions
  64269. #
  64270. # Will fail if it does not set reg0 to 2.
  64271. ##
  64272. ("cf_dplmc_player_party_meets_autoloot_conditions",
  64273. [
  64274. (store_skill_level, ":best_loot_skill", "skl_looting", "trp_player"),
  64275. (store_skill_level, ":player_inv_skill", "skl_inventory_management", "trp_player"),
  64276. (assign, ":best_inv_skill", ":player_inv_skill"),
  64277. (assign, ":num_companions", 0),
  64278. (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  64279. (try_for_range, ":stack_no", 0, ":num_stacks"),
  64280. (party_stack_get_troop_id, ":stack_troop", "p_main_party", ":stack_no"),
  64281. (ge, ":stack_troop", 0),
  64282. #Check skill
  64283. (is_between, ":stack_troop", heroes_begin, heroes_end),
  64284. (store_skill_level, ":hero_skill", "skl_inventory_management", ":stack_troop"),
  64285. (val_max, ":best_inv_skill", ":hero_skill"),
  64286.  
  64287. (store_skill_level, ":hero_skill", "skl_looting", ":stack_troop"),
  64288. (val_max, ":best_loot_skill", ":hero_skill"),
  64289. #Check is companion
  64290. (is_between, ":stack_troop", companions_begin, companions_end),
  64291. (val_add, ":num_companions", 1),
  64292. (try_end),
  64293.  
  64294. (try_begin),
  64295. (lt, ":player_inv_skill", 2),
  64296. (lt, ":best_inv_skill", 3),
  64297. (lt, ":best_loot_skill", 2),
  64298. (assign, reg0, 0),
  64299. (try_begin),
  64300. (lt, ":num_companions", 1),#change 2011-06-07
  64301. (assign, reg0, -1),
  64302. (try_end),
  64303. (else_try),
  64304. (assign, reg0, 1),
  64305. (gt, ":num_companions", 0),
  64306. (assign, reg0, 2),
  64307. (try_end),
  64308.  
  64309. (eq, reg0, 2),
  64310. ]),
  64311.  
  64312.  
  64313. ##"script_dplmc_troop_get_family_relation_to_troop"
  64314. ##
  64315. ##Like troop_get_family_relation_to_troop, except instead of writing to s11,
  64316. ##it writes the index of the relation string to reg1, and writes nothing at
  64317. ##all to reg4.
  64318. ("dplmc_troop_get_family_relation_to_troop",
  64319. [
  64320. (store_script_param_1, ":troop_1"),
  64321. (store_script_param_2, ":troop_2"),
  64322.  
  64323. ##dplmc start+
  64324.  
  64325. (try_begin),
  64326. (eq, ":troop_1", active_npcs_including_player_begin),
  64327. (assign, ":troop_1", "trp_player"),
  64328. (try_end),
  64329. (try_begin),
  64330. (eq, ":troop_2", active_npcs_including_player_begin),
  64331. (assign, ":troop_2", "trp_player"),
  64332. (try_end),
  64333.  
  64334. #use gender script
  64335. #(troop_get_type, ":gender_1", ":troop_1"),
  64336. (call_script, "script_dplmc_store_troop_is_female", ":troop_1"),
  64337. (assign, ":gender_1", reg0),
  64338. (assign, ":relation_string", "str_no_relation"),
  64339. ##dplmc end+
  64340. (assign, ":relation_strength", 0),
  64341.  
  64342. ##dplmc start+
  64343. #Uninitialized memory is 0, which equals "trp_player", which is the cause
  64344. #of some annoying bugs. In Native the game doesn't set the various family
  64345. #slots to -1 except for the player and in the heroes_begin to heroes_end
  64346. #range.
  64347.  
  64348. (troop_get_slot, ":spouse_of_1", ":troop_1", slot_troop_spouse),#just do this to get an error if the troop ID is bad
  64349. (troop_get_slot, ":spouse_of_2", ":troop_2", slot_troop_spouse),#just do this to get an error if the troop ID is bad
  64350.  
  64351. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":troop_1", ":troop_2", slot_troop_spouse),
  64352. (assign, ":spouse_of_1", reg0),
  64353. (assign, ":spouse_of_2", reg1),
  64354.  
  64355. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":spouse_of_1", ":spouse_of_2", slot_troop_father),
  64356. (assign, ":father_of_spouse_of_1", reg0),
  64357. (assign, ":father_of_spouse_of_2", reg1),
  64358.  
  64359. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":spouse_of_1", ":spouse_of_2", slot_troop_mother),
  64360. #(assign, ":mother_of_spouse_of_1", reg0),
  64361. (assign, ":mother_of_spouse_of_2", reg1),
  64362.  
  64363. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":troop_1", ":troop_2", slot_troop_father),
  64364. (assign, ":father_of_1", reg0),
  64365. (assign, ":father_of_2", reg1),
  64366.  
  64367. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":troop_1", ":troop_2", slot_troop_mother),
  64368. (assign, ":mother_of_1", reg0),
  64369. (assign, ":mother_of_2", reg1),
  64370.  
  64371. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":father_of_1", ":father_of_2", slot_troop_father),
  64372. (assign, ":paternal_grandfather_of_1", reg0),
  64373. (assign, ":paternal_grandfather_of_2", reg1),
  64374.  
  64375. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":father_of_1", ":father_of_2", slot_troop_mother),
  64376. (assign, ":paternal_grandmother_of_1", reg0),
  64377. (assign, ":paternal_grandmother_of_2", reg1),
  64378.  
  64379. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":mother_of_1", ":mother_of_2", slot_troop_father),
  64380. (assign, ":maternal_grandfather_of_1", reg0),
  64381. (assign, ":maternal_grandfather_of_2", reg1),
  64382.  
  64383. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":mother_of_1", ":mother_of_2", slot_troop_mother),
  64384. (assign, ":maternal_grandmother_of_1", reg0),
  64385. (assign, ":maternal_grandmother_of_2", reg1),
  64386.  
  64387. (call_script, "script_dplmc_helper_get_troop1_troop2_family_slot_aux", ":troop_1", ":troop_2", slot_troop_guardian),
  64388. (assign, ":guardian_of_1", reg0),
  64389. (assign, ":guardian_of_2", reg1),
  64390. ##diplomacy end+
  64391.  
  64392. #(str_store_string, s11, "str_no_relation"),
  64393.  
  64394. (try_begin),
  64395. (eq, ":troop_1", ":troop_2"),
  64396. #self
  64397. (else_try),
  64398. ##diplomacy start+
  64399. (this_or_next|eq, ":spouse_of_2", ":troop_1"),#polygamy helper
  64400. ##diplomacy end+
  64401. (eq, ":spouse_of_1", ":troop_2"),
  64402. (assign, ":relation_strength", 20),
  64403. (try_begin),
  64404. (eq, ":gender_1", tf_female),
  64405. (assign, ":relation_string", "str_wife"),
  64406. (else_try),
  64407. (assign, ":relation_string", "str_husband"),
  64408. (try_end),
  64409. (else_try),
  64410. (eq, ":father_of_2", ":troop_1"),
  64411. (assign, ":relation_strength", 15),
  64412. (assign, ":relation_string", "str_father"),
  64413. (else_try),
  64414. (eq, ":mother_of_2", ":troop_1"),
  64415. (assign, ":relation_strength", 15),
  64416. (assign, ":relation_string", "str_mother"),
  64417. (else_try),
  64418. (this_or_next|eq, ":father_of_1", ":troop_2"),
  64419. (eq, ":mother_of_1", ":troop_2"),
  64420. (assign, ":relation_strength", 15),
  64421. (try_begin),
  64422. (eq, ":gender_1", tf_female),
  64423. (assign, ":relation_string", "str_daughter"),
  64424. (else_try),
  64425. (assign, ":relation_string", "str_son"),
  64426. (try_end),
  64427. ##diplomacy start+
  64428. (else_try),
  64429. #Check for half-siblings: sharing a father
  64430. (neq, ":father_of_1", -1),
  64431. (eq, ":father_of_1", ":father_of_2"),
  64432. (neq, ":mother_of_1", ":mother_of_2"),
  64433. (assign, ":relation_strength", 10),
  64434. (try_begin),
  64435. (eq, ":gender_1", tf_female),
  64436. (assign, ":relation_string", "str_dplmc_half_sister"),
  64437. (else_try),
  64438. (assign, ":relation_string", "str_dplmc_half_brother"),
  64439. (try_end),
  64440. (else_try),
  64441. #Check for half-siblings: sharing a mother
  64442. (neq, ":mother_of_1", -1),
  64443. (eq, ":mother_of_1", ":mother_of_2"),
  64444. (neq, ":father_of_1", ":father_of_2"),
  64445. (assign, ":relation_strength", 10),
  64446. (try_begin),
  64447. (eq, ":gender_1", tf_female),
  64448. (assign, ":relation_string", "str_dplmc_half_sister"),
  64449. (else_try),
  64450. (assign, ":relation_string", "str_dplmc_half_brother"),
  64451. (try_end),
  64452. ##diplomacy end+
  64453. (else_try),
  64454. #(gt, ":father_of_1", -1), #necessary, as some lords do not have the father registered #dplmc+ replaced
  64455. (neq, ":father_of_1", -1), #dplmc+ added
  64456. (eq, ":father_of_1", ":father_of_2"),
  64457. (assign, ":relation_strength", 10),
  64458. (try_begin),
  64459. (eq, ":gender_1", tf_female),
  64460. (assign, ":relation_string", "str_sister"),
  64461. (else_try),
  64462. (assign, ":relation_string", "str_brother"),
  64463. (try_end),
  64464. (else_try),
  64465. (eq, ":guardian_of_2", ":troop_1"),
  64466. (assign, ":relation_strength", 10),
  64467. (try_begin),
  64468. (eq, ":gender_1", tf_female),
  64469. (assign, ":relation_string", "str_sister"),
  64470. (else_try),
  64471. (assign, ":relation_string", "str_brother"),
  64472. (try_end),
  64473. (else_try),
  64474. (eq, ":guardian_of_1", ":troop_2"),
  64475. (assign, ":relation_strength", 10),
  64476. (try_begin),
  64477. (eq, ":gender_1", tf_female),
  64478. (assign, ":relation_string", "str_sister"),
  64479. (else_try),
  64480. (assign, ":relation_string", "str_brother"),
  64481. (try_end),
  64482. ##diplomacy start+
  64483. (else_try),#polygamy, between two people married to the same person
  64484. (neq, ":spouse_of_1", -1),
  64485. (eq, ":spouse_of_2", ":spouse_of_1"),
  64486. (assign, ":relation_strength", 10),
  64487. (try_begin),
  64488. (call_script, "script_dplmc_store_troop_is_female", ":troop_2"),
  64489. (neq, ":gender_1", reg0),
  64490. (assign, ":relation_string", "str_dplmc_co_spouse"),
  64491. (else_try),
  64492. (eq, ":gender_1", tf_female),
  64493. (assign, ":relation_string", "str_dplmc_sister_wife"),
  64494. (else_try),
  64495. (assign, ":relation_string", "str_dplmc_co_husband"),
  64496. (try_end),
  64497. ##diplomacy end+
  64498. (else_try),
  64499. #(gt, ":paternal_grandfather_of_1", -1),#dplmc+ replaced
  64500. (neq, ":father_of_2", -1),#dplmc+ added
  64501. (this_or_next|eq, ":maternal_grandfather_of_1", ":father_of_2"),#dplmc+ added
  64502. (eq, ":paternal_grandfather_of_1", ":father_of_2"),
  64503. (assign, ":relation_strength", 4),
  64504. (try_begin),
  64505. (eq, ":gender_1", tf_female),
  64506. (assign, ":relation_string", "str_niece"),
  64507. (else_try),
  64508. (assign, ":relation_string", "str_nephew"),
  64509. (try_end),
  64510. ##diplomacy start+: add niece/nephew through mother
  64511. (else_try),
  64512. (neq, ":mother_of_2", -1),
  64513. (this_or_next|eq, ":maternal_grandmother_of_1", ":mother_of_2"),
  64514. (eq, ":paternal_grandmother_of_1", ":mother_of_2"),
  64515. (assign, ":relation_strength", 4),
  64516. (try_begin),
  64517. (eq, ":gender_1", tf_female),
  64518. (assign, ":relation_string", "str_niece"),
  64519. (else_try),
  64520. (assign, ":relation_string", "str_nephew"),
  64521. (try_end),
  64522. ##diplomacy end+
  64523. (else_try), #specifically aunt and uncle by blood -- i assume that in a medieval society with lots of internal family conflicts, they would not include aunts and uncles by marriage
  64524. #(gt, ":paternal_grandfather_of_2", -1),#dplmc+ replaced
  64525. (neq, ":father_of_1", -1),#dplmc+ added
  64526. (this_or_next|eq, ":maternal_grandfather_of_2", ":father_of_1"),#dplmc+ added
  64527. (eq, ":paternal_grandfather_of_2", ":father_of_1"),
  64528. (assign, ":relation_strength", 4),
  64529. (try_begin),
  64530. (eq, ":gender_1", tf_female),
  64531. (assign, ":relation_string", "str_aunt"),
  64532. (else_try),
  64533. (assign, ":relation_string", "str_uncle"),
  64534. (try_end),
  64535. ##diplomacy start+
  64536. #blood uncles & blood aunts, continued (via mother)
  64537. (else_try),
  64538. (neq, ":mother_of_1", -1),
  64539. (this_or_next|eq, ":maternal_grandmother_of_2", ":mother_of_1"),
  64540. (eq, ":paternal_grandmother_of_2", ":mother_of_1"),
  64541. (assign, ":relation_strength", 4),
  64542. (try_begin),
  64543. (eq, ":gender_1", tf_female),
  64544. (assign, ":relation_string", "str_aunt"),
  64545. (else_try),
  64546. (assign, ":relation_string", "str_uncle"),
  64547. (try_end),
  64548. ##diplomacy end+
  64549. (else_try),
  64550. #(gt, ":paternal_grandfather_of_1", 0),#dplmc+ replaced (why was this one "gt 0" but the previous "gt -1"?)
  64551. (neq, ":paternal_grandfather_of_1", -1),#dplmc+ added
  64552. (this_or_next|eq, ":maternal_grandfather_of_2", ":paternal_grandfather_of_1"),#dplmc+ added
  64553. (eq, ":paternal_grandfather_of_2", ":paternal_grandfather_of_1"),
  64554. (assign, ":relation_strength", 2),
  64555. (assign, ":relation_string", "str_cousin"),
  64556. ##diplomacy start+
  64557. #Add cousin via paternal grandmother or maternal grandparents
  64558. (else_try),
  64559. (neq, ":maternal_grandfather_of_1", -1),
  64560. (this_or_next|eq, ":maternal_grandfather_of_2", ":maternal_grandfather_of_1"),
  64561. (eq, ":paternal_grandfather_of_2", ":maternal_grandfather_of_1"),
  64562. (assign, ":relation_strength", 2),
  64563. (assign, ":relation_string", "str_cousin"),
  64564. (else_try),
  64565. (neq, ":paternal_grandmother_of_1", -1),
  64566. (this_or_next|eq, ":maternal_grandmother_of_2", ":paternal_grandmother_of_1"),
  64567. (eq, ":paternal_grandmother_of_2", ":paternal_grandmother_of_1"),
  64568. (assign, ":relation_strength", 2),
  64569. (assign, ":relation_string", "str_cousin"),
  64570. (else_try),
  64571. (neq, ":maternal_grandmother_of_1", -1),
  64572. (this_or_next|eq, ":maternal_grandmother_of_2", ":maternal_grandmother_of_1"),
  64573. (eq, ":paternal_grandmother_of_2", ":maternal_grandmother_of_1"),
  64574. (assign, ":relation_strength", 2),
  64575. (assign, ":relation_string", "str_cousin"),
  64576. ##diplomacy end+
  64577. (else_try),
  64578. (eq, ":father_of_spouse_of_1", ":troop_2"),
  64579. (assign, ":relation_strength", 5),
  64580. (try_begin),
  64581. (eq, ":gender_1", tf_female),
  64582. (assign, ":relation_string", "str_daughterinlaw"),
  64583. (else_try),
  64584. (assign, ":relation_string", "str_soninlaw"),
  64585. (try_end),
  64586. (else_try),
  64587. (eq, ":father_of_spouse_of_2", ":troop_1"),
  64588. (assign, ":relation_strength", 5),
  64589. (assign, ":relation_string", "str_fatherinlaw"),
  64590. (else_try),
  64591. (eq, ":mother_of_spouse_of_2", ":troop_1"),
  64592. (neq, ":mother_of_spouse_of_2", "trp_player"), #May be necessary if mother for troops not set to -1
  64593. (assign, ":relation_strength", 5),
  64594. (assign, ":relation_string", "str_motherinlaw"),
  64595.  
  64596. (else_try),
  64597. #(gt, ":father_of_spouse_of_1", -1), #necessary #dplmc+ replaced
  64598. (neq, ":father_of_spouse_of_1", -1), #dplmc+ added
  64599. (eq, ":father_of_spouse_of_1", ":father_of_2"),
  64600. (assign, ":relation_strength", 5),
  64601. (try_begin),
  64602. (eq, ":gender_1", tf_female),
  64603. (assign, ":relation_string", "str_sisterinlaw"),
  64604. (else_try),
  64605. (assign, ":relation_string", "str_brotherinlaw"),
  64606. (try_end),
  64607. (else_try),
  64608. #(gt, ":father_of_spouse_of_2", -1), #necessary #dplmc+ replaced
  64609. (neq, ":father_of_spouse_of_2", -1), #dplmc+ added
  64610. (eq, ":father_of_spouse_of_2", ":father_of_1"),
  64611. (assign, ":relation_strength", 5),
  64612. (try_begin),
  64613. (eq, ":gender_1", tf_female),
  64614. (assign, ":relation_string", "str_sisterinlaw"),
  64615. (else_try),
  64616. (assign, ":relation_string", "str_brotherinlaw"),
  64617. (try_end),
  64618. (else_try),
  64619. # (gt, ":spouse_of_2", -1), #necessary to avoid bug #dplmc+ replaced
  64620. (neq, ":spouse_of_2", -1), #dplmc+ added
  64621. (troop_slot_eq, ":spouse_of_2", slot_troop_guardian, ":troop_1"),
  64622. (assign, ":relation_strength", 5),
  64623. (try_begin),
  64624. #(eq, ":gender_1", tf_female),#dplmc+ replaced
  64625. (eq, ":gender_1", tf_female),#dplmc+ added
  64626. (assign, ":relation_string", "str_sisterinlaw"),
  64627. (else_try),
  64628. (assign, ":relation_string", "str_brotherinlaw"),
  64629. (try_end),
  64630. (else_try),
  64631. #(gt, ":spouse_of_1", -1), #necessary to avoid bug #dplmc+ replaced
  64632. (neq, ":spouse_of_1", -1), #dplmc+ added
  64633. (troop_slot_eq, ":spouse_of_1", slot_troop_guardian, ":troop_2"),
  64634. (assign, ":relation_strength", 5),
  64635. (try_begin),
  64636. (eq, ":gender_1", tf_female),
  64637. (assign, ":relation_string", "str_sisterinlaw"),
  64638. (else_try),
  64639. (assign, ":relation_string", "str_brotherinlaw"),
  64640. (try_end),
  64641. (else_try),
  64642. #grandchild
  64643. (neq, ":troop_2", -1),
  64644. (this_or_next|eq, ":paternal_grandfather_of_1", ":troop_2"),
  64645. (this_or_next|eq, ":maternal_grandfather_of_1", ":troop_2"),
  64646. (this_or_next|eq, ":paternal_grandmother_of_1", ":troop_2"),
  64647. (eq, ":maternal_grandmother_of_1", ":troop_2"),
  64648. (assign, ":relation_strength", 4),
  64649. (try_begin),
  64650. (eq, ":gender_1", tf_female),
  64651. (assign, ":relation_string", "str_dplmc_granddaughter"),
  64652. (else_try),
  64653. (assign, ":relation_string", "str_dplmc_grandson"),
  64654. (try_end),
  64655. (else_try),
  64656. #grandparent
  64657. (neq, ":troop_1", -1),
  64658. (this_or_next|eq, ":paternal_grandfather_of_2", ":troop_1"),
  64659. (this_or_next|eq, ":maternal_grandfather_of_2", ":troop_1"),
  64660. (this_or_next|eq, ":paternal_grandmother_of_2", ":troop_1"),
  64661. (eq, ":maternal_grandmother_of_2", ":troop_1"),
  64662. (assign, ":relation_strength", 4),
  64663. (try_begin),
  64664. (eq, ":gender_1", tf_female),
  64665. (assign, ":relation_string", "str_dplmc_grandmother"),
  64666. (else_try),
  64667. (assign, ":relation_string", "str_dplmc_grandfather"),
  64668. (try_end),
  64669. (try_end),
  64670. ##diplomacy start+
  64671. ##Add relations for rulers not already encoded
  64672. (try_begin),
  64673. (eq, ":relation_strength", 0),
  64674. (neq, ":troop_1", ":troop_2"),
  64675. (try_begin),
  64676. #Lady Isolla of Suno's father King Esterich was King Harlaus's cousin,
  64677. #making them first cousins once removed. Assign a weight of "1"
  64678. #to this (for reference, the lowest value normally given in Native is 2).
  64679. (this_or_next|eq, ":troop_1", "trp_kingdom_1_lord"),
  64680. (eq, ":troop_1", "trp_kingdom_1_pretender"),
  64681. (this_or_next|eq, ":troop_2", "trp_kingdom_1_lord"),
  64682. (eq, ":troop_2", "trp_kingdom_1_pretender"),
  64683. (assign, ":relation_strength", 1),
  64684. (assign, ":relation_string", "str_cousin"),
  64685. (else_try),
  64686. #Prince Valdym's uncle was Regent Burelek, father of King Yaroglek,
  64687. #making the two of them first cousins.
  64688. (this_or_next|eq, ":troop_1", "trp_kingdom_2_lord"),
  64689. (eq, ":troop_1", "trp_kingdom_2_pretender"),
  64690. (this_or_next|eq, ":troop_2", "trp_kingdom_2_lord"),
  64691. (eq, ":troop_2", "trp_kingdom_2_pretender"),
  64692. (assign, ":relation_strength", 2),
  64693. (assign, ":relation_string", "str_cousin"),
  64694. (else_try),
  64695. #Sanjar Khan and Dustum Khan were both sons of Janakir Khan
  64696. #(although by different mothers) making them half-brothers.
  64697. (this_or_next|eq, ":troop_1", "trp_kingdom_3_lord"),
  64698. (eq, ":troop_1", "trp_kingdom_3_pretender"),
  64699. (this_or_next|eq, ":troop_2", "trp_kingdom_3_lord"),
  64700. (eq, ":troop_2", "trp_kingdom_3_pretender"),
  64701. (assign, ":relation_strength", 10),
  64702. (assign, ":relation_string", "str_dplmc_half_brother"),
  64703. #Adjust their parentage to make this work automatically
  64704. (try_begin),
  64705. (troop_slot_eq, ":troop_1", slot_troop_father, -1),
  64706. (troop_slot_eq, ":troop_2", slot_troop_father, -1),
  64707. #Set their "father" slot to a number guaranteed not to have spurious collisions
  64708. (store_mul, ":janakir_khan", "trp_kingdom_3_lord", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),#defined in module_constants.py
  64709. (val_add, ":janakir_khan", DPLMC_VIRTUAL_RELATIVE_FATHER_OFFSET),#defined in module_constants.py
  64710. (troop_set_slot, ":troop_1", slot_troop_father, ":janakir_khan"),
  64711. (troop_set_slot, ":troop_2", slot_troop_father, ":janakir_khan"),
  64712. #Differentiate their mothers, so they are half-brothers instead of full-brothers
  64713. (try_begin),
  64714. (troop_slot_eq, ":troop_1", slot_troop_mother, -1),
  64715. (store_mul, reg0, ":troop_1", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),
  64716. (val_add, reg0, DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),
  64717. (troop_set_slot, ":troop_1", slot_troop_mother, reg0),
  64718. (try_end),
  64719. (try_begin),
  64720. (troop_slot_eq, ":troop_2", slot_troop_mother, -1),
  64721. (store_mul, reg0, ":troop_2", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),
  64722. (val_add, reg0, DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),
  64723. (troop_set_slot, ":troop_2", slot_troop_mother, reg0),
  64724. (try_end),
  64725. (try_end),
  64726. (try_end),
  64727. (try_end),
  64728. ##Add uncles and aunts by marriage.
  64729. ##In Native, the relation strength for blood uncles/aunts is 4, and for cousins is 2.
  64730. ##In light of this I've decided to set the relation strength for aunts/uncles by marriage to 2.
  64731. (try_begin),
  64732. (lt, ":relation_strength", 2),#Skip this check if a stronger relation has been found.
  64733. #Test if troop_1 is married to a sibling of one of troop_2's parents, pt. 1
  64734. (ge, ":spouse_of_1", 0),
  64735. (neg|troop_slot_eq, ":spouse_of_1", slot_troop_father, -1),
  64736. (this_or_next|troop_slot_eq, ":spouse_of_1", slot_troop_father, ":paternal_grandfather_of_2"),
  64737. (troop_slot_eq, ":spouse_of_1", slot_troop_father, ":maternal_grandfather_of_2"),
  64738. (assign, ":relation_strength", 2),
  64739. (try_begin),
  64740. (eq, ":gender_1", tf_female),
  64741. (assign, ":relation_string", "str_aunt"),
  64742. (else_try),
  64743. (assign, ":relation_string", "str_uncle"),
  64744. (try_end),
  64745. (else_try),
  64746. (lt, ":relation_strength", 2),#Skip this check if a stronger relation has been found.
  64747. #Test if troop_1 is married to a sibling of one of troop_2's parents, pt. 2
  64748. (ge, ":spouse_of_1", 0),
  64749. (neg|troop_slot_eq, ":spouse_of_1", slot_troop_mother, -1),
  64750. (this_or_next|troop_slot_eq, ":spouse_of_1", slot_troop_mother, ":paternal_grandmother_of_2"),
  64751. (troop_slot_eq, ":spouse_of_1", slot_troop_mother, ":maternal_grandmother_of_2"),
  64752. (assign, ":relation_strength", 2),
  64753. (try_begin),
  64754. (eq, ":gender_1", tf_female),
  64755. (assign, ":relation_string", "str_aunt"),
  64756. (else_try),
  64757. (assign, ":relation_string", "str_uncle"),
  64758. (try_end),
  64759. (else_try),
  64760. (lt, ":relation_strength", 2),#Skip this check if a stronger relation has been found.
  64761. #Test if troop_2 is married to a sibling of one of troop_1's parents, pt. 1
  64762. (ge, ":spouse_of_2", 0),
  64763. (neg|troop_slot_eq, ":spouse_of_2", slot_troop_father, -1),
  64764. (this_or_next|troop_slot_eq, ":spouse_of_2", slot_troop_father, ":paternal_grandfather_of_1"),
  64765. (troop_slot_eq, ":spouse_of_2", slot_troop_father, ":maternal_grandfather_of_1"),
  64766. (assign, ":relation_strength", 2),
  64767. (try_begin),
  64768. (eq, ":gender_1", tf_female),
  64769. (assign, ":relation_string", "str_niece"),
  64770. (else_try),
  64771. (assign, ":relation_string", "str_nephew"),
  64772. (try_end),
  64773. (else_try),
  64774. (lt, ":relation_strength", 2),#Skip this check if a stronger relation has been found.
  64775. #Test if troop_2 is married to a sibling of one of troop_1's parents, pt. 2
  64776. (ge, ":spouse_of_2", 0),
  64777. (neg|troop_slot_eq, ":spouse_of_2", slot_troop_mother, -1),
  64778. (this_or_next|troop_slot_eq, ":spouse_of_2", slot_troop_mother, ":paternal_grandmother_of_1"),
  64779. (troop_slot_eq, ":spouse_of_2", slot_troop_mother, ":maternal_grandmother_of_1"),
  64780. (assign, ":relation_strength", 2),
  64781. (try_begin),
  64782. (eq, ":gender_1", tf_female),
  64783. (assign, ":relation_string", "str_niece"),
  64784. (else_try),
  64785. (assign, ":relation_string", "str_nephew"),
  64786. (try_end),
  64787. (try_end),
  64788.  
  64789. (try_begin),
  64790. (this_or_next|neg|troop_is_hero, ":troop_1"),
  64791. (neg|troop_is_hero, ":troop_2"),
  64792. (assign, ":relation_string", "str_no_relation"),
  64793. (assign, ":relation_strength", 0),
  64794. (try_end),
  64795.  
  64796. (assign, reg0, ":relation_strength"),
  64797. (assign, reg1, ":relation_string"),
  64798. ]),
  64799.  
  64800. ##"script_cf_dplmc_faction_has_bias_against_gender"
  64801. ("cf_dplmc_faction_has_bias_against_gender", [
  64802. (store_script_param_1, ":faction_no"),
  64803. (store_script_param_2, ":test_gender"),#Special: 1 is female
  64804.  
  64805. (assign, reg0, 0),
  64806. (lt, "$g_disable_condescending_comments", 2),#If bias is disabled, do not continue
  64807. (is_between, ":test_gender", 0, 2),#valid genders are 0 and 1
  64808.  
  64809. (try_begin),
  64810. (eq, ":faction_no", "fac_player_supporters_faction"),
  64811. (is_between, "$players_kingdom", npc_kingdoms_begin, npc_kingdoms_end),
  64812. (assign, ":faction_no", "$players_kingdom"),
  64813. (try_end),
  64814.  
  64815. (try_begin),
  64816. #For a-typical factions, nothing by default.
  64817. (neg|is_between, ":faction_no", npc_kingdoms_begin, npc_kingdoms_end),
  64818. (else_try),
  64819. #If the leader has that gender, no prejudice.
  64820. (faction_get_slot, ":active_npc", ":faction_no", slot_faction_leader),
  64821. (gt, ":active_npc", -1),
  64822. (call_script, "script_dplmc_store_troop_is_female", ":active_npc"),
  64823. (eq, reg0, ":test_gender"),
  64824. (assign, reg0, 0),
  64825. (else_try),
  64826. #Traditional gender prejudice if both are true:
  64827. #1. The faction has no original members of the specified gender.
  64828. #2. The faction has original members with non-accepting lord personalities.
  64829.  
  64830. (assign, ":num_closeminded", 0),
  64831. (assign, ":end_cond", active_npcs_end),
  64832.  
  64833. (try_for_range, ":active_npc", active_npcs_begin, ":end_cond"),#Deliberately do not include kingdom ladies
  64834. #Also deliberately exclude companions and pretenders
  64835. #(Pretenders are marginalized at the start of the game, and
  64836. #companions don't necessarily start in positions of power either)
  64837. (this_or_next|is_between, ":active_npc", kings_begin, kings_end),
  64838. (is_between, ":active_npc", lords_begin, lords_end),
  64839. (troop_slot_eq, ":active_npc", slot_troop_original_faction, ":faction_no"),
  64840.  
  64841. (call_script, "script_dplmc_store_troop_is_female", ":active_npc"),
  64842. (try_begin),
  64843. (eq, reg0, ":test_gender"),
  64844. (assign, ":num_closeminded", -1000),
  64845. (assign, ":end_cond", ":active_npc"),
  64846. (else_try),
  64847. (troop_get_slot, reg0, ":active_npc", slot_lord_reputation_type),
  64848. (is_between, reg0, lrep_none + 1, lrep_roguish),#Lord (non-commoner, non-liege, non-lady) personality type
  64849. (neq, reg0, lrep_cunning),
  64850. (neq, reg0, lrep_goodnatured),
  64851. (val_add, ":num_closeminded", 1),
  64852. (try_end),
  64853. (try_end),
  64854.  
  64855. (store_sub, reg0, ":num_closeminded", 1),#Needs at least one
  64856. (val_clamp, reg0, 0, 2),
  64857. (try_end),
  64858.  
  64859. (try_begin),
  64860. (ge, "$cheat_mode", 1),
  64861. (assign, ":end_cond", reg1),#just save reg1 and reg2 (ignore the normal meaning of the variable names)
  64862. (assign, ":active_npc", reg2),
  64863. (assign, reg1, ":faction_no"),
  64864. (assign, reg2, ":test_gender"),
  64865. (display_message, "@{!} Checked if faction {reg1} is prejudiced against {reg2?women:men}: {reg0?true:false}"),
  64866. (assign, reg1, ":end_cond"),#revert reg1 and reg2 (ignore the normal meaning of the variable names)
  64867. (assign, reg2, ":active_npc"),
  64868. (try_end),
  64869. (gt, reg0, 0),
  64870. ]),
  64871.  
  64872. #"script_dplmc_store_troop_personality_caution_level"
  64873. #
  64874. # INPUT:
  64875. # arg1 :troop_no
  64876. # OUTPUT:
  64877. # reg0 -1 for aggressive
  64878. # 0 for neither
  64879. # 1 for cautious
  64880. ("dplmc_store_troop_personality_caution_level", [
  64881. #Used a number of places to determine whether a lord is cautious
  64882. #or aggressive. The standard is something like:
  64883. #
  64884. #For cautious:
  64885. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_upstanding),
  64886. # (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_debauched),
  64887. # (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_goodnatured),
  64888. # (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_cunning),
  64889. #
  64890. #For aggressive:
  64891. #(this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_martial),
  64892. # (this_or_next|troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_quarrelsome),
  64893. # (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_selfrighteous),
  64894. #
  64895. #I've expanded this for companion/lady personalities.
  64896. #The result can be either:
  64897. # -1 = aggressive
  64898. # 0 = neutral
  64899. # 1 = cautious
  64900. (store_script_param_1, ":troop_no"),
  64901.  
  64902. (try_begin),
  64903. (neg|is_between, ":troop_no", heroes_begin, heroes_end),#The player or troops that don't have slot_lord_reputation_type
  64904. (assign, reg0, 0),#neither cautious nor aggressive
  64905. (else_try),
  64906. (call_script, "script_dplmc_get_troop_morality_value", ":troop_no", tmt_aristocratic),
  64907. (lt, reg0, 0),#compliments when the player retreats
  64908. (assign, reg0, 1),#cautious
  64909. (else_try),
  64910. (gt, reg0, 0),#complains when the player retreats
  64911. (assign, reg0, -1),#aggressive
  64912. (else_try),
  64913. (troop_get_slot, ":reputation", ":troop_no", slot_lord_reputation_type),
  64914. (this_or_next|eq, ":reputation", lrep_adventurous),
  64915. (this_or_next|eq, ":reputation", lrep_martial),
  64916. (this_or_next|eq, ":reputation", lrep_quarrelsome),
  64917. (eq, ":reputation", lrep_selfrighteous),
  64918. (assign, reg0, -1),#aggressive
  64919. (else_try),
  64920. (this_or_next|ge, ":reputation", lrep_conventional),
  64921. (this_or_next|eq, ":reputation", lrep_upstanding),
  64922. (this_or_next|eq, ":reputation", lrep_debauched),
  64923. (this_or_next|eq, ":reputation", lrep_goodnatured),
  64924. (eq, ":reputation", lrep_cunning),
  64925. (assign, reg0, 1),#cautious
  64926. (else_try),
  64927. (assign, reg0, 0),#neither cautious nor aggressive
  64928. (try_end),
  64929. ]),
  64930.  
  64931. ##"script_dplmc_cap_troop_describes_troop_to_troop_s1"
  64932. #
  64933. # e.g.
  64934. #
  64935. #(call_script, "script_dplmc_cap_troop_describes_troop_to_troop_s1", 1, "trp_player", ":third_lord", "$g_talk_troop"),
  64936. #
  64937. #INPUT:
  64938. # arg1 :capitalization (0 if middle of sentence, 1 if sentence start)
  64939. # arg2 :speaker (the one doing the talking)
  64940. # arg3 :described (the one being named)
  64941. # arg4 :listener (the one being spoken to)
  64942. #
  64943. #OUTPUT:
  64944. # Writes result to s1, clobbers s0
  64945. #
  64946. #Similar to "script_troop_describes_troop_to_s15", except
  64947. #it takes into account the perspective of the one being
  64948. #spoken to, and writes to s1
  64949. ("dplmc_cap_troop_describes_troop_to_troop_s1",
  64950. [
  64951. (store_script_param, ":capitalization", 1),
  64952. (store_script_param, ":speaker", 2),
  64953. (store_script_param, ":described", 3),
  64954. (store_script_param, ":listener", 4),
  64955.  
  64956. (assign, ":save_reg0", reg0),
  64957. (assign, ":save_reg1", reg1),
  64958.  
  64959. (str_store_troop_name, s0, ":described"),
  64960.  
  64961. (assign, reg0, ":capitalization"),
  64962. (try_begin),
  64963. (eq, ":described", ":listener"),
  64964. (neq, ":speaker", ":listener"),
  64965. (str_store_string, s0, "@{reg0?Y:y}ou"),
  64966. (assign, reg0, 1),
  64967. (else_try),
  64968. (eq, ":described", ":speaker"),
  64969. (str_store_string, s0, "@{reg0?M:m}yself"),
  64970. (assign, reg0, 1),
  64971. (else_try),
  64972. (this_or_next|eq, ":described", "trp_player"),#only calculate family relationships for the player and heroes
  64973. (is_between, ":described", heroes_begin, heroes_end),
  64974. (assign, ":speaker_relation", 0),
  64975. (assign, ":speaker_relation_string", 0),
  64976. (try_begin),
  64977. (this_or_next|eq, ":speaker", "trp_player"),#only calculate family relationships for the player and heroes
  64978. (is_between, ":speaker", heroes_begin, heroes_end),
  64979. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":described", ":speaker"),
  64980. (assign, ":speaker_relation", reg0),
  64981. (assign, ":speaker_relation_string", reg1),
  64982. (try_end),
  64983. (assign, reg0, 0),
  64984. (try_begin),
  64985. (this_or_next|eq, ":described", "trp_player"),#only calculate family relationships for the player and heroes
  64986. (is_between, ":described", heroes_begin, heroes_end),
  64987. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":described", ":listener"),
  64988. (try_end),
  64989. (this_or_next|ge, ":speaker_relation", 1),
  64990. (ge, reg0, 1),
  64991. (try_begin),
  64992. (eq, ":speaker_relation", reg0),
  64993. (eq, reg1, ":speaker_relation_string"),
  64994. (neq, ":speaker", ":listener"),
  64995. (assign, reg0, ":capitalization"),
  64996. (str_store_string, s1, ":speaker_relation_string"),
  64997. (str_store_string, s1, "@{reg0?O:o}ur {s1} {s0}"),
  64998. (else_try),
  64999. (ge, ":speaker_relation", reg0),
  65000. (assign, reg0, ":capitalization"),
  65001. (str_store_string, s1, ":speaker_relation_string"),
  65002. (str_store_string, s1, "@{reg0?M:m}y {s1} {s0}"),
  65003. (else_try),
  65004. (assign, reg0, ":capitalization"),
  65005. (str_store_string, s1, reg1),
  65006. (str_store_string, s1, "@{reg0?Y:y}our {s1} {s0}"),
  65007. (try_end),
  65008. ###Disable "marshall/liege", because that's done elsewhere anyway
  65009. #(else_try),
  65010. # (store_faction_of_troop, ":speaker_faction", ":speaker"),
  65011. # (try_begin),
  65012. # (eq, ":speaker", "trp_player"),
  65013. # (assign, ":speaker_faction", "$players_kingdom"),
  65014. # (try_end),
  65015. #
  65016. # (store_faction_of_troop, ":listener_faction", ":listener"),
  65017. # (try_begin),
  65018. # (eq, ":listener", "trp_player"),
  65019. # (assign, ":listener_faction", "$players_kingdom"),
  65020. # (try_end),
  65021. #
  65022. # (faction_slot_eq, ":speaker_faction", slot_faction_leader, ":described"),
  65023. # (this_or_next|is_between, ":speaker_faction", npc_kingdoms_begin, npc_kingdoms_end),
  65024. # (faction_slot_eq, ":speaker_faction", slot_faction_state, sfs_active),
  65025. # (this_or_next|neq, ":described", "trp_player"),
  65026. # (eq, ":speaker_faction", "$players_kingdom"),
  65027. # (assign, reg0, ":capitalization"),
  65028. # (try_begin),
  65029. # (eq, ":speaker_faction", ":listener_faction"),
  65030. # (neq, ":speaker", ":listener"),
  65031. # (str_store_string, s1, "@{reg0?O:o}ur liege {s0}"),
  65032. # (else_try),
  65033. # (str_store_string, s1, "@{reg0?M:m}y liege {s0}"),
  65034. # (try_end),
  65035. #(else_try),
  65036. # (faction_slot_eq, ":speaker_faction", slot_faction_marshall, ":described"),
  65037. # (this_or_next|is_between, ":speaker_faction", npc_kingdoms_begin, npc_kingdoms_end),
  65038. # (faction_slot_eq, ":speaker_faction", slot_faction_state, sfs_active),
  65039. # (this_or_next|neq, ":described", "trp_player"),
  65040. # (eq, ":speaker_faction", "$players_kingdom"),
  65041. # (try_begin),
  65042. # (eq, ":speaker_faction", ":listener_faction"),
  65043. # (neq, ":speaker", ":listener"),
  65044. # (str_store_string, s1, "@{reg0?O:o}ur marshall {s0}"),
  65045. # (else_try),
  65046. # (str_store_string, s1, "@{reg0?M:m}y marshall {s0}"),
  65047. # (try_end),
  65048. #(else_try),
  65049. # (this_or_next|is_between, ":listener_faction", npc_kingdoms_begin, npc_kingdoms_end),
  65050. # (faction_slot_eq, ":listener_faction", slot_faction_state, sfs_active),
  65051. # (faction_slot_eq, ":listener_faction", slot_faction_leader, ":described"),
  65052. # (this_or_next|neq, ":described", "trp_player"),
  65053. # (eq, ":listener_faction", "$players_kingdom"),
  65054. # (assign, reg0, ":capitalization"),
  65055. # (str_store_string, s1, "@{reg0?Y:y}our liege {s0}"),
  65056.  
  65057. ###Disable "friend", because it gets really spammy. (It looks really stupid to have
  65058. ###a list of fifty names, all of them starting with "Your Friend So-and-So".)
  65059. #(else_try),
  65060. # (call_script, "script_troop_get_relation_with_troop", ":described", ":listener"),
  65061. # (ge, reg0, 20),
  65062. # (this_or_next|neq, ":listener", "trp_player"),
  65063. # (ge, reg0, 50),
  65064. # (call_script, "script_troop_get_relation_with_troop", ":described", ":speaker"),
  65065. # (this_or_next|neq, ":listener", "trp_player"),
  65066. # (neq, ":speaker_trp_player"),
  65067. # (try_begin),
  65068. # (ge, reg0, 20),
  65069. # (this_or_next|neq, ":speaker", "trp_player"),
  65070. # (ge, reg0, 50),
  65071. # (assign, reg0, ":capitalization"),
  65072. # (str_store_string, s1, "@{reg0?O:o}ur friend {s0}"),
  65073. # (else_try),
  65074. # (assign, reg0, ":capitalization"),
  65075. # (str_store_string, s1, "@{reg0?Y:y}our friend {s0}"),
  65076. # (try_end),
  65077. #(else_try),
  65078. # (call_script, "script_troop_get_relation_with_troop", ":described", ":speaker"),
  65079. # (ge, reg0, 20),
  65080. # (this_or_next|neq, ":speaker", "trp_player"),
  65081. # (ge, reg0, 50),
  65082. # (assign, reg0, ":capitalization"),
  65083. # (str_store_string, s1, "@{reg0?M:m}y friend {s0}"),
  65084.  
  65085. ###The "<Jarl Aedin> of <Tihr>" condition works fine, but I'm not particularly impressed.
  65086. ###I'm not sure it's an improvement over just using their name, so I'm disabling it for now.
  65087. #(else_try),
  65088. # #Did not use relation string: name by owned town.
  65089. # #Do not use names of castles, due to potential absurdities like "Count Harringoth of Harringoth Castle".
  65090. # #Skip kings and pretenders because of "Lady Isolla of Suno of Suno" and similar things.
  65091. # (neg|is_between, ":described", kings_begin, kings_end),
  65092. # (neg|is_between, ":described", pretenders_begin, pretenders_end),
  65093. # (this_or_next|eq, ":described", "trp_player"),
  65094. # (is_between, ":described", heroes_begin, heroes_end),
  65095. #
  65096. # (assign, ":owned_town", -1),
  65097. # (assign, ":owned_town_score", -1),
  65098. # (troop_get_slot, ":original_faction", ":described", slot_troop_original_faction),
  65099. # (try_for_range, ":town_no", towns_begin, towns_end),
  65100. # (party_get_slot, ":town_lord", ":town_no", slot_town_lord),
  65101. # (ge, ":town_lord", 0),
  65102. # (assign, reg0, 0),
  65103. # (try_begin),
  65104. # (eq, ":town_lord", ":described"),
  65105. # (assign, reg0, 10),
  65106. # (else_try),
  65107. # (this_or_next|troop_slot_eq, ":town_lord", slot_troop_spouse, ":described"),
  65108. # (troop_slot_eq, ":described", slot_troop_spouse, ":town_lord"),
  65109. # (this_or_next|is_between, ":described", kingdom_ladies_begin, kingdom_ladies_end),
  65110. # (troop_slot_eq, ":described", slot_troop_occupation, slto_kingdom_lady),
  65111. # (assign, reg0, 1),
  65112. # (else_try),
  65113. # (assign, reg0, 0),
  65114. # (try_end),
  65115. # (gt, reg0, 0),
  65116. # (try_begin),
  65117. # (party_slot_eq, ":town_no", slot_center_original_faction, ":original_faction"),
  65118. # (val_add, reg0, 1),
  65119. # (try_end),
  65120. # (try_begin),
  65121. # (this_or_next|party_slot_eq, ":town_no", dplmc_slot_center_original_lord, ":described"),
  65122. # (party_slot_eq, ":town_no", dplmc_slot_center_original_lord, ":town_lord"),
  65123. # (val_add, reg0, 2),
  65124. # (try_end),
  65125. # (try_begin),
  65126. # (this_or_next|troop_slot_eq, ":town_lord", slot_troop_home, ":town_no"),
  65127. # (troop_slot_eq, ":town_lord", slot_troop_home, ":town_no"),
  65128. # (val_add, reg0, 2),
  65129. # (try_end),
  65130. # (gt, reg0, ":owned_town_score"),
  65131. # (assign, ":owned_town_score", reg0),
  65132. # (assign, ":owned_town", ":town_no"),
  65133. # (try_end),
  65134. # (is_between, ":owned_town", towns_begin, towns_end),
  65135. # (str_store_party_name, s1, ":owned_town"),
  65136. # (str_store_string, s1, "@{s0} of {s1}"),
  65137. (else_try),
  65138. (str_store_string, s1, "str_s0"),
  65139. (try_end),
  65140.  
  65141. (assign, reg0, ":save_reg0"),
  65142. (assign, reg1, ":save_reg1"),
  65143. (str_store_string_reg, s0, s1),
  65144. ]),
  65145.  
  65146. ##"script_dplmc_helper_get_troop1_troop2_family_slot_aux"
  65147. ##
  65148. ## Helper function that does something specific that I want in
  65149. ## script_dplmc_troop_get_family_relation_to_troop.
  65150. ##
  65151. ## Gets the slot value, but for troops that aren't trp_player
  65152. ## and are not within (heroes_begin, heroes_end), values of "0"
  65153. ## are transformed to -1. Also gives a result of -1 (instead of
  65154. ## an error) for negative troop IDs, which is what I want in
  65155. ## this situation (otherwise I'd be explicitly checking this and
  65156. ## setting the result to -1 if it was bad).
  65157. ##
  65158. ## Also, values equal to "active_npcs_including_player_begin" are
  65159. ## transformed to "trp_player" (i.e. 0), to allow storing that
  65160. ## value.
  65161. ##
  65162. ##INPUT: arg1 :troop_1
  65163. ## arg2 :troop_2
  65164. ## arg3 :slot_no
  65165. ##
  65166. ##OUTPUT: reg0 value of slot for troop_1, or -1
  65167. ## reg1 value of slot for troop_2, or -1
  65168. ("dplmc_helper_get_troop1_troop2_family_slot_aux",
  65169. [
  65170. (store_script_param, ":troop_1", 1),
  65171. (store_script_param, ":troop_2", 2),
  65172. (store_script_param, ":slot_no", 3),
  65173.  
  65174. #(1) Get the value for the first troop into reg0
  65175. (try_begin),
  65176. #Negative numbers are placeholders for invalid family members
  65177. (lt, ":troop_1", 0),
  65178. (assign, reg0, -1),
  65179. (else_try),
  65180. #For active_npcs_including_player_begin, use the family slot from trp_player
  65181. (eq, ":troop_1", active_npcs_including_player_begin),
  65182. (troop_get_slot, reg0, "trp_player", ":slot_no"),
  65183. (else_try),
  65184. #Otherwise get the family member slot
  65185. (troop_get_slot, reg0, ":troop_1", ":slot_no"),
  65186. #However, for non-heroes, the memory might not be initialized,
  65187. #so don't take a value of 0 at face-value.
  65188. (eq, reg0, 0),
  65189. (neg|is_between, ":troop_1", heroes_begin, heroes_end),
  65190. (neq, ":troop_1", "trp_player"),
  65191. (assign, reg0, -1),
  65192. (try_end),
  65193.  
  65194. #Translate from active_npcs_including_player_begin to trp_player
  65195. (try_begin),
  65196. (eq, reg0, active_npcs_including_player_begin),
  65197. (assign, reg0, "trp_player"),
  65198. (try_end),
  65199.  
  65200. #(2) Get the value for the second troop into reg1
  65201. (try_begin),
  65202. #Negative numbers are placeholders for invalid family members
  65203. (lt, ":troop_2", 0),
  65204. (assign, reg1, -1),
  65205. (else_try),
  65206. #For active_npcs_including_player_begin, use the family slot from trp_player
  65207. (eq, ":troop_2", active_npcs_including_player_begin),
  65208. (troop_get_slot, reg1, "trp_player", ":slot_no"),
  65209. (else_try),
  65210. #Otherwise get the family member slot
  65211. (troop_get_slot, reg1, ":troop_2", ":slot_no"),
  65212. #However, for non-heroes, the memory might not be initialized,
  65213. #so don't take a value of 0 at face-value.
  65214. (eq, reg1, 0),
  65215. (neg|is_between, ":troop_2", heroes_begin, heroes_end),
  65216. (neq, ":troop_2", "trp_player"),
  65217. (assign, reg1, -1),
  65218. (try_end),
  65219.  
  65220. #Translate from active_npcs_including_player_begin to trp_player
  65221. (try_begin),
  65222. (eq, reg1, active_npcs_including_player_begin),
  65223. (assign, reg1, "trp_player"),
  65224. (try_end),
  65225. ]),
  65226.  
  65227. ##"script_dplmc_estimate_center_weekly_income"
  65228. #
  65229. # INPUT: arg1 :center_no
  65230. # OUTPUT: reg0 estimated value of weekly income
  65231. #
  65232. #TODO: Add a better explanation for why this function does not include tarrifs.
  65233. ("dplmc_estimate_center_weekly_income", [
  65234. (store_script_param_1, ":center_no"),
  65235. (party_get_slot, ":prosperity", ":center_no", slot_town_prosperity),
  65236. (try_begin),
  65237. #If there is some sort of aberration, assign to 50 instead of
  65238. #clamping, on the assumption that the value bears no relation
  65239. #to the true prosperity at all.
  65240. (neg|is_between, ":prosperity", 0, 101),
  65241. (assign, ":prosperity", 50),
  65242. (try_end),
  65243. (store_add, reg0, 20, ":prosperity"),
  65244. (val_mul, reg0, 1200),
  65245. (val_div, reg0, 120),
  65246. (try_begin),
  65247. (party_slot_eq, ":center_no", slot_party_type, spt_town),
  65248. #Towns have higher base rent than castles and villages
  65249. (val_mul, reg0, 2),
  65250. #Include town garrison allowance
  65251. (val_mul, ":prosperity", 15),
  65252. (val_add, ":prosperity", 700),
  65253. (val_mul, ":prosperity", 3),
  65254. (val_div, ":prosperity", 2),
  65255. (val_add, reg0, ":prosperity"),
  65256. (else_try),
  65257. (party_slot_eq, ":center_no", slot_party_type, spt_castle),
  65258. #Include castle garrison allowance
  65259. (val_mul, ":prosperity", 15),
  65260. (val_add, ":prosperity", 700),
  65261. (val_add, reg0, ":prosperity"),
  65262. (try_end),
  65263. #At this point, the final result is in reg0.
  65264. ]),
  65265.  
  65266. # "script_dplmc_get_closest_center_or_two"
  65267. # Input: arg1 = party_no
  65268. # Output: reg0 = center_no (closest)
  65269. # reg1 = center_no2 (another close center or -1)
  65270. #
  65271. # If reg1 is non-negative, it should make some sense to say "<party_no> is
  65272. # between <reg0> and <reg1>".
  65273. #
  65274. # The way I do this is:
  65275. # 1. Find the closest center to the party.
  65276. # 2. Excluding the center from (1), find the closest center to the
  65277. # party which is not closer to the center from (1) than it is to
  65278. # the party. (There might not be any centers matching this
  65279. # description.)
  65280. #
  65281. # If the party is much closer to center_1 than center_2, I discard
  65282. # the second center. (The rationale is that if I'm standing on my
  65283. # doorstep, it is be helpful to say "I am between my house and the
  65284. # grocery store". It is less misleading to just say "I am near my
  65285. # house.")
  65286. ("dplmc_get_closest_center_or_two",
  65287. [
  65288. (store_script_param_1, ":party_no"),
  65289. (call_script, "script_get_closest_center", ":party_no"),#writes closest center to reg0
  65290. (store_distance_to_party_from_party, ":distance_to_beat", ":party_no", reg0),
  65291. (val_mul, ":distance_to_beat", 2),
  65292. (val_add, ":distance_to_beat", 1),
  65293.  
  65294. (assign, reg1, -1),
  65295. (try_for_range, ":center_no", centers_begin, centers_end),
  65296. (neq, ":center_no", reg0),
  65297. (store_distance_to_party_from_party, ":party_to_center_distance", ":party_no", ":center_no"),
  65298. (lt, ":party_to_center_distance", ":distance_to_beat"),
  65299. (store_distance_to_party_from_party, ":center_to_center_distance", reg0, ":center_no"),
  65300. (gt, ":center_to_center_distance", ":party_to_center_distance"),
  65301. (assign, ":distance_to_beat", ":party_to_center_distance"),
  65302. (assign, reg1, ":center_no"),
  65303. (try_end),
  65304. ]),
  65305.  
  65306.  
  65307. # Jrider +
  65308. ###################################################################################
  65309. # REPORT PRESENTATIONS v1.2 scripts
  65310. # Script overlay_container_add_listbox_item
  65311. # use ...
  65312. # return ...
  65313. ("overlay_container_add_listbox_item", [
  65314. (store_script_param, ":line_y", 1),
  65315. (store_script_param, ":npc_id", 2),
  65316.  
  65317. (set_container_overlay, "$g_jrider_character_relation_listbox"),
  65318.  
  65319. # create text overlay for entry
  65320. (create_text_overlay, reg10, s1, tf_left_align),
  65321. (overlay_set_color, reg10, 0xDDDDDD),
  65322. (position_set_x, pos1, 650),
  65323. (position_set_y, pos1, 750),
  65324. (overlay_set_size, reg10, pos1),
  65325. (position_set_x, pos1, 0),
  65326. (position_set_y, pos1, ":line_y"),
  65327. (overlay_set_position, reg10, pos1),
  65328.  
  65329. # create button
  65330. (create_image_button_overlay, reg10, "mesh_white_plane", "mesh_white_plane"),
  65331. (position_set_x, pos1, 0), # 590 real, 0 scrollarea
  65332. (position_set_y, pos1, ":line_y"),
  65333. (overlay_set_position, reg10, pos1),
  65334. (position_set_x, pos1, 16000),
  65335. (position_set_y, pos1, 750),
  65336. (overlay_set_size, reg10, pos1),
  65337. (overlay_set_alpha, reg10, 0),
  65338. (overlay_set_color, reg10, 0xDDDDDD),
  65339.  
  65340. # store relation of button id to character number for use in triggers
  65341. (store_add, ":current_storage_index", "$g_base_character_presentation_storage_index", reg10),
  65342. (troop_set_slot, "trp_temp_array_b", ":current_storage_index", "$num_charinfo_candidates"),
  65343.  
  65344. # reset variables if appropriate flags are up
  65345. (try_begin),
  65346. (try_begin),
  65347. (this_or_next|eq, "$g_jrider_pres_called_from_menu", 1),
  65348. (ge, "$g_jrider_reset_selected_on_faction", 1),
  65349.  
  65350. (assign, "$character_info_id", ":npc_id"),
  65351. (assign, "$g_jrider_last_checked_indicator", reg10),
  65352. (assign, "$g_latest_character_relation_entry", "$num_charinfo_candidates"),
  65353. (try_end),
  65354. (try_end),
  65355.  
  65356. # close the container
  65357. (set_container_overlay, -1),
  65358. ]),
  65359.  
  65360. # script get_relation_candidate_list_for_presentation
  65361. # return a list of candidate according to type of list and restrict options
  65362. # Use ...
  65363. ("fill_relation_canditate_list_for_presentation",
  65364. [
  65365. (store_script_param, ":pres_type", 1),
  65366. (store_script_param, ":base_candidates_y", 2),
  65367.  
  65368. # Type of list from global variable: 0 courtship, 1 known lords
  65369. (try_begin),
  65370. ## For courtship:
  65371. (eq, ":pres_type", 0),
  65372.  
  65373. (try_for_range_backwards, ":lady", kingdom_ladies_begin, kingdom_ladies_end),
  65374. (troop_slot_ge, ":lady", slot_troop_met, 1), # met or better
  65375. (troop_slot_eq, ":lady", slot_troop_spouse, -1), # unmarried
  65376.  
  65377. # use faction filter
  65378. (store_troop_faction, ":lady_faction", ":lady"),
  65379. (val_sub, ":lady_faction", kingdoms_begin),
  65380. (this_or_next|eq, "$g_jrider_faction_filter", -1),
  65381. (eq, "$g_jrider_faction_filter", ":lady_faction"),
  65382.  
  65383. (call_script, "script_troop_get_relation_with_troop", "trp_player", ":lady"),
  65384. (gt, reg0, 0),
  65385. (assign, reg3, reg0),
  65386.  
  65387. (str_store_troop_name, s2, ":lady"),
  65388.  
  65389. (store_current_hours, ":hours_since_last_visit"),
  65390. (troop_get_slot, ":last_visit_hour", ":lady", slot_troop_last_talk_time),
  65391. (val_sub, ":hours_since_last_visit", ":last_visit_hour"),
  65392. (store_div, ":days_since_last_visit", ":hours_since_last_visit", 24),
  65393. (assign, reg4, ":days_since_last_visit"),
  65394.  
  65395. #(str_store_string, s1, "str_s1_s2_relation_reg3_last_visit_reg4_days_ago"),
  65396. (str_store_string, s1, "@{s2}: {reg3}, {reg4} days"),
  65397.  
  65398. # create custom listbox entry, set the container first
  65399. (store_mul, ":y_mult", "$num_charinfo_candidates", 16), # adapt y position to entry number, was 18
  65400. (store_add, ":line_y", ":base_candidates_y", ":y_mult"),
  65401.  
  65402. (call_script, "script_overlay_container_add_listbox_item", ":line_y", ":lady"),
  65403.  
  65404. # candidate found, store troop id for later use
  65405. (store_add, ":current_storage_index", "$g_base_character_presentation_storage_index", "$num_charinfo_candidates"),
  65406. (troop_set_slot, "trp_temp_array_c", ":current_storage_index", ":lady"),
  65407.  
  65408. # update entry counter
  65409. (val_add, "$num_charinfo_candidates", 1),
  65410. (try_end),
  65411. ## End courtship relations
  65412. (else_try),
  65413. ## For lord relations
  65414. (eq, ":pres_type", 1),
  65415.  
  65416. # Loop to identify
  65417. (try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
  65418. (troop_set_slot, ":active_npc", slot_troop_temp_slot, 0),
  65419. (try_end),
  65420.  
  65421. (try_for_range, ":unused", active_npcs_begin, active_npcs_end),
  65422.  
  65423. (assign, ":score_to_beat", 101),
  65424. (assign, ":best_relation_remaining_npc", -1),
  65425.  
  65426. (try_for_range, ":active_npc", active_npcs_begin, active_npcs_end),
  65427. (troop_slot_eq, ":active_npc", slot_troop_temp_slot, 0),
  65428. (troop_slot_ge, ":active_npc", slot_troop_met, 1),
  65429. (troop_slot_eq, ":active_npc", slot_troop_occupation, slto_kingdom_hero),
  65430.  
  65431. (call_script, "script_troop_get_player_relation", ":active_npc"),
  65432. (assign, ":relation_with_player", reg0),
  65433. (le, ":relation_with_player", ":score_to_beat"),
  65434.  
  65435. (assign, ":score_to_beat", ":relation_with_player"),
  65436. (assign, ":best_relation_remaining_npc", ":active_npc"),
  65437. (try_end),
  65438. (gt, ":best_relation_remaining_npc", -1),
  65439.  
  65440. (str_store_troop_name, s4, ":best_relation_remaining_npc"),
  65441. (assign, reg4, ":score_to_beat"),
  65442.  
  65443. (str_store_string, s1, "@{s4}: {reg4}"),
  65444. (troop_set_slot, ":best_relation_remaining_npc", slot_troop_temp_slot, 1),
  65445.  
  65446. # use faction filter
  65447. (store_troop_faction, ":npc_faction", ":best_relation_remaining_npc"),
  65448. (val_sub, ":npc_faction", kingdoms_begin),
  65449. (this_or_next|eq, "$g_jrider_faction_filter", -1),
  65450. (eq, "$g_jrider_faction_filter", ":npc_faction"),
  65451.  
  65452. # candidate found,
  65453. # create custom listbox entry, set the container first
  65454. (store_mul, ":y_mult", "$num_charinfo_candidates", 16), # adapt y position to entry number, was 18
  65455. (store_add, ":line_y", ":base_candidates_y", ":y_mult"),
  65456.  
  65457. (call_script, "script_overlay_container_add_listbox_item", ":line_y", ":best_relation_remaining_npc"),
  65458.  
  65459. #store troop id for later use (could be merged with the object id)
  65460. (store_add, ":current_storage_index", "$g_base_character_presentation_storage_index", "$num_charinfo_candidates"),
  65461. (troop_set_slot, "trp_temp_array_c", ":current_storage_index", ":best_relation_remaining_npc"),
  65462.  
  65463. # update entry counter
  65464. (val_add, "$num_charinfo_candidates", 1),
  65465. (try_end),
  65466. ## END Lords relations
  65467. (else_try),
  65468. ## Character and Companions
  65469. (eq, ":pres_type", 2),
  65470.  
  65471. # companions
  65472. (try_for_range_backwards, ":companion", companions_begin, companions_end),
  65473. (troop_slot_eq, ":companion", slot_troop_occupation, slto_player_companion),
  65474.  
  65475. (str_store_troop_name, s1, ":companion"),
  65476.  
  65477. (try_begin),
  65478. (troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_kingsupport),
  65479. (str_store_string, s1, "@{s1}(gathering support)"),
  65480. (else_try),
  65481. (troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_gather_intel),
  65482. (str_store_string, s1, "@{s1} (intelligence)" ),
  65483. (else_try),
  65484. (troop_slot_ge, ":companion", slot_troop_current_mission, npc_mission_peace_request),
  65485. (neg|troop_slot_eq, ":companion", slot_troop_current_mission, 8),
  65486. (str_store_string, s1, "@{s1} (ambassy)"),
  65487. (else_try),
  65488. (eq, ":companion", "$g_player_minister"),
  65489. (str_store_string, s1, "@{s1} (minister"),
  65490. (else_try),
  65491. (main_party_has_troop, ":companion"),
  65492. (str_store_string, s1, "@{s1} (under arms)"),
  65493. (else_try),
  65494. (troop_slot_eq, ":companion", slot_troop_current_mission, npc_mission_rejoin_when_possible),
  65495. (str_store_string, s1, "@{s1} (attempting to rejoin)"),
  65496. (else_try),
  65497. (troop_slot_ge, ":companion", slot_troop_cur_center, 1),
  65498. (str_store_string, s1, "@{s1} (separated after battle)"),
  65499. (try_end),
  65500. # candidate found,
  65501. # create custom listbox entry, set the container first
  65502. (store_mul, ":y_mult", "$num_charinfo_candidates", 16), # adapt y position to entry number, was 18
  65503. (store_add, ":line_y", ":base_candidates_y", ":y_mult"),
  65504.  
  65505. (call_script, "script_overlay_container_add_listbox_item", ":line_y", ":companion"),
  65506.  
  65507. #store troop id for later use (could be merged with the object id)
  65508. (store_add, ":current_storage_index", "$g_base_character_presentation_storage_index", "$num_charinfo_candidates"),
  65509. (troop_set_slot, "trp_temp_array_c", ":current_storage_index", ":companion"),
  65510.  
  65511. # update entry counter
  65512. (val_add, "$num_charinfo_candidates", 1),
  65513. (try_end),
  65514. # END companions
  65515.  
  65516. # Wife/Betrothed
  65517. # END Wife/Betrothed
  65518.  
  65519. (try_begin),
  65520. # Character
  65521. (str_store_troop_name, s1, "trp_player"),
  65522.  
  65523. # candidate found,
  65524. # create custom listbox entry, set the container first
  65525. (store_mul, ":y_mult", "$num_charinfo_candidates", 16), # adapt y position to entry number, was 18
  65526. (store_add, ":line_y", ":base_candidates_y", ":y_mult"),
  65527.  
  65528. (call_script, "script_overlay_container_add_listbox_item", ":line_y", "trp_player"),
  65529.  
  65530. #store troop id for later use (could be merged with the object id)
  65531. (store_add, ":current_storage_index", "$g_base_character_presentation_storage_index", "$num_charinfo_candidates"),
  65532. (troop_set_slot, "trp_temp_array_c", ":current_storage_index", "trp_player"),
  65533.  
  65534. # update entry counter
  65535. (val_add, "$num_charinfo_candidates", 1),
  65536. (try_end),
  65537. # End Character
  65538.  
  65539. (try_end),
  65540. ## END Character and Companions
  65541. ]),
  65542.  
  65543. # script get_troop_relation_to_player_string
  65544. # return relation to player string in the specified parameters
  65545. #
  65546. ("get_troop_relation_to_player_string",
  65547. [
  65548. (store_script_param, ":target_string", 1),
  65549. (store_script_param, ":troop_no", 2),
  65550.  
  65551. (call_script, "script_troop_get_player_relation", ":troop_no"),
  65552. (assign, ":relation", reg0),
  65553. (str_clear, s61),
  65554.  
  65555. (store_add, ":normalized_relation", ":relation", 100),
  65556. (val_add, ":normalized_relation", 5),
  65557. (store_div, ":str_offset", ":normalized_relation", 10),
  65558. (val_clamp, ":str_offset", 0, 20),
  65559. (store_add, ":str_rel_id", "str_relation_mnus_100_ns", ":str_offset"),
  65560.  
  65561. ## Make something if troop has relation but not strong enought to warrant a string
  65562. (try_begin),
  65563. (neq, ":str_rel_id", "str_relation_plus_0_ns"),
  65564. (str_store_string, s61, ":str_rel_id"),
  65565. (else_try),
  65566. (neg|eq, reg0, 0),
  65567. (str_is_empty, s61),
  65568. (str_store_string, s61, "@ knows of you."),
  65569. (else_try),
  65570. (eq, reg0, 0),
  65571. (str_is_empty, s61),
  65572. (str_store_string, s61, "@ has no opinion about you."),
  65573. (try_end),
  65574.  
  65575. ## copy result string to target string
  65576. (str_store_string_reg, ":target_string", s61),
  65577. ]),
  65578.  
  65579. # script get_troop_holdings
  65580. # returns number of fief and list name (reg50, s50)
  65581. ("get_troop_holdings",
  65582. [
  65583. (store_script_param, ":troop_no", 1),
  65584.  
  65585. (assign, ":owned_centers", 0),
  65586. (assign, ":num_centers", 0),
  65587. (try_for_range_backwards, ":cur_center", centers_begin, centers_end),
  65588. (party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
  65589. (try_begin),
  65590. (eq, ":num_centers", 0),
  65591. (str_store_party_name, s50, ":cur_center"),
  65592. (val_add, ":owned_centers", 1),
  65593. (else_try),
  65594. (eq, ":num_centers", 1),
  65595. (str_store_party_name, s57, ":cur_center"),
  65596. (str_store_string, s50, "@{s57} and {s50}"),
  65597. (val_add, ":owned_centers", 1),
  65598. (else_try),
  65599. (str_store_party_name, s57, ":cur_center"),
  65600. (str_store_string, s50, "@{!}{s57}, {s50}"),
  65601. (val_add, ":owned_centers", 1),
  65602. (try_end),
  65603. (val_add, ":num_centers", 1),
  65604. (try_end),
  65605. (assign, reg50, ":owned_centers"),
  65606. ]),
  65607.  
  65608. # script generate_extended_troop_relation_information_string
  65609. # return information about troop according to type (lord, lady, maiden)
  65610. # Use (hm lots of registers and strings)
  65611. # result stored in s1
  65612. ("generate_extended_troop_relation_information_string",
  65613. [
  65614. (store_script_param, ":troop_no", 1),
  65615.  
  65616. # clear the strings and registers we'll use to prevent external interference
  65617. (str_clear, s1),
  65618. (str_clear, s2),
  65619. (str_clear, s60),
  65620. (str_clear, s42),
  65621. (str_clear, s43),
  65622. (str_clear, s44),
  65623. (str_clear, s45),
  65624. (str_clear, s46),
  65625. (str_clear, s47),
  65626. (str_clear, s48),
  65627. (str_clear, s49),
  65628. (str_clear, s50),
  65629. (assign, reg40,0),
  65630. (assign, reg41,0),
  65631. (assign, reg43,0),
  65632. (assign, reg44,0),
  65633. (assign, reg46,0),
  65634. (assign, reg47,0),
  65635. (assign, reg48,0),
  65636. (assign, reg49,0),
  65637. (assign, reg50,0),
  65638. (assign, reg51,0),
  65639.  
  65640. (try_begin),
  65641. (eq, ":troop_no", "trp_player"),
  65642. (overlay_set_display, "$g_jrider_character_faction_filter", 0),
  65643.  
  65644. # Troop name
  65645. (str_store_troop_name, s1, ":troop_no"),
  65646.  
  65647. # Get renown - slot_troop_renown
  65648. (troop_get_slot, ":renown", ":troop_no", slot_troop_renown),
  65649. (assign, reg40, ":renown"),
  65650.  
  65651. # Controversy - slot_troop_controversy
  65652. (troop_get_slot, ":controversy", ":troop_no", slot_troop_controversy),
  65653. (assign, reg41, ":controversy"),
  65654.  
  65655. # Honor - $player_honor
  65656. (assign, reg42, "$player_honor"),
  65657.  
  65658. # Right to rule - $player_right_to_rule
  65659. (assign, reg43, "$player_right_to_rule"),
  65660.  
  65661. # Current faction
  65662. (store_add, reg45, "$players_kingdom"),
  65663. (try_begin),
  65664. (is_between, "$players_kingdom", "fac_player_supporters_faction", npc_kingdoms_end),
  65665. (str_store_faction_name, s45, "$players_kingdom"),
  65666. (else_try),
  65667. (assign, reg45, 0),
  65668. (str_store_string, s45, "@Calradia."),
  65669. (try_end),
  65670.  
  65671. # status
  65672. (assign, ":origin_faction", "$players_kingdom"),
  65673. #SB : gender strings
  65674. (try_begin),
  65675. (is_between, ":origin_faction", npc_kingdoms_begin, npc_kingdoms_end),
  65676. (str_store_string, s44, "@sworn {man/woman}"),
  65677. (else_try),
  65678. (eq, ":origin_faction", "fac_player_supporters_faction"),
  65679. (str_store_string, s44, "@ruler"),
  65680. (else_try),
  65681. (str_store_string, s44, "@free {man/woman}"),
  65682. (try_end),
  65683.  
  65684. # Current liege and relation
  65685. (faction_get_slot, ":liege", "$players_kingdom", slot_faction_leader),
  65686. (str_store_troop_name, s46, ":liege"),
  65687. (try_begin),
  65688. (eq, ":liege", ":troop_no"),
  65689. (assign, reg46, 0),
  65690. (else_try),
  65691. (assign, reg46, ":liege"),
  65692. (str_clear, s47),
  65693. (str_clear, s60),
  65694.  
  65695. # Relation to liege
  65696. (call_script, "script_get_troop_relation_to_player_string", s47, ":liege"),
  65697. (end_try),
  65698.  
  65699. # Holdings
  65700. (call_script, "script_get_troop_holdings", ":troop_no"),
  65701.  
  65702. #### Final Storage
  65703. (str_store_string, s1, "@{s1} Renown: {reg40}, Controversy: {reg41}^Honor: {reg42}, Right to rule: {reg43}^\
  65704. You are a {s44} of {s45}^{reg45?{reg46?Your liege, {s46},{s47}:You are the ruler of {s45}}:}^^Friends: ^Enemies: ^^Fiefs:^ {reg50?{s50}:no fief}"),
  65705. #######################
  65706. # END Player information
  65707. (else_try),
  65708. #######################
  65709. # Lord information
  65710. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  65711.  
  65712. # Troop name
  65713. (str_store_troop_name, s1, ":troop_no"),
  65714.  
  65715. # relation to player
  65716. (str_clear, s2),
  65717. (str_clear, s60),
  65718. (call_script, "script_get_troop_relation_to_player_string", s2, ":troop_no"),
  65719.  
  65720. # Get renown - slot_troop_renown
  65721. (troop_get_slot, ":renown", ":troop_no", slot_troop_renown),
  65722. (assign, reg40, ":renown"),
  65723.  
  65724. # Controversy - slot_troop_controversy
  65725. (troop_get_slot, ":controversy", ":troop_no", slot_troop_controversy),
  65726. (assign, reg41, ":controversy"),
  65727.  
  65728. # Get Reputation type - slot_lord_reputation_type
  65729. (troop_get_slot, ":reputation", ":troop_no", slot_lord_reputation_type),
  65730. (assign, reg42, "str_personality_archetypes"),
  65731. (val_add, reg42, ":reputation"),
  65732. (str_store_string, s42, reg42),
  65733.  
  65734. (assign, reg42, ":reputation"),
  65735. # Intrigue impatience - slot_troop_intrigue_impatience
  65736. (troop_get_slot, ":impatience", ":troop_no", slot_troop_intrigue_impatience),
  65737. (assign, reg43, ":impatience"),
  65738.  
  65739. # Current faction - store_troop_faction
  65740. (store_troop_faction, ":faction", ":troop_no"),
  65741. (troop_get_slot, ":origin_faction", ":troop_no", slot_troop_original_faction),
  65742.  
  65743. # Original faction - slot_troop_original_faction
  65744. (try_begin), #SB : do not display original faction string if same
  65745. (neq, ":faction", ":origin_faction"),
  65746. (val_sub, ":origin_faction", npc_kingdoms_begin),
  65747. (val_add, ":origin_faction", "str_kingdom_1_adjective"),
  65748. (str_store_string, s44, ":origin_faction"),
  65749. (assign, reg44, 1),
  65750. (else_try), #if same, start line with capitalized Noble
  65751. (assign, reg44, 0),
  65752. (try_end), #actually skip this line altogether if ruler
  65753. (str_store_faction_name, s45, ":faction"),
  65754.  
  65755. # Current liege - deduced from current faction
  65756. (faction_get_slot, ":liege", ":faction", slot_faction_leader),
  65757. (try_begin),
  65758. #When a member of a faction without a valid leader
  65759. (lt, ":liege", 0),
  65760. (assign, reg46, ":liege"),
  65761. (str_store_string, s46, "str_noone"),
  65762. (assign, reg47, 0),
  65763. (else_try),
  65764. (str_store_troop_name, s46, ":liege"),
  65765. (try_begin),
  65766. (eq, ":liege", ":troop_no"),
  65767. (assign, reg46, 0),
  65768. (else_try),
  65769. (assign, reg46, ":liege"),
  65770. # Relation to liege
  65771. (call_script, "script_troop_get_relation_with_troop", ":troop_no", ":liege"),
  65772. (assign, reg47, reg0),
  65773. (end_try),
  65774. (try_end),
  65775.  
  65776. # Promised a fief ?
  65777. (troop_get_slot, reg51, ":troop_no", slot_troop_promised_fief),
  65778.  
  65779. # Holdings
  65780. (call_script, "script_get_troop_holdings", ":troop_no"),
  65781.  
  65782. # slot_troop_prisoner_of_party
  65783. (assign, reg48, 0),
  65784. (try_begin),
  65785. (troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  65786. (assign, reg48, 1),
  65787. (troop_get_slot, ":prisoner_party", ":troop_no", slot_troop_prisoner_of_party),
  65788. (store_faction_of_party, ":party_faction", ":prisoner_party"),
  65789. (str_store_faction_name, s48, ":party_faction"),
  65790. (try_end),
  65791.  
  65792. # Days since last meeting
  65793. (store_current_hours, ":hours_since_last_visit"),
  65794. (troop_get_slot, ":last_visit_hour", ":troop_no", slot_troop_last_talk_time),
  65795. (val_sub, ":hours_since_last_visit", ":last_visit_hour"),
  65796. (store_div, reg49, ":hours_since_last_visit", 24),
  65797.  
  65798. #### Final Storage (8 lines)
  65799. (str_store_string, s1, "@{s1}{s2} {reg46?Reputed to be {s42}:}^Renown: {reg40}, Controversy: {reg41} {reg46?Impatience: {reg43}:}^\
  65800. {reg46?{reg44?{s44} noble:Noble} of the {s45}^Liege: {s46}, Relation: {reg47}:Ruler of the {s45}}^^{reg48?Currently prisoner of the {s48}:}^\
  65801. Days since last meeting: {reg49}^^Fiefs {reg51?(was promised a fief):}:^ {reg50?{s50}:no fief}"),
  65802. ######################
  65803. ## END lord infomation
  65804. (else_try),
  65805. #########################
  65806. # kingdom lady, unmarried
  65807. (is_between, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  65808. (troop_slot_eq, ":troop_no", slot_troop_spouse, -1),
  65809.  
  65810. (str_store_troop_name, s1, ":troop_no"),
  65811.  
  65812. # relation to player
  65813. (str_clear, s2),
  65814. (str_clear, s60),
  65815. (call_script, "script_get_troop_relation_to_player_string", s2, ":troop_no"),
  65816.  
  65817. # Controversy - slot_troop_controversy
  65818. (troop_get_slot, ":controversy", ":troop_no", slot_troop_controversy),
  65819. (assign, reg41, ":controversy"),
  65820.  
  65821. # Reputation type
  65822. (troop_get_slot, ":reputation", ":troop_no", slot_lord_reputation_type),
  65823. (try_begin),
  65824. (eq, ":reputation", lrep_conventional),
  65825. (str_store_string, s42, "@conventional"),
  65826. (else_try),
  65827. (eq, ":reputation", lrep_adventurous),
  65828. (str_store_string, s42, "@adventurous"),
  65829. (else_try),
  65830. (eq, ":reputation", lrep_otherworldly),
  65831. (str_store_string, s42, "@otherwordly"),
  65832. (else_try),
  65833. (eq, ":reputation", lrep_ambitious),
  65834. (str_store_string, s42, "@ambitious"),
  65835. (else_try),
  65836. (eq, ":reputation", lrep_moralist),
  65837. (str_store_string, s42, "@moralist"),
  65838. (else_try),
  65839. (assign, reg42, "str_personality_archetypes"),
  65840. (val_add, reg42, ":reputation"),
  65841. (str_store_string, s42, reg42),
  65842. (try_end),
  65843.  
  65844. # courtship state - slot_troop_courtship_state
  65845. (troop_get_slot, ":courtship_state", ":troop_no", slot_troop_courtship_state),
  65846. (try_begin),
  65847. (eq, ":courtship_state", 1),
  65848. (str_store_string, s43, "@just met"),
  65849. (else_try),
  65850. (eq, ":courtship_state", 2),
  65851. (str_store_string, s43, "@admirer"),
  65852. (else_try),
  65853. (eq, ":courtship_state", 3),
  65854. (str_store_string, s43, "@promised"),
  65855. (else_try),
  65856. (eq, ":courtship_state", 4),
  65857. (str_store_string, s43, "@breakup"),
  65858. (else_try),
  65859. (str_store_string, s43, "@unknown"),
  65860. (try_end),
  65861.  
  65862. # Current faction - store_troop_faction
  65863. (store_troop_faction, ":faction", ":troop_no"),
  65864. (troop_get_slot, ":origin_faction", ":troop_no", slot_troop_original_faction),
  65865.  
  65866. # Original faction - slot_troop_original_faction
  65867. (try_begin),
  65868. (val_sub, ":origin_faction", npc_kingdoms_begin),
  65869. (val_add, ":origin_faction", "str_kingdom_1_adjective"),
  65870. (str_store_string, s44, ":origin_faction"),
  65871. (end_try),
  65872. (str_store_faction_name, s45, ":faction"),
  65873.  
  65874. # Father/Guardian
  65875. (assign, reg46, 0),
  65876. (try_begin),
  65877. (troop_slot_ge, ":troop_no", slot_troop_father, 0),
  65878. (troop_get_slot, ":guardian", ":troop_no", slot_troop_father),
  65879. (assign, reg46, 1),
  65880. (else_try),
  65881. (troop_get_slot, ":guardian", ":troop_no", slot_troop_guardian),
  65882. (try_end),
  65883. (str_store_troop_name, s46, ":guardian"),
  65884.  
  65885. # Relation with player
  65886. (str_clear, s47),
  65887. (str_clear, s60),
  65888. (call_script, "script_get_troop_relation_to_player_string", s47, ":guardian"),
  65889.  
  65890. # courtship permission - slot_lord_granted_courtship_permission
  65891. (try_begin),
  65892. (troop_slot_ge, ":guardian", slot_lord_granted_courtship_permission, 1),
  65893. (assign, reg45, 1),
  65894. (else_try),
  65895. (assign, reg45, 0),
  65896. (try_end),
  65897.  
  65898. # betrothed
  65899. (assign, reg48, 0),
  65900. (try_begin),
  65901. (troop_slot_ge, ":troop_no", slot_troop_betrothed, 0),
  65902. (troop_get_slot, reg48, ":troop_no", slot_troop_betrothed),
  65903. (str_store_troop_name, s48, reg48),
  65904. (assign, reg48, 1),
  65905. (try_end),
  65906.  
  65907. # Days since last meeting
  65908. (store_current_hours, ":hours_since_last_visit"),
  65909. (troop_get_slot, ":last_visit_hour", ":troop_no", slot_troop_last_talk_time),
  65910. (val_sub, ":hours_since_last_visit", ":last_visit_hour"),
  65911. (store_div, reg49, ":hours_since_last_visit", 24),
  65912.  
  65913. # Heard poems
  65914. (assign, reg50, 0),
  65915. (str_clear, s50),
  65916.  
  65917. (try_begin),
  65918. (troop_slot_eq, ":troop_no", slot_lady_courtship_heroic_recited, 1),
  65919. (val_add, reg50, 1),
  65920. (str_store_string, s50, "@Heroic {s50}"),
  65921. (try_end),
  65922. (try_begin),
  65923. (troop_slot_eq, ":troop_no", slot_lady_courtship_allegoric_recited, 1),
  65924. (val_add, reg50, 1),
  65925. (str_store_string, s50, "@Allegoric {s50}"),
  65926. (try_end),
  65927. (try_begin),
  65928. (troop_slot_eq, ":troop_no", slot_lady_courtship_comic_recited, 1),
  65929. (val_add, reg50, 1),
  65930. (str_store_string, s50, "@Comic {s50}"),
  65931. (try_end),
  65932. (try_begin),
  65933. (troop_slot_eq, ":troop_no", slot_lady_courtship_mystic_recited, 1),
  65934. (val_add, reg50, 1),
  65935. (str_store_string, s50, "@Mystic {s50}"),
  65936. (try_end),
  65937. (try_begin),
  65938. (troop_slot_eq, ":troop_no", slot_lady_courtship_tragic_recited, 1),
  65939. (val_add, reg50, 1),
  65940. (str_store_string, s50, "@Tragic {s50}"),
  65941. (try_end),
  65942.  
  65943. #### Final Storage (8 lines)
  65944. (str_store_string, s1, "@{s1}{s2} Controversy: {reg41}^Reputation: {s42}, Courtship state: {s43}^\
  65945. Belongs to the {s45}^{reg46?Her father, {s46}:Her guardian, {s46}}{s47}^Allowed to visit: {reg45?yes:no} {reg48?Betrothed to {s48}:}^^\
  65946. Days since last meeting: {reg49}^^Poems:^ {reg50?{s50}:no poem heard}"),
  65947. #########################
  65948. # END kingdom lady, unmarried
  65949. (else_try),
  65950. #########################
  65951. # companions
  65952. (is_between, ":troop_no", companions_begin, companions_end),
  65953. (overlay_set_display, "$g_jrider_character_faction_filter", 0),
  65954.  
  65955. (str_store_troop_name, s1, ":troop_no"),
  65956.  
  65957. (troop_get_slot, ":reputation", ":troop_no", slot_lord_reputation_type),
  65958.  
  65959. (assign, reg42, "str_personality_archetypes"),
  65960. (val_add, reg42, ":reputation"),
  65961. (str_store_string, s42, reg42),
  65962.  
  65963. # birthplace
  65964. (troop_get_slot, ":home", ":troop_no", slot_troop_home),
  65965. (str_store_party_name, s43, ":home"),
  65966.  
  65967. # contacts town - slot_troop_town_with_contacts
  65968. (troop_get_slot, ":contact_town", ":troop_no", slot_troop_town_with_contacts),
  65969. (str_store_party_name, s44, ":contact_town"),
  65970.  
  65971. # current faction of contact town
  65972. (store_faction_of_party, ":town_faction", ":contact_town"),
  65973. (str_store_faction_name, s45, ":town_faction"),
  65974.  
  65975. # slot_troop_prisoner_of_party
  65976. (assign, reg48, 0),
  65977. (try_begin),
  65978. (troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  65979. (assign, reg48, 1),
  65980. (troop_get_slot, ":prisoner_party", ":troop_no", slot_troop_prisoner_of_party),
  65981. (store_faction_of_party, ":party_faction", ":prisoner_party"),
  65982. (str_store_faction_name, s48, ":party_faction"),
  65983. (try_end),
  65984.  
  65985. # Days since last meeting
  65986. (store_current_hours, ":hours_since_last_visit"),
  65987. (troop_get_slot, ":last_visit_hour", ":troop_no", slot_troop_last_talk_time),
  65988. (val_sub, ":hours_since_last_visit", ":last_visit_hour"),
  65989. (store_div, reg49, ":hours_since_last_visit", 24),
  65990.  
  65991. (try_begin), # Companion gathering support for Right to Rule
  65992. (troop_slot_eq, ":troop_no", slot_troop_current_mission, npc_mission_kingsupport),
  65993. (str_store_string, s50, "@Gathering support"),
  65994. (else_try), # Companion gathering intelligence
  65995. (troop_slot_eq, ":troop_no", slot_troop_current_mission, npc_mission_gather_intel),
  65996. (troop_get_slot, ":contact_town", ":troop_no", slot_troop_town_with_contacts),
  65997. (store_faction_of_party, ":town_faction", ":contact_town"),
  65998. (str_store_faction_name, s66, ":town_faction"),
  65999. (str_store_string, s50, "@Gathering intelligence in the {s66}"),
  66000. (else_try), # Companion on peace mission
  66001. (troop_slot_ge, ":troop_no", slot_troop_current_mission, npc_mission_peace_request),
  66002. (neg|troop_slot_ge, ":troop_no", slot_troop_current_mission, 8),
  66003.  
  66004. (troop_get_slot, ":troop_no", ":troop_no", slot_troop_mission_object),
  66005. (str_store_faction_name, s66, ":faction"),
  66006.  
  66007. (str_store_string, s50, "@Ambassy to {s66}"),
  66008. (else_try), # Companion is serving as minister player has court
  66009. (eq, ":troop_no", "$g_player_minister"),
  66010. (str_store_string, s50, "@Minister"),
  66011. (else_try),
  66012. (str_store_string, s50, "str_dplmc_none"),
  66013. (try_end),
  66014.  
  66015. # days left
  66016. (troop_get_slot, reg50, ":troop_no", slot_troop_days_on_mission),
  66017.  
  66018. #### Final Storage (8 lines)
  66019. (str_store_string, s1, "@{s1}, {s2}^Reputation: {s42}^\
  66020. Born at {s43}^Contact in {s44} of the {s45}.^\
  66021. ^{reg48?Currently prisoner of the {s48}:}^Days since last talked to: {reg49}^^Current mission:^ {s50}{reg50?, back in {reg50} days.:}"),
  66022. #########################
  66023. # END companions
  66024. (try_end),
  66025. ]),
  66026.  
  66027. # Script generate_known_poems_string
  66028. # generate in s1 list of known poems filling with blank lines for unknown ones
  66029. ("generate_known_poems_string",
  66030. [
  66031. # Known poems string
  66032. (assign, ":num_poems", 0),
  66033. (str_store_string, s1, "str_s1__poems_known"),
  66034. (try_begin),
  66035. (gt, "$allegoric_poem_recitations", 0),
  66036. (str_store_string, s1, "str_s1_storming_the_castle_of_love_allegoric"),
  66037. (val_add, ":num_poems", 1),
  66038. (try_end),
  66039. (try_begin),
  66040. (gt, "$tragic_poem_recitations", 0),
  66041. (str_store_string, s1, "str_s1_kais_and_layali_tragic"),
  66042. (val_add, ":num_poems", 1),
  66043. (try_end),
  66044. (try_begin),
  66045. (gt, "$comic_poem_recitations", 0),
  66046. (str_store_string, s1, "str_s1_a_conversation_in_the_garden_comic"),
  66047. (val_add, ":num_poems", 1),
  66048. (try_end),
  66049. (try_begin),
  66050. (gt, "$heroic_poem_recitations", 0),
  66051. (str_store_string, s1, "str_s1_helgered_and_kara_epic"),
  66052. (val_add, ":num_poems", 1),
  66053. (try_end),
  66054. (try_begin),
  66055. (gt, "$mystic_poem_recitations", 0),
  66056. (str_store_string, s1, "str_s1_a_hearts_desire_mystic"),
  66057. (val_add, ":num_poems", 1),
  66058. (try_end),
  66059.  
  66060. # fill blank lines
  66061. (try_for_range, ":num_poems", 5),
  66062. (str_store_string, s1, "@{s1}^"),
  66063. (try_end),
  66064. ]),
  66065. # Jrider -
  66066.  
  66067. #"script_dplmc_save_civilian_clothing"
  66068. ##Save civilian clothing so it will still appear later
  66069. #
  66070. #INPUT: troop number
  66071. #OUTPUT: none
  66072. ("dplmc_save_civilian_clothing", [
  66073. (store_script_param, ":troop_no", 1),
  66074. #SB : this interferes with auto-loot
  66075. (try_begin),
  66076. (gt, ":troop_no", 0),#deliberately exclude player
  66077. (troop_is_hero, ":troop_no"),#only applies to unique characters
  66078. (try_for_range, ":dest_slot", dplmc_ek_alt_items_begin, min(dplmc_ek_alt_items_end, dplmc_ek_alt_items_begin + 4)),
  66079. (store_add, ":source_slot", ":dest_slot", ek_head - dplmc_ek_alt_items_begin),
  66080. (troop_get_inventory_slot, ":item_id", ":troop_no", ":dest_slot"),
  66081. (lt, ":item_id", 1),#do not overwrite an existing item in the destination slot
  66082. (troop_get_inventory_slot, ":item_id", ":troop_no", ":source_slot"),
  66083. (troop_set_inventory_slot, ":troop_no", ":dest_slot", ":item_id"),
  66084. (try_end),
  66085. (try_end),
  66086. ]),
  66087. ##diplomacy end+
  66088.  
  66089. ##diplomacy end+
  66090.  
  66091. #Equipment cost fix
  66092. ("player_get_value_of_original_items",
  66093. [
  66094. (store_script_param, ":player_no", 1),
  66095. (store_script_param, ":agent_no", 2),
  66096. (store_script_param, ":troop_id", 3),
  66097. (assign, ":total_equipment_cost", 0),
  66098. (try_for_range, ":i_item_slot", 0, 8),
  66099. (neg|player_item_slot_is_picked_up, ":player_no", ":i_item_slot"),
  66100. (agent_get_item_slot, ":item_id", ":agent_no", ":i_item_slot"), #value between 0-7, order is weapon1, weapon2, weapon3, weapon4, head_armor, body_armor, leg_armor, hand_armor
  66101. #(player_get_item_id, ":item_id", ":player_no", ":i_item_slot"), #only for server
  66102. (neq, ":item_id", -1),
  66103. (call_script, "script_multiplayer_get_item_value_for_troop", ":item_id", ":troop_id"),
  66104. (val_add, ":total_equipment_cost", reg0),
  66105.  
  66106. #Debugging
  66107. #(assign, reg1, ":total_equipment_cost"),
  66108. #(str_store_item_name, s0, ":item_id"),
  66109. #(multiplayer_send_string_to_player, ":player_no", multiplayer_event_show_server_message, "@{s0} for {reg0}g added to total equipment cost, which is now: {reg1}g"),
  66110. ##
  66111. (try_end),
  66112. (try_for_agents, ":cur_horse"),
  66113. #Check all horses in the scene and see if one of them is agent_no's bought horse. Won't be enough to just do (agent_get_horse, ":horse", ":agent_no"),
  66114. #since you get money back for a bought horse, even if you have dismounted it, if the horse is still alive and has no other rider.
  66115. (agent_is_alive, ":cur_horse"),
  66116. (neg|agent_is_human, ":cur_horse"), #Spawned agent is horse
  66117. (agent_get_slot, ":agent_no_bought_horse", ":agent_no", slot_agent_bought_horse),
  66118. (eq, ":agent_no_bought_horse", ":cur_horse"),
  66119. (assign, ":add_horse_cost_to_equipment_value", 0),
  66120. (try_begin),
  66121. (agent_get_rider, ":rider_agent_id", ":cur_horse"),
  66122. (try_begin),
  66123. (neq, ":rider_agent_id", -1),
  66124. (neg|agent_is_non_player, ":rider_agent_id"),
  66125. (agent_get_slot, ":agent_no_bought_horse", ":rider_agent_id", slot_agent_bought_horse),
  66126. (eq, ":agent_no_bought_horse", ":cur_horse"), #agent_no is mounted on the same horse he bought
  66127. (assign, ":add_horse_cost_to_equipment_value", 1),
  66128.  
  66129. #Debugging
  66130. #(agent_get_item_id, ":mount_type", ":cur_horse"), #(works only for horses, returns -1 otherwise)
  66131. #(str_store_item_name, s0, ":mount_type"),
  66132. #(multiplayer_send_string_to_player, ":player_no", multiplayer_event_show_server_message, "@You are mounted on your bought {s0} and will get money for it"),
  66133. ##
  66134. (else_try),
  66135. (eq, ":rider_agent_id", -1), #If cur_horse doesn't have a rider
  66136. (agent_get_horse, ":agent_no_mount", ":agent_no"),
  66137. (eq, ":agent_no_mount", -1), #If agent_no is not mounted on another horse
  66138. (agent_get_slot, ":agent_no_bought_horse", ":agent_no", slot_agent_bought_horse),
  66139. (eq, ":agent_no_bought_horse", ":cur_horse"),
  66140. (assign, ":add_horse_cost_to_equipment_value", 1),
  66141.  
  66142. #Debugging
  66143. #(agent_get_item_id, ":mount_type", ":cur_horse"), #(works only for horses, returns -1 otherwise)
  66144. #(str_store_item_name, s0, ":mount_type"),
  66145. #(multiplayer_send_string_to_player, ":player_no", multiplayer_event_show_server_message, "@Your bought {s0} is alive so you get money for it"),
  66146. ##
  66147. (try_end),
  66148. (eq, ":add_horse_cost_to_equipment_value", 1),
  66149. (agent_get_item_id, ":cur_mount_type", ":cur_horse"), #Checks which type the horse is
  66150. (call_script, "script_multiplayer_get_item_value_for_troop", ":cur_mount_type", ":troop_id"),
  66151. (val_add, ":total_equipment_cost", reg0),
  66152. (multiplayer_send_string_to_player, ":player_no", multiplayer_event_show_server_message, "@Added money for your old horse"),
  66153. (try_end),
  66154. (try_end),
  66155. (agent_set_slot, ":agent_no", slot_agent_bought_horse, -1),
  66156. (assign, reg0, ":total_equipment_cost"),
  66157. ]),
  66158. ###
  66159.  
  66160. ##script_improve_center
  66161. #helper script for building in centers
  66162. ("improve_center", [
  66163. (store_script_param, ":center_no", 1),
  66164. (store_script_param, ":builder", 2),
  66165. (store_script_param, ":improvement_time", 3),
  66166. (party_set_slot, ":center_no", slot_center_current_improvement, "$g_improvement_type"),
  66167. (store_current_hours, ":cur_hours"),
  66168. (store_mul, ":hours_takes", ":improvement_time", 24),
  66169. (val_add, ":hours_takes", ":cur_hours"),
  66170. (party_set_slot, ":center_no", slot_center_improvement_end_hour, ":hours_takes"),
  66171. (assign, reg6, ":improvement_time"),
  66172. (call_script, "script_get_improvement_details", "$g_improvement_type"),
  66173. (add_party_note_from_sreg, ":center_no", 2, "@A {s0} is being built. It will finish in {reg6} days", 1),
  66174. (try_begin), #should probably raise this depending on project instead of constant reward
  66175. (troop_is_hero, ":builder"),
  66176. (neq, ":builder", "trp_player"),
  66177. (call_script, "script_change_troop_renown", ":builder", dplmc_companion_skill_renown),
  66178. (try_end),
  66179. ]),
  66180.  
  66181. ##script_calculate_improvement_limit
  66182. #calculate threshold for building stuff
  66183. #input: troop_no, center_no (unused)
  66184. #output: reg0
  66185. ("calculate_improvement_limit", [
  66186. (store_script_param_1, ":troop_no"),
  66187. (store_script_param_2, ":center_no"),
  66188. (assign, ":limit", dplmc_improvement_limit),
  66189. (troop_get_slot, ":personality", ":troop_no", slot_lord_reputation_type),
  66190. (try_begin), #bad personality, unlikely to ever build property
  66191. (is_between, ":personality", lrep_selfrighteous, lrep_goodnatured),
  66192. (val_mul, ":limit", ":personality"),
  66193. (val_div, ":limit", 2),
  66194. (else_try), #include companion personality types
  66195. (is_between, ":personality", lrep_goodnatured, lrep_custodian),
  66196. (try_begin), #exception
  66197. (neq, ":personality", lrep_roguish),
  66198. (store_mul, ":level", ":personality", 250),
  66199. (val_sub, ":limit", ":level"),
  66200. (try_end),
  66201. (try_end),
  66202. (assign, reg0, ":limit"),
  66203. ]),
  66204.  
  66205. ##script_calculate_equipment_limit
  66206. #calculate threshold for upgrading equipment imod from merchants
  66207. #input: troop_no, center_no (unused)
  66208. #output: reg0
  66209. ("calculate_equipment_limit", [
  66210. (store_script_param_1, ":troop_no"),
  66211. (store_script_param_2, ":center_no"),
  66212. (assign, ":limit", dplmc_equipment_limit),
  66213. (troop_get_slot, ":personality", ":troop_no", slot_lord_reputation_type),
  66214.  
  66215. (try_begin), #focus on arms
  66216. (is_between, ":personality", lrep_martial, lrep_selfrighteous),
  66217. (val_div, ":limit", 2),
  66218. (else_try), #invest in gear not fief
  66219. (eq, ":personality", lrep_roguish),
  66220. (val_sub, ":limit", 1000),
  66221. (try_end),
  66222.  
  66223. #aristocracy modifier as enthusiasm for shopping
  66224. (store_faction_of_party, ":faction_no", ":center_no"),
  66225. (faction_get_slot, ":aristocracy", ":faction_no", dplmc_slot_faction_aristocracy),
  66226. (val_mul, ":aristocracy", -100), #high plutocracy more shopping, decreasing threshold
  66227. (val_add, ":limit", ":aristocracy"),
  66228.  
  66229. (assign, reg0, ":limit"),
  66230. ]),
  66231. #script_change_troop_intrigue_impatience
  66232. #inputs: troop_no ($g_talk_troop), amount
  66233. #output: slot_troop_intrigue_impatience changed
  66234. ("change_troop_intrigue_impatience", [
  66235. (store_script_param_1, ":troop_no"),
  66236. (store_script_param_2, ":amount"),
  66237. (troop_get_slot, ":impatience", ":troop_no", slot_troop_intrigue_impatience),
  66238. (val_max, ":impatience", ":amount"),
  66239. (troop_set_slot, ":troop_no", slot_troop_intrigue_impatience, ":impatience"),
  66240. ]),
  66241. #script_center_get_bandits
  66242. #inputs: center_no, mode
  66243. #output: bandit_troop in reg0
  66244. # get an appropriate bandit to infest the village
  66245. ("center_get_bandits",[
  66246.  
  66247. (store_script_param_1, ":village_no"),
  66248. (store_script_param_2, ":mode"),
  66249. (assign, ":bandit_troop", "trp_looter"),
  66250.  
  66251. (try_begin), #native mode
  66252. (eq, ":mode", -1),
  66253. (store_random_in_range, ":random_no", 0, 3),
  66254. (try_begin),
  66255. (eq, ":random_no", 0),
  66256. (assign, ":bandit_troop", "trp_bandit"),
  66257. (else_try),
  66258. (eq, ":random_no", 1),
  66259. (assign, ":bandit_troop", "trp_mountain_bandit"),
  66260. (else_try),
  66261. (assign, ":bandit_troop", "trp_forest_bandit"),
  66262. (try_end),
  66263. (else_try), #faction mode
  66264. (eq, ":mode", 0),
  66265.  
  66266. (assign, ":bandit_troop", "trp_looter"),
  66267. # (store_faction_of_party, ":faction", ":village_no"),
  66268. (party_get_slot, ":faction", ":village_no", slot_center_original_faction),
  66269. (store_random_in_range, ":random_no", 0, 10),
  66270. (try_begin), #deserter troops, 10% chance
  66271. (eq, ":random_no", 0),
  66272. (faction_get_slot, ":bandit_troop", ":faction", slot_faction_deserter_troop),
  66273. (else_try),
  66274. (lt, ":random_no", 6), #regular bandits (looter to brigand), 50%
  66275. (val_div, ":random_no", 2),
  66276. (store_add, ":bandit_troop","trp_looter",":random_no"),
  66277. (else_try), #regional bandits, 40% (should be terrain based though)
  66278. (try_begin),
  66279. (eq, ":faction", "fac_kingdom_6"),
  66280. (assign, ":bandit_troop", "trp_desert_bandit"),
  66281. (else_try),
  66282. (eq, ":faction", "fac_kingdom_5"),
  66283. (assign, ":bandit_troop", "trp_mountain_bandit"),
  66284. (else_try),
  66285. (eq, ":faction", "fac_kingdom_4"),
  66286. (assign, ":bandit_troop", "trp_sea_raider"),
  66287. (else_try),
  66288. (eq, ":faction", "fac_kingdom_3"),
  66289. (assign, ":bandit_troop", "trp_steppe_bandit"),
  66290. (else_try),
  66291. (eq, ":faction", "fac_kingdom_2"),
  66292. (assign, ":bandit_troop", "trp_taiga_bandit"),
  66293. (else_try),
  66294. (eq, ":faction", "fac_kingdom_1"),
  66295. (assign, ":bandit_troop", "trp_forest_bandit"),
  66296. (try_end),
  66297. (try_end),
  66298. (else_try), #terrain mode
  66299. (eq, ":mode", 1),
  66300. #base type first
  66301. (party_get_current_terrain, ":terrain_type", ":village_no"),
  66302. (try_begin),
  66303. (this_or_next|eq, ":terrain_type", rt_steppe),
  66304. (eq, ":terrain_type", rt_steppe_forest),
  66305. (assign, ":bandit_troop", "trp_steppe_bandit"),
  66306. # (else_try),
  66307. # (eq, ":terrain_type", rt_plain),
  66308. # (assign, ":bandit_troop", "trp_bandit"),
  66309. (else_try),
  66310. (this_or_next|eq, ":terrain_type", rt_snow),
  66311. (eq, ":terrain_type", rt_snow_forest),
  66312. (assign, ":bandit_troop", "trp_taiga_bandit"),
  66313. (else_try),
  66314. (this_or_next|eq, ":terrain_type", rt_desert),
  66315. (eq, ":terrain_type", rt_desert_forest),
  66316. (assign, ":bandit_troop", "trp_desert_bandit"),
  66317. # (else_try),
  66318. # (eq, ":terrain_type", rt_forest),
  66319. # (assign, ":bandit_troop", "trp_forest_bandit"),
  66320. (try_end),
  66321. (try_begin),
  66322. (eq, ":bandit_troop", "trp_looter"), #still not picked
  66323. #proximity to features (forest, mountain, ocean),
  66324. (party_get_position, pos1, ":village_no"),
  66325. (try_begin), #cf operation to see if it's near water
  66326. (map_get_water_position_around_position, pos2, pos1, 5),
  66327. # after finding water limit range of spawning (so sea raiders don't appear upriver)
  66328. (store_add, ":limit", "p_sea_raider_spawn_point_1", num_sea_raider_spawn_points),
  66329. (try_for_range, ":spawn_point", "p_sea_raider_spawn_point_1", ":limit"),
  66330. (store_distance_to_party_from_party, ":distance", ":village_no", ":spawn_point"),
  66331. (lt, ":distance", 50), # 200% bandit spawning radius
  66332. (assign, ":limit", -1),
  66333. (try_end),
  66334. (eq, ":limit", -1), #within boundaries
  66335. (assign, ":bandit_troop", "trp_sea_raider"),
  66336. (else_try), #sample random points until we find forest/mountain (coast)
  66337. (assign, ":forest_count", 0),
  66338. (assign, ":mountain_count", 0),
  66339. (assign, ":other_count", 0),
  66340. (try_for_range, ":unused", 0, 100),
  66341. (map_get_land_position_around_position, pos2, pos1, 5),
  66342. (party_set_position, "p_temp_party", pos2),
  66343. (party_get_current_terrain, ":terrain_type", "p_temp_party"),
  66344. (try_begin),
  66345. (eq, ":terrain_type", rt_forest),
  66346. (val_add, ":forest_count", 1),
  66347. (else_try),
  66348. (eq, ":terrain_type", rt_mountain),
  66349. (val_add, ":mountain_count", 1),
  66350. (else_try),
  66351. (val_add, ":other_count", 1),
  66352. (try_end),
  66353. (try_end),
  66354. (try_begin), # not enough features
  66355. (gt, ":other_count", 75), #pass through to faction calls
  66356. (call_script, "script_center_get_bandits", ":village_no", 0),
  66357. (assign, ":bandit_troop", reg0),
  66358. (else_try),
  66359. (gt, ":forest_count", ":mountain_count"),
  66360. (gt, ":forest_count", 15),
  66361. (assign, ":bandit_troop", "trp_forest_bandit"),
  66362. (else_try),
  66363. (gt, ":mountain_count", ":forest_count"),
  66364. (gt, ":mountain_count", 15),
  66365. (assign, ":bandit_troop", "trp_mountain_bandit"),
  66366. (try_end),
  66367. (try_end),
  66368. (try_end),
  66369. (try_end),
  66370. (assign, reg0, ":bandit_troop"),
  66371. ]),
  66372.  
  66373.  
  66374. ("create_wpn_slot_overlay", [
  66375. (store_script_param, ":slot", 1),
  66376. (store_script_param, ":pos", 2),
  66377. (init_position, pos1),
  66378. (position_set_x, pos1, 270),
  66379. (position_set_y, pos1, ":pos"),
  66380. (create_combo_button_overlay, ":obj"),
  66381. (overlay_set_position, ":obj", pos1),
  66382. (assign, ":sub_overlay_id", 0),
  66383. (store_add, ":upgrade_slot", ":slot", dplmc_slot_upgrade_wpn_0),
  66384.  
  66385. # #SB : add meta-types
  66386. # (overlay_add_item, ":obj", "str_dplmc_hero_wpn_slot_pikes"),
  66387. # (overlay_add_item, ":obj", "str_dplmc_hero_wpn_slot_lance"),
  66388. # (overlay_add_item, ":obj", "str_dplmc_hero_wpn_slot_morningstar"),
  66389. # (try_for_range_backwards, ":item_type", dplmc_itp_morningstar, dplmc_itp_pike + 1),
  66390. # (troop_slot_eq, "$temp", ":upgrade_slot", ":item_type"),
  66391. # (overlay_set_val, ":obj", ":sub_overlay_id"),
  66392. # (else_try),
  66393. # (val_add, ":sub_overlay_id", 1),
  66394. # (try_end),
  66395. (call_script, "script_dplmc_get_current_item_for_autoloot", ":slot"), #goes to "keep current", s10
  66396. (try_for_range_backwards, ":item_type", 0, itp_type_animal),
  66397. (this_or_next|is_between, ":item_type", itp_type_one_handed_wpn, itp_type_goods),
  66398. (this_or_next|is_between, ":item_type", itp_type_pistol, itp_type_animal),
  66399. (eq, ":item_type", 0),
  66400. (store_add, ":out_string", "str_dplmc_hero_wpn_slot_none", ":item_type"),
  66401. (overlay_add_item, ":obj", ":out_string"),
  66402. (try_begin), #find base type
  66403. (troop_get_slot, ":cur_value", "$temp", ":upgrade_slot"),
  66404. (val_mod, ":cur_value", meta_itp_mask),
  66405. (eq, ":cur_value", ":item_type"),
  66406. (overlay_set_val, ":obj", ":sub_overlay_id"),
  66407. (try_end),
  66408. (val_add, ":sub_overlay_id", 1),
  66409. (try_end),
  66410.  
  66411. #store id in slot
  66412. (troop_set_slot, "trp_stack_selection_ids", ":slot", ":obj"),
  66413. # # only works for original button, not drop-down lists
  66414. # (overlay_set_additional_render_height, ":obj", 99),
  66415.  
  66416. (assign, reg1, ":obj"), #return overlay id
  66417. ]),
  66418.  
  66419.  
  66420. ("update_wpn_slot_itp", [
  66421. (store_script_param, ":slot", 1),
  66422. (store_script_param, ":value", 2),
  66423. (troop_get_slot, ":item_type", "trp_temp_array_c", ":value"),
  66424. (troop_get_slot, ":slot_value", "$temp", ":slot"),
  66425. (try_begin), #if new value supports metamods, inherit
  66426. (call_script, "script_cf_item_type_has_advanced_autoloot", ":item_type"),
  66427. (store_mod, ":original_value", ":slot_value", meta_itp_mask),
  66428. (val_sub, ":slot_value", ":original_value"), #remove original itp
  66429. (val_add, ":slot_value", ":item_type"), #add new
  66430. (else_try), #otherwise replace value
  66431. (assign, ":slot_value", ":item_type"),
  66432. (try_end),
  66433. (troop_set_slot, "$temp", ":slot", ":slot_value"),
  66434. (assign, "$temp_2", ":slot"),
  66435. #restart presentation instead of updating overlay value (because we can't)
  66436. (start_presentation, "prsnt_dplmc_autoloot_upgrade_management"),
  66437. ]),
  66438. #script_item_get_type_aux : auxiliary item classification script, see header_items for values
  66439. #input : item
  66440. #output: reg0, item type or meta-type
  66441. ("item_get_type_aux", [
  66442. (store_script_param, ":item", 1),
  66443.  
  66444. (item_get_type, ":itp", ":item"),
  66445. (try_begin),
  66446. # (item_slot_eq, ":item", dplmc_slot_two_handed_one_handed, 1),
  66447. # (item_has_property, ":item", itp_type_two_handed_wpn),
  66448. (eq, ":itp", itp_type_two_handed_wpn),
  66449. (neg|item_has_property, ":item", itp_two_handed),
  66450. (assign, ":itp", dplmc_itp_morningstar), # type 11 = two-handed/one-handed
  66451. (else_try),
  66452. (eq, ":itp", itp_type_polearm),
  66453. (item_get_swing_damage, ":swing", ":item"),
  66454. (item_get_thrust_damage, ":thrust", ":item"),
  66455. (try_begin),
  66456. (ge, ":swing", ":thrust"),
  66457. (item_get_swing_damage_type, ":damage_type", ":item"),
  66458. (eq, ":damage_type", cut),
  66459. (assign, ":itp", dplmc_itp_halberd),
  66460. (else_try),
  66461. (lt, ":swing", ":thrust"),
  66462. (try_begin), #lances
  66463. (item_has_property, ":item", itp_couchable),
  66464. (assign, ":itp", dplmc_itp_lance),
  66465. (else_try), #can't be both lance and pike
  66466. # (item_has_property, ":item", itp_cant_use_on_horseback), #too restrictive
  66467. (item_get_weapon_length, ":length", ":item"),
  66468. (ge, ":length", dplmc_pike_length_cutoff), #arbitrary value to allow awlpikes to fall in range
  66469. (item_has_capability, ":item", itcf_thrust_polearm), #has two-handed thrust
  66470. (this_or_next|item_has_property, ":item", itp_two_handed),
  66471. (item_has_property, ":item", itp_penalty_with_shield),
  66472. (assign, ":itp", dplmc_itp_pike),
  66473. (try_end),
  66474. (try_end),
  66475. (try_end),
  66476. (assign, reg0, ":itp"),
  66477. ]),
  66478.  
  66479. #check if weapons are wholly inappropriate for actual combat
  66480. ("cf_melee_weapon_is_civilian", [
  66481. (store_script_param, ":item", 1),
  66482. (this_or_next|is_between, ":item", "itm_sickle", "itm_dagger"),
  66483. (this_or_next|is_between, ":item", "itm_scythe", "itm_military_fork"),
  66484. (this_or_next|eq, ":item", "itm_wooden_stick"),
  66485. (eq, ":item", "itm_torch"),
  66486. # (eq, ":item", "itm_stones"),
  66487. #include arena weapons here as well
  66488. ]),
  66489.  
  66490. #check if the item type has advanced auto-loot options available (damage type, meta-type)
  66491. ("cf_item_type_has_advanced_autoloot", [
  66492. (store_script_param, ":item_type", 1),
  66493. (this_or_next|is_between, ":item_type", itp_type_one_handed_wpn, itp_type_shield),
  66494. (eq, ":item_type", itp_type_thrown), #throwing axe vs jaridss vs rocks
  66495. #all other ranged weapons are pierce (for now) excluding arena ones
  66496. ]),
  66497.  
  66498. #script_display_policy_string_to_reg
  66499. #unify string register usage to one temp s0 and one output s20
  66500. #register reg2,3 are used for mode and postfix
  66501. ("display_policy_string_to_reg", [
  66502. (store_script_param, ":faction_no", 1),
  66503. (store_script_param, reg2, 2), #whether it is third person "the" or first person "our"
  66504. (store_script_param, reg3, 3), #spaces or line breaks as the postfix delimiter
  66505.  
  66506. (str_store_faction_name_link, s5, ":faction_no"),
  66507. (assign, ":string", "str_dplmc_neither_centralize_nor_decentralized"),
  66508. (faction_get_slot, ":centralization", ":faction_no", dplmc_slot_faction_centralization),
  66509. (val_add, ":string", ":centralization"),
  66510. (str_store_string, s0, ":string"),
  66511. (str_store_string, s20, "@{s20}{reg2?Our government:The goverment of the {s5}} is {s0}.{reg3?^: }"),
  66512.  
  66513. (assign, ":string", "str_dplmc_neither_aristocratic_nor_plutocratic"),
  66514. (faction_get_slot, ":aristocraty", ":faction_no", dplmc_slot_faction_aristocracy),
  66515. (val_add, ":string", ":aristocraty"),
  66516. (str_store_string, s0, ":string"),
  66517. (str_store_string, s20, "@{s20}The upper class society is {s0}.{reg3?^: }"),
  66518.  
  66519. (assign, ":string", "str_dplmc_mixture_serfs"),
  66520. (faction_get_slot, ":serfdom", ":faction_no", dplmc_slot_faction_serfdom),
  66521. (val_add, ":string", ":serfdom"),
  66522. (str_store_string, s0, ":string"),
  66523. (str_store_string, s20, "@{s20}{reg2?Our:The} people are {s0}.{reg3?^: }"),
  66524.  
  66525. (assign, ":string", "str_dplmc_mediocre_quality"),
  66526. (faction_get_slot, ":quality", ":faction_no", dplmc_slot_faction_quality),
  66527. (val_add, ":string", ":quality"),
  66528. (str_store_string, s0, ":string"),
  66529. (str_store_string, s20, "@{s20}{reg2?Our:The} troops have {s0}.{reg3?^: }"),
  66530.  
  66531. ##nested diplomacy start+ add mercantilism
  66532. (assign, ":string", "str_dplmc_neither_mercantilist_nor_laissez_faire"),
  66533. (faction_get_slot, ":mercantilism", ":faction_no", dplmc_slot_faction_mercantilism),
  66534. (val_add, ":string", ":mercantilism"),
  66535. (str_store_string, s0, ":string"),
  66536. (str_store_string, s20, "@{s20}{reg2?Our:The government's} approach to trade is {s0}.{reg3?^: }"),
  66537. ]),
  66538.  
  66539. #native stuff for startup merchants
  66540. ("get_troop_of_merchant",
  66541. [
  66542. (store_faction_of_party, ":starting_town_faction", "$g_starting_town"),
  66543. (store_sub, ":troop_of_merchant", ":starting_town_faction", npc_kingdoms_begin),
  66544. (val_add, ":troop_of_merchant", startup_merchants_begin),
  66545. (assign, reg0, ":troop_of_merchant"),
  66546. ]),
  66547.  
  66548. #reusable code to check whether npcs in a specific range have been met
  66549. #does not account for alternative towns
  66550. ("cf_no_known_taverngoers",
  66551. [
  66552. (store_script_param_1, ":begin"),
  66553. (store_script_param_2, ":end"),
  66554. # (assign, ":num_towns", tavern_booksellers_end),
  66555. (try_for_range, ":troop_no", ":begin", ":end"),
  66556. # (neg|party_slot_eq, ":town_no", slot_center_tavern_bookseller, 0),
  66557. # (party_get_slot, ":seller", ":town_no", slot_center_tavern_bookseller),#addition - fixed 2011-03-29
  66558. (troop_slot_ge, ":troop_no", slot_troop_met, 1),
  66559. (troop_get_slot, ":town_no", ":troop_no", slot_troop_cur_center),
  66560. (is_between, ":town_no", walled_centers_begin, walled_centers_end),
  66561. (assign, ":end", ":begin"), #loop break
  66562. (try_end),
  66563. (neq, ":begin", ":end"),
  66564. ]),
  66565.  
  66566. #script_list_known_taverngoers
  66567. #input: starting/ending troop range, also party slot if necessary as error check
  66568. #output: location of known tavern npcs to s11
  66569. ("list_known_taverngoers",
  66570. [
  66571. (store_script_param, ":begin", 1),
  66572. (store_script_param, ":end", 2),
  66573. (store_script_param, ":slot_no", 3),
  66574.  
  66575. (assign, ":num_towns", 0),
  66576. (try_for_range, ":troop_no", ":begin", ":end"),
  66577. (this_or_next|troop_slot_ge, ":troop_no", slot_troop_met, 1),
  66578. (troop_slot_eq, ":troop_no", slot_troop_cur_center, "$current_town"),
  66579. (troop_get_slot, ":town_no", ":troop_no", slot_troop_cur_center),
  66580. (is_between, ":town_no", walled_centers_begin, walled_centers_end),
  66581. # (neg|party_slot_eq, ":town_no", slot_center_ransom_broker, 0),
  66582. (party_slot_eq, ":town_no", ":slot_no", ":troop_no"),
  66583. (val_add, ":num_towns", 1),
  66584. (str_store_party_name_link, s50, ":town_no"),
  66585. (try_begin),
  66586. (eq, ":num_towns", 1),
  66587. (str_store_string, s51, s50),
  66588. (else_try),
  66589. (eq, ":num_towns", 2),
  66590. (str_store_string, s51, "str_s50_and_s51"),
  66591. (else_try),
  66592. (str_store_string, s51, "str_s50_comma_s51"),
  66593. (try_end),
  66594.  
  66595. (try_begin), #list false tavern npcs
  66596. (call_script, "script_cf_find_alternative_town_for_taverngoers", ":town_no", -9),
  66597. (assign, ":alternative_town", reg0),
  66598. (neg|party_slot_ge, ":alternative_town", ":slot_no", ":begin"),
  66599. (val_add, ":num_towns", 1),
  66600. (str_store_party_name_link, s52, ":alternative_town"),
  66601. (try_begin), #this is at least the second town in the string
  66602. (eq, ":num_towns", 2),
  66603. (str_store_string, s51, "str_s52_and_s51"),
  66604. (else_try),
  66605. (str_store_string, s51, "str_s52_comma_s51"),
  66606. (try_end),
  66607. (try_end),
  66608. # (display_message, "@{s51}"),
  66609. (try_end),
  66610. (str_store_troop_name_plural, s10, ":begin"), #default titles "book_merchant" "ransom_broker" etc
  66611. (str_store_string_reg, s11, s51),
  66612. (display_message, "@You can find {s10}s at {s11}."),
  66613. ]),
  66614. #native functionality to increase tavern diversity
  66615. ("cf_find_alternative_town_for_taverngoers",
  66616. [
  66617. (store_script_param_1, ":town_no"),
  66618. (store_script_param_2, ":adder"),
  66619. (store_add, ":alternative_town", ":town_no", ":adder"), #should really randomize this
  66620.  
  66621. # (store_sub, ":num_towns", towns_end, towns_begin),
  66622. (try_begin),
  66623. (ge, ":alternative_town", towns_end),
  66624. (val_sub, ":alternative_town", towns_end),
  66625. (val_add, ":alternative_town", towns_begin),
  66626. (else_try),
  66627. (lt, ":alternative_town", towns_begin),
  66628. (val_add, ":alternative_town", towns_end),
  66629. (try_end),
  66630. ##diplomacy start+
  66631. #The above code makes assumptions about the number of towns that might not be true on other maps.
  66632. #Changing it to support variable sizes would not be hard, but I'm not convinced that it is so
  66633. #desirable in the first place.
  66634. (is_between, ":alternative_town", towns_begin, towns_end),
  66635. # (party_slot_eq, ":alternative_town", slot_party_type, spt_town),
  66636. (assign, reg0, ":alternative_town"),
  66637. ]),
  66638.  
  66639. #script_calculate_ransom_contribution
  66640. #input : troop_no, amount expected, properly set up qst_rescue_prisoner targets
  66641. #assumes no other sources of debt (dialog prevents condition) and quest troop is active and related
  66642. #output : amount lord_no personally pays in reg0, cached in slot_troop_player_debt, cleared when player rejects it
  66643. ("calculate_ransom_contribution", [
  66644. (store_script_param_1, ":lord_no"), #usually $g_talk_troop
  66645. (store_script_param_2, ":ransom_size"), #2000 from quest giver, up to 125*strength for other relatives
  66646. #because kingdom ladies aren't landholders, they give it without consequence of debt if quest fails (also less dialogue to write)
  66647. (assign, ":ransom_amount", 0),
  66648.  
  66649. (try_begin),
  66650. (check_quest_active, "qst_rescue_prisoner"),
  66651. (quest_get_slot, ":prisoner", "qst_rescue_prisoner", slot_quest_target_troop),
  66652. (quest_get_slot, ":cur_ransom", "qst_rescue_prisoner", slot_quest_target_state),
  66653. (try_begin),
  66654. #each +-2 relation has 1% effect on calculation to the effect of 50%/150% initial value
  66655. (call_script, "script_troop_get_relation_with_troop", ":lord_no", ":prisoner"),
  66656. (store_div, ":relation", reg0, 2),
  66657. (val_add, ":relation", 100),
  66658. (val_mul, ":ransom_amount", ":relation"),
  66659. (val_div, ":ransom_amount", 100),
  66660. (try_end),
  66661. # problem is this script has variance in output, we can use the cached slot_quest_target_amount
  66662. (call_script, "script_calculate_ransom_amount_for_troop", ":prisoner"),
  66663. (assign, ":ransom", reg0), #original amount
  66664. (val_add, ":ransom_size", ":cur_ransom"),
  66665. (try_begin), #contributed too much, get remainder before arbitrary cap
  66666. (gt, ":ransom_size", ":ransom"),
  66667. (store_sub, ":ransom_amount", ":ransom", ":cur_ransom"),
  66668. (else_try), #give full amount
  66669. (store_sub, ":ransom_amount", ":ransom_size", ":cur_ransom"), #undo adding existing ransom
  66670. (try_end),
  66671.  
  66672. (try_begin), #active npcs have wealth
  66673. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  66674. (troop_get_slot, ":cur_wealth", ":lord_no", slot_troop_wealth),
  66675. (val_div, ":cur_wealth", 2), #at most half for contributing
  66676. (val_min, ":cur_wealth", ":ransom"),
  66677. (val_min, ":ransom_amount", ":cur_wealth"), #actual amount the lord can give
  66678. (try_end),
  66679. (troop_set_slot, ":lord_no", slot_troop_player_debt, ":ransom_amount"),
  66680. (try_end),
  66681. (assign, reg0, ":ransom_amount"),
  66682. ]
  66683. ),
  66684.  
  66685. #script_lend_money_for_ransom
  66686. #actually parcels out the amount calculated in the above script
  66687. ("lend_money_for_ransom", [
  66688. (store_script_param_1, ":lord_no"), #usually $g_talk_troop
  66689. (try_begin),
  66690. (troop_get_slot, ":ransom_amount", ":lord_no", slot_troop_player_debt),
  66691. (le, ":ransom_amount", 0),
  66692. (store_script_param_2, ":ransom_amount"),
  66693. (try_end),
  66694. (quest_get_slot, ":cur_ransom", "qst_rescue_prisoner", slot_quest_target_state),
  66695. (val_add, ":cur_ransom", ":ransom_amount"), #actual amount to give
  66696.  
  66697. #set up quests
  66698. (quest_set_slot, "qst_rescue_prisoner", slot_quest_target_state, ":cur_ransom"),
  66699. (assign, reg0, ":cur_ransom"),
  66700. #the amount calculated at the start, will differ from expected ransom
  66701. (quest_get_slot, reg1, "qst_rescue_prisoner", slot_quest_target_amount),
  66702. (str_store_string, s1, "@You have raised {reg0}/{reg1} denars for the ransom"),
  66703. (add_quest_note_from_sreg, "qst_rescue_prisoner", 4, s1, 1), #0:date, 1:giver, 2:desc 3:time
  66704.  
  66705. #move actual gold
  66706. (troop_add_gold, "trp_player", ":ransom_amount"),
  66707. (try_begin),
  66708. (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  66709. (call_script, "script_dplmc_remove_gold_from_lord_and_holdings", ":ransom_amount", ":lord_no"),
  66710. (val_add, ":ransom_amount", dplmc_ransom_debt_mask), #masking this from "real" debt
  66711. (troop_set_slot, ":lord_no", slot_troop_player_debt, ":ransom_amount"),
  66712. (try_end),
  66713.  
  66714. ]
  66715. ),
  66716.  
  66717.  
  66718. #script_cf_dplmc_battle_continuation
  66719. #new camera setup scripts, setting up other calls
  66720.  
  66721. ("cf_dplmc_battle_continuation", [
  66722. (eq, "$g_dplmc_battle_continuation", 0),
  66723. (assign, ":num_allies", 0),
  66724. (try_for_agents, ":agent"),
  66725. (agent_is_ally, ":agent"),
  66726. (agent_is_alive, ":agent"),
  66727. (val_add, ":num_allies", 1),
  66728. (try_end),
  66729. (gt, ":num_allies", 0),
  66730. (try_begin),
  66731. (eq, "$g_dplmc_cam_activated", 0),
  66732. #(store_mission_timer_a, "$g_dplmc_main_hero_fallen_seconds"),
  66733. (assign, "$g_dplmc_cam_activated", "$g_dplmc_cam_default"),
  66734.  
  66735. (display_message, "@You have been knocked out by the enemy. Watch your men continue the fight without you or press Tab to retreat."),
  66736. (store_add, ":string", "$g_dplmc_cam_activated", "str_camera_keyboard"),
  66737. (val_sub, ":string", 1),
  66738. (display_message, ":string"),
  66739. # (display_message, "@To watch the fight you can use 'w, a, s, d, numpad_+/numpad_-' to move and 'numpad_1,2,3,4,6,8' to rotate the cam."),
  66740.  
  66741. (try_begin), #http://forums.taleworlds.com/index.php/topic,322343.0.html
  66742. (eq, "$g_dplmc_charge_when_dead", 1),
  66743. (get_player_agent_no, ":player_agent"),
  66744. (agent_get_team, ":player_team", ":player_agent"),
  66745. (set_show_messages, 0),
  66746. (team_give_order, ":player_team", grc_everyone, mordr_charge),
  66747. (team_give_order, ":player_team", grc_everyone, mordr_use_any_weapon),
  66748. (team_give_order, ":player_team", grc_everyone, mordr_fire_at_will),
  66749. (set_show_messages, 1),
  66750. (try_end),
  66751.  
  66752. (mission_cam_get_position, pos1), #Death pos
  66753. (position_get_rotation_around_z, ":rot_z", pos1),
  66754.  
  66755. (init_position, pos47),
  66756. (position_copy_origin, pos47, pos1), #Copy X,Y,Z pos
  66757. (position_rotate_z, pos47, ":rot_z"), #Copying X-Rotation is likely possible, but I haven't figured it out yet
  66758.  
  66759. (mission_cam_set_mode, 1, 0, 0), #Manual?
  66760.  
  66761. (try_begin), #auto-assign the closest agent
  66762. (eq, "$g_dplmc_cam_activated", camera_follow),
  66763. (call_script, "script_dmod_closest_agent"),
  66764. (try_end),
  66765.  
  66766. (mission_cam_set_position, pos47),
  66767. (try_end),
  66768. ]),
  66769.  
  66770. ("init_keys_array", keys_array()),
  66771. ("setup_camera_keys", [
  66772.  
  66773. # (assign, "$g_dplmc_cam_default", camera_keyboard),
  66774. # (assign, "$g_camera_up", key_w),
  66775. # (assign, "$g_camera_down", key_s),
  66776. # (assign, "$g_camera_left", key_a),
  66777. # (assign, "$g_camera_right", key_d),
  66778.  
  66779. #default custom commander y/z offsets
  66780. (call_script, "script_setup_camera_offset"),
  66781. #these will be retained after being changed inside missions
  66782.  
  66783. #deathcam
  66784. (assign, "$g_cam_tilt_left", key_numpad_1),
  66785. (assign, "$g_cam_tilt_right", key_numpad_3),
  66786.  
  66787. (assign, "$g_camera_adjust_add", key_numpad_plus),
  66788. (assign, "$g_camera_adjust_sub", key_numpad_minus),
  66789.  
  66790. #normally numpad swaps equipment, but we're dead so w/e
  66791. (assign, "$g_camera_rot_up", key_numpad_8),
  66792. (assign, "$g_camera_rot_down", key_numpad_2),
  66793. (assign, "$g_camera_rot_left", key_numpad_4),
  66794. (assign, "$g_camera_rot_right", key_numpad_6),
  66795. ]),
  66796.  
  66797. #call when camera positions get weird
  66798. ("setup_camera_offset",
  66799. [
  66800. (assign, "$g_camera_z", 200),
  66801. (assign, "$g_camera_y", -175),
  66802. (assign, "$g_camera_rotate_x", 0),
  66803. (assign, "$g_camera_rotate_y", 0),
  66804. (assign, "$g_camera_rotate_z", 0),
  66805.  
  66806. ]),
  66807.  
  66808. #initialize all active death cam globals
  66809. ("init_death_cam",
  66810. [
  66811. (assign, "$deathcam_mouse_last_x", 5000),
  66812. (assign, "$deathcam_mouse_last_y", 3750),
  66813. (assign, "$deathcam_mouse_last_notmoved_x", 5000),
  66814. (assign, "$deathcam_mouse_last_notmoved_y", 3750),
  66815. (assign, "$deathcam_mouse_notmoved_x", 5000), #Center screen (10k fixed pos)
  66816. (assign, "$deathcam_mouse_notmoved_y", 3750),
  66817. (assign, "$deathcam_mouse_notmoved_counter", 0),
  66818.  
  66819. (assign, "$deathcam_total_rotx", 0),
  66820.  
  66821. (assign, "$deathcam_sensitivity_x", 400), #4:3 ratio may be best
  66822. (assign, "$deathcam_sensitivity_y", 300), #If modified, change values in common_move_deathcam
  66823.  
  66824. (assign, "$deathcam_prsnt_was_active", 0),
  66825.  
  66826. (assign, "$deathcam_keyboard_rotation_x", 0),
  66827. (assign, "$deathcam_keyboard_rotation_y", 0),
  66828.  
  66829. (assign, "$g_dplmc_cam_activated", 0),
  66830. (assign, "$dmod_current_agent", -1),
  66831. # check if keys are not set/invalid
  66832. (try_begin),
  66833. (neg|is_between, "$g_dplmc_cam_default", camera_keyboard, camera_follow + 1),
  66834. (call_script, "script_setup_camera_keys"),
  66835. (assign, "$g_dplmc_cam_default", camera_keyboard),
  66836. (try_end),
  66837.  
  66838. (get_player_agent_no, "$g_player_agent"),
  66839. (agent_get_team, "$g_player_team", "$g_player_agent"),
  66840. ]),
  66841.  
  66842. ("cf_cancel_camera_keys", [
  66843. (this_or_next|game_key_is_down, gk_view_char),
  66844. (this_or_next|game_key_is_down, gk_zoom),
  66845. (game_key_is_down, gk_cam_toggle),
  66846. (mission_cam_set_mode, 0),
  66847. ]),
  66848.  
  66849. ("dmod_closest_agent", [
  66850. (assign, ":cur_agent", -1),
  66851. (assign, ":distance", 999999),
  66852. (mission_cam_get_position, pos11),
  66853. (position_set_z_to_ground_level, pos11),
  66854. (try_for_agents, ":agent_no"),
  66855. (agent_is_human, ":agent_no"),
  66856. (agent_is_alive, ":agent_no"),
  66857. (agent_is_ally, ":agent_no"),
  66858. #position on the ground
  66859. (agent_get_position, pos13, ":agent_no"),
  66860. # (position_get_screen_projection, pos14, pos13),
  66861. # (get_distance_between_positions, ":cur_distance", pos12, pos14),
  66862. (get_distance_between_positions, ":cur_distance", pos11, pos13),
  66863. (lt, ":cur_distance", ":distance"),
  66864. (assign, ":distance", ":cur_distance"),
  66865. (assign, ":cur_agent", ":agent_no"),
  66866. (try_end),
  66867. (try_begin),
  66868. (neq, ":cur_agent", 1),
  66869. (assign, "$dmod_current_agent", ":cur_agent"),
  66870. (str_store_agent_name, 1, "$dmod_current_agent"),
  66871. (display_message, "@Selected Troop: {s1}"),
  66872. (try_end),
  66873.  
  66874. ]
  66875. ),
  66876. # script_dmod_cycle_forwards
  66877. # Output: New $dmod_current_agent
  66878. # Used to cycle forwards through valid agents
  66879. ("dmod_cycle_forwards",[
  66880.  
  66881. (assign, ":agent_moved", 0),
  66882. (assign, ":first_agent", -1),
  66883. # (get_player_agent_no, ":player_agent"),
  66884. # (agent_get_team, ":player_team", ":player_agent"),
  66885.  
  66886. (try_for_agents, ":agent_no"),
  66887. (neq, ":agent_moved", 1),
  66888. (neq, ":agent_no", "$g_player_agent"),
  66889. (agent_is_human, ":agent_no"),
  66890. (agent_is_alive, ":agent_no"),
  66891. (agent_is_ally, ":agent_no"),
  66892. # (agent_get_team, ":cur_team", ":agent_no"),
  66893. # (this_or_next|eq, ":cur_team", 5), #bodyguards
  66894. # (eq, ":cur_team", ":player_team"),
  66895. (try_begin),
  66896. (lt, ":first_agent", 0),
  66897. (assign, ":first_agent", ":agent_no"),
  66898. (try_end),
  66899. (gt, ":agent_no", "$dmod_current_agent"),
  66900. (assign, "$dmod_current_agent", ":agent_no"),
  66901. (assign, ":agent_moved", 1),
  66902. (try_end),
  66903.  
  66904. (try_begin),
  66905. (eq, ":agent_moved", 0),
  66906. (neq, ":first_agent", -1),
  66907. (assign, "$dmod_current_agent", ":first_agent"),
  66908. (assign, ":agent_moved", 1),
  66909. (else_try),
  66910. (eq, ":agent_moved", 0),
  66911. (eq, ":first_agent", -1),
  66912. (display_message, "@No Troops Left."),
  66913. (try_end),
  66914.  
  66915. (try_begin),
  66916. (eq, ":agent_moved", 1),
  66917. (str_store_agent_name, s1, "$dmod_current_agent"),
  66918. (display_message, "@Selected Troop: {s1}"),
  66919. (try_end),
  66920. #(assign, "$dmod_move_camera", 1),
  66921. ]),
  66922.  
  66923. # script_dmod_cycle_backwards
  66924. # Output: New $dmod_current_agent
  66925. # Used to cycle backwards through valid agents
  66926. ("dmod_cycle_backwards",[
  66927.  
  66928. (assign, ":new_agent", -1),
  66929. (assign, ":last_agent", -1),
  66930. # (get_player_agent_no, ":player_agent"),
  66931. # (agent_get_team, ":player_team", ":player_agent"),
  66932.  
  66933. (try_for_agents, ":agent_no"),
  66934. (neq, ":agent_no", "$g_player_agent"),
  66935. (agent_is_human, ":agent_no"),
  66936. (agent_is_alive, ":agent_no"),
  66937. (agent_is_ally, ":agent_no"),
  66938. # (agent_get_team, ":cur_team", ":agent_no"),
  66939. # (this_or_next|eq, ":cur_team", 5), #bodyguards
  66940. # (eq, ":cur_team", ":player_team"),
  66941. (assign, ":last_agent", ":agent_no"),
  66942. (lt, ":agent_no", "$dmod_current_agent"),
  66943. (assign, ":new_agent", ":agent_no"),
  66944. (try_end),
  66945.  
  66946. (try_begin),
  66947. (eq, ":new_agent", -1),
  66948. (neq, ":last_agent", -1),
  66949. (assign, ":new_agent", ":last_agent"),
  66950. (else_try),
  66951. (eq, ":new_agent", -1),
  66952. (eq, ":last_agent", -1),
  66953. (display_message, "@No Troops Left."),
  66954. (try_end),
  66955.  
  66956. (try_begin),
  66957. (neq, ":new_agent", -1),
  66958. (assign, "$dmod_current_agent", ":new_agent"),
  66959. (str_store_agent_name, 1, "$dmod_current_agent"),
  66960. (display_message, "@Selected Troop: {s1}"),
  66961. (try_end),
  66962. ]),
  66963.  
  66964.  
  66965.  
  66966. #script_start_town_conversation
  66967. #input: center's slot no, entry points
  66968. #used to talk to various center merchant npcs including guildmaster
  66969. ("start_town_conversation",
  66970. [
  66971. (store_script_param, ":troop_slot_no", 1),
  66972. (store_script_param, ":entry_no", 2),
  66973.  
  66974. (assign, "$talk_context", tc_town_talk),
  66975. (try_begin),
  66976. (eq, ":troop_slot_no", slot_town_merchant),
  66977. (assign, ":scene_slot_no", slot_town_store),
  66978. (else_try),
  66979. (eq, ":troop_slot_no", slot_town_tavernkeeper),
  66980. (assign, ":scene_slot_no", slot_town_tavern),
  66981. (assign, "$talk_context", tc_tavern_talk),
  66982. (else_try),
  66983. (assign, ":scene_slot_no", slot_town_center),
  66984. (try_end),
  66985.  
  66986. (party_get_slot, ":conversation_scene", "$current_town", ":scene_slot_no"),
  66987. (modify_visitors_at_site, ":conversation_scene"),
  66988. (reset_visitors),
  66989. (set_visitor, 0, "trp_player"),
  66990.  
  66991. (try_begin),
  66992. (gt, "$sneaked_into_town", disguise_none),
  66993. (mission_tpl_entry_set_override_flags, "mt_conversation_encounter", 0, af_override_all),
  66994. #SB : use script call
  66995. (call_script, "script_set_disguise_override_items", "mt_conversation_encounter", 0, 0),
  66996. (else_try),
  66997. (mission_tpl_entry_set_override_flags, "mt_conversation_encounter", 0, af_override_horse),
  66998. (mission_tpl_entry_clear_override_items, "mt_conversation_encounter", 0),
  66999. (try_end),
  67000. (party_get_slot, ":conversation_troop", "$current_town", ":troop_slot_no"),
  67001. (set_visitor, ":entry_no", ":conversation_troop"),
  67002. (set_jump_mission,"mt_conversation_encounter"),
  67003. (jump_to_scene, ":conversation_scene"),
  67004. (change_screen_map_conversation, ":conversation_troop"),
  67005. ]),
  67006. #talking to people outside the court (neutral, tc_castle_gate)
  67007.  
  67008. ("start_courtyard_conversation",
  67009. [
  67010. (store_script_param, ":conversation_troop", 1),
  67011. (store_script_param, ":center_no", 2),
  67012.  
  67013. (party_get_slot, ":conversation_scene", ":center_no", slot_town_center), #castle's exterior
  67014. (modify_visitors_at_site, ":conversation_scene"),
  67015. (reset_visitors),
  67016. (try_begin), #player vs troop, not much processing
  67017. (neg|troop_is_hero, ":conversation_troop"),
  67018.  
  67019. (else_try), #talking to lords, compare relative positions
  67020. (assign, ":supplicant", "trp_player"),
  67021. (store_faction_of_party, ":faction_no", ":center_no"),
  67022. (call_script, "script_dplmc_get_troop_standing_in_faction", "trp_player", ":faction_no"),
  67023. (assign, ":player_standing", reg0),
  67024. (call_script, "script_dplmc_get_troop_standing_in_faction", ":conversation_troop", ":faction_no"),
  67025. (assign, ":other_troop_standing", reg0),
  67026.  
  67027. #23 : castle guard (adjacent), 2: lord's hall door
  67028. (assign, ":entry_lower", 23),
  67029. (assign, ":entry_upper", 2),
  67030. #overwrite standing if center owned
  67031. (try_begin),
  67032. (party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
  67033. (assign, ":player_standing", 9999),
  67034. (else_try),
  67035. (party_slot_eq, ":center_no", slot_town_lord, ":conversation_troop"),
  67036. (assign, ":other_troop_standing", 9999),
  67037. (else_try), #strangers, use default street entry point (this may be outside in towns, 0 preferred)
  67038. (this_or_next|eq, ":player_standing", DPLMC_FACTION_STANDING_UNAFFILIATED),
  67039. (eq, ":other_troop_standing", DPLMC_FACTION_STANDING_UNAFFILIATED),
  67040. (assign, ":entry_lower", 1),
  67041. (try_end),
  67042.  
  67043. (try_begin), #player is usually supplicant
  67044. (gt, ":player_standing", ":other_troop_standing"),
  67045. (assign, ":supplicant", ":conversation_troop"),
  67046. (assign, ":conversation_troop", "trp_player"),
  67047. (else_try),
  67048. (is_between, ":center_no", towns_begin, towns_end),
  67049. (eq, ":player_standing", ":other_troop_standing"),
  67050. (assign, ":entry_upper", 27),
  67051. (assign, ":entry_lower", 28),
  67052. (try_end),
  67053. (try_end),
  67054.  
  67055. (mission_tpl_entry_set_override_flags, "mt_conversation_encounter", ":entry_lower", af_override_horse|af_override_head|af_override_weapons),
  67056. (mission_tpl_entry_set_override_flags, "mt_conversation_encounter", ":entry_upper", af_override_horse|af_override_fullhelm),
  67057. (set_visitor, ":entry_lower", ":supplicant"),
  67058. (set_visitor, ":entry_upper", ":conversation_troop"),
  67059.  
  67060. (set_jump_mission,"mt_conversation_encounter"),
  67061. (jump_to_scene, ":conversation_scene"),
  67062. (change_screen_map_conversation, ":conversation_troop"),
  67063. ]),
  67064.  
  67065. #talking to people within the court (after capture for instance)
  67066. ("start_court_conversation",
  67067. [
  67068. (store_script_param, ":conversation_troop", 1),
  67069. (store_script_param, ":center_no", 2),
  67070.  
  67071. (party_get_slot, ":conversation_scene", ":center_no", slot_town_castle),
  67072. (modify_visitors_at_site, ":conversation_scene"),
  67073. (reset_visitors),
  67074. (set_visitor, 0, "trp_player"),
  67075. (mission_tpl_entry_set_override_flags, "mt_conversation_encounter", 0, af_override_horse),
  67076.  
  67077. #clear flags for actual courtly conversations?
  67078. (store_random_in_range, ":entry_no", 16, 32),
  67079. (mission_tpl_entry_set_override_flags, "mt_conversation_encounter", ":entry_no", af_override_horse),
  67080. (try_begin),
  67081. (troop_is_hero, ":conversation_troop"),
  67082. (set_visitor, ":entry_no", ":conversation_troop"),
  67083. (else_try),
  67084. (store_script_param, ":troop_dna", 3),
  67085. (set_visitor, ":entry_no", ":conversation_troop", ":troop_dna"),
  67086. (try_end),
  67087. (set_jump_mission,"mt_conversation_encounter"),
  67088. (jump_to_scene, ":conversation_scene"),
  67089. (change_screen_map_conversation, ":conversation_troop"),
  67090. ]),
  67091.  
  67092.  
  67093. #script_companion_get_mission_string
  67094. #input: companion troop_id
  67095. #output: "{!}{s4}: {s8} ({s5})" to s0
  67096. #unify the menu (rarely called) and troop notes for consistency
  67097. #side-effects include overwriting s9, reg3, etc.
  67098. ("companion_get_mission_string", [
  67099. (store_script_param, ":companion", 1),
  67100. (try_begin), #do not impose conditions here, do so from calling script
  67101. # (this_or_next|main_party_has_troop, ":companion"),
  67102. # (this_or_next|troop_slot_ge, ":companion", slot_troop_current_mission, 1),
  67103. # (eq, "$g_player_minister", ":companion"),
  67104. (str_store_troop_name, s4, ":companion"),
  67105. (str_clear, s5),
  67106. (str_clear, s8),
  67107. (troop_get_slot, ":days_left", ":companion", slot_troop_days_on_mission),
  67108. (troop_get_slot, ":mission", ":companion", slot_troop_current_mission),
  67109. (try_begin),
  67110. (le, ":days_left", 0),
  67111. (str_store_string, s5, "str_whereabouts_unknown"),
  67112. (else_try),
  67113. (eq, ":days_left", 1),
  67114. (str_store_string, s5, "str_expected_back_imminently"),
  67115. (else_try),
  67116. (assign, reg3, ":days_left"),
  67117. (str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
  67118. (try_end),
  67119.  
  67120.  
  67121. (try_begin),
  67122. (eq, ":mission", npc_mission_kingsupport),
  67123. (str_store_string, s8, "str_gathering_support"),
  67124. (else_try),
  67125. (this_or_next|eq, ":mission", npc_mission_gather_intel),
  67126. (eq, ":mission", dplmc_npc_mission_rescue_prisoner), #new mission
  67127. (troop_get_slot, ":town_with_contacts", ":companion", slot_troop_town_with_contacts),
  67128. (str_store_party_name, s9, ":town_with_contacts"),
  67129. (try_begin),
  67130. (eq, ":mission", npc_mission_gather_intel),
  67131. (str_store_string, s8, "str_gathering_intelligence"),
  67132. (else_try),
  67133. (eq, ":mission", dplmc_npc_mission_rescue_prisoner),
  67134. (str_store_string, s8, "str_preparing_prison_break"),
  67135. (try_end),
  67136. (else_try),
  67137. (this_or_next|is_between, ":mission", npc_mission_peace_request, npc_mission_rejoin_when_possible),
  67138. (is_between, ":mission", dplmc_npc_mission_war_request, dplmc_npc_mission_rescue_prisoner),
  67139.  
  67140. (troop_get_slot, ":faction", ":companion", slot_troop_mission_object),
  67141. (str_store_faction_name, s9, ":faction"),
  67142. (str_store_string, s8, "str_diplomatic_embassy_to_s9"),
  67143. # (else_try), #diplomacy missions
  67144.  
  67145. (else_try),
  67146. (eq, ":companion", "$g_player_minister"),
  67147. (str_store_string, s8, "str_serving_as_minister"),
  67148. (try_begin),
  67149. (is_between, "$g_player_court", centers_begin, centers_end),
  67150. (str_store_party_name, s9, "$g_player_court"),
  67151. (str_store_string, s5, "str_in_your_court_at_s9"),
  67152. (else_try),
  67153. (str_store_string, s5, "str_awaiting_the_capture_of_a_fortress_which_can_serve_as_your_court"),
  67154. (try_end),
  67155. (else_try),
  67156. (eq, ":mission", npc_mission_rejoin_when_possible),
  67157. (str_store_string, s8, "str_attempting_to_rejoin_party"),
  67158. (else_try),
  67159. (main_party_has_troop, ":companion"),
  67160. (str_store_string, s8, "str_under_arms"),
  67161. (str_store_string, s5, "str_in_your_party"),
  67162. (else_try), #Companions who are in a center
  67163. (troop_slot_ge, ":companion", slot_troop_cur_center, centers_begin),
  67164. (str_store_string, s8, "str_separated_from_party"),
  67165. (str_store_string, s5, "str_whereabouts_unknown"),
  67166. (else_try), #Companions who are (imprisoned) in a center
  67167. (troop_slot_ge, ":companion", slot_troop_prisoner_of_party, centers_begin),
  67168. (str_store_string, s8, "str_missing_after_battle"),
  67169. (str_store_string, s5, "str_whereabouts_unknown"),
  67170. (else_try),
  67171. (try_begin),
  67172. (check_quest_active, "qst_lend_companion"),
  67173. (quest_slot_eq, "qst_lend_companion", slot_quest_target_troop, ":companion"),
  67174. (quest_get_slot, ":lord", "qst_lend_companion", slot_quest_giver_troop),
  67175. (str_store_troop_name, s5, ":lord"),
  67176. (str_store_string, s8, "str_accompanying_s5"),
  67177. (str_store_string, s5, "str_on_loan"),
  67178. (else_try),
  67179. (check_quest_active, "qst_lend_surgeon"),
  67180. (quest_slot_eq, "qst_lend_surgeon", slot_quest_target_troop, ":companion"),
  67181. (quest_get_slot, ":lord", "qst_lend_surgeon", slot_quest_giver_troop),
  67182. (str_store_troop_name, s5, ":lord"),
  67183. (str_store_string, s8, "str_accompanying_s5"),
  67184. (str_store_string, s5, "str_on_loan"),
  67185. (try_end),
  67186. (try_end),
  67187.  
  67188. (str_store_string, s0, "str_s4_s8_s5"),
  67189. (try_end),
  67190. ]
  67191. ),
  67192. #iterates through list of obtainable soldiers (and check if the player has reclassified them to a custom class > grc_cavalry)
  67193. #instead of going through all troops globally, we check the selected center's garrison's upgraded troops
  67194. ("cf_troop_class_activated",
  67195. [
  67196. (store_script_param, ":grc", 1),
  67197. (store_script_param, ":party_no", 2),
  67198. (is_between, ":grc", grc_infantry, grc_everyone),
  67199. (try_begin), #first 3 always available
  67200. (le, ":grc", grc_cavalry),
  67201. (assign, ":end", -1),
  67202. (else_try),
  67203. (party_get_num_companion_stacks, ":end", ":party_no"),
  67204.  
  67205. (try_for_range, ":stack_no", 0, ":end"),
  67206. (party_stack_get_troop_id, ":troop_no", ":party_no", ":stack_no"),
  67207. (neg|troop_is_hero, ":troop_no"),
  67208. (try_begin),
  67209. (troop_get_upgrade_troop, ":upgrade_troop", ":troop_no", 0),
  67210. (gt, ":upgrade_troop", 0),
  67211. (troop_get_class, ":class_no", ":upgrade_troop"),
  67212. (eq, ":class_no", ":grc"),
  67213. (assign, ":end", -1),
  67214. (try_end),
  67215. (try_begin), #not found, check other upgrade
  67216. (neq, ":end", -1),
  67217. (troop_get_upgrade_troop, ":upgrade_troop", ":troop_no", 1),
  67218. (gt, ":upgrade_troop", 0),
  67219. (troop_get_class, ":class_no", ":upgrade_troop"),
  67220. (eq, ":class_no", ":grc"),
  67221. (assign, ":end", -1),
  67222. (try_end),
  67223. (try_end),
  67224. # (try_for_range, ":troop_no", soldiers_begin, soldiers_end),
  67225. # (neg|troop_is_hero, ":troop_no"),
  67226. # (troop_get_class, ":class", ":troop_no"),
  67227. # (try_end),
  67228. (try_end),
  67229. (eq, ":end", -1),
  67230.  
  67231. ]),
  67232.  
  67233. ("cf_troop_is_class",
  67234. [
  67235. (store_script_param, ":grc", 1),
  67236. (store_script_param, ":troop_no", 2),
  67237. (is_between, ":grc", grc_infantry, grc_everyone), #usually $g_constable_training_type
  67238. (gt, ":troop_no", 0), #this is usually obtained through troop_get_upgrade_troop, sanitize it here
  67239.  
  67240. (troop_get_class, ":class_no", ":troop_no"),
  67241. (eq, ":grc", ":class_no"),
  67242. ]),
  67243. #script_dplmc_npc_morale
  67244. ("dplmc_npc_morale",
  67245. [
  67246. (store_script_param_1, ":npc"),
  67247. (store_script_param_2, ":mode"),
  67248. (try_begin), #if we actually care
  67249. (eq, ":mode", 1),
  67250. (call_script, "script_npc_morale", ":npc"),
  67251. (else_try), #we just want the numbers
  67252. (troop_get_slot, ":morality_grievances", ":npc", slot_troop_morality_penalties),
  67253. (troop_get_slot, ":personality_grievances", ":npc", slot_troop_personalityclash_penalties),
  67254. (party_get_morale, ":party_morale", "p_main_party"),
  67255.  
  67256. (store_sub, ":troop_morale", ":party_morale", ":morality_grievances"),
  67257. (val_sub, ":troop_morale", ":personality_grievances"),
  67258. (val_add, ":troop_morale", 50),
  67259.  
  67260. # (assign, reg8, ":troop_morale"),
  67261.  
  67262. (val_mul, ":troop_morale", 3),
  67263. (val_div, ":troop_morale", 4),
  67264. (val_clamp, ":troop_morale", 0, 100),
  67265. (assign, reg0, ":troop_morale"),
  67266. (try_end),
  67267. ]),
  67268.  
  67269. #script_build_background_answer_story
  67270. #input: sreg, other info based off global background_answer variables
  67271. #output: story to s0, side effects are reg11, s10 through s13
  67272. ("build_background_answer_story", [
  67273. (store_script_param_1, ":sreg"),
  67274. (assign, reg11, "$character_gender"),
  67275. (store_sub, ":string", "$background_answer_4", cb4_revenge),
  67276. (val_add, ":string", "str_story_reason_revenge"),
  67277. (str_store_string, s13, ":string"),
  67278. (store_sub, ":string", "$background_answer_3", dplmc_cb3_bravo),
  67279. (val_add, ":string", "str_story_job_bravo"),
  67280. (str_store_string, s12, ":string"),
  67281. (store_sub, ":string", "$background_answer_2", cb2_page), #values for this start from 0
  67282. (val_add, ":string", "str_story_childhood_page"),
  67283. (str_store_string, s11, ":string"),
  67284. (store_sub, ":string", "$background_type", cb_noble),
  67285. (val_add, ":string", "str_story_parent_noble"),
  67286. (str_store_string, s10, ":string"),
  67287. (str_store_string, ":sreg", "str_story_all"),
  67288. ]),
  67289.  
  67290. #whenever the player does something nice, spectators cheer
  67291. ("agents_cheer_during_training", [
  67292. (party_get_morale, ":cur_morale", "p_main_party"),
  67293. (assign, ":boundary", 150),
  67294. #first aid double-stacks since it's not a battle
  67295. (try_for_agents, ":agent_no"),
  67296. (agent_is_active, ":agent_no"),
  67297. (agent_is_human, ":agent_no"),
  67298. # (agent_get_troop_id, ":troop_no", ":agent_no"), #a spectator
  67299. (neg|agent_has_item_equipped, ":agent_no", "itm_practice_boots"),
  67300. (store_random_in_range, ":random_no", ":cur_morale", 250),
  67301. (gt, ":random_no", ":boundary"),
  67302. (val_add, ":boundary", 15),
  67303. (agent_set_animation, ":agent_no", "anim_cheer"),
  67304. (store_random_in_range, ":random_no", 0, 100),
  67305. (agent_set_animation_progress, ":agent_no", ":random_no"),
  67306. (try_end),
  67307. ]),
  67308.  
  67309. #a separate trigger handles when they're actually knocked out
  67310. ("troop_set_training_health_from_agent", [
  67311. (party_get_skill_level, ":first_aid", "p_main_party", "skl_first_aid"),
  67312. #first aid double-stacks since it's not a battle
  67313. (try_for_agents, ":agent_no"),
  67314. # (agent_is_active, ":agent_no"),
  67315. (agent_is_human, ":agent_no"),
  67316. (agent_get_troop_id, ":troop_no", ":agent_no"),
  67317. (troop_is_hero, ":troop_no"),
  67318. (store_troop_health, ":health", ":troop_no", 0), #this is not yet deducted
  67319. (store_agent_hit_points, ":hp", ":agent_no", 0),
  67320. (val_sub, ":hp", ":health"), #this is the difference
  67321. (try_begin),
  67322. (agent_is_alive, ":agent_no"),
  67323. (store_skill_level, ":skill", "skl_first_aid", ":troop_no"),
  67324. (val_add, ":skill", ":first_aid"),
  67325. (else_try),
  67326. (assign, ":skill", ":first_aid"),
  67327. (try_end),
  67328. (val_mul, ":skill", -5), #as per skill description
  67329. (val_add, ":skill", 100), # 100 - skill effect
  67330. #apply skill effect and set health
  67331. (val_mul, ":hp", ":skill"),
  67332. (val_div, ":hp", 100),
  67333. (val_add, ":hp", ":health"), #subtract modified difference
  67334. (troop_set_health, ":troop_no", ":hp", 0),
  67335. (try_end),
  67336. ]),
  67337.  
  67338. #script_agent_apply_training_health
  67339. #input: player_agent, called from abm_training during melee fights, can also be used for tournament if desired
  67340. ("agent_apply_training_health", [
  67341. (store_script_param_1, ":agent_no"),
  67342. # (store_script_param_2, "$current_town"),
  67343.  
  67344. (party_get_skill_level, ":first_aid", "p_main_party", "skl_first_aid"),
  67345. (party_get_slot, ":relation", "$current_town", slot_center_player_relation), #range from -100 to 100
  67346. (store_sub, ":relation", 200, ":relation"), #300 to 100
  67347.  
  67348. (store_troop_health, ":health", "trp_player", 0), #this is not yet deducted
  67349. (store_agent_hit_points, ":hp", ":agent_no", 0),
  67350.  
  67351. (val_sub, ":hp", ":health"), #this is the difference (non-positive)
  67352. (try_begin),
  67353. (agent_is_alive, ":agent_no"),
  67354. (store_skill_level, ":skill", "skl_first_aid", "trp_player"),
  67355. (else_try),
  67356. (assign, ":skill", 0),
  67357. (try_end),
  67358. (val_add, ":skill", ":first_aid"),
  67359. (val_mul, ":skill", -5), #as per skill description
  67360. (val_add, ":skill", 100), # 100 - skill effect
  67361. #apply skill effect, relation effect and set health
  67362. (val_mul, ":hp", ":skill"),
  67363. (val_div, ":hp", 100),
  67364. (val_mul, ":hp", ":relation"),
  67365. (val_div, ":hp", 200),
  67366. (val_add, ":health", ":hp"), #subtract modified difference
  67367. (val_max, ":health", 5),
  67368. (troop_set_health, "trp_player", ":health", 0),
  67369. ]),
  67370.  
  67371. # script_party_heal_all_members_aux, opposite of script_party_wound_all_members_aux
  67372. # Input: arg1 = party_no
  67373. ("party_heal_all_members_aux",
  67374. [
  67375. (store_script_param_1, ":party_no"),
  67376.  
  67377. (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  67378. (try_for_range_backwards, ":i_stack", 0, ":num_stacks"),
  67379. (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  67380. (try_begin),
  67381. (neg|troop_is_hero, ":stack_troop"),
  67382. # (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  67383. (party_stack_get_num_wounded, ":stack_size",":party_no",":i_stack"),
  67384. (party_add_members, ":party_no", ":stack_troop", ":stack_size"),
  67385. (party_remove_members_wounded_first, ":party_no", ":stack_troop", ":stack_size"),
  67386. (else_try),
  67387. (troop_set_health, ":stack_troop", 100),
  67388. (try_end),
  67389. (try_end),
  67390. (party_get_num_attached_parties, ":num_attached_parties", ":party_no"),
  67391. (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
  67392. (party_get_attached_party_with_rank, ":attached_party", ":party_no", ":attached_party_rank"),
  67393. (call_script, "script_party_heal_all_members_aux", ":attached_party"),
  67394. (try_end),
  67395. ]
  67396. ),
  67397.  
  67398. #script_cf_village_normal_cond
  67399. # INPUT: none
  67400. # OUTPUT: none
  67401. ("cf_village_normal_cond",
  67402. [
  67403. (store_script_param, ":party_no", 1),
  67404. (neg|party_slot_eq, ":party_no", slot_village_state, svs_looted),
  67405. (neg|party_slot_eq, ":party_no", slot_village_state, svs_deserted), #SB : addition here
  67406. (neg|party_slot_eq, ":party_no", slot_village_state, svs_being_raided),
  67407. (neg|party_slot_ge, ":party_no", slot_village_infested_by_bandits, 1),
  67408. ]
  67409. ),
  67410.  
  67411. #script_cf_has_companion_emissary for diplomatic options
  67412. ("cf_has_companion_emissary",
  67413. [
  67414. (assign, ":companion_found", companions_end),
  67415. (try_for_range, ":emissary", companions_begin, companions_end),
  67416. (main_party_has_troop, ":emissary"),
  67417. (assign, ":companion_found", companions_begin),
  67418. (try_end),
  67419. (neq, ":companion_found", companions_end),
  67420. ]),
  67421.  
  67422. #script_get_chest_troop fetches the appropriate placeholder for player storage
  67423. # INPUT: center, usually $current_town
  67424. # OUTPUT: none
  67425. ("get_chest_troop",
  67426. [
  67427. (store_script_param, ":party_no", 1),
  67428. (try_begin),
  67429. (gt, "$g_player_chamberlain", 0),
  67430. (assign, ":chest_troop", "trp_household_possessions"),
  67431. (else_try), #assume troops same order as parties
  67432. # (party_get_slot, ":chest_troop", ":party_no", slot_town_seneschal),
  67433. (val_sub, ":party_no", towns_begin),
  67434. (store_add, ":chest_troop", ":party_no", "trp_town_1_seneschal"),
  67435. (try_end),
  67436. (assign, reg0, ":chest_troop"),
  67437. ]),
  67438.  
  67439. #script_change_faction_troop_morale
  67440. #input - faction, change, display mode
  67441. #output - a colored message
  67442. ("change_faction_troop_morale",
  67443. [(store_script_param, ":faction_no", 1),
  67444. (store_script_param, ":morale_change", 2),
  67445. (store_script_param, ":display", 3),
  67446. (try_begin),
  67447. (eq, ":display", 1),
  67448. (neg|faction_slot_eq, ":faction_no", slot_faction_state, sfs_active),
  67449. (assign, ":display", 0),
  67450. (try_end),
  67451. #check if main party has troop of type before displaying
  67452. (try_begin),
  67453. (eq, ":display", 1),
  67454. (party_get_num_companion_stacks, ":num_stacks", "p_main_party"),
  67455. (try_for_range, ":stack", 1, ":num_stacks"),
  67456. (party_stack_get_troop_id, ":troop", "p_main_party", ":stack"),
  67457. (store_troop_faction, ":fac", ":troop"),
  67458. (eq, ":fac", ":faction_no"),
  67459. (assign, ":num_stacks", 1), #break
  67460. (try_end),
  67461. (neq, ":num_stacks", 1), #none found
  67462. (assign, ":display", 0),
  67463. (try_end),
  67464. #effects are still applied regardless - the displayed morale is divided by 100
  67465. (faction_get_slot, ":morale", ":faction_no", slot_faction_morale_of_player_troops),
  67466. (store_div, reg1, ":morale", 100),
  67467. (val_add, ":morale", ":morale_change"),
  67468. (store_div, reg2, ":morale", 100),
  67469. (faction_set_slot, ":faction_no", slot_faction_morale_of_player_troops, ":morale"),
  67470.  
  67471. # (try_begin),
  67472. # (store_sub, ":diff", reg2, reg1),
  67473. # (eq, ":diff", 0), #negligible
  67474. # (assign, ":display", 0),
  67475. # (try_end),
  67476.  
  67477. #actual output
  67478. (try_begin),
  67479. (eq, ":display", 1),
  67480. (neq, reg1, reg2), #non-zero difference
  67481. #set up s1
  67482. (faction_get_slot, ":adjective", ":faction_no", slot_faction_adjective),
  67483. (str_store_string, s1, ":adjective"),
  67484. (str_store_string, s1, "@{s1} troops"),
  67485. #get increase/decrease, either string will work
  67486. (assign, ":string", "str_troop_relation_detoriated"),
  67487. (try_begin),
  67488. (gt, ":morale_change", 0),
  67489. (assign, ":string", "str_troop_relation_increased"),
  67490. (try_end),
  67491. #get color
  67492. (faction_get_color, ":color", ":faction_no"),
  67493. (display_message, ":string", ":color"),
  67494. (try_end),
  67495. ]
  67496. ),
  67497.  
  67498. #script_encounter_agent_draw_weapon
  67499. #input: none, based on $g_talk_agent
  67500. #output: none, agent wields first available weapon to show aggression
  67501. ("encounter_agent_draw_weapon",
  67502. [
  67503. (store_conversation_agent, "$g_talk_agent"),
  67504. (try_begin),
  67505. (agent_get_item_slot, ":item_no", "$g_talk_agent", ek_item_0),
  67506. (gt, ":item_no", 0),
  67507. (agent_set_wielded_item, "$g_talk_agent", ":item_no"),
  67508. (try_end),
  67509.  
  67510. ]),
  67511.  
  67512. #script_troop_debug_range
  67513. #input: troop, head or tail, sreg
  67514. #output: reg0 as head or tail, sreg holding a short description
  67515. ("cf_troop_debug_range",
  67516. [
  67517. (store_script_param, ":troop_no", 1),
  67518. (store_script_param, ":sreg", 2),
  67519. (store_script_param, ":direction", 3),
  67520. (assign, ":result", ":troop_no"),
  67521. (try_begin),
  67522. (is_between, ":troop_no", heroes_begin, heroes_end),
  67523. (str_store_string, ":sreg", "@hero"),
  67524. (try_begin),
  67525. (eq, ":direction", -1),
  67526. (assign, ":result", heroes_begin),
  67527. (else_try),
  67528. (eq, ":direction", 1),
  67529. (store_sub, ":result", heroes_end, ":direction"),
  67530. (try_end),
  67531. (try_begin),
  67532. (is_between, ":troop_no", companions_begin, companions_end),
  67533. (str_store_string, ":sreg", "@companion"),
  67534. (try_begin),
  67535. (eq, ":direction", -1),
  67536. (assign, ":result", companions_begin),
  67537. (else_try),
  67538. (eq, ":direction", 1),
  67539. (store_sub, ":result", companions_end, ":direction"),
  67540. (try_end),
  67541. (else_try),
  67542. (is_between, ":troop_no", kings_begin, kings_end),
  67543. (str_store_string, ":sreg", "@king"),
  67544. (try_begin),
  67545. (eq, ":direction", -1),
  67546. (assign, ":result", kings_begin),
  67547. (else_try),
  67548. (eq, ":direction", 1),
  67549. (store_sub, ":result", kings_end, ":direction"),
  67550. (try_end),
  67551. (else_try),
  67552. (is_between, ":troop_no", lords_begin, lords_end),
  67553. (str_store_string, ":sreg", "@lord"),
  67554. (try_begin),
  67555. (eq, ":direction", -1),
  67556. (assign, ":result", lords_begin),
  67557. (else_try),
  67558. (eq, ":direction", 1),
  67559. (store_sub, ":result", lords_end, ":direction"),
  67560. (try_end),
  67561. (else_try),
  67562. (is_between, ":troop_no", pretenders_begin, pretenders_end),
  67563. (str_store_string, ":sreg", "@pretender"),
  67564. (try_begin),
  67565. (eq, ":direction", -1),
  67566. (assign, ":result", pretenders_begin),
  67567. (else_try),
  67568. (eq, ":direction", 1),
  67569. (store_sub, ":result", pretenders_end, ":direction"),
  67570. (try_end),
  67571. (else_try),
  67572. (is_between, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  67573. (str_store_string, ":sreg", "@lady"),
  67574. (try_begin),
  67575. (eq, ":direction", -1),
  67576. (assign, ":result", kingdom_ladies_begin),
  67577. (else_try),
  67578. (eq, ":direction", 1),
  67579. (store_sub, ":result", kingdom_ladies_end, ":direction"),
  67580. (try_end),
  67581. (try_end),
  67582. (else_try),
  67583. (is_between, ":troop_no", bandits_begin, bandits_end),
  67584. (str_store_string, ":sreg", "@bandit"),
  67585. (try_begin),
  67586. (eq, ":direction", -1),
  67587. (assign, ":result", bandits_begin),
  67588. (else_try),
  67589. (eq, ":direction", 1),
  67590. (store_sub, ":result", bandits_end, ":direction"),
  67591. (try_end),
  67592. (else_try),
  67593. (is_between, ":troop_no", tavern_minstrels_begin, tavern_minstrels_end),
  67594. (str_store_string, ":sreg", "@minstrel"),
  67595. (try_begin),
  67596. (eq, ":direction", -1),
  67597. (assign, ":result", tavern_minstrels_begin),
  67598. (else_try),
  67599. (eq, ":direction", 1),
  67600. (store_sub, ":result", tavern_minstrels_end, ":direction"),
  67601. (try_end),
  67602. (else_try),
  67603. (is_between, ":troop_no", tavern_booksellers_begin, tavern_booksellers_end),
  67604. (str_store_string, ":sreg", "@bookseller"),
  67605. (try_begin),
  67606. (eq, ":direction", -1),
  67607. (assign, ":result", tavern_booksellers_begin),
  67608. (else_try),
  67609. (eq, ":direction", 1),
  67610. (store_sub, ":result", tavern_booksellers_end, ":direction"),
  67611. (try_end),
  67612. (else_try),
  67613. (is_between, ":troop_no", tavern_travelers_begin, tavern_travelers_end),
  67614. (str_store_string, ":sreg", "@traveler"),
  67615. (try_begin),
  67616. (eq, ":direction", -1),
  67617. (assign, ":result", tavern_travelers_begin),
  67618. (else_try),
  67619. (eq, ":direction", 1),
  67620. (store_sub, ":result", tavern_travelers_end, ":direction"),
  67621. (try_end),
  67622. (else_try),
  67623. (is_between, ":troop_no", ransom_brokers_begin, ransom_brokers_end),
  67624. (str_store_string, ":sreg", "@ransom broker"),
  67625. (try_begin),
  67626. (eq, ":direction", -1),
  67627. (assign, ":result", ransom_brokers_begin),
  67628. (else_try),
  67629. (eq, ":direction", 1),
  67630. (store_sub, ":result", ransom_brokers_end, ":direction"),
  67631. (try_end),
  67632. (else_try),
  67633. (is_between, ":troop_no", mercenary_troops_begin, mercenary_troops_end),
  67634. (str_store_string, ":sreg", "@mercenary"),
  67635. (try_begin),
  67636. (eq, ":direction", -1),
  67637. (assign, ":result", mercenary_troops_begin),
  67638. (else_try),
  67639. (eq, ":direction", 1),
  67640. (store_sub, ":result", mercenary_troops_end, ":direction"),
  67641. (try_end),
  67642. (else_try),
  67643. (is_between, ":troop_no", multiplayer_ai_troops_begin, multiplayer_troops_end),
  67644. (str_store_string, ":sreg", "@multiplayer troop"),
  67645. (try_begin),
  67646. (eq, ":direction", -1),
  67647. (assign, ":result", multiplayer_ai_troops_begin),
  67648. (else_try),
  67649. (eq, ":direction", 1),
  67650. (store_sub, ":result", multiplayer_troops_end, ":direction"),
  67651. (try_end),
  67652. (else_try),
  67653. (is_between, ":troop_no", quick_battle_troops_begin, quick_battle_troops_end),
  67654. (str_store_string, ":sreg", "@quick battler"),
  67655. (try_begin),
  67656. (eq, ":direction", -1),
  67657. (assign, ":result", quick_battle_troops_begin),
  67658. (else_try),
  67659. (eq, ":direction", 1),
  67660. (store_sub, ":result", quick_battle_troops_end, ":direction"),
  67661. (try_end),
  67662. (else_try),
  67663. (is_between, ":troop_no", training_ground_trainers_begin, training_ground_trainers_end),
  67664. (str_store_string, ":sreg", "@trainer"),
  67665. (try_begin),
  67666. (eq, ":direction", -1),
  67667. (assign, ":result", training_ground_trainers_begin),
  67668. (else_try),
  67669. (eq, ":direction", 1),
  67670. (store_sub, ":result", training_ground_trainers_end, ":direction"),
  67671. (try_end),
  67672. (else_try),
  67673. (is_between, ":troop_no", arena_masters_begin, arena_masters_end),
  67674. (str_store_string, ":sreg", "@arena master"),
  67675. (try_begin),
  67676. (eq, ":direction", -1),
  67677. (assign, ":result", arena_masters_begin),
  67678. (else_try),
  67679. (eq, ":direction", 1),
  67680. (store_sub, ":result", arena_masters_end, ":direction"),
  67681. (try_end),
  67682. (else_try),
  67683. (is_between, ":troop_no", walkers_begin, walkers_end),
  67684. (str_store_string, ":sreg", "@walker"),
  67685. (try_begin),
  67686. (eq, ":direction", -1),
  67687. (assign, ":result", walkers_begin),
  67688. (else_try),
  67689. (eq, ":direction", 1),
  67690. (store_sub, ":result", walkers_end, ":direction"),
  67691. (try_end),
  67692. (else_try),
  67693. (is_between, ":troop_no", merchants_begin, merchants_end),
  67694. (str_store_string, ":sreg", "@merchant"),
  67695. (try_begin),
  67696. (eq, ":direction", -1),
  67697. (assign, ":result", merchants_begin),
  67698. (else_try),
  67699. (eq, ":direction", 1),
  67700. (store_sub, ":result", merchants_end, ":direction"),
  67701. (try_end),
  67702. (try_begin),
  67703. (is_between, ":troop_no", armor_merchants_begin, armor_merchants_end),
  67704. (str_store_string, ":sreg", "@armor merchant"),
  67705. (try_begin),
  67706. (eq, ":direction", -1),
  67707. (assign, ":result", armor_merchants_begin),
  67708. (else_try),
  67709. (eq, ":direction", 1),
  67710. (store_sub, ":result", armor_merchants_end, ":direction"),
  67711. (try_end),
  67712. (else_try),
  67713. (is_between, ":troop_no", weapon_merchants_begin, weapon_merchants_end),
  67714. (str_store_string, ":sreg", "@weapon merchant"),
  67715. (try_begin),
  67716. (eq, ":direction", -1),
  67717. (assign, ":result", weapon_merchants_begin),
  67718. (else_try),
  67719. (eq, ":direction", 1),
  67720. (store_sub, ":result", weapon_merchants_end, ":direction"),
  67721. (try_end),
  67722. (else_try),
  67723. (is_between, ":troop_no", tavernkeepers_begin, tavernkeepers_end),
  67724. (str_store_string, ":sreg", "@tavernkeeper"),
  67725. (try_begin),
  67726. (eq, ":direction", -1),
  67727. (assign, ":result", tavernkeepers_begin),
  67728. (else_try),
  67729. (eq, ":direction", 1),
  67730. (store_sub, ":result", tavernkeepers_end, ":direction"),
  67731. (try_end),
  67732. (else_try),
  67733. (is_between, ":troop_no", goods_merchants_begin, goods_merchants_end),
  67734. (str_store_string, ":sreg", "@goods merchant"),
  67735. (try_begin),
  67736. (eq, ":direction", -1),
  67737. (assign, ":result", goods_merchants_begin),
  67738. (else_try),
  67739. (eq, ":direction", 1),
  67740. (store_sub, ":result", goods_merchants_end, ":direction"),
  67741. (try_end),
  67742. (else_try),
  67743. (is_between, ":troop_no", horse_merchants_begin, horse_merchants_end),
  67744. (str_store_string, ":sreg", "@horse merchant"),
  67745. (try_begin),
  67746. (eq, ":direction", -1),
  67747. (assign, ":result", horse_merchants_begin),
  67748. (else_try),
  67749. (eq, ":direction", 1),
  67750. (store_sub, ":result", horse_merchants_end, ":direction"),
  67751. (try_end),
  67752. (else_try),
  67753. (is_between, ":troop_no", mayors_begin, mayors_end),
  67754. (str_store_string, ":sreg", "@guildmaster"),
  67755. (try_begin),
  67756. (eq, ":direction", -1),
  67757. (assign, ":result", mayors_begin),
  67758. (else_try),
  67759. (eq, ":direction", 1),
  67760. (store_sub, ":result", mayors_end, ":direction"),
  67761. (try_end),
  67762. (else_try),
  67763. (is_between, ":troop_no", village_elders_begin, village_elders_end),
  67764. (str_store_string, ":sreg", "@village elder"),
  67765. (try_begin),
  67766. (eq, ":direction", -1),
  67767. (assign, ":result", village_elders_begin),
  67768. (else_try),
  67769. (eq, ":direction", 1),
  67770. (store_sub, ":result", village_elders_end, ":direction"),
  67771. (try_end),
  67772. (try_end),
  67773. (else_try),
  67774. (is_between, ":troop_no", startup_merchants_begin, startup_merchants_end),
  67775. (str_store_string, ":sreg", "@startup merchant"),
  67776. (try_begin),
  67777. (eq, ":direction", -1),
  67778. (assign, ":result", startup_merchants_begin),
  67779. (else_try),
  67780. (eq, ":direction", 1),
  67781. (store_sub, ":result", startup_merchants_end, ":direction"),
  67782. (try_end),
  67783. (else_try),
  67784. (is_between, ":troop_no", tournament_champions_begin, tournament_champions_end),
  67785. (str_store_string, ":sreg", "@tournament fighter"),
  67786. (try_begin),
  67787. (eq, ":direction", -1),
  67788. (assign, ":result", tournament_champions_begin),
  67789. (else_try),
  67790. (eq, ":direction", 1),
  67791. (store_sub, ":result", tournament_champions_end, ":direction"),
  67792. (try_end),
  67793. (else_try),
  67794. (is_between, ":troop_no", craftsman_begin, craftsman_end),
  67795. (str_store_string, ":sreg", "@craftsman"),
  67796. (try_begin),
  67797. (eq, ":direction", -1),
  67798. (assign, ":result", craftsman_begin),
  67799. (else_try),
  67800. (eq, ":direction", 1),
  67801. (store_sub, ":result", craftsman_end, ":direction"),
  67802. (try_end),
  67803. (else_try),
  67804. (is_between, ":troop_no", "trp_town_1_seneschal", arena_masters_begin),
  67805. (str_store_string, ":sreg", "@court chests"),
  67806. (try_begin),
  67807. (eq, ":direction", -1),
  67808. (assign, ":result", "trp_town_1_seneschal"),
  67809. (else_try),
  67810. (eq, ":direction", 1),
  67811. (store_sub, ":result", arena_masters_begin, ":direction"),
  67812. (try_end),
  67813. (else_try),
  67814. (is_between, ":troop_no", "trp_zendar_chest", "trp_local_merchant"),
  67815. (str_store_string, ":sreg", "@chest or array"),
  67816. (try_begin),
  67817. (eq, ":direction", -1),
  67818. (assign, ":result", "trp_zendar_chest"),
  67819. (else_try),
  67820. (eq, ":direction", 1),
  67821. (store_sub, ":result", "trp_local_merchant", ":direction"),
  67822. (try_end),
  67823. (else_try),
  67824. (is_between, ":troop_no", "trp_log_array_entry_type", quick_battle_troops_begin),
  67825. (str_store_string, ":sreg", "@log array"),
  67826. (try_begin),
  67827. (eq, ":direction", -1),
  67828. (assign, ":result", "trp_log_array_entry_type"),
  67829. (else_try),
  67830. (eq, ":direction", 1),
  67831. (store_sub, ":result", quick_battle_troops_begin, ":direction"),
  67832. (try_end),
  67833. (else_try),
  67834. (is_between, ":troop_no", "trp_local_merchant", "trp_quick_battle_6_player"),
  67835. (str_store_string, ":sreg", "@quest troop"),
  67836. (try_begin),
  67837. (eq, ":direction", -1),
  67838. (assign, ":result", "trp_local_merchant"),
  67839. (else_try),
  67840. (eq, ":direction", 1),
  67841. (store_sub, ":result", "trp_quick_battle_6_player", ":direction"),
  67842. (try_end),
  67843. (else_try),
  67844. (is_between, ":troop_no", multiplayer_coop_class_templates_begin, multiplayer_coop_companion_equipment_sets_end),
  67845. (str_store_string, ":sreg", "@coop troop"),
  67846. (try_begin),
  67847. (eq, ":direction", -1),
  67848. (assign, ":result", multiplayer_coop_class_templates_begin),
  67849. (else_try),
  67850. (eq, ":direction", 1),
  67851. (store_sub, ":result", multiplayer_coop_companion_equipment_sets_end, ":direction"),
  67852. (try_end),
  67853. (else_try),
  67854. (is_between, ":troop_no", dplmc_employees_begin, dplmc_employees_end),
  67855. (str_store_string, ":sreg", "@court member"),
  67856. (try_begin),
  67857. (eq, ":direction", -1),
  67858. (assign, ":result", dplmc_employees_begin),
  67859. (else_try),
  67860. (eq, ":direction", 1),
  67861. (store_sub, ":result", dplmc_employees_end, ":direction"),
  67862. (try_end),
  67863. (else_try),
  67864. (is_between, ":troop_no", fighters_begin, fighters_end),
  67865. (str_store_string, ":sreg", "@fighter"),
  67866. (try_begin),
  67867. (eq, ":direction", -1),
  67868. (assign, ":result", fighters_begin),
  67869. (else_try),
  67870. (eq, ":direction", 1),
  67871. (store_sub, ":result", fighters_end, ":direction"),
  67872. (try_end),
  67873. (else_try),
  67874. (is_between, ":troop_no", "trp_tutorial_fighter_1", startup_merchants_begin),
  67875. (str_store_string, ":sreg", "@tutorial fighter"),
  67876. (try_begin),
  67877. (eq, ":direction", -1),
  67878. (assign, ":result", "trp_tutorial_fighter_1"),
  67879. (else_try),
  67880. (eq, ":direction", 1),
  67881. (store_sub, ":result", startup_merchants_begin, ":direction"),
  67882. (try_end),
  67883. (else_try), #sarranids
  67884. (is_between, ":troop_no", "trp_sarranid_recruit", "trp_looter"),
  67885. (str_store_string, ":sreg", "str_kingdom_6_adjective"),
  67886. (try_begin),
  67887. (eq, ":direction", -1),
  67888. (assign, ":result", "trp_sarranid_recruit"),
  67889. (else_try),
  67890. (eq, ":direction", 1),
  67891. (store_sub, ":result", "trp_looter", ":direction"),
  67892. (try_end),
  67893. (else_try), #rhodoks
  67894. (is_between, ":troop_no", "trp_rhodok_tribesman", "trp_sarranid_recruit"),
  67895. (str_store_string, ":sreg", "str_kingdom_5_adjective"),
  67896. (try_begin),
  67897. (eq, ":direction", -1),
  67898. (assign, ":result", "trp_rhodok_tribesman"),
  67899. (else_try),
  67900. (eq, ":direction", 1),
  67901. (store_sub, ":result", "trp_sarranid_recruit", ":direction"),
  67902. (try_end),
  67903. (else_try), #nords
  67904. (is_between, ":troop_no", "trp_nord_recruit", "trp_rhodok_tribesman"),
  67905. (str_store_string, ":sreg", "str_kingdom_4_adjective"),
  67906. (try_begin),
  67907. (eq, ":direction", -1),
  67908. (assign, ":result", "trp_nord_recruit"),
  67909. (else_try),
  67910. (eq, ":direction", 1),
  67911. (store_sub, ":result", "trp_rhodok_tribesman", ":direction"),
  67912. (try_end),
  67913. (else_try), #khergits
  67914. (is_between, ":troop_no", "trp_khergit_tribesman", "trp_nord_recruit"),
  67915. (str_store_string, ":sreg", "str_kingdom_3_adjective"),
  67916. (try_begin),
  67917. (eq, ":direction", -1),
  67918. (assign, ":result", "trp_khergit_tribesman"),
  67919. (else_try),
  67920. (eq, ":direction", 1),
  67921. (store_sub, ":result", "trp_nord_recruit", ":direction"),
  67922. (try_end),
  67923. (else_try), #vaegirs
  67924. (is_between, ":troop_no", "trp_vaegir_recruit", "trp_khergit_tribesman"),
  67925. (str_store_string, ":sreg", "str_kingdom_2_adjective"),
  67926. (try_begin),
  67927. (eq, ":direction", -1),
  67928. (assign, ":result", "trp_vaegir_recruit"),
  67929. (else_try),
  67930. (eq, ":direction", 1),
  67931. (store_sub, ":result", "trp_khergit_tribesman", ":direction"),
  67932. (try_end),
  67933. (else_try), #swadians
  67934. (is_between, ":troop_no", "trp_swadian_recruit", "trp_vaegir_recruit"),
  67935. (str_store_string, ":sreg", "str_kingdom_1_adjective"),
  67936. (try_begin),
  67937. (eq, ":direction", -1),
  67938. (assign, ":result", "trp_swadian_recruit"),
  67939. (else_try),
  67940. (eq, ":direction", 1),
  67941. (store_sub, ":result", "trp_vaegir_recruit", ":direction"),
  67942. (try_end),
  67943. (try_end),
  67944. (this_or_next|eq, ":direction", 0),
  67945. (neq, ":result", ":troop_no"),
  67946. (assign, reg0, ":result"),
  67947.  
  67948. ]),
  67949.  
  67950. #script_get_proficient_melee_training_weapon
  67951. #input : troop_no
  67952. #output : item_no as the practice weapon
  67953. ("get_proficient_melee_training_weapon",
  67954. [
  67955. (store_script_param, ":troop_no", 1),
  67956. (store_proficiency_level, ":onehands", ":troop_no", wpt_one_handed_weapon),
  67957. (store_proficiency_level, ":twohands", ":troop_no", wpt_two_handed_weapon),
  67958. (store_proficiency_level, ":polearms", ":troop_no", wpt_polearm),
  67959.  
  67960. (assign, ":item_no", -1),
  67961. (try_begin), #practice shield will be added automatically
  67962. (ge, ":onehands", ":twohands"),
  67963. (ge, ":onehands", ":polearms"),
  67964. # (agent_equip_item, ":agent_no", "itm_practice_shield"),
  67965. (assign, ":item_no", "itm_practice_sword"),
  67966. (else_try),
  67967. (ge, ":twohands", ":onehands"),
  67968. (ge, ":twohands", ":polearms"),
  67969. (assign, ":item_no", "itm_heavy_practice_sword"),
  67970. (else_try),
  67971. (ge, ":polearms", ":onehands"),
  67972. (ge, ":polearms", ":twohands"),
  67973. (assign, ":item_no", "itm_practice_staff"),
  67974. (try_end),
  67975. (assign, reg0, ":item_no"),
  67976. ]),
  67977.  
  67978. # script_spawn_looters
  67979. # Input: arg1 = center_no, arg2 = number of looters to spawn
  67980. # Output: none
  67981. ("spawn_looters",
  67982. [
  67983. (store_script_param, ":center_no", 1),
  67984. (store_script_param, ":num_looters", 2),
  67985. # (party_set_slot, ":center_no", slot_center_is_besieged_by, -1), #clear siege
  67986. # (call_script, "script_village_set_state", ":center_no", 0), #clear siege flag
  67987. (set_spawn_radius, 4),
  67988. (try_for_range, ":unused", 0, ":num_looters"),
  67989. (spawn_around_party, ":center_no", "pt_looters"),
  67990. (party_set_ai_behavior, reg0, ai_bhvr_avoid_party),
  67991. (party_set_ai_object, reg0, ":center_no"),
  67992. (try_end),
  67993. ]),
  67994.  
  67995. #script_troop_transfer_gold
  67996. ("troop_transfer_gold",
  67997. [
  67998. (store_script_param, ":source", 1),
  67999. (store_script_param, ":destination", 2),
  68000. (store_script_param, ":amount", 3),
  68001. (store_troop_gold, ":cur_amount", ":source"),
  68002. (try_begin),
  68003. (gt, ":amount", 0), #0 means move all
  68004. (val_min, ":cur_amount", ":amount"),
  68005. (try_end),
  68006. (troop_remove_gold, ":source", ":cur_amount"),
  68007. # (troop_add_gold, ":destination", ":cur_amount"),
  68008. (call_script, "script_troop_add_gold", ":destination", ":cur_amount"),
  68009. (assign, reg0, ":cur_amount"),
  68010. ]),
  68011. # script_move_inventory_and_gold
  68012. # generally this is used to move the backup to the player
  68013. # Input: arg1 = source, arg2 = destnation
  68014. # Output: none
  68015.  
  68016. ("move_inventory_and_gold",
  68017. [
  68018. (store_script_param, ":source", 1),
  68019. (store_script_param, ":destination", 2),
  68020. (store_script_param, ":move_gold", 3),
  68021. #assume trp_temp_troop is an available placeholder
  68022.  
  68023. (troop_sort_inventory, ":source"), #order them, too lazy to maintain 2 loops
  68024. (troop_get_inventory_capacity, ":inv_cap", ":source"),
  68025. (troop_get_inventory_capacity, ":player_cap", ":destination"),
  68026. (assign, ":inv_slot", ek_food + 1), #start from the bottom, skip source's equipment
  68027. (try_for_range, ":i_slot", ek_food + 1, ":player_cap"),
  68028. (troop_get_inventory_slot, ":cur_item", ":destination", ":i_slot"),
  68029. (eq, ":cur_item", -1), #empty slot
  68030. (troop_get_inventory_slot, ":item", ":source", ":inv_slot"),
  68031. (troop_set_inventory_slot, ":destination", ":i_slot", ":item"),
  68032. (try_begin),
  68033. (neq, ":cur_item", -1),
  68034. (troop_get_inventory_slot_modifier, ":imod", ":source", ":inv_slot"),
  68035. (troop_set_inventory_slot_modifier, ":destination", ":i_slot", ":imod"),
  68036. (try_begin),
  68037. (troop_inventory_slot_get_item_amount, ":amount", ":source", ":inv_slot"),
  68038. (gt, ":amount", 0),
  68039. (troop_inventory_slot_set_item_amount, ":destination", ":i_slot", ":amount"),
  68040. (try_end),
  68041. (try_end),
  68042. (troop_set_inventory_slot, ":source", ":inv_slot", -1),
  68043. (val_add, ":inv_slot", 1),
  68044.  
  68045. (try_begin), #loop break
  68046. (ge, ":inv_slot", ":inv_cap"),
  68047. (assign, ":player_cap", -1),
  68048. (try_end),
  68049. (try_end),
  68050. (troop_clear_inventory, ":source"), #clear off the rest if no capacity in destination
  68051. #do gold addition
  68052. (try_begin),
  68053. (eq, ":move_gold", -1), #move all
  68054. (store_troop_gold, ":cur_amount", ":source"),
  68055. (troop_remove_gold, ":source", ":cur_amount"),
  68056. (troop_add_gold, ":destination", ":cur_amount"),
  68057. (else_try),
  68058. (gt, ":move_gold", 0), #specific amount
  68059. (call_script, "script_troop_transfer_gold", ":source", ":destination", ":move_gold"),
  68060. (try_end),
  68061. ]),
  68062.  
  68063. #script_get_disguise_string
  68064. #calculate the string offset by iteratively dividing by 2
  68065. ("get_disguise_string", [
  68066. (store_script_param, ":cur_val", 1),
  68067. (store_script_param, ":sreg", 2),
  68068. (store_add, ":end_val", "str_pilgrim_disguise", num_disguises),
  68069. (str_clear, ":sreg"),
  68070. (try_for_range, ":string", "str_pilgrim_disguise", ":end_val"),
  68071. (eq, ":cur_val", 1), #
  68072. (assign, ":end_val", -1), #loop break
  68073. (str_store_string, ":sreg", ":string"),
  68074. (else_try),
  68075. (val_div, ":cur_val", 2), #divide by 2, next iteration
  68076. (try_end),
  68077. ]),
  68078. #script_acquire_disguise
  68079. #lets the player use the disguise by setting the slot, shows message
  68080. ("acquire_disguise", [
  68081. (store_script_param, ":disguise", 1),
  68082. (troop_get_slot, ":cur_disguise", "trp_player", slot_troop_player_disguise_sets),
  68083. (val_or, ":cur_disguise", ":disguise"),
  68084. (troop_set_slot, "trp_player", slot_troop_player_disguise_sets, ":cur_disguise"),
  68085. (call_script, "script_get_disguise_string", ":disguise", 0),
  68086. # (str_store_string, s0, reg0),
  68087. (display_message, "@Acquired {s0}'s clothing", message_alert),
  68088. ]),
  68089. #script_set_disguise_overide_items
  68090. #see also start of module_mission_templates for static list of items
  68091. #note that the override flags are not being set here
  68092. ("set_disguise_override_items", [
  68093. (store_script_param, ":mission_template", 1),
  68094. (store_script_param, ":entry_no", 2),
  68095. (store_script_param, ":with_weapon", 3),
  68096.  
  68097. (mission_tpl_entry_clear_override_items, ":mission_template", ":entry_no"),
  68098. (try_begin),
  68099. (eq, "$sneaked_into_town", disguise_pilgrim),
  68100. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_pilgrim_disguise"),
  68101. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_pilgrim_hood"),
  68102. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_wrapping_boots"),
  68103. (try_begin),
  68104. (eq, ":with_weapon", 1),
  68105. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_practice_staff"),
  68106. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_throwing_daggers"),
  68107. (try_end),
  68108. (else_try),
  68109. (eq, "$sneaked_into_town", disguise_farmer),
  68110. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_felt_hat"),
  68111. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_coarse_tunic"),
  68112. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_nomad_boots"),
  68113. (try_begin),
  68114. (eq, ":with_weapon", 1),
  68115. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_battle_fork"),
  68116. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_cleaver"),
  68117. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_stones"),
  68118. (try_end),
  68119. (else_try),
  68120. (eq, "$sneaked_into_town", disguise_hunter),
  68121. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_black_hood"),
  68122. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_leather_gloves"),
  68123. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_light_leather"),
  68124. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_light_leather_boots"),
  68125. (try_begin),
  68126. (eq, ":with_weapon", 1),
  68127. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_sword_khergit_1"),
  68128. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_hunting_bow"),
  68129. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_barbed_arrows"),
  68130. (try_end),
  68131. (else_try),
  68132. (eq, "$sneaked_into_town", disguise_merchant),
  68133. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_leather_jacket"),
  68134. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_woolen_hose"),
  68135. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_felt_steppe_cap"),
  68136. (try_begin),
  68137. (eq, ":with_weapon", 1),
  68138. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_dagger"),
  68139. (try_end),
  68140. (else_try),
  68141. (eq, "$sneaked_into_town", disguise_guard),
  68142. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_footman_helmet"),
  68143. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_mail_mittens"),
  68144. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_maiL_shirt"),
  68145. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_mail_chausses"),
  68146. (try_begin),
  68147. (eq, ":with_weapon", 1),
  68148. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_fighting_pick"),
  68149. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_tab_shield_round_c"),
  68150. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_war_spear"),
  68151. (try_end),
  68152. (else_try),
  68153. (eq, "$sneaked_into_town", disguise_bard),
  68154. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_linen_tunic"),
  68155. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_leather_boots"),
  68156. (try_begin),
  68157. (eq, ":with_weapon", 1),
  68158. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_winged_mace"),
  68159. (mission_tpl_entry_add_override_item, ":mission_template", ":entry_no", "itm_lyre"),
  68160. (try_end),
  68161. (try_end),
  68162. ]),
  68163.  
  68164.  
  68165. ("get_dest_color_from_rgb",
  68166. [
  68167. (store_script_param, ":red", 1),
  68168. (store_script_param, ":green", 2),
  68169. (store_script_param, ":blue", 3),
  68170.  
  68171. (assign, ":cur_color", 0xFF000000),
  68172. (val_mul, ":green", 0x100),
  68173. (val_mul, ":red", 0x10000),
  68174. (val_add, ":cur_color", ":blue"),
  68175. (val_add, ":cur_color", ":green"),
  68176. (val_add, ":cur_color", ":red"),
  68177. (assign, reg0, ":cur_color"),
  68178. ]),
  68179.  
  68180. ("convert_rgb_code_to_html_code",
  68181. [
  68182. (store_script_param, ":red", 1),
  68183. (store_script_param, ":green", 2),
  68184. (store_script_param, ":blue", 3),
  68185.  
  68186. # (str_store_string, s0, "@#"),
  68187.  
  68188. (store_div, reg11, ":red", 0x10),
  68189. #(store_add, ":dest_string", "str_key_0", reg11"),
  68190. #(str_store_string, s1, ":dest_string"),
  68191. #(str_store_string, s0, "@{s0}{s1}"),
  68192.  
  68193. (store_mod, reg12, ":red", 0x10),
  68194. #(store_add, ":dest_string", "str_key_0", ":r_2"),
  68195. #(str_store_string, s1, ":dest_string"),
  68196. #(str_store_string, s0, "@{s0}{s1}"),
  68197.  
  68198. (store_div, reg13, ":green", 0x10),
  68199. #(store_add, ":dest_string", "str_key_0", ":g_1"),
  68200. #(str_store_string, s1, ":dest_string"),
  68201. #(str_store_string, s0, "@{s0}{s1}"),
  68202.  
  68203. (store_mod, reg14, ":green", 0x10),
  68204. #(store_add, ":dest_string", "str_key_0", ":g_2"),
  68205. #(str_store_string, s1, ":dest_string"),
  68206. #(str_store_string, s0, "@{s0}{s1}"),
  68207.  
  68208. (store_div, reg15, ":blue", 0x10),
  68209. #(store_add, ":dest_string", "str_key_0", ":b_1"),
  68210. #(str_store_string, s1, ":dest_string"),
  68211. #(str_store_string, s0, "@{s0}{s1}"),
  68212.  
  68213. (store_mod, reg16, ":blue", 0x10),
  68214. #(store_add, ":dest_string", "str_key_0", ":b_2"),
  68215. #(str_store_string, s1, ":dest_string"),
  68216. #(str_store_string, s0, "@{s0}{s1}"),
  68217. (str_store_string, s0, "str_html_color"),
  68218. ]),
  68219.  
  68220. ("convert_slot_no_to_color",
  68221. [
  68222. (store_script_param, ":cur_color", 1),
  68223.  
  68224. (store_mod, ":blue", ":cur_color", 6),
  68225. (val_div, ":cur_color", 6),
  68226. (store_mod, ":green", ":cur_color", 6),
  68227. (val_div, ":cur_color", 6),
  68228. (store_mod, ":red", ":cur_color", 6),
  68229. (val_mul, ":blue", 0x33),
  68230. (val_mul, ":green", 0x33),
  68231. (val_mul, ":red", 0x33),
  68232. (assign, ":dest_color", 0xFF000000),
  68233. (val_mul, ":green", 0x100),
  68234. (val_mul, ":red", 0x10000),
  68235. (val_add, ":dest_color", ":blue"),
  68236. (val_add, ":dest_color", ":green"),
  68237. (val_add, ":dest_color", ":red"),
  68238. (assign, reg0, ":dest_color"),
  68239. ]),
  68240.  
  68241. ("change_color",
  68242. [
  68243. (call_script, "script_get_dest_color_from_rgb", reg2, reg3, reg4),
  68244. (assign, ":cur_color", reg0),
  68245. (overlay_set_color, "$g_presentation_obj_2", ":cur_color"),
  68246. (try_begin),
  68247. (eq, "$g_presentation_state", recolor_kingdom),
  68248. (troop_get_slot, ":cur_faction", "trp_temp_array_a", "$temp"),
  68249. (faction_set_color, ":cur_faction", ":cur_color"),
  68250. (else_try),
  68251. (eq, "$g_presentation_state", recolor_heraldic),
  68252. (troop_get_slot, ":banner", "trp_player", slot_troop_banner_scene_prop),
  68253. (val_sub, ":banner", banner_scene_props_begin),
  68254. (troop_set_slot, "trp_banner_background_color_array", ":banner", ":cur_color"),
  68255. (else_try),
  68256. (eq, "$g_presentation_state", recolor_groups),
  68257. (troop_set_slot, "trp_multiplayer_data", "$temp", ":cur_color"),
  68258. (try_end),
  68259. (call_script, "script_convert_rgb_code_to_html_code", reg2, reg3, reg4),
  68260. (overlay_set_text, "$g_presentation_obj_9", "str_html"),
  68261. ]),
  68262. #INVASION MODE START
  68263. # script_multiplayer_ccoop_prepare_spawn_wave
  68264. # Input: none
  68265. # Output: none
  68266. ("multiplayer_ccoop_prepare_spawn_wave",
  68267. [
  68268. (try_begin),
  68269. (multiplayer_is_server),
  68270. (set_fixed_point_multiplier, 100),
  68271.  
  68272. #generate next wave spawn points
  68273. (store_random_in_range, ":spawn_point1", 80, 88),
  68274. (store_random_in_range, ":spawn_point2", 80, 88),
  68275. (try_begin),
  68276. (eq, ":spawn_point1", ":spawn_point2"),
  68277. (assign, ":spawn_point2", -1),
  68278. (end_try),
  68279.  
  68280. #(assign, reg0, ":spawn_point1"),
  68281. #(assign, reg1, ":spawn_point2"),
  68282. #(display_message, "@spawn points generated as 1: {reg0} 2: {reg1}"),
  68283.  
  68284. #(store_mod, ":wave_no_mod", "$g_multiplayer_ccoop_wave_no", 10),
  68285. (store_sub, ":wave_no_mod", "$g_multiplayer_ccoop_wave_no", "$g_mp_coop_last_king_wave"),
  68286.  
  68287. #Now the script makes a calculation to decide how many enemies to spawn.
  68288.  
  68289. (assign, ":num_troops_for_wave", 4),
  68290. (assign, ":number_of_players_at_team_1", 0),
  68291. (get_max_players, ":num_players"),
  68292. (try_for_range, ":cur_player", 0, ":num_players"),
  68293. (player_is_active, ":cur_player"),
  68294. (player_get_team_no, ":player_team", ":cur_player"),
  68295. (eq, ":player_team", 0),
  68296. (val_add, ":number_of_players_at_team_1", 1),
  68297. (try_end),
  68298.  
  68299.  
  68300. (assign, reg0, ":number_of_players_at_team_1"), #debug, delete
  68301.  
  68302. (val_sub, ":number_of_players_at_team_1", 1), # for simplifying the formula
  68303. (try_for_range, ":cur_multiplier", 1, 4),
  68304. (gt, ":number_of_players_at_team_1", 0),
  68305. (store_mul, ":used_multiplier", ":cur_multiplier", 2),
  68306. (val_min, ":used_multiplier", ":number_of_players_at_team_1"),
  68307. (val_sub, ":number_of_players_at_team_1", ":used_multiplier"),
  68308. (store_sub, ":used_multiplier_2", 5, ":cur_multiplier"),
  68309. (store_mul, ":added_num_troops", ":used_multiplier_2", ":used_multiplier"),
  68310. (val_add, ":num_troops_for_wave", ":added_num_troops"),
  68311. (try_end),
  68312.  
  68313. (try_begin),
  68314. (le, "$g_multiplayer_ccoop_wave_no", 3),
  68315. (assign, ":spawn_point2", -1), # for the first 3 waves, spawn from only 1 point
  68316. (try_end),
  68317.  
  68318. #Clear all enemy wave data slots
  68319. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin, 0),
  68320. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 1, 0),
  68321. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 2, 0),
  68322. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 3, 0),
  68323. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 4, 0),
  68324. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 5, 0),
  68325. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 6, 0),
  68326. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 7, 0),
  68327. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 8, 0),
  68328. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 9, 0),
  68329. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 10, 0),
  68330. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 11, 0),
  68331. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 12, 0),
  68332. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 13, 0),
  68333. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 14, 0),
  68334. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 15, 0),
  68335.  
  68336.  
  68337. (store_mul, ":wave_effect_on_troops", 20, ":wave_no_mod"),
  68338. (val_add, ":wave_effect_on_troops", 80), # it will be 100, 120, 140, 160, ... beginning from wave 1.
  68339.  
  68340. (val_mul, ":num_troops_for_wave", ":wave_effect_on_troops"),
  68341. (val_div, ":num_troops_for_wave", 100),
  68342.  
  68343. (try_begin),
  68344. (ge, "$g_mp_coop_king_waves", 1), # wave++
  68345. (val_mul, ":num_troops_for_wave", 130),
  68346. (val_div, ":num_troops_for_wave", 100),
  68347. (try_end),
  68348.  
  68349. #Used to reset max enemy level counter for endless mode
  68350. (store_sub, ":since_last_boss", "$g_multiplayer_ccoop_wave_no", "$g_mp_coop_last_king_wave"),
  68351.  
  68352. #Restrict the level of wave troops
  68353. (try_begin),
  68354. (ge, ":since_last_boss", 10),
  68355. (assign, ":max_level", 30),
  68356. (else_try),
  68357. (ge, ":since_last_boss", 8),
  68358. (assign, ":max_level", 24),
  68359. (else_try),
  68360. (ge, ":since_last_boss", 6),
  68361. (assign, ":max_level", 20),
  68362. (else_try),
  68363. (ge, ":since_last_boss", 4),
  68364. (assign, ":max_level", 15),
  68365. (else_try),
  68366. (ge, ":since_last_boss", 2),
  68367. (assign, ":max_level", 10),
  68368. (else_try),
  68369. (ge, ":since_last_boss", 1),
  68370. (assign, ":max_level", 6),
  68371. (try_end),
  68372.  
  68373. (assign, ":spawn_lord", 0),
  68374.  
  68375. (assign, "$g_ccoop_king_troop", -1),
  68376.  
  68377. (try_begin),
  68378. (ge, ":since_last_boss", 3),
  68379. (store_random_in_range, ":spawn_lord_check", 0, 2), #after wave 3, 50% chance for a lord wave
  68380. (this_or_next|ge, ":spawn_lord_check", 1),
  68381. (this_or_next|eq, ":since_last_boss", 3), #always spawn a lord on wave 3
  68382. (eq, ":since_last_boss", 10), #king always spawns on wave 10
  68383. (val_add, "$g_mp_coop_lord_waves", 1),
  68384. (try_begin),
  68385. (store_mod, ":spawn_king", "$g_mp_coop_lord_waves", 5), #If 5th lord wave occurs before wave 10, it become the king wave
  68386. (this_or_next|eq, ":spawn_king", 0),
  68387. (eq, ":since_last_boss", 10),
  68388. (gt, "$g_mp_coop_lord_waves", 0), #prevents first lord wave from being a king wave
  68389. (gt, ":since_last_boss", 1), #not necessary
  68390.  
  68391. (try_begin),
  68392. (eq, "$g_multiplayer_team_2_faction", "fac_ccoop_all_stars"),
  68393. (store_random_in_range, ":used_troop_no", kings_begin, kings_end), #all stars faction uses a random king!
  68394. (else_try),
  68395. (eq, "$g_multiplayer_team_2_faction", "fac_outlaws"),
  68396. (assign, ":reusing_quick_battle_king", 1),
  68397. (try_for_range, ":unused", 0, 10),
  68398. (eq, ":reusing_quick_battle_king", 1),
  68399. (store_random_in_range, ":used_troop_no" ,quick_battle_troops_begin, quick_battle_troops_end), #outlaws wave uses a quick battle troop for a king
  68400. (neg|troop_slot_eq, ":used_troop_no", slot_troop_coop_lord_spawned, 2), #it tries 10 times not to use one of the lords but if it fails, gives up eventually, and raises one from the dead
  68401. (assign, ":reusing_quick_battle_king", 0),
  68402. (try_end),
  68403. (else_try),
  68404. (try_for_range, ":cur_troop", kings_begin, kings_end), #selects the right king for the faction
  68405. (store_troop_faction, ":troop_faction", ":cur_troop"),
  68406. (eq, ":troop_faction", "$g_multiplayer_team_2_faction"),
  68407. (assign, ":used_troop_no", ":cur_troop"),
  68408. (try_end),
  68409. (try_end),
  68410. #(assign, ":cur_max_level", 0),
  68411. (assign, ":spawn_lord", 1),
  68412. (assign, "$g_ccoop_king_troop", ":used_troop_no"),
  68413.  
  68414.  
  68415. #Reset all spawn trackers to allow any lords to spawn again for each elite tier in endless mode
  68416. (try_for_range, ":cur_troop", lords_begin, lords_end),
  68417. (troop_set_slot, ":cur_troop", slot_troop_coop_lord_spawned, 0),
  68418. (try_end),
  68419. (try_for_range, ":cur_troop", quick_battle_troops_begin, quick_battle_troops_end),
  68420. (troop_set_slot, ":cur_troop", slot_troop_coop_lord_spawned, 0),
  68421. (try_end),
  68422. (else_try),
  68423. (assign, ":spawn_lord", 1), #variable is used to keep slots safe while generating the rest of the wave
  68424.  
  68425. #reset data for all possible lord troops before generating a lord
  68426.  
  68427. (try_for_range, ":cur_troop", lords_begin, lords_end),
  68428. (neg|troop_slot_eq, ":cur_troop", slot_troop_coop_lord_spawned, 2), #if slot_troop_coop_lord_spawned = 2, lord has already spawned - do not reset data
  68429. (troop_set_slot, ":cur_troop", slot_troop_coop_lord_spawned, 0),
  68430. (try_end),
  68431.  
  68432. (try_for_range, ":cur_troop", quick_battle_troops_begin, quick_battle_troops_end),
  68433. (neg|troop_slot_eq, ":cur_troop", slot_troop_coop_lord_spawned, 2),
  68434. (troop_set_slot, ":cur_troop", slot_troop_coop_lord_spawned, 0),
  68435. (try_end),
  68436.  
  68437. (assign, ":eligible_troop_count", 0),
  68438.  
  68439. #Find troops that are eligible
  68440. (try_for_range, ":cur_troop", lords_begin, lords_end),
  68441. (store_troop_faction, ":troop_faction", ":cur_troop"),
  68442. (this_or_next|eq, ":troop_faction", "$g_multiplayer_team_2_faction"),
  68443. (eq, "$g_multiplayer_team_2_faction", "fac_ccoop_all_stars"), #all lords are eligible in all stars
  68444. (neg|troop_slot_eq, ":cur_troop", slot_troop_coop_lord_spawned, 2), #don't resurrect lords (until a king wave)
  68445. (troop_set_slot, ":cur_troop", slot_troop_coop_lord_spawned, 1), #set eligible to be checked the second time around
  68446. (val_add, ":eligible_troop_count", 1), #increase the upper limit for the random generator
  68447. (try_end),
  68448.  
  68449. (try_for_range, ":cur_troop", quick_battle_troops_begin, quick_battle_troops_end),
  68450. (store_troop_faction, ":troop_faction", ":cur_troop"),
  68451. (this_or_next|eq, "$g_multiplayer_team_2_faction", "fac_outlaws"),
  68452. (eq, "$g_multiplayer_team_2_faction", "fac_ccoop_all_stars"), #all quick battle troops are eligible in all stars
  68453. (neg|troop_slot_eq, ":cur_troop", slot_troop_coop_lord_spawned, 2), #don't resurrect quick battle troops (until a king wave)
  68454. (troop_set_slot, ":cur_troop", slot_troop_coop_lord_spawned, 1),
  68455. (val_add, ":eligible_troop_count", 1),
  68456. (try_end),
  68457.  
  68458.  
  68459. (store_random_in_range, ":randomiser", 0, ":eligible_troop_count"), #randomise a lord from the eligible troops
  68460. (assign, ":random_checker", 0),
  68461.  
  68462.  
  68463. (try_for_range, ":cur_troop", lords_begin, lords_end),
  68464. (troop_slot_eq, ":cur_troop", slot_troop_coop_lord_spawned, 1), #use this to check the troops we marked as eligible lords
  68465.  
  68466. (assign, reg0, ":cur_troop"), # debug
  68467.  
  68468. (try_begin),
  68469. (eq, ":random_checker", ":randomiser"), #found her/him!
  68470. (assign, ":used_troop_no", ":cur_troop"),
  68471. (troop_set_slot, ":cur_troop", slot_troop_coop_lord_spawned, 2), #prevent our lord from spawning again
  68472. (try_end),
  68473. (val_add, ":random_checker", 1),
  68474.  
  68475. (try_end),
  68476.  
  68477. #continue checking all possible troops
  68478. (try_for_range, ":cur_troop", quick_battle_troops_begin, quick_battle_troops_end),
  68479. (troop_slot_eq, ":cur_troop", slot_troop_coop_lord_spawned, 1),
  68480.  
  68481. (assign, reg0, ":cur_troop"), # debug
  68482.  
  68483. (try_begin),
  68484. (eq, ":random_checker", ":randomiser"),
  68485. (assign, ":used_troop_no", ":cur_troop"),
  68486. (troop_set_slot, ":cur_troop", slot_troop_coop_lord_spawned, 2),
  68487. (try_end),
  68488. (val_add, ":random_checker", 1),
  68489.  
  68490. (try_end),
  68491. (try_end),
  68492. #set the wave spawn data for our leader
  68493. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 1, ":used_troop_no"),
  68494. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 2, 1), #only one leader
  68495. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 3, ":spawn_point1"), #always use spawn_point1 for simplicity
  68496. (troop_get_slot, ":num_bot_types", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin),
  68497. (val_add, ":num_bot_types", 2), #adding two bot types because we're about to add the guards anyway
  68498. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin, ":num_bot_types"),
  68499. (assign, ":cur_max_level", -1),
  68500. (store_troop_faction, ":used_troop_faction_no", ":used_troop_no"), #use guards from the same faction as the wave leader (used mainly for all stars wave)
  68501. (try_begin),
  68502. (eq, "$g_multiplayer_team_2_faction", "fac_outlaws"),
  68503. (assign, ":guard_troop_no", "trp_sea_raider_leader"), #outlaws always use sea raider captains as guards
  68504. (else_try),
  68505. (try_for_range, ":cur_troop", soldiers_begin, soldiers_end), #check all soldiers to find a suitable guard troop
  68506. (store_troop_faction, ":troop_faction", ":cur_troop"),
  68507. (eq, ":troop_faction", ":used_troop_faction_no"), #same faction as the leader?
  68508. (store_character_level, ":cur_level", ":cur_troop"),
  68509. (gt, ":cur_level", ":cur_max_level"), #higher than previous soldiers found from our required faction?
  68510. (assign, ":cur_max_level", ":cur_level"),
  68511. (assign, ":guard_troop_no", ":cur_troop"),
  68512. (try_end),
  68513. (try_end),
  68514. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 4, ":guard_troop_no"), #set the troop id in the correct wave data slot
  68515. (try_begin),
  68516. (eq, ":spawn_king", 0), #double guards for the king! simple but creates a nice final challenge
  68517. (gt, "$g_mp_coop_lord_waves", 0),
  68518. (gt, ":since_last_boss", 1),
  68519. (assign, ":guard_count", 2),
  68520. (else_try),
  68521. (assign, ":guard_count", 1),
  68522. (try_end),
  68523. (get_max_players, ":num_players"),
  68524. (assign, ":total_players", 0),
  68525. (try_for_range, ":cur_player", 0, ":num_players"), #find out how many players are on the defenders
  68526. (player_is_active, ":cur_player"),
  68527. (player_get_team_no, ":cur_team", ":cur_player"),
  68528. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_ccoop_return_of_the_king, "$g_ccoop_king_troop"),
  68529. (eq, ":cur_team", 0),
  68530. (val_add, ":total_players", 1),
  68531. (try_end),
  68532. (val_mul, ":guard_count", ":total_players"), #1 guard per player for lord waves; 2 for the king
  68533. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 5, ":guard_count"), #set the number
  68534. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 6, ":spawn_point1"), #spawn guards with the wave leader
  68535. (val_add, ":spawn_lord", 1), #used in code below to avoid "boosting" guards when data slots are full... also prevents us legitimately "boosting" generated troops that match the guard troop, which is a shame but not critical
  68536. (try_end),
  68537.  
  68538.  
  68539. (assign, ":eligible_troop_count", 0), #reset this and start looking for eligible troops to fill the wave
  68540.  
  68541. (try_for_range, ":cur_troop", soldiers_begin, soldiers_end),
  68542. (troop_set_slot, ":cur_troop", slot_troop_mp_squad_type, 0), #we use this slot to check if they are eligible - was previously used for something else in WFaS. should have been renamed really...
  68543. (try_end),
  68544.  
  68545. (try_for_range, ":cur_troop", soldiers_begin, soldiers_end),
  68546. (neq, ":cur_troop", "trp_mercenaries_end"),
  68547.  
  68548. (store_troop_faction, ":troop_faction", ":cur_troop"),
  68549. (this_or_next|eq, ":troop_faction", "$g_multiplayer_team_2_faction"), #right faction?
  68550. (eq, "$g_multiplayer_team_2_faction", "fac_ccoop_all_stars"), #... or all stars?
  68551. (store_character_level, ":troop_level", ":cur_troop"),
  68552. (le, ":troop_level", ":max_level"), #doesn't exceed our level cap for the current wave?
  68553. (troop_set_slot, ":cur_troop", slot_troop_mp_squad_type, 1), #eligible!
  68554. (val_add, ":eligible_troop_count", 1), #add the count to be used by the randomiser
  68555. (assign, reg0, ":used_troop_no"), # debug
  68556. (display_debug_message, "@{!}used troop no is {reg0}"), # debug
  68557. (try_end),
  68558.  
  68559. (try_for_range, ":cur_bot_readying", 0, ":num_troops_for_wave"), #run this individually for every single wave bot we want to generate - not very efficient! Causes a momentary spike with a lot of players
  68560. (assign, reg0, ":cur_bot_readying"),
  68561. (try_begin),
  68562. (neg|troop_slot_eq, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 13, 0), #if all data is filled (this slot is the last used for wave bot ids)
  68563. (store_random_in_range, ":booster_slot", ":spawn_lord", 5), #pick an existing troop to "boost" - don't "boost" the wave leader or guards
  68564.  
  68565. (val_mul, ":booster_slot", 3), #get to the right data slot
  68566. (val_add, ":booster_slot", multi_data_ccoop_wave_spawn_data_begin + 1), # used troop no
  68567.  
  68568. (val_add, ":booster_slot", 1), # used troop count
  68569. (troop_get_slot, ":used_troop_count", "trp_multiplayer_data", ":booster_slot"), #get the current number spawning
  68570. (val_add, ":used_troop_count", 1), #boost!
  68571. (troop_set_slot, "trp_multiplayer_data", ":booster_slot", ":used_troop_count"), #rewrite the slot with the new number of that troop
  68572. (else_try),
  68573. #if there are still slots available (there are 5 total), we look for a troop again
  68574.  
  68575.  
  68576. (store_random_in_range, ":randomiser", 0, ":eligible_troop_count"), #pick a number...
  68577. (assign, ":random_checker", 0),
  68578.  
  68579.  
  68580. (try_for_range, ":cur_troop", soldiers_begin, soldiers_end), #this covers all troops for factions, outlaws and all stars
  68581. (troop_slot_eq, ":cur_troop", slot_troop_mp_squad_type, 1),
  68582.  
  68583.  
  68584. (try_begin),
  68585. (eq, ":random_checker", ":randomiser"),
  68586. (assign, ":used_troop_no", ":cur_troop"), #found our troop!
  68587. (try_end),
  68588. (val_add, ":random_checker", 1),
  68589.  
  68590. (try_end),
  68591.  
  68592. (try_begin),
  68593. (assign, ":troop_already_spawning", 0), #found our troop! But is that troop already spawning?
  68594. (try_for_range, ":cur_slot", 0, 5), #check our existing data slots
  68595. (val_mul, ":cur_slot", 3),
  68596. (val_add, ":cur_slot", multi_data_ccoop_wave_spawn_data_begin + 1), #... the ones that hold our troop ids
  68597. (troop_get_slot, ":cur_slot_troop_no", "trp_multiplayer_data", ":cur_slot"),
  68598. (eq, ":cur_slot_troop_no", ":used_troop_no"), #is there a match?
  68599.  
  68600. (val_add, ":cur_slot", 1), # move our slot to the one which holds the number of that troop type which will spawn
  68601. (troop_get_slot, ":used_troop_count", "trp_multiplayer_data", ":cur_slot"),
  68602. (val_add, ":used_troop_count", 1), #and add one more
  68603. (troop_set_slot, "trp_multiplayer_data", ":cur_slot", ":used_troop_count"),
  68604. #(assign, ":used_slot", ":cur_slot"),
  68605. (assign, ":troop_already_spawning", 1),
  68606. #(display_message, "@troop already spawning!"),
  68607. (try_end),
  68608. (eq, ":troop_already_spawning", 1), #don't try else if that troop type was already spawning
  68609. (else_try),
  68610. (assign, ":found_empty_slot", 0), #but if the troop wasn't already spawning..
  68611. (try_for_range, ":cur_slot", ":spawn_lord", 5),
  68612. (neq, ":found_empty_slot", 1), #find the next empty slot
  68613. (val_mul, ":cur_slot", 3),
  68614. (val_add, ":cur_slot", multi_data_ccoop_wave_spawn_data_begin + 1),
  68615.  
  68616. (troop_get_slot, ":cur_slot_troop_no", "trp_multiplayer_data", ":cur_slot"),
  68617. (eq, ":cur_slot_troop_no", 0), #is it empty?
  68618.  
  68619.  
  68620. (troop_set_slot, "trp_multiplayer_data", ":cur_slot", ":used_troop_no"), #not anymore!
  68621.  
  68622.  
  68623. (val_add, ":cur_slot", 1),
  68624. (troop_get_slot, ":used_troop_count", "trp_multiplayer_data", ":cur_slot"),
  68625. (val_add, ":used_troop_count", 1), #should be one anyway, since this is the first troop of that type
  68626. (troop_set_slot, "trp_multiplayer_data", ":cur_slot", ":used_troop_count"),
  68627.  
  68628. (troop_get_slot, ":num_bot_types", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin),
  68629. (val_add, ":num_bot_types", 1), #increase the number of bot types, which is sent along with the other data - used by the spawning script
  68630. (troop_set_slot, "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin, ":num_bot_types"),
  68631.  
  68632. (assign, ":used_slot", ":cur_slot"),
  68633. (assign, ":found_empty_slot", 1),
  68634. (store_random_in_range, ":used_entry_point", 0, 2), #randomise the entry point
  68635. (try_begin),
  68636. (this_or_next|eq, ":used_entry_point", 0),
  68637. (le, ":spawn_point2", 0), #and always user spawn_point1 if spawn_point2 isn't active for this wave
  68638. (assign, ":used_entry_point", ":spawn_point1"),
  68639. (else_try),
  68640. (assign, ":used_entry_point", ":spawn_point2"),
  68641. (try_end),
  68642. (val_add, ":used_slot", 1),
  68643. (troop_set_slot, "trp_multiplayer_data", ":used_slot", ":used_entry_point"),
  68644. (try_end),
  68645. (try_end),
  68646. (try_end),
  68647.  
  68648. (try_end),
  68649.  
  68650. (get_max_players, ":max_players"), #send data to clients so they can see what troops are spawning next
  68651. (try_for_range, ":cur_player", 1, ":max_players"),
  68652. (player_is_active, ":cur_player"),
  68653. (call_script, "script_multiplayer_ccoop_send_troop_data_to_client", ":cur_player"),
  68654. (try_end),
  68655.  
  68656. (try_end),
  68657. ]),
  68658.  
  68659.  
  68660. # script_multiplayer_ccoop_calculate_round_duration
  68661. # Input: none
  68662. # Output: none
  68663. ("multiplayer_ccoop_calculate_round_duration",
  68664. [
  68665. (try_begin),
  68666. (multiplayer_is_server),
  68667. (assign, "$g_multiplayer_ccoop_enemy_respawn_secs", 300), #5min
  68668.  
  68669. (store_sub, ":wave_no", "$g_multiplayer_ccoop_wave_no", 1),
  68670. (val_max, ":wave_no", 0),
  68671. (store_mod, ":mod", ":wave_no", 10),
  68672. (val_mul, ":mod", 30),
  68673. (val_add, "$g_multiplayer_ccoop_enemy_respawn_secs", ":mod"),
  68674.  
  68675. (try_begin),
  68676. (gt, "$g_multiplayer_ccoop_wave_no", 20),
  68677. (val_mul, "$g_multiplayer_ccoop_enemy_respawn_secs", 2),
  68678. (else_try),
  68679. (gt, "$g_multiplayer_ccoop_wave_no", 10),
  68680. (val_mul, "$g_multiplayer_ccoop_enemy_respawn_secs", 3),
  68681. (val_div, "$g_multiplayer_ccoop_enemy_respawn_secs", 2),
  68682. (try_end),
  68683.  
  68684. (get_max_players, ":num_players"),
  68685. (try_for_range, ":cur_player", 1, ":num_players"),
  68686. (player_is_active, ":cur_player"),
  68687. (assign, reg0, ":cur_player"),
  68688. (display_debug_message, "@{!}sending message to {reg0} multiplayer_event_other_event_ccoop_count_down_invisible"),
  68689. (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_ccoop_count_down_invisible, "$g_multiplayer_ccoop_enemy_respawn_secs", "$g_multiplayer_ccoop_wave_no"),
  68690. (try_end),
  68691. (try_end),
  68692. ]),
  68693.  
  68694.  
  68695. # script_multiplayer_ccoop_send_troop_data_to_client
  68696. # Input: client number
  68697. # Output: none
  68698. ("multiplayer_ccoop_send_troop_data_to_client",
  68699. [
  68700. (try_begin),
  68701. (store_script_param, ":cur_player", 1),
  68702.  
  68703. (troop_get_slot, ":data_1", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin),
  68704. (troop_get_slot, ":data_2", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 1),
  68705. (troop_get_slot, ":data_3", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 2),
  68706. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_ccoop_update_spawn_data_1, ":data_1", ":data_2", ":data_3"),
  68707. (troop_get_slot, ":data_1", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 3),
  68708. (troop_get_slot, ":data_2", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 4),
  68709. (troop_get_slot, ":data_3", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 5),
  68710. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_ccoop_update_spawn_data_2, ":data_1", ":data_2", ":data_3"),
  68711. (troop_get_slot, ":data_1", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 6),
  68712. (troop_get_slot, ":data_2", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 7),
  68713. (troop_get_slot, ":data_3", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 8),
  68714. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_ccoop_update_spawn_data_3, ":data_1", ":data_2", ":data_3"),
  68715. (troop_get_slot, ":data_1", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 9),
  68716. (troop_get_slot, ":data_2", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 10),
  68717. (troop_get_slot, ":data_3", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 11),
  68718. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_ccoop_update_spawn_data_4, ":data_1", ":data_2", ":data_3"),
  68719. (troop_get_slot, ":data_1", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 12),
  68720. (troop_get_slot, ":data_2", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 13),
  68721. (troop_get_slot, ":data_3", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 14),
  68722. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_ccoop_update_spawn_data_5, ":data_1", ":data_2", ":data_3"),
  68723. (troop_get_slot, ":data_1", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 15),
  68724. (multiplayer_send_2_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_ccoop_update_spawn_data_6, ":data_1"),
  68725. (try_end),
  68726. ]),
  68727.  
  68728. # script_multiplayer_ccoop_spawn_wave
  68729. # Input: spawn_required -> how many bots are needed
  68730. # Output: none
  68731. ("multiplayer_ccoop_spawn_wave",
  68732. [
  68733. (try_begin),
  68734. (multiplayer_is_server),
  68735. (set_fixed_point_multiplier, 100),
  68736.  
  68737. (store_script_param, ":spawn_required", 1),
  68738.  
  68739. (assign, reg0, ":spawn_required"), # debug
  68740. (display_debug_message, "@{!}spawn required is: {reg0}"),
  68741.  
  68742. (assign, ":num_troops_for_wave", 0),
  68743.  
  68744. #(troop_get_slot, ":num_bot_types", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin),
  68745. (try_for_range, ":cur_bot_type", 0, 5),
  68746. (store_mul, ":cur_slot", ":cur_bot_type", 3),
  68747. (val_add, ":cur_slot", multi_data_ccoop_wave_spawn_data_begin + 2),
  68748. (troop_get_slot, ":cur_bot_count", "trp_multiplayer_data", ":cur_slot"),
  68749. (val_add, ":num_troops_for_wave", ":cur_bot_count"),
  68750. (try_end),
  68751.  
  68752. (assign, reg0, ":num_troops_for_wave"), # debug
  68753. (display_debug_message, "@{!}num_troops_for_wave is {reg0}"),
  68754.  
  68755. (assign, ":reduced_spawn_amount", 0),
  68756. (assign, ":reduced_spawn_amount_mod", 0),
  68757. (try_begin),
  68758. (gt, ":num_troops_for_wave", ":spawn_required"),
  68759. (store_sub, ":reduced_spawn_amount", ":num_troops_for_wave", ":spawn_required"),
  68760. #(store_mod, ":reduced_spawn_amount_mod", ":reduced_spawn_amount", ":num_bot_types"),
  68761. #(val_div, ":reduced_spawn_amount", ":num_bot_types"),
  68762.  
  68763. (assign, reg0, ":reduced_spawn_amount"), # debug
  68764. (assign, reg1, ":reduced_spawn_amount_mod"), # debug
  68765. (display_debug_message, "@{!}num_troops_for_wave is gt spawn_required. reduced_spawn_amount is {reg0}, reduced_spawn_amount_mod is {reg1}"),
  68766. (try_end),
  68767.  
  68768. (store_current_scene, ":cur_scene"),
  68769. (modify_visitors_at_site, ":cur_scene"),
  68770. (assign, ":num_troops_spawned", 0),
  68771.  
  68772. #(troop_get_slot, ":leader_no", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 1),
  68773. #(troop_get_slot, ":point_no", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin + 3),
  68774. #(entry_point_get_position, pos60, ":point_no"),
  68775.  
  68776.  
  68777.  
  68778. (try_for_range, ":cur_bot_spawning", 0, 5),
  68779. (store_mul, ":cur_slot", ":cur_bot_spawning", 3),
  68780. (val_add, ":cur_slot", multi_data_ccoop_wave_spawn_data_begin + 1),
  68781. (troop_get_slot, ":spawned_troop_no", "trp_multiplayer_data", ":cur_slot"),
  68782. (gt, ":spawned_troop_no", 0),
  68783. (val_add, ":cur_slot", 1),
  68784. (troop_get_slot, ":spawned_troop_count", "trp_multiplayer_data", ":cur_slot"),
  68785. (assign, ":original_spawned_troop_count", ":spawned_troop_count"),
  68786.  
  68787. (assign, reg0, ":original_spawned_troop_count"), # debug
  68788. (display_debug_message, "@{!}original_spawned_troop_count is {reg0}"),
  68789.  
  68790. (val_add, ":cur_slot", 1),
  68791. (troop_get_slot, ":spawned_troop_entry_point", "trp_multiplayer_data", ":cur_slot"),
  68792.  
  68793.  
  68794. (val_sub, ":spawned_troop_count", ":reduced_spawn_amount"),
  68795. (try_begin),
  68796. (lt, ":cur_bot_spawning", ":reduced_spawn_amount_mod"),
  68797. (val_sub, ":spawned_troop_count", 1),
  68798.  
  68799. (assign, reg0, ":cur_bot_spawning"), # debug
  68800. (assign, reg1, ":reduced_spawn_amount_mod"), # debug
  68801. (display_debug_message, "@{!}reducing spawn amount by one"),
  68802. (try_end),
  68803.  
  68804. (assign, reg0, ":cur_bot_spawning"), # debug
  68805. (assign, reg1, ":spawned_troop_entry_point"), # debug
  68806. (str_store_troop_name, s0, ":spawned_troop_no"), # debug
  68807. (assign, reg2, ":spawned_troop_count"), # debug
  68808. (display_debug_message, "@{!}spawning bot group {reg0}: {reg2} {s0} from entry point {reg1}"),
  68809.  
  68810. (add_visitors_to_current_scene, ":spawned_troop_entry_point", ":spawned_troop_no", ":spawned_troop_count", 1, -1),
  68811.  
  68812. (val_add, ":num_troops_spawned", ":spawned_troop_count"),
  68813. (val_sub, ":original_spawned_troop_count", ":spawned_troop_count"),
  68814. (store_mul, ":cur_slot", ":cur_bot_spawning", 3),
  68815. (val_add, ":cur_slot", multi_data_ccoop_wave_spawn_data_begin + 2),
  68816. (troop_set_slot, "trp_multiplayer_data", ":cur_slot", ":original_spawned_troop_count"),
  68817. (try_end),
  68818.  
  68819. # sync clients
  68820. (get_max_players, ":num_players"),
  68821. (try_for_range, ":cur_player", 1, ":num_players"),
  68822. (player_is_active, ":cur_player"),
  68823. (call_script, "script_multiplayer_ccoop_send_troop_data_to_client", ":cur_player"),
  68824. (try_end),
  68825. (try_end),
  68826. ]),
  68827.  
  68828. # script_multiplayer_ccoop_check_reinforcement
  68829. # Input: arg1 = team 1 initial count, arg2 = team 2 initial count
  68830. # Output: reg0 = number of players to be moved from team1 to team2 (can be negative).
  68831. ("multiplayer_ccoop_check_reinforcement",
  68832. [
  68833. (try_begin),
  68834. (multiplayer_is_server),
  68835.  
  68836. (call_script, "script_multiplayer_ccoop_get_alive_enemy_count"),
  68837. (store_sub, ":free_enemy_slots", 100, reg0), #enemy required
  68838.  
  68839. (try_begin),
  68840. (ge, ":free_enemy_slots", 50), # if 50 or more enemy reinforcement needed
  68841.  
  68842. (call_script, "script_multiplayer_ccoop_spawn_wave", ":free_enemy_slots"),
  68843. (else_try),
  68844. #(lt, ":free_enemy_slots", 50),
  68845. (assign, ":num_troops_for_wave", 0),
  68846. (troop_get_slot, ":num_bot_types", "trp_multiplayer_data", multi_data_ccoop_wave_spawn_data_begin),
  68847. (try_for_range, ":cur_bot_type", 0, ":num_bot_types"),
  68848. (store_mul, ":cur_slot", ":cur_bot_type", 3),
  68849. (val_add, ":cur_slot", multi_data_ccoop_wave_spawn_data_begin + 2),
  68850. (troop_get_slot, ":cur_bot_count", "trp_multiplayer_data", ":cur_slot"),
  68851. (val_add, ":num_troops_for_wave", ":cur_bot_count"),
  68852. (try_end),
  68853.  
  68854. (ge, ":free_enemy_slots", ":num_troops_for_wave"),
  68855. (call_script, "script_multiplayer_ccoop_spawn_wave", ":free_enemy_slots"),
  68856. (try_end),
  68857. (try_end),
  68858. ]),
  68859.  
  68860. # script_multiplayer_get_balance_dif
  68861. # Input: arg1 = team 1 initial count, arg2 = team 2 initial count
  68862. # Output: reg0 = number of players to be moved from team1 to team2 (can be negative).
  68863. ("multiplayer_get_balance_dif",
  68864. [
  68865. (store_script_param, ":number_of_players_at_team_1", 1),
  68866. (store_script_param, ":number_of_players_at_team_2", 2),
  68867. (get_max_players, ":num_players"),
  68868. (try_for_range, ":cur_player", 0, ":num_players"),
  68869. (player_is_active, ":cur_player"),
  68870. (player_get_team_no, ":player_team", ":cur_player"),
  68871. (try_begin),
  68872. (eq, ":player_team", 0),
  68873. (val_add, ":number_of_players_at_team_1", 1),
  68874. (else_try),
  68875. (eq, ":player_team", 1),
  68876. (val_add, ":number_of_players_at_team_2", 1),
  68877. (try_end),
  68878. (try_end),
  68879. (assign, ":single_player_move_effect", 2),
  68880.  
  68881. (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),
  68882. (assign, ":number_of_players_will_be_moved", 0),
  68883. (try_begin),
  68884. (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),
  68885. (le, ":difference_of_number_of_players", ":checked_value"),
  68886. (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", ":single_player_move_effect"),
  68887. (else_try),
  68888. (ge, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),
  68889. (store_div, ":number_of_players_will_be_moved", ":difference_of_number_of_players", ":single_player_move_effect"),
  68890. (try_end),
  68891. (assign, reg0, ":number_of_players_will_be_moved"),
  68892. ]
  68893. ),
  68894.  
  68895.  
  68896. # script_multiplayer_server_play_sound_at_position
  68897. # Input: arg1 = sound_id
  68898. # Input: pos60 = position
  68899. # Output: none
  68900. ("multiplayer_server_play_sound_at_position",
  68901. [
  68902. (store_script_param, ":sound_id", 1),
  68903.  
  68904. (try_begin),
  68905. (this_or_next|multiplayer_is_server),
  68906. (neg|game_in_multiplayer_mode),
  68907.  
  68908. (is_between, ":sound_id", 0, "snd_sounds_end"), # Valid sound
  68909.  
  68910. (try_begin),
  68911. (neg|multiplayer_is_dedicated_server), # If a client and not a dedicated server that calls then play locally.
  68912. (play_sound_at_position, ":sound_id", pos60),
  68913. (try_end),
  68914.  
  68915. (try_begin),
  68916. (multiplayer_is_server), # If this is a server broadcast the sound to all players
  68917.  
  68918. (set_fixed_point_multiplier, 100),
  68919. (position_get_x,":xvalue", pos60),
  68920. (position_get_y,":yvalue", pos60),
  68921. (position_get_z,":zvalue", pos60),
  68922.  
  68923. (get_max_players, ":num_players"),
  68924. (try_for_range, ":cur_player", 1, ":num_players"),
  68925. (player_is_active,":cur_player"),
  68926.  
  68927. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_return_sound_at_pos,":xvalue",":yvalue",":zvalue",":sound_id"),
  68928. (try_end),
  68929. (try_end),
  68930. (try_end),
  68931. ]),
  68932.  
  68933.  
  68934. # script_mp_set_coop_companions
  68935. ("mp_set_coop_companions",
  68936. [
  68937. (store_script_param, ":player_id", 1),
  68938. (assign, ":slot_id", slot_player_companion_ids_begin),
  68939. (player_set_slot, ":player_id", ":slot_id", "$g_presentation_obj_coop_companion_0"),
  68940. #(str_store_troop_name, s0, "$g_presentation_obj_coop_companion_0"),
  68941. #(troop_set_class, "$g_presentation_obj_coop_companion_0", 0),
  68942. #(class_set_name, 0, s0),
  68943. (val_add, ":slot_id", 1),
  68944. (player_set_slot, ":player_id", ":slot_id", "$g_presentation_obj_coop_companion_1"),
  68945. #(str_store_troop_name, s0, "$g_presentation_obj_coop_companion_1"),
  68946. #(troop_set_class, "$g_presentation_obj_coop_companion_0", 1),
  68947. #(class_set_name, 1, s0),
  68948. (val_add, ":slot_id", 1),
  68949. (player_set_slot, ":player_id", ":slot_id", "$g_presentation_obj_coop_companion_class_0"),
  68950. (assign, reg0, "$g_presentation_obj_coop_companion_class_0"),
  68951. #(display_message, "@setting companion class on client: {reg0}"),
  68952. (val_add, ":slot_id", 1),
  68953. (player_set_slot, ":player_id", ":slot_id", "$g_presentation_obj_coop_companion_class_1"),
  68954. ]),
  68955.  
  68956.  
  68957. # # script_mp_ccoop_change_map
  68958. # #MCA: change map
  68959. # ("mp_ccoop_change_map",
  68960. # [
  68961. # (try_begin),
  68962. # (multiplayer_is_dedicated_server),
  68963. #
  68964. # # random scene
  68965. # (store_random_in_range, ":scene_no", multiplayer_scenes_begin, multiplayer_scenes_end),
  68966. #
  68967. # (assign, "$g_multiplayer_selected_map", ":scene_no"),
  68968. # (team_set_faction, 0, "$g_multiplayer_next_team_1_faction"),
  68969. # (team_set_faction, 1, "$g_multiplayer_next_team_2_faction"),
  68970. # (call_script, "script_game_multiplayer_get_game_type_mission_template", "$g_multiplayer_game_type"),
  68971. # (start_multiplayer_mission, reg0, "$g_multiplayer_selected_map", 1),
  68972. # (else_try),
  68973. # (multiplayer_is_server),
  68974. # (call_script, "script_game_multiplayer_get_game_type_mission_template", "$g_multiplayer_game_type"),
  68975. # (start_multiplayer_mission, reg0, "$g_multiplayer_selected_map", 1),
  68976. # (try_end),
  68977. # ]
  68978. # ),
  68979.  
  68980.  
  68981.  
  68982. # script_mp_get_player_alive_troop_count
  68983. # MCA
  68984. # returns alive bot count for player team on reg0
  68985. ("mp_get_player_alive_troop_count", # parameters: 1. player_id 2. troop_id
  68986. [
  68987. (store_script_param, ":player_id", 1),
  68988. (store_script_param, ":troop_id", 2),
  68989.  
  68990. (player_get_team_no, ":player_team", ":player_id"),
  68991.  
  68992. (assign, ":troop_count", 0),
  68993.  
  68994. (try_for_agents, ":cur_agent"),
  68995. (agent_is_human, ":cur_agent"),
  68996. (agent_is_alive, ":cur_agent"),
  68997. (agent_is_non_player, ":cur_agent"),
  68998. (agent_get_team, ":cur_agent_team", ":cur_agent"),
  68999.  
  69000. (try_begin),
  69001. (eq, ":player_team", ":cur_agent_team"),
  69002. (agent_get_troop_id, ":agent_troop_id", ":cur_agent"),
  69003. (eq, ":troop_id", ":agent_troop_id"),
  69004.  
  69005. # if agent belongs to the player
  69006. (agent_get_group, ":agent_group", ":cur_agent"),
  69007. (eq, ":agent_group", ":player_id"),
  69008.  
  69009. (val_add, ":troop_count", 1),
  69010. (try_end),
  69011. (try_end),
  69012.  
  69013. (assign, reg0, ":troop_count"),
  69014.  
  69015. #MCA
  69016. # (assign, reg1, ":troop_id"),
  69017. # (assign, reg2, ":player_id"),
  69018. # (display_debug_message, "@{!}alive troop ({reg1}) count: {reg0} for player {reg2}"),
  69019. ]),
  69020.  
  69021. # script_mp_get_player_total_alive_troop_count
  69022. # MCA
  69023. # returns total alive bot count for player team on reg0
  69024. ("mp_get_player_total_alive_troop_count", # parameters: 1. player_id
  69025. [
  69026. (store_script_param, ":player_id", 1),
  69027.  
  69028. (player_get_team_no, ":player_team", ":player_id"),
  69029.  
  69030. (assign, ":troop_count", 0),
  69031.  
  69032. (try_for_agents, ":cur_agent"),
  69033. (agent_is_human, ":cur_agent"),
  69034. (agent_is_alive, ":cur_agent"),
  69035. (agent_is_non_player, ":cur_agent"),
  69036. (agent_get_team, ":cur_agent_team", ":cur_agent"),
  69037.  
  69038. # if agent belongs to the player
  69039. (agent_get_group, ":agent_group", ":cur_agent"),
  69040. (eq, ":agent_group", ":player_id"),
  69041.  
  69042. (try_begin),
  69043. (eq, ":player_team", ":cur_agent_team"),
  69044. (val_add, ":troop_count", 1),
  69045. (try_end),
  69046. (try_end),
  69047.  
  69048. (assign, reg0, ":troop_count"),
  69049.  
  69050. #MCA
  69051. # (assign, reg2, ":player_id"),
  69052. # (display_debug_message, "@{!}total alive troop count: {reg0} for player {reg2}"),
  69053. ]),
  69054.  
  69055. # script_multiplayer_spawn_player_bot_squad_at_point
  69056. ("multiplayer_spawn_player_bot_squad_at_point",
  69057. [
  69058. (store_script_param, ":player_no", 1),
  69059. (store_script_param, ":player_team", 2),
  69060. (store_script_param, ":point_no", 3),
  69061.  
  69062. (try_begin),
  69063.  
  69064. (call_script, "script_multiplayer_get_bots_count", ":player_no"),
  69065. (assign, ":player_bot_count", reg0),
  69066.  
  69067.  
  69068. (try_for_range, ":slot_id", slot_player_companion_ids_begin, slot_player_companion_ids_end),
  69069. (lt, ":player_bot_count", 2),
  69070.  
  69071. (player_get_slot, ":companion_id", ":player_no", ":slot_id"),
  69072. (call_script, "script_mp_get_player_alive_troop_count", ":player_no", ":companion_id"),
  69073. (eq, reg0, 0),
  69074. #(try_begin),
  69075. # (try_for_range, ":cur_slot", slot_player_companion_ids_begin, slot_player_companion_classes_end),
  69076. # (assign, reg1, ":cur_slot"),
  69077. # (player_get_slot, reg2, ":player_no", ":cur_slot"),
  69078. # (multiplayer_send_string_to_player, ":player_no", multiplayer_event_show_server_message, "@{!}spawning companion slot: {reg1} value {reg2}"),
  69079. # (try_end),
  69080. #(try_end),
  69081.  
  69082. (call_script, "script_mp_spawn_coop_companion", ":player_no", ":companion_id", ":slot_id", ":player_team", ":point_no"),
  69083. #(try_begin),
  69084. # (try_for_range, ":cur_slot", slot_player_companion_ids_begin, slot_player_companion_classes_end),
  69085. # (assign, reg1, ":cur_slot"),
  69086. # (player_get_slot, reg2, ":player_no", ":cur_slot"),
  69087. # (multiplayer_send_string_to_player, ":player_no", multiplayer_event_show_server_message, "@{!}after spawning slot: {reg1} value {reg2}"),
  69088. # (try_end),
  69089. #(try_end),
  69090.  
  69091.  
  69092. (val_add, ":player_bot_count", 1),
  69093. (try_end),
  69094.  
  69095. (try_end),
  69096. ]),
  69097.  
  69098. ("multiplayer_get_spawn_point_close_to_bots",
  69099. [
  69100. (store_script_param, ":player_no", 1),
  69101. (player_get_team_no, ":player_team", ":player_no"),
  69102. (assign, ":x_pos", 0),
  69103. (assign, ":y_pos", 0),
  69104. (assign, ":num_living_players", 0),
  69105. (try_for_agents, ":agent_no"),
  69106. (agent_is_human, ":agent_no"),
  69107. (agent_is_alive, ":agent_no"),
  69108. (agent_is_non_player, ":agent_no"),
  69109. (agent_get_group, ":agent_group", ":agent_no"),
  69110. (agent_get_team, ":agent_team", ":agent_no"),
  69111. (try_begin),
  69112. (eq, ":agent_group", ":player_no"),
  69113. (eq, ":agent_team", ":player_team"),
  69114. (agent_get_position, pos2, ":agent_no"),
  69115. (position_get_x, ":x1", pos2),
  69116. (position_get_y, ":y1", pos2),
  69117. (val_add, ":x_pos", ":x1"),
  69118. (val_add, ":y_pos", ":y1"),
  69119. (val_add, ":num_living_players", 1),
  69120. (try_end),
  69121. (try_end),
  69122. (try_begin),
  69123. (gt, ":num_living_players", 0),
  69124. (val_div, ":x_pos", ":num_living_players"),
  69125. (val_div, ":y_pos", ":num_living_players"),
  69126. (try_end),
  69127. (position_set_x, pos0, ":x_pos"),
  69128. (position_set_y, pos0, ":y_pos"),
  69129. (position_set_z, pos0, 0),
  69130. (assign, ":best_score", 0),
  69131. (assign, ":best_point", 0),
  69132. (try_for_range, ":i_point", 0, multi_num_valid_entry_points),
  69133. (entry_point_get_position, pos1, ":i_point"),
  69134. (position_set_z, pos1, 0),
  69135. (get_sq_distance_between_positions_in_meters, ":dist", pos0, pos1),
  69136. (try_begin),
  69137. (le, ":dist", multi_dist_to_capt_spawn_point),
  69138. (val_max, ":dist", 1),
  69139. (store_mul, ":score", multi_dist_to_capt_spawn_point, 1000),
  69140. (val_div, ":score", ":dist"),
  69141. (try_begin),
  69142. (gt, ":score", ":best_score"),
  69143. (assign, ":best_point", ":i_point"),
  69144. (assign, ":best_score", ":score"),
  69145. (try_end),
  69146. (try_end),
  69147. (try_end),
  69148. (assign, reg0, ":best_point"),
  69149. ]),
  69150.  
  69151. # script_multiplayer_get_spawn_point_close_to_player
  69152. # input: arg1 = player_no
  69153. # output: reg0 = best_spawn_point
  69154. ("multiplayer_get_spawn_point_close_to_player",
  69155. [
  69156. (store_script_param, ":player_no", 1),
  69157. (player_get_agent_id, ":player_agent", ":player_no"),
  69158. (position_set_x, pos0, 0),
  69159. (position_set_y, pos0, 0),
  69160. (try_begin),
  69161. (agent_is_alive, ":player_agent"),
  69162. (agent_get_position, pos0, ":player_agent"),
  69163. (try_end),
  69164.  
  69165. (position_set_z, pos0, 0),
  69166. (assign, ":best_score", 0),
  69167. (assign, ":best_point", 0),
  69168. (try_for_range, ":i_point", 0, multi_num_valid_entry_points),
  69169. (entry_point_get_position, pos1, ":i_point"),
  69170. (position_set_z, pos1, 0),
  69171. (get_sq_distance_between_positions_in_meters, ":dist", pos0, pos1),
  69172. (try_begin),
  69173. (le, ":dist", multi_dist_to_capt_spawn_point),
  69174. (val_max, ":dist", 1),
  69175. (store_mul, ":score", multi_dist_to_capt_spawn_point, 1000),
  69176. (val_div, ":score", ":dist"),
  69177. (try_begin),
  69178. (gt, ":score", ":best_score"),
  69179. (assign, ":best_point", ":i_point"),
  69180. (assign, ":best_score", ":score"),
  69181. (try_end),
  69182. (try_end),
  69183. (try_end),
  69184. (assign, reg0, ":best_point"),
  69185. ]),
  69186.  
  69187. ("multiplayer_get_bots_count",
  69188. [
  69189. (store_script_param, ":player_no", 1),
  69190. (player_get_team_no, ":player_team", ":player_no"),
  69191. (assign, ":num_living_players", 0),
  69192. (try_for_agents, ":agent_no"),
  69193. (agent_is_human, ":agent_no"),
  69194. (agent_is_alive, ":agent_no"),
  69195. (agent_is_non_player, ":agent_no"),
  69196. (agent_get_group, ":agent_group", ":agent_no"),
  69197. (agent_get_team, ":agent_team", ":agent_no"),
  69198. (try_begin),
  69199. (eq, ":agent_group", ":player_no"),
  69200. (eq, ":agent_team", ":player_team"),
  69201. (val_add, ":num_living_players", 1),
  69202. (try_end),
  69203. (try_end),
  69204. (assign, reg0, ":num_living_players"),
  69205. ]),
  69206.  
  69207. ("multiplayer_get_selected_squad_slot_id",
  69208. [
  69209. (store_script_param, ":player_no", 1),
  69210. (assign, ":cur_troop_no", slot_player_bot_type_1_wanted),
  69211. (try_for_range, ":slot_no", slot_player_bot_type_1_wanted, slot_player_bot_type_4_wanted+1),
  69212. (player_get_slot, ":value", ":player_no", ":slot_no"),
  69213. (try_begin),
  69214. (eq, ":value", 1),
  69215. (assign, ":cur_troop_no", ":slot_no"),
  69216. (try_end),
  69217. (try_end),
  69218. (assign, reg0, ":cur_troop_no"),
  69219. ]),
  69220.  
  69221.  
  69222. # script_cf_multiplayer_event_team_change
  69223. ("cf_multiplayer_event_team_change",
  69224. [
  69225. (store_script_param, ":player_no", 1),
  69226. (try_begin),
  69227. (eq, "$g_multiplayer_is_game_type_captain", 1),
  69228. (player_get_team_no, ":player_team", ":player_no"),
  69229. #(player_get_agent_id, ":player_agent", ":player_no"),
  69230. (try_for_agents, ":agent_no"),
  69231. (agent_is_human, ":agent_no"),
  69232. (agent_is_alive, ":agent_no"),
  69233. (agent_is_non_player, ":agent_no"),
  69234. (agent_get_group, ":agent_group", ":agent_no"),
  69235. (agent_get_team, ":agent_team", ":agent_no"),
  69236. (try_begin),
  69237. (eq, ":agent_group", ":player_no"),
  69238. (eq, ":agent_team", ":player_team"),
  69239.  
  69240. ## increase player's kill count by 2 since death of each squad member will cause -2 score on team change
  69241. #(player_get_kill_count, ":player_kill_count", ":player_no"),
  69242. #(val_add, ":player_kill_count", 2),
  69243. #(player_set_kill_count, ":player_no", ":player_kill_count"),
  69244. ## also decrease death by 2 for the same reason
  69245. #(player_get_death_count, ":player_death_count", ":player_no"),
  69246. #(val_sub, ":player_death_count", 2),
  69247. #(player_set_death_count, ":player_no", ":player_death_count"),
  69248.  
  69249. #(call_script, "script_add_kill_death_counts", ":player_agent", ":agent_no"),
  69250. (remove_agent, ":agent_no"),
  69251. (try_end),
  69252. (try_end),
  69253. (try_end),
  69254. ]),
  69255.  
  69256.  
  69257.  
  69258.  
  69259. # script_team_get_attack_readying_ranged_agent_percentage
  69260. # Input: arg1: team_no, arg2: try for team's enemies
  69261. # Output: reg0: percentage attack readying ranged agent,
  69262. ("team_get_attack_readying_ranged_agent_percentage",
  69263. [
  69264. (store_script_param, ":team_no", 1),
  69265. (store_script_param, ":negate", 2),
  69266. (assign, ":num_ranged_agents", 0),
  69267. (assign, ":num_readying_attack", 0),
  69268. (try_for_agents,":cur_agent"),
  69269. (agent_is_alive, ":cur_agent"),
  69270. (agent_is_human, ":cur_agent"),
  69271. (agent_get_team, ":agent_team", ":cur_agent"),
  69272. (assign, ":continue", 0),
  69273. (try_begin),
  69274. (eq, ":negate", 1),
  69275. (teams_are_enemies, ":agent_team", ":team_no"),
  69276. (assign, ":continue", 1),
  69277. (else_try),
  69278. (eq, ":agent_team", ":team_no"),
  69279. (assign, ":continue", 1),
  69280. (try_end),
  69281. (eq, ":continue", 1),
  69282. (agent_get_combat_state, ":agent_cs", ":cur_agent"),
  69283. (agent_get_wielded_item, ":agent_wi0", ":cur_agent", 0),
  69284. (try_begin),
  69285. (is_between,":agent_wi0",ranged_weapons_begin,ranged_weapons_end),
  69286. (val_add, ":num_ranged_agents", 1),
  69287. (try_begin),
  69288. (eq, ":agent_cs", 1),#atkcs_readying_attack
  69289. (val_add, ":num_readying_attack", 1),
  69290. (try_end),
  69291. (try_end),
  69292. (try_end),
  69293.  
  69294. (try_begin),
  69295. (eq, ":num_ranged_agents", 0),
  69296. (assign, ":num_ranged_agents", 1),
  69297. (try_end),
  69298. (store_mul, ":perc_readying_attack_over_rangeds", ":num_readying_attack", 100),
  69299. (val_div, ":perc_readying_attack_over_rangeds", ":num_ranged_agents"),
  69300. (assign, reg0, ":perc_readying_attack_over_rangeds"),
  69301. ]),
  69302.  
  69303. # script_multiplayer_get_requested_squad_count
  69304. # Input: none
  69305. # Output: reg0 = requested squad count
  69306. ("multiplayer_get_requested_squad_count",
  69307. [
  69308. (store_script_param, ":player_id", 1),
  69309. (assign, ":total_troop_count", 0),
  69310. (try_for_range, ":slot_id", slot_player_companion_ids_begin, slot_player_companion_ids_end),
  69311. (player_get_slot, ":troop_count", ":player_id", ":slot_id"),
  69312. (val_add, ":total_troop_count", ":troop_count"),
  69313. (try_end),
  69314.  
  69315. (assign, reg0, ":total_troop_count"),
  69316. ]),
  69317.  
  69318.  
  69319.  
  69320.  
  69321. # script_multiplayer_update_cost_labels
  69322. # Input: none
  69323. # Output: none
  69324. ("multiplayer_update_cost_labels",
  69325. [
  69326. (multiplayer_get_my_player, ":my_player_no"),
  69327. (player_get_gold, ":player_gold", ":my_player_no"),
  69328. (call_script, "script_multiplayer_calculate_cur_selected_items_cost", ":my_player_no", 1),
  69329.  
  69330. (overlay_set_text, "$g_presentation_obj_item_select_12", "str_total_item_cost_reg0"),
  69331. (try_begin),
  69332. (ge, ":player_gold", reg0),
  69333. (overlay_set_color, "$g_presentation_obj_item_select_12", 0xFFFFFF),
  69334. (else_try),
  69335. (overlay_set_color, "$g_presentation_obj_item_select_12", 0xFF0000),
  69336. (try_end),
  69337. ]),
  69338.  
  69339. # script_multiplayer_ccoop_give_round_bonus_gold
  69340. # Input: none
  69341. # Output: none
  69342. ("multiplayer_ccoop_give_round_bonus_gold",
  69343. [
  69344. (try_begin),
  69345. (gt, "$g_multiplayer_ccoop_wave_no", 0),
  69346. (store_mul, ":bonus_gold", "$g_multiplayer_ccoop_wave_no", 100),
  69347. (val_add, ":bonus_gold", 400),
  69348.  
  69349. (get_max_players, ":num_players"),
  69350. (try_for_range, ":cur_player", 0, ":num_players"),
  69351. (player_is_active, ":cur_player"),
  69352. (player_get_gold, ":player_gold", ":cur_player"),
  69353. (val_add, ":player_gold", ":bonus_gold"),
  69354. (player_set_gold, ":cur_player", ":player_gold", multi_max_gold_that_can_be_stored),
  69355. (try_end),
  69356. (try_end),
  69357. ]),
  69358.  
  69359. # script_multiplayer_ccoop_destroy_prison_cart
  69360. # Input: none
  69361. # Output: none
  69362. ("multiplayer_ccoop_destroy_prison_cart",
  69363. [
  69364. (try_begin),
  69365. (multiplayer_is_server),
  69366.  
  69367. (try_begin),
  69368. (multiplayer_is_dedicated_server),
  69369.  
  69370. (assign, "$g_prison_cart_previous_point", "$g_prison_cart_point"),
  69371. (assign, "$g_prison_cart_point", 0),
  69372.  
  69373. (scene_prop_get_instance, ":prison_cart", "spr_prison_cart", 0),
  69374. (scene_prop_get_instance, ":prison_cart_door_left", "spr_prison_cart_door_left", 0),
  69375. (scene_prop_get_instance, ":prison_cart_door_right", "spr_prison_cart_door_right", 0),
  69376.  
  69377. (set_fixed_point_multiplier, 100),
  69378.  
  69379. (prop_instance_get_position, pos1, ":prison_cart"),
  69380. (position_set_z, pos1, -4000), #40m down
  69381. (prop_instance_set_position, ":prison_cart", pos1),
  69382. (prop_instance_set_position, ":prison_cart_door_left", pos1),
  69383. (prop_instance_set_position, ":prison_cart_door_right", pos1),
  69384. (try_end),
  69385.  
  69386. (display_debug_message, "@{!}destroy prison cart"),
  69387.  
  69388. # send destroy prison cart event to clients
  69389. (get_max_players, ":max_players"),
  69390. (try_for_range, ":cur_player", 0, ":max_players"),
  69391. (player_is_active, ":cur_player"),
  69392. (multiplayer_send_int_to_player, ":cur_player", multiplayer_event_other_events,
  69393. multiplayer_event_other_destroy_prison_cart),
  69394. (try_end),
  69395.  
  69396. (try_end),
  69397. ]),
  69398.  
  69399. # script_multiplayer_ccoop_spawn_prison_cart
  69400. # INPUT: none
  69401. # OUTPUT: none
  69402. ("multiplayer_ccoop_spawn_prison_cart",
  69403. [
  69404. (try_begin),
  69405. (multiplayer_is_server),
  69406.  
  69407. # get prison cart random spawn point
  69408. (store_random_in_range, "$g_prison_cart_point", 70, 75),
  69409.  
  69410. #
  69411. (assign, reg0, "$g_prison_cart_point"),
  69412. (display_debug_message, "@{!}spawning prison cart at point {reg0}"),
  69413. #
  69414.  
  69415. # set prison cart position
  69416. (set_fixed_point_multiplier, 100),
  69417. (scene_prop_get_instance, ":prison_cart", "spr_prison_cart", 0),
  69418. (entry_point_get_position, pos1, "$g_prison_cart_point"),
  69419. (position_move_y, pos1, -400), #4m back
  69420. (position_set_z_to_ground_level, pos1),
  69421. (prop_instance_set_position, ":prison_cart", pos1),
  69422.  
  69423. # place left door
  69424. (scene_prop_get_instance, ":prison_cart_door_left", "spr_prison_cart_door_left", 0),
  69425. (init_position, pos2),
  69426. (position_set_x, pos2, 84, 0),
  69427. (position_set_y, pos2, -314, 0),
  69428. (position_set_z, pos2, 121, 0),
  69429. (position_transform_position_to_parent, pos3, pos1, pos2),
  69430. (prop_instance_set_position, ":prison_cart_door_left", pos3),
  69431. (scene_prop_set_hit_points, ":prison_cart_door_left", 300),
  69432.  
  69433. # place right door
  69434. (scene_prop_get_instance, ":prison_cart_door_right", "spr_prison_cart_door_right", 0),
  69435. (init_position, pos2),
  69436. (position_set_x, pos2, -84, 0),
  69437. (position_set_y, pos2, -315, 0),
  69438. (position_set_z, pos2, 123, 0),
  69439. (position_transform_position_to_parent, pos3, pos1, pos2),
  69440. (prop_instance_set_position, ":prison_cart_door_right", pos3),
  69441. (scene_prop_set_hit_points, ":prison_cart_door_right", 300),
  69442.  
  69443. (try_begin),
  69444. #(neg|multiplayer_is_dedicated_server),
  69445. (call_script, "script_multiplayer_ccoop_set_prison_cart_visibility", 1),
  69446.  
  69447. # display prison cart hint message to alive players
  69448. (get_player_agent_no, ":player_agent"),
  69449. (ge, ":player_agent", 0),
  69450. (display_message, "str_prison_cart_hint"),
  69451.  
  69452. (start_presentation, "prsnt_multiplayer_ccoop_next_wave_time_counter"), # to display ask for help to respawn hint
  69453. (try_end),
  69454.  
  69455. # send destroy prison cart event to clients
  69456. (get_max_players, ":max_players"),
  69457. (try_for_range, ":cur_player", 1, ":max_players"),
  69458. (try_begin),
  69459. (player_is_active, ":cur_player"),
  69460. (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events,
  69461. multiplayer_event_other_spawn_prison_cart, "$g_prison_cart_point", 300),
  69462. (try_end),
  69463. (try_end),
  69464. (try_end),
  69465. ]),
  69466.  
  69467. # script_multiplayer_ccoop_get_alive_enemy_count
  69468. # Input: none
  69469. # Output: reg0 = alive_enemy_count
  69470. ("multiplayer_ccoop_get_alive_enemy_count",
  69471. [
  69472. (assign, ":alive_enemy_count", 0),
  69473. (try_for_agents, ":cur_agent"),
  69474. (try_begin),
  69475. (agent_is_active, ":cur_agent"),
  69476. (agent_is_human, ":cur_agent"),
  69477. (agent_is_alive, ":cur_agent"),
  69478. (agent_get_team, ":cur_agent_team", ":cur_agent"),
  69479. (eq, ":cur_agent_team", 1),
  69480. (val_add, ":alive_enemy_count", 1),
  69481. (try_end),
  69482. (try_end),
  69483. (assign, reg0, ":alive_enemy_count"),
  69484. ]),
  69485.  
  69486.  
  69487. #berk
  69488. #script_add_troop_to_cur_tableau_for_multiplayer
  69489. # INPUT: troop_no
  69490. # OUTPUT: none
  69491. ("add_troop_to_cur_tableau_for_multiplayer",
  69492. [
  69493. (store_script_param, ":troop_no",1),
  69494.  
  69495. (set_fixed_point_multiplier, 100),
  69496.  
  69497. (cur_tableau_clear_override_items),
  69498. (cur_tableau_set_override_flags, af_override_fullhelm),
  69499. ## (cur_tableau_set_override_flags, af_override_head|af_override_weapons),
  69500.  
  69501. (init_position, pos2),
  69502. (cur_tableau_set_camera_parameters, 1, 8, 8, 10, 10000),
  69503.  
  69504. (init_position, pos5),
  69505. (assign, ":cam_height", 300),
  69506. # (val_mod, ":camera_distance", 5),
  69507. (assign, ":camera_distance", 1000),
  69508. (assign, ":camera_yaw", -15),
  69509. (assign, ":camera_pitch", -18),
  69510. (assign, ":animation", anim_stand_man),
  69511.  
  69512. (troop_get_inventory_slot, ":horse_item", ":troop_no", ek_horse),
  69513. (try_begin),
  69514. (gt, ":horse_item", 0),
  69515. (cur_tableau_add_horse, ":horse_item", pos2, "anim_horse_stand", 0),
  69516. (assign, ":animation", "anim_ride_0"),
  69517. (assign, ":camera_pitch", -20),
  69518. (assign, ":camera_yaw", -25),
  69519. (assign, ":cam_height", 500),
  69520. (assign, ":camera_distance", 1400),
  69521. (position_move_x, pos5, 50, 0),
  69522. (try_end),
  69523. (position_set_z, pos5, ":cam_height"),
  69524.  
  69525. # camera looks towards -z axis
  69526. (position_rotate_x, pos5, -90),
  69527. (position_rotate_z, pos5, 180),
  69528.  
  69529. # now apply yaw and pitch
  69530. (position_rotate_y, pos5, ":camera_yaw"),
  69531. (position_rotate_x, pos5, ":camera_pitch"),
  69532. (position_move_z, pos5, ":camera_distance", 0),
  69533. (position_move_x, pos5, -120, 0),
  69534. (position_move_y, pos5, 130, 0),
  69535.  
  69536. (try_begin),
  69537. (troop_is_hero, ":troop_no"),
  69538. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", -1),
  69539. (else_try),
  69540. (store_mul, ":random_seed", ":troop_no", 126233),
  69541. (val_mod, ":random_seed", 1000),
  69542. (val_add, ":random_seed", 1),
  69543. (cur_tableau_add_troop, ":troop_no", pos2, ":animation", ":random_seed"),
  69544. (try_end),
  69545. (cur_tableau_set_camera_position, pos5),
  69546.  
  69547. (copy_position, pos8, pos5),
  69548. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  69549. (position_rotate_z, pos8, 30),
  69550. (position_rotate_x, pos8, -60),
  69551. (cur_tableau_add_sun_light, pos8, 175,150,125),
  69552. ]),
  69553.  
  69554. # script_mp_set_player_troop_id
  69555. # Input: arg1 = player_no, arg2 = troop_id, arg3 = sync with server
  69556. # Output: none
  69557. ("mp_set_player_troop_id",
  69558. [
  69559. (store_script_param, ":player_no", 1),
  69560. (store_script_param, ":troop_id", 2),
  69561. (store_script_param, ":do_sync", 3),
  69562. (player_set_troop_id, ":player_no", ":troop_id"),
  69563. (try_begin),
  69564. (eq, ":troop_id", -1),
  69565. (call_script, "script_multiplayer_clear_player_selected_items", ":player_no"), # just to make sure
  69566. (else_try),
  69567. (call_script, "script_multiplayer_set_default_item_selections_for_troop", ":player_no", ":troop_id"),
  69568. (try_end),
  69569. # server will do the same, so no need to send the new selections
  69570. (try_begin),
  69571. (neq, ":do_sync", 0),
  69572. (multiplayer_send_int_to_server, multiplayer_event_change_troop_id, ":troop_id"),
  69573. (try_end),
  69574. ]),
  69575.  
  69576. # script_mp_set_player_team_no
  69577. # Input: arg1 = player_no, arg2 = team_no, arg3 = sync with server
  69578. # Output: none
  69579. ("mp_set_player_team_no",
  69580. [
  69581. (store_script_param, ":player_no", 1),
  69582. (store_script_param, ":team_no", 2),
  69583. (store_script_param, ":do_sync", 3),
  69584. (player_set_team_no, ":player_no", ":team_no"),
  69585. (try_begin),
  69586. (neq, ":do_sync", 0),
  69587.  
  69588. #(assign, reg0, ":team_no"),
  69589. #(display_debug_message, "@{!}multiplayer_event_change_team_no is sent with team_no: {reg0}"),
  69590.  
  69591. (multiplayer_send_int_to_server, multiplayer_event_change_team_no, ":team_no"),
  69592. (try_end),
  69593. (call_script, "script_mp_set_player_troop_id", ":player_no", -1, 0),
  69594. #(call_script, "script_multiplayer_reset_squad_on_team_change_for_captain_game_types", ":player_no"),
  69595. # server will do the same, so no need to send the new selections
  69596. ]),
  69597.  
  69598.  
  69599.  
  69600.  
  69601. # script_multiplayer_ccoop_set_prison_cart_visibility
  69602. # Input: arg1 = visible
  69603. # Output: none
  69604. ("multiplayer_ccoop_set_prison_cart_visibility",
  69605. [
  69606. (store_script_param, ":visibility", 1),
  69607.  
  69608. (set_fixed_point_multiplier, 100),
  69609.  
  69610. (try_begin),
  69611. (scene_prop_get_instance, ":prison_cart", "spr_prison_cart", 0),
  69612. (scene_prop_get_instance, ":prison_cart_door_left", "spr_prison_cart_door_left", 0),
  69613. (scene_prop_get_instance, ":prison_cart_door_right", "spr_prison_cart_door_right", 0),
  69614.  
  69615. (try_begin),
  69616. (eq, ":visibility", 0), # if make invisible
  69617.  
  69618. (scene_prop_fade_out, ":prison_cart", 400),
  69619. (scene_prop_fade_out, ":prison_cart_door_left", 400),
  69620. (scene_prop_fade_out, ":prison_cart_door_right", 400),
  69621.  
  69622. (prop_instance_enable_physics, ":prison_cart", 0),
  69623. (prop_instance_enable_physics, ":prison_cart_door_left", 0),
  69624. (prop_instance_enable_physics, ":prison_cart_door_right", 0),
  69625.  
  69626. (store_mission_timer_a, "$g_multiplayer_ccoop_move_prison_cart"),
  69627. (val_add, "$g_multiplayer_ccoop_move_prison_cart", 5), # after 5secs (related to 400)
  69628.  
  69629. (assign, "$g_prison_cart_previous_point", "$g_prison_cart_point"),
  69630. (assign, "$g_prison_cart_point", 0),
  69631. (else_try),
  69632. (gt, ":visibility", 0), # if make visible
  69633.  
  69634. (scene_prop_fade_in, ":prison_cart", 300),
  69635. (scene_prop_fade_in, ":prison_cart_door_left", 300),
  69636. (scene_prop_fade_in, ":prison_cart_door_right", 300),
  69637.  
  69638. (prop_instance_enable_physics, ":prison_cart", 1),
  69639. (prop_instance_enable_physics, ":prison_cart_door_left", 1),
  69640. (prop_instance_enable_physics, ":prison_cart_door_right", 1),
  69641. (try_end),
  69642. (try_end),
  69643. ]),
  69644.  
  69645. # script_multiplayer_ccoop_spawn_player_and_bots
  69646. # INPUT: 1. player_no
  69647. # OUTPUT: 0 if player not spawned, 1 if player spawned on reg0
  69648. ("multiplayer_ccoop_spawn_player_and_bots",
  69649. [
  69650. (store_script_param, ":player_no", 1),
  69651.  
  69652. (try_begin),
  69653. (neg|player_is_busy_with_menus, ":player_no"),
  69654. (player_get_team_no, ":player_team", ":player_no"), #if player is currently spectator do not spawn his agent
  69655. (lt, ":player_team", multi_team_spectator),
  69656.  
  69657. (player_get_troop_id, ":player_troop", ":player_no"), #if troop is not selected do not spawn his agent
  69658. (ge, ":player_troop", 0),
  69659.  
  69660. (call_script, "script_multiplayer_buy_agent_equipment", ":player_no"),
  69661.  
  69662. (troop_get_inventory_slot, ":has_horse", ":player_troop", ek_horse),
  69663. (try_begin),
  69664. (ge, ":has_horse", 0),
  69665. (assign, ":is_horseman", 1),
  69666. (else_try),
  69667. (assign, ":is_horseman", 0),
  69668. (try_end),
  69669.  
  69670. (call_script, "script_multiplayer_get_bots_count", ":player_no"),
  69671. (assign, ":bot_count", reg0),
  69672.  
  69673. (try_begin),
  69674. #(gt, "$g_prison_cart_point", 0),
  69675. (gt, "$g_multiplayer_ccoop_enemy_respawn_secs", 31),
  69676.  
  69677. (assign, reg0, "$g_prison_cart_previous_point"),
  69678. (display_debug_message, "@{!}prison cart spawn at point {reg0}"),
  69679.  
  69680. (player_spawn_new_agent, ":player_no", "$g_prison_cart_previous_point"),
  69681. (call_script, "script_multiplayer_spawn_player_bot_squad_at_point", ":player_no", ":player_team", "$g_prison_cart_previous_point"),
  69682. (else_try),
  69683. (try_begin),
  69684. (gt, ":bot_count", 0),
  69685. (call_script, "script_multiplayer_get_spawn_point_close_to_bots", ":player_no"),
  69686. (player_spawn_new_agent, ":player_no", reg0),
  69687.  
  69688. # spawn requested bots
  69689. (call_script, "script_multiplayer_get_spawn_point_close_to_bots", ":player_no"),
  69690. (call_script, "script_multiplayer_spawn_player_bot_squad_at_point", ":player_no", ":player_team", reg0),
  69691. (else_try),
  69692. (call_script, "script_multiplayer_find_spawn_point", ":player_team", 1, ":is_horseman"),
  69693. (assign, ":point_no", reg0),
  69694. (player_spawn_new_agent, ":player_no", ":point_no"),
  69695. (call_script, "script_multiplayer_spawn_player_bot_squad_at_point", ":player_no", ":player_team", ":point_no"),
  69696. (end_try),
  69697. (end_try),
  69698.  
  69699. (try_begin),
  69700. (player_get_slot, ":player_first_spawn", ":player_no", slot_player_first_spawn),
  69701. (gt, ":player_first_spawn", 0),
  69702. #(player_set_slot, ":player_no", slot_player_join_time, ":player_join_time"),
  69703. (player_set_slot, ":player_no", slot_player_first_spawn, 0),
  69704. (try_end),
  69705.  
  69706. (assign, reg0, 1), # player spawned
  69707. (else_try),
  69708. (assign, reg0, 0), # player not spawned
  69709. (end_try),
  69710. ]),
  69711.  
  69712. # script_multiplayer_set_g_multiplayer_is_game_type_captain
  69713. # Input: none
  69714. # Output: none
  69715. ("multiplayer_set_g_multiplayer_is_game_type_captain",
  69716. [
  69717. (try_begin),
  69718. (eq, "$g_multiplayer_game_type", multiplayer_game_type_captain_coop),
  69719. (assign, "$g_multiplayer_is_game_type_captain", 1),
  69720. (else_try),
  69721. (assign, "$g_multiplayer_is_game_type_captain", 0),
  69722. (try_end),
  69723. ]),
  69724.  
  69725.  
  69726. # script_cf_multiplayer_can_buy_squad
  69727. # Input: none
  69728. # Output: reg0:can buy squad
  69729. ("cf_multiplayer_can_buy_squad",
  69730. [
  69731. (assign, ":can_buy_squad", 0),
  69732. (try_begin),
  69733. (eq, "$g_multiplayer_is_game_type_captain", 1),
  69734. (assign, ":can_buy_squad", 1),
  69735. (try_end),
  69736. # disable squad buying for second team
  69737. # (try_begin),
  69738. # (eq, ":can_buy_squad", 1),
  69739. # (eq, "$g_multiplayer_game_type", multiplayer_game_type_captain_battle),
  69740. # (multiplayer_get_my_team, ":my_team"),
  69741. # (eq, ":my_team", 1),
  69742. # (assign, ":can_buy_squad", 0),
  69743. # (try_end),
  69744. (eq, ":can_buy_squad", 1),
  69745. ]),
  69746.  
  69747. # script_avarage_of_two_points
  69748. # Input: pos1, pos2
  69749. # Output: pos1
  69750. ("avarage_of_two_points",
  69751. [
  69752. (position_get_x, ":x_pos1", pos1),
  69753. (position_get_x, ":x_pos2", pos2),
  69754. (val_add, ":x_pos1", ":x_pos2"),
  69755. (val_div, ":x_pos1", 2),
  69756. (position_set_x, pos1, ":x_pos1"),
  69757.  
  69758. (position_get_y, ":y_pos1", pos1),
  69759. (position_get_y, ":y_pos2", pos2),
  69760. (val_add, ":y_pos1", ":y_pos2"),
  69761. (val_div, ":y_pos1", 2),
  69762. (position_set_y, pos1, ":y_pos1"),
  69763.  
  69764. (position_get_z, ":z_pos1", pos1),
  69765. (position_get_z, ":z_pos2", pos2),
  69766. (val_add, ":z_pos1", ":z_pos2"),
  69767. (val_div, ":z_pos1", 2),
  69768. (position_set_z, pos1, ":z_pos1"),
  69769. ]),
  69770.  
  69771. # script_multiplayer_ccoop_start_player_and_squad_respawn_period
  69772. # INPUT: arg1 = spawn_alive_player_squad
  69773. # OUTPUT: none
  69774. ("multiplayer_ccoop_start_player_and_squad_respawn_period",
  69775. [
  69776. (try_begin),
  69777. (multiplayer_is_server),
  69778. #(neq, "$g_multiplayer_ccoop_wave_no", 1),
  69779.  
  69780. (store_script_param, "$g_multiplayer_ccoop_spawn_alive_player_squad_and_minus_one_first_spawn_slots_and_minus_one_first_spawn_slots", 1),
  69781.  
  69782. # reset first spawn slot
  69783. (get_max_players, ":max_players"),
  69784. (try_for_range, ":player_no", 0, ":max_players"),
  69785. (player_is_active, ":player_no"),
  69786. #(neg|player_slot_eq, ":player_no", slot_player_first_spawn, -1),
  69787. (try_begin),
  69788. (eq, "$g_multiplayer_ccoop_spawn_alive_player_squad_and_minus_one_first_spawn_slots_and_minus_one_first_spawn_slots", 1),
  69789. (player_set_slot, ":player_no", slot_player_first_spawn, 1),
  69790. (else_try),
  69791. (player_get_slot, ":player_first_spawn", ":player_no", slot_player_first_spawn),
  69792. (ge, ":player_first_spawn", 0),
  69793. (player_set_slot, ":player_no", slot_player_first_spawn, 1),
  69794. (try_end),
  69795. #(multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_other_events, multiplayer_event_other_event_ccoop_lock_companions, 1),
  69796. (try_end),
  69797.  
  69798. # start player&squad spawn period
  69799. (assign, "$g_multiplayer_ccoop_spawn_player_and_squad_counter", 30),
  69800. (try_end),
  69801. ]),
  69802.  
  69803.  
  69804.  
  69805. # script_multiplayer_upgrade_player_equipment
  69806. # INPUT: arg1 = player_no
  69807. # OUTPUT: none
  69808. ("multiplayer_upgrade_player_equipment",
  69809. [
  69810. (store_script_param, ":player_no", 1),
  69811.  
  69812. (assign, reg0, ":player_no"),
  69813. (display_debug_message, "@{!}multiplayer_upgrade_player_equipment: {reg0}"),
  69814.  
  69815. (player_get_troop_id, ":player_troop", ":player_no"),
  69816. (player_get_agent_id, ":player_agent", ":player_no"),
  69817. (player_get_gold, ":player_gold", ":player_no"),
  69818. (try_for_range, ":cur_item_slot", 0, ek_horse), # don't include horse
  69819. (store_add, ":cur_player_slot", ":cur_item_slot", slot_player_cur_selected_item_indices_begin),
  69820. (store_add, ":cur_player_slot_i", ":cur_item_slot", slot_player_selected_item_indices_begin),
  69821. (player_get_slot, ":cur_player_slot_i_item", ":player_no", ":cur_player_slot_i"),
  69822. (agent_get_item_slot, ":agent_item", ":player_agent", ":cur_item_slot"),
  69823. (try_begin),
  69824. (this_or_next|lt, ":cur_player_slot_i_item", 0),
  69825. (this_or_next|is_between, ":agent_item", coop_drops_begin, coop_new_items_end),
  69826. (player_item_slot_is_picked_up, ":player_no", ":cur_item_slot"),
  69827. (player_set_slot, ":player_no", ":cur_player_slot", -1),
  69828. #(str_store_item_name, s0, ":agent_item"),
  69829. #(display_message, "@setting {s0} as null"),
  69830. (else_try),
  69831. #(agent_get_item_slot, ":agent_item", ":player_agent", ":cur_item_slot"),
  69832. (player_set_slot, ":player_no", ":cur_player_slot", ":agent_item"),
  69833. (try_end),
  69834.  
  69835. (try_end),
  69836. (player_set_slot, ":player_no", slot_player_cur_selected_item_indices_begin + 8, -1), # mark horse as -1
  69837. (call_script, "script_multiplayer_calculate_cur_selected_items_cost", ":player_no", 0),
  69838. (assign, ":added_gold", reg0),
  69839. #(display_message, "@gold to add: {reg0}"),
  69840. (val_add, ":player_gold", ":added_gold"),
  69841.  
  69842. (try_for_range, ":i_item", slot_player_selected_item_indices_begin, slot_player_selected_item_indices_end),
  69843. (player_get_slot, ":selected_item_index", ":player_no", ":i_item"),
  69844. (store_sub, ":i_cur_selected_item", ":i_item", slot_player_selected_item_indices_begin),
  69845. (agent_get_item_slot, ":agent_item", ":player_agent", ":i_cur_selected_item"),
  69846. (try_begin),
  69847. (this_or_next|lt, ":selected_item_index", 0),
  69848. (this_or_next|player_item_slot_is_picked_up, ":player_no", ":i_cur_selected_item"),
  69849. (this_or_next|is_between, ":agent_item", coop_drops_begin, coop_new_items_end),
  69850. (eq, ":i_cur_selected_item", ek_horse), # remove horse selection for this special case
  69851. (assign, ":selected_item_index", -1),
  69852. (try_end),
  69853. (val_add, ":i_cur_selected_item", slot_player_cur_selected_item_indices_begin),
  69854. (player_set_slot, ":player_no", ":i_cur_selected_item", ":selected_item_index"),
  69855. (try_end),
  69856. (assign, ":end_cond", 1000),
  69857.  
  69858.  
  69859. (try_for_range, ":unused", 0, ":end_cond"),
  69860. (call_script, "script_multiplayer_calculate_cur_selected_items_cost", ":player_no", 0),
  69861. (assign, ":total_cost", reg0),
  69862. (try_begin),
  69863. (gt, ":total_cost", ":player_gold"),
  69864. #downgrade one of the selected items
  69865. #first normalize the prices
  69866. #then prioritize some of the weapon classes for specific troop classes
  69867. (call_script, "script_multiplayer_get_troop_class", ":player_troop"),
  69868. (assign, ":player_troop_class", reg0),
  69869.  
  69870. (assign, ":max_cost_value", 0),
  69871. (assign, ":max_cost_value_index", -1),
  69872. (try_for_range, ":i_item", slot_player_cur_selected_item_indices_begin, slot_player_cur_selected_item_indices_end),
  69873. (player_get_slot, ":item_id", ":player_no", ":i_item"),
  69874. (ge, ":item_id", 0), #might be -1 for horses etc.
  69875. (call_script, "script_multiplayer_get_item_value_for_troop", ":item_id", ":player_troop"),
  69876. (assign, ":item_value", reg0),
  69877. (store_sub, ":item_type", ":i_item", slot_player_cur_selected_item_indices_begin),
  69878. (try_begin), #items
  69879. (this_or_next|eq, ":item_type", 0),
  69880. (this_or_next|eq, ":item_type", 1),
  69881. (this_or_next|eq, ":item_type", 2),
  69882. (eq, ":item_type", 3),
  69883. (val_mul, ":item_value", 5),
  69884. (else_try), #head
  69885. (eq, ":item_type", 4),
  69886. (val_mul, ":item_value", 4),
  69887. (else_try), #body
  69888. (eq, ":item_type", 5),
  69889. (val_mul, ":item_value", 2),
  69890. (else_try), #foot
  69891. (eq, ":item_type", 6),
  69892. (val_mul, ":item_value", 8),
  69893. (else_try), #gloves
  69894. (eq, ":item_type", 7),
  69895. (val_mul, ":item_value", 8),
  69896. (else_try), #horse
  69897. #base value (most expensive)
  69898. (try_end),
  69899. (item_get_slot, ":item_class", ":item_id", slot_item_multiplayer_item_class),
  69900. (try_begin),
  69901. (eq, ":player_troop_class", multi_troop_class_infantry),
  69902. (this_or_next|eq, ":item_class", multi_item_class_type_sword),
  69903. (this_or_next|eq, ":item_class", multi_item_class_type_axe),
  69904. (this_or_next|eq, ":item_class", multi_item_class_type_blunt),
  69905. (this_or_next|eq, ":item_class", multi_item_class_type_war_picks),
  69906. (this_or_next|eq, ":item_class", multi_item_class_type_two_handed_sword),
  69907. (this_or_next|eq, ":item_class", multi_item_class_type_small_shield),
  69908. (eq, ":item_class", multi_item_class_type_two_handed_axe),
  69909. (val_div, ":item_value", 2),
  69910. (else_try),
  69911. (eq, ":player_troop_class", multi_troop_class_spearman),
  69912. (this_or_next|eq, ":item_class", multi_item_class_type_spear),
  69913. (eq, ":item_class", multi_item_class_type_large_shield),
  69914. (val_div, ":item_value", 2),
  69915. (else_try),
  69916. (eq, ":player_troop_class", multi_troop_class_cavalry),
  69917. (this_or_next|eq, ":item_class", multi_item_class_type_lance),
  69918. (this_or_next|eq, ":item_class", multi_item_class_type_sword),
  69919. (eq, ":item_class", multi_item_class_type_horse),
  69920. (val_div, ":item_value", 2),
  69921. (else_try),
  69922. (eq, ":player_troop_class", multi_troop_class_archer),
  69923. (this_or_next|eq, ":item_class", multi_item_class_type_bow),
  69924. (eq, ":item_class", multi_item_class_type_arrow),
  69925. (val_div, ":item_value", 2),
  69926. (else_try),
  69927. (eq, ":player_troop_class", multi_troop_class_crossbowman),
  69928. (this_or_next|eq, ":item_class", multi_item_class_type_crossbow),
  69929. (eq, ":item_class", multi_item_class_type_bolt),
  69930. (val_div, ":item_value", 2),
  69931. (else_try),
  69932. (eq, ":player_troop_class", multi_troop_class_mounted_archer),
  69933. (this_or_next|eq, ":item_class", multi_item_class_type_bow),
  69934. (this_or_next|eq, ":item_class", multi_item_class_type_arrow),
  69935. (eq, ":item_class", multi_item_class_type_horse),
  69936. (val_div, ":item_value", 2),
  69937. (else_try),
  69938. (eq, ":player_troop_class", multi_troop_class_mounted_crossbowman),
  69939. (this_or_next|eq, ":item_class", multi_item_class_type_crossbow),
  69940. (this_or_next|eq, ":item_class", multi_item_class_type_bolt),
  69941. (eq, ":item_class", multi_item_class_type_horse),
  69942. (val_div, ":item_value", 2),
  69943. (try_end),
  69944.  
  69945. (try_begin),
  69946. (gt, ":item_value", ":max_cost_value"),
  69947. (assign, ":max_cost_value", ":item_value"),
  69948. (assign, ":max_cost_value_index", ":i_item"),
  69949. (try_end),
  69950. (try_end),
  69951.  
  69952. #max_cost_value and max_cost_value_index will definitely be valid
  69953. #unless no items are left (therefore some items must cost 0 gold)
  69954. (player_get_slot, ":item_id", ":player_no", ":max_cost_value_index"),
  69955. (call_script, "script_multiplayer_get_previous_item_for_item_and_troop", ":item_id", ":player_troop"),
  69956. (assign, ":item_id", reg0),
  69957. (player_set_slot, ":player_no", ":max_cost_value_index", ":item_id"),
  69958. (else_try),
  69959.  
  69960. (assign, ":end_cond", 0),
  69961. (assign, ":total_cost", reg0),
  69962. #(display_message, "@total_cost: {reg0}"),
  69963. (val_sub, ":player_gold", ":total_cost"),
  69964. (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
  69965. (try_for_range, ":i_item", slot_player_cur_selected_item_indices_begin, slot_player_cur_selected_item_indices_end),
  69966. (player_get_slot, ":item_id", ":player_no", ":i_item"),
  69967.  
  69968.  
  69969. # add the item to agent
  69970. (try_begin),
  69971. (ge, ":item_id", 0),
  69972.  
  69973. (store_sub, ":item_slot", ":i_item", slot_player_cur_selected_item_indices_begin),
  69974. #(store_add, ":i_actual_selected_item", ":item_slot", slot_player_selected_item_indices_begin),
  69975. #(player_slot_ge, ":player_no", ":i_actual_selected_item", 0),
  69976. (agent_get_item_slot, ":agent_item", ":player_agent", ":item_slot"),
  69977. (neq, ":agent_item", ":item_id"),
  69978.  
  69979. (neg|is_between, ":agent_item", coop_drops_begin, coop_new_items_end),
  69980.  
  69981. (get_max_players, ":num_players"),
  69982. (try_begin),
  69983. (ge, ":agent_item", 0),
  69984.  
  69985. (agent_unequip_item, ":player_agent", ":agent_item", ":item_slot"),
  69986.  
  69987. (try_for_range, ":cur_player", 1, ":num_players"),
  69988. (player_is_active, ":cur_player"),
  69989. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_unequip_item,
  69990. ":player_agent", ":agent_item", ":item_slot"),
  69991. (try_end),
  69992. (try_end),
  69993. (agent_equip_item, ":player_agent", ":item_id"),
  69994.  
  69995. (try_for_range, ":cur_player", 1, ":num_players"),
  69996. (player_is_active, ":cur_player"),
  69997. (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
  69998. ":player_agent", ":item_id"),
  69999. (try_end),
  70000.  
  70001. (try_end),
  70002. (try_end),
  70003. (player_set_slot, ":player_no", slot_player_total_equipment_value, ":total_cost"),
  70004. (try_end),
  70005. (try_end),
  70006. ]),
  70007.  
  70008. # script_cf_multiplayer_upgrade_companion_equipment
  70009. # INPUT: arg1 = agent_no
  70010. # OUTPUT: none
  70011. ("cf_multiplayer_upgrade_companion_equipment",
  70012. [
  70013. (store_script_param, ":agent_no", 1),
  70014. #(agent_is_human, ":agent_no"),
  70015. #(agent_is_alive, ":agent_no"),
  70016. #(agent_is_non_player, ":agent_no"),
  70017. #(agent_get_team, ":team_no", ":agent_no"),
  70018.  
  70019. (agent_get_group, ":agent_group", ":agent_no"),
  70020. (player_is_active, ":agent_group"),
  70021. (agent_get_troop_id, ":troop_no", ":agent_no"),
  70022.  
  70023. #(assign, reg0, ":troop_no"),
  70024. #(display_message, "@troop no: {reg0}"),
  70025.  
  70026. (assign, ":matching_companion_found", 0),
  70027.  
  70028. (try_for_range, ":cur_slot", slot_player_companion_ids_begin, slot_player_companion_ids_end),
  70029. (player_get_slot, ":companion_no", ":agent_group", ":cur_slot"),
  70030. (eq, ":troop_no", ":companion_no"),
  70031. (assign, ":matching_companion_found", 1),
  70032. #(display_message, "@pass"),
  70033. (val_sub, ":cur_slot", slot_player_companion_ids_begin),
  70034. (val_add, ":cur_slot", slot_player_companion_levels_begin),
  70035. (player_get_slot, ":companion_level", ":agent_group", ":cur_slot"),
  70036. (val_sub, ":cur_slot", slot_player_companion_levels_begin),
  70037. (val_add, ":cur_slot", slot_player_companion_classes_begin),
  70038. (player_get_slot, ":companion_template", ":agent_group", ":cur_slot"),
  70039. (try_end),
  70040.  
  70041. #(try_begin),
  70042. # (ge, ":companion_template", 0),
  70043. # (str_store_troop_name, s0, ":companion_template"),
  70044. # (multiplayer_send_string_to_player, ":agent_group", multiplayer_event_show_server_message, "@{!}companion template identified as {s0}"),
  70045. #(try_end),
  70046.  
  70047. (eq, ":matching_companion_found", 1),
  70048.  
  70049. (try_begin),
  70050. (is_between, ":companion_template", multiplayer_coop_class_templates_begin, multiplayer_coop_class_templates_end),
  70051. (assign, ":multiplier", 18),
  70052. (else_try),
  70053. (assign, ":multiplier", 16),
  70054. (try_end),
  70055.  
  70056. (try_begin),
  70057. (lt, ":companion_level", 3),
  70058. (store_mul, ":template_leveler", ":companion_level", ":multiplier"),
  70059. (val_add, ":companion_template", ":template_leveler"),
  70060. (else_try),
  70061. (store_mul, ":template_leveler", 3, ":multiplier"), #4 is max level
  70062. (val_add, ":companion_template", ":template_leveler"),
  70063. (try_end),
  70064.  
  70065. #(try_begin),
  70066. # (ge, ":companion_template", 0),
  70067. # (str_store_troop_name, s0, ":companion_template"),
  70068. # (multiplayer_send_string_to_player, ":agent_group", multiplayer_event_show_server_message, "@{!}companion template multiplied to {s0}"),
  70069. #(try_end),
  70070.  
  70071. #(assign, reg0, ":companion_template"),
  70072. #(display_message, "@companion template: {reg0}"),
  70073.  
  70074. (assign, ":has_special_melee", 0),
  70075. (assign, ":has_special_ranged", 0),
  70076. #(eq, ":team_no", 0),
  70077.  
  70078. (troop_equip_items, ":companion_template"),
  70079. (get_max_players, ":num_players"),
  70080.  
  70081. (try_for_range, ":cur_slot", 0, 4),
  70082. (agent_get_item_slot, ":item_id", ":agent_no", ":cur_slot"),
  70083. (ge, ":item_id", 0),
  70084. (try_begin),
  70085. (is_between, ":item_id", coop_drops_begin, coop_new_items_end),
  70086. #(assign, reg0, ":agent_no"),
  70087. #(assign, reg1, ":cur_slot"),
  70088. #(assign, reg2, ":item_id"),
  70089. #(display_message, "@special item on companion! agent: {reg0} slot: {reg1} item: {reg2}"),
  70090. (item_get_type, ":item_type", ":item_id"),
  70091. (try_begin),
  70092. (this_or_next|eq, ":item_type", itp_type_one_handed_wpn),
  70093. (this_or_next|eq, ":item_type", itp_type_two_handed_wpn),
  70094. (eq, ":item_type", itp_type_polearm),
  70095. (assign, ":has_special_melee", 1),
  70096. (else_try),
  70097. (this_or_next|eq, ":item_type", itp_type_bow),
  70098. (this_or_next|eq, ":item_type", itp_type_crossbow),
  70099. (eq, ":item_type", itp_type_thrown),
  70100. (assign, ":has_special_ranged", 1),
  70101. (try_end),
  70102. (else_try),
  70103. (agent_unequip_item, ":agent_no", ":item_id", ":cur_slot"),
  70104. (try_for_range, ":cur_player", 1, ":num_players"),
  70105. (player_is_active, ":cur_player"),
  70106. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_unequip_item,
  70107. ":agent_no", ":item_id", ":cur_slot"),
  70108. (try_end),
  70109. (try_end),
  70110. (try_end),
  70111.  
  70112. (try_for_range, ":cur_slot", 0, 9),
  70113. #(ge, ":item_id", 0),
  70114.  
  70115. (troop_get_inventory_slot, ":cur_item", ":companion_template", ":cur_slot"),
  70116. #(assign, reg0, ":cur_item"),
  70117. #(display_message, "@item from template {reg0}"),
  70118. (gt, ":cur_item", 0),
  70119. #(str_store_item_name, s0, ":cur_item"),
  70120. #(multiplayer_send_string_to_player, ":agent_group", multiplayer_event_show_server_message, "@{!}companion template has item {s0}"),
  70121. (item_get_type, ":cur_item_type", ":cur_item"),
  70122. (try_begin),
  70123. (is_between, ":cur_item_type", itp_type_head_armor, itp_type_pistol),
  70124. (assign, ":found_matching_armor_piece", 0),
  70125. (try_for_range, ":cur_equipped_slot", 4, 8),
  70126. (agent_get_item_slot, ":cur_item_equipped", ":agent_no", ":cur_equipped_slot"),
  70127. (ge, ":cur_item_equipped", 0),
  70128. (item_get_type, ":cur_item_equipped_type", ":cur_item_equipped"),
  70129. (eq, ":cur_item_type", ":cur_item_equipped_type"),
  70130. #(str_store_item_name, s1, ":cur_item_equipped"),
  70131. (assign, ":found_matching_armor_piece", 1),
  70132. (neq, ":cur_item_equipped", ":cur_item"),
  70133. #(multiplayer_send_string_to_player, ":agent_group", multiplayer_event_show_server_message, "@{!}found matching armour piece {s1}"),
  70134. #(display_message, "@found_matching_armor_piece"),
  70135. (neg|is_between, ":cur_item_equipped", coop_drops_begin, coop_new_items_end),
  70136. (agent_unequip_item, ":agent_no", ":cur_item_equipped", ":cur_equipped_slot"),
  70137. (try_for_range, ":cur_player", 1, ":num_players"),
  70138. (player_is_active, ":cur_player"),
  70139. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_unequip_item,
  70140. ":agent_no", ":cur_item_equipped", ":cur_equipped_slot"),
  70141. (try_end),
  70142. (agent_equip_item, ":agent_no", ":cur_item"),
  70143. #(multiplayer_send_string_to_player, ":agent_group", multiplayer_event_show_server_message, "@{!}equipping {s0}"),
  70144. (try_for_range, ":cur_player", 1, ":num_players"),
  70145. (player_is_active, ":cur_player"),
  70146. (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
  70147. ":agent_no", ":cur_item"),
  70148. (try_end),
  70149. (try_end),
  70150. (try_begin),
  70151. (eq, ":found_matching_armor_piece", 0),
  70152. (agent_equip_item, ":agent_no", ":cur_item"),
  70153. (try_for_range, ":cur_player", 1, ":num_players"),
  70154. (player_is_active, ":cur_player"),
  70155. (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
  70156. ":agent_no", ":cur_item"),
  70157. (try_end),
  70158. (try_end),
  70159. (else_try),
  70160. (assign, ":equip_cur_item", 0),
  70161. (try_begin),
  70162. (this_or_next|eq, ":cur_item_type", itp_type_one_handed_wpn),
  70163. (this_or_next|eq, ":cur_item_type", itp_type_two_handed_wpn),
  70164. (this_or_next|eq, ":cur_item_type", itp_type_shield),
  70165. (eq, ":cur_item_type", itp_type_polearm),
  70166. (eq, ":has_special_melee", 0),
  70167. (assign, ":equip_cur_item", 1),
  70168. (else_try),
  70169. (this_or_next|eq, ":cur_item_type", itp_type_bow),
  70170. (this_or_next|eq, ":cur_item_type", itp_type_crossbow),
  70171. (this_or_next|eq, ":cur_item_type", itp_type_thrown),
  70172. (this_or_next|eq, ":cur_item_type", itp_type_bolts),
  70173. (eq, ":cur_item_type", itp_type_arrows),
  70174. (eq, ":has_special_ranged", 0),
  70175. (assign, ":equip_cur_item", 1),
  70176. (try_end),
  70177. (eq, ":equip_cur_item", 1),
  70178. #(multiplayer_send_string_to_player, ":agent_group", multiplayer_event_show_server_message, "@{!}equipping {s0}"),
  70179. (agent_equip_item, ":agent_no", ":cur_item"),
  70180. (try_for_range, ":cur_player", 1, ":num_players"),
  70181. (player_is_active, ":cur_player"),
  70182. (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
  70183. ":agent_no", ":cur_item"),
  70184. (try_end),
  70185. #(try_end),
  70186. (try_end),
  70187. (try_end),
  70188.  
  70189. ]),
  70190.  
  70191.  
  70192.  
  70193.  
  70194.  
  70195. #script_mp_spawn_coop_companion
  70196. ("mp_spawn_coop_companion", #this code is to make sure that companions spawn with or without their horse depending on their class/map
  70197. [
  70198. (store_script_param, ":player_no", 1),
  70199. (store_script_param, ":troop_no", 2),
  70200. (store_script_param, ":slot_no", 3),
  70201. (store_script_param, ":player_team", 4),
  70202. (store_script_param, ":point_no", 5),
  70203.  
  70204. (troop_equip_items, ":troop_no"),
  70205.  
  70206.  
  70207. (val_add, ":slot_no", 2),
  70208. (player_get_slot, ":class_id", ":player_no", ":slot_no"),
  70209.  
  70210. (assign, ":has_horse", 0),
  70211.  
  70212. (try_for_range, ":cur_slot", 0, 9), #check if the class they are spawning as is mounted (default classes/personal equipment always has a horse)
  70213. (eq, ":has_horse", 0),
  70214. (troop_get_inventory_slot, ":cur_item", ":class_id", ":cur_slot"),
  70215. (gt, ":cur_item", 0),
  70216. (item_get_type, ":cur_item_type", ":cur_item"),
  70217. (eq, ":cur_item_type", itp_type_horse),
  70218. (assign, ":has_horse", 1), #found a horse!
  70219. (try_end),
  70220.  
  70221. (store_current_scene, ":cur_scene"),
  70222. (scene_get_slot, ":scene_disallow_horses", ":cur_scene", slot_scene_ccoop_disallow_horses), #this is set as 1 for all maps that should be played without horses
  70223.  
  70224. (try_for_range, ":cur_slot", 0, 9),
  70225. (troop_get_inventory_slot, ":cur_item", ":troop_no", ":cur_slot"),
  70226. (ge, ":cur_item", 0),
  70227. (item_get_type, ":cur_item_type", ":cur_item"),
  70228. (troop_remove_item, ":troop_no", ":cur_item"),
  70229. (try_begin),
  70230. (eq, ":cur_item_type", itp_type_horse),
  70231. (troop_set_slot, ":troop_no", slot_troop_coop_lord_spawned, ":cur_item"),
  70232. (else_try),
  70233. (val_add, ":cur_slot", multi_data_equipment_holder_begin),
  70234. (troop_set_slot, "trp_multiplayer_data", ":cur_slot", ":cur_item"),
  70235. (try_end),
  70236. (try_end),
  70237.  
  70238. (troop_clear_inventory, ":troop_no"),
  70239.  
  70240. (try_for_range, ":cur_slot", multi_data_equipment_holder_begin, multi_data_equipment_holder_end),
  70241. (troop_get_slot, ":cur_item", "trp_multiplayer_data", ":cur_slot"),
  70242. (gt, ":cur_item", 0),
  70243. (troop_add_item, ":troop_no", ":cur_item"),
  70244. (try_end),
  70245.  
  70246. (try_begin),
  70247. (eq, ":scene_disallow_horses", 0),
  70248. (eq, ":has_horse", 1),
  70249. (troop_get_slot, ":horse_no", ":troop_no", slot_troop_coop_lord_spawned),
  70250. (troop_add_item, ":troop_no", ":horse_no"),
  70251. (troop_set_slot, ":troop_no", slot_troop_coop_lord_spawned, -1),
  70252. (try_end),
  70253.  
  70254. (troop_equip_items, ":troop_no"),
  70255.  
  70256. (modify_visitors_at_site, ":cur_scene"),
  70257. (add_visitors_to_current_scene, ":point_no", ":troop_no", 1, ":player_team", ":player_no"),
  70258.  
  70259.  
  70260.  
  70261. ]),
  70262.  
  70263. #script_coop_generate_item_drop
  70264. # INPUT: none
  70265. # OUTPUT: reg0 = item_id
  70266. ("coop_generate_item_drop",
  70267. [
  70268. (store_script_param, ":player_id", 1),
  70269. #(store_script_param, ":instance_id", 1),
  70270. #(store_script_param, ":user_id", 2),
  70271.  
  70272. (store_random_in_range, "$g_ccoop_currently_dropping_item", coop_drops_begin, coop_drops_end), #change this to add variation to the items that drop - any item should work! The description will be hidden for regular items
  70273. #(assign, "$g_ccoop_currently_dropping_item", "itm_javelin_bow"), ##DEBUG - makes chests always drop the same item - useful for testing!
  70274. (player_set_slot, ":player_id", slot_player_coop_dropped_item, "$g_ccoop_currently_dropping_item"), #we hold the item in a slot, server-side, to prevent funny business!
  70275. #(assign, reg0, ":dropped_item"),
  70276.  
  70277.  
  70278. ]),
  70279.  
  70280. #script_coop_drop_item
  70281. # INPUT: arg1 = item_id
  70282. # OUTPUT: none
  70283. ("coop_drop_item",
  70284. [
  70285. (store_script_param, reg0, 1),
  70286. (store_script_param, reg1, 2),
  70287. (store_script_param, reg2, 3),
  70288.  
  70289. #script simply starts the presentation but could have extra features added
  70290.  
  70291. (start_presentation, "prsnt_coop_assign_drop_to_group_member"),
  70292.  
  70293.  
  70294. ]),
  70295.  
  70296. #try brackets for this need to be checked and rearranged
  70297. #script_cf_coop_give_item_to_assigned_group_member
  70298. # INPUT: arg1 = item_id, arg2 = item_id
  70299. # OUTPUT: none
  70300. ("cf_coop_give_item_to_assigned_group_member",
  70301. [
  70302. (store_script_param, ":player_no", 1),
  70303. (store_script_param, ":assigned_agent_id", 2),
  70304. (player_is_active, ":player_no"),
  70305.  
  70306. (assign, ":cancel_drop", 0), #script can be awkward because it relies on data sent by clients!
  70307.  
  70308.  
  70309.  
  70310.  
  70311.  
  70312. (assign, ":total_to_be_equipped", 0), #we need to check how many weapon slots the player is using and drop the item if there isn't enough space
  70313.  
  70314. (player_get_slot, ":item_id", ":player_no", slot_player_coop_dropped_item),
  70315. (ge, ":item_id", 0), #we should also make sure that the item is real - this is kept server side but bad code can change slots accidentally! ehem...
  70316.  
  70317. (try_begin),
  70318. (eq, ":assigned_agent_id", 0), #this is sent as 0, when the client wants to equip the item to their own character - behaviour for players and companions is different
  70319. (player_get_agent_id, ":assigned_agent_id", ":player_no"), #but we need the agent id anyway...
  70320. (assign, ":group_id", ":player_no"),
  70321. (try_begin),
  70322. (agent_is_active, ":assigned_agent_id"),
  70323. (agent_is_alive, ":assigned_agent_id"), #let's make sure they didn't die at a bad time!
  70324. (assign, ":num_equipped_weapons", 0),
  70325. (item_get_slot, ":item_has_ammo", ":item_id", slot_item_ccoop_has_ammo), #javelin bow needs two slots (one for ammo) - if the player doesn't have room for both, we just drop everything
  70326. (val_add, ":item_has_ammo", 1), #we use this variable but a better name would be something like ":wep_slots_required" - all weapons need at least one
  70327. (try_for_range, ":cur_slot", 0, 4),
  70328. (agent_get_item_slot, ":cur_item", ":assigned_agent_id", ":cur_slot"),
  70329. (ge, ":cur_item", 0),
  70330. (val_add, ":num_equipped_weapons", 1), #count how many weapon slots they are using
  70331. (try_end),
  70332. (try_begin),
  70333. (item_get_type, ":item_type", ":item_id"),
  70334. (ge, ":item_type", itp_type_head_armor),
  70335. (assign, ":item_has_ammo", 0), #armours always overwrite the existing item
  70336. (try_end),
  70337.  
  70338. (store_add, ":total_to_be_equipped", ":num_equipped_weapons", ":item_has_ammo"), #save the total weapon slots that would be required if we equipped this weapon
  70339. (else_try),
  70340. (assign, ":cancel_drop", 1),
  70341. (player_set_slot, ":player_no", slot_player_coop_dropped_item, -1),
  70342. (try_end),
  70343. (else_try),
  70344. (agent_is_active, ":assigned_agent_id"), #if the assignee isn't the player, let's make sure it's a real agent anyway
  70345. (agent_is_alive, ":assigned_agent_id"),
  70346. (agent_is_human, ":assigned_agent_id"),
  70347. (agent_get_group, ":group_id", ":assigned_agent_id"), #we use this in a check below
  70348. (else_try), #fail script
  70349. (assign, ":cancel_drop", 1),
  70350. (player_set_slot, ":player_no", slot_player_coop_dropped_item, -1),
  70351. (try_end),
  70352.  
  70353. (eq, ":cancel_drop", 0),
  70354.  
  70355.  
  70356.  
  70357. (try_begin),
  70358. (gt, ":total_to_be_equipped", 4), #if we don't have room, the item falls to the floor... grab it, quick!
  70359. (assign, ":cancel_drop", 1),
  70360. (player_set_slot, ":player_no", slot_player_coop_dropped_item, -1), #keep this slot empty while players aren't assigning an item - otherwise a script could allow them to assign it later, which is cheating!
  70361. (agent_get_position, pos1, ":assigned_agent_id"),
  70362. (position_move_z, pos1, 20), #prevents the item from spawning in the ground... most of the time
  70363. (set_spawn_position, pos1),
  70364. (spawn_item, ":item_id"),
  70365. (str_store_string, s0, "str_ccoop_dropping_item_on_ground"),
  70366. (multiplayer_send_string_to_player, ":player_no", multiplayer_event_show_server_message, s0), #tell the player what's happened
  70367. (try_begin),
  70368. (eq, ":item_id", "itm_javelin_bow"),
  70369. (spawn_item, "itm_javelin_bow_ammo"), #and give them the ammo from the jav bow!
  70370. (try_end),
  70371. (try_end),
  70372.  
  70373. (eq, ":cancel_drop", 0), #are we still good?
  70374.  
  70375. (get_max_players, ":num_players"), #we'll be using this in our equipping events
  70376.  
  70377. (try_begin),
  70378. (eq, ":group_id", ":player_no"), #just in case a player tries to assign a drop to someone else's companion!
  70379.  
  70380. (player_is_active, ":group_id"), #let's not have an error in case they disconnected
  70381.  
  70382. (item_get_type, ":item_type", ":item_id"), #different behaviour for weapons/armour etc.
  70383.  
  70384. (try_begin), #for non players, remove existing weapons that are melee/ranged so they always only have one of each
  70385. (agent_is_non_player, ":assigned_agent_id"),
  70386.  
  70387.  
  70388. (try_begin),
  70389. (this_or_next|eq, ":item_type", itp_type_one_handed_wpn),
  70390. (this_or_next|eq, ":item_type", itp_type_two_handed_wpn),
  70391. (eq, ":item_type", itp_type_polearm),
  70392. (try_for_range, ":cur_slot", 0, 4),
  70393. (agent_get_item_slot, ":cur_item", ":assigned_agent_id", ":cur_slot"),
  70394. (ge, ":cur_item", 0),
  70395. (item_get_type, ":cur_item_type", ":cur_item"),
  70396. (this_or_next|eq, ":cur_item_type", itp_type_one_handed_wpn),
  70397. (this_or_next|eq, ":cur_item_type", itp_type_two_handed_wpn),
  70398. (this_or_next|eq, ":cur_item_type", itp_type_shield),
  70399. (eq, ":cur_item_type", itp_type_polearm),
  70400. (agent_unequip_item, ":assigned_agent_id", ":cur_item", ":cur_slot"),
  70401. (try_for_range, ":cur_player", 0, ":num_players"),
  70402. (player_is_active, ":cur_player"),
  70403. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_unequip_item,
  70404. ":assigned_agent_id", ":cur_item", ":cur_slot"),
  70405. (try_end),
  70406. (try_end),
  70407. (else_try),
  70408. (this_or_next|eq, ":item_type", itp_type_bow),
  70409. (this_or_next|eq, ":item_type", itp_type_crossbow),
  70410. (eq, ":item_type", itp_type_thrown),
  70411. (try_for_range, ":cur_slot", 0, 4),
  70412. (agent_get_item_slot, ":cur_item", ":assigned_agent_id", ":cur_slot"),
  70413. (ge, ":cur_item", 0),
  70414. (item_get_type, ":cur_item_type", ":cur_item"),
  70415. (this_or_next|eq, ":cur_item_type", itp_type_bow),
  70416. (this_or_next|eq, ":cur_item_type", itp_type_crossbow),
  70417. (this_or_next|eq, ":cur_item_type", itp_type_thrown),
  70418. (this_or_next|eq, ":cur_item_type", itp_type_bolts),
  70419. (eq, ":cur_item_type", itp_type_arrows),
  70420. (agent_unequip_item, ":assigned_agent_id", ":cur_item", ":cur_slot"),
  70421. (try_for_range, ":cur_player", 0, ":num_players"),
  70422. (player_is_active, ":cur_player"),
  70423. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_unequip_item,
  70424. ":assigned_agent_id", ":cur_item", ":cur_slot"),
  70425. (try_end),
  70426. (try_end),
  70427. (try_end),
  70428. (try_end),
  70429.  
  70430. ##should be set as script to be called with above network messages
  70431. (try_begin),
  70432. (is_between, ":item_type", itp_type_head_armor, itp_type_pistol), #for armours we always replace the existing item directly
  70433. (try_for_range, ":cur_slot", 4, 8),
  70434. (agent_get_item_slot, ":cur_item", ":assigned_agent_id", ":cur_slot"),
  70435. (ge, ":cur_item", 0),
  70436. (item_get_type, ":cur_item_type", ":cur_item"),
  70437. (eq, ":cur_item_type", ":item_type"),
  70438. (agent_unequip_item, ":assigned_agent_id", ":cur_item"),
  70439. (try_for_range, ":cur_player", 0, ":num_players"),
  70440. (player_is_active, ":cur_player"),
  70441. (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_unequip_item,
  70442. ":assigned_agent_id", ":cur_item", ":cur_slot"),
  70443. (try_end),
  70444. (try_begin), #and we shouldn't forget to remove their special effects!
  70445. (eq, ":cur_item", "itm_running_boots"),
  70446. (agent_set_speed_modifier, ":assigned_agent_id", 100),
  70447. (else_try),
  70448. (eq, ":cur_item", "itm_power_gloves"),
  70449. (agent_set_damage_modifier, ":assigned_agent_id", 100),
  70450. (end_try),
  70451. (try_end),
  70452. (try_end),
  70453.  
  70454. (agent_equip_item, ":assigned_agent_id", ":item_id"), #and now we're ready to equip the item
  70455. (try_for_range, ":cur_player", 0, ":num_players"),
  70456. (player_is_active, ":cur_player"),
  70457. (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
  70458. ":assigned_agent_id", ":item_id"),
  70459. (try_end),
  70460.  
  70461. #additional items and effects
  70462. (try_begin),
  70463. (eq, ":item_id", "itm_javelin_bow"),
  70464. (agent_equip_item, ":assigned_agent_id", "itm_javelin_bow_ammo"),
  70465. (try_for_range, ":cur_player", 0, ":num_players"),
  70466. (player_is_active, ":cur_player"),
  70467. (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
  70468. ":assigned_agent_id", "itm_javelin_bow_ammo"), #don't forget to add the ammo for the javelin bow!
  70469. (try_end),
  70470. (else_try),
  70471. (eq, ":item_id", "itm_running_boots"), #and add any new effects...
  70472. (agent_set_speed_modifier, ":assigned_agent_id", 150),
  70473. (else_try),
  70474. (eq, ":item_id", "itm_power_gloves"),
  70475. (agent_set_damage_modifier, ":assigned_agent_id", 150),
  70476. (else_try),
  70477. (eq, ":item_id", "itm_kicking_boots"),
  70478. (agent_is_non_player, ":assigned_agent_id"),
  70479. (agent_set_kick_allowed, ":assigned_agent_id", 1),
  70480. (try_end),
  70481. (try_end),
  70482.  
  70483. (player_set_slot, ":player_no", slot_player_coop_dropped_item, -1), #again, prevent players from trying to equip items when they shouldn't
  70484.  
  70485. ]),
  70486.  
  70487. #script_add_player_to_cur_tableau_for_coop
  70488. # INPUT: type
  70489. # OUTPUT: none
  70490. ("add_player_to_cur_tableau_for_coop", [ #we use this for the image of the player when assigning an item from a chest
  70491. #(store_script_param, ":troop_no", 1),
  70492. #(store_script_param, ":canvas_no", 2),
  70493. (cur_tableau_set_override_flags, af_override_everything),
  70494.  
  70495. (multiplayer_get_my_player, ":my_player_no"),
  70496.  
  70497. (assign, ":canvas_no", "trp_coop_companion_equipment_ui_0"),
  70498.  
  70499. (player_get_agent_id, ":my_agent_no", ":my_player_no"), #player is always alive so we just show their current equipment
  70500.  
  70501. (try_for_range, ":cur_inv_slot", 0, 8),
  70502. (agent_get_item_slot, ":cur_item", ":my_agent_no", ":cur_inv_slot"),
  70503. (ge, ":cur_item", 0),
  70504. (cur_tableau_add_override_item, ":cur_item"),
  70505. (try_end),
  70506.  
  70507.  
  70508. (try_begin),
  70509. (player_get_gender , ":is_female", ":my_player_no"),
  70510. (eq, ":is_female", 1),
  70511. (val_add, ":canvas_no", 1),
  70512. (try_end),
  70513.  
  70514. #(assign, reg0, ":canvas_no"),
  70515. #(display_message, "@canvas no: {reg0}"),
  70516.  
  70517. (str_store_player_face_keys, s0, ":my_player_no"),
  70518. (troop_set_face_keys, ":canvas_no", s0),
  70519.  
  70520. (store_mod, ":animation", ":my_agent_no", 4),
  70521.  
  70522. (val_add, ":animation", "anim_pose_1"),
  70523.  
  70524.  
  70525.  
  70526. (set_fixed_point_multiplier, 100),
  70527. (cur_tableau_set_camera_parameters, 1, 6, 6, 10, 10000),
  70528. (assign, ":cam_height", 145),
  70529. (assign, ":camera_distance", 350),
  70530. (assign, ":camera_pitch", 2),
  70531.  
  70532. (init_position, pos5),
  70533. (position_set_z, pos5, ":cam_height"),
  70534. # camera looks towards -z axis
  70535. (position_rotate_x, pos5, -90),
  70536. (position_rotate_z, pos5, 180),
  70537. # now apply yaw and pitch
  70538. (assign, ":camera_yaw", -50),
  70539. (position_move_x, pos5, -10, 0),
  70540. (position_rotate_y, pos5, ":camera_yaw"),
  70541. (position_rotate_x, pos5, ":camera_pitch"),
  70542. (position_move_z, pos5, ":camera_distance", 0),
  70543. (position_move_y, pos5, 60, 0),
  70544.  
  70545.  
  70546. (init_position, pos2),
  70547. (cur_tableau_add_troop, ":canvas_no", pos2, ":animation", 0),
  70548. (cur_tableau_set_camera_position, pos5),
  70549.  
  70550. (copy_position, pos8, pos5),
  70551. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  70552. (position_rotate_z, pos8, 30),
  70553. (position_rotate_x, pos8, -50),
  70554. (cur_tableau_add_sun_light, pos8, 175,150,125),
  70555. ]),
  70556.  
  70557. #script_add_troop_to_cur_tableau_for_coop
  70558. # INPUT: type
  70559. # OUTPUT: none
  70560. ("add_troop_to_cur_tableau_for_coop", [
  70561. (store_script_param, ":troop_no", 1),
  70562. #(store_script_param, ":canvas_no", 2),
  70563. (cur_tableau_set_override_flags, af_override_everything),
  70564.  
  70565. (multiplayer_get_my_player, ":my_player_no"),
  70566. (assign, ":companion_alive", 0),
  70567. (assign, ":canvas_no", "trp_coop_companion_equipment_ui_0"), #we use different troops for each companion... for simplicity
  70568. (try_for_agents, ":cur_agent"), #lets find the agent for our companion
  70569. (eq, ":companion_alive", 0),
  70570. (agent_is_active, ":cur_agent"), #living companions show their current equipment, while dead companions show what they're going to spawn with next
  70571. (agent_is_alive, ":cur_agent"),
  70572. (agent_is_non_player, ":cur_agent"),
  70573. (agent_get_troop_id, ":cur_troop_id", ":cur_agent"),
  70574. (eq, ":cur_troop_id", ":troop_no"),
  70575. (agent_get_group, ":cur_agent_group", ":cur_agent"),
  70576. (eq, ":cur_agent_group", ":my_player_no"),
  70577. (try_for_range, ":cur_slot", slot_player_companion_ids_begin, slot_player_companion_ids_end),
  70578. (player_slot_eq, ":my_player_no", ":cur_slot", ":cur_troop_id"),
  70579. (try_for_range, ":cur_inv_slot", 0, 8),
  70580. (agent_get_item_slot, ":cur_item", ":cur_agent", ":cur_inv_slot"),
  70581. (ge, ":cur_item", 0),
  70582. (cur_tableau_add_override_item, ":cur_item"),
  70583. (try_end),
  70584. (try_begin),
  70585. (gt, ":cur_slot", slot_player_companion_ids_begin),
  70586. (val_add, ":canvas_no", 2),
  70587. (try_end),
  70588. (try_end),
  70589. (assign, ":companion_alive", 1), #so we'll be using their current gear for the tableau
  70590. (try_end),
  70591.  
  70592. (try_begin),
  70593. (eq, ":companion_alive", 0), #for dead companions, we check their class and level to get the right template
  70594. (try_for_range, ":cur_slot", slot_player_companion_ids_begin, slot_player_companion_ids_end),
  70595. (player_slot_eq, ":my_player_no", ":cur_slot", ":troop_no"), #check which companion we're using (since this isn't sent as a parameter...)
  70596. (try_begin),
  70597. (gt, ":cur_slot", slot_player_companion_ids_begin),
  70598. (val_add, ":canvas_no", 2), #the second companion uses different troops
  70599. (try_end),
  70600. (val_add, ":cur_slot", 2),
  70601. (player_get_slot, ":template_no", ":my_player_no", ":cur_slot"), #get their class
  70602. (val_add, ":cur_slot", 2),
  70603. (player_get_slot, ":level_no", ":my_player_no", ":cur_slot"), #and upgrade it for their level
  70604. (try_begin),
  70605. (ge, ":template_no", "trp_npc1_1"), #companion class troops come after faction class troops
  70606. (val_mul, ":level_no", 16), #there are 16 at each level tier (one for each companion) so multiply by 16 to get to the right level
  70607. (val_add, ":template_no", ":level_no"),
  70608. (else_try),
  70609. (val_mul, ":level_no", 18), #18 at each level tier for faction classes (6 factions * 3 troops, one ranged, one melee, one cav)
  70610. (val_add, ":template_no", ":level_no"),
  70611. (try_end),
  70612. (try_for_range, ":cur_inv_slot", 0, 8),
  70613. (troop_get_inventory_slot, ":cur_item", ":template_no", ":cur_inv_slot"),
  70614. (ge, ":cur_item", 0),
  70615. (cur_tableau_add_override_item, ":cur_item"),
  70616. (try_end),
  70617. (try_end),
  70618. (try_end),
  70619.  
  70620. (try_begin),
  70621. (troop_get_type, ":is_female", ":troop_no"),
  70622. (eq, ":is_female", 1),
  70623. (val_add, ":canvas_no", 1), #the female blank canvas troop is directly after the male for each companion... this line could be (val_add, ":canvas_no", ":is_female"),
  70624. (try_end),
  70625.  
  70626. #(assign, reg0, ":canvas_no"),
  70627. #(display_message, "@canvas no: {reg0}"),
  70628.  
  70629. (str_store_troop_face_keys, s0, ":troop_no"),
  70630. (troop_set_face_keys, ":canvas_no", s0), #give the right face to the canvas...
  70631.  
  70632. (try_begin), #these lines just add some variety to the poses - it's not really random but that would be complicated, since it needs to be consistent when this script is run for the alpha layer
  70633. (eq, ":companion_alive", 1),
  70634. (store_mod, ":animation", ":cur_agent", 4), #for alive troops, it uses the agent id, which is pretty close to random
  70635. (else_try),
  70636. (store_mod, ":animation", ":template_no", 4), #for dead troops it's based on the class
  70637. (try_end),
  70638.  
  70639. (val_add, ":animation", "anim_pose_1"), #there are a few poses after this one, which it chooses from
  70640.  
  70641.  
  70642.  
  70643. (set_fixed_point_multiplier, 100),
  70644. (cur_tableau_set_camera_parameters, 1, 6, 6, 10, 10000),
  70645. (assign, ":cam_height", 145),
  70646. (assign, ":camera_distance", 350),
  70647. (assign, ":camera_pitch", 2),
  70648.  
  70649. (init_position, pos5),
  70650. (position_set_z, pos5, ":cam_height"),
  70651. # camera looks towards -z axis
  70652. (position_rotate_x, pos5, -90),
  70653. (position_rotate_z, pos5, 180),
  70654. # now apply yaw and pitch
  70655. (try_begin),
  70656. (lt, ":canvas_no", "trp_coop_companion_equipment_ui_1"), #use different camera angles for each companion because it looks cooler - also it looks a bit weird if they face towards the edge of the screen
  70657. (assign, ":camera_yaw", -50),
  70658. (position_move_x, pos5, -10, 0),
  70659. (else_try),
  70660. (assign, ":camera_yaw", -10),
  70661. (position_move_x, pos5, 10, 0),
  70662. (try_end),
  70663. (position_rotate_y, pos5, ":camera_yaw"),
  70664. (position_rotate_x, pos5, ":camera_pitch"),
  70665. (position_move_z, pos5, ":camera_distance", 0),
  70666. (position_move_y, pos5, 60, 0),
  70667.  
  70668.  
  70669. (init_position, pos2),
  70670. (cur_tableau_add_troop, ":canvas_no", pos2, ":animation", 0),
  70671. (cur_tableau_set_camera_position, pos5),
  70672.  
  70673. (copy_position, pos8, pos5),
  70674. (position_rotate_x, pos8, -90), #y axis aligned with camera now. z is up
  70675. (position_rotate_z, pos8, 30),
  70676. (position_rotate_x, pos8, -50),
  70677. (cur_tableau_add_sun_light, pos8, 175,150,125),
  70678. ]),
  70679. #INVASION MODE END
  70680.  
  70681. #SB : update script moved here from triggers, so we can call from menu
  70682. ("dplmc_version_checker",
  70683. [
  70684.  
  70685. ##diplomacy start+
  70686. ##Add version checking, so the corrections are only applied once.
  70687. ##This allows for more complicated things to be added here in the future
  70688. #SB : coop troops added Dec. 2016, no SP change but troops need to be re-appended
  70689. (try_begin),
  70690. (troop_is_hero, dplmc_prev_employee), #if the older savegame had diplomacy troops already (but were pushed down)
  70691. (troop_get_slot, ":diplomacy_version_code", dplmc_prev_employee, dplmc_slot_troop_affiliated),
  70692. #We need to fix all the slot values and troops in wrong parties (recruiters etc)
  70693. (assign, ":troop_no", dplmc_prev_employee),
  70694. (try_for_range, ":new_troop", dplmc_employees_begin, dplmc_employees_end),
  70695. (try_for_range, ":slot_no", 0, dplmc_slot_troop_affiliated + 1),
  70696. (troop_get_slot, ":old_value", ":troop_no", ":slot_no"),
  70697. (troop_set_slot, ":new_troop", ":slot_no", ":old_value"),
  70698. (try_end),
  70699. (val_add, ":troop_no", 1), #move up by 1
  70700. (try_end),
  70701. (else_try),
  70702. (troop_get_slot, ":diplomacy_version_code", "trp_dplmc_chamberlain", dplmc_slot_troop_affiliated), #I've arbitrarily picked "when I started tracking this" as 0
  70703. (try_end),
  70704.  
  70705.  
  70706. (store_mod, ":verification", ":diplomacy_version_code", 128),
  70707. (assign, ":save_reg0", reg0),
  70708. (assign, ":save_reg1", reg1),
  70709. (try_begin),
  70710. #Detect bad values
  70711. (neq, ":diplomacy_version_code", 0),
  70712. (neq, ":verification", 68),
  70713. (assign, reg0, ":diplomacy_version_code"),
  70714. (display_message, "@{!} A slot had an unexpected value: {reg0}. This might be because you are using an incompatible troop list, or are using a non-native strange game. This message will repeat daily."),
  70715. (assign, ":diplomacy_version_code", -1),
  70716. (else_try),
  70717. (val_div, ":diplomacy_version_code", 128),
  70718. #Update if necessary.
  70719. (lt, ":diplomacy_version_code", DPLMC_CURRENT_VERSION_CODE),
  70720. (ge, "$cheat_mode", 1),
  70721. (assign, reg0, ":diplomacy_version_code"),
  70722.  
  70723. (assign, reg1, DPLMC_CURRENT_VERSION_CODE),
  70724. (display_message, "@{!} DEBUG - Detected a new version of diplomacy: previous version was {reg0}, and current version is {reg1}. Performing updates."),
  70725. (val_mul, reg1, 128),
  70726. (val_add, reg1, DPLMC_VERSION_LOW_7_BITS),
  70727. (troop_set_slot, "trp_dplmc_chamberlain", dplmc_slot_troop_affiliated, reg1),
  70728. (try_end),
  70729.  
  70730. (try_begin),
  70731. (is_between, ":diplomacy_version_code", -1, 1),#-1 or 0
  70732. #Native behavior follows
  70733. ##diplomacy end+
  70734.  
  70735. #this to correct string errors in games started in 1.104 or before
  70736. (party_set_name, "p_steppe_bandit_spawn_point", "str_the_steppes"),
  70737. (party_set_name, "p_taiga_bandit_spawn_point", "str_the_tundra"),
  70738. (party_set_name, "p_forest_bandit_spawn_point", "str_the_forests"),
  70739. (party_set_name, "p_mountain_bandit_spawn_point", "str_the_highlands"),
  70740. (party_set_name, "p_sea_raider_spawn_point_1", "str_the_coast"),
  70741. (party_set_name, "p_sea_raider_spawn_point_2", "str_the_coast"),
  70742. (party_set_name, "p_desert_bandit_spawn_point", "str_the_deserts"),
  70743.  
  70744.  
  70745. #this to correct inappropriate home strings - Katrin to Uxkhal, Matheld to Fearichen
  70746. # (troop_set_slot, "trp_npc11", slot_troop_home, "p_town_7"),
  70747. (troop_set_slot, "trp_npc8", slot_troop_home, "p_village_35"),
  70748.  
  70749. (troop_set_slot, "trp_npc15", slot_troop_town_with_contacts, "p_town_20"), #durquba
  70750.  
  70751. #this to correct linen production at villages of durquba
  70752. (party_set_slot, "p_village_93", slot_center_linen_looms, 0), #mazigh
  70753. (party_set_slot, "p_village_94", slot_center_linen_looms, 0), #sekhtem
  70754. (party_set_slot, "p_village_95", slot_center_linen_looms, 0), #qalyut
  70755. (party_set_slot, "p_village_96", slot_center_linen_looms, 0), #tilimsal
  70756. (party_set_slot, "p_village_97", slot_center_linen_looms, 0), #shibal zumr
  70757. (party_set_slot, "p_village_102", slot_center_linen_looms, 0), #tamnuh
  70758. (party_set_slot, "p_village_109", slot_center_linen_looms, 0), #habba
  70759.  
  70760. (party_set_slot, "p_village_67", slot_center_fishing_fleet, 0), #Tebandra
  70761. (party_set_slot, "p_village_5", slot_center_fishing_fleet, 15), #Kulum
  70762.  
  70763. ##diplomacy start+
  70764. #End the changes in Native
  70765. (try_end),
  70766.  
  70767. #Behavior specific to a fresh Diplomacy version
  70768. (try_begin),
  70769. (ge, ":diplomacy_version_code", 0),#do not run this if the code is bad
  70770. (lt, ":diplomacy_version_code", 1),
  70771.  
  70772. #Add home centers for claimants (mods not using standard NPCs or map may wish to remove this)
  70773. (troop_set_slot, "trp_kingdom_1_pretender", slot_troop_home, "p_town_4"),#Lady Isolle - Suno
  70774. (troop_set_slot, "trp_kingdom_2_pretender", slot_troop_home, "p_town_11"),#Prince Valdym - Curaw
  70775. (troop_set_slot, "trp_kingdom_3_pretender", slot_troop_home, "p_town_18"),#Dustum Khan - Narra
  70776. (troop_set_slot, "trp_kingdom_4_pretender", slot_troop_home, "p_town_12"),#Lethwin Far-Seeker - Wercheg
  70777. (troop_set_slot, "trp_kingdom_5_pretender", slot_troop_home, "p_town_3"),#Lord Kastor - Veluca
  70778. (troop_set_slot, "trp_kingdom_6_pretender", slot_troop_home, "p_town_20"),#Arwa the Pearled One - Durquba
  70779. #add ancestral fiefs to home slots (mods not using standard NPCs or map should remove this)
  70780. (troop_set_slot, "trp_knight_2_10", slot_troop_home, "p_castle_29"), #Nelag_Castle
  70781. (troop_set_slot, "trp_knight_3_4", slot_troop_home, "p_castle_30"), #Asugan_Castle
  70782. (troop_set_slot, "trp_knight_1_3", slot_troop_home, "p_castle_35"), #Haringoth_Castle
  70783. (troop_set_slot, "trp_knight_5_11", slot_troop_home, "p_castle_33"), #Etrosq_Castle
  70784. #Also the primary six towns (mods not using standard NPCs or map may wish to remove this)
  70785. (troop_set_slot, "trp_kingdom_1_lord", slot_troop_home, "p_town_6"),#King Harlaus to Praven
  70786. (troop_set_slot, "trp_kingdom_2_lord", slot_troop_home, "p_town_8"),#King Yaroglek to Reyvadin
  70787. (troop_set_slot, "trp_kingdom_3_lord", slot_troop_home, "p_town_10"),#Sanjar Khan to Tulga
  70788. (troop_set_slot, "trp_kingdom_4_lord", slot_troop_home, "p_town_1"),#King Ragnar to Sargoth
  70789. (troop_set_slot, "trp_kingdom_5_lord", slot_troop_home, "p_town_5"),#King Graveth to Jelkala
  70790. (troop_set_slot, "trp_kingdom_6_lord", slot_troop_home, "p_town_19"),#Sultan Hakim to Shariz
  70791.  
  70792. (call_script, "script_dplmc_init_domestic_policy"),
  70793. #Set the "original lord" values corresponding to the above.
  70794. (try_for_range, ":troop_no", active_npcs_begin, active_npcs_end),
  70795. (this_or_next|eq, ":troop_no", "trp_knight_2_10"),#Nelag
  70796. (this_or_next|eq, ":troop_no", "trp_knight_3_4"),#Asugan
  70797. (this_or_next|eq, ":troop_no", "trp_knight_1_3"),#Haringoth
  70798. (this_or_next|eq, ":troop_no", "trp_knight_5_11"),#Etrosq
  70799. (this_or_next|is_between, ":troop_no", kings_begin, kings_end),
  70800. (is_between, ":troop_no", pretenders_begin, pretenders_end),
  70801.  
  70802. (troop_get_slot, ":center_no", ":troop_no", slot_troop_home),
  70803. (is_between, ":center_no", centers_begin, centers_end),
  70804. (neg|party_slot_ge, ":center_no", dplmc_slot_center_original_lord, 1),
  70805. (party_set_slot, ":center_no", dplmc_slot_center_original_lord, ":troop_no"),
  70806.  
  70807. #Also set "ex-lord"
  70808. (neg|is_between, ":troop_no", pretenders_begin, pretenders_end),
  70809. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  70810. (neg|party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  70811. (neg|party_slot_ge, ":center_no", dplmc_slot_center_ex_lord, 1),
  70812. (party_set_slot, ":center_no", dplmc_slot_center_ex_lord, ":troop_no"),
  70813. (try_end),
  70814.  
  70815. #Make sure the affiliation slot is set correctly.
  70816. (try_begin),
  70817. (is_between, "$g_player_affiliated_troop", lords_begin, kingdom_ladies_end),
  70818. (troop_get_slot, ":slot_val", "$g_player_affiliated_troop", dplmc_slot_troop_affiliated),
  70819. (is_between, ":slot_val", 0, 3),#0 is default, 1 is asked, in previous versions there was no use of 2
  70820. (troop_set_slot, "$g_player_affiliated_troop", dplmc_slot_troop_affiliated, 3),#3 is affiliated
  70821. (try_end),
  70822.  
  70823. #Set father/mother slots for the unmarried medium-age lords, so checking for
  70824. #being related will work as expected.
  70825. (try_for_range, ":troop_no", lords_begin, lords_end),
  70826. (troop_slot_eq, ":troop_no", slot_troop_father, -1),
  70827. (troop_slot_eq, ":troop_no", slot_troop_mother, -1),
  70828. (store_mul, ":father", ":troop_no", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),#defined in module_constants.py
  70829. (val_add, ":father", DPLMC_VIRTUAL_RELATIVE_FATHER_OFFSET),
  70830. (troop_set_slot, ":troop_no", slot_troop_father, ":father"),
  70831. (store_add, ":mother", ":father", DPLMC_VIRTUAL_RELATIVE_MOTHER_OFFSET - DPLMC_VIRTUAL_RELATIVE_FATHER_OFFSET),
  70832. (troop_set_slot, ":troop_no", slot_troop_mother, ":mother"),
  70833. (try_end),
  70834.  
  70835. #Fix kingdom lady daughters having "slot_troop_mother" set to themselves.
  70836. #The old fix was in troop_get_family_relation_to_troop, but now we can
  70837. #just do it once here.
  70838. (try_for_range, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  70839. (try_begin),
  70840. (troop_slot_eq, ":troop_no", slot_troop_mother, ":troop_no"),
  70841. (troop_get_slot, ":father", ":troop_no", slot_troop_father),
  70842. (try_begin),
  70843. (is_between, ":father", active_npcs_begin, active_npcs_end),
  70844. (troop_get_slot, ":mother", ":father", slot_troop_spouse),
  70845. (troop_set_slot, ":troop_no", slot_troop_mother, ":mother"),
  70846. (try_begin),
  70847. #Print a message if desired
  70848. (ge, "$cheat_mode", 1),
  70849. (str_store_troop_name, s0, ":troop_no"),
  70850. (display_message, "@{!}DEBUG - Fixed slot_troop_mother for {s0}."),
  70851. (try_end),
  70852. (else_try),
  70853. (troop_set_slot, ":troop_no", slot_troop_mother, -1),#better than being set to herself
  70854. #Print a message if desired
  70855. (ge, "$cheat_mode", 1),
  70856. (str_store_troop_name, s0, ":troop_no"),
  70857. (display_message, "@{!}DEBUG - When fixing slot_troop_mother for {s0}, could not find a valid mother."),
  70858. (try_end),
  70859. #While we're at it, also give parents to the sisters of the middle-aged lords.
  70860. (else_try),
  70861. (troop_slot_eq, ":troop_no", slot_troop_father, -1),
  70862. (troop_slot_eq, ":troop_no", slot_troop_mother, -1),
  70863. #"Guardian" here means brother
  70864. (troop_get_slot, ":guardian", ":troop_no", slot_troop_guardian),
  70865. (ge, ":guardian", 1),
  70866. #Has brother's father
  70867. (troop_get_slot, ":father", ":guardian", slot_troop_father),
  70868. (troop_set_slot, ":troop_no", slot_troop_father, ":father"),
  70869. #Has brother's mother
  70870. (troop_get_slot, ":mother", ":guardian", slot_troop_mother),
  70871. (troop_set_slot, ":troop_no", slot_troop_mother, ":mother"),
  70872. (try_end),
  70873. #Also set original factions for ladies.
  70874. (neg|troop_slot_ge, ":troop_no", slot_troop_original_faction, 1),
  70875. (assign, ":guardian", -1),
  70876. (try_begin),
  70877. (troop_slot_ge, ":troop_no", slot_troop_father, 1),
  70878. (troop_get_slot, ":guardian", ":troop_no", slot_troop_father),
  70879. (else_try),
  70880. (troop_slot_ge, ":troop_no", slot_troop_guardian, 1),
  70881. (troop_get_slot, ":guardian", ":troop_no", slot_troop_guardian),
  70882. (else_try),
  70883. (troop_slot_ge, ":troop_no", slot_troop_spouse, 1),
  70884. (troop_get_slot, ":guardian", ":troop_no", slot_troop_spouse),
  70885. (try_end),
  70886. (ge, ":guardian", 1),
  70887. (troop_get_slot, ":original_faction", ":guardian", slot_troop_original_faction),
  70888. (troop_set_slot, ":troop_no", slot_troop_original_faction, ":original_faction"),
  70889. (try_end),
  70890.  
  70891. ##Set relations between kingdom ladies and their relatives.
  70892. ##Do *not* initialize their relations with anyone they aren't related to:
  70893. ##that is used for courtship.
  70894. ## The purpose of this initialization is so if a kingdom lady gets promoted,
  70895. ##her relations aren't a featureless slate. Also, it would be interesting to
  70896. ##further develop the idea of ladies as pursuing agendas even if they aren't
  70897. ##leading warbands, which would benefit from giving them relations with other
  70898. ##people.
  70899. #
  70900. #Because relations may already exist, only call this in instances where
  70901. #they are 0 or 1 (the latter just means "met" between NPCs).
  70902. (try_for_range, ":lady", kingdom_ladies_begin, kingdom_ladies_end),
  70903. (troop_slot_eq, ":lady", slot_troop_occupation, slto_kingdom_lady),
  70904. (troop_get_slot, ":lady_faction", ":lady", slot_troop_original_faction),
  70905. (ge, ":lady_faction", 1),
  70906.  
  70907. (try_for_range, ":other_hero", heroes_begin, heroes_end),
  70908. (this_or_next|troop_slot_eq, ":other_hero", slot_troop_occupation, slto_kingdom_lady),
  70909. (this_or_next|troop_slot_eq, ":other_hero", slot_troop_occupation, slto_kingdom_hero),
  70910. (troop_slot_eq, ":other_hero", slot_troop_occupation, slto_inactive_pretender),
  70911. (troop_slot_eq, ":other_hero", slot_troop_original_faction, ":lady_faction"),
  70912.  
  70913. #Because this is not a new game: first check if relations have developed
  70914. (call_script, "script_troop_get_relation_with_troop", ":lady", ":other_hero"),
  70915. (is_between, reg0, 0, 2),#0 or 1
  70916.  
  70917. (try_begin),
  70918. (this_or_next|troop_slot_eq, ":lady", slot_troop_spouse, ":other_hero"),
  70919. (troop_slot_eq, ":other_hero", slot_troop_spouse, ":lady"),
  70920. (store_random_in_range, reg0, 0, 11),
  70921. (else_try),
  70922. #(call_script, "script_troop_get_family_relation_to_troop", ":lady", ":other_hero"),
  70923. (call_script, "script_dplmc_troop_get_family_relation_to_troop", ":lady", ":other_hero"),
  70924. (try_end),
  70925.  
  70926. (call_script, "script_troop_change_relation_with_troop", ":lady", ":other_hero", reg0),
  70927.  
  70928. #This relation change only applies between kingdom ladies.
  70929. (troop_slot_eq, ":other_hero", slot_troop_occupation, slto_kingdom_lady),
  70930. (is_between, ":other_hero", kingdom_ladies_begin, kingdom_ladies_end),
  70931.  
  70932. (store_random_in_range, ":random", 0, 11),
  70933. (call_script, "script_troop_change_relation_with_troop", ":lady", ":other_hero", ":random"),
  70934. (try_end),
  70935. (try_end),
  70936.  
  70937. #Change the occupation of exiled lords (not including pretenders or kings)
  70938. (try_for_range, ":troop_no", lords_begin, lords_end),
  70939. (store_troop_faction, ":faction_no", ":troop_no"),
  70940. #A lord in the outlaw faction
  70941. (eq, ":faction_no", "fac_outlaws"),
  70942. #Possible values for his occupation if he's an exile (but there's some overlap between these and "bandit hero")
  70943. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),#<- The default
  70944. (this_or_next|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_inactive),#<- This can happen joining the player faction
  70945. (troop_slot_eq, ":troop_no", slot_troop_occupation, 0),#<- This gets set for prisoners
  70946. #(Quick Check) Not leading a party or the prisoner of a party or at a center
  70947. (neg|troop_slot_ge, ":troop_no", slot_troop_leaded_party, 0),
  70948. (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),
  70949. (neg|troop_slot_ge, ":troop_no", slot_troop_cur_center, 1),#deliberately 1 instead of 0
  70950. #(Slow check) Does not own any fiefs
  70951. (assign, ":end", centers_end),
  70952. (try_for_range, ":center_no", centers_begin, ":end"),
  70953. (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
  70954. (assign, ":end", ":center_no"),#stop loop, and also signal failure
  70955. (try_end),
  70956. #(Slow check) Explicitly verify he is not a prisoner anywhere.
  70957. (call_script, "script_search_troop_prisoner_of_party", ":troop_no"),
  70958. (eq, reg0, -1),
  70959. #(Slow check) Explicitly verify he's not a member of any party
  70960. (assign, ":member_of_party", -1),
  70961. (try_for_parties, ":party_no"),
  70962. (eq, ":member_of_party", -1),
  70963. (this_or_next|eq, ":party_no", "p_main_party"),
  70964. (ge, ":party_no", centers_begin),
  70965. (party_count_members_of_type, ":count", ":party_no", ":troop_no"),
  70966. (gt, ":count", 0),
  70967. (assign, ":member_of_party", ":party_no"),
  70968. (try_end),
  70969. (eq, ":member_of_party", -1),
  70970. #Finally verified that he is in exile. Set the slot value to make
  70971. #this easier in the future.
  70972. (troop_set_slot, ":troop_no", slot_troop_occupation, dplmc_slto_exile),
  70973. (try_begin),
  70974. (ge, "$cheat_mode", 1),
  70975. (str_store_troop_name, s0, ":troop_no"),
  70976. (display_message, "@{!}DEBUG - Changed occupation of {s0} to dplmc_slto_exile"),
  70977. (try_end),
  70978. (try_end),
  70979.  
  70980. #Initialize histories for supported pretenders.
  70981. (try_for_range, ":troop_no", pretenders_begin, pretenders_end),
  70982. (neg|troop_slot_eq, ":troop_no", slot_troop_met, 0),
  70983. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  70984. (troop_slot_eq, ":troop_no", slot_troop_playerparty_history, 0),
  70985. (troop_set_slot, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_granted_fief),
  70986. (try_end),
  70987.  
  70988. #Initialize histories for promoted companions
  70989. (try_for_range, ":troop_no", companions_begin, companions_end),
  70990. (neg|troop_slot_eq, ":troop_no", slot_troop_met, 0),
  70991. (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  70992. (neg|troop_slot_eq, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_nonplayer_entry),
  70993. (troop_set_slot, ":troop_no", slot_troop_playerparty_history, dplmc_pp_history_granted_fief),
  70994. (try_end),
  70995.  
  70996. #For all centers, update new slots
  70997. (try_for_range, ":center_no", centers_begin, centers_end),
  70998. #Last attacker
  70999. (try_begin),
  71000. (party_slot_eq, ":center_no", dplmc_slot_center_last_attacker, 0),
  71001. (party_slot_eq, ":center_no", dplmc_slot_center_last_attacked_time, 0),
  71002. (party_set_slot, ":center_no", dplmc_slot_center_last_attacker, -1),
  71003. (try_end),
  71004.  
  71005. (party_slot_eq, ":center_no", dplmc_slot_center_last_transfer_time, 0),
  71006. #Ex-lord
  71007. (try_begin),
  71008. (party_slot_eq, ":center_no", dplmc_slot_center_ex_lord, 0),
  71009. (party_set_slot, ":center_no", dplmc_slot_center_ex_lord, -1),
  71010. (try_end),
  71011. #Original lord
  71012. (try_begin),
  71013. (party_slot_eq, ":center_no", dplmc_slot_center_original_lord, 0),
  71014. (neg|troop_slot_eq, "trp_player", slot_troop_home, ":center_no"),
  71015. (party_set_slot, ":center_no", dplmc_slot_center_original_lord, -1),
  71016. (try_end),
  71017. (try_end),
  71018.  
  71019. #Don't bother filling in "last caravan arrival" slots with fake values.
  71020. #Right now the scripts check and do that automatically if they aren't
  71021. #set.
  71022.  
  71023. #Perform initialization for autoloot / autosell.
  71024. (call_script, "script_dplmc_initialize_autoloot", 1),#argument "1" forces this to make changes
  71025.  
  71026. #Fix a mistake I had introduced before, where you could get the wrong
  71027. #"marry betrothed" quest when courting a lady.
  71028. (try_begin),
  71029. (check_quest_active, "qst_wed_betrothed_female"),
  71030. (quest_get_slot, ":betrothed_troop", "qst_wed_betrothed_female", slot_quest_giver_troop),
  71031. (is_between, ":betrothed_troop", kingdom_ladies_begin, kingdom_ladies_end),
  71032. (display_message, "@{!}FIXED PROBLEM - Cancelled erroneous version of qst_wed_betrothed_female. You should be able to marry normally if you try again."),
  71033. (call_script, "script_abort_quest", "qst_wed_betrothed_female", 0),#abort with type 0 "event" should give no penalties to the player
  71034. (try_end),
  71035. #End version-checked block.
  71036. (try_end),
  71037.  
  71038. (try_begin),
  71039. (is_between, ":diplomacy_version_code", 1, 110615),
  71040. #Fix a bug that was introduced in some version before 2011-06-15 that made
  71041. #all "young unmarried lords" only have half-siblings, with either their own
  71042. #father or mother slot uninitialized.
  71043. (try_begin),
  71044. (lt, 31, heroes_begin),
  71045. (neg|troop_slot_eq, 31, 31, 0),#"slot_troop_father" was 31 in those saved games
  71046. (troop_set_slot, 31, 31, -1),#(it still is 31 as far as I know, but this code should remain the same even if the slot value changes)
  71047. (try_end),
  71048. (try_begin),
  71049. (lt, 32, heroes_begin),
  71050. (neg|troop_slot_eq, 32,32,0),#"slot_troop_mother" was 32 in those saved games
  71051. (troop_set_slot, 32, 32, -1),
  71052. (try_end),
  71053. (try_for_range, ":troop_no", lords_begin, lords_end),
  71054. (troop_get_slot, reg0, ":troop_no", slot_troop_father),
  71055. (troop_get_slot, reg1, ":troop_no", slot_troop_mother),
  71056. (try_begin),
  71057. (is_between, reg0, lords_begin, lords_end),
  71058. (neg|is_between, reg1, kingdom_ladies_begin, kingdom_ladies_end),
  71059. (troop_get_slot, reg1, reg0, slot_troop_spouse),
  71060. (is_between, reg1, kingdom_ladies_begin, kingdom_ladies_end),
  71061. (troop_set_slot, ":troop_no", slot_troop_mother, reg1),
  71062. (call_script, "script_update_troop_notes", ":troop_no"),#Doesn't actually do anything
  71063. (else_try),
  71064. (is_between, reg1, kingdom_ladies_begin, kingdom_ladies_end),
  71065. (neg|is_between, reg0, lords_begin, lords_end),
  71066. (troop_get_slot, reg0, reg1, slot_troop_spouse),
  71067. (is_between, reg0, lords_begin, lords_end),
  71068. (troop_set_slot, ":troop_no", slot_troop_father, reg0),
  71069. (call_script, "script_update_troop_notes", ":troop_no"),#Doesn't actually do anything
  71070. (try_end),
  71071. (try_end),
  71072.  
  71073. #For old saved games, a reputation bug that was introduced in the release 2011-06-06 and was fixed on 2011-06-07.
  71074. (eq, ":diplomacy_version_code", 1),
  71075. (assign, reg0, 0),
  71076. (try_for_range, ":troop_no", lords_begin, lords_end),
  71077. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_none),
  71078. (store_random_in_range, reg1, lrep_none, lrep_roguish),
  71079. (val_max, reg1, lrep_none + 1),#So there's an extra chance of getting reputation 1, which is lrep_martial
  71080. (troop_set_slot, ":troop_no", slot_lord_reputation_type, reg1),
  71081. (val_add, reg0, 1),
  71082. (try_end),
  71083.  
  71084. (try_begin),
  71085. (ge, "$cheat_mode", 1),
  71086. (store_sub, reg1, reg0, 1),
  71087. (display_message, "@{!} Bug fix: set personality types for {reg0} {reg1?lords:lord}"),
  71088. (try_end),
  71089.  
  71090. (assign, reg0, 0),
  71091. (try_for_range, ":troop_no", kingdom_ladies_begin, kingdom_ladies_end),
  71092. (neq, ":troop_no", "trp_knight_1_1_wife"),#That lady should not appear in the game
  71093. (troop_slot_eq, ":troop_no", slot_lord_reputation_type, lrep_none),
  71094. (store_random_in_range, reg1, lrep_conventional - 1, lrep_moralist + 1),
  71095. (val_max, reg1, lrep_conventional),#So there's an extra chance of getting lrep_conventional
  71096. (troop_set_slot, ":troop_no", slot_lord_reputation_type, reg1),
  71097. (val_add, reg0, 1),
  71098. (try_end),
  71099.  
  71100. (try_begin),
  71101. (ge, "$cheat_mode", 1),
  71102. (store_sub, reg1, reg0, 1),
  71103. (display_message, "@{!} Bug fix: set personality types for {reg0} {reg1?ladies:lady}"),
  71104. (try_end),
  71105. (try_end),
  71106.  
  71107. #Behavior for an upgrade from Native or pre-Diplomacy 4.0 to Diplomacy 4.0
  71108. (try_begin),
  71109. (is_between, ":diplomacy_version_code", 0, 111001),
  71110. #Fix: slot_faction_leader and slot_faction_marshall should not equal trp_player
  71111. #if the player is not a member of the faction. (This is initially true because
  71112. #trp_player is 0, and uninitialized slots default to 0.)
  71113. (try_for_range, ":faction_no", 0, dplmc_factions_end),
  71114. (neq, ":faction_no", "fac_player_faction"),
  71115. (neq, ":faction_no", "fac_player_supporters_faction"),
  71116. (this_or_next|neq, ":faction_no", "$players_kingdom"),
  71117. (eq, ":faction_no", 0),
  71118. #The player is not a member of the faction:
  71119. (try_begin),
  71120. (faction_slot_eq, ":faction_no", slot_faction_leader, 0),
  71121. (faction_set_slot, ":faction_no", slot_faction_leader, -1),
  71122. (try_end),
  71123. (try_begin),
  71124. (faction_slot_eq, ":faction_no", slot_faction_marshall, 0),
  71125. (faction_set_slot, ":faction_no", slot_faction_marshall, -1),
  71126. (try_end),
  71127. (try_end),
  71128. #Initialize home slots for town merchants, elders, etc.
  71129. (try_for_range, ":center_no", centers_begin, centers_end),
  71130. (try_for_range, ":troop_no", dplmc_slot_town_merchants_begin, dplmc_slot_town_merchants_end),
  71131. (party_get_slot, ":troop_no", ":center_no", ":troop_no"),
  71132. (gt, ":troop_no", walkers_end),
  71133. (troop_is_hero, ":troop_no"),
  71134. (troop_slot_eq, ":troop_no", slot_troop_home, 0),
  71135. (troop_set_slot, ":troop_no", slot_troop_home, ":center_no"),
  71136. (try_end),
  71137. (try_end),
  71138. #Initialize home slots for startup merchants. (Merchant of Praven, etc.)
  71139. #This should be done after kings have their home slots initialized.
  71140. (try_for_range, ":troop_no", kings_begin, kings_end),
  71141. (troop_get_slot, ":center_no", ":troop_no", slot_troop_home),
  71142. (val_sub, ":troop_no", kings_begin),
  71143. (val_add, ":troop_no", startup_merchants_begin),
  71144. (is_between, ":troop_no", startup_merchants_begin, startup_merchants_end),#Right now there's a startup merchant for each faction. Verify this hasn't unexpectedly changed.
  71145. (neg|troop_slot_ge, ":troop_no", slot_troop_home, 1),#Verify that the home slot is not already set
  71146. (troop_set_slot, ":troop_no", slot_troop_home, ":center_no"),
  71147. (try_end),
  71148. #Reset potentially bad value in "slot_troop_stance_on_faction_issue" (i.e. 153) from auto-loot
  71149. (eq, 153, slot_troop_stance_on_faction_issue),
  71150. (try_for_range, ":troop_no", companions_begin, companions_end),
  71151. (try_begin),
  71152. (neg|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
  71153. (troop_set_slot, ":troop_no", slot_troop_stance_on_faction_issue, -1),
  71154. (else_try),
  71155. (troop_get_slot, ":slot_val", ":troop_no", slot_troop_stance_on_faction_issue),
  71156. (neg|is_between, ":slot_val", -1, 1),#0 or -1
  71157. (neg|is_between, ":slot_val", heroes_begin, heroes_end),
  71158. (troop_set_slot, ":troop_no", slot_troop_stance_on_faction_issue, -1),
  71159. (try_end),
  71160. (try_end),
  71161. (try_end),
  71162.  
  71163. #SB : new features
  71164. (try_begin),
  71165. (is_between, ":diplomacy_version_code", 0, DPLMC_CURRENT_VERSION_CODE),
  71166. #set up camera keys
  71167. (call_script, "script_setup_camera_keys"),
  71168.  
  71169. #replace recruiter/messenger
  71170. (try_for_parties, ":party_no"),
  71171. (party_is_active, ":party_no"),
  71172. (party_get_template_id, ":party_template", ":party_no"),
  71173. (this_or_next|eq, ":party_template", "pt_dplmc_recruiter"),
  71174. (eq, ":party_template", "pt_messenger_party"),
  71175. #
  71176. (try_end),
  71177.  
  71178. #set up disguise system, disabled by default
  71179. (assign, "$g_dplmc_player_disguise", 0),
  71180. (try_begin),
  71181. (assign, ":disguise", disguise_pilgrim), #always available
  71182. #farmer, acquired from village elders
  71183. (assign, ":villages_end", villages_end),
  71184. (try_for_range, ":center_no", villages_begin, ":villages_end"),
  71185. (party_slot_ge, ":center_no", slot_center_player_relation, 25),
  71186. (val_add, ":disguise", disguise_farmer),
  71187. (assign, ":villages_end", -1), #loop break
  71188. (try_end),
  71189.  
  71190. #hunter, acquired from background or archery skill
  71191. (try_begin),
  71192. (store_proficiency_level, ":cur_amount", "trp_player", wpt_archery),
  71193. (this_or_next|ge, ":cur_amount", 250),
  71194. (this_or_next|eq, "$background_answer", cb_forester),
  71195. (this_or_next|eq, "$background_answer_2", cb2_steppe_child),
  71196. (eq, "$background_answer_3", cb3_poacher),
  71197. (val_add, ":disguise", disguise_hunter),
  71198. (try_end),
  71199.  
  71200. #merchant, from background or gold count or enterprise
  71201. (try_begin),
  71202. (assign, ":continue", 0),
  71203. (assign, ":villages_end", towns_end),
  71204. (try_for_range, ":center_no", towns_begin, ":villages_end"),
  71205. (party_slot_ge, ":center_no", slot_center_player_enterprise, 1),
  71206. (assign, ":continue", 1),
  71207. (assign, ":villages_end", towns_begin), #loop break
  71208. (try_end),
  71209. (try_begin),
  71210. (eq, ":continue", 0),
  71211. (store_troop_gold, ":cur_amount", "trp_player"),
  71212. (store_skill_level, ":cur_skill", "trp_player", "skl_trade"),
  71213. (ge, ":cur_skill", 5),
  71214. (ge, ":cur_amount", 10000),
  71215. (assign, ":continue", 1),
  71216. (try_end),
  71217. (this_or_next|gt, ":continue", 0),
  71218. (this_or_next|eq, "$background_answer", cb_merchant),
  71219. (this_or_next|eq, "$background_answer_2", cb2_merchants_helper),
  71220. (eq, "$background_answer_3", cb3_peddler),
  71221. (val_add, ":disguise", disguise_merchant),
  71222. (try_end),
  71223.  
  71224. #guard, from background or weapon mastery
  71225. (try_begin),
  71226. (store_skill_level, ":cur_skill", "trp_player", "skl_weapon_master"),
  71227. (this_or_next|ge, ":cur_skill", 5),
  71228. (this_or_next|eq, "$background_answer", cb_guard),
  71229. (this_or_next|eq, "$background_answer_3", dplmc_cb3_bravo),
  71230. (this_or_next|eq, "$background_answer_3", dplmc_cb3_merc),
  71231. (eq, "$background_answer_3", cb3_squire),
  71232. (val_add, ":disguise", disguise_guard),
  71233. (try_end),
  71234.  
  71235. #bard, from background or known songs
  71236. (try_begin),
  71237. (store_add, ":cur_amount", "$allegoric_poem_recitations", "$mystic_poem_recitations"),
  71238. (val_add, ":cur_amount", "$tragic_poem_recitations"),
  71239. (val_add, ":cur_amount", "$heroic_poem_recitations"),
  71240. (val_add, ":cur_amount", "$comic_poem_recitations"),
  71241. (this_or_next|ge, ":cur_amount", 2), #2 poems known
  71242. (eq, "$background_answer_3", cb3_troubadour),
  71243. (val_add, ":disguise", disguise_bard),
  71244. (try_end),
  71245. (try_end),
  71246. (troop_set_slot, "trp_player", slot_troop_player_disguise_sets, ":disguise"),
  71247.  
  71248.  
  71249. #equip voulges
  71250. (troop_add_item, "trp_fighter_woman", "itm_shortened_voulge"),
  71251. (troop_add_item, "trp_swadian_sergeant", "itm_awlpike_long"),
  71252. (troop_add_item, "trp_swadian_deserter", "itm_shortened_voulge"),
  71253. (troop_add_item, "trp_swadian_deserter", "itm_long_voulge"),
  71254. (troop_add_item, "trp_swadian_crossbowman", "itm_shortened_voulge"),
  71255. (troop_add_item, "trp_swadian_sharpshooter", "itm_long_voulge"),
  71256. (troop_add_item, "trp_vaegir_guard", "itm_two_handed_battle_axe_2"),
  71257. (troop_add_item, "trp_vaegir_guard", "itm_long_bardiche"),
  71258. (troop_add_item, "trp_vaegir_infantry", "itm_two_handed_battle_axe_2"),
  71259. (troop_remove_item, "trp_vaegir_infantry", "itm_battle_axe"),
  71260.  
  71261. #add coloured tunics to messengers, remove leather_jerkin
  71262. (troop_remove_item, "trp_swadian_messenger", "itm_leather_jerkin"),
  71263. (troop_remove_item, "trp_vaegir_messenger", "itm_leather_jerkin"),
  71264. (troop_remove_item, "trp_vaegir_messenger", "itm_sword_medieval_b"),
  71265. (troop_remove_item, "trp_khergit_messenger", "itm_leather_jerkin"),
  71266. (troop_remove_item, "trp_khergit_messenger", "itm_short_bow"),
  71267. (troop_remove_item, "trp_khergit_messenger", "itm_arrows"),
  71268. (troop_remove_item, "trp_nord_messenger", "itm_leather_jerkin"),
  71269. (troop_remove_item, "trp_nord_messenger", "itm_short_bow"),
  71270. (troop_remove_item, "trp_rhodok_messenger", "itm_leather_jerkin"),
  71271. (troop_remove_item, "trp_rhodok_messenger", "itm_short_bow"),
  71272. (troop_remove_item, "trp_rhodok_messenger", "itm_arrows"),
  71273. #sarranid messenger already copied from horseman
  71274. (troop_add_item, "trp_swadian_messenger", "itm_arena_tunic_red"),
  71275. (troop_add_item, "trp_vaegir_messenger", "itm_fighting_axe"),
  71276. (troop_add_item, "trp_vaegir_messenger", "itm_studded_leather_coat"),
  71277. (troop_add_item, "trp_khergit_messenger", "itm_khergit_bow"),
  71278. (troop_add_item, "trp_khergit_messenger", "itm_khergit_arrows"),
  71279. (troop_add_item, "trp_khergit_messenger", "itm_nomad_robe"),
  71280. (troop_add_item, "trp_nord_messenger", "itm_long_bow"),
  71281. (troop_add_item, "trp_nord_messenger", "itm_arena_tunic_blue"),
  71282. (troop_add_item, "trp_rhodok_messenger", "itm_light_crossbow"),
  71283. (troop_add_item, "trp_rhodok_messenger", "itm_steel_bolts"),
  71284. (troop_add_item, "trp_rhodok_messenger", "itm_arena_tunic_green"),
  71285.  
  71286. #equip tavern drunks/assassin (could be done as easily in trigger)
  71287. (troop_add_item, "trp_belligerent_drunk","itm_sword_medieval_a"),
  71288. (troop_add_item, "trp_belligerent_drunk","itm_sword_khergit_1"),
  71289. (troop_add_item, "trp_belligerent_drunk","itm_arabian_sword_a"),
  71290. (troop_remove_item, "trp_hired_assassin","itm_sword_medieval_a"),
  71291. (troop_add_item, "trp_hired_assassin","itm_sword_viking_3"),
  71292. (troop_add_item, "trp_hired_assassin","itm_sword_medieval_d_long"),
  71293. (troop_add_item, "trp_hired_assassin","itm_sword_khergit_4"),
  71294. (troop_add_item, "trp_hired_assassin","itm_arabian_sword_d"),
  71295. (troop_add_item, "trp_hired_assassin","itm_strange_sword"),
  71296.  
  71297. #rivacheg strange bonus chest
  71298. (store_random_in_range, ":imod", imod_rusty, imod_strong),
  71299. (troop_add_item, "trp_bonus_chest_1","itm_strange_sword", ":imod"),
  71300. (store_random_in_range, ":imod", imod_rusty, imod_strong),
  71301. (troop_add_item, "trp_bonus_chest_1","itm_strange_great_sword", ":imod"),
  71302. (store_random_in_range, ":imod", imod_tattered, imod_lame),
  71303. (troop_add_item, "trp_bonus_chest_1","itm_strange_boots", ":imod"),
  71304. (store_random_in_range, ":imod", imod_tattered, imod_lame),
  71305. (troop_add_item, "trp_bonus_chest_1","itm_strange_helmet", ":imod"),
  71306.  
  71307. (troop_add_item, "trp_bonus_chest_2","itm_bride_dress", imod_stubborn),
  71308. (troop_add_item, "trp_bonus_chest_2","itm_bride_crown", imod_deadly),
  71309. (troop_add_item, "trp_bonus_chest_2","itm_bride_shoes", imod_smelling),
  71310. (troop_add_item, "trp_bonus_chest_2","itm_torch", imod_old),
  71311.  
  71312. (troop_add_item, "trp_bonus_chest_3","itm_black_armor", imod_lordly),
  71313. (troop_add_item, "trp_bonus_chest_3","itm_black_greaves", imod_lordly),
  71314. (troop_add_item, "trp_bonus_chest_3","itm_black_helmet", imod_lordly),
  71315. (troop_add_item, "trp_bonus_chest_3","itm_steel_shield", imod_lordly),
  71316. (troop_add_item, "trp_bonus_chest_3","itm_charger", imod_lordly), #charger_plate_1
  71317.  
  71318. #training ground variables based on global
  71319. (try_for_range, ":npc", training_ground_trainers_begin, training_ground_trainers_end),
  71320. #init trainer vars, global applied to all trainers instead of individual progress
  71321. # (troop_set_slot, ":npc", slot_troop_trainer_met, 0),
  71322. (troop_set_slot, ":npc", slot_troop_trainer_waiting_for_result, "$waiting_for_training_fight_result"),
  71323. (troop_set_slot, ":npc", slot_troop_trainer_training_fight_won, "$training_fight_won"),
  71324. (troop_set_slot, ":npc", slot_troop_trainer_num_opponents_to_beat, "$num_opponents_to_beat_in_a_row"),
  71325. (troop_set_slot, ":npc", slot_troop_trainer_training_system_explained, "$training_system_explained"),
  71326. (troop_set_slot, ":npc", slot_troop_trainer_opponent_troop, "$novicemaster_opponent_troop"),
  71327. (troop_set_slot, ":npc", slot_troop_trainer_training_difficulty, "$novice_training_difficulty"),
  71328. #add random equipment
  71329. (store_random_in_range, ":item_no", "itm_practice_sword", "itm_practice_shield"),
  71330. (troop_add_item, ":npc", ":item_no", imod_champion),
  71331. (store_sub, ":offset", ":npc", training_ground_trainers_begin),
  71332. #init grounds vars
  71333. (store_add, ":grounds", ":offset", training_grounds_begin),
  71334. (store_add, ":scene", ":offset", "scn_training_ground_ranged_melee_1"),
  71335. (party_set_slot, ":grounds", slot_grounds_melee, ":scene"),
  71336. (store_add, ":scene", ":offset", "scn_training_ground_horse_track_1"),
  71337. (party_set_slot, ":grounds", slot_grounds_track, ":scene"),
  71338. (party_set_slot, ":grounds", slot_grounds_trainer, ":npc"),
  71339. (party_set_slot, ":grounds", slot_grounds_count, "$g_training_ground_training_count"),
  71340. (troop_set_slot, ":npc", slot_troop_cur_center, ":grounds"),
  71341. (try_end),
  71342.  
  71343. #other tavern npc based on location
  71344. (try_for_range, ":town_no", towns_begin, towns_end),
  71345. (try_for_range, ":slot_no", slot_center_ransom_broker, slot_center_tavern_minstrel + 1),
  71346. (neq, ":slot_no", slot_center_traveler_info_faction),
  71347. (party_get_slot, ":npc", ":town_no", ":slot_no"),
  71348. (is_between, ":npc", ransom_brokers_begin, tavern_minstrels_end),
  71349. (troop_set_slot, ":npc", slot_troop_cur_center, ":town_no"),
  71350. (try_end),
  71351. (try_end),
  71352. (try_end),
  71353. #Ensure $character_gender is set correctly
  71354. (try_begin),
  71355. (call_script, "script_cf_dplmc_troop_is_female", "trp_player"),
  71356. (assign, "$character_gender", tf_female),
  71357. (else_try),
  71358. (assign, "$character_gender", tf_male),
  71359. (try_end),
  71360. ##diplomacy end+
  71361.  
  71362. (assign, reg1, ":save_reg1"),#Revert register
  71363. (assign, reg0, ":save_reg0"),#Revert register
  71364.  
  71365. ]),
  71366. ]
Add Comment
Please, Sign In to add comment