﻿marry_off_interaction = {
	icon = icon_marriage
	category = interaction_category_diplomacy
	common_interaction = yes

	desc = marry_off_interaction_desc
	
	send_name = marry_off_send
	needs_recipient_to_open = no
	special_interaction = arrange_marriage_interaction
	interface = marriage
	redirect = {
		if = {
			limit = {
				exists = scope:secondary_actor
			}
			scope:recipient = {
				save_scope_as = secondary_recipient
				matchmaker = {
					save_scope_as = recipient
				}
			}

		}
		else = {
			scope:recipient = {
				save_scope_as = secondary_actor
			}
			clear_saved_scope = recipient
		}
	}

	populate_recipient_list = {
		#populate only with your courtiers or children/grandchildren if you are a landless adventurer
		if = {
			limit = {
				scope:actor = {
					has_government = landless_adventurer_government
				}
			}
			scope:secondary_actor = {
				if = {
					limit = {
						scope:actor != this
					}
					add_to_list = characters
				}
				every_courtier = {
					limit = {
						trigger_if = {
							limit = {
								is_concubine = yes
							}
							is_concubine_of = scope:actor
							can_marry_character_trigger = { CHARACTER = scope:actor }
						}
					}
					add_to_list = characters
				}
				every_courtier_away = {
					limit = {
						trigger_if = {
							limit = {
								is_concubine = yes
							}
							is_concubine_of = scope:actor
							can_marry_character_trigger = { CHARACTER = scope:actor }
						}
					}
					add_to_list = characters
				}
				every_child = {
					even_if_dead = yes
					if = {
						limit = {
							is_alive = yes
							NOT = { is_in_list = characters }
							trigger_if = {
								limit = {
									is_concubine = yes
								}
								is_concubine_of = scope:actor
								can_marry_character_trigger = { CHARACTER = scope:actor }
							}
						}
						add_to_list = characters
					}
					every_child = {
						even_if_dead = yes
						if = {
							limit = {
								is_alive = yes
								NOT = { is_in_list = characters }
								trigger_if = {
									limit = {
										is_concubine = yes
									}
									is_concubine_of = scope:actor
									can_marry_character_trigger = { CHARACTER = scope:actor }
								}
							}
							add_to_list = characters
						}
						every_child = {
							if = {
								limit = {
									is_alive = yes
									NOT = { is_in_list = characters }
									trigger_if = {
										limit = {
											is_concubine = yes
										}
										is_concubine_of = scope:actor
										can_marry_character_trigger = { CHARACTER = scope:actor }
									}
								}
								add_to_list = characters
							}
						}
					}
				}
			}
		}
		#otherwise, populate with anyone eligible
		else = {
			scope:secondary_actor = {
				if = {
					limit = {
						culture = { has_cultural_parameter = reduced_marriage_acceptance_distant_realms }
					}
					every_opposite_sex_spouse_candidate = {
						limit = {
							top_liege.culture = scope:secondary_actor.top_liege.culture
						}
						add_to_list = characters
					}
					if = {
						limit = { allowed_to_marry_same_sex_trigger = yes }
						every_same_sex_spouse_candidate = {
							limit = {
								scope:secondary_actor != this
								top_liege.culture = scope:secondary_actor.top_liege.culture
							}
							add_to_list = characters
						}
					}
				}
				else = {
					every_opposite_sex_spouse_candidate = {
						add_to_list = characters
					}
					if = {
						limit = { allowed_to_marry_same_sex_trigger = yes }
						every_same_sex_spouse_candidate = {
							limit = {
								scope:secondary_actor != this
							}
							add_to_list = characters
						}
					}
				}
			}
		}
	}

	cost = {
		prestige = {
			value = 0
			if = {
				limit = {
					exists = scope:actor
					exists = scope:recipient
					exists = scope:secondary_recipient
					exists = scope:secondary_actor
					scope:secondary_actor = { is_close_family_of = scope:actor }
					scope:recipient = {
						OR = {
							AND = {
								vassal_contract_has_flag = vassal_contract_marriage_favor
								is_allied_to = scope:actor
							}
							NOT = { vassal_contract_has_flag = vassal_contract_marriage_favor}
						}
					}
				}
				add = {
					scope:actor = {
						every_vassal = {
							limit = {
								vassal_contract_has_flag = vassal_contract_marriage_favor
								NOT = { is_allied_to = scope:actor }
								NOR = {
									this = scope:recipient
									this = scope:secondary_recipient
								}
							}
							add = medium_prestige_value
						}
					}
					desc = VASSAL_WITH_MARRIAGE_FAVOR
				}
			}
		}
		
		influence = {
			value = 0
			if = {
				limit = { scope:influence_send_option = yes }
				add = scope:actor.medium_influence_value
				desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
			}
		}
	}

	interface_priority = 60

	# actor, recipient ... characters arranging the marriage
	# secondary_actor, secondary_recipient ... characters that should marry

	is_shown = {
		# Enable only for yourself if you're a landless adventurer
		trigger_if = {
			limit = {
				scope:actor = {
					has_government = landless_adventurer_government
				}
			}
			scope:secondary_actor = {
				scope:actor = this
			}
		}
		scope:secondary_actor = {
			#Is this someone I can marry off?
			OR = {
				is_courtier_of = scope:actor
				AND = {
					is_child_of = scope:actor
					target_is_liege_or_above = scope:actor
				}
				# LMF: added primary heir's children in your realm
				AND = {
					scope:actor = { is_ai = no }
					any_parent = {
						is_child_of = scope:actor
						is_primary_heir_of = scope:actor
					}
					target_is_liege_or_above = scope:actor
				}
				# LMF: added primary heir's grandchildren in your realm
				AND = {
					scope:actor = { is_ai = no }
					any_parent = {
						even_if_dead = yes
						any_parent = {
							is_child_of = scope:actor
							is_primary_heir_of = scope:actor
						}
					}
					target_is_liege_or_above = scope:actor
				}
				# LMF: added grandchildren/great-grandchildren who are your heirs and in your realm
				AND = {
					scope:actor = { is_ai = no }
					is_primary_heir_of = scope:actor
					OR = {
						is_grandchild_of = scope:actor
						is_great_grandchild_of = scope:actor
					}
					target_is_liege_or_above = scope:actor
				}
				scope:actor = this
			}
			#They can be married
			can_marry_trigger = yes
			#To account for a person marrying their concubines
			trigger_if = {
				limit = {
					is_concubine = yes
				}
				is_concubine_of = scope:actor
				can_marry_character_trigger = { CHARACTER = scope:actor }
			}
		}
		# Block further marriage proposals for people who have a pending grand wedding
		NOR = {
			scope:secondary_actor ?= { has_been_promised_grand_wedding = yes }
			scope:secondary_recipient ?= { has_been_promised_grand_wedding = yes }
		}
	}

	is_valid_showing_failures_only = {
		#Diplomatic availability & prison
		scope:secondary_actor = {
			is_imprisoned = no
			bp2_valid_for_standard_interactions_trigger = yes
		}
		marriage_interaction_non_loyal_diarchs_refuse_secondary_marriage_trigger = { TARGET = secondary_actor }
		trigger_if = {
			limit = {
				scope:secondary_actor != scope:secondary_recipient
			}
			marriage_interaction_non_loyal_diarchs_refuse_secondary_marriage_trigger = { TARGET = secondary_recipient }
		}
		marriage_interaction_non_loyal_diarchs_refuse_secondary_marriage_trigger = { TARGET = actor }
		marriage_interaction_non_loyal_diarchs_refuse_secondary_marriage_trigger = { TARGET = recipient }
	}

	has_valid_target_showing_failures_only = {
		marriage_interaction_valid_target_trigger = yes  #Checks marriage status, betrothed, gender, consanguinity, faith hostility etc.

		#Diplomatic availability & prison (located here because these will never be set at the start)
		scope:recipient = {
			is_imprisoned = no
		}
		NOT = {
			scope:actor = {
				is_at_war_with = scope:recipient
			}
		}
		trigger_if = {
			limit = { scope:recipient != scope:secondary_recipient }
			scope:secondary_recipient = {
				is_imprisoned = no
				bp2_valid_for_standard_interactions_trigger = yes
			}
		}
		#secondary_actor is checked above because they are always available

		#Blocks AI from marrying player guests
		scope:secondary_recipient = {
			trigger_if = {
				limit = {
					is_pool_guest = yes
					host = {
						is_ai = no
						this != scope:actor
					}
				}
				NOT = { is_pool_guest_of = host }
			}
		}
	}

	on_send = {
		if = {
			limit = {
				scope:grand_wedding_promise = yes
			}
			scope:actor = {
				set_variable = {
					name = grand_wedding_promise_pending
					days = 10
				}
				if = {
					limit = {
						is_ai = yes
					}
					remove_short_term_gold = ai_wedding_promise_gold_actor
				}
			}
		}
		if = {
			limit = { exists = global_var:travel_the_distance_is_loaded }
			ttd_on_send_marriage_effect = yes
		}
	}

	on_accept = {
		marriage_interaction_on_accept_effect = yes
		
		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = medium_unity_gain
			DESC = clan_unity_marry_off.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
		
		scope:actor = {
			if = {
				limit = {
					scope:herd_send_option = yes
				}
				pay_herd = {
					target = scope:recipient
					value = scope:actor.domicile.medium_herd_value
				}
			}
			if = {
				limit = {
					has_variable = grand_wedding_promise_pending
				}
				remove_variable = grand_wedding_promise_pending
			}
		}
		
		if = {
			limit = { exists = global_var:travel_the_distance_is_loaded }
			ttd_on_accept_marriage_effect = yes
		}
	}

	on_decline = {
		scope:actor = {
			if = {
				limit = { this != scope:recipient }
				trigger_event = marriage_interaction.0011
			}
			if = {
				limit = {
					has_variable = grand_wedding_promise_pending
				}
				remove_variable = grand_wedding_promise_pending
			}
		}
		
		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = medium_unity_loss
			DESC = clan_unity_marry_off_decline.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
		
		if = {
			limit = { exists = global_var:travel_the_distance_is_loaded }
			ttd_marriage_proposal_clean_up_effect = yes
		}
	}

	auto_accept = {
		marriage_interaction_auto_accept_trigger = yes #Strong hook conditions
	}
	
	ai_accept = {
		base = 0 # Should be 0 for all interactions
		
		marriage_ai_accept_modifier = yes
		
		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
	}

	send_option = {
		flag = grand_wedding_promise
		localization = GRAND_WEDDING_PROMISE

		is_shown = {
			scope:actor = { #Can organize a Grand Wedding
				highest_held_title_tier > tier_barony
				is_landed_or_landless_administrative = yes
				trigger_if = {
					limit = {
						is_ai = yes
					}
					is_at_war = no
				}
				# DLC locked
				has_dlc_feature = tours_and_tournaments
				has_dlc_feature = advanced_activities
			}
		}

		current_description = {
			desc = "GRAND_WEDDING_PROMISE_INFO"
		}

		is_valid = {
			scope:actor = {
				gold >= real_wedding_cost_actor_scope
				trigger_if = {
					limit = { is_ai = yes }
					is_available = yes
				}
				custom_tooltip = {
					text = grand_wedding_already_promised_tt
					NOR = {
						AND = {
							has_variable = promised_grand_wedding_marriage_countdown
							var:promised_grand_wedding_marriage_countdown = { is_alive = yes }
						}
						has_variable = grand_wedding_promise_pending
					}
				}
			}
			custom_tooltip = {
				text = grand_wedding_only_dominant_side
				trigger_if = {
					limit = {
						scope:secondary_actor ?= {
							is_female = yes
						}
					}
					OR = {
						scope:secondary_actor ?= { matrilinear_betrothal = yes }
						scope:matrilineal = yes
					}
				}
				trigger_else = {
					NOR = {
						scope:secondary_actor ?= { matrilinear_betrothal = yes }
						scope:matrilineal = yes
					}
				}
			}
			custom_tooltip = {
				text = grand_wedding_only_family
				scope:secondary_actor ?= {
					is_close_or_extended_family_of = scope:actor
				}
			}
		}
	}
	
	send_option = {
		flag = matrilineal
		localization = "MATRILINEAL_OFFER"
		is_shown = {
			NAND = {
				scope:secondary_actor ?= { is_male = yes }
				scope:secondary_recipient ?= { is_male = yes }
			}
		}
		starts_enabled = {
			scope:actor = {
				OR = {
					faith = {
						has_doctrine = doctrine_gender_female_dominated
					}
					# LMF: added AI option for cultures with equal or female inheritance to use matrilineal
					AND = {
						is_ai = yes
						scope:secondary_actor ?= { is_female = yes }
						culture = {
							OR = {
								has_cultural_tradition = tradition_equal_inheritance
								has_cultural_tradition = tradition_female_only_inheritance
							}
						}
						OR = {
							is_landed = yes
							any_heir_title = {}
						}
						NOR = {
							has_game_rule = matrilineal_marriages_never
							has_game_rule = matrilineal_marriages_female_and_equal
						}
					}
					# LMF: added AI option for female rulers to use matrilineal for their own wedding
					AND = {
						is_landed = yes
						scope:secondary_actor ?= this
						is_female = yes
						is_ai = yes
						NOR = {
							has_trait = humble
							has_trait = zealous
							has_game_rule = matrilineal_marriages_never
							has_game_rule = matrilineal_marriages_female_and_equal
						}
					}
					# LMF: added AI option for dukes+ to use matrilineal for their female heirs
					AND = {
						is_landed = yes
						primary_title.tier >= tier_duchy
						is_ai = yes
						scope:secondary_actor ?= {
							is_female = yes
							is_primary_heir_of = scope:actor
						}
						NOR = {
							has_trait = humble
							has_trait = zealous
							has_game_rule = matrilineal_marriages_never
							has_game_rule = matrilineal_marriages_female_and_equal
						}
					}
					# LMF: added AI option for bold dukes+ to use matrilineal once they have enough alliances
					AND = {
						is_landed = yes
						primary_title.tier >= tier_duchy
						is_ai = yes
						scope:secondary_actor ?= {
							is_female = yes
							is_close_family_of = scope:actor
							dynasty ?= scope:actor.dynasty
						}
						ai_boldness >= medium_positive_boldness
						any_ally = {
							NOR = {
								target_is_vassal_or_below = scope:actor
								target_is_liege_or_above = scope:actor
							}
							count >= 4
						}
						NOR = {
							has_trait = humble
							has_trait = zealous
							has_game_rule = matrilineal_marriages_never
							has_game_rule = matrilineal_marriages_female_and_equal
						}
					}					
					AND = {
						scope:secondary_actor ?= { is_female = yes }
						faith = { has_doctrine = doctrine_gender_equal }
					}
					AND = {
						scope:secondary_actor ?= this
						is_female = yes
						is_ai = no
					}
					AND = {
						scope:secondary_actor ?= { is_female = yes }
						scope:secondary_recipient ?= { is_female = yes }
					}
				}
			}
		}
		# so they can use grand wedding...
		can_be_changed = {
			NAND = {
				scope:secondary_actor ?= { is_female = yes }
				scope:secondary_recipient ?= { is_female = yes }
			}
		}
	}
	
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = MARRIAGE_HOOK
	}
	#This option cannot be linked with the hook icon, because recipient isn't known in the right-click menu
	
	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence 
			scope:actor = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:actor = { influence >= medium_influence_value }
			# Both characters are within the same top realm
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	
	send_option = { # MPO Herd
		is_shown = { # Actor must have a government that uses Herd 
			scope:actor = {
				government_has_flag = government_is_nomadic
				is_ai = no
			}
			# Recipient must care about Herd
			scope:recipient = {
				government_has_flag = government_is_nomadic
			}
		}
		is_valid = {
			# Actor has enough Herd
			scope:actor = { domicile.herd >= domicile.medium_herd_value }
		}
		flag = herd_send_option
		localization = TRADE_HERD_FOR_BETTER_AI_ACCEPTANCE
	}
	
	send_options_exclusive = no
	
	show_effects_in_notification = no
	greeting = positive
	
	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:secondary_actor = {
						is_adult = yes
					}
					scope:secondary_recipient = {
						is_adult = yes
					}
					NOR = {
						scope:secondary_actor = { has_been_promised_grand_wedding = yes }
						scope:secondary_recipient = { has_been_promised_grand_wedding = yes }
					}
				}
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = {
								scope:matrilineal = yes
								scope:secondary_actor = scope:actor
								scope:secondary_recipient = scope:recipient
							}
							desc = MARRIAGE_NOTIFICATION_BOTH_PERSONAL_MATRI
						}
						triggered_desc = {
							trigger = {
								scope:matrilineal = yes
								scope:secondary_actor = scope:actor
							}
							desc = MARRIAGE_NOTIFICATION_ACTOR_PERSONAL_MATRI
						}
						triggered_desc = {
							trigger = {
								scope:matrilineal = yes
								scope:secondary_recipient = scope:recipient
							}
							desc = MARRIAGE_NOTIFICATION_RECIPIENT_PERSONAL_MATRI
						}
						triggered_desc = {
							trigger = {
								scope:matrilineal = yes
							}
							desc = MARRIAGE_NOTIFICATION_MATRI
						}
						triggered_desc = {
							trigger = {
								scope:secondary_actor = scope:actor
								scope:secondary_recipient = scope:recipient
							}
							desc = MARRIAGE_NOTIFICATION_BOTH_PERSONAL
						}
						triggered_desc = {
							trigger = {
								scope:secondary_actor = scope:actor
							}
							desc = MARRIAGE_NOTIFICATION_ACTOR_PERSONAL
						}
						triggered_desc = {
							trigger = {
								scope:secondary_recipient = scope:recipient
							}
							desc = MARRIAGE_NOTIFICATION_RECIPIENT_PERSONAL
						}
						desc = MARRIAGE_NOTIFICATION
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:matrilineal = yes
							scope:secondary_actor = scope:actor
							scope:secondary_recipient = scope:recipient
						}
						desc = BETROTHAL_NOTIFICATION_BOTH_PERSONAL_MATRI
					}
					triggered_desc = {
						trigger = {
							scope:matrilineal = yes
							scope:secondary_actor = scope:actor
						}
						desc = BETROTHAL_NOTIFICATION_ACTOR_PERSONAL_MATRI
					}
					triggered_desc = {
						trigger = {
							scope:matrilineal = yes
							scope:secondary_recipient = scope:recipient
						}
						desc = BETROTHAL_NOTIFICATION_RECIPIENT_PERSONAL_MATRI
					}
					triggered_desc = {
						trigger = {
							scope:matrilineal = yes
						}
						desc = BETROTHAL_NOTIFICATION_MATRI
					}
					triggered_desc = {
						trigger = {
							scope:secondary_actor = scope:actor
							scope:secondary_recipient = scope:recipient
						}
						desc = BETROTHAL_NOTIFICATION_BOTH_PERSONAL
					}
					triggered_desc = {
						trigger = {
							scope:secondary_actor = scope:actor
						}
						desc = BETROTHAL_NOTIFICATION_ACTOR_PERSONAL
					}
					triggered_desc = {
						trigger = {
							scope:secondary_recipient = scope:recipient
						}
						desc = BETROTHAL_NOTIFICATION_RECIPIENT_PERSONAL
					}
					desc = BETROTHAL_NOTIFICATION
				}
			}
		}
	}
}

