code:
regula_fascinare = {
	skill = diplomacy
	icon = icon_scheme_personal

	cooldown = { months = 2 }
	is_secret = yes
	base_secrecy = 10
	hostile = no
	uses_agents = yes
	power_per_skill_point = 20
	resistance_per_skill_point = 0
	minimum_progress_chance = 35
	maximum_progress_chance = 95
	# Does not use Spymaster
	spymaster_power_per_skill_point = 0
	spymaster_resistance_per_skill_point = 0
	minimum_success = 25

	allow = {
		is_adult = yes
		fascinare_allowed = yes
		is_imprisoned = no
		scope:target = {
			is_adult = yes
			is_male = no # Leaving the door open for futas, etc.
			NOR = {
				has_trait = paelex
				has_trait = mulsa
				has_trait = contubernalis
				has_trait = orba
			}
			is_imprisoned = no
		}
	}
	### This code shouldn't be necessary.  Handled at the character interaction stage.
	# 	trigger_if = {
	# 		limit = { is_ai = yes }
	# 		scope:target = {
	# 			trigger_if = { # Block AI from seducing lowborn nobodies in the players court
	# 				limit = {
	# 					exists = liege
	# 					liege = { is_ai = no }
	# 					NOR = {
	# 						is_courtier_of = scope:owner
	# 						is_foreign_court_or_pool_guest_of = scope:owner
	# 					}
	# 				}
	# 				OR = {
	# 					is_lowborn = no
	# 					is_landed = yes
	# 				}
	# 			}
	# 			trigger_if = { #So players don't get spammed by AI seduction
	# 				limit = {
	# 					is_ai = no
	# 				}
	# 				NOT = {
	# 					any_targeting_scheme = {
	# 						scheme_type = seduce
	# 					}
	# 				}
	# 			}
	# 		}
	# 	}
	# }

	valid = {
		NOT = { scope:target = { has_trait = incapable } }
		is_imprisoned = no

		scope:target = {
			is_imprisoned = no
			NOR = {
				has_trait = paelex
				has_trait = mulsa
				has_trait = contubernalis
				has_trait = orba
			}
			OR = {
				exists = location
				in_diplomatic_range = scope:owner
			}
		}
	}

	use_secrecy = {
		use_fascinare_secrecy_trigger = yes
	}

	valid_agent = {
		is_regula_trigger = yes
		age >= 16
	}

	agent_join_chance = {
		base = 0

		# Enslaved
		modifier = {
			add = 100
			has_trait = devoted_trait_group
			desc = SCHEME_FASCINARE_DEVOTED
		}
		### Too overpowered.
		# # Famuli
		# modifier = {
		# 	add = 10
		# 	faith = { religion_tag = regula_religion }
		# 	desc = SCHEME_FASCINARE_FAMULI
		# }

		# Base Reluctance, including negative AI Energy
		modifier = {
			add = {
				value = -20
				if = {
					limit = {
						ai_energy < 0
					}
					add = {
						value = ai_energy
						multiply = 0.5
					}
				}
			}
			desc = BASE_RELUCTANCE
		}

		#Is Owner sending a gift in the invite interaction?
		modifier = {
			add = 10
			exists = scope:gift
			always = scope:gift
			NOT = {
				OR = {
					scope:target = { is_parent_of = root }
					root = { is_parent_of = scope:target }
				}
			}
			desc = "SCHEME_WITH_GIFT"
		}

		#Target will never scheme against themselves
		modifier = {
			add = -1000
			this = scope:target
			desc = COMPASSIONATE_REASON #SCHEME_NOT_AGAINST_SELF
		}

		#Target is not diplomatically available
		modifier = {
			add = -1000
			is_available = no
			desc = SCHEME_NOT_DIPLOMATICALLY_AVAILABLE
		}

		# Cowardice
		modifier = {
			trigger = {
				ai_boldness < 0
			}
			add = {
				value = ai_boldness
			}
			desc = SCHEME_I_AM_A_COWARD
		}

		#How much does Agent like Owner?
		opinion_modifier = {
			trigger = {
				NOT = { this = scope:owner }
			}
			who = this
			opinion_target = scope:owner
			multiplier = 0.25
			#step = 5
			desc = SCHEME_MY_OPINION_OF_YOU
		}
	}

	base_success_chance = {
		base = 0

		#Magister

		modifier = {
			desc = FASCINARE_SUBJECT_BONUS
			scope:target = {
				OR = {
					is_foreign_court_or_pool_guest = yes
					is_courtier = yes
				}
				OR = {
					court_owner.top_liege = scope:owner
					court_owner = scope:owner
				}
			}
			add = 40
		}

		modifier = {
			desc = FASCINARE_UNIMPORTANT_BONUS
			scope:target = {
				OR = {
					is_foreign_court_or_pool_guest = yes
					is_courtier = yes
				}
				NOR = {
					court_owner.top_liege = scope:owner
					court_owner = scope:owner
					court_owner = {
						is_close_family_of = scope:target
					}
					court_owner = {
						is_consort_of = scope:target
					}
				}
			}
			add = 20
		}

		#Diplomacy based
		compare_modifier = {
			desc = "sway_my_diplomacy"
			target = scope:owner
			value = diplomacy
			multiplier = 2
		}

		modifier = { # Home Advantage perk bonus against own Courtiers and Guests
			desc = SEDUCE_COURTIER_GUEST_PERK_BONUS
			scope:owner = { has_perk = home_advantage_perk }
			scope:target = {
				OR = {
					is_courtier_of = scope:owner
					is_pool_guest_of = scope:owner
					is_foreign_court_guest_of = scope:owner
				}
			}
			add = home_advantage_perk_bonus
		}
		modifier = { # Smooth Operator perk bonus
			desc = SEDUCE_PERK_BONUS
			scope:owner = { has_perk = smooth_operator_perk }
			always = yes
			add = smooth_operator_perk_bonus
		}

		modifier = { # Legacy bonus
			desc = LEGACY_PERK_BONUS
			scope:owner = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_adventure_legacy_2
				}
			}
			always = yes
			add = fp1_adventure_legacy_2_success_chance_seduction
		}

		modifier = {
			desc = "SCHEME_SCHEMER_TRAIT"
			scope:owner = { has_trait = seducer }
			add = 25
		}

		#Beauty good
		modifier = {
			desc = "scheme_beauty_good_1"
			scope:owner = { has_trait = beauty_good_1 }
			add = 10
		}
		modifier = {
			desc = "scheme_beauty_good_2"
			scope:owner = { has_trait = beauty_good_2 }
			add = 15
		}
		modifier = {
			desc = "scheme_beauty_good_3"
			scope:owner = { has_trait = beauty_good_3 }
			add = 20
		}

		#Physique good
		modifier = {
			desc = "scheme_physique_good_1"
			scope:owner = { has_trait = physique_good_1 }
			add = 5
		}
		modifier = {
			desc = "scheme_physique_good_2"
			scope:owner = { has_trait = physique_good_2 }
			add = 10
		}
		modifier = {
			desc = "scheme_physique_good_3"
			scope:owner = { has_trait = physique_good_3 }
			add = 15
		}

		#Beauty bad
		modifier = {
			desc = "scheme_beauty_bad_1"
			scope:owner = { has_trait = beauty_bad_1 }
			add = -10
		}
		modifier = {
			desc = "scheme_beauty_bad_2"
			scope:owner = { has_trait = beauty_bad_2 }
			add = -15
		}
		modifier = {
			desc = "scheme_beauty_bad_3"
			scope:owner = { has_trait = beauty_bad_3 }
			add = -20
		}

		#Sexuality
		modifier = {
			desc = SCHEME_SEDUCE_WRONG_GENDER
			scope:owner = {
				NOR = {
					is_attracted_to_gender_of = scope:target
					has_perk = unshackled_lust_perk # Removed by the Unshackled Lust Perk
				}
			}
			add = -25
		}

		#TARGET#

		#Lustful/hedonist
		modifier = {
			desc = "SCHEME_REVELER"
			scope:target = { has_trait = lifestyle_reveler }
			add = 15
		}
		modifier = {
			desc = "SCHEME_LUSTFUL_TRAIT"
			scope:target = { has_trait = lustful }
			add = 30
		}

		#Chaste/shy
		modifier = {
			desc = "SCHEME_CHASTE_TRAIT"
			scope:target = { has_trait = chaste }
			add = -20
		}
		modifier = {
			desc = "SCHEME_SHY_TRAIT"
			scope:target = { has_trait = shy }
			add = -20
		}

		#Opinion of owner
		opinion_modifier = {
			desc = SCHEME_FASCINARE_THEIR_OPINION
			who = scope:target
			opinion_target = scope:owner
			min = -25
			max = 25
			multiplier = 0.75
		}

		#Target is owner's spouse
		modifier = { #
			trigger = { scope:owner = { is_consort_of = scope:target } }
			scope:target = {
				NOT = { has_relation_rival = scope:owner }
			}
			add = 75
			desc = "SCHEME_SEDUCE_SPOUSE_BONUS"
		}
		#Target is owner's lover.
		modifier = {
			add = 125
			scope:owner = {
				has_relation_lover = scope:target
			}
			desc = "HAS_RELATION_LOVER_WITH_TARGET"
		}
		#Target is owner's soulmate.
		modifier = {
			add = 100
			scope:owner = {
				has_relation_soulmate = scope:target
			}
			desc = "HAS_RELATION_SOULMATE_WITH_TARGET"
		}
		#Target is owner's friend.
		modifier = {
			add = 50
			scope:owner = {
				has_relation_friend = scope:target
			}
			desc = "HAS_RELATION_FRIEND_WITH_TARGET"
		}
		#Target is owner's best friend.
		modifier = {
			add = 150
			scope:owner = {
				has_relation_best_friend = scope:target
			}
			desc = "HAS_RELATION_BEST_FRIEND_WITH_TARGET"
		}
		#Target is owner's rival.
		modifier = {
			add = -50
			scope:owner = {
				has_relation_rival = scope:target
			}
			desc = "HAS_RELATION_RIVAL_WITH_TARGET"
		}
		#Target is owner's nemesis.
		modifier = {
			add = -125
			scope:owner = {
				has_relation_nemesis = scope:target
			}
			desc = "HAS_RELATION_NEMESIS_WITH_TARGET"
		}
		#Trait similarity to owner
		compatibility_modifier = {
			who = scope:target
			compatibility_target = scope:owner
			min = -15
			max = 30
			multiplier = 2
		}

		#Rank tier difference (landed target/target whose liege doesn't care)
		modifier = { #3 or more higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 20
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 0
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 1
				}
			}
		}
		modifier = { # Equal rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = -20
			desc = "RANK_EQUAL_TO_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 0
				}
			}
		}
		modifier = { #1 lower rank
			trigger = {
				scope:owner = {
					NOT = { is_consort_of = scope:target } # Your spouse doesn't care if you're a different rank than them.
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -45
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = -1
				}
			}
		}
		modifier = { #2 lower rank
			trigger = {
				scope:owner = {
					NOT = { is_consort_of = scope:target } # Your spouse doesn't care if you're a different rank than them.
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -60
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = -2
				}
			}
		}
		modifier = { #3 or less lower rank
			trigger = {
				scope:owner = {
					NOT = { is_consort_of = scope:target } # Your spouse doesn't care if you're a different rank than them.
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -90
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value <= -3
				}
			}
		}

		#Rank tier difference (unlanded character)
		modifier = { #3 or more higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 20
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 0
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = 1
				}
			}
		}
		modifier = { #Equal  rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = -20
			desc = "RANK_EQUAL_TO_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = 0
				}
			}
		}
		modifier = { #1 lower rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = -30
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = -1
				}
			}
		}
		modifier = { #2 lower rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = -45
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = -2
				}
			}
		}
		modifier = { #3 or less lower rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = -75
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value <= -3
				}
			}
		}
		#Extra rank bonus/penalty if target is arrogant/ambitious
		modifier = {
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # No 'social climbing' if you're already their spouse!
			desc = SCHEME_SOCIAL_CLIMBER_RANK_BONUS
			add = 10
			scope:target = {
				OR = {
					has_trait = arrogant
					has_trait = ambitious
					has_trait = greedy
				}
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			OR = {
				AND = {
					scope:target = { personal_scheme_success_compare_target_liege_tier_trigger = yes }
					scope:owner.highest_held_title_tier > scope:target.liege.highest_held_title_tier
				}
				AND = {
					scope:target = { personal_scheme_success_compare_target_liege_tier_trigger = no }
					scope:owner.highest_held_title_tier > scope:target.highest_held_title_tier
				}
			}
		}
		modifier = {
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # No 'social climbing' if you're already their spouse!
			desc = SCHEME_SOCIAL_CLIMBER_RANK_PENALTY
			add = -10
			scope:target = {
				OR = {
					has_trait = arrogant
					has_trait = ambitious
					has_trait = greedy
				}
			}
			OR = {
				AND = {
					scope:target = { personal_scheme_success_compare_target_liege_tier_trigger = yes }
					scope:owner.highest_held_title_tier < scope:target.liege.highest_held_title_tier
				}
				AND = {
					scope:target = { personal_scheme_success_compare_target_liege_tier_trigger = no }
					scope:owner.highest_held_title_tier < scope:target.highest_held_title_tier
				}
			}
		}
		modifier = {
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # The spouse bonus is applied elsewhere.
			desc = FASCINARE_SCHEME_RULER_BONUS
			add = 25
			scope:target = {
				is_vassal_or_below_of = scope:owner
			}
		}
				# Dynasty Kin Personal Scheme Success Chance on Dynasty Perk
		modifier = {
			add = kin_legacy_4_success_chance
			desc = KIN_LEGACY_DESC
			exists = scope:owner.dynasty
			scope:owner.dynasty = {
				has_dynasty_perk = kin_legacy_4
			}
			scope:target.dynasty = scope:owner.dynasty
		}

		# Thicker Than Water Perk
		modifier = {
			add = thicker_than_water_bonus
			desc = BEFRIEND_THICKER_THAN_WATER_PERK_DESC
			scope:owner = {
				has_perk = thicker_than_water_perk
			}
			scope:target = {
				is_close_or_extended_family_of = scope:owner
			}
		}
	}

	agent_success_chance = {
		base = 0
		first_valid = {
			modifier = {
				add = 50
				is_spouse_of = scope:target
				desc = "SCHEME_AGENT_IS_SPOUSE"
			}
			modifier = {
				add = 50
				has_relation_best_friend = scope:target
				desc = "SCHEME_AGENT_IS_BEST_FRIEND"
			}
			modifier = {
				add = 50
				has_relation_guardian = scope:target
				desc = "SCHEME_AGENT_IS_GUARDIAN"
			}
			modifier = {
				add = 30
				has_relation_friend = scope:target
				desc = "SCHEME_AGENT_IS_FRIEND"
			}
			modifier = {
				add = 30
				is_concubine_of = scope:target
				desc = "SCHEME_AGENT_IS_CONCUBINE"
			}
			modifier = {
				add = 100
				has_relation_lover = scope:target
				desc = "SCHEME_AGENT_IS_LOVER"
			}
			modifier = {
				add = 30
				scope:target = {
					is_ruler = yes
				}
				has_council_position = councillor_spymaster
				scope:target.cp:councillor_spymaster = this
				desc = "SCHEME_AGENT_IS_SPYMASTER"
			}
			modifier = {
				add = 30
				scope:target = {
					is_ruler = no
				}
				has_council_position = councillor_spymaster
				scope:target.liege.cp:councillor_spymaster = this
				desc = "SCHEME_AGENT_IS_SPYMASTER_IN_MY_COURT"
			}
			modifier = {
				add = 20
				is_close_family_of = scope:target
				desc = "SCHEME_AGENT_IS_CLOSE_KIN"
			}
			modifier = {
				add = 15
				is_powerful_vassal_of = scope:target
				desc = "SCHEME_AGENT_IS_POWERFUL_VASSAL"
			}
			modifier = {
				add = 15
				is_extended_family_of = scope:target
				desc = "SCHEME_AGENT_IS_EXTENDED_FAMILY"
			}
			modifier = {
				add = 10
				scope:target.liege = scope:owner
				desc = "SCHEME_AGENT_IS_COURTIER_MY_COURT"
			}
			modifier = {
				add = 10
				is_ruler = no
				scope:target.liege = this.liege
				desc = "SCHEME_AGENT_IS_FELLOW_COURTIER"
			}
			modifier = {
				add = 5
				desc = "SCHEME_AGENT_IS_COURTIER"
			}
		}
	}

	on_ready = {
		scheme_owner = {
			#Do I want to proceed to a roll?
			if = {
				limit = {
					is_ai = no
					OR = {
						use_fascinare_secrecy_trigger = yes
						is_ruler = yes
					}
					global_var:fascinare_events_enabled = yes
				}
				trigger_event = fascinare_outcome.0001
			}
			#Jump straight to roll
			else = {
				trigger_event = fascinare_outcome.0002
			}
		}
	}

	on_invalidated = {
		if = {
			limit = {
				scheme_target = { is_alive = no }
			}
			scheme_owner = {
				trigger_event = fascinare_outcome.0005
			}
		}
		#They gain the Mulsa trait via other means.
		# if = {
		# 	limit = {
		# 		scheme_progress < 90
		# 		scheme_target = { has_trait = devoted_trait_group }
		# 	}
		# 	scheme_owner = {
		# 		send_interface_message = {
		# 			type = event_generic_neutral
		# 			title = fascinare_invalid_title
		# 			left_icon = scope:target
		# 			custom_tooltip = fascinare_invalid
		# 		}
		# 	}
		# }
		else_if = { #fallback invalidation
			limit = {
				OR = {
					scope:owner = { is_imprisoned = yes }
					scope:target = { is_imprisoned = yes }

					scope:target = {
						NOR = {
							exists = location
							in_diplomatic_range = scope:owner
						}
					}
				}
			}
			scheme_owner = {
				send_interface_message = {
					type = event_generic_neutral
					title = fascinare_invalid_title
					left_icon = scope:target
					custom_tooltip = fascinare_invalid
					add_piety = 100
				}
			}
		}
	}

	# Depending on target, we start with bonus progress
	on_start = {
		save_scope_as = scheme

		scheme_owner = { save_scope_as = owner }
		scheme_target = { save_scope_as = target }

		add_bonus_fascinare_progress = yes
	}

	# on_start = {
	# 	#Handle incest hard reject
	# 	save_scope_as = scheme
	# 	scheme_owner = { save_scope_as = owner }
	# 	scheme_target = { save_scope_as = target }

	# 	if = {
	# 		limit = {
	# 			scope:target = {
	# 				is_close_or_extended_family_of = scope:owner
	# 				NOT = { is_consort_of = scope:owner }
	# 			}
	# 		}
	# 		scope:target = {
	# 			trigger_event = {
	# 				id = seduce_outcome.8101 #Hard reject event, ai weights on options determine yes/no
	# 				days = { 7 14 }
	# 			}
	# 		}
	# 	}
	# }

	on_monthly = {
		save_scope_as = scheme
		scheme_owner = { save_scope_as = owner }
		scheme_target = { save_scope_as = target }
	}
	success_desc = "FASCINARE_SUCCESS_DESC"
}


