code:
###MARRIAGE SCRIPTED MODIFIERS###

marriage_ai_accept_modifier = { ###MARRIAGE SCRIPTED MODIFIERS###
	#########
	# HOOKS #
	#########
	modifier = { #Weak hook
		scope:marriage_hook = yes
		add = 100
		scope:actor = { NOT = { has_strong_hook = scope:recipient } }
		desc = SCHEME_WEAK_HOOK_USED
	}
	modifier = { #Strong Hook (in some cases it's not auto accept)
		scope:marriage_hook = yes
		add = 200
		scope:actor = { has_strong_hook = scope:recipient }
		desc = SCHEME_STRONG_HOOK_USED
	}

	#########
	# PERKS #
	#########
	modifier = { # A lot of acceptance for yourself - you are likely already married, thus you need motivation to get rid of your spouse to marry someone better
		scope:actor = { has_perk = promising_prospects_perk }
		scope:actor = scope:secondary_actor
		add = promising_prospects_self_value
		desc = PROMISING_PROSPECTS_PERK_MODIFIER
	}
	modifier = { # A significant but lesser chunk of acceptance for your extended family, to increase the value of the perk!
		scope:actor = { has_perk = promising_prospects_perk }
		NOT = { scope:actor = scope:secondary_actor }
		scope:secondary_actor = {
			is_close_or_extended_family_of = scope:actor
		}
		add = promising_prospects_other_value
		desc = PROMISING_PROSPECTS_PERK_MODIFIER
	}
	modifier = { # Dynasty Glory Perk acceptance, checks the secondary recipients dynasty for the perk
		exists = scope:secondary_actor.dynasty
		scope:secondary_actor.dynasty = { has_dynasty_perk = glory_legacy_1 }
		add = glory_legacy_1_marriage_acceptance
		desc = DYNASTY_LEGACY_GLORY_MARRIAGE_ACCEPTANCE_PERK_MODIFIER
	}

	##########################
	# WHO IS GETTING MARRIED #
	##########################
	modifier = {
		add = -15 # Less likely if it's the recipient him/herself
		scope:recipient = scope:secondary_recipient
		desc = MY_OWN_MARRIAGE_REASON
	}
	#More likely if the secondary_actor is the actor's heir
	modifier = {
		add = 10
		scope:actor = {
			exists = player_heir
			player_heir_position = {
				value <= 4 #0, 1, 2, 3, 4 = 5 first player heirs
				target = scope:secondary_actor
			}
			NOT = {
				player_heir_position = {
					value = 0 #player heir
					target = scope:secondary_actor
				}
			}
		}
		scope:actor = {
			tier_difference = {
				target = scope:recipient
				value > 0
			}
		}
		desc = MARRYING_HEIR_REASON
	}

	modifier = {
		add = 20
		scope:actor = {
			exists = player_heir
			player_heir_position = {
				value = 0 #player heir
				target = scope:secondary_actor
			}
		}
		scope:actor = {
			tier_difference = {
				target = scope:recipient
				value > 0
			}
		}
		desc = MARRYING_HEIR_REASON
	}

	##############################################
	# ALLIANCE/HOSTILITY FACTORS ("REALPOLITIK") #
	##############################################
	modifier = {
		add = {
			value = 40
			if = {
				limit = {
					scope:actor = {
						tier_difference = {
							target = scope:recipient
							value = -1
						}
					}
				}
				subtract = 10
			}
			else_if = {
				limit = {
					scope:actor = {
						tier_difference = {
							target = scope:recipient
							value = -2
						}
					}
				}
				subtract = 30
			}
			if = {
				limit = {
					scope:actor = {
						any_ally = {
							NOR = {
    							target_is_liege_or_above = scope:actor
    							target_is_vassal_or_below = scope:actor
							}
							count >= 2
						}
					}
				}
				scope:actor = {
					every_ally = {
						limit = {
							NOR = {
    							target_is_liege_or_above = scope:actor
    							target_is_vassal_or_below = scope:actor
							}
						}
						multiply = 0.5
					}
				}
			}
		}
		scope:recipient = {
			NOR = {
				is_allied_to = scope:actor
				scope:actor = { # Emperors do not care for Counts at all
					tier_difference = {
						target = scope:recipient
						value <= -3
					}
				}
			}
			OR = {
				ai_diplomacy_stance = {
					target = scope:actor
					stance = neutral
				}
				ai_diplomacy_stance = {
					target = scope:actor
					stance = threat
				}
			}
			yields_alliance = {
				candidate = scope:secondary_recipient
				target = scope:actor
				target_candidate = scope:secondary_actor
			}
		}
		OR = {
			scope:actor = {
				is_independent_ruler = yes
			}
			scope:recipient = {
				is_independent_ruler = yes
			}
			scope:recipient.liege = scope:actor.liege
		}

		desc = DESIRES_ALLIANCE
	}
	modifier = {
		add = {
			value = 100
			if = {
				limit = {
					scope:actor = {
						any_ally = {
							NOR = {
    							target_is_liege_or_above = scope:actor
    							target_is_vassal_or_below = scope:actor
							}
							count >= 2
						}
					}
				}
				scope:actor = {
					every_ally = {
						limit = {
							NOR = {
    							target_is_liege_or_above = scope:actor
    							target_is_vassal_or_below = scope:actor
							}
						}
						multiply = 0.5
					}
				}
			}
		}
		scope:recipient = {
			NOT = { is_allied_to = scope:actor }
			ai_diplomacy_stance = {
				target = scope:actor
				stance = friend
			}
			yields_alliance = {
				candidate = scope:secondary_recipient
				target = scope:actor
				target_candidate = scope:secondary_actor
			}
		}
		desc = DESIRES_ALLIANCE
	}
	modifier = {
		add = -100
		scope:recipient = {
			NOT = { is_allied_to = scope:actor }
			ai_diplomacy_stance = {
				target = scope:actor
				stance = enemy
			}
			yields_alliance = {
				candidate = scope:secondary_recipient
				target = scope:actor
				target_candidate = scope:secondary_actor
			}
		}
		desc = DOES_NOT_WANT_ALLIANCE
	}
	modifier = {
		add = {
			scope:actor = {
				every_ally = {
					limit = {
						NOR = {
    						target_is_liege_or_above = scope:actor
    						target_is_vassal_or_below = scope:actor
						}
					}
					add = -15
				}
			}
		}
		scope:actor = {
			any_ally = {
				NOR = {
					target_is_vassal_or_below = scope:actor
					target_is_liege_or_above = scope:actor
				}
				count >= 2
			}
		}
		scope:recipient = {
			NOR = {
				is_allied_to = scope:actor
				target_is_vassal_or_below = scope:actor
				target_is_liege_or_above = scope:actor
			}
			yields_alliance = {
				candidate = scope:secondary_recipient
				target = scope:actor
				target_candidate = scope:secondary_actor
			}
		}
		desc = YOU_HAVE_TOO_MANY_ALLIANCES
	}
	# Clan contract: Marriage Favor
	modifier = {
		add = 100
		OR = {
			# Liege PoV
			scope:recipient = {
				is_vassal_of = scope:actor
				vassal_contract_has_flag = vassal_contract_marriage_favor
			}
			# Vassal PoV
			scope:actor = {
				is_vassal_of = scope:recipient
				vassal_contract_has_flag = vassal_contract_marriage_favor
			}
		}

		desc = VASSAL_CONTRACT_MARRIAGE_FAVOR_BONUS
	}

	####################
	# TIER DIFFERENCES #
	####################
	modifier = {
		scope:recipient = {
			OR = {
				AND = {
					is_lowborn = no
					dynasty = scope:secondary_recipient.dynasty
				}
				is_close_or_extended_family_of = scope:secondary_recipient
			}
		}
		scope:actor = {
			OR = {
				is_close_or_extended_family_of = scope:secondary_actor
				this = scope:secondary_actor
			}
			tier_difference = {
				target = scope:recipient
				value >= 1
			}
		}
		add = {
			value = scope:actor.highest_held_title_tier
			subtract = scope:recipient.highest_held_title_tier
			multiply = 30
		}
		desc = MARRYING_UP_REASON
	}

	modifier = {
		scope:recipient = {
			OR = {
				AND = {
					is_lowborn = no
					dynasty = scope:secondary_recipient.dynasty
				}
				is_close_or_extended_family_of = scope:secondary_recipient
			}
		}
		scope:actor = {
			OR = {
				is_close_or_extended_family_of = scope:secondary_actor
				this = scope:secondary_actor
			}
			tier_difference = {
				target = scope:recipient
				value <= -1
			}
		}
		add = {
			value = scope:actor.highest_held_title_tier
			subtract = scope:recipient.highest_held_title_tier
			if = {
				limit = { scope:actor.highest_held_title_tier = tier_kingdom }
				multiply = 30
			}
			else = {
				multiply = 40
			}
		}
		desc = MARRYING_DOWN_REASON
	}

	modifier = {
		scope:recipient = {
			OR = {
				AND = {
					is_lowborn = no
					dynasty = scope:secondary_recipient.dynasty
				}
				is_close_or_extended_family_of = scope:secondary_recipient
			}
		}
		scope:actor = {
			NOR = {
				is_close_or_extended_family_of = scope:secondary_actor
				this = scope:secondary_actor
			}
		}
		NOR = {
			scope:secondary_actor = {
				tier_difference = {
					target = scope:recipient
					value >= 0
				}
			}
			AND = {
				exists = scope:secondary_actor.father
				scope:secondary_actor.father = {
					tier_difference = {
						target = scope:recipient
						value >= 0
					}
				}
			}
			AND = {
				exists = scope:secondary_actor.mother
				scope:secondary_actor.mother = {
					tier_difference = {
						target = scope:recipient
						value >= 0
					}
				}
			}
		}
		add = {
			value = 0
			if = {
				limit = {
					scope:secondary_actor = {
						exists = father.primary_title
						trigger_if = {
							limit = {
								exists = mother.primary_title
							}
							father.primary_title.tier >= mother.primary_title.tier
						}
					}
				}
				add = scope:secondary_actor.father.highest_held_title_tier
				subtract = scope:recipient.highest_held_title_tier
				if = {
					limit = { scope:secondary_actor.father.highest_held_title_tier = tier_kingdom }
					multiply = 30
				}
				else = {
					multiply = 40
				}
			}
			else_if = {
				limit = {
					scope:secondary_actor = {
						exists = mother.primary_title
						trigger_if = {
							limit = {
								exists = father.primary_title
							}
							mother.primary_title.tier >= father.primary_title.tier
						}
					}
				}
				add = scope:secondary_actor.mother.highest_held_title_tier
				subtract = scope:recipient.highest_held_title_tier
				if = {
					limit = { scope:secondary_actor.mother.highest_held_title_tier = tier_kingdom }
					multiply = 30
				}
				else = {
					multiply = 40
				}
			}
			else = {
				add = scope:secondary_actor.highest_held_title_tier
				subtract = scope:recipient.highest_held_title_tier
				if = {
					limit = { scope:secondary_actor.highest_held_title_tier = tier_kingdom }
					multiply = 30
				}
				else = {
					multiply = 40
				}
			}

		}
		desc = MARRYING_DOWN_REASON
	}

	############
	# OPINIONS #
	############
	opinion_modifier = { # More likely to accept if Recipient likes the person the Actor offers for marriage
		trigger = {
			NOT = { scope:recipient = scope:secondary_actor }
		}
		who = scope:recipient
		opinion_target = scope:secondary_actor
		multiplier = 0.25
		desc = AI_OPINION_REASON
	}
	opinion_modifier = { # A lot more likely if Recipient likes Actor
		trigger = {
			NOT = { scope:actor = scope:recipient }
		}
		who = scope:recipient
		opinion_target = scope:actor
		multiplier = 0.75
		desc = AI_OPINION_REASON
	}
	modifier = { # Likely to want two candidates who like each other to marry if Recipient likes them both
		add = 15
		scope:secondary_recipient = { #Do they like each other a lot?
			opinion = {
				target = scope:secondary_actor
				value > 50
			}
			reverse_opinion = {
				target = scope:secondary_actor
				value > 50
			}
		}
		scope:recipient = { #The Recipient needs to want well for both candidates
			NOT = { has_trait = sadistic }
			NOT = { has_trait = callous }
			NOT = { has_trait = cynical }
			opinion = {
				target = scope:secondary_actor
				value > 0
			}
			opinion = {
				target = scope:secondary_recipient
				value > 0
			}
		}
		desc = wishes_well_for_lovers_tooltip
	}
	compare_modifier = { #If the Secondary_recipient has the Love opinion for the Secondary_actor, add the Recipients compassion value
		target = scope:recipient
		trigger = {
			scope:recipient = {
				ai_compassion > 0
				opinion = {
					target = scope:secondary_recipient
					value > 0
				}
			}
			scope:secondary_recipient = {
				has_opinion_modifier = {
					target = scope:secondary_actor
					modifier = love_opinion
				}
			}
		}
		value = ai_compassion
		multiplier = 0.25
	}
	modifier = { # Recipient wants to marry their lovers
		add = 25
		scope:secondary_recipient = scope:recipient
		scope:secondary_recipient = {
			has_relation_lover = scope:secondary_actor
			NOT = { has_relation_soulmate = scope:secondary_actor }
			# If it's a secret relation we know of it
			trigger_if = {
				limit = {
					any_secret = {
						secret_type = secret_lover
						secret_target = scope:secondary_actor
					}
				}
				any_secret = {
					secret_type = secret_lover
					secret_target = scope:secondary_actor
					any_secret_knower = {
						this = scope:actor
					}
				}
			}
		}
		desc = ARE_LOVERS_REASON
	}

	modifier = { # Recipient wants to marry their soulmates
		add = 100
		scope:secondary_recipient = scope:recipient
		scope:secondary_recipient = {
			has_relation_soulmate = scope:secondary_actor
			# If it's a secret relation we know of it
			trigger_if = {
				limit = {
					any_secret = {
						secret_type = secret_lover
						secret_target = scope:secondary_actor
					}
				}
				any_secret = {
					secret_type = secret_lover
					secret_target = scope:secondary_actor
					any_secret_knower = {
						this = scope:actor
					}
				}
			}
		}
		desc = ARE_SOULMATES_REASON
	}

	modifier = { # Same language
		add = 5
		desc = speaks_same_language_interaction_reason
		trigger = {
			scope:actor = {
				knows_language_of_culture = scope:recipient.culture
			}
		}
	}

	modifier = { # Shared Court Language (non-spoken)
		add = 5
		desc = foreign_realm_court_language_non_spoken_interaction_reason
		trigger = {
			scope:actor = {
				has_royal_court = yes
				NOT = { knows_court_language_of = this }
			}
			NOT = {
				scope:actor.top_liege = scope:recipient.top_liege
			}
			OR = {
				AND = {
					scope:recipient = {
						has_royal_court = yes
					}
					scope:actor = { # You share Court Language
						has_same_court_language = scope:recipient
					}
				}

				scope:recipient = { # The recipient doesn't have a royal court, but their liege does
					is_independent_ruler = no
					is_pool_character = no
					has_royal_court = no
					exists = liege
					liege = {
						has_royal_court = yes
						has_same_court_language = scope:actor
					}
				}
				scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege does, while their liege doesn't have a royal court
					is_independent_ruler = no
					is_pool_character = no
					has_royal_court = no
					exists = liege.liege
					liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege = {
						has_royal_court = yes
						has_same_court_language = scope:actor
					}
				}
				scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege does, while their liege doesn't have a royal court
					is_independent_ruler = no
					is_pool_character = no
					has_royal_court = no
					exists = liege.liege
					exists = liege.liege.liege
					liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege.liege = {
						has_royal_court = yes
						has_same_court_language = scope:actor
					}
				}
				scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege's liege does, while their liege doesn't have a royal court
					is_independent_ruler = no
					is_pool_character = no
					has_royal_court = no
					exists = liege.liege
					exists = liege.liege.liege
					exists = liege.liege.liege.liege
					liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege.liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege.liege.liege = {
						has_royal_court = yes
						has_same_court_language = scope:actor
					}
				}
			}
		}
	}

	modifier = { # Shared Court Language (spoken)
		add = 15
		desc = foreign_realm_court_language_spoken_interaction_reason
		trigger = {
			scope:actor = {
				has_royal_court = yes
				knows_court_language_of = this
			}
			NOT = {
				scope:actor.top_liege = scope:recipient.top_liege
			}
			OR = {
				AND = {
					scope:recipient = {
						has_royal_court = yes
					}
					scope:actor = { # You share Court Language
						has_same_court_language = scope:recipient
					}
				}

				scope:recipient = { # The recipient doesn't have a royal court, but their liege does
					is_independent_ruler = no
					is_pool_character = no
					has_royal_court = no
					exists = liege
					liege = {
						has_royal_court = yes
						has_same_court_language = scope:actor
					}
				}
				scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege does, while their liege doesn't have a royal court
					is_independent_ruler = no
					is_pool_character = no
					has_royal_court = no
					exists = liege.liege
					liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege = {
						has_royal_court = yes
						has_same_court_language = scope:actor
					}
				}
				scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege does, while their liege doesn't have a royal court
					is_independent_ruler = no
					is_pool_character = no
					has_royal_court = no
					exists = liege.liege
					exists = liege.liege.liege
					liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege.liege = {
						has_royal_court = yes
						has_same_court_language = scope:actor
					}
				}
				scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege's liege does, while their liege doesn't have a royal court
					is_independent_ruler = no
					is_pool_character = no
					has_royal_court = no
					exists = liege.liege
					exists = liege.liege.liege
					exists = liege.liege.liege.liege
					liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege.liege = {
						is_independent_ruler = no
						has_royal_court = no
					}
					liege.liege.liege.liege = {
						has_royal_court = yes
						has_same_court_language = scope:actor
					}
				}
			}
		}
	}

	###########################
	# DYNASTY PRESTIGE LEVELS #
	###########################
	modifier = {
		scope:secondary_actor = { has_dynasty = no }
		add = {
			value = -20 # AI really doesn't like marrying lowborn courtiers.
			if = {
				limit = { # Especially not if they're not lowborn themselves
					scope:secondary_recipient = { has_dynasty = yes }
				}
				multiply = 6
			}
		}
		desc = AI_DYNASTY_PRESTIGE_REASON_LOWBORN
	}
	modifier = {
		scope:secondary_actor = { has_dynasty = yes }
		scope:recipient.dynasty = scope:secondary_recipient.dynasty
		NOT = { scope:secondary_actor.dynasty = { dynasty_prestige_level = 1 } } #Would equal a value of 0, so we hide it
		add = {
			value = scope:secondary_actor.dynasty.dynasty_prestige_level
			multiply = 5
			subtract = 5 #At 0 dynasty prestige level, there should be a penalty
		}
		desc = AI_DYNASTY_PRESTIGE_REASON_SECONDARY
	}

	#####################################
	# PENALTIES FOR INCORRECT LINEALITY # (matrilineal for men, patrilineal for women. Ignored entirely for same-sex marriage)
	#####################################
	modifier = {
		scope:secondary_recipient = {
			exists = dynasty
			exists = scope:recipient.dynasty
			dynasty = scope:recipient.dynasty
			NAND = {
				dynasty = scope:actor.dynasty
				dynasty = scope:secondary_actor.dynasty
				scope:secondary_actor = { NOT = { has_trait = bastard } }
			}

			scope:recipient = { is_ruler = yes }
			scope:secondary_actor = { sex_opposite_of = scope:secondary_recipient }
			#Incorrect lineality
			OR = {
				AND = {
					NOT = { always = scope:matrilineal }
					is_female = yes
				}
				AND = {
					always = scope:matrilineal
					is_male = yes
				}
			}
		}
		#Only cares about the ruler, first 3 heirs, and the dominant gender dynasty members
		scope:recipient = {
			OR = {
				this = scope:secondary_recipient
				AND = {
					exists = player_heir
					player_heir_position = { #0, 1, 2 = the first three player heirs in succession line.
						value <= 2
						target = scope:secondary_recipient
					}
				}
				has_realm_law = equal_law
				AND = {
					scope:secondary_recipient = { is_female = yes }
					OR = {
						has_realm_law = female_only_law
						has_realm_law = female_preference_law
					}
				}
				AND = {
					scope:secondary_recipient = { is_male = yes }
					OR = {
						has_realm_law = male_only_law
						has_realm_law = male_preference_law
					}
				}
			}
		}

		add = {
			#For the ruler themselves and their first player heir
			if = {
				limit = {
					scope:recipient = {
						OR = {
							this = scope:secondary_recipient
							AND = {
								exists = player_heir
								player_heir_position = {
									value = 0 #First player heir
									target = scope:secondary_recipient
								}
							}
						}
					}
					OR = {
						AND = {
							scope:recipient.faith = {
								has_doctrine = doctrine_gender_male_dominated
							}
							scope:secondary_recipient = {
								is_male = yes
							}
						}
						AND = {
							scope:recipient.faith = {
								has_doctrine = doctrine_gender_female_dominated
							}
							scope:secondary_recipient = {
								is_female = yes
							}
						}
					}
				}
				subtract = 1000
			}
			else_if = {
				limit = {
					scope:recipient = {
						OR = {
							this = scope:secondary_recipient
							AND = {
								exists = player_heir
								player_heir_position = {
									value = 0 #First player heir
									target = scope:secondary_recipient
								}
							}
						}
					}
				}
				subtract = 100
			}
			#For the second heir
			else_if = {
				limit = {
					scope:recipient = {
						exists = player_heir
						player_heir_position = {
							value = 1 #Second player heir
							target = scope:secondary_recipient
						}
					}
				}
				subtract = 60 #A bit more than a strong hook
			}
			#For the third heir
			else_if = {
				limit = {
					scope:recipient = {
						exists = player_heir
						player_heir_position = {
							value = 2 #Third player heir
							target = scope:secondary_recipient
						}
					}
				}
				subtract = 30 #A bit more than a weak hook
			}
			else_if = {
				limit = {
					scope:recipient = { has_realm_law = equal_law }
				}
				subtract = 10 #If The realm law is equal, and the secondary_recipient is NOT ruler or their 1st/2nd/3rd heir, slash the penalty in half
			}
			else = {
				subtract = 20 #Base penalty for dynasty members who are NOT ruler or their 1st/2nd/3rd heir
			}
		}
		desc = MATRILINEAL_PATRILINEAL_REASON
	}

	#########
	# FAITH #
	#########
	modifier = { # A recipient will be reluctant (to differing degrees) to agree to marriages sent from an actor of a different faith
		add = {
			value = -10
			if = {
				limit = {
					NOR = {
						# Exempt certain struggle phases.
						is_struggle_parameter_active_interfaith_marriages_available_between_involved_characters_trigger = yes
						# Exempt Conciliation struggle resolution
						AND = {
							has_global_variable = fp2_struggle_conciliation_ending
							fp2_struggle_conciliation_special_cultural_rules_trigger = { C1 = scope:recipient C2 = scope:actor }
						}
					}
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value > faith_astray_level
							}
						}
					}
					subtract = 15
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_hostility_prevents_marriage_level
							}
						}
					}
					subtract = 975
				}
			}
		}

		scope:recipient.faith = {
			faith_hostility_level = {
				target = scope:actor.faith
				value > faith_fully_accepted_level
			}
		}
		desc = MARRY_DIFFERENT_FAITH_REASON
	}

	modifier = { # Polygamy not supported
		add = -1000
		desc = DIVORCE_POLYGAMY

		scope:secondary_actor = {
			is_married = yes
		}
		AND = {
			scope:secondary_recipient.culture = { NOT = { has_cultural_tradition = tradition_polygamous } }
			scope:secondary_recipient.faith = { NOT = { is_polygamous = yes } }
		}
	}

	modifier = { # Same-sex marriage not supported in recipient's faith
		add = -1000
		desc = SAME_SEX_MARRIAGE_FAITH_REASON

		scope:secondary_recipient = {
			sex_same_as = scope:secondary_actor
			allowed_to_marry_same_sex_trigger = no
		}
	}

	modifier = { # A debuff for no fertility to same-sex marriage
		add = -200
		desc = SAME_SEX_MARRIAGE_FERTILITY_REASON

		scope:secondary_recipient = {
			allowed_to_marry_same_sex_trigger = yes
			sex_same_as = scope:secondary_actor
			OR = {
				is_ruler = yes
				AND = {
					exists = scope:recipient.primary_heir
					scope:recipient.primary_heir = { this = scope:secondary_recipient }
				}
			}
			NOT = {
				any_child = {
					count >= 2
				}
			}
		}
	}

	###############
	# PROCREATION #
	###############
	compare_modifier = { # Recipient is reluctant to marry old women (procreation is a key factor)
		trigger = {
			scope:secondary_actor = {
				age > 29
				is_female = yes
			}
			scope:secondary_recipient = {
				is_adult = yes
				OR = {
					AND = {
						exists = scope:secondary_recipient.dynasty
						scope:secondary_recipient.dynasty = {
							OR = {
								any_dynasty_member = {
									count >= 2
								}
								dynasty_prestige_level > 1
							}
						}
					}
					is_ruler = yes
					is_close_or_extended_family_of = scope:recipient
					this = scope:recipient.player_heir
				}
			}
		}
		target = scope:secondary_actor
		value = age
		multiplier = -5.0
		step = 1
		offset = -29
		desc = MARRY_AGE
	}

	compare_modifier = { # Recipient is VERY reluctant to betrothe old women to boys
		trigger = {
			scope:secondary_actor = {
				age > 20
				is_female = yes
			}
			scope:secondary_recipient = {
				is_adult = no
			}
		}
		target = scope:secondary_actor
		value = age
		multiplier = -5.0
		step = 1
		offset = -20
		desc = MARRY_AGE
	}

	modifier = { # A Recipient is unlikely to agree to a marriage where the Secondary_recipient is fertile and the Secondary_actor isn't even if Secondary_recipient has children
		add = -100

		scope:secondary_recipient = {
			OR = {
				fertility > 0.1
				is_adult = no
			}
			OR = {
				AND = {
					exists = scope:secondary_recipient.dynasty
					scope:secondary_recipient.dynasty = {
						OR = {
							any_dynasty_member = {
								count >= 2
							}
							dynasty_prestige_level > 1
						}
					}
				}
				is_ruler = yes
				is_close_or_extended_family_of = scope:recipient
				this = scope:recipient.player_heir
			}
			OR = {
				is_female = no
				age < 45
			}
			any_child = {
				count >= 1
			}
		}
		scope:secondary_actor = {
			is_adult = yes
			OR = {
				fertility < 0.1
				AND = {
					is_female = yes
					age >= marriage_female_fertility_cutoff_age_value
				}
			}
		}
		desc = MARRY_LOW_FERTILITY_REASON
	}

	modifier = { # A Recipient is VERY unlikely to agree to a marriage where the Secondary_recipient is fertile and the Secondary_actor isn't if Secondary_recipient doesn't have children
		add = -200

		scope:secondary_recipient = {
			OR = {
				fertility > 0.1
				is_adult = no
			}
			OR = {
				AND = {
					exists = scope:secondary_recipient.dynasty
					scope:secondary_recipient.dynasty = {
						OR = {
							any_dynasty_member = {
								count >= 2
							}
							dynasty_prestige_level > 1
						}
					}
				}
				is_ruler = yes
				is_close_or_extended_family_of = scope:recipient
				this = scope:recipient.player_heir
			}
			OR = {
				is_female = no
				age < 45
			}
			any_child = {
				count < 1
			}
		}
		scope:secondary_actor = {
			is_adult = yes
			OR = {
				fertility < 0.1
				AND = {
					is_female = yes
					age >= marriage_female_fertility_cutoff_age_value
				}
			}
		}
		desc = MARRY_LOW_FERTILITY_REASON
	}

	modifier = { # A Recipient is VERY unlikely to agree to a marriage where the Secondary_recipient is a fertile woman and the Secondary_actor is an underage boy who won't become an adult before the woman is infertile
		add = -200

		scope:secondary_recipient = {
			is_female = yes
			is_adult = yes
			age < 45
			OR = {
				AND = {
					exists = scope:secondary_recipient.dynasty
					scope:secondary_recipient.dynasty = {
						OR = {
							any_dynasty_member = {
								count >= 2
							}
							dynasty_prestige_level > 1
						}
					}
				}
				is_ruler = yes
				is_close_or_extended_family_of = scope:recipient
				this = scope:recipient.player_heir
			}
		}
		scope:secondary_actor = {
			is_adult = no
		}
		marriage_fertile_age_reverse_value >= 43

		desc = MARRY_LOW_FERTILITY_REASON
	}

	modifier = { # A Recipient is VERY unlikely to agree to a marriage where the Secondary_actor is a woman and the Secondary_recipient is an underage boy who won't become an adult before the woman is infertile
		add = -200

		scope:secondary_actor = {
			is_female = yes
			is_adult = yes
		}
		scope:secondary_recipient = {
			is_adult = no
			OR = {
				AND = {
					exists = scope:secondary_recipient.dynasty
					scope:secondary_recipient.dynasty = {
						OR = {
							any_dynasty_member = {
								count >= 2
							}
							dynasty_prestige_level > 1
						}
					}
				}
				is_ruler = yes
				is_close_or_extended_family_of = scope:recipient
				this = scope:recipient.player_heir
			}
		}
		marriage_fertile_age_value >= 43

		desc = MARRY_LOW_FERTILITY_REASON
	}

	modifier = { # Unimportant courtier? Fair game, have them.
		add = 10

		scope:secondary_recipient = {
			is_adult = yes
			NOR = {
				dynasty = scope:recipient.dynasty
				is_close_or_extended_family_of = scope:recipient

				is_councillor_of = scope:recipient
				has_relation_lover = scope:recipient
				has_relation_soulmate = scope:recipient
				has_relation_friend = scope:recipient
				has_relation_best_friend = scope:recipient
				is_knight_of = scope:recipient
				exists = inspiration
			}
		}
		desc = MARRY_UNIMPORTANT_COURTIER_REASON
	}

	modifier = {
		add = -10
		scope:secondary_recipient = {
			is_adult = yes
			OR = {
				is_councillor_of = scope:recipient
				has_relation_lover = scope:recipient
				has_relation_soulmate = scope:recipient
				has_relation_friend = scope:recipient
				has_relation_best_friend = scope:recipient
				is_knight_of = scope:recipient
				AND = {
					exists = inspiration
					inspiration = {
						exists = inspiration_sponsor
						inspiration_sponsor = scope:recipient
					}
				}
			}
		}
		desc = MARRY_CARES_ABOUT_COURTIER_REASON
	}

	modifier = {
		add = -25
		scope:secondary_recipient = {
			any_child = {
				is_child_of = scope:recipient
			}
			NOT = { this = scope:recipient }
		}
		desc = MARRY_PARENT_OF_CHILDREN_REASON
	}

	#########
	# LIEGE #
	#########
	modifier = { # A Recipient is more likely to agree to a marriage arranged by their liege.
		add = 40

		scope:recipient = {
			target_is_liege_or_above = scope:actor
			NOT = { target_is_liege_or_above = scope:secondary_actor }
			OR = {
				opinion = {
					target = scope:secondary_actor
					value > -40
				}
				NOT = { is_close_or_extended_family_of = scope:secondary_recipient }
			}
		}
		desc = LIEGE_REASON
	}

	modifier = { # A Recipient is more likely to agree to a marriage with their liege.
		add = 60

		scope:recipient = {
			target_is_liege_or_above = scope:secondary_actor
		}
		desc = LIEGE_REASON
	}

	#############
	# CLAIMANTS #
	#############
	modifier = { # Don't agree to marry off Claimants to inconsequential courtiers
		add = -50
		scope:secondary_recipient = {
			is_claimant = yes
			NOT = {
				any_claim = {
					holder = scope:recipient
				}
			}
			NOR = {
				this = scope:recipient
				is_close_or_extended_family_of = scope:recipient
			}
		}
		scope:secondary_actor = {
			is_landed = no
			NOT = { is_close_or_extended_family_of = scope:secondary_recipient }
		}
		desc = VALUABLE_CLAIMANT
	}

	modifier = { # Reluctance in marrying off Claimants to my own titles, if I am not related to the secondary_recipient. I'd rather keep the claimants under lock and key!
		add = -50
		scope:secondary_recipient = {
			any_claim = {
				holder = scope:recipient
			}
			NOT = { is_close_or_extended_family_of = scope:recipient }
		}
		desc = CLAIMANT_TO_MY_TITLES
	}

	#########
	# DREAD #
	#########
	#More likely to accept a preposition that doesn't include them if they fear you
	modifier = {
		add = intimidated_marriage_reason_value
		scope:recipient = {
			NOT = { this = scope:secondary_recipient }
			target_is_liege_or_above = scope:actor
			has_dread_level_towards = {
				target = scope:actor
				level = 1
			}
		}
		desc = INTIMIDATED_REASON
	}
	modifier = {
		add = cowed_marriage_reason_value
		scope:recipient = {
			NOT = { this = scope:secondary_recipient }
			target_is_liege_or_above = scope:actor
			has_dread_level_towards = {
				target = scope:actor
				level = 2
			}
		}
		desc = COWED_REASON
	}

	modifier = {
		add = intimidated_marriage_external_reason_value
		scope:recipient = {
			NOT = { this = scope:secondary_recipient }
			NOT = { target_is_liege_or_above = scope:actor }
			has_dread_level_towards = {
				target = scope:actor
				level = 1
			}
		}
		desc = INTIMIDATED_REASON
	}
	modifier = {
		add = cowed_marriage_external_reason_value
		scope:recipient = {
			NOT = { this = scope:secondary_recipient }
			NOT = { target_is_liege_or_above = scope:actor }
			has_dread_level_towards = {
				target = scope:actor
				level = 2
			}
		}
		desc = COWED_REASON
	}
	#Less likely to accept a marriage with someone they are scared off
	modifier = {
		add = -50
		scope:actor = scope:secondary_actor
		scope:recipient = {
			this = scope:secondary_recipient
			target_is_liege_or_above = scope:actor
			has_dread_level_towards = {
				target = scope:actor
				level = 1
			}
		}
		desc = INTIMIDATED_REASON
	}
	modifier = {
		add = -75
		scope:actor = scope:secondary_actor
		scope:recipient = {
			this = scope:secondary_recipient
			target_is_liege_or_above = scope:actor
			has_dread_level_towards = {
				target = scope:actor
				level = 2
			}
		}
		desc = COWED_REASON
	}

	modifier = {
		add = -75
		scope:actor = scope:secondary_actor
		scope:recipient = {
			this = scope:secondary_recipient
			NOT = { target_is_liege_or_above = scope:actor }
			has_dread_level_towards = {
				target = scope:actor
				level = 1
			}
		}
		desc = INTIMIDATED_REASON
	}
	modifier = {
		add = -150
		scope:actor = scope:secondary_actor
		scope:recipient = {
			this = scope:secondary_recipient
			NOT = { target_is_liege_or_above = scope:actor }
			has_dread_level_towards = {
				target = scope:actor
				level = 2
			}
		}
		desc = COWED_REASON
	}
	#More likely to accept a marriage proposal from someone they're scared of if they're not the secondary_actor
	modifier = {
		add = intimidated_marriage_not_secondary_reason_value
		NOT = { scope:actor = scope:secondary_actor }
		scope:recipient = {
			this = scope:secondary_recipient
			has_dread_level_towards = {
				target = scope:actor
				level = 1
			}
		}
		desc = INTIMIDATED_REASON
	}
	modifier = {
		add = cowed_marriage_not_secondary_reason_value
		NOT = { scope:actor = scope:secondary_actor }
		scope:recipient = {
			this = scope:secondary_recipient
			has_dread_level_towards = {
				target = scope:actor
				level = 2
			}
		}
		desc = COWED_REASON
	}

	opinion_modifier = { # Additional reluctance if recipient likes the close relative
		trigger = {
			NOT = { scope:recipient = scope:secondary_recipient }
			scope:recipient = {
				OR = {
					is_close_or_extended_family_of = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
				}
				opinion = {
					target = scope:secondary_recipient
					value > 10
				}
			}
		}

		who = scope:recipient
		opinion_target = scope:secondary_recipient
		multiplier = -0.15
		desc = DEAR_TO_ME_REASON
	}

	### FAMILY CONSIDERATIONS
	modifier = {
		add = -1000
		scope:recipient.faith = {
			NOT = {
				faith_allows_marriage_consanguinity_trigger = { CHARACTER_1 = scope:secondary_recipient CHARACTER_2 = scope:secondary_actor }
			}
		}
		desc = MARRY_CONSANGUINITY_REASON
	}

	modifier = {
		trigger = {
			scope:secondary_recipient = {
				age > 20
				OR = {
					dynasty = scope:recipient.dynasty
					is_close_or_extended_family_of = scope:recipient
				}
			}
		}
		add = {
			value = scope:secondary_recipient.age
			subtract = 20
		}
		desc = MARRIAGE_DESPERATION
	}

	modifier = { #The actor's spouse has boosted the AI's willingness to marry the heir
		add = 75
		scope:actor = {
			exists = player_heir
			player_heir = scope:secondary_actor
		}
		scope:secondary_actor = {
			has_character_modifier = heir_easier_to_marry_off_modifier
		}
		desc = MARRIAGE_SPOUSE_COUNCILLOR_BOOST_HEIR
	}
	modifier = {
		add = 50
		scope:secondary_actor = {
			is_child_of = scope:actor
			has_character_modifier = child_easier_to_marry_off_modifier
		}
		desc = MARRIAGE_SPOUSE_COUNCILLOR_BOOST_CHILD
	}

	################
	# INSPIRATIONS #
	################

	modifier = { # Inspired people will be _very_ hesitant
		exists = scope:secondary_recipient.inspiration
		has_completed_inspiration = no
		add = -100
		desc = IS_FOCUSING_ON_INSPIRATION_MODIFIER
	}

	##################
	# COURT GRANDEUR #
	##################

	modifier = { # Court grandeur level above expected level gives a boost
		add = ep1_court_grandeur_marriage_acceptance_value
		desc = COURT_GRANDEUR_LEVEL_MARRIAGE_ACCEPTANCE_BOOST_MODIFIER
		scope:actor = {
			has_royal_court = yes
			court_grandeur_current_level > court_grandeur_minimum_expected_level
		}
	}

	modifier = { # Court grandeur level below expected level gives a penalty
		add = ep1_court_grandeur_marriage_acceptance_value_penalty
		desc = COURT_GRANDEUR_LEVEL_MARRIAGE_ACCEPTANCE_PENALTY_MODIFIER
		scope:actor = {
			has_royal_court = yes
			court_grandeur_current_level < court_grandeur_minimum_expected_level
		}
	}

	################
	#  TRADITIONS  #
	################
	modifier = { # Wedding Ceremonies
		scope:actor.culture = { has_cultural_parameter = marriage_acceptance_bonus }
		add = 10
		desc = TRADITION_BONUS_WEDDING_CEREMONIES
	}
	modifier = {
		add = -50
		scope:recipient = {
			culture = {
				has_cultural_parameter = dislikes_marrying_outside_of_culture
			}
		}
		NOT = {
			scope:recipient.culture = scope:actor.culture
		}
		desc = TRADITION_PENALTY_ISOLATIONIST
	}
}

