﻿####MARRIAGE TRIGGER LIST###

#GENERAL MARRIAGE TRIGGERS
#can_marry_common_trigger
#can_marry_trigger
#could_marry_character_trigger
#can_marry_character_trigger
#marriage_between_characters_unlocks_alliance_of_min_tier_trigger
#can_become_concubine

#MARRIAGE INTERACTION TRIGGERS

#############################
# GENERAL MARRIAGE TRIGGERS #
#############################

# Is allowed to marry (current marriage/concubine status ignored)
can_marry_common_trigger = {
	is_alive = yes
	NOT = { has_trait_with_flag = can_not_marry }
	can_remarry_trigger = yes ## mr_mod line

	trigger_if = {
		limit = {
			exists = primary_title
		}
		NOR = {
			# Block Mercenaries from marrying or showing up in marriage interactions
			primary_title = {
				is_mercenary_company = yes
			}
			is_leading_faction_type = peasant_faction
			is_leading_faction_type = populist_faction
			government_has_flag = government_is_herder
		}
	}

	# Clergy cannot marry if their faith disallows it
	trigger_if = {
		limit = {
			is_clergy = yes
		}
		faith = {
			has_doctrine_parameter = clergy_can_marry
		}
	}
	trigger_if = {
		limit = {
			exists = liege.involved_activity.var:tournament_marriage_prize
			this = liege.involved_activity.var:tournament_marriage_prize
		}
		exists = scope:contest_winner
	}
}

can_remarry_trigger = {
	trigger_if = {
		limit = {
			#is_ai = yes
			NOT = { has_game_rule = character_remarriage_disabled }
			any_former_spouse = {
				even_if_dead = yes
			}
		}
		trigger_if = {
			limit = {
				OR = {
					AND = {
						fertility < low_fertility
						NOT = { has_trait = celibate }
					}
					AND = {
						is_female = yes
						effective_age > define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
					}
				}
			}
			OR = {
				# character is not marrying for procreation but for kinks
				has_trait = lustful
				# character needs an heir
				AND = {
					is_ruler = yes
					is_landed = yes
					NOT = { exists = primary_heir } # no heir
				}
			}
		}
		trigger_if = {
			limit = { has_game_rule = character_remarriage_restricted }
			can_remarry_common_trigger = yes
		}
		trigger_else_if = {
			limit = { has_game_rule = character_remarriage_general }
			OR = {
				NOT = { any_child = {} } # no child
				ai_sociability > high_positive_ai_value
				has_trait = lustful
				save_temporary_scope_value_as = {
					name = parent_age_quartered
					value = {
						value = effective_age
						multiply = 0.25
						min = 0
					}
				}
				any_child = { # 75% of children are younger than the parent's age quartered
					effective_age < scope:parent_age_quartered
					percent >= 0.75
				}
				can_remarry_common_trigger = yes
			}
		}
		trigger_else = {
			OR = {
				NOT = { any_child = {} } # no child
				ai_sociability > medium_positive_ai_value
				has_trait = lustful
				save_temporary_scope_value_as = {
					name = parent_age_halved
					value = {
						value = effective_age
						multiply = 0.5
						min = 0
					}
				}
				any_child = { # half of children are younger than the parent's age halved
					effective_age < scope:parent_age_halved
					percent >= 0.5
				}
				can_remarry_common_trigger = yes
			}
		}
	}
	always = yes
}

can_remarry_common_trigger = {
	NOT = { has_variable = qol_honoring_dead_lover_spouse }
	# don't have a child I love or children I like
	save_temporary_scope_value_as = {
		name = qol_my_opinion_of_children
		value = {
			every_child = {
				if = {
					limit = {
						reverse_opinion = {
							target = prev
							value >= high_positive_opinion
						}
					}
					add = 5
				}
				else_if = {
					limit = {
						reverse_opinion = {
							target = prev
							value >= medium_positive_opinion
						}
					}
					add = 3
				}
				else_if = {
					limit = {
						reverse_opinion = {
							target = prev
							value >= low_positive_opinion
						}
					}
					add = 2
				}
				else = {
					add = 1
				}
			}
		}
	}
	scope:qol_my_opinion_of_children < 4
}