﻿
can_become_concubine_of_character_trigger = {
	is_hostage = no
	trigger_if = {
		limit = {
			NOT = { is_imprisoned_by = $CHARACTER$ }
		}
		is_married = no
		is_betrothed = no
		is_concubine = no
		number_of_concubines = 0
	}
	trigger_if = {
		limit = {
			is_imprisoned_by = $CHARACTER$
			is_married = yes
		}
		NOT = { is_spouse_of = $CHARACTER$ }
	}
	NOR = {
		is_concubine_of = $CHARACTER$
		has_character_flag = has_been_offered_as_concubine
	}
	trigger_if = {
		limit = { 
			OR = {
				is_ruler = yes
				is_playable_character = yes
			}
		}
		is_imprisoned_by = $CHARACTER$
		is_ai = yes
	}
	trigger_if = {
		limit = { has_trait = devoted }
		is_imprisoned_by = $CHARACTER$
	}
	is_adult = yes
	can_become_concubine_character_trigger = { CHARACTER = $CHARACTER$ } #Gender, recent divorce, allowed to marry, no illegal incest etc.
}

can_become_concubine_of_character_valid_trigger = {
	is_hostage = no
	trigger_if = {
		limit = {
			NOT = { is_imprisoned_by = $CHARACTER$ }
		}
		is_married = no
		is_betrothed = no
		is_concubine = no
		number_of_concubines = 0
	}
	trigger_if = {
		limit = {
			is_imprisoned_by = $CHARACTER$
			is_married = yes
		}
		NOT = { is_spouse_of = $CHARACTER$ }
	}
	NOR = {
		is_concubine_of = $CHARACTER$
		has_character_flag = has_been_offered_as_concubine
	}
	trigger_if = {
		limit = { 
			OR = {
				is_ruler = yes
				is_playable_character = yes
			}
		}
		is_imprisoned_by = $CHARACTER$
		is_ai = yes
	}
	trigger_if = {
		limit = { has_trait = devoted }
		is_imprisoned_by = $CHARACTER$
	}
	is_adult = yes
	can_take_as_concubine_character_trigger  = { CHARACTER = $CHARACTER$ } #Gender, recent divorce, allowed to marry, no illegal incest etc.
}

can_be_offered_as_concubine_to_character_trigger = {
	trigger_if = {
		limit = {
			NOT = { is_imprisoned_by = $GIVER$ }
		}
		is_married = no
		is_betrothed = no
		OR = {
			is_concubine = no
			AND = {
				is_concubine_of = $GIVER$
				NOT = { has_trait = concubine_elevated }
			}
		}
		number_of_concubines = 0
	}
	trigger_if = {
		limit = {
			is_imprisoned_by = $GIVER$
			is_married = yes
		}
		NOR = {
			is_spouse_of = $CHARACTER$
			is_spouse_of = $GIVER$
		}
	}
	NOR = {
		is_concubine_of = $CHARACTER$
		has_character_flag = has_been_offered_as_concubine
	}
	trigger_if = {
		limit = { 
			OR = {
				is_ruler = yes
				is_playable_character = yes
			}
		}
		is_imprisoned_by = $CHARACTER$
		is_ai = yes
	}
	trigger_if = {
		limit = { has_trait = devoted }
		is_imprisoned_by = $CHARACTER$
	}
	is_adult = yes
	NOT = {
		is_theocratic_lessee = yes
	}
	can_become_concubine_character_trigger = { CHARACTER = $CHARACTER$ } #Gender, recent divorce, allowed to marry, no illegal incest etc.
}

# Same as can_marry_common_trigger, but with exceptions for nuns/monks/devoted
can_become_concubine_common_trigger = {
	is_alive = yes
	OR = {
		NOT = { has_trait_with_flag = can_not_marry }
		AND = { 
			is_imprisoned = yes
			has_trait = devoted
			imprisoner = {
				faith_hostility_level = {
					target = root.faith
					value >= faith_hostile_level = 2
				}
			}
		} 
	}

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

	# Clergy cannot marry if their faith disallows it
	trigger_if = {
		limit = {
			is_clergy = yes
		}
		OR = {
			faith = {
				has_doctrine_parameter = clergy_can_marry
			}
			AND = { 
				is_imprisoned = yes
				has_trait = devoted 
				imprisoner = {
					faith_hostility_level = {
						target = root.faith
						value >= faith_hostile_level = 2
					}
				}
			} 		
		}
	}
	trigger_if = {
		limit = {
			exists = liege.involved_activity.var:tournament_marriage_prize
			this = liege.involved_activity.var:tournament_marriage_prize
		}
		exists = scope:contest_winner
	}
}

