From 7bf97df8b9a66f5c9497085f63ac91a9fbddc4f3 Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 05:41:50 +0000
Subject: [PATCH 1/9] Fix missing ruling style for null character.

---
 Regula_Magistri/common/traits/regula_traits.txt              | 5 +++++
 .../localization/english/regula_traits_l_english.yml         | 5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Regula_Magistri/common/traits/regula_traits.txt b/Regula_Magistri/common/traits/regula_traits.txt
index 34b0f3a8..6ad60ecd 100644
--- a/Regula_Magistri/common/traits/regula_traits.txt
+++ b/Regula_Magistri/common/traits/regula_traits.txt
@@ -664,6 +664,11 @@ paelex = {
 		}
 		first_valid = {
 			# Add Economical archtype
+			# Fallback - No Character
+			triggered_desc = {
+				trigger = { NOT = { exists = this } }
+				desc = trait_paelex_ruling_style_none
+			}
 			# Warlike
 			triggered_desc = {
 				trigger = { ai_has_warlike_personality = yes }
diff --git a/Regula_Magistri/localization/english/regula_traits_l_english.yml b/Regula_Magistri/localization/english/regula_traits_l_english.yml
index 44c01850..c311b63d 100644
--- a/Regula_Magistri/localization/english/regula_traits_l_english.yml
+++ b/Regula_Magistri/localization/english/regula_traits_l_english.yml
@@ -46,8 +46,8 @@
 	trait_tropaeum_character_desc:0 "[ROOT.GetCharacter.GetFirstNameNoTooltip] has been claimed as a trophy of your conquest. Her head bows in subservience."
 
 	trait_paelex:0 "Paelex"
-	trait_paelex_desc:0 "This woman belongs to you, body and soul. Her words carry an echo of your will."
-	trait_paelex_character_desc:0 "[ROOT.GetCharacter.GetFirstNameNoTooltip] belongs to you, body and soul. Her words carry an echo of your will."
+	trait_paelex_desc:0 "This woman belongs to you, body and soul."
+	trait_paelex_character_desc:0 "[ROOT.GetCharacter.GetFirstNameNoTooltip] belongs to you, body and soul."
 
 	# Paelex Extra Titles/Descs
 		trait_paelex_regina:0 "Regina"
@@ -60,6 +60,7 @@
 		trait_paelex_comitissa_desc:0 "[ROOT.GetCharacter.GetFirstNameNoTooltip] belongs to you, body and soul."
 
 		# Extra loc for flavour
+		trait_paelex_ruling_style_none:0 "Her words carry an echo of your will."
 		trait_paelex_ruling_style_warlike:0 "She rules [ROOT.GetCharacter.GetPrimaryTitle.GetNameNoTooltip], ensuring that your Famuli are trained and ready for war at a moments notice, to ensure the spread of your rule."
 		trait_paelex_ruling_style_cautious:0 "She rules [ROOT.GetCharacter.GetPrimaryTitle.GetNameNoTooltip], constantly preparing for the defense of your beloved Famuli and realm by training warriors and building defenses."
 		trait_paelex_ruling_style_builder:0 "She rules [ROOT.GetCharacter.GetPrimaryTitle.GetNameNoTooltip], investing heavily in infrastructure to meet the demands of your swelling Famuli population."
-- 
GitLab


From 0e3ea0ab26636a50ad8c809481c9ed177d029787 Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 05:46:54 +0000
Subject: [PATCH 2/9] Fix no longer valid in_activity_type

---
 Regula_Magistri/common/activities/intents/regula_intents.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Regula_Magistri/common/activities/intents/regula_intents.txt b/Regula_Magistri/common/activities/intents/regula_intents.txt
index 476db9cd..7e438276 100644
--- a/Regula_Magistri/common/activities/intents/regula_intents.txt
+++ b/Regula_Magistri/common/activities/intents/regula_intents.txt
@@ -41,7 +41,7 @@ regula_heal_intent = {
 			text = orgy_heal_intent_limit
 			trigger_if = {
 				limit = {
-					in_activity_type = activity_regula_orgy
+					involved_activity ?= { has_activity_type = activity_regula_orgy }
 				}
 				NOT = { has_completed_activity_intent = regula_heal_intent }
 			}
@@ -191,7 +191,7 @@ regula_recruit_intent = {
 			text = orgy_recruit_intent_limit
 			trigger_if = {
 				limit = {
-					in_activity_type = activity_regula_orgy
+					involved_activity ?= { has_activity_type = activity_regula_orgy }
 					exists = var:orgy_recruit_number
 				}
 				var:orgy_recruit_number < 3
-- 
GitLab


From 24bc8607aeff933245cdb1b9e57a3bfe8b5693f7 Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 05:50:17 +0000
Subject: [PATCH 3/9] Replace also seemingly invalid is_culture_head?

---
 Regula_Magistri/common/decisions/regula_holy_order_decision.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Regula_Magistri/common/decisions/regula_holy_order_decision.txt b/Regula_Magistri/common/decisions/regula_holy_order_decision.txt
index 8c2b9fba..c3c01875 100644
--- a/Regula_Magistri/common/decisions/regula_holy_order_decision.txt
+++ b/Regula_Magistri/common/decisions/regula_holy_order_decision.txt
@@ -365,8 +365,8 @@ regula_create_holy_order_decision = {
 		# Discover Virgo innovation into Magister culture if its not already unlocked
 		if = {
 			limit = {
-				is_culture_head = yes
 				culture = {
+					culture_head ?= root
 					NOT = { has_innovation = innovation_regula_virgo_training }
 				}
 			}
-- 
GitLab


From 7db79aa02c116cc5153cd9c6093087439b9d6349 Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 05:55:24 +0000
Subject: [PATCH 4/9] Handle case for revela_secretum where secret doesn't have
 a target.

---
 .../regula_ai_character_interactions.txt                      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Regula_Magistri/common/character_interactions/regula_ai_character_interactions.txt b/Regula_Magistri/common/character_interactions/regula_ai_character_interactions.txt
index 1ac073f8..21c0747f 100644
--- a/Regula_Magistri/common/character_interactions/regula_ai_character_interactions.txt
+++ b/Regula_Magistri/common/character_interactions/regula_ai_character_interactions.txt
@@ -601,7 +601,7 @@ revela_secretum = {
 					any_secret = { # There's something to discover
 						NOR = {
 							is_known_by = scope:actor
-							secret_target = scope:recipient
+							secret_target ?= scope:recipient
 						}
 					}
 				}
@@ -609,7 +609,7 @@ revela_secretum = {
 					limit = {
 						NOR = {
 							is_known_by = scope:actor
-							secret_target = scope:recipient
+							secret_target ?= scope:recipient
 						} # Hilarious as it is, they shouldn't be revealing their own secrets.
 					}
 					weight = {
-- 
GitLab


From aab6e4201090faebff1bd3bec7f8e59530d53aa9 Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 06:09:20 +0000
Subject: [PATCH 5/9] Fix some behavior with abice_maritus due to attempting to
 transfer capital baronies & spouse movement effects being performed in the
 wrong scope.

---
 .../regula_character_interactions_court.txt   | 123 +++++++++---------
 1 file changed, 62 insertions(+), 61 deletions(-)

diff --git a/Regula_Magistri/common/character_interactions/regula_character_interactions_court.txt b/Regula_Magistri/common/character_interactions/regula_character_interactions_court.txt
index 360d9670..247d5c55 100644
--- a/Regula_Magistri/common/character_interactions/regula_character_interactions_court.txt
+++ b/Regula_Magistri/common/character_interactions/regula_character_interactions_court.txt
@@ -1109,6 +1109,10 @@ regula_enact_abice_maritus_interaction = {
 				add_claim_on_loss = no
 			}
 			every_held_title = {
+				limit = {
+					is_capital_barony = no
+				}
+
 				change_title_holder_include_vassals = {
 					holder = scope:recipient
 					change = scope:change
@@ -1125,81 +1129,78 @@ regula_enact_abice_maritus_interaction = {
 		}
 
 		scope:recipient.primary_spouse = {
-			scope:recipient = {
-				if = {
-					limit = {
-						scope:recipient.top_liege = { # This is going to be of limited utility for foreign Mulsa.
-							any_vassal_or_below = {
-								has_government = theocracy_government
-								primary_title.tier > tier_barony
-								faith = scope:actor.faith
-							}
-						}
-					}
-					scope:recipient.top_liege = {
-						random_vassal_or_below = {
-							limit = {
-								has_government = theocracy_government
-								primary_title.tier > tier_barony
-								faith = scope:actor.faith
-							}
-							save_scope_as = theocratic_travel_target
-						}
-					}
-					visit_court_of = scope:theocratic_travel_target
+			add_opinion = {
+				modifier = demanded_taking_vows
+				target = scope:recipient
+			}
+			add_trait = devoted
+			add_piety_level = 1
+			if = {
+				limit = { is_ruler = yes }
+				depose = yes
+			}
+			if = {
+				limit = {
+					is_married = yes
 				}
-				else_if = {
-					limit = {
-						exists = scope:recipient.capital_province
-					}
-					move_to_pool_at = scope:recipient.capital_province
+				every_spouse = {
+					divorce = scope:recipient.primary_spouse
 				}
-				kick_from_court_interaction_warning_tooltip_effect = yes
 			}
-			scope:recipient.primary_spouse = {
-				add_opinion = {
-					modifier = demanded_taking_vows
-					target = scope:recipient
+			if = {
+				limit = {
+					exists = betrothed
 				}
-				add_trait = devoted
-				add_piety_level = 1
-				if = {
-					limit = { is_ruler = yes }
-					depose = yes
+				break_betrothal = betrothed
+			}
+			if = {
+				limit = {
+					is_concubine = yes
 				}
-				if = {
-					limit = {
-						is_married = yes
-					}
-					every_spouse = {
-						divorce = scope:recipient.primary_spouse
-					}
+				this.concubinist = {
+					remove_concubine = scope:recipient.primary_spouse
 				}
-				if = {
-					limit = {
-						exists = betrothed
-					}
-					break_betrothal = betrothed
+			}
+			if = {
+				limit = {
+					number_of_concubines > 0
 				}
-				if = {
-					limit = {
-						is_concubine = yes
-					}
-					this.concubinist = {
-						remove_concubine = scope:recipient.primary_spouse
+				every_concubine = {
+					scope:recipient = {
+						remove_concubine = prev
 					}
 				}
-				if = {
-					limit = {
-						number_of_concubines > 0
+			}
+
+			if = {
+				limit = {
+					scope:recipient.top_liege = { # This is going to be of limited utility for foreign Mulsa.
+						any_vassal_or_below = {
+							has_government = theocracy_government
+							primary_title.tier > tier_barony
+							faith = scope:actor.faith
+						}
 					}
-					every_concubine = {
-						scope:recipient = {
-							remove_concubine = prev
+				}
+				scope:recipient.top_liege = {
+					random_vassal_or_below = {
+						limit = {
+							has_government = theocracy_government
+							primary_title.tier > tier_barony
+							faith = scope:actor.faith
 						}
+						save_scope_as = theocratic_travel_target
 					}
 				}
+				visit_court_of = scope:theocratic_travel_target
+			}
+			else_if = {
+				limit = {
+					exists = scope:recipient.capital_province
+				}
+				move_to_pool_at = scope:recipient.capital_province
 			}
+			kick_from_court_interaction_warning_tooltip_effect = yes
 		}
 	}
 
-- 
GitLab


From 9ea8416ac92fd818a0674de2a2e678d02db7123e Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 06:16:58 +0000
Subject: [PATCH 6/9] Guard against null culture head.

---
 .../common/culture/traditions/regula_traditions.txt  | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Regula_Magistri/common/culture/traditions/regula_traditions.txt b/Regula_Magistri/common/culture/traditions/regula_traditions.txt
index b2f9c2f6..19688483 100644
--- a/Regula_Magistri/common/culture/traditions/regula_traditions.txt
+++ b/Regula_Magistri/common/culture/traditions/regula_traditions.txt
@@ -28,7 +28,7 @@ tradition_famuli_warriors = {
 	# Assumes player is a culture head, and has Regula religion
 	# This is a fallback pick anyway, as you normally get this via the decision
 	can_pick = {
-		culture_head = {
+		culture_head ?= {
 			has_religion = religion:regula_religion
 		}
 		has_cultural_pillar = martial_custom_regula
@@ -84,7 +84,7 @@ tradition_famuli_enslavers = {
 	}
 
 	can_pick = {
-		culture_head = {
+		culture_head ?= {
 			has_religion = religion:regula_religion
 			custom_tooltip = {
 				text = require_enslaver_accolade_knight
@@ -154,7 +154,7 @@ tradition_magistri_submission = {
 	# Assumes player is a culture head, and has Regula religion
 	# This is a fallback pick anyway, as you normally get this via the decision
 	can_pick = {
-		culture_head = {
+		culture_head ?= {
 			has_religion = religion:regula_religion
 		}
 	}
@@ -207,7 +207,7 @@ tradition_magistri_submission = {
 			# Tradition is free if we already have the Regula religion
 			if = {
 				limit = {
-					culture_head = {
+					culture_head ?= {
 						has_religion = religion:regula_religion
 					}
 				}
@@ -238,7 +238,7 @@ tradition_magister_bloodline = {
 
 	# Assumes player is a culture head, and has Regula religion
 	can_pick = {
-		culture_head = {
+		culture_head ?= {
 			has_religion = religion:regula_religion
 		}
 	}
@@ -264,7 +264,7 @@ tradition_magister_bloodline = {
 			# Tradition is free if we already have the Regula religion
 			if = {
 				limit = {
-					culture_head = {
+					culture_head ?= {
 						has_religion = religion:regula_religion
 					}
 				}
-- 
GitLab


From 2a611c890ed442d2d45e8a714551dfa3d3aa70f0 Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 06:34:30 +0000
Subject: [PATCH 7/9] Split curo privignos event description up to handle the
 case with null father or mother (the second of which technically shouldn't
 happen...but symmetry or something...).

---
 .../regula_privignos_events.txt                | 18 +++++++++++++++---
 .../regula_privignos_events_l_english.yml      |  5 ++++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/Regula_Magistri/events/relations_events/regula_privignos_events.txt b/Regula_Magistri/events/relations_events/regula_privignos_events.txt
index ae9e91cf..343cc797 100644
--- a/Regula_Magistri/events/relations_events/regula_privignos_events.txt
+++ b/Regula_Magistri/events/relations_events/regula_privignos_events.txt
@@ -4,7 +4,19 @@
 regula_curo_privignos_event.0001 = {
 	type = character_event
 	title = regula_curo_privignos_event.0001.t
-	desc = regula_curo_privignos_event.0001.desc
+	desc = {
+		desc = regula_curo_privignos_event.0001.desc_start
+		triggered_desc = {
+			trigger = { exists = scope:father_stepchild }
+			desc = regula_curo_privignos_event.0001.desc_father
+		}
+		desc = double_line_break
+		triggered_desc = {
+			trigger = { exists = scope:mother_stepchild }
+			desc = regula_curo_privignos_event.0001.desc_mother
+		}
+		desc = regula_curo_privignos_event.0001.desc_end
+	}
 	theme = regula_theme
 	override_background = {
 		reference = council_chamber
@@ -23,10 +35,10 @@ regula_curo_privignos_event.0001 = {
 	lower_center_portrait = scope:recipient.father
 
 	immediate = {
-		scope:recipient.father = {
+		scope:recipient.father ?= {
 			save_scope_as = father_stepchild
 		}
-		scope:recipient.mother = {
+		scope:recipient.mother ?= {
 			save_scope_as = mother_stepchild
 		}
 	}
diff --git a/Regula_Magistri/localization/english/event_localization/regula_privignos_events_l_english.yml b/Regula_Magistri/localization/english/event_localization/regula_privignos_events_l_english.yml
index 302e4f69..ca77b520 100644
--- a/Regula_Magistri/localization/english/event_localization/regula_privignos_events_l_english.yml
+++ b/Regula_Magistri/localization/english/event_localization/regula_privignos_events_l_english.yml
@@ -1,6 +1,9 @@
 l_english:
   regula_curo_privignos_event.0001.t:0 "Decide the Fate of your Stepchild"
-  regula_curo_privignos_event.0001.desc:0 "[recipient.GetFirstName] is not of your loins. Rather [recipient.GetSheHe] is the [recipient.Custom('GetDaughterSon')] of [father_stepchild.GetTitledFirstName].\n\nWhen you brought [recipient.GetHerHis] mother, [mother_stepchild.GetFirstName], into your harem, [recipient.GetFirstName] came along as additional baggage. To this day, [recipient.GetSheHe] plays in your house with your children."
+  regula_curo_privignos_event.0001.desc_start:0 "[recipient.GetFirstName] is not of your loins."
+  regula_curo_privignos_event.0001.desc_father:0 "Rather [recipient.GetSheHe] is the [recipient.Custom('GetDaughterSon')] of [father_stepchild.GetTitledFirstName]."
+  regula_curo_privignos_event.0001.desc_mother:0 "When you brought [recipient.GetHerHis] mother, [mother_stepchild.GetFirstName], into your harem, [recipient.GetFirstName] came along as additional baggage."
+  regula_curo_privignos_event.0001.desc_end:0 "To this day, [recipient.GetSheHe] plays in your house with your children."
 
   regula_curo_privignos_event.0001.a:0 "#P @dynasty_icon! Allow [recipient.GetFirstNameNoTooltip] to join your house as family.#!"
   regula_curo_privignos_event.0001.b:0 "@child_icon! Take [recipient.GetHerHim] under your protection, but no more."
-- 
GitLab


From 9d64d6b869b3f5891ac076de10369574ef625d70 Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 06:39:28 +0000
Subject: [PATCH 8/9] Can't make someone who is already a courtier into a
 courtier again.

---
 .../regula_privignos_events.txt                | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/Regula_Magistri/events/relations_events/regula_privignos_events.txt b/Regula_Magistri/events/relations_events/regula_privignos_events.txt
index 343cc797..8a145597 100644
--- a/Regula_Magistri/events/relations_events/regula_privignos_events.txt
+++ b/Regula_Magistri/events/relations_events/regula_privignos_events.txt
@@ -55,8 +55,8 @@ regula_curo_privignos_event.0001 = {
 			add_opinion = {
 					modifier = regula_curo_privignos_added_to_dynasty
 					target = scope:actor
-				}
 			}
+		}
 		scope:actor = {
 			add_prestige = -100
 			add_dread = -10
@@ -64,7 +64,13 @@ regula_curo_privignos_event.0001 = {
 				type = loyalty_hook
 				target = scope:recipient
 			}
-			add_courtier = scope:recipient
+
+			if = {
+				limit = {
+					NOT = { is_employer_of = scope:recipient }
+				}
+				add_courtier = scope:recipient
+			}
 		}
 	}
 
@@ -85,7 +91,13 @@ regula_curo_privignos_event.0001 = {
 				type = loyalty_hook
 				target = scope:recipient
 			}
-			add_courtier = scope:recipient
+
+			if = {
+				limit = {
+					NOT = { is_employer_of = scope:recipient }
+				}
+				add_courtier = scope:recipient
+			}
 		}
 	}
 
-- 
GitLab


From 86c516580239a019538dd4d568047a7aebce4a36 Mon Sep 17 00:00:00 2001
From: OzcarMike <43490-OzcarMike@users.noreply.gitgud.io>
Date: Fri, 6 Sep 2024 07:02:28 +0000
Subject: [PATCH 9/9] Adjust behavior for rival relationship setting to handle
 case where relationship is already present.

---
 .../relations_events/regula_adultery_events.txt     | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/Regula_Magistri/events/relations_events/regula_adultery_events.txt b/Regula_Magistri/events/relations_events/regula_adultery_events.txt
index 48885213..275ee526 100644
--- a/Regula_Magistri/events/relations_events/regula_adultery_events.txt
+++ b/Regula_Magistri/events/relations_events/regula_adultery_events.txt
@@ -221,7 +221,10 @@ regula_adultery.1001 = {
 				type = dungeon
 			}
 		}
-		else = {
+		else_if = {
+			limit = {
+				can_set_relation_rival_trigger = { CHARACTER = scope:adultery_lover }
+			}
 			set_relation_rival = scope:adultery_lover
 		}
 	}
@@ -507,7 +510,13 @@ regula_adultery.2001 = {
 			}
 		}
 		else = {
-			set_relation_potential_rival = scope:sex_partner
+			scope:lover_spouse = { save_scope_as = relationship_reason_involved_character }
+			progress_towards_rival_effect = {
+				CHARACTER = scope:sex_partner
+				OPINION = 0
+				REASON = rival_slept_with_spouse
+			}
+			clear_saved_scope = relationship_reason_involved_character
 		}
 	}
 
-- 
GitLab