﻿namespace = lmf_heir

###########################
# CHILDHOOD & HEIR EVENTS #
###########################

scripted_trigger can_be_new_educator_trigger = {
	is_physically_able_adult = yes
	num_of_relation_ward < FF_ward_limit
	has_recoverable_disease_trigger = no
	NOR = {
		has_trait = education_martial_1
		has_trait = education_diplomacy_1
		has_trait = education_intrigue_1
		has_trait = education_stewardship_1
		has_trait = education_learning_1
		has_relation_rival = scope:current_host
	}
}

scripted_trigger has_good_martial_trait_trigger = {
	OR = {
		has_trait = brave
		has_trait = physique_good
		has_trait = shrewd
		has_trait = giant
		prowess >= 12
		AND = {
			religion = { exists = var:variable_ghw_unlocked }
			has_trait = zealous
		}
	}
}

scripted_trigger has_bad_martial_trait_trigger = {
	OR = {
		has_trait = craven
		has_trait = physique_bad
		has_trait = weak
		has_trait = spindly
		has_trait = wheezing
		has_trait = bleeder
		has_trait = inbred
		has_trait = dwarf
		has_trait = hunchbacked
		has_trait = clubfooted
		has_trait = blind
	}
}

scripted_trigger suitable_child_combatant_trigger = {
	OR = {
		# their gender can fight already
		can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:current_host }
		# they could potentially get the Shield Maiden trait
		scope:current_host.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
		# they're potentially a good enough swordsperson to ignore gender restrictions
		scope:current_host.culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
		# this is a particularly capable daughter (every ruler only gets one)
		AND = {
			is_female = yes
			has_good_martial_trait_trigger = yes
			scope:current_host = {
				NOT = { has_character_flag = had_lmfmod_1500_event_daughter }
			}
		}
	}
}

# Child of 8+ really wants to learn martial instead
lmf_heir.1500 = {
	type = character_event

	hidden = yes

	trigger = {
		has_bp2_dlc_trigger = yes
		age >= 8
		age <= 12
		prowess >= 4
		has_dynasty = yes
		exists = host
		is_playable_character = no
		host = { save_temporary_scope_as = current_host }
		OR = {
			is_close_family_of = scope:current_host
			is_great_grandchild_of = scope:current_host
		}
		OR = {
			has_trait = rowdy
			has_trait = bossy
		}
		OR = {
			AND = {
				has_focus = education_learning
				martial > learning
			}
			AND = {
				has_focus = education_diplomacy
				martial > diplomacy
			}
			AND = {
				has_focus = education_intrigue
				martial > intrigue
			}
			AND = {
				has_focus = education_stewardship
				martial > stewardship
			}
		}
		has_bad_martial_trait_trigger = no
		has_recoverable_disease_trigger = no
		is_available_ai = yes
		suitable_child_combatant_trigger = yes
		NOR = {
			host = root
			has_character_flag = had_lmfmod_1500_event
			has_character_flag = had_lmfmod_1502_event
			has_character_flag = had_lmfmod_1504_event
		}
		scope:current_host = {
			is_adult = yes
			any_courtier = {
				has_education_martial_trigger = yes
				can_be_new_educator_trigger = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:current_host }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			has_trait = brave
			add = 2
		}
		modifier = {
			prowess >= 6
			add = 0.5
		}
		modifier = {
			prowess >= 8
			add = 0.5
		}
		modifier = {
			OR = {
				AND = {
					has_focus = education_learning
					martial_plus_2 > learning
				}
				AND = {
					has_focus = education_diplomacy
					martial_plus_2 > diplomacy
				}
				AND = {
					has_focus = education_intrigue
					martial_plus_2 > intrigue
				}
				AND = {
					has_focus = education_stewardship
					martial_plus_2 > stewardship
				}
			}
			add = 0.5
		}
		modifier = {
			OR = {
				AND = {
					has_focus = education_learning
					martial_plus_4 > learning
				}
				AND = {
					has_focus = education_diplomacy
					martial_plus_4 > diplomacy
				}
				AND = {
					has_focus = education_intrigue
					martial_plus_4 > intrigue
				}
				AND = {
					has_focus = education_stewardship
					martial_plus_4 > stewardship
				}
			}
			add = 0.5
		}
		modifier = {
			is_female = yes
			exists = host
			host = {
				is_female = yes
				culture = { has_cultural_parameter = has_access_to_shieldmaidens }
			}
			add = 1
		}
		modifier = {
			religion = { exists = var:variable_ghw_unlocked }
			has_trait = zealous
			add = 1
		}
		modifier = {
			factor = 0.5
			exists = host
			NOR = {
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root.host }
				host = { sex_same_as = root }
				host = { is_ai = no }
			}
		}
	}

	immediate = {
		add_character_flag = had_lmfmod_1500_event
		save_scope_as = focus_child
		if = {
			limit = { is_female = yes }
			host = { add_character_flag = had_lmfmod_1500_event_daughter }
		}
		if = {
			limit = { num_of_relation_guardian > 0 }
			random_relation = {
				type = guardian
				save_scope_as = guardian
			}
		}
		host = {
			trigger_event = lmf_heir.1501
		}
	}
}

lmf_heir.1501 = {
	type = character_event
	title = lmf_heir.1501.t
	desc = {
		desc = lmf_heir.1501.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:focus_child = {
						NOR = {
							can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
							root.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
							root.culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
						}
					}
				}
				desc = lmf_heir.1501.unusual
			}
			desc = lmf_heir.1501.default
		}
		desc = lmf_heir.1501.end
	}
	theme = family

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:new_educator
		animation = throne_room_conversation_4
	}
	lower_right_portrait = scope:focus_child
	override_background = { reference = army_camp }

	immediate = {
		root = { save_scope_as = current_host }
		hidden_effect = {
			every_courtier = {
				limit = {
					has_education_martial_trigger = yes
					can_be_new_educator_trigger = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
					NOT = { has_relation_ward = scope:focus_child }
				}
				alternative_limit = {
					has_education_martial_trigger = yes
					can_be_new_educator_trigger = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				add_to_list = potential_educators
			}
			ordered_in_list = {
				list = potential_educators
				order_by = martial_educator_value
				save_scope_as = new_educator
			}
		}
	}

	option = {
		name = lmf_heir.1501.a # Let them switch to martial
		custom_tooltip = lmf_heir.1500.a.tt_change
		custom_tooltip = lmf_heir.1500.a.tt_tutor
		hidden_effect = {
			scope:focus_child = {
				set_focus = education_martial
				change_variable = {
					name = education_martial_variable
					add = age
				}
			}
		}
		scope:focus_child = {
			add_martial_skill = 1
			add_prowess_skill = 2
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			add_opinion = {
				target = scope:new_educator
				modifier = grateful_opinion
				opinion = 20
			}
			if = {
				limit = {
					exists = scope:guardian
					NOT = { has_relation_guardian = scope:new_educator }
				}
				remove_guardian_effect = {
					GUARDIAN = scope:guardian
					WARD = scope:focus_child
					RETURN_WARD = no
					HIDE_OPINION = yes
				}
			}
			if = {
				limit = {
					NOT = { has_relation_guardian = scope:new_educator }
				}
				set_relation_guardian = scope:new_educator
			}
			if = {
				limit = {
					NOR = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						root.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
						root.culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
					}
				}
				add_character_flag = {
					flag = might_ignore_gender_army_rules
					years = 10
				}
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 50
				religion = { exists = var:variable_ghw_unlocked }
				ai_zeal > 0
			}
			ai_value_modifier = {
				ai_compassion = 2
			}
			modifier = {
				factor = 0.5
				scope:focus_child = {
					NOT = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
				}
			}
			modifier = {
				factor = 0
				is_physically_able_adult = yes
				is_parent_of = scope:focus_child
				has_education_martial_trigger = yes
				OR = {
					num_of_relation_ward < FF_ward_limit
					has_relation_ward = scope:focus_child
				}
			}
			modifier = {
				factor = 0
				NOT = { has_trait = compassionate }
				scope:focus_child = {
					is_player_heir_of = root
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
			}
		}
	}
	option = {
		trigger = {
			is_physically_able_adult = yes
			OR = {
				num_of_relation_ward < FF_ward_limit
				has_relation_ward = scope:focus_child
			}
		}
		name = {
			trigger = {
				NOT = { has_relation_ward = scope:focus_child }
			}
			text = lmf_heir.1501.c # They can help, but I'll train him
		}
		name = {
			trigger = {
				has_relation_ward = scope:focus_child
			}
			text = lmf_heir.1501.c # They can help, but I'll keep training him
		}
		custom_tooltip = lmf_heir.1500.a.tt_change
		custom_tooltip = lmf_heir.1500.a.tt_tutor
		hidden_effect = {
			scope:focus_child = {
				set_focus = education_martial
				change_variable = {
					name = education_martial_variable
					add = age
				}
			}
		}
		scope:focus_child = {
			add_martial_skill = 1
			add_prowess_skill = 2
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			add_opinion = {
				target = scope:new_educator
				modifier = grateful_opinion
				opinion = 20
			}
			if = {
				limit = {
					exists = scope:guardian
					NOT = { has_relation_guardian = root }
				}
				remove_guardian_effect = {
					GUARDIAN = scope:guardian
					WARD = scope:focus_child
					RETURN_WARD = no
					HIDE_OPINION = yes
				}
			}
			if = {
				limit = {
					NOT = { has_relation_guardian = root }
				}
				set_relation_guardian = root
			}
			if = {
				limit = {
					NOR = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						root.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
						root.culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
					}
				}
				add_character_flag = {
					flag = might_ignore_gender_army_rules
					years = 10
				}
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 50
				religion = { exists = var:variable_ghw_unlocked }
				ai_zeal > 0
			}
			ai_value_modifier = {
				ai_compassion = 2
			}
			modifier = {
				factor = 0.5
				scope:focus_child = {
					NOT = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
				}
			}
			modifier = {
				factor = 0
				has_education_martial_trigger = no
			}
			modifier = {
				factor = 0
				NOT = { is_parent_of = scope:focus_child }
			}
			modifier = {
				factor = 0
				NOT = { has_trait = compassionate }
				scope:focus_child = {
					is_player_heir_of = root
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
			}
		}
	}
	option = {
		name = lmf_heir.1501.b # No, they must focus on their current studies
		stress_impact = {
			base = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			callous = minor_stress_impact_loss
		}
		custom_tooltip = bp2_yearly.1030.b.tt
		#To avoid an empty random list
		hidden_effect = {
			scope:focus_child = { education_point_acquisition_effect = yes }
		}
		scope:focus_child = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
			stress_impact = {
				base = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 2
				has_trait = diligent
			}
			modifier = {
				factor = 2
				has_trait = callous
			}
		}
	}
}

# Child of 8+ wants to abandon martial training
lmf_heir.1502 = {
	type = character_event

	hidden = yes

	trigger = {
		has_bp2_dlc_trigger = yes
		age >= 8
		age <= 12
		has_dynasty = yes
		exists = host
		is_playable_character = no
		host = { save_temporary_scope_as = current_host }
		scope:current_host = { is_adult = yes }
		OR = {
			is_close_family_of = scope:current_host
			is_great_grandchild_of = scope:current_host
		}
		has_focus = education_martial
		has_good_martial_trait_trigger = no
		OR = {
			has_bad_martial_trait_trigger = yes
			AND = {
				has_trait = charming
				OR = {
					intrigue > martial
					diplomacy > martial
				}
			}
			AND = {
				has_trait = curious
				OR = {
					learning > martial
					diplomacy > martial
				}
			}
			AND = {
				has_trait = pensive
				OR = {
					learning > martial
					stewardship > martial
				}
			}
		}
		has_recoverable_disease_trigger = no
		is_available_ai = yes
		NOR = {
			host = root
			has_character_flag = had_lmfmod_1500_event
			has_character_flag = had_lmfmod_1502_event
			has_character_flag = had_lmfmod_1504_event
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			has_trait = craven
			add = 2
		}
		modifier = {
			has_trait = physique_bad_1
			add = 1
		}
		modifier = {
			has_trait = physique_bad_2
			add = 2
		}
		modifier = {
			has_trait = physique_bad_3
			add = 3
		}
		modifier = {
			NOR = {
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root.host }
				root.host.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
				root.host.culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
			}
			add = 2
		}
		modifier = {
			root.host = { has_education_martial_trigger = no }
			add = 1
		}
		modifier = {
			root.host = { has_education_martial_trigger = yes }
			add = 0.5
		}
	}

	immediate = {
		add_character_flag = had_lmfmod_1502_event
		save_scope_as = focus_child
		if = {
			limit = { num_of_relation_guardian > 0 }
			random_relation = {
				type = guardian
				save_scope_as = guardian
			}
		}
		host = {
			trigger_event = lmf_heir.1503
		}
	}
}

lmf_heir.1503 = {
	type = character_event
	title = lmf_heir.1503.t
	desc = {
		desc = lmf_heir.1503.start
		triggered_desc = {
			trigger = {
				scope:focus_child = {
					NOR = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						root.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
						root.culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
					}
				}
			}
			desc = lmf_heir.1503.female
		}
		desc = lmf_heir.1503.end
	}
	theme = family

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:focus_child
		animation = shame
	}
	override_background = { reference = army_camp }

	immediate = {
		root = { save_scope_as = current_host }
		hidden_effect = {
			every_courtier = {
				limit = {
					has_education_learning_trigger = yes
					can_be_new_educator_trigger = yes
					NOT = { has_relation_ward = scope:focus_child }
				}
				add_to_list = potential_learning_educator
			}
			every_courtier = {
				limit = {
					has_education_diplomacy_trigger = yes
					can_be_new_educator_trigger = yes
					NOT = { has_relation_ward = scope:focus_child }
				}
				add_to_list = potential_diplomacy_educator
			}
			every_courtier = {
				limit = {
					has_education_stewardship_trigger = yes
					can_be_new_educator_trigger = yes
					NOT = { has_relation_ward = scope:focus_child }
				}
				add_to_list = potential_stewardship_educator
			}
			every_courtier = {
				limit = {
					has_education_intrigue_trigger = yes
					can_be_new_educator_trigger = yes
					NOT = { has_relation_ward = scope:focus_child }
				}
				add_to_list = potential_intrigue_educator
			}

			if = {
				limit = {
					any_in_list = { list = potential_learning_educator }
				}
				ordered_in_list = {
					list = potential_learning_educator
					order_by = learning_educator_value
					save_scope_as = new_learning_educator
				}
			}
			if = {
				limit = {
					any_in_list = { list = potential_diplomacy_educator }
				}
				ordered_in_list = {
					list = potential_diplomacy_educator
					order_by = diplomacy_educator_value
					save_scope_as = new_diplomacy_educator
				}
			}
			if = {
				limit = {
					any_in_list = { list = potential_stewardship_educator }
				}
				ordered_in_list = {
					list = potential_stewardship_educator
					order_by = stewardship_educator_value
					save_scope_as = new_stewardship_educator
				}
			}
			if = {
				limit = {
					any_in_list = { list = potential_intrigue_educator }
				}
				ordered_in_list = {
					list = potential_intrigue_educator
					order_by = intrigue_educator_value
					save_scope_as = new_intrigue_educator
				}
			}
		}
	}

	option = {
		trigger = {
			scope:focus_child = {
				OR = {
					has_trait = curious
					has_trait = charming
				}
			}
		}
		name = {
			trigger = { exists = scope:new_diplomacy_educator }
			text = lmf_heir.1503.a #switch to diplomacy, new tutor
		}
		name = {
			trigger = { NOT = { exists = scope:new_diplomacy_educator } }
			text = lmf_heir.1503.b #switch to diplomacy, no new tutor
		}
		custom_tooltip = lmf_heir.1503.a.tt_change
		if = {
			limit = { exists = scope:new_diplomacy_educator }
			custom_tooltip = lmf_heir.1503.a.tt_tutor
		}
		else = {
			custom_tooltip = lmf_heir.1503.tt_no_tutor
		}
		hidden_effect = {
			scope:focus_child = {
				set_focus = education_diplomacy
				change_variable = {
					name = education_diplomacy_variable
					add = scope:focus_child.age
				}
			}
		}
		scope:focus_child = {
			add_diplomacy_skill = 1
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			if = {
				limit = {
					exists = scope:guardian
					exists = scope:new_diplomacy_educator
					NOT = { has_relation_guardian = scope:new_diplomacy_educator }
				}
				remove_guardian_effect = {
					GUARDIAN = scope:guardian
					WARD = scope:focus_child
					RETURN_WARD = no
					HIDE_OPINION = yes
				}
			}
			if = {
				limit = {
					exists = scope:new_diplomacy_educator
					NOT = { has_relation_guardian = scope:new_diplomacy_educator }
				}
				set_relation_guardian = scope:new_diplomacy_educator
			}
			else_if = {
				limit = {
					NOT = { exists = scope:new_diplomacy_educator }
				}
				stress_impact = {
					base = minor_stress_impact_gain
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = {
		trigger = {
			scope:focus_child = {
				OR = {
					has_trait = pensive
					has_trait = bossy
				}
			}
		}
		name = {
			trigger = { exists = scope:new_stewardship_educator }
			text = lmf_heir.1503.c #switch to stewardship, new tutor
		}
		name = {
			trigger = { NOT = { exists = scope:new_stewardship_educator } }
			text = lmf_heir.1503.d #switch to stewardship, no new tutor
		}
		custom_tooltip = lmf_heir.1503.b.tt_change
		if = {
			limit = { exists = scope:new_stewardship_educator }
			custom_tooltip = lmf_heir.1503.b.tt_tutor
		}
		else = {
			custom_tooltip = lmf_heir.1503.tt_no_tutor
		}
		hidden_effect = {
			scope:focus_child = {
				set_focus = education_stewardship
				change_variable = {
					name = education_stewardship_variable
					add = scope:focus_child.age
				}
			}
		}
		scope:focus_child = {
			add_stewardship_skill = 1
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			if = {
				limit = {
					exists = scope:guardian
					exists = scope:new_stewardship_educator
					NOT = { has_relation_guardian = scope:new_stewardship_educator }
				}
				remove_guardian_effect = {
					GUARDIAN = scope:guardian
					WARD = scope:focus_child
					RETURN_WARD = no
					HIDE_OPINION = yes
				}
			}
			if = {
				limit = {
					exists = scope:new_stewardship_educator
					NOT = { has_relation_guardian = scope:new_stewardship_educator }
				}
				set_relation_guardian = scope:new_stewardship_educator
			}
			else_if = {
				limit = {
					NOT = { exists = scope:new_stewardship_educator }
				}
				stress_impact = {
					base = minor_stress_impact_gain
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = {
		trigger = {
			scope:focus_child = {
				OR = {
					has_trait = rowdy
					has_trait = charming
				}
			}
		}
		name = {
			trigger = { exists = scope:new_intrigue_educator }
			text = lmf_heir.1503.e #switch to intrigue, new tutor
		}
		name = {
			trigger = { NOT = { exists = scope:new_intrigue_educator } }
			text = lmf_heir.1503.f #switch to intrigue, no new tutor
		}
		custom_tooltip = lmf_heir.1503.c.tt_change
		if = {
			limit = { exists = scope:new_intrigue_educator }
			custom_tooltip = lmf_heir.1503.c.tt_tutor
		}
		else = {
			custom_tooltip = lmf_heir.1503.tt_no_tutor
		}
		hidden_effect = {
			scope:focus_child = {
				set_focus = education_intrigue
				change_variable = {
					name = education_intrigue_variable
					add = scope:focus_child.age
				}
			}
		}
		scope:focus_child = {
			add_intrigue_skill = 1
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			if = {
				limit = {
					exists = scope:guardian
					exists = scope:new_intrigue_educator
					NOT = { has_relation_guardian = scope:new_intrigue_educator }
				}
				remove_guardian_effect = {
					GUARDIAN = scope:guardian
					WARD = scope:focus_child
					RETURN_WARD = no
					HIDE_OPINION = yes
				}
			}
			if = {
				limit = {
					exists = scope:new_intrigue_educator
					NOT = { has_relation_guardian = scope:new_intrigue_educator }
				}
				set_relation_guardian = scope:new_intrigue_educator
			}
			else_if = {
				limit = {
					NOT = { exists = scope:new_intrigue_educator }
				}
				stress_impact = {
					base = minor_stress_impact_gain
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = {
		trigger = {
			scope:focus_child = {
				OR = {
					has_trait = pensive
					has_trait = curious
				}
			}
		}
		name = {
			trigger = { exists = scope:new_learning_educator }
			text = lmf_heir.1503.g #switch to learning, new tutor
		}
		name = {
			trigger = { NOT = { exists = scope:new_learning_educator } }
			text = lmf_heir.1503.h #switch to learning, no new tutor
		}
		custom_tooltip = lmf_heir.1503.d.tt_change
		if = {
			limit = { exists = scope:new_learning_educator }
			custom_tooltip = lmf_heir.1503.d.tt_tutor
		}
		else = {
			custom_tooltip = lmf_heir.1503.tt_no_tutor
		}
		hidden_effect = {
			scope:focus_child = {
				set_focus = education_learning
				change_variable = {
					name = education_learning_variable
					add = scope:focus_child.age
				}
			}
		}
		scope:focus_child = {
			add_learning_skill = 1
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			if = {
				limit = {
					exists = scope:guardian
					exists = scope:new_learning_educator
					NOT = { has_relation_guardian = scope:new_learning_educator }
				}
				remove_guardian_effect = {
					GUARDIAN = scope:guardian
					WARD = scope:focus_child
					RETURN_WARD = no
					HIDE_OPINION = yes
				}
			}
			if = {
				limit = {
					exists = scope:new_learning_educator
					NOT = { has_relation_guardian = scope:new_learning_educator }
				}
				set_relation_guardian = scope:new_learning_educator
			}
			else_if = {
				limit = {
					NOT = { exists = scope:new_learning_educator }
				}
				stress_impact = {
					base = minor_stress_impact_gain
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = {
		name = lmf_heir.1503.i #no, stay with current studies
		stress_impact = {
			base = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			callous = minor_stress_impact_loss
		}
		custom_tooltip = bp2_yearly.1030.b.tt
		#To avoid an empty random list
		hidden_effect = {
			scope:focus_child = { education_point_acquisition_effect = yes }
		}
		scope:focus_child = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
			stress_impact = {
				base = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 2
				has_trait = diligent
			}
			modifier = {
				factor = 2
				has_trait = callous
			}
			modifier = {
				factor = 3
				NOT = { has_trait = compassionate }
				scope:focus_child = {
					is_player_heir_of = root
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
			}
			ai_value_modifier = {
				ai_compassion = -1
			}
			min = 0
		}
	}
}

# Non-combatant daughter of 8+ wants to take up the blade
lmf_heir.1504 = {
	type = character_event

	hidden = yes

	trigger = {
		has_bp2_dlc_trigger = yes
		age >= 8
		age <= 14
		is_female = yes
		has_dynasty = yes
		has_focus = education_martial
		prowess >= 4
		exists = host
		is_playable_character = no
		host = { save_temporary_scope_as = current_host }
		scope:current_host = { is_adult = yes }
		OR = {
			is_child_of = scope:current_host
			is_sibling_of = scope:current_host
			is_nibling_of = scope:current_host
			is_grandchild_of = scope:current_host
			is_great_grandchild_of = scope:current_host
		}
		OR = {
			has_trait = rowdy
			has_trait = bossy
			any_relation = {
				type = guardian
				sex_same_as = root
				has_character_modifier = ignores_gender_army_rules
			}
		}
		has_good_martial_trait_trigger = yes
		has_bad_martial_trait_trigger = no
		has_recoverable_disease_trigger = no

		NOR = {
			host = root
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:current_host }
			scope:current_host.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
			scope:current_host.culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
			scope:current_host = { has_character_flag = had_lmfmod_1500_event_daughter }
			has_character_flag = had_lmfmod_1500_event
			has_character_flag = had_lmfmod_1502_event
			has_character_flag = had_lmfmod_1504_event
			has_character_flag = might_ignore_gender_army_rules
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			has_trait = brave
			add = 2
		}
		modifier = {
			prowess >= 6
			add = 0.5
		}
		modifier = {
			prowess >= 8
			add = 0.5
		}
		modifier = {
			martial >= 6
			add = 0.5
		}
		modifier = {
			martial >= 8
			add = 0.5
		}
		modifier = {
			religion = { exists = var:variable_ghw_unlocked }
			has_trait = zealous
			add = 1
		}
		modifier = {
			any_relation = {
				type = guardian
				sex_same_as = root
			}
			add = 1
		}
		modifier = {
			host = {
				any_courtier = {
					sex_same_as = root
					has_character_modifier = ignores_gender_army_rules
				}
			}
			add = 1
		}
	}

	immediate = {
		add_character_flag = had_lmfmod_1504_event
		save_scope_as = focus_child
		host = {
			add_character_flag = had_lmfmod_1500_event_daughter
			trigger_event = lmf_heir.1505
		}
	}
}

lmf_heir.1505 = {
	type = character_event
	title = lmf_heir.1505.t
	desc = lmf_heir.1505.desc
	theme = family

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:focus_child
		animation = aggressive_wooden_sword
	}
	override_background = { reference = army_camp }

	option = {
		name = lmf_heir.1505.a #Let her learn proper bladecraft
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_zeal = -0.5
			}
			min = 0
		}
		stress_impact = {
			base = minor_stress_impact_gain
			compassionate = minor_stress_impact_loss
			zealous = minor_stress_impact_gain
		}
		custom_tooltip = bp2_yearly.1030.b.tt
		scope:focus_child = {
			add_martial_skill = 1
			add_prowess_skill = 2
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			hidden_effect = {
				education_point_acquisition_effect = yes
				add_character_flag = {
					flag = might_ignore_gender_army_rules
					years = 10
				}
			}
		}
	}
	option = {
		name = lmf_heir.1505.b #No, that would be inappropriate
		scope:focus_child = {
			add_martial_skill = 1
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
			stress_impact = {
				base = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 75
		}
	}
}

# Check for female fighter on adulthood
lmf_heir.1506 = {
	type = character_event

	hidden = yes

	trigger = {
		is_adult = yes
		is_female = yes
		has_character_flag = might_ignore_gender_army_rules
	}

	immediate = {
		if = {
			limit = {
				OR = {
					is_playable_character = yes
					has_education_martial_trigger = no
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
					culture = { has_cultural_parameter = has_access_to_shieldmaidens }
					culture = { has_cultural_parameter = high_prowess_ignores_knight_restrictions }
				}
			}
			remove_character_flag = might_ignore_gender_army_rules
		}
		else_if = {
			limit = {
				NOT = { exists = host }
				OR = {
					has_good_martial_trait_trigger = no
					has_bad_martial_trait_trigger = yes
					has_trait = education_martial_1
					prowess < 10
				}
			}
			remove_character_flag = might_ignore_gender_army_rules
		}
		else_if = {
			limit = {
				NOT = { exists = host }
			}
			remove_character_flag = might_ignore_gender_army_rules
			add_character_modifier = ignores_gender_army_rules
		}
		else = {
			save_scope_as = focus_child
			host = { trigger_event = lmf_heir.1507 }
		}
	}
}

lmf_heir.1507 = {
	type = character_event
	title = lmf_heir.1507.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:martial_success = flag:yes }
				desc = lmf_heir.1507.success
			}
			desc = lmf_heir.1507.failure
		}
	}
	theme = family

	left_portrait = {
		character = scope:focus_child
		triggered_animation = {
			trigger = { scope:martial_success = flag:no }
			animation = shame
		}
		animation = celebrate_sword
	}
	override_background = { reference = army_camp }

	immediate = {
		hidden_effect = {
			scope:focus_child = {
				add_character_flag = wear_armor
				if = {
					limit = {
						OR = {
							has_good_martial_trait_trigger = no
							has_bad_martial_trait_trigger = yes
							has_trait = education_martial_1
							prowess < 10
						}
					}
					save_scope_value_as = {
						name = martial_success
						value = flag:no
					}
				}
				else = {
					save_scope_value_as = {
						name = martial_success
						value = flag:yes
					}
				}
			}
		}
	}

	option = {
		trigger = { scope:martial_success = flag:yes }
		name = lmf_heir.1507.a
		scope:focus_child = {
			add_prestige = medium_prestige_gain
			stress_impact = { base = medium_stress_impact_loss }
			remove_character_flag = might_ignore_gender_army_rules
			add_character_modifier = ignores_gender_army_rules
		}
	}
	option = {
		trigger = { scope:martial_success = flag:no }
		name = lmf_heir.1507.b
		add_prestige = medium_prestige_loss
		scope:focus_child = {
			add_prestige = minor_prestige_loss
			stress_impact = { base = medium_stress_impact_gain }
			remove_character_flag = might_ignore_gender_army_rules
		}
	}

	after = {
		hidden_effect = {
			scope:focus_child = { remove_character_flag = wear_armor }
		}
	}
}

# Child wants to marry for love
lmf_heir.1510 = {
	type = character_event

	hidden = yes

	trigger = {
		age >= 12
		is_betrothed = no
		is_married = no
		has_dynasty = yes
		is_playable_character = no
		has_recoverable_disease_trigger = no
		basic_is_available_ai = yes
		exists = host
		exists = matchmaker
		ai_boldness > 0
		can_marry_common_trigger = yes
		OR = {
			is_non_courtier_marriage_candidate = { RULER = host }
			AND = {
				is_courtier_of = host
				OR = {
					is_close_family_of = host
					is_great_grandchild_of = host
				}
			}
		}
		NOR = {
			has_character_flag = cannot_get_will_not_wed_trait
			has_variable = is_in_marriage_introduction
			has_trait = content
			has_trait = humble
			host = root
		}
		host = {
			is_physically_able_adult = yes
			highest_held_title_tier > tier_county
			this = root.matchmaker
			OR = {
				is_parent_of = root
				is_grandparent_of = root
				is_great_grandparent_of = root
			}
			NOR = {
				has_government = mercenary_government
				has_government = republic_government
				has_government = theocracy_government
				has_government = holy_order_government
				has_relation_rival = root
				has_imprisonment_reason = root
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			ai_boldness >= 50
		}
		modifier = {
			add = -0.5
			ai_boldness < 20
		}
		modifier = {
			add = 2
			OR = {
				has_sexuality = homosexual
				has_sexuality = asexual
			}
		}
		modifier = {
			add = 2
			has_trait = chaste
		}
		modifier = {
			add = 1
			likely_to_take_lover_trigger = yes
		}
		modifier = {
			add = 1
			any_close_family_member = {
				is_close_family_of = root
				exists = host
				host = root.host
				has_opinion_modifier = {
					target = root.host
					modifier = allowed_marry_for_love_opinion
				}
			}
		}
	}

	immediate = {
		random_list = {
			100 = { #asks for right to marry on own
				modifier = {
					add = 100
					any_sibling = {
						has_opinion_modifier = {
							target = root.host
							modifier = allowed_marry_for_love_opinion
						}
					}
				}
				modifier = {
					add = 50
					OR = {
						has_sexuality = homosexual
						has_sexuality = asexual
					}
				}
				modifier = {
					add = 50
					OR = {
						has_trait = chaste
						likely_to_take_lover_trigger = yes
					}
				}
				ai_value_modifier = {
					ai_boldness = 1
				}
				modifier = {
					factor = 0.5
					OR = {
						AND = {
							faith = { has_doctrine_parameter = male_dominated_law }
							is_female = yes
							NOR = {
								has_character_flag = might_ignore_gender_army_rules
								has_character_modifier = ignores_gender_army_rules
							}
						}
						AND = {
							faith = { has_doctrine_parameter = female_dominated_law }
							is_male = yes
						}
					}
				}
				min = 0
				save_scope_as = focus_child
				host = { trigger_event = lmf_heir.1511 }
			}
			100 = { #does not ask (at least for another three years)
				modifier = {
					add = 100
					any_sibling = {
						has_opinion_modifier = {
							target = root.host
							modifier = refused_marry_for_love_opinion
						}
					}
				}
				add_character_flag = { flag = cannot_get_will_not_wed_trait years = 3 }
			}
		}
	}
}

lmf_heir.1511 = {
	type = character_event
	title = lmf_heir.1511.t
	desc = {
		desc = lmf_heir.1511.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:focus_child = {
						OR = {
							has_sexuality = homosexual
							has_sexuality = asexual
							has_trait = chaste
						}
					}
				}
				desc = lmf_heir.1511.desc.sex
			}
			triggered_desc = {
				trigger = {
					scope:focus_child = { likely_to_take_lover_trigger = yes }
				}
				desc = lmf_heir.1511.desc.lustful
			}
			triggered_desc = {
				trigger = { exists = scope:favored_sibling }
				desc = lmf_heir.1511.desc.sibling
			}
			desc = lmf_heir.1511.desc.adventure
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:focus_child = { is_female = yes }
				}
				desc = lmf_heir.1511.desc.end.female
			}
			desc = lmf_heir.1511.desc.end
		}
	}
	theme = family

	left_portrait = {
		character = scope:focus_child
		animation = personality_bold
	}

	immediate = {
		hidden_effect = {
			scope:focus_child = {
				random_sibling = {
					limit = {
						has_opinion_modifier = {
							target = root
							modifier = allowed_marry_for_love_opinion
						}
					}
					save_scope_as = favored_sibling
				}
			}
		}
	}

	option = {
		name = lmf_heir.1511.a #Very well
		scope:focus_child = {
			add_trait_force_tooltip = will_not_wed
			hidden_effect = {
				create_story = {
					type = lmf_will_not_wed_story_cycle
				}
			}
		}
		improve_relationship_effect = {
			TARGET = scope:focus_child
			REASON = allowed_to_marry_at_will
		}

		ai_chance = {
			base = 50
			opinion_modifier = {
				who = root
				opinion_target = scope:focus_child
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_compassion = 1
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1511.b #That's not going to happen
		scope:focus_child = {
			worsen_relationship_effect = {
				TARGET = root
				REASON = overrode_marriage_wishes
			}
			add_opinion = {
				target = root
				modifier = refused_marry_for_love_opinion
			}
			add_character_flag = cannot_get_will_not_wed_trait
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 50
				scope:focus_child = {
					OR = {
						AND = {
							faith = { has_doctrine_parameter = male_dominated_law }
							is_female = yes
						}
						AND = {
							faith = { has_doctrine_parameter = female_dominated_law }
							is_male = yes
						}
					}
				}
			}
			modifier = {
				add = 50
				any_ally = { count < 1 }
			}
			ai_value_modifier = {
				ai_honor = 0.5
				min = 0
			}
			min = 1
		}
	}
}

scripted_effect start_introduction_effect = {
	$SUITOR$ = {
		save_scope_as = secondary_recipient
		if = {
			limit = { exists = matchmaker }
			matchmaker = { save_scope_as = recipient }
		}
		else = { save_scope_as = recipient }
	}

	if = {
		limit = {
			scope:recipient = scope:actor
		}
		if = {
			limit = { exists = global_var:travel_the_distance_is_loaded }
			ttd_on_send_marriage_effect = yes
		}
		custom_tooltip = begin_introduction_same_court.tt
		scope:actor = { trigger_event = lmf_interaction.1322 } # Bounce event for a secondary recipient which is part of the actor's court
	}
	else_if = {
		limit = {
			scope:recipient = { is_ai = no }
		}
		scope:actor = {
			run_interaction = {
				interaction = introduce_to_marry_interaction
				actor = scope:actor
				recipient = scope:recipient
				secondary_actor = scope:secondary_actor
				secondary_recipient = scope:secondary_recipient
				send_threshold = accept
			}
		}
	}
	else = {
		if = {
			limit = { exists = global_var:travel_the_distance_is_loaded }
			ttd_on_send_marriage_effect = yes
		}
		hidden_effect = {
			scope:actor = {
				remove_marriage_introduction_variables = yes
				set_marriage_introduction_variables = yes
			}
			scope:secondary_actor = {
				remove_marriage_introduction_variables = yes
				set_marriage_introduction_variables = yes
			}
			save_scope_value_as = {
				name = secondary_actor_is_pleased
				value = yes
			}
		}
		custom_tooltip = begin_introduction_invite_secrec.tt
		scope:recipient = { trigger_event = lmf_interaction.1302 } # Secondary Recipient reacts to coming visit
	}
}

scripted_effect check_heir_training_trait = {
	if = {
		limit = {
			NOT = { exists = scope:trainee_heir }
		}
		$HEIR$ = { save_scope_as = trainee_heir }
	}
	$HEIR$ = {
		if = {
			limit = {
				NOT = { has_trait = education_heir_training }
				var:heir_training_var >= 50
			}
			$HEIR_LIEGE$ = {
				send_interface_message = {
					type = event_generic_good
					title = lmf_heir.1530.heir_training.tt
					right_icon = $HEIR$
					$HEIR$ = {
						if = {
							limit = { has_trait = heir_in_training }
							hidden_effect = { remove_trait = heir_in_training }
						}
						add_trait_force_tooltip = education_heir_training_1
					}
				}
			}
		}
		else_if = {
			limit = {
				has_trait = education_heir_training_1
				var:heir_training_var >= 100
			}
			$HEIR_LIEGE$ = {
				send_interface_message = {
					type = event_generic_good
					title = lmf_heir.1530.heir_training.tt
					right_icon = $HEIR$
					$HEIR$ = {
						hidden_effect = { remove_trait = education_heir_training_1 }
						add_trait_force_tooltip = education_heir_training_2
					}
				}
			}
		}
		else_if = {
			limit = {
				has_trait = education_heir_training_2
				var:heir_training_var >= 150
			}
			$HEIR_LIEGE$ = {
				send_interface_message = {
					type = event_generic_good
					title = lmf_heir.1530.heir_training.tt
					right_icon = $HEIR$
					$HEIR$ = {
						hidden_effect = { remove_trait = education_heir_training_2 }
						add_trait_force_tooltip = education_heir_training_3
					}
				}
			}
		}
		else_if = {
			limit = {
				has_trait = education_heir_training_3
				var:heir_training_var >= 200
			}
			$HEIR_LIEGE$ = {
				send_interface_message = {
					type = event_generic_good
					title = lmf_heir.1530.heir_training.tt
					right_icon = $HEIR$
					$HEIR$ = {
						hidden_effect = { remove_trait = education_heir_training_3 }
						add_trait_force_tooltip = education_heir_training_4
					}
				}
			}
		}
	}
}

scripted_effect allow_heir_marriage_effect = {
	if = {
		limit = {
			reverse_has_opinion_modifier = {
				modifier = refused_marriage_permission_opinion
				target = scope:heir
			}
		}
		scope:heir = {
			remove_opinion = { target = root modifier = refused_marriage_permission_opinion }
		}
	}
	if = {
		limit = {
			reverse_has_opinion_modifier = {
				modifier = refused_marriage_permission_opinion
				target = scope:heir_lover
			}
		}
		scope:heir_lover = {
			remove_opinion = { target = root modifier = refused_marriage_permission_opinion }
		}
	}
	marriage_permission_given_effect = yes
	courtiers_marry_effect = yes
}

# Family member suggests suitors for introduction
lmf_heir.1516 = {
	type = character_event
	title = lmf_heir.1516.t
	desc = {
		desc = lmf_heir.1516.desc.start
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:suitor_3 }
				desc = lmf_heir.1516.desc.three
			}
			triggered_desc = {
				trigger = { exists = scope:suitor_2 }
				desc = lmf_heir.1516.desc.two
			}
			desc = lmf_heir.1516.desc.one
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:matrilineal ?= yes }
				desc = lmf_heir.1516.desc.matrilineal
			}
			desc = lmf_heir.1516.desc.normal
		}
		desc = lmf_heir.1516.desc.end
	}
	theme = family

	left_portrait = {
		character = scope:secondary_actor
		animation = thinking
		camera = camera_event_right
	}
	override_background = { reference = study }
	lower_left_portrait = scope:suitor_1
	lower_right_portrait = scope:suitor_3
	lower_center_portrait = scope:suitor_2

	immediate = {
		scope:secondary_actor = { no_hat_respectful_effect = yes }
		scope:suitor_1 ?= { no_hat_respectful_effect = yes }
		scope:suitor_2 ?= { no_hat_respectful_effect = yes }
		scope:suitor_3 ?= { no_hat_respectful_effect = yes }
	}

	option = {
		trigger = { exists = scope:suitor_1 }
		name = lmf_heir.1516.a #pick suitor_1
		get_heir_match_lineality_effect = { HEIR = scope:secondary_actor MATCH = scope:suitor_1 }
		start_introduction_effect = { SUITOR = scope:suitor_1 }
		if = {
			limit = { scope:secondary_actor = { is_female = yes } }
			if = {
				limit = {
					heir_match_is_matrilineal = { HEIR = scope:secondary_actor MATCH = scope:suitor_1 }
				}
				custom_tooltip = lmf_heir.1516.warning.matrilineal_tt
			}
			else = {
				custom_tooltip = lmf_heir.1516.warning.patrilineal_tt
			}
		}
		ai_chance = {
			base = 35
			modifier = {
				add = -10
				scope:suitor_1 = { is_lowborn = yes }
			}
			modifier = {
				add = {
					value = scope:suitor_1.highest_held_title_tier
					multiply = 10
				}
				scope:suitor_1 = { is_ruler = yes }
			}
			modifier = {
				add = 20
				scope:suitor_1 = {
					is_ruler = no
					any_heir_title = { tier >= tier_county }
				}
			}
			modifier = {
				add = 10
				scope:suitor_1 = {
					any_close_family_member = {
						is_ruler = yes
						is_close_family_of = scope:suitor_1
					}
				}
			}
			modifier = {
				scope:suitor_1.sum_of_all_skills_and_prowess_value >= 60
				add = {
					value = scope:suitor_1.sum_of_all_skills_and_prowess_value
					divide = 4
				}
			}
		}
	}
	option = {
		trigger = { exists = scope:suitor_2 }
		name = lmf_heir.1516.b #pick suitor_2
		get_heir_match_lineality_effect = { HEIR = scope:secondary_actor MATCH = scope:suitor_2 }
		start_introduction_effect = { SUITOR = scope:suitor_2 }
		if = {
			limit = { scope:secondary_actor = { is_female = yes } }
			if = {
				limit = {
					heir_match_is_matrilineal = { HEIR = scope:secondary_actor MATCH = scope:suitor_2 }
				}
				custom_tooltip = lmf_heir.1516.warning.matrilineal_tt
			}
			else = {
				custom_tooltip = lmf_heir.1516.warning.patrilineal_tt
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				add = -10
				scope:suitor_2 = { is_lowborn = yes }
			}
			modifier = {
				add = {
					value = scope:suitor_2.highest_held_title_tier
					multiply = 10
				}
				scope:suitor_2 = { is_ruler = yes }
			}
			modifier = {
				add = 20
				scope:suitor_2 = {
					is_ruler = no
					any_heir_title = { tier >= tier_county }
				}
			}
			modifier = {
				add = 10
				scope:suitor_2 = {
					any_close_family_member = {
						is_ruler = yes
						is_close_family_of = scope:suitor_2
					}
				}
			}
			modifier = {
				scope:suitor_2.sum_of_all_skills_and_prowess_value >= 60
				add = {
					value = scope:suitor_1.sum_of_all_skills_and_prowess_value
					divide = 4
				}
			}
		}
	}
	option = {
		trigger = { exists = scope:suitor_3 }
		name = lmf_heir.1516.c #pick suitor_3
		get_heir_match_lineality_effect = { HEIR = scope:secondary_actor MATCH = scope:suitor_3 }
		start_introduction_effect = { SUITOR = scope:suitor_3 }
		if = {
			limit = { scope:secondary_actor = { is_female = yes } }
			if = {
				limit = {
					heir_match_is_matrilineal = { HEIR = scope:secondary_actor MATCH = scope:suitor_3 }
				}
				custom_tooltip = lmf_heir.1516.warning.matrilineal_tt
			}
			else = {
				custom_tooltip = lmf_heir.1516.warning.patrilineal_tt
			}
		}
		ai_chance = {
			base = 15
			modifier = {
				add = -10
				scope:suitor_3 = { is_lowborn = yes }
			}
			modifier = {
				add = {
					value = scope:suitor_2.highest_held_title_tier
					multiply = 10
				}
				scope:suitor_3 = { is_ruler = yes }
			}
			modifier = {
				add = 20
				scope:suitor_3 = {
					is_ruler = no
					any_heir_title = { tier >= tier_county }
				}
			}
			modifier = {
				add = 10
				scope:suitor_3 = {
					any_close_family_member = {
						is_ruler = yes
						is_close_family_of = scope:suitor_3
					}
				}
			}
			modifier = {
				scope:suitor_3.sum_of_all_skills_and_prowess_value >= 60
				add = {
					value = scope:suitor_1.sum_of_all_skills_and_prowess_value
					divide = 4
				}
			}
		}
	}
	option = {
		name = lmf_heir.1516.d #I'll find someone for you
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_honor = -0.5
				min = -24
			}
		}
	}

	after = {
		scope:secondary_actor = { remove_no_hat_effect = yes }
		scope:suitor_1 ?= { remove_no_hat_effect = yes }
		scope:suitor_2 ?= { remove_no_hat_effect = yes }
		scope:suitor_3 ?= { remove_no_hat_effect = yes }
	}
}

# Family member abandons Will Not Wed trait
lmf_heir.1517 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:focus_child = { has_character_flag = directed_to_marry } }
				desc = lmf_heir.1517.t.directed
			}
			desc = lmf_heir.1517.t
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:focus_child = { has_character_flag = directed_to_marry } }
				desc = lmf_heir.1517.desc.directed
			}
			desc = lmf_heir.1517.desc
		}
	}
	theme = family

	left_portrait = {
		character = scope:focus_child
		animation = shame
	}

	option = {
		name = {
			trigger = { scope:focus_child = { has_character_flag = directed_to_marry } }
			text = lmf_heir.1517.b
		}
		name = {
			trigger = { scope:focus_child = { NOT = { has_character_flag = directed_to_marry } } }
			text = lmf_heir.1517.a
		}
		scope:focus_child = {
			remove_trait_force_tooltip = will_not_wed
			add_character_flag = cannot_get_will_not_wed_trait
			hidden_effect = {
				random_owned_story = {
					type = lmf_will_not_wed_story_cycle
					end_story = yes
				}
			}
		}
	}
}

# Family member asks to return from adventures
lmf_heir.1518 = {
	type = character_event
	title = lmf_heir.1518.t
	desc = lmf_heir.1518.desc
	theme = family

	left_portrait = {
		character = scope:focus_child
		animation = shame
		outfit_tags = { travel_cloak }
	}
	override_background = { reference = terrain }

	immediate = {
		scope:focus_child = {
			remove_trait_force_tooltip = will_not_wed
			add_character_flag = cannot_get_will_not_wed_trait
			if = {
				limit = { has_character_modifier = lust_for_adventure }
				remove_character_modifier = lust_for_adventure
			}
			hidden_effect = {
				random_owned_story = {
					type = lmf_will_not_wed_story_cycle
					end_story = yes
				}
			}
		}
	}

	option = {
		name = lmf_heir.1518.a #Bring them back
		scope:focus_child = {
			every_traveling_family_member = {
				root = { add_courtier = prev }
				hidden_effect = { return_to_court = yes }
			}
		}
		ai_chance = {
			base = 100
		}
	}
	option = {
		name = lmf_heir.1518.b #They're fine where they are
		ai_chance = {
			base = 0
		}
	}
}

scripted_trigger can_be_ordered_to_wed_by = {
	OR = {
		is_ai = yes
		this = $LIEGE$
	}
	OR = {
		this = $LIEGE$
		is_courtier_of = $LIEGE$
		is_pool_character = yes
		is_vassal_of = $LIEGE$
		AND = {
			is_courtier = yes
			liege = {
				is_ai = yes
				OR = {
					has_government = mercenary_government
					has_government = republic_government
					has_government = theocracy_government
					has_government = holy_order_government
					is_vassal_of = $LIEGE$
				}
			}
		}
	}
}

scripted_trigger can_be_ordered_to_abandon_vows_by = {
	OR = {
		has_trait = devoted
		has_trait = order_member
	}
	NOR = {
		has_trait = seclusion
		has_trait = eunuch
		has_trait = widowed
		is_ruler = yes
	}
	can_be_ordered_to_wed_by = { LIEGE = $LIEGE$ }
}

scripted_trigger can_be_ordered_to_break_betrothal_by = {
	is_betrothed = yes
	is_ai = yes
	has_been_promised_grand_wedding = no
	betrothed = {
		OR = {
			is_ai = yes
			this = $LIEGE$
		}
		trigger_if = {
			limit = { is_courtier = yes }
			OR = {
				liege = { is_ai = yes }
				liege = $LIEGE$
			}
		}
	}
	OR = {
		can_be_ordered_to_wed_by = { LIEGE = $LIEGE$ }
		betrothed = {
			can_be_ordered_to_wed_by = { LIEGE = $LIEGE$ }
		}
	}
}

scripted_trigger can_reverse_marriage_refusal = {
	can_be_introduced_character_trigger = { CHARACTER = $CHARACTER$ }
	would_need_elopement_to_marry_target = { TARGET = $CHARACTER$ }
	can_be_ordered_to_wed_by = { LIEGE = $LIEGE$ }
}

# Host discovers that family member with Will Not Wed has a secret lover they can't marry
lmf_heir.1519 = {
	type = character_event
	title = lmf_heir.1519.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:knows_secret }
				desc = lmf_heir.1519.desc.start.secret
			}
			desc = lmf_heir.1519.desc.start
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:heir = { sex_same_as = scope:heir_lover }
					allowed_to_marry_same_sex_trigger = no
				}
				desc = lmf_heir.1519.desc.samesex
			}
			triggered_desc = {
				trigger = { scope:heir_lover = { has_trait = devoted } }
				desc = lmf_heir.1519.desc.devoted
			}
			triggered_desc = {
				trigger = { scope:heir_lover = { has_trait = order_member } }
				desc = lmf_heir.1519.desc.order
			}
			triggered_desc = {
				trigger = { scope:heir_lover = { is_married = yes } }
				desc = lmf_heir.1519.desc.married
			}
			triggered_desc = {
				trigger = { scope:heir_lover = { is_betrothed = yes } }
				desc = lmf_heir.1519.desc.betrothed
			}
			triggered_desc = {
				trigger = {
					scope:heir = { has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root } }
					scope:heir_lover = { has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root } }
				}
				desc = lmf_heir.1519.desc.permission.both
			}
			triggered_desc = {
				trigger = {
					scope:heir = {
						has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root }
						is_female = yes
					}
				}
				desc = lmf_heir.1519.desc.permission.heir.woman
			}
			triggered_desc = {
				trigger = {
					scope:heir = {
						has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root }
						is_female = no
					}
				}
				desc = lmf_heir.1519.desc.permission.heir.man
			}
			triggered_desc = {
				trigger = {
					scope:heir_lover = {
						has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root }
						is_female = yes
					}
				}
				desc = lmf_heir.1519.desc.permission.lover.woman
			}
			triggered_desc = {
				trigger = {
					scope:heir_lover = {
						has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root }
						is_female = no
					}
				}
				desc = lmf_heir.1519.desc.permission.lover.man
			}
			desc = lmf_heir.1519.desc.generic
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:heir_lover = {
						OR = {
							can_be_ordered_to_abandon_vows_by = { LIEGE = root }
							can_be_ordered_to_break_betrothal_by = { LIEGE = root }
							can_reverse_marriage_refusal = { CHARACTER = scope:heir LIEGE = root }
						}
					}
				}
				desc = lmf_heir.1519.desc.end.canact
			}
			desc = lmf_heir.1519.desc.end
		}
	}
	theme = family

	left_portrait = {
		character = scope:heir
		animation = shame
	}
	override_background = { reference = relaxing_room }
	lower_right_portrait = scope:heir_lover

	immediate = {
		scope:heir = {
			random_owned_story = {
				type = lmf_will_not_wed_story_cycle
				set_variable = { name = willnotwed_had_lover_revealed value = yes }
			}
			if = {
				limit = {
					any_secret = {
						type = secret_lover
						secret_target = scope:heir_lover
						NOT = { is_known_by = root }
					}
				}
				random_secret = {
					type = secret_lover
					limit = {
						secret_target = scope:heir_lover
						NOT = { is_known_by = root }
					}
					reveal_to = root
				}
			}
			else = {
				save_scope_value_as = { name = knows_secret value = yes }
			}
			save_scope_as = proposer
			save_scope_as = owner
		}
		scope:heir_lover = {
			save_scope_as = proposer_target
			save_scope_as = target
		}
	}

	option = {
		name = lmf_heir.1519.a #They must break up at once

		if = {
			limit = { has_hook = scope:heir }
			remove_hook = { target = scope:heir }
		}
		scope:heir = {
			if = {
				limit = { is_imprisoned_by = root }
				release_from_prison = yes
			}
			if = {
				limit = { target_is_liege_or_above = root }
				consume_all_criminal_reasons_effect = {
					LIEGE = root
					CRIMINAL = scope:heir
				}
			}
		}
		if = {
			limit = {
				scope:heir = { has_relation_soulmate = scope:heir_lover }
			}
			scope:heir = {
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = interfered_in_my_romance
					OPINION = -50
				}
			}
			scope:heir_lover = {
				worsen_relationship_effect = {
					TARGET = root
					REASON = interfered_in_my_romance
				}
			}
		}
		else = {
			scope:heir = {
				worsen_relationship_effect = {
					TARGET = root
					REASON = interfered_in_my_romance
				}
			}
		}
		lover_breakup_effect = {
			BREAKER = scope:heir
			LOVER = scope:heir_lover
		}

		ai_chance = {
			base = 50
			modifier = {
				factor = 3
				scope:heir = { sex_same_as = scope:heir_lover }
				ai_zeal >= low_positive_ai_value
			}
			modifier = {
				factor = 2
				scope:heir = { any_heir_title = {} }
			}
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}
	option = {
		trigger = {
			scope:heir_lover = {
				can_reverse_marriage_refusal = { CHARACTER = scope:heir LIEGE = root }
			}
		}
		name = lmf_heir.1519.b #I give my leave for them to marry

		allow_heir_marriage_effect = yes

		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				scope:heir_lover = { has_no_particular_noble_roots_trigger = yes }
			}
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			min = 0
		}
	}
	option = {
		trigger = {
			scope:heir_lover = {
				can_be_ordered_to_abandon_vows_by = { LIEGE = root }
				can_elope_character_trigger = { CHARACTER = scope:heir }
			}
		}
		name = lmf_heir.1519.c #They must abandon their vows and marry

		scope:heir_lover = { remove_religious_traits_effect = yes }
		allow_heir_marriage_effect = yes

		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				scope:heir_lover = { has_no_particular_noble_roots_trigger = yes }
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_zeal = -0.5
			}
			min = 0
		}
	}
	option = {
		trigger = {
			scope:heir_lover = {
				can_be_ordered_to_break_betrothal_by = { LIEGE = root }
				could_be_introduced_character_trigger = { CHARACTER = scope:heir }
			}
		}
		name = lmf_heir.1519.d #They must abandon their betrothal and marry

		scope:heir_lover = { break_betrothal = scope:heir_lover.betrothed }
		allow_heir_marriage_effect = yes

		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				scope:heir_lover = { has_no_particular_noble_roots_trigger = yes }
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = -0.3
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1519.e #I will leave the happy lovebirds to it
		ai_chance = {
			base = 20
			modifier = {
				add = 80
				scope:heir = { sex_same_as = scope:heir_lover }
				OR = {
					has_sexuality = homosexual
					has_sexuality = bisexual
				}
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = -0.5
			}
			min = 1
		}
	}
}

# Bounce event to re-check lover marriage availability
lmf_heir.1520 = {
	type = character_event
	hidden = yes

	trigger = {
		exists = host
		has_trait = will_not_wed
		is_physically_able_ai_adult = yes
		num_of_relation_lover = 1
		trigger_if = {
			limit = { NOT = { has_character_flag = directed_to_marry } }
			might_agree_to_marriage = yes
		}
		OR = {
			is_non_courtier_marriage_candidate = { RULER = host }
			AND = {
				is_courtier = yes
				OR = {
					is_close_or_extended_family_of = host
					is_great_grandchild_of = host
				}
			}
		}
		scope:target = {
			has_relation_lover = root
			is_physically_able_ai_adult = yes
			NOR = {
				is_close_or_extended_family_of = root
				has_relation_rival = root.host
				has_relation_lover = root.host
				root.host = { has_imprisonment_reason = prev }
				is_consort_of = root.host
				betrothed ?= root.host
				is_concubine = yes
				is_diarch = yes
				would_need_elopement_to_marry_target = { TARGET = root }
			}
			might_agree_to_marriage = yes
			can_be_introduced_character_trigger = { CHARACTER = root }
		}
	}

	immediate = {
		# check to see if they're both available
		if = {
			limit = {
				scope:owner = {
					is_available = yes
					bp2_valid_for_standard_interactions_trigger = yes
				}
				scope:target = {
					is_available = yes
					bp2_valid_for_standard_interactions_trigger = yes
					NOR = {
						is_at_war_with = root.story_owner.host
						liege ?= { is_at_war_with = root.story_owner.host }
						AND = {
							exists = inspiration
							has_completed_inspiration = no
						}
					}
				}
			}
			# proceed with marriage request
			find_proposer_and_lieges_effect = yes
			if = {
				limit = { exists = scope:proposer_liege }
				scope:proposer_liege = { trigger_event = lmf_scheme.1031 }
			}
			else = {
				scope:proposer_target_liege = { trigger_event = lmf_scheme.1032 }
			}
		}
	}
}

# Bounce event to re-check lover discovery availability
lmf_heir.1521 = {
	type = character_event
	hidden = yes

	trigger = {
		exists = host
		has_trait = will_not_wed
		is_physically_able_ai_adult = yes
		num_of_relation_lover = 1
		trigger_if = {
			limit = { NOT = { has_character_flag = directed_to_marry } }
			might_agree_to_marriage = yes
		}
		OR = {
			is_non_courtier_marriage_candidate = { RULER = host }
			AND = {
				is_courtier = yes
				OR = {
					is_close_or_extended_family_of = host
					is_great_grandchild_of = host
				}
			}
		}
		scope:heir_lover = {
			has_relation_lover = root
			is_physically_able_ai_adult = yes
			NOR = {
				is_close_or_extended_family_of = root
				has_relation_rival = root.host
				has_relation_lover = root.host
				root.host = { has_imprisonment_reason = prev }
				is_consort_of = root.host
				betrothed ?= root.host
				is_concubine = yes
				is_diarch = yes
			}
			OR = {
				AND = {
					can_be_introduced_character_trigger = { CHARACTER = root }
					would_need_elopement_to_marry_target = { TARGET = root }
				}
				AND = {
					NOT = {
						can_be_introduced_character_trigger = { CHARACTER = root }
					}
					OR = {
						has_trait = devoted
						has_trait = order_member
						has_trait = septon
						has_trait = silent_sister
						is_married = yes
						is_betrothed = yes
						AND = {
							allowed_to_marry_same_sex_trigger = no
							sex_same_as = root
						}
					}
				}
			}
		}
	}

	immediate = {
		# check to see if they're both available
		if = {
			limit = {
				scope:heir = {
					is_available = yes
					bp2_valid_for_standard_interactions_trigger = yes
				}
				scope:heir_lover = {
					is_available = yes
					bp2_valid_for_standard_interactions_trigger = yes
					NOR = {
						is_at_war_with = scope:heir.host
						liege ?= { is_at_war_with = scope:heir.host }
						AND = {
							exists = inspiration
							has_completed_inspiration = no
						}
					}
				}
			}
			scope:heir = {
				random = {
					chance = 75
					modifier = {
						add = 20
						NOT = {
							any_secret = {
								type = secret_lover
								secret_target = scope:heir_lover
								NOT = { is_known_by = scope:heir.host }
							}
						}
					}
					host = { trigger_event = lmf_heir.1519 }
				}
			}
		}
	}
}

# Gaining Trained Heir trait
lmf_heir.1530 = {
	type = character_event

	hidden = yes

	trigger = {
		age >= 12
		is_playable_character = no
		exists = host
		is_player_heir_of = host
		has_recoverable_disease_trigger = no
		is_incapable = no
		host = {
			is_landed = yes
			highest_held_title_tier >= tier_county
			NOR = {
				has_government = mercenary_government
				has_government = republic_government
				has_government = theocracy_government
				has_government = holy_order_government
			}
		}
	}

	immediate = {
		# check if their training can advance
		if = {
			limit = {
				is_available = yes
				NOR = {
					has_game_rule = lmf_no_heir_training
					has_trait = education_heir_training_4
				}
				OR = {
					AND = {
						is_adult = no
						num_of_relation_guardian > 0
						any_relation = {
							type = guardian
							is_imprisoned = no
							has_contagious_deadly_disease_trigger = no
							is_incapable = no
							is_at_same_location = root
							has_recoverable_disease_trigger = no
						}
					}
					AND = {
						is_adult = yes
						host = {
							is_adult = yes
							is_imprisoned = no
							has_contagious_deadly_disease_trigger = no
							is_incapable = no
							is_at_same_location = root
							has_recoverable_disease_trigger = no
						}
					}
				}
			}

			# give them the variable if they don't have it already
			if = {
				limit = {
					NOT = { has_variable = heir_training_var }
				}
				set_variable = {
					name = heir_training_var
					value = 0
				}
			}
			# give them the Heir in Training trait if they don't have it already
			root = { save_scope_as = trainee_heir }
			if = {
				limit = {
					NOR = {
						has_trait = heir_in_training
						has_trait = education_heir_training_1
						has_trait = education_heir_training_2
						has_trait = education_heir_training_3
						has_trait = education_heir_training_4
					}
				}
				host = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1530.heir_begin_training.tt
						right_icon = scope:trainee_heir
						scope:trainee_heir = {
							add_trait_force_tooltip = heir_in_training
						}
					}
				}
			}

			# figure out who's training them
			if = {
				limit = { is_adult = yes }
				host = { save_scope_as = trainer }
			}
			else = {
				random_relation = {
					type = guardian
					save_scope_as = trainer
				}
			}

			change_variable = {
				name = heir_training_var
				add = heir_training_value
			}

			# now see if the trait should advance
			check_heir_training_trait = { HEIR = root HEIR_LIEGE = root.host }
		}
	}
}

# Yearly check for courtiers of the liege's dynasty, to give them a better chance of at least one child
lmf_heir.1531 = {
	type = character_event

	hidden = yes

	immediate = {
		every_courtier = {
			limit = {
				is_married = yes
				is_female = yes
			}
			trigger_event = {
				id = lmf_heir.1532
				days = { 1 180 }
			}
		}
	}
}

lmf_heir.1532 = {
	type = character_event

	hidden = yes

	trigger = {
		is_courtier = yes
		primary_spouse ?= { is_courtier = yes }
		is_available_quick = {
			incapable = no
			imprisoned = no
		}
		has_recoverable_disease_trigger = no
		is_pregnant = no
		NOR = {
			has_character_flag = lmf_no_children
			primary_spouse = { has_character_flag = lmf_no_children }
		}
		OR = {
			is_player_heir_of = liege
			is_close_or_extended_family_of = liege
			any_heir_title = { tier >= tier_county }
			any_pretender_title = {
				tier >= tier_county
				place_in_line_of_succession = { target = prev value < 3 }
			}
			any_claim = {
				pressed = yes
				tier >= tier_county
			}
			primary_spouse = {
				OR = {
					AND = {
						exists = liege
						OR = {
							is_player_heir_of = liege
							is_close_or_extended_family_of = liege
						}
					}
					is_player_heir_of = root.liege
					is_close_or_extended_family_of = root.liege
					any_heir_title = { tier >= tier_county }
					any_pretender_title = {
						tier >= tier_county
						place_in_line_of_succession = { target = prev value < 3 }
					}
					any_claim = {
						pressed = yes
						tier >= tier_county
					}
				}
			}
		}
		liege = {
			highest_held_title_tier >= tier_county
			NOR = {
				has_government = mercenary_government
				has_government = republic_government
				has_government = theocracy_government
				has_government = holy_order_government
			}
		}
		any_child = {
			is_child_of = root.primary_spouse
			count < root.num_expected_children
		}
	}

	immediate = {
		if = {
			limit = {
				primary_spouse = {
					is_available_quick = {
						incapable = no
						imprisoned = no
					}
					has_recoverable_disease_trigger = no
					possible_pregnancy_after_sex_with_character_trigger = { CHARACTER = root }
					is_in_same_location_or_activity_as = { CHARACTER = root }
				}
			}
			had_sex_with_effect = {
				CHARACTER = primary_spouse
				PREGNANCY_CHANCE = annual_chance_children
			}
		}
		if = {
			limit = {
				exists = location
				trigger_if = {
					limit = { has_game_rule = lmf_realistic_pregnancies_player_only }
					OR = {
						should_use_realistic_pregnancy_player_only = yes
						primary_spouse = { should_use_realistic_pregnancy_player_only = yes }
					}
				}
				trigger_else = {
					has_game_rule = lmf_realistic_pregnancies_active
				}
				NOR = {
					has_character_flag = made_recent_courtier_visit
					has_trait = pregnant
					has_variable = visited_by_target
				}
				primary_spouse = {
					is_courtier = yes
					NOT = { is_courtier_of = root.liege }
					exists = location
					possible_pregnancy_after_sex_with_character_trigger = { CHARACTER = root }
					is_available_ai = yes
					has_recoverable_disease_trigger = no
					is_hostage = no
					NOR = {
						has_trait = pregnant
						is_in_same_location_or_activity_as = { CHARACTER = root }
						location.county ?= { any_county_province = { any_province_epidemic = { count >= 1 } } }
						liege = { is_at_war = yes }
						liege = { has_character_modifier = isolating_modifier }
						liege.capital_county ?= { has_county_modifier = isolate_capital_decision_modifier }
						has_variable = visited_by_target
					}
					in_diplomatic_range = root
				}
			}
			save_scope_as = recipient
			add_character_flag = { flag = made_recent_courtier_visit years = 3 }
			primary_spouse = {
				save_scope_as = actor
				set_variable = { name = visited_by_target value = root }
				add_opinion = { target = root modifier = agreed_to_visit_opinion }
			}
			liege = {
				send_interface_toast = {
					type = send_interface_message
					title = lmf_scheme.1050.title
					right_icon = scope:actor
					left_icon = scope:recipient
					custom_tooltip = lmf_scheme.1050.tt
				}
			}
			# now send them for a visit
			create_story = {
				type = lmf_visit_invitation_story_cycle
				save_scope_as = story
			}
			scope:story = {
				set_variable = { name = visit_target value = scope:actor }
				if = {
					limit = { exists = scope:actor.liege.capital_province }
					set_variable = { name = visit_province value = scope:actor.liege.capital_province }
				}
				else = {
					set_variable = { name = visit_province value = scope:actor.location }
				}
				if = {
					limit = { exists = scope:recipient.liege.capital_province }
					set_variable = { name = start_province value = scope:recipient.liege.capital_province }
				}
				else = {
					set_variable = { name = start_province value = scope:recipient.location }
				}
				set_variable = { name = courtier_visit value = flag:yes }
			}
			start_travel_plan = {
				destination = scope:story.var:visit_province
				on_travel_planner_cancel_event = lmf_interaction.1502
				on_arrival_event = lmf_interaction.1505
				on_arrival_destinations = all_but_last
			}
			# and give them a small safety boost
			current_travel_plan = {
				add_travel_plan_modifier = travel_guide_modifier
			}
		}
	}
}

scripted_effect find_suitable_introduction_proposer = {
	save_scope_as = secondary_actor
	root = { save_scope_as = actor }
	save_scope_value_as = { name = matrilineal value = no }
	save_scope_value_as = { name = hook value = no }
	save_scope_value_as = { name = grand_wedding_promise value = no }
	save_scope_value_as = { name = influence_send_option value = no }
	save_scope_value_as = { name = herd_send_option value = no }

	# first sort out the total candidates
	every_opposite_sex_spouse_candidate = {
		limit = {
			is_married = no
			is_betrothed = no
			age >= 12
			trigger_if = {
				limit = {
					scope:secondary_actor = {
						is_female = yes
						age < 25
					}
				}
				age <= scope:secondary_actor.age_plus_25
				age >= scope:secondary_actor.age_minus_10
			}
			trigger_else_if = {
				limit = {
					scope:secondary_actor = { is_female = yes }
				}
				age <= scope:secondary_actor.age_plus_10
				age >= scope:secondary_actor.age_minus_10
			}
			trigger_else = {
				age <= scope:secondary_actor.age_plus_5
				age >= scope:secondary_actor.age_minus_25
			}
			trigger_if = {
				limit = { is_female = yes }
				age <= marriage_female_fertility_cutoff_age_value
			}
			has_dynasty = yes
			is_available_ai = yes
			is_healthy = yes
			has_recoverable_disease_trigger = no
			bp2_valid_for_standard_interactions_trigger = yes
			introduction_interaction_can_be_picked_trigger = yes
			is_concubine = no
			exists = location
			NOR = {
				has_variable = is_in_marriage_introduction
				has_character_flag = had_recent_introduction
				this = scope:actor
				is_close_or_extended_family_of = scope:secondary_actor
				has_opinion_modifier = { target = scope:secondary_actor modifier = refused_marriage_proposal_opinion }
				AND = {
					is_landless_ruler = yes
					faith.religious_head = this
					NOT = { scope:secondary_actor.faith = faith }
				}
			}
			save_temporary_scope_as = secondary_recipient
			OR = {
				AND = {
					is_landed = yes
					highest_held_title_tier > tier_barony
					exists = capital_province
					is_adult = yes
					is_at_war = no
					NOR = {
						has_government = mercenary_government
						has_government = republic_government
						has_government = theocracy_government
						has_government = holy_order_government
					}
					save_temporary_scope_as = recipient
				}
				AND = {
					is_courtier = yes
					NOT = { is_courtier_of = root }
					exists = matchmaker
					exists = liege
					matchmaker = {
						this = scope:secondary_recipient.liege
						is_close_or_extended_family_of = scope:secondary_recipient
						is_landed = yes
						highest_held_title_tier > tier_barony
						exists = capital_province
						is_adult = yes
						is_available_ai = yes
						is_at_war = no
						OR = {
							ai_compassion >= 0 # isn't heartless enough to deny their relative a love match
							has_trait = family_first # puts family first
							has_trait = eccentric # will buck norms
							culture = { has_cultural_tradition = tradition_chivalry } # culture believes in courtly love
							scope:secondary_recipient = { # only way to marry off the relative
								has_trait = will_not_wed
								any_owned_story = { type = lmf_will_not_wed_story_cycle }
							}
						}
						NOR = {
							has_variable = is_in_marriage_introduction
							has_government = mercenary_government
							has_government = republic_government
							has_government = theocracy_government
							has_government = holy_order_government
						}
						save_temporary_scope_as = recipient
					}
				}
			}
			introduction_interaction_valid_target_trigger = yes
			scope:recipient.capital_province = {
				squared_distance = { target = scope:actor.capital_province value < 500000 }
			}
		}
		add_to_list = potential_suitors
	}

	# now whittle them down to only those who would invite your family member
	if = {
		limit = {
			list_size = { name = potential_suitors value > 0 }
		}
		every_in_list = {
			list = potential_suitors

			save_temporary_scope_as = match
			save_temporary_opinion_value_as = { name = match_opinion target = scope:secondary_actor }
			scope:secondary_actor = { save_temporary_scope_as = candidate }

			if = {
				limit = { scope:candidate.introduction_candidate_interest_value > 0 }
				set_variable = {
					name = interest_value
					value = scope:candidate.introduction_candidate_interest_value
					days = 1
				}

				save_temporary_scope_as = secondary_recipient
				if = {
					limit = { exists = matchmaker }
					matchmaker = { save_temporary_scope_as = recipient }
				}
				else = { save_temporary_scope_as = recipient }

				# check to make sure they'd accept a proposal (as if made by the player to them)
				random = {
					chance = 0
					marriage_ai_accept_modifier = yes
					evaluate_action_increasing_house_unity = { VALUE = 100 }
					modifier = { factor = 100 }

					add_to_list = suitors
				}
			}
		}
	}

	# now pick out the most interested one (bonus if they have Refuses to Wed trait or are someone significant)
	if = {
		limit = {
			list_size = { name = suitors value > 0 }
		}
		ordered_in_list = {
			list = suitors
			order_by = {
				value = var:interest_value
				if = {
					limit = { has_trait = will_not_wed }
					add = 100
				}
				if = {
					limit = { is_playable_character = yes }
					add = 50
				}
				if = {
					limit = {
						is_playable_character = no
						is_primary_heir_of = liege
					}
					add = 50
				}
				if = {
					limit = {
						is_playable_character = no
						NOT = { is_primary_heir_of = liege }
						any_heir_title = {}
					}
					add = 25
				}
				if = {
					limit = {
						is_landed = yes
						OR = {
							primary_title.tier >= scope:actor.primary_title.tier
							liege.primary_title.tier >= scope:actor.primary_title.tier
						}
					}
					add = 25
				}
				if = {
					limit = {
						is_playable_character = no
						NOR = {
							any_heir_title = {}
							has_trait = will_not_wed
						}
						is_extended_family_of = liege
					}
					add = -25
				}
			}
			save_scope_as = suitor_1
		}
	}
}

scripted_effect start_introduction_proposal_effect = {
	root = {
		add_character_flag = {
			flag = had_recent_ai_introduction_proposal
			months = 36
		}
		# switch to recipient scope, as they now become the receiver of the proposal
		save_scope_as = recipient
	}
	# switch secondary_actor to secondary_recipient scope, as they now become the target of the proposal
	scope:secondary_actor = { save_scope_as = secondary_recipient }

	# now establish the proposers of the introduction request
	scope:suitor_1 = {
		save_scope_as = secondary_actor
		if = {
			limit = { exists = matchmaker }
			matchmaker = { save_scope_as = actor }
		}
		else = { save_scope_as = actor }
	}

	scope:actor = {
		# set variables to use in the marriage notification gui
		set_variable = use_introduction
		set_variable = { name = secactor value = scope:secondary_actor }
		set_variable = { name = secrecip value = scope:secondary_recipient }
		set_variable = { name = recip value = scope:recipient }
		set_variable = { name = root_actor value = scope:actor }

		# run the ai-specific character interaction, targeting the player
		run_interaction = {
			interaction = introduce_to_marry_interaction_ai
			redirect = no
			actor = scope:actor
			recipient = scope:recipient
			secondary_actor = scope:secondary_actor
			secondary_recipient = scope:secondary_recipient
			send_threshold = decline
		}
	}
}

# Yearly check for introduction invitations from the AI
lmf_heir.1540 = {
	type = character_event

	hidden = yes

	trigger = {
		is_landed = yes
		highest_held_title_tier > tier_county
		exists = capital_county
	}

	immediate = {
		if = {
			limit = {
				is_available = yes
				NOR = {
					is_at_war = yes
					has_variable = is_in_marriage_introduction
					has_character_flag = had_recent_ai_introduction_proposal
				}
			}
			if = {
				limit = {
					age >= 12
					is_available = yes
					is_healthy = yes
					is_married = no
					is_betrothed = no
					has_been_promised_grand_wedding = no
					has_recoverable_disease_trigger = no
					bp2_valid_for_standard_interactions_trigger = yes
					introduction_interaction_can_be_picked_trigger = yes
					NOR = {
						has_character_flag = had_recent_introduction
						has_character_flag = checked_ai_introduction_proposal_last_year
					}
				}
				remove_character_flag ?= checked_ai_introduction_proposal_last_year
				add_character_flag = {
					flag = checked_ai_introduction_proposal_last_year
					months = 12
				}
				random = {
					chance = 50
					find_suitable_introduction_proposer = yes

					if = {
						limit = { exists = scope:suitor_1 }
						start_introduction_proposal_effect = yes
					}
				}
			}
			else_if = {
				limit = {
					any_close_or_extended_family_member = {
						is_courtier_of = root
						age >= 12
						is_available_ai = yes
						is_healthy = yes
						has_recoverable_disease_trigger = no
						bp2_valid_for_standard_interactions_trigger = yes
						introduction_interaction_can_be_picked_trigger = yes
						is_concubine = no
						NOT = { has_character_flag = had_recent_introduction }
						exists = matchmaker
						matchmaker = root
					}
				}
				random_close_or_extended_family_member = {
					limit = {
						is_courtier_of = root
						age >= 12
						is_available_ai = yes
						is_healthy = yes
						has_recoverable_disease_trigger = no
						bp2_valid_for_standard_interactions_trigger = yes
						introduction_interaction_can_be_picked_trigger = yes
						is_concubine = no
						NOT = { has_character_flag = had_recent_introduction }
						exists = matchmaker
						matchmaker = root
					}
					weight = {
						base = 5
						modifier = {
							add = 50
							has_trait = will_not_wed
							any_owned_story = { type = lmf_will_not_wed_story_cycle }
						}
						modifier = {
							add = 10
							any_heir_title = {}
						}
						modifier = {
							add = 10
							is_adult = yes
							age <= 25
						}
						modifier = {
							factor = 0.5
							age > 25
						}
						modifier = {
							factor = 0.5
							has_character_flag = checked_ai_introduction_proposal_last_year
						}
					}
					remove_character_flag ?= checked_ai_introduction_proposal_last_year
					add_character_flag = {
						flag = checked_ai_introduction_proposal_last_year
						months = 12
					}
					random = {
						chance = 25
						modifier = {
							add = 25
							is_adult = yes
						}
						modifier = {
							add = 25
							any_heir_title = {}
						}
						modifier = {
							add = 25
							has_trait = will_not_wed
							any_owned_story = { type = lmf_will_not_wed_story_cycle }
						}
						modifier = {
							add = 25
							root = {
								NOR = {
									has_character_flag = checked_ai_introduction_proposal_last_year
									any_close_or_extended_family_member = {
										is_courtier_of = root
										has_character_flag = checked_ai_introduction_proposal_last_year
									}
								}
							}
						}
						max = 100
						find_suitable_introduction_proposer = yes
						if = {
							limit = { exists = scope:suitor_1 }
							start_introduction_proposal_effect = yes
						}
					}
				}
			}
		}
		# when the player is busy, re-check in 30 days if the event falls earlier in the year
		# (we skip January because that might be a holdover from the previous year)
		else_if = {
			limit = {
				current_month > 1
				current_month < 9
			}
			trigger_event = {
				id = lmf_heir.1540
				days = 30
			}
		}
	}
}

# Auto-assigning guardians to children
lmf_heir.1550 = {
	type = character_event

	hidden = yes

	trigger = {
		age >= childhood_education_start_age
		num_of_relation_guardian = 0
		is_available_child = yes
		is_courtier = yes
		exists = liege
		exists = host
		liege = host
		NOR = {
			any_close_family_member = {
				is_ruler = yes
				is_close_family_of = root
			}
			has_recoverable_disease_trigger = yes
		}
	}

	immediate = {
		#just in case they don't have a focus
		if = {
			limit = {
				NOR = {
					has_focus = education_diplomacy
					has_focus = education_martial
					has_focus = education_stewardship
					has_focus = education_intrigue
					has_focus = education_learning
				}
			}
			set_random_focus_effect = yes
		}

		#now let's assign them a guardian
		liege = { save_scope_as = current_host }
		root = { save_scope_as = focus_child }

		if = {
			limit = { has_focus = education_diplomacy }
			find_new_guardian_effect = { RULER = scope:current_host CHILD = scope:focus_child EDUCATION = diplomacy }
		}
		else_if = {
			limit = { has_focus = education_martial }
			find_new_guardian_effect = { RULER = scope:current_host CHILD = scope:focus_child EDUCATION = martial }
		}
		else_if = {
			limit = { has_focus = education_stewardship }
			find_new_guardian_effect = { RULER = scope:current_host CHILD = scope:focus_child EDUCATION = stewardship }
		}
		else_if = {
			limit = { has_focus = education_intrigue }
			find_new_guardian_effect = { RULER = scope:current_host CHILD = scope:focus_child EDUCATION = intrigue }
		}
		else = {
			find_new_guardian_effect = { RULER = scope:current_host CHILD = scope:focus_child EDUCATION = learning }
		}

		#and assign the guardian to them, no fanfare needed
		if = {
			limit = { exists = scope:new_guardian }
			scope:focus_child = { set_relation_guardian = scope:new_guardian }
		}
	}
}

scripted_trigger is_available_language_tutor = {
	is_physically_able_adult = yes
	has_recoverable_disease_trigger = no
	learning >= 5
	NOR = {
		has_trait = intellect_bad
		has_trait = lazy
		has_trait = impatient
		has_trait = infirm
		is_in_list = available_tutors
	}
}

scripted_trigger is_available_language_pupil = {
	is_adult = no
	is_physically_able = yes
	has_recoverable_disease_trigger = no
	age >= 6
	OR = {
		is_close_or_extended_family_of = scope:liege
		is_great_grandchild_of = scope:liege
	}
	trigger_if = {
		limit = {
			NOT = { is_courtier_of = scope:liege }
		}
		any_relation = {
			type = guardian
			is_in_the_same_court_as = scope:liege
		}
	}
	NOR = {
		num_of_known_languages >= language_soft_cap
		any_scheme = { type = learn_language }
	}
}

scripted_effect compile_needed_languages = {
	culture = {
		if = {
			limit = {
				NOT = { is_in_list = needed_languages }
			}
			add_to_list = needed_languages
			add_to_list = $ALSO_LIST$
		}
	}
}

# Auto-assigning learn language schemes to children
lmf_heir.1560 = {
	type = character_event
	hidden = yes
	
	trigger = {
		scope:liege = {
			any_courtier_or_guest = {
				is_available_language_pupil = yes
			}
		}
	}
	
	immediate = {
		scope:liege = {
			# first build a list of the languages needed
			culture = { add_to_list = needed_languages }
			every_sub_realm_county = {
				compile_needed_languages = { ALSO_LIST = realm_languages }
			}
			every_vassal = {
				limit = { highest_held_title_tier > scope:liege.highest_tier_minus_2 }
				compile_needed_languages = { ALSO_LIST = vassal_languages }
			}
			every_liege_or_above = {
				compile_needed_languages = { ALSO_LIST = liege_languages }
			}
			every_ally = {
				limit = {
					highest_held_title_tier > scope:liege.highest_tier_minus_1
					NOT = { is_vassal_or_below_of = scope:liege }
				}
				compile_needed_languages = { ALSO_LIST = ally_languages }
			}		
			every_neighboring_and_across_water_top_liege_realm_owner = {
				limit = {
					OR = {
						highest_held_title_tier >= scope:liege.highest_held_title_tier
						max_military_strength >= scope:liege.eighty_percent_of_max_military_strength
					}
				}
				compile_needed_languages = { ALSO_LIST = neighbour_languages }
			}
			
			# then build a list of available courtiers
			every_courtier = {
				limit = { is_available_language_tutor = yes }
				add_to_list = available_tutors
			}
			every_vassal = {
				limit = { is_available_language_tutor = yes }
				add_to_list = available_tutors
			}
			if = {
				limit = {
					list_size = { name = available_tutors value > 0 }
				}
				# now go through each pupil and pick out a tutor
				every_courtier_or_guest = {
					limit = { is_available_language_pupil = yes }
					save_temporary_scope_as = current_pupil
					random_in_list = {
						list = available_tutors
						limit = {
							language_tutor_value > 0
							NOT = { has_relation_rival = scope:current_pupil }
						}
						weight = {
							base = 0
							modifier = {
								always = yes
								add = language_tutor_value
							}
							modifier = {
								factor = 1.5
								is_extended_family_of = scope:current_pupil
							}
							modifier = {
								factor = 2
								is_close_family_of = scope:current_pupil
							}
							modifier = {
								factor = 1.5
								has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:current_pupil }
							}
							modifier = {
								factor = 2
								has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:current_pupil }
							}
							modifier = {
								factor = 0.1
								has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:current_pupil }
							}
						}
						save_temporary_scope_as = selected_tutor
						scope:current_pupil = {
							begin_scheme_basic_effect = {
								SCHEME_TYPE = learn_language
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:selected_tutor
							}
						}
						scope:liege = {
							send_interface_message = {
								type = event_generic_neutral_with_text
								title = lmf_heir_language_scheme_begun.title
								desc = lmf_heir_language_scheme_begun.desc
								left_icon = scope:current_pupil
								right_icon = scope:selected_tutor
							}
						}
						if = {
							limit = {
								scope:tutor = { aptitude:court_tutor_court_position = 1 }
							}
							random_scheme = {
								type = learn_language
								add_scheme_modifier = { type = court_tutor_child_language_rank_1_modifier }
							}
						}
						else_if = {
							limit = {
								scope:tutor = { aptitude:court_tutor_court_position = 2 }
							}
							random_scheme = {
								type = learn_language
								add_scheme_modifier = { type = court_tutor_child_language_rank_2_modifier }
							}
						}
						else_if = {
							limit = {
								scope:tutor = { aptitude:court_tutor_court_position = 3 }
							}
							random_scheme = {
								type = learn_language
								add_scheme_modifier = { type = court_tutor_child_language_rank_3_modifier }
							}
						}
						else_if = {
							limit = {
								scope:tutor = { aptitude:court_tutor_court_position = 4 }
							}
							random_scheme = {
								type = learn_language
								add_scheme_modifier = { type = court_tutor_child_language_rank_4_modifier }
							}
						}
						else_if = {
							limit = {
								scope:tutor = { aptitude:court_tutor_court_position = 5 }
							}
							random_scheme = {
								type = learn_language
								add_scheme_modifier = { type = court_tutor_child_language_rank_5_modifier }
							}
						}
					}
				}
			}
		}
	}
}

# Court Tutor proposes hiring a language tutor for the children
lmf_heir.1561 = {
	type = character_event
	hidden = yes
	
	trigger = {
		NOT = { has_character_flag = court_tutor_suggestion_cooldown }
		scope:tutor = {
			is_alive = yes
			is_courtier_of = root
			has_court_position = court_tutor_court_position
		}
		any_courtier_or_guest = {
			is_available_language_pupil = yes
		}
	}
	
	immediate = {
		# first build a list of the languages needed
		every_sub_realm_county = {
			compile_needed_languages = { ALSO_LIST = realm_languages }
		}
		every_vassal = {
			limit = { highest_held_title_tier >= scope:liege.highest_tier_minus_2 }
			compile_needed_languages = { ALSO_LIST = vassal_languages }
		}
		every_liege_or_above = {
			compile_needed_languages = { ALSO_LIST = liege_languages }
		}
		every_ally = {
			limit = {
				highest_held_title_tier > scope:liege.highest_tier_minus_1
				NOT = { is_vassal_or_below_of = scope:liege }
			}
			compile_needed_languages = { ALSO_LIST = ally_languages }
		}		
		every_neighboring_and_across_water_top_liege_realm_owner = {
			limit = {
				OR = {
					highest_held_title_tier >= scope:liege.highest_held_title_tier
					max_military_strength >= scope:liege.eighty_percent_of_max_military_strength
				}
			}
			compile_needed_languages = { ALSO_LIST = neighbour_languages }
		}
	
		# now remove cultures from that list which we have tutors for
		every_courtier = {
			limit = {
				is_physically_able_adult = yes
				learning >= 5
				NOR = {
					has_trait = intellect_bad
					has_trait = lazy
					has_trait = impatient
					has_trait = infirm
				}
			}
			save_temporary_scope_as = current_potential_tutor
			every_in_list = {
				list = needed_languages
				limit = {
					OR = {
						this = scope:current_potential_tutor.culture
						has_same_culture_language = scope:current_potential_tutor.culture
					}
				}
				remove_from_list = needed_languages
			}
		}
		every_vassal = {
			limit = {
				is_physically_able_adult = yes
				learning >= 5
				NOR = {
					has_trait = intellect_bad
					has_trait = lazy
					has_trait = impatient
					has_trait = infirm
				}
			}
			save_temporary_scope_as = current_potential_tutor
			every_in_list = {
				list = needed_languages
				limit = {
					OR = {
						this = scope:current_potential_tutor.culture
						has_same_culture_language = scope:current_potential_tutor.culture
					}
				}
				remove_from_list = needed_languages
			}
		}
	
		if = {
			limit = {
				list_size = { name = needed_languages value > 0 }
			}
			random_in_list = {
				list = needed_languages
				weight = {
					base = 0
					modifier = {
						is_in_list = realm_languages
						add = 400
					}
					modifier = {
						is_in_list = vassal_languages
						add = 150
					}
					modifier = {
						is_in_list = liege_languages
						add = 75
					}
					modifier = {
						is_in_list = ally_languages
						add = 25
					}
					modifier = {
						is_in_list = neighbour_languages
						add = 10
					}
				}
				save_scope_as = tutor_culture
				scope:liege = {
					add_character_flag = { flag = court_tutor_suggestion_cooldown years = 5 }
					trigger_event = lmf_heir.1562
				}
			}
		}
	}
}

lmf_heir.1562 = {
	type = character_event
	title = lmf_heir.1562.t
	desc = {
		desc = lmf_heir.1562.desc.start
		first_valid = {
			triggered_desc = {
				trigger = { scope:language_tutor = { has_trait = devoted } }
				desc = lmf_heir.1562.desc.devoted
			}
			triggered_desc = {
				trigger = { scope:language_tutor = { has_trait = lifestyle_poet } }
				desc = lmf_heir.1562.desc.poet
			}
			triggered_desc = {
				trigger = { scope:language_tutor = { has_trait = scholar } }
				desc = lmf_heir.1562.desc.scholar
			}
			triggered_desc = {
				trigger = { scope:language_tutor = { has_trait = intellect_good } }
				desc = lmf_heir.1562.desc.shrewd
			}
			triggered_desc = {
				trigger = { scope:language_tutor = { has_trait = lifestyle_traveler } }
				desc = lmf_heir.1562.desc.traveler
			}
			desc = lmf_heir.1562.desc.default
		}
		desc = lmf_heir.1562.desc.mid
		first_valid = {
			triggered_desc = {
				trigger = { scope:language_tutor.culture = { is_in_list = realm_languages } }
				desc = lmf_heir.1562.desc.realm
			}
			triggered_desc = {
				trigger = { scope:language_tutor.culture = { is_in_list = vassal_languages } }
				desc = lmf_heir.1562.desc.vassal
			}
			triggered_desc = {
				trigger = { scope:language_tutor.culture = { is_in_list = liege_languages } }
				desc = lmf_heir.1562.desc.liege
			}
			triggered_desc = {
				trigger = { scope:language_tutor.culture = { is_in_list = ally_languages } }
				desc = lmf_heir.1562.desc.ally
			}
			desc = lmf_heir.1562.desc.neighbour
		}
		desc = lmf_heir.1562.desc.end
	}
	theme = dynasty
	
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:language_tutor
		animation = throne_room_bow_1
	}
	lower_right_portrait = scope:tutor
	
	immediate = {
		hidden_effect = {
			create_character = {
				template = lmf_language_tutor
				location = root.capital_province
				save_scope_as = language_tutor
			}
			if = {
				limit = {
					list_size = { name = vassal_languages value > 0 }
					scope:language_tutor.culture = { is_in_list = vassal_languages }
				}
				random_vassal = {
					limit = { culture = scope:language_tutor.culture }
					weight = {
						base = 1
						modifier = {
							always = yes
							add = {
								value = primary_title.tier
								multiply = 5
							}
						}
					}
					save_scope_as = language_vassal
				}
			}
			if = {
				limit = {
					list_size = { name = ally_languages value > 0 }
					scope:language_tutor.culture = { is_in_list = ally_languages }
				}
				random_ally = {
					limit = { culture = scope:language_tutor.culture }
					weight = {
						base = 1
						modifier = {
							always = yes
							add = {
								value = primary_title.tier
								multiply = 5
							}
						}
					}
					save_scope_as = language_ally
				}
			}
			if = {
				limit = {
					list_size = { name = neighbour_languages value > 0 }
					scope:language_tutor.culture = { is_in_list = neighbour_languages }
				}
				random_neighboring_and_across_water_top_liege_realm_owner = {
					limit = { culture = scope:language_tutor.culture }
					weight = {
						base = 1
						modifier = {
							always = yes
							add = {
								value = primary_title.tier
								multiply = 5
							}
						}
					}
					save_scope_as = language_neighbour
				}
			}
		}
	}
	
	option = {
		name = lmf_heir.1562.a #That sounds like an excellent idea
		pay_short_term_gold = {
			target = scope:language_tutor
			gold = minor_gold_value
		}
		add_courtier = scope:language_tutor
		scope:language_tutor = {
			add_character_flag = { flag = will_not_leave years = 20 }
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
	}
	option = {
		name = lmf_heir.1562.b #No, this is unnecessary
		hidden_effect = {
			scope:language_tutor = {
				silent_disappearance_effect = yes
			}
		}
	}
}


###########################
# HEIR-IN-TRAINING EVENTS #
###########################

scripted_trigger has_superior_skill_trigger = {
	OR = {
		AND = {
			diplomacy > $COMPARE1$.diplomacy
			diplomacy > $COMPARE2$.diplomacy
		}
		AND = {
			martial > $COMPARE1$.martial
			martial > $COMPARE2$.martial
		}
		AND = {
			stewardship > $COMPARE1$.stewardship
			stewardship > $COMPARE2$.stewardship
		}
		AND = {
			intrigue > $COMPARE1$.intrigue
			intrigue > $COMPARE2$.intrigue
		}
		AND = {
			learning > $COMPARE1$.learning
			learning > $COMPARE2$.learning
		}
	}
}

scripted_trigger is_objectionable_ruler_trait_trigger = {
	save_temporary_scope_as = trait_check
	$HOST$ = {
		NOT = { has_trait = scope:trait_check }
	}
	OR = {
		AND = {
			has_trait_category = personality
			is_positive_ruler_trait = no
			any_opposite_trait = {
				$HOST$ = { has_trait = scope:trait_check }
			}
		}
		AND = {
			has_trait_category = personality
			$HOST$.faith = $HEIR$.faith
			$HEIR$.faith = { trait_is_sin = scope:trait_check }
			$HOST$ = { num_sinful_traits < 2 }
		}
		AND = {
			is_negative_ruler_trait = yes
			$HOST$ = {
				NOR = {
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
					has_trait = compassionate
					has_trait = trusting
				}
				OR = {
					has_trait = ambitious
					has_trait = diligent
					has_trait = impatient
				}
			}
		}
		AND = {
			this = trait:drunkard
			$HOST$ = {
				NOR = {
					has_trait = gluttonous
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
					has_trait = compassionate
					has_trait = trusting
				}
				OR = {
					has_trait = ambitious
					has_trait = diligent
					has_trait = impatient
					has_trait = temperate
				}
			}
		}
		AND = {
			this = trait:rakish
			$HOST$ = {
				NOR = {
					has_trait = seducer
					is_deviant_trigger = yes
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
					has_trait = compassionate
					has_trait = trusting
				}
				OR = {
					has_negative_attitude_towards_trait_trigger = { TRAIT = trait:fornicator GENDER_CHARACTER = $HEIR$ }
					AND = {
						has_negative_attitude_towards_trait_trigger = { TRAIT = trait:sodomite GENDER_CHARACTER = $HEIR$ }
						$HEIR$ = {
							is_male = yes
							OR = {
								has_sexuality = homosexual
								has_sexuality = bisexual
							}
						}
					}
				}
			}
		}
		AND = {
			OR = {
				this = trait:profligate
				this = trait:improvident
			}
			$HOST$ = {
				NOR = {
					has_trait = profligate
					has_trait = improvident
					has_trait = generous
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
					has_trait = compassionate
					has_trait = trusting
				}
				OR = {
					has_trait = ambitious
					has_trait = diligent
					has_trait = impatient
					has_trait = greedy
					has_trait = arrogant
				}
			}
		}
		AND = {
			this = trait:reclusive
			$HOST$ = {
				NOR = {
					has_trait = shy
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
					has_trait = compassionate
					has_trait = trusting
				}
				OR = {
					has_trait = ambitious
					has_trait = diligent
					has_trait = impatient
					has_trait = gregarious
				}
			}
		}
		AND = {
			this = trait:irritable
			$HOST$ = {
				NOR = {
					has_trait = wrathful
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
					has_trait = compassionate
					has_trait = trusting
				}
				OR = {
					has_trait = ambitious
					has_trait = diligent
					has_trait = patient
					has_trait = calm
				}
			}
		}
		AND = {
			this = trait:inappetetic
			$HOST$ = {
				NOR = {
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
					has_trait = compassionate
					has_trait = trusting
				}
				OR = {
					has_trait = ambitious
					has_trait = diligent
					has_trait = impatient
					has_trait = gluttonous
				}
			}
		}
		AND = {
			this = trait:contrite
			$HOST$ = {
				NOR = {
					has_trait = lazy
					has_trait = content
					has_trait = forgiving
					has_trait = compassionate
					has_trait = trusting
				}
				OR = {
					has_trait = ambitious
					has_trait = diligent
					has_trait = impatient
					has_trait = paranoid
					has_trait = deceitful
				}
			}
		}
	}
}

scripted_trigger is_appropriate_heir_visit_target = {
	is_adult = yes
	is_landed = yes
	exists = capital_province
	highest_held_title_tier >= tier_county
	has_superior_skill_trigger = { COMPARE1 = $HEIR$ COMPARE2 = $HEIR$.host }
	NOR = {
		this = $HEIR$.host
		is_travelling = yes
		is_in_army = yes
		is_imprisoned = yes
		is_incapable = yes
		has_recoverable_disease_trigger = yes
		is_at_war = yes
		has_relation_rival = $HEIR$
		has_relation_rival = $HEIR$.host
		has_character_flag = had_recent_heir_visit
		has_character_flag = recently_refused_heir_visit
		has_government = mercenary_government
		has_government = republic_government
		has_government = theocracy_government
		has_government = holy_order_government
		has_character_modifier = isolating_modifier
		capital_county = {
			OR = {
				has_county_modifier = isolate_capital_decision_modifier
				any_county_province = { any_province_epidemic = { count >= 1 } }
			}
		}
	}
}

scripted_effect add_heir_event_delay_flags_effect = {
	if = {
		limit = { has_game_rule = lmf_less_frequent_heir_events }
		player_heir = {
			if = {
				limit = { is_adult = no }
				add_character_flag = {
					flag = had_recent_heir_event
					months = 18
				}
			}
			else_if = {
				limit = { age >= 25 }
				add_character_flag = {
					flag = had_recent_heir_event
					months = 60
				}
			}
			else = {
				add_character_flag = {
					flag = had_recent_heir_event
					months = 36
				}
			}
		}
	}
	else_if = {
		limit = { has_game_rule = lmf_more_frequent_heir_events }
		player_heir = {
			if = {
				limit = { is_adult = no }
				add_character_flag = {
					flag = had_recent_heir_event
					months = 6
				}
			}
			else_if = {
				limit = { age >= 25 }
				add_character_flag = {
					flag = had_recent_heir_event
					months = 24
				}
			}
			else = {
				add_character_flag = {
					flag = had_recent_heir_event
					months = 12
				}
			}
		}
	}
	else = {
		player_heir = {
			if = {
				limit = { is_adult = no }
				add_character_flag = {
					flag = had_recent_heir_event
					months = 6
				}
			}
			else_if = {
				limit = { age >= 25 }
				add_character_flag = {
					flag = had_recent_heir_event
					months = 36
				}
			}
			else = {
				add_character_flag = {
					flag = had_recent_heir_event
					months = 24
				}
			}
		}
	}
}

# Main bounce event for heir events
lmf_heir.1600 = {
	type = character_event

	hidden = yes

	trigger = {
		age >= 12
		is_playable_character = no
		exists = host
		is_player_heir_of = host
		has_variable = heir_training_var

		is_courtier = yes
		is_available = yes
		has_recoverable_disease_trigger = no

		NOR = {
			has_game_rule = lmf_no_heir_events
			has_game_rule = lmf_no_heir_training
		}

		trigger_if = {
			limit = {
				host = { highest_held_title_tier == tier_county }
			}
			host = {
				OR = {
					is_ai = no
					liege ?= { is_ai = no }
					top_liege = this
				}
			}
		}

		host = {
			is_available = yes
			has_recoverable_disease_trigger = no
			exists = capital_county
		}
	}

	on_trigger_fail = {
		# for player heirs, will retry the event once
		if = {
			limit = {
				host = { is_ai = no }
				NOT = { has_character_flag = retry_heir_event }
			}
			add_character_flag = {
				flag = retry_heir_event
				days = 95
			}
			trigger_event = {
				id = lmf_heir.1600
				days = 90
			}
		}
	}

	immediate = {
		random_list = {
			100 = { # Child heir is confused by court
				modifier = {
					factor = 0.5
					OR = {
						has_trait = rowdy
						has_trait = bossy
					}
				}
				modifier = {
					factor = 2
					has_trait = pensive
				}
				trigger = {
					is_adult = no
					NOT = { has_character_flag = had_lmf1601_heir_event }
				}
				add_character_flag = { flag = had_lmf1601_heir_event months = 48 }
				host = { trigger_event = lmf_heir.1601 }
			}
			100 = { # Child heir altercation with jealous family member
				trigger = {
					is_adult = no
					NOT = { has_character_flag = had_lmf1602_heir_event }
					any_close_family_member = {
						is_playable_character = no
						is_close_family_of = root
						host = root.host
						age <= root.age_plus_3
						age > root.age_minus_3
						OR = {
							sex_same_as = root
							has_trait = ambitious
							has_trait = wrathful
						}
						NOR = {
							has_relation_rival = root
							has_relation_friend = root
							has_trait = content
							has_trait = calm
						}
					}
				}
				add_character_flag = { flag = had_lmf1602_heir_event months = 48 }
				host = { trigger_event = lmf_heir.1602 }
			}
			100 = { # Child heir asking too many questions
				modifier = {
					factor = 2
					has_trait = curious
				}
				modifier = {
					factor = 0.5
					has_trait = pensive
				}
				trigger = {
					is_adult = no
					NOT = { has_character_flag = had_lmf1603_heir_event }
				}
				add_character_flag = { flag = had_lmf1603_heir_event months = 48 }
				host = { trigger_event = lmf_heir.1603 }
			}
			200 = { # Child heir asks about war
				trigger = {
					is_adult = no
					host = { is_at_war = yes }
					NOT = { has_character_flag = had_lmf1604_heir_event }
				}
				add_character_flag = { flag = had_lmf1604_heir_event months = 48 }
				host = { trigger_event = lmf_heir.1604 }
			}
			100 = { # Councillor complains about heir
				modifier = {
					factor = 2
					has_personality_dominant_trigger = yes
				}
				modifier = {
					factor = 0.5
					has_personality_submissive_trigger = yes
				}
				trigger = {
					age >= 14
					NOT = { has_character_flag = had_lmf1605_heir_event }
					host = {
						any_councillor = {
							is_available = yes
							has_recoverable_disease_trigger = no
							NOR = {
								this = root
								has_relation_friend = root
								has_relation_nemesis = root
								is_close_family_of = root
								has_trait = patient
							}
						}
					}
				}
				add_character_flag = { flag = had_lmf1605_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1605 }
			}
			100 = { # Heir complains that courtier won't listen
				modifier = {
					factor = 0.5
					has_personality_dominant_trigger = yes
				}
				modifier = {
					factor = 2
					has_personality_submissive_trigger = yes
				}
				modifier = {
					factor = 2
					is_female = yes
				}
				trigger = {
					NOT = { has_character_flag = had_lmf1606_heir_event }
					host = {
						any_courtier = {
							is_adult = yes
							ai_boldness >= 0
							opinion = { target = root value <= 0 }
							is_available = yes
							has_recoverable_disease_trigger = no
							NOR = {
								this = root
								is_close_or_extended_family_of = root
								is_consort_of = root.host
								has_relation_lover = root
								has_relation_friend = root
							}
						}
					}
				}
				add_character_flag = { flag = had_lmf1606_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1606 }
			}
			100 = { # Adult heir interferes in ruler business
				modifier = {
					factor = 1.5
					has_personality_dominant_trigger = yes
				}
				modifier = {
					factor = 2
					host = { has_trait = infirm }
				}
				trigger = {
					is_adult = yes
					has_personality_submissive_trigger = no
					host = { age >= 50 }
					NOT = { has_character_flag = had_lmf1607_heir_event }
				}
				add_character_flag = { flag = had_lmf1607_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1607 }
			}
			100 = { # Adult heir knight angry at other knight
				ai_value_modifier = {
					ai_compassion = -0.5
					ai_vengefulness = 0.5
				}
				trigger = {
					is_adult = yes
					is_knight_of = host
					NOR = {
						has_trait = wounded
						has_character_flag = had_lmf1608_heir_event
					}
					host = {
						any_courtier = {
							is_knight_of = prev
							ai_boldness >= 0
							martial > root.martial
							is_available = yes
							has_recoverable_disease_trigger = no
							NOR = {
								is_close_or_extended_family_of = root
								has_relation_friend = root
								has_relation_lover = root
							}
						}
					}
				}
				add_character_flag = { flag = had_lmf1608_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1608 }
			}
			25 = { # Adult heir knight badly wounded
				trigger = {
					is_adult = yes
					is_knight_of = host
					NOR = {
						has_trait = wounded
						has_character_flag = had_lmf1609_heir_event
					}
				}
				add_character_flag = { flag = had_lmf1609_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1609 }
			}
			100 = { # Offload some duties onto adult heir?
				modifier = {
					factor = 2
					host = { has_trait = infirm }
				}
				modifier = {
					factor = 2
					host = { stress > high_medium_stress }
				}
				trigger = {
					is_adult = yes
					host = { age >= 50 }
					NOT = { has_character_flag = had_lmf1610_heir_event }
				}
				add_character_flag = { flag = had_lmf1610_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1610 }
			}
			100 = { # Have heir work on local project?
				trigger = {
					is_adult = yes
					host = {
						short_term_gold >= medium_gold_value
						exists = capital_county
						capital_county = {
							NOR = {
								has_county_modifier = heir_successful_project_modifier
								has_county_modifier = heir_failed_project_modifier
							}
						}
					}
					NOT = { has_character_flag = had_lmf1611_heir_event }
				}
				add_character_flag = { flag = had_lmf1611_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1611 }
			}
			100 = { # Heir has objectionable ruler trait
				modifier = {
					add = 50
					host = { has_trait = diligent }
				}
				modifier = {
					add = 25
					host = { has_trait = ambitious }
				}
				modifier = {
					add = 25
					host = { has_trait = impatient }
				}
				modifier = {
					add = -50
					host = { has_trait = lazy }
				}
				modifier = {
					add = -25
					host = { has_trait = content }
				}
				modifier = {
					add = -25
					host = { has_trait = forgiving }
				}
				min = 1
				trigger = {
					is_adult = yes
					NOT = { has_character_flag = had_lmf1612_heir_event }
					any_character_trait = {
						is_objectionable_ruler_trait_trigger = { HEIR = root HOST = root.host }
					}
				}
				add_character_flag = { flag = had_lmf1612_heir_event years = 20 }
				host = { trigger_event = lmf_heir.1612 }
			}
			100 = { # Heir shirking responsibilities
				modifier = {
					add = -50
					is_adult = no
				}
				ai_value_modifier = {
					ai_honor = -0.5
					ai_energy = -0.5
				}
				min = 0
				trigger = {
					NOT = { has_character_flag = had_lmf1613_heir_event }
				}
				add_character_flag = { flag = had_lmf1613_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1613 }
			}
			100 = { # Heir showing real dedication
				modifier = {
					add = -50
					is_adult = no
				}
				ai_value_modifier = {
					ai_honor = 0.5
					ai_energy = 0.5
				}
				min = 0
				trigger = {
					NOT = { has_character_flag = had_lmf1613_heir_event } #yes, this is intentional
				}
				add_character_flag = { flag = had_lmf1613_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1614 }
			}
			50 = { # Heir gains a trait of liege's
				modifier = {
					add = 50
					any_character_trait = {
						has_trait_category = personality
						count < 3
					}
				}
				trigger = {
					any_character_trait = {
						has_trait_category = personality
						count < 4
					}
					opinion = { target = host value >= 0 }
					NOR = {
						has_relation_rival = host
						has_character_flag = had_lmf1615_heir_event
					}
					host = {
						any_character_trait = {
							has_trait_category = personality
							NOR = {
								root = { has_trait = prev }
								any_opposite_trait = {
									root = { has_trait = prev }
								}
							}
						}
					}
				}
				add_character_flag = { flag = had_lmf1615_heir_event years = 10 }
				host = { trigger_event = lmf_heir.1615 }
			}
			200 = { # Send heir to spend time abroad?
				modifier = {
					factor = 2
					is_adult = yes
					NOT = { has_character_flag = went_on_heir_voyage }
				}
				ai_value_modifier = {
					ai_energy = 0.5
					ai_boldness = 0.5
				}
				modifier = {
					factor = 0.5
					host = { highest_held_title_tier == tier_county }
				}
				min = 0
				trigger = {
					age >= 14
					NOR = {
						has_character_flag = had_lmf1625_heir_event
						is_pregnant = yes
						has_trait = education_heir_training_4
					}
					host = {
						is_at_war = no
						OR = {
							top_liege = {
								is_appropriate_heir_visit_target = { HEIR = root }
							}
							top_liege = {
								any_vassal_or_below = {
									is_appropriate_heir_visit_target = { HEIR = root }
								}
							}
							any_ally = {
								is_appropriate_heir_visit_target = { HEIR = root }
							}
							any_relation = {
								type = friend
								is_appropriate_heir_visit_target = { HEIR = root }
							}
							any_close_or_extended_family_member = {
								is_appropriate_heir_visit_target = { HEIR = root }
							}
						}
						NOR = {
							has_character_modifier = isolating_modifier
							capital_county = {
								OR = {
									has_county_modifier = isolate_capital_decision_modifier
									any_county_province = { any_province_epidemic = { count >= 1 } }
								}
							}
						}
					}
				}
				if = {
					limit = {
						host = { highest_held_title_tier == tier_county }
					}
					add_character_flag = had_lmf1625_heir_event
				}
				else = {
					add_character_flag = { flag = had_lmf1625_heir_event years = 5 }
				}
				host = { trigger_event = lmf_heir.1625 }
			}
			10 = {}
		}
	}
}

# Child heir is confused by court
lmf_heir.1601 = {
	type = character_event
	title = lmf_heir.1601.t
	desc = lmf_heir.1601.desc
	theme = family

	left_portrait = {
		character = root
		animation = throne_room_conversation_3
	}
	right_portrait = {
		character = scope:your_heir
		animation = thinking
	}
	override_background = { reference = throne_room }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
		}
	}

	option = {
		name = lmf_heir.1601.a # Explain patiently
		stress_impact = {
			base = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			patient = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		scope:your_heir = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		random_list = {
			20 = {
				modifier = {
					add = {
						value = diplomacy
						multiply = 1
					}
				}
				modifier = {
					add = {
						value = learning
						multiply = 2
					}
				}
				modifier = {
					add = {
						value = scope:your_heir.learning
						multiply = 3
					}
				}
				modifier = {
					add = 20
					has_trait = patient
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = diligent }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_good_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_good_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_good_3 }
				}
				desc = lmf_heir.1601.a.success.tt
				custom_tooltip = lmf_heir.1601.a.success.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = minor_stress_impact_loss
							curious = minor_stress_impact_loss
							diligent = minor_stress_impact_loss
							ambitious = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1601.a.success.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.success.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = minor_stress_impact_loss
								curious = minor_stress_impact_loss
								diligent = minor_stress_impact_loss
								ambitious = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = 20
							}
						}
						check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
					}
				}
			}
			60 = {
				modifier = {
					add = 20
					has_trait = impatient
				}
				modifier = {
					add = 20
					has_trait = irritable
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 40
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.failure.tt
				custom_tooltip = lmf_heir.1601.a.failure.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = minor_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
							lazy = minor_stress_impact_loss
							content = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = lmf_heir.1601.a.failure.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.failure.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = minor_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
								lazy = minor_stress_impact_loss
								content = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = -10
							}
						}
					}
				}
			}
			20 = {
				modifier = {
					add = 10
					has_trait = impatient
				}
				modifier = {
					add = 10
					has_trait = irritable
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.critfail.tt
				custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = medium_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1601.a.critfail.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = medium_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
							}
							change_variable = {
								name = heir_training_var
								add = -40
							}
						}
					}
				}
			}
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
			modifier = {
				add = 50
				has_trait = patient
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1601.b # Send him to someone else for an explanation
		stress_impact = {
			diligent = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			impatient = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
		}
		scope:your_heir = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				add = 50
				has_trait = impatient
			}
		}
	}
}

# Child heir altercation with jealous family member
lmf_heir.1602 = {
	type = character_event
	title = lmf_heir.1602.t
	desc = lmf_heir.1602.desc
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = shock
	}
	right_portrait = {
		character = scope:angry_family
		animation = rage
	}
	override_background = { reference = garden }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = {
				save_scope_as = your_heir
				random_close_family_member = {
					limit = {
						is_playable_character = no
						host = root
						age <= scope:your_heir.age_plus_3
						age > scope:your_heir.age_minus_3
						OR = {
							sex_same_as = scope:your_heir
							has_trait = ambitious
							has_trait = wrathful
						}
						NOR = {
							has_relation_rival = scope:your_heir
							has_relation_friend = scope:your_heir
							has_trait = content
							has_trait = calm
						}
					}
					weight = {
						base = 1
						ai_value_modifier = {
							ai_honor = -0.5
							ai_vengefulness = 0.5
						}
						opinion_modifier = {
							who = this
							opinion_target = scope:your_heir
							multiplier = -0.5
							min = 0
						}
						min = 1
					}
					save_scope_as = angry_family
					no_hat_respectful_effect = yes
				}
			}
		}
	}

	option = {
		name = lmf_heir.1602.a
		scope:angry_family = {
			add_opinion = {
				target = scope:your_heir
				modifier = envy_opinion
				opinion = -15
			}
			worsen_relationship_effect = {
				TARGET = scope:your_heir
				REASON = fought_over_heir_status
			}
		}
	}

	after = {
		scope:angry_family = { remove_no_hat_effect = yes }
	}
}

# Child heir asking too many questions
lmf_heir.1603 = {
	type = character_event
	title = lmf_heir.1603.t
	desc = lmf_heir.1603.desc
	theme = family

	left_portrait = {
		character = root
		animation = eyeroll
	}
	right_portrait = {
		character = scope:your_heir
		animation = stress
	}

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
		}
	}

	option = {
		name = lmf_heir.1603.a
		stress_impact = {
			base = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			patient = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			irritable = minor_stress_impact_gain
		}
	}
}

# Child heir asks about war
lmf_heir.1604 = {
	type = character_event
	title = lmf_heir.1604.t
	desc = lmf_heir.1604.desc
	theme = family

	left_portrait = {
		character = root
		animation = throne_room_conversation_2
	}
	right_portrait = {
		character = scope:your_heir
		animation = thinking
	}
	override_background = { reference = army_camp }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
			random_character_war = {
				if = {
					limit = { is_defender = root }
					primary_attacker = { save_scope_as = war_target }
				}
				else = {
					primary_defender = { save_scope_as = war_target }
				}
			}
		}
	}

	option = {
		name = lmf_heir.1604.a # Explain patiently
		stress_impact = {
			base = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			patient = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		scope:your_heir = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		random_list = {
			20 = {
				modifier = {
					add = {
						value = diplomacy
						multiply = 1
					}
				}
				modifier = {
					add = {
						value = learning
						multiply = 2
					}
				}
				modifier = {
					add = {
						value = scope:your_heir.learning
						multiply = 3
					}
				}
				modifier = {
					add = 20
					has_trait = patient
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = diligent }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_good_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_good_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_good_3 }
				}
				desc = lmf_heir.1601.a.success.tt
				custom_tooltip = lmf_heir.1601.a.success.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = minor_stress_impact_loss
							curious = minor_stress_impact_loss
							diligent = minor_stress_impact_loss
							ambitious = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1601.a.success.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.success.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = minor_stress_impact_loss
								curious = minor_stress_impact_loss
								diligent = minor_stress_impact_loss
								ambitious = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = 20
							}
						}
						check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
					}
				}
			}
			60 = {
				modifier = {
					add = 20
					has_trait = impatient
				}
				modifier = {
					add = 20
					has_trait = irritable
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 40
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.failure.tt
				custom_tooltip = lmf_heir.1601.a.failure.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = minor_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
							lazy = minor_stress_impact_loss
							content = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = lmf_heir.1601.a.failure.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.failure.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = minor_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
								lazy = minor_stress_impact_loss
								content = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = -10
							}
						}
					}
				}
			}
			20 = {
				modifier = {
					add = 10
					has_trait = impatient
				}
				modifier = {
					add = 10
					has_trait = irritable
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.critfail.tt
				custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = medium_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1601.a.critfail.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = medium_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
							}
							change_variable = {
								name = heir_training_var
								add = -40
							}
						}
					}
				}
			}
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
			modifier = {
				add = 50
				has_trait = patient
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1604.b # Send him to someone else for an explanation
		stress_impact = {
			diligent = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			impatient = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
		}
		scope:your_heir = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				add = 50
				has_trait = impatient
			}
		}
	}
}

# Councillor complains about heir
lmf_heir.1605 = {
	type = character_event
	title = lmf_heir.1605.t
	desc = {
		desc = lmf_heir.1605.desc.start
		first_valid = {
			triggered_desc = {
				trigger = { scope:your_heir = { sex_same_as = root } }
				desc = lmf_heir.1605.desc.same
			}
			triggered_desc = {
				trigger = { exists = primary_spouse }
				desc = lmf_heir.1605.desc.opposite
			}
			desc = lmf_heir.1605.desc.default
		}
	}
	theme = family

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:your_councillor
		animation = anger
	}
	lower_right_portrait = scope:your_heir
	override_background = { reference = throne_room }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
			random_councillor = {
				limit = {
					is_available = yes
					has_recoverable_disease_trigger = no
					NOR = {
						this = scope:your_heir
						has_relation_friend = scope:your_heir
						has_relation_nemesis = scope:your_heir
						is_close_family_of = scope:your_heir
						has_trait = patient
					}
				}
				weight = {
					base = 1
					ai_value_modifier = {
						ai_vengefulness = 1
						ai_compassion = -0.5
					}
					opinion_modifier = {
						who = this
						opinion_target = scope:your_heir
						multiplier = -0.5
						min = 0
					}
					min = 1
				}
				save_scope_as = your_councillor
			}
		}
	}

	option = {
		name = lmf_heir.1605.a #Try to teach heir some tact
		stress_impact = {
			base = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			patient = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}

		scope:your_councillor = {
			add_opinion = {
				target = scope:your_heir
				modifier = angry_opinion
				opinion = -20
			}
		}

		random_list = {
			20 = {
				modifier = {
					add = {
						value = diplomacy
						multiply = 2
					}
				}
				modifier = {
					add = {
						value = learning
						multiply = 1
					}
				}
				modifier = {
					add = {
						value = scope:your_heir.diplomacy
						multiply = 3
					}
				}
				modifier = {
					add = 20
					has_trait = patient
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = diligent }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_good_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_good_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_good_3 }
				}
				modifier = {
					add = -20
					diplomacy <= scope:your_heir.diplomacy
				}
				desc = lmf_heir.1601.a.success.tt
				custom_tooltip = lmf_heir.1601.a.success.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_diplomacy_lifestyle_xp = medium_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_loss
							curious = minor_stress_impact_loss
							diligent = minor_stress_impact_loss
							ambitious = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1601.a.success.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.success.effect.tt
						scope:your_heir = {
							add_diplomacy_lifestyle_xp = medium_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_loss
								curious = minor_stress_impact_loss
								diligent = minor_stress_impact_loss
								ambitious = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = 20
							}
						}
						check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
					}
				}
			}
			60 = {
				modifier = {
					add = 20
					has_trait = impatient
				}
				modifier = {
					add = 20
					has_trait = irritable
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 40
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.failure.tt
				custom_tooltip = lmf_heir.1601.a.failure.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_diplomacy_lifestyle_xp = minor_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
							lazy = minor_stress_impact_loss
							content = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = lmf_heir.1601.a.failure.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.failure.effect.tt
						scope:your_heir = {
							add_diplomacy_lifestyle_xp = minor_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
								lazy = minor_stress_impact_loss
								content = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = -10
							}
						}
					}
				}
			}
			20 = {
				modifier = {
					add = 10
					has_trait = impatient
				}
				modifier = {
					add = 10
					has_trait = irritable
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.critfail.tt
				custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = medium_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1601.a.critfail.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = medium_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
							}
							change_variable = {
								name = heir_training_var
								add = -40
							}
						}
					}
				}
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
			modifier = {
				add = 50
				has_trait = patient
			}
			modifier = {
				add = 50
				diplomacy > scope:your_heir.diplomacy
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1605.b #Encourage councillor to help
		stress_impact = {
			diligent = minor_stress_impact_loss
			gregarious = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}

		random_list = {
			20 = {
				modifier = {
					add = {
						value = diplomacy
						multiply = 3
					}
				}
				ai_value_modifier = {
					who = scope:your_councillor
					ai_compassion = 1.0
					ai_honor = 0.5
					ai_vengefulness = -0.5
				}
				opinion_modifier = {
					who = scope:your_councillor
					opinion_target = root
					multiplier = 0.5
					max = 25
				}
				min = 1
				desc = lmf_heir.1605.b.success.tt
				custom_tooltip = lmf_heir.1601.a.success.effect.tt
				show_as_tooltip = {
					scope:your_councillor = {
						improve_relationship_effect = {
							TARGET = scope:your_heir
							REASON = convinced_to_help_heir
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1605.b.success.tt
						right_icon = scope:your_councillor
						custom_tooltip = lmf_heir.1601.a.success.effect.tt
						scope:your_councillor = {
							improve_relationship_effect = {
								TARGET = scope:your_heir
								REASON = convinced_to_help_heir
							}
						}
						scope:your_heir = {
							change_variable = {
								name = heir_training_var
								add = 20
							}
						}
						check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
					}
				}
			}
			60 = {
				modifier = {
					add = 20
					scope:your_councillor = { has_trait = impatient }
				}
				modifier = {
					add = 20
					scope:your_councillor = { has_trait = irritable }
				}
				desc = lmf_heir.1605.b.failure.tt
				show_as_tooltip = {
					scope:your_councillor = {
						add_opinion = {
							target = scope:your_heir
							modifier = angry_opinion
							opinion = -20
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = lmf_heir.1605.b.failure.tt
						right_icon = scope:your_councillor
						scope:your_councillor = {
							add_opinion = {
								target = scope:your_heir
								modifier = angry_opinion
								opinion = -20
							}
						}
					}
				}
			}
			20 = {
				modifier = {
					add = 10
					scope:your_councillor = { has_trait = impatient }
				}
				modifier = {
					add = 10
					scope:your_councillor = { has_trait = irritable }
				}
				desc = lmf_heir.1605.b.critfail.tt
				show_as_tooltip = {
					scope:your_councillor = {
						add_opinion = {
							target = root
							modifier = insult_opinion
							opinion = -10
						}
						worsen_relationship_effect = {
							TARGET = scope:your_heir
							REASON = not_convinced_to_help_heir
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1605.b.critfail.tt
						right_icon = scope:your_councillor
						scope:your_councillor = {
							add_opinion = {
								target = root
								modifier = insult_opinion
								opinion = -10
							}
							worsen_relationship_effect = {
								TARGET = scope:your_heir
								REASON = not_convinced_to_help_heir
							}
						}
					}
				}
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
			modifier = {
				add = 50
				reverse_opinion = { target = scope:your_councillor value >= 20 }
			}
			modifier = {
				add = -50
				reverse_opinion = { target = scope:your_councillor value <= -20 }
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1605.c #Let them work it out themselves
		stress_impact = {
			diligent = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			impatient = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
		}

		random_list = {
			50 = {
				modifier = {
					add = {
						value = scope:your_heir.diplomacy
						multiply = 3
					}
				}
				desc = lmf_heir.1605.c.success.tt
				show_chance = no
				show_as_tooltip = {
					scope:your_councillor = {
						add_opinion = {
							target = scope:your_heir
							modifier = respect_opinion
							opinion = 20
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1605.c.success.tt
						right_icon = scope:your_councillor
						scope:your_councillor = {
							add_opinion = {
								target = scope:your_heir
								modifier = respect_opinion
								opinion = 20
							}
						}
					}
				}
			}
			50 = {
				desc = lmf_heir.1605.c.failure.tt
				show_chance = no
				show_as_tooltip = {
					scope:your_councillor = {
						worsen_relationship_effect = {
							TARGET = scope:your_heir
							REASON = not_convinced_to_help_heir
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1605.c.failure.tt
						right_icon = scope:your_councillor
						scope:your_councillor = {
							worsen_relationship_effect = {
								TARGET = scope:your_heir
								REASON = not_convinced_to_help_heir
							}
						}
					}
				}
			}
		}

		ai_chance = {
			base = 20
			modifier = {
				add = 50
				has_trait = impatient
			}
		}
	}
}

# Heir complains that courtier won't listen
lmf_heir.1606 = {
	type = character_event
	title = lmf_heir.1606.t
	desc = lmf_heir.1606.desc
	theme = family

	left_portrait = {
		character = scope:your_courtier
		animation = dismissal
	}
	right_portrait = {
		character = scope:your_heir
		animation = stress
	}
	override_background = { reference = study }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
			random_courtier = {
				limit = {
					is_adult = yes
					ai_boldness >= 0
					opinion = { target = scope:your_heir value <= 0 }
					is_available = yes
					has_recoverable_disease_trigger = no
					NOR = {
						this = scope:your_heir
						is_close_or_extended_family_of = scope:your_heir
						is_consort_of = root
						has_relation_lover = scope:your_heir
						has_relation_friend = scope:your_heir
					}
				}
				weight = {
					base = 1
					ai_value_modifier = {
						ai_vengefulness = 0.5
						ai_boldness = 0.5
						ai_compassion = -0.5
					}
					opinion_modifier = {
						who = this
						opinion_target = scope:your_heir
						multiplier = -0.5
					}
					modifier = {
						add = 20
						scope:your_heir = { is_female = yes }
						is_male = yes
					}
					modifier = {
						trigger = {
							age > scope:your_heir.age
						}
						add = {
							value = age
							subtract = scope:your_heir.age
							multiply = 3
						}
					}
					modifier = {
						factor = 0.5
						is_lowborn = yes
					}
					min = 1
				}
				save_scope_as = your_courtier
			}
		}
	}

	option = {
		name = lmf_heir.1606.a # Add Forgiving
		trigger = {
			scope:your_heir = {
				is_adult = no
				NOR = {
					has_trait = forgiving
					has_trait = vengeful
				}
				any_character_trait = {
					has_trait_category = personality
					count < 4
				}
			}
		}
		show_as_unavailable = {
			scope:your_heir = {
				is_adult = no
				any_character_trait = {
					has_trait_category = personality
					count < 4
				}
				OR = {
					has_trait = forgiving
					has_trait = vengeful
				}
			}
		}
		scope:your_heir = { add_trait_force_tooltip = forgiving }
		ai_chance = {
			base = 0
		}
	}
	option = {
		name = lmf_heir.1606.b # Add Brave
		trigger = {
			scope:your_heir = {
				is_adult = no
				NOR = {
					has_trait = craven
					has_trait = brave
				}
				any_character_trait = {
					has_trait_category = personality
					count < 4
				}
			}
		}
		show_as_unavailable = {
			scope:your_heir = {
				is_adult = no
				any_character_trait = {
					has_trait_category = personality
					count < 4
				}
				OR = {
					has_trait = craven
					has_trait = brave
				}
			}
		}
		scope:your_heir = {
			add_trait_force_tooltip = brave
			add_opinion = {
				target = scope:your_courtier
				modifier = insult_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 0
		}
	}
	option = {
		name = lmf_heir.1606.c # Add Wrathful
		trigger = {
			scope:your_heir = {
				is_adult = no
				NOR = {
					has_trait = wrathful
					has_trait = calm
				}
				any_character_trait = {
					has_trait_category = personality
					count < 4
				}
			}
		}
		show_as_unavailable = {
			scope:your_heir = {
				is_adult = no
				any_character_trait = {
					has_trait_category = personality
					count < 4
				}
				OR = {
					has_trait = wrathful
					has_trait = calm
				}
			}
		}
		scope:your_heir = {
			add_trait_force_tooltip = wrathful
			worsen_relationship_effect = {
				TARGET = scope:your_courtier
				REASON = will_not_listen_to_heir
			}
		}
		ai_chance = {
			base = 0
		}
	}
	option = {
		name = lmf_heir.1606.d # Teach heir how to handle the situation
		stress_impact = {
			base = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			patient = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		scope:your_heir = {
			add_opinion = {
				target = scope:your_courtier
				modifier = insult_opinion
				opinion = -20
			}
		}
		random_list = {
			20 = {
				modifier = {
					add = {
						value = diplomacy
						multiply = 2
					}
				}
				modifier = {
					add = {
						value = learning
						multiply = 1
					}
				}
				modifier = {
					add = {
						value = scope:your_heir.diplomacy
						multiply = 3
					}
				}
				modifier = {
					add = 20
					has_trait = patient
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = diligent }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_good_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_good_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_good_3 }
				}
				modifier = {
					add = -20
					diplomacy <= scope:your_heir.diplomacy
				}
				desc = lmf_heir.1601.a.success.tt
				custom_tooltip = lmf_heir.1601.a.success.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_diplomacy_lifestyle_xp = medium_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_loss
							curious = minor_stress_impact_loss
							diligent = minor_stress_impact_loss
							ambitious = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1601.a.success.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.success.effect.tt
						scope:your_heir = {
							add_diplomacy_lifestyle_xp = medium_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_loss
								curious = minor_stress_impact_loss
								diligent = minor_stress_impact_loss
								ambitious = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = 20
							}
						}
						check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
					}
				}
			}
			60 = {
				modifier = {
					add = 20
					has_trait = impatient
				}
				modifier = {
					add = 20
					has_trait = irritable
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 40
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.failure.tt
				custom_tooltip = lmf_heir.1601.a.failure.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_diplomacy_lifestyle_xp = minor_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
							lazy = minor_stress_impact_loss
							content = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = lmf_heir.1601.a.failure.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.failure.effect.tt
						scope:your_heir = {
							add_diplomacy_lifestyle_xp = minor_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
								lazy = minor_stress_impact_loss
								content = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = -10
							}
						}
					}
				}
			}
			20 = {
				modifier = {
					add = 10
					has_trait = impatient
				}
				modifier = {
					add = 10
					has_trait = irritable
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.critfail.tt
				custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = medium_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1601.a.critfail.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = medium_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
							}
							change_variable = {
								name = heir_training_var
								add = -40
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
			modifier = {
				add = 50
				has_trait = patient
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1606.e # Reprimand the courtier
		stress_impact = {
			diligent = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			impatient = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
		}
		scope:your_heir = {
			stress_impact = {
				base = minor_stress_impact_loss
			}
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		scope:your_courtier = {
			stress_impact = {
				base = medium_stress_impact_gain
			}
			worsen_relationship_effect = {
				TARGET = root
				REASON = forced_to_listen_to_heir
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				add = 50
				has_trait = impatient
			}
		}
	}
}

# Adult heir interferes in ruler business
lmf_heir.1607 = {
	type = character_event
	title = lmf_heir.1607.t
	desc = lmf_heir.1607.desc
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = personality_bold
	}
	override_background = { reference = throne_room }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
		}
	}

	option = {
		name = lmf_heir.1607.a #Allow it to continue
		add_prestige = medium_prestige_loss
		stress_impact = {
			base = medium_stress_impact_gain
			diligent = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			trusting = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
		}
		custom_tooltip = lmf_heir.1601.a.success.effect.tt
		scope:your_heir = {
			random = {
				chance = 50
				add_stewardship_lifestyle_xp = medium_lifestyle_xp
			}
			change_variable = {
				name = heir_training_var
				add = 20
			}
		}
		check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
			}
			min = 1
		}
	}
	option = {
		name = lmf_heir.1607.b #They must learn more respect
		add_dread = minor_dread_gain
		stress_impact = {
			paranoid = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			trusting = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		scope:your_heir = {
			stress_impact = {
				base = medium_stress_impact_gain
				diligent = minor_stress_impact_gain
				arrogant = minor_stress_impact_gain
				humble = minor_stress_impact_loss
				lazy = minor_stress_impact_loss
			}
			add_opinion = {
				target = root
				modifier = flustered_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 1
			}
			min = 1
		}
	}
}

# Adult heir knight angry at other knight
lmf_heir.1608 = {
	type = character_event
	title = lmf_heir.1608.t
	desc = lmf_heir.1608.desc
	theme = family

	left_portrait = {
		character = scope:your_courtier
		animation = dismissal
	}
	right_portrait = {
		character = scope:your_heir
		animation = anger
	}
	override_background = { reference = army_camp }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
			random_courtier = {
				limit = {
					is_knight_of = root
					ai_boldness >= 0
					martial > scope:your_heir.martial
					is_available = yes
					has_recoverable_disease_trigger = no
					NOR = {
						is_close_or_extended_family_of = scope:your_heir
						has_relation_friend = scope:your_heir
						has_relation_lover = scope:your_heir
					}
				}
				weight = {
					base = 1
					ai_value_modifier = {
						ai_boldness = 0.5
						ai_honor = -0.5
						max = 50
					}
					opinion_modifier = {
						who = this
						opinion_target = scope:your_heir
						multiplier = -0.5
						max = 25
						min = -25
					}
					modifier = {
						add = {
							value = martial
							subtract = scope:your_heir.martial
							multiply = 3
						}
					}
					modifier = {
						factor = 0.5
						is_lowborn = yes
					}
					min = 1
				}
				save_scope_as = your_courtier
			}
		}
	}

	option = {
		name = lmf_heir.1608.a #He must learn to be better
		stress_impact = {
			base = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			patient = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		scope:your_heir = {
			add_opinion = {
				target = scope:your_courtier
				modifier = insult_opinion
				opinion = -20
			}
		}
		random_list = {
			20 = {
				modifier = {
					add = {
						value = martial
						multiply = 3
					}
				}
				modifier = {
					add = {
						value = scope:your_heir.learning
						multiply = 2
					}
				}
				modifier = {
					add = 20
					has_trait = patient
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = diligent }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_good_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_good_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_good_3 }
				}
				modifier = {
					add = -20
					martial <= scope:your_heir.martial
				}
				desc = lmf_heir.1601.a.success.tt
				custom_tooltip = lmf_heir.1601.a.success.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_martial_lifestyle_xp = medium_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_loss
							curious = minor_stress_impact_loss
							diligent = minor_stress_impact_loss
							ambitious = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1601.a.success.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.success.effect.tt
						scope:your_heir = {
							add_martial_lifestyle_xp = medium_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_loss
								curious = minor_stress_impact_loss
								diligent = minor_stress_impact_loss
								ambitious = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = 20
							}
						}
						check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
					}
				}
			}
			60 = {
				modifier = {
					add = 20
					has_trait = impatient
				}
				modifier = {
					add = 20
					has_trait = irritable
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 40
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.failure.tt
				custom_tooltip = lmf_heir.1601.a.failure.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_martial_lifestyle_xp = minor_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
							lazy = minor_stress_impact_loss
							content = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = lmf_heir.1601.a.failure.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.failure.effect.tt
						scope:your_heir = {
							add_martial_lifestyle_xp = minor_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
								lazy = minor_stress_impact_loss
								content = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = -10
							}
						}
					}
				}
			}
			20 = {
				modifier = {
					add = 10
					has_trait = impatient
				}
				modifier = {
					add = 10
					has_trait = irritable
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1601.a.critfail.tt
				custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = medium_stress_impact_gain
							pensive = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							impatient = minor_stress_impact_gain
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1601.a.critfail.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = medium_stress_impact_gain
								pensive = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								impatient = minor_stress_impact_gain
							}
							change_variable = {
								name = heir_training_var
								add = -40
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
			modifier = {
				add = 50
				has_trait = patient
			}
			modifier = {
				add = -30
				martial < scope:your_heir.martial
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1608.b #Knight must know his place
		stress_impact = {
			compassionate = minor_stress_impact_gain
			impatient = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
		}
		scope:your_heir = {
			stress_impact = {
				base = minor_stress_impact_loss
			}
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		scope:your_courtier = {
			stress_impact = {
				base = medium_stress_impact_gain
			}
			worsen_relationship_effect = {
				TARGET = root
				REASON = forced_to_listen_to_heir
			}
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_vengefulness = 0.5
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.1608.c #They can work it out themselves
		stress_impact = {
			diligent = minor_stress_impact_gain
			impatient = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
		}
		random_list = {
			50 = {
				modifier = {
					add = {
						value = scope:your_heir.diplomacy
						multiply = 3
					}
				}
				desc = lmf_heir.1605.c.success.tt
				show_chance = no
				show_as_tooltip = {
					scope:your_courtier = {
						add_opinion = {
							target = scope:your_heir
							modifier = respect_opinion
							opinion = 20
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1605.c.success.tt
						right_icon = scope:your_courtier
						scope:your_courtier = {
							add_opinion = {
								target = scope:your_heir
								modifier = respect_opinion
								opinion = 20
							}
						}
					}
				}
			}
			50 = {
				desc = lmf_heir.1605.c.failure.tt
				show_chance = no
				show_as_tooltip = {
					scope:your_courtier = {
						worsen_relationship_effect = {
							TARGET = scope:your_heir
							REASON = not_convinced_to_help_heir
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1605.c.failure.tt
						right_icon = scope:your_courtier
						scope:your_courtier = {
							worsen_relationship_effect = {
								TARGET = scope:your_heir
								REASON = does_not_respect_heir
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 20
			modifier = {
				add = 50
				has_trait = impatient
			}
		}
	}
}

# Adult heir knight badly wounded
lmf_heir.1609 = {
	type = character_event
	title = lmf_heir.1609.t
	desc = lmf_heir.1609.desc
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = shock
	}
	override_background = { reference = army_camp }
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_health_bad" }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = {
				save_scope_as = your_heir
				hunt_wound_select_effect = yes
				random_list = {
					6 = {
						hunt_wound_apply_effect = { SEVERE = no }
					}
					2 = {
						hunt_wound_apply_effect = { SEVERE = yes }
					}
				}
			}
		}
	}

	option = {
		name = lmf_heir.1609.a
		custom_tooltip = lmf_heir.1609.a.injured.tt
		scope:your_heir = {
			show_as_tooltip = {
				if = {
					limit = { has_trait = wounded_1 }
					add_trait_force_tooltip = wounded_1
				}
				else_if = {
					limit = { has_trait = wounded_2 }
					add_trait_force_tooltip = wounded_2
				}
				else_if = {
					limit = { has_trait = wounded_3 }
					add_trait_force_tooltip = wounded_3
				}
				if = {
					limit = { scope:severe = yes }
					switch = {
						trigger = scope:wound
						flag:wound = {}
						flag:incapable = { add_trait_force_tooltip = incapable }
						flag:maimed = { add_trait_force_tooltip = maimed }
						flag:one_eyed = { add_trait_force_tooltip = one_eyed }
						flag:one_legged = { add_trait_force_tooltip = one_legged }
						flag:disfigured = { add_trait_force_tooltip = disfigured }
						flag:none = {}
					}
				}
			}
		}
	}
}

# Offload some duties onto adult heir?
lmf_heir.1610 = {
	type = character_event
	title = lmf_heir.1610.t
	desc = lmf_heir.1610.desc
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = thinking
	}
	override_background = { reference = throne_room }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
		}
	}

	option = {
		name = lmf_heir.1610.a #Do it
		stress_impact = {
			base = medium_stress_impact_loss
			trusting = minor_stress_impact_loss
			content = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		random_list = {
			40 = {
				modifier = {
					add = {
						value = scope:your_heir.stewardship
						multiply = 4
					}
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = diligent }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = ambitious }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_good_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_good_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_good_3 }
				}
				desc = lmf_heir.1610.a.success.tt
				custom_tooltip = lmf_heir.1601.a.success.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_stewardship_lifestyle_xp = medium_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_loss
							diligent = minor_stress_impact_loss
							ambitious = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1610.a.success.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.success.effect.tt
						scope:your_heir = {
							add_stewardship_lifestyle_xp = medium_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_loss
								diligent = minor_stress_impact_loss
								ambitious = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = 20
							}
						}
						check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
					}
				}
			}
			60 = {
				modifier = {
					add = 20
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 40
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1610.a.failure.tt
				custom_tooltip = lmf_heir.1601.a.failure.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_stewardship_lifestyle_xp = minor_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							arrogant = minor_stress_impact_gain
							lazy = minor_stress_impact_loss
							humble = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = lmf_heir.1610.a.failure.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.failure.effect.tt
						scope:your_heir = {
							add_stewardship_lifestyle_xp = minor_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								arrogant = minor_stress_impact_gain
								lazy = minor_stress_impact_loss
								humble = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = -10
							}
						}
					}
				}
			}
			20 = {
				modifier = {
					add = 10
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1610.a.critfail.tt
				custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = medium_stress_impact_gain
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1610.a.critfail.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = medium_stress_impact_gain
							}
							change_variable = {
								name = heir_training_var
								add = -40
							}
						}
					}
				}
			}
		}
		ai_chance = {
			factor = 50
			modifier = {
				add = 50
				has_trait = trusting
			}
			modifier = {
				add = 50
				has_trait = content
			}
			modifier = {
				add = 100
				stress > high_medium_stress
			}
		}
	}
	option = {
		name = lmf_heir.1610.b #No, he's not ready yet
		stress_impact = {
			base = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
			content = minor_stress_impact_gain
			paranoid = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
			stubborn = minor_stress_impact_loss
		}
		ai_chance = {
			factor = 50
			modifier = {
				add = 50
				has_trait = paranoid
			}
			modifier = {
				add = 50
				has_trait = ambitious
			}
			modifier = {
				add = 50
				has_trait = stubborn
			}
		}
	}
}

# Have heir work on local project?
lmf_heir.1611 = {
	type = character_event
	title = lmf_heir.1611.t
	desc = lmf_heir.1611.desc
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = thinking
	}
	override_background = { reference = market }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
			capital_county = { save_scope_as = project_county }
		}
	}

	option = {
		name = lmf_heir.1611.a #Do it
		remove_short_term_gold = medium_gold_value
		scope:your_heir = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		random_list = {
			40 = {
				modifier = {
					add = {
						value = scope:your_heir.stewardship
						multiply = 4
					}
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = diligent }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = ambitious }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_good_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_good_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_good_3 }
				}
				desc = lmf_heir.1611.a.success.tt
				custom_tooltip = lmf_heir.1601.a.success.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_stewardship_lifestyle_xp = medium_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_loss
							diligent = minor_stress_impact_loss
							ambitious = minor_stress_impact_loss
						}
					}
					capital_county = {
						add_county_modifier = {
							modifier = heir_successful_project_modifier
							years = 5
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good
						title = lmf_heir.1611.a.success.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.success.effect.tt
						scope:your_heir = {
							add_stewardship_lifestyle_xp = medium_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_loss
								diligent = minor_stress_impact_loss
								ambitious = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = 20
							}
						}
						check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
						capital_county = {
							add_county_modifier = {
								modifier = heir_successful_project_modifier
								years = 5
							}
						}
					}
				}
			}
			60 = {
				modifier = {
					add = 20
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 40
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1611.a.failure.tt
				custom_tooltip = lmf_heir.1601.a.failure.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						add_stewardship_lifestyle_xp = minor_lifestyle_xp
						stress_impact = {
							base = minor_stress_impact_gain
							diligent = minor_stress_impact_gain
							arrogant = minor_stress_impact_gain
							lazy = minor_stress_impact_loss
							humble = minor_stress_impact_loss
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = lmf_heir.1611.a.failure.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.failure.effect.tt
						scope:your_heir = {
							add_stewardship_lifestyle_xp = minor_lifestyle_xp
							stress_impact = {
								base = minor_stress_impact_gain
								diligent = minor_stress_impact_gain
								arrogant = minor_stress_impact_gain
								lazy = minor_stress_impact_loss
								humble = minor_stress_impact_loss
							}
							change_variable = {
								name = heir_training_var
								add = -10
							}
						}
					}
				}
			}
			20 = {
				modifier = {
					add = 10
					scope:your_heir = { has_trait = lazy }
				}
				modifier = {
					add = 10
					scope:your_heir = { has_trait = intellect_bad_1 }
				}
				modifier = {
					add = 20
					scope:your_heir = { has_trait = intellect_bad_2 }
				}
				modifier = {
					add = 30
					scope:your_heir = { has_trait = intellect_bad_3 }
				}
				desc = lmf_heir.1611.a.critfail.tt
				custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
				show_as_tooltip = {
					scope:your_heir = {
						stress_impact = {
							base = medium_stress_impact_gain
						}
					}
					capital_county = {
						add_county_modifier = {
							modifier = heir_failed_project_modifier
							years = 5
						}
					}
				}
				hidden_effect = {
					send_interface_message = {
						type = event_generic_bad
						title = lmf_heir.1611.a.critfail.tt
						right_icon = scope:your_heir
						custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
						scope:your_heir = {
							stress_impact = {
								base = medium_stress_impact_gain
							}
							change_variable = {
								name = heir_training_var
								add = -40
							}
						}
						capital_county = {
							add_county_modifier = {
								modifier = heir_failed_project_modifier
								years = 5
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 50
				has_trait = trusting
			}
			modifier = {
				add = 50
				has_trait = diligent
			}
			modifier = {
				add = 100
				scope:your_heir = { stewardship >= 15 }
			}
		}
	}
	option = {
		name = lmf_heir.1611.b #No, he's not ready
		scope:your_heir = {
			stress_impact = {
				base = minor_stress_impact_gain
			}
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 50
				has_trait = paranoid
			}
			modifier = {
				add = 50
				has_trait = lazy
			}
			modifier = {
				add = 100
				scope:your_heir = { stewardship <= 5 }
			}
		}
	}
}

# Heir has conflicting or sinful trait
lmf_heir.1612 = {
	type = character_event
	title = lmf_heir.1612.t
	desc = {
		desc = lmf_heir.1612.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:heir_trait = {
						any_opposite_trait = {
							root = { has_trait = prev }
						}
					}
				}
				desc = lmf_heir.1612.desc.opposite
			}
			triggered_desc = {
				trigger = {
					faith = { trait_is_sin = scope:heir_trait }
					num_sinful_traits > 0
				}
				desc = lmf_heir.1612.desc.alsosinful
			}
			triggered_desc = {
				trigger = {
					faith = { trait_is_sin = scope:heir_trait }
				}
				desc = lmf_heir.1612.desc.sinful
			}
			desc = lmf_heir.1612.desc.default
		}
		desc = lmf_heir.1612.desc.end
	}
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = shame
	}

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = {
				save_scope_as = your_heir
				random_character_trait = {
					limit = {
						is_objectionable_ruler_trait_trigger = { HEIR = scope:your_heir HOST = root }
					}
					weight = {
						base = 1
						modifier = {
							add = 2
							has_trait_category = personality
							root.faith = {
								this = scope:your_heir.faith
								trait_is_sin = prev
							}
							root = { num_sinful_traits > 0 }
							any_opposite_trait = {
								root = { has_trait = prev }
							}
						}
						modifier = {
							add = 3
							is_positive_ruler_trait = no
							any_opposite_trait = {
								root = { has_trait = prev }
							}
						}
						modifier = {
							add = 6
							has_trait_category = personality
							root.faith = {
								this = scope:your_heir.faith
								trait_is_sin = prev
							}
							root = { num_sinful_traits < 1 }
							any_opposite_trait = {
								root = { has_trait = prev }
							}
						}
						modifier = {
							add = 9
							is_negative_ruler_trait = yes
						}
						modifier = {
							add = 4
							has_trait_category = personality
							is_negative_ruler_trait = no
							is_positive_ruler_trait = no
						}
						modifier = {
							add = 1
							NOT = { has_trait_category = personality }
						}
					}
					save_scope_as = heir_trait
					scope:your_heir = {
						set_variable = {
							name = heir_trait
							value = scope:heir_trait
						}
					}
				}
			}
		}
	}

	option = {
		name = lmf_heir.1612.a #Encourage them to change
		scope:your_heir = {
			stress_impact = {
				base = medium_stress_impact_gain
				diligent = minor_stress_impact_loss
				trusting = minor_stress_impact_loss
				stubborn = minor_stress_impact_gain
				paranoid = minor_stress_impact_gain
			}
			random_list = {
				50 = {
					modifier = {
						add = {
							value = root.diplomacy
							multiply = 2
						}
					}
					modifier = {
						add = 10
						has_trait = diligent
					}
					modifier = {
						add = 10
						has_trait = trusting
					}
					show_as_tooltip = {
						remove_trait_force_tooltip = scope:heir_trait
					}
					hidden_effect = {
						root = {
							send_interface_message = {
								type = event_generic_good
								title = lmf_heir.1612.a.success.tt
								right_icon = scope:your_heir
								scope:your_heir = {
									remove_trait_force_tooltip = scope:heir_trait
								}
							}
						}
					}
				}
				50 = {
					modifier = {
						add = 10
						has_trait = stubborn
					}
					modifier = {
						add = 10
						has_trait = paranoid
					}
					show_as_tooltip = {
						worsen_relationship_effect = {
							TARGET = root
							REASON = tried_to_change_heir
						}
					}
					hidden_effect = {
						root = {
							send_interface_message = {
								type = event_generic_bad
								title = lmf_heir.1612.a.failure.tt
								right_icon = scope:your_heir
								scope:your_heir = {
									worsen_relationship_effect = {
										TARGET = root
										REASON = tried_to_change_heir
									}
								}
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 70
			modifier = {
				add = 50
				faith = { trait_is_sin = scope:heir_trait }
				OR = {
					has_trait = zealous
					AND = {
						num_sinful_traits < 1
						ai_zeal >= 0
					}
				}
			}
			modifier = {
				add = 50
				scope:heir_trait = { is_negative_ruler_trait = yes }
			}
		}
	}
	option = {
		name = lmf_heir.1612.b #Leave it well enough alone
		scope:your_heir = {
			add_opinion = {
				target = root
				modifier = kindness_opinion
				opinion = 20
			}
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_compassion = 1
			}
			modifier = {
				add = 50
				scope:heir_trait = { is_positive_ruler_trait = yes }
			}
			min = 1
		}
	}

	after = {
		scope:your_heir = { remove_variable = heir_trait }
	}
}

# Heir shirking responsibilities
lmf_heir.1613 = {
	type = character_event
	title = lmf_heir.1613.t
	desc = lmf_heir.1613.desc
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = boredom
	}
	override_background = { reference = throne_room }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
		}
	}

	option = {
		name = lmf_heir.1613.a
		custom_tooltip = lmf_heir.1601.a.critfail.effect.tt
		scope:your_heir = {
			stress_impact = {
				base = minor_stress_impact_loss
			}
			change_variable = {
				name = heir_training_var
				add = -20
			}
		}
	}
}

# Heir showing real dedication
lmf_heir.1614 = {
	type = character_event
	title = lmf_heir.1614.t
	desc = lmf_heir.1614.desc
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = personality_bold
	}
	override_background = { reference = throne_room }

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
		}
	}

	option = {
		name = lmf_heir.1614.a
		custom_tooltip = lmf_heir.1601.a.success.effect.tt
		scope:your_heir = {
			stress_impact = {
				base = minor_stress_impact_gain
			}
			change_variable = {
				name = heir_training_var
				add = 20
			}
			if = {
				limit = { root.diplomacy >= scope:your_heir.diplomacy_plus_5 }
				add_diplomacy_skill = 1
			}
			else_if = {
				limit = { root.stewardship >= scope:your_heir.stewardship_plus_5 }
				add_stewardship_skill = 1
			}
			else_if = {
				limit = { root.martial >= scope:your_heir.martial_plus_5 }
				add_martial_skill = 1
			}
			else_if = {
				limit = { root.learning >= scope:your_heir.learning_plus_5 }
				add_learning_skill = 1
			}
			else_if = {
				limit = { root.intrigue >= scope:your_heir.intrigue_plus_5 }
				add_intrigue_skill = 1
			}
		}
		check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = root }
	}
}

# Heir gains a trait of liege's
lmf_heir.1615 = {
	type = character_event
	title = lmf_heir.1615.t
	desc = lmf_heir.1615.desc
	theme = family

	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:your_heir
		animation = admiration
	}

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = { save_scope_as = your_heir }
			random_character_trait = {
				limit = {
					has_trait_category = personality
					NOR = {
						scope:your_heir = { has_trait = prev }
						any_opposite_trait = {
							scope:your_heir = { has_trait = prev }
						}
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 2
						NOT = {
							scope:your_heir.faith = {
								trait_is_sin = prev
							}
						}
					}
				}
				save_scope_as = heir_trait
			}
		}
	}

	option = {
		name = lmf_heir.1615.a
		scope:your_heir = { add_trait_force_tooltip = scope:heir_trait }
	}
}


################################
# HEIR TRAVELING ABROAD EVENTS #
################################

scripted_trigger heir_can_crush_trigger = {
	is_adult = no
	num_of_relation_crush < 1
	ai_boldness >= 0
	might_cheat_on_every_partner_trigger = yes
	NOR = {
		has_trait = chaste
		has_sexuality = asexual
		is_malformed_trigger = yes
		has_any_illness = yes
		is_involved_in_any_romantic_scheme = yes
	}
}

scripted_trigger is_candidate_for_heir_crush = {
	OR = {
		AND = {
			is_landed = yes
			age <= 40
		}
		AND = {
			age < 20
			age >= scope:your_heir.age_minus_3
		}
	}
	is_below_ai_lover_soft_cap_trigger = yes
	is_interesting_character_trigger = yes
	is_available = yes
	has_recoverable_disease_trigger = no
	trigger_if = {
		limit = { is_adult = yes }
		might_cheat_on_every_partner_trigger = yes
		willing_to_take_character_as_lover = { LOVER = scope:your_heir }
	}
	trigger_else = {
		num_of_relation_crush < 1
		is_attracted_to_gender_of = scope:your_heir
	}
	reverse_opinion = { target = scope:your_heir value >= -10 }
	trait_compatibility = { target = scope:your_heir value > medium_negative_trait_compatibility }
	NOR = {
		has_trait = chaste
		is_clergy = yes
		has_trait = devoted
		has_council_position = councillor_court_chaplain
		is_close_or_extended_family_of = scope:your_heir
		is_malformed_trigger = yes
		is_unattractive_trigger = yes
		has_any_illness = yes
		is_involved_in_any_romantic_scheme = yes
		has_relation_friend = scope:your_heir
		has_relation_rival = scope:your_heir
	}
}

scripted_trigger is_candidate_for_heir_seduction = {
	is_adult = yes
	is_below_ai_lover_soft_cap_trigger = yes
	is_interesting_character_trigger = yes
	is_available = yes
	has_recoverable_disease_trigger = no
	fertility > 0.1
	trigger_if = {
		limit = { is_landed = yes }
		OR = {
			age < 40
			has_trait = beauty_good
			has_trait = physique_good
			diplomacy >= 20
		}
	}
	trigger_else_if = {
		limit = {
			scope:your_heir = {
				is_female = yes
				age < 25
			}
		}
		age <= scope:your_heir.age_plus_25
		age >= scope:your_heir.age_minus_10
	}
	trigger_else_if = {
		limit = {
			scope:your_heir = { is_female = yes }
		}
		age <= scope:your_heir.age_plus_10
		age >= scope:your_heir.age_minus_10
	}
	trigger_else = {
		age <= scope:your_heir.age
		age >= scope:your_heir.age_minus_25
	}
	can_set_relation_lover_trigger = { CHARACTER = scope:your_heir }
	might_cheat_on_every_partner_trigger = yes
	willing_to_take_character_as_lover = { LOVER = scope:your_heir }
	save_temporary_scope_as = potential_lover
	accepts_incest_with_each_other_trigger = { CHARACTER_1 = scope:your_heir CHARACTER_2 = scope:potential_lover }
	trigger_if = {
		limit = {
			scope:your_heir = { ai_boldness < 20 }
		}
		NOR = {
			primary_spouse ?= { is_liege_or_above_of = scope:your_heir }
			any_parent = { is_liege_or_above_of = scope:your_heir }
		}
	}
	trigger_if = {
		limit = {
			scope:your_heir = { ai_honor > 0 }
		}
		OR = {
			is_married = no
			is_consort_of = scope:your_heir
		}
		OR = {
			is_betrothed = no
			betrothed = { this = scope:your_heir }
		}
	}
	trigger_if = {
		limit = {
			scope:your_heir = {
				NOR = {
					is_deviant_trigger = yes
					ai_zeal <= low_negative_ai_value
					faith = { has_doctrine = tenet_carnal_exaltation }
					faith = { has_doctrine = doctrine_clerical_marriage_allowed }
				}
			}
		}
		NOR = {
			is_clergy = yes
			has_trait = devoted
			has_council_position = councillor_court_chaplain
		}
	}
	reverse_opinion = { target = scope:your_heir value >= -10 }
	OR = {
		trait_compatibility = { target = scope:your_heir value > low_positive_trait_compatibility }
		has_relation_potential_lover = scope:your_heir
	}
	NOR = {
		has_trait = chaste
		has_trait = infirm
		is_malformed_trigger = yes
		is_unattractive_trigger = yes
		has_any_illness = yes
		is_involved_in_any_romantic_scheme = yes
		has_relation_friend = scope:your_heir
		has_relation_rival = scope:your_heir
	}
}

scripted_trigger is_candidate_for_heir_teaching = {
	is_available_ai = yes
	has_recoverable_disease_trigger = no
	NOR = {
		has_relation_rival = scope:your_heir
		has_relation_guardian = scope:your_heir
		has_relation_ward = scope:your_heir
		has_relation_rival = scope:heir_liege
		this = scope:heir_liege
		has_character_flag = no_heir_training
	}
}

scripted_trigger is_candidate_for_heir_friend = {
	num_of_relation_friend <= 3
	sex_same_as = scope:your_heir
	is_available = yes
	has_recoverable_disease_trigger = no
	can_set_relation_friend_trigger = { CHARACTER = scope:your_heir }
	OR = {
		trait_compatibility = { target = scope:your_heir value >= medium_positive_trait_compatibility }
		has_relation_potential_friend = scope:your_heir
	}
	trigger_if = {
		limit = {
			scope:your_heir = { is_adult = no }
		}
		age >= scope:your_heir.age_plus_3
		age <= scope:your_heir.age_minus_3
	}
	trigger_else = {
		age >= 15
		age >= scope:your_heir.age_plus_5
		age <= scope:your_heir.age_minus_5
	}
	OR = {
		highest_held_title_tier > tier_barony
		is_councillor = yes
		any_close_or_extended_family_member = { highest_held_title_tier > tier_barony }
		any_spouse = { highest_held_title_tier > tier_barony }
		AND = {
			exists = dynasty
			dynasty.dynasty_prestige_level >= 2
		}
	}
	NOR = {
		has_relation_potential_rival = scope:your_heir
		has_relation_lover = scope:your_heir
	}
}

scripted_trigger is_candidate_for_heir_enemy = {
	num_of_relation_rival < 3
	sex_same_as = scope:your_heir
	is_available = yes
	has_recoverable_disease_trigger = no
	can_set_relation_rival_trigger = { CHARACTER = scope:your_heir }
	OR = {
		trait_compatibility = { target = scope:your_heir value <= medium_negative_trait_compatibility }
		has_relation_potential_rival = scope:your_heir
	}
	trigger_if = {
		limit = {
			scope:your_heir = { is_adult = no }
		}
		age >= scope:your_heir.age_plus_3
		age <= scope:your_heir.age_minus_3
	}
	trigger_else = {
		age >= 15
		age >= scope:your_heir.age_plus_5
		age <= scope:your_heir.age_minus_5
	}
	OR = {
		highest_held_title_tier > tier_barony
		is_councillor = yes
		any_close_or_extended_family_member = { highest_held_title_tier > tier_barony }
		any_spouse = { highest_held_title_tier > tier_barony }
		AND = {
			exists = dynasty
			dynasty.dynasty_prestige_level >= 2
		}
	}
	NOR = {
		has_relation_potential_friend = scope:your_heir
		has_relation_lover = scope:your_heir
	}
}

scripted_trigger heir_can_learn_secrets = {
	has_any_secrets = yes
	OR = {
		is_ruler = yes
		is_close_or_extended_family_of = scope:heir_visit_target
		is_close_or_extended_family_of = scope:heir_liege
		is_councillor_of = scope:heir_visit_target
	}
	trigger_if = {
		limit = { is_ruler = yes }
		highest_held_title_tier >= tier_county
	}
	NOR = {
		has_relation_friend = scope:your_heir
		this = scope:heir_liege
	}
}

scripted_trigger culture_differs_from_heir = {
	NOR = {
		scope:your_heir.culture = { has_same_culture_language = $TARGET$.culture }
		scope:your_heir = { knows_language_of_culture = $TARGET$.culture }
	}
}

scripted_effect start_heir_travel_plan_effect = {
	$VISITING$ = {
		hidden_effect = {
			add_character_flag = { flag = had_recent_heir_visit years = 5 }
			set_variable = { name = visited_by_heir value = $VISITOR$ }
		}
	}
	$VISITOR$ = {
		hidden_effect = {
			create_story = {
				type = lmf_heir_visit_story_cycle
				save_scope_as = story
			}
			scope:story ?= {
				set_variable = { name = heir_liege value = $PARENT$ }
				set_variable = { name = heir_visit_origin value = $VISITOR$.location }
				set_variable = { name = heir_visit_target value = $VISITING$ }
				set_variable = { name = heir_visit_location value = $VISITING$.capital_province }
			}
			start_travel_plan = {
				destination = $VISITING$.capital_province
				on_travel_planner_cancel_event = lmf_heir.1630
				on_arrival_event = lmf_heir.1631
				on_arrival_destinations = all_but_last
			}
		}
	}
}

scripted_effect heir_cancel_visit_notification = {
	if = {
		limit = {
			scope:your_heir = { is_incapable = yes }
		}
		send_interface_message = {
			type = event_generic_bad_with_text
			title = lmf_heir.1630.t.cancel
			desc = lmf_heir.1630.desc.incapable
			left_icon = scope:your_heir
			right_icon = scope:heir_visit_target
		}
	}
	else_if = {
		limit = {
			exists = scope:heir_liege.player_heir
			NOT = { scope:your_heir = scope:heir_liege.player_heir }
		}
		send_interface_message = {
			type = event_generic_bad_with_text
			title = lmf_heir.1630.t.cancel
			desc = lmf_heir.1630.desc.notheir
			left_icon = scope:your_heir
			right_icon = scope:heir_visit_target
		}
	}
	else_if = {
		limit = {
			NOT = { exists = scope:heir_liege.player_heir }
		}
		send_interface_message = {
			type = event_generic_bad_with_text
			title = lmf_heir.1630.t.cancel
			desc = lmf_heir.1630.desc.notruler
			left_icon = scope:your_heir
			right_icon = scope:heir_visit_target
		}
	}
	else = {
		send_interface_message = {
			type = event_generic_bad_with_text
			title =  lmf_heir.1631.t.cancel
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:heir_visit_target = { is_alive = no }
						}
						desc = lmf_heir.1631.desc.dead
					}
					triggered_desc = {
						trigger = {
							scope:heir_visit_target = {
								NOT = { this = scope:target_county.holder }
							}
						}
						desc = lmf_heir.1631.desc.notruler
					}
					triggered_desc = {
						trigger = {
							scope:heir_visit_target = { is_imprisoned = yes }
						}
						desc = lmf_heir.1631.desc.imprisoned
					}
					triggered_desc = {
						trigger = {
							scope:heir_visit_location = {
								OR = {
									is_occupied = yes
									any_army_in_location = {
										army_owner = { is_at_war_with = scope:heir_visit_target }
									}
								}
							}
						}
						desc = lmf_heir.1631.desc.siege
					}
					triggered_desc = {
						trigger = {
							scope:heir_visit_target = { has_character_modifier = isolating_modifier }
						}
						desc = lmf_heir.1631.desc.isolating
					}
					triggered_desc = {
						trigger = {
							scope:target_county = { has_county_modifier = isolate_capital_decision_modifier }
						}
						desc = lmf_heir.1631.desc.capital
					}
					triggered_desc = {
						trigger = {
							scope:heir_visit_target = { is_incapable = yes }
						}
						desc = lmf_heir.1631.desc.incapable
					}
					desc = lmf_heir.1631.desc
				}
			}
			left_icon = scope:your_heir
			right_icon = scope:heir_visit_target
			if = {
				limit = {
					is_ai = no
					player_heir ?= scope:your_heir
				}
				scope:your_heir = {
					show_as_tooltip = { heir_learns_from_visit_effect = yes }
				}
			}
		}
	}
}

scripted_effect heir_gathers_secrets_effect = {
	save_temporary_scope_as = secret_holder
	every_secret = {
		limit = {
			NOR = {
				is_in_list = potential_secrets
				is_known_by = scope:your_heir
				secret_is_incriminating_trigger = { TARGET = scope:your_heir }
			}
			OR = {
				is_blackmailable_secret_trigger = { BLACKMAILER = scope:your_heir PARTICIPANT = scope:secret_holder }
				secret_is_always_interesting_trigger = yes
			}
		}
		add_to_list = potential_secrets
	}
}

scripted_effect heir_learns_secret_effect = {
	if = {
		limit = {
			list_size = { name = potential_secrets value > 0 }
		}
		random_in_list = {
			list = potential_secrets
			weight = {
				base = 1
				modifier = {
					add = 20
					secret_owner = { has_relation_rival = scope:your_heir }
				}
				modifier = {
					add = 10
					secret_owner = { has_relation_rival = scope:heir_liege }
				}
				modifier = {
					add = 10
					secret_owner = scope:heir_visit_target
				}
				modifier = {
					add = 5
					NOT = { secret_owner = scope:heir_visit_target }
					secret_owner = { is_ruler = yes }
				}
				modifier = {
					add = 2
					secret_owner = {
						is_ruler = no
						any_heir_title = {}
					}
				}
				modifier = {
					add = 3
					secret_owner = { is_close_family_of = scope:heir_visit_target }
				}
				modifier = {
					add = -2
					secret_owner = {
						reverse_opinion = { target = scope:your_heir value >= 20 }
					}
				}
				modifier = {
					add = -2
					secret_owner = {
						reverse_opinion = { target = scope:your_heir value >= 50 }
					}
				}
				modifier = {
					add = 2
					secret_owner = {
						NOT = { has_relation_rival = scope:your_heir }
						reverse_opinion = { target = scope:your_heir value < 0 }
					}
				}
				min = 1
			}
			hidden_effect = {
				reveal_to = scope:your_heir
				if = {
					limit = {
						NOR = {
							is_known_by = scope:heir_liege
							secret_is_incriminating_trigger = { TARGET = scope:heir_liege }
						}
					}
					set_variable = { name = heir_will_reveal value = yes }
				}
				remove_from_list = potential_secrets
			}
		}
	}
}

scripted_effect add_heir_lifestyle_effect = {
	if = {
		limit = { scope:story.var:visit_$SKILL$ = 1 }
		add_$SKILL$_lifestyle_xp = 100
	}
	if = {
		limit = { scope:story.var:visit_$SKILL$ = 2 }
		add_$SKILL$_lifestyle_xp = 300
	}
	if = {
		limit = { scope:story.var:visit_$SKILL$ = 3 }
		add_$SKILL$_lifestyle_xp = 300
		add_$SKILL$_skill = 1
	}
	if = {
		limit = { scope:story.var:visit_$SKILL$ = 4 }
		add_$SKILL$_lifestyle_xp = 500
		add_$SKILL$_skill = 1
	}
	if = {
		limit = { scope:story.var:visit_$SKILL$ > 4 }
		add_$SKILL$_lifestyle_xp = 500
		add_$SKILL$_skill = 2
	}
}

scripted_effect heir_learns_from_visit_effect = {
	# increase/decrease heir training
	if = {
		limit = {
			has_variable = heir_training_var
			scope:story.var:visit_success > 0
		}
		if = {
			limit = { scope:story.var:visit_success > 4 }
			custom_tooltip = lmf_heir.heir.progress.large.tt
		}
		else_if = {
			limit = { scope:story.var:visit_success > 2 }
			custom_tooltip = lmf_heir.heir.progress.moderate.tt
		}
		else = {
			custom_tooltip = lmf_heir.heir.progress.minor.tt
		}
		change_variable = {
			name = heir_training_var
			add = {
				value = scope:story.var:visit_success
				multiply = 5
			}
		}
		check_heir_training_trait = { HEIR = scope:your_heir HEIR_LIEGE = scope:heir_liege }
	}
	if = {
		limit = {
			has_variable = heir_training_var
			scope:story.var:visit_success < 0
		}
		custom_tooltip = lmf_heir.heir.progress.negative.tt
		change_variable = {
			name = heir_training_var
			add = {
				value = scope:story.var:visit_success
				multiply = 5
			}
		}
	}
	# increase lifestyle XP
	if = {
		limit = { scope:story.var:visit_diplomacy > 0 }
		add_heir_lifestyle_effect = { SKILL = diplomacy }
	}
	if = {
		limit = { scope:story.var:visit_martial > 0 }
		add_heir_lifestyle_effect = { SKILL = martial }
	}
	if = {
		limit = { scope:story.var:visit_prowess > 0 }
		add_prowess_skill = scope:story.var:visit_prowess
	}
	if = {
		limit = { scope:story.var:visit_stewardship > 0 }
		add_heir_lifestyle_effect = { SKILL = stewardship }
	}
	if = {
		limit = { scope:story.var:visit_intrigue > 0 }
		add_heir_lifestyle_effect = { SKILL = intrigue }
	}
	if = {
		limit = { scope:story.var:visit_learning > 0 }
		add_heir_lifestyle_effect = { SKILL = learning }
	}
	# increase lifestyle hunter XP
	if = {
		limit = { scope:story.var:visit_hunter > 0 }
		if = {
			limit = { NOT = { has_trait = lifestyle_hunter } }
			add_trait_force_tooltip = lifestyle_hunter
			if = {
				limit = { scope:story.var:visit_hunter > 1 }
				add_trait_xp = {
					trait = lifestyle_hunter
					track = hunter
					value = {
						value = scope:story.var:visit_hunter
						add = -1
						multiply = 10
					}
				}
			}
		}
		else = {
			add_trait_xp = {
				trait = lifestyle_hunter
				track = hunter
				value = {
					value = scope:story.var:visit_hunter
					multiply = 10
				}
			}
		}
	}
	# increase lifestyle reveler XP
	if = {
		limit = { scope:story.var:visit_reveler > 0 }
		if = {
			limit = { NOT = { has_trait = lifestyle_reveler } }
			add_trait_force_tooltip = lifestyle_reveler
			if = {
				limit = { scope:story.var:visit_reveler > 1 }
				add_trait_xp = {
					trait = lifestyle_reveler
					value = {
						value = scope:story.var:visit_reveler
						add = -1
						multiply = 10
					}
				}
			}
		}
		else = {
			add_trait_xp = {
				trait = lifestyle_reveler
				value = {
					value = scope:story.var:visit_reveler
					multiply = 10
				}
			}
		}
	}
	# add open minded perk
	if = {
		limit = {
			scope:story.var:visit_language > 0
			NOT = { has_perk = open_minded_perk }
		}
		random = {
			chance = 0
			modifier = {
				add = {
					value = scope:story.var:visit_language
					multiply = 30
				}
			}
			modifier = {
				add = {
					value = learning
					multiply = 2
				}
			}
			max = 100
			add_perk = open_minded_perk
			if = {
				limit = { has_trait = lifestyle_mystic }
				add_trait_xp = {
					trait = lifestyle_mystic
					value = lifestyle_mystic_xp_gain_minor_value
				}
			}
		}
	}
	# reveals learned secrets to liege
	if = {
		limit = {
			any_known_secret = {
				has_variable = heir_will_reveal
				NOR = {
					is_known_by = scope:heir_liege
					secret_is_incriminating_trigger = { TARGET = scope:heir_liege }
					secret_is_incriminating_trigger = { TARGET = scope:your_heir }
				}
			}
		}
		custom_tooltip = lmf_heir.1681.secrets.to.tell.tt
		every_known_secret = {
			limit = {
				has_variable = heir_will_reveal
				NOR = {
					is_known_by = scope:heir_liege
					secret_is_incriminating_trigger = { TARGET = scope:heir_liege }
					secret_is_incriminating_trigger = { TARGET = scope:your_heir }
				}
			}
			reveal_to = scope:heir_liege
			remove_variable = heir_will_reveal
		}
	}
}

scripted_effect record_visit_item_effect = {
	if = {
		limit = {
			NOT = { exists = scope:first_visit_item }
		}
		save_scope_value_as = { name = first_visit_item value = flag:$ITEM$ }
	}
	else_if = {
		limit = {
			NOT = { exists = scope:second_visit_item }
		}
		save_scope_value_as = { name = second_visit_item value = flag:$ITEM$ }
	}
	else = {
		save_scope_value_as = { name = third_visit_item value = flag:$ITEM$ }
	}
}

scripted_effect advance_heir_timer_effect = {
	scope:story = {
		change_variable = { name = visit_time add = 1 }
	}
	scope:your_heir = {
		if = {
			limit = { scope:story.var:visit_time = 4 }
			trigger_event = { id = lmf_heir.1650 days = 14 }
		}
		else = {
			trigger_event = { id = lmf_heir.1650 days = { 45 60 } }
		}
	}
}

# Send heir to spend time abroad?
lmf_heir.1625 = {
	type = character_event
	title = lmf_heir.1625.t
	desc = {
		desc = lmf_heir.1625.desc.start
		first_valid = {
			triggered_desc = {
				trigger = { is_close_or_extended_family_of = scope:your_heir }
				desc = lmf_heir.1625.desc.family
			}
			desc = lmf_heir.1625.desc.notfamily
		}
		desc = lmf_heir.1625.desc.mid
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:your_vassal.diplomacy > scope:your_heir.diplomacy
					scope:your_vassal.diplomacy > root.diplomacy
				}
				desc = lmf_heir.1625.desc.diplomacy
			}
			triggered_desc = {
				trigger = {
					scope:your_vassal.stewardship > scope:your_heir.stewardship
					scope:your_vassal.stewardship > root.stewardship
				}
				desc = lmf_heir.1625.desc.stewardship
			}
			triggered_desc = {
				trigger = {
					scope:your_vassal.martial > scope:your_heir.martial
					scope:your_vassal.martial > root.martial
				}
				desc = lmf_heir.1625.desc.martial
			}
			triggered_desc = {
				trigger = {
					scope:your_vassal.learning > scope:your_heir.learning
					scope:your_vassal.learning > root.learning
				}
				desc = lmf_heir.1625.desc.learning
			}
			desc = lmf_heir.1625.desc.intrigue
		}
		desc = lmf_heir.1625.desc.bridge
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:your_vassal = {
						OR = {
							has_relation_friend = scope:your_heir
							has_relation_lover = scope:your_heir
						}
					}
				}
				desc = lmf_heir.1625.desc.myfriend
			}
			triggered_desc = {
				trigger = {
					scope:your_vassal = { is_close_or_extended_family_of = root }
				}
				desc = lmf_heir.1625.desc.alsofamily
			}
			triggered_desc = {
				trigger = {
					scope:your_vassal = { has_relation_friend = root }
				}
				desc = lmf_heir.1625.desc.friend
			}
			triggered_desc = {
				trigger = {
					scope:your_vassal = { is_allied_to = root }
				}
				desc = lmf_heir.1625.desc.ally
			}
			triggered_desc = {
				trigger = {
					scope:your_vassal = { is_vassal_of = root }
				}
				desc = lmf_heir.1625.desc.vassal
			}
			triggered_desc = {
				trigger = {
					top_liege != this
					target_is_liege_or_above = scope:your_vassal
				}
				desc = lmf_heir.1625.desc.liege
			}
			desc = lmf_heir.1625.desc.realm
		}
		desc = lmf_heir.1625.desc.end
	}
	theme = family

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:your_heir
		animation = throne_room_bow_3
	}
	lower_right_portrait = scope:your_vassal

	immediate = {
		hidden_effect = {
			add_heir_event_delay_flags_effect = yes
			player_heir = {
				save_scope_as = your_heir
				add_character_flag = no_hat
			}

			# build the list of candidates
			top_liege = {
				if = {
					limit = { is_appropriate_heir_visit_target = { HEIR = scope:your_heir } }
					add_to_list = potential_heir_targets
				}
				every_vassal_or_below = {
					limit = {
						is_appropriate_heir_visit_target = { HEIR = scope:your_heir }
						NOT = { is_in_list = potential_heir_targets }
					}
					add_to_list = potential_heir_targets
				}
			}
			every_ally = {
				limit = {
					is_appropriate_heir_visit_target = { HEIR = scope:your_heir }
					NOT = { is_in_list = potential_heir_targets }
				}
				add_to_list = potential_heir_targets
			}
			every_relation = {
				type = friend
				limit = {
					is_appropriate_heir_visit_target = { HEIR = scope:your_heir }
					NOT = { is_in_list = potential_heir_targets }
				}
				add_to_list = potential_heir_targets
			}
			every_close_or_extended_family_member = {
				limit = {
					is_appropriate_heir_visit_target = { HEIR = scope:your_heir }
					NOT = { is_in_list = potential_heir_targets }
				}
				add_to_list = potential_heir_targets
			}

			random_in_list = {
				list = potential_heir_targets
				weight = {
					base = 10
					ai_value_modifier = {
						ai_honor = 0.5
						max = 20
					}
					opinion_modifier = {
						who = this
						opinion_target = root
						multiplier = 0.5
						max = 20
					}
					modifier = {
						add = 30
						is_ai = no
					}
					modifier = {
						add = 10
						is_allied_to = root
					}
					modifier = {
						add = 10
						is_close_or_extended_family_of = scope:your_heir
					}
					modifier = {
						add = 10
						highest_held_title_tier == tier_duchy
					}
					modifier = {
						add = 20
						highest_held_title_tier > tier_duchy
					}
					modifier = {
						add = 10
						has_relation_friend = root
					}
					modifier = {
						add = 20
						OR = {
							has_relation_friend = scope:your_heir
							any_courtier = { has_relation_friend = scope:your_heir }
						}
					}
					modifier = {
						add = 50
						OR = {
							has_relation_lover = scope:your_heir
							any_courtier = { has_relation_lover = scope:your_heir }
						}
					}
					modifier = {
						add = -5
						NOR = {
							liege = root
							is_liege_or_above_of = root
						}
					}
					modifier = {
						add = -5
						scope:your_heir = { ai_energy < 0 }
						NOT = { target_is_liege_or_above = root }
					}
					modifier = {
						add = 10
						scope:your_heir = { ai_energy >= 20 }
						NOT = { target_is_liege_or_above = root }
					}
					modifier = {
						add = 10
						scope:your_heir = { ai_energy >= 50 }
						NOT = { target_is_liege_or_above = root }
					}
					modifier = {
						add = {
							value = diplomacy
							multiply = 3
							subtract = scope:your_heir.diplomacy
						}
						diplomacy > root.diplomacy
						diplomacy > scope:your_heir.diplomacy
					}
					modifier = {
						add = {
							value = stewardship
							multiply = 3
							subtract = scope:your_heir.stewardship
						}
						stewardship > root.stewardship
						stewardship > scope:your_heir.stewardship
						OR = {
							diplomacy <= root.diplomacy
							diplomacy <= scope:your_heir.diplomacy
						}
					}
					modifier = {
						add = {
							value = martial
							multiply = 3
							subtract = scope:your_heir.martial
						}
						martial > root.martial
						martial > scope:your_heir.martial
						OR = {
							diplomacy <= root.diplomacy
							diplomacy <= scope:your_heir.diplomacy
							stewardship <= root.stewardship
							stewardship <= scope:your_heir.stewardship
						}
					}
					modifier = {
						add = {
							value = learning
							multiply = 3
							subtract = scope:your_heir.learning
						}
						learning > root.learning
						learning > scope:your_heir.learning
						OR = {
							diplomacy <= root.diplomacy
							diplomacy <= scope:your_heir.diplomacy
							stewardship <= root.stewardship
							stewardship <= scope:your_heir.stewardship
							martial <= root.martial
							martial <= scope:your_heir.martial
						}
					}
					modifier = {
						add = {
							value = intrigue
							multiply = 3
							subtract = scope:your_heir.intrigue
						}
						intrigue > root.intrigue
						intrigue > scope:your_heir.intrigue
						OR = {
							diplomacy <= root.diplomacy
							diplomacy <= scope:your_heir.diplomacy
							stewardship <= root.stewardship
							stewardship <= scope:your_heir.stewardship
							martial <= root.martial
							martial <= scope:your_heir.martial
							learning <= root.learning
							learning <= scope:your_heir.learning
						}
					}
					modifier = {
						factor = 0.5
						is_ai = yes
						capital_province = {
							squared_distance = { target = root.capital_province value < 150000 }
						}
					}
					min = 1
				}
				save_scope_as = your_vassal
			}
		}
	}

	option = {
		name = lmf_heir.1625.a #He may go
		if = {
			limit = {
				scope:your_vassal = { is_ai = no }
			}
			custom_tooltip = lmf_heir.1625.a.player.tt
			root = { save_scope_as = heir_liege }
			scope:your_vassal = { trigger_event = lmf_heir.1626 }
		}
		else = {
			custom_tooltip = lmf_heir.1625.a.tt
			start_heir_travel_plan_effect = { VISITOR = scope:your_heir VISITING = scope:your_vassal PARENT = root }
		}
		ai_chance = {
			factor = 80
			ai_value_modifier = {
				ai_compassion = 1
			}
			min = 1
		}
	}
	option = {
		name = lmf_heir.1625.b #Absolutely not. He stays here.
		scope:your_heir = {
			stress_impact = {
				base = minor_stress_impact_gain
			}
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		ai_chance = {
			factor = 20
		}
	}

	after = {
		player_heir = { remove_no_hat_effect = yes }
	}
}

# Asking a player permission for heir to visit
lmf_heir.1626 = {
	type = letter_event
	opening = lmf_heir.1626.opening
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { is_close_or_extended_family_of = scope:your_heir }
				desc = lmf_heir.1626.desc.opening.family
			}
			desc = lmf_heir.1626.desc.opening
		}
		desc = lmf_heir.1626.desc
	}
	sender = scope:heir_liege

	option = {
		name = lmf_heir.1626.a # Let him come
		custom_tooltip = lmf_heir.1626.a.tt
		scope:heir_liege = {
			trigger_event = lmf_heir.1627
		}
	}
	option = {
		name = lmf_heir.1626.b # Send my regrets
		add_character_flag = {
			flag = recently_refused_heir_visit
			years = 10
		}
		scope:heir_liege = {
			trigger_event = lmf_heir.1628
		}
	}
}

# Permission given for visit
lmf_heir.1627 = {
	type = letter_event
	opening = lmf_heir.1627.opening
	desc = lmf_heir.1627.desc
	sender = scope:your_vassal

	option = {
		name = lmf_heir.1627.a
		custom_tooltip = lmf_heir.1625.a.tt
		start_heir_travel_plan_effect = { VISITOR = scope:your_heir VISITING = scope:your_vassal PARENT = root }
	}
}

# Permission refused
lmf_heir.1628 = {
	type = letter_event
	opening = lmf_heir.1628.opening
	desc = lmf_heir.1628.desc
	sender = scope:your_vassal

	immediate = {
		hidden_effect = {
			scope:your_vassal = { remove_from_list = potential_heir_targets }
			random_in_list = {
				list = potential_heir_targets
				weight = {
					base = 1
					ai_value_modifier = {
						ai_honor = 0.5
					}
					opinion_modifier = {
						who = this
						opinion_target = root
						multiplier = 0.5
						max = 20
					}
					modifier = {
						add = 5
						is_allied_to = root
					}
					modifier = {
						add = 5
						is_close_or_extended_family_of = scope:your_heir
					}
					modifier = {
						add = 5
						highest_held_title_tier == tier_duchy
					}
					modifier = {
						add = 10
						highest_held_title_tier == tier_kingdom
					}
					modifier = {
						add = 15
						highest_held_title_tier == tier_empire
					}
					modifier = {
						add = 20
						has_relation_friend = root
					}
					modifier = {
						add = 20
						has_relation_friend = scope:your_heir
					}
					modifier = {
						add = 20
						has_relation_lover = scope:your_heir
					}
					modifier = {
						add = -10
						NOR = {
							liege = root
							is_liege_or_above_of = root
						}
					}
					modifier = {
						add = -10
						NOT = { top_liege = root.top_liege }
					}
					modifier = {
						add = {
							value = diplomacy
							multiply = 2
							subtract = scope:your_heir.diplomacy
						}
						diplomacy > root.diplomacy
						diplomacy > scope:your_heir.diplomacy
					}
					modifier = {
						add = {
							value = stewardship
							multiply = 2
							subtract = scope:your_heir.stewardship
						}
						stewardship > root.stewardship
						stewardship > scope:your_heir.stewardship
						OR = {
							diplomacy <= root.diplomacy
							diplomacy <= scope:your_heir.diplomacy
						}
					}
					modifier = {
						add = {
							value = martial
							multiply = 2
							subtract = scope:your_heir.martial
						}
						martial > root.martial
						martial > scope:your_heir.martial
						OR = {
							diplomacy <= root.diplomacy
							diplomacy <= scope:your_heir.diplomacy
							stewardship <= root.stewardship
							stewardship <= scope:your_heir.stewardship
						}
					}
					modifier = {
						add = {
							value = learning
							multiply = 2
							subtract = scope:your_heir.learning
						}
						learning > root.learning
						learning > scope:your_heir.learning
						OR = {
							diplomacy <= root.diplomacy
							diplomacy <= scope:your_heir.diplomacy
							stewardship <= root.stewardship
							stewardship <= scope:your_heir.stewardship
							martial <= root.martial
							martial <= scope:your_heir.martial
						}
					}
					modifier = {
						add = {
							value = intrigue
							multiply = 2
							subtract = scope:your_heir.intrigue
						}
						intrigue > root.intrigue
						intrigue > scope:your_heir.intrigue
						OR = {
							diplomacy <= root.diplomacy
							diplomacy <= scope:your_heir.diplomacy
							stewardship <= root.stewardship
							stewardship <= scope:your_heir.stewardship
							martial <= root.martial
							martial <= scope:your_heir.martial
							learning <= root.learning
							learning <= scope:your_heir.learning
						}
					}
					min = 1
				}
				save_scope_as = alternate_vassal
			}
		}
	}

	option = {
		name = lmf_heir.1628.a #Perhaps alternate would do?
		trigger = { exists = scope:alternate_vassal }
		scope:alternate_vassal = { save_scope_as = your_vassal }
		if = {
			limit = {
				scope:alternate_vassal = { is_ai = no }
			}
			custom_tooltip = lmf_heir.1625.a.player.tt
			root = { save_scope_as = heir_liege }
			scope:alternate_vassal = { trigger_event = lmf_heir.1626 }
		}
		else = {
			custom_tooltip = lmf_heir.1625.a.tt
			hidden_effect = {
				scope:alternate_vassal = {
					add_character_flag = {
						flag = had_recent_heir_visit
						years = 5
					}
				}
				scope:your_heir = {
					set_variable = {
						name = heir_liege
						value = root
						years = 5
					}
					set_variable = {
						name = heir_visit_target
						value = scope:alternate_vassal
						years = 5
					}
					set_variable = {
						name = heir_visit_location
						value = scope:alternate_vassal.capital_province
						years = 5
					}
					start_travel_plan = {
						destination = var:heir_visit_location
						on_travel_planner_cancel_event = lmf_heir.1630
						on_arrival_event = lmf_heir.1631
						on_arrival_destinations = all_but_last
					}
				}
			}
		}
		ai_chance = {
			base = 80
		}
	}
	option = {
		name = lmf_heir.1628.b #So much for that
		ai_chance = {
			base = 20
		}
	}
}

# Cancellation event
lmf_heir.1630 = {
	hidden = yes

	trigger = {
		exists = scope:story
	}

	immediate = {
		save_scope_as = your_heir
		scope:story.var:heir_liege = { save_scope_as = heir_liege }
		scope:story.var:heir_visit_target = { save_scope_as = heir_visit_target }

		if = {
			limit = {
				current_travel_plan ?= {
					travel_plan_owner = root
					OR = {
						any_future_path_location = { this = scope:story.var:heir_visit_location }
						is_paused = yes
					}
				}
			}
			current_travel_plan = { cancel_travel_plan = yes }
		}
		if = {
			limit = { exists = scope:story.var:notify_target_title }
			scope:heir_visit_target = {
				send_interface_message = {
					type = event_generic_bad_with_text
					title = lmf_heir.1630.t.cancel
					desc = lmf_heir.1630.desc.title
					left_icon = scope:your_heir
				}
			}
		}
		else_if = {
			limit = { exists = scope:story.var:notify_target_imprison }
			scope:heir_visit_target = {
				if = {
					limit = {
						NOT = { this = scope:imprisoner }
					}
					send_interface_message = {
						type = event_generic_bad_with_text
						title = lmf_heir.1630.t.cancel
						desc = lmf_heir.1630.desc.imprisoned
						left_icon = scope:your_heir
						right_icon = scope:imprisoner
					}
				}
			}
			scope:heir_liege = {
				if = {
					limit = {
						NOT = { this = scope:imprisoner }
					}
					send_interface_message = {
						type = event_generic_bad_with_text
						title = lmf_heir.1630.t.cancel
						desc = lmf_heir.1630.desc.imprisoned
						left_icon = scope:your_heir
						right_icon = scope:imprisoner
						if = {
							limit = { is_ai = no }
							scope:your_heir = {
								show_as_tooltip = { heir_learns_from_visit_effect = yes }
							}
						}
					}
				}
			}
		}
		else_if = {
			limit = { exists = scope:story.var:notify_target_war }
			scope:heir_visit_target = {
				send_interface_message = {
					type = event_generic_bad_with_text
					title = lmf_heir.1630.t.cancel
					desc = lmf_heir.1630.desc.war
					left_icon = scope:your_heir
				}
			}
		}
		else_if = {
			limit = { exists = scope:story.var:notify_liege_death }
			scope:heir_liege = {
				send_interface_message = {
					type = event_generic_bad_with_text
					title = lmf_heir.1630.t.cancel
					desc = lmf_heir.1630.desc.target.death
					left_icon = scope:your_heir
					right_icon = scope:heir_visit_target
					if = {
						limit = { is_ai = no }
						scope:your_heir = {
							show_as_tooltip = { heir_learns_from_visit_effect = yes }
						}
					}
				}
			}
		}
		scope:your_heir = { heir_learns_from_visit_effect = yes }
		scope:story = { end_story = yes }
	}
}

# Check if the visit to the vassal is still valid
lmf_heir.1631 = {
	hidden = yes

	trigger = {
		is_incapable = no
		any_owned_story = {
			type = lmf_heir_visit_story_cycle
			save_temporary_scope_as = check_story
			var:heir_liege = { player_heir ?= root }
			var:heir_visit_target = {
				is_alive = yes
				is_imprisoned = no
				is_incapable = no
				NOT = { has_character_modifier = isolating_modifier }
			}
			var:heir_visit_location = {
				county = {
					holder = scope:check_story.var:heir_visit_target
					NOT = { has_county_modifier = isolate_capital_decision_modifier }
				}
				NOR = {
					is_occupied = yes
					any_army_in_location = {
						army_owner = { is_at_war_with = scope:check_story.var:heir_visit_target }
					}
				}
			}
		}
	}

	on_trigger_fail = {
		if = {
			limit = {
				any_owned_story = { type = lmf_heir_visit_story_cycle }
			}
			random_owned_story = {
				type = lmf_heir_visit_story_cycle
				save_scope_as = story
				root = { save_scope_as = your_heir }
				var:heir_liege = { save_scope_as = heir_liege }
				var:heir_visit_target = { save_scope_as = heir_visit_target }
				var:heir_visit_location = { save_scope_as = heir_visit_location }
				var:heir_visit_location.county = { save_scope_as = target_county }

				var:heir_liege = { heir_cancel_visit_notification = yes }
				var:heir_visit_target = { heir_cancel_visit_notification = yes }
				root = { heir_learns_from_visit_effect = yes }
				end_story = yes
			}
		}
	}

	immediate = {
		save_scope_as = your_heir
		random_owned_story = {
			type = lmf_heir_visit_story_cycle
			save_scope_as = story
			var:heir_liege = { save_scope_as = heir_liege }
			var:heir_visit_location = { save_scope_as = heir_visit_location }
			var:heir_visit_location.county = { save_scope_as = target_county }
			var:heir_visit_origin = { save_scope_as = heir_visit_origin }
			var:heir_visit_target = {
				save_scope_as = heir_visit_target
				trigger_event = lmf_heir.1633
			}
		}
	}
}

# Recall heir once war begins?
lmf_heir.1632 = {
	type = character_event
	title = lmf_heir.1632.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					is_at_war_with = scope:heir_host
					OR = {
						scope:heir_host = scope:attacker
						scope:heir_host = scope:defender
					}
				}
				desc = lmf_heir.1632.desc.atwar.primary
			}
			triggered_desc = {
				trigger = {
					is_at_war_with = scope:heir_host
					scope:attacker = root
				}
				desc = lmf_heir.1632.desc.atwar.rootattacker
			}
			triggered_desc = {
				trigger = {
					is_at_war_with = scope:heir_host
					scope:defender = root
				}
				desc = lmf_heir.1632.desc.atwar.rootdefender
			}
			triggered_desc = {
				trigger = {
					is_at_war_with = scope:heir_host
				}
				desc = lmf_heir.1632.desc.atwar
			}
			desc = lmf_heir.1632.desc
		}
	}
	theme = family

	left_portrait = {
		character = scope:your_heir
		animation = worry
		outfit_tags = { travel_cloak }
	}
	override_background = { reference = army_camp }

	trigger = {
		player_heir = {
			exists = current_travel_plan
			any_owned_story = {
				type = lmf_heir_visit_story_cycle
				var:heir_visit_location ?= { save_temporary_scope_as = target_loc }
				root.player_heir.current_travel_plan = {
					travel_plan_owner = root.player_heir
					OR = {
						any_future_path_location = { this = scope:target_loc }
						is_paused = yes
					}
					can_cancel = yes
				}
			}
		}
		exists = scope:war.primary_attacker
		exists = scope:war.primary_defender
	}

	immediate = {
		player_heir = {
			save_scope_as = your_heir
			random_owned_story = {
				type = lmf_heir_visit_story_cycle
				save_scope_as = story
				var:heir_visit_target = { save_scope_as = heir_host }
			}
		}
		scope:war.primary_attacker = { save_scope_as = attacker }
		scope:war.primary_defender = { save_scope_as = defender }
	}

	option = {
		name = lmf_heir.1632.a #Recall them at once
		scope:story = {
			set_variable = { name = notify_target_war value = flag:yes }
		}
		scope:your_heir = {
			show_as_tooltip = {
				current_travel_plan = { cancel_travel_plan = yes }
			}
			trigger_event = lmf_heir.1630
		}
		ai_chance = {
			factor = 20
			modifier = {
				factor = 0
				scope:your_heir = { is_knight = no }
			}
		}
	}
	option = {
		name = lmf_heir.1632.b #They're fine where they are
		trigger = {
			NOT = { is_at_war_with = scope:heir_host }
		}
		ai_chance = {
			factor = 80
			modifier = {
				factor = 2
				scope:your_heir.current_travel_plan ?= { is_paused = yes }
			}
			modifier = {
				factor = 0.1
				has_trait = paranoid
			}
		}
	}
}

# Vassal receives the heir
lmf_heir.1633 = {
	type = character_event
	title = lmf_heir.1633.t
	desc = {
		desc = lmf_heir.1633.desc.begin
		first_valid = {
			triggered_desc = {
				trigger = { is_available = no }
				desc = lmf_heir.1633.desc.away
			}
			desc = lmf_heir.1633.desc.end
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		outfit_tags = { travel_cloak }
	}
	override_background = { reference = bp2_courtyard }

	immediate = {
		scope:your_heir = {
			no_hat_respectful_effect = yes
			add_character_flag = went_on_heir_voyage
			current_travel_plan = {
				hidden_effect = { pause_travel_plan = yes }
			}
		}
	}

	option = {
		name = lmf_heir.1633.a # Spend time training the heir
		trigger = { is_available = yes }
		custom_tooltip = lmf_heir.1633.a.tt
		scope:story = {
			set_variable = { name = host_will_train value = yes }
			set_variable = { name = heir_in_training value = yes }
		}
		scope:your_heir = {
			trigger_event = { id = lmf_heir.1650 days = 14 }
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 100
				has_trait = diligent
			}
			modifier = {
				add = 50
				has_trait = patient
			}
			modifier = {
				add = 50
				has_trait = just
			}
		}
	}
	option = {
		name = {
			trigger = { is_available = yes }
			text = lmf_heir.1633.b # He can stay, but I have better things to do
		}
		name = {
			trigger = { is_available = no }
			text = lmf_heir.1633.c # Make sure he's kept entertained
		}
		custom_tooltip = lmf_heir.1633.c.tt
		scope:story = {
			set_variable = { name = heir_in_training value = yes }
		}
		scope:your_heir = {
			trigger_event = { id = lmf_heir.1650 days = 14 }
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 50
				has_trait = lazy
			}
			modifier = {
				add = 50
				has_trait = impatient
			}
			modifier = {
				add = 50
				has_trait = reclusive
			}
			modifier = {
				add = 50
				has_trait = irritable
			}
			modifier = {
				add = 100
				has_trait = diligent
				is_available = no
			}
			modifier = {
				add = 50
				has_trait = just
				is_available = no
			}
		}
	}
	option = {
		name = lmf_heir.1633.d #What he does is no concern of mine
		custom_tooltip = lmf_heir.1633.d.tt
		stress_impact = {
			diligent = minor_stress_impact_gain
			just = minor_stress_impact_gain
			paranoid = minor_stress_impact_loss
			arbitrary = minor_stress_impact_loss
		}
		remove_variable ?= visited_by_heir
		scope:story = {
			set_variable = { name = heir_on_their_own value = yes }
			set_variable = { name = visit_time value = 3 }
		}
		scope:your_heir = {
			add_opinion = { target = root modifier = disrespect_opinion opinion = -15 }
			trigger_event = { id = lmf_heir.1650 days = { 100 130 } }
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				has_trait = paranoid
			}
			modifier = {
				add = 50
				has_trait = arbitrary
			}
			modifier = {
				add = 20
				opinion = { target = scope:heir_liege value <= -20 }
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
	}
}

# Activity Bounce Event
lmf_heir.1650 = {
	type = character_event
	hidden = yes

	trigger = {
		is_incapable = no
		is_ruler = no
		scope:heir_liege = { player_heir = scope:your_heir }
		exists = scope:story
		scope:heir_visit_target = {
			is_alive = yes
			is_imprisoned = no
			is_incapable = no
			NOT = { has_character_modifier = isolating_modifier }
		}
		scope:target_county = {
			holder = scope:heir_visit_target
			NOT = { has_county_modifier = isolate_capital_decision_modifier }
		}
		scope:heir_visit_location = {
			NOR = {
				is_occupied = yes
				any_army_in_location = {
					army_owner = { is_at_war_with = scope:heir_visit_target }
				}
 			}
		}
	}

	on_trigger_fail = {
		if = {
			limit = {
				is_alive = yes
				is_ruler = no
				is_imprisoned = no
				exists = scope:story
			}
			scope:heir_liege = { heir_cancel_visit_notification = yes }
			scope:heir_visit_target = { heir_cancel_visit_notification = yes }
			heir_learns_from_visit_effect = yes
			scope:story = { end_story = yes }

			current_travel_plan ?= {
				if = {
					limit = {
						travel_plan_owner = root
						is_paused = yes
					}
					resume_travel_plan = yes
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { scope:story.var:visit_time >= 4 } # is the wrap up event
			scope:heir_visit_target = { trigger_event = lmf_heir.1680 }
		}
		else_if = {
			limit = { has_recoverable_disease_trigger = yes }
			scope:story = {
				change_variable = { name = visit_time_sick add = 1 }
			}
			advance_heir_timer_effect = yes
		}
		else_if = {
			limit = { scope:story.var:visit_time = 0 } # is the first event
			random_list = {
				100 = { # Heir's behavior is impressive
					modifier = {
						has_personality_benevolent_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_dominant_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_extroverted_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_levelheaded_trigger = yes
						factor = 2
					}
					ai_value_modifier = {
						ai_honor = 1
						ai_energy = 1
						ai_sociability = 1
					}
					min = 1
					scope:heir_visit_target = { trigger_event = lmf_heir.1651 }
				}
				100 = { # Heir's behavior is unpleasant
					modifier = {
						has_personality_malicious_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_emotional_trigger = yes
						factor = 2
					}
					ai_value_modifier = {
						ai_honor = -1
						ai_energy = 1
						ai_sociability = -1
					}
					min = 1
					scope:heir_visit_target = { trigger_event = lmf_heir.1652 }
				}
				100 = { # Heir avoids everyone
					trigger = {
						OR = {
							has_trait = shy
							has_trait = chaste
							has_trait = craven
							has_trait = paranoid
							has_trait = reclusive
						}
					}
					modifier = {
						has_personality_dominant_trigger = yes
						factor = 0.5
					}
					modifier = {
						has_personality_submissive_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_extroverted_trigger = yes
						factor = 0.5
					}
					modifier = {
						has_personality_introverted_trigger = yes
						factor = 2
					}
					ai_value_modifier = {
						ai_sociability = -1
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1653 }
				}
				100 = { # Heir misses home
					trigger = {
						OR = {
							is_adult = no
							has_trait = shy
						}
					}
					modifier = {
						has_personality_introverted_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_extroverted_trigger = yes
						factor = 0.5
					}
					ai_value_modifier = {
						ai_sociability = -1
						ai_boldness = -1
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1654 }
				}
				100 = { # Heir is quiet and dutiful
					trigger = {
						NOR = {
							has_trait = gregarious
							has_trait = lazy
							has_trait = impatient
							has_trait = wrathful
						}
					}
					modifier = {
						has_personality_emotional_trigger = yes
						factor = 0.5
					}
					modifier = {
						has_personality_extroverted_trigger = yes
						factor = 0.5
					}
					modifier = {
						has_personality_introverted_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_levelheaded_trigger = yes
						factor = 2
					}
					ai_value_modifier = {
						ai_rationality = 1
						ai_boldness = -1
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1655 }
				}
				100 = { # Heir is a troublemaker
					trigger = {
						OR = {
							has_trait = wrathful
							has_trait = impatient
							has_trait = paranoid
							has_trait = drunkard
							has_trait = lunatic
							has_trait = lustful
							has_trait_malicious_trigger = yes
						}
					}
					modifier = {
						has_personality_malicious_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_extroverted_trigger = yes
						factor = 2
					}
					modifier = {
						has_personality_emotional_trigger = yes
						factor = 2
					}
					ai_value_modifier = {
						ai_vengefulness = 1
						ai_compassion = -1
						ai_honor = -1
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1656 }
				}
			}
		}
		else = {
			random_list = {
				250 = { # Heir spends time with liege
					trigger = {
						exists = scope:story.var:host_will_train
						scope:heir_visit_target = {
							is_available = yes
							has_recoverable_disease_trigger = no
						}
					}
					modifier = {
						factor = 0.5
						exists = scope:story.var:host_has_trained
					}
					ai_value_modifier = {
						who = scope:heir_visit_target
						ai_honor = 0.5
						ai_energy = 0.5
					}
					ai_value_modifier = {
						ai_honor = 0.5
						ai_energy = 1
					}
					modifier = {
						factor = 2
						has_trait = ambitious
					}
					modifier = {
						factor = 2
						has_trait = diligent
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:trouble
							scope:heir_behavior = flag:homesick
							scope:heir_behavior = flag:avoidant
						}
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:dutiful
							scope:heir_behavior = flag:impressive
						}
					}
					min = 10
					scope:heir_visit_target = { trigger_event = lmf_heir.1660 }
				}
				100 = { # Attraction between heir and liege
					trigger = {
						exists = scope:story.var:host_will_train
						NOR = {
							has_trait = chaste
							exists = scope:story.var:had_heir_1661_event
							exists = scope:story.var:had_heir_1674_event
							exists = scope:was_previously_annoying
						}
						OR = {
							AND = {
								heir_can_crush_trigger = yes
								scope:heir_visit_target = { is_candidate_for_heir_crush = yes }
							}
							AND = {
								is_appropriate_ai_seduction_courtier = yes
								scope:heir_visit_target = { is_candidate_for_heir_seduction = yes }
							}
						}
						scope:heir_visit_target = {
							is_available = yes
							has_recoverable_disease_trigger = no
						}
					}
					ai_value_modifier = {
						ai_boldness = 0.5
						ai_honor = -0.5
					}
					ai_value_modifier = {
						who = scope:heir_visit_target
						ai_boldness = 0.5
						ai_honor = -0.5
					}
					modifier = {
						factor = 2
						likely_to_take_lover_trigger = yes
					}
					modifier = {
						factor = 2
						scope:heir_visit_target = { likely_to_take_lover_trigger = yes }
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:impressive
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:unpleasant
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1661 }
				}
				100 = { # Heir spends time learning from councillor
					trigger = {
						exists = scope:story.var:heir_in_training
						scope:heir_visit_target = {
							any_councillor = {
								is_candidate_for_heir_teaching = yes
								OR = {
									AND = {
										has_council_position = councillor_chancellor
										diplomacy > scope:your_heir.diplomacy
									}
									AND = {
										has_council_position = councillor_steward
										stewardship > scope:your_heir.stewardship
									}
									AND = {
										has_council_position = councillor_marshal
										martial > scope:your_heir.martial
									}
									AND = {
										has_council_position = councillor_spymaster
										intrigue > scope:your_heir.intrigue
									}
								}
							}
						}
						trigger_if = {
							limit = { exists = scope:story.var:host_will_train }
							NOT = { exists = scope:story.var:had_heir_1662_event }
						}
					}
					ai_value_modifier = {
						ai_honor = 0.5
						ai_energy = 0.5
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:dutiful
							scope:heir_behavior = flag:impressive
						}
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:trouble
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:unpleasant
						}
					}
					modifier = {
						factor = 0.5
						scope:heir_visit_target = {
							NOR = {
								cp:councillor_chancellor ?= {
									is_candidate_for_heir_teaching = yes
									diplomacy > scope:your_heir.diplomacy_plus_5
								}
								cp:councillor_steward ?= {
									is_candidate_for_heir_teaching = yes
									stewardship > scope:your_heir.stewardship_plus_5
								}
								cp:councillor_marshal ?= {
									is_candidate_for_heir_teaching = yes
									martial > scope:your_heir.martial_plus_5
								}
								cp:councillor_spymaster ?= {
									is_candidate_for_heir_teaching = yes
									intrigue > scope:your_heir.intrigue_plus_5
								}
							}
						}
					}
					modifier = {
						factor = 0.5
						exists = scope:story.var:had_heir_1662_event
					}
					min = 1
					scope:heir_visit_target = { trigger_event = lmf_heir.1662 }
				}
				50 = { # Heir spends time with court member
					trigger = {
						exists = scope:story.var:heir_in_training
						scope:heir_visit_target = {
							any_courtier = {
								is_candidate_for_heir_teaching = yes
								is_councillor = no
								OR = {
									AND = {
										has_court_position = court_physician_court_position
										learning > scope:your_heir.learning
									}
									AND = {
										has_court_position = chronicler_court_position
										diplomacy > scope:your_heir.diplomacy
									}
									AND = {
										has_court_position = master_of_horse_court_position
										martial > scope:your_heir.martial
									}
									AND = {
										has_court_position = seneschal_court_position
										stewardship > scope:your_heir.stewardship
									}
									AND = {
										has_court_position = food_taster_court_position
										intrigue > scope:your_heir.intrigue
									}
								}
							}
						}
						trigger_if = {
							limit = { exists = scope:story.var:host_will_train }
							NOT = { exists = scope:story.var:had_heir_1663_event }
						}
					}
					ai_value_modifier = {
						ai_honor = 0.5
						ai_energy = 0.5
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:dutiful
							scope:heir_behavior = flag:impressive
						}
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:trouble
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:unpleasant
						}
					}
					modifier = {
						factor = 0.5
						scope:heir_visit_target = {
							NOR = {
								court_position:court_physician_court_position ?= {
									is_candidate_for_heir_teaching = yes
									is_councillor = no
									learning > scope:your_heir.learning_plus_5
								}
								court_position:chronicler_court_position ?= {
									is_candidate_for_heir_teaching = yes
									is_councillor = no
									diplomacy > scope:your_heir.diplomacy_plus_5
								}
								court_position:master_of_horse_court_position ?= {
									is_candidate_for_heir_teaching = yes
									is_councillor = no
									martial > scope:your_heir.martial_plus_5
								}
								court_position:seneschal_court_position ?= {
									is_candidate_for_heir_teaching = yes
									is_councillor = no
									stewardship > scope:your_heir.stewardship_plus_5
								}
								court_position:food_taster_court_position ?= {
									is_candidate_for_heir_teaching = yes
									is_councillor = no
									intrigue > scope:your_heir.intrigue_plus_5
								}
							}
						}
					}
					modifier = {
						factor = 0.5
						exists = scope:story.var:had_heir_1663_event
					}
					min = 1
					scope:heir_visit_target = { trigger_event = lmf_heir.1663 }
				}
				100 = { # Heir spends time with knight
					trigger = {
						exists = scope:story.var:heir_in_training
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:heir_liege }
						NOT = { exists = scope:story.var:had_heir_1664_event }
						OR = {
							is_knight = yes
							has_trait = lifestyle_blademaster
							has_trait = education_martial
							has_focus = education_martial
							has_trait = rowdy
						}
						scope:heir_visit_target = {
							any_knight = {
								is_candidate_for_heir_teaching = yes
								is_councillor = no
								NOT = { has_court_position = master_of_horse_court_position }
								OR = {
									martial > scope:your_heir.martial
									prowess > scope:your_heir.prowess
								}
							}
						}
					}
					ai_value_modifier = {
						ai_boldness = 1
						ai_energy = 0.5
					}
					modifier = {
						always = yes
						add = {
							value = prowess
							subtract = 6
							multiply = 10
						}
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:impressive
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:trouble
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:unpleasant
						}
					}
					modifier = {
						factor = 0.5
						scope:heir_visit_target = {
							NOT = {
								any_knight = {
									is_candidate_for_heir_teaching = yes
									is_councillor = no
									NOT = { has_court_position = master_of_horse_court_position }
									OR = {
										martial > scope:your_heir.martial_plus_5
										prowess > scope:your_heir.prowess_plus_5
									}
								}
							}
						}
					}
					min = 1
					scope:heir_visit_target = { trigger_event = lmf_heir.1664 }
				}
				50 = { # Heir duels a knight
					trigger = {
						exists = scope:story.var:heir_in_training
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:heir_liege }
						NOR = {
							has_trait = craven
							exists = scope:story.var:had_heir_1664_event
						}
						OR = {
							has_personality_malicious_trigger = yes
							has_personality_dominant_trigger = yes
							has_personality_emotional_trigger = yes
						}
						OR = {
							is_knight = yes
							has_trait = lifestyle_blademaster
							has_trait = education_martial
							has_focus = education_martial
							has_trait = rowdy
						}
						scope:heir_visit_target = {
							any_knight = {
								is_candidate_for_heir_teaching = yes
								is_councillor = no
								NOT = { has_court_position = master_of_horse_court_position }
								martial > scope:your_heir.martial
								is_healthy = yes
							}
						}
					}
					ai_value_modifier = {
						ai_boldness = 0.5
						ai_rationality = -0.5
						ai_vengefulness = 1
					}
					modifier = {
						always = yes
						add = {
							value = prowess
							subtract = 8
							multiply = 10
						}
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:trouble
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:dutiful
							scope:heir_behavior = flag:homesick
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:impressive
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1665 }
				}
				100 = { # Heir pokes around learning secrets
					trigger = {
						exists = scope:story.var:heir_in_training
						NOT = { exists = scope:story.var:had_heir_1666_event }
						OR = {
							has_trait = education_intrigue
							has_focus = education_intrigue
							intrigue >= 12
							AND = {
								has_trait = ambitious
								ai_honor < 0
							}
						}
					}
					modifier = {
						always = yes
						add = {
							value = intrigue
							subtract = 8
							multiply = 10
						}
					}
					ai_value_modifier = {
						ai_honor = -0.5
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						scope:heir_behavior = flag:dutiful
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:avoidant
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1666 }
				}
				100 = { # Heir is indiscreet
					trigger = {
						exists = scope:story.var:heir_in_training
						NOT = { exists = scope:story.var:had_heir_1666_event }
						OR = {
							has_trait = deceitful
							has_trait = education_intrigue
							has_focus = education_intrigue
							AND = {
								has_trait = ambitious
								ai_honor < 0
							}
						}
					}
					modifier = {
						always = yes
						add = {
							value = 8
							subtract = intrigue
							multiply = 10
						}
					}
					ai_value_modifier = {
						ai_honor = -0.5
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:unpleasant
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						scope:heir_behavior = flag:dutiful
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1667 }
				}
				100 = { # Heir spends time in the library
					trigger = {
						exists = scope:story.var:heir_in_training
						NOT = { exists = scope:story.var:had_heir_1668_event }
						OR = {
							has_personality_introverted_trigger = yes
							has_trait = scholar
							has_trait = education_learning
							has_focus = education_learning
						}
					}
					modifier = {
						always = yes
						add = {
							value = learning
							subtract = 6
							multiply = 10
						}
					}
					ai_value_modifier = {
						ai_sociability = -0.5
						ai_rationality = 0.5
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:trouble
							scope:heir_behavior = flag:impressive
						}
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:dutiful
							scope:heir_behavior = flag:homesick
							scope:heir_behavior = flag:avoidant
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1668 }
				}
				100 = { # Heir is a delight in the castle
					trigger = {
						exists = scope:story.var:heir_in_training
						NOR = {
							has_trait = shy
							has_trait = arrogant
							exists = scope:story.var:had_heir_1669_event
						}
						OR = {
							has_personality_benevolent_trigger = yes
							has_personality_extroverted_trigger = yes
							has_trait = education_diplomacy
							has_focus = education_diplomacy
						}
					}
					modifier = {
						always = yes
						add = {
							value = diplomacy
							subtract = 8
							multiply = 10
						}
					}
					ai_value_modifier = {
						ai_sociability = 0.5
						ai_compassion = 0.5
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:impressive
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:trouble
							scope:heir_behavior = flag:homesick
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:unpleasant
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1669 }
				}
				100 = { # Heir is avoided by the castle
					trigger = {
						exists = scope:story.var:heir_in_training
						NOR = {
							has_trait = gregarious
							has_trait = humble
							NOT = { exists = scope:story.var:had_heir_1669_event }
						}
						OR = {
							has_personality_annoying_trigger = yes
							has_personality_malicious_trigger = yes
							has_trait = education_diplomacy
							has_focus = education_diplomacy
						}
					}
					modifier = {
						always = yes
						add = {
							value = 8
							subtract = diplomacy
							multiply = 10
						}
					}
					ai_value_modifier = {
						ai_sociability = -0.5
						ai_compassion = -0.5
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:homesick
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:unpleasant
						}
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:dutiful
							scope:heir_behavior = flag:impressive
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1670 }
				}
				100 = { # Heir works on castle project
					trigger = {
						exists = scope:story.var:heir_in_training
						NOR = {
							has_trait = arrogant
							exists = scope:story.var:had_heir_1671_event
						}
						OR = {
							has_trait = diligent
							has_trait = humble
							has_trait = education_stewardship
							has_focus = education_stewardship
						}
					}
					ai_value_modifier = {
						ai_energy = 0.5
					}
					modifier = {
						always = yes
						add = {
							value = stewardship
							subtract = 8
							multiply = 10
						}
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:dutiful
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:trouble
							scope:heir_behavior = flag:unpleasant
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							has_trait = education_stewardship
							has_focus = education_stewardship
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1671 }
				}
				100 = { # Heir gets into fight with courtier
					trigger = {
						num_of_relation_rival < 3
						exists = scope:story.var:heir_in_training
						NOT = { exists = scope:story.var:had_heir_1672_event }
						OR = {
							has_personality_malicious_trigger = yes
							has_personality_emotional_trigger = yes
						}
						scope:heir_visit_target = {
							any_courtier = {
								is_candidate_for_heir_enemy = yes
							}
						}
					}
					ai_value_modifier = {
						ai_vengefulness = 1
						ai_rationality = -0.5
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:trouble
							scope:heir_behavior = flag:unpleasant
						}
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:dutiful
							scope:heir_behavior = flag:impressive
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1672 }
				}
				100 = { # Heir gets along with courtier
					trigger = {
						num_of_relation_friend <= 3
						exists = scope:story.var:heir_in_training
						NOR = {
							has_personality_malicious_trigger = yes
							exists = scope:story.var:had_heir_1672_event
						}
						scope:heir_visit_target = {
							any_courtier = {
								is_candidate_for_heir_friend = yes
							}
						}
					}
					ai_value_modifier = {
						ai_sociability = 0.5
						ai_compassion = 0.5
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:impressive
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:unpleasant
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1673 }
				}
				300 = { # Heir falls in love with courtier
					trigger = {
						exists = scope:story.var:heir_in_training
						NOR = {
							has_trait = chaste
							exists = scope:story.var:had_heir_1672_event
							exists = scope:story.var:had_heir_1661_event
						}
						trigger_if = {
							limit = { is_adult = no }
							heir_can_crush_trigger = yes
							scope:heir_visit_target = {
								any_courtier = { is_candidate_for_heir_crush = yes }
							}
						}
						trigger_else = {
							is_appropriate_ai_seduction_courtier = yes
							scope:heir_visit_target = {
								any_courtier = { is_candidate_for_heir_seduction = yes }
							}
						}
					}
					ai_value_modifier = {
						trigger = { is_adult = yes }
						ai_honor = -1
						ai_boldness = 0.5
					}
					ai_value_modifier = {
						trigger = { is_adult = no }
						ai_boldness = 0.5
					}
					modifier = {
						factor = 2
						is_adult = yes
						exists = scope:heir_behavior
						scope:heir_behavior = flag:trouble
					}
					modifier = {
						factor = 0.5
						is_adult = yes
						exists = scope:heir_behavior
						scope:heir_behavior = flag:dutiful
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:avoidant
							scope:heir_behavior = flag:impressive
						}
					}
					min = 0
					scope:heir_visit_target = { trigger_event = lmf_heir.1674 }
				}
				100 = { # Heir goes hunting
					trigger = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:heir_liege }
						NOR = {
							has_trait = craven
							has_trait = physique_bad
							has_trait = weak
							exists = scope:story.var:had_heir_1675_event
						}
						OR = {
							has_trait = lifestyle_hunter
							has_trait = education_martial
							has_focus = education_martial
							exists = scope:story.var:heir_on_their_own
							ai_energy >= 0
						}
					}
					ai_value_modifier = {
						ai_energy = 1
						ai_boldness = 1
					}
					modifier = {
						factor = 0.5
						exists = scope:story.var:heir_in_training
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:avoidant
					}
					min = 1
					scope:heir_visit_target = { trigger_event = lmf_heir.1675 }
				}
				100 = { # Heir tours the countryside
					trigger = {
						NOT = { exists = scope:story.var:had_heir_1676_event }
						OR = {
							exists = scope:story.var:heir_on_their_own
							ai_energy >= 0
						}
					}
					ai_value_modifier = {
						ai_energy = 1
					}
					modifier = {
						factor = 0.5
						exists = scope:story.var:heir_in_training
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:avoidant
					}
					min = 1
					scope:heir_visit_target = { trigger_event = lmf_heir.1676 }
				}
				100 = { # Heir parties it up
					trigger = {
						age > 14
						NOR = {
							has_trait = shy
							has_trait = temperate
							has_trait = pensive
							exists = scope:story.var:had_heir_1677_event
							AND = {
								exists = scope:story.var:heir_in_training
								has_trait = diligent
							}
						}
						OR = {
							has_trait = lifestyle_reveler
							has_trait = drunkard
							likely_to_take_lover_trigger = yes
							stress > normal_baseline_stress
							ai_sociability >= low_positive_ai_value
							ai_rationality <= high_negative_ai_value
						}
					}
					ai_value_modifier = {
						ai_sociability = 1
						ai_rationality = -0.5
					}
					modifier = {
						factor = 0.5
						exists = scope:story.var:heir_in_training
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:trouble
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						OR = {
							scope:heir_behavior = flag:dutiful
							scope:heir_behavior = flag:homesick
							scope:heir_behavior = flag:impressive
						}
					}
					min = 1
					scope:heir_visit_target = { trigger_event = lmf_heir.1677 }
				}
				50 = { # Heir does nothing at all
					ai_value_modifier = {
						ai_energy = -1
					}
					modifier = {
						factor = 2
						exists = scope:heir_behavior
						scope:heir_behavior = flag:homesick
					}
					modifier = {
						factor = 0.5
						exists = scope:heir_behavior
						scope:heir_behavior = flag:impressive
					}
					modifier = {
						factor = 0.5
						has_trait = diligent
					}
					modifier = {
						factor = 0.5
						has_trait = ambitious
					}
					modifier = {
						factor = 0.5
						exists = scope:story.var:had_heir_1678_event
					}
					min = 1
					if = {
						limit = { scope:story.var:visit_time = 3 }
						scope:heir_visit_target = { trigger_event = lmf_heir.1678 }
					}
					else = {
						scope:story = {
							change_variable = { name = visit_time_nothing add = 1 }
						}
						advance_heir_timer_effect = yes
					}
				}
			}
		}
	}
}

### BEHAVIOR EVENTS

# Heir's behavior is impressive
lmf_heir.1651 = {
	type = character_event
	title = lmf_heir.1651.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { location = root.capital_province }
				}
				desc = lmf_heir.1651.desc.away
			}
			triggered_desc = {
				trigger = { is_available = no }
				desc = lmf_heir.1651.desc.busy
			}
			desc = lmf_heir.1651.desc.there
		}
		desc = lmf_heir.1651.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = interested
	}
	override_background = { reference = relaxing_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }
		save_scope_value_as = { name = heir_behavior value = flag:impressive }
	}

	option = {
		name = lmf_heir.1651.a
		custom_tooltip = lmf_heir.1651.tt
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir's behavior is unpleasant
lmf_heir.1652 = {
	type = character_event
	title = lmf_heir.1652.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { location = root.capital_province }
				}
				desc = lmf_heir.1652.desc.away
			}
			triggered_desc = {
				trigger = { is_available = no }
				desc = lmf_heir.1652.desc.busy
			}
			desc = lmf_heir.1652.desc.there
		}
		desc = lmf_heir.1652.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = disapproval
	}
	override_background = { reference = relaxing_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }
		save_scope_value_as = { name = heir_behavior value = flag:unpleasant }
	}

	option = {
		name = lmf_heir.1652.a
		custom_tooltip = lmf_heir.1652.tt
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir avoids everyone
lmf_heir.1653 = {
	type = character_event
	title = lmf_heir.1653.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { location = root.capital_province }
				}
				desc = lmf_heir.1653.desc.away
			}
			triggered_desc = {
				trigger = { is_available = no }
				desc = lmf_heir.1653.desc.busy
			}
			desc = lmf_heir.1653.desc.there
		}
		desc = lmf_heir.1653.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = shame
	}
	override_background = { reference = relaxing_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }
		save_scope_value_as = { name = heir_behavior value = flag:avoidant }
	}

	option = {
		name = lmf_heir.1653.a
		custom_tooltip = lmf_heir.1653.tt
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir misses home
lmf_heir.1654 = {
	type = character_event
	title = lmf_heir.1654.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { location = root.capital_province }
				}
				desc = lmf_heir.1654.desc.away
			}
			triggered_desc = {
				trigger = { is_available = no }
				desc = lmf_heir.1654.desc.busy
			}
			desc = lmf_heir.1654.desc.there
		}
		desc = lmf_heir.1654.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = sadness
	}
	override_background = { reference = relaxing_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }
		save_scope_value_as = { name = heir_behavior value = flag:homesick }
	}

	option = {
		name = lmf_heir.1654.a
		custom_tooltip = lmf_heir.1654.tt
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir is quiet and dutiful
lmf_heir.1655 = {
	type = character_event
	title = lmf_heir.1655.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { location = root.capital_province }
				}
				desc = lmf_heir.1655.desc.away
			}
			triggered_desc = {
				trigger = { is_available = no }
				desc = lmf_heir.1655.desc.busy
			}
			desc = lmf_heir.1655.desc.there
		}
		desc = lmf_heir.1655.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = personality_honorable
	}
	override_background = { reference = relaxing_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }
		save_scope_value_as = { name = heir_behavior value = flag:dutiful }
	}

	option = {
		name = lmf_heir.1655.a
		custom_tooltip = lmf_heir.1655.tt
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir is a troublemaker
lmf_heir.1656 = {
	type = character_event
	title = lmf_heir.1656.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { location = root.capital_province }
				}
				desc = lmf_heir.1656.desc.away
			}
			triggered_desc = {
				trigger = { is_available = no }
				desc = lmf_heir.1656.desc.busy
			}
			desc = lmf_heir.1656.desc.there
		}
		desc = lmf_heir.1656.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = scheme
	}
	override_background = { reference = relaxing_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }
		save_scope_value_as = { name = heir_behavior value = flag:trouble }
	}

	option = {
		name = lmf_heir.1656.a
		custom_tooltip = lmf_heir.1656.tt
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

### HEIR IN THE CASTLE

# Heir spends time with liege
lmf_heir.1660 = {
	type = character_event
	title = lmf_heir.1660.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:story.var:host_has_trained = 1 }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { exists = scope:was_annoying }
							desc = lmf_heir.1660.desc.first.annoy
						}
						desc = lmf_heir.1660.desc.first.helpful
					}
				}
			}
			triggered_desc = {
				trigger = { scope:story.var:host_has_trained = 2 }
				desc = {
					desc = lmf_heir.1660.desc.second.begin
					first_valid = {
						triggered_desc = {
							trigger = {
								exists = scope:was_annoying
								exists = scope:was_previously_annoying
							}
							desc = lmf_heir.1660.desc.second.annoy.wasannoy
						}
						triggered_desc = {
							trigger = { exists = scope:was_annoying }
							desc = lmf_heir.1660.desc.second.annoy.washelpful
						}
						triggered_desc = {
							trigger = {
								exists = scope:was_helpful
								exists = scope:was_previously_annoying
							}
							desc = lmf_heir.1660.desc.second.helpful.wasannoy
						}
						desc = lmf_heir.1660.desc.second.helpful.washelpful
					}
					desc = {
						first_valid = {
							triggered_desc = {
								trigger = { exists = scope:was_annoying }
								desc = lmf_heir.1660.desc.second.annoy
							}
							desc = lmf_heir.1660.desc.second.helpful
						}
					}
				}
			}
			desc = {
				desc = lmf_heir.1660.desc.third.begin
				first_valid = {
					triggered_desc = {
						trigger = {
							exists = scope:was_annoying
							exists = scope:was_previously_annoying
						}
						desc = lmf_heir.1660.desc.third.annoy.wasannoy
					}
					triggered_desc = {
						trigger = { exists = scope:was_annoying }
						desc = lmf_heir.1660.desc.third.annoy.washelpful
					}
					triggered_desc = {
						trigger = {
							exists = scope:was_helpful
							exists = scope:was_previously_annoying
						}
						desc = lmf_heir.1660.desc.third.helpful.wasannoy
					}
					desc = lmf_heir.1660.desc.third.helpful.washelpful
				}
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { exists = scope:was_annoying }
							desc = lmf_heir.1660.desc.third.annoy
						}
						desc = lmf_heir.1660.desc.third.helpful
					}
				}
			}
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { exists = scope:was_annoying }
			animation = stress
		}
		animation = thinking
	}
	right_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:was_annoying }
			animation = eyeroll
		}
		animation = debating
	}
	override_background = { reference = throne_room }

	immediate = {
		# what are you teaching him?
		random_list = {
			10 = {
				trigger = {
					diplomacy > scope:your_heir.diplomacy
					diplomacy > scope:heir_liege.diplomacy
				}
				modifier = {
					factor = 10
					diplomacy > scope:your_heir.diplomacy_plus_5
					diplomacy > scope:heir_liege.diplomacy_plus_5
				}
				modifier = {
					factor = 10
					highest_skill = diplomacy
				}
				save_scope_value_as = { name = training_heir_skill value = flag:diplomacy }
			}
			10 = {
				trigger = {
					martial > scope:your_heir.martial
					martial > scope:heir_liege.martial
				}
				modifier = {
					factor = 10
					martial > scope:your_heir.martial_plus_5
					martial > scope:heir_liege.martial_plus_5
				}
				modifier = {
					factor = 10
					highest_skill = martial
				}
				save_scope_value_as = { name = training_heir_skill value = flag:martial }
			}
			1 = {
				modifier = {
					add = 9
					stewardship > scope:your_heir.stewardship
					stewardship > scope:heir_liege.stewardship
				}
				modifier = {
					factor = 10
					stewardship > scope:your_heir.stewardship_plus_5
					stewardship > scope:heir_liege.stewardship_plus_5
				}
				modifier = {
					factor = 10
					highest_skill = stewardship
				}
				save_scope_value_as = { name = training_heir_skill value = flag:stewardship }
			}
			10 = {
				trigger = {
					intrigue > scope:your_heir.intrigue
					intrigue > scope:heir_liege.intrigue
				}
				modifier = {
					factor = 10
					intrigue > scope:your_heir.intrigue_plus_5
					intrigue > scope:heir_liege.intrigue_plus_5
				}
				modifier = {
					factor = 10
					highest_skill = intrigue
				}
				save_scope_value_as = { name = training_heir_skill value = flag:intrigue }
			}
			10 = {
				trigger = {
					learning > scope:your_heir.learning
					learning > scope:heir_liege.learning
				}
				modifier = {
					factor = 10
					learning > scope:your_heir.learning_plus_5
					learning > scope:heir_liege.learning_plus_5
				}
				modifier = {
					factor = 10
					highest_skill = learning
				}
				save_scope_value_as = { name = training_heir_skill value = flag:learning }
			}
		}
		scope:your_heir = {
			# first remove his hat
			no_hat_respectful_effect = yes
			# check whether the heir was annoying or actually helpful
			random_list = {
				100 = {
					modifier = {
						add = 50
						OR = {
							has_relation_friend = scope:your_heir
							has_relation_potential_friend = scope:your_heir
						}
					}
					modifier = {
						add = 50
						scope:your_heir = { probably_intelligent_trigger = yes }
					}
					modifier = {
						add = 50
						scope:your_heir = { has_personality_levelheaded_trigger = yes }
					}
					opinion_modifier = {
						trigger = { is_ai = yes }
						who = root
						opinion_target = scope:your_heir
						multiplier = 0.5
					}
					opinion_modifier = {
						who = scope:your_heir
						opinion_target = root
						multiplier = 0.5
					}
					ai_value_modifier = {
						who = scope:your_heir
						ai_honor = 1
						ai_energy = 0.5
						ai_rationality = 1
					}
					min = 1
					save_scope_value_as = { name = was_helpful value = yes }
					scope:story = {
						change_variable = { name = visit_success add = 2 }
					}
				}
				100 = {
					modifier = {
						add = {
							value = scope:story.var:host_has_trained
							multiply = 50
						}
						exists = scope:story.var:host_has_trained
					}
					modifier = {
						add = 50
						OR = {
							has_relation_rival = scope:your_heir
							has_relation_potential_rival = scope:your_heir
						}
					}
					modifier = {
						add = 50
						scope:your_heir = { has_trait_submissive_trigger = yes }
					}
					modifier = {
						add = 50
						scope:your_heir = { has_personality_annoying_trigger = yes }
					}
					modifier = {
						add = 50
						scope:your_heir = { probably_unintelligent_trigger = yes }
					}
					ai_value_modifier = {
						who = scope:your_heir
						ai_vengefulness = 1
						ai_energy = -0.5
					}
					min = 1
					save_scope_value_as = { name = was_annoying value = yes }
					scope:story = {
						change_variable = { name = visit_success add = 1 }
					}
				}
			}
		}
		scope:story = {
			# increment story variables
			change_variable = { name = visit_time_target add = 1 }
			if = {
				limit = {
					NOT = { exists = var:host_has_trained }
				}
				set_variable = { name = host_has_trained value = 1 }
			}
			else = {
				change_variable = { name = host_has_trained add = 1 }
			}
		}
	}

	option = {
		name = {
			trigger = { exists = scope:was_helpful }
			text = lmf_heir.1660.a
		}
		name = {
			trigger = { exists = scope:was_annoying }
			text = lmf_heir.1660.b
		}
		if = {
			limit = { exists = scope:was_annoying }
			custom_tooltip = lmf_heir.heir.progress.minor.tt
			stress_impact = {
				base = medium_stress_impact_gain
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
			}
			if = {
				limit = { has_relation_rival = scope:your_heir }
				add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20 }
				reverse_add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20}
			}
			else = {
				worsen_relationship_effect = {
					TARGET = scope:your_heir
					REASON = annoyed_by_heir_training
				}
			}
			scope:story = {
				if = {
					limit = { scope:training_heir_skill = flag:diplomacy }
					change_variable = { name = visit_diplomacy add = 1 }
				}
				else_if = {
					limit = { scope:training_heir_skill = flag:martial }
					change_variable = { name = visit_martial add = 1 }
				}
				else_if = {
					limit = { scope:training_heir_skill = flag:stewardship }
					change_variable = { name = visit_stewardship add = 1 }
				}
				else_if = {
					limit = { scope:training_heir_skill = flag:intrigue }
					change_variable = { name = visit_intrigue add = 1 }
				}
				else = {
					change_variable = { name = visit_learning add = 1 }
				}
			}
		}
		else = {
			custom_tooltip = lmf_heir.heir.progress.moderate.tt
			stress_impact = {
				base = minor_stress_impact_gain
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
			}
			if = {
				limit = { has_relation_friend = scope:your_heir }
				add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
				reverse_add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
			}
			else = {
				improve_relationship_effect = {
					TARGET = scope:your_heir
					REASON = spent_time_with_heir
				}
			}
			scope:story = {
				if = {
					limit = { scope:training_heir_skill = flag:diplomacy }
					change_variable = { name = visit_diplomacy add = 2 }
				}
				else_if = {
					limit = { scope:training_heir_skill = flag:martial }
					change_variable = { name = visit_martial add = 2 }
				}
				else_if = {
					limit = { scope:training_heir_skill = flag:stewardship }
					change_variable = { name = visit_stewardship add = 2 }
				}
				else_if = {
					limit = { scope:training_heir_skill = flag:intrigue }
					change_variable = { name = visit_intrigue add = 2 }
				}
				else = {
					change_variable = { name = visit_learning add = 2 }
				}
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		clear_saved_scope = training_heir_skill
		if = {
			limit = { exists = scope:was_helpful }
			clear_saved_scope = was_helpful
			clear_saved_scope = was_previously_annoying
			save_scope_value_as = { name = was_previously_helpful value = yes }
		}
		else = {
			clear_saved_scope = was_annoying
			clear_saved_scope = was_previously_helpful
			save_scope_value_as = { name = was_previously_annoying value = yes }
		}
		advance_heir_timer_effect = yes
	}
}

# Attraction between heir and liege
lmf_heir.1661 = {
	type = character_event
	title = lmf_heir.1661.t
	desc = {
		desc = lmf_heir.1661.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:your_heir = { is_adult = no }
				}
				desc = lmf_heir.1661.desc.child
			}
			desc = lmf_heir.1661.desc.adult
		}
		desc = lmf_heir.1661.desc.end
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:your_heir = { is_adult = no } }
			animation = admiration
		}
		animation = flirtation
	}
	right_portrait = {
		character = root
		animation = laugh
	}
	override_background = { reference = throne_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }
		scope:story = {
			# increment story variables
			change_variable = { name = visit_time_target add = 1 }
			change_variable = { name = visit_success add = 2 }
			set_variable = { name = had_heir_1661_event value = yes }
		}
	}

	option = {
		trigger = {
			scope:your_heir = { is_adult = yes }
		}
		name = lmf_heir.1661.a #This should be interesting
		had_sex_with_effect = { CHARACTER = scope:your_heir PREGNANCY_CHANCE = pregnancy_chance }
		set_relation_lover = { target = scope:your_heir reason = bonded_while_heir_training }
		ai_chance = {
			base = 20
		}
	}
	option = {
		trigger = {
			scope:your_heir = { is_adult = yes }
		}
		name = lmf_heir.1661.b #Maybe for now, but once he's gone we're done
		had_sex_with_effect = { CHARACTER = scope:your_heir PREGNANCY_CHANCE = pregnancy_chance }
		reverse_add_opinion = { target = scope:your_heir modifier = tryst_opinion opinion = 20 }
		if = {
			limit = { is_ai = yes }
			add_opinion = { target = scope:your_heir modifier = tryst_opinion opinion = 20 }
		}
		ai_chance = {
			base = 20
		}
	}
	option = {
		trigger = {
			scope:your_heir = { is_adult = no }
		}
		name = lmf_heir.1661.c #I'm flattered. Maybe once he's older...
		scope:your_heir = {
			set_relation_crush = { target = root reason = crush_while_heir_training }
		}
		if = {
			limit = { is_ai = yes }
			add_opinion = { target = scope:your_heir modifier = amused_opinion opinion = 20 }
		}
		ai_chance = {
			base = 20
		}
	}
	option = {
		name = lmf_heir.1661.d #Quietly shut this down before it goes anywhere
		reverse_add_opinion = { target = scope:your_heir modifier = disappointed_opinion opinion = -15 }
		ai_chance = {
			base = 60
			ai_value_modifier = {
				ai_honor = 1
				min = -20
			}
			modifier = {
				factor = 3
				likely_to_take_lover_trigger = no
			}
			modifier = {
				factor = 0.5
				likely_to_take_lover_trigger = yes
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir spends time learning from councillor
lmf_heir.1662 = {
	type = character_event
	title = lmf_heir.1662.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1662.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1662.desc.busy
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1662.desc.notrain
		}
		desc = lmf_heir.1662.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:your_councillor = { has_council_position = councillor_chancellor }
				}
				desc = lmf_heir.1662.desc.chancellor
			}
			triggered_desc = {
				trigger = {
					scope:your_councillor = { has_council_position = councillor_steward }
				}
				desc = lmf_heir.1662.desc.steward
			}
			triggered_desc = {
				trigger = {
					scope:your_councillor = { has_council_position = councillor_marshal }
				}
				desc = lmf_heir.1662.desc.marshal
			}
			desc = lmf_heir.1662.desc.spymaster
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:training_went_well = yes }
				desc = lmf_heir.1662.desc.well
			}
			desc = lmf_heir.1662.desc.poorly
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:training_went_well = no }
			animation = boredom
		}
		animation = thinking
	}
	right_portrait = {
		character = scope:your_councillor
		triggered_animation = {
			trigger = { scope:training_went_well = no }
			animation = disapproval
		}
		animation = debating
	}
	override_background = {
		trigger = {
			scope:your_councillor = { has_council_position = councillor_chancellor }
		}
		reference = study
	}
	override_background = {
		trigger = {
			scope:your_councillor = { has_council_position = councillor_steward }
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			scope:your_councillor = { has_council_position = councillor_marshal }
		}
		reference = army_camp
	}
	override_background = {
		trigger = {
			scope:your_councillor = { has_council_position = councillor_spymaster }
		}
		reference = corridor_night
	}

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# first pick a councillor
		scope:heir_visit_target = {
			every_councillor = {
				limit = {
					is_candidate_for_heir_teaching = yes
					OR = {
						AND = {
							has_council_position = councillor_chancellor
							diplomacy > scope:your_heir.diplomacy
						}
						AND = {
							has_council_position = councillor_steward
							stewardship > scope:your_heir.stewardship
						}
						AND = {
							has_council_position = councillor_marshal
							martial > scope:your_heir.martial
						}
						AND = {
							has_council_position = councillor_spymaster
							intrigue > scope:your_heir.intrigue
						}
					}
				}
				add_to_list = councillor_teachers
			}
		}
		random_in_list = {
			list = councillor_teachers
			weight = {
				base = 10
				modifier = {
					add = 10
					has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:your_heir }
				}
				modifier = {
					add = 5
					opinion = { target = scope:your_heir value > 0 }
				}
				modifier = {
					add = 5
					reverse_opinion = { target = scope:your_heir value > 0 }
				}
				modifier = {
					add = -5
					opinion = { target = scope:your_heir value < 0 }
				}
				modifier = {
					add = -5
					reverse_opinion = { target = scope:your_heir value < 0 }
				}
				modifier = {
					add = 10
					has_council_position = councillor_chancellor
					scope:your_heir = {
						OR = {
							has_trait = education_diplomacy
							has_focus = education_diplomacy
						}
					}
				}
				modifier = {
					add = 10
					has_council_position = councillor_steward
					scope:your_heir = {
						OR = {
							has_trait = education_stewardship
							has_focus = education_stewardship
						}
					}
				}
				modifier = {
					add = 10
					has_council_position = councillor_marshal
					scope:your_heir = {
						OR = {
							has_trait = education_martial
							has_focus = education_martial
						}
					}
				}
				modifier = {
					add = 10
					has_council_position = councillor_spymaster
					scope:your_heir = {
						OR = {
							has_trait = education_intrigue
							has_focus = education_intrigue
						}
					}
				}
				modifier = {
					add = 20
					has_council_position = councillor_chancellor
					diplomacy > scope:your_heir.diplomacy_plus_5
				}
				modifier = {
					add = 20
					has_council_position = councillor_steward
					stewardship > scope:your_heir.stewardship_plus_5
				}
				modifier = {
					add = 20
					has_council_position = councillor_marshal
					martial > scope:your_heir.martial_plus_5
				}
				modifier = {
					add = 20
					has_council_position = councillor_spymaster
					intrigue > scope:your_heir.intrigue_plus_5
				}
				min = 1
			}
			save_scope_as = your_councillor
			add_character_flag = { flag = no_heir_training months = 6 }
		}

		# did the training go well?
		random_list = {
			100 = {
				modifier = {
					add = 50
					exists = scope:heir_behavior
					OR = {
						scope:heir_behavior = flag:dutiful
						scope:heir_behavior = flag:impressive
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_honor = 0.5
					ai_energy = 0.5
				}
				compatibility_modifier = {
					who = scope:your_heir
					compatibility_target = scope:your_councillor
					multiplier = 2
				}
				min = 10
				save_scope_value_as = { name = training_went_well value = yes }
			}
			100 = {
				modifier = {
					add = 50
					exists = scope:heir_behavior
					OR = {
						scope:heir_behavior = flag:trouble
						scope:heir_behavior = flag:homesick
						scope:heir_behavior = flag:avoidant
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_honor = -0.5
					ai_energy = -0.5
				}
				min = 10
				save_scope_value_as = { name = training_went_well value = no }
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			set_variable = { name = had_heir_1662_event value = yes }
		}
	}

	option = {
		trigger = { scope:training_went_well = yes }
		name = lmf_heir.1662.a
		custom_tooltip = lmf_heir.heir.progress.moderate.tt
		scope:your_councillor = {
			stress_impact = {
				base = minor_stress_impact_gain
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
			}
			if = {
				limit = { has_relation_friend = scope:your_heir }
				add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
				reverse_add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
			}
			else = {
				improve_relationship_effect = {
					TARGET = scope:your_heir
					REASON = spent_time_with_heir
				}
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 2 }
			if = {
				limit = { scope:your_councillor = { has_council_position = councillor_chancellor } }
				change_variable = { name = visit_diplomacy add = 2 }
			}
			else_if = {
				limit = { scope:your_councillor = { has_council_position = councillor_marshal } }
				change_variable = { name = visit_martial add = 2 }
			}
			else_if = {
				limit = { scope:your_councillor = { has_council_position = councillor_steward } }
				change_variable = { name = visit_stewardship add = 2 }
			}
			else = {
				change_variable = { name = visit_intrigue add = 2 }
			}
		}
	}
	option = {
		trigger = { scope:training_went_well = no }
		name = lmf_heir.1662.b
		custom_tooltip = lmf_heir.heir.progress.minor.tt
		scope:your_councillor = {
			stress_impact = {
				base = medium_stress_impact_gain
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
			}
			if = {
				limit = { has_relation_rival = scope:your_heir }
				add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20 }
				reverse_add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20}
			}
			else = {
				worsen_relationship_effect = {
					TARGET = scope:your_heir
					REASON = annoyed_by_heir_training
				}
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 1 }
			if = {
				limit = { scope:your_councillor = { has_council_position = councillor_chancellor } }
				change_variable = { name = visit_diplomacy add = 1 }
			}
			else_if = {
				limit = { scope:your_councillor = { has_council_position = councillor_marshal } }
				change_variable = { name = visit_martial add = 1 }
			}
			else_if = {
				limit = { scope:your_councillor = { has_council_position = councillor_steward } }
				change_variable = { name = visit_stewardship add = 1 }
			}
			else = {
				change_variable = { name = visit_intrigue add = 1 }
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		clear_saved_scope = training_went_well
		advance_heir_timer_effect = yes
	}
}

# Heir spends time with court member
lmf_heir.1663 = {
	type = character_event
	title = lmf_heir.1663.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1663.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1663.desc.busy
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1663.desc.notrain
		}
		desc = lmf_heir.1663.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:your_courtier = { has_court_position = court_physician_court_position }
				}
				desc = lmf_heir.1663.desc.physician
			}
			triggered_desc = {
				trigger = {
					scope:your_courtier = { has_court_position = chronicler_court_position }
				}
				desc = lmf_heir.1663.desc.chronicler
			}
			triggered_desc = {
				trigger = {
					scope:your_courtier = { has_court_position = master_of_horse_court_position }
				}
				desc = lmf_heir.1663.desc.horse
			}
			triggered_desc = {
				trigger = {
					scope:your_courtier = { has_court_position = seneschal_court_position }
				}
				desc = lmf_heir.1663.desc.seneschal
			}
			desc = lmf_heir.1663.desc.taster
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:training_went_well = yes }
				desc = lmf_heir.1663.desc.well
			}
			desc = lmf_heir.1663.desc.poorly
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:training_went_well = no }
			animation = shame
		}
		animation = thinking
	}
	right_portrait = {
		character = scope:your_courtier
		triggered_animation = {
			trigger = { scope:training_went_well = no }
			animation = disappointed
		}
		animation = debating
	}
	override_background = {
		trigger = {
			scope:your_courtier = { has_court_position = court_physician_court_position }
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			scope:your_courtier = { has_court_position = chronicler_court_position }
		}
		reference = garden
	}
	override_background = {
		trigger = {
			scope:your_courtier = { has_court_position = master_of_horse_court_position }
		}
		reference = armory
	}
	override_background = {
		trigger = {
			scope:your_courtier = { has_court_position = seneschal_court_position }
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			scope:your_courtier = { has_court_position = food_taster_court_position }
		}
		reference = feast
	}

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# first pick a court member
		scope:heir_visit_target = {
			every_courtier = {
				limit = {
					is_candidate_for_heir_teaching = yes
					is_councillor = no
					OR = {
						AND = {
							has_court_position = court_physician_court_position
							learning > scope:your_heir.learning
						}
						AND = {
							has_court_position = chronicler_court_position
							diplomacy > scope:your_heir.diplomacy
						}
						AND = {
							has_court_position = master_of_horse_court_position
							martial > scope:your_heir.martial
						}
						AND = {
							has_court_position = seneschal_court_position
							stewardship > scope:your_heir.stewardship
						}
						AND = {
							has_court_position = food_taster_court_position
							intrigue > scope:your_heir.intrigue
						}
					}
				}
				add_to_list = court_teachers
			}
		}
		random_in_list = {
			list = court_teachers
			weight = {
				base = 5
				modifier = {
					add = 10
					has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:your_heir }
				}
				modifier = {
					add = 5
					opinion = { target = scope:your_heir value > 0 }
				}
				modifier = {
					add = 5
					reverse_opinion = { target = scope:your_heir value > 0 }
				}
				modifier = {
					add = -5
					opinion = { target = scope:your_heir value < 0 }
				}
				modifier = {
					add = -5
					reverse_opinion = { target = scope:your_heir value < 0 }
				}
				modifier = {
					add = 10
					has_court_position = chronicler_court_position
					scope:your_heir = {
						OR = {
							has_trait = education_diplomacy
							has_focus = education_diplomacy
						}
					}
				}
				modifier = {
					add = 10
					has_court_position = seneschal_court_position
					scope:your_heir = {
						OR = {
							has_trait = education_stewardship
							has_focus = education_stewardship
						}
					}
				}
				modifier = {
					add = 10
					has_court_position = master_of_horse_court_position
					scope:your_heir = {
						OR = {
							has_trait = education_martial
							has_focus = education_martial
						}
					}
				}
				modifier = {
					add = 10
					has_court_position = food_taster_court_position
					scope:your_heir = {
						OR = {
							has_trait = education_intrigue
							has_focus = education_intrigue
						}
					}
				}
				modifier = {
					add = 10
					has_court_position = court_physician_court_position
					scope:your_heir = {
						OR = {
							has_trait = education_learning
							has_focus = education_learning
						}
					}
				}
				modifier = {
					add = 20
					has_court_position = chronicler_court_position
					diplomacy > scope:your_heir.diplomacy_plus_5
				}
				modifier = {
					add = 20
					has_court_position = seneschal_court_position
					stewardship > scope:your_heir.stewardship_plus_5
				}
				modifier = {
					add = 20
					has_court_position = master_of_horse_court_position
					martial > scope:your_heir.martial_plus_5
				}
				modifier = {
					add = 20
					has_court_position = food_taster_court_position
					intrigue > scope:your_heir.intrigue_plus_5
				}
				modifier = {
					add = 20
					has_court_position = court_physician_court_position
					learning > scope:your_heir.learning_plus_5
				}
				min = 1
			}
			save_scope_as = your_courtier
			add_character_flag = { flag = no_heir_training months = 6 }
		}

		# did the training go well?
		random_list = {
			100 = {
				modifier = {
					add = 50
					exists = scope:heir_behavior
					OR = {
						scope:heir_behavior = flag:dutiful
						scope:heir_behavior = flag:impressive
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_honor = 0.5
					ai_energy = 0.5
				}
				compatibility_modifier = {
					who = scope:your_heir
					compatibility_target = scope:your_courtier
					multiplier = 2
				}
				min = 10
				save_scope_value_as = { name = training_went_well value = yes }
			}
			100 = {
				modifier = {
					add = 50
					exists = scope:heir_behavior
					OR = {
						scope:heir_behavior = flag:trouble
						scope:heir_behavior = flag:homesick
						scope:heir_behavior = flag:avoidant
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_honor = -0.5
					ai_energy = -0.5
				}
				min = 10
				save_scope_value_as = { name = training_went_well value = no }
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			set_variable = { name = had_heir_1663_event value = yes }
		}
	}

	option = {
		trigger = { scope:training_went_well = yes }
		name = lmf_heir.1663.a
		custom_tooltip = lmf_heir.heir.progress.moderate.tt
		scope:your_courtier = {
			stress_impact = {
				base = minor_stress_impact_gain
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
			}
			if = {
				limit = { has_relation_friend = scope:your_heir }
				add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
				reverse_add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
			}
			else = {
				improve_relationship_effect = {
					TARGET = scope:your_heir
					REASON = spent_time_with_heir
				}
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 2 }
			if = {
				limit = { scope:your_courtier = { has_court_position = chronicler_court_position } }
				change_variable = { name = visit_diplomacy add = 2 }
			}
			else_if = {
				limit = { scope:your_courtier = { has_court_position = master_of_horse_court_position } }
				change_variable = { name = visit_martial add = 2 }
			}
			else_if = {
				limit = { scope:your_courtier = { has_court_position = seneschal_court_position } }
				change_variable = { name = visit_stewardship add = 2 }
			}
			else_if = {
				limit = { scope:your_courtier = { has_court_position = court_physician_court_position } }
				change_variable = { name = visit_learning add = 2 }
			}
			else = {
				change_variable = { name = visit_intrigue add = 2 }
			}
		}
	}
	option = {
		trigger = { scope:training_went_well = no }
		name = lmf_heir.1663.b
		custom_tooltip = lmf_heir.heir.progress.minor.tt
		scope:your_courtier = {
			stress_impact = {
				base = medium_stress_impact_gain
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
			}
			if = {
				limit = { has_relation_rival = scope:your_heir }
				add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20 }
				reverse_add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20}
			}
			else = {
				worsen_relationship_effect = {
					TARGET = scope:your_heir
					REASON = annoyed_by_heir_training
				}
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 1 }
			if = {
				limit = { scope:your_courtier = { has_court_position = chronicler_court_position } }
				change_variable = { name = visit_diplomacy add = 1 }
			}
			else_if = {
				limit = { scope:your_courtier = { has_court_position = master_of_horse_court_position } }
				change_variable = { name = visit_martial add = 1 }
			}
			else_if = {
				limit = { scope:your_courtier = { has_court_position = seneschal_court_position } }
				change_variable = { name = visit_stewardship add = 1 }
			}
			else_if = {
				limit = { scope:your_courtier = { has_court_position = court_physician_court_position } }
				change_variable = { name = visit_learning add = 1 }
			}
			else = {
				change_variable = { name = visit_intrigue add = 1 }
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		clear_saved_scope = training_went_well
		advance_heir_timer_effect = yes
	}
}

# Heir spends time with knight
lmf_heir.1664 = {
	type = character_event
	title = lmf_heir.1664.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1664.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1664.desc.busy
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1664.desc.notrain
		}
		desc = lmf_heir.1664.desc
	}
	theme = realm

	right_portrait = {
		character = scope:your_heir
		animation = celebrate_sword
	}
	left_portrait = {
		character = scope:your_courtier
		animation = debating
	}
	override_background = { reference = army_camp }

	immediate = {
		scope:your_heir = { add_character_flag = wear_armor }

		# first pick a knight
		scope:heir_visit_target = {
			random_knight = {
				limit = {
					is_candidate_for_heir_teaching = yes
					is_councillor = no
					NOT = { has_court_position = master_of_horse_court_position }
					OR = {
						martial > scope:your_heir.martial
						prowess > scope:your_heir.prowess
					}
				}
				weight = {
					base = 5
					modifier = {
						add = 10
						has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:your_heir }
					}
					modifier = {
						add = 5
						opinion = { target = scope:your_heir value > 0 }
					}
					modifier = {
						add = 5
						reverse_opinion = { target = scope:your_heir value > 0 }
					}
					modifier = {
						add = -5
						opinion = { target = scope:your_heir value < 0 }
					}
					modifier = {
						add = -5
						reverse_opinion = { target = scope:your_heir value < 0 }
					}
					modifier = {
						add = -5
						prowess < scope:your_heir.prowess
					}
					modifier = {
						add = -5
						martial < scope:your_heir.martial
					}
					modifier = {
						add = 5
						prowess > scope:your_heir.prowess
					}
					modifier = {
						add = 5
						martial > scope:your_heir.martial
					}
					modifier = {
						add = 20
						prowess > scope:your_heir.prowess_plus_5
					}
					modifier = {
						add = 20
						martial > scope:your_heir.martial_plus_5
					}
					min = 1
				}
				save_scope_as = your_courtier
				add_character_flag = wear_armor
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = 2 }
			if = {
				limit = { scope:your_courtier.martial >= scope:your_heir.martial_plus_5 }
				change_variable = { name = visit_martial add = 2 }
			}
			else = {
				change_variable = { name = visit_martial add = 1 }
			}
			if = {
				limit = { scope:your_courtier.prowess >= scope:your_heir.prowess_plus_5 }
				change_variable = { name = visit_prowess add = 2 }
			}
			else_if = {
				limit = { scope:your_courtier.prowess > scope:your_heir.prowess }
				change_variable = { name = visit_prowess add = 1 }
			}
			set_variable = { name = had_heir_1664_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1664.a
		custom_tooltip = lmf_heir.heir.progress.moderate.tt
		scope:your_courtier = {
			stress_impact = {
				base = minor_stress_impact_gain
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
			}
			if = {
				limit = { has_relation_friend = scope:your_heir }
				add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
				reverse_add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
			}
			else = {
				improve_relationship_effect = {
					TARGET = scope:your_heir
					REASON = spent_time_with_heir
				}
			}
		}
	}

	after = {
		scope:your_heir = { remove_character_flag = wear_armor }
		scope:your_courtier = { remove_character_flag = wear_armor }
		advance_heir_timer_effect = yes
	}
}

# Heir duels a knight
lmf_heir.1665 = {
	type = character_event
	title = lmf_heir.1665.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1664.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1664.desc.busy
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1664.desc.notrain
		}
		desc = lmf_heir.1665.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:your_heir = { is_adult = no }
				}
				desc = lmf_heir.1665.desc.child
			}
			desc = lmf_heir.1665.desc.adult
		}
		desc = lmf_heir.1665.desc.end
	}
	theme = realm

	right_portrait = {
		character = scope:your_heir
		animation = aggressive_sword
	}
	left_portrait = {
		character = scope:your_courtier
		animation = disgust
	}
	override_background = { reference = army_camp }

	immediate = {
		scope:your_heir = { add_character_flag = wear_armor }

		# first pick a knight
		scope:heir_visit_target = {
			random_knight = {
				limit = {
					is_candidate_for_heir_teaching = yes
					is_councillor = no
					NOT = { has_court_position = master_of_horse_court_position }
					martial > scope:your_heir.martial
					is_healthy = yes
				}
				weight = {
					base = 10
					compatibility_modifier = {
						compatibility_target = scope:your_heir
						multiplier = -1
					}
					modifier = {
						add = -10
						has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:your_heir }
					}
					modifier = {
						add = -5
						opinion = { target = scope:your_heir value > 0 }
					}
					modifier = {
						add = -5
						reverse_opinion = { target = scope:your_heir value > 0 }
					}
					modifier = {
						add = 5
						opinion = { target = scope:your_heir value < 0 }
					}
					modifier = {
						add = 5
						reverse_opinion = { target = scope:your_heir value < 0 }
					}
					modifier = {
						add = -5
						prowess < scope:your_heir.prowess
					}
					modifier = {
						add = 5
						prowess > scope:your_heir.prowess
					}
					modifier = {
						add = 10
						martial > scope:your_heir.martial_plus_5
					}
					min = 1
				}
				save_scope_as = your_courtier
				add_character_flag = wear_armor
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = -1 }
			change_variable = { name = visit_martial add = 1 }
			set_variable = { name = had_heir_1664_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1665.a
		custom_tooltip = lmf_heir.heir.progress.negative.tt
		scope:your_courtier = {
			stress_impact = {
				base = medium_stress_impact_gain
				compassionate = minor_stress_impact_loss
				forgiving = minor_stress_impact_loss
				wrathful = minor_stress_impact_gain
				vengeful = minor_stress_impact_gain
			}
			worsen_relationship_effect = { 
				TARGET = scope:your_heir
				REASON = dueled_during_heir_training
			}
			duel = {
				skill = prowess
				target = scope:your_heir
				5 = {
					desc = lmf_heir.1665.a.courtier.severe.tt
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
					}
					modifier = {
						factor = 2
						scope:your_courtier = { has_relation_nemesis = scope:your_heir }
					}
					modifier = {
						factor = 2
						scope:your_courtier = {
							has_personality_malicious_trigger = yes
						}
					}
					modifier = {
						factor = 0.5
						scope:your_courtier = {
							OR = {
								has_personality_benevolent_trigger = yes
								has_personality_levelheaded_trigger = yes
							}
						}
					}
					root = {
						send_interface_toast = {
							title = lmf_heir.1665.a.courtier.severe.tt
							left_icon = scope:your_courtier
							right_icon = scope:your_heir
							scope:your_heir = {
								hunt_wound_select_effect = yes
								hunt_wound_apply_effect = { SEVERE = yes }
								hunt_wound_tooltip_effect = yes
							}
						}
					}
					scope:heir_liege = {
						send_interface_message = {
							type = event_generic_bad_with_text
							title =  lmf_heir.1665.heir.duel.title
							desc = lmf_heir.1665.heir.severe.duel.desc
							left_icon = scope:your_heir
							right_icon = scope:your_courtier
						}
					}
				}
				45 = {
					desc = lmf_heir.1665.a.courtier.win.tt
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
					}
					root = {
						send_interface_toast = {
							title = lmf_heir.1665.a.courtier.win.tt
							left_icon = scope:your_courtier
							right_icon = scope:your_heir
							scope:your_heir = {
								increase_wounds_effect = { REASON = duel }
							}
						}
					}
					scope:heir_liege = {
						send_interface_message = {
							type = event_generic_bad_with_text
							title =  lmf_heir.1665.heir.duel.title
							desc = lmf_heir.1665.heir.duel.desc
							left_icon = scope:your_heir
							right_icon = scope:your_courtier
						}
					}
				}
				45 = {
					desc = lmf_heir.1665.a.heir.win.tt
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
					}
					root = {
						send_interface_toast = {
							title = lmf_heir.1665.a.heir.win.tt
							left_icon = scope:your_courtier
							right_icon = scope:your_heir
							scope:your_courtier = {
								increase_wounds_effect = { REASON = duel }
							}
						}
					}
				}
				5 = {
					desc = lmf_heir.1665.a.heir.severe.tt
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
					}
					modifier = {
						factor = 2
						scope:your_heir = { has_relation_nemesis = scope:your_courtier }
					}
					modifier = {
						factor = 2
						scope:your_heir = {
							has_personality_malicious_trigger = yes
						}
					}
					modifier = {
						factor = 0.5
						scope:your_heir = {
							OR = {
								has_personality_benevolent_trigger = yes
								has_personality_levelheaded_trigger = yes
							}
						}
					}
					root = {
						send_interface_toast = {
							title = lmf_heir.1665.a.heir.severe.tt
							left_icon = scope:your_courtier
							right_icon = scope:your_heir
							scope:your_courtier = {
								hunt_wound_select_effect = yes
								hunt_wound_apply_effect = { SEVERE = yes }
								hunt_wound_tooltip_effect = yes
							}
						}
					}
				}
			}
		}
		scope:your_heir = {
			hidden_effect = {
				stress_impact = {
					base = medium_stress_impact_gain
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
					wrathful = minor_stress_impact_loss
					vengeful = minor_stress_impact_loss
				}
			}
		}
	}

	after = {
		scope:your_heir = { remove_character_flag = wear_armor }
		scope:your_courtier = { remove_character_flag = wear_armor }
		advance_heir_timer_effect = yes
	}
}

# Heir pokes around learning secrets
lmf_heir.1666 = {
	type = character_event
	title = lmf_heir.1666.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1666.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1666.desc.busy
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = yes
			}
			desc = lmf_heir.1666.desc.train
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1666.desc.notrain
		}
		desc = lmf_heir.1666.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = page_flipping
	}
	override_background = { reference = corridor_night }

	immediate = {
		# find some secrets the heir can learn
		if = {
			limit = {
				heir_can_learn_secrets = yes
				exists = scope:story.var:host_will_train
			}
			heir_gathers_secrets_effect = yes
		}
		every_courtier = {
			limit = { heir_can_learn_secrets = yes }
			heir_gathers_secrets_effect = yes
		}
		every_vassal = {
			limit = { heir_can_learn_secrets = yes }
			heir_gathers_secrets_effect = yes
		}

		# grab one or more secrets, based on the heir's intrigue skill
		scope:your_heir = {
			heir_learns_secret_effect = yes
			if = {
				limit = { intrigue >= 12 }
				heir_learns_secret_effect = yes
			}
			if = {
				limit = { intrigue >= 18 }
				heir_learns_secret_effect = yes
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = 2 }
			change_variable = { name = visit_intrigue add = 2 }
			set_variable = { name = had_heir_1666_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1666.a
		custom_tooltip = lmf_heir.heir.progress.moderate.tt
	}

	after = {
		advance_heir_timer_effect = yes
	}
}

# Heir is indiscreet
lmf_heir.1667 = {
	type = character_event
	title = lmf_heir.1667.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1666.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1666.desc.busy
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = yes
			}
			desc = lmf_heir.1666.desc.train
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1666.desc.notrain
		}
		desc = lmf_heir.1667.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = shame
	}
	override_background = { reference = corridor_night }

	immediate = {
		# find some secrets the heir can learn
		if = {
			limit = {
				heir_can_learn_secrets = yes
				exists = scope:story.var:host_will_train
			}
			heir_gathers_secrets_effect = yes
		}
		every_courtier = {
			limit = { heir_can_learn_secrets = yes }
			heir_gathers_secrets_effect = yes
		}
		every_vassal = {
			limit = { heir_can_learn_secrets = yes }
			heir_gathers_secrets_effect = yes
		}

		# grab one secret, if heir skill is high enough
		scope:your_heir = {
			if = {
				limit = { intrigue >= 12 }
				heir_learns_secret_effect = yes
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = -1 }
			change_variable = { name = visit_intrigue add = 1 }
			set_variable = { name = had_heir_1666_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1667.a
		custom_tooltip = lmf_heir.heir.progress.negative.tt
		if = {
			limit = { has_relation_rival = scope:your_heir }
			add_opinion = { target = scope:your_heir modifier = suspicion_opinion opinion = -20 }
		}
		else = {
			worsen_relationship_effect = {
				TARGET = scope:your_heir
				REASON = heir_digging_up_secrets
			}
		}
	}

	after = {
		advance_heir_timer_effect = yes
	}
}

# Heir spends time in the library
lmf_heir.1668 = {
	type = character_event
	title = lmf_heir.1668.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1666.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1666.desc.busy
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = yes
			}
			desc = lmf_heir.1666.desc.train
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1666.desc.notrain
		}
		desc = lmf_heir.1668.desc.start
		first_valid = {
			triggered_desc = {
				trigger = { scope:training_went_well = yes }
				desc = lmf_heir.1668.desc.well
			}
			desc = lmf_heir.1668.desc.poorly
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = reading
	}
	override_background = { reference = study }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# did the time go well?
		random_list = {
			100 = {
				modifier = {
					add = 50
					exists = scope:heir_behavior
					OR = {
						scope:heir_behavior = flag:dutiful
						scope:heir_behavior = flag:avoidant
						scope:heir_behavior = flag:homesick
					}
				}
				modifier = {
					always = yes
					add = {
						value = scope:your_heir.learning
						subtract = 6
						multiply = 10
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_energy = 0.5
				}
				min = 10
				save_scope_value_as = { name = training_went_well value = yes }
			}
			100 = {
				modifier = {
					add = 50
					exists = scope:heir_behavior
					OR = {
						scope:heir_behavior = flag:trouble
						scope:heir_behavior = flag:impressive
					}
				}
				modifier = {
					always = yes
					add = {
						value = 6
						subtract = scope:your_heir.learning
						multiply = 10
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_energy = -0.5
				}
				min = 10
				save_scope_value_as = { name = training_went_well value = no }
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			set_variable = { name = had_heir_1668_event value = yes }
		}
	}

	option = {
		trigger = { scope:training_went_well = yes }
		name = lmf_heir.1668.a
		custom_tooltip = lmf_heir.heir.progress.moderate.tt
		scope:your_heir = {
			if = {
				limit = { has_personality_introverted_trigger = yes }
				stress_impact = {
					base = minor_stress_impact_loss
					pensive = minor_stress_impact_loss
					shy = minor_stress_impact_loss
					rowdy = minor_stress_impact_gain
					gregarious = minor_stress_impact_gain
				}
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 1 }
			change_variable = { name = visit_learning add = 2 }
		}
	}
	option = {
		trigger = { scope:training_went_well = no }
		name = lmf_heir.1668.b
		custom_tooltip = lmf_heir.heir.progress.minor.tt
		scope:your_heir = {
			if = {
				limit = { has_personality_introverted_trigger = yes }
				stress_impact = {
					base = minor_stress_impact_loss
					pensive = minor_stress_impact_loss
					shy = minor_stress_impact_loss
					rowdy = minor_stress_impact_gain
					gregarious = minor_stress_impact_gain
				}
			}
		}
		scope:story = {
			change_variable = { name = visit_learning add = 1 }
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		clear_saved_scope = training_went_well
		advance_heir_timer_effect = yes
	}
}

# Heir is a delight in the castle
lmf_heir.1669 = {
	type = character_event
	title = lmf_heir.1669.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:impressive }
				desc = lmf_heir.1669.desc.impressive
			}
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:unpleasant }
				desc = lmf_heir.1669.desc.unpleasant
			}
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:trouble }
				desc = lmf_heir.1669.desc.trouble
			}
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:dutiful }
				desc = lmf_heir.1669.desc.dutiful
			}
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:homesick }
				desc = lmf_heir.1669.desc.homesick
			}
			desc = lmf_heir.1669.desc.avoid
		}
		desc = lmf_heir.1669.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = laugh
	}
	override_background = { reference = relaxing_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = 2 }
			change_variable = { name = visit_diplomacy add = 2 }
			set_variable = { name = had_heir_1669_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1669.a
		custom_tooltip = lmf_heir.heir.progress.moderate.tt
		save_scope_value_as = { name = heir_behavior value = flag:impressive }
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir is avoided by the castle
lmf_heir.1670 = {
	type = character_event
	title = lmf_heir.1670.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:impressive }
				desc = lmf_heir.1670.desc.impressive
			}
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:unpleasant }
				desc = lmf_heir.1670.desc.unpleasant
			}
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:trouble }
				desc = lmf_heir.1670.desc.trouble
			}
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:dutiful }
				desc = lmf_heir.1670.desc.dutiful
			}
			triggered_desc = {
				trigger = { scope:heir_behavior = flag:homesick }
				desc = lmf_heir.1670.desc.homesick
			}
			desc = lmf_heir.1670.desc.avoid
		}
		desc = lmf_heir.1670.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = disgust
	}
	override_background = { reference = relaxing_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = -1 }
			change_variable = { name = visit_diplomacy add = 1 }
			set_variable = { name = had_heir_1669_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1670.a
		custom_tooltip = lmf_heir.heir.progress.negative.tt
		save_scope_value_as = { name = heir_behavior value = flag:unpleasant }
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir works on castle project
lmf_heir.1671 = {
	type = character_event
	title = lmf_heir.1671.t
	desc = {
		desc = lmf_heir.1671.desc.start
		first_valid = {
			triggered_desc = {
				trigger = { scope:training_went_well = yes }
				desc = lmf_heir.1671.desc.well
			}
			desc = lmf_heir.1671.desc.poorly
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:training_went_well = no }
			animation = stress
		}
		animation = survey
		outfit_tags = { travel_cloak }
	}
	override_background = { reference = terrain_scope }

	immediate = {
		capital_province = { save_scope_as = background_terrain_scope }
		scope:your_heir = { no_hat_respectful_effect = yes }

		# did the project go well?
		random_list = {
			100 = {
				modifier = {
					add = 50
					exists = scope:heir_behavior
					OR = {
						scope:heir_behavior = flag:dutiful
						scope:heir_behavior = flag:impressive
					}
				}
				modifier = {
					always = yes
					add = {
						value = scope:your_heir.stewardship
						subtract = 6
						multiply = 10
					}
				}
				modifier = {
					always = yes
					add = {
						value = scope:your_heir.learning
						subtract = 6
						multiply = 5
					}
				}
				modifier = {
					always = yes
					add = {
						value = scope:your_heir.diplomacy
						subtract = 6
						multiply = 5
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_energy = 1
				}
				min = 10
				save_scope_value_as = { name = training_went_well value = yes }
			}
			100 = {
				modifier = {
					add = 50
					exists = scope:heir_behavior
					OR = {
						scope:heir_behavior = flag:trouble
						scope:heir_behavior = flag:avoidant
						scope:heir_behavior = flag:unpleasant
					}
				}
				modifier = {
					always = yes
					add = {
						value = 6
						subtract = scope:your_heir.stewardship
						multiply = 10
					}
				}
				modifier = {
					always = yes
					add = {
						value = 6
						subtract = scope:your_heir.learning
						multiply = 5
					}
				}
				modifier = {
					always = yes
					add = {
						value = 6
						subtract = scope:your_heir.diplomacy
						multiply = 5
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_energy = -1
				}
				min = 10
				save_scope_value_as = { name = training_went_well value = no }
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			set_variable = { name = had_heir_1671_event value = yes }
		}
	}

	option = {
		trigger = { scope:training_went_well = yes }
		name = lmf_heir.1671.a
		custom_tooltip = lmf_heir.heir.progress.moderate.tt
		scope:story = {
			change_variable = { name = visit_success add = 2 }
			change_variable = { name = visit_stewardship add = 2 }
		}
	}
	option = {
		trigger = { scope:training_went_well = no }
		name = lmf_heir.1671.b
		custom_tooltip = lmf_heir.heir.progress.minor.tt
		scope:story = {
			change_variable = { name = visit_stewardship add = 1 }
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		clear_saved_scope = training_went_well
		advance_heir_timer_effect = yes
	}
}

# Heir gets into fight with courtier
lmf_heir.1672 = {
	type = character_event
	title = lmf_heir.1672.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1666.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1666.desc.busy
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = yes
			}
			desc = lmf_heir.1666.desc.train
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1666.desc.notrain
		}
		desc = lmf_heir.1672.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = anger
	}
	right_portrait = {
		character = scope:your_courtier
		animation = dismissal
	}
	override_background = { reference = throne_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# pick courtier to fight
		random_courtier = {
			limit = { is_candidate_for_heir_enemy = yes }
			weight = {
				base = 10
				opinion_modifier = {
					who = scope:your_heir
					opinion_target = this
					multiplier = -0.5
				}
				compatibility_modifier = {
					who = scope:your_heir
					compatibility_target = this
					multiplier = -2
				}
				modifier = {
					add = 50
					has_relation_potential_rival = scope:your_heir
				}
				min = 1
			}
			save_scope_as = your_courtier
			no_hat_respectful_effect = yes
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = -1 }
			set_variable = { name = had_heir_1672_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1672.a
		scope:your_courtier = {
			set_relation_rival = {
				reason = fight_during_heir_training
				target = scope:your_heir
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		scope:your_courtier = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir gets along with courtier
lmf_heir.1673 = {
	type = character_event
	title = lmf_heir.1673.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1666.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1666.desc.busy
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = yes
			}
			desc = lmf_heir.1666.desc.train
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1666.desc.notrain
		}
		desc = lmf_heir.1673.desc
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = interested
	}
	right_portrait = {
		character = scope:your_courtier
		animation = laugh
	}
	override_background = { reference = throne_room }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# pick courtier to fight
		random_courtier = {
			limit = { is_candidate_for_heir_friend = yes }
			weight = {
				base = 10
				opinion_modifier = {
					who = scope:your_heir
					opinion_target = this
					multiplier = 0.5
				}
				compatibility_modifier = {
					who = scope:your_heir
					compatibility_target = this
					multiplier = 2
				}
				modifier = {
					add = 50
					has_relation_potential_friend = scope:your_heir
				}
				min = 1
			}
			save_scope_as = your_courtier
			no_hat_respectful_effect = yes
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = 2 }
			set_variable = { name = had_heir_1672_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1672.a
		scope:your_courtier = {
			set_relation_friend = {
				reason = befriended_during_heir_training
				target = scope:your_heir
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		scope:your_courtier = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir falls in love with courtier
lmf_heir.1674 = {
	type = character_event
	title = lmf_heir.1674.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1666.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1666.desc.busy
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = yes
			}
			desc = lmf_heir.1666.desc.train
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1666.desc.notrain
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:your_heir = { is_adult = yes }
				}
				desc = lmf_heir.1674.desc.adult
			}
			triggered_desc = {
				trigger = {
					scope:your_heir = { is_adult = no }
					scope:your_courtier = { is_adult = yes }
				}
				desc = lmf_heir.1674.desc.child
			}
			desc = lmf_heir.1674.desc.bothchild
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:your_heir = { is_adult = no } }
			animation = admiration
		}
		animation = flirtation_left
	}
	right_portrait = {
		character = scope:your_courtier
		triggered_animation = {
			trigger = { scope:your_heir = { is_adult = no } }
			animation = debating
		}
		animation = laugh
	}
	override_background = { reference = garden }

	immediate = {
		scope:your_heir = { add_character_flag = no_hat }

		# pick courtier to romance
		random_courtier = {
			limit = {
				OR = {
					AND = {
						scope:your_heir = { is_adult = no }
						is_candidate_for_heir_crush = yes
					}
					AND = {
						scope:your_heir = { is_adult = yes }
						is_candidate_for_heir_seduction = yes
					}
				}
			}
			weight = {
				base = 10
				modifier = {
					add = {
						value = attraction
						multiply = 2
					}
					always = yes
				}
				opinion_modifier = {
					who = scope:your_heir
					opinion_target = this
					multiplier = 0.5
					max = 20
					min = -20
				}
				compatibility_modifier = {
					who = scope:your_heir
					compatibility_target = this
					multiplier = 2
				}
				modifier = {
					add = 50
					scope:your_heir = { is_adult = yes }
					has_relation_potential_lover = scope:your_heir
				}
				min = 1
			}
			save_scope_as = your_courtier
			add_character_flag = no_hat
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_castle add = 1 }
			change_variable = { name = visit_success add = 1 }
			set_variable = { name = had_heir_1672_event value = yes }
			set_variable = { name = had_heir_1674_event value = yes }
		}
	}

	option = {
		trigger = { scope:your_heir = { is_adult = yes } }
		name = lmf_heir.1674.a
		custom_tooltip = lmf_heir.heir.progress.minor.tt
		scope:your_heir = {
			add_opinion = { target = scope:your_courtier modifier = grateful_opinion opinion = 20 }
			reverse_add_opinion = { target = scope:your_courtier modifier = respect_opinion opinion = 20 }
			hidden_effect = {
				set_relation_lover = {
					target = scope:your_courtier
					reason = fell_in_love_heir_training
				}
			}
		}
	}
	option = {
		trigger = { scope:your_heir = { is_adult = no } }
		name = lmf_heir.1674.b
		custom_tooltip = lmf_heir.heir.progress.minor.tt
		scope:your_heir = {
			add_opinion = { target = scope:your_courtier modifier = grateful_opinion opinion = 20 }
			reverse_add_opinion = { target = scope:your_courtier modifier = respect_opinion opinion = 20 }
			set_relation_crush = {
				target = scope:your_courtier
				reason = crushed_heir_training
			}
		}
		if = {
			limit = {
				scope:your_courtier = {
					is_adult = no
					trait_compatibility = { target = scope:your_heir value >= 10 }
				}
			}
			hidden_effect = {
				scope:your_courtier = {
					set_relation_crush = {
						target = scope:your_heir
						reason = crushed_heir_training
					}
				}
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		scope:your_courtier = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Heir goes hunting
lmf_heir.1675 = {
	type = character_event
	title = lmf_heir.1675.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:liege_will_join }
				desc = {
					desc = lmf_heir.1675.desc.invite
					first_valid = {
						triggered_desc = {
							trigger = { scope:hunt_went_well = yes }
							desc = lmf_heir.1675.desc.invite.well
						}
						desc = lmf_heir.1675.desc.invite.poorly
					}
				}
			}
			triggered_desc = {
				trigger = { exists = scope:story.var:heir_in_training }
				desc = {
					desc = lmf_heir.1675.desc.start
					first_valid = {
						triggered_desc = {
							trigger = { scope:hunt_went_well = yes }
							desc = lmf_heir.1675.desc.well
						}
						desc = lmf_heir.1675.desc.poorly
					}
				}
			}
			desc = {
				desc = lmf_heir.1675.desc.notrain
				first_valid = {
					triggered_desc = {
						trigger = { scope:hunt_went_well = yes }
						desc = lmf_heir.1675.desc.notrain.well
					}
					desc = lmf_heir.1675.desc.notrain.poorly
				}
			}
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:hunt_went_well = no }
			animation = hunting_shortbow_rest_arrow_default
		}
		animation = hunting_horn
		outfit_tags = { travel_cloak }
	}
	right_portrait = {
		trigger = { exists = scope:liege_will_join }
		character = root
		triggered_animation = {
			trigger = { scope:hunt_went_well = no }
			animation = disapproval
		}
		animation = laugh
		outfit_tags = { travel_cloak }
	}
	override_background = { reference = wilderness_forest }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# does the liege come along?
		if = {
			limit = {
				exists = scope:story.var:host_will_train
				is_available = yes
				has_recoverable_disease_trigger = no
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:heir_visit_target }
				NOR = {
					has_trait = craven
					has_trait = physique_bad
					has_trait = weak
					has_relation_rival = scope:your_heir
				}
			}
			save_scope_value_as = { name = liege_will_join value = yes }
			no_hat_respectful_effect = yes
		}

		# did the hunt go well?
		random_list = {
			100 = {
				modifier = {
					add = 50
					scope:your_heir = { has_trait = lifestyle_hunter }
				}
				modifier = {
					always = yes
					add = {
						value = scope:your_heir.martial
						subtract = 6
						multiply = 10
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_energy = 1
					ai_boldness = 0.5
				}
				ai_value_modifier = {
					trigger = { exists = scope:liege_will_join }
					who = scope:your_heir
					ai_sociability = 0.5
				}
				min = 10
				save_scope_value_as = { name = hunt_went_well value = yes }
			}
			100 = {
				modifier = {
					always = yes
					add = {
						value = 6
						subtract = scope:your_heir.martial
						multiply = 10
					}
				}
				modifier = {
					factor = 0.5
					scope:your_heir = { has_trait = lifestyle_hunter }
				}
				modifier = {
					factor = 0.5
					exists = scope:liege_will_join
				}
				min = 10
				save_scope_value_as = { name = hunt_went_well value = no }
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_hunt add = 1 }
			set_variable = { name = had_heir_1675_event value = yes }
		}
	}

	option = {
		trigger = {
			scope:hunt_went_well = yes
			exists = scope:liege_will_join
		}
		name = lmf_heir.1675.a
		stress_impact = {
			base = medium_stress_impact_loss
			lifestyle_hunter = minor_stress_impact_loss
			gregarious = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		if = {
			limit = { has_relation_friend = scope:your_heir }
			add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
			reverse_add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
		}
		else = {
			improve_relationship_effect = {
				TARGET = scope:your_heir
				REASON = excellent_hunting_trip
			}
		}
		hidden_effect = {
			create_artifact_animal_trinket_effect = {
				OWNER = root
				HUNTER = root
				LEGENDARY = no
				ANIMAL = flag:none
			}
		}
		scope:your_heir = {
			hidden_effect = {
				stress_impact = {
					base = medium_stress_impact_loss
					lifestyle_hunter = minor_stress_impact_loss
					gregarious = minor_stress_impact_loss
					shy = minor_stress_impact_gain
					paranoid = minor_stress_impact_gain
				}
				create_artifact_animal_trinket_effect = {
					OWNER = scope:your_heir
					HUNTER = scope:your_heir
					LEGENDARY = no
					ANIMAL = flag:none
				}
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 1 }
			change_variable = { name = visit_hunter add = 2 }
		}
	}
	option = {
		trigger = {
			scope:hunt_went_well = yes
			NOT = { exists = scope:liege_will_join }
		}
		name = lmf_heir.1675.b
		scope:your_heir = {
			stress_impact = {
				base = medium_stress_impact_loss
				lifestyle_hunter = minor_stress_impact_loss
				gregarious = minor_stress_impact_loss
				shy = minor_stress_impact_gain
				paranoid = minor_stress_impact_gain
			}
			hidden_effect = {
				create_artifact_animal_trinket_effect = {
					OWNER = scope:your_heir
					HUNTER = scope:your_heir
					LEGENDARY = no
					ANIMAL = flag:none
				}
			}
		}
		scope:story = {
			change_variable = { name = visit_hunter add = 2 }
		}
	}
	option = {
		trigger = {
			scope:hunt_went_well = no
			exists = scope:liege_will_join
		}
		name = lmf_heir.1675.c
		stress_impact = {
			base = medium_stress_impact_gain
			lifestyle_hunter = minor_stress_impact_loss
			patient = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		if = {
			limit = { has_relation_rival = scope:your_heir }
			add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20 }
			reverse_add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20}
		}
		else = {
			worsen_relationship_effect = {
				TARGET = scope:your_heir
				REASON = disastrous_hunting_trip
			}
		}
		scope:your_heir = {
			hidden_effect = {
				stress_impact = {
					base = medium_stress_impact_gain
					lifestyle_hunter = minor_stress_impact_loss
					patient = minor_stress_impact_loss
					impatient = minor_stress_impact_gain
					paranoid = minor_stress_impact_gain
				}
			}
			random = {
				chance = 50
				hunt_wound_select_effect = yes
				hunt_wound_apply_effect = { SEVERE = no }
				hunt_wound_tooltip_effect = yes
			}
		}
		scope:story = {
			change_variable = { name = visit_hunter add = 1 }
		}
	}
	option = {
		trigger = {
			scope:hunt_went_well = no
			NOT = { exists = scope:liege_will_join }
		}
		name = lmf_heir.1675.d
		scope:your_heir = {
			stress_impact = {
				base = medium_stress_impact_gain
				lifestyle_hunter = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				paranoid = minor_stress_impact_gain
			}
			random = {
				chance = 50
				hunt_wound_select_effect = yes
				hunt_wound_apply_effect = { SEVERE = no }
				hunt_wound_tooltip_effect = yes
			}
		}
		scope:story = {
			change_variable = { name = visit_hunter add = 1 }
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		if = {
			limit = { exists = scope:liege_will_join }
			clear_saved_scope = liege_will_join
			remove_no_hat_effect = yes
		}
		clear_saved_scope = hunt_went_well
		advance_heir_timer_effect = yes
	}
}

# Heir tours the countryside
lmf_heir.1676 = {
	type = character_event
	title = lmf_heir.1676.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				NOT = { location = root.capital_province }
			}
			desc = lmf_heir.1666.desc.away
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = no
			}
			desc = lmf_heir.1666.desc.busy
		}
		triggered_desc = {
			trigger = {
				exists = scope:story.var:host_will_train
				location = root.capital_province
				is_available = yes
			}
			desc = lmf_heir.1666.desc.train
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:story.var:host_will_train }
			}
			desc = lmf_heir.1666.desc.notrain
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:story.var:heir_in_training }
				desc = lmf_heir.1676.train
			}
			desc = lmf_heir.1676.notrain
		}
		desc = lmf_heir.1676.desc.begin
		first_valid = {
			triggered_desc = {
				trigger = { scope:tour_went_well = yes }
				desc = lmf_heir.1676.desc.well
			}
			desc = lmf_heir.1676.desc.poorly
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:tour_went_well = no }
			animation = stress
		}
		animation = happiness
		outfit_tags = { travel_cloak }
	}
	override_background = { reference = market }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# did the tour go well?
		random_list = {
			100 = {
				modifier = {
					add = 50
					scope:your_heir = { has_trait = humble }
				}
				modifier = {
					always = yes
					add = {
						value = scope:your_heir.learning
						subtract = 6
						multiply = 10
					}
				}
				modifier = {
					always = yes
					add = {
						value = scope:your_heir.diplomacy
						subtract = 6
						multiply = 5
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_energy = 1
					ai_sociability = 0.5
				}
				min = 10
				save_scope_value_as = { name = tour_went_well value = yes }
			}
			50 = {
				modifier = {
					add = 50
					scope:your_heir = { has_trait = arrogant }
				}
				modifier = {
					always = yes
					add = {
						value = 6
						subtract = scope:your_heir.martial
						multiply = 10
					}
				}
				min = 10
				save_scope_value_as = { name = tour_went_well value = no }
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_tour add = 1 }
			set_variable = { name = had_heir_1676_event value = yes }
		}
	}

	option = {
		trigger = { scope:tour_went_well = yes }
		name = lmf_heir.1676.a
		custom_tooltip = lmf_heir.heir.progress.moderate.tt
		scope:your_heir = {
			stress_impact = {
				base = minor_stress_impact_loss
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				humble = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
				arrogant = minor_stress_impact_gain
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 2 }
			if = {
				limit = { culture_differs_from_heir = { TARGET = scope:target_county } }
				change_variable = { name = visit_language add = 2 }
			}
		}
	}
	option = {
		trigger = { scope:tour_went_well = no }
		name = lmf_heir.1676.b
		custom_tooltip = lmf_heir.heir.progress.minor.tt
		scope:your_heir = {
			stress_impact = {
				base = medium_stress_impact_gain
				diligent = minor_stress_impact_loss
				patient = minor_stress_impact_loss
				humble = minor_stress_impact_loss
				impatient = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
				arrogant = minor_stress_impact_gain
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 1 }
			if = {
				limit = { culture_differs_from_heir = { TARGET = scope:target_county } }
				change_variable = { name = visit_language add = 1 }
			}
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		clear_saved_scope = tour_went_well
		advance_heir_timer_effect = yes
	}
}

# Heir parties it up
lmf_heir.1677 = {
	type = character_event
	title = lmf_heir.1677.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:liege_will_join }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { scope:story.var:visit_time = 1 }
							desc = lmf_heir.1677.desc.none
						}
						triggered_desc = {
							trigger = {
								OR = {
									scope:story.var:visit_time_castle > 0
									scope:story.var:visit_time_target > 0
								}
							}
							desc = lmf_heir.1677.desc.castle
						}
						desc = lmf_heir.1677.desc.away
					}
					desc = lmf_heir.1677.desc.invite
					first_valid = {
						triggered_desc = {
							trigger = { scope:partying_went_well = yes }
							desc = lmf_heir.1677.desc.invite.well
						}
						desc = lmf_heir.1677.desc.invite.poorly
					}
					first_valid = {
						triggered_desc = {
							trigger = { NOT = { exists = scope:your_heir.var:had_recent_sex } }
							desc = lmf_heir.1677.desc.invite.nosex
						}
						triggered_desc = {
							trigger = { scope:your_heir.var:had_recent_sex = flag:female }
							desc = lmf_heir.1677.desc.invite.woman
						}
						desc = lmf_heir.1677.desc.invite.man
					}
					first_valid = {
						triggered_desc = {
							trigger = { scope:partying_went_well = yes }
							desc = lmf_heir.1677.desc.invite.well.end
						}
						desc = lmf_heir.1677.desc.invite.poorly.end
					}
				}
			}
			triggered_desc = {
				trigger = { exists = scope:story.var:heir_in_training }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { scope:story.var:visit_time = 1 }
							desc = lmf_heir.1677.desc.none
						}
						triggered_desc = {
							trigger = {
								OR = {
									scope:story.var:visit_time_castle > 0
									scope:story.var:visit_time_target > 0
								}
							}
							desc = lmf_heir.1677.desc.castle
						}
						desc = lmf_heir.1677.desc.away
					}
					desc = lmf_heir.1677.desc.noinvite
					first_valid = {
						triggered_desc = {
							trigger = { scope:partying_went_well = yes }
							desc = lmf_heir.1677.desc.noinvite.well
						}
						desc = lmf_heir.1677.desc.noinvite.poorly
					}
				}
			}
			desc = {
				desc = lmf_heir.1677.desc.start
				first_valid = {
					triggered_desc = {
						trigger = { scope:partying_went_well = yes }
						desc = lmf_heir.1677.desc.well
					}
					desc = lmf_heir.1677.desc.poorly
				}
			}
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:partying_went_well = no }
			animation = wedding_drunk
		}
		animation = toast_goblet
		outfit_tags = { travel_cloak }
	}
	right_portrait = {
		trigger = { exists = scope:liege_will_join }
		character = root
		triggered_animation = {
			trigger = { scope:partying_went_well = no }
			animation = disgust
		}
		animation = drink_goblet
		outfit_tags = { travel_cloak }
	}
	override_background = { reference = tavern }

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# does the liege come along?
		if = {
			limit = {
				exists = scope:story.var:host_will_train
				is_available = yes
				has_recoverable_disease_trigger = no
				NOR = {
					has_trait = temperate
					has_trait = shy
					has_trait = reclusive
					has_relation_rival = scope:your_heir
				}
			}
			save_scope_value_as = { name = liege_will_join value = yes }
			no_hat_respectful_effect = yes
		}

		# did the partying go well?
		random_list = {
			100 = {
				modifier = {
					add = 50
					scope:your_heir = { has_trait = lustful }
				}
				modifier = {
					add = 50
					scope:your_heir = { has_trait = lifestyle_reveler }
				}
				modifier = {
					always = yes
					add = {
						value = scope:your_heir.diplomacy
						subtract = 6
						multiply = 5
					}
				}
				ai_value_modifier = {
					who = scope:your_heir
					ai_sociability = 1
					ai_energy = 0.5
				}
				min = 10
				save_scope_value_as = { name = partying_went_well value = yes }
			}
			50 = {
				ai_value_modifier = {
					trigger = {
						exists = scope:liege_will_join
						scope:your_heir.ai_rationality < 0
					}
					who = scope:your_heir
					ai_rationality = -0.5
				}
				modifier = {
					add = 50
					scope:your_heir = { has_trait = chaste }
				}
				modifier = {
					factor = 0.5
					scope:your_heir = { has_trait = lifestyle_reveler }
				}
				modifier = {
					factor = 0.5
					exists = scope:liege_will_join
				}
				min = 10
				save_scope_value_as = { name = partying_went_well value = no }
			}
		}

		# does the heir let off steam?
		scope:your_heir = {
			if = {
				limit = {
					is_adult = yes
					OR = {
						has_trait = drunkard
						likely_to_take_lover_trigger = yes
						AND = {
							stress > normal_baseline_stress
							might_cheat_on_every_partner_trigger = yes
						}
					}
					NOR = {
						has_trait = celibate
						has_trait = chaste
						has_sexuality = asexual
						has_variable = had_recent_sex
					}
				}
				random_list = {
					1 = {}
					25 = {
						trigger = {
							is_attracted_to_men = yes
							can_have_children = yes
						}
						if = {
							limit = { scope:partying_went_well = yes }
							create_character = {
								template = lmf_beautiful_local
								gender = male
								location = root.capital_province
								faith = root.capital_province.county.faith
								culture = root.capital_province.county.culture
								save_scope_as = sex_partner
								after_creation = {
									if = {
										limit = { scope:your_heir = { is_male = yes } }
										set_sexuality = homosexual
									}
									else = {
										set_sexuality = heterosexual
									}
								}
							}
						}
						else = {
							create_character = {
								template = lmf_prostitute
								gender = male
								location = root.capital_province
								faith = root.capital_province.county.faith
								culture = root.capital_province.county.culture
								save_scope_as = sex_partner
								after_creation = {
									set_sexuality = bisexual
								}
							}
						}
						hidden_effect = {
							lmf_random_sex_and_possible_stray_effect = { CHARACTER = scope:sex_partner }
						}
					}
					75 = {
						trigger = {
							is_attracted_to_women = yes
							can_have_children = yes
						}
						if = {
							limit = { scope:partying_went_well = yes }
							create_character = {
								template = lmf_beautiful_local
								gender = female
								location = root.capital_province
								faith = root.capital_province.county.faith
								culture = root.capital_province.county.culture
								save_scope_as = sex_partner
								after_creation = {
									if = {
										limit = { scope:your_heir = { is_male = yes } }
										set_sexuality = homosexual
									}
									else = {
										set_sexuality = heterosexual
									}
								}
							}
						}
						else = {
							create_character = {
								template = lmf_prostitute
								gender = female
								location = root.capital_province
								faith = root.capital_province.county.faith
								culture = root.capital_province.county.culture
								save_scope_as = sex_partner
								after_creation = {
									set_sexuality = bisexual
								}
							}
						}
						scope:sex_partner = {
							set_variable = { name = heir_visit value = yes }
							set_variable = { name = story_stray_seed_heir_visit_target value = root }
						}
						hidden_effect = {
							lmf_random_sex_and_possible_stray_effect = { CHARACTER = scope:sex_partner }
						}
					}
				}
			}
		}

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_party add = 1 }
			set_variable = { name = had_heir_1677_event value = yes }
		}
	}

	option = {
		trigger = {
			scope:partying_went_well = yes
			exists = scope:liege_will_join
		}
		name = lmf_heir.1677.a
		add_stress = major_stress_impact_loss
		scope:your_heir = { add_stress = major_stress_impact_loss }
		if = {
			limit = { has_relation_friend = scope:your_heir }
			add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
			reverse_add_opinion = { target = scope:your_heir modifier = friendliness_opinion opinion = 20 }
		}
		else = {
			improve_relationship_effect = {
				TARGET = scope:your_heir
				REASON = excellent_party_with_heir
			}
		}
		scope:story = {
			change_variable = { name = visit_success add = 1 }
			change_variable = { name = visit_reveler add = 2 }
		}
	}
	option = {
		trigger = {
			scope:partying_went_well = yes
			NOT = { exists = scope:liege_will_join }
		}
		name = lmf_heir.1677.b
		scope:your_heir = { add_stress = major_stress_impact_loss }
		scope:story = {
			change_variable = { name = visit_reveler add = 2 }
		}
	}
	option = {
		trigger = {
			scope:partying_went_well = no
			exists = scope:liege_will_join
		}
		name = lmf_heir.1677.c
		add_stress = minor_stress_impact_gain
		scope:your_heir = { add_stress = medium_stress_impact_loss }
		if = {
			limit = { has_relation_rival = scope:your_heir }
			add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20 }
			reverse_add_opinion = { target = scope:your_heir modifier = unfriendly_opinion opinion = -20}
		}
		else = {
			worsen_relationship_effect = {
				TARGET = scope:your_heir
				REASON = disastrous_party_with_heir
			}
		}
		scope:story = {
			change_variable = { name = visit_reveler add = 1 }
		}
	}
	option = {
		trigger = {
			scope:partying_went_well = no
			NOT = { exists = scope:liege_will_join }
		}
		name = lmf_heir.1677.d
		scope:your_heir = { add_stress = medium_stress_impact_loss }
		scope:story = {
			change_variable = { name = visit_reveler add = 1 }
		}
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		if = {
			limit = { exists = scope:liege_will_join }
			clear_saved_scope = liege_will_join
			remove_no_hat_effect = yes
		}
		clear_saved_scope = partying_went_well
		advance_heir_timer_effect = yes

		# make the peasant woman disappear if she's not pregnant after all
		hidden_effect = {
			if = {
				limit = {
					exists = scope:sex_partner
					NOR = {
						scope:sex_partner = { any_owned_story = { type = lmf_stray_seed_story_cycle } }
						scope:sex_partner = { is_pregnant = yes }
						scope:your_heir = { any_owned_story = { type = story_peasant_affair } }
						scope:your_heir = { is_pregnant = yes }
					}
				}
				scope:sex_partner = {
					death = { death_reason = death_vanished }
				}
			}
		}
	}
}

# Heir does nothing at all
lmf_heir.1678 = {
	type = character_event
	title = lmf_heir.1678.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:story.var:heir_in_training
					scope:story.var:visit_time_nothing = 1
				}
				desc = lmf_heir.1678.desc.one
			}
			triggered_desc = {
				trigger = {
					exists = scope:story.var:heir_in_training
					scope:story.var:visit_time_nothing = 2
				}
				desc = lmf_heir.1678.desc.two
			}
			desc = lmf_heir.1678.desc.all
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:story.var:heir_in_training }
				desc = lmf_heir.1678.desc.castle
			}
			desc = lmf_heir.1678.desc.town
		}
		desc = lmf_heir.1678.desc.end
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		animation = boredom
	}
	override_background = {
		trigger = { exists = scope:story.var:heir_in_training }
		reference = bedchamber
	}
	override_background = {
		trigger = { exists = scope:story.var:heir_on_their_own }
		reference = market
	}

	immediate = {
		scope:your_heir = { no_hat_respectful_effect = yes }

		# increment story variables
		scope:story = {
			change_variable = { name = visit_time_nothing add = 1 }
			set_variable = { name = had_heir_1678_event value = yes }
		}
	}

	option = {
		name = lmf_heir.1678.a
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		advance_heir_timer_effect = yes
	}
}

# Final night's dinner/farewell
lmf_heir.1680 = {
	type = character_event
	title = lmf_heir.1680.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:story.var:heir_on_their_own }
				desc = {
					desc = lmf_heir.1680.desc.notrain
					first_valid = {
						triggered_desc = {
							trigger = {
								OR = {
									is_imprisoned = yes
									NOT = { location = root.capital_province }
								}
							}
							desc = lmf_heir.1680.desc.notrain.away
						}
						triggered_desc = {
							trigger = { has_recoverable_disease_trigger = yes }
							desc = lmf_heir.1680.desc.notrain.ill
						}
						triggered_desc = {
							trigger = { is_available = no }
							desc = lmf_heir.1680.desc.notrain.busy
						}
						desc = lmf_heir.1680.desc.notrain.meet
					}
					triggered_desc = {
						trigger = {
							OR = {
								is_available = no
								has_recoverable_disease_trigger = yes
								NOT = { location = root.capital_province }
							}
						}
						desc = lmf_heir.1680.desc.notrain.nomeet.end
					}
				}
			}
			desc = {
				desc = lmf_heir.1680.desc.train
				first_valid = {
					triggered_desc = {
						trigger = {
							OR = {
								is_imprisoned = yes
								NOT = { location = root.capital_province }
							}
						}
						desc = lmf_heir.1680.desc.train.away
					}
					triggered_desc = {
						trigger = { has_recoverable_disease_trigger = yes }
						desc = lmf_heir.1680.desc.train.ill
					}
					triggered_desc = {
						trigger = { is_available = no }
						desc = lmf_heir.1680.desc.train.busy
					}
					triggered_desc = {
						trigger = { has_relation_rival = scope:your_heir }
						desc = lmf_heir.1680.desc.train.meet.enemy
					}
					triggered_desc = {
						trigger = {
							OR = {
								has_relation_friend = scope:your_heir
								has_relation_lover = scope:your_heir
								reverse_has_opinion_modifier = { modifier = tryst_opinion target = scope:your_heir }
							}
						}
						desc = lmf_heir.1680.desc.train.meet.friend
					}
					desc = lmf_heir.1680.desc.train.meet.neutral
				}
				first_valid = {
					triggered_desc = {
						trigger = { scope:story.var:visit_success > 4 }
						desc = lmf_heir.1680.desc.train.success
					}
					triggered_desc = {
						trigger = { scope:story.var:visit_success < 1 }
						desc = lmf_heir.1680.desc.train.failure
					}
					desc = lmf_heir.1680.desc.train.neutral
				}
				desc = lmf_heir.1680.desc.train.end
			}
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:story.var:visit_success < 1 }
			animation = shame
		}
		triggered_animation = {
			trigger = { scope:story.var:visit_success > 4 }
			animation = happiness
		}
		animation = throne_room_bow_2
		triggered_outfit = {
			trigger = { exists = scope:story.var:heir_on_their_own }
			remove_default_outfit = no
			outfit_tags = { travel_cloak }
		}
	}
	right_portrait = {
		trigger = {
			is_available = yes
			has_recoverable_disease_trigger = no
			location = root.capital_province
		}
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_relation_lover = scope:your_heir
					reverse_has_opinion_modifier = { modifier = tryst_opinion target = scope:your_heir }
				}
			}
			animation = interested
		}
		triggered_animation = {
			trigger = { has_relation_rival = scope:your_heir }
			animation = dismissal
		}
		triggered_animation = {
			trigger = { has_relation_friend = scope:your_heir }
			animation = admiration
		}
		triggered_animation = {
			trigger = { scope:story.var:visit_success < 1 }
			animation = disgust
		}
		animation = throne_room_conversation_4
	}
	override_background = {
		trigger = { exists = scope:story.var:heir_in_training }
		reference = feast
	}
	override_background = {
		trigger = { exists = scope:story.var:heir_on_their_own }
		reference = courtyard
	}

	immediate = {
		scope:your_heir = {
			save_scope_as = bg_override_char
			no_hat_respectful_effect = yes
		}
	}

	option = {
		name = {
			trigger = {
				OR = {
					has_relation_lover = scope:your_heir
					reverse_has_opinion_modifier = { modifier = tryst_opinion target = scope:your_heir }
				}
			}
			text = lmf_heir.1680.a
		}
		name = {
			trigger = { has_relation_rival = scope:your_heir }
			text = lmf_heir.1680.b
		}
		name = {
			trigger = { has_relation_friend = scope:your_heir }
			text = lmf_heir.1680.c
		}
		name = {
			trigger = { scope:story.var:visit_success > 4 }
			text = lmf_heir.1680.d
		}
		name = {
			trigger = { scope:story.var:visit_success < 1 }
			text = lmf_heir.1680.e
		}
		name = {
			trigger = {
				scope:story.var:visit_success > 0
				scope:story.var:visit_success < 5
			}
			text = lmf_heir.1680.f
		}
		custom_tooltip = lmf_heir.1680.end.tt
	}

	after = {
		scope:your_heir = { remove_no_hat_effect = yes }
		if = {
			limit = {
				scope:heir_liege = {
					is_alive = yes
					is_ruler = yes
				}
			}
			scope:heir_liege = { trigger_event = lmf_heir.1681 }
		}
		else = {
			scope:your_heir = {
				current_travel_plan ?= { resume_travel_plan = yes }
			}
			scope:story = { end_story = yes }
		}
	}
}

# Heir's liege informed of return
lmf_heir.1681 = {
	type = character_event
	title = lmf_heir.1680.t
	desc = {
		desc = lmf_heir.1681.desc.start
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:story.var:heir_on_their_own }
				desc = {
					desc = lmf_heir.1681.desc.notrain
					first_valid = {
						triggered_desc = {
							trigger = {
								scope:story.var:visit_time_hunt > 0
								scope:story.var:visit_hunter > 1
							}
							desc = lmf_heir.1681.desc.notrain.hunt.good
						}
						triggered_desc = {
							trigger = { scope:story.var:visit_time_hunt > 0 }
							desc = lmf_heir.1681.desc.notrain.hunt.poor
						}
						triggered_desc = {
							trigger = {
								scope:story.var:visit_time_tour > 0
								scope:story.var:visit_success > 1
							}
							desc = lmf_heir.1681.desc.notrain.tour.good
						}
						triggered_desc = {
							trigger = { scope:story.var:visit_time_tour > 0 }
							desc = lmf_heir.1681.desc.notrain.tour.poor
						}
						triggered_desc = {
							trigger = {
								scope:story.var:visit_time_party > 0
								scope:story.var:visit_reveler > 1
							}
							desc = lmf_heir.1681.desc.notrain.party.good
						}
						triggered_desc = {
							trigger = { scope:story.var:visit_time_party > 0 }
							desc = lmf_heir.1681.desc.notrain.party.poor
						}
						triggered_desc = {
							trigger = { scope:story.var:visit_time_sick > 0 }
							desc = lmf_heir.1681.desc.notrain.sick
						}
						desc = lmf_heir.1681.desc.notrain.nothing
					}
					desc = lmf_heir.1681.desc.notrain.end
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:story.var:host_will_train }
						desc = lmf_heir.1681.desc.train
					}
					desc = lmf_heir.1681.desc.train.castle
				}
				first_valid = {
					triggered_desc = {
						trigger = {
							NOR = {
								exists = scope:second_visit_item
								exists = scope:third_visit_item
							}
						}
						desc = {
							desc = lmf_heir.1681.desc.train.all
							first_valid = {
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:host }
									desc = lmf_heir.1681.desc.host
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:castle }
									desc = lmf_heir.1681.desc.castle
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:hunt }
									desc = lmf_heir.1681.desc.hunt
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:tour }
									desc = lmf_heir.1681.desc.tour
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:party }
									desc = lmf_heir.1681.desc.party
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:sick }
									desc = lmf_heir.1681.desc.sick
								}
								desc = lmf_heir.1681.desc.nothing
							}
						}
					}
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:third_visit_item }
						}
						desc = {
							desc = lmf_heir.1681.desc.train.most
							first_valid = {
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:host }
									desc = lmf_heir.1681.desc.host
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:castle }
									desc = lmf_heir.1681.desc.castle
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:hunt }
									desc = lmf_heir.1681.desc.hunt
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:tour }
									desc = lmf_heir.1681.desc.tour
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:party }
									desc = lmf_heir.1681.desc.party
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:sick }
									desc = lmf_heir.1681.desc.sick
								}
								triggered_desc = {
									trigger = { scope:first_visit_item = flag:nothing }
									desc = lmf_heir.1681.desc.nothing
								}
							}
							desc = lmf_heir.1681.desc.train.rest
							first_valid = {
								triggered_desc = {
									trigger = { scope:second_visit_item = flag:host }
									desc = lmf_heir.1681.desc.host
								}
								triggered_desc = {
									trigger = { scope:second_visit_item = flag:castle }
									desc = lmf_heir.1681.desc.castle
								}
								triggered_desc = {
									trigger = { scope:second_visit_item = flag:hunt }
									desc = lmf_heir.1681.desc.hunt
								}
								triggered_desc = {
									trigger = { scope:second_visit_item = flag:tour }
									desc = lmf_heir.1681.desc.tour
								}
								triggered_desc = {
									trigger = { scope:second_visit_item = flag:party }
									desc = lmf_heir.1681.desc.party
								}
								triggered_desc = {
									trigger = { scope:second_visit_item = flag:sick }
									desc = lmf_heir.1681.desc.sick
								}
								triggered_desc = {
									trigger = { scope:second_visit_item = flag:nothing }
									desc = lmf_heir.1681.desc.nothing
								}
							}
						}
					}
					desc = {
						desc = lmf_heir.1681.desc.train.some
						first_valid = {
							triggered_desc = {
								trigger = { scope:first_visit_item = flag:host }
								desc = lmf_heir.1681.desc.host
							}
							triggered_desc = {
								trigger = { scope:first_visit_item = flag:castle }
								desc = lmf_heir.1681.desc.castle
							}
							triggered_desc = {
								trigger = { scope:first_visit_item = flag:hunt }
								desc = lmf_heir.1681.desc.hunt
							}
							triggered_desc = {
								trigger = { scope:first_visit_item = flag:tour }
								desc = lmf_heir.1681.desc.tour
							}
							triggered_desc = {
								trigger = { scope:first_visit_item = flag:party }
								desc = lmf_heir.1681.desc.party
							}
							triggered_desc = {
								trigger = { scope:first_visit_item = flag:sick }
								desc = lmf_heir.1681.desc.sick
							}
							triggered_desc = {
								trigger = { scope:first_visit_item = flag:nothing }
								desc = lmf_heir.1681.desc.nothing
							}
						}
						desc = lmf_heir.1681.desc.train.second
						first_valid = {
							triggered_desc = {
								trigger = { scope:second_visit_item = flag:host }
								desc = lmf_heir.1681.desc.host
							}
							triggered_desc = {
								trigger = { scope:second_visit_item = flag:castle }
								desc = lmf_heir.1681.desc.castle
							}
							triggered_desc = {
								trigger = { scope:second_visit_item = flag:hunt }
								desc = lmf_heir.1681.desc.hunt
							}
							triggered_desc = {
								trigger = { scope:second_visit_item = flag:tour }
								desc = lmf_heir.1681.desc.tour
							}
							triggered_desc = {
								trigger = { scope:second_visit_item = flag:party }
								desc = lmf_heir.1681.desc.party
							}
							triggered_desc = {
								trigger = { scope:second_visit_item = flag:sick }
								desc = lmf_heir.1681.desc.sick
							}
							triggered_desc = {
								trigger = { scope:second_visit_item = flag:nothing }
								desc = lmf_heir.1681.desc.nothing
							}
						}
						desc = lmf_heir.1681.desc.train.third
						first_valid = {
							triggered_desc = {
								trigger = { scope:third_visit_item = flag:host }
								desc = lmf_heir.1681.desc.host
							}
							triggered_desc = {
								trigger = { scope:third_visit_item = flag:castle }
								desc = lmf_heir.1681.desc.castle
							}
							triggered_desc = {
								trigger = { scope:third_visit_item = flag:hunt }
								desc = lmf_heir.1681.desc.hunt
							}
							triggered_desc = {
								trigger = { scope:third_visit_item = flag:tour }
								desc = lmf_heir.1681.desc.tour
							}
							triggered_desc = {
								trigger = { scope:third_visit_item = flag:party }
								desc = lmf_heir.1681.desc.party
							}
							triggered_desc = {
								trigger = { scope:third_visit_item = flag:sick }
								desc = lmf_heir.1681.desc.sick
							}
							triggered_desc = {
								trigger = { scope:third_visit_item = flag:nothing }
								desc = lmf_heir.1681.desc.nothing
							}
						}
					}
				}
				first_valid = {
					triggered_desc = {
						trigger = { scope:story.var:visit_success > 4 }
						desc = lmf_heir.1681.desc.train.good
					}
					triggered_desc = {
						trigger = { scope:story.var:visit_success < 1 }
						desc = lmf_heir.1681.desc.train.poor
					}
					desc = lmf_heir.1681.desc.train.neutral
				}
			}
		}
	}
	theme = realm

	left_portrait = {
		character = scope:your_heir
		triggered_animation = {
			trigger = { scope:story.var:visit_success < 1 }
			animation = shame
		}
		triggered_animation = {
			trigger = { scope:story.var:visit_success > 4 }
			animation = happiness
		}
		outfit_tags = { travel_cloak }
	}
	override_background = { reference = terrain_scope }

	immediate = {
		scope:heir_visit_target.capital_province = { save_scope_as = background_terrain_scope }

		# for the localization
		if = {
			limit = { scope:story.var:visit_time_target > 1 }
			record_visit_item_effect = { ITEM = host }
		}
		if = {
			limit = { scope:story.var:visit_time_castle > 1 }
			record_visit_item_effect = { ITEM = castle }
		}
		if = {
			limit = { scope:story.var:visit_time_hunt > 1 }
			record_visit_item_effect = { ITEM = hunt }
		}
		if = {
			limit = { scope:story.var:visit_time_tour > 1 }
			record_visit_item_effect = { ITEM = tour }
		}
		if = {
			limit = { scope:story.var:visit_time_party > 1 }
			record_visit_item_effect = { ITEM = party }
		}
		if = {
			limit = { scope:story.var:visit_time_sick > 1 }
			record_visit_item_effect = { ITEM = sick }
		}
		if = {
			limit = { scope:story.var:visit_time_nothing > 1 }
			record_visit_item_effect = { ITEM = nothing }
		}
		if = {
			limit = { scope:story.var:visit_time_castle = 1 }
			record_visit_item_effect = { ITEM = castle }
		}
		if = {
			limit = { scope:story.var:visit_time_hunt = 1 }
			record_visit_item_effect = { ITEM = hunt }
		}
		if = {
			limit = { scope:story.var:visit_time_tour = 1 }
			record_visit_item_effect = { ITEM = tour }
		}
		if = {
			limit = { scope:story.var:visit_time_party = 1 }
			record_visit_item_effect = { ITEM = party }
		}
		if = {
			limit = { scope:story.var:visit_time_target = 1 }
			record_visit_item_effect = { ITEM = host }
		}
		if = {
			limit = { scope:story.var:visit_time_sick = 1 }
			record_visit_item_effect = { ITEM = sick }
		}
		if = {
			limit = { scope:story.var:visit_time_nothing = 1 }
			record_visit_item_effect = { ITEM = nothing }
		}
	}

	option = {
		name = lmf_heir.1681.a
		custom_tooltip = lmf_heir.1680.end.tt
		scope:your_heir = { heir_learns_from_visit_effect = yes }
		if = {
			limit = {
				is_ai = yes
				exists = scope:story.var:heir_on_their_own
			}
			add_opinion = { target = scope:heir_visit_target modifier = disrespect_opinion opinion = -10 }
		}
	}

	after = {
		scope:your_heir.current_travel_plan ?= {
			if = {
				limit = { is_paused = yes }
				hidden_effect = { resume_travel_plan = yes }
			}
		}
		scope:story = { end_story = yes }
	}
}

# Product of a night of revelry shows up months/years later
lmf_heir.1700 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:bastard_child_father = scope:bastard_child_father_liege }
				desc = lmf_heir.1700.own.t
			}
			triggered_desc = {
				trigger = { scope:bastard_child_father = { is_child_of = root } }
				desc = lmf_heir.1700.son.t
			}
			desc = lmf_heir.1700.relative.t
		}
	}
	desc = {
		first_valid = {
			# adult bastard shows up alone
			triggered_desc = {
				trigger = { scope:bastard_child = scope:visitor }
				desc = {
					first_valid = {
						# father is the ruler
						triggered_desc = {
							trigger = { scope:bastard_child_father = scope:bastard_child_father_liege }
							desc = {
								desc = lmf_heir.1700.bastard.me.start
								first_valid = {
									triggered_desc = {
										trigger = { exists = scope:story.var:heir_visit }
										desc = lmf_heir.1700.bastard.me.heirvisit
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_camp_follower }
										desc = lmf_heir.1700.bastard.me.campfollower
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_tavern_girl }
										desc = lmf_heir.1700.bastard.me.taverngirl
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_lost_guide }
										desc = lmf_heir.1700.bastard.me.lostguide
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_camp_caught_eye }
										desc = lmf_heir.1700.bastard.me.campcaughteye
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_found_pool }
										desc = lmf_heir.1700.bastard.me.foundpool
									}
									desc = lmf_heir.1700.bastard.me.default
								}
								desc = lmf_heir.1700.bastard.me.end
							}
						}
						# father is alive
						triggered_desc = {
							trigger = { scope:bastard_child_father = { is_alive = yes } }
							desc = {
								desc = lmf_heir.1700.bastard.alive.start
								first_valid = {
									triggered_desc = {
										trigger = { exists = scope:story.var:heir_visit }
										desc = lmf_heir.1700.bastard.alive.heirvisit
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_camp_follower }
										desc = lmf_heir.1700.bastard.alive.campfollower
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_tavern_girl }
										desc = lmf_heir.1700.bastard.alive.taverngirl
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_lost_guide }
										desc = lmf_heir.1700.bastard.alive.lostguide
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_camp_caught_eye }
										desc = lmf_heir.1700.bastard.alive.campcaughteye
									}
									triggered_desc = {
										trigger = { exists = scope:story.var:army_found_pool }
										desc = lmf_heir.1700.bastard.alive.foundpool
									}
									desc = lmf_heir.1700.bastard.alive.default
								}
								desc = lmf_heir.1700.bastard.alive.end
							}
						}
						# father is dead
						desc = {
							desc = lmf_heir.1700.bastard.dead.start
							first_valid = {
								triggered_desc = {
									trigger = { exists = story_owner.var:heir_visit }
									desc = lmf_heir.1700.bastard.dead.heirvisit
								}
								triggered_desc = {
									trigger = { exists = story_owner.var:army_camp_follower }
									desc = lmf_heir.1700.bastard.dead.campfollower
								}
								triggered_desc = {
									trigger = { exists = story_owner.var:army_tavern_girl }
									desc = lmf_heir.1700.bastard.dead.taverngirl
								}
								triggered_desc = {
									trigger = { exists = story_owner.var:army_lost_guide }
									desc = lmf_heir.1700.bastard.dead.lostguide
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_camp_caught_eye }
									desc = lmf_heir.1700.bastard.dead.campcaughteye
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_found_pool }
									desc = lmf_heir.1700.bastard.dead.foundpool
								}
								desc = lmf_heir.1700.bastard.dead.default
							}
							desc = lmf_heir.1700.bastard.dead.end
						}
					}
				}
			}
			# mother shows up with bastard child
			desc = {
				first_valid = {
					# father is the ruler
					triggered_desc = {
						trigger = { scope:bastard_child_father = scope:bastard_child_father_liege }
						desc = {
							desc = lmf_heir.1700.mother.me.start
							first_valid = {
								triggered_desc = {
									trigger = { exists = scope:story.var:heir_visit }
									desc = lmf_heir.1700.mother.me.heirvisit
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_camp_follower }
									desc = lmf_heir.1700.mother.me.campfollower
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_tavern_girl }
									desc = lmf_heir.1700.mother.me.taverngirl
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_lost_guide }
									desc = lmf_heir.1700.mother.me.lostguide
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_camp_caught_eye }
									desc = lmf_heir.1700.mother.me.campcaughteye
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_found_pool }
									desc = lmf_heir.1700.mother.me.foundpool
								}
								desc = lmf_heir.1700.mother.me.default
							}
							desc = lmf_heir.1700.mother.me.mid
							first_valid = {
								triggered_desc = {
									trigger = { scope:bastard_child.age < 1 }
									desc = lmf_heir.1700.mother.me.newborn
								}
								desc = lmf_heir.1700.mother.me.child
							}
							desc = lmf_heir.1700.mother.me.end
						}
					}
					# father is alive
					triggered_desc = {
						trigger = { scope:bastard_child_father = { is_alive = yes } }
						desc = {
							desc = lmf_heir.1700.mother.alive.start
							first_valid = {
								triggered_desc = {
									trigger = { exists = scope:story.var:heir_visit }
									desc = lmf_heir.1700.mother.alive.heirvisit
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_camp_follower }
									desc = lmf_heir.1700.mother.alive.campfollower
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_tavern_girl }
									desc = lmf_heir.1700.mother.alive.taverngirl
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_lost_guide }
									desc = lmf_heir.1700.mother.alive.lostguide
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_camp_caught_eye }
									desc = lmf_heir.1700.mother.alive.campcaughteye
								}
								triggered_desc = {
									trigger = { exists = scope:story.var:army_found_pool }
									desc = lmf_heir.1700.mother.alive.foundpool
								}
								desc = lmf_heir.1700.mother.alive.default
							}
							desc = lmf_heir.1700.mother.alive.mid
							first_valid = {
								triggered_desc = {
									trigger = { scope:bastard_child.age < 1 }
									desc = lmf_heir.1700.mother.alive.newborn
								}
								desc = lmf_heir.1700.mother.alive.child
							}
							desc = lmf_heir.1700.mother.alive.end
						}
					}
					# father is dead
					desc = {
						desc = lmf_heir.1700.mother.dead.start
						first_valid = {
							triggered_desc = {
								trigger = { exists = scope:story.var:heir_visit }
								desc = lmf_heir.1700.mother.dead.heirvisit
							}
							triggered_desc = {
								trigger = { exists = scope:story.var:army_camp_follower }
								desc = lmf_heir.1700.mother.dead.campfollower
							}
							triggered_desc = {
								trigger = { exists = scope:story.var:army_tavern_girl }
								desc = lmf_heir.1700.mother.dead.taverngirl
							}
							triggered_desc = {
								trigger = { exists = scope:story.var:army_lost_guide }
								desc = lmf_heir.1700.mother.dead.lostguide
							}
							triggered_desc = {
								trigger = { exists = scope:story.var:army_camp_caught_eye }
								desc = lmf_heir.1700.mother.dead.campcaughteye
							}
							triggered_desc = {
								trigger = { exists = scope:story.var:army_found_pool }
								desc = lmf_heir.1700.mother.dead.foundpool
							}
							desc = lmf_heir.1700.mother.dead.default
						}
						desc = lmf_heir.1700.mother.dead.mid
						first_valid = {
							triggered_desc = {
								trigger = { scope:bastard_child.age < 1 }
								desc = lmf_heir.1700.mother.dead.newborn
							}
							desc = lmf_heir.1700.mother.dead.child
						}
						desc = lmf_heir.1700.mother.dead.end
					}
				}
			}
		}
	}
	theme = bastardy

	left_portrait = {
		character = scope:greeter
		triggered_animation = {
			trigger = { scope:greeter = scope:bastard_child_father }
			animation = shame
		}
		animation = thinking
	}
	right_portrait = {
		character = scope:visitor
		triggered_animation = {
			trigger = {
				NOT = { scope:visitor = scope:bastard_child }
				scope:bastard_child.age < 1
			}
			animation = newborn
		}
		animation = throne_room_bow_1
	}
	lower_right_portrait = {
		trigger = {
			NOT = { scope:visitor = scope:bastard_child }
		}
		character = scope:bastard_child
	}
	lower_left_portrait = {
		trigger = {
			scope:bastard_child_father = { is_alive = no }
		}
		character = scope:bastard_child_father
	}
	override_background = { reference = courtyard }

	immediate = {
		# move mother and child to capital, leaving their old court if need be
		scope:visitor = {
			hidden_effect = {
				add_character_flag = no_hat
				if = {
					limit = { is_courtier = yes }
					scope:visitor.liege = { remove_courtier_or_guest = scope:visitor }
				}
				move_to_pool_at = scope:bastard_child_father_liege.capital_province
				set_variable = { name = last_visited_ruler value = scope:bastard_child_father_liege days = 1825 }
			}
		}
		if = {
			limit = {
				NOT = { scope:bastard_child = scope:visitor }
			}
			scope:bastard_child = {
				hidden_effect = {
					add_character_flag = no_hat
					if = {
						limit = { is_courtier = yes }
						scope:bastard_child.liege = { remove_courtier_or_guest = scope:bastard_child }
					}
					move_to_pool_at = scope:bastard_child_father_liege.capital_province
					set_variable = { name = last_visited_ruler value = scope:bastard_child_father_liege days = 1825 }
				}
			}
		}
		# grab secret
		scope:visitor = {
			random_secret = {
				type = secret_unmarried_illegitimate_child
				limit = { secret_target = scope:bastard_child }
				save_scope_as = bastard_secret
			}
		}
		# setting whose portrait will appear, greeting the visitor
		if = {
			limit = { scope:bastard_child_father = { is_alive = yes } }
			scope:bastard_child_father = {
				save_scope_as = greeter
				add_character_flag = had_stray_seed_story_cycle
			}
		}
		else = {
			root = { save_scope_as = greeter }
		}
		# set a flag so this can't happen too often
		add_character_flag = { flag = had_recent_bastard_appearance years = 5 }
	}

	option = {
		name = lmf_heir.1700.a #they can stay
		scope:bastard_secret = {
			if = {
				limit = { scope:bastard_child_father = { is_alive = yes } }
				reveal_to_without_events_effect = { CHARACTER = scope:bastard_child_father }
			}
			if = {
				limit = {
					NOT = { scope:bastard_child_father = scope:bastard_child_father_liege }
				}
				reveal_to_without_events_effect = { CHARACTER = scope:bastard_child_father_liege }
			}
		}
		add_courtier = scope:visitor
		hidden_effect = {
			consume_all_criminal_reasons_effect = {
				LIEGE = root
				CRIMINAL = scope:visitor
			}
		}
		if = {
			limit = { NOT = { scope:visitor = scope:bastard_child } }
			add_courtier = scope:bastard_child
		}
		scope:visitor = {
			add_character_flag = { flag = will_not_leave years = 20 }
			add_opinion = {
				modifier = kindness_opinion
				target = root
				opinion = 20
			}
		}
		if = {
			limit = { NOT = { scope:visitor = scope:bastard_child } }
			scope:bastard_child = {
				add_character_flag = { flag = will_not_leave years = 20 }
				add_opinion = {
					modifier = kindness_opinion
					target = root
					opinion = 20
				}
			}
		}
		if = {
			limit = {
				scope:bastard_child_father = root
				is_married = no
			}
			stress_impact = {
				base = minor_stress_impact_gain
				compassionate = medium_stress_impact_loss
				just = medium_stress_impact_loss
				chaste = minor_stress_impact_gain
			}
		}
		else_if = {
			limit = { scope:bastard_child_father = root }
			stress_impact = {
				base = medium_stress_impact_gain
				compassionate = medium_stress_impact_loss
				just = medium_stress_impact_loss
				chaste = medium_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				compassionate = medium_stress_impact_loss
				just = medium_stress_impact_loss
				zealous = minor_stress_impact_gain
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 1.0
				ai_zeal = -0.2
			}
			modifier = {
				add = 20
				scope:bastard_child_father = root
				is_married = no
			}
			modifier = {
				add = 20
				scope:bastard_child_father = {
					NOT = { this = root }
					is_alive = yes
					is_married = no
				}
			}
			opinion_modifier = {
				trigger = {
					exists = primary_spouse
					scope:bastard_child_father = root
				}
				who = root
				opinion_target = primary_spouse
				multiplier = -0.2
				step = 5
			}
			opinion_modifier = {
				trigger = {
					scope:bastard_child_father = {
						NOT = { this = root }
						is_alive = yes
					}
				}
				who = root
				opinion_target = scope:bastard_child_father
				multiplier = -0.2
				step = 5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:visitor
				multiplier = 0.7
				step = 5
			}
			modifier = {
				add = 10
				OR = {
					has_trait = lustful
					has_trait = callous
					has_trait = fickle
					has_trait = compassionate
				}
			}
		}
	}
	option = {
		name = lmf_heir.1700.b #takes responsibility for child
		if = {
			limit = { exists = scope:bastard_secret }
			scope:bastard_secret = { expose_secret = root }
		}
		add_courtier = scope:visitor
		hidden_effect = {
			consume_all_criminal_reasons_effect = {
				LIEGE = root
				CRIMINAL = scope:visitor
			}
		}
		if = {
			limit = { NOT = { scope:visitor = scope:bastard_child } }
			add_courtier = scope:bastard_child
		}
		scope:visitor = {
			add_character_flag = { flag = will_not_leave years = 20 }
			add_opinion = {
				modifier = kindness_opinion
				target = root
				opinion = 40
			}
		}
		if = {
			limit = { NOT = { scope:visitor = scope:bastard_child } }
			scope:bastard_child = {
				add_character_flag = { flag = will_not_leave years = 20 }
				add_opinion = {
					modifier = kindness_opinion
					target = root
					opinion = 40
				}
			}
		}
		if = {
			limit = {
				scope:bastard_child_father = root
				is_married = no
			}
			stress_impact = {
				base = medium_stress_impact_gain
				compassionate = medium_stress_impact_loss
				lustful = minor_stress_impact_loss
				just = medium_stress_impact_loss
				chaste = medium_stress_impact_gain
			}
		}
		else_if = {
			limit = { scope:bastard_child_father = root }
			stress_impact = {
				base = major_stress_impact_gain
				compassionate = medium_stress_impact_loss
				lustful = minor_stress_impact_loss
				just = medium_stress_impact_loss
				chaste = medium_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				base = minor_stress_impact_gain
				compassionate = medium_stress_impact_loss
				just = medium_stress_impact_loss
				zealous = medium_stress_impact_gain
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 0.5
				ai_zeal = -0.2
			}
			modifier = {
				add = 20
				scope:bastard_child_father = root
				is_married = no
			}
			modifier = {
				add = 20
				scope:bastard_child_father = {
					NOT = { this = root }
					is_alive = yes
					is_married = no
				}
			}
			opinion_modifier = {
				trigger = {
					exists = primary_spouse
					scope:bastard_child_father = root
				}
				who = root
				opinion_target = primary_spouse
				multiplier = -0.5
				step = 5
			}
			opinion_modifier = {
				trigger = {
					scope:bastard_child_father = {
						NOT = { this = root }
						is_alive = yes
					}
				}
				who = root
				opinion_target = scope:bastard_child_father
				multiplier = -0.5
				step = 5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:visitor
				multiplier = 0.7
				step = 5
			}
			modifier = {
				add = 10
				OR = {
					has_trait = lustful
					has_trait = callous
					has_trait = fickle
					has_trait = compassionate
				}
			}
		}
	}
	option = {
		name = lmf_heir.1700.c #get rid of them
		scope:bastard_secret = {
			if = {
				limit = { scope:bastard_child_father = { is_alive = yes } }
				reveal_to = scope:bastard_child_father
			}
			if = {
				limit = {
					NOT = { scope:bastard_child_father = scope:bastard_child_father_liege }
				}
				reveal_to = scope:bastard_child_father_liege
			}
		}
		scope:visitor = {
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -40
			}
		}
		if = {
			limit = { NOT = { scope:visitor = scope:bastard_child } }
			scope:bastard_child = {
				add_opinion = {
					modifier = refusal_opinion
					target = root
					opinion = -40
				}
			}
		}
		if = {
			limit = {
				scope:bastard_child_father = root
				is_married = no
			}
			stress_impact = {
				compassionate = medium_stress_impact_gain
				lustful = medium_stress_impact_gain
				just = medium_stress_impact_gain
				chaste = medium_stress_impact_loss
			}
		}
		else_if = {
			limit = { scope:bastard_child_father = root }
			stress_impact = {
				base = medium_stress_impact_gain
				compassionate = medium_stress_impact_gain
				honest = medium_stress_impact_gain
				lustful = minor_stress_impact_gain
				just = medium_stress_impact_gain
				chaste = minor_stress_impact_loss
				deceitful = minor_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				base = minor_stress_impact_loss
				compassionate = medium_stress_impact_gain
				just = medium_stress_impact_gain
				zealous = medium_stress_impact_loss
				callous = minor_stress_impact_loss
				sadistic = minor_stress_impact_loss
				arbitrary = minor_stress_impact_loss
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
				ai_compassion = -0.5
				ai_zeal = 0.5
			}
			opinion_modifier = {
				trigger = {
					exists = primary_spouse
					scope:bastard_child_father = root
				}
				who = root
				opinion_target = primary_spouse
				multiplier = 0.5
				step = 5
			}
			opinion_modifier = {
				trigger = {
					scope:bastard_child_father = {
						NOT = { this = root }
						is_alive = yes
					}
				}
				who = root
				opinion_target = scope:bastard_child_father
				multiplier = 0.5
				step = 5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:visitor
				multiplier = -0.5
				step = 5
			}
			modifier = {
				add = 10
				has_trait = chaste
			}
		}
	}

	after = {
		scope:visitor = { remove_no_hat_effect = yes }
		scope:bastard_child = { remove_no_hat_effect = yes }
		scope:story = { end_story = yes }
	}
}


####################
# BETROTHAL EVENTS #
####################

scripted_trigger lmf_check_existing_objections = {
	NAND = {
		exists = scope:objection_1
		OR = {
			scope:objection_1 = flag:$OBJECTION$
			scope:objection_1 = flag:fallthrough
		}
	}
	NAND = {
		exists = scope:objection_2
		OR = {
			scope:objection_2 = flag:$OBJECTION$
			scope:objection_2 = flag:fallthrough
		}
	}
}

scripted_trigger lmf_has_wrong_lineality_betrothal = {
	exists = betrothed
	is_lowborn = no
	OR = {
		AND = {
			is_female = yes
			patrilinear_betrothal = yes
		}
		AND = {
			is_male = yes
			matrilinear_betrothal = yes
		}
	}
	trigger_if = {
		limit = {
			betrothed = { has_dynasty = yes }
		}
		NOT = { dynasty = betrothed.dynasty }
	}
}

scripted_trigger lmf_should_have_proper_lineality = {
	OR = {
		is_ruler = yes
		any_heir_title = {
			trigger_if = {
				limit = { has_title_law_flag = elective_succession_law }
				exists = holder
			}
			trigger_else = {
				holder ?= {
					NOR = {
						has_government = mercenary_government
						has_government = republic_government
						has_government = theocracy_government
						has_government = holy_order_government
					}
					OR = {
						is_parent_of = root
						is_grandparent_of = root
						is_great_grandparent_of = root
						has_very_low_fertility_trigger = yes
						AND = {
							is_adult = no
							OR = {
								has_trait = leper
								has_trait = incapable
								has_trait = inbred
								has_trait = infertile
								has_trait = eunuch
							}
						}
					}
				}
			}
			count > 0
		}
		is_eldest_preferred_grandchild_of = { GRANDPARENT = $RULER$ }
	}
	
	# did not have ruler/heir status when the betrothal was made
	NAND = {
		has_variable = betrothal_ruler_or_heir
		var:betrothal_ruler_or_heir = betrothed
	}
}

scripted_trigger lmf_betrothed_lover_elope_possible = {
	scope:betrothed_1 = {
		NOR = {
			has_variable = waiting_to_elope # handled via story
			is_involved_in_any_romantic_scheme = yes
		}
	}
	scope:betrothed_lover ?= {
		is_physically_able_ai_adult = yes
		can_elope_character_trigger = { CHARACTER = scope:betrothed_1 }
		OR = {
			is_married = no
			might_cheat_on_partner_trigger = { PARTNER = scope:betrothed_lover.primary_spouse }
		}
		NOR = {
			has_variable = waiting_to_elope # handled via story
			is_involved_in_any_romantic_scheme = yes
		}
	}
}

scripted_effect lmf_end_betrothal_effect = {
	#This scripted effect mimics the effects of the break betrothal character interaction
	#but without the underlying assumption that the liege is also going against the wishes
	#of the recipient (their child)

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

	#Prestige penalty
	if = {
		limit = {
			OR = {
				scope:rejected_betrothed = { highest_held_title_tier = tier_empire }
				scope:rejected_betrothal_owner = { highest_held_title_tier = tier_empire }
			}
		}
		scope:actor = { add_prestige = massive_prestige_loss }
	}
	else_if = {
		limit = {
			OR = {
				scope:rejected_betrothed = { highest_held_title_tier = tier_kingdom }
				scope:rejected_betrothal_owner = { highest_held_title_tier = tier_kingdom }
			}
		}
		scope:actor = { add_prestige = major_prestige_loss }
	}
	else_if = {
		limit = {
			OR = {
				scope:rejected_betrothed = { highest_held_title_tier = tier_duchy }
				scope:rejected_betrothal_owner = { highest_held_title_tier = tier_duchy }
			}
		}
		scope:actor = { add_prestige = medium_prestige_loss }
	}
	else_if = {
		limit = {
			OR = {
				scope:rejected_betrothed = { highest_held_title_tier = tier_county }
				scope:rejected_betrothal_owner = { highest_held_title_tier = tier_county }
			}
		}
		scope:actor = { add_prestige = minor_prestige_loss }
	}
	else_if = {
		limit = {
			OR = {
				scope:rejected_betrothed = { highest_held_title_tier = tier_barony }
				scope:rejected_betrothal_owner = { highest_held_title_tier = tier_barony }
			}
		}
		scope:actor = { add_prestige = miniscule_prestige_loss }
	}

	#Grand wedding promised
	if = {
		limit = {
			OR = {
				scope:rejecting_betrothed = { has_been_promised_grand_wedding = yes }
				scope:rejected_betrothed = { has_been_promised_grand_wedding = yes }
			}
		}
		scope:actor = { break_grand_wedding_betrothal_effect = yes }
		if = {
			limit = { scope:rejected_betrothed = root }
			hidden_effect = {
				add_opinion = {
					target = scope:actor
					modifier = broke_betrothal_opinion
				}
				scope:rejecting_betrothed = {
					break_betrothal = scope:rejected_betrothed
				}
			}
		}
		else = {
			if = {
				limit = {
					NOT = { exists = scope:no_notification }
				}
				scope:rejected_betrothed = { trigger_event = lmf_heir.2003 }
			}
		}
	}
	#Otherwise, send notification
	else = {
		scope:rejected_betrothed = {
			show_as_tooltip = {
				add_opinion = {
					target = scope:actor
					modifier = broke_betrothal_opinion
				}
			}
			if = {
				limit = { scope:rejected_betrothed = root }
				hidden_effect = {
					add_opinion = {
						target = scope:actor
						modifier = broke_betrothal_opinion
					}
					scope:rejecting_betrothed = {
						break_betrothal = scope:rejected_betrothed
					}
				}
			}
			else = {
				if = {
					limit = { exists = scope:no_notification }
					hidden_effect = {
						add_opinion = {
							target = scope:actor
							modifier = broke_betrothal_opinion
						}
						scope:rejecting_betrothed = {
							break_betrothal = scope:rejected_betrothed
						}
					}
				}
				else = {
					hidden_effect = { trigger_event = lmf_heir.2003 }
				}
			}
		}
	}

	#Personal opinion hit for the rejected_betrothal_owner
	if = {
		limit = {
			NOR = {
				scope:rejected_betrothed = scope:rejected_betrothal_owner
				scope:actor = scope:rejected_betrothal_owner
				root = scope:rejected_betrothal_owner
			}
		}
		scope:rejected_betrothal_owner = {
			if = {
				limit = {
					NOR = {
						scope:rejected_betrothed = { has_been_promised_grand_wedding = yes }
						scope:rejecting_betrothed = { has_been_promised_grand_wedding = yes }
					}
				}
				show_as_tooltip = {
					add_opinion = {
						target = scope:actor
						modifier = broke_betrothal_opinion
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = scope:no_notification }
				}
				hidden_effect = {
					add_opinion = {
						target = scope:actor
						modifier = broke_betrothal_opinion
					}
				}
			}
			else = {
				hidden_effect = { trigger_event = lmf_heir.2003 }
			}
		}
	}

	#Opinion hit for close relatives of the rejected_betrothed (that are not rejected_betrothal_owner)
	if = {
		limit = {
			scope:rejected_betrothed = {
				any_close_or_extended_family_member = {
					NOR = {
						this = scope:rejected_betrothal_owner
						this = scope:rejecting_betrothed
						this = scope:actor
					}
					count >= 1
				}
			}
		}
		if = {
			limit = {
				OR = {
					scope:rejected_betrothed = { has_been_promised_grand_wedding = yes }
					scope:rejecting_betrothed = { has_been_promised_grand_wedding = yes }
				}
			}
			scope:rejected_betrothed = {
				every_close_or_extended_family_member = {
					limit = {
						NOR = {
							this = scope:rejected_betrothal_owner
							this = scope:rejecting_betrothed
							this = scope:actor
						}
					}
					custom = all_family_members

					add_opinion = {
						target = scope:actor
						modifier = broke_betrothal_grand_wedding_opinion
						opinion = -50
					}
				}
			}
		}
		else = {
			scope:rejected_betrothed = {
				every_close_or_extended_family_member = {
					limit = {
						NOR = {
							this = scope:rejected_betrothal_owner
							this = scope:rejecting_betrothed
							this = scope:actor
						}
					}
					custom = all_family_members
					add_opinion = {
						target = scope:actor
						modifier = broke_betrothal_opinion
					}
				}
			}
		}
	}

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

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

scripted_effect lmf_assign_engagement_objection = {
	if = {
		limit = {
			NOT = { exists = scope:objection_1 }
		}
		save_scope_value_as = { name = objection_1 value = flag:$OBJECTION$ }
	}
	else_if = {
		limit = {
			NOT = { exists = scope:objection_2 }
		}
		save_scope_value_as = { name = objection_2 value = flag:$OBJECTION$ }
	}
	else = {
		save_scope_value_as = { name = objection_3 value = flag:$OBJECTION$ }
	}
}

scripted_effect lmf_pick_engagement_objection = {
	random_list = {
		# negative opinion
		10 = {
			trigger = {
				opinion = { target = scope:betrothed_2 value < 0 }
				lmf_check_existing_objections = { OBJECTION = neg_opinion }
			}
			modifier = {
				factor = 10
				opinion = { target = scope:betrothed_2 value < -50 }
			}
			modifier = {
				factor = 10
				has_relation_rival = scope:betrothed_2
			}
			lmf_assign_engagement_objection = { OBJECTION = neg_opinion }
		}
		# incest
		100 = {
			modifier = {
				factor = 10
				ai_zeal >= high_positive_ai_value
			}
			trigger = {
				OR = {
					is_sibling_of = scope:betrothed_2
					AND = {
						OR = {
							is_uncle_or_aunt_of = scope:betrothed_2
							scope:betrothed_2 = { is_uncle_or_aunt_of = scope:betrothed_1 }
						}
						faith = {
							NOT = { has_doctrine_parameter = allows_aunt_nephew_and_uncle_niece_marriage }
						}
					}
					AND = {
						is_cousin_of = scope:betrothed_2
						faith = {
							NOT = { has_doctrine_parameter = allows_cousin_marriage }
						}
					}
				}
				has_negative_attitude_towards_trait_trigger = { TRAIT = trait:incestuous GENDER_CHARACTER = scope:betrothed_1 }
				lmf_check_existing_objections = { OBJECTION = incest }
			}
			lmf_assign_engagement_objection = { OBJECTION = incest }
		}
		# lowborn
		100 = {
			trigger = {
				scope:betrothed_2 = { is_lowborn = yes }
				lmf_check_existing_objections = { OBJECTION = lowborn }
			}
			lmf_assign_engagement_objection = { OBJECTION = lowborn }
		}
		# bastard
		100 = {
			trigger = {
				is_illegitimate = no
				faith ?= {
					NOT = { has_doctrine_parameter = bastards_none }
				}
				scope:betrothed_2 = { is_illegitimate = yes }
				lmf_check_existing_objections = { OBJECTION = bastard }
			}
			lmf_assign_engagement_objection = { OBJECTION = bastard }
		}
		# not attracted to me
		100 = {
			trigger = {
				scope:betrothed_2 = {
					NOR = {
						has_sexuality = none
						is_attracted_to_gender_of = scope:betrothed_1
					}
				}
				lmf_check_existing_objections = { OBJECTION = attracted_to_me }
				lmf_check_existing_objections = { OBJECTION = attracted_to_them }
			}
			modifier = {
				factor = 10
				scope:betrothed_2 = {
					OR = {
						has_trait = sodomite
						any_secret = {
							type = secret_homosexual
							is_known_by = scope:betrothed_1
						}
					}
				}
				has_negative_attitude_towards_trait_trigger = { TRAIT = trait:sodomite GENDER_CHARACTER = scope:betrothed_2 }
			}
			lmf_assign_engagement_objection = { OBJECTION = attracted_to_me }
		}
		# not attracted to them
		100 = {
			trigger = {
				NOR = {
					has_sexuality = none
					is_attracted_to_gender_of = scope:betrothed_2
				}
				lmf_check_existing_objections = { OBJECTION = attracted_to_me }
				lmf_check_existing_objections = { OBJECTION = attracted_to_them }
			}
			lmf_assign_engagement_objection = { OBJECTION = attracted_to_them }
		}
		# dwarf
		1000 = {
			trigger = {
				scope:betrothed_2 = { has_trait = dwarf }
				is_malformed_trigger = no
				lmf_check_existing_objections = { OBJECTION = dwarf }
				lmf_check_existing_objections = { OBJECTION = hunchback }
				lmf_check_existing_objections = { OBJECTION = hideous }
				lmf_check_existing_objections = { OBJECTION = ugly }
				lmf_check_existing_objections = { OBJECTION = unattractive }
			}
			lmf_assign_engagement_objection = { OBJECTION = dwarf }
		}
		# hunchback
		1000 = {
			trigger = {
				scope:betrothed_2 = { has_trait = hunchbacked }
				is_malformed_trigger = no
				lmf_check_existing_objections = { OBJECTION = dwarf }
				lmf_check_existing_objections = { OBJECTION = hunchback }
				lmf_check_existing_objections = { OBJECTION = hideous }
				lmf_check_existing_objections = { OBJECTION = ugly }
				lmf_check_existing_objections = { OBJECTION = unattractive }
			}
			lmf_assign_engagement_objection = { OBJECTION = hunchback }
		}
		# hideous
		1000 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						is_malformed_trigger = yes
						has_trait = beauty_bad_3
					}
					NOR = {
						has_trait = dwarf
						has_trait = hunchbacked
					}
				}
				is_malformed_trigger = no
				NOT = { has_trait = beauty_bad }
				lmf_check_existing_objections = { OBJECTION = dwarf }
				lmf_check_existing_objections = { OBJECTION = hunchback }
				lmf_check_existing_objections = { OBJECTION = hideous }
				lmf_check_existing_objections = { OBJECTION = ugly }
				lmf_check_existing_objections = { OBJECTION = unattractive }
			}
			lmf_assign_engagement_objection = { OBJECTION = hideous }
		}
		# ugly
		100 = {
			trigger = {
				scope:betrothed_2 = {
					is_malformed_trigger = no
					has_trait = beauty_bad_2
				}
				is_malformed_trigger = no
				NOT = { has_trait = beauty_bad }
				lmf_check_existing_objections = { OBJECTION = dwarf }
				lmf_check_existing_objections = { OBJECTION = hunchback }
				lmf_check_existing_objections = { OBJECTION = hideous }
				lmf_check_existing_objections = { OBJECTION = ugly }
				lmf_check_existing_objections = { OBJECTION = unattractive }
			}
			lmf_assign_engagement_objection = { OBJECTION = ugly }
		}
		# unattractive
		100 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = beauty_bad_1
						AND = {
							OR = {
								current_weight > overweight_value
								current_weight < underweight_value
							}
							scope:betrothed_1 = {
								current_weight <= overweight_value
								current_weight >= underweight_value
							}
						}
					}
					NOR = {
						is_malformed_trigger = yes
						has_trait = beauty_bad_2
						has_trait = beauty_bad_3
					}
				}
				is_malformed_trigger = no
				NOT = { has_trait = beauty_bad }
				lmf_check_existing_objections = { OBJECTION = dwarf }
				lmf_check_existing_objections = { OBJECTION = hunchback }
				lmf_check_existing_objections = { OBJECTION = hideous }
				lmf_check_existing_objections = { OBJECTION = ugly }
				lmf_check_existing_objections = { OBJECTION = unattractive }
			}
			lmf_assign_engagement_objection = { OBJECTION = unattractive }
		}
		# idiot
		1000 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = intellect_bad_3
						has_trait = intellect_bad_2
					}
				}
				NOR = {
					has_trait = intellect_bad
					has_trait = dull
				}
				lmf_check_existing_objections = { OBJECTION = idiot }
				lmf_check_existing_objections = { OBJECTION = dull }
			}
			lmf_assign_engagement_objection = { OBJECTION = idiot }
		}
		# dull
		100 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = intellect_bad_1
						has_trait = dull
					}
				}
				NOR = {
					has_trait = intellect_bad
					has_trait = dull
				}
				lmf_check_existing_objections = { OBJECTION = idiot }
				lmf_check_existing_objections = { OBJECTION = dull }
			}
			lmf_assign_engagement_objection = { OBJECTION = dull }
		}
		# weak
		10 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = weak
						has_trait = physique_bad
					}
				}
				NOR = {
					has_trait = weak
					has_trait = physique_bad
				}
				lmf_check_existing_objections = { OBJECTION = weak }
			}
			modifier = {
				factor = 10
				scope:betrothed_2 = { has_trait = physique_bad_3 }
			}
			lmf_assign_engagement_objection = { OBJECTION = weak }
		}
		# lesser family
		100 = {
			trigger = {
				NOT = { has_trait = humble }
				scope:betrothed_2 = { exists = dynasty }
				trigger_if = {
					limit = {
						OR = {
							has_trait = arrogant
							has_trait = ambitious
							has_trait = greedy
						}
					}
					dynasty.dynasty_prestige_level >= scope:betrothed_2.dynasty.dynasty_prestige_level
				}
				trigger_else = {
					dynasty.dynasty_prestige_level >= scope:betrothed_2.dynasty.dynasty_prestige_level_plus_2
				}
				lmf_check_existing_objections = { OBJECTION = lesser }
			}
			lmf_assign_engagement_objection = { OBJECTION = lesser }
		}
		# lazy
		10 = {
			trigger = {
				scope:betrothed_2 = { has_trait = lazy }
				NOT = { has_trait = lazy }
				OR = {
					has_trait = diligent
					ai_energy >= high_positive_ai_value
					AND = {
						faith = { trait_is_sin = lazy }
						num_sinful_traits < 1
					}
				}
				lmf_check_existing_objections = { OBJECTION = lazy }
			}
			lmf_assign_engagement_objection = { OBJECTION = lazy }
		}
		# deceitful
		10 = {
			trigger = {
				scope:betrothed_2 = { has_trait = deceitful }
				NOT = { has_trait = deceitful }
				OR = {
					has_trait = honest
					ai_honor >= high_positive_ai_value
					AND = {
						faith = { trait_is_sin = deceitful }
						num_sinful_traits < 1
					}
				}
				lmf_check_existing_objections = { OBJECTION = deceitful }
			}
			lmf_assign_engagement_objection = { OBJECTION = deceitful }
		}
		# craven
		10 = {
			trigger = {
				scope:betrothed_2 = { has_trait = craven }
				NOT = { has_trait = craven }
				OR = {
					has_trait = brave
					ai_boldness >= high_positive_ai_value
					AND = {
						faith = { trait_is_sin = craven }
						num_sinful_traits < 1
					}
				}
				lmf_check_existing_objections = { OBJECTION = craven }
			}
			lmf_assign_engagement_objection = { OBJECTION = craven }
		}
		# shy
		10 = {
			trigger = {
				scope:betrothed_2 = { has_trait = shy }
				NOT = { has_trait = shy }
				OR = {
					has_trait = gregarious
					ai_sociability >= high_positive_ai_value
					AND = {
						faith = { trait_is_sin = shy }
						num_sinful_traits < 1
					}
				}
				lmf_check_existing_objections = { OBJECTION = shy }
			}
			lmf_assign_engagement_objection = { OBJECTION = shy }
		}
		# bold
		10 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = ambitious
						has_trait = arrogant
					}
				}
				NOR = {
					has_trait = ambitious
					has_trait = arrogant
				}
				OR = {
					has_trait = humble
					has_trait = content
					ai_boldness <= high_negative_ai_value
				}
				lmf_check_existing_objections = { OBJECTION = bold }
			}
			lmf_assign_engagement_objection = { OBJECTION = bold }
		}
		# meek
		10 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = humble
						has_trait = content
					}
				}
				NOR = {
					has_trait = humble
					has_trait = content
				}
				OR = {
					has_trait = ambitious
					has_trait = arrogant
					ai_boldness >= high_positive_ai_value
				}
				lmf_check_existing_objections = { OBJECTION = meek }
			}
			lmf_assign_engagement_objection = { OBJECTION = meek }
		}
		# drunkard
		100 = {
			trigger = {
				scope:betrothed_2 = { has_trait = drunkard }
				NOR = {
					has_trait = drunkard
					has_trait = gluttonous
					has_trait = lifestyle_reveler
				}
				lmf_check_existing_objections = { OBJECTION = drunkard }
			}
			lmf_assign_engagement_objection = { OBJECTION = drunkard }
		}
		# sad
		10 = {
			trigger = {
				scope:betrothed_2 = { has_trait = depressed }
				NOR = {
					has_trait = depressed
					ai_compassion >= low_positive_ai_value
				}
				lmf_check_existing_objections = { OBJECTION = sad }
			}
			lmf_assign_engagement_objection = { OBJECTION = sad }
		}
		# crazy
		100 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = lunatic
						has_trait = possessed
					}
				}
				NOR = {
					has_trait = lunatic
					has_trait = possessed
				}
				lmf_check_existing_objections = { OBJECTION = crazy }
			}
			lmf_assign_engagement_objection = { OBJECTION = crazy }
		}
		# unkind
		100 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = sadistic
						has_trait = callous
					}
				}
				NOR = {
					has_trait = sadistic
					has_trait = callous
				}
				OR = {
					has_trait = compassionate
					ai_compassion >= high_positive_ai_value
				}
				lmf_check_existing_objections = { OBJECTION = unkind }
			}
			lmf_assign_engagement_objection = { OBJECTION = unkind }
		}
		# prude
		10 = {
			trigger = {
				scope:betrothed_2 = { has_trait = chaste }
				NOT = { has_trait = chaste }
				likely_to_take_lover_trigger = yes
				lmf_check_existing_objections = { OBJECTION = prude }
			}
			lmf_assign_engagement_objection = { OBJECTION = prude }
		}
		# unfaithful
		1000 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						likely_to_take_lover_trigger = yes
						has_trait = adulterer
						has_trait = fornicator
						any_relation = {
							type = lover
							NOR = {
								this = scope:betrothed_1
								lover_is_secret_trigger = { CHARACTER = scope:betrothed_2 }
							}
						}
					}
				}
				likely_to_take_lover_trigger = no
				has_negative_attitude_towards_trait_trigger = { TRAIT = trait:adulterer GENDER_CHARACTER = scope:betrothed_2 }
				lmf_check_existing_objections = { OBJECTION = unfaithful }
			}
			lmf_assign_engagement_objection = { OBJECTION = unfaithful }
		}
		# much too young
		1000 = {
			trigger = {
				age >= scope:betrothed_2.age_plus_25
				lmf_check_existing_objections = { OBJECTION = much_too_young }
				lmf_check_existing_objections = { OBJECTION = too_young }
			}
			lmf_assign_engagement_objection = { OBJECTION = much_too_young }
		}
		# too young
		100 = {
			trigger = {
				age >= scope:betrothed_2.age_plus_10
				lmf_check_existing_objections = { OBJECTION = much_too_young }
				lmf_check_existing_objections = { OBJECTION = too_young }
			}
			lmf_assign_engagement_objection = { OBJECTION = too_young }
		}
		# much too old
		1000 = {
			trigger = {
				age_plus_25 <= scope:betrothed_2.age
				lmf_check_existing_objections = { OBJECTION = much_too_old }
				lmf_check_existing_objections = { OBJECTION = too_old }
			}
			lmf_assign_engagement_objection = { OBJECTION = much_too_old }
		}
		# too old
		100 = {
			trigger = {
				age_plus_10 <= scope:betrothed_2.age
				lmf_check_existing_objections = { OBJECTION = much_too_old }
				lmf_check_existing_objections = { OBJECTION = too_old }
			}
			lmf_assign_engagement_objection = { OBJECTION = too_old }
		}
		# too unlike
		100 = {
			trigger = {
				trait_compatibility = {
					target = scope:betrothed_2
					value <= high_negative_trait_compatibility
				}
				lmf_check_existing_objections = { OBJECTION = unlike }
			}
			lmf_assign_engagement_objection = { OBJECTION = unlike }
		}
		# std
		100 = {
			trigger = {
				scope:betrothed_2 = { has_std_trigger = yes }
				has_std_trigger = no
				lmf_check_existing_objections = { OBJECTION = std }
			}
			lmf_assign_engagement_objection = { OBJECTION = std }
		}
		# reputation
		1000 = {
			trigger = {
				scope:betrothed_2 = {
					OR = {
						has_trait = torturer
						has_trait = murderer
						has_trait = kinslayer_1
						has_trait = kinslayer_2
						has_trait = kinslayer_3
						AND = {
							has_trait = incestuous
							scope:betrothed_1 = { has_negative_attitude_towards_trait_trigger = { TRAIT = trait:incestuous GENDER_CHARACTER = scope:betrothed_2 } }
						}
						AND = {
							has_trait = deviant
							scope:betrothed_1 = { has_negative_attitude_towards_trait_trigger = { TRAIT = trait:deviant GENDER_CHARACTER = scope:betrothed_2 } }
						}
						AND = {
							has_trait = cannibal
							scope:betrothed_1 = { has_negative_attitude_towards_trait_trigger = { TRAIT = trait:cannibal GENDER_CHARACTER = scope:betrothed_2 } }
						}
						AND = {
							has_trait = witch
							scope:betrothed_1 = { has_negative_attitude_towards_trait_trigger = { TRAIT = trait:witch GENDER_CHARACTER = scope:betrothed_2 } }
						}
						AND = {
							has_trait = sodomite
							is_attracted_to_gender_of = scope:betrothed_1
							scope:betrothed_1 = { has_negative_attitude_towards_trait_trigger = { TRAIT = trait:sodomite GENDER_CHARACTER = scope:betrothed_2 } }
						}
					}
				}
				NOR = {
					has_trait = torturer
					has_trait = murderer
					has_trait = kinslayer_1
					has_trait = kinslayer_2
					has_trait = kinslayer_3
					has_trait = incestuous
					has_trait = deviant
					has_trait = cannibal
					has_trait = witch
					has_trait = sodomite
				}
				lmf_check_existing_objections = { OBJECTION = reputation }
			}
			lmf_assign_engagement_objection = { OBJECTION = reputation }
		}
		# has bastard child
		100 = {
			trigger = {
				scope:betrothed_2 = {
					any_child = {
						even_if_dead = yes
						is_illegitimate = yes
						NOT = { is_child_of = scope:betrothed_1 }
					}
				}
				is_illegitimate = no
				NOR = {
					has_trait = fornicator
					has_trait = adulterer
					any_child = {
						even_if_dead = yes
						is_illegitimate = yes
					}
				}
				lmf_check_existing_objections = { OBJECTION = child }
			}
			lmf_assign_engagement_objection = { OBJECTION = child }
		}
		# religion
		10 = {
			trigger = {
				NOR = {
					faith = scope:betrothed_2.faith
					ai_zeal < 0
				}
				faith = {
					faith_hostility_level = {
						target = scope:betrothed_2.faith
						value >= faith_astray_level
					}
				}
				lmf_check_existing_objections = { OBJECTION = faith }
			}
			modifier = {
				factor = 10
				has_trait = zealous
			}
			modifier = {
				factor = 0.1
				NOT = { has_trait = zealous }
				faith = {
					faith_hostility_level = {
						target = scope:betrothed_2.faith
						value = faith_astray_level
					}
				}
			}
			modifier = {
				factor = 10
				faith = {
					faith_hostility_level = {
						target = scope:betrothed_2.faith
						value >= faith_evil_level
					}
				}
			}
			lmf_assign_engagement_objection = { OBJECTION = faith }
		}
		# culture
		5 = {
			trigger = {
				NOT = {
					culture = scope:betrothed_2.culture
				}
				culture = {
					cultural_acceptance = {
						target = scope:betrothed_2.culture
						value < 10
					}
				}
				lmf_check_existing_objections = { OBJECTION = culture }
			}
			modifier = {
				factor = 10
				culture = {
					cultural_acceptance = {
						target = scope:betrothed_2.culture
						value <= 0
					}
				}
			}
			lmf_assign_engagement_objection = { OBJECTION = culture }
		}
		# unremarkable
		5 = {
			trigger = {
				scope:betrothed_2 = {
					NOR = {
						has_trait = intellect_good
						has_trait = physique_good
						has_trait = beauty_good
						has_any_high_skill_rating = yes
					}
				}
				OR = {
					has_trait = intellect_good
					has_trait = physique_good
					has_trait = beauty_good
					has_any_high_skill_rating = yes
				}
				lmf_check_existing_objections = { OBJECTION = unremarkable }
			}
			lmf_assign_engagement_objection = { OBJECTION = unremarkable }
		}
		# fallthrough
		1 = {
			lmf_assign_engagement_objection = { OBJECTION = fallthrough }
		}
	}
}

scripted_effect lmf_allow_lover_marriage = {
	# remove any previous marriage refusal opinions
	hidden_effect = {
		if = {
			limit = {
				reverse_has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = scope:betrothed_1 }
			}
			scope:betrothed_1 = {
				remove_opinion = { target = root modifier = refused_marriage_permission_opinion }
			}
		}
		if = {
			limit = {
				reverse_has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = scope:betrothed_lover }
			}
			scope:betrothed_lover = {
				remove_opinion = { target = root modifier = refused_marriage_permission_opinion }
			}
		}
	}
	# and add new opinions
	reverse_add_opinion = { modifier = granted_marriage_permission_opinion target = scope:betrothed_1 }
	reverse_add_opinion = { modifier = granted_marriage_permission_opinion target = scope:betrothed_lover }
	# add a hook to both parties
	if = {
		limit = {
			can_add_hook = {
				target = scope:betrothed_1
				type = favor_hook
			}
		}
		add_hook = {
			type = favor_hook
			target = scope:betrothed_1
		}
	}
	if = {
		limit = {
			can_add_hook = {
				target = scope:betrothed_lover
				type = favor_hook
			}
		}
		add_hook = {
			type = favor_hook
			target = scope:betrothed_lover
		}
	}
	# remove Will Not Wed trait and the story cycle, if possessed
	scope:betrothed_1 = {
		if = {
			limit = { has_trait = will_not_wed }
			remove_trait = will_not_wed
			hidden_effect = {
				random_owned_story = {
					type = lmf_will_not_wed_story_cycle
					end_story = yes
				}
			}
		}
	}
	scope:betrothed_lover = {
		if = {
			limit = { has_trait = will_not_wed }
			remove_trait = will_not_wed
			hidden_effect = {
				random_owned_story = {
					type = lmf_will_not_wed_story_cycle
					end_story = yes
				}
			}
		}
	}
	# now marry them
	if = {
		# check for a special matrilineal condition
		limit = {
			# child is an heir or first in line to a title
			scope:betrothed_1 = {
				is_female = yes
				OR = {
					any_heir_title = {}
					any_pretender_title = {
						place_in_line_of_succession = {
							target = scope:betrothed_1
							value <= 2
						}
					}
				}
			}
			# the lover is either a lower tier ruler
			# or is heir/first in line to lower tier titles
			# or is none of the above
			scope:betrothed_lover = {
				trigger_if = {
					limit = { is_ruler = yes }
					highest_held_title_tier < root.highest_held_title_tier
				}
				NOR = {
					any_heir_title = { tier >= root.highest_held_title_tier }
					any_pretender_title = {
						tier >= root.highest_held_title_tier
						place_in_line_of_succession = {
							target = scope:betrothed_lover
							value <= 2
						}
					}
				}
			}
		}
		scope:betrothed_lover = {
			marry_matrilineal = scope:betrothed_1
		}
	}
	# failing the above conditions, we check the normal matrilineal rules
	else_if = {
		limit = {
			should_marry_matrilineally_trigger = { PROPOSER = scope:betrothed_1 TARGET = scope:betrothed_lover }
		}
		scope:betrothed_lover = {
			marry_matrilineal = scope:betrothed_1
		}
	}
	else = {
		scope:betrothed_1 = {
			marry = scope:betrothed_lover
		}
	}
	hidden_effect = {
		# move them to the proper court and
		move_characters_to_proper_court_effect = { CHARACTER_1 = scope:betrothed_1 CHARACTER_2 = scope:betrothed_lover }
		# they might break up with any other current lovers
		scope:betrothed_1 = { soulmate_lover_breakup_effect = { EXCLUDE = scope:betrothed_lover } }
		scope:betrothed_lover = { soulmate_lover_breakup_effect = { EXCLUDE = scope:betrothed_1 } }
	}
}

# Bounce event to check if the child is unhappy with their betrothal
lmf_heir.2000 = {
	hidden = yes

	trigger = {
		NOT = { has_game_rule = lmf_no_betrothal_objection }
		# is 12+ years old, noble, and betrothed
		exists = betrothed
		age >= 12
		has_dynasty = yes
		# and essentially able to interact
		basic_is_available_ai = yes
		has_recoverable_disease_trigger = no

		# their host is their matchmaker
		is_courtier = yes
		exists = host
		exists = matchmaker
		OR = {
			host = matchmaker
			is_non_courtier_marriage_candidate = { RULER = root.host }
		}

		# and a close relative or grandparent ruler (of duke+ tier)
		host = {
			highest_held_title_tier > tier_county
			OR = {
				is_close_family_of = root
				is_great_grandparent_of = root
			}
			is_physically_able_adult = yes
			NOR = {
				has_government = mercenary_government
				has_government = republic_government
				has_government = theocracy_government
				has_government = holy_order_government
			}
			# who the child can break off the betrothal with
			trigger_if = {
				limit = { this = root.betrothed }
				root = {
					is_character_interaction_valid = {
						recipient = root.betrothed
						interaction = break_betrothal_interaction
					}
				}
			}
			# or they can break the betrothal
			trigger_else = {
				is_character_interaction_valid = {
					recipient = root.betrothed
					interaction = break_betrothal_interaction
				}
				# and isn't the child's rival
				NOT = { has_relation_rival = root }
			}
		}
		# the child wasn't betrothed through an introduction
		# or already in love with their betrothed, a hostage, or submissive
		# and didn't previously have an event which makes this impossible
		NOR = {
			host = root
			has_any_good_relationship_with_character_trigger = { CHARACTER = root.betrothed }
			has_opinion_modifier = { target = betrothed modifier = successful_marriage_introduction }
			has_opinion_modifier = { target = betrothed modifier = failed_marriage_introduction }
			is_hostage = yes
			has_trait = content
			has_trait = humble
			has_personality_submissive_trigger = yes
			has_character_flag = cannot_get_will_not_wed_trait
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			ai_boldness >= 50
			factor = 2
		}
		modifier = {
			is_hot_headed_trigger = yes
			factor = 2
		}
		modifier = {
			has_trait = arrogant
			factor = 2
		}
		modifier = {
			age >= 14
			factor = 2
		}
		modifier = {
			age >= 15
			factor = 2
		}
		modifier = {
			factor = 2
			has_game_rule = lmf_more_betrothal_objection
		}
		modifier = {
			factor = 0.5
			has_game_rule = lmf_less_betrothal_objection
		}
	}

	immediate = {
		# first save their overall approval value towards their betrothed
		betrothed = { save_temporary_scope_as = candidate }
		save_temporary_scope_as = match
		save_temporary_opinion_value_as = { name = match_opinion target = scope:candidate }
		set_variable = { name = betrothed_approval value = scope:candidate.introduction_candidate_interest_value days = 1 }

		# then check if the child is displeased with their betrothed
		if = {
			limit = {
				# some children have higher standards
				trigger_if = {
					limit = {
						OR = {
							# more often
							has_game_rule = lmf_more_betrothal_objection
							# they're more arrogant/assertive
							has_trait = arrogant
							ai_boldness >= high_positive_ai_value
							is_hot_headed_trigger = yes
							# or not attracted to their betrothed's gender
							NOT = { is_attracted_to_gender_of = betrothed }
							# or already have a lover who isn't the betrothed
							any_relation = {
								type = lover
								NOT = { this = root.betrothed }
							}
						}
					}
					var:betrothed_approval < 0
				}
				# otherwise they'll be a bit more lenient
				trigger_else = {
					var:betrothed_approval <= -20
				}
			}
			# see if they will actually object
			random = {
				chance = 20
				modifier = {
					add = {
						value = var:betrothed_approval
						multiply = -0.5
					}
				}
				ai_value_modifier = {
					ai_boldness = 1
					ai_rationality = -1
				}
				modifier = {
					add = 25
					has_trait = stubborn
				}
				modifier = {
					add = 25
					has_trait = arrogant
				}
				modifier = {
					add = -50
					has_trait = humble
				}
				modifier = {
					add = -50
					has_trait = content
				}
				modifier = {
					add = 50
					NOT = { is_attracted_to_gender_of = betrothed }
				}
				modifier = {
					add = 50
					any_relation = {
						type = lover
						NOT = { this = root.betrothed }
					}
				}
				modifier = {
					add = 50
					has_any_bad_relationship_with_character_trigger = { CHARACTER = root.betrothed }
				}
				modifier = {
					add = 20
					has_game_rule = lmf_more_betrothal_objection
				}
				modifier= {
					add = -20
					has_game_rule = lmf_less_betrothal_objection
				}
				min = 0
				max = 100
				save_scope_value_as = { name = is_objecting value = yes }
			}
		}
		
		# trigger objection event, if there's going to be one
		if = {
			limit = { exists = scope:is_objecting }
			save_scope_as = betrothed_1
			betrothed = { save_scope_as = betrothed_2 }
			# automatically break it off if the matchmaker is also the betrothed
			if = {
				limit = { matchmaker = scope:betrothed_2 }
				matchmaker = { trigger_event = lmf_heir.2001 }
			}
			# otherwise object to the betrothal
			else = {
				matchmaker = { trigger_event = lmf_heir.2002 }
			}
		}
		# otherwise disable further checks for two years and see if any
		# adult betrothed objects - they might not get to check otherwise
		else = {
			add_character_flag = { flag = cannot_get_will_not_wed_trait months = 24 }
			if = {
				limit = {
					betrothed = { is_adult = yes }
				}
				betrothed = {
					trigger_event = lmf_heir.2000
				}
			}
		}
	}
}

# Child leaves betrothed liege
lmf_heir.2001 = {
	type = letter_event
	opening = lmf_heir.2001.opening
	desc = lmf_heir.2001.desc
	sender = {
		character = scope:betrothed_1
		animation = disgust
	}

	immediate = {
		# set the scopes for the breaking betrothal
		save_scope_as = recipient
		save_scope_as = rejected_betrothed
		save_scope_as = rejected_betrothal_owner
		scope:betrothed_1 = {
			save_scope_as = actor
			save_scope_as = rejecting_betrothed
		}

		# now end the betrothal - even though some traits would end it automatically,
		# we still want the opinion changes and notifications
		lmf_end_betrothal_effect = yes

		# add opinion that will prevent re-engagement later
		scope:betrothed_1 = {
			hidden_effect = {
				add_opinion = { target = root modifier = ended_engagement_opinion }
				reverse_add_opinion = { target = root modifier = ended_engagement_opinion }
			}
		}

		# child leaves court
		scope:betrothed_1 = {
			remove_character_flag = cannot_get_will_not_wed_trait
			lose_guardians_and_wards_effect = { LIEGE = root COURTIER = scope:betrothed_1 }
			add_trait_force_tooltip = will_not_wed
			hidden_effect = {
				create_story = {
					type = lmf_will_not_wed_story_cycle
				}
			}
			add_character_modifier = {
				modifier = lust_for_adventure
				years = 5
			}
			create_character_memory = {
				type = lmf_memory_left_court
				participants = { court = root }
			}
			scope:new_memory = {
				set_variable = {
					name = liege_title
					value = root.primary_title
				}
			}
			lmf_move_to_pool_effect = yes
		}
	}

	option = {
		name = lmf_heir.2001.a #She'll return in time, I'm sure of it.
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
				ai_vengefulness = -0.5
			}
			min = 1
		}
	}
	option = {
		name = lmf_heir.2001.b #Then she needn't return anytime soon
		worsen_relationship_effect = { 
			TARGET = scope:betrothed_1
			REASON = abandoned_our_betrothal
		}
		add_opinion = { target = scope:betrothed_1 modifier = upset_opinion opinion = -30 }
		reverse_add_opinion = { target = scope:betrothed_1 modifier = hate_opinion opinion = -30 }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
			}
			min = 0
		}
	}
	option = {
		trigger = {
			scope:betrothed_1 = {
				OR = {
					any_heir_title = { holder ?= root }
					any_pretender_title = { holder ?= root }
				}
				NOT = { has_trait = disinherited }
			}
			culture = {
				NOT = { has_cultural_parameter = cannot_disherit }
			}
		}
		name = lmf_heir.2001.c #Then she'll have no inheritance of mine!
		scope:betrothed_1 = {
			disinherit_effect = { DISINHERITOR = root }
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 1
			}
			modifier = {
				factor = 0
				primary_heir = scope:betrothed_1
			}
			min = 0
		}
	}
}

# Child objects to betrothal
lmf_heir.2002 = {
	type = character_event
	window = lmf_feast_event_window
	title = lmf_heir.2002.t
	desc = {
		desc = lmf_heir.2002.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:betrothed_1 = { has_personality_submissive_trigger = yes }
				}
				desc = lmf_heir.2002.desc.submissive
			}
			triggered_desc = {
				trigger = {
					scope:betrothed_1 = {
						OR = {
							has_personality_dominant_trigger = yes
							has_personality_malicious_trigger = yes
						}
					}
				}
				desc = lmf_heir.2002.desc.angry
			}
			desc = lmf_heir.2002.desc.beg
		}
		desc = lmf_heir.2002.desc.mid
		first_valid = {
			# no objections picked
			triggered_desc = {
				trigger = { scope:objection_1 = flag:fallthrough }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { exists = scope:betrothed_lover }
							desc = {
								desc = lmf_heir.2002.desc.one
								desc = lmf_heir.2002.desc.lover
							}
						}
						desc = lmf_heir.2002.desc.nothing
					}
				}
			}
			# one objection picked
			triggered_desc = {
				trigger = {
					NOT = { scope:objection_1 = flag:fallthrough }
					scope:objection_2 = flag:fallthrough
				}
				desc = {
					desc = lmf_heir.2002.desc.one
					first_valid = {
						triggered_desc = {
							trigger = { exists = scope:betrothed_lover }
							desc = lmf_heir.2002.desc.lover
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:neg_opinion }
							desc = lmf_engagement_objection_negative_opinion
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:incest }
							desc = lmf_engagement_objection_incest
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:lowborn }
							desc = lmf_engagement_objection_lowborn
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:bastard }
							desc = lmf_engagement_objection_bastard
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:attracted_to_me }
							desc = lmf_engagement_objection_not_attracted_to_me
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:attracted_to_them }
							desc = lmf_engagement_objection_not_attracted_to_them
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:dwarf }
							desc = lmf_engagement_objection_dwarf
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:hunchback }
							desc = lmf_engagement_objection_hunchback
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:hideous }
							desc = lmf_engagement_objection_hideous
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:ugly }
							desc = lmf_engagement_objection_ugly
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unattractive }
							desc = lmf_engagement_objection_unattractive
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:idiot }
							desc = lmf_engagement_objection_idiot
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:dull }
							desc = lmf_engagement_objection_dull
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:weak }
							desc = lmf_engagement_objection_weak
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:lesser }
							desc = lmf_engagement_objection_lesser
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:lazy }
							desc = lmf_engagement_objection_lazy
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:deceitful }
							desc = lmf_engagement_objection_deceitful
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:craven }
							desc = lmf_engagement_objection_craven
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:shy }
							desc = lmf_engagement_objection_shy
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:bold }
							desc = lmf_engagement_objection_bold
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:meek }
							desc = lmf_engagement_objection_meek
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:drunkard }
							desc = lmf_engagement_objection_drunkard
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:sad }
							desc = lmf_engagement_objection_sad
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:crazy }
							desc = lmf_engagement_objection_crazy
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unkind }
							desc = lmf_engagement_objection_unkind
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:prude }
							desc = lmf_engagement_objection_prude
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unfaithful }
							desc = lmf_engagement_objection_unfaithful
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:too_young }
							desc = lmf_engagement_objection_too_young
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:too_old }
							desc = lmf_engagement_objection_too_old
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:much_too_young }
							desc = lmf_engagement_objection_much_too_young
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:much_too_old }
							desc = lmf_engagement_objection_much_too_old
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unlike }
							desc = lmf_engagement_objection_unlike
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:std }
							desc = lmf_engagement_objection_std
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:reputation }
							desc = lmf_engagement_objection_reputation
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:faith }
							desc = lmf_engagement_objection_faith
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:culture }
							desc = lmf_engagement_objection_culture
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:child }
							desc = lmf_engagement_objection_child
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unremarkable }
							desc = lmf_engagement_objection_unremarkable
						}
						desc = lmf_engagement_objection_unremarkable
					}
				}
			}
			# two objections picked
			triggered_desc = {
				trigger = {
					NOR = {
						scope:objection_1 = flag:fallthrough
						scope:objection_2 = flag:fallthrough
					}
					scope:objection_3 = flag:fallthrough
				}
				desc = {
					desc = lmf_heir.2002.desc.first
					first_valid = {
						triggered_desc = {
							trigger = { scope:objection_1 = flag:neg_opinion }
							desc = lmf_engagement_objection_negative_opinion
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:incest }
							desc = lmf_engagement_objection_incest
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:lowborn }
							desc = lmf_engagement_objection_lowborn
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:bastard }
							desc = lmf_engagement_objection_bastard
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:attracted_to_me }
							desc = lmf_engagement_objection_not_attracted_to_me
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:attracted_to_them }
							desc = lmf_engagement_objection_not_attracted_to_them
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:dwarf }
							desc = lmf_engagement_objection_dwarf
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:hunchback }
							desc = lmf_engagement_objection_hunchback
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:hideous }
							desc = lmf_engagement_objection_hideous
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:ugly }
							desc = lmf_engagement_objection_ugly
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unattractive }
							desc = lmf_engagement_objection_unattractive
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:idiot }
							desc = lmf_engagement_objection_idiot
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:dull }
							desc = lmf_engagement_objection_dull
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:weak }
							desc = lmf_engagement_objection_weak
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:lesser }
							desc = lmf_engagement_objection_lesser
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:lazy }
							desc = lmf_engagement_objection_lazy
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:deceitful }
							desc = lmf_engagement_objection_deceitful
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:craven }
							desc = lmf_engagement_objection_craven
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:shy }
							desc = lmf_engagement_objection_shy
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:bold }
							desc = lmf_engagement_objection_bold
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:meek }
							desc = lmf_engagement_objection_meek
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:drunkard }
							desc = lmf_engagement_objection_drunkard
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:sad }
							desc = lmf_engagement_objection_sad
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:crazy }
							desc = lmf_engagement_objection_crazy
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unkind }
							desc = lmf_engagement_objection_unkind
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:prude }
							desc = lmf_engagement_objection_prude
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unfaithful }
							desc = lmf_engagement_objection_unfaithful
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:too_young }
							desc = lmf_engagement_objection_too_young
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:too_old }
							desc = lmf_engagement_objection_too_old
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:much_too_young }
							desc = lmf_engagement_objection_much_too_young
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:much_too_old }
							desc = lmf_engagement_objection_much_too_old
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unlike }
							desc = lmf_engagement_objection_unlike
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:std }
							desc = lmf_engagement_objection_std
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:reputation }
							desc = lmf_engagement_objection_reputation
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:faith }
							desc = lmf_engagement_objection_faith
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:culture }
							desc = lmf_engagement_objection_culture
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:child }
							desc = lmf_engagement_objection_child
						}
						triggered_desc = {
							trigger = { scope:objection_1 = flag:unremarkable }
							desc = lmf_engagement_objection_unremarkable
						}
						desc = lmf_engagement_objection_unremarkable
					}
					desc lmf_heir.2002.desc.second
					first_valid = {
						triggered_desc = {
							trigger = { exists = scope:betrothed_lover }
							desc = lmf_heir.2002.desc.lover
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:neg_opinion }
							desc = lmf_engagement_objection_negative_opinion
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:incest }
							desc = lmf_engagement_objection_incest
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:lowborn }
							desc = lmf_engagement_objection_lowborn
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:bastard }
							desc = lmf_engagement_objection_bastard
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:attracted_to_me }
							desc = lmf_engagement_objection_not_attracted_to_me
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:attracted_to_them }
							desc = lmf_engagement_objection_not_attracted_to_them
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:dwarf }
							desc = lmf_engagement_objection_dwarf
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:hunchback }
							desc = lmf_engagement_objection_hunchback
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:hideous }
							desc = lmf_engagement_objection_hideous
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:ugly }
							desc = lmf_engagement_objection_ugly
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:unattractive }
							desc = lmf_engagement_objection_unattractive
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:idiot }
							desc = lmf_engagement_objection_idiot
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:dull }
							desc = lmf_engagement_objection_dull
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:weak }
							desc = lmf_engagement_objection_weak
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:lesser }
							desc = lmf_engagement_objection_lesser
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:lazy }
							desc = lmf_engagement_objection_lazy
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:deceitful }
							desc = lmf_engagement_objection_deceitful
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:craven }
							desc = lmf_engagement_objection_craven
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:shy }
							desc = lmf_engagement_objection_shy
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:bold }
							desc = lmf_engagement_objection_bold
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:meek }
							desc = lmf_engagement_objection_meek
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:drunkard }
							desc = lmf_engagement_objection_drunkard
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:sad }
							desc = lmf_engagement_objection_sad
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:crazy }
							desc = lmf_engagement_objection_crazy
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:unkind }
							desc = lmf_engagement_objection_unkind
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:prude }
							desc = lmf_engagement_objection_prude
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:unfaithful }
							desc = lmf_engagement_objection_unfaithful
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:too_young }
							desc = lmf_engagement_objection_too_young
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:too_old }
							desc = lmf_engagement_objection_too_old
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:much_too_young }
							desc = lmf_engagement_objection_much_too_young
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:much_too_old }
							desc = lmf_engagement_objection_much_too_old
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:unlike }
							desc = lmf_engagement_objection_unlike
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:std }
							desc = lmf_engagement_objection_std
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:reputation }
							desc = lmf_engagement_objection_reputation
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:faith }
							desc = lmf_engagement_objection_faith
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:culture }
							desc = lmf_engagement_objection_culture
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:child }
							desc = lmf_engagement_objection_child
						}
						triggered_desc = {
							trigger = { scope:objection_2 = flag:unremarkable }
							desc = lmf_engagement_objection_unremarkable
						}
						desc = lmf_engagement_objection_unremarkable
					}
				}
			}
			# three objections picked
			desc = {
				desc = lmf_heir.2002.desc.first
				first_valid = {
					triggered_desc = {
						trigger = { scope:objection_1 = flag:neg_opinion }
						desc = lmf_engagement_objection_negative_opinion
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:incest }
						desc = lmf_engagement_objection_incest
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:lowborn }
						desc = lmf_engagement_objection_lowborn
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:bastard }
						desc = lmf_engagement_objection_bastard
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:attracted_to_me }
						desc = lmf_engagement_objection_not_attracted_to_me
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:attracted_to_them }
						desc = lmf_engagement_objection_not_attracted_to_them
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:dwarf }
						desc = lmf_engagement_objection_dwarf
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:hunchback }
						desc = lmf_engagement_objection_hunchback
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:hideous }
						desc = lmf_engagement_objection_hideous
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:ugly }
						desc = lmf_engagement_objection_ugly
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:unattractive }
						desc = lmf_engagement_objection_unattractive
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:idiot }
						desc = lmf_engagement_objection_idiot
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:dull }
						desc = lmf_engagement_objection_dull
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:weak }
						desc = lmf_engagement_objection_weak
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:lesser }
						desc = lmf_engagement_objection_lesser
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:lazy }
						desc = lmf_engagement_objection_lazy
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:deceitful }
						desc = lmf_engagement_objection_deceitful
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:craven }
						desc = lmf_engagement_objection_craven
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:shy }
						desc = lmf_engagement_objection_shy
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:bold }
						desc = lmf_engagement_objection_bold
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:meek }
						desc = lmf_engagement_objection_meek
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:drunkard }
						desc = lmf_engagement_objection_drunkard
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:sad }
						desc = lmf_engagement_objection_sad
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:crazy }
						desc = lmf_engagement_objection_crazy
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:unkind }
						desc = lmf_engagement_objection_unkind
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:prude }
						desc = lmf_engagement_objection_prude
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:unfaithful }
						desc = lmf_engagement_objection_unfaithful
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:too_young }
						desc = lmf_engagement_objection_too_young
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:too_old }
						desc = lmf_engagement_objection_too_old
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:much_too_young }
						desc = lmf_engagement_objection_much_too_young
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:much_too_old }
						desc = lmf_engagement_objection_much_too_old
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:unlike }
						desc = lmf_engagement_objection_unlike
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:std }
						desc = lmf_engagement_objection_std
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:reputation }
						desc = lmf_engagement_objection_reputation
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:faith }
						desc = lmf_engagement_objection_faith
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:culture }
						desc = lmf_engagement_objection_culture
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:child }
						desc = lmf_engagement_objection_child
					}
					triggered_desc = {
						trigger = { scope:objection_1 = flag:unremarkable }
						desc = lmf_engagement_objection_unremarkable
					}
					desc = lmf_engagement_objection_unremarkable
				}
				desc = lmf_heir.2002.desc.second
				first_valid = {
					triggered_desc = {
						trigger = { scope:objection_2 = flag:neg_opinion }
						desc = lmf_engagement_objection_negative_opinion
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:incest }
						desc = lmf_engagement_objection_incest
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:lowborn }
						desc = lmf_engagement_objection_lowborn
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:bastard }
						desc = lmf_engagement_objection_bastard
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:attracted_to_me }
						desc = lmf_engagement_objection_not_attracted_to_me
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:attracted_to_them }
						desc = lmf_engagement_objection_not_attracted_to_them
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:dwarf }
						desc = lmf_engagement_objection_dwarf
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:hunchback }
						desc = lmf_engagement_objection_hunchback
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:hideous }
						desc = lmf_engagement_objection_hideous
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:ugly }
						desc = lmf_engagement_objection_ugly
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:unattractive }
						desc = lmf_engagement_objection_unattractive
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:idiot }
						desc = lmf_engagement_objection_idiot
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:dull }
						desc = lmf_engagement_objection_dull
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:weak }
						desc = lmf_engagement_objection_weak
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:lesser }
						desc = lmf_engagement_objection_lesser
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:lazy }
						desc = lmf_engagement_objection_lazy
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:deceitful }
						desc = lmf_engagement_objection_deceitful
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:craven }
						desc = lmf_engagement_objection_craven
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:shy }
						desc = lmf_engagement_objection_shy
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:bold }
						desc = lmf_engagement_objection_bold
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:meek }
						desc = lmf_engagement_objection_meek
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:drunkard }
						desc = lmf_engagement_objection_drunkard
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:sad }
						desc = lmf_engagement_objection_sad
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:crazy }
						desc = lmf_engagement_objection_crazy
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:unkind }
						desc = lmf_engagement_objection_unkind
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:prude }
						desc = lmf_engagement_objection_prude
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:unfaithful }
						desc = lmf_engagement_objection_unfaithful
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:too_young }
						desc = lmf_engagement_objection_too_young
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:too_old }
						desc = lmf_engagement_objection_too_old
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:much_too_young }
						desc = lmf_engagement_objection_much_too_young
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:much_too_old }
						desc = lmf_engagement_objection_much_too_old
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:unlike }
						desc = lmf_engagement_objection_unlike
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:std }
						desc = lmf_engagement_objection_std
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:reputation }
						desc = lmf_engagement_objection_reputation
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:faith }
						desc = lmf_engagement_objection_faith
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:culture }
						desc = lmf_engagement_objection_culture
					}

					triggered_desc = {
						trigger = { scope:objection_2 = flag:child }
						desc = lmf_engagement_objection_child
					}
					triggered_desc = {
						trigger = { scope:objection_2 = flag:unremarkable }
						desc = lmf_engagement_objection_unremarkable
					}
					desc = lmf_engagement_objection_unremarkable
				}
				desc = lmf_heir.2002.desc.third
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:betrothed_lover }
						desc = lmf_heir.2002.desc.lover
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:neg_opinion }
						desc = lmf_engagement_objection_negative_opinion
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:incest }
						desc = lmf_engagement_objection_incest
					}

					triggered_desc = {
						trigger = { scope:objection_3 = flag:lowborn }
						desc = lmf_engagement_objection_lowborn
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:bastard }
						desc = lmf_engagement_objection_bastard
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:attracted_to_me }
						desc = lmf_engagement_objection_not_attracted_to_me
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:attracted_to_them }
						desc = lmf_engagement_objection_not_attracted_to_them
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:dwarf }
						desc = lmf_engagement_objection_dwarf
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:hunchback }
						desc = lmf_engagement_objection_hunchback
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:hideous }
						desc = lmf_engagement_objection_hideous
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:ugly }
						desc = lmf_engagement_objection_ugly
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:unattractive }
						desc = lmf_engagement_objection_unattractive
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:idiot }
						desc = lmf_engagement_objection_idiot
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:dull }
						desc = lmf_engagement_objection_dull
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:weak }
						desc = lmf_engagement_objection_weak
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:lesser }
						desc = lmf_engagement_objection_lesser
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:lazy }
						desc = lmf_engagement_objection_lazy
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:deceitful }
						desc = lmf_engagement_objection_deceitful
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:craven }
						desc = lmf_engagement_objection_craven
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:shy }
						desc = lmf_engagement_objection_shy
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:bold }
						desc = lmf_engagement_objection_bold
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:meek }
						desc = lmf_engagement_objection_meek
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:drunkard }
						desc = lmf_engagement_objection_drunkard
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:sad }
						desc = lmf_engagement_objection_sad
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:crazy }
						desc = lmf_engagement_objection_crazy
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:unkind }
						desc = lmf_engagement_objection_unkind
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:prude }
						desc = lmf_engagement_objection_prude
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:unfaithful }
						desc = lmf_engagement_objection_unfaithful
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:too_young }
						desc = lmf_engagement_objection_too_young
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:too_old }
						desc = lmf_engagement_objection_too_old
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:much_too_young }
						desc = lmf_engagement_objection_much_too_young
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:much_too_old }
						desc = lmf_engagement_objection_much_too_old
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:unlike }
						desc = lmf_engagement_objection_unlike
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:std }
						desc = lmf_engagement_objection_std
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:reputation }
						desc = lmf_engagement_objection_reputation
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:faith }
						desc = lmf_engagement_objection_faith
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:culture }
						desc = lmf_engagement_objection_culture
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:child }
						desc = lmf_engagement_objection_child
					}
					triggered_desc = {
						trigger = { scope:objection_3 = flag:unremarkable }
						desc = lmf_engagement_objection_unremarkable
					}
					desc = lmf_engagement_objection_unremarkable
				}
			}
		}
		desc = lmf_heir.2002.desc.end
	}
	theme = family

	left_portrait = {
		character = scope:betrothed_1
		triggered_animation = {
			trigger = {
				scope:betrothed_1 = {
					has_personality_submissive_trigger = yes
				}
			}
			animation = shame
		}
		triggered_animation = {
			trigger = {
				scope:betrothed_1 = {
					OR = {
						has_personality_dominant_trigger = yes
						has_personality_malicious_trigger = yes
					}
				}
			}
			animation = anger
		}
		animation = beg
	}
	lower_right_portrait = scope:betrothed_2
	lower_center_portrait = {
		trigger = { exists = scope:betrothed_lover }
		character = scope:betrothed_lover
	}

	immediate = {
		# grab the child's current lover
		if = {
			limit = {
				scope:betrothed_1 = {
					any_relation = {
						type = lover
						NOT = { this = scope:betrothed_2 }
					}
				}
			}
			scope:betrothed_1 = {
				random_relation = {
					type = lover
					limit = {
						basic_is_available_ai = yes
						bp2_valid_for_standard_interactions_trigger = yes
						NOR = {
							is_close_or_extended_family_of = scope:betrothed_1
							has_relation_rival = root
							has_relation_lover = root
							root = { has_imprisonment_reason = prev }
							is_at_war_with = root
							is_consort_of = root
							betrothed ?= root
							liege ?= { is_at_war_with = root }
							is_concubine = yes
							is_diarch = yes
							AND = {
								exists = inspiration
								has_completed_inspiration = no
							}
						}
						# but only if it's possible they might marry
						unlikely_to_commit = no
						OR = {
							AND = {
								can_be_introduced_character_trigger = { CHARACTER = scope:betrothed_1 }
								can_be_ordered_to_wed_by = { LIEGE = root }
							}
							AND = {
								can_be_ordered_to_abandon_vows_by = { LIEGE = root }
								is_married = no
								is_betrothed = no
							}
							can_be_ordered_to_break_betrothal_by = { LIEGE = root }
						}
					}
					save_scope_as = betrothed_lover
				}
			}
		}

		# set the scopes for the breaking betrothal, in case they're needed
		save_scope_as = actor
		scope:betrothed_1 = {
			save_scope_as = recipient
			save_scope_as = rejecting_betrothed
		}
		scope:betrothed_2 = {
			save_scope_as = rejected_betrothed
			if = {
				limit = {
					matchmaker ?= {
						NOT = { this = scope:rejected_betrothed }
						is_close_or_extended_family_of = scope:rejected_betrothed
					}
				}
				matchmaker = { save_scope_as = rejected_betrothal_owner }
			}
			else = {
				save_scope_as = rejected_betrothal_owner
			}
		}

		# grab three objections for the loc, if this is a player
		if = {
			limit = { is_ai = no }
			scope:betrothed_1 = {
				lmf_pick_engagement_objection = yes
				lmf_pick_engagement_objection = yes
				lmf_pick_engagement_objection = yes
			}
		}
		else = {
			save_scope_value_as = { name = objection_1 value = flag:fallthrough }
		}
	}

	option = {
		name = lmf_heir.2002.a # I'll allow it, for now
		scope:betrothed_1 = {
			add_opinion = { target = root modifier = grateful_opinion opinion = 30 }
			add_trait_force_tooltip = will_not_wed
			hidden_effect = {
				create_story = {
					type = lmf_will_not_wed_story_cycle
				}
			}
		}
		improve_relationship_effect = {
			TARGET = scope:betrothed_1
			REASON = allowed_to_marry_at_will
		}
		lmf_end_betrothal_effect = yes

		# add opinion that will prevent re-engagement later
		scope:betrothed_1 = {
			hidden_effect = {
				add_opinion = { target = scope:betrothed_2 modifier = ended_engagement_opinion }
				reverse_add_opinion = { target = scope:betrothed_2 modifier = ended_engagement_opinion }
			}
		}

		ai_chance = {
			base = 50
			opinion_modifier = {
				who = root
				opinion_target = scope:betrothed_1
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_compassion = 1
			}
			modifier = {
				add = 50
				scope:betrothed_1 = {
					lmf_has_wrong_lineality_betrothal = yes
					lmf_should_have_proper_lineality = { RULER = root }
				}
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.2002.b # You don't have to marry him, but you will marry
		reverse_add_opinion = { target = scope:betrothed_1 modifier = grateful_opinion opinion = 20 }
		lmf_end_betrothal_effect = yes

		# add opinion that will prevent re-engagement later
		scope:betrothed_1 = {
			hidden_effect = {
				add_character_flag = cannot_get_will_not_wed_trait
				add_opinion = { target = scope:betrothed_2 modifier = ended_engagement_opinion }
				reverse_add_opinion = { target = scope:betrothed_2 modifier = ended_engagement_opinion }
			}
		}

		ai_chance = {
			base = 50
			opinion_modifier = {
				who = root
				opinion_target = scope:betrothed_1
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_rationality = 0.5
			}
			modifier = {
				add = 100
				scope:betrothed_1 = {
					lmf_has_wrong_lineality_betrothal = yes
					lmf_should_have_proper_lineality = { RULER = root }
				}
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.2002.c # You may marry your lover
		trigger = {
			scope:betrothed_lover ?= {
				can_be_introduced_character_trigger = { CHARACTER = scope:betrothed_1 }
				can_be_ordered_to_wed_by = { LIEGE = root }
			}
		}
		lmf_end_betrothal_effect = yes
		lmf_allow_lover_marriage = yes
		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				scope:betrothed_lover = { has_no_particular_noble_roots_trigger = yes }
			}
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.2002.d # Lover will break betrothal and marry you instead
		trigger = {
			scope:betrothed_lover ?= {
				can_be_ordered_to_break_betrothal_by = { LIEGE = root }
			}
		}
		scope:betrothed_lover = { break_betrothal = scope:betrothed_lover.betrothed }
		lmf_end_betrothal_effect = yes
		lmf_allow_lover_marriage = yes
		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				scope:betrothed_lover = { has_no_particular_noble_roots_trigger = yes }
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = -0.3
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.2002.e # Lover will abandon their vows and marry you instead
		trigger = {
			scope:betrothed_lover ?= {
				can_be_ordered_to_abandon_vows_by = { LIEGE = root }
				is_married = no
				is_betrothed = no
			}
		}
		scope:betrothed_lover = { remove_religious_traits_effect = yes }
		lmf_end_betrothal_effect = yes
		lmf_allow_lover_marriage = yes
		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				scope:betrothed_lover = { has_no_particular_noble_roots_trigger = yes }
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_zeal = -0.5
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.2002.f # Are you mad? You'll do as I say!
		custom_tooltip = lmf_heir.2002.f.tt
		scope:betrothed_1 = {
			worsen_relationship_effect = {
				TARGET = root
				REASON = overrode_marriage_wishes
			}
			add_opinion = {
				target = root
				modifier = hate_opinion
				opinion = -50
			}
			add_character_flag = cannot_get_will_not_wed_trait

			# possible reaction
			hidden_effect = {
				random_list = {
					# nothing happens
					10 = {
						ai_value_modifier = {
							ai_rationality = 0.25
							min = 0
						}
						ai_value_modifier = {
							ai_boldness = -0.25
							min = 0
						}
						ai_value_modifier = {
							ai_vengefulness = -0.25
							min = 0
						}
						modifier = {
							scope:betrothed_1 = { has_trait = fickle }
							add = 100
						}
						modifier = {
							OR = {
								ai_rationality <= -100
								ai_boldness >= 100
								ai_vengefulness >= 100
								has_trait = stubborn
							}
							factor = 0
						}
					}
					# mild response
					60 = {
						ai_value_modifier = {
							ai_rationality = 0.5
							min = 0
						}
						ai_value_modifier = {
							ai_boldness = -0.5
							min = 0
						}
						ai_value_modifier = {
							ai_vengefulness = -0.5
							min = 0
						}
						random_list = {
							4 = {
								trigger = {
									NOT = { has_trait = depressed }
								}
								trait:depressed_1 = { save_scope_as = trait_added }
							}
							1 = {
								trigger = { can_be_drunkard = yes }
								trait:drunkard = { save_scope_as = trait_added }
							}
							1 = {
								trigger = { can_be_inappetetic = yes }
								trait:inappetetic = { save_scope_as = trait_added }
							}
							1 = {
								trigger = { can_be_comfort_eater = yes }
								trait:comfort_eater = { save_scope_as = trait_added }
							}
							1 = {
								trigger = { can_be_irritable = yes }
								trait:irritable = { save_scope_as = trait_added }
							}
							1 = {
								trigger = { can_be_reclusive = yes }
								trait:reclusive = { save_scope_as = trait_added }
							}
							1 = {
								trigger = { can_be_hashishiyah = yes }
								trait:hashishiyah = { save_scope_as = trait_added }
							}
							1 = {}
						}
						if = {
							limit = { exists = scope:trait_added }
							root = {
								send_interface_message = {
									type = event_generic_neutral
									title = lmf_heir.2002.mild.tt
									left_icon = scope:betrothed_1
									scope:betrothed_1 = {
										add_trait_force_tooltip = scope:trait_added
									}
								}
							}
						}
					}
					# moderate response
					20 = {
						ai_value_modifier = {
							ai_rationality = -0.5
							min = 0
						}
						ai_value_modifier = {
							ai_boldness = 0.5
							min = 0
						}
						ai_value_modifier = {
							ai_vengefulness = 0.5
							min = 0
						}
						random_list = {
							# refuses marriage with anyone
							75 = {
								root = { trigger_event = lmf_heir.2004 }
							}
							# will become betrothed's rival
							25 = {
								trigger = {
									can_set_relation_rival_trigger = { CHARACTER = scope:betrothed_2 }
								}
								set_relation_rival = { reason = rival_forced_betrothal target = scope:betrothed_2 }
							}
						}
					}
					# extreme response
					10 = {
						ai_value_modifier = {
							ai_rationality = -0.25
							min = 0
						}
						ai_value_modifier = {
							ai_boldness = 0.25
							min = 0
						}
						ai_value_modifier = {
							ai_vengefulness = 0.25
							min = 0
						}
						modifier = {
							has_trait = stubborn
							add = 100
						}
						modifier = {
							OR = {
								ai_rationality >= 100
								ai_boldness <= -100
								ai_vengefulness <= -100
								has_trait = fickle
							}
							factor = 0
						}
						random_list = {
							# starts an elope story with lover
							# we use this since either party might not be able to start a scheme right this moment
							# and the story will guide them towards it
							200 = {
								trigger = {
									lmf_betrothed_lover_elope_possible = yes
								}
								modifier = {
									scope:betrothed_lover = { is_married = yes }
									factor = 0.25
								}
								scope:betrothed_1 = {
									set_variable = { name = waiting_to_elope value = scope:proposer_target years = 20 }
									create_story = { type = lmf_waiting_to_elope_story_cycle }
								}
								scope:betrothed_lover = {
									set_variable = { name = waiting_to_elope value = scope:proposer years = 20 }
									create_story = {
										type = lmf_waiting_to_elope_story_cycle
										save_scope_as = story
									}
									scope:story = {
										set_variable = { name = elope_promised value = 10 }
									}
								}
							}
							# leaves the court
							50 = {
								ai_value_modifier = {
									ai_zeal = -0.5
								}
								min = 25
								max = 75
								save_scope_value_as = { name = path value = flag:leave }
								root = { trigger_event = lmf_heir.2006 }
							}
							# holy order
							0 = {
								trigger = {
									NOR = {
										has_trait = devoted
										has_trait = order_member
										any_heir_title = {}
										is_pregnant = yes
									}
									pool_character_can_go_to_holy_order = { CHARACTER = root }
									lmf_betrothed_lover_elope_possible = no
								}
								modifier = {
									add = 20
									religion = { exists = var:variable_ghw_unlocked }
								}
								modifier = {
									add = 100
									faith = { exists = great_holy_war }
								}
								ai_value_modifier = {
									ai_zeal = 1.0
									ai_honor = 0.5
									ai_boldness = 0.5
								}
								modifier = {
									any_heir_title = {}
									factor = 0.5
								}
								modifier = {
									has_education_martial_trigger = no
									factor = 0.5
								}
								min = 0
								save_scope_value_as = { name = path value = flag:holyorder }
								root = { trigger_event = lmf_heir.2006 }
							}
							# devoted
							0 = {
								trigger = {
									NOR = {
										has_trait = devoted
										has_trait = order_member
										any_heir_title = {}
										is_pregnant = yes
									}
									pool_character_can_take_holy_vows = { CHARACTER = root }
									lmf_betrothed_lover_elope_possible = no
								}
								ai_value_modifier = {
									ai_zeal = 1
								}
								modifier = {
									any_heir_title = {}
									factor = 0.5
								}
								modifier = {
									pool_character_can_go_to_holy_order = { CHARACTER = root }
									factor = 0.5
								}
								modifier = {
									has_education_learning_trigger = no
									factor = 0.5
								}
								min = 0
								save_scope_value_as = { name = path value = flag:devoted }
								root = { trigger_event = lmf_heir.2006 }
							}
							# death
							10 = {
								trigger = {
									OR = {
										has_trait = depressed
										ai_rationality <= high_negative_ai_value
										has_personality_emotional_trigger = yes
									}
								}
								root = { trigger_event = lmf_heir.2005 }
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 50
				exists = scope:betrothed_lover
			}
			ai_value_modifier = {
				ai_honor = 1
				min = 0
			}
			modifier = {
				add = 200
				scope:betrothed_1 = { has_been_promised_grand_wedding = yes }
			}
			modifier = {
				add = 100
				yields_alliance = {
					candidate = scope:betrothed_1
					target = scope:rejected_betrothal_owner
					target_candidate = scope:rejected_betrothed
				}
			}
			modifier = {
				add = 50
				scope:rejected_betrothal_owner = { is_powerful_vassal_of = root }
			}
			modifier = {
				add = 100
				exists = var:promised_to_marry_1
				var:promised_to_marry_1 = {
					this = scope:rejected_betrothed
					any_parent = { is_vassal_of = root }
				}
				exists = var:promised_to_marry_2
				var:promised_to_marry_2 = {
					this = scope:betrothed_1
					is_close_family_of = root
				}
			}
			modifier = {
				add = 100
				is_at_war = yes
				any_war_ally = { this = scope:rejected_betrothal_owner }
			}
			min = 1
		}
	}
}

# Notification that the betrothal has been broken
lmf_heir.2003 = {
	type = letter_event
	opening = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = { this = scope:rejecting_betrothed }
				}
				desc = lmf_heir.2003.opening.harsh
			}
			desc = lmf_heir.2003.opening.apologetic
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = { this = scope:rejecting_betrothed }
				}
				desc = {
					desc = lmf_heir.2003.betrothed.start
					first_valid = {
						triggered_desc = {
							trigger = { this = scope:rejected_betrothed }
							desc = lmf_heir.2003.betrothed.torejected
						}
						desc = lmf_heir.2003.betrothed.toliege
					}
					desc = lmf_heir.2003.betrothed.end
				}
			}
			desc = {
				desc = lmf_heir.2003.start
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:rejected_betrothed }
						desc = lmf_heir.2003.torejected
					}
					desc = lmf_heir.2003.toliege
				}
				desc = lmf_heir.2003.end
			}
		}
	}
	sender = {
		character = scope:actor
		triggered_animation = {
			trigger = { scope:actor = scope:rejecting_betrothed }
			animation = dismissal
		}
		animation = shame
	}

	immediate = {
		if = {
			limit = {
				NOT = { scope:actor = scope:rejecting_betrothed }
			}
			scope:rejecting_betrothed = { save_scope_as = betrothed_portrait }
		}
	}

	option = {
		name = lmf_heir.2003.a
		add_opinion = {
			target = scope:actor
			modifier = broke_betrothal_opinion
		}
		show_as_tooltip = {
			scope:rejecting_betrothed = {
				break_betrothal = scope:rejected_betrothed
			}
		}
	}

	after = {
		hidden_effect = {
			if = {
				limit = { this = scope:rejected_betrothed }
				scope:rejecting_betrothed = {
					break_betrothal = scope:rejected_betrothed
				}
			}
		}
	}
}

# Child refuses to marry
lmf_heir.2004 = {
	type = character_event
	title = lmf_heir.2004.t
	desc = lmf_heir.2004.desc
	theme = family

	left_portrait = {
		character = scope:betrothed_1
		animation = disgust
	}

	immediate = {
		# first switch the scopes so the child can end the betrothal directly
		scope:betrothed_1 = { save_scope_as = actor }
		scope:betrothed_2 = { save_scope_as = recipient }

		# now end the betrothal - even though some traits would end it automatically,
		# we still want the opinion changes and notifications
		save_scope_as = actor_liege
		lmf_end_betrothal_effect = yes

		# add opinion that will prevent re-engagement later
		scope:betrothed_1 = {
			hidden_effect = {
				add_opinion = { target = scope:betrothed_2 modifier = ended_engagement_opinion }
				reverse_add_opinion = { target = scope:betrothed_2 modifier = ended_engagement_opinion }
			}
			# and start the story
			remove_character_flag = cannot_get_will_not_wed_trait
			add_trait = will_not_wed
			hidden_effect = {
				create_story = {
					type = lmf_will_not_wed_story_cycle
				}
			}
		}
	}

	option = {
		name = lmf_heir.2004.a
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
			}
			min = 1
		}
	}
	option = {
		name = lmf_heir.2004.b
		rightfully_imprison_character_effect = {
			TARGET = scope:betrothed_1
			IMPRISONER = root
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_vengefulness = 1
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.2004.c
		scope:betrothed_1 = {
			if = {
				limit = {
					root.culture = {
						NOT = { has_cultural_parameter = cannot_disherit }
					}
				}
				disinherit_effect = { DISINHERITOR = root }
				add_character_flag = made_disinherit_demand #so they won't challenge it later
			}
			banish = yes
			add_opinion = { modifier = banished_me target = root }
			hidden_effect = {
				random_owned_story = {
					type = lmf_will_not_wed_story_cycle
					end_story = yes
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_vengefulness = 0.5
			}
			min = 0
		}
	}
}

# Child commits suicide after being refused
lmf_heir.2005 = {
	type = character_event
	title = lmf_heir.2005.t
	desc = lmf_heir.2005.desc
	theme = death

	left_portrait = {
		character = root
		animation = grief
	}
	right_portrait = {
		character = scope:betrothed_1
		animation = dead
	}
	override_background = { reference = ce1_catacombs }

	immediate = {
		scope:betrothed_1 = {
			if = {
				limit = {
					NOR = {
						has_trait = depressed
						has_trait = possessed
						has_trait = lunatic
					}
				}
				add_trait = depressed_1
			}
			death = { death_reason = death_suicide }
		}
	}

	option = {
		name = lmf_heir.2005.a
	}
}

# Child leaves court after being refused
lmf_heir.2006 = {
	type = letter_event
	opening = lmf_heir.2006.opening
	desc = {
		desc = lmf_heir.2006.start
		first_valid = {
			triggered_desc = {
				trigger = { scope:path = flag:leave }
				desc = lmf_heir.2006.leave
			}
			triggered_desc = {
				trigger = { scope:path = flag:holyorder }
				desc = lmf_heir.2006.holyorder
			}
			triggered_desc = {
				trigger = { scope:path = flag:devoted }
				desc = lmf_heir.2006.devoted
			}
			desc = lmf_heir.2006.leave
		}
	}
	sender = {
		character = scope:betrothed_1
		animation = disgust
	}

	immediate = {
		# first switch the scopes so the child can end the betrothal directly
		scope:betrothed_1 = { save_scope_as = actor }
		scope:betrothed_2 = { save_scope_as = recipient }

		# now end the betrothal - even though some traits would end it automatically,
		# we still want the opinion changes and notifications
		save_scope_as = actor_liege
		lmf_end_betrothal_effect = yes

		# add opinion that will prevent re-engagement later
		scope:betrothed_1 = {
			hidden_effect = {
				add_opinion = { target = scope:betrothed_2 modifier = ended_engagement_opinion }
				reverse_add_opinion = { target = scope:betrothed_2 modifier = ended_engagement_opinion }
			}
		}

		# now make the specific changes for their chosen path
		if = {
			limit = { scope:path = flag:holyorder }
			scope:betrothed_1 = {
				create_character_memory = {
					type = lmf_memory_left_court
					participants = { court = root }
				}
				scope:new_memory = {
					set_variable = {
						name = liege_title
						value = root.primary_title
					}
				}
				pool_character_join_holy_order = { CHARACTER = scope:betrothed_1 }
				remove_character_flag = cannot_get_will_not_wed_trait
				add_character_modifier = {
					modifier = lust_for_adventure
					years = 10
				}
			}
		}
		else_if = {
			limit = { scope:path = flag:devoted }
			scope:betrothed_1 = {
				create_character_memory = {
					type = lmf_memory_left_court
					participants = { court = root }
				}
				scope:new_memory = {
					set_variable = {
						name = liege_title
						value = root.primary_title
					}
				}
				pool_character_take_vows = { CHARACTER = scope:betrothed_1 }
				remove_character_flag = cannot_get_will_not_wed_trait
				add_character_modifier = {
					modifier = lust_for_adventure
					years = 5
				}
			}
		}
		else = {
			scope:betrothed_1 = {
				remove_character_flag = cannot_get_will_not_wed_trait
				lose_guardians_and_wards_effect = { LIEGE = root COURTIER = scope:betrothed_1 }
				add_trait_force_tooltip = will_not_wed
				hidden_effect = {
					create_story = {
						type = lmf_will_not_wed_story_cycle
					}
				}
				add_character_modifier = { modifier = lust_for_adventure years = 10 }
				create_character_memory = {
					type = lmf_memory_left_court
					participants = { court = root }
				}
				scope:new_memory = {
					set_variable = {
						name = liege_title
						value = root.primary_title
					}
				}
				lmf_move_to_pool_effect = yes
			}
		}
	}

	option = {
		trigger = {
			NOT = { scope:path = flag:leave }
		}
		name = {
			trigger = { scope:path = flag:holyorder }
			text = lmf_heir.2006.a.holyorder
		}
		name = {
			trigger = { scope:path = flag:devoted }
			text = lmf_heir.2006.a.devoted
		}
		ai_chance = {
			base = 100
		}
	}
	option = {
		trigger = {
			scope:path = flag:leave
			NOT = {
				culture = { has_cultural_parameter = cannot_disherit }
			}
		}
		name = lmf_heir.2006.a.leave #If that's what she wants, she needn't return here. Ever!
		stress_impact = {
			forgiving = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		scope:betrothed_1 = {
			hidden_effect = {
				random_owned_story = {
					type = lmf_will_not_wed_story_cycle
					end_story = yes
				}
			}
			disinherit_effect = { DISINHERITOR = root }
			add_character_flag = made_disinherit_demand #so they won't challenge it later
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 1
			}
			min = 0
		}
	}
	option = {
		trigger = { scope:path = flag:leave }
		name = lmf_heir.2006.b.leave #She'll return, in time. I'm certain of it.
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
			}
			min = 1
		}
	}
}

### Betrothal renegotiation

# bounce event to determine whether lineality needs to be renegotiated
lmf_heir.2020 = {
	type = character_event
	hidden = yes

	trigger = {
		exists = betrothed
		NOT = { has_game_rule = lmf_no_betrothal_objection }
	}

	immediate = {
		# check to see if there's a matchmaker
		if = {
			limit = {
				exists = matchmaker
				exists = dynasty
				matchmaker = {
					is_ai = yes
					dynasty ?= root.dynasty
					highest_held_title_tier >= tier_county
					# who will stand up for them (or themselves)
					trigger_if = {
						limit = {
							top_liege != this
							is_powerful_vassal = no
						}
						NOR = {
							target_is_liege_or_above = root.betrothed
							target_is_liege_or_above = root.betrothed.matchmaker
							has_dread_level_towards = { target = root.betrothed level >= 1 }
							has_dread_level_towards = { target = root.betrothed.matchmaker level >= 1 }
						}
					}
					NOR = {
						has_trait_rank = { trait = intellect_bad rank > 1 }
						ai_honor >= very_high_positive_ai_value
						AND = {
							has_personality_submissive_trigger = yes
							OR = {
								target_is_liege_or_above = root.betrothed
								target_is_liege_or_above = root.betrothed.matchmaker
								has_dread_level_towards = { target = root.betrothed level >= 1 }
								has_dread_level_towards = { target = root.betrothed.matchmaker level >= 1 }
								highest_held_title_tier_plus_one < root.betrothed.highest_held_title_tier
								highest_held_title_tier_plus_one < root.betrothed.matchmaker.highest_held_title_tier
							}
						}
						AND = {
							ai_zeal >= 100
							ai_compassion <= low_positive_ai_value
							root = {
								is_wrong_gender_in_faith_trigger = { FAITH = root.faith }
								this != root.matchmaker
							}
						}
					}
					# and can actually break the betrothal
					is_character_interaction_valid = {
						recipient = root.betrothed
						interaction = break_betrothal_interaction
					}
				}
			}
			matchmaker = { save_scope_as = actor }
			# check to see if they're an heir or ruler in a wrong-lineality betrothal
			if = {
				limit = {
					is_ai = yes
					lmf_has_wrong_lineality_betrothal = yes
					lmf_should_have_proper_lineality = { RULER = scope:actor }
					trigger_if = {
						limit = { is_female = yes }
						NOT = { has_game_rule = matrilineal_marriages_never }
						trigger_if = {
							limit = { has_game_rule = matrilineal_marriages_female_and_equal }
							OR = {
								scope:actor = { has_realm_law = equal_law }
								faith = { has_doctrine_parameter = gender_equal_law }
							}
						}
						trigger_if = {
							limit = { has_game_rule = matrilineal_marriages_no_player_exception }
							OR = {
								dynasty = { dynasty_prestige_level >= 4 }
								scope:actor.highest_held_title_tier >= tier_duchy
								scope:actor = { has_realm_law = equal_law }
								faith = { has_doctrine_parameter = gender_equal_law }
							}
						}
						trigger_if = {
							limit = { has_game_rule = default_matrilineal_marriages }
							OR = {
								dynasty = { dynasty_prestige_level >= 4 }
								scope:actor.highest_held_title_tier >= tier_duchy
								scope:actor = { has_realm_law = equal_law }
								faith = { has_doctrine_parameter = gender_equal_law }
								any_player = {
									exists = dynasty
									dynasty = root.dynasty
									is_close_family_of = root
								}
							}
						}
					}
				}
				# save all the needed scopes
				save_scope_as = recipient
				save_scope_as = rejecting_betrothed
				betrothed = {
					save_scope_as = rejected_betrothed
					if = {
						limit = {
							matchmaker ?= {
								NOT = { this = scope:rejected_betrothed }
							}
						}
						matchmaker = { save_scope_as = rejected_betrothal_owner }
					}
					else = {
						save_scope_as = rejected_betrothal_owner
					}
				}
				save_scope_value_as = { name = no_notification value = yes }
				# now send the letter
				scope:rejected_betrothal_owner = { trigger_event = lmf_heir.2021 }
			}
			else = {
				if = {
					limit = {
						betrothed = { is_adult = yes }
					}
					betrothed = {
						trigger_event = lmf_heir.2020
					}
				}
			}
		}
		else = {
			if = {
				limit = {
					betrothed = { is_adult = yes }
				}
				betrothed = {
					trigger_event = lmf_heir.2020
				}
			}
		}
	}
}

# letter demanding renegotiation of betrothal
lmf_heir.2021 = {
	type = letter_event
	opening = lmf_heir.2021.opening
	desc = {
		desc = lmf_heir.2021.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = {
						this = scope:rejecting_betrothed
						is_ruler = yes
					}
				}
				desc = lmf_heir.2021.self.ruler
			}
			triggered_desc = {
				trigger = {
					scope:actor = {
						this = scope:rejecting_betrothed
						any_heir_title = {}
					}
				}
				desc = lmf_heir.2021.self.heir
			}
			triggered_desc = {
				trigger = {
					scope:actor = {
						this = scope:rejecting_betrothed
					}
				}
				desc = lmf_heir.2021.self.default
			}
			triggered_desc = {
				trigger = {
					scope:rejecting_betrothed = {
						is_ruler = yes
					}
				}
				desc = lmf_heir.2021.other.ruler
			}
			triggered_desc = {
				trigger = {
					scope:rejecting_betrothed = {
						any_heir_title = {}
					}
				}
				desc = lmf_heir.2021.other.heir
			}
			desc = lmf_heir.2021.other.default
		}
		desc = lmf_heir.2021.mid
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = {
						this = scope:rejecting_betrothed
					}
					scope:rejected_betrothed = {
						this = scope:rejected_betrothal_owner
					}
				}
				desc = lmf_heir.2021.self.withtarget
			}
			triggered_desc = {
				trigger = {
					scope:actor = {
						this = scope:rejecting_betrothed
					}
				}
				desc = lmf_heir.2021.self.withother
			}
			triggered_desc = {
				trigger = {
					scope:rejected_betrothed = {
						this = scope:rejected_betrothal_owner
					}
				}
				desc = lmf_heir.2021.other.withtarget
			}
			desc = lmf_heir.2021.other.withother
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:rejecting_betrothed = { is_female = yes }
				}
				desc = lmf_heir.2021.matrilineal
			}
			desc = lmf_heir.2021.patrilineal
		}
		desc = lmf_heir.2021.end
	}
	sender = scope:actor

	# these triggers are things that will prevent the rejected betrothal owner from cancelling the betrothal
	trigger = {
		NOR = {
			# they've cancelled a betrothal previously
			has_opinion_modifier = { modifier = broke_betrothal_opinion target = scope:actor }
			has_opinion_modifier = { modifier = broke_betrothal_grand_wedding_opinion target = scope:actor }
			has_opinion_modifier = { modifier = renegotiated_betrothal_opinion target = scope:actor }
			# I have a hook on them
			has_strong_hook = scope:actor
			# they're allies at war and the marriage is where the alliance comes from
			AND = {
				is_ruler = yes
				scope:actor = { is_ruler = yes }
				is_allied_in_war = scope:actor
				yields_alliance = {
					candidate = scope:rejected_betrothed
					target = scope:actor
					target_candidate = scope:rejecting_betrothed
				}
			}
		}
	}

	option = {
		name = lmf_heir.2021.a # Very well, I agree to your terms
		if = {
			limit = {
				scope:rejecting_betrothed = { is_female = yes }
			}
			custom_tooltip = lmf_heir.2021.a.matrilineal.tt
		}
		else = {
			custom_tooltip = lmf_heir.2021.a.patrilineal.tt
		}
		scope:rejecting_betrothed = {
			hidden_effect = {
				break_betrothal = scope:rejected_betrothed
				if = {
					limit = { is_female = yes }
					create_betrothal_matrilineal = scope:rejected_betrothed
				}
				else = {
					create_betrothal = scope:rejected_betrothed
				}
			}
		}
		add_opinion = {
			target = scope:actor
			modifier = renegotiated_betrothal_opinion
		}
		send_interface_message = {
			type = event_generic_good
			title = lmf_heir.2021.a.title
			left_icon = scope:rejecting_betrothed
			right_icon = scope:rejected_betrothed
			scope:rejecting_betrothed = {
				if = {
					limit = { is_female = yes }
					show_as_tooltip = { create_betrothal_matrilineal = scope:rejected_betrothed }
				}
				else = {
					show_as_tooltip = { create_betrothal = scope:rejected_betrothed }
				}
			}
		}
		scope:actor = {
			send_interface_message = {
				type = event_generic_good
				title = lmf_heir.2021.a.title
				left_icon = scope:rejecting_betrothed
				right_icon = scope:rejected_betrothed
				scope:rejecting_betrothed = {
					if = {
						limit = { is_female = yes }
						show_as_tooltip = { create_betrothal_matrilineal = scope:rejected_betrothed }
					}
					else = {
						show_as_tooltip = { create_betrothal = scope:rejected_betrothed }
					}
				}
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = -0.5
				ai_rationality = 0.5
			}
			modifier = {
				add = 75
				scope:rejected_betrothed = {
					NOR = {
						any_pretender_title = {
							holder ?= root
							place_in_line_of_succession = {
								target = scope:rejected_betrothed
								value <= 4
							}
						}
						any_pretender_title = {
							place_in_line_of_succession = {
								target = scope:rejected_betrothed
								value <= 2
							}
						}
					}
				}
			}
			modifier = {
				add = 75
				scope:rejected_betrothed = {
					OR = {
						is_illegitimate = yes
						has_trait = disputed_heritage
						has_trait = disinherited
						has_trait = denounced
					}
				}
			}
			modifier = {
				add = 50
				highest_held_title_tier <= scope:actor.highest_tier_minus_2
			}
			modifier = {
				factor = 0
				scope:rejected_betrothed = {
					lmf_should_have_proper_lineality = { RULER = root }
				}
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.2021.b # I'll allow the betrothal to end, but we should maintain our alliance
		trigger = {
			is_ruler = yes
			scope:actor = { is_ruler = yes }
			is_allied_to = scope:actor
			yields_alliance = {
				candidate = scope:rejected_betrothed
				target = scope:actor
				target_candidate = scope:rejecting_betrothed
			}
			OR = {
				diplomacy >= 20
				has_perk = defensive_negotiations_perk
			}
		}
		show_as_unavailable = {
			is_ruler = yes
			scope:actor = { is_ruler = yes }
			is_allied_to = scope:actor
			yields_alliance = {
				candidate = scope:rejected_betrothed
				target = scope:actor
				target_candidate = scope:rejecting_betrothed
			}
			NOR = {
				diplomacy >= 20
				has_perk = defensive_negotiations_perk
			}
		}
		skill = diplomacy
		custom_tooltip = lmf_heir.2021.b.tt
		hidden_effect = {
			add_opinion = { modifier = event_negotiated_alliance_opinion target = scope:actor }
			reverse_add_opinion = { modifier = event_negotiated_alliance_opinion target = scope:actor }
		}
		scope:rejecting_betrothed = {
			break_betrothal = scope:rejected_betrothed
			hidden_effect = {
				add_opinion = { target = scope:rejected_betrothed modifier = ended_engagement_opinion }
				reverse_add_opinion = { target = scope:rejected_betrothed modifier = ended_engagement_opinion }
			}
		}
		create_alliance = {
			target = scope:actor
			allied_through_owner = root
			allied_through_target = scope:actor
		}
		add_opinion = {
			target = scope:actor
			modifier = renegotiated_betrothal_opinion
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 1.0
			}
			min = 0
		}
	}
	option = {
		name = lmf_heir.2021.c # The betrothal will not be renegotiated just because you wish it so!
		lmf_end_betrothal_effect = yes
		scope:rejecting_betrothed = {
			hidden_effect = {
				add_opinion = { target = scope:rejected_betrothed modifier = ended_engagement_opinion }
				reverse_add_opinion = { target = scope:rejected_betrothed modifier = ended_engagement_opinion }
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_vengefulness = 1.0
				ai_greed = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:actor
				multiplier = -0.5
				min = -20
			}
			modifier = {
				add = 50
				scope:actor.highest_held_title_tier <= root.highest_tier_minus_2
			}
			modifier = {
				add = 50
				scope:rejected_betrothed = {
					OR = {
						any_pretender_title = {
							holder ?= root
							place_in_line_of_succession = {
								target = scope:rejected_betrothed
								value <= 4
							}
						}
						any_pretender_title = {
							place_in_line_of_succession = {
								target = scope:rejected_betrothed
								value <= 2
							}
						}
					}
					NOT = {
						lmf_should_have_proper_lineality = { RULER = root }
					}
				}
			}
			modifier = {
				add = 50
				has_trait = arrogant
			}
			modifier = {
				add = 25
				has_trait = ambitious
			}
			modifier = {
				add = 25
				has_trait = stubborn
			}
			modifier = {
				factor = 0.5
				is_ruler = no
			}
			min = 1
		}
	}
}


###########################
# ALLOW LOVE MATCH EVENTS #
###########################

# Initial response to interaction - family member has lover they can marry
lmf_heir.2050 = {
	type = character_event
	title = lmf_heir.2050.t
	desc = {
		desc = lmf_heir.2050.start
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:knows_secret }
				desc = lmf_heir.2050.knows
			}
			desc = lmf_heir.2050.secret
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:heir = { has_relation_soulmate = scope:heir_lover } }
				desc = lmf_heir.2050.soulmate
			}
			desc = lmf_heir.2050.lover
		}
		desc = lmf_heir.2050.end
	}
	theme = family
	
	left_portrait = {
		character = scope:heir
		animation = shame
		camera = camera_event_right
	}
	override_background = { reference = relaxing_room }
	lower_right_portrait = scope:heir_lover
	
	immediate = {
		scope:heir = {
			add_character_flag = no_hat
			save_scope_as = proposer
			if = {
				limit = {
					any_secret = {
						type = secret_lover
						secret_target = scope:heir_lover
						NOT = { is_known_by = root }
					}
				}
				random_secret = {
					type = secret_lover
					limit = {
						secret_target = scope:heir_lover
						NOT = { is_known_by = root }
					}
					reveal_to = root
				}
			}
			else = {
				save_scope_value_as = { name = knows_secret value = yes }
			}
			if = {
				limit = {
					OR = {
						AND = {
							is_female = yes
							any_heir_title = {}
							NOR = {
								has_trait = content
								has_trait = humble
							}
							trigger_if = {
								limit = { has_game_rule = matrilineal_marriages_never }
								OR = {
									host = { has_realm_law = female_only_law }
									host = { has_realm_law = female_preference_law }
									faith = { has_doctrine_parameter = female_dominated_law }
								}
							}
							trigger_if = {
								limit = { has_game_rule = matrilineal_marriages_female_and_equal }
								OR = {
									host = { has_realm_law = female_only_law }
									host = { has_realm_law = female_preference_law }
									host = { has_realm_law = equal_law }
									faith = { has_doctrine_parameter = female_dominated_law }
								}
							}
						}
						AND = {
							scope:heir_lover = {
								is_female = yes
								OR = {
									is_ruler = yes
									any_heir_title = {}
								}
							}
							NOR = {
								any_heir_title = {}
								AND = {
									is_close_family_of = root
									scope:heir_lover = { is_ruler = yes }
									root.highest_held_title_tier > scope:heir_lover.highest_held_title_tier_plus_one
								}
								AND = {
									is_close_family_of = root
									scope:heir_lover = {
										is_ruler = no
										NOT = {
											any_heir_title = { tier >= root.highest_held_title_tier_minus_one }
										}
									}
								}
							}
						}
					}
				}
				save_scope_value_as = { name = matrilineal value = yes }
			}
			else = {
				save_scope_value_as = { name = matrilineal value = no }
			}
		}
		scope:heir_lover = {
			save_scope_as = proposer_target
			if = {
				limit = {
					is_courtier = yes
					NOT = { is_courtier_of = root }
					exists = liege
				}
				save_scope_value_as = { name = needs_liege_permission value = yes }
			}
			else_if = {
				limit = { is_ruler = yes }
				save_scope_value_as = { name = needs_their_permission value = yes }
			}
			else = {
				save_scope_value_as = { name = needs_no_permission value = yes }
			}
		}
		save_scope_value_as = { name = hook value = no }
		save_scope_value_as = { name = grand_wedding_promise value = no }
		save_scope_value_as = { name = influence_send_option value = no }
		save_scope_value_as = { name = herd_send_option value = no }
	}
	
	option = {
		name = lmf_heir.2050.a #Unsuitable choice - they need to break up
		if = {
			limit = { has_hook = scope:heir }
			remove_hook = { target = scope:heir }
		}
		if = {
			limit = {
				scope:heir = { has_relation_soulmate = scope:heir_lover }
			}
			scope:heir = {
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = interfered_in_my_romance
					OPINION = -50
				}
			}
			scope:heir_lover = {
				worsen_relationship_effect = {
					TARGET = root
					REASON = interfered_in_my_romance
				}
			}
		}
		else = {
			scope:heir = {
				worsen_relationship_effect = {
					TARGET = root
					REASON = interfered_in_my_romance
				}
			}
		}
		lover_breakup_effect = {
			BREAKER = scope:heir
			LOVER = scope:heir_lover
		}
	}
	option = {
		name = lmf_heir.2050.b #I give them permission
		trigger = { exists = scope:needs_no_permission }
		marriage_permission_given_effect = yes
		courtiers_marry_effect = yes
	}
	option = {
		name = lmf_heir.2050.c #Let's approach their liege and see
		trigger = { exists = scope:needs_liege_permission }
		custom_tooltip = lmf_heir.2050.c.tt
		if = {
			limit = { scope:matrilineal = yes }
			custom_tooltip = lmf_heir.2050.matrilineal.tt
		}
		else = {
			custom_tooltip = lmf_heir.2050.patrilineal.tt
		}
		run_interaction = {
			interaction = arrange_marriage_interaction
			redirect = no
			actor = root
			recipient = scope:heir_lover.liege
			secondary_actor = scope:heir
			secondary_recipient = scope:heir_lover
			send_threshold = decline
		}
		trigger_event = { id = lmf_heir.2053 days = 10 }
	}
	option = {
		name = lmf_heir.2050.d #Let's approach them and see
		trigger = { exists = scope:needs_their_permission }
		custom_tooltip = lmf_heir.2050.d.tt
		if = {
			limit = { scope:matrilineal = yes }
			custom_tooltip = lmf_heir.2050.matrilineal.tt
		}
		else = {
			custom_tooltip = lmf_heir.2050.patrilineal.tt
		}
		run_interaction = {
			interaction = arrange_marriage_interaction
			redirect = no
			actor = root
			recipient = scope:heir_lover
			secondary_actor = scope:heir
			secondary_recipient = scope:heir_lover
			send_threshold = decline
		}
		trigger_event = { id = lmf_heir.2053 days = 10 }
	}
	
	after = {
		scope:heir = { remove_no_hat_effect = yes }
	}
}

# Initial response to interaction - family member has lover they CAN'T marry
lmf_heir.2051 = {
	type = character_event
	title = lmf_heir.2051.t
	desc = {
		desc = lmf_heir.2051.start
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:knows_secret }
				desc = lmf_heir.2051.knows
			}
			desc = lmf_heir.2051.secret
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:heir = { sex_same_as = scope:heir_lover }
					allowed_to_marry_same_sex_trigger = no
				}
				desc = lmf_heir.2051.desc.samesex
			}
			triggered_desc = {
				trigger = { scope:heir_lover = { has_trait = devoted } }
				desc = lmf_heir.2051.desc.devoted
			}
			triggered_desc = {
				trigger = { scope:heir_lover = { has_trait = order_member } }
				desc = lmf_heir.2051.desc.order
			}
			triggered_desc = {
				trigger = { scope:heir_lover = { is_married = yes } }
				desc = lmf_heir.2051.desc.married
			}
			triggered_desc = {
				trigger = { scope:heir_lover = { is_betrothed = yes } }
				desc = lmf_heir.2051.desc.betrothed
			}
			triggered_desc = {
				trigger = {
					scope:heir = { has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root } }
					scope:heir_lover = { has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root } }
				}
				desc = lmf_heir.2051.desc.permission.both
			}
			triggered_desc = {
				trigger = {
					scope:heir = {
						has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root }
						is_female = yes
					}
				}
				desc = lmf_heir.2051.desc.permission.heir.woman
			}
			triggered_desc = {
				trigger = {
					scope:heir = {
						has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root }
						is_female = no
					}
				}
				desc = lmf_heir.2051.desc.permission.heir.man
			}
			triggered_desc = {
				trigger = {
					scope:heir_lover = {
						has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root }
						is_female = yes
					}
				}
				desc = lmf_heir.2051.desc.permission.lover.woman
			}
			triggered_desc = {
				trigger = {
					scope:heir_lover = {
						has_opinion_modifier = { modifier = refused_marriage_permission_opinion target = root }
						is_female = no
					}
				}
				desc = lmf_heir.2051.desc.permission.lover.man
			}
			desc = lmf_heir.2051.desc.generic
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:heir_lover = {
						OR = {
							can_be_ordered_to_abandon_vows_by = { LIEGE = root }
							can_be_ordered_to_break_betrothal_by = { LIEGE = root }
							can_reverse_marriage_refusal = { CHARACTER = scope:heir LIEGE = root }
						}
					}
				}
				desc = lmf_heir.2051.desc.end.canact
			}
			desc = lmf_heir.2051.desc.end
		}
	}
	theme = family
	
	left_portrait = {
		character = scope:heir
		animation = shame
		camera = camera_event_right
	}
	override_background = { reference = relaxing_room }
	lower_right_portrait = scope:heir_lover
	
	immediate = {
		scope:heir = {
			add_character_flag = no_hat
			random_owned_story = {
				type = lmf_will_not_wed_story_cycle
				set_variable = { name = willnotwed_had_lover_revealed value = yes }
			}
			if = {
				limit = {
					any_secret = {
						type = secret_lover
						secret_target = scope:heir_lover
						NOT = { is_known_by = root }
					}
				}
				random_secret = {
					type = secret_lover
					limit = {
						secret_target = scope:heir_lover
						NOT = { is_known_by = root }
					}
					reveal_to = root
				}
			}
			else = {
				save_scope_value_as = { name = knows_secret value = yes }
			}
			save_scope_as = proposer
			save_scope_as = owner
		}
		scope:heir_lover = {
			save_scope_as = proposer_target
			save_scope_as = target
		}
	}

	option = {
		name = lmf_heir.2051.a #They must break up at once
		if = {
			limit = { has_hook = scope:heir }
			remove_hook = { target = scope:heir }
		}
		if = {
			limit = {
				scope:heir = { has_relation_soulmate = scope:heir_lover }
			}
			scope:heir = {
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = interfered_in_my_romance
					OPINION = -50
				}
			}
			scope:heir_lover = {
				worsen_relationship_effect = {
					TARGET = root
					REASON = interfered_in_my_romance
				}
			}
		}
		else = {
			scope:heir = {
				worsen_relationship_effect = {
					TARGET = root
					REASON = interfered_in_my_romance
				}
			}
		}
		lover_breakup_effect = {
			BREAKER = scope:heir
			LOVER = scope:heir_lover
		}
		scope:heir = {
			add_trait_force_tooltip = will_not_wed
			add_character_flag = { flag = directed_to_marry years = 10 }
			hidden_effect = {
				create_story = {
					type = lmf_will_not_wed_story_cycle
				}
			}
		}
	}
	option = {
		trigger = {
			scope:heir_lover = {
				can_reverse_marriage_refusal = { CHARACTER = scope:heir LIEGE = root }
			}
		}
		name = lmf_heir.2051.b #I give my leave for them to marry
		
		allow_heir_marriage_effect = yes
	}
	option = {
		trigger = {
			scope:heir_lover = {
				can_be_ordered_to_abandon_vows_by = { LIEGE = root }
				can_elope_character_trigger = { CHARACTER = scope:heir }
			}
		}
		name = lmf_heir.2051.c #They must abandon their vows and marry
		
		scope:heir_lover = { remove_religious_traits_effect = yes }
		allow_heir_marriage_effect = yes
	}
	option = {
		trigger = {
			scope:heir_lover = {
				can_be_ordered_to_break_betrothal_by = { LIEGE = root }
				could_be_introduced_character_trigger = { CHARACTER = scope:heir }
			}
		}
		name = lmf_heir.2051.d #They must abandon their betrothal and marry
		
		scope:heir_lover = { break_betrothal = scope:heir_lover.betrothed }
		allow_heir_marriage_effect = yes
	}
	option = {
		name = lmf_heir.2051.e #Nothing to be done about it, then
		scope:heir = {
			add_trait_force_tooltip = will_not_wed
			add_character_flag = { flag = directed_to_marry years = 10 }
			hidden_effect = {
				create_story = {
					type = lmf_will_not_wed_story_cycle
				}
			}
		}
	}
	option = {
		name = lmf_heir.2051.f #Time to take his future back into my hands
		scope:heir = {
			add_character_flag = cannot_get_will_not_wed_trait
			worsen_relationship_effect = { 
				TARGET = root
				REASON = overrode_marriage_wishes
			}
		}
	}

	after = {
		scope:heir = { remove_no_hat_effect = yes }
	}
}

# Initial response to interaction - family member suggests introductions
lmf_heir.2052 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:heir = { might_agree_to_marriage = no } }
				desc = lmf_heir.2052.t.notwant
			}
			desc = lmf_heir.2052.t
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:heir = { might_agree_to_marriage = no } }
				desc = lmf_heir.2052.desc.start.notwant
			}
			desc = lmf_heir.2052.desc.start
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:suitor_3 }
				desc = lmf_heir.2052.desc.three
			}
			triggered_desc = {
				trigger = { exists = scope:suitor_2 }
				desc = lmf_heir.2052.desc.two
			}
			desc = lmf_heir.2052.desc.one
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:matrilineal ?= yes }
				desc = lmf_heir.2052.desc.matrilineal
			}
			desc = lmf_heir.2052.desc.normal
		}
		desc = lmf_heir.2052.desc.end
	}
	theme = family

	left_portrait = {
		character = scope:secondary_actor
		animation = thinking
		camera = camera_event_right
	}
	override_background = { reference = study }
	lower_left_portrait = scope:suitor_1
	lower_center_portrait = scope:suitor_2
	lower_right_portrait = scope:suitor_3
	
	immediate = {
		scope:heir = { no_hat_respectful_effect = yes }
		scope:suitor_1 ?= { no_hat_respectful_effect = yes }
		scope:suitor_2 ?= { no_hat_respectful_effect = yes }
		scope:suitor_3 ?= { no_hat_respectful_effect = yes }
	}

	option = {
		trigger = { exists = scope:suitor_1 }
		name = lmf_heir.2052.a #pick suitor_1
		get_heir_match_lineality_effect = { HEIR = scope:secondary_actor MATCH = scope:suitor_1 }
		start_introduction_effect = { SUITOR = scope:suitor_1 }
		if = {
			limit = { scope:secondary_actor = { is_female = yes } }
			if = {
				limit = {
					heir_match_is_matrilineal = { HEIR = scope:secondary_actor MATCH = scope:suitor_1 }
				}
				custom_tooltip = lmf_heir.1516.warning.matrilineal_tt
			}
			else = {
				custom_tooltip = lmf_heir.1516.warning.patrilineal_tt
			}
		}
	}
	option = {
		trigger = { exists = scope:suitor_2 }
		name = lmf_heir.2052.b #pick suitor_2
		get_heir_match_lineality_effect = { HEIR = scope:secondary_actor MATCH = scope:suitor_2 }
		start_introduction_effect = { SUITOR = scope:suitor_2 }
		if = {
			limit = { scope:secondary_actor = { is_female = yes } }
			if = {
				limit = {
					heir_match_is_matrilineal = { HEIR = scope:secondary_actor MATCH = scope:suitor_2 }
				}
				custom_tooltip = lmf_heir.1516.warning.matrilineal_tt
			}
			else = {
				custom_tooltip = lmf_heir.1516.warning.patrilineal_tt
			}
		}
	}
	option = {
		trigger = { exists = scope:suitor_3 }
		name = lmf_heir.2052.c #pick suitor_3
		get_heir_match_lineality_effect = { HEIR = scope:secondary_actor MATCH = scope:suitor_3 }
		start_introduction_effect = { SUITOR = scope:suitor_3 }
		if = {
			limit = { scope:secondary_actor = { is_female = yes } }
			if = {
				limit = {
					heir_match_is_matrilineal = { HEIR = scope:secondary_actor MATCH = scope:suitor_3 }
				}
				custom_tooltip = lmf_heir.1516.warning.matrilineal_tt
			}
			else = {
				custom_tooltip = lmf_heir.1516.warning.patrilineal_tt
			}
		}
	}
	option = {
		name = lmf_heir.2052.d #I'll find someone for you
	}
	
	after = {
		scope:heir = { remove_no_hat_effect = yes }
		scope:suitor_1 ?= { remove_no_hat_effect = yes }
		scope:suitor_2 ?= { remove_no_hat_effect = yes }
		scope:suitor_3 ?= { remove_no_hat_effect = yes }
	}
}

# Family member dejected by refusal
lmf_heir.2053 = {
	type = character_event
	title = lmf_heir.2053.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:needs_their_permission }
				desc = lmf_heir.2053.desc.ruler
			}
			desc = lmf_heir.2053.desc.liege
		}
		desc = lmf_heir.2053.desc.end
	}
	theme = family
	
	left_portrait = {
		character = scope:heir
		animation = sadness
		camera = camera_event_right
	}
	override_background = { reference = study }
	
	trigger = {
		scope:heir = {
			is_alive = yes
			is_physically_able = yes
			is_married = no
			is_betrothed = no
			matchmaker ?= root
			host ?= root
			OR = {
				is_non_courtier_marriage_candidate = { RULER = root }
				AND = {
					is_courtier_of = root
					OR = {
						is_close_or_extended_family_of = root
						is_great_grandchild_of = root
					}
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				scope:heir = { has_relation_lover = scope:heir_lover }
			}
			lover_breakup_effect = {
				BREAKER = scope:heir
				LOVER = scope:heir_lover
			}
		}
		scope:heir = {
			if = {
				limit = { has_character_flag = cannot_get_will_not_wed_trait }
				remove_character_flag = cannot_get_will_not_wed_trait
			}
		}
	}
	
	option = {
		name = lmf_heir.2053.a #He'll find someone in time
		scope:heir = {
			add_trait_force_tooltip = will_not_wed
			add_character_flag = { flag = directed_to_marry years = 10 }
			hidden_effect = {
				create_story = {
					type = lmf_will_not_wed_story_cycle
				}
			}
		}
	}

	option = {
		name = lmf_heir.2053.b #Time to take his future back into my hands
		scope:heir = {
			add_character_flag = cannot_get_will_not_wed_trait
			worsen_relationship_effect = { 
				TARGET = root
				REASON = overrode_marriage_wishes
			}
		}
	}
}

# Initial response to interaction - family member stalls
lmf_heir.2054 = {
	type = character_event
	title = lmf_heir.2054.t
	desc = {
		desc = lmf_heir.2054.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:heir = { num_of_relation_lover > 0 }
				}
				desc = lmf_heir.2054.desc.lover
			}
			desc = lmf_heir.2054.desc.default
		}
		desc = lmf_heir.2054.desc.end
	}
	theme = family
	
	left_portrait = {
		character = scope:heir
		animation = thinking
		camera = camera_event_right
	}
	override_background = { reference = study }

	option = {
		name = lmf_heir.2054.a
	}
}