code:
regula_forge_inheritance_law = {
	skill = intrigue
	icon = icon_scheme_hostile

	cooldown = { months = 2 }
	is_secret = yes
	base_secrecy = 25
	hostile = yes
	uses_agents = no
	power_per_skill_point = 6
	resistance_per_skill_point = 2
	tier_resistance = 1
	minimum_progress_chance = 35
	maximum_progress_chance = 95
	# Does not use Spymaster
	spymaster_power_per_skill_point = 3
	spymaster_resistance_per_skill_point = 1
	minimum_success = 50

	allow = {
		is_adult = yes
		any_secret = {
			secret_type = regula_covert_conversion
		}
		is_imprisoned = no
		scope:target = {
			is_imprisoned = no
		}
	}

	valid = {
		NOT = { scope:target = { has_trait = incapable } }
		is_imprisoned = no

		scope:target = {
			is_imprisoned = no
			OR = {
				exists = location
				in_diplomatic_range = scope:owner
			}
		}
	}

	valid_agent = {
		is_regula_trigger = yes
		age >= 16
	}

	agent_join_chance = {
		base = 0
	}

	base_success_chance = {
		base = 25

		hostile_scheme_base_chance_modifier = yes

		modifier = {
			add = 20
			desc = FABRICATE_HOOK_DECEITFUL
			scope:owner = {
				has_trait = deceitful
			}
		}

		modifier = {
			add = -20
			desc = FABRICATE_HOOK_HONEST
			scope:owner = {
				has_trait = honest
			}
		}

		modifier = {
			add = 10
			desc = FABRICATE_HOOK_TARGET_TRUSTING
			scope:target = {
				has_trait = trusting
			}
		}

		modifier = {
			add = 10
			desc = FABRICATE_HOOK_TARGET_INTELLECT_BAD_1
			scope:target = {
				has_trait = intellect_bad_1
			}
		}

		modifier = {
			add = 20
			desc = FABRICATE_HOOK_TARGET_INTELLECT_BAD_2
			scope:target = {
				has_trait = intellect_bad_2
			}
		}

		modifier = {
			add = 30
			desc = FABRICATE_HOOK_TARGET_INTELLECT_BAD_3
			scope:target = {
				has_trait = intellect_bad_3
			}
		}

		modifier = {
			add = -10
			desc = FABRICATE_HOOK_TARGET_INTELLECT_GOOD_1
			scope:target = {
				has_trait = intellect_good_1
			}
		}

		modifier = {
			add = -20
			desc = FABRICATE_HOOK_TARGET_INTELLECT_GOOD_2
			scope:target = {
				has_trait = intellect_good_2
			}
		}

		modifier = {
			add = -30
			desc = FABRICATE_HOOK_TARGET_INTELLECT_GOOD_3
			scope:target = {
				has_trait = intellect_good_3
			}
		}

		modifier = {
			add = -20
			desc = FABRICATE_HOOK_TARGET_SCHEMER
			scope:target = {
				has_trait = schemer
			}
		}

		modifier = {
			add = -20
			desc = FABRICATE_HOOK_TARGET_PARANOID
			scope:target = {
				has_trait = paranoid
			}
		}

		modifier = {
			add = -10
			desc = FABRICATE_HOOK_TARGET_FICKLE
			scope:target = {
				has_trait = fickle
			}
		}

		modifier = {
			add = 10
			desc = FABRICATE_HOOK_TARGET_ARROGANT
			scope:target = {
				has_trait = arrogant
			}
		}

		modifier = {
			add = 20
			desc = FABRICATE_HOOK_TARGET_GREEDY
			scope:target = {
				has_trait = greedy
			}
		}

		modifier = {
			add = 10
			desc = FABRICATE_HOOK_TARGET_CRAVEN
			scope:target = {
				has_trait = craven
			}
		}

		compare_modifier = {
			value = scope:owner.cp:councillor_spymaster.intrigue
			multiplier = 2
			desc = FABRICATE_HOOK_SPYMASTER_INTRIGUE
			trigger = {
				exists = scope:owner.cp:councillor_spymaster
				NOT = { scope:owner.cp:councillor_spymaster = scope:target }
			}
		}

		modifier = {
			add = -50
			desc = FABRICATE_HOOK_TARGETING_SPYMASTER
			scope:target = {
				has_council_position = councillor_spymaster
			}
		}

		# Spiritual Head of Faith
		modifier = {
			add = -50
			desc = "SCHEME_VS_SPIRITUAL_HOF"
			scope:target = {
				faith = scope:owner.faith
				faith = {
					has_doctrine = doctrine_spiritual_head
				}
				faith = {
					exists = religious_head
					religious_head = {
			 			this = scope:target
			 		}
				}
			}
		}

		modifier = {
			desc = "SCHEME_SCHEMER_TRAIT"
			scope:owner = { has_trait = schemer }
			add = 25
		}

		#Rank tier difference (landed target/target whose liege doesn't care)
		modifier = { #3 or more higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 20
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # Your spouse doesn't care if you're a different rank than them.
			add = 0
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 1
				}
			}
		}

		# Dynasty Kin Personal Scheme Success Chance on Dynasty Perk
		modifier = {
			add = kin_legacy_4_success_chance
			desc = KIN_LEGACY_DESC
			exists = scope:owner.dynasty
			scope:owner.dynasty = {
				has_dynasty_perk = kin_legacy_4
			}
			scope:target.dynasty = scope:owner.dynasty
		}

		# Thicker Than Water Perk
		modifier = {
			add = thicker_than_water_bonus
			desc = BEFRIEND_THICKER_THAN_WATER_PERK_DESC
			scope:owner = {
				has_perk = thicker_than_water_perk
			}
			scope:target = {
				is_close_or_extended_family_of = scope:owner
			}
		}
	}

	on_ready = {
		scheme_owner = {
			#Do I want to proceed to a roll?
			if = {
				limit = {
					is_ai = no
				}
				random_list = {
					50 = { #Warrior Princess
						trigger_event = regula_forge_inheritance_outcome.0001
					}
					50 = { #Haruspex
						trigger_event = regula_forge_inheritance_outcome.0002
					}
				}
			}
		}
	}
	# # Do the Success Roll
	# random = {
	# 	chance = scheme_success_chance
	# 	save_scope_value_as = {
	# 		name = scheme_succeeded
	# 		value = yes
	# 	}
	# }
	# # Do the Secrecy Roll
	# save_scope_value_as = {
	# 	name = discovery_chance
	# 	value = {
	# 		value = 100
	# 		subtract = scheme_secrecy
	# 	}
	# }
	# random = {
	# 	chance = scope:discovery_chance
	# 	save_scope_value_as = {
	# 		name = scheme_discovered
	# 		value = yes
	# 	}
	# }

	# # On Success: Fire Event
	# if = {
	# 	limit = { exists = scope:scheme_succeeded }
	# 	scheme_owner = {
	# 		trigger_event = {
	# 			id = regula_forge_inheritance_outcome.1000
	# 		}
	# 	}
	# }

	# else = {
	# 	if = {
	# 		limit = { exists = scope:scheme_discovered }
	# 		scheme_owner = {
	# 			trigger_event = {
	# 				id = regula_forge_inheritance_outcome.2000
	# 			}
	# 		}
	# 	}
	# 	else = {
	# 		scheme_owner = {
	# 			send_interface_message = {
	# 				type = fabricate_hook_bad_message
	# 				title = regula_forge_inheritance_law_failed_reset_message

	# 				custom_tooltip = restart_scheme_tt
	# 				hidden_effect = {
	# 					scope:scheme = {
	# 						add_scheme_progress = -10
	# 					}
	# 				}
	# 			}
	# 		}
	# 	}
	# }

	on_invalidated = {
		if = {
			limit = {
				scheme_target = { is_alive = no }
			}
			scheme_owner = {
				send_interface_message = {
					type = event_generic_neutral
					title = regula_forge_inheritance_invalid
					left_icon = scope:target
					custom_tooltip = regula_forge_inheritance_invalid_dead_tt
					add_gold = 75
					add_prestige = 125
				}
			}
		}

		else_if = { #fallback invalidation
			limit = {
				OR = {
					scope:owner = { is_imprisoned = yes }
					scope:target = { is_imprisoned = yes }

					scope:target = {
						NOR = {
							exists = location
							in_diplomatic_range = scope:owner
						}
					}
				}
			}
			scheme_owner = {
				send_interface_message = {
					type = event_generic_neutral
					title = regula_forge_inheritance_invalid
					left_icon = scope:target
					custom_tooltip = regula_forge_inheritance_invalid_inaccessible_tt
					add_gold = 100
					add_prestige = 200
				}
			}
		}
	}

	on_monthly = {
		hostile_scheme_discovery_chance_effect = yes
	}
	success_desc = "FORGE_INHERITANCE_LAW_SUCCESS_DESC"
	discovery_desc = "FORGE_INHERITANCE_LAW_DISCOVERY_DESC"
}

