
arrange_marriage_interaction = {
	category = interaction_category_diplomacy
	common_interaction = yes

	special_interaction = arrange_marriage_interaction
	interface = marriage
	use_diplomatic_range = {
		trigger_if = {
			limit = { exists = scope:secondary_actor.betrothed }
			NOT = {
				scope:secondary_actor = {
					betrothed = scope:secondary_recipient
				}
			}
		}
	}

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = scope:recipient
				}
				desc = arrange_marriage_interaction_desc_ruler_at_own_court
			}
			triggered_desc = {
				trigger = {
					scope:actor = {
						can_marry_character_trigger = {
							CHARACTER = scope:recipient
						}
					}
					scope:recipient = { is_ruler = yes }
				}
				desc = arrange_marriage_interaction_desc_both_rulers_can_marry
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						is_ruler = yes
						can_marry_trigger = yes
					}
				}
				desc = arrange_marriage_interaction_desc_both_rulers_recipient_only_can_marry
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						is_ruler = yes
					}
				}
				desc = arrange_marriage_interaction_desc_both_rulers_recipient_neither_can_marry
			}
			triggered_desc = {
				trigger = {
					scope:actor = {
						can_marry_character_trigger = {
							CHARACTER = scope:recipient
						}
					}
				}
				desc = arrange_marriage_interaction_desc_one_ruler_can_marry
			}
			desc = arrange_marriage_interaction_desc_recipient_one_ruler_cannot_marry
		}
	}
	
	redirect = {
		# If the define MARRIAGE_OWNER_IS_MATCHMAKER is set to yes, the actor must end up as the "matchmaker" link for courtiers
		scope:actor = {
			if = {
				limit = {
					exists = matchmaker
					NOT = { this = matchmaker }
				}
				save_scope_as = secondary_actor
				matchmaker = {
					save_scope_as = actor
				}
			}
			if = {
				limit = {
					is_betrothed = yes
					betrothed = scope:recipient
				}

				save_scope_as = secondary_actor
			}
		}

		scope:recipient = {
			if = {
				limit = {
					is_betrothed = yes
					betrothed.matchmaker = scope:actor
					is_adult = yes
					betrothed = {
						is_adult = yes
					}
				}

				save_scope_as = secondary_recipient
				matchmaker = {
					save_scope_as = recipient
				}
				betrothed = {
					save_scope_as = secondary_actor
				}
			}
			if = {
				limit = {
					exists = matchmaker
					NOT = { this = matchmaker }
				}
				save_scope_as = secondary_recipient
				matchmaker = {
					save_scope_as = recipient
				}
			}
		}
	}

	populate_actor_list = {
		scope:actor = {
			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
						}
					}
				}
			}
		}
	}

	populate_recipient_list = {
		scope:recipient = {
			add_to_list = characters
			every_courtier = {
				add_to_list = characters
			}
			every_courtier_away = {
				add_to_list = characters
			}
			every_child = {
				limit = {
					NOT = { is_in_list = characters }
				}
				add_to_list = characters
			}
		}
	}

	interface_priority = 60

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

	is_shown = {
		scope:actor = {
			OR = {
				is_landed = yes #Can arrange marriages for others
				AND = {
					#You're just a courtier? Only use the interaction on characters you can marry
					sex_opposite_of = scope:recipient
					can_marry_character_trigger = { CHARACTER = scope:recipient }
				}
			}
		}
		#If you're interacting with someone who isn't their own matchmaker, only show the interaction if they can get married. (If someone isn't their own matchmaker, they will be set as secondary_recipient by code and their matchmaker becomes recipient)
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = {
				OR = {
					marriage_interaction_can_be_picked_trigger = yes #Can marry anyone
					AND = {
						ready_to_marry_betrothed_trigger = yes
						OR = {
							betrothed = scope:secondary_actor
							trigger_if = {
								limit = { exists = betrothed.liege }
								betrothed.liege = scope:actor
							}
						}
					}
				}
				#To account for a person marrying their concubines/consorts
				trigger_if = {
					limit = {
						is_concubine = yes
					}
					is_concubine_of = scope:actor
					can_marry_character_trigger = { CHARACTER = scope:actor }
				}
			}
		}
	}
	
	is_valid_showing_failures_only = {
		#If we're opening this interaction through the interaction menu (i.e. not all scopes exist yet)
		#This was giving double-warnings about a marry-able character existing so it's commented out for now
		#custom_description = {
		#	text = character_to_marry_exists
		#	object = scope:recipient
		#	scope:recipient = {
		#		OR = {
		#			any_courtier = {
		#				is_at_home = yes
		#				marriage_interaction_can_be_picked_trigger= yes
		#			}
		#			any_child = {
		#				marriage_interaction_can_be_picked_trigger= yes
		#			}
		#		}
		#	}
		#}
		trigger_if = {
			limit = {
				NAND = {
					exists = scope:secondary_actor
					exists = scope:secondary_recipient
				}
			}
			#There is an available marriage
			custom_description = {
				text = "basic_can_marry_check_recipient"
				subject = scope:actor
				object = scope:recipient
				scope:recipient = {
					OR = {
						AND = {
							#Recipient can marry
							can_marry_trigger = yes
							#To account for a person marrying their concubines/consorts
							trigger_if = {
								limit = {
									is_concubine = yes
								}
								is_concubine_of = scope:actor
								can_marry_character_trigger = { CHARACTER = scope:actor }
							}
						}
						AND = {
							is_ruler = yes #(Following are only for rulers)
							OR = {
								any_child = {
									matchmaker = scope:actor
									OR = {
										#Any of recipient's children can marry
										AND = {
											can_marry_trigger = yes
											#To account for a person marrying their concubines/consorts
											trigger_if = {
												limit = {
													is_concubine = yes
												}
												is_concubine_of = scope:actor
											}
										}
										#Any of recipient's children are ready to marry their betrothed
										AND = {
											ready_to_marry_betrothed_trigger = yes
											betrothed.matchmaker = scope:actor
										}
									}
								}
								any_courtier = {
									OR = {
										#Any of recipient's courtiers can marry
										AND = {
											can_marry_trigger = yes
											#To account for a person marrying their concubines/consorts
											trigger_if = {
												limit = {
													is_concubine = yes
												}
												is_concubine_of = scope:actor
											}
										}
										#Any of recipient's courtiers are ready to marry their betrothed
										AND = {
											ready_to_marry_betrothed_trigger = yes
											betrothed.matchmaker = scope:actor
										}
									}
								}
							}
						}
					}
				}
			}
		}
		#Diplomatic availability & prison
		scope:recipient = {
			is_diplomatically_available = yes
			is_imprisoned = no
		}
		NOT = {
			scope:actor = {
				is_at_war_with = scope:recipient
			}
		}
		trigger_if = { #(must be here because secondary_recipient can be set at the start)
			limit = {
				exists = scope:secondary_recipient
				NOT = { scope:secondary_recipient = scope:recipient }
			}
			scope:secondary_recipient = {
				is_diplomatically_available = yes
				is_imprisoned = no
			}
		}
		trigger_if = { #(must be here because secondary_recipient can be set at the start)
			limit = {
				exists = scope:secondary_actor
				NOT = { scope:secondary_actor = scope:actor }
			}
			scope:secondary_actor = {
				is_diplomatically_available = yes
				is_imprisoned = no
			}
		}
	}
	
	# whether a character can be picked for the interaction, interface only (e.g. picking the first character in the marriage interaction)
	# in character scope, actor and recipient event targets can be used, but not the secondary characters (because none exist yet)
	can_be_picked = {
		OR = {
			marriage_interaction_can_be_picked_trigger = yes
			AND = {
				exists = scope:secondary_actor
				exists = scope:secondary_recipient
				scope:secondary_actor.betrothed = scope:secondary_recipient
			}
		}
	}

	#Is evaluated only after secondary_recipient and secondary_actor are both chosen
	has_valid_target_showing_failures_only = {
		marriage_interaction_valid_target_trigger = yes  #Checks marriage status, betrothed, gender, consanguinity, faith hostility etc.

		#Blocks AI from marrying player guests
		scope:secondary_recipient = {
			trigger_if = {
				limit = {
					is_pool_guest = yes
					host = {
						is_ai = no
						NOT = { this = scope:actor }
					}
				}
				NOT = { is_pool_guest_of = host }
			}
		}
		
		#Blocks most AI's from marrying Evil faiths
		trigger_if = {
			limit = {
				scope:actor = {
					is_ai = yes
					NOT = { has_trait = cynical }
				}
			}
			scope:recipient.faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value < faith_hostility_prevents_marriage_level
				}
			}
		}
	}

	pre_auto_accept = {
		if = {
			limit = {
				NOT = { scope:recipient = scope:actor }
			}
			scope:recipient = {
				if = {
					limit = { scope:secondary_actor.betrothed = scope:secondary_recipient }
					send_interface_toast = {
						type = msg_betrothal_fulfilled
						left_icon = scope:secondary_actor
						right_icon = scope:secondary_recipient
					}
				}
				else = {
					send_interface_toast = {
						type = msg_marriage_forced
						left_icon = scope:secondary_actor
						right_icon = scope:secondary_recipient
					}
				}
			}
		}
	}

	on_accept = {
		marriage_interaction_on_accept_effect = yes		
	}

	on_decline = {
		scope:actor = {
			if = {	
				limit = { NOT = { this = scope:recipient } }
				trigger_event = marriage_interaction.0011	
			}
		}
	}

	
	auto_accept = {
		marriage_interaction_auto_accept_trigger = yes #Strong hook conditions
	}
	
	ai_accept = {
		base = 0

		marriage_ai_accept_modifier = yes
	}

	
	send_option = {
		flag = matrilineal
		localization = MATRILINEAL_OFFER
		current_description = {
			triggered_desc = {
				trigger = {
					exists = scope:secondary_actor
					scope:secondary_actor = {
						betrothed = scope:secondary_recipient
						matrilinear_betrothal = yes
					}
				}
				desc = "MATRILINEAL_OFFER_BETROTHAL_INFO"
			}
		}
		is_shown = {
			scope:secondary_actor = { matri_marriage_allowed = yes }
			scope:actor = { matri_marriage_allowed = yes }
		}
		is_valid = {
			scope:secondary_recipient = { matri_marriage_allowed = yes }
			scope:secondary_actor = { matri_marriage_allowed = yes }
		}
		can_be_changed = {
			trigger_if = {
				limit = {
					exists = scope:secondary_actor
				}
				scope:secondary_actor = {
					NOT = {
						betrothed = scope:secondary_recipient
					}
				}
			}
			scope:actor = { matri_marriage_allowed = yes }
		}
		starts_enabled = {
			scope:actor = { matri_marriage_allowed = yes }
			trigger_if = {
				limit = {
					exists = scope:secondary_actor
					scope:secondary_actor = {
						betrothed = scope:secondary_recipient
					}
				}
				scope:secondary_actor = {
					matrilinear_betrothal = yes
				}
			}
			trigger_else_if = {
				limit = {
					exists = scope:secondary_actor
					scope:actor = scope:secondary_actor
					is_female = yes
					is_ai = no
				}
				always = yes
			}
			trigger_else = {
				scope:actor = {
					OR= {
						faith = {
							has_doctrine = doctrine_gender_female_dominated
						}
						AND = {
							scope:secondary_recipient = {
								is_female = yes
								scope:actor = scope:recipient
							}
							faith = { has_doctrine = doctrine_gender_equal }
						}
						AND = {
							exists = scope:secondary_actor
							scope:actor = scope:secondary_actor
							is_female = yes
							is_ai = no
						}
					}
				}
			}
		}
	}
	

	send_option = {
		is_shown = {
			scope:secondary_actor = {
				NOT = {
					betrothed = scope:secondary_recipient
				}
			}
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = marriage_hook
		localization = MARRIAGE_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	
	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
					}
				}
				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
				}
			}
		}
	}
}