elopment_ai_accept_modifier = { #Should copy marriage_ai_accept_modifier on relevant points, note: there are no secondary targets
	############
	# ELOPMENT #
	############

	modifier = {
		NOT = { has_relation_soulmate = scope:actor }
		add = {
			value = -25
			if = {
				limit = {
					is_married = yes
				}
				add = -25
			}
		}
		desc = AI_ELOPE_CONSEQUENCES
	}

	#########
	# PERKS #
	#########
	modifier = { # A lot of acceptance for yourself - you are likely already married, thus you need motivation to get rid of your spouse to marry someone better
		scope:actor = { has_perk = promising_prospects_perk }
		add = promising_prospects_self_value
		desc = PROMISING_PROSPECTS_PERK_MODIFIER
	}
	modifier = { # Dynasty Glory Perk acceptance,
		exists = scope:actor.dynasty
		scope:actor.dynasty = { has_dynasty_perk = glory_legacy_1 }
		add = glory_legacy_1_marriage_acceptance
		desc = DYNASTY_LEGACY_GLORY_MARRIAGE_ACCEPTANCE_PERK_MODIFIER
	}

	############
	# OPINIONS #
	############
	opinion_modifier = { # More likely to accept if Recipient likes the person the Actor offers for marriage
		who = scope:recipient
		opinion_target = scope:actor
		multiplier = 1
		desc = AI_OPINION_REASON
	}

	opinion_modifier = {
		trigger = { exists = scope:recipient.primary_spouse }
		who = scope:recipient
		opinion_target = scope:recipient.primary_spouse
		multiplier = -1
		desc = AI_SPOUSE_OPINION
	}

	####################
	# TIER DIFFERENCES #
	####################
	modifier = {
		exists = scope:recipient.liege.dynasty
		scope:recipient = {
			OR = {
				AND = {
					is_lowborn = no
					exists = dynasty
					dynasty = scope:recipient.liege.dynasty
				}
				is_close_or_extended_family_of = scope:recipient.liege
				is_spouse_of = scope:recipient.liege
			}
		}
		scope:actor.primary_title.tier > scope:recipient.liege.primary_title.tier
		add = {
			value = scope:actor.highest_held_title_tier
			subtract = scope:recipient.liege.highest_held_title_tier
			multiply = 30
		}
		desc = MARRYING_UP_REASON
	}

	modifier = {
		exists = scope:recipient.liege.dynasty
		scope:recipient = {
			OR = {
				AND = {
					is_lowborn = no
					exists = dynasty
					dynasty = scope:recipient.liege.dynasty
				}
				is_close_or_extended_family_of = scope:recipient.liege
				is_spouse_of = scope:recipient.liege
			}
		}
		scope:actor.primary_title.tier < scope:recipient.liege.primary_title.tier
		add = {
			value = scope:actor.highest_held_title_tier
			subtract = scope:recipient.liege.highest_held_title_tier
			if = {
				limit = { scope:actor.highest_held_title_tier = tier_kingdom }
				multiply = 25
			}
			else = {
				multiply = 35
			}
		}
		desc = MARRYING_DOWN_REASON
	}

	###########################
	# DYNASTY PRESTIGE LEVELS #
	###########################
	modifier = {
		scope:actor = {
			OR = {
				has_dynasty = no
				scope:actor = {
					has_dynasty = yes
					dynasty.dynasty_prestige_level = 0
				}
			}
		}
		add = -5
		desc = AI_DYNASTY_PRESTIGE_REASON
	}
	modifier = {
		scope:actor = {
			has_dynasty = yes
			dynasty.dynasty_prestige_level >= 2
		}
		add = {
			value = scope:actor.dynasty.dynasty_prestige_level
			multiply = 5
			subtract = 5 #At 0 dynasty prestige level, there should be a penalty
		}
		desc = AI_DYNASTY_PRESTIGE_REASON
	}

	#########
	# FAITH #
	#########
	modifier = { # A recipient will be reluctant (to differing degrees) to agree to marriages sent from an actor of a different faith
		scope:recipient.faith = {
			faith_hostility_level = {
				target = scope:actor.faith
				value > faith_fully_accepted_level
			}
		}
		add = {
			value = -10
			if = {
				limit = {
					scope:recipient.faith = {
						faith_hostility_level = {
							target = scope:actor.faith
							value > faith_astray_level
						}
					}
				}
				subtract = 15
			}
			if = {
				limit = {
					scope:recipient.faith = {
						faith_hostility_level = {
							target = scope:actor.faith
							value >= faith_hostility_prevents_marriage_level
						}
					}
				}
				subtract = 975
			}
		}

		desc = MARRY_DIFFERENT_FAITH_REASON
	}

	##################
	# MISC PENALTIES #
	##################
	modifier = {
		scope:recipient.liege = { has_weak_hook = scope:recipient }
		desc = AI_ELOPE_WEAK_HOOK
		add = -15
	}

	modifier = {
		scope:recipient.liege = { has_strong_hook = scope:recipient }
		desc = AI_ELOPE_STRONG_HOOK
		add = -100
	}

	modifier = {
		scope:recipient = {
			any_heir_title = {
				place_in_line_of_succession = {
					target = scope:recipient
					value <= 1
				}
			}
		}
		desc = AI_ELOPE_INHERITANCE
		add = -75
	}

	modifier = {
		scope:recipient = {
			NOT = {
				any_heir_title = {
					place_in_line_of_succession = {
						target = scope:recipient
						value <= 1
					}
				}
			}
			any_heir_title = {
				place_in_line_of_succession = {
					target = scope:recipient
					value <= 3
				}
			}
		}
		desc = AI_ELOPE_POSSIBLE_INHERITANCE
		add = -30
	}

	#########################
	# FAMILY CONSIDERATIONS #
	#########################

	modifier = {
		add = -1000
		scope:recipient.faith = {
			NOT = {
				faith_allows_marriage_consanguinity_trigger = { CHARACTER_1 = scope:recipient CHARACTER_2 = scope:actor }
			}
		}
		desc = MARRY_CONSANGUINITY_REASON
	}
}

