# Jrider + Begin new scripts
# TITLES v0.3.3 #####
# script troop_set_title_according_to_faction_gender_and_lands
# calculate and set new title for lords, ladies and companions
# use s0 and s1
# change v0.3: use s61 and reg10
("troop_set_title_according_to_faction_gender_and_lands",
[
(store_script_param, ":troop_no", 1),
(store_script_param, ":faction_no", 2),
# Find title index in strings block
# to use culture (if set) for player's faction title +
(try_begin),
(eq, ":faction_no", "fac_player_supporters_faction"), # limit change to player faction
# ensure the value is within valid active faction, the player may start with No Faction which would do strange things if used
(is_between, "$g_player_culture", kingdoms_begin, kingdoms_end), # that includes player faction
(assign, ":faction_no", "$g_player_culture"), # the global holds a faction so simply re-assign it to the local ":faction" variable.
(try_end),
# to use culture (if set) for player's faction title -
(store_sub, ":title_index", ":faction_no", kingdoms_begin), # 0 player, 1 swadian ...
# Ensure we process only npcs member of a kingdom, including player
(try_begin), # Npcs serving as lord and ladies
# v0.1 change +
(is_between, ":faction_no", kingdoms_begin, kingdoms_end), # normaly this one should exclude companions that are not vassals
(neg|is_between, ":troop_no", pretenders_begin, pretenders_end), # exclude pretenders
(this_or_next|is_between, ":troop_no", active_npcs_begin, kingdom_ladies_end), # v0.3.1 change to include player
(eq, ":troop_no", "trp_player"), # include player player # v0.3.1 change
# (neq, ":troop_no", "trp_player"), # exclude player # v0.3.1 commented, wasn't relevant anyway
(faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
(str_store_troop_name_plural, s0, ":troop_no"),
# v0.1 change -
# External computation blocks
# Get Gender
(troop_get_type, ":gender", ":troop_no"),
# NPC's largest fief (works for male and female, compute spouse fief as well)
# 1 no fief, 2 village, 3 castle, 4 town
(assign, ":largest_fief", 0),
(try_for_range, ":cur_center", centers_begin, centers_end),
(troop_get_slot, ":spouse_no", ":troop_no", slot_troop_spouse),
(neq, ":troop_no", ":faction_leader"), # exclude research for ruler
(neq, ":spouse_no", ":faction_leader"), # exclude research for ruler's wife
(lt, ":largest_fief", 3),
(party_slot_ge, ":cur_center", slot_town_lord, 0),
(this_or_next|party_slot_eq, ":cur_center", slot_town_lord, ":spouse_no"),
(party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
(try_begin),
(party_slot_eq, ":cur_center", slot_party_type, spt_town),
(lt, ":largest_fief", 3),
(assign, ":largest_fief", 3),
(else_try),
(party_slot_eq, ":cur_center", slot_party_type, spt_castle),
(lt, ":largest_fief", 2),
(assign, ":largest_fief", 2),
(else_try),
(party_slot_eq, ":cur_center", slot_party_type, spt_village),
(lt, ":largest_fief", 1),
(assign, ":largest_fief", 1),
(try_end),
(try_end),
# base title(s) computation blocks
# Determine NPCs quality in order of importance
# for male NPCs: 4 Ruler, 3 town, 2 castle, 1 village, 0 landless
# for female NPCs: 5 unmarried (kingdom lady only), 4 queen, 3 wife or town, 2 wife or castle, 1 wife or village, 0 wife or landless
(assign, ":quality", 0),
(try_begin), # Male npcs
(eq, ":gender", 0),
(try_begin),
(eq, ":troop_no", ":faction_leader"), # is king
(assign, ":quality", 4),
(else_try),
(assign, ":quality", ":largest_fief"),
(try_end),
(else_try), # Female npcs, a bit more complex queen, landowner, companions without a fief,
(try_begin), # wife of faction leader
# v0.3.3 change +
(this_or_next|troop_slot_eq, ":troop_no", slot_troop_spouse, ":faction_leader"),
(eq, ":troop_no", ":faction_leader"), # is queen
# v0.3.3 change -
(assign, ":quality", 4),
(else_try), # is a landowner - index 1 to 3
(gt, ":largest_fief", 0),
(assign, ":quality", ":largest_fief"),
(else_try), # a companion vassal without fief
(is_between, ":troop_no", companions_begin, companions_end),
(assign, ":quality", 0),
(else_try), # married lady whose husband has no fief
(troop_slot_ge, ":troop_no", slot_troop_spouse, 0),
(assign, ":quality", 0),
(else_try), # unmarried lady without fief
(assign, ":quality", 5),
(try_end),
(try_end),
# v0.3 changes +
# compute troop relation to ruler suffix
#(try_begin),
# (neq, ":troop_no", ":faction_leader"), # exclude from suffix if king v0.3.2 change
#(call_script, "script_troop_get_relation_with_troop", ":troop_no", ":faction_leader"),
#(assign, ":relation", reg0),
#(str_clear, s61),
#(assign, reg10, 0),
#(try_begin), # update reg10
# (this_or_next|gt, ":relation", 19),
#(lt, ":relation", -19),
#(assign, reg10, ":relation"),
#(store_add, ":normalized_relation", ":relation", 100),
#(store_div, ":str_offset", ":normalized_relation", 20),
#(val_clamp, ":str_offset", 0, 10), # does 10 work ? only 10 strings in there
#(store_add, ":str_rel_id", "str_ruler_relation_mnus_100_ns", ":str_offset"),
#(str_store_string, s61, ":str_rel_id"),
#(try_end),
#(else_try), # clear register and string
# (str_clear, s61),
# (assign, reg10, 0),
#(try_end),
# v0.3 changes -
# Find title index in strings block
(store_sub, ":title_index", ":faction_no", kingdoms_begin), # 0 player, 1 swadian ...
(try_begin), #male, 5 title entries
(eq, ":gender", 0),
(val_mul, ":title_index", 5),
(val_add, ":title_index", kingdom_titles_male_begin),
(else_try), # female, 6 title entries
(val_mul, ":title_index", 6),
(val_add, ":title_index", kingdom_titles_female_begin),
(try_end),
(val_add, ":title_index", ":quality"),
# Set title and party name block
# assign title
(str_store_string, s1, ":title_index"),
(troop_set_name, ":troop_no", s1),
# rename party
(troop_get_slot, ":troop_party", ":troop_no", slot_troop_leaded_party),
(try_begin),
# v0.2 change to prevent opcode error
(gt, ":troop_party", 0),
(str_store_troop_name, s5, ":troop_no"),
(party_set_name, ":troop_party", "str_s5_s_party"),
(try_end), # v0.2 change
(try_end),
]),
# Special titles for companions not used as vassals
# (try_begin),
# (neg|eq, ":faction_no", "fac_player_supporters_faction"), # v0.2 change
# (neg|troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero), # v0.3 change, exclude companion if he became a kingdom lord
# (is_between, ":troop_no", companions_begin, companions_end),
# Store the plural name
# (str_store_troop_name_plural, s0, ":troop_no"),
# Set the title
# (try_begin), # Male npcs
# (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_player_companion),
# (str_store_string, s1, "str_hero_titles_party"),
# (else_try),
# (call_script, "script_get_troop_specialisation", ":troop_no", ":faction_no"),
# (assign, ":title_index", reg0),
# (val_add, ":title_index", hero_titles_begin),
# (str_store_string, s1, ":title_index"),
#(try_end),
# assign title
# (troop_set_name, ":troop_no", s1),
#(try_end),
# Script get_troop_specialisation
# Assess companion current skills to find the strongest trend
#("get_troop_specialisation",
#[
# (store_script_param, ":troop_no", 1),
# (store_script_param, ":faction_no", 2),
# (try_begin),
# (neg|eq, ":faction_no", "fac_player_supporters_faction"), # v0.2 change
# (is_between, ":troop_no", companions_begin, companions_end),
# Other titles according to function in group
# Scout (Ausculare) - PathFinding, Tracking and Spotting
# (store_skill_level, ":scout", "skl_spotting", ":troop_no"),
#(store_skill_level, ":scout_skill", "skl_pathfinding", ":troop_no"),
#(val_add, ":scout", ":scout_skill"),
#(store_skill_level, ":scout_skill", "skl_tracking", ":troop_no"),
#(val_add, ":scout", ":scout_skill"),
# Physician (Fisique) - Wound Treatment, Surgery, First Aid
#(store_skill_level, ":physician", "skl_wound_treatment", ":troop_no"),
#(store_skill_level, ":physician_skill", "skl_first_aid", ":troop_no"),
#(val_add, ":physician", ":physician_skill"),
#(store_skill_level, ":physician_skill", "skl_surgery", ":troop_no"),
#(val_add, ":physician", ":physician_skill"),
# Tactician (Tassein) - Tactics, Engineer, Trainer
#(store_skill_level, ":tactician", "skl_tactics", ":troop_no"),
#(store_skill_level, ":tactician_skill", "skl_engineer", ":troop_no"),
# (val_add, ":tactician", ":tactician_skill"),
# (store_skill_level, ":tactician_skill", "skl_trainer", ":troop_no"),
# (val_add, ":tactician", ":tactician_skill"),
# Trader (Empori) - Trade Looting, Foraging (foraging is a new skill I'm working on)
# (store_skill_level, ":trader", "skl_trade", ":troop_no"),
# (store_skill_level, ":trader_skill", "skl_looting", ":troop_no"),
# (val_add, ":trader", ":trader_skill"),
#(store_skill_level, ":trader_skill", "skl_foraging", ":troop_no"), # uncomment if using foraging
#(val_add, ":trader", ":trader_skill"), # uncomment if using foraging
# (val_mul, ":trader", 3), # comment if using foraging
# (val_div, ":trader", 2), # comment if using foraging
# Diplomat (Missi) - Persuasion
# (store_skill_level, ":diplomat", "skl_persuasion", ":troop_no"),
# (val_mul, ":diplomat", 3),
# (try_begin), # Just your basic hero
# (eq, ":diplomat", 0),
# (eq, ":tactician", 0),
# (eq, ":scout", 0),
# (eq, ":physician", 0),
# (eq, ":trader", 0),
# (assign, reg0, 0),
#(else_try), # Diplomat - skilled in Persuasion and Trainer
# (gt, ":diplomat", 0),
# (ge, ":diplomat", ":tactician"),
# (ge, ":diplomat", ":scout"),
#(ge, ":diplomat", ":physician"),
#(ge, ":diplomat", ":trader"),
#(assign, reg0, 1),
#(else_try), # Tactician - skilled in Tactics and Engineer
# (gt, ":tactician", 0),
# (ge, ":diplomat", ":scout"),
# (ge, ":diplomat", ":physician"),
#(ge, ":diplomat", ":trader"),
#(assign, reg0, 2),
#(else_try), # Scout - skilled in Spotting, Tracking and Pathfinding
# (gt, ":scout", 0),
# (ge, ":diplomat", ":physician"),
# (ge, ":diplomat", ":trader"),
#(assign, reg0, 3),
#(else_try), # Physician - skilled in Wound Treatment, Surgery and First Aid
# (gt, ":physician", 0),
# (ge, ":physician", ":trader"),
# (assign, reg0, 4),
#(else_try), # Trader - skilled in Trade
# (gt, ":trader", 0),
# (assign, reg0, 5),
#(try_end),
#(try_end),
# ]),
# Jrdier -