#This interaction is referenced in code! If it's renamed you have to ping a coder
marry_off_interaction = {
	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_if = {
			scope:recipient = {
				save_scope_as = secondary_actor
			}
			clear_saved_scope = recipient
		}
	}

	populate_recipient_list = {
		scope:secondary_actor = {
			every_spouse_candidate = {
				limit = {
					NAND = {
						is_landless_ruler = yes
						faith.religious_head = this
						NOT = { scope:secondary_actor.faith = faith }
					}
				}
				add_to_list = characters
			}
		}
	}

	interface_priority = 60

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

	is_shown = {
		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
				}
				scope:actor = this
			}
			#They can be married
			can_marry_trigger = yes
			#To account for a person marrying their concubines/consorts
			trigger_if = {
				limit = {
					is_concubine = yes
				}
				is_concubine_of = scope:actor
				can_marry_character_trigger = { CHARACTER = scope:actor }
			}
		}
	}

	is_valid_showing_failures_only = {
		#Diplomatic availability & prison
		scope:secondary_actor = {
			is_diplomatically_available = yes
			is_imprisoned = no
		}
	}

	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_diplomatically_available = yes
			is_imprisoned = no
		}
		NOT = {
			scope:actor = {
				is_at_war_with = scope:recipient
			}
		}
		trigger_if = {
			limit = { NOT = { scope:recipient = scope:secondary_recipient } }
			scope:secondary_recipient = {
				is_diplomatically_available = yes
				is_imprisoned = no
			}
		}
		#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
						NOT = { this = scope:actor }
					}
				}
				NOT = { is_pool_guest_of = host }
			}
		}
	}

	on_accept = {
		marriage_interaction_on_accept_effect = yes
	}

	on_decline = {
		scope:actor = {
			if = {	
				limit = { NOT = { this = scope:recipient } }
				trigger_event = marriage_interaction.0011	
			}
		}
	}

	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
	}
	
	send_option = {
		is_valid = {
			scope:actor = { matri_marriage_allowed = yes }
			scope:secondary_actor = { matri_marriage_allowed = yes }
		}
		flag = matrilineal
		localization = "MATRILINEAL_OFFER"
		starts_enabled = {
			scope:actor = {
				matri_marriage_allowed = yes
				OR= {
					faith = {
						has_doctrine = doctrine_gender_female_dominated
					}
					AND = {
						scope:secondary_actor = { is_female = yes }
						faith = { has_doctrine = doctrine_gender_equal }
					}
					AND = {
						exists = scope:secondary_actor
						scope:actor = scope:secondary_actor
						is_female = yes
						is_ai = no
					}
				}
			}
		}
	}
	
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = marriage_hook
		localization = MARRIAGE_HOOK
	}
	#This option cannot be linked with the hook icon, because recipient isn't known in the right-click menu
	
	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
					}
				}
				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
				}
			}
		}
	}
}