divorce_character_ai_accept_modifier = {
	modifier = {
		add = -50
		desc = BASE_RELUCTANCE
	}

	modifier = { # Less likely if it's the recipient him/herself
		add = -100
		desc = MY_OWN_MARRIAGE_REASON
		scope:recipient = scope:secondary_recipient
	}

	opinion_modifier = { # A lot more likely if Recipient likes Actor
		trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
		who = scope:recipient
		opinion_target = scope:actor
		multiplier = 1
		desc = AI_OPINION_REASON
	}

	opinion_modifier = { # Unlikely if Recipient likes Secondary Recipient
		trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
		who = scope:recipient
		opinion_target = scope:secondary_recipient
		multiplier = -1
		desc = AI_OPINION_REASON
	}

	modifier = { # Very unlikely if the marriage is between kin and the religion has Divine Marriages
		add = -100
		desc = DIVORCE_HOLY
		scope:actor = {
			faith = {
				has_doctrine = tenet_divine_marriage
			}
		}
		scope:actor = {
			OR = {
				is_cousin_of = scope:secondary_recipient
				is_close_or_extended_family_of = scope:secondary_recipient
			}
		}
	}

	modifier = { # More likely if the spouse is openly incestuous
		add = 150
		desc = DIVORCE_OPENLY_INCESTUOUS_SPOUSE

		scope:secondary_recipient = {
			any_relation = {
				type = lover
				NOR = {
					this = scope:actor
					this = scope:recipient
				}
				relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = scope:secondary_recipient	}
			}
		}
	}

	modifier = { # More likely if the spouse has been unfaithful (lover relation or std)
		trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
		desc = DIVORCE_INFIDELITY
		add = {
			# Cheating isn't awful
			if = {
				limit = {
					trigger_if = {
						limit = {
							scope:secondary_recipient = { is_male = yes }
						}
						faith = { has_doctrine = doctrine_adultery_men_accepted }
					}
					trigger_else_if = {
						limit = {
							scope:secondary_recipient = { is_female = yes }
						}
						faith = { has_doctrine = doctrine_adultery_women_accepted }
					}
					# making the default behavior explicit if no other trigger_(else_)ifs are valid
					trigger_else = {
						always = yes
					}
				}
				value = 20
			}
			# Cheating is awful
			else = {
				value = 50
			}
		}
		scope:secondary_recipient = {
			exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
		}
	}

	modifier = { # Eunuchs
		trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
		add = 100
		desc = DIVORCE_IMPOTENT_EUNUCH
		scope:secondary_recipient = {
			is_female = no
			has_trait = eunuch
		}
	}

	modifier = { # Very likely if the marriage has turned Polygamous and their faith doesn't support it
		trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
		add = 100
		desc = DIVORCE_POLYGAMY
		scope:actor = {
			any_consort = {
				is_alive = yes
				NOT = { this = scope:secondary_recipient }
			}
			any_consort = {
				this = scope:secondary_recipient
			}
		}
		AND = {
			scope:secondary_recipient.culture = { NOT = { has_cultural_tradition = tradition_polygamous } }
			scope:secondary_recipient.faith = { NOT = { has_doctrine = doctrine_polygamy } }
		}
	}

	modifier = { # Heathens
		trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
		add = 100
		desc = DIVORCE_HEATHEN
		NOT = {
			scope:secondary_recipient.faith.religion = scope:actor.faith.religion
		}
	}

	modifier = { # Heretic
		trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
		add = 10
		desc = DIVORCE_HERETIC
		scope:secondary_recipient.faith.religion = scope:actor.faith.religion
		scope:secondary_recipient = {
			NOT = {
				faith = scope:actor.faith
			}
		}
	}

	modifier = { # I am a Kinslayer
		add = -50
		desc = I_AM_A_KINSLAYER
		scope:actor = {
			has_trait_rank = {
				trait = kinslayer
				rank >= 1
			}
		}
	}

	modifier = { # They are a Kinslayer
		trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
		add = 50
		desc = THEY_ARE_A_KINSLAYER
		scope:secondary_recipient = {
			has_trait_rank = {
				trait = kinslayer
				rank >= 1
			}
		}
	}

	modifier = { # Friend of the Head of Faith
		add = 50
		desc = WE_ARE_FRIENDS
		scope:recipient = {
			has_relation_friend = scope:actor
		}
	}

	modifier = { # Best Friend of the Head of Faith
		add = 150
		desc = WE_ARE_BEST_FRIENDS
		scope:recipient = {
			has_relation_best_friend = scope:actor
		}
	}

	modifier = { # Lover of the Head of Faith
		add = 25
		desc = WE_ARE_LOVERS
		scope:recipient = {
			has_relation_lover = scope:actor
		}
	}

	modifier = { # Rival of the Head of Faith
		add = -100
		desc = WE_ARE_RIVALS
		scope:recipient = {
			has_relation_rival = scope:actor
		}
	}

	modifier = { # Nemesis of the Head of Faith
		add = -500
		desc = WE_ARE_NEMESES
		scope:recipient = {
			has_relation_nemesis = scope:actor
		}
	}
}

