﻿#Interactions relating to the head of the dynasty

adopt_interaction = {
	icon = icon_dynasty
	category = interaction_category_diplomacy
	interface_priority = 60

	desc = adopt_interaction_desc
	use_diplomatic_range = yes
	
	is_shown = {
		OR = {
			# Cultures that default with this tradition should still be able to adopt
			scope:actor.culture = { has_cultural_parameter = allows_adoption }
			NOT = { 
				has_game_rule = no_adoption
			}
		}
		NOT = { 
			scope:recipient = scope:actor
		}
		scope:actor = {
			is_adult = yes
			OR = {
				# Compassionate people like adopting
				has_trait = compassionate
				# Game rule as an overriding factor
				has_game_rule = adoption_always_allowed
				# You have no kids and your fertility is low
				AND = {
					any_child = {
						count < 1
					}
					fertility <= low_fertility
				}
				# You are married to a same-sex partner
				AND = {
					is_married = yes
					# People in bisexual polygamous spheres are not valid for this
					NOT = {
						OR = {
							AND = {
								any_consort = {
									is_female = yes
								}
								is_male = yes
							}
							AND = {
								any_consort = {
									is_male = yes
								}
								is_female = yes
							}
						}
					}
				}
				# You are unmarried and uninterested in having biological children
				AND = {
					is_married = no
					OR = {
						has_sexuality = asexual
						has_sexuality = homosexual
					}
				}
				# You have a cultrad that lets you adopt
				culture = { has_cultural_parameter = allows_adoption }
			}
			OR = {
				# You are unmarried
				is_married = no
				# You are the dominant partner in at least one of your marriages
				AND = {
					is_female = yes
					matrilinear_marriage = yes
				}
				AND = {
					is_male = yes
					matrilinear_marriage = no
				}
				# Your marriage is same-sex
				NOT = {
					OR = {
						AND = {
							any_consort = {
								is_female = yes
							}
							is_male = yes
						}
						AND = {
							any_consort = {
								is_male = yes
							}
							is_female = yes
						}
					}
				}
			}
		}
		scope:recipient = {
			# Children only
			is_adult = no
			# Landless only (ruler used to catch edge-cases of landless HoF children)
			is_ruler = no
			# Don't get imprisoned children and so on
			is_available = yes
			# None of their close relatives are rulers
			NOT = {
				any_close_or_extended_family_member = { is_ruler = yes }
			}
			# They don't already belong to your house
			NOT = { house = scope:actor.house }
			# Don't adopt your own grandkids
			NOT = {
				any_ancestor = {
					this = scope:actor
				}
			}
			# Don't steal the King of France's great nephew
			NOT = {
				any_liege_or_above = {
					prev.dynasty = dynasty
				}
			}
		}
	}

	is_valid = {}

	is_valid_showing_failures_only = {}

	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence 
			scope:actor = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:actor = { influence >= medium_influence_value }
			# Both characters are within the same top realm
			scope:recipient.top_liege = scope:actor.top_liege
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	send_options_exclusive = no
	
	on_accept = {
		show_as_tooltip = {
			adopt_effect = {
				CHILD = scope:recipient
				ADOPTER = scope:actor
			}
		}
		hidden_effect = {
			scope:actor = { trigger_event = adoption.0001 }
		}
	}
	
	cost = {
		renown = {
			value = {
				add = medium_dynasty_prestige_value
				if = { # Free for free adoption
					limit = {
						scope:actor = {
							OR = {
								culture = { has_cultural_parameter = free_adoption }
								has_game_rule = adoption_always_allowed
							}
						}
					}
					multiply = 0
				}
				if = { # Free for same-sex couples
					limit = {
						scope:actor = {
							OR = {
								AND = {
									any_consort = {
										is_female = yes
									}
									is_female = yes
								}
								AND = {
									any_consort = {
										is_male = yes
									}
									is_male = yes
								}
							}
						}
					}
					multiply = 0
				}
			}
		}
		prestige = {
			value = {
				add = medium_prestige_value
				if = {
					limit = {
						scope:actor = {
							OR = {
								culture = { has_cultural_parameter = free_adoption }
								has_game_rule = adoption_always_allowed
							}
						}
					}
					multiply = 0
				}
			}
		}
		piety = {
			value = {
				add = medium_piety_value
				if = {
					limit = {
						scope:actor = {
							OR = {
								culture = { has_cultural_parameter = free_adoption }
								has_game_rule = adoption_always_allowed
							}
						}
					}
					multiply = 0
				}
				# No piety cost for adopting a righteous-faith child
				if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value < faith_astray_level
							}
						}
					}
					multiply = 0
				}
				else_if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value > faith_astray_level
							}
						}
					}
					add = minor_piety_value
				}
				else_if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value > faith_hostile_level
							}
						}
					}
					add = medium_piety_value
				}
			}
		}
		influence = {
			value = 0
			if = {
				limit = { scope:influence_send_option = yes }
				add = scope:actor.medium_influence_value
				desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
			}
		}
	}

	ai_potential = {
		any_child = {
			count < 2
		}
		OR = {
			fertility <= low_fertility
			AND = {
				is_male = yes
				NOT = {
					any_spouse = {
						fertility > low_fertility
						is_female = yes
					}
				}
			}
			AND = {
				is_female = yes
				NOT = {
					any_spouse = {
						fertility > low_fertility
						is_male = yes
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = courtiers
		ai_recipients = guests
		# Friends, wards, etc.
		ai_recipients = scripted_relations
		max = 20
	}
	
	ai_accept = {
		base = 0
		modifier = { # My parents are alive
			add = -15
			desc = parents_are_alive_tt
			OR = {
				father ?= { is_alive = yes }
				mother ?= { is_alive = yes }
			}
		}
		modifier = { # I hate my mother
			add = 10
			desc = i_hate_my_mother_tt
			exists = mother
			mother = { is_alive = yes }
			opinion = {
				value <= medium_negative_opinion
				target = mother
			}
		}
		modifier = { # I hate my father
			add = 10
			desc = i_hate_my_father_tt
			exists = father
			father = { is_alive = yes }
			opinion = {
				value <= medium_negative_opinion
				target = father
			}
		}
		modifier = { # I like my mother
			add = -10
			desc = i_like_my_mother_tt
			exists = mother
			mother = { is_alive = yes }
			opinion = {
					value >= medium_positive_opinion
					target = mother
				}
		}
		modifier = { # I like my father
			add = -10
			desc = i_like_my_father_tt
			exists = father
			father = { is_alive = yes }
			opinion = {
				value >= medium_positive_opinion
				target = father
			}
		}
		modifier = { # I like you
			add = {
				value = 5
				if = {
					limit = {
						opinion = {
							value >= high_positive_opinion
							target = scope:actor
						}
					}
					add = 10
				}
				if = {
					limit = {
						opinion = {
							value >= very_high_positive_opinion
							target = scope:actor
						}
					}
					add = 10
				}
			}
			desc = i_like_you_tt
			opinion = {
				value >= medium_positive_opinion
				target = scope:actor
			}
		}
		modifier = { # You're my friend :)
			add = 10
			desc = youre_my_friend_tt
			has_relation_friend = scope:actor
		}
		modifier = { # You're my guardian
			add = 10
			desc = youre_my_guardian_tt
			has_relation_guardian = scope:actor
		}
		modifier = { # I have no mother
			add = 5
			desc = i_want_a_mother_tt
			scope:actor = { is_female = yes }
			OR = {
				NOT = { exists = mother }
				mother = { is_alive = no }
			}
		}
		modifier = { # I have no father
			add = 5
			desc = i_want_a_father_tt
			scope:actor = { is_male = yes }
			OR = {
				NOT = { exists = father }
				father = { is_alive = no }
			}
		}
		modifier = { # I am a noble!
			add = -15
			desc = i_am_noble_tt
			has_no_particular_noble_roots_trigger = no
		}
		modifier = { # We are so alike ^^
			add = { 
				value = 5
				if = {
					limit = {
						number_of_personality_traits_in_common = {
							target = scope:actor
							value = 2
						}
					}
					multiply = 2
				}
				else_if = {
					limit = {
						number_of_personality_traits_in_common = {
							target = scope:actor
							value = 3
						}
					}
					multiply = 3
				}
				else_if = {
					limit = {
						number_of_personality_traits_in_common = {
							target = scope:actor
							value = 4
						}
					}
					multiply = 4
				}
			}
			desc = we_are_alike_tt
			number_of_personality_traits_in_common = {
				target = scope:actor
				value >= 1
			}
		}
		modifier = { # Yo, you're offering me a place in a landed house? Sick.
			add = 10
			desc = ambition_tt
			has_trait = ambitious
		}
		modifier = {
			add = 25
			scope:influence_send_option = yes
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
		}
	}
	
	ai_frequency = 120
	
	ai_will_do = {
		base = 50

		modifier = { # I am childless and my marriage will never produce heirs
			add = 100
			scope:actor = {
				any_child = {
					count < 1
				}
				OR = {
					fertility <= low_fertility
					AND = {
						is_male = yes
						NOT = {
							any_spouse = {
								fertility > low_fertility
								is_female = yes
							}
						}
					}
					AND = {
						is_female = yes
						NOT = {
							any_spouse = {
								fertility > low_fertility
								is_male = yes
							}
						}
					}
				}
			}
		}

		modifier = { # I am kind and the child is an orphan
			add = 100
			scope:actor = {
				ai_compassion >= high_positive_compassion
			}
			NOT = {
				exists = scope:recipient.mother
				exists = scope:recipient.father
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 1
				}
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 2
				}
			}
		}

		modifier = { # Traits in common
			add = 25
			scope:actor = {
				number_of_personality_traits_in_common = {
					target = scope:recipient
					value = 3
				}
			}
		}

		modifier = { # My culture is into adoption
			add = 25
			scope:actor = {
				OR = {
					culture = { has_cultural_parameter = free_adoption }
					has_game_rule = adoption_always_allowed
				}
			}
		}

		modifier = { # I like the kid
			add = 25
			scope:actor = {
				opinion = {
					value >= medium_positive_opinion
					target = scope:recipient
				}
			}
		}

		modifier = { # The kid is my friend uwu
			add = 25
			scope:actor = {
				has_relation_friend = scope:recipient
			}
		}

		modifier = { # The kid is my ward
			add = 25
			scope:actor = {
				has_relation_guardian = scope:recipient
			}
		}

		modifier = { # I care about bloodlines and dynasties and whatnot
			add = -25
			scope:actor = {
				NOR = {
					culture = { has_cultural_parameter = free_adoption }
					has_game_rule = adoption_always_allowed
					has_trait = humble
					has_trait = callous
				}
			}
		}
		
		modifier = { # I will not adopt filthy filthy heretics
			factor = 0
			faith = {
				faith_hostility_level = {
					target = scope:recipient.faith
					value >= faith_astray_level
				}
			}
		}
	}
}

adventurer_adopt_interaction = {
	icon = icon_adopt_house_member
	category = interaction_category_diplomacy
	interface_priority = 60
	cooldown = { years = 2 }

	desc = adventurer_adopt_interaction_desc
	use_diplomatic_range = yes
	
	is_shown = {
		scope:actor = { is_landless_adventurer = yes }
		scope:recipient = {
			is_ruler = no
			# They don't already belong to your dynasty
			NOT = { dynasty = scope:actor.dynasty }
		}
	}

	is_valid = {}

	is_valid_showing_failures_only = {
		# Don't get imprisoned children and so on
		scope:recipient = {
			is_available = yes
			is_courtier_of = scope:actor
			opinion = {
				value >= 40 # sync with define:NDomicile|TEMPERAMENT_THRESHOLD_HIGH
				target = scope:actor
			}
			has_no_particular_noble_roots_trigger = yes
		}
		scope:recipient = {
			NOT = { has_trait = devoted }
		}
		scope:recipient = {
			NOT = { has_trait = gallivanter }
		}
	}
	
	on_accept = {
		show_as_tooltip = {
			adventurer_adopt_effect = {
				CHILD = scope:recipient
				ADOPTER = scope:actor
			}
			scope:actor = { set_designated_heir = scope:recipient }
		}
		hidden_effect = {
			scope:actor = { trigger_event = adoption.0002 }
		}
	}
	
	cost = {
		prestige = {
			value = {
				add = medium_prestige_value
				if = {
					limit = {
						scope:actor = {
							OR = {
								culture = { has_cultural_parameter = free_adoption }
								has_game_rule = adoption_always_allowed
							}
						}
					}
					multiply = 0
				}
			}
		}
	}
	
	ai_accept = {
		base = 0
		modifier = { # My parents are alive
			add = -15
			desc = parents_are_alive_tt
			OR = {
				father ?= { is_alive = yes }
				mother ?= { is_alive = yes }
			}
		}
		modifier = { # I hate my mother
			add = 10
			desc = i_hate_my_mother_tt
			exists = mother
			mother = { is_alive = yes }
			opinion = {
				value <= medium_negative_opinion
				target = mother
			}
		}
		modifier = { # I hate my father
			add = 10
			desc = i_hate_my_father_tt
			exists = father
			father = { is_alive = yes }
			opinion = {
				value <= medium_negative_opinion
				target = father
			}
		}
		modifier = { # I like my mother
			add = -10
			desc = i_like_my_mother_tt
			exists = mother
			mother = { is_alive = yes }
			opinion = {
				value >= medium_positive_opinion
				target = mother
			}
		}
		modifier = { # I like my father
			add = -10
			desc = i_like_my_father_tt
			exists = father
			father = { is_alive = yes }
			opinion = {
				value >= medium_positive_opinion
				target = father
			}
		}
		modifier = { # I like you
			add = {
				value = 5
				if = {
					limit = {
						opinion = {
							value >= high_positive_opinion
							target = scope:actor
						}
					}
					add = 10
				}
				if = {
					limit = {
						opinion = {
							value >= very_high_positive_opinion
							target = scope:actor
						}
					}
					add = 10
				}
			}
			desc = i_like_you_tt
			opinion = {
				value >= medium_positive_opinion
				target = scope:actor
			}
		}
		modifier = { # You're my friend :)
			add = 10
			desc = youre_my_friend_tt
			has_relation_friend = scope:actor
		}
		modifier = { # You're my guardian
			add = 10
			desc = youre_my_guardian_tt
			has_relation_guardian = scope:actor
		}
		modifier = { # I have no mother
			add = 5
			desc = i_want_a_mother_tt
			scope:actor = { is_female = yes }
			OR = {
				NOT = { exists = mother }
				mother = { is_alive = no }
			}
		}
		modifier = { # I have no father
			add = 5
			desc = i_want_a_father_tt
			scope:actor = { is_male = yes }
			OR = {
				NOT = { exists = father }
				father = { is_alive = no }
			}
		}
		modifier = { # I am a noble!
			add = -15
			desc = i_am_noble_tt
			has_no_particular_noble_roots_trigger = no
		}
		modifier = { # We are so alike ^^
			add = { 
				value = 5
				if = {
					limit = {
						number_of_personality_traits_in_common = {
							target = scope:actor
							value = 2
						}
					}
					multiply = 2
				}
				else_if = {
					limit = {
						number_of_personality_traits_in_common = {
							target = scope:actor
							value = 3
						}
					}
					multiply = 3
				}
				else_if = {
					limit = {
						number_of_personality_traits_in_common = {
							target = scope:actor
							value = 4
						}
					}
					multiply = 4
				}
			}
			desc = we_are_alike_tt
			number_of_personality_traits_in_common = {
				target = scope:actor
				value >= 1
			}
		}
		modifier = { # Yo, you're offering me a place in a landed house? Sick.
			add = 10
			desc = ambition_tt
			has_trait = ambitious
		}
	}
}