break_betrothal_interaction = {
	category = interaction_category_diplomacy
	special_interaction = break_betrothal_interaction
	use_diplomatic_range = no
	
	is_shown = {
		OR = {
			#Betrothed to betrothed
			scope:actor.betrothed = scope:recipient

			#Actor breaking recipient's betrothal with their courtier/vassal child
			scope:actor = {
				any_courtier = {
					is_ai = yes
					is_betrothed = yes
					betrothed = { this = scope:recipient }
					OR = {
						is_landed = no
						any_parent = { this = scope:actor }
					}
				}
			}

			#Actor breaking the betrothal of their courtier/vassal child
			scope:recipient = {
				is_ai = yes
				is_betrothed = yes
			 	OR = {
			 		AND = {
			 			is_landed = no
			 			liege = scope:actor
			 		}
			 		AND = {
			 			is_child_of = scope:actor
			 			NOT = {
			 				matchmaker = {
			 					is_parent_of = prev
			 					NOT = { this = scope:actor }
			 				}
			 			}
			 			OR = {
			 				is_landed = no
			 				target_is_liege_or_above = scope:actor
			 			}
			 		}
			 	}
			 	betrothed = { always = yes }
			}

			#Break recipient's betrothal with actor's vassal child/courtier
			scope:recipient = {
				is_betrothed = yes
				betrothed = {
					is_ai = yes
					OR = {
						AND = {
							is_child_of = scope:actor
							target_is_liege_or_above = scope:actor
				 			NOT = {
				 				matchmaker = {
				 					is_parent_of = prev
				 					NOT = { this = scope:actor }
				 				}
				 			}
						}
						AND = {
							is_landed = no
							liege = scope:actor
						}
					}
				}
			}

			#Actor breaking their betrothal to recipient's courtier/vassal child
			AND = {
				scope:actor = { is_betrothed = yes }
				scope:recipient = {
					OR = {
						#Check for courtiers
						any_courtier = {
							is_betrothed = yes
							betrothed = scope:actor
							liege = scope:recipient
						}
						#Check for vassal children
						any_child = {
							is_betrothed = yes
							betrothed = scope:actor
							OR = {
								is_landed = no
								target_is_liege_or_above = scope:recipient
							}
				 			NOT = {
				 				matchmaker = {
				 					is_parent_of = prev
				 					NOT = { this = scope:actor }
				 				}
				 			}
						}
					}
				}
			}
		}
	}

	is_valid = {
		
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes }
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		# Recipient is the betrothed
		custom_description = {
			text = break_betrothal_hook_used
			object = scope:recipient
			trigger_if = {
				limit = {
					exists = scope:recipient.betrothed
					OR = {
						scope:recipient.betrothed = scope:actor
						scope:recipient.betrothed = {
							is_ai = yes
							OR = {
								AND = {
									is_child_of = scope:actor
									target_is_liege_or_above = scope:actor
						 			NOT = {
						 				matchmaker = {
						 					is_parent_of = prev
						 					NOT = { this = scope:actor }
						 				}
						 			}
								}
								AND = {
									is_landed = no
									liege = scope:actor
								}
							}
						}
					}
					exists = scope:recipient.var:hook_used_for_betrothal
				}
				scope:recipient.var:hook_used_for_betrothal = {
					NOT = { this = scope:recipient.betrothed }
				}
			}
		}

		custom_description = {
			text = break_betrothal_hook_used
			object = scope:recipient
			trigger_if = {
				limit = {
					exists = scope:recipient.betrothed
					OR = {
						scope:recipient = scope:actor
						scope:recipient = {
							is_ai = yes
							OR = {
								AND = {
									is_child_of = scope:actor
									target_is_liege_or_above = scope:actor
						 			NOT = {
						 				matchmaker = {
						 					is_parent_of = prev
						 					NOT = { this = scope:actor }
						 				}
						 			}
								}
								AND = {
									is_landed = no
									liege = scope:actor
								}
							}
						}
					}
					exists = scope:recipient.betrothed.var:hook_used_for_betrothal
				}
				scope:recipient.betrothed.var:hook_used_for_betrothal = {
					NOT = { this = scope:recipient }
				}
			}
		}

		# Secondary Recipient is the betrothed
		custom_description = {
			text = break_betrothal_hook_used
			object = scope:recipient
			trigger_if = {
				limit = {
					scope:recipient = {
						OR = {
							#Check for courtiers
							any_courtier = {
								is_betrothed = yes
								betrothed = scope:actor
								liege = scope:recipient
								exists = var:hook_used_for_betrothal
								var:hook_used_for_betrothal = {
									this = scope:actor
								}
							}
							#Check for vassal children
							any_child = {
								is_betrothed = yes
								betrothed = scope:actor
								OR = {
									is_landed = no
									target_is_liege_or_above = scope:recipient
								}
					 			NOT = {
					 				matchmaker = {
					 					is_parent_of = prev
					 					NOT = { this = scope:actor }
					 				}
					 			}
								exists = var:hook_used_for_betrothal
								var:hook_used_for_betrothal = {
									this = scope:actor
								}
							}
						}
					}
				}
				always = no
			}
		}
	}

	on_accept = {
		#Identifies the "injured party"
		scope:recipient = {
			if = {
				limit = { matchmaker = scope:actor }
				betrothed = { save_scope_as = rejected_betrothed }
				save_scope_as = rejecting_betrothed
			}
			else_if = {
				limit = {
					OR = {
						#Check for courtiers
						any_courtier = {
							is_betrothed = yes
							is_ai = yes
							betrothed = scope:actor
							liege = scope:recipient
						}
						#Check for vassal children
						any_child = {
							is_betrothed = yes
							is_ai = yes
							betrothed = scope:actor
							target_is_liege_or_above = scope:recipient
						}
					}
				}
				scope:actor.betrothed = {
					save_scope_as = rejected_betrothed
				}
				scope:actor = {
					save_scope_as = rejecting_betrothed
				}
			}

			else = {
				save_scope_as = rejected_betrothed
				betrothed = { save_scope_as = rejecting_betrothed }
			}
		}

		scope:recipient = { trigger_event = marriage_interaction.0020 }

		#Tooltip for betrothal breakage
		show_as_tooltip = {
			scope:rejected_betrothed = {
				break_betrothal = scope:rejecting_betrothed
			}
		}

		#Figures out if the liege of rejected_betrothed cares
		scope:rejected_betrothed = {
			if = {
				limit = { #The liege matter when assigning prestige/opinion hits
					matchmaker = {
						NOT = { this = scope:rejected_betrothed }
						is_close_or_extended_family_of = scope:rejected_betrothed
					}
				}

				matchmaker = { save_scope_as = rejected_betrothal_owner }
			}

			else = { #The liege doesn't matter, only the betrothed
				save_scope_as = rejected_betrothal_owner
			}
		}

		if = {
			limit = { #Only if you had no reason to break the betrothal
				NOR = {
					scope:rejected_betrothed = { has_trait = eunuch }
					scope:rejecting_betrothed = { has_trait = eunuch }
				}
			}
			#Prestige penalty
			if = {
				limit = {
					OR = {
						scope:rejected_betrothed = { highest_held_title_tier = tier_empire }
						scope:rejected_betrothal_owner = { highest_held_title_tier = tier_empire }
					}
					#Only applied for relevant characters
					OR = {
						scope:rejected_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:rejecting_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:actor = {
							yields_alliance = {
								candidate = scope:rejecting_betrothed
								target = scope:rejected_betrothal_owner
								target_candidate = scope:rejected_betrothed
							}
						}
					}
				}
				scope:actor = { add_prestige = massive_prestige_loss }
			}

			else_if = {
				limit = {
					OR = {
						scope:rejected_betrothed = { highest_held_title_tier = tier_kingdom }
						scope:rejected_betrothal_owner = { highest_held_title_tier = tier_kingdom }
					}
					#Only applied for relevant characters
					OR = {
						scope:rejected_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:rejecting_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:actor = {
							yields_alliance = {
								candidate = scope:rejecting_betrothed
								target = scope:rejected_betrothal_owner
								target_candidate = scope:rejected_betrothed
							}
						}
					}
				}
				scope:actor = { add_prestige = major_prestige_loss }
			}

			else_if = {
				limit = {
					OR = {
						scope:rejected_betrothed = { highest_held_title_tier = tier_duchy }
						scope:rejected_betrothal_owner = { highest_held_title_tier = tier_duchy }
					}
					#Only applied for relevant characters
					OR = {
						scope:rejected_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:rejecting_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:actor = {
							yields_alliance = {
								candidate = scope:rejecting_betrothed
								target = scope:rejected_betrothal_owner
								target_candidate = scope:rejected_betrothed
							}
						}
					}
				}
				scope:actor = { add_prestige = medium_prestige_loss }
			}

			else_if = {
				limit = {
					OR = {
						scope:rejected_betrothed = { highest_held_title_tier = tier_county }
						scope:rejected_betrothal_owner = { highest_held_title_tier = tier_county }
					}
					#Only applied for relevant characters
					OR = {
						scope:rejected_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:rejecting_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:actor = {
							yields_alliance = {
								candidate = scope:rejecting_betrothed
								target = scope:rejected_betrothal_owner
								target_candidate = scope:rejected_betrothed
							}
						}
					}
				}
				scope:actor = { add_prestige = minor_prestige_loss }
			}

			else_if = {
				limit = {
					OR = {
						scope:rejected_betrothed = { highest_held_title_tier = tier_barony }
						scope:rejected_betrothal_owner = { highest_held_title_tier = tier_barony }
					}
					#Only applied for relevant characters
					OR = {
						scope:rejected_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:rejecting_betrothed = {
							OR = {
								is_close_family_of = scope:actor
								dynasty = scope:actor.dynasty
							}
						}
						scope:actor = {
							yields_alliance = {
								candidate = scope:rejecting_betrothed
								target = scope:rejected_betrothal_owner
								target_candidate = scope:rejected_betrothed
							}
						}
					}
				}
				scope:actor = { add_prestige = miniscule_prestige_loss }
			}
		}

		######################################
		# Opinion hits & notification events #
		######################################
		#Personal opinion hit for the rejected_betrothed
		if = {
			limit = { NOT = { scope:rejected_betrothed = scope:actor } }
			scope:rejected_betrothed = {
				if = {
					limit = {
						NOR = {
							has_trait = eunuch
							scope:rejecting_betrothed = { has_trait = eunuch }
						}
					}
					show_as_tooltip = {
						add_opinion = {
							target = scope:actor
							modifier = broke_betrothal_opinion
						}
					}
				}

				hidden_effect = { trigger_event = marriage_interaction.0001 }
			}
		}
		else = {
			hidden_effect = {
				scope:rejecting_betrothed = {
					break_betrothal = scope:rejected_betrothed
				}
			}
		}

		#Personal opinion hit for the rejected_betrothal_owner
		if = {
			limit = {
				NOR = {
					scope:rejected_betrothed = {
						this = scope:rejected_betrothal_owner
					}
					scope:actor = {
						this = scope:rejected_betrothal_owner
					}
					scope:actor = {
						this = scope:rejected_betrothed
					}
				}
			}
			scope:rejected_betrothal_owner = {
				if = {
					limit = {
						NOR = {
							scope:rejected_betrothed = { has_trait = eunuch }
							scope:rejecting_betrothed = { has_trait = eunuch }
						}
					}
					show_as_tooltip = {
						add_opinion = {
							target = scope:actor
							modifier = broke_betrothal_opinion
						}
					}
				}

				hidden_effect = { trigger_event = marriage_interaction.0001 }
			}
		}

		if = {
			limit = {
				NOR = {
					scope:rejected_betrothed = { has_trait = eunuch }
					scope:rejecting_betrothed = { has_trait = eunuch }
				}
			}
			#Opinion hit for close relatives of the rejected_betrothed (that are not rejected_betrothed_owner)
			if = {
				limit = {
					NOT = { scope:rejected_betrothed = scope:actor }
					scope:rejected_betrothed = {
						any_close_or_extended_family_member = {
							NOT = { this = scope:rejected_betrothal_owner }
							count >= 1
						}
					}
				}
				scope:rejected_betrothed = {
					every_close_or_extended_family_member = {
						limit = {
							NOT = { this = scope:rejected_betrothal_owner }
						}
						custom = all_family_members
						add_opinion = {
							target = scope:actor
							modifier = broke_betrothal_opinion
						}
					}
				}
			}

			#Opinion hit for close relatives of the rejecting_betrothed (that are not also close relatives to rejected_betrothed)
			if = {
				limit = {
					NOR = {
						scope:rejecting_betrothed = scope:actor
						scope:rejected_betrothed = scope:actor
					}
					scope:rejecting_betrothed = {
						any_close_or_extended_family_member = {
							NOR = {
								is_close_or_extended_family_of = scope:rejected_betrothed
								this = scope:rejected_betrothal_owner
								this = scope:rejected_betrothed
							}
							count >= 1
						}
					}
				}
				scope:rejecting_betrothed = {
					every_close_or_extended_family_member = {
						limit = {
							NOR = {
								is_close_or_extended_family_of = scope:rejected_betrothed
								this = scope:rejected_betrothal_owner
								this = scope:rejected_betrothed
							}
						}
						custom = all_family_members
						add_opinion = {
							target = scope:actor
							modifier = broke_betrothal_opinion
						}
					}
				}
			}
		}

		scope:actor = {
		# Was the marriage of relevence to the player?
			if = {
				limit = { 
					scope:rejecting_betrothed = {
						is_player_heir_of = scope:actor
					}
				}
				hidden_effect = {
					send_interface_toast = {
						title = msg_break_betrothal
						left_icon = scope:rejecting_betrothed
						right_icon = scope:rejected_betrothed
						custom_tooltip = break_betrothal_hook_toast_desc
					}
				}
			}
			else = { 
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = msg_break_betrothal
						left_icon = scope:rejecting_betrothed
						right_icon = scope:rejected_betrothed
						custom_tooltip = break_betrothal_hook_toast_desc
					}
				}
			}

			#Was the marriage promised to a vassal?
			if = {
				limit = {
					exists = var:promised_to_marry_1
					var:promised_to_marry_1 = {
						this = scope:rejected_betrothed
						any_parent = {
							is_vassal_of = scope:actor
						}
					}
					exists = var:promised_to_marry_2
					var:promised_to_marry_2 = {
						this = scope:rejecting_betrothed
						is_close_family_of = scope:actor
					}
				}
				remove_variable = promised_to_marry_1
				remove_variable = promised_to_marry_2
				trigger_event = clan.1002
			}
		}
	}

	auto_accept = yes
}

