("initialize_aristocracy",
[
#LORD OCCUPATIONS, BLOOD RELATIONSHIPS, RENOWN AND REPUTATIONS
#King ages
(try_for_range, ":cur_troop", kings_begin, kings_end),
(troop_set_slot, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
(store_random_in_range, ":age", 50, 60),
(troop_set_slot, ":cur_troop", slot_troop_age, ":age"),
##diplomacy start+
#(eq, ":cur_troop", "trp_kingdom_5_lord"),#<-- There was no reason for this to be in the loop, so moved it out.
#(troop_set_slot, ":cur_troop", slot_troop_age, 47),
(try_end),
(troop_set_slot, "trp_kingdom_5_lord", slot_troop_age, 47),#<-- Moved from above
##diplomacy end+
#The first thing - family structure
#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
#lords 9 to 12 are unmarried landowners with sisters
#lords 13 to 20 are sons who still live in their fathers' houses
#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
(try_for_range, ":cur_troop", kingdom_ladies_begin, kingdom_ladies_end),
(troop_set_slot, ":cur_troop", slot_troop_occupation, slto_kingdom_lady),
(try_end),
(assign, ":cur_lady", "trp_kingdom_1_lady_1"),
(try_for_range, ":cur_troop", lords_begin, lords_end),
##Tocan Invasion
# NE test for family relations
(neq, ":cur_troop", "trp_dark_knight_lord"),
(neq, ":cur_troop", "trp_dark_knight_lord1"),
(neq, ":cur_troop", "trp_dark_knight_lord2"),
(neq, ":cur_troop", "trp_dark_knight_lord3"),
(neq, ":cur_troop", "trp_dark_knight_lord4"),
(neq, ":cur_troop", "trp_dark_knight_lord5"),
(neq, ":cur_troop", "trp_dark_knight_lord6"),
(neq, ":cur_troop", "trp_dark_knight_lord7"),
(neq, ":cur_troop", "trp_dark_knight_lord8"),
(neq, ":cur_troop", "trp_dark_knight_lord9"),
(neq, ":cur_troop", "trp_dark_knight_lord10"),
(neq, ":cur_troop", "trp_dark_knight_lord11"),
(neq, ":cur_troop", "trp_dark_knight_lord12"),
(neq, ":cur_troop", "trp_dark_knight_lord13"),
(neq, ":cur_troop", "trp_dark_knight_lord14"),
(neq, ":cur_troop", "trp_dark_knight_lord15"),
(neq, ":cur_troop", "trp_dark_knight_lord16"),
(neq, ":cur_troop", "trp_dark_knight_lord17"),
(neq, ":cur_troop", "trp_dark_knight_lord18"),
(neq, ":cur_troop", "trp_dark_knight_lord19"),
(neq, ":cur_troop", "trp_dark_knight_lord20"),
# Ne end
(troop_set_slot, ":cur_troop", slot_troop_occupation, slto_kingdom_hero),
(store_random_in_range, ":father_age_at_birth", 23, 26),
# (store_random_in_range, ":mother_age_at_birth", 19, 22),
(try_begin),
(is_between, ":cur_troop", "trp_knight_1_1", "knight_2_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_1_1"),
(assign, ":ancestor_seed", 1),
(else_try),
(is_between, ":cur_troop", "knight_2_1", "knight_3_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_2_1"),
(assign, ":ancestor_seed", 7),
(else_try),
(is_between, ":cur_troop", "knight_3_1", "knight_4_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_3_1"),
(assign, ":ancestor_seed", 13),
(else_try),
(is_between, ":cur_troop", "knight_4_1", "knight_5_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_4_1"),
(assign, ":ancestor_seed", 19),
(else_try),
(is_between, ":cur_troop", "knight_5_1", "knight_6_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_5_1"),
(assign, ":ancestor_seed", 25),
(else_try),
(is_between, ":cur_troop", "knight_6_1", "knight_tra_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
(assign, ":ancestor_seed", 31),
(else_try),
(is_between, ":cur_troop", "knight_tra_1", "knight_gau_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
(assign, ":ancestor_seed", 37),
(else_try),
(is_between, ":cur_troop", "knight_gau_1", "knight_ibe_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
(assign, ":ancestor_seed", 43),
(else_try),
(is_between, ":cur_troop", "knight_ibe_1", "knight_gr1_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
(assign, ":ancestor_seed", 49),
(else_try),
(is_between, ":cur_troop", "knight_gr1_1", "knight_gr2_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
(assign, ":ancestor_seed", 55),
(else_try),
(is_between, ":cur_troop", "knight_gr2_1", "knight_gr3_1"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
(assign, ":ancestor_seed", 61),
(else_try),
(is_between, ":cur_troop", "knight_gr3_1", "trp_kingdom_1_pretender"),
(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
(assign, ":ancestor_seed", 67),
(try_end),
(try_begin),
(lt, ":npc_seed", 8), #NPC seed is the order in the faction
##diplomacy start+ do not overwrite reputation if it was already set explicitly
(troop_get_slot, ":reputation", ":cur_troop", slot_lord_reputation_type),
(try_begin),
(lt, ":reputation", 1),
#Original behavior:
(assign, ":reputation", ":npc_seed"),
(try_end),
##diplomacy end+
(store_random_in_range, ":age", 45, 64),
##diplomacy start+ only set father if not already set
(try_begin),#<- dplmc+ added
(troop_slot_eq, ":cur_troop", slot_troop_father, -1),#<- dplmc+ added
(store_random_in_range, ":father", 0, 3), #six possible fathers
(val_add, ":father", ":ancestor_seed"),
(troop_set_slot, ":cur_troop", slot_troop_father, ":father"),
(try_end),#<- dplmc+ added
##diplomacy end+
#wife
##diplomacy start+ do not rebind an already-set wife
(try_begin),
(troop_slot_eq, ":cur_troop", slot_troop_spouse, -1),
#There may be a better solution, but to avoid oddities disable automatic spouses if there is a gender mismatch.
#Mods that add additional races may want to tweak this (for example if some races shouldn't intermarry).
(call_script, "script_dplmc_store_is_female_troop_1_troop_2", ":cur_troop", ":cur_lady"),
#Types are stored to reg0 and reg1.
(neq, reg0, reg1),#lord and lady aren't both female or both non-female
(val_mul, reg0, reg1),
(eq, reg0, 0),#at least one of lord or lady is non-female
##diplomacy end+
(troop_set_slot, ":cur_troop", slot_troop_spouse, ":cur_lady"),
(troop_set_slot, ":cur_lady", slot_troop_spouse, ":cur_troop"),
(store_random_in_range, ":wife_reputation", 20, 26),
(try_begin),
(eq, ":wife_reputation", 20),
(assign, ":wife_reputation", lrep_conventional),
(try_end),
(troop_set_slot, ":cur_lady", slot_lord_reputation_type, ":wife_reputation"),
(call_script, "script_init_troop_age", ":cur_lady", 49),
(call_script, "script_add_lady_items", ":cur_lady"),
(val_add, ":cur_lady", 1),
##diplomacy start+
(try_end),