elope_interaction = {
	icon = icon_scheme_elope
	category = interaction_category_friendly

	scheme = elope

	desc = elope_interaction_desc

	notification_text = elope_interaction_notification

	ai_targets = {
		ai_recipients = scripted_relations
	}

	ai_target_quick_trigger = {
		adult = yes
		attracted_to_owner = yes
		owner_attracted = yes
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 144
		duchy = 36
		kingdom = 0
		empire = 0
		hegemony = 0
	}

	redirect = {
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
	}

	is_shown = {
		scope:actor = {
			OR = {
				has_relation_lover = scope:recipient
				has_relation_soulmate = scope:recipient
				AND = {
					has_government = landless_adventurer_government
					has_perk = accomplished_forger_perk
				}
			}
		}
		scope:recipient = {
			is_adult = yes
			is_courtier = yes
			NOR = {
				is_courtier_of = scope:actor
				is_consort_of = scope:actor
			}
			can_elope_character_trigger = { CHARACTER = scope:actor }
		}
	}


	is_valid_showing_failures_only = {
		scope:recipient = {
			is_travelling = no
			NOT = { has_trait = eunuch }
		}
		scope:actor = {
			is_imprisoned = no
			is_travelling = no
			NOT = { has_trait = eunuch }
			can_start_scheme = {
				type = elope
				target_character = scope:recipient
			}
		}
		trigger_if = { #For landless adventurers we check range.
			limit = {
				scope:actor = {
					is_landless_adventurer = yes
				}
			}
			ep3_laamp_diplo_range_trigger = {
				TARGET = scope:recipient
				LAAMP = scope:actor
			}
		}
	}


	ai_accept = {
		base = 0

		elopment_ai_accept_modifier = yes
	}

	ai_potential = {
		is_adult = yes
		OR = {
			any_relation = { type = lover }
			any_relation = { type = soulmate }
		}
		NOR = {
			has_trait = celibate
			has_trait = infirm
			scheme_generic_ai_blocker_trigger = yes
		}
	}

	ai_min_reply_days = 1
	ai_max_reply_days = 3

	on_auto_accept = {
		scope:actor = {
			stress_impact = {
				honest = minor_stress_impact_gain
				just = minor_stress_impact_gain
			}
			show_as_tooltip = {
				elope_success_effect = {
					TARGET = scope:recipient
					OWNER = scope:actor
				}
			}
		}
		hidden_effect = {
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = elope_interaction_notification

					left_icon = scope:actor
					right_icon = scope:recipient

					begin_scheme_basic_effect = {
						SCHEME_TYPE = elope
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
					}

					show_as_tooltip = {
						stress_impact = {
							honest = minor_stress_impact_gain
							just = minor_stress_impact_gain
						}
					}
				}
			}
		}
	}
	
	on_accept = {
		scope:actor = {
			stress_impact = {
				honest = minor_stress_impact_gain
				just = minor_stress_impact_gain
			}
			show_as_tooltip = {
				elope_success_effect = {
					TARGET = scope:recipient
					OWNER = scope:actor
				}
			}
		}
		hidden_effect = {
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = elope_interaction_notification

					left_icon = scope:actor
					right_icon = scope:recipient

					begin_scheme_basic_effect = {
						SCHEME_TYPE = elope
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
					}

					show_as_tooltip = {
						stress_impact = {
							honest = minor_stress_impact_gain
							just = minor_stress_impact_gain
						}
					}
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = elope_interaction_decline_toast
				left_icon = scope:recipient
			}
		}
	}

	auto_accept = {
		scope:actor = {
			has_relation_soulmate = scope:recipient
		}
	}

	ai_will_do = {
		base = 100
		
		# More likely to elope with soulmate
		modifier = {
			add = 25
			scope:actor = { has_relation_soulmate = scope:recipient }
		}

		# Don't bother if intrigue total is way too low
		modifier = {
			add = {
				value = scope:actor.intrigue
				multiply = 4
			}
		}
		modifier = {
			add = {
				value = scope:recipient.intrigue
				multiply = 4
			}
		}
		modifier = {
			add = {
				value = scope:recipient.liege.intrigue
				multiply = -4
			}
		}
		modifier = {
			exists = scope:recipient.liege.cp:councillor_spymaster
			NOR = {
				scope:recipient.liege.cp:councillor_spymaster = scope:recipient
				scope:recipient.liege.cp:councillor_spymaster = scope:actor
				scope:actor = {
					any_scheme = {
						scheme_target_character = scope:recipient
						scheme_is_character_agent = scope:recipient.liege.cp:councillor_spymaster
					}
				}
			}
			add = {
				value = scope:recipient.liege.cp:councillor_spymaster.intrigue
				multiply = -4
			}
		}
		
		# Won't leave their spouse if they like them or they're a ruler
		modifier = {
			factor = 0
			scope:actor = {
				ai_rationality > -100 # Lunatics can do whatever
				exists = primary_spouse
				primary_spouse = { is_ruler = yes }
			}
		}
		
		# Won't leave their spouse for a lover if they like them
		modifier = {
			factor = 0
			scope:actor = {
				ai_rationality > -100 # Lunatics can do whatever
				NOT = { has_relation_soulmate = scope:recipient }
				exists = primary_spouse
				primary_spouse = {
					reverse_opinion = { target = scope:actor value >= 20 }
					opinion = { target = scope:actor value >= 20 }
				}
			}
		}
		
		# Rulers won't elope if they're cowards
		modifier = {
			factor = 0
			scope:actor = {
				is_ruler = yes
				ai_boldness < 0
			}
		}
		
		# Rulers won't elope with married women or leave their wife if they're honorable
		modifier = {
			factor = 0
			scope:actor = {
				is_ruler = yes
				ai_rationality > -100 # Lunatics can do whatever
				ai_honor >= low_positive_ai_value
				OR = {
					scope:recipient = { is_married = yes }
					is_married = yes
				}
			}
		}
		
		# Rulers won't elope with an infertile spouse if they don't already have children
		modifier = {
			factor = 0
			scope:actor = {
				is_ruler = yes
				fertility > 0.1
				OR = {
					is_female = no
					age < marriage_female_fertility_cutoff_age_value
				}
				NOT = {
					any_child = { count > 1 }
				}
			}
			scope:recipient = {
				is_adult = yes
				OR = {
					fertility < 0.1
					sex_same_as = scope:actor
					AND = {
						is_female = yes
						age >= marriage_female_fertility_cutoff_age_value
					}											
				}
			}
		}
		
		# Don't make the target's close family angry if they're friend/ally/liege unless it's your soulmate
		modifier = {
			factor = 0
			scope:actor = {
				ai_rationality > -100 # Lunatics can do whatever
				NOT = { has_relation_soulmate = scope:recipient }
			}
			scope:recipient = {
				any_close_family_member = {
					is_close_family_of = scope:recipient
					OR = {
						has_relation_friend = scope:actor
						is_allied_to = scope:actor
						target_is_liege_or_above = scope:actor
					}
				}
			}
		}
		
		# Don't initiate the elopement if wrong gender and your partner is the bolder one
		modifier = {
			factor = 0
			scope:actor = {
				ai_boldness < scope:recipient.ai_boldness
				OR = {
					AND = {
						is_female = yes
						NOR = {
							faith = { has_doctrine = doctrine_gender_female_dominated }
							faith = { has_doctrine = doctrine_gender_equal }
							is_ruler = yes
						}
					}
					AND = {
						is_female = no
						NOR = {
							faith = { has_doctrine = doctrine_gender_male_dominated }
							faith = { has_doctrine = doctrine_gender_equal }
							is_ruler = yes
						}
					}
				}
			}
		}
		
		ttd_minor_distance_ai_modifier = yes
	}
}