make_concubine_interaction = {
	category = interaction_category_diplomacy

	desc = make_concubine_interaction_desc

	interface = concubine_list
	
	ai_targets = {
		ai_recipients = prisoners
	}
	ai_targets = {
		ai_recipients = courtiers
	}
	ai_target_quick_trigger = {
		adult = yes
		owner_attracted = yes # Not optimal, but saves a lot of performance
	}
	ai_frequency = 12

	needs_recipient_to_open = yes

	redirect = {
		# The UI will open to the already filled left and right first if we don't tell it we've got both sides filled
		scope:actor = {
			save_scope_as = secondary_actor
		}
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
	}

	populate_recipient_list = {
		scope:actor = {
			every_courtier = {
				limit = {
					can_become_concubine_of_actor_trigger = yes
				}
				add_to_list = characters
			}
			every_prisoner = {
				limit = {
					NOT = { is_in_list = characters }
					can_become_concubine_of_actor_trigger = yes
				}
				add_to_list = characters
			}
		}
	}
	
	is_shown = {
		scope:actor = {
			allowed_concubines = yes
			is_adult = yes
		}
		scope:recipient = {
			OR = {
				is_courtier_of = scope:actor
				is_imprisoned_by = scope:actor
			}
			can_become_concubine_of_actor_trigger = yes
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = take_concubine_allowed_more
			object = scope:recipient
			scope:actor = {
				allowed_more_concubines = yes
			}
		}
		scope:recipient = {
			is_diplomatically_available = yes
			OR = {
				AND = {
					is_imprisoned_by = scope:actor
					is_married = yes
				}
				is_married = no
			}
		}
	}
	
	ai_potential = {
		is_landed = yes
		is_adult = yes
		fertility > 0
		allowed_more_concubines = yes
		NOR = {
			has_trait = chaste
			has_trait = celibate
			has_sexuality = asexual
		}
	}
	
	auto_accept = yes
	
	ai_will_do = {
		base = 0
		
		modifier = { # Basic Filtering
			add = 100
			scope:actor = {
				number_of_concubines < number_of_desired_concubines
			}
			scope:recipient = {
				sex_opposite_of = scope:actor
				fertility > 0.2
				age < 36
			}
		}
		
		modifier = {
			add = 100
			scope:recipient = {
				is_imprisoned_by = scope:actor
				sex_opposite_of = scope:actor
				OR = {
					is_lowborn = no
					num_of_good_genetic_traits > 0
				}
				fertility > 0.1
				trigger_if = {
					limit = {
						is_female = yes
					}
					age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
				}
			}
		}

		modifier = { # Incest Filtering: Hard NO!
			factor = 0
			scope:actor = {
				relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = scope:recipient }
				NOR = {
					accepts_incest_with_trigger = { CHARACTER = scope:recipient }
					sexually_liberal_trigger = yes
					AND = {
						AND = {
							exists = primary_heir
							primary_heir = { NOT = { dynasty = root.dynasty }	}
						}
						NOT = {
							primary_title = {
								any_title_heir = {	dynasty = root.dynasty 	}
							}
						}
					}
				}
			}
		}

		modifier = { # Incest Filtering: Not likely, but keep the door open...
			factor = 0.2 
			scope:actor = {
				relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = scope:recipient }
				OR = {
					accepts_incest_with_trigger = { CHARACTER = scope:recipient }
					sexually_liberal_trigger = yes
					AND = {
						primary_heir = { NOT = { dynasty = root.dynasty }	}
						NOT = {
							primary_title = {
								any_title_heir = {	dynasty = root.dynasty 	}
							}
						}
					}
				}
			}
		}

		modifier = { # Less likely if married to a player and the target is the player heir 
			factor = 0.4
			scope:actor = {
				any_spouse = {
					is_ai = no
					scope:recipient = {	
						OR = {
							is_primary_heir_of = prev 
							is_heir_of = prev
						}
					}
				}
			}
		}
	}
	
	on_accept = {
		concubine_on_accept_effect = yes
	}
}

