﻿
# Stripped down version of make_concubine_interaction for the AI
# Avoids redirection logic and recipient list building to improve performance
ai_make_concubine_interaction = {
	hidden = yes
	
	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

	ai_potential = {
		is_playable_character = yes
		is_adult = yes
		fertility > 0
		allowed_more_concubines = yes
		NOR = {
			has_trait = chaste
			has_trait = celibate
			has_sexuality = asexual
		}
	}

	is_shown = {
		make_concubine_is_shown_trigger = yes
	}

	is_valid_showing_failures_only = {
		make_concubine_is_valid_trigger = yes
	}

	auto_accept = yes

	ai_will_do = {
		base = 0

		#### MOD BEGIN ####
		modifier = { # Soulmate Filtering
			add = 200
			scope:actor = {
				is_married = yes
				has_relation_soulmate = scope:recipient
			}
		}

		modifier = { # Lover Filtering
			add = 100
			scope:actor = { has_relation_lover = scope:recipient }
		}
		#### MOD END ####
		modifier = { # Basic Filtering
			add = 100
			scope:actor = {
				number_of_concubines < number_of_desired_concubines
			}
			scope:recipient = {
				can_have_children_with = { CHARACTER = scope:actor } # Only if you can have kids since this is about fertility and genetic traits
				fertility > 0.2
				is_young_character = yes
			}
		}
		
		modifier = {
			add = 100
			scope:recipient = {
				is_imprisoned_by = scope:actor
				can_have_children_with = { CHARACTER = scope:actor } # Only if you can have kids since this is about fertility and genetic traits
				OR = {
					is_lowborn = no
					num_of_good_genetic_traits > 0
				}
				fertility > 0.1
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		modifier = {
			add = 100
			scope:actor = {
				allowed_to_marry_same_sex_trigger = yes
				sex_same_as = scope:recipient
				is_attracted_to_gender_of = scope:recipient
				OR = { #If they're not in need of kids, or someone who they can have kids with
					any_child = {
						count >= 2
					}
					any_consort = {
						can_have_children_with = { CHARACTER = scope:actor }
						fertility > 0.1
					}
				}
			}
		}

		modifier = { #Even if you're allowed to take same-sex concubines we don't want the AI to do so without a good reason if they're not attracted to the person
			add = -200
			scope:actor = {
				allowed_to_marry_same_sex_trigger = yes
				sex_same_as = scope:recipient
				NOT = { is_attracted_to_gender_of = scope:recipient }
			}
		}

		modifier = { # If they don't have a batch of kids and opposite sex consorts to handle that situation
			add = -200
			scope:actor = {
				allowed_to_marry_same_sex_trigger = yes
				sex_same_as = scope:recipient
				NOT = {
					any_child = {
						count >= 2
					}
				}
				NOT = {
					any_consort = {
						can_have_children_with = { CHARACTER = scope:actor }
						fertility > 0.1
					}
				}
			}
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}

		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 = {
						exists = primary_heir
						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 = {
		scope:actor = {
			save_scope_as = secondary_actor
		}
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
		concubine_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 = minor_unity_gain
			DESC = clan_unity_concubinage.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}
}

offer_truce_concubine = {
	interface_priority = 1
	category = interaction_category_diplomacy
	icon = concubine_icon

	ai_maybe = yes
	popup_on_receive = yes

	desc = offer_truce_concubine_desc

	ai_targets = {
		ai_recipients = neighboring_rulers
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 144

	cooldown = { years = 3 }
	cooldown_against_recipient = { years = 5 }

	greeting = positive
	notification_text = OFFER_TRUCE_CONCUBINE_NOTIFICATION

	#interface = concubine_list

	needs_recipient_to_open = yes

	populate_actor_list = {
		scope:actor = {
			every_courtier = {
				limit = {
					can_be_offered_as_concubine_to_character_trigger = {
						GIVER = scope:actor
						CHARACTER = scope:recipient
					}
					trigger_if = {
						limit = { is_female = yes }
						is_visibly_fertile = yes
					}
				}
				add_to_list = characters
			}
			every_prisoner = {
				limit = {
					NOT = { is_in_list = characters }
					can_be_offered_as_concubine_to_character_trigger = {
						GIVER = scope:actor
						CHARACTER = scope:recipient
					}
					trigger_if = {
						limit = { is_female = yes }
						is_visibly_fertile = yes
					}
				}
				add_to_list = characters
			}
		}
	}

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor = {
			OR = {
				culture = { has_cultural_tradition = tradition_concubines }
				faith = { has_doctrine = doctrine_concubines }
			}
			OR = {
				is_independent_ruler = yes
				top_liege = scope:recipient.top_liege
			}
		}
		scope:recipient = {
			can_attack_in_hierarchy = scope:actor
			allowed_concubines = yes
			is_adult = yes
			is_landed = yes
			OR = {
				is_independent_ruler = yes
				top_liege = scope:actor.top_liege
			}
			NOR = {
				any_liege_or_above = { this = scope:actor }
				any_vassal_or_below = { this = scope:actor }
			}
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = take_concubine_available_character_opp
			object = scope:recipient
			scope:actor = {
				OR = {
					any_courtier = {
						can_be_offered_as_concubine_to_character_trigger = {
							GIVER = scope:actor
							CHARACTER = scope:recipient
						}
					}
					any_prisoner = {
						can_be_offered_as_concubine_to_character_trigger = {
							GIVER = scope:actor
							CHARACTER = scope:recipient
						}
					}
				}
			}
		}
		custom_description = {
			text = take_concubine_allowed_more
			object = scope:recipient
			scope:recipient = {
				allowed_more_concubines = yes
			}
		}
		# Make sure that scope:actor is going into this with a clean, no-recent/active/forbidden hostilities mindset.
		scope:actor = {
			NOR = {
				# Involved characters can't be on opposite sides in an active war.
				is_at_war_with = scope:recipient
				# Allied characters aren't allowed to do this because it _should_ be redundant. Unless you're planning something. Which you shouldn't announce like that.
				is_allied_to = scope:recipient
				# And we should just disallow anyone who already has a truce with you, even though I guess you might technically want to replace it.
				any_truce_holder = { this = scope:recipient }
			}
		}
	}

	can_be_picked = {
		is_adult = yes
	}

	can_send = {
		custom_description = {
			text = character_unavailable_to_be_offered_as_concubine
			object = scope:secondary_actor
			scope:secondary_actor = {
				can_be_offered_as_concubine_to_character_trigger = {
					GIVER = scope:actor
					CHARACTER = scope:recipient
				}
			}
		}
	}

	auto_accept = no

	ai_accept = {
		base = 0

		modifier = {
			add = {
				value = 50
			}
			scope:secondary_actor = {
				is_close_family_of = scope:actor
			}
		}

		modifier = {
			add = {
				value = 30
			}
			scope:secondary_actor = {
				house = scope:actor.house
				NOT = { is_close_family_of = scope:actor }
			}
		}
	
		modifier = {
			add = {
				value = 20
			}
			scope:secondary_actor = {
				dynasty = scope:actor.dynasty
				NOR = {
					is_close_family_of = scope:actor
					house = scope:actor.house
				}
			}
		}
	
		modifier = {
			add = {
				value = 50
				multiply = scope:secondary_actor.num_of_good_genetic_traits
				multiply = 0.5
			}
			scope:secondary_actor = {
				num_of_good_genetic_traits > 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_POSITIVE_TRAIT_REASON
		}

		modifier = {
			add = {
				value = 50
				multiply = 0.5
			}
			scope:secondary_actor = {
				is_lowborn = no
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON_NOBLE
		}

		modifier = {
			add = {
				value = -50
				multiply = scope:secondary_actor.num_of_bad_genetic_traits
				multiply = 0.5
			}
			scope:secondary_actor = {
				OR = {
					num_of_bad_genetic_traits > 0
				}
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_NEGATIVE_TRAIT_REASON
		}

		modifier = {
			add = {
				value = -50
				multiply = 0.5
			}
			scope:secondary_actor = {
				is_lowborn = yes
				num_of_good_genetic_traits = 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON_LOWBORN_NO_POSITIVE_TRAIT
		}
		
		opinion_modifier = { # Opinion of you
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.6
			desc = AI_OPINION_REASON
		}

		opinion_modifier = { # Opinion of concubine
			who = scope:recipient
			opinion_target = scope:secondary_actor
			multiplier = 0.125
			desc = AI_OPINION_REASON
		}

		compare_modifier = { # Recipient is reluctant to marry old women (procreation is a key factor)
			trigger = {
				scope:secondary_actor = {
					is_young_character = no
					is_female = yes
				}
			}
			target = scope:secondary_actor
			value = age
			multiplier = -5.0
			step = 1
			offset = -29
			desc = MARRY_AGE
		}

		modifier = { # A Recipient is unwilling to take a same-sex concubine if their faith doesn't support it
			add = -1000
			
			scope:recipient = {
				allowed_to_marry_same_sex_trigger = no
				sex_same_as = scope:secondary_actor
			}
			desc = SAME_SEX_MARRIAGE_FAITH_REASON_RECIPIENT
		}

		modifier = { # Unwilling if they don't have a batch of kids and opposite sex consorts to handle that situation
			add = {
				value = -200
				multiply = 0.5
			}
			scope:recipient = {
				allowed_to_marry_same_sex_trigger = yes
				sex_same_as = scope:secondary_actor
				trigger_if = {
					limit = {
						NOT = {
							any_consort = {
								can_have_children_with = { CHARACTER = scope:recipient }
								fertility > 0.1
							}
						}
					}
					any_child = {
						is_player_heir_of = root
					}
				}
				trigger_else = {
					always = no
				}
			}
			desc = AI_NO_FERTILITY_REASON
		}

		modifier = {
			add = {
				value = 50
				multiply = 0.5
			}
			scope:recipient = {
				is_attracted_to_gender_of = scope:secondary_actor
			}
			desc = AI_ATTRACTION_REASON
		}

		modifier = { # A Recipient is more likely to agree if you're their liege
			add = {
				value = 40
				multiply = 0.5
			}
			
			scope:recipient = {
				target_is_liege_or_above = scope:actor
			}
			desc = LIEGE_REASON
		}

		#More/Less likely based on difference in rank between actor and recipient
		modifier = {
			add = {
				value = 20
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = 30
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = 40
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = 50
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = 60
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 5
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -20
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -30
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -40
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -50
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -60
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -5
				}
			}
			desc = AI_RANK_DIFF
		}
		
		modifier = {
			add = {
				value = intimidated_reason_value
				multiply = 0.5
			}
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = {
				value = cowed_reason_value
				multiply = 0.5
			}
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = {
				value = intimidated_external_reason_value
				multiply = 0.5
			}
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = {
				value = cowed_external_reason_value
				multiply = 0.5
			}
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		modifier = {
			add = -250
			scope:secondary_actor = {
				has_std_trigger = yes
			}
			desc = AI_STD_REASON
		}
		modifier = {
			add = -250
			scope:secondary_actor = {
				has_epidemic_disease_trigger = yes
			}
			desc = AI_CONTAGIOUS_REASON
		}
		modifier = {
			add = -5000
			scope:secondary_actor = {
				fertility <= 0
			}
			desc = AI_FERTILITY_REASON
		}
		modifier = {
			scope:hook = yes
			add = {
				value = 500
				multiply = 0.5
			}
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:hook = yes
			add = {
				value = 1000
				multiply = 0.5
			}
			scope:actor = { has_strong_hook = scope:recipient }
			desc = SCHEME_STRONG_HOOK_USED
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		
		# Struggle
		modifier = {
			trigger_if = {
				limit = {
					scope:recipient = {
						any_character_struggle = {
							involvement = involved
						}
					}
					scope:actor = {
						any_character_struggle = {
							involvement = involved
						}
					}
				}
			}
			trigger_else = {
				always = no
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -50
				}
				else_if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
						}
					}
					add = 100
				}
			}
			desc = AI_STRUGGLE_INTENT
		}

		# Greedy AI
		modifier = {
			add = {
				value = ai_greed
				multiply = 0.5
			}
			ai_greed >= 1
			desc = AI_VALUE_MODIFIER_GREED
		}
		# Boldness always plays a factor.
		modifier = {
			add = {
				value = ai_boldness
				multiply = -0.5
			}
			NOT = { ai_boldness = 0 }
			desc = AI_VALUE_MODIFIER_BOLDNESS
		}
		# Ambitious AI like freedom.
		modifier = {
			add = -50
			has_trait = ambitious
			desc = PT_AI_LIKES_FREEDOM_TO_WAR_REASON
		}
		# AI who are in debt will take whatever windfalls they can.
		modifier = {
			add = {
				value = debt_level
				# Our first rank is 0, so we add one to always get a positive number.
				add = 1
				multiply = 10
			}
			debt_level >= 0
			desc = PT_AI_IS_IN_DEBT
		}
		# Pacifist AI are happy to avoid war.
		modifier = {
			add = 25
			faith = { has_doctrine_parameter = pacifist_opinion_active }
			desc = PT_AI_IS_PACIFIST_FAITH
		}
		modifier = {
			add = 25
			culture = { has_cultural_parameter = reduced_cost_for_conversion_to_pacifist_faith }
			desc = PT_AI_IS_PACIFIST_CULTURE
		}
		# War likeliness.
		## This is primarily intended to mitigate conquest, invasion, and religious CBs, so we don't account for them.
		## Scope:recipient has some claim to scope:actor's lands.
		modifier = {
			add = -20
			any_claim = {
				count = 1
				exists = holder
				holder = scope:actor
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## Scope:recipient has decent claim to scope:actor's lands.
		modifier = {
			add = -40
			OR = {
				any_claim = {
					count >= 2
					exists = holder
					holder = scope:actor
				}
				any_claim = {
					count = 1
					exists = holder
					holder = scope:actor
					save_temporary_scope_as = claim_temp
					scope:recipient = { has_strong_claim_on = scope:claim_temp }
				}
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## Scope:recipient has strong claim to scope:actor's lands.
		modifier = {
			add = -60
			any_claim = {
				count >= 2
				exists = holder
				holder = scope:actor
				save_temporary_scope_as = claim_temp
				scope:recipient = { has_strong_claim_on = scope:claim_temp }
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## Scope:recipient can de jure grab your land.
		### Dukes don't take much.
		modifier = {
			add = -30
			highest_held_title_tier = tier_duchy
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:actor = {
				any_sub_realm_county = {
					count >= 3
					any_this_title_or_de_jure_above = { holder = scope:actor }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		### Kings need a lot more.
		modifier = {
			add = -30
			highest_held_title_tier = tier_kingdom
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:actor = {
				any_sub_realm_county = {
					count >= 10
					any_this_title_or_de_jure_above = { holder = scope:actor }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		### Emperors take quite a bit to get fussed.
		modifier = {
			add = -30
			highest_held_title_tier = tier_empire
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:actor = {
				any_sub_realm_county = {
					count >= 20
					any_this_title_or_de_jure_above = { holder = scope:actor }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		# Relative power.
		## Scope:actor has far fewer levies than scope:recipient.
		modifier = {
			add = -30
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_far_weaker_value
			desc = PT_AI_RECIPIENT_IS_MUCH_STRONGER
		}
		## Scope:actor has fewer levies than scope:recipient.
		modifier = {
			add = -10
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_far_weaker_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_somewhat_weaker_value
			desc = PT_AI_RECIPIENT_IS_SOMEWHAT_STRONGER
		}
		## Scope:actor has roughly equal levies with scope:recipient.
		modifier = {
			add = 10
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_somewhat_weaker_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_somewhat_stronger_value
			desc = PT_AI_RECIPIENT_IS_ROUGHLY_EQUAL
		}
		## Scope:actor has more levies than scope:recipient.
		modifier = {
			add = 25
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_somewhat_stronger_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_far_stronger_value
			desc = PT_AI_RECIPIENT_IS_SOMEWHAT_WEAKER
		}
		## Scope:actor has far more levies than scope:recipient.
		modifier = {
			add = 50
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_far_stronger_value
			desc = PT_AI_RECIPIENT_IS_MUCH_WEAKER
		}

		# Struggle
		modifier = {
			desc = AI_STRUGGLE_INTENT
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -50
				}
				else_if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
						}
					}
					add = 100
				}
			}
		}
	}

	ai_potential = {
		is_adult = yes
		NOT = { has_trait = incapable }
		is_at_war = no
		NOR = {
			has_trait = greedy
			ai_greed > very_high_positive_ai_value
		}
		OR = {
			culture = { has_cultural_tradition = tradition_concubines }
			faith = { has_doctrine = doctrine_concubines }
		}
	}

	ai_will_do = {
		base = 0
		
		modifier = { # Basic Filtering
			add = 50
			scope:recipient = {
				number_of_concubines < number_of_desired_concubines
			}
			scope:secondary_actor = {
				trigger_if = {
					limit = {
						allowed_to_marry_same_sex_trigger = no
					}
					sex_opposite_of = scope:recipient
				}
				fertility > 0.2
				is_young_character = yes
				NOR = {
					is_councillor_of = scope:actor
					is_of_major_interest_trigger = {
						CHARACTER = scope:actor
					}
					is_concubine_of = scope:actor
				}
			}
		}

		modifier = { # If secondary_actor is close to actor, a good character, or if actor should take them as concubine
			add = -100
			scope:secondary_actor = {
				is_of_minor_interest_trigger = {
					CHARACTER = scope:actor
				}
				AND = {
					can_become_concubine_of_character_trigger = { CHARACTER = scope:actor }
					scope:actor = { number_of_concubines < number_of_desired_concubines }
				}
			}
		}

		modifier = { # If secondary_actor could be an agent...
			add = 25
			scope:actor = {
				any_scheme = {
					scheme_target_character = scope:recipient
					save_temporary_scope_as = scheme_check
				}
			}
			scope:secondary_actor = {
				char_can_fit_into_scheme_trigger = { SCHEME = scope:scheme_check }
			}
		}
		
		modifier = { # More likely if it's a neighboring ruler that you want to like you
			add = 50
			scope:recipient = {
				any_neighboring_top_liege_realm_owner = { this = scope:actor }
				max_military_strength > scope:actor.max_military_strength
			}
		}
		
		modifier = { # More likely if its your friend and it's a nice concubine
			add = 50
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
				}
			}
			scope:secondary_actor = {
				fertility > 0.2
				is_young_character = yes
				OR = {
					has_trait = lustful
					num_of_good_genetic_traits > 0
				}
			}
		}

		modifier = { #Even if they're allowed to take same-sex concubines we don't want the AI to suggest it without a good reason if they're not attracted to the person
			add = -200
			scope:recipient = {
				allowed_to_marry_same_sex_trigger = yes
				sex_same_as = scope:secondary_actor
				NOT = { is_attracted_to_gender_of = scope:secondary_actor }
			}
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}

		modifier = { # No if it's a same-sex concubinage and actor isn't accepting of it
			factor = 0
			scope:actor = {
				allowed_to_marry_same_sex_trigger = no
				scope:recipient = { sex_same_as = scope:secondary_actor }
			}
		}

		modifier = { # No if it's a same-sex concubinage and recipient isn't accepting of it
			factor = 0
			scope:recipient = {
				allowed_to_marry_same_sex_trigger = no
				sex_same_as = scope:secondary_actor
			}
		}

		modifier = { # Incest Filtering: Hard NO!
			factor = 0
			scope:recipient = {
				relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = scope:secondary_actor }
				NOR = {
					accepts_incest_with_trigger = { CHARACTER = scope:secondary_actor }
					sexually_liberal_trigger = yes
				}
			}
		}

		modifier = { # Incest Filtering: Not likely, but keep the door open...
			factor = 0.2 
			scope:recipient = {
				relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = scope:secondary_actor }
				OR = {
					accepts_incest_with_trigger = { CHARACTER = scope:secondary_actor }
					sexually_liberal_trigger = yes
				}
			}
		}

		modifier = { # Faith considerations
			factor = 0
			scope:recipient = {
				faith = {
					faith_hostility_level = {
						target = scope:actor.faith
						value >= faith_hostile_level
					}
				}
				NOR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
				}
			}
		}
		
		# Some personalities & traits just don't want to fight.
		## Cravens (who aren't also ambitious).
		modifier = {
			add = 25
			has_trait = craven
			NOT = { has_trait = ambitious }
		}
		## Those with chronically low boldness (who aren't also ambitious).
		modifier = {
			add = 25
			ai_boldness <= very_high_negative_ai_value
			NOT = { has_trait = ambitious }
		}
		## Pacifists.
		modifier = {
			add = 25
			faith = { has_doctrine_parameter = pacifist_opinion_active }
		}
		modifier = {
			add = 25
			culture = { has_cultural_parameter = reduced_cost_for_conversion_to_pacifist_faith }
		}
		## Wrathful or ambitious characters don't like to bother.
		modifier = {
			add = -25
			has_trait = ambitious
		}
		modifier  = {
			add = -25
			has_trait = wrathful
		}
		## Arbitrary characters don't get truces to begin with.
		modifier = {
			add = -50
			has_trait = arbitrary
		}
		## We deliberately avoid warlike faiths *not* doing it; there's plenty of examples of such bought truces amongst these faiths, so we let them keep at it if they match other criteria.
		# Force checks.
		## Try to buy truces from somewhat stronger realms...
		modifier = {
			add = 50
			scope:recipient.max_military_strength >= scope:actor.purchase_truce_interaction_recipient_somewhat_stronger_value
		}
		## ... and much stronger realms.
		modifier = {
			add = 50
			scope:recipient.max_military_strength >= scope:actor.purchase_truce_interaction_recipient_far_stronger_value
		}

		# Struggle
		modifier = {
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -50
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
						}
					}
					add = 100
				}
			}
		}
		# Finally, calculate factors.
		## Only buy truces from weaker/roughly-equal realms if you're craven have been at war forever.
		modifier = {
			factor = 0
			max_military_strength <= scope:actor.purchase_truce_interaction_recipient_somewhat_weaker_value
			NOR = {
				has_trait = craven
				days_of_continuous_war <= 3650
			}
		}
		## Never buy a truce from someone who actually can't declare war on you.
		modifier = {
			factor = 0
			scope:recipient = {
				NOT = { has_any_cb_on = scope:actor }
			}
		}
		## Don't buy truces from people who are likely going to be dead soon, or if you yourself will die soon, since they'll be wasted.
		modifier = {
			factor = 0
			OR = {
				health <= poor_health
				scope:recipient = { health <= poor_health }
			}
		}
	}

	on_send = {
		scope:secondary_actor = { # to block the same character from being offered twice
			add_character_flag = {
				flag = has_been_offered_as_concubine
				days = 5
			}
		}
	}
	
	on_accept = {
		concubine_truce_on_accept_effect = { ACTOR = scope:actor RECIPIENT = scope:recipient CONCUBINE = scope:secondary_actor }

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_concubinage_offer.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = msg_concubine_offer_rejected_title
				right_icon = scope:recipient
				left_icon = scope:secondary_actor
				custom_tooltip = msg_concubine_offer_rejected
			}
		}

		# 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_concubinage_offer_decline.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	send_options_exclusive = no
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
}

request_truce_concubine = {
	interface_priority = 2
	category = interaction_category_diplomacy
	icon = concubine_icon

	ai_maybe = yes
	popup_on_receive = yes

	desc = request_truce_concubine_desc

	ai_targets = {
		ai_recipients = neighboring_rulers
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 144

	cooldown = { years = 3 }
	cooldown_against_recipient = { years = 5 }

	greeting = positive
	notification_text = REQUEST_TRUCE_CONCUBINE_NOTIFICATION

	#interface = concubine_list

	needs_recipient_to_open = yes

	populate_recipient_list = {
		scope:recipient = {
			every_courtier = {
				limit = {
					can_be_offered_as_concubine_to_character_trigger = {
						GIVER = scope:recipient
						CHARACTER = scope:actor
					}
					trigger_if = {
						limit = { is_female = yes }
						is_visibly_fertile = yes
					}
				}
				add_to_list = characters
			}
			every_prisoner = {
				limit = {
					NOT = { is_in_list = characters }
					can_be_offered_as_concubine_to_character_trigger = {
						GIVER = scope:recipient
						CHARACTER = scope:actor
					}
					trigger_if = {
						limit = { is_female = yes }
						is_visibly_fertile = yes
					}
				}
				add_to_list = characters
			}
		}
	}

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:recipient = {
			is_ruler = yes
			OR = {
				culture = { has_cultural_tradition = tradition_concubines }
				faith = { has_doctrine = doctrine_concubines }
			}
			OR = {
				is_independent_ruler = yes
				top_liege = scope:actor.top_liege
			}
		}
		scope:actor = {
			can_attack_in_hierarchy = scope:recipient
			allowed_concubines = yes
			is_adult = yes
			is_landed = yes
			OR = {
				is_independent_ruler = yes
				top_liege = scope:recipient.top_liege
			}
			NOR = {
				any_liege_or_above = { this = scope:recipient }
				any_vassal_or_below = { this = scope:recipient }
			}
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = take_concubine_available_character_opp
			object = scope:actor
			scope:recipient = {
				OR = {
					any_courtier = {
						can_be_offered_as_concubine_to_character_trigger = {
							GIVER = scope:recipient
							CHARACTER = scope:actor
						}
					}
					any_prisoner = {
						can_be_offered_as_concubine_to_character_trigger = {
							GIVER = scope:recipient
							CHARACTER = scope:actor
						}
					}
				}
			}
		}
		custom_description = {
			text = take_concubine_allowed_more
			object = scope:actor
			scope:actor = {
				allowed_more_concubines = yes
			}
		}
		# Make sure that scope:recipient is going into this with a clean, no-recent/active/forbidden hostilities mindset.
		scope:recipient = {
			NOR = {
				# Involved characters can't be on opposite sides in an active war.
				is_at_war_with = scope:actor
				# Allied characters aren't allowed to do this because it _should_ be redundant. Unless you're planning something. Which you shouldn't announce like that.
				is_allied_to = scope:actor
				# And we should just disallow anyone who already has a truce with you, even though I guess you might technically want to replace it.
				any_truce_holder = { this = scope:actor }
			}
		}
	}

	can_be_picked = {
		is_adult = yes
	}

	can_send = {
		custom_description = {
			text = character_unavailable_to_be_offered_as_concubine
			object = scope:secondary_recipient
			scope:secondary_recipient = {
				can_be_offered_as_concubine_to_character_trigger = {
					GIVER = scope:recipient
					CHARACTER = scope:actor
				}
			}
		}
	}

	auto_accept = no

	ai_will_do = {
		base = 0

		modifier = {
			add = {
				value = 50
			}
			scope:secondary_recipient = {
				is_close_family_of = scope:recipient
			}
		}

		modifier = {
			add = {
				value = 30
			}
			scope:secondary_recipient = {
				house = scope:recipient.house
				NOT = { is_close_family_of = scope:recipient }
			}
		}
	
		modifier = {
			add = {
				value = 20
			}
			scope:secondary_recipient = {
				dynasty = scope:recipient.dynasty
				NOR = {
					is_close_family_of = scope:recipient
					house = scope:recipient.house
				}
			}
		}

		modifier = { # Soulmate Filtering
			add = 100
			scope:actor = {
				is_married = yes
				has_relation_soulmate = scope:secondary_recipient
			}
		}

		modifier = { # Lover Filtering
			add = 50
			scope:actor = { has_relation_lover = scope:secondary_recipient }
		}

		modifier = { # Basic Filtering
			add = {
				value = 50
				multiply = 0.5
			}
			scope:actor = {
				number_of_concubines < number_of_desired_concubines
			}
			scope:secondary_recipient = {
				trigger_if = {
					limit = {
						allowed_to_marry_same_sex_trigger = no
					}
					sex_opposite_of = scope:actor
				}
				fertility > 0.2
				is_young_character = yes
				NOR = {
					is_councillor_of = scope:recipient
					is_of_major_interest_trigger = {
						CHARACTER = scope:recipient
					}
					is_concubine_of = scope:recipient
				}
			}
		}
	
		modifier = {
			add = {
				value = 50
				multiply = scope:secondary_recipient.num_of_good_genetic_traits
				multiply = 0.5
			}
			scope:secondary_recipient = {
				num_of_good_genetic_traits > 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		modifier = {
			add = {
				value = 50
				multiply = 0.5
			}
			scope:secondary_recipient = {
				is_lowborn = no
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		modifier = {
			add = {
				value = -50
				multiply = scope:secondary_recipient.num_of_bad_genetic_traits
				multiply = 0.5
			}
			scope:secondary_recipient = {
				OR = {
					num_of_bad_genetic_traits > 0
				}
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		modifier = {
			add = {
				value = -50
				multiply = 0.5
			}
			scope:secondary_recipient = {
				is_lowborn = yes
				num_of_good_genetic_traits = 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		opinion_modifier = { # Opinion of recipient
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = 1.0
		}

		opinion_modifier = { # Opinion of concubine
			who = scope:actor
			opinion_target = scope:secondary_recipient
			multiplier = 0.125
		}

		compare_modifier = { # Actor is reluctant to marry old women (procreation is a key factor)
			trigger = {
				scope:secondary_recipient = {
					is_young_character = no
					is_female = yes
				}
			}
			target = scope:secondary_recipient
			value = age
			multiplier = -5.0
			step = 1
			offset = -29
		}

		modifier = { # An actor is unwilling to take a same-sex concubine if their faith doesn't support it
			add = -1000
			
			scope:actor = {
				allowed_to_marry_same_sex_trigger = no
				sex_same_as = scope:secondary_recipient
			}
		}

		modifier = { # Unwilling if they don't have a batch of kids and opposite sex consorts to handle that situation
			add = {
				value = -200
				multiply = 0.5
			}
			scope:actor = {
				allowed_to_marry_same_sex_trigger = yes
				sex_same_as = scope:secondary_recipient
				trigger_if = {
					limit = {
						NOT = {
							any_consort = {
								can_have_children_with = { CHARACTER = scope:actor }
								fertility > 0.1
							}
						}
					}
					any_child = {
						is_player_heir_of = root
					}
				}
				trigger_else = {
					always = no
				}
			}
		}

		modifier = {
			add = {
				value = 50
				multiply = 0.5
			}
			scope:actor = {
				is_attracted_to_gender_of = scope:secondary_recipient
			}
		}

		modifier = { # An actor is more likely to agree if the recipient is their liege
			add = {
				value = 40
				multiply = 0.5
			}
			
			scope:actor = {
				target_is_liege_or_above = scope:recipient
			}
		}

		#More/Less likely based on difference in rank between recipient and actor
		modifier = {
			add = {
				value = 20
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 1
				}
			}
		}
		modifier = {
			add = {
				value = 30
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 2
				}
			}
		}
		modifier = {
			add = {
				value = 40
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 3
				}
			}
		}
		modifier = {
			add = {
				value = 50
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 4
				}
			}
		}
		modifier = {
			add = {
				value = 60
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 5
				}
			}
		}
		modifier = {
			add = {
				value = -20
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -1
				}
			}
		}
		modifier = {
			add = {
				value = -30
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -2
				}
			}
		}
		modifier = {
			add = {
				value = -40
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -3
				}
			}
		}
		modifier = {
			add = {
				value = -50
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -4
				}
			}
		}
		modifier = {
			add = {
				value = -60
				multiply = 0.5
			}
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -5
				}
			}
		}
		
		modifier = {
			add = {
				value = intimidated_reason_value
				multiply = 0.5
			}
			scope:actor = {
				target_is_liege_or_above = scope:recipient
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}
		modifier = {
			add = {
				value = cowed_reason_value
				multiply = 0.5
			}
			scope:actor = {
				target_is_liege_or_above = scope:recipient
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}
		
		modifier = {
			add = {
				value = intimidated_external_reason_value
				multiply = 0.5
			}
			scope:actor = {
				NOT = { target_is_liege_or_above = scope:recipient }
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}
		modifier = {
			add = {
				value = cowed_external_reason_value
				multiply = 0.5
			}
			scope:actor = {
				NOT = { target_is_liege_or_above = scope:recipient }
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}
		modifier = {
			add = -250
			scope:secondary_recipient = {
				has_std_trigger = yes
			}
		}
		modifier = {
			add = -250
			scope:secondary_recipient = {
				has_epidemic_disease_trigger = yes
			}
		}
		modifier = {
			add = -5000
			scope:secondary_recipient = {
				fertility <= 0
			}
		}
		modifier = {
			scope:hook = yes
			add = {
				value = 500
				multiply = 0.5
			}
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
		}
		modifier = {
			scope:hook = yes
			add = {
				value = 100
				multiply = 0.5
			}
			scope:actor = { has_strong_hook = scope:recipient }
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}

		# Struggle
		modifier = {
			trigger_if = {
				limit = {
					scope:actor = {
						any_character_struggle = {
							involvement = involved
						}
					}
					scope:recipient = {
						any_character_struggle = {
							involvement = involved
						}
					}
				}
			}
			trigger_else = {
				always = no
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -50
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
						}
					}
					add = 100
				}
			}
		}

		# Greedy AI
		modifier = {
			add = {
				value = ai_greed
				multiply = 0.5
			}
			ai_greed >= 1
			desc = AI_VALUE_MODIFIER_GREED
		}
		# Boldness always plays a factor.
		modifier = {
			add = {
				value = ai_boldness
				multiply = -0.5
			}
			NOT = { ai_boldness = 0 }
			desc = AI_VALUE_MODIFIER_BOLDNESS
		}
		# Ambitious AI like freedom.
		modifier = {
			add = -50
			has_trait = ambitious
			desc = PT_AI_LIKES_FREEDOM_TO_WAR_REASON
		}
		# AI who are in debt will take whatever windfalls they can.
		modifier = {
			add = {
				value = debt_level
				# Our first rank is 0, so we add one to always get a positive number.
				add = 1
				multiply = 10
			}
			debt_level >= 0
			desc = PT_AI_IS_IN_DEBT
		}
		# Pacifist AI are happy to avoid war.
		modifier = {
			add = 25
			faith = { has_doctrine_parameter = pacifist_opinion_active }
			desc = PT_AI_IS_PACIFIST_FAITH
		}
		modifier = {
			add = 25
			culture = { has_cultural_parameter = reduced_cost_for_conversion_to_pacifist_faith }
			desc = PT_AI_IS_PACIFIST_CULTURE
		}
		# War likeliness.
		## This is primarily intended to mitigate conquest, invasion, and religious CBs, so we don't account for them.
		## scope:actor has some claim to scope:recipient's lands.
		modifier = {
			add = -20
			any_claim = {
				count = 1
				exists = holder
				holder = scope:recipient
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## scope:actor has decent claim to scope:recipient's lands.
		modifier = {
			add = -40
			OR = {
				any_claim = {
					count >= 2
					exists = holder
					holder = scope:recipient
				}
				any_claim = {
					count = 1
					exists = holder
					holder = scope:recipient
					save_temporary_scope_as = claim_temp
					scope:actor = { has_strong_claim_on = scope:claim_temp }
				}
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## scope:actor has strong claim to scope:recipient's lands.
		modifier = {
			add = -60
			any_claim = {
				count >= 2
				exists = holder
				holder = scope:recipient
				save_temporary_scope_as = claim_temp
				scope:actor = { has_strong_claim_on = scope:claim_temp }
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## scope:actor can de jure grab your land.
		### Dukes don't take much.
		modifier = {
			add = -30
			highest_held_title_tier = tier_duchy
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:recipient = {
				any_sub_realm_county = {
					count >= 3
					any_this_title_or_de_jure_above = { holder = scope:recipient }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		### Kings need a lot more.
		modifier = {
			add = -30
			highest_held_title_tier = tier_kingdom
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:recipient = {
				any_sub_realm_county = {
					count >= 10
					any_this_title_or_de_jure_above = { holder = scope:recipient }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		### Emperors take quite a bit to get fussed.
		modifier = {
			add = -30
			highest_held_title_tier = tier_empire
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:recipient = {
				any_sub_realm_county = {
					count >= 20
					any_this_title_or_de_jure_above = { holder = scope:recipient }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		# Force checks.
		## Try to buy truces from somewhat stronger realms...
		modifier = {
			add = 50
			scope:recipient.max_military_strength >= scope:actor.purchase_truce_interaction_recipient_somewhat_stronger_value
		}
		## ... and much stronger realms.
		modifier = {
			add = 50
			scope:recipient.max_military_strength >= scope:actor.purchase_truce_interaction_recipient_far_stronger_value
		}

		# Struggle
		modifier = {
			desc = AI_STRUGGLE_INTENT
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -50
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
						}
					}
					add = 100
				}
			}
		}
	}

	ai_potential = {
		is_adult = yes
		NOT = { has_trait = incapable }
		is_at_war = no
		NOR = {
			has_trait = greedy
			ai_greed > very_high_positive_ai_value
		}
		OR = {
			culture = { has_cultural_tradition = tradition_concubines }
			faith = { has_doctrine = doctrine_concubines }
		}
	}

	ai_accept = {
		base = 0

		modifier = {
			add = {
				value = -50
			}
			scope:secondary_recipient = {
				is_close_family_of = scope:recipient
			}
		}

		modifier = {
			add = {
				value = -30
			}
			scope:secondary_recipient = {
				house = scope:recipient.house
				NOT = { is_close_family_of = scope:recipient }
			}
		}
	
		modifier = {
			add = {
				value = -20
			}
			scope:secondary_recipient = {
				dynasty = scope:recipient.dynasty
				NOR = {
					is_close_family_of = scope:recipient
					house = scope:recipient.house
				}
			}
		}

		modifier = { # Soulmate Filtering
			add = -100
			scope:recipient = {
				has_relation_soulmate = scope:secondary_recipient
			}
			desc = ARE_SOULMATES_REASON
		}

		modifier = { # Lover Filtering
			add = -50
			scope:actor = { has_relation_lover = scope:secondary_recipient }
			desc = ARE_LOVERS_REASON
		}

		modifier = { 
			add = -50
			scope:recipient = {
				any_child = {
					any_parent = { this = scope:secondary_recipient }
				}
			}
		}

		modifier = { # Likely to want two candidates who like each other to marry if Recipient likes them both
			add = 15
			scope:secondary_recipient = { #Do they like each other a lot?
				opinion = {
					target = scope:actor
					value > 50
				}
				reverse_opinion = {
					target = scope:actor
					value > 50
				}
			}
			scope:recipient = { #The Recipient needs to want well for both candidates
				NOT = { has_trait = sadistic }
				NOT = { has_trait = callous }
				NOT = { has_trait = cynical }
				opinion = {
					target = scope:actor
					value > 0
				}
				opinion = {
					target = scope:secondary_recipient
					value > 0
				}
			}
			desc = wishes_well_for_lovers_tooltip
		}
	
		modifier = {
			add = {
				value = -50
				multiply = scope:secondary_recipient.num_of_good_genetic_traits
				multiply = 0.5
			}
			scope:secondary_recipient = {
				num_of_good_genetic_traits > 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_POSITIVE_TRAIT_REASON
		}

		modifier = {
			add = {
				value = -50
				multiply = 0.5
			}
			scope:secondary_recipient = {
				is_lowborn = no
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON_NOBLE
		}

		modifier = {
			add = {
				value = 50
				multiply = scope:secondary_recipient.num_of_bad_genetic_traits
				multiply = 0.5
			}
			scope:secondary_recipient = {
				OR = {
					num_of_bad_genetic_traits > 0
				}
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_NEGATIVE_TRAIT_REASON
		}

		modifier = {
			add = {
				value = 50
				multiply = 0.5
			}
			scope:secondary_recipient = {
				is_lowborn = yes
				num_of_good_genetic_traits = 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON_LOWBORN_NO_POSITIVE_TRAIT
		}
		
		opinion_modifier = { # Opinion of you
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.6
			desc = AI_OPINION_REASON
		}

		opinion_modifier = { # Opinion of concubine
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -0.125
			desc = AI_OPINION_REASON
		}

		modifier = { # A Recipient is unwilling to offer a same-sex concubine if their faith doesn't support it
			add = -1000
			
			scope:actor = {
				allowed_to_marry_same_sex_trigger = no
				sex_same_as = scope:secondary_recipient
			}
			desc = SAME_SEX_MARRIAGE_FAITH_REASON_RECIPIENT
		}

		modifier = { # A Recipient is less likely to agree if they're your liege
			add = {
				value = -40
				multiply = 0.5
			}
			
			scope:actor = {
				target_is_liege_or_above = scope:recipient
			}
			desc = LIEGE_REASON
		}

		#More/Less likely based on difference in rank between actor and recipient
		modifier = {
			add = {
				value = 20
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = 30
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = 40
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = 50
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = 60
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 5
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -20
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -30
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -40
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -50
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = {
				value = -60
				multiply = 0.5
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -5
				}
			}
			desc = AI_RANK_DIFF
		}
		
		modifier = {
			add = {
				value = intimidated_reason_value
				multiply = 0.5
			}
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = {
				value = cowed_reason_value
				multiply = 0.5
			}
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = {
				value = intimidated_external_reason_value
				multiply = 0.5
			}
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = {
				value = cowed_external_reason_value
				multiply = 0.5
			}
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		modifier = {
			add = -5000
			scope:secondary_recipient = {
				fertility <= 0
			}
			desc = AI_FERTILITY_REASON
		}
		modifier = {
			scope:hook = yes
			add = {
				value = 500
				multiply = 0.5
			}
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:hook = yes
			add = {
				value = 1000
				multiply = 0.5
			}
			scope:actor = { has_strong_hook = scope:recipient }
			desc = SCHEME_STRONG_HOOK_USED
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		
		# Struggle
		modifier = {
			trigger_if = {
				limit = {
					scope:recipient = {
						any_character_struggle = {
							involvement = involved
						}
					}
					scope:actor = {
						any_character_struggle = {
							involvement = involved
						}
					}
				}
			}
			trigger_else = {
				always = no
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -50
				}
				else_if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
						}
					}
					add = 100
				}
			}
			desc = AI_STRUGGLE_INTENT
		}

		# Greedy AI
		modifier = {
			add = {
				value = ai_greed
				multiply = -0.5
			}
			ai_greed >= 1
			desc = AI_VALUE_MODIFIER_GREED
		}
		# Boldness always plays a factor.
		modifier = {
			add = {
				value = ai_boldness
				multiply = -0.5
			}
			NOT = { ai_boldness = 0 }
			desc = AI_VALUE_MODIFIER_BOLDNESS
		}
		# Ambitious AI like freedom.
		modifier = {
			add = -50
			has_trait = ambitious
			desc = PT_AI_LIKES_FREEDOM_TO_WAR_REASON
		}
		# AI who are in debt will take whatever windfalls they can.
		modifier = {
			add = {
				value = debt_level
				# Our first rank is 0, so we add one to always get a positive number.
				add = 1
				multiply = 10
			}
			debt_level >= 0
			desc = PT_AI_IS_IN_DEBT
		}
		# Pacifist AI are happy to avoid war.
		modifier = {
			add = 25
			faith = { has_doctrine_parameter = pacifist_opinion_active }
			desc = PT_AI_IS_PACIFIST_FAITH
		}
		modifier = {
			add = 25
			culture = { has_cultural_parameter = reduced_cost_for_conversion_to_pacifist_faith }
			desc = PT_AI_IS_PACIFIST_CULTURE
		}
		# War likeliness.
		## This is primarily intended to mitigate conquest, invasion, and religious CBs, so we don't account for them.
		## Scope:recipient has some claim to scope:actor's lands.
		modifier = {
			add = -20
			any_claim = {
				count = 1
				exists = holder
				holder = scope:actor
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## Scope:recipient has decent claim to scope:actor's lands.
		modifier = {
			add = -40
			OR = {
				any_claim = {
					count >= 2
					exists = holder
					holder = scope:actor
				}
				any_claim = {
					count = 1
					exists = holder
					holder = scope:actor
					save_temporary_scope_as = claim_temp
					scope:recipient = { has_strong_claim_on = scope:claim_temp }
				}
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## Scope:recipient has strong claim to scope:actor's lands.
		modifier = {
			add = -60
			any_claim = {
				count >= 2
				exists = holder
				holder = scope:actor
				save_temporary_scope_as = claim_temp
				scope:recipient = { has_strong_claim_on = scope:claim_temp }
			}
			desc = PT_AI_PERSONALLY_CLAIMS_YOUR_LAND
		}
		## Scope:recipient can de jure grab your land.
		### Dukes don't take much.
		modifier = {
			add = -30
			highest_held_title_tier = tier_duchy
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:actor = {
				any_sub_realm_county = {
					count >= 3
					any_this_title_or_de_jure_above = { holder = scope:actor }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		### Kings need a lot more.
		modifier = {
			add = -30
			highest_held_title_tier = tier_kingdom
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:actor = {
				any_sub_realm_county = {
					count >= 10
					any_this_title_or_de_jure_above = { holder = scope:actor }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		### Emperors take quite a bit to get fussed.
		modifier = {
			add = -30
			highest_held_title_tier = tier_empire
			purchase_truce_interaction_recipient_can_de_jure_war_actor_trigger = yes
			scope:actor = {
				any_sub_realm_county = {
					count >= 20
					any_this_title_or_de_jure_above = { holder = scope:actor }
				}
			}
			desc = PT_AI_DE_JURE_CLAIMS_YOUR_LAND
		}
		
		# Relative power.
		## Scope:actor has far fewer levies than scope:recipient.
		modifier = {
			add = -30
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_far_weaker_value
			desc = PT_AI_RECIPIENT_IS_MUCH_STRONGER
		}
		## Scope:actor has fewer levies than scope:recipient.
		modifier = {
			add = -10
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_far_weaker_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_somewhat_weaker_value
			desc = PT_AI_RECIPIENT_IS_SOMEWHAT_STRONGER
		}
		## Scope:actor has roughly equal levies with scope:recipient.
		modifier = {
			add = 10
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_somewhat_weaker_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_somewhat_stronger_value
			desc = PT_AI_RECIPIENT_IS_ROUGHLY_EQUAL
		}
		## Scope:actor has more levies than scope:recipient.
		modifier = {
			add = 25
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_somewhat_stronger_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_far_stronger_value
			desc = PT_AI_RECIPIENT_IS_SOMEWHAT_WEAKER
		}
		## Scope:actor has far more levies than scope:recipient.
		modifier = {
			add = 50
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_far_stronger_value
			desc = PT_AI_RECIPIENT_IS_MUCH_WEAKER
		}

		modifier = { # Not direct neighbors
			NOT = { scope:actor.top_liege = scope:recipient.top_liege }
			NOR = {
				scope:actor = { character_is_land_realm_neighbor = scope:recipient }
				scope:recipient = { character_is_land_realm_neighbor = scope:actor }
			}
			add = -25
			desc = HOSTAGE_NOT_NEIGHBORING_REALM_REASON
		}
		modifier = { # Distant neighbors
			scope:actor = {
				NOR = {
					character_is_realm_neighbor = scope:recipient
					top_liege = scope:recipient.top_liege
				}
			}
			scope:recipient= {
				NOR = {
					character_is_land_realm_neighbor = scope:actor
					capital_province ?= {
						squared_distance = { target = scope:actor.capital_province value < 200000 }
					}
				}
			}
			add = -25
			desc = HOSTAGE_DISTANT_REALM_REASON
		}

		# Struggle
		modifier = {
			desc = AI_STRUGGLE_INTENT
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -50
				}
				else_if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_sign_truce_outside_war
							}
						}
					}
					add = 100
				}
			}
		}
		# Finally, calculate factors.
		## Only buy truces from weaker/roughly-equal realms if you're craven have been at war forever.
		modifier = {
			factor = 0
			max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_somewhat_weaker_value
			NOR = {
				has_trait = craven
				days_of_continuous_war <= 3650
			}
		}
		## Never buy a truce from someone who actually can't declare war on you.
		modifier = {
			factor = 0
			scope:actor = {
				NOT = { has_any_cb_on = scope:recipient }
			}
		}
		## Don't buy truces from people who are likely going to be dead soon, or if you yourself will die soon, since they'll be wasted.
		modifier = {
			factor = 0
			OR = {
				health <= poor_health
				scope:actor = { health <= poor_health }
			}
		}
	}

	on_send = {
		scope:secondary_recipient = { # to block the same character from being offered twice
			add_character_flag = {
				flag = has_been_offered_as_concubine
				days = 5
			}
		}
	}
	
	on_accept = {
		concubine_truce_on_accept_effect = { ACTOR = scope:recipient RECIPIENT = scope:actor CONCUBINE = scope:secondary_recipient }

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:recipient
			TARGET = scope:actor
			VALUE = minor_unity_gain
			DESC = clan_unity_concubinage_offer.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_generic_neutral
				title = msg_concubine_offer_rejected_title
				right_icon = scope:recipient
				left_icon = scope:secondary_recipient
				custom_tooltip = msg_concubine_request_rejected
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:recipient
			TARGET = scope:actor
			VALUE = medium_unity_loss
			DESC = clan_unity_concubinage_offer_decline.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	send_options_exclusive = no
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
}

request_concubine = {
	interface_priority = 3
	category = interaction_category_diplomacy
	icon = concubine_icon

	desc = request_concubine_desc

	ai_targets = {
		ai_recipients = neighboring_rulers
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 144

	greeting = positive
	notification_text = REQUEST_CONCUBINE_NOTIFICATION

	#interface = concubine_list

	needs_recipient_to_open = yes

	populate_recipient_list = {
		scope:recipient = {
			every_courtier = {
				limit = {
					can_be_offered_as_concubine_to_character_trigger = {
						GIVER = scope:recipient
						CHARACTER = scope:actor
					}
					trigger_if = {
						limit = { is_female = yes }
						is_visibly_fertile = yes
					}
				}
				add_to_list = characters
			}
			every_prisoner = {
				limit = {
					NOT = { is_in_list = characters }
					can_be_offered_as_concubine_to_character_trigger = {
						GIVER = scope:recipient
						CHARACTER = scope:actor
					}
					trigger_if = {
						limit = { is_female = yes }
						is_visibly_fertile = yes
					}
				}
				add_to_list = characters
			}
		}
	}

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:recipient = {
			is_ruler = yes
			OR = {
				culture = { has_cultural_tradition = tradition_concubines }
				faith = { has_doctrine = doctrine_concubines }
			}
		}
		scope:actor = {
			allowed_concubines = yes
			is_adult = yes
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = take_concubine_available_character_opp
			object = scope:actor
			scope:recipient = {
				OR = {
					any_courtier = {
						can_be_offered_as_concubine_to_character_trigger = {
							GIVER = scope:recipient
							CHARACTER = scope:actor
						}
					}
					any_prisoner = {
						can_be_offered_as_concubine_to_character_trigger = {
							GIVER = scope:recipient
							CHARACTER = scope:actor
						}
					}
				}
			}
		}
		custom_description = {
			text = take_concubine_allowed_more
			object = scope:actor
			scope:actor = {
				allowed_more_concubines = yes
			}
		}
	}

	can_be_picked = {
		is_adult = yes
	}

	can_send = {
		custom_description = {
			text = character_unavailable_to_be_offered_as_concubine
			object = scope:secondary_recipient
			scope:secondary_recipient = {
				can_be_offered_as_concubine_to_character_trigger = {
					GIVER = scope:recipient
					CHARACTER = scope:actor
				}
			}
		}
	}

	auto_accept = no

	ai_will_do = {
		base = 0

		modifier = { # Soulmate Filtering
			add = 100
			scope:actor = {
				is_married = yes
				has_relation_soulmate = scope:secondary_recipient
			}
		}

		modifier = { # Lover Filtering
			add = 50
			scope:actor = { has_relation_lover = scope:secondary_recipient }
		}
	
		modifier = { # Basic Filtering
			add = 50
			scope:actor = {
				number_of_concubines < number_of_desired_concubines
			}
			scope:secondary_recipient = {
				trigger_if = {
					limit = {
						allowed_to_marry_same_sex_trigger = no
					}
					sex_opposite_of = scope:actor
				}
				fertility > 0.2
				is_young_character = yes
				NOR = {
					is_councillor_of = scope:recipient
					is_of_major_interest_trigger = {
						CHARACTER = scope:recipient
					}
					is_concubine_of = scope:recipient
				}
			}
		}
	
		modifier = {
			add = {
				value = 50
				multiply = scope:secondary_recipient.num_of_good_genetic_traits
			}
			scope:secondary_recipient = {
				num_of_good_genetic_traits > 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		modifier = {
			add = {
				value = 50
			}
			scope:secondary_recipient = {
				is_lowborn = no
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		modifier = {
			add = {
				value = -50
				multiply = scope:secondary_recipient.num_of_bad_genetic_traits
			}
			scope:secondary_recipient = {
				OR = {
					num_of_bad_genetic_traits > 0
				}
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		modifier = {
			add = {
				value = -50
			}
			scope:secondary_recipient = {
				is_lowborn = yes
				num_of_good_genetic_traits = 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
		}

		opinion_modifier = { # Opinion of recipient
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = 1.0
		}

		opinion_modifier = { # Opinion of concubine
			who = scope:actor
			opinion_target = scope:secondary_recipient
			multiplier = 0.25
		}

		compare_modifier = { # Actor is reluctant to marry old women (procreation is a key factor)
			trigger = {
				scope:secondary_recipient = {
					is_young_character = no
					is_female = yes
				}
			}
			target = scope:secondary_recipient
			value = age
			multiplier = -5.0
			step = 1
			offset = -29
		}

		modifier = { # An actor is unwilling to take a same-sex concubine if their faith doesn't support it
			add = -1000
			
			scope:actor = {
				allowed_to_marry_same_sex_trigger = no
				sex_same_as = scope:secondary_recipient
			}
		}

		modifier = { # Unwilling if they don't have a batch of kids and opposite sex consorts to handle that situation
			add = -200
			scope:actor = {
				allowed_to_marry_same_sex_trigger = yes
				sex_same_as = scope:secondary_recipient
				trigger_if = {
					limit = {
						NOT = {
							any_consort = {
								can_have_children_with = { CHARACTER = scope:actor }
								fertility > 0.1
							}
						}
					}
					any_child = {
						is_player_heir_of = root
					}
				}
				trigger_else = {
					always = no
				}
			}
		}

		modifier = {
			add = 50
			scope:actor = {
				is_attracted_to_gender_of = scope:secondary_recipient
			}
		}

		modifier = { # An actor is more likely to agree if the recipient is their liege
			add = 40
			
			scope:actor = {
				target_is_liege_or_above = scope:recipient
			}
		}

		#More/Less likely based on difference in rank between recipient and actor
		modifier = {
			add = 20
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 1
				}
			}
		}
		modifier = {
			add = 30
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 2
				}
			}
		}
		modifier = {
			add = 40
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 3
				}
			}
		}
		modifier = {
			add = 50
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 4
				}
			}
		}
		modifier = {
			add = 60
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = 5
				}
			}
		}
		modifier = {
			add = -20
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -1
				}
			}
		}
		modifier = {
			add = -30
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -2
				}
			}
		}
		modifier = {
			add = -40
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -3
				}
			}
		}
		modifier = {
			add = -50
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -4
				}
			}
		}
		modifier = {
			add = -60
			scope:recipient = {
				tier_difference = {
					target = scope:actor
					value = -5
				}
			}
		}
		
		modifier = {
			add = intimidated_reason_value
			scope:actor = {
				target_is_liege_or_above = scope:recipient
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}
		modifier = {
			add = cowed_reason_value
			scope:actor = {
				target_is_liege_or_above = scope:recipient
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}
		
		modifier = {
			add = intimidated_external_reason_value
			scope:actor = {
				NOT = { target_is_liege_or_above = scope:recipient }
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}
		modifier = {
			add = cowed_external_reason_value
			scope:actor = {
				NOT = { target_is_liege_or_above = scope:recipient }
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}
		modifier = {
			add = -250
			scope:secondary_recipient = {
				has_std_trigger = yes
			}
		}
		modifier = {
			add = -250
			scope:secondary_recipient = {
				has_epidemic_disease_trigger = yes
			}
		}
		modifier = {
			add = -5000
			scope:secondary_recipient = {
				fertility <= 0
			}
		}
		modifier = {
			scope:hook = yes
			add = 500
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
		}
		modifier = {
			scope:hook = yes
			add = 1000
			scope:actor = { has_strong_hook = scope:recipient }
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
	}

	ai_potential = {
		is_adult = yes
		NOT = { has_trait = incapable }
		is_at_war = no
		NOR = {
			has_trait = greedy
			ai_greed > very_high_positive_ai_value
		}
		OR = {
			culture = { has_cultural_tradition = tradition_concubines }
			faith = { has_doctrine = doctrine_concubines }
		}
	}

	ai_accept = {
		base = -50

		modifier = {
			add = 50
			scope:recipient = {
				has_relation_friend = scope:actor
			}
			desc = ACTIVITY_GUEST_FRIEND_REASON
		}

		modifier = {
			add = {
				value = -50
			}
			scope:secondary_recipient = {
				is_close_family_of = scope:recipient
			}
		}

		modifier = {
			add = {
				value = -30
			}
			scope:secondary_recipient = {
				house = scope:recipient.house
				NOT = { is_close_family_of = scope:recipient }
			}
		}
	
		modifier = {
			add = {
				value = -20
			}
			scope:secondary_recipient = {
				dynasty = scope:recipient.dynasty
				NOR = {
					is_close_family_of = scope:recipient
					house = scope:recipient.house
				}
			}
		}

		modifier = { # Soulmate Filtering
			add = -100
			scope:recipient = {
				has_relation_soulmate = scope:secondary_recipient
			}
			desc = ARE_SOULMATES_REASON
		}

		modifier = { # Lover Filtering
			add = -50
			scope:actor = { has_relation_lover = scope:secondary_recipient }
			desc = ARE_LOVERS_REASON
		}

		modifier = { 
			add = -50
			scope:recipient = {
				any_child = {
					any_parent = { this = scope:secondary_recipient }
				}
			}
		}

		modifier = { # Likely to want two candidates who like each other to marry if Recipient likes them both
			add = 15
			scope:secondary_recipient = { #Do they like each other a lot?
				opinion = {
					target = scope:actor
					value > 50
				}
				reverse_opinion = {
					target = scope:actor
					value > 50
				}
			}
			scope:recipient = { #The Recipient needs to want well for both candidates
				NOT = { has_trait = sadistic }
				NOT = { has_trait = callous }
				NOT = { has_trait = cynical }
				opinion = {
					target = scope:actor
					value > 0
				}
				opinion = {
					target = scope:secondary_recipient
					value > 0
				}
			}
			desc = wishes_well_for_lovers_tooltip
		}

		modifier = {
			add = {
				value = -50
				multiply = scope:secondary_recipient.num_of_good_genetic_traits
			}
			scope:secondary_recipient = {
				num_of_good_genetic_traits > 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_POSITIVE_TRAIT_REASON
		}

		modifier = {
			add = {
				value = -50
			}
			scope:secondary_recipient = {
				is_lowborn = no
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON_NOBLE
		}

		modifier = {
			add = {
				value = 50
				multiply = scope:secondary_recipient.num_of_bad_genetic_traits
			}
			scope:secondary_recipient = {
				OR = {
					num_of_bad_genetic_traits > 0
				}
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_NEGATIVE_TRAIT_REASON
		}

		modifier = {
			add = {
				value = 50
			}
			scope:secondary_recipient = {
				is_lowborn = yes
				num_of_good_genetic_traits = 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON_LOWBORN_NO_POSITIVE_TRAIT
		}

		opinion_modifier = { # Opinion of you
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}

		opinion_modifier = { # Opinion of concubine
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -0.25
			desc = AI_OPINION_REASON
		}

		modifier = { # A Recipient is unwilling to offer a same-sex concubine if their faith doesn't support it
			add = -1000
			
			scope:actor = {
				allowed_to_marry_same_sex_trigger = no
				sex_same_as = scope:secondary_recipient
			}
			desc = SAME_SEX_MARRIAGE_FAITH_REASON_RECIPIENT
		}

		modifier = { # A Recipient is less likely to agree if they're your liege
			add = -40
			
			scope:actor = {
				target_is_liege_or_above = scope:recipient
			}
			desc = LIEGE_REASON
		}

		#More/Less likely based on difference in rank between actor and recipient
		modifier = {
			add = 20
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 40
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 50
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 60
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 5
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -20
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -40
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -50
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -60
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -5
				}
			}
			desc = AI_RANK_DIFF
		}
		
		modifier = {
			add = intimidated_reason_value
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_reason_value
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = intimidated_external_reason_value
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_external_reason_value
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		modifier = {
			add = -5000
			scope:secondary_recipient = {
				fertility <= 0
			}
			desc = AI_FERTILITY_REASON
		}
		modifier = {
			scope:hook = yes
			add = 500
			scope:actor = { NOT = { has_strong_hook = scope:recipient } }
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:hook = yes
			add = 1000
			scope:actor = { has_strong_hook = scope:recipient }
			desc = SCHEME_STRONG_HOOK_USED
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		
		# Relative power.
		## Scope:actor has far fewer levies than scope:recipient.
		modifier = {
			add = -30
			scope:recipient = { 
				any_neighboring_top_liege_realm_owner = { this = scope:actor } 
			}
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_far_weaker_value
			desc = PT_AI_RECIPIENT_IS_MUCH_STRONGER
		}
		## Scope:actor has fewer levies than scope:recipient.
		modifier = {
			add = -10
			scope:recipient = { 
				any_neighboring_top_liege_realm_owner = { this = scope:actor } 
			}
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_far_weaker_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_somewhat_weaker_value
			desc = PT_AI_RECIPIENT_IS_SOMEWHAT_STRONGER
		}
		## Scope:actor has roughly equal levies with scope:recipient.
		modifier = {
			add = 10
			scope:recipient = { 
				any_neighboring_top_liege_realm_owner = { this = scope:actor } 
			}
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_somewhat_weaker_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_somewhat_stronger_value
			desc = PT_AI_RECIPIENT_IS_ROUGHLY_EQUAL
		}
		## Scope:actor has more levies than scope:recipient.
		modifier = {
			add = 25
			scope:recipient = { 
				any_neighboring_top_liege_realm_owner = { this = scope:actor } 
			}
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_somewhat_stronger_value
			scope:actor.max_military_strength <= scope:recipient.purchase_truce_interaction_recipient_far_stronger_value
			desc = PT_AI_RECIPIENT_IS_SOMEWHAT_WEAKER
		}
		## Scope:actor has far more levies than scope:recipient.
		modifier = {
			add = 50
			scope:recipient = { 
				any_neighboring_top_liege_realm_owner = { this = scope:actor } 
			}
			scope:actor.max_military_strength > scope:recipient.purchase_truce_interaction_recipient_far_stronger_value
			desc = PT_AI_RECIPIENT_IS_MUCH_WEAKER
		}
		
		modifier = { # Not direct neighbors
			NOT = { scope:actor.top_liege = scope:recipient.top_liege }
			NOR = {
				scope:actor = { character_is_land_realm_neighbor = scope:recipient }
				scope:recipient = { character_is_land_realm_neighbor = scope:actor }
			}
			add = -25
			desc = HOSTAGE_NOT_NEIGHBORING_REALM_REASON
		}
		modifier = { # Distant neighbors
			scope:actor = {
				NOR = {
					character_is_realm_neighbor = scope:recipient
					top_liege = scope:recipient.top_liege
				}
			}
			scope:recipient= {
				NOR = {
					character_is_land_realm_neighbor = scope:actor
					capital_province ?= {
						squared_distance = { target = scope:actor.capital_province value < 200000 }
					}
				}
			}
			add = -25
			desc = HOSTAGE_DISTANT_REALM_REASON
		}
	}

	on_send = {
		scope:secondary_recipient = { # to block the same character from being offered twice
			add_character_flag = {
				flag = has_been_offered_as_concubine
				days = 5
			}
		}
	}
	
	on_accept = {
		concubine_request_on_accept_effect = yes

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:recipient
			TARGET = scope:actor
			VALUE = minor_unity_gain
			DESC = clan_unity_concubinage_offer.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_generic_neutral
				title = msg_concubine_offer_rejected_title
				right_icon = scope:recipient
				left_icon = scope:secondary_recipient
				custom_tooltip = msg_concubine_request_rejected
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:recipient
			TARGET = scope:actor
			VALUE = medium_unity_loss
			DESC = clan_unity_concubinage_offer_decline.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	send_options_exclusive = no
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
}

elevate_concubine_interaction = {
	icon = concubine_icon
	category = interaction_category_diplomacy
	desc = elevate_concubine_interaction_desc

	is_shown = {
		scope:recipient = { 
			is_concubine_of = scope:actor
			has_trait = concubine
			NOT = { 
				has_opinion_modifier = { 
					target = scope:actor
					modifier = forced_me_concubine_marriage_opinion
				} 
			}
		}
	}

	is_valid = {}

	auto_accept = yes

	cost = {
		prestige = {
			value = bastard_legitimization_prestige_cost
			multiply = 2
		}
	}
	
	on_accept = {
		scope:actor = {
			stress_impact = {
				arrogant = minor_stress_impact_gain
			}
			send_interface_message = {
				type = event_generic_neutral
				title = elevate_concubine_interaction_notification
				right_icon = scope:recipient
				show_as_tooltip = {
					scope:recipient = {
						add_opinion = {
							target = scope:actor
							modifier = legitimized_me_opinion
						}
						if = {
							limit = { 
								any_close_family_member = {
									is_child_of = scope:recipient
									is_child_of = scope:actor
									is_child_of_concubine_trigger = yes
									is_legitimized_child_of_concubine_trigger = no
								}
							}
							add_opinion = {
								target = scope:actor
								modifier = legitimized_my_children_opinion
							}
						}
					}
					scope:actor = {
						every_spouse = {
							if = {
								limit = { scope:recipient = { is_ruler = yes } }
								add_opinion = {
									target = scope:actor
									modifier = suspicion_opinion
									opinion = -40
								}
							}
							else = {
								add_opinion = {
									target = scope:actor
									modifier = angry_opinion
									opinion = -80
								}				
							}
						}
					}
				}
			}
		}
		
		hidden_effect = {
			scope:recipient = {
				remove_trait = concubine
				add_trait = concubine_elevated
				add_opinion = {
					target = scope:actor
					modifier = legitimized_me_opinion
				}
				if = {
					limit = { 
						any_close_family_member = {
							is_child_of = scope:recipient
							is_child_of = scope:actor
							is_child_of_concubine_trigger = yes
							is_legitimized_child_of_concubine_trigger = no
						}
					}
					add_opinion = {
						target = scope:actor
						modifier = legitimized_my_children_opinion
					}
					every_child = {
						limit = {
							is_child_of = scope:recipient
							is_child_of = scope:actor
							is_child_of_concubine_trigger = yes
							is_legitimized_child_of_concubine_trigger = no
						}
						legitimize_child_of_concubine_if_parent_elevated_effect = yes
					}
				}
			}
			scope:actor = {
				every_spouse = {
					if = {
						limit = { scope:recipient = { is_ruler = yes } }
						if = {
							limit = { 
								is_visibly_fertile = yes
								scope:recipient = { is_visibly_fertile = no } 
							}
							add_opinion = {
								target = scope:actor
								modifier = suspicion_opinion
								opinion = -60
							}
						}
						else = {
							add_opinion = {
								target = scope:actor
								modifier = suspicion_opinion
								opinion = -30
							}
						}
					}
					else = {
						if = {
							limit = { 
								OR = {
									is_visibly_fertile = yes
									scope:recipient = { is_visibly_fertile = no }
								}
							}
							add_opinion = {
								target = scope:actor
								modifier = angry_opinion
								opinion = -100
							}
						}
						else = {
							add_opinion = {
								target = scope:actor
								modifier = hurt_opinion
								opinion = -50
							}							
						}
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = courtiers
	}
	
	ai_targets = {
		ai_recipients = vassals
	}

	ai_targets = {
		ai_recipients = prisoners
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency = 55
	
	ai_potential = {
		is_ruler = yes
	}
	
	ai_will_do = {
		base = 0

		modifier = {
			add = -100
			scope:actor = {
				any_spouse = {
					has_relation_soulmate = scope:actor
				}
			}
		}
		
		modifier = {
			add = -75
			scope:actor = {
				any_spouse = {
					has_relation_lover = scope:actor
				}
			}
		}
		
		modifier = {
			add = -75
			scope:actor = {
				any_spouse = {
					has_relation_best_friend = scope:actor
				}
			}
		}
		
		modifier = {
			add = -50
			scope:actor = {
				any_spouse = {
					has_relation_friend = scope:actor
				}
			}
		}

		modifier = {
			add = 100
			scope:actor = {
				has_relation_soulmate = scope:recipient
			}
		}

		modifier = {
			add = 75
			scope:actor = {
				has_relation_lover = scope:recipient
			}
		}
	
		modifier = {
			add = 75
			scope:actor = {
				has_relation_best_friend = scope:recipient
			}
		}
		
		modifier = {
			add = 50
			scope:recipient = { is_ruler = yes }
		}

		modifier = {
			add = 50
			exists = scope:actor.primary_spouse
			scope:actor.primary_spouse = { is_visibly_fertile = no }
			scope:actor = { has_eligible_child_heir_trigger = no }
			scope:recipient = { 
				is_visibly_fertile = yes
				any_child = { 
					is_child_of_concubine_trigger = yes
					is_child_of = scope:actor
					count = 0 
				}
			}
		}
	}
}