license: mit


code:
regula_instiga_discordia = {
	skill = diplomacy
	hostile = yes
	icon = icon_scheme_personal

	uses_agents = no
	power_per_skill_point = 50.0
	resistance_per_skill_point = 0
	power_per_agent_skill_point = 5

	minimum_progress_chance = 40
	maximum_progress_chance = 95
	minimum_success = 5
	maximum_secrecy = 95
	maximum_success = 95

	allow = {
		is_adult = yes
		is_imprisoned = no
		is_independent_ruler = no
	}

	valid = {
		scope:target = {
			is_imprisoned = no
			exists = location
		}
		# Special AI exceptions
	}

	base_success_chance = {
		base = 40

		hostile_scheme_base_chance_modifier = yes

		compare_modifier = {
			desc = "sway_my_diplomacy"
			target = scope:owner
			value = diplomacy
			multiplier = 5
		}
		# Proxy for trust
		opinion_modifier = {
			desc = SCHEME_BEFRIEND_THEIR_OPINION
			who = scope:target
			opinion_target = scope:owner
			max = 50
			min = -10
			multiplier = 0.75
		}
		# At War
		first_valid = {
			modifier = {
				add = -50
				desc = "SCHEME_AT_WAR"
				scope:target = {
					is_at_war = yes
				}
			}
		}
	}

	is_secret = yes
	base_secrecy = 50 # Gossip is hard to stop

	on_ready = {
		scheme_owner = {
			if = {
				limit = {
					has_character_flag = is_in_event_regula_instiga_discordia_outcome_0001
				}
				trigger_event = {
					id = regula_instiga_discordia_outcome.0001
					days = 1
				}
			}
			else = {
				trigger_event = regula_instiga_discordia_outcome.0001
			}
		}
	}

	on_invalidated = {
		if = {
			limit = {
				scope:target = { is_alive = no }
			}
			global_var:magister_character = {
				send_interface_toast = {
					title = regula_instiga_discordia_invalidated_title
					left_icon = scope:owner
					right_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_died
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:target = {
					is_imprisoned = yes
					imprisoner = scope:owner
				}
				scope:owner = {
					NOT = { has_character_flag = is_in_event_regula_instiga_discordia_outcome_0001 } #They've got a pretty good alibi
				}
			}
			global_var:magister_character = {
				send_interface_message = {
					title = regula_instiga_discordia_invalidated_title
					type = regula_instiga_discordia_invalidated_i_imprisoned_message
					desc = regula_instiga_discordia_i_imprisoned_them_message
					left_icon = scope:target
				}
			}
		}
		else_if = {
			limit = {
				scope:target = { is_imprisoned = yes }
			}
			scope:target.imprisoner = {
				save_scope_as = other_imprisoner
			}
			global_var:magister_character = {
				send_interface_toast = {
					title = regula_instiga_discordia_invalidated_title
					left_icon = scope:target
					right_icon = scope:other_imprisoner
					custom_description_no_bullet = {
						subject = scope:other_imprisoner
						object = scope:target
						text = scheme_target_imprisoned_by_other
					}
				}
			}
		}
		else_if = {
			limit = {
				global_var:magister_character = {
					is_alive = no
				}
			}
			scope:scheme = {
				end_scheme = yes
			}
		}
	}

	success_desc = "REGULA_INSTIGA_DISCORDIA_SUCCESS_DESC"
	discovery_desc = "REGULA_INSTIGA_DISCORDIA_DISCOVERY_DESC"
}


code:
rapta_maritus = {
	skill = intrigue
	hostile = yes
	icon = icon_scheme_personal

	uses_agents = no
	power_per_skill_point = 50.0
	resistance_per_skill_point = 0
	power_per_agent_skill_point = 5

	minimum_progress_chance = 40
	maximum_progress_chance = 95
	minimum_success = 5
	maximum_secrecy = 95
	maximum_success = 95

	allow = {
		is_adult = yes
		is_imprisoned = no
		is_married = yes
	}

	valid = {
		OR = {
			NOT = { is_parent_of = scope:target }
			has_trait_with_flag = can_murder_own_children
		}
		scope:target = {
			is_imprisoned = no
			exists = location
		}
		# Special AI exceptions
	}

	base_success_chance = {
		base = 25

		hostile_scheme_base_chance_modifier = yes

		compare_modifier = {
			desc = "sway_my_diplomacy"
			target = scope:owner
			value = intrigue
			multiplier = 5
		}

		# At War
		first_valid = {
			modifier = {
				add = -20
				desc = "SCHEME_AT_WAR"
				scope:target = {
					is_at_war_with = scope:owner
				}
			}
			modifier = {
				add = -15
				scope:target = {
					is_landed = no
					exists = liege
					liege = {
						is_at_war_with = scope:owner
					}
				}
				desc = "SCHEME_AT_WAR_WITH_LIEGE"
			}
			modifier = {
				add = -10
				scope:target = {
					is_landed = yes
					exists = liege
					liege = {
						is_at_war_with = scope:owner
					}
				}
				desc = "SCHEME_AT_WAR_WITH_LIEGE"
			}
		}
	}

	cooldown = { years = 3 }
	is_secret = yes
	base_secrecy = 25 # No one expects their own spouse.

	on_ready = {
		scheme_owner = {
			if = {
				limit = {
					has_character_flag = is_in_event_rapta_maritus_outcome_0001
				}
				trigger_event = {
					id = rapta_maritus_outcome.0001
					days = 1
				}
			}
			else = {
				trigger_event = rapta_maritus_outcome.0001
			}
		}
	}

	on_monthly = {
		hostile_scheme_discovery_chance_effect = yes
		if = {
			limit = {
				NOT = { exists = scope:discovery_event_happening }
			}
			scheme_owner = {
				trigger_event = {
					on_action = rapta_maritus_ongoing
					days = { 1 30 }
				}
			}
		}
	}

	on_invalidated = {
		if = {
			limit = {
				scope:target = { is_alive = no }
			}
			global_var:magister_character = {
				send_interface_toast = {
					title = rapta_maritus_scheme_invalidated_title
					left_icon = scope:owner
					right_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_died
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:target = {
					is_imprisoned = yes
					imprisoner = scope:owner
				}
				scope:owner = {
					NOT = { has_character_flag = is_in_event_rapta_maritus_outcome_0001 } #You probably abducted them
				}
			}
			global_var:magister_character = {
				send_interface_message = {
					title = rapta_maritus_scheme_invalidated_title
					type = rapta_maritus_invalidated_i_imprisoned_message
					desc = rapta_maritus_scheme_i_imprisoned_them_message
					left_icon = scope:target
				}
			}
		}
		else_if = {
			limit = {
				scope:target = { is_imprisoned = yes }
			}
			scope:target.imprisoner = {
				save_scope_as = other_imprisoner
			}
			global_var:magister_character = {
				send_interface_toast = {
					title = rapta_maritus_scheme_invalidated_title
					left_icon = scope:target
					right_icon = scope:other_imprisoner
					custom_description_no_bullet = {
						subject = scope:other_imprisoner
						object = scope:target
						text = scheme_target_imprisoned_by_other
					}
				}
			}
		}
		else_if = {
			limit = {
				global_var:magister_character = {
					is_alive = no
				}
			}
			scope:scheme = {
				end_scheme = yes
			}
		}
	}

	success_desc = "RAPTA_MARITUS_SUCCESS_DESC"
	discovery_desc = "RAPTA_MARITUS_DISCOVERY_DESC"
}


code:
#############################
# Regula Men-at-Arms Values #
#############################

#########
# Costs #
#########
# Using @[skirmisher_recruitment_cost] doesnt work, so using hardcoded values

pedites_recruitment_cost     = 45
pedites_low_maint_cost       = 0.15
pedites_high_maint_cost      = 0.45

sagittarius_recruitment_cost = 55
sagittarius_low_maint_cost   = 0.2
sagittarius_high_maint_cost  = 0.6

equitatus_recruitment_cost   = 85
equitatus_low_maint_cost     = 0.35
equitatus_high_maint_cost    = 1.05

sacerdos_recruitment_cost   = 90
sacerdos_low_maint_cost     = 0.4
sacerdos_high_maint_cost    = 1.2


code:
# Bloodline value goals - Single Life
# These are the values we check against to see if we "succeed" in achieving that bloodline
regula_fascinare_tally_goal = 50
regula_domitans_tally_goal = 10
regula_contubernalis_tally_goal = 5
regula_domination_war_tally_goal = 5
regula_servitude_war_tally_goal = 3
regula_potestas_queen_tally_goal = 3
regula_obedience_tally_goal = 15

# Bloodline value goals - Cumulative
regula_fascinare_tally_goal_cumulative = 150
regula_domitans_tally_goal_cumulative = 25
regula_contubernalis_tally_goal_cumulative = 15
regula_domination_war_tally_goal_cumulative = 10
regula_servitude_war_tally_goal_cumulative = 5
regula_potestas_queen_tally_goal_cumulative = 5
regula_obedience_tally_goal_cumulative = 50

# Interaction Costs
# Piety costs for interactions
regula_mutare_corpus_interaction_piety_cost = 300

# Sums up all relevant skills.
regula_character_total_skills = {
	value = 0
	add = diplomacy
	add = martial
	add = stewardship
	add = intrigue
	add = learning
}

# Counts the number of powerful vassals that are crypto-famuli.
regula_num_covert_powerful_vassals = {
	value = 0
	every_vassal = {
		limit = {
			is_powerful_vassal_of = root
			any_secret = {
				secret_type = regula_covert_conversion
			}
		}
		add = 1
	}
}

# Counts the number of children that the magister has with this woman.
regula_num_magister_children = {
	value = 0
	every_child = {
		limit = {
			this.father = global_var:magister_character
		}
		add = 1
	}
}

regula_num_children = {
	value = 0
	every_child = {
		add = 1
	}
}

# Counts the nuber of pregnant wives, concubines, and lovers.
regula_num_pregnant_consorts_and_lovers = {
	value = 0
	every_consort = {
		limit = {
			is_pregnant = yes
		}
		add = 1
	}
	# every_relation = {
	# 	type = lover
	# 	limit = {
	# 		NOT = { primary_spouse = prev }  ### UPDATE - verify code
	# 		is_pregnant = yes
	# 	}
	# 	add = 1
	# }
}

# Calculates the number of concubines with titles. Catches domina too.
regula_num_landed_concubines = {
	value = 0
	every_consort= {
		limit = {
			highest_held_title_tier >= tier_county
			OR = {
				has_trait = paelex
				has_trait = domina
			}
		}
		add = 1
	}
}

regula_num_unlanded_consorts = {
	value = 0
	every_consort= {
		limit = {
			is_landed = no
		}
		add = 1
	}
}

regula_potestas_non_transfunde_cost = {
	value = 0
	every_held_title = {
		add = regula_title_cost
	}
	every_vassal_or_below = { # Vassals count for half.
		limit = {
			highest_held_title_tier = tier_duchy
		}
		add = 300
	}
	every_vassal_or_below = {
		limit = {
			highest_held_title_tier = tier_county
		}
		add = 150
	}

	if = {
		limit = {
			tier_difference = {
				target = scope:actor
				value = -2
			}
		}
		multiply = 0.5
	}
	if = {
		limit = {
			tier_difference = {
				target = scope:actor
				value = -3
			}
		}
		multiply = 0.25
	}
	if = {
		limit = {
			AND = {
				character_is_realm_neighbor = scope:actor
				NOT = {
					character_is_land_realm_neighbor = scope:actor
				}
			}
		}
		multiply = 1.25 # A little pricier if they're not nearby.
	}
	# if = {   ### UPDATE - has_trait triggers register as false, regardless of validity. Not restricted to devoted traits or recipient.
	# 	limit = {
	# 		OR = {
	# 			has_trait = mulsa
	# 			has_trait = paelex # Just in case
	# 			has_trait = domina # Just in case
	# 		}
	# 	}
	# 	multiply = 0.5 # You're also convincing the smallfolk and the minor lords. Having the target on your side isn't everything.
	# }
	#

	# We get to spend less depending on our piety level
	multiply = regula_piety_level_reduction_multiplier
}

regula_abice_maritus_cost = {
	value = 0
	scope:recipient.primary_spouse = {
		every_held_title = {
			add = regula_title_cost
		}
		every_vassal_or_below = { # Vassals count for half.
			limit = {
				highest_held_title_tier = tier_duchy
			}
			add = 300
		}
		every_vassal_or_below = {
			limit = {
				highest_held_title_tier = tier_county
			}
			add = 150
		}

		if = {
			limit = {
				tier_difference = {
					target = scope:actor
					value = -2
				}
			}
			multiply = 0.5
		}
		if = {
			limit = {
				tier_difference = {
					target = scope:actor
					value = -3
				}
			}
			multiply = 0.25
		}
		if = {
			limit = {
				AND = {
					character_is_realm_neighbor = scope:actor
					NOT = {
						character_is_land_realm_neighbor = scope:actor
					}
				}
			}
			multiply = 1.25 # A little pricier if they're not nearby.
		}
	}

	# We get to spend less depending on our piety level
	multiply = regula_piety_level_reduction_multiplier

	if = {
		limit = {
			global_var:magister_character.faith = {
				controls_holy_site_with_flag = 	regula_abice_maritus_active
			}
		}
		multiply = 0.5
	}
}

regula_domination_war_cost = {
	value = 0
	scope:defender = {
		every_held_title = {
			add = regula_title_cost
		}
		every_vassal_or_below = { # Vassals count for half.
			limit = {
				highest_held_title_tier = tier_duchy
			}
			add = 300
		}
		every_vassal_or_below = {
			limit = {
				highest_held_title_tier = tier_county
			}
			add = 150
		}

		if = {
			limit = {
				tier_difference = {
					target = scope:actor
					value = -2
				}
			}
			multiply = 0.5
		}
		if = {
			limit = {
				tier_difference = {
					target = scope:actor
					value = -3
				}
			}
			multiply = 0.25
		}
		if = {
			limit = {
				AND = {
					character_is_realm_neighbor = scope:actor
					NOT = {
						character_is_land_realm_neighbor = scope:actor
					}
				}
			}
			multiply = 1.25 # A little pricier if they're not nearby.
		}
	}

	# We get to spend less depending on our piety level
	multiply = regula_piety_level_reduction_multiplier

	if = {
		limit = {
			global_var:magister_character.faith = {
				controls_holy_site_with_flag = 	regula_abice_maritus_active
			}
		}
		multiply = 0.5
	}

	# As this is a domination war, it costs less
	multiply = 0.5
}

regula_titulum_novis_cost = {
	value = 0

	scope:target = {
		# Add the piety cost of titles below the landed_title, eg any counties below duchy or duchys + counties below kingdom
		every_in_de_jure_hierarchy = {
			if = {
				limit = {
					holder = scope:recipient
				}
				add = regula_title_cost
			}
		}
	}

	# We get to spend less depending on our piety level
	#multiply = regula_piety_level_reduction_multiplier

}

# Get cost of title
regula_title_cost = {
	value = 0
	if = {
		limit = {
			tier = 1
		}
		add = 25
	}
	if = {
		limit = {
			tier = 2
		}
		add = 100
	}
	if = {
		limit = {
			tier = 3
		}
		add = 300
	}
	if = {
		limit = {
			tier = 4
		}
		add = 500
	}
	if = {
		limit = {
			tier = 5
		}
		add = 1500
	}
}

# Depending on our piety level, we have a multiplier that reduces costs slightly
regula_piety_level_reduction_multiplier = {
	value = 1 # 100 percent

	# Poenitens (level 0) get an increase of 10%
	# Cenobite (level 1) get no reduction
	# Zelator (Level 2) get 10% reduction
	# Skeuophylax (level 3) get 20% reduction
	# Synkellos (level 4) get 35% reduction
	# Exarch (level 5) get 50& reduction

	if = {
		limit = {
			global_var:magister_character = {
				piety_level = 0
			}
		}
		multiply = 1.1
	}

	if = {
		limit = {
			global_var:magister_character = {
				piety_level = 2
			}
		}
		multiply = 0.9
	}

	if = {
		limit = {
			global_var:magister_character = {
				piety_level = 3
			}
		}
		multiply = 0.8
	}

	if = {
		limit = {
			global_var:magister_character = {
				piety_level = 4
			}
		}
		multiply = 0.65
	}

	if = {
		limit = {
			global_var:magister_character = {
				piety_level = 5
			}
		}
		multiply = 0.5
	}
}

# Counts up number of Counties your Holy orders have
regula_num_holy_order_counties = {
	value = 0
	every_sub_realm_barony = {
		if = {
			limit = {
				is_under_holy_order_lease = yes
				lessee_title.holder = {
					faith = global_var:magister_character.faith	# We assume the Magister has the Magistrain faith
				}
			}
			add = 1
		}
	}
}

# Returns the dynasty prestige you get from enslaving a ward who either has a title or is the primary heir to a title
# TODO, how do we find out the highest title a character is first in line for?
# Scope should be ward character
regula_ward_highest_title_to_dynasty_prestige = {
	value = 0
	# They are a ward that already has a primary title of this rank
	if = {
		limit = {
			primary_title.tier = 1
		}
		add = 25
	}
	if = {
		limit = {
			primary_title.tier = 2
		}
		add = 100
	}
	if = {
		limit = {
			primary_title.tier = 3
		}
		add = 300
	}
	if = {
		limit = {
			primary_title.tier = 4
		}
		add = 750
	}
	if = {
		limit = {
			primary_title.tier = 5
		}
		add = 1250
	}
}


code:
regula_beautiful_character = {
	age = { 18 35 }
	random_traits_list = {
		count = 1
		education_diplomacy_2 = {}
		education_diplomacy_3 = {}
		education_diplomacy_4 = {}
		education_stewardship_2 = {}
		education_stewardship_3 = {}
		education_stewardship_4 = {}
	}
	random_traits_list = {
		count = 1
		beauty_good_2 = {}
		beauty_good_3 = {}
	}
	random_traits_list = {
		count = 1
		deceitful = {}
		gregarious = {}
		ambitious = {}
		diligent = {}
	}
	#Personality trait 2-3
	random_traits_list = {
		count = 2
		gluttonous = {}
		temperate  = {}
		greedy = {}
		generous = {}
		wrathful = {}
		calm = {}
		patient = {}
		impatient = {}
		honest = {}
		trusting = {}
		compassionate = {}
		fickle = {}
		forgiving = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	diplomacy = {
		min_template_decent_skill
		max_template_decent_skill
	}
}

regula_champion_giant_character = {
	age = { 18 25 }
	random_traits_list = {
		count = 1
		education_martial_2 = {}
		education_martial_3 = {}
		education_martial_4 = {}
	}
    random_traits_list = {
		count = 1
		brave = {}
		just = {}
	}
    random_traits_list = {
		count = 1
		wrathful = {}
		arrogant = {}
		impatient = {}
		ambitious = {}
		zealous = {}
		stubborn = {}
		callous = {}
		vengeful = {}
	}
    random_traits_list = {
		count = { 0 1 }
		blademaster_1 = {}
		blademaster_2 = {}
		blademaster_3 = {}
        berserker = {}
        physique_good_2 = {}
        physique_good_3 = {}
	}
	dynasty = none
	random_traits = no
    martial = {
		min_template_average_skill
		max_template_average_skill
	}
    prowess = { 20 30 }
	faith = this.faith
	culture = this.culture
	trait = giant
}

regula_commander_character = {
	age = { 18 25 }
	random_traits_list = {
		count = 1
		education_martial_3 = {}
		education_martial_4 = {}
	}
    random_traits_list = {
		count = 1
		ambitious = {}
		diligent = {}
	}
    random_traits_list = {
		count = 2
		brave = {}
		arrogant = {}
		patient = {}
		sadistic = {}
		zealous = {}
		stubborn = {}
		callous = {}
		vengeful = {}
	}
    random_traits_list = {
		count = 1
		overseer = {}
		strategist = {}
		architect = {}
		administrator = {}
        military_engineer = {}
        logistician = {}
		aggressive_attacker = {}
		unyielding_defender = {}
		forder = {}
		flexible_leader = {}
	}
	trait = holy_warrior
	dynasty = none
	random_traits = no
    martial = {	20 30 }
	faith = this.faith
	culture = this.culture
	trait = deviant
}

# Each Inititate is specialised
# 1. The Solider - Giant, Strong style traits, good martial and prowess
# 2. The Spy - High Intrigue, prowess
# 3. The Priestess - High Learning, Zealous
# 4. The Lady - decent stats all around, content, good vassal/wife
# 5. The Breeder - Good congential traits, chance for pure blooded, not so great stat line
# Common Inititates
regula_inititate_solider_common_character = {
	age = { 18 18 }
	random_traits_list = {
		education_martial_2 = {}
		education_martial_3 = {}
	}
	random_traits_list = {
		physique_good_1 = {}
		physique_good_2 = {}
	}
	# Two "good" traits
	random_traits_list = {
		brave = {}
		zealous = {}
	}
	random_traits_list = {
		lustful = {}
		diligent = {}
		patient = {}
		humble = {}
		just = {}
		ambitious = {}
	}
	# One "bad" trait
	random_traits_list = {
		wrathful = {}
		#impatient = {}
		arrogant = {}
		sadistic = {}
		stubborn = {}
		vengeful = {}
	}
	trait = holy_warrior
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	martial = {
		min_template_decent_skill
		max_template_decent_skill
	}
	prowess = {
		min_template_decent_skill
		max_template_decent_skill
	}
}

regula_inititate_spy_common_character = {
	age = { 18 18 }
	random_traits_list = {
		education_intrigue_2 = {}
		education_intrigue_3 = {}
	}
	random_traits_list = {
		count = {1 2}
		beauty_good_1 = {}
		intellect_good_1 = {}
	}
	# Two "good" traits
	random_traits_list = {
		paranoid = {}
		diligent = {}
	}
	random_traits_list = {
		lustful = {}
		patient = {}
		fickle = {}
		ambitious = {}
		zealous = {}
		deceitful = {}
	}
	# One "bad" trait
	random_traits_list = {
		compassionate = {}
		trusting = {}
		gluttonous = {}
		arrogant = {}
		honest = {}
		lazy = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	intrigue = {
		min_template_decent_skill
		max_template_decent_skill
	}
}

regula_inititate_priestess_common_character = {
	age = { 18 18 }
	random_traits_list = {
		count = 1
		education_learning_2 = {}
		education_learning_3 = {}
	}
	trait = intellect_good_1
	# Two "good" traits
	trait = zealous
	random_traits_list = {
		count = 1
		lustful = {}
		content = {}
		patient = {}
		humble = {}
		just = {}
		compassionate = {}
	}
	# One "bad" trait
	random_traits_list = {
		count = 1
		wrathful = {}
		gluttonous = {}
		arrogant = {}
		lazy = {}
		stubborn = {}
		craven = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	learning = {
		min_template_decent_skill
		max_template_decent_skill
	}
}

regula_inititate_lady_common_character = {
	age = { 18 18 }
	random_traits_list = {
		count = 1
		education_stewardship_2 = {}
		education_stewardship_3 = {}
		education_diplomacy_2 = {}
		education_diplomacy_3 = {}
	}
	random_traits_list = {
		beauty_good_1 = {}
		intellect_good_1 = {}
		physique_good_1 = {}
	}
	# Two "good" traits
	random_traits_list = {
		content = {}
		trusting = {}
	}
	random_traits_list = {
		lustful = {}
		diligent = {}
		patient = {}
		humble = {}
		just = {}
		gregarious = {}
	}
	# One "bad" trait
	random_traits_list = {
		callous = {}
		ambitious = {}
		arrogant = {}
		greedy = {}
		stubborn = {}
		vengeful = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	diplomacy = {
		min_template_decent_skill
		max_template_decent_skill
	}
	stewardship = {
		min_template_decent_skill
		max_template_decent_skill
	}
}

regula_inititate_breeder_common_character = {
	age = { 18 18 }
	random_traits_list = {
		education_martial_1 = {}
		education_stewardship_1 = {}
		education_diplomacy_1 = {}
		education_learning_1 = {}
		education_intrigue_1 = {}
	}
	random_traits_list = {
		count = {2 3}
		beauty_good_1 = {}
		beauty_good_2 = {}
		intellect_good_1 = {}
		intellect_good_2 = {}
		physique_good_1 = {}
		physique_good_2 = {}
		fecund = {}
	}
	# Two "good" traits
	trait = lustful
	random_traits_list = {
		gregarious = {}
		content = {}
		honest = {}
		humble = {}
		trusting = {}
		calm = {}
	}
	# One "bad" trait
	random_traits_list = {
		gluttonous = {}
		greedy = {}
		arrogant = {}
		lazy = {}
		stubborn = {}
		shy = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
}

# Noble Inititates
regula_inititate_solider_noble_character = {
	age = { 18 18 }
	random_traits_list = {
		education_martial_3 = {}
		education_martial_4 = {}
	}
	random_traits_list = {
		physique_good_2 = {}
		physique_good_3 = {}
	}
	random_traits_list = {
		beauty_good_1 = {}
		intellect_good_1 = {}
	}
	random_traits_list = {
		brave = {}
		zealous = {}
	}
	random_traits_list = {
		count = 2
		lustful = {}
		diligent = {}
		patient = {}
		humble = {}
		just = {}
		ambitious = {}
	}
	random_traits_list = {
		strategist = {}
		overseer = {}
		gallant = {}
	}
	trait = holy_warrior
	random_traits_list = {
		logistician = {}
		military_engineer = {}
		aggressive_attacker = {}
		unyielding_defender = {}
		forder = {}
		flexible_leader = {}
		desert_warrior = {}
		jungle_stalker = {}
		reaver = {}
		reckless = {}
		open_terrain_expert = {}
		rough_terrain_expert = {}
		forest_fighter = {}
		cautious_leader = {}
		organizer = {}
		winter_soldier = {}
	}
	trait = blademaster_1
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	martial = {
		max_template_decent_skill
		max_template_high_skill
	}
	prowess = {
		max_template_decent_skill
		max_template_high_skill
	}
}

regula_inititate_spy_noble_character = {
	age = { 18 18 }
	random_traits_list = {
		education_intrigue_3 = {}
		education_intrigue_4 = {}
	}
	random_traits_list = {
		count = {1 2}
		beauty_good_2 = {}
		intellect_good_2 = {}
	}
	random_traits_list = {
		beauty_good_1 = {}
		intellect_good_1 = {}
	}
	# Two "good" traits
	random_traits_list = {
		paranoid = {}
		diligent = {}
	}
	random_traits_list = {
		count = 2
		lustful = {}
		patient = {}
		fickle = {}
		ambitious = {}
		zealous = {}
		deceitful = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	intrigue = {
		max_template_decent_skill
		max_template_high_skill
	}
}

regula_inititate_priestess_noble_character = {
	age = { 18 18 }
	random_traits_list = {
		count = 1
		education_learning_3 = {}
		education_learning_4 = {}
	}
	trait = intellect_good_2
	# Two "good" traits
	trait = zealous
	random_traits_list = {
		count = 2
		lustful = {}
		content = {}
		patient = {}
		humble = {}
		just = {}
		compassionate = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	learning = {
		max_template_decent_skill
		max_template_high_skill
	}
}

regula_inititate_lady_noble_character = {
	age = { 18 18 }
	random_traits_list = {
		count = 1
		education_stewardship_3 = {}
		education_stewardship_4 = {}
		education_diplomacy_3 = {}
		education_diplomacy_4 = {}
	}
	random_traits_list = {
		count = 2
		beauty_good_1 = {}
		intellect_good_1 = {}
		physique_good_1 = {}
		beauty_good_2 = {}
		intellect_good_2 = {}
		physique_good_2 = {}
		fecund = {}
	}
	# Two "good" traits
	trait = content
	random_traits_list = {
		count = 2
		trusting = {}
		lustful = {}
		diligent = {}
		patient = {}
		humble = {}
		just = {}
		gregarious = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	diplomacy = {
		max_template_decent_skill
		max_template_high_skill
	}
	stewardship = {
		max_template_decent_skill
		max_template_high_skill
	}
}

regula_inititate_breeder_noble_character = {
	age = { 18 18 }
	random_traits_list = {
		education_martial_2 = {}
		education_stewardship_2 = {}
		education_diplomacy_2 = {}
		education_learning_2 = {}
		education_intrigue_2 = {}
	}
	random_traits_list = {
		count = {3 4}
		beauty_good_2 = {}
		intellect_good_2 = {}
		physique_good_2 = {}
		beauty_good_3 = {}
		intellect_good_3 = {}
		physique_good_3 = {}
		fecund = {}
		pure_blooded = {}
	}
	# Two "good" traits
	trait = lustful
	random_traits_list = {
		count = 2
		gregarious = {}
		content = {}
		honest = {}
		humble = {}
		trusting = {}
		calm = {}
	}
	# Breeder trait
	trait = regula_bun_bloodline
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
}
# Royal Inititates
regula_inititate_solider_royal_character = {
	age = { 18 18 }
	trait = education_martial_4
	trait = physique_good_3
	trait = strong
	random_traits_list = {
		count = 2
		beauty_good_1 = {}
		beauty_good_2 = {}
		intellect_good_1 = {}
		intellect_good_2 = {}
	}
	trait = brave
	random_traits_list = {
		count = 2
		zealous = {}
		lustful = {}
		diligent = {}
		patient = {}
		humble = {}
		just = {}
		ambitious = {}
	}
	random_traits_list = {
		strategist = {}
		overseer = {}
		gallant = {}
	}
	trait = holy_warrior
	random_traits_list = {
		count = 2
		logistician = {}
		military_engineer = {}
		aggressive_attacker = {}
		unyielding_defender = {}
		forder = {}
		flexible_leader = {}
		desert_warrior = {}
		jungle_stalker = {}
		reaver = {}
		reckless = {}
		open_terrain_expert = {}
		rough_terrain_expert = {}
		forest_fighter = {}
		cautious_leader = {}
		organizer = {}
		winter_soldier = {}
	}
	random_traits_list = {
		blademaster_2 = {}
		blademaster_3 = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	martial = {
		min_template_high_skill
		max_template_high_skill
	}
	prowess = {
		min_template_high_skill
		max_template_high_skill
	}
}

regula_inititate_spy_royal_character = {
	age = { 18 18 }
	trait = education_intrigue_4
	trait = intellect_good_3
	random_traits_list = {
		beauty_good_2 = {}
		beauty_good_3 = {}
	}
	trait = paranoid
	random_traits_list = {
		count = 2
		lustful = {}
		patient = {}
		fickle = {}
		ambitious = {}
		zealous = {}
		deceitful = {}
	}
	trait = schemer
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	intrigue = {
		min_template_high_skill
		max_template_high_skill
	}
}

regula_inititate_priestess_royal_character = {
	age = { 18 18 }
	trait = education_learning_4
	trait = intellect_good_3
	random_traits_list = {
		beauty_good_1 = {}
		beauty_good_2 = {}
		beauty_good_3 = {}
	}
	trait = zealous
	random_traits_list = {
		count = 2
		lustful = {}
		content = {}
		patient = {}
		humble = {}
		just = {}
		compassionate = {}
		calm = {}
	}
	trait = theologian
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	learning = {
		min_template_high_skill
		max_template_high_skill
	}
}

regula_inititate_lady_royal_character = {
	age = { 18 18 }
	random_traits_list = {
		count = 1
		education_stewardship_4 = {}
		education_diplomacy_4 = {}
	}
	random_traits_list = {
		count = 4
		beauty_good_1 = {}
		intellect_good_1 = {}
		physique_good_1 = {}
		beauty_good_2 = {}
		intellect_good_2 = {}
		physique_good_2 = {}
		beauty_good_3 = {}
		intellect_good_3 = {}
		physique_good_3 = {}
		fecund = {}
	}
	trait = content
	random_traits_list = {
		count = 2
		trusting = {}
		lustful = {}
		diligent = {}
		patient = {}
		humble = {}
		just = {}
		gregarious = {}
	}
	random_traits_list = {
		count = 2
		administrator = {}
		architect = {}
		diplomat = {}
		family_first = {}
	}
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
	diplomacy = {
		min_template_high_skill
		max_template_high_skill
	}
	stewardship = {
		min_template_high_skill
		max_template_high_skill
	}
}

regula_inititate_breeder_royal_character = {
	age = { 18 18 }
	random_traits_list = {
		education_martial_3 = {}
		education_stewardship_3 = {}
		education_diplomacy_3 = {}
		education_learning_3 = {}
		education_intrigue_3 = {}
	}
	trait = beauty_good_3
	trait = intellect_good_3
	trait = physique_good_3
	trait = fecund
	trait = pure_blooded
	trait = lustful
	random_traits_list = {
		count = 2
		gregarious = {}
		content = {}
		honest = {}
		humble = {}
		trusting = {}
		calm = {}
	}
	trait = whole_of_body
	# Breeder trait
	trait = regula_bun_bloodline
	# Multitasker trait
	trait = regula_multitasker_bloodline
	dynasty = none
	random_traits = no
	faith = this.faith
	culture = this.culture
}


code:
marriage_interaction_on_accept_effect = {
	#Use hook
	if = {
		limit = { always = scope:marriage_hook }
		scope:actor = {
			use_hook = scope:recipient
		}
		#To make sure betrothals can't be broken if a hook was used
		if = {
			limit = {
				OR = {
					scope:secondary_actor = { is_adult = no }
					scope:secondary_recipient = { is_adult = no }
				}
			}
			scope:secondary_actor = {
				set_variable = {
					name = hook_used_for_betrothal
					value = scope:secondary_recipient
				}
			}
		}
	}

	#No longer concubine
	if = {
		limit = {
			scope:secondary_recipient = { is_concubine = yes }
		}
		scope:secondary_recipient = {
			random_consort = {
				limit = {
					any_concubine = { this = scope:secondary_recipient }
				}
				remove_concubine = scope:secondary_recipient
			}
		}
	}
	if = {
		limit = {
			scope:secondary_actor = { is_concubine = yes }
		}
		scope:secondary_actor = {
			random_consort = {
				limit = {
					any_concubine = { this = scope:secondary_actor }
				}
				remove_concubine = scope:secondary_actor
			}
		}
	}

	#Marriage notification events
	hidden_effect = {
		scope:actor = {
			if = {
				limit = { NOT = { this = scope:recipient } }
				trigger_event = marriage_interaction.0010
			}
			else = { #In my own court
				if = {
					limit = { #Betrothal?
						OR = {
							scope:secondary_actor = { is_adult = no }
							scope:secondary_recipient = { is_adult = no }
						}
					}
					send_interface_toast = {
						title = arrange_marriage_interaction_accept_betrothal_toast
						left_icon = scope:secondary_actor
						right_icon = scope:secondary_recipient
						custom_tooltip  = arrange_marriage_interaction_accept_betrothal_toast_desc
					}
				}
				else = {
					send_interface_toast = {
						title = arrange_marriage_interaction_accept_toast
						left_icon = scope:secondary_actor
						right_icon = scope:secondary_recipient
						custom_tooltip  = arrange_marriage_interaction_accept_toast_desc
					}
				}
			}
		}

		# Apply any relevant opinion penalties for relatives of spouse.
		scope:secondary_actor = {
			if = { # Polygamy
				limit = {
					any_consort = {
						count >= 2
					}
				}
				every_consort = {
					# If the spouse themselves does not believe in polygamy...
					limit = {
						NOR = {
							culture = { has_cultural_tradition = tradition_polygamous }
							faith = { is_polygamous = yes }
							faith = { has_doctrine = doctrine_concubines }
						}
					}

					#... then family members who also do not believe in polygamy aren't happy about having a relative forced into polygamous union with you.
					every_close_family_member = {
						if = {
							limit = {
								NOR = {
									culture = { has_cultural_tradition = tradition_polygamous }
									faith = { has_doctrine = doctrine_polygamy }
									faith = { has_doctrine = doctrine_concubines }
								}
							}
							add_opinion = {
								target = scope:secondary_actor
								modifier = relative_in_blasphemous_union_opinion
							}
						}
					}

					# NOTE: Spouse's own opinions handled in the 'on_marriage' code on_action inside of marriage_concubinage.txt, and are not included here.
				}
			}
		}
		scope:secondary_recipient = {
			if = { #Same-sex relations
				limit = {
					allowed_to_marry_same_sex_trigger = no
					sex_same_as = scope:secondary_actor
				}
				every_close_family_member = {
					if = {
						limit = {
							allowed_to_marry_same_sex_trigger = no
						}
						add_opinion = {
							target = scope:secondary_actor
							modifier = relative_in_blasphemous_union_opinion
						}
					}
				}
			}
		}
	}

	###MANAGEMENT SCRIPT FOR VARIOUS EVENTS/CONTENT###

	#If your spouse councillor had boosted the chance of marriage, remove modifier
	if = {
		limit = {
			scope:secondary_actor = {
				has_character_modifier = heir_easier_to_marry_off_modifier
			}
			scope:actor = { player_heir = scope:secondary_actor }
		}
		scope:secondary_actor = {
			remove_character_modifier = heir_easier_to_marry_off_modifier
		}
	}
	if = {
		limit = {
			scope:secondary_actor = {
				is_child_of = scope:actor
				has_character_modifier = child_easier_to_marry_off_modifier
			}
		}
		scope:secondary_actor = {
			remove_character_modifier = child_easier_to_marry_off_modifier
		}
	}

	#AI Break up consideration after marriage
	scope:secondary_recipient = {
		if = {
			limit = {
				is_adult = yes
				is_ai = yes
			}
			scope:secondary_actor = { save_scope_as = new_spouse_secondary_actor }
			trigger_event = lover.0205
		}
	}
	scope:secondary_actor = {
		if = {
			limit = {
				is_adult = yes
				is_ai = yes
			}
			scope:secondary_recipient = { save_scope_as = new_spouse_secondary_recipient }
			trigger_event = lover.0205
		}
	}

	# Struggle parameters

	#interfaith wedding costs piety
	if = {
		limit = {
			scope:secondary_actor = {
				NOT = { faith = scope:secondary_recipient.faith }
			}
			scope:actor ={
				any_character_struggle = {
					has_struggle_phase_parameter = interfaith_marriages_between_involved_characters_costs_piety
				}
			}
		}
		scope:actor = {
			add_piety = major_piety_loss
		}
	}
	#interfaith wedding provides piety
	if = {
		limit = {
			scope:secondary_actor = {
				NOT = { faith = scope:secondary_recipient.faith }
			}
			scope:actor ={
				any_character_struggle = {
					has_struggle_phase_parameter = interfaith_marriages_between_involved_characters_gives_piety
				}
			}
		}
		scope:actor = {
			add_piety = medium_piety_gain
		}
	}
}

concubine_on_accept_effect = {
	scope:recipient = {
		trigger_event = marriage_interaction.0040
		if = {
			# Victim is angry for being forced into concubinage.
			limit = {
				is_imprisoned = yes
			}
			release_from_prison = yes
			add_opinion = {
				target = scope:actor
				modifier = forced_me_concubine_marriage_opinion
			}

			# Family members of victim are also angry that you've forced them into concubinage.
			every_close_family_member = {
				if = {
					limit = {
						NOT = { this = scope:actor } # Don't hate yourself.
					}
					add_opinion = {
						target = scope:actor
						modifier = forced_family_concubine_marriage_opinion
					}
					hidden_effect = {
						send_interface_message = {
							type = event_generic_neutral
							title = msg_close_family_member_taken_as_concubine_title
							right_icon = scope:recipient
							left_icon = scope:secondary_actor
							show_as_tooltip = { scope:secondary_actor = { make_concubine = scope:recipient } }
						}
					}

					# Family members are even *more* angry if they don't believe in concubines/polyamory (different from polygamy). Also if they don't accept same-sex relationships
					if = {
						limit = {
							OR = {
								NOT = { faith = { has_doctrine = doctrine_concubines } }
								NOT = { faith = { has_doctrine = tenet_polyamory } }
								AND = {
									allowed_to_marry_same_sex_trigger = no
									scope:recipient = { sex_same_as = scope:secondary_actor }
								}
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = relative_in_blasphemous_union_opinion
						}
					}
				}
			}

			# Spouses, if any exist, are also furious.
			if = {
				limit = {
					is_married = yes
				}
				every_spouse = {
					show_as_tooltip = {
						add_opinion = {
							target = scope:actor
							modifier = forced_spouse_concubine_marriage_opinion
						}
						divorce = scope:recipient # no additional opinion hit, no scripted effect
					}
					trigger_event = marriage_interaction.0041
				}
			}

			# Stealing concubines pisses the former concubinist off.
			if = {
				limit = {
					is_concubine = yes
				}
				this.concubinist = {
					show_as_tooltip = {
						add_opinion = {
							target = scope:secondary_actor
							modifier = stole_concubine_opinion
						}
						remove_concubine = scope:recipient # no additional opinion hit, no scripted effect
					}
					trigger_event = marriage_interaction.0041
				}
			}

			# Break any betrothals which may exist (without additional opinion penalties).
			if = {
				limit = { exists = betrothed }
				betrothed = { trigger_event = marriage_interaction.0041 }
				break_betrothal = betrothed
			}

			# Having concubines means they're now no longer yours.
			if = {
				limit = { number_of_concubines > 0	}
				every_concubine = {
					scope:recipient = {
						remove_concubine = prev
					}
				}
			}
		}
	}

	# Send us a notification about what we just did.
	scope:secondary_actor = {
		hidden_effect = {
			send_interface_toast = {
				type = event_generic_neutral
				title = msg_concubine_taken_title
				right_icon = scope:recipient
				make_concubine = scope:recipient
			}
		}
	}
}

#This effect has some small differences to the previous one since this one involves one extra person (the one you give a concubine to)
concubine_offer_on_accept_effect = {
	scope:secondary_actor = {
		trigger_event = marriage_interaction.0040
		if = {
			# Victim is angry for being forced into concubinage.
			limit = {
				is_imprisoned = yes
			}
			add_character_flag = {
				flag = block_release_from_prison_event
				days = 3
			}
			release_from_prison = yes
			add_opinion = {
				target = scope:actor
				modifier = forced_me_concubine_marriage_opinion
			}

			# Family members of victim are also angry that you've forced them into concubinage.
			every_close_family_member = {
				if = {
					limit = {
						NOT = { this = scope:actor } # Don't hate yourself.
					}
					add_opinion = {
						target = scope:actor
						modifier = forced_family_concubine_marriage_opinion
					}
					hidden_effect = {
						send_interface_message = {
							type = event_generic_neutral
							title = msg_close_family_member_offered_as_concubine_title
							right_icon = scope:recipient
							left_icon = scope:secondary_actor
							show_as_tooltip = { scope:secondary_actor = { make_concubine = scope:recipient } }
						}
					}

					# Family members are even *more* angry if they don't believe in concubines/polyamory (different from polygamy). Also if they don't accept same-sex relationships
					if = {
						limit = {
							OR = {
								NOT = { faith = { has_doctrine = doctrine_concubines } }
								NOT = { faith = { has_doctrine = tenet_polyamory } }
								AND = {
									allowed_to_marry_same_sex_trigger = no
									scope:recipient = { sex_same_as = scope:secondary_actor }
								}
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = relative_in_blasphemous_union_opinion
						}
					}
				}
			}

			# Spouses, if any exist, are also furious.
			if = {
				limit = {
					is_married = yes
					#A check to make sure you haven't somehow married them during the consideration time
					NOT = { any_spouse = { this = scope:recipient } }
				}
				every_spouse = {
					add_opinion = {
						target = scope:actor
						modifier = forced_spouse_concubine_marriage_opinion
					}
					divorce = scope:secondary_actor # no additional opinion hit, no scripted effect
					save_scope_value_as = { # For tooltips in the coming event
						name = was_spouse
						value = yes
					}
					trigger_event = marriage_interaction.0043
				}
			}

			# Stealing concubines pisses the former concubinist off.
			if = {
				limit = {
					is_concubine = yes
					#A check to make sure you haven't somehow gotten them as concubine during the consideration time
					NOT = { any_consort = { this = scope:recipient } }
				}
				this.concubinist = {
					if = {
						limit = {
							NOT = {
								this = scope:actor
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = stole_concubine_opinion
						}
						remove_concubine = scope:secondary_actor # no additional opinion hit, no scripted effect
						save_scope_value_as = { # For tooltips in the coming event
							name = was_concubine
							value = yes
						}
						trigger_event = marriage_interaction.0043
					}
					else = {
						remove_concubine = scope:secondary_actor # no additional opinion hit, no scripted effect
					}
				}
			}

			# Break any betrothals which may exist (without additional opinion penalties).
			if = {
				limit = {
					exists = betrothed
					#A check to make sure you haven't somehow gotten betrothed to them during the consideration time
					NOT = { betrothed = scope:recipient }
				}
				betrothed = { trigger_event = marriage_interaction.0043 }
				break_betrothal = betrothed
			}

			# Having concubines means they're now no longer yours.
			if = {
				limit = { number_of_concubines > 0	}
				every_concubine = {
					scope:secondary_actor = {
						remove_concubine = prev
					}
				}
			}
		}
		if = {
			limit = {
				is_concubine_of = scope:actor
			}
			scope:actor = {
				remove_concubine = scope:secondary_actor
			}
		}
		remove_character_flag = has_been_offered_as_concubine
	}

	# Send us a notification about what we just did. If the secondary_actor somehow ended up as a consort (spouse/concubine) or betrothed to recipient during the consideration time of this request we'll send a message about that instead (should only happen to AI tho)
	if = {
		limit = { #Invalidation message
			scope:secondary_actor = {
				OR = {
					any_consort = { count >= 1 }
					exists = betrothed
				}
			}
		}
		scope:secondary_actor = {
			# If they've somehow already become entangled with the recipient we tell this
			if = {
				limit = {
					OR = {
						is_consort_of = scope:recipient
						AND = {
							exists = betrothed
							betrothed = scope:recipient
						}
					}
				}
				scope:recipient = {
					save_scope_as = spouse
				}
			}
			# Else, if they've married or gotten betrothed to someone else, we say this
			else_if = {
				limit = {
					exists = betrothed
				}
				betrothed = {
					save_scope_as = spouse
				}
			}
			else = {
				random_consort = {
					limit = {
						this = scope:secondary_actor.primary_spouse
					}
					alternative_limit = {
						always = yes
					}
					save_scope_as = spouse
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_generic_neutral
				title = msg_concubine_offered_invalidated_title
				right_icon = scope:recipient
				left_icon = scope:secondary_actor
				if = {
					limit = {
						scope:secondary_actor = { is_consort_of = scope:spouse }
					}
					custom_tooltip = msg_concubine_offered_invalidated_consort
				}
				else = {
					custom_tooltip = msg_concubine_offered_invalidated_betrothed
				}
			}
		}
		scope:recipient = {
			send_interface_toast = {
				type = event_generic_neutral
				title = msg_concubine_offered_invalidated_recipient_title
				right_icon = scope:actor
				left_icon = scope:secondary_actor
				if = {
					limit = {
						scope:secondary_actor = { is_consort_of = scope:spouse }
					}
					custom_tooltip = msg_concubine_offered_invalidated_consort
				}
				else = {
					custom_tooltip = msg_concubine_offered_invalidated_betrothed
				}
			}
		}
	}
	else = { #Proper notification
		scope:actor = {
			send_interface_toast = {
				type = event_generic_neutral
				title = msg_concubine_offered_title
				right_icon = scope:recipient
				left_icon = scope:secondary_actor
				scope:recipient = {
					make_concubine = scope:secondary_actor
					if = { #Scale opinion gain a bit depending on how cool the concubine is
						limit = {
							scope:secondary_actor = {
								OR = {
									has_trait = beauty_good_2
									has_trait = beauty_good_3
									num_of_good_genetic_traits > 1
									has_relation_lover = scope:recipient
									has_relation_soulmate = scope:recipient
								}
								trigger_if = {
									limit = {
										is_female = yes
									}
									age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
								}
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = grateful_opinion
							opinion = 40
						}
					}
					else_if = {
						limit = {
							scope:secondary_actor = {
								OR = {
									is_lowborn = no
									has_trait = beauty_good_1
									num_of_good_genetic_traits > 0
									has_relation_friend = scope:recipient
									has_relation_best_friend = scope:recipient
								}
								trigger_if = {
									limit = {
										is_female = yes
									}
									age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
								}
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = grateful_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = scope:actor
							modifier = grateful_opinion
							opinion = 20
						}
					}
				}
			}
		}
	}
}

divorce_effect = {
	$DIVORCER$ = {
		if = {
			limit = {
				any_spouse = {
					this = $DIVORCEE$
				}
			}
			divorce = $DIVORCEE$
		}

		reverse_add_opinion = {
			modifier = divorced_me_opinion
			target = $DIVORCEE$
		}
	}
	# Opinion hit
	$DIVORCEE$ = {
		every_close_or_extended_family_member = {
			limit = { NOT = { this = $DIVORCER$ } } # don't hate yourself just because of some incest
			custom = all_family_members
			add_opinion = {
				modifier = divorced_close_kin
				target = $DIVORCER$
			}
		}
	}

	if = {
		limit = {
			$DIVORCER$ = {
				has_character_modifier = rejected_from_marriage_bed_modifier
			}
		}
		$DIVORCER$ = { remove_character_modifier = rejected_from_marriage_bed_modifier }
	}
	if = {
		limit = {
			$DIVORCEE$ = {
				has_character_modifier = rejected_from_marriage_bed_modifier
			}
		}
		$DIVORCEE$ = { remove_character_modifier = rejected_from_marriage_bed_modifier }
	}
}

less_verbose_divorce_effect = {
	$DIVORCER$ = {
		if = {
			limit = {
				any_spouse = {
					this = $DIVORCEE$
				}
			}
			divorce = $DIVORCEE$
		}

		hidden_effect = {
			reverse_add_opinion = {
				modifier = divorced_me_opinion
				target = $DIVORCEE$
			}
		}
	}
	hidden_effect = {
		# Opinion hit
		$DIVORCEE$ = {
			every_close_or_extended_family_member = {
				limit = { NOT = { this = $DIVORCER$ } } # don't hate yourself just because of some incest
				custom = all_family_members
				add_opinion = {
					modifier = divorced_close_kin
					target = $DIVORCER$
				}
			}
		}

		if = {
			limit = {
				$DIVORCER$ = {
					has_character_modifier = rejected_from_marriage_bed_modifier
				}
			}
			$DIVORCER$ = { remove_character_modifier = rejected_from_marriage_bed_modifier }
		}
		if = {
			limit = {
				$DIVORCEE$ = {
					has_character_modifier = rejected_from_marriage_bed_modifier
				}
			}
			$DIVORCEE$ = { remove_character_modifier = rejected_from_marriage_bed_modifier }
		}
	}
}

marriage_soulmate_exclusivity_confrontation_effect = {
	$SPOUSE_1$ = { add_to_temporary_list = new_spouses }
	$SPOUSE_2$ = { add_to_temporary_list = new_spouses }

	every_in_list = {
		list = new_spouses
		limit = {
			any_relation = {
				type = soulmate
				NOT = { is_in_list = new_spouses }
			}
		}
		add_character_flag = {
			flag = can_be_confronted_about_lover_exclusivity
			days = 1825
		}
	}
}

# CHARACTER = character we check for if they should send a message
# SPOUSE = the spouse in this divorce
# scope:reason = flag:script or flag:faith
send_divorce_notifications_effect = {
	$CHARACTER$ = {
		if = {
			limit = {
				is_ai = no
			}
			switch = {
				trigger = scope:reason
				flag:script = {
					send_interface_message = {
						type = msg_divorce
						left_icon = $SPOUSE$
					}
				}
				flag:faith = {
					send_interface_message = {
						type = msg_spouse_invalidated
						left_icon = $SPOUSE$
					}
				}
			}
		}
		else_if = {
			limit = {
				any_heir_to_title = {
					exists = holder
					holder = { is_ai = no }
				}
			}
			every_heir_to_title = {
				limit = {
					exists = holder
					holder = { is_ai = no }
				}
				holder = {
					if = {
						limit = {
							NOT = { is_in_list = had_notification_sent }
						}
						add_to_list = had_notification_sent
						switch = {
							trigger = scope:reason
							flag:script = {
								send_interface_message = {
									type = msg_divorce_player_heir
									left_icon = $CHARACTER$
									right_icon = $SPOUSE$
								}
							}
							flag:faith = {
								send_interface_message = {
									type = msg_spouse_invalidated_player_heir
									left_icon = $CHARACTER$
									right_icon = $SPOUSE$
								}
							}
						}
					}
				}
			}
		}
	}
}

# CHARACTER = character we check for if they should send a message
# BETROTHED = the other person in the betrothal
# scope:reason = flag:timeout, flag:death, flag:faith, or flag:script
send_break_betrothal_notifications_effect = {
	$CHARACTER$ = {
		if = {
			limit = {
				is_ai = no
			}
			switch = {
				trigger = scope:reason
				flag:script = {
					send_interface_message = {
						type = msg_break_betrothal
						left_icon = $BETROTHED$
					}
				}
				flag:faith = {
					send_interface_message = {
						type = msg_betrothal_invalidated
						left_icon = $BETROTHED$
					}
				}
				# flag:death is hanlded by normal death management events
				# flag:timeout is hanlded by caller separately
			}
		}
		else_if = {
			limit = {
				any_heir_to_title = {
					exists = holder
					holder = { is_ai = no }
				}
			}
			every_heir_to_title = {
				limit = {
					holder = { is_ai = no }
				}
				holder = {
					if = {
						limit = {
							NOT = { is_in_list = had_notification_sent }
						}
						add_to_list = had_notification_sent
						switch = {
							trigger = scope:reason
							flag:script = {
								send_interface_message = {
									type = msg_break_betrothal_player_heir
									left_icon = $CHARACTER$
									right_icon = $BETROTHED$
								}
							}
							flag:faith = {
								send_interface_message = {
									type = msg_betrothal_invalidated_player_heir
									left_icon = $CHARACTER$
									right_icon = $BETROTHED$
								}
							}
							# flag:death is hanlded by normal death management events
							# flag:timeout is hanlded by caller separately
						}
					}
				}
			}
		}
	}
}

# When you take spouses/concubines whose Faith does not permit that union, they will gain opinion penalties.
# This effect adds/updates/replaces/removes those opinion penalties, as approprite to the current situation.
update_active_consort_opinion_effect = {

	# If we currently have any existing consort opinion modifiers, check if they should be downgraded from permanent modifiers to decaying modifiers.
	downgrade_invalid_consort_opinions_effect = { PARTNER = $PARTNER$ }

	if = {
		# If this opinion change was triggered by being divorced/set-aside, we may still technically be married/joined to PARTNER at this moment, but we won't be very shortly and should skip this step.
		limit = {
			NOR = {
				exists = scope:is_being_divorced
				exists = scope:is_being_set_aside
			}
		}

		# Oterwise, apply any new consort opinion effects that are applicable.
		if = {
			# Characters who do not believe in concubinage, but are forced into it, have the harshest opinion penalties.
			limit = {
				is_concubine_of = $PARTNER$
				NOT = { faith = { has_doctrine = doctrine_concubines }}
			}
			if = {
				# Harshest opinion penalty if they are a concubine but believe in monogamy
				limit = { faith = { has_doctrine = doctrine_monogamy }}
				add_opinion = {
					target = $PARTNER$
					modifier = concubine_with_monogamous_faith_opinion
				}
			}
			else_if = {
				# Lesser-but-still-harsh opinion penalty if they are a concubine but believe in polygamy
				limit = {
					OR = {
						culture = { has_cultural_tradition = tradition_polygamous }
						faith = { has_doctrine = doctrine_polygamy }
					}
				}
				add_opinion = {
					target = $PARTNER$
					modifier = concubine_with_polygamous_faith_opinion
				}
			}
		}
		else_if = {
			# Characters who are legitimate spouses of their partner, but do not approve of their partner's other spouses/concubines, will have milder opinion penalties.
			limit = {
				is_spouse_of = $PARTNER$
				$PARTNER$ = { any_consort = { count >= 2 }}
				NOT = { faith = { has_doctrine = doctrine_concubines }}
				NOT = { faith = { has_doctrine = tenet_polyamory }}
			}
			if = {
				limit = {
					$PARTNER$ = { any_concubine = { count >= 1 }}
				}
				add_opinion = {
					target = $PARTNER$
					modifier = spouse_does_not_believe_in_concubines_opinion
				}
				#Remove the opinion modifier if you flip-flop and go get concubines after getting rid of them all...
				remove_opinion = {
					target = $PARTNER$
					modifier = spouse_does_not_believe_in_former_concubines_opinion
				}
			}
			else_if = {
				limit = {
					NOR = {
						culture = { has_cultural_tradition = tradition_polygamous }
						faith = { is_polygamous = yes }

					}
				}
				add_opinion = {
					target = $PARTNER$
					modifier = polygamous_marriage_opinion
				}
			}
		}
		#Same-sex not accepted penalty
		if = {
			limit = {
				allowed_to_marry_same_sex_trigger = no
				sex_same_as = $PARTNER$
			}
			add_opinion = {
				target = $PARTNER$
				modifier = same_sex_with_no_acceptance_opinion
			}
		}
	}
}

# Checks if we have any permanent opinion modifiers which are no longer applicable. If so, downgrade them to decaying opinion modifiers.
downgrade_invalid_consort_opinions_effect = {
	if = {
		limit = {
			has_opinion_modifier = {
				modifier = concubine_with_monogamous_faith_opinion
				target = $PARTNER$
			}
			OR = {
				# We are no longer a concubine of PARTNER...
				NOT = { is_concubine_of = $PARTNER$ }
				# ...or will no longer be a concubine of them.
				trigger_if = {
					limit = { exists = scope:is_being_set_aside}
					scope:is_being_set_aside = this
				}

				# Or, our Faith has changed to permit us being a concubine.
				faith = { has_doctrine = doctrine_concubines }
			}
		}
		remove_opinion = {
			modifier = concubine_with_monogamous_faith_opinion
			target = $PARTNER$
		}
		add_opinion = {
			modifier = formerly_concubine_with_monogamous_faith_opinion
			target = $PARTNER$
		}
	}

	if = {
		limit = {
			has_opinion_modifier = {
				modifier = concubine_with_polygamous_faith_opinion
				target = $PARTNER$
			}
			OR = {
				# We are no longer a concubine of PARTNER...
				NOT = { is_concubine_of = $PARTNER$ }
				# ...or will no longer be a concubine of them.
				trigger_if = {
					limit = { exists = scope:is_being_set_aside}
					scope:is_being_set_aside = this
				}

				# Or, our Faith has changed to permit us being a concubine.
				faith = { has_doctrine = doctrine_concubines }
			}
		}
		remove_opinion = {
			modifier = concubine_with_polygamous_faith_opinion
			target = $PARTNER$
		}
		add_opinion = {
			modifier = formerly_concubine_with_polygamous_faith_opinion
			target = $PARTNER$
		}
	}

	if = {
		limit = {
			has_opinion_modifier = {
				modifier = spouse_does_not_believe_in_concubines_opinion
				target = $PARTNER$
			}
			OR = {
				# We are no longer married to PARTNER...
				NOT = { is_spouse_of = $PARTNER$ }
				# ...or will no longer be married to them.
				trigger_if = {
					limit = { exists = scope:is_being_divorced}
					scope:is_being_divorced = this
				}

				# Or, the offending relationship no longer exists.
				$PARTNER$ = { any_concubine = {	count = 0 }}
				AND = {
					# The last remaining concubine is being set aside, leaving none.
					exists = scope:is_being_set_aside
					$PARTNER$ = { any_concubine = { count = 1 }}
				}

				# Or, our Faith has changed to permit the relationship.
				faith = { has_doctrine = doctrine_concubines }
				faith = { has_doctrine = tenet_polyamory }
			}
		}
		remove_opinion = {
			modifier = spouse_does_not_believe_in_concubines_opinion
			target = $PARTNER$
		}
		add_opinion = {
			modifier = spouse_does_not_believe_in_former_concubines_opinion
			target = $PARTNER$
		}
	}

	if = {
		limit = {
			has_opinion_modifier = {
				modifier = polygamous_marriage_opinion
				target = $PARTNER$
			}
			OR = {
				# We are no longer married to PARTNER...
				NOT = { is_spouse_of = $PARTNER$ }
				# ...or will no longer be married to them.
				trigger_if = {
					limit = { exists = scope:is_being_divorced}
					scope:is_being_divorced = this
				}

				# Or, the offending relationship no longer exists.
				$PARTNER$ = { any_spouse = { count = 1 }}
				AND = {
					# One of the 2 remaining spouses will be divorced next tick, leaving only 1.
					exists = scope:is_being_divorced
					$PARTNER$ = { any_spouse = { count = 2 }}
				}

				# Or, our Faith has changed to permit the relationship.
				faith = { has_doctrine = doctrine_concubines }
				culture = { has_cultural_tradition = tradition_polygamous }
				faith = { is_polygamous = yes }
				faith = { has_doctrine = tenet_polyamory }
			}
		}
		remove_opinion = {
			modifier = polygamous_marriage_opinion
			target = $PARTNER$
		}
		add_opinion = {
			modifier = former_polygamous_marriage_opinion
			target = $PARTNER$
		}
	}

	if = {
		limit = {
			has_opinion_modifier = {
				modifier = same_sex_with_no_acceptance_opinion
				target = $PARTNER$
			}
			OR = {
				# We are no partner of PARTNER...
				NOT = { is_consort_of = $PARTNER$ }
				# ...or will no longer be married to them
				trigger_if = {
					limit = { exists = scope:is_being_divorced}
					scope:is_being_divorced = this
				}
				# ...or will no longer be a concubine of them
				trigger_if = {
					limit = { exists = scope:is_being_set_aside}
					scope:is_being_set_aside = this
				}

				# Or, the offending relationship no longer exists.
				sex_opposite_of = $PARTNER$

				# Or, our Faith has changed to permit the relationship.
				allowed_to_marry_same_sex_trigger = yes
			}
		}
		remove_opinion = {
			modifier = same_sex_with_no_acceptance_opinion
			target = $PARTNER$
		}
		add_opinion = {
			modifier = former_same_sex_with_no_acceptance_opinion
			target = $PARTNER$
		}
	}
}