find_concubine = {
	category = interaction_category_diplomacy

	desc = find_concubine_desc

	interface = concubine_list

	needs_recipient_to_open = no

	redirect = {
		scope:actor = { # The UI will open to the already filled left first if we don't tell it we've got "our side" actor which is always ourselves
			save_scope_as = secondary_actor
		}
	}

	populate_recipient_list = {
		scope:actor = {
			every_courtier = {
				limit = {
					can_become_concubine_of_actor_trigger = yes
				}
				add_to_list = characters
			}
			every_prisoner = {
				limit = {
					NOT = { is_in_list = characters }
					can_become_concubine_of_actor_trigger = yes
				}
				add_to_list = characters
			}
		}
	}

	is_shown = {
		scope:actor = {
			allowed_concubines = yes
			is_adult = yes
			trigger_if = { #So that we show the recipient list, but can also only use this on ourselves, we have to do this check in the beginning
				limit = {
					NOT = { exists = scope:secondary_recipient }
				}
				scope:actor = scope:recipient
			}
		}
		trigger_if = {
			limit = {
				NOT = { scope:actor = scope:recipient }
			}
			scope:actor = {
				sex_opposite_of = scope:recipient
				NOT = { relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = scope:recipient } }
			}
			scope:recipient = {
				can_become_concubine_of_actor_trigger = yes
				is_adult = yes
				OR = {
					is_imprisoned_by = scope:actor
					is_courtier_of = scope:actor
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = take_concubine_allowed_more
			object = scope:recipient
			scope:actor = {
				allowed_more_concubines = yes
			}
		}
		trigger_if = {
			limit = {
				NOT = { scope:actor = scope:recipient }
			}
			scope:recipient = {
				can_become_concubine_of_actor_trigger = yes
			}
		}
	}

	can_be_picked = {
		is_adult = yes
	}

	auto_accept = yes

	ai_will_do = {
		base = 0
	}
	
	on_accept = {
		concubine_on_accept_effect = yes
	}
}

dismiss_concubine_interaction = {
	category = interaction_category_diplomacy
	
	is_shown = {
		scope:recipient = {
			is_concubine_of = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes }
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
	}

	auto_accept = yes
	
	on_accept = {
		scope:actor = {
			stress_impact = {
				compassionate = minor_stress_impact_gain
			}
			hidden_effect = {
				send_interface_toast = {
					type = event_generic_neutral
					title = msg_concubine_dismissed_title
					right_icon = scope:recipient
					remove_concubine = scope:recipient
				}
			}
		}
		scope:recipient = {
			trigger_event = marriage_interaction.0050

			# Being thrown aside is humiliating, even if you didn't want to be a concubine in the first place.
			add_opinion = {
				modifier = set_me_aside_opinion
				target = scope:actor
			}

			# Figure out where we should go now that we're no longer a concubine.
			if = {
				limit = {
					is_councillor_of = scope:actor
				}
				# Then they should remain in court
			}
			else_if = { #Dismiss to relevant court, or to pool
				limit = {
					any_close_family_member = {
						is_landed = yes
					}
				}
				random_close_family_member = {
					limit = {
						is_child_of = scope:recipient
						is_landed = yes
					}
					alternative_limit = {
						is_parent_of = scope:recipient
						is_landed = yes
					}
					alternative_limit = {
						is_landed = yes
					}
					add_courtier = scope:recipient
				}
			}
			else = {
				move_to_pool = yes
			}
		}
	}
}

divorce_character_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no

	desc = divorce_character_interaction_desc

	is_shown = {
		scope:actor.faith = {
			# We are not required to seek approval of a spiritual HoF
			NAND = {
				has_doctrine = doctrine_divorce_approval
				has_doctrine = doctrine_spiritual_head
				exists = religious_head
			}
			# We are not required to seek approval of a house head
			NAND = {
				has_doctrine = doctrine_divorce_approval
				exists = scope:actor.house
				exists = scope:actor.house.house_head
				scope:actor = { is_house_head = no }
			}
		}
		scope:recipient = {
			is_spouse_of = scope:actor
			is_concubine = no # Can set aside Concubines at any time
		}
	}

	is_valid_showing_failures_only = {
		NOT = {
			scope:actor.faith = {
				has_doctrine = doctrine_divorce_disallowed
			}
		}
		scope:recipient = { is_diplomatically_available = yes }
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		scope:actor = {
			piety >= divorce_cost
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			divorce_effect = {
				DIVORCER = scope:actor
				DIVORCEE = scope:recipient
			}
			add_piety = { subtract = divorce_cost }
		}
		scope:recipient = {
			trigger_event = marriage_interaction.0030
		}
	}
	
	# AI
	ai_targets = {
		ai_recipients = spouses
	}
	ai_frequency = 36
	
	ai_potential = {
		is_ruler = yes
	}

	ai_will_do = {
		base = 0

		modifier = { # The AI wants to divorce should they not have an heir that is their own child, and their spouse is infertile
			add = 100
			scope:actor = {
				fertility > 0.1
				NOT = {
					any_child = {
						is_heir_of = scope:actor
					}
				}
			}
			scope:recipient = {
				is_ai = yes
				fertility < 0.1
			}
		}
	}
}