#two characters could potentially marry (does NOT check that they're unmarried)
can_become_concubine_character_trigger = {
	save_temporary_scope_as = can_marry_check
	can_become_concubine_common_trigger = yes
	$CHARACTER$ = { can_marry_common_trigger = yes }
	#Opposite genders if you don't have accepted same-sex marriage game rule enabled and your faith supports it
	trigger_if = {
		limit = { #If you're someone's courtier, your liege can marry you anyway
			NOT = { is_courtier_of = $CHARACTER$ }
			allowed_to_marry_same_sex_trigger = no
		}
		sex_opposite_of = $CHARACTER$
	}
	trigger_if = {
		limit = { #If you're someone's courtier, your liege can marry you anyway
			$CHARACTER$ = { NOT = { is_courtier_of = scope:can_marry_check } }
			$CHARACTER$ = { allowed_to_marry_same_sex_trigger = no }
		}
		sex_opposite_of = $CHARACTER$
	}
	trigger_if = {
		limit = {
			is_courtier_of = $CHARACTER$
			$CHARACTER$ = { allowed_to_marry_same_sex_trigger = no }
		}
		sex_opposite_of = $CHARACTER$
	}
	trigger_if = {
		limit = {
			$CHARACTER$ = { is_courtier_of = scope:can_marry_check }
			allowed_to_marry_same_sex_trigger = no
		}
		sex_opposite_of = $CHARACTER$
	}
	#Have you recently divorced this character?
	NOT = {
		has_opinion_modifier = {
			modifier = divorced_me_opinion
			target = $CHARACTER$
		}
	}
	#Faith hostility & consanguinity
	trigger_if = {
		limit = { NOT = { is_courtier_of = $CHARACTER$ } } #If you're someone's courtier, your liege can marry you anyway
		faith = {
			faith_allows_marriage_consanguinity_trigger = {
				CHARACTER_1 = scope:can_marry_check
				CHARACTER_2 = $CHARACTER$
			}
			#faith_hostility_level = {
			#	target = $CHARACTER$.faith
			#	value < faith_hostility_prevents_marriage_level
			#}
		}
	}
	trigger_if = {
		limit = { $CHARACTER$ = { NOT = { is_courtier_of = scope:can_marry_check } } } #If you're someone's courtier, your liege can marry you anyway
		$CHARACTER$.faith = {
			faith_allows_marriage_consanguinity_trigger = {
				CHARACTER_1 = scope:can_marry_check
				CHARACTER_2 = $CHARACTER$
			}
			#faith_hostility_level = {
			#	target = scope:can_marry_check.faith
			#	value < faith_hostility_prevents_marriage_level
			#}
		}
	}
	trigger_if = {
		limit = {
			any_close_or_extended_family_member = {
				any_spouse = { this = $CHARACTER$ }
			}
		}
		faith = { has_doctrine = doctrine_consanguinity_unrestricted }
		$CHARACTER$ = {
			faith = { has_doctrine = doctrine_consanguinity_unrestricted }
			NOT = {
				any_spouse = {
					is_close_or_extended_family_of = scope:can_marry_check
					NOT = {
						faith = { has_doctrine = doctrine_consanguinity_unrestricted }
					}
				}
			}
		}
	}
	# Cannot marry self
	NOT = {
		scope:can_marry_check = { is_spouse_of = $CHARACTER$ }
	}
}

# Same trigger as above with the exception of the recent divorce trigger
can_take_as_concubine_character_trigger = {
	save_temporary_scope_as = can_marry_check
	can_become_concubine_common_trigger = yes
	$CHARACTER$ = { can_marry_common_trigger = yes }
	#Opposite genders if you don't have accepted same-sex marriage game rule enabled and your faith supports it
	trigger_if = {
		limit = {
			$CHARACTER$ = { allowed_to_marry_same_sex_trigger = no }
		}
		sex_opposite_of = $CHARACTER$
	}
	#Faith hostility & consanguinity
	trigger_if = {
		limit = { NOT = { is_courtier_of = $CHARACTER$ } } #If you're someone's courtier, your liege can marry you anyway
		faith = {
			faith_allows_marriage_consanguinity_trigger = {
				CHARACTER_1 = scope:can_marry_check
				CHARACTER_2 = $CHARACTER$
			}
			#faith_hostility_level = {
			#	target = $CHARACTER$.faith
			#	value < faith_hostility_prevents_marriage_level
			#}
		}
	}
	trigger_if = {
		limit = { $CHARACTER$ = { NOT = { is_courtier_of = scope:can_marry_check } } } #If you're someone's courtier, your liege can marry you anyway
		$CHARACTER$.faith = {
			faith_allows_marriage_consanguinity_trigger = {
				CHARACTER_1 = scope:can_marry_check
				CHARACTER_2 = $CHARACTER$
			}
			#faith_hostility_level = {
			#	target = scope:can_marry_check.faith
			#	value < faith_hostility_prevents_marriage_level
			#}
		}
	}
	NOT = {
		scope:can_marry_check = { is_spouse_of = $CHARACTER$ }
	}
}