﻿might_cheat_on_partner_trigger = {
	NOT = { has_trait = celibate }
	is_eunuch_trigger = no
	trigger_if = {
		limit = { is_ai = no }
		# Players always have the option to cheat - we check this here so that we don't constantly need to OR it when using might_cheat_on_every_partner_trigger.
		always = yes
	}
	trigger_if = {
		limit = {
			$PARTNER$ = {
				government_has_flag = government_is_nomadic 
			}
		}
		NOT = {
			$PARTNER$ = {
				domicile ?= {
					has_domicile_parameter = nomad_yurt_spouse_will_not_cheat
				}
			}
		}
	}
	trigger_else_if = {
		limit = { mgr_can_seduce = no }
		always = no
	}
	trigger_else_if = {
		limit = { has_game_rule = more_seduction }
		always = yes
	}
	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.
			# Additionally, some cultures do not have scruples about extramarital relationships.
			accepts_adultery_without_penalty_trigger = no
		}
		
		NOT = { has_trait = loyal } # Loyal people never cheat

		# Soulmates never cheat, unless they're Lustful/Seducer and have low Honor
		trigger_if = {
			limit = { has_relation_soulmate = $PARTNER$ }
			ai_honor <= medium_negative_ai_value
			calc_true_if = {
				amount >= 2
				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
					# Dishonorable and callous enough to not care about current partners (regardless of opinion).
					AND = {
						ai_compassion <= high_negative_ai_value
						ai_honor <= high_negative_ai_value 
					}
					# Needs aren't getting met.
					AND = {
						is_deviant_trigger = yes
						$PARTNER$ = { is_deviant_trigger = no }
					}
					# Rakish character that's about to have a mental breakdown.
					AND = {
						has_trait = rakish
						stress_level >= 2
					}
				}

				# Calc for honour.
				## Characters with really lacking honour might cheat even at decently opinion positive levels.
				trigger_if = {
					limit = { ai_honor <= high_negative_ai_value }
					# Consorts (spouses, concubines).
					trigger_if = {
						limit = { is_consort_of = $PARTNER$ }
						opinion = {
							target = $PARTNER$
							value <= medium_positive_opinion
						}
					}
					# Lovers.
					trigger_else = {
						opinion = {
							target = $PARTNER$
							value <= high_positive_opinion
						}
					}
				}
				## Characters with at least some honour require much less happy relationships.
				trigger_else_if = {
					limit = { ai_honor <= medium_positive_ai_value }
					# Consorts (spouses, concubines).
					trigger_if = {
						limit = { is_consort_of = $PARTNER$ }
						# Consorts (spouses, concubines) 
						opinion = {
							target = $PARTNER$
							value <= neutral_opinion
						}
					}
					# Lovers.
					trigger_else = {
						opinion = {
							target = $PARTNER$
							value <= low_positive_opinion # 80 for lovers
						}
					}
				}
				## Finally, characters might also cheat if they just dislike their partner enough, regardless of honor.
				trigger_else = {
					opinion = {
						target = $PARTNER$
						value <= high_negative_opinion
					}
				}
			}
		}
	}
	# Having an extramarital relationship with someone else would not count as cheating on this person.
	trigger_else = { always = yes }
}

eligible_for_affairs_trigger = {
	NOR = {
		has_trait = celibate
		#Technically (and, historically, frequently) eunuchs can still have affairs, they just aren't able to impregnate.
		OR = {
			accepts_adultery_without_penalty_trigger = yes
			trait_is_shunned_or_criminal_in_faith_trigger = {
				TRAIT = adulterer
				FAITH = root.faith
				GENDER_CHARACTER = root
			}
			trait_is_shunned_or_criminal_in_faith_trigger = {
				TRAIT = fornicator
				FAITH = root.faith
				GENDER_CHARACTER = root
			}
		}
	}
	mgr_can_seduce = yes
}
accepts_adultery_without_penalty_trigger = {
	OR = {
		has_game_rule = more_seduction
		faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
		culture = { has_cultural_parameter = adultery_always_accepted }
		AND = {
			government_has_flag = government_is_mandala
			house ?= { has_house_power_parameter = aspect_of_creation }
		}
	}
}