divorce_character_house_head_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no

	redirect = {
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
		if = {
			limit = {
				exists = scope:actor.house.house_head
			}
			scope:actor.house.house_head = {
				save_scope_as = recipient
			}
		}
	}

	greeting = positive
	notification_text = ASK_FOR_DIVORCE_NOTIFICATION

	is_shown = {
		exists = scope:actor.house.house_head
		NOT = { scope:actor = scope:actor.house.house_head } # no need to ask yourself
		scope:actor.faith = {
			has_doctrine = doctrine_divorce_approval
		}
		NAND = {
			exists = scope:actor.faith.religious_head
			scope:actor.faith = {
				has_doctrine = doctrine_spiritual_head
			}
		}
		scope:secondary_recipient = {
			is_spouse_of = scope:actor
			is_concubine = no # Can set aside Concubines at any time
		}
	}

	is_valid_showing_failures_only = {
		# Denounced trait?
		scope:recipient = { is_diplomatically_available = yes }
		scope:secondary_recipient = { is_diplomatically_available = yes }
		NOT = {
			scope:secondary_recipient = { has_strong_hook = scope:actor }
		}
		scope:actor = {
			piety >= divorce_cost
		}
	}
	
	ai_accept = {
		base = 0 # Should be 0 for all interactions
		
		divorce_character_ai_accept_modifier = yes
		
		modifier = { # Infertility
			add = 20
			desc = DIVORCE_INFERTILE
			scope:actor = {
				fertility > 0.1
			}
			scope:secondary_recipient = {
				fertility < 0.1
				NOR = {
					any_child = {
						is_child_of = scope:actor
					}
					has_trait = eunuch
				}
			}
		}
		
		modifier = { # Negative for having given you children
			add = -50
			desc = DIVORCE_GIVEN_CHILDREN
			scope:secondary_recipient = {
				any_child = {
					count >= 3
					is_child_of = scope:actor
					dynasty = scope:actor.dynasty
				}
			}
		}
		
		modifier = { # They are of the same dynasty as the House Head
			trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
			add = -10
			desc = THEY_ARE_MY_DYNASTY_MEMBER
			scope:recipient = {
				is_lowborn = no
				NOR = {
					is_cousin_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
				}
				dynasty = scope:secondary_recipient.dynasty
				NOR = {
					house = scope:secondary_recipient.house
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor	
					scope:recipient.dynasty = scope:actor.dynasty
				}
			}
		}
		
		modifier = { # They are of the same house as the House Head
			trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
			add = -20
			desc = THEY_ARE_MY_HOUSE_MEMBER
			scope:recipient = {
				is_lowborn = no
				NOR = {
					is_cousin_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
				}
				house = scope:secondary_recipient.house
				NOR = {
					house = scope:actor.house
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor	
					scope:recipient.house = scope:actor.house
				}
			}
		}
		
		modifier = { # They are close kin to the House Head
			trigger = { NOT = { scope:recipient = scope:secondary_recipient } }
			add = -35
			desc = THEY_ARE_MY_CLOSE_KIN
			scope:recipient = {
				OR = {
					is_cousin_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
				}
			}
		}
		
		modifier = {
			add = 50
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 100
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = 10
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 20
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:divorce_hook = yes
		}
	}
	
	send_option = {
		is_shown = {
			NOT = { scope:actor = scope:recipient }
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = divorce_hook
		localization = GENERIC_SPEND_A_HOOK
	}	
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	
	send_options_exclusive = no
	
	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		if = {
			limit = { always = scope:divorce_hook }
			scope:actor = {
				use_hook = scope:recipient
			}
		}
		if = {
			limit = {
				scope:actor = scope:actor.house.house_head
			}
			scope:actor = {
				divorce_effect = {
					DIVORCER = scope:actor
					DIVORCEE = scope:secondary_recipient
				}
			}
		}
		else = {
			show_as_tooltip = {
				scope:actor = {
					divorce_effect = {
						DIVORCER = scope:actor
						DIVORCEE = scope:secondary_recipient
					}
				}
			}
			scope:actor = {
				trigger_event = religious_interaction.2
			}
		}
		scope:actor = {
			add_piety = { subtract = divorce_cost }
		}
	}

	on_decline = {
		send_interface_toast = {
			title = divorce_character_rel_head_interaction_decline_notification

			right_icon = scope:actor.house.house_head
		}
	}
	
	# AI
	ai_targets = {
		ai_recipients = spouses
	}
	ai_frequency = 36
	
	ai_potential = {
		is_ruler = yes
	}

	ai_will_do = {
		base = 0

		modifier = { # The AI wants to divorce should they not have an heir that is their own child, and their spouse is infertile
			add = 100
			scope:actor = {
				fertility > 0.1
				NOT = {
					any_child = {
						is_heir_of = scope:actor
					}
				}
			}
			scope:secondary_recipient = {
				is_ai = yes
				fertility < 0.1
			}
		}
		
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:divorce_hook = yes
			add = -1
		}
	}
}