license: mit


code:
elector_voting_pattern_traits_compeditae_elective_modifier = {
	##########################	Elector voting patterns (traits)	##########################
	#Personality Traits compatibility
	#Sins vs Virtues
	#Crime traits
	#Attraction (including sexual traits)
	#Special cases (ex. deformities, disfigured for Byzantines)

	#Trait compatibility between elector and candidate
	compatibility_modifier = {
		who = root
		compatibility_target = scope:candidate
		min = -50
		max = 50
		trigger = {
			NOT = { root = scope:candidate }
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_sinful
		NOT = { this = scope:candidate } #Do not judge yourself.
		NOT = { has_trait = cynical }
		ai_zeal > 0
		scope:candidate = { num_sinful_traits >= 1 }
		add = {
			subtract = 5
			if = { #Check specific number...
				limit = {
					scope:candidate = { num_sinful_traits >= 2 }
				}
				subtract = 5
			}
			if = { #Check specific number...
				limit = {
					scope:candidate = { num_sinful_traits >= 3 }
				}
				subtract = 5
			}
			if = { #Check specific number...
				limit = {
					scope:candidate = { num_sinful_traits >= 4 }
				}
				subtract = 5
			}
			if = { #Check specific number...
				limit = {
					scope:candidate = { num_sinful_traits >= 5 }
				}
				subtract = 5
			}
			if = { #Princely elective more unforgiving.
				limit = {
					scope:title = { has_title_law = princely_elective_succession_law }
				}
				multiply = 2
			}
			multiply = ai_zeal #...Multiply by Elector Zeal.
			multiply = 0.1 #Reduce overall to avoid extreme numbers.
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_virtuous
		NOR = {
			this = scope:candidate	#Do not judge yourself.
			has_trait = cynical
		}
		ai_zeal > 0
		scope:candidate = { num_virtuous_traits >= 1 }
		add = {
			add = 5
			if = { #Check specific number...
				limit = {
					scope:candidate = { num_virtuous_traits >= 2 }
				}
				add = 5
			}
			if = { #Check specific number...
				limit = {
					scope:candidate = { num_virtuous_traits >= 3 }
				}
				add = 5
			}
			if = { #Check specific number...
				limit = {
					scope:candidate = { num_virtuous_traits >= 4 }
				}
				add = 5
			}
			if = { #Check specific number...
				limit = {
					scope:candidate = { num_virtuous_traits >= 5 }
				}
				add = 5
			}
			if = { #Princely elective more unforgiving.
				limit = {
					scope:title = { has_title_law = princely_elective_succession_law }
				}
				multiply = 2
			}
			multiply = ai_zeal #...Multiply by Elector Zeal.
			multiply = 0.1 #Reduce overall to avoid extreme numbers.
		}
	}
	#Excommunication
	modifier = {
		desc = tooltip_feudal_elector_vote_excommunication
		NOT = { this = scope:candidate } #Do not judge yourself.
		faith = { has_doctrine_parameter = excommunication_active }
		faith = scope:candidate.faith
		root.faith.religious_head = scope:candidate.faith.religious_head #Must have been excommunicated by the same Pope.
		OR = {
			NOT = { has_trait = excommunicated }
			has_trait = arbitrary #No need for consistency
		}
		scope:candidate = { has_trait = excommunicated }
		add = {
			subtract = 25
			if = { #Religious gradients.
				limit = { ai_zeal > 0 }
				subtract = {
					value = ai_zeal
					multiply = 0.5
				}
			}
			if = { #Princely Elective doubles.
				limit = {
					scope:title = { has_title_law = princely_elective_succession_law }
				}
				multiply = 2
			}
		}
	}
	#Kinslayer Crime
	modifier = {
		desc = tooltip_feudal_elector_vote_kinslayer
		NOR = {
			this = scope:candidate	#Do not judge yourself.
			faith = { has_doctrine = doctrine_kinslaying_accepted }
		}
		OR = {
			NOT = { has_trait = kinslayer }
			has_trait = arbitrary #No need for consistency
		}
		scope:candidate = { has_trait = kinslayer }
		add = {
			value = 0
			if = { #Check specific trait, multiply depending on religious doctrine.
				limit = {
					scope:candidate = { has_trait = kinslayer_1 }
				}
				subtract = 10
				if = {
					limit = {
						faith = { has_doctrine = doctrine_kinslaying_any_dynasty_member_crime }
					}
					multiply = 2
				}
			}
			else_if = {
				limit = {
					scope:candidate = { has_trait = kinslayer_2 }
				}
				subtract = 15
				if = {
					limit = {
						faith = {
							OR = {
								has_doctrine = doctrine_kinslaying_any_dynasty_member_crime
								has_doctrine = doctrine_kinslaying_extended_family_crime
							}
						}
					}
					multiply = 2
				}
			}
			else_if = {
				limit = {
					scope:candidate = { has_trait = kinslayer_3 }
				}
				subtract = 20
				if = {
					limit = {
						faith = {
							OR = {
								has_doctrine = doctrine_kinslaying_any_dynasty_member_crime
								has_doctrine = doctrine_kinslaying_extended_family_crime
								has_doctrine = doctrine_kinslaying_close_kin_crime
							}
						}
					}
					multiply = 2
				}
			}
			#And further add malus depending on Elector's relation to the Kinslaying candidate.
			if = {
				limit = {
					exists = scope:candidate.dynasty
					NOT = { dynasty = scope:candidate.dynasty }
				}
				subtract = 10
			}
			else_if = {
				limit = {
					exists = scope:candidate.dynasty
					dynasty = scope:candidate.dynasty
					NOT = { is_close_family_of = scope:candidate }
				}
				subtract = 20
			}
			else_if = {
				limit = {
					exists = scope:candidate.dynasty
					dynasty = scope:candidate.dynasty
					is_close_family_of = scope:candidate
				}
				subtract = 30
			}
			if = { #Boost for Scandinavian Elective.
				limit = {
					scope:title = { has_title_law = scandinavian_elective_succession_law }
				}
				multiply = 1.5
			}
		}
	}

	#Deviancy
	modifier = {
		desc = tooltip_feudal_elector_vote_deviant
		NOT = {
			this = scope:candidate	#Do not judge yourself.
			faith = { has_doctrine = doctrine_deviancy_accepted }
		}
		OR = {
			NOT = { has_trait = deviant }
			has_trait = arbitrary #No need for consistency
		}
		scope:candidate = { has_trait = deviant }
		add = 15
	}
	#Cannibalism
	modifier = {
		desc = tooltip_feudal_elector_vote_cannibal
		NOR = {
			this = scope:candidate	#Do not judge yourself.
			faith = { has_doctrine_parameter = cannibalism_legal }
		}
		OR = {
			NOT = { has_trait = cannibal }
			has_trait = arbitrary #No need for consistency
		}
		scope:candidate = { has_trait = cannibal }
		add = {
			subtract = 30
			if = { #Religious gradients.
				limit = { ai_zeal > 10 }
				subtract = {
					value = ai_zeal
					multiply = 0.5
				}
			}
		}
	}
	#Attraction
	modifier = {
		desc = tooltip_feudal_elector_vote_attractive
		NOT = { this = scope:candidate } #Do not judge yourself, you dirty AI.
		is_adult = yes
		scope:candidate = {
			is_adult = yes
			attraction >= 25
		}
		add = {
			value = 1
			multiply = scope:candidate.attraction
			multiply = 0.2
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_ugly
		NOT = { this = scope:candidate } #Do not judge yourself.
		is_adult = yes
		scope:candidate = {
			is_adult = yes
			attraction <= -25
		}
		add = {
			value = 0
			multiply = scope:candidate.attraction
			multiply = 0.2
		}
	}
	#Fertility
	modifier = {
		desc = tooltip_compeditae_elector_vote_fertility
		NOT = { this = scope:candidate }
		is_adult = yes
		scope:candidate = {
			is_adult = yes
		}
		add = {
			value = 0
			if = {
				limit = {
					scope:candidate = { fertility >= 0.5 }
				}
				add = 5
			}
			if = {
				limit = {
					scope:candidate = { fertility >= 0.7 }
				}
				add = 5
			}
			if = {
				limit = {
					scope:candidate = { fertility >= 0.9 }
				}
				add = 5
			}
		}
	}
	#Multitasker
	modifier = {
		desc = tooltip_compeditae_elector_vote_multitasker
		NOT = { this = scope:candidate }
		is_adult = yes
		scope:candidate = {
			has_trait = regula_multitasker_bloodline
		}
		add = {
			value = 25
		}
	}
	#Health
	modifier = {
		desc = tooltip_compeditae_elector_vote_health
		NOT = { this = scope:candidate }
		is_adult = yes
		scope:candidate = {
			is_adult = yes
		}
		add = {
			value = 0
			if = {
				limit = {
					scope:candidate = { health <= 2 }
				}
				add = -50
			}
			if = {
				limit = {
					scope:candidate = { health >= 3 }
				}
				add = 5
			}
			if = {
				limit = {
					scope:candidate = { health >= 5 }
				}
				add = 10
			}
			if = {
				limit = {
					scope:candidate = { health >= 7 }
				}
				add = 10
			}
		}
	}
	#Bloodline
	modifier = {
		desc = tooltip_compeditae_elector_vote_pure_blooded
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = {
			has_trait = pure_blooded
		}
		add = {
			value = 100
		}
	}
	#Obligatory sex characteristics
	#Big dick
	modifier = {
		desc = tooltip_compeditae_elector_vote_dick_big
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = {
			OR = {
				has_trait = dick_big
			}
		}
		add = {
			add = 10
			if = {
				limit = {
					scope:candidate = { has_trait = dick_big_1 }
				}
				add = 5
			}
			if = {
				limit = {
					scope:candidate = {
						OR = {
							has_trait = dick_big_2
						}
					}
				}
				add = 10
			}
			if = {
				limit = {
					scope:candidate = { has_trait = dick_big_3 }
				}
				add = 15
			}
		}
	}
	#Small dick
	modifier = {
		desc = tooltip_compeditae_elector_vote_dick_small
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = {
			OR = {
				has_trait = dick_small
			}
		}
		add = {
			subtract = 10
			if = {
				limit = {
					scope:candidate = { has_trait = dick_small_1 }
				}
				subtract = 5
			}
			if = {
				limit = {
					scope:candidate = {
						OR = {
							has_trait = dick_small_2
						}
					}
				}
				subtract = 10
			}
			if = {
				limit = {
					scope:candidate = { has_trait = dick_small_3 }
				}
				subtract = 15
			}
		}
	}

	#Special cases (ex. deformities, disfigured for Byzantines)
	modifier = {
		add = -35
		desc = tooltip_feudal_elector_vote_incapable
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = { has_trait = incapable }
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_incapable_warrior
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = { has_trait = incapable }
		add = {
			subtract = 50
			if = { #Scandinavian elective more unforgiving.
				limit = {
					scope:title = { has_title_law = scandinavian_elective_succession_law }
				}
				multiply = 2
			}
		}
	}
	modifier = {
		add = -15
		desc = tooltip_feudal_elector_vote_infirm
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_diplomatic_society_trigger = no
		scope:candidate = { has_trait = infirm }
	}
	modifier = {
		add = -30
		desc = tooltip_feudal_elector_vote_infirm_diplomat
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_diplomatic_society_trigger = yes
		scope:candidate = { has_trait = infirm }
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_disfigured
		this_is_martial_society_trigger = no
		scope:candidate = { has_trait = disfigured }
		add = -15
	}
	modifier = {
		add = -10
		desc = tooltip_feudal_elector_vote_maimed
		this_is_martial_society_trigger = no
		scope:candidate = { has_trait = maimed }
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_maimed_warrior
		this_is_martial_society_trigger = yes
		scope:candidate = { has_trait = maimed }
		add = {
			subtract = 15
			if = { #Scandinavian elective more unforgiving.
				limit = {
					scope:title = { has_title_law = scandinavian_elective_succession_law }
				}
				multiply = 2
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_genius_diplomat
		NOT = { this = scope:candidate } #Do not judge yourself.
		OR = {
			this_is_diplomatic_society_trigger = yes
			this_is_spiritual_society_trigger = yes
		}
		scope:candidate = {
			OR = {
				has_trait = intellect_good
				has_trait = shrewd
			}
		}
		add = {
			value = 10
			if = {
				limit = {
					scope:candidate = { has_trait = intellect_good_1 }
				}
				add = 5
			}
			if = {
				limit = {
					scope:candidate = {
						OR = {
							has_trait = intellect_good_2
							has_trait = shrewd
						}
					}
				}
				add = 10
			}
			if = {
				limit = {
					scope:candidate = { has_trait = intellect_good_3 }
				}
				add = 15
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_genius
		NOT = { this = scope:candidate } #Do not judge yourself.
		NOR = {
			this_is_diplomatic_society_trigger = yes
			this_is_spiritual_society_trigger = yes
		}
		scope:candidate = {
			OR = {
				has_trait = intellect_good
				has_trait = shrewd
			}
		}
		add = {
			value = 0
			if = {
				limit = {
					scope:candidate = { has_trait = intellect_good_1 }
				}
				add = 5
			}
			if = {
				limit = {
					scope:candidate = {
						OR = {
							has_trait = intellect_good_2
							has_trait = shrewd
						}
					}
				}
				add = 10
			}
			if = {
				limit = {
					scope:candidate = { has_trait = intellect_good_3 }
				}
				add = 15
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_strong
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = {
			OR = {
				has_trait = physique_good
				has_trait = strong
			}
		}
		add = {
			value = 0
			if = {
				limit = {
					scope:candidate = { has_trait = physique_good_1 }
				}
				add = 5
			}
			if = {
				limit = {
					scope:candidate = {
						OR = {
							has_trait = strong
							has_trait = physique_good_2
						}
					}
				}
				add = 10
			}
			if = {
				limit = {
					scope:candidate = { has_trait = physique_good_3 }
				}
				add = 15
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_strong_warrior
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = {
			OR = {
				has_trait = physique_good
				has_trait = strong
			}
		}
		add = {
			value = 10
			if = {
				limit = {
					scope:candidate = { has_trait = physique_good_1 }
				}
				add = 5
			}
			if = {
				limit = {
					scope:candidate = {
						OR = {
							has_trait = strong
							has_trait = physique_good_2
						}
					}
				}
				add = 10
			}
			if = {
				limit = {
					scope:candidate = { has_trait = physique_good_3 }
				}
				add = 15
			}
			if = { #Scandinavian elective more unforgiving.
				limit = {
					scope:title = { has_title_law = scandinavian_elective_succession_law }
				}
				multiply = 2
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_imbecile
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_diplomatic_society_trigger = no
		scope:candidate = {
			OR = {
				has_trait = intellect_bad
				has_trait = dull
			}
		}
		add = {
			value = 0
			if = {
				limit = {
					scope:candidate = { has_trait = intellect_bad_1 }
				}
				subtract = 5
			}
			if = {
				limit = {
					scope:candidate = {
						OR = {
							has_trait = intellect_bad_2
							has_trait = dull
						}
					}
				}
				subtract = 10
			}
			if = {
				limit = {
					scope:candidate = { has_trait = intellect_bad_3 }
				}
				subtract = 15
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_imbecile_diplomat
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_diplomatic_society_trigger = yes
		scope:candidate = {
			OR = {
				has_trait = intellect_bad
				has_trait = dull
			}
		}
		add = {
			subtract = 10
			if = {
				limit = {
					scope:candidate = { has_trait = intellect_bad_1 }
				}
				subtract = 5
			}
			if = {
				limit = {
					scope:candidate = {
						OR = {
							has_trait = intellect_bad_2
							has_trait = dull
						}
					}
				}
				subtract = 10
			}
			if = {
				limit = {
					scope:candidate = { has_trait = intellect_bad_3 }
				}
				subtract = 15
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_clubfooted
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = { has_trait = clubfooted }
		add = {
			subtract = 5
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_dwarf
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = { has_trait = dwarf }
		add = {
			subtract = 15
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_dwarf_warrior
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = { has_trait = dwarf }
		add = {
			subtract = 30
			if = { #Scandinavian elective more unforgiving.
				limit = {
					scope:title = { has_title_law = scandinavian_elective_succession_law }
				}
				multiply = 2
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_hunchback
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = {has_trait = hunchbacked }
		add = {
			subtract = 15
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_hunchback_warrior
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = { has_trait = hunchbacked }
		add = {
			subtract = 30
			if = { #Scandinavian elective more unforgiving.
				limit = {
					scope:title = { has_title_law = scandinavian_elective_succession_law }
				}
				multiply = 2
			}
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_inbred
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = {
			OR = {
				has_trait = inbred
				has_trait = spindly
				has_trait = scaly
				has_trait = albino
				has_trait = wheezing
				has_trait = bleeder
			}
		}
		add = {
			subtract = 100
		}
	}
	modifier = {
		desc = tooltip_feudal_elector_vote_lisping
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = { has_trait = lisping }
		add = {
			subtract = 5
		}
	}
	modifier = {
		add = -5
		desc = tooltip_feudal_elector_vote_stuttering
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = { has_trait = stuttering }
	}
	modifier = { #Shunned for being a lunatic
		add = -5
		desc = tooltip_feudal_elector_vote_lunatic_negative
		NOT = { this = scope:candidate } #Do not judge yourself.
		OR = {
			has_trait = arbitrary #No need for consistency
			NOR = {
				has_trait = lunatic
				has_trait = possessed
			}
		}
		scope:candidate = { has_trait = lunatic }
	}
	modifier = { #Shunned for being possessed
		add = -15
		desc = tooltip_feudal_elector_vote_possessed_negative
		NOR = {
			this = scope:candidate	#Do not judge yourself.
			faith = { has_doctrine_parameter = spirit_possession_active }
		}
		OR = {
			has_trait = arbitrary #No need for consistency
			NOR = {
				has_trait = lunatic
				has_trait = possessed
			}
		}
		scope:candidate = { has_trait = possessed }
	}
	modifier = { #Praised for being possessed
		add = 35
		desc = tooltip_feudal_elector_vote_possessed_positive
		NOT = { this = scope:candidate } #Do not judge yourself.
		faith = { has_doctrine_parameter = spirit_possession_active }
		ai_zeal > 10
		scope:candidate = { has_trait = possessed }
	}
	modifier = { #Praised for being Pilgrim
		add = 10
		desc = tooltip_feudal_elector_vote_pilgrim_positive
		NOT = { this = scope:candidate } #Do not judge yourself.
		faith = scope:candidate.faith
		ai_zeal > 10
		scope:candidate = { has_trait = pilgrim }
	}
	modifier = { #Praised for being Crusader
		add = 10
		desc = tooltip_feudal_elector_vote_crusader_positive
		NOT = { this = scope:candidate } #Do not judge yourself.
		faith = scope:candidate.faith
		ai_zeal > 10
		scope:candidate = { has_trait = faith_warrior }
	}
	modifier = { #Shunned for being Crusader
		add = -15
		desc = tooltip_feudal_elector_vote_crusader_negative
		NOR = {
			this = scope:candidate	#Do not judge yourself.
			faith = scope:candidate.faith
		}
		faith = {
			faith_hostility_level = {
				target = scope:candidate.faith
				value >= faith_hostile_level
			}
		}
		ai_zeal > 10
		scope:candidate = { has_trait = faith_warrior }
	}
	modifier = { #Praised for being a saoshyant_descendant
		add = 10
		desc = tooltip_feudal_elector_vote_saoshyant_descendant_positive
		NOT = { this = scope:candidate } #Do not judge yourself.
		faith = { religion_tag = zoroastrianism_religion }
		scope:candidate = { has_trait = saoshyant_descendant }
	}
	modifier = { #Praised for being Adventurer
		add = 10
		desc = tooltip_feudal_elector_vote_adventurer_positive
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = { has_trait = adventurer }
	}
	modifier = { #Shunned for being Adventurer
		add = -10
		desc = tooltip_feudal_elector_vote_adventurer_negative
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = { has_trait = adventurer }
	}
	modifier = { #Praised for being Berserker
		add = 5
		desc = tooltip_feudal_elector_vote_berserker_positive
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = { has_trait = berserker }
	}
	modifier = { #Shunned for being Berserker
		add = -20
		desc = tooltip_feudal_elector_vote_berserker_negative
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = { has_trait = berserker }
	}
	modifier = { #Shunned for being blind
		desc = tooltip_feudal_elector_vote_blinded_negative
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = { has_trait = blind }
		add = {
			subtract = 10
		}
	}
	modifier = { #Shunned for being blind
		desc = tooltip_feudal_elector_vote_blinded_negative_warrior
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = { has_trait = blind }
		add = {
			subtract = 20
			if = { #Scandinavian elective more unforgiving.
				limit = {
					scope:title = { has_title_law = scandinavian_elective_succession_law }
				}
				multiply = 2
			}
		}
	}
	modifier = { #Shunned for being eunuch
		desc = tooltip_feudal_elector_vote_eunuch_negative
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = {has_trait = eunuch }
		add = -40
	}
	modifier = { #Shunned for being eunuch
		desc = tooltip_feudal_elector_vote_eunuch_negative_warrior
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = {has_trait = eunuch }
		add = -60
	}
	modifier = { #Shunned for being eunuch
		desc = tooltip_feudal_elector_vote_eunuch_negative_byzantine
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = { has_trait = eunuch }
		add = -150
	}
	modifier = { #Praised for being Giant
		add = 10
		desc = tooltip_feudal_elector_vote_giant_positive
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = yes
		scope:candidate = { has_trait = giant }
	}
	modifier = { #Shunned for being Giant
		add = -10
		desc = tooltip_feudal_elector_vote_giant_negative
		NOT = { this = scope:candidate } #Do not judge yourself.
		this_is_martial_society_trigger = no
		scope:candidate = { has_trait = giant }
	}
	modifier = { #Shunned for being unproved courtier in the shadow of the ruler.
		add = -10
		desc = tooltip_feudal_elector_vote_spoiled_courtier
		scope:candidate = { this = scope:holder_candidate }
		NOT = { this = scope:candidate } #Do not judge yourself.
		scope:candidate = {
			NOR = {
				is_ruler = yes
				has_council_position = councillor_marshal
				has_council_position = councillor_chancellor
				has_council_position = councillor_steward
				has_council_position = councillor_spymaster
				has_council_position = councillor_court_chaplain
			}
			OR = {
				has_trait = deviant
				has_trait = lazy
				has_trait = lifestyle_reveler
				has_trait = seducer
				has_trait = drunkard
				has_trait = shy
			}
		}
	}
}

elector_voting_pattern_opinion_compeditae_elective_modifier = {
	##########################	Elector voting patterns (opinion)	##########################
	#Ruler is lunatic, vote against his pick
	modifier = {
		add = -10
		desc = tooltip_feudal_elector_anti_vote_ruler_lunatic
		scope:candidate = { this = scope:holder_candidate }
		NOR = {
			this = scope:candidate	#But not if it's me.
			has_trait = lunatic #Don't care
			has_trait = possessed #Don't care
			has_trait = arbitrary #Don't care
			has_trait = zealous #Might be the gods speaking
			faith = { has_doctrine_parameter = spirit_possession_active } #Actually blessed
		}
		scope:holder = {
			has_trait = lunatic
		}
	}
	#Ruler is possessed, vote against his pick
	modifier = {
		add = -10
		desc = tooltip_feudal_elector_anti_vote_ruler_possessed
		scope:candidate = { this = scope:holder_candidate }
		ai_zeal > 0
		NOR = {
			this = scope:candidate	#But not if it's me.
			has_trait = lunatic #Don't care
			has_trait = possessed #Don't care
			has_trait = arbitrary #Don't care
			faith = { has_doctrine_parameter = spirit_possession_active } #Actually blessed
		}
		scope:holder = {
			has_trait = possessed
		}
	}
	#Unless adorcism is a thing
	modifier = {
		add = 25
		desc = tooltip_feudal_elector_anti_vote_ruler_possessed_positive
		scope:candidate = { this = scope:holder_candidate }
		faith = { has_doctrine_parameter = spirit_possession_active } #Actually blessed
		ai_zeal > 0
		scope:holder = {
			has_trait = possessed
		}
	}
	#Ruler is just, trust his pick
	modifier = {
		desc = tooltip_feudal_elector_pro_vote_ruler_just
		scope:candidate = { this = scope:holder_candidate }
		NOR = {
			this = scope:holder  #But not if it's me.
			this = scope:candidate  #But not if it's me.
		}
		NOR = {
			has_trait = lunatic #Don't care
			has_trait = possessed #Don't care
			has_trait = arbitrary #Don't like it
			has_trait = sadistic #Don't care
			faith = { trait_is_sin = just } #Not a positive.
		}
		scope:holder = { has_trait = just }
		add = {
			value = 25
			if = {
				limit = {
					faith = { has_doctrine_parameter = legalism_trust_just_leader_active }
				}
				add = 15
			}
		}
	}
	#Ruler is a Tyrant, vote against his pick
	modifier = {
		desc = tooltip_feudal_elector_anti_vote_ruler_tyrant
		scope:candidate = { this = scope:holder_candidate }
		NOR = {
			this = scope:holder  #But not if it's me.
			this = scope:candidate  #But not if it's me.
		}
		NOR = {
			has_trait = lunatic #Don't care
			has_trait = possessed #Don't care
			has_trait = arbitrary #Don't care
			has_trait = sadistic #Don't care
			has_trait = callous #Don't care
		}
		scope:holder = {
			tyranny >= low_tyranny
		}
		add = {
			subtract = 25
			if = {
				limit = {
					tyranny >= medium_tyranny
				}
				subtract = 25
			}
			if = {
				limit = {
					tyranny >= high_tyranny
				}
				subtract = 50
			}
		}
	}
	#Ruler is Dreaded, vote for his pick
	modifier = {
		desc = tooltip_feudal_elector_anti_vote_ruler_dreaded
		scope:candidate = { this = scope:holder_candidate }
		NOR = {
			this = scope:holder  #But not if it's me.
			this = scope:candidate  #But not if it's me.
		}
		NOR = {
			has_trait = lunatic #Don't care
			has_trait = arbitrary #Don't care
		}
		scope:holder = { dread >= low_dread	}
		dread_modified_ai_boldness = {
			dreaded_character = scope:holder
			value <= -25
		}
		add = {
			value = 0
			if = {
				limit = {
					dread_modified_ai_boldness = {
						dreaded_character = scope:holder
						value <= -50
					}
				}
				add = 5
			}
			if = {
				limit = {
					dread_modified_ai_boldness = {
						dreaded_character = scope:holder
						value <= -75
					}
				}
				add = 10
			}
			if = {
				limit = {
					dread_modified_ai_boldness = {
						dreaded_character = scope:holder
						value <= -95
					}
				}
				add = 15
			}
		}
	}
	##########################	Raw Opinion bonus towards Candidate	##########################
	modifier = { #Raw Opinion bonus (negative)
		desc = tooltip_feudal_elector_vote_opinion_negative
		NOT = { this = scope:candidate } #Not on yourself.
		save_temporary_opinion_value_as = {
			name = opinion_of_candidate
			target = scope:candidate
		}
		scope:opinion_of_candidate <= low_negative_opinion
		add = {
			subtract = 15
			if = { #Even less so if lower opinion.
				limit = {
					scope:opinion_of_candidate <= medium_negative_opinion
				}
				subtract = 15 #-30 total
			}
			if = { #Even less so if lower opinion.
				limit = {
					scope:opinion_of_candidate <= high_negative_opinion
				}
				subtract = 20 #-50 total
			}
			if = { #Even less so if lower opinion.
				limit = {
					scope:opinion_of_candidate <= very_high_negative_opinion
				}
				subtract = 50 #-100 total
			}
			if = { #Even less so if rival.
				limit = {
					has_relation_rival = scope:candidate
				}
				subtract = 50 #-150 total
			}
			if = { #Further increased for Tanistry.
				limit = {
					scope:title = { has_title_law = gaelic_elective_succession_law }
				}
				multiply = 1.5
			}
		}
	}
	modifier = { #Raw Opinion bonus (positive)
		desc = tooltip_feudal_elector_vote_opinion_positive
		NOT = {
			has_relation_rival = scope:candidate #Completely removed for rivals.
		}
		NOT = { this = scope:candidate } #Not on yourself.
		save_temporary_opinion_value_as = {
			name = opinion_of_candidate
			target = scope:candidate
		}
		scope:opinion_of_candidate >= low_positive_opinion
		add = {
			value = 15
			if = { #Even more so if higher opinion.
				limit = {
					scope:opinion_of_candidate >= medium_positive_opinion
				}
				add = 15 #30 total
			}
			if = { #Even more so if higher opinion.
				limit = {
					scope:opinion_of_candidate >= high_positive_opinion
				}
				add = 20 #50 total
			}
			if = { #Even more so if higher opinion.
				limit = {
					scope:opinion_of_candidate >= very_high_positive_opinion
				}
				add = 20 #70 total
			}
			if = { #Even more so if friend/lover.
				limit = {
					OR = {
						has_relation_friend = scope:candidate
						has_relation_lover = scope:candidate
					}
				}
				add = 30 #100 total
			}
			if = { #Further increased for Tanistry.
				limit = {
					scope:title = { has_title_law = gaelic_elective_succession_law }
				}
				multiply = 1.5
			}
		}
	}
	##########################	Raw Opinion bonus towards Ruler	##########################
	modifier = { #Vassal hates ruler, therefore votes against the ruler's candidate (scope:holder_candidate)
		desc = tooltip_feudal_elector_anti_vote_ruler_opinion_negative
		scope:candidate = scope:holder_candidate
		NOR = {
			this = scope:holder  #But not if it's me.
			this = scope:candidate  #But not if it's me.
		}
		save_temporary_opinion_value_as = {
			name = opinion_of_holder
			target = scope:holder
		}
		scope:opinion_of_holder <= low_negative_opinion
		add = {
			subtract = 10
			if = { #Even less so if lower opinion.
				limit = {
					scope:opinion_of_holder <= medium_negative_opinion
				}
				subtract = 15 #-25 total
			}
			if = { #Even less so if lower opinion.
				limit = {
					scope:opinion_of_holder <= high_negative_opinion
				}
				subtract = 25 #-50 total
			}
			if = { #Even less so if lower opinion.
				limit = {
					scope:opinion_of_holder <= very_high_negative_opinion
				}
				subtract = 50 #-100 total
			}
			if = { #Even less so if rival.
				limit = {
					has_relation_rival = scope:holder
				}
				subtract = 50 #-150 total
			}
		}
	}
	# modifier = { #Vassal loves ruler, therefore votes for the ruler's candidate (scope:holder_candidate)
	# 	desc = tooltip_feudal_elector_pro_vote_ruler_opinion_positive
	# 	scope:candidate = scope:holder_candidate
	# 	NOR = {
	# 		this = scope:holder  #But not if it's me.
	# 		this = scope:candidate  #But not if it's me.
	# 	}
	# 	save_temporary_opinion_value_as = {
	# 		name = opinion_of_holder
	# 		target = scope:holder
	# 	}
	# 	scope:opinion_of_holder >= low_positive_opinion
	# 	add = {
	# 		value = 0
	# 		# if = { #Even more so if higher opinion.
	# 		# 	limit = {
	# 		# 		opinion = {
	# 		# 			target = scope:holder
	# 		# 			value >= medium_positive_opinion
	# 		# 		}
	# 		# 	}
	# 		# 	add = 5 #5 total
	# 		# }
	# 		# if = { #Even more so if higher opinion.
	# 		# 	limit = {
	# 		# 		opinion = {
	# 		# 			target = scope:holder
	# 		# 			value >= high_positive_opinion
	# 		# 		}
	# 		# 	}
	# 		# 	add = 10 #15 total
	# 		# }
	# 		# if = { #Even more so if higher opinion.
	# 		# 	limit = {
	# 		# 		opinion = {
	# 		# 			target = scope:holder
	# 		# 			value >= very_high_positive_opinion
	# 		# 		}
	# 		# 	}
	# 		# 	add = 25 #50 total
	# 		# }
	# 		if = { #Even more so if friend/lover.
	# 			limit = {
	# 				OR = {
	# 					has_relation_friend = scope:holder
	# 					has_relation_lover = scope:holder
	# 				}
	# 			}
	# 			add = 50 #100 total
	# 		}
	# 	}
	# }
	modifier = { #Vassal obeys the Magister.
		desc = tooltip_compeditae_elector_pro_vote_magister_level
		scope:candidate = scope:holder_candidate
		NOR = {
			this = scope:holder  #But not if it's me.
			this = scope:candidate  #But not if it's me.
		}
		add = {
			value = 0
			if = {
				limit = {
					global_var:magister_character = {
						has_trait = magister_1
					}
				}
				add = -25 #Malus if the magister is disgraced.
			}
			if = {
				limit = {
					global_var:magister_character = {
						has_trait = magister_2
					}
				}
				add = 0
			}
			if = {
				limit = {
					global_var:magister_character = {
						has_trait = magister_3
					}
				}
				add = 10
			}
			if = {
				limit = {
					global_var:magister_character = {
						has_trait = magister_4
					}
				}
				add = 15
			}
			if = {
				limit = {
					global_var:magister_character = {
						has_trait = magister_5
					}
				}
				add = 25
			}
			if = {
				limit = {
					global_var:magister_character = {
						has_trait = magister_6
					}
				}
				add = 40
			}
		}
	}
}


code:
might_cheat_on_partner_trigger = {

	### Regula devoted don't cheat.
	trigger_if = {
		limit = { has_trait = devoted_trait_group }
		always = no
	}

	trigger_else_if = {
		limit = {
			# If $PARTNER$ isn't actually my partner, it's not cheating!
			OR = {
				has_relation_lover = $PARTNER$
				is_consort_of = $PARTNER$ # Includes both spouses and concubines
			}

			# Additionally, in faiths with the Polyamory doctrine, extramarital relationships aren't considered to be cheating on partners.
			NOT = { faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active } }
		}

		# Soulmates never cheat, unless they're Lustful/Seducer and have low Honor
		trigger_else_if = {
			limit = { has_relation_soulmate = $PARTNER$ }
			ai_honor <= medium_negative_ai_value
			has_trait = lustful
			has_trait = seducer
			has_focus = intrigue_temptation_focus
		}

		# Non-soulmates have slightly more complex criteria
		trigger_else = {
			OR = {
				# Having one of these things that makes characters always willing to cheat:
				OR = {
					has_trait = lustful
					has_trait = seducer
					has_focus = intrigue_temptation_focus

					AND = {
						# Dishonorable and callous enough to not care about current partners (regardless of opinion).
						ai_compassion <= high_negative_ai_value
						ai_honor <= high_negative_ai_value
					}
					AND = {
						# Needs aren't getting met
						is_deviant_trigger = yes
						$PARTNER$ = { is_deviant_trigger = no }
					}
				}

				# Otherwise, they need to not be honorable and not have a strong like of this partner
				AND = {
					ai_honor < high_positive_ai_value
					trigger_if = {
						limit = {
							is_consort_of = $PARTNER$
						}
						opinion = {
							target = $PARTNER$
							value <= high_positive_opinion # 60 for spouses/concubines
						}
					}
					trigger_else = {
						opinion = {
							target = $PARTNER$
							value <= very_high_positive_opinion # 80 for lovers
						}
					}
				}

				# Might also cheat if they just dislike their partner, regardless of honor
				AND = {
					opinion = {
						target = $PARTNER$
						value < neutral_opinion # -1 or lower for spouses, concubines, or lovers
					}
				}
			}
		}
	}
	trigger_else = { always = yes } # Having an extramarital relationship with someone else would not count as cheating on this person.
}

### This should shut down the random lover events.
can_set_relation_lover_trigger = {
	is_adult = yes
	NOT = { this = $CHARACTER$ }
	is_attracted_to_gender_of = $CHARACTER$
	$CHARACTER$ = {
		is_adult = yes
		is_attracted_to_gender_of = prev
	}
	NOT = {
		has_relation_lover = $CHARACTER$
		has_trait = devoted_trait_group
	}
	NOR = {
		AND = {
			NOT = {
				$CHARACTER$ = {
					OR = {
						has_trait = magister_trait_group
						has_trait = devoted_trait_group
					}
				}
			}
			has_trait = devoted_trait_group
		}
		AND = {
			$CHARACTER$ = {
				OR = {
					has_trait = devoted_trait_group
				}
			}
			NOR = {
				has_trait = magister_trait_group
				has_trait = devoted_trait_group
			}
		}
	}
}

can_set_relation_soulmate_trigger = {
	is_adult = yes
	NOT = { this = $CHARACTER$ }
	is_attracted_to_gender_of = $CHARACTER$
	$CHARACTER$ = {
		is_adult = yes
		is_attracted_to_gender_of = prev
	}
	NOR = {
		has_relation_rival = $CHARACTER$
		has_relation_nemesis = $CHARACTER$
		AND = {
			NOT = {
				$CHARACTER$ = {
					OR = {
						has_trait = magister_trait_group
						has_trait = devoted_trait_group
					}
				}
			}
			has_trait = devoted_trait_group
		}
		AND = {
			$CHARACTER$ = {
				OR = {
					has_trait = devoted_trait_group
				}
			}
			NOR = {
				has_trait = magister_trait_group
				has_trait = devoted_trait_group
			}
		}
	}
	num_of_relation_soulmate = 0
	$CHARACTER$ = { num_of_relation_soulmate = 0 }
}


code:
valid_demand_conversion_conditions_trigger = {
	scope:recipient = { is_available = yes }
	scope:recipient = { NOT = { has_strong_hook = scope:actor } }
	scope:recipient = { NOT = { has_trait = devoted } }
	scope:recipient = { NOT = { has_trait = order_member } }
	scope:recipient = {
		NOT = { is_imprisoned_by = scope:actor }
	}

	### Regula devoted can't be converted by anyone but the magister.
    trigger_if = {
        limit = {
            scope:recipient = { has_trait = devoted_trait_group }
        }
        scope:actor = { has_trait = magister_trait_group }
    }

	custom_description = {
		text = "is_head_of_religion"
		subject = scope:recipient
		NOT = { scope:recipient.faith.religious_head = scope:recipient }
	}

	custom_description = {
		text = "is_protected_via_contract"
		subject = scope:recipient
		NAND = { # Vassal Contract forbids meddling by liege
			exists = scope:recipient.liege
			scope:recipient.liege = scope:actor
			scope:recipient = {
				is_ruler = yes
				vassal_contract_has_flag = religiously_protected
			}
		}
	}
}


code:
valid_demand_conversion_conditions_trigger = {
	scope:recipient = { is_available = yes }
	scope:recipient = { NOT = { has_strong_hook = scope:actor } }
	scope:recipient = { NOT = { has_trait = devoted } }
	scope:recipient = { NOT = { has_trait = order_member } }
	scope:recipient = {
		NOT = { is_imprisoned_by = scope:actor }
	}

	### Regula devoted can't be converted by anyone but the magister.
    trigger_if = {
        limit = {
            scope:recipient = { has_trait = devoted_trait_group }
        }
        scope:actor = { has_trait = magister_trait_group }
    }

	custom_description = {
		text = "is_head_of_religion"
		subject = scope:recipient
		NOT = { scope:recipient.faith.religious_head = scope:recipient }
	}

	custom_description = {
		text = "is_protected_via_contract"
		subject = scope:recipient
		NAND = { # Vassal Contract forbids meddling by liege
			exists = scope:recipient.liege
			scope:recipient.liege = scope:actor
			scope:recipient = {
				is_ruler = yes
				has_government = feudal_government
				vassal_contract_has_flag = religiously_protected
			}
		}
	}
}


code:
# Cultural MAA triggers - Used in various places for triggers, AI weights, etc.
# Note, we replace the vanilla culture triggers here so that Regula rulers use Famuli troops over regular ones
# Hopefully this doesnt conflict to much with other mods
culture_has_skirmisher_maa = {
	OR = {
		has_cultural_parameter = unlock_maa_horn_warrior
		has_cultural_parameter = unlock_maa_shomer
		has_cultural_parameter = unlock_maa_abudrar
		has_cultural_parameter = unlock_maa_guinea_warrior
		has_cultural_parameter = unlock_maa_famuli
		has_innovation = innovation_adaptive_militia #Goedendag - Later Era MAA
	}
}

culture_has_archer_maa = {
	OR = {
		has_cultural_parameter = unlock_maa_archers_of_the_nile
		has_cultural_parameter = unlock_maa_bush_hunter
		has_cultural_parameter = unlock_maa_metsanvartija
		has_cultural_parameter = unlock_maa_longbowmen
		has_cultural_parameter = unlock_maa_famuli
		has_innovation = innovation_repeating_crossbow #Chu-ko-nu Archers
		has_innovation = innovation_bamboo_bows #Paiks
	}
}

culture_has_light_cavalry_maa = {
	OR = {
		has_cultural_parameter = unlock_maa_mulaththamun
		has_cultural_parameter = unlock_maa_hussar #Konni
		has_cultural_parameter = unlock_maa_famuli
		has_innovation = innovation_desert_tactics #Chasseur
		has_innovation = innovation_caballeros #Caballero
		has_innovation = innovation_hobbies #Hobelar
		has_innovation = innovation_sahel_horsemen #Sahel Horsemen
	}
}

culture_has_heavy_infantry_maa = {
	OR = {
		has_cultural_parameter = unlock_maa_ayyar
		has_cultural_parameter = unlock_maa_mubarizun
		has_cultural_parameter = unlock_maa_druzhina
		has_cultural_parameter = unlock_maa_khandayat
		has_cultural_parameter = unlock_maa_garudas
		has_cultural_parameter = unlock_maa_palace_guards
		has_cultural_parameter = unlock_maa_huscarls
		has_cultural_parameter = unlock_maa_mountaineer
		has_cultural_parameter = unlock_maa_zbrojnosh
		has_cultural_parameter = unlock_maa_famuli
		has_innovation = innovation_sarawit #Sarawit - Later Era MAA
		has_innovation = innovation_legionnaires #Praetorian
	}
}


code:
is_polygamous = {
	OR = {
		has_doctrine = doctrine_concubine_regula
		has_doctrine = doctrine_polygamy
	}
}


code:
# Verifies religious status.
is_regula_trigger = {
	OR = {
		faith = { religion_tag = regula_religion }
	}
}


code:
fascinare_allowed = {
	trigger_if = {
		limit = {
			is_ai = yes
			OR = {
				has_trait = mulsa
				has_trait = paelex
				has_trait = domina
			}
		}
		scope:faith = {
			controls_holy_site_with_flag = holy_site_reg_mulsa_fascinare_flag
		}
	}
	trigger_else = {
		has_trait = magister_trait_group
	}
}

use_fascinare_secrecy_trigger = {
	scope:target = {
		NOR = {
			is_consort_of = scope:owner
			is_courtier_of = scope:owner
		}
		exists = liege
		OR = {
			is_consort_of = scope:target.liege
			is_close_family_of = scope:target.liege
			house = scope:target.house
		}
	}
}


code:
regula_virus_imprisonable_trigger = {
	AND = {
		is_landed = no
    	scope:contagion_court_owner = {  # Add the spymaster to the list?
			NOT = { faith = global_var:magister_character.faith }
		}
    }
}


code:
regula_covert_conversion = {
    category = religious

    is_valid = {
		scope:secret_owner = {
			NOT = { faith = { religion_tag = regula_religion } }
		}
	}

	is_shunned = {
	}

	is_criminal = {
        scope:secret_owner = {
			is_male = yes
		}
	}

	on_expose = {
		save_scope_as = secret

		secret_owner = {
			save_scope_as = owner
		}
		if = {
			limit = { exists = secret_target }
			secret_target = { save_scope_as = target }
		}

		#Save spouses, close family members, liege and anyone whom I am primary heir of
		scope:owner = {
			save_list_targets_for_secret_exposure_events_effect = { SECRET = scope:secret CHARACTER = scope:owner }
		}

		#Send the notification event
		every_in_list = {
			list = send_exposed_secret_event_list

			trigger_event = secrets.0107

		}

		### Sending feed messages to other characters who care ###
		scope:owner = {
			#Save secret knowers and extended family members for feed messages
			save_list_targets_for_secret_exposure_feed_messages_effect = { SECRET = scope:secret CHARACTER = scope:owner }
		}

		every_in_list = {
			list = send_exposed_secret_feed_message_list
			save_scope_as = secret_expose_feed_message_scope

			send_interface_message = {
				type = secret_exposed_message
				left_icon = scope:owner
				title = secret_exposed_notification_effect_message
				desc = secret_exposed_notification_effect_message_witch

				if = {
					limit = { has_hook_from_secret = scope:secret }
					if = {
						limit = {
							has_hook_of_type = {
								target = scope:owner
								type = weak_blackmail_hook
							}
						}
						remove_hook = {
							target = scope:owner
							type = weak_blackmail_hook
						}
					}
					else_if = {
						limit = {
							has_hook_of_type = {
								target = scope:owner
								type = strong_blackmail_hook
							}
						}
						remove_hook = {
							target = scope:owner
							type = strong_blackmail_hook
						}
					}
				}
			}
		}

		### Send toast to exposer ###
		if = {
			limit = {
				trigger_if = {
					limit = { exists = scope:target }
					NOR = {
						scope:secret_exposer = scope:target
						scope:secret_exposer = scope:owner
					}
				}
				trigger_else = {
					NOT = { scope:secret_exposer = scope:owner }
				}
			}
			scope:secret_exposer = {
				save_scope_as = secret_expose_feed_message_scope
				send_interface_toast = {
					left_icon = scope:owner
					title = secret_exposed_notification_effect_message

					custom_tooltip = secret_exposed_notification_effect_message_witch.i_exposed

					if = {
						limit = { has_hook_from_secret = scope:secret }
						remove_hook = {
							target = scope:owner
							type = weak_blackmail_hook
						}
					}
				}
			}
		}

		scope:secret_owner = {
			if = {
				limit = {
					NOT = {
						this = scope:secret_exposer
					}
					is_male = yes # The house of cards only comes down when the PC is revealed.
				}
				trigger_event = regula_initialize_event.0008
			}
			else = {  ### UPDATE - This doesn't work.
				global_var:regula_secret_keeper = {
					random_targeting_secret = {
						limit = {
							secret_type = regula_covert_conversion
							secret_owner = {
								is_male = yes
							}
						}
						scope:secreties.secret_owner = {
							save_scope_as = truetrial
						}
					}
				}
				global_var:regula_secret_keeper = {
					random_targeting_secret = {
						limit = {
							secret_type = regula_covert_conversion
							secret_owner = {
								is_male = yes
							}
						}
						save_scope_as = regula_secret
						scope:regula_secret.secret_owner = {
							save_scope_as = proto_magister
						}
						scope:proto_magister = {
							send_interface_message = {
								type = secret_exposed_message
								left_icon = scope:owner
								title = regula_covert_conversion_exposed_message
								desc = regula_covert_conversion_exposed_message_desc

								if = {
									limit = { has_hook_from_secret = scope:secret }
									if = {
										limit = {
											has_hook_of_type = {
												target = scope:owner
												type = weak_blackmail_hook
											}
										}
										remove_hook = {
											target = scope:owner
											type = weak_blackmail_hook
										}
									}
									else_if = {
										limit = {
											has_hook_of_type = {
												target = scope:owner
												type = strong_blackmail_hook
											}
										}
										remove_hook = {
											target = scope:owner
											type = strong_blackmail_hook
										}
									}
								}
								reverse_add_opinion = {
									target = scope:owner
									modifier = hate_opinion
									opinion = -20
								}
							}
						}
					}
				}
			}
		}
	}
}