Splitting faction's lords - Fixed, Tutorial on post post #4

Users who are viewing this thread

mercury19

Sergeant at Arms
So I'm working on a personal project that involves adding 5 extra factions. I'm carving them out of the current factions, with 2 cities per faction. I've managed to create the cultures and assign the towns and such, but I'm running into trouble with the lords. Namely, that families are getting all messed up. Rather than add 20 new lords for each faction, I decided to split the existing factions, so half of the vaegir lords went to one of the new factions, and half of the ladies too. But the initialize aristocracy script was built for 20 lords per faction, so the factions are ending up all mixed up, with vaegir lords from the sultanate and stuff. Any suggestions?

Fixed! The solution is on the fourth post!
 
Yeah it's this part, just change the seed calculation (right now there's 1 ancestor seed per faction and npc seed's just the hero's relative position).
Code:
		(try_begin),
			(is_between, ":cur_troop", "trp_knight_1_1", "trp_knight_2_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_1_1"),
			(assign, ":ancestor_seed", 1),
		(else_try),
			(is_between, ":cur_troop", "trp_knight_2_1", "trp_knight_3_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_2_1"),
			(assign, ":ancestor_seed", 7),

		(else_try),
			(is_between, ":cur_troop", "trp_knight_3_1", "trp_knight_4_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_3_1"),
			(assign, ":ancestor_seed", 13),
		(else_try),
			(is_between, ":cur_troop", "trp_knight_4_1", "trp_knight_5_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_4_1"),
			(assign, ":ancestor_seed", 19),

		(else_try),
			(is_between, ":cur_troop", "trp_knight_5_1", "trp_knight_6_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_5_1"),
			(assign, ":ancestor_seed", 25),
		(else_try),
			(is_between, ":cur_troop", "trp_knight_6_1", "trp_kingdom_1_pretender"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
			(assign, ":ancestor_seed", 31),
		(try_end),
 
Ah I found my problem! I think. I had changed that area of the scripts, but I had also changed a ton more in lots of other places. Starting from a clean slate, I've discovered that all you have to do is add your faction to the script above, and add the extra lords. The number of lords doesn't really matter, but the number of ladies does, or at least it appears to. There have to be 20 ladies, or it'll get all messed up. I'm going to do a bit more investigating and post my findings here, but as of now I've added 10 lords of one of the new factions and 20 ladies, and all of the relations seem to be fine.
 
I have found the solution!

Ok, the first part of this is that all the factions have to have the same number of Lords and Ladies, no exceptions. Also, the number of Lords and Ladies must be equal, or there will be either lords or ladies with no relations to anyone at all.

Next, go into the initialize_aristocracy script, in module_scripts.

Code:
("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),
		(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", "trp_knight_2_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_1_1"),
			(assign, ":ancestor_seed", 1),

		(else_try),
			(is_between, ":cur_troop", "trp_knight_2_1", "trp_knight_3_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_2_1"),
			(assign, ":ancestor_seed", 7),

		(else_try),
			(is_between, ":cur_troop", "trp_knight_3_1", "trp_knight_4_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_3_1"),
			(assign, ":ancestor_seed", 13),

		(else_try),
			(is_between, ":cur_troop", "trp_knight_4_1", "trp_knight_5_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_4_1"),
			(assign, ":ancestor_seed", 19),

		(else_try),
			(is_between, ":cur_troop", "trp_knight_5_1", "trp_knight_6_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_5_1"),
			(assign, ":ancestor_seed", 25),

		(else_try),
			(is_between, ":cur_troop", "trp_knight_6_1", "trp_knight_7_1"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_6_1"),
			(assign, ":ancestor_seed", 31),
			
		(else_try),
			(is_between, ":cur_troop", "trp_knight_7_1", "trp_kingdom_1_pretender"),
			(store_sub, ":npc_seed", ":cur_troop", "trp_knight_7_1"),
			(assign, ":ancestor_seed", 37),

		(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),
			##diplomacy end+

			#daughter
			##diplomacy start+
			(try_begin),
			##diplomacy end+
				(troop_set_slot, ":cur_lady", slot_troop_father, ":cur_troop"),
				(store_sub, ":mother", ":cur_lady", 1),
				(call_script, "script_init_troop_age", ":cur_lady", 19),
			##diplomacy start+
				#fix native bug (daughters are their own mothers)
				#(troop_set_slot, ":cur_lady", slot_troop_mother, ":cur_lady"),
				(troop_set_slot, ":cur_lady", slot_troop_mother, ":mother"),
				(try_begin),
					#swap father and mother slots if the lord was female (do nothing if both were female)
					(call_script, "script_dplmc_store_is_female_troop_1_troop_2", ":cur_troop", ":mother"),
					(neq, reg0, 0),#:cur_troop is female
					(eq, reg1, 0),#:mother is not female
					(troop_set_slot, ":cur_lady", slot_troop_mother, ":cur_troop"),
					(troop_set_slot, ":cur_lady", slot_troop_father, ":mother"),
				(try_end),
			##diplomacy end+
				(store_random_in_range, ":lady_reputation", lrep_conventional, 34), #33% chance of father-derived
				(try_begin),
					(le, ":lady_reputation", 25),
					(troop_set_slot, ":cur_lady", slot_lord_reputation_type, ":lady_reputation"),
				(else_try),
					(eq, ":lady_reputation", 26),
					(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_conventional),
				(else_try),
					(eq, ":lady_reputation", 27),
					(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_moralist),
				(else_try),
					(assign, ":guardian_reputation", ":reputation"),
					(try_begin),
						(this_or_next|eq, ":guardian_reputation", lrep_martial),
							(eq, ":guardian_reputation", 0),
						(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_conventional),
					(else_try),
						(eq, ":guardian_reputation", lrep_quarrelsome),
						(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_otherworldly),
					(else_try),
						(eq, ":guardian_reputation", lrep_selfrighteous),
						(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_ambitious),
					(else_try),
						(eq, ":guardian_reputation", lrep_cunning),
						(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_adventurous),
					(else_try),
						(eq, ":guardian_reputation", lrep_goodnatured),
						(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_adventurous),
					(else_try),
						(eq, ":guardian_reputation", lrep_debauched),
						(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_ambitious),
					(else_try),
						(eq, ":guardian_reputation", lrep_upstanding),
						(troop_set_slot, ":cur_lady", slot_lord_reputation_type, lrep_moralist),
					(try_end),
				(try_end),

				(call_script, "script_add_lady_items", ":cur_lady"),
				(val_add, ":cur_lady", 1),
			##diplomacy start+
			(try_end),
			##diplomacy end+
			#high renown

		(else_try),	#Older unmarried lords
			(is_between, ":npc_seed", 8, 12),

			(store_random_in_range, ":age", 25, 36),
			##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:
				(store_random_in_range, ":reputation", 0, 8),
			(try_end),
			##diplomacy end+

			(store_random_in_range, ":sister_reputation", 20, 26),
			(try_begin),
				(eq, ":sister_reputation", 20),
				(assign, ":sister_reputation", lrep_conventional),
			(try_end),
			(troop_set_slot, ":cur_lady", slot_lord_reputation_type, ":sister_reputation"),

			(troop_set_slot, ":cur_lady", slot_troop_guardian, ":cur_troop"),
			##diplomacy start+
			#Initialize parents
			(try_begin),
				(troop_slot_eq, ":cur_troop", slot_troop_father, -1),
				(store_mul, ":new_index", ":cur_troop", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),#defined in module_constants.py
				(val_add, ":new_index", DPLMC_VIRTUAL_RELATIVE_FATHER_OFFSET),#defined in module_constants.py
				(troop_set_slot, ":cur_troop", slot_troop_father, ":new_index"),
				(troop_slot_eq, ":cur_lady", slot_troop_father, -1),
				(troop_set_slot, ":cur_lady", slot_troop_father, ":new_index"),
			(try_end),
			(try_begin),
				(troop_slot_eq, ":cur_troop", slot_troop_mother, -1),
				(store_mul, ":new_index", ":cur_troop", DPLMC_VIRTUAL_RELATIVE_MULTIPLIER),#defined in module_constants.py
				(val_add, ":new_index", DPLMC_VIRTUAL_RELATIVE_MOTHER_OFFSET),#defined in module_constants.py
				(troop_set_slot, ":cur_troop", slot_troop_mother, ":new_index"),
				(troop_slot_eq, ":cur_lady", slot_troop_mother, -1),
				(troop_set_slot, ":cur_lady", slot_troop_mother, ":new_index"),
			(try_end),
			##diplomacy end+

			(call_script, "script_init_troop_age", ":cur_lady", 21),
			(call_script, "script_add_lady_items", ":cur_lady"),

			(val_add, ":cur_lady", 1),

		(else_try),	#Younger unmarried lords
			#age is father's minus 20 to 25
			(store_sub, ":father", ":cur_troop", 12),
			##diplomacy start+
			#Some submods don't pay attention to this aspect of the troop list, and
			#so initialization produces absurd or impossible results.  Prevent such
			#things from appearing in the game.
			(try_begin),
				#"father" can be father or mother
				#(troop_get_type, ":parent_type", ":father"),
				(try_begin),
					#(eq, ":parent_type", tf_female),
					(call_script, "script_cf_dplmc_troop_is_female", ":father"),
					(assign, ":parent_slot", slot_troop_mother),
					(assign, ":other_parent_slot", slot_troop_father),
				(else_try),
					(assign, ":parent_slot", slot_troop_father),
					(assign, ":other_parent_slot", slot_troop_mother),
				(try_end),

				(troop_slot_eq, ":cur_troop", ":parent_slot", -1),
				(store_add, ":logical_minimum_age", ":father_age_at_birth", 16),
				(troop_slot_ge, ":father", slot_troop_age, ":logical_minimum_age"),
				#Passed test
				(troop_set_slot, ":cur_troop", ":parent_slot", ":father"),
				#Set mother if not already specified
				(try_begin),
					(troop_slot_eq, ":cur_troop", ":other_parent_slot", -1),
					(troop_get_slot, ":mother", ":father", slot_troop_spouse),
					(troop_set_slot, ":cur_troop", ":other_parent_slot", ":mother"),
				(try_end),

				(troop_get_slot, ":father_age", ":father", slot_troop_age),
				(store_sub, ":age", ":father_age", ":father_age_at_birth"),

				(troop_get_slot, ":reputation", ":cur_troop", slot_lord_reputation_type),
				(try_begin),
					#Don't change reputation if it already has been set
					(lt, ":reputation", 1),
					#50% chance of having father's rep
					(store_random_in_range, ":reputation", 0, 16),

					(gt, ":reputation", 7),
					(troop_get_slot, ":reputation", ":father", slot_lord_reputation_type),
				(try_end),
			(else_try),
				#Average age is [45,63] minus [23,25], so [22, 38]
				(store_random_in_range, ":age", 22, 39),
				(troop_get_slot, ":reputation", ":cur_troop", slot_lord_reputation_type),
				#Don't change reputation if it already has been set
				(lt, ":reputation", 1),
				(store_random_in_range, ":reputation", 0, 8),
			(try_end),
			#diplomacy end+
		(try_end),

		(try_begin),
			(eq, ":reputation", 0),
			(assign, ":reputation", 1),
		(try_end),

        (troop_set_slot, ":cur_troop", slot_lord_reputation_type, ":reputation"),

		(call_script, "script_init_troop_age", ":cur_troop", ":age"),
	  (try_end),

	  (try_begin),
	    (eq, "$cheat_mode", 1),
	    (assign, reg3, "$cheat_mode"),
	    (display_message, "@{!}DEBUG -- Assigned lord reputation and relations"),

#	    (display_message, "str_assigned_lord_reputation_and_relations_cheat_mode_reg3"), #This string can be removed
	  (try_end),

	  (try_for_range, ":cur_troop", pretenders_begin, pretenders_end),
		(troop_set_slot, ":cur_troop", slot_troop_occupation, slto_inactive_pretender),
		(store_random_in_range, ":age", 25, 30),
		(troop_set_slot, ":cur_troop", slot_troop_age, ":age"),
		(eq, ":cur_troop", "trp_kingdom_5_pretender"),
		(troop_set_slot, ":cur_troop", slot_troop_age, 45),
	  (try_end),
	]),

Then find these lines of code:

(lt, ":npc_seed", 8

(is_between, ":npc_seed", 8, 12),

(store_sub, ":father", ":cur_troop", 12),

the first one will dictate how many of your lords are Patriarchs. The one's with wives and children.

The second one will dictate how many of your lords are not married, and have sisters, and don't have parents in game.

The third one will dictate the sons of the Patriarchs, who are unmarried.

I have 10 lords per faction, so I set the first number as 4, so I had 4 Patriarchs, the second two were 4 and 6, so I had 2 Brothers, and the last number was also 6, so I had 4 Sons. I then went into module_troops and commented out the 11th-20th lords and ladies for every single faction. Upon building the module and loading the game, I discovered that all of the family trees worked correctly!

When adding a faction, in this script even if you have a different number of lords and ladies, at the very top where it set's the ancestor_seeds, still add 6 to the number. I don't think changing that is necessary and it may mess things up. This is for the section of code that user Somebody posted in reply to my original post, above.

Let me know if you have any questions!
 
Back
Top Bottom