divorce_character_rel_head_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no

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

		if = {
			limit = {
				exists = scope:actor.faith.religious_head
			}
			scope:actor.faith.religious_head = {
				save_scope_as = recipient
			}
		}
	}

	greeting = positive
	notification_text = ASK_FOR_DIVORCE_NOTIFICATION

	is_shown = {
		exists = scope:actor.faith.religious_head
		scope:actor.faith = {
			has_doctrine = doctrine_spiritual_head
			has_doctrine = doctrine_divorce_approval
		}
		scope:secondary_recipient = {
			is_spouse_of = scope:actor
			is_concubine = no # Can set aside Concubines at any time
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { has_trait = excommunicated }
		}
		scope:recipient = { is_diplomatically_available = yes }
		scope:secondary_recipient = { is_diplomatically_available = yes }
		NOT = {
			scope:secondary_recipient = { has_strong_hook = scope:actor }
		}
		scope:actor = {
			piety >= divorce_cost
		}
	}

	ai_accept = {
		base = 0 # Should be 0 for all interactions
		
		divorce_character_ai_accept_modifier = yes

		modifier = { # Divine Family is part of the faith
			add = -100
			desc = DIVORCE_INCESTUOUS

			scope:actor = { 
				is_close_or_extended_family_of = scope:secondary_recipient
				faith = { has_doctrine = tenet_divine_marriage }
			}
		}
		
		modifier = { # More likely if the marriage is incestuous, unless Divine Family is part of the faith
			add = 100
			desc = DIVORCE_INCESTUOUS

			scope:actor = {
				relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = scope:secondary_recipient	}
			}
		}		
		
		modifier = { # They are of the same dynasty as the Head of Faith
			add = -5
			desc = THEY_ARE_MY_DYNASTY_MEMBER
			scope:recipient = {
				is_lowborn = no
				dynasty = scope:secondary_recipient.dynasty
				NOR = {
					house = scope:secondary_recipient.house
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor	
					scope:recipient.dynasty = scope:actor.dynasty
				}
			}
		}
		
		modifier = { # You are of the same dynasty as the Head of Faith
			add = 5
			desc = YOU_ARE_MY_DYNASTY_MEMBER
			scope:recipient = {
				is_lowborn = no
				dynasty = scope:actor.dynasty
				NOR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor
					scope:recipient.dynasty = scope:secondary_recipient.dynasty
				}
			}
		}
		
		modifier = { # They are of the same house as the Head of Faith
			add = -10
			desc = THEY_ARE_MY_HOUSE_MEMBER
			scope:recipient = {
				is_lowborn = no
				house = scope:secondary_recipient.house
				NOR = {
					house = scope:actor.house
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor	
					scope:recipient.house = scope:actor.house
				}
			}
		}
		
		modifier = { # You are of the same house as the Head of Faith
			add = 10
			desc = YOU_ARE_MY_HOUSE_MEMBER
			scope:recipient = {
				is_lowborn = no
				house = scope:actor.house
				NOR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor
					scope:recipient.house = scope:secondary_recipient.house
				}
			}
		}
		
		modifier = { # Related to the Head of Faith
			add = 25
			desc = YOU_ARE_MY_RELATIVE
			scope:recipient = {
				OR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
				}
				NOT = { is_child_of = scope:actor }
			}
		}
		
		modifier = { # Parent of the Head of Faith
			add = 50
			desc = PARENTS #YOU_ARE_MY_PARENT
			scope:recipient = {
				is_child_of = scope:actor
			}
		}
		
		modifier = {
			add = {
				add = 10
				multiply = scope:actor.num_virtuous_traits
			}
			scope:actor.num_virtuous_traits > 0
			desc = I_AM_VIRTUOUS
		}
		
		modifier = {
			add = {
				add = -10
				multiply = scope:secondary_recipient.num_virtuous_traits
			}
			scope:secondary_recipient.num_virtuous_traits > 0
			desc = THEY_ARE_VIRTUOUS
		}
		
		modifier = {
			add = {
				add = -10
				multiply = scope:actor.num_sinful_traits
			}
			scope:actor.num_sinful_traits > 0
			desc = I_AM_SINFUL
		}
		
		modifier = {
			add = {
				add = 10
				multiply = scope:secondary_recipient.num_sinful_traits
			}
			scope:secondary_recipient.num_sinful_traits > 0
			desc = THEY_ARE_SINFUL
		}
	}
	
	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:divorce_hook = yes
		}
	}
	
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = divorce_hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	
	send_options_exclusive = no
	
	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		if = {
			limit = { always = scope:divorce_hook }
			scope:actor = {
				use_hook = scope:recipient
			}
		}
		show_as_tooltip = {
			scope:actor = {
				divorce_effect = {
					DIVORCER = scope:actor
					DIVORCEE = scope:secondary_recipient
				}
			}
		}
		scope:actor = {
			trigger_event = religious_interaction.1
			add_piety = { subtract = divorce_cost }
		}
	}

	on_decline = {
		send_interface_toast = {
			title = divorce_character_rel_head_interaction_decline_notification

			right_icon = scope:actor.faith.religious_head
		}
	}
	
	# AI
	ai_targets = {
		ai_recipients = spouses
	}
	ai_frequency = 36
	
	ai_potential = {
		is_ruler = yes
	}

	ai_will_do = {
		base = 0

		modifier = { # The AI wants to divorce should they not have an heir that is their own child, and their spouse is infertile
			add = 100
			scope:actor = {
				fertility > 0.1
				NOT = {
					any_child = {
						is_heir_of = scope:actor
					}
				}
			}
			scope:secondary_recipient = {
				is_ai = yes
				fertility < 0.1
			}
		}
		
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:divorce_hook = yes
			add = -1
		}
	}	
}


