#Individual lord political calculations
#Check for lords without fiefs, auto-defections, etc
(0.5,
[
##diplomacy start+
#This is fairly complicated, and it was getting nearly unreadable so I reformatted it.
#The old version is visible in version control.
(assign, ":save_reg0", reg0),
(val_add, "$g_lord_long_term_count", 1),
(try_begin),
(neg|is_between, "$g_lord_long_term_count", active_npcs_including_player_begin, active_npcs_end),
(assign, "$g_lord_long_term_count", active_npcs_including_player_begin),
(try_end),
##Add political calculations for kingdom ladies. Just extending the range would
##slow down the political calculations cycle, which would have possibly-unforeseen results.
##Instead, add a second iteration to deal with extensions.
(try_for_range, ":iteration", 0, 2),
(assign, ":troop_no", "$g_lord_long_term_count"),
(try_begin),
(eq, ":iteration", 1),
(val_sub, ":troop_no", active_npcs_including_player_begin),
(val_add, ":troop_no", active_npcs_end),
(try_end),
#Crude check to make sure that a careless modder (i.e. me) didn't decide it
#would be a good idea to redefine active_npcs to include kingdom_ladies,
#which would make the second iteration run off the end of the heroes list.
(is_between, ":troop_no", active_npcs_including_player_begin, heroes_end),
#Special handling for trp_player, and get the troop's faction
(try_begin),
(eq, ":troop_no", "trp_kingdom_heroes_including_player_begin"),
(assign, ":troop_no", "trp_player"),
(assign, ":faction", "$players_kingdom"),
(else_try),
(store_faction_of_troop, ":faction", ":troop_no"),
(try_end),
(try_begin),
(eq, "$cheat_mode", 1),
(str_store_troop_name, s9, ":troop_no"),
(display_message, "@{!}DEBUG -- Doing political calculations for {s9}"),
(try_end),
#Tally the fiefs owned by the hero, and cache the value in slot.
#If a lord owns no fiefs, his relations with his liege may deteriorate.
(try_begin),
(assign, reg0, 1),#Center points + 1
(try_for_range, ":center", centers_begin, centers_end),
(party_slot_eq, ":center", slot_town_lord, ":troop_no"),
(try_begin),
(is_between, ":center", towns_begin, towns_end),
(val_add, reg0, 3),#3 points per town
(else_try),
(is_between, ":center", walled_centers_begin, walled_centers_end),
(val_add, reg0, 2),#2 points per castle
(else_try),
(val_add, reg0, 1),#1 point per village
(try_end),
(try_end),
#Update cached total
(troop_set_slot, ":troop_no", dplmc_slot_troop_center_points_plus_one, reg0),
#If a lord has no fiefs, relation loss potentially results.
#Do not apply this to the player.
(eq, reg0, 1),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(neq, ":troop_no", "trp_player"),
#Don't apply this to the leader
(faction_get_slot, ":faction_leader", ":faction", slot_faction_leader),
(gt, ":faction_leader", -1),
(neq, ":faction_leader", ":troop_no"),
(neg|troop_slot_eq, ":faction_leader", slot_troop_spouse, ":troop_no"),
(neg|troop_slot_eq, ":troop_no", slot_troop_spouse, ":faction_leader"),
(troop_get_slot, ":troop_reputation", ":troop_no", slot_lord_reputation_type),
(try_begin),
(this_or_next|eq, ":troop_reputation", lrep_quarrelsome),
(this_or_next|eq, ":troop_reputation", lrep_selfrighteous),
(this_or_next|eq, ":troop_reputation", lrep_cunning),
(eq, ":troop_reputation", lrep_debauched),
(call_script, "script_troop_change_relation_with_troop", ":troop_no", ":faction_leader", -4),
(val_add, "$total_no_fief_changes", -4),
(else_try),
(this_or_next|eq, ":troop_reputation", lrep_ambitious),#add support for lady personalities
(eq, ":troop_reputation", lrep_martial),
(call_script, "script_troop_change_relation_with_troop", ":troop_no", ":faction_leader", -2),
(val_add, "$total_no_fief_changes", -2),
(try_end),
(try_end),