elope_interaction = {
	category = interaction_category_friendly

	scheme = elope

	desc = elope_interaction_desc

	notification_text = elope_interaction_notification
	
	ai_targets = {
		ai_recipients = realm_characters
		chance = 0.25
	}
	
	ai_target_quick_trigger = {
		adult = yes
		attracted_to_owner = yes
		owner_attracted = yes
	}
	ai_frequency = 72

	redirect = {
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
	}
	
	is_shown = {
		scope:actor = {
			OR = {
				has_relation_lover = scope:recipient
				has_relation_soulmate = scope:recipient
			}
		}
		scope:recipient = {
			is_courtier = yes
			NOR = {
				is_courtier_of = scope:actor
				is_consort_of = scope:actor
			}
			could_marry_character_trigger = { CHARACTER = scope:actor }
		}
	}
	

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes }
		scope:actor = {
			can_start_scheme = {
				type = elope
				target = scope:recipient
			}
		}
	}

	
	ai_accept = {
		base = 0

		elopment_ai_accept_modifier = yes
	}
	
	ai_potential = {
		is_adult = yes
		OR = {
			num_of_relation_lover > 0
			num_of_relation_soulmate > 0
		}
		NOR = {
			has_trait = celibate
			any_scheme = {
				OR = {
					scheme_type = befriend
					scheme_type = sway
					scheme_type = seduce
					scheme_type = courting
					scheme_type = elope
				}
			}
		}
	}
	
	ai_min_reply_days = 1
	ai_max_reply_days = 3
	
	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 = {
					title = elope_interaction_notification

					left_icon = scope:actor					
					right_icon = scope:recipient

					start_scheme = {
						type = elope
						target = scope:recipient
					}

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

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				title = elope_interaction_decline_toast
				left_icon = scope:recipient
			}
		}
	}
	
	ai_will_do = {
		base = 100
	}
}
