﻿#Scripted effects relating to education

#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!

#education_point_acquisition_effect - Rolls a random chance for assigning education points based on a number of factors. Run in a pulse event every half year of childhood.

#education_point_acquisition_additional_points_effect - Effect to award more education points through one-offs like events etc.

#education_complete_notification_effect - Identifies characters for the "Education Completed" notification events and sends the events.

#save_childhood_trait_as_variable_effect - Saves childhood trait as a variable flag

#assign_commander_trait_effect - To assign a commander trait to a child with a martial education

#wrap_up_education_effect - Additional effects run to wrap up education

#rank_up_education_effect - Increases your education by 1 rank unless it's at 4 (or you don't have any)

######################################################################
# EFFECTS
######################################################################


#Education point acquisition

education_point_acquisition_effect = {
	if = {
		limit = { has_focus = education_diplomacy }
		education_point_acquisition_support_effect = { SKILL = diplomacy }
	}
	else_if = {
		limit = { has_focus = education_martial }
		education_point_acquisition_support_effect = { SKILL = martial }
	}
	else_if = {
		limit = { has_focus = education_stewardship }
		education_point_acquisition_support_effect = { SKILL = stewardship }
	}
	else_if = {
		limit = { has_focus = education_intrigue }
		education_point_acquisition_support_effect = { SKILL = intrigue }
	}
	else_if = {
		limit = { has_focus = education_learning }
		education_point_acquisition_support_effect = { SKILL = learning }
	}
}

#Effect to award more education points through one-offs like events etc
#Takes argument LEVEL low/mid
education_point_acquisition_additional_points_effect = {
	save_temporary_scope_value_as = {
		name = point_level
		value = flag:$LEVEL$
	}
	#Mid
	if = {
		limit = { scope:point_level = flag:mid }
		if = {
			limit = { has_focus = education_diplomacy }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_diplomacy_variable }
				}
				set_variable = {
					name = education_diplomacy_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_diplomacy_variable
				add = 6
			}
		}
		else_if = {
			limit = { has_focus = education_martial }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_martial_variable }
				}
				set_variable = {
					name = education_martial_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_martial_variable
				add = 6
			}
		}
		else_if = {
			limit = { has_focus = education_stewardship }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_stewardship_variable }
				}
				set_variable = {
					name = education_stewardship_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_stewardship_variable
				add = 6
			}
		}
		else_if = {
			limit = { has_focus = education_intrigue }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_intrigue_variable }
				}
				set_variable = {
					name = education_intrigue_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_intrigue_variable
				add = 6
			}
		}
		else_if = {
			limit = { has_focus = education_learning }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_learning_variable }
				}
				set_variable = {
					name = education_learning_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_learning_variable
				add = 6
			}
		}
	}
	#Low
	else_if = {
		limit = { scope:point_level = flag:low }
		if = {
			limit = { has_focus = education_diplomacy }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_diplomacy_variable }
				}
				set_variable = {
					name = education_diplomacy_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_diplomacy_variable
				add = 4
			}
		}
		else_if = {
			limit = { has_focus = education_martial }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_martial_variable }
				}
				set_variable = {
					name = education_martial_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_martial_variable
				add = 4
			}
		}
		else_if = {
			limit = { has_focus = education_stewardship }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_stewardship_variable }
				}
				set_variable = {
					name = education_stewardship_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_stewardship_variable
				add = 4
			}
		}
		else_if = {
			limit = { has_focus = education_intrigue }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_intrigue_variable }
				}
				set_variable = {
					name = education_intrigue_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_intrigue_variable
				add = 4
			}
		}
		else_if = {
			limit = { has_focus = education_learning }
			#Set variables if they don't exist
			if = {
				limit = {
					NOT = { has_variable = education_learning_variable }
				}
				set_variable = {
					name = education_learning_variable
					value = 0
				}
			}
			#Award more points
			change_variable = {
				name = education_learning_variable
				add = 4
			}
		}
	}
}

education_point_acquisition_support_effect = {
	#Save educator
	if = {
		limit = {
			any_relation = {
				type = guardian
				always = yes
			}
		}
		random_relation = {
			type = guardian
			save_scope_as = educator
		}
	}
	else_if = {
		limit = {
			court_owner ?= { employs_court_position = court_tutor_court_position }		
		}
		court_owner = { 
			random_court_position_holder = {
				type = court_tutor_court_position
				save_scope_as = educator
			}
		}
	}
	else_if = {
		limit = {
			court_owner ?= { employs_court_position = court_guru_court_position }		
		}
		court_owner = { 
			random_court_position_holder = {
				type = court_guru_court_position
				save_scope_as = educator
			}
		}
	}

	#Set variables if they don't exist
	if = {
		limit = {
			NOT = { has_variable = education_$SKILL$_variable }
		}
		set_variable = {
			name = education_$SKILL$_variable
			value = 0
		}
	}

	#Randomize success or failure
	random_list = {
		#Success
		60 = {
			#Child intelligence
			modifier = {
				has_trait = intellect_good_3
				add = 20
			}
			modifier = {
				has_trait = intellect_good_2
				add = 15
			}
			modifier = {
				OR = {
					has_trait = intellect_good_1
					has_trait = shrewd
				}
				add = 10
			}
			#Educator intelligence & skill
			modifier = {
				exists = scope:educator
				add = {
					scope:educator = {
						#Intelligence
						if = {
							limit = { has_trait = intellect_good_3 }
							value = 15
						}
						else_if = {
							limit = { has_trait = intellect_good_2 }
							value = 10
						}
						else_if = {
							limit = {
								OR = {
									has_trait = intellect_good_1
									has_trait = shrewd
								}
							}
							value = 5
						}
						#Specific skill
						add = {
							value = $SKILL$
							multiply = educator_skill_modifier_factor
						}
						#Learning skill
						add = {
							value = learning
							multiply = educator_learning_skill_modifier_factor
						}
						#Storyteller tradition
						if = {
							limit = { culture = { has_cultural_parameter = better_ward_education } }
							value = 10
						}
					}
				}
			}

			#Affinity
			modifier = {
				has_$SKILL$_education_affinity_childhood_trait_trigger = yes
				add = matching_childhood_trait_modifier_value
			}

			#Disaffinity
			modifier = {
				has_$SKILL$_education_disaffinity_childhood_trait_trigger = yes
				add = mismatching_childhood_trait_modifier_value
			}

			modifier = {
				scope:educator.house ?= { has_house_power_parameter = service_house_improved_educator_outcome_chance }
				add = 5
			}

			change_variable = {
				name = education_$SKILL$_variable
				add = 2
			}
		}
		#Failure
		40 = {
			#Child intelligence
			modifier = {
				OR = {
					has_trait = intellect_bad_3
					has_trait = inbred
				}
				add = 20
			}
			modifier = {
				has_trait = intellect_bad_2
				add = 15
			}
			modifier = {
				OR = {
					has_trait = intellect_bad_1
					has_trait = dull
				}
				add = 10
			}

			#Educator intelligence & skill
			modifier = {
				exists = scope:educator
				add = {
					value = 0
					scope:educator = {
						#Intelligence
						if = {
							limit = { has_trait = intellect_bad_3 }
							value = 15
						}
						else_if = {
							limit = { has_trait = intellect_bad_2 }
							value = 10
						}
						else_if = {
							limit = {
								OR = {
									has_trait = intellect_bad_1
									has_trait = dull
								}
							}
							value = 5
						}
					}
				}
			}
			modifier = {
				add = 20
				NOT = {
					exists = scope:educator
				}
			}
		}
	}
}

education_point_add_general_effect = {
	switch = {
		trigger = has_focus
		education_diplomacy = {
			education_point_add_point_effect = { SKILL = diplomacy VALUE = $VALUE$ }
		}
		education_martial = {
			education_point_add_point_effect = { SKILL = martial VALUE = $VALUE$ }
		}
		education_stewardship = {
			education_point_add_point_effect = { SKILL = stewardship VALUE = $VALUE$ }
		}
		education_intrigue = {
			education_point_add_point_effect = { SKILL = intrigue VALUE = $VALUE$ }
		}
		education_learning = {
			education_point_add_point_effect = { SKILL = learning VALUE = $VALUE$ }
		}
	}
}

education_point_add_point_effect = {
	#Set variables if they don't exist
	if = {
		limit = {
			NOT = { has_variable = education_$SKILL$_variable }
		}
		set_variable = {
			name = education_$SKILL$_variable
			value = 0
		}
	}
	# Change variable
	change_variable = {
		name = education_$SKILL$_variable
		add = $VALUE$
	}
}

#Effect to identify characters for the "Education Completed" notification events
education_complete_notification_effect = {
	save_scope_as = educated_child
	if = {
		limit = {
			any_relation = { type = guardian }
		}
		random_relation = {
			type = guardian
			if = {
				limit = { this = { is_parent_of = root } }
				save_scope_as = parent_guardian
				trigger_event = coming_of_age.1001
			}
			else = {
				save_scope_as = guardian
				if = {
					limit = {
						scope:educated_child = {
							any_parent = { is_alive = no }
							any_parent = { is_alive = yes }
						}
					}
					random_parent = {
						limit = { is_alive = yes }
						save_scope_as = living_parent
					}
					random_parent = {
						limit = { is_alive = no }
						save_scope_as = dead_parent
					}
					trigger_event = coming_of_age.1003 #Event for non-parent guardian when one parent of the child is dead
				}
				else_if = {
					limit = {
						scope:educated_child = {
							any_parent = {
								is_alive = yes
								count = 2
							}
						}
					}
					scope:educated_child.father = { save_scope_as = father }
					scope:educated_child.mother = { save_scope_as = mother }
					trigger_event = coming_of_age.1004 #Event for non-parent guardian when both parents are alive
				}
				else_if = {
					limit = {
						OR = {
							NOT = { exists = scope:educated_child.father }
							NOT = { exists = scope:educated_child.mother }
						}
					}
					if = {
						limit = {
							exists = scope:educated_child.father
						}
						scope:educated_child.father = {
							save_scope_as = parent
						}
					}
					if = {
						limit = {
							exists = scope:educated_child.mother
						}
						scope:educated_child.mother = {
							save_scope_as = parent
						}
					}
					if = {
						limit = {
							NOT = { exists = scope:parent }
						}
						trigger_event = coming_of_age.1005
					}
					else = {
						trigger_event = coming_of_age.1003
					}
				}
				else = {
					scope:educated_child.father = { save_scope_as = father }
					scope:educated_child.mother = { save_scope_as = mother }
					trigger_event = coming_of_age.1005 #Event for non-parent guardian when both parents are dead
				}
			}
			hidden_effect = { # Hidden to avoid duplicate effect messages
				#Relationship back-up clean-up
				remove_guardian_effect = {
					GUARDIAN = this
					WARD = scope:educated_child
					RETURN_WARD = no
					HIDE_OPINION = no
				}
			}
		}
	}
	every_parent = {
		limit = {
			OR = {
				NOT = { exists = scope:parent_guardian }
				AND = {
					exists = scope:parent_guardian
					this != scope:parent_guardian
				}
			}
		}
		trigger_event = coming_of_age.1002
	}
	# Inform non-parent dynasty member players they are in the court of
	if = {
		limit = { is_lowborn = no }
		every_player = {
			limit = {
				scope:educated_child.dynasty ?= dynasty
				NOR = {
					is_parent_of = scope:educated_child
					scope:parent_guardian ?= this
				}
				OR = {
					scope:educated_child.liege ?= this
					scope:educated_child.employer ?= this
					scope:educated_child.court_owner ?= this
				}
			}
			save_scope_as = relative
			send_interface_message = {
				type = msg_dynasty_child_of_age
				title = msg_dynasty_child_of_age_title
				desc = msg_dynasty_child_of_age_desc
				left_icon = scope:educated_child
				scope:educated_child = { display_correct_education_trait_gain_tooltip_effect = yes }
			}
		}
	}
	liege ?= {
		if = {
			limit = {
				is_ai = no
				is_employer_of = scope:educated_child
				NOR = {
					scope:educated_child.dynasty ?= dynasty
					is_parent_of = scope:educated_child
					scope:parent_guardian ?= this
				}
			}
			save_scope_as = relative
			send_interface_message = {
				type = msg_courtier_child_of_age
				title = msg_courtier_child_of_age_title
				desc = msg_dynasty_child_of_age_desc
				left_icon = scope:educated_child
				scope:educated_child = { display_correct_education_trait_gain_tooltip_effect = yes }
			}
		}
	}
}

#To extract and save event_targets to use in coming_of_age notification event
save_event_targets_from_childhood_effect = {
	if = {
		limit = {
			any_relation = { type = friend always = yes }
		}
		random_relation = {
			type = friend
			save_scope_as = friend
		}
	}
	if = {
		limit = {
			exists = var:had_childhood_crush_variable
		}
		var:had_childhood_crush_variable = {
			save_scope_as = crush
		}
	}
	if = {
		limit = {
			exists = var:had_childhood_bully_variable
		}
		var:had_childhood_bully_variable = {
			save_scope_as = bully
		}
	}
	if = {
		limit = {
			exists = var:had_childhood_victim_variable
		}
		var:had_childhood_victim_variable = {
			save_scope_as = victim
		}
	}
}

#To assign a commander trait (based on culture, faith, etc.) to a child with a martial education
assign_commander_trait_effect = {
	random_list = {
		100 = {
			trigger = { NOT = { has_trait = logistician } }
			add_trait = logistician
		}
		100 = {
			trigger = { NOT = { has_trait = military_engineer } }
			add_trait = military_engineer
		}
		100 = {
			trigger = { NOT = { has_trait = aggressive_attacker } }
			add_trait = aggressive_attacker
		}
		100 = {
			trigger = { NOT = { has_trait = unyielding_defender } }
			add_trait = unyielding_defender
		}
		100 = {
			trigger = { NOT = { has_trait = forder } }
			add_trait = forder
		}
		100 = {
			trigger = { NOT = { has_trait = flexible_leader } }
			add_trait = flexible_leader
		}
		100 = {
			trigger = {
				NOT = { has_trait = desert_warrior }
				OR = {
					any_directly_owned_province = {
						terrain = desert
					}
					AND = {
						exists = scope:educator
						scope:educator = {
							any_directly_owned_province = {
								terrain = desert
							}
						}
					}
					AND = {
						NOT = { exists = scope:educator }
						liege ?= {
							any_directly_owned_province = {
								terrain = desert
							}
						}
					}
				}
			}
			modifier = {
				culture = {
					has_cultural_parameter = desert_warrior_trait_more_common
				}
				factor = 2
			}
			add_trait = desert_warrior
		}
		100 = {
			trigger = {
				NOT = { has_trait = jungle_stalker }
				OR = {
					any_directly_owned_province = {
						terrain = jungle
					}
					AND = {
						exists = scope:educator
						scope:educator = {
							any_directly_owned_province = {
								terrain = jungle
							}
						}
					}
					AND = {
						NOT = { exists = scope:educator }
						liege ?= {
							any_directly_owned_province = {
								terrain = jungle
							}
						}
					}
				}
			}
			modifier = {
				culture = {
					has_cultural_parameter = jungle_stalker_trait_more_common
				}
				factor = 2
			}
			add_trait = jungle_stalker
		}
		100 = {
			trigger = {
				NOT = { has_trait = winter_soldier }
				OR = {
					any_directly_owned_province = {
						OR = {
							terrain = taiga
							geographical_region = world_tibet
							geographical_region = world_europe_north
							geographical_region = world_europe_east
							geographical_region = world_steppe
						}
					}
					AND = {
						exists = scope:educator
						scope:educator = {
							any_directly_owned_province = {
								OR = {
									terrain = taiga
									geographical_region = world_tibet
									geographical_region = world_europe_north
									geographical_region = world_europe_east
									geographical_region = world_steppe
								}
							}
						}
					}
					AND = {
						NOT = { exists = scope:educator }
						liege ?= {
							any_directly_owned_province = {
								OR = {
									terrain = taiga
									geographical_region = world_tibet
									geographical_region = world_europe_north
									geographical_region = world_europe_east
									geographical_region = world_steppe
								}
							}
						}
					}
				}
			}
			modifier = {
				culture = {
					has_cultural_parameter = winter_soldier_trait_more_common
				}
				factor = 2
			}
			add_trait = winter_soldier
		}
		100 = {
			trigger = { NOT = { has_trait = reaver } }
			add_trait = reaver
		}
		100 = {
			trigger = { NOT = { has_trait = reckless } }
			add_trait = reckless
		}
		100 = {
			trigger = { NOT = { has_trait = holy_warrior } }
			add_trait = holy_warrior
		}
		100 = {
			trigger = {
				culture = {
					has_cultural_parameter = forest_fighter_trait_more_common
				}
				NOT = { has_trait = forest_fighter }
				OR = {
					any_directly_owned_province = {
						OR = {
							terrain = forest
							terrain = taiga
						}
					}
					AND = {
						exists = scope:educator
						scope:educator = {
							any_directly_owned_province = {
								OR = {
									terrain = forest
									terrain = taiga
								}
							}
						}
					}
					AND = {
						NOT = { exists = scope:educator }
						liege ?= {
							any_directly_owned_province = {
								OR = {
									terrain = forest
									terrain = taiga
								}
							}
						}
					}
				}
			}
			modifier = {
				culture = {
					has_cultural_parameter = forest_fighter_trait_more_common
				}
				factor = 2
			}
			add_trait = forest_fighter
		}
		100 = {
			trigger = {
				culture = {
					has_cultural_parameter = rough_terrain_expert_trait_more_common
				}
				NOT = { has_trait = rough_terrain_expert }
				OR = {
					any_directly_owned_province = {
						OR = {
							terrain = mountains
							terrain = hills
							terrain = wetlands
						}
					}
					AND = {
						exists = scope:educator
						scope:educator = {
							any_directly_owned_province = {
								OR = {
									terrain = mountains
									terrain = hills
									terrain = wetlands
								}
							}
						}
					}
					AND = {
						NOT = { exists = scope:educator }
						liege ?= {
							any_directly_owned_province = {
								OR = {
									terrain = mountains
									terrain = hills
									terrain = wetlands
								}
							}
						}
					}
				}
			}
			modifier = {
				culture = {
					has_cultural_parameter = rough_terrain_expert_trait_more_common
				}
				factor = 2
			}
			add_trait = rough_terrain_expert
		}
	}
}



custom_tooltip_learning_coming_of_age_effect = {
	if = {
		limit = {
			has_trait = education_learning_1
		}
		custom_tooltip = coming_of_age.0001.tt.1
	}
	else_if = {
		limit = {
			has_trait = education_learning_2
		}
		custom_tooltip = coming_of_age.0001.tt.2
	}
	else_if = {
		limit = {
			has_trait = education_learning_3
		}
		custom_tooltip = coming_of_age.0001.tt.3
	}
	else_if = {
		limit = {
			has_trait = education_learning_4
		}
		custom_tooltip = coming_of_age.0001.tt.4
	}
	if = {
		limit = {
			exists = scope:crush
		}
		custom_tooltip = coming_of_age.0001.tt.5
	}
	if = {
		limit = {
			exists = scope:victim
		}
		custom_tooltip = coming_of_age.0001.tt.7
	}
	if = {
		limit = {
			exists = scope:bully
		}
		custom_tooltip = coming_of_age.0001.tt.9
	}
}

custom_tooltip_stewardship_coming_of_age_effect = {
	if = {
		limit = {
			has_trait = education_stewardship_1
		}
		custom_tooltip = coming_of_age.0001.tt.1
	}
	else_if = {
		limit = {
			has_trait = education_stewardship_2
		}
		custom_tooltip = coming_of_age.0001.tt.2
	}
	else_if = {
		limit = {
			has_trait = education_stewardship_3
		}
		custom_tooltip = coming_of_age.0001.tt.3
	}
	else_if = {
		limit = {
			has_trait = education_stewardship_4
		}
		custom_tooltip = coming_of_age.0001.tt.4
	}
	if = {
		limit = {
			exists = scope:crush
		}
		custom_tooltip = coming_of_age.0001.tt.5
	}
	if = {
		limit = {
			exists = scope:victim
		}
		custom_tooltip = coming_of_age.0001.tt.7
	}
	if = {
		limit = {
			exists = scope:bully
		}
		custom_tooltip = coming_of_age.0001.tt.9
	}
}

custom_tooltip_martial_coming_of_age_effect = {
	if = {
		limit = {
			has_trait = education_martial_1
		}
		custom_tooltip = coming_of_age.0001.tt.1
	}
	else_if = {
		limit = {
			has_trait = education_martial_2
		}
		custom_tooltip = coming_of_age.0001.tt.2
	}
	else_if = {
		limit = {
			has_trait = education_martial_3
		}
		custom_tooltip = coming_of_age.0001.tt.3
	}
	else_if = {
		limit = {
			has_trait = education_martial_4
		}
		custom_tooltip = coming_of_age.0001.tt.4
	}
	if = {
		limit = {
			exists = scope:crush
		}
		custom_tooltip = coming_of_age.0001.tt.5
	}
	if = {
		limit = {
			exists = scope:victim
		}
		custom_tooltip = coming_of_age.0001.tt.7
	}
	if = {
		limit = {
			exists = scope:bully
		}
		custom_tooltip = coming_of_age.0001.tt.9
	}
}

custom_tooltip_intrigue_coming_of_age_effect = {
	if = {
		limit = {
			has_trait = education_intrigue_1
		}
		custom_tooltip = coming_of_age.0001.tt.1
	}
	else_if = {
		limit = {
			has_trait = education_intrigue_2
		}
		custom_tooltip = coming_of_age.0001.tt.2
	}
	else_if = {
		limit = {
			has_trait = education_intrigue_3
		}
		custom_tooltip = coming_of_age.0001.tt.3
	}
	else_if = {
		limit = {
			has_trait = education_intrigue_4
		}
		custom_tooltip = coming_of_age.0001.tt.4
	}
	if = {
		limit = {
			exists = scope:crush
		}
		custom_tooltip = coming_of_age.0001.tt.5
	}
	if = {
		limit = {
			exists = scope:victim
		}
		custom_tooltip = coming_of_age.0001.tt.7
	}
	if = {
		limit = {
			exists = scope:bully
		}
		custom_tooltip = coming_of_age.0001.tt.9
	}
}

custom_tooltip_diplomacy_coming_of_age_effect = {
	if = {
		limit = {
			has_trait = education_diplomacy_1
		}
		custom_tooltip = coming_of_age.0001.tt.1
	}
	else_if = {
		limit = {
			has_trait = education_diplomacy_2
		}
		custom_tooltip = coming_of_age.0001.tt.2
	}
	else_if = {
		limit = {
			has_trait = education_diplomacy_3
		}
		custom_tooltip = coming_of_age.0001.tt.3
	}
	else_if = {
		limit = {
			has_trait = education_diplomacy_4
		}
		custom_tooltip = coming_of_age.0001.tt.4
	}
	if = {
		limit = {
			exists = scope:crush
		}
		custom_tooltip = coming_of_age.0001.tt.5
	}
	if = {
		limit = {
			exists = scope:victim
		}
		custom_tooltip = coming_of_age.0001.tt.7
	}
	if = {
		limit = {
			exists = scope:bully
		}
		custom_tooltip = coming_of_age.0001.tt.9
	}
}


remove_variables_and_trait_coming_of_age_effect = {
	if = {
		limit = {
			exists = var:had_childhood_crush_variable
		}
		remove_variable = had_childhood_crush_variable
	}
	if = {
		limit = {
			exists = var:unrequited_crush
		}
		remove_variable = unrequited_crush
	}
	if = {
		limit = {
			exists = var:had_childhood_victim_variable
		}
		remove_variable = had_childhood_victim_variable
	}
	if = {
		limit = {
			exists = var:had_childhood_bully_variable
		}
		remove_variable = had_childhood_bully_variable
	}
	if = {
		limit = { has_trait = curious }
		remove_trait = curious
	}
	if = {
		limit = { has_trait = rowdy }
		remove_trait = rowdy
	}
	if = {
		limit = { has_trait = bossy }
		remove_trait = bossy
	}
	if = {
		limit = { has_trait = charming }
		remove_trait = charming
	}
	if = {
		limit = { has_trait = pensive }
		remove_trait = pensive
	}
	if = {
		limit = {
			has_character_flag = bully_destroyed_toy
		}
		remove_character_flag = bully_destroyed_toy
	}
	if = {
		limit = {
			has_character_flag = natural_education_progression
		}
		remove_character_flag = natural_education_progression
	}
	if = {
		limit = {
			has_variable = education_point_gain_variable
		}
		remove_variable = education_point_gain_variable
	}
	if = {
		limit = {
			has_variable = childhood_trait_type
		}
		remove_variable = childhood_trait_type
	}
	if = {
		limit = {
			exists = var:education_diplomacy_variable
		}
		remove_variable = education_diplomacy_variable
	}
	if = {
		limit = {
			exists = var:education_martial_variable
		}
		remove_variable = education_martial_variable
	}
	if = {
		limit = {
			exists = var:education_stewardship_variable
		}
		remove_variable = education_stewardship_variable
	}
	if = {
		limit = {
			exists = var:education_intrigue_variable
		}
		remove_variable = education_intrigue_variable
	}
	if = {
		limit = {
			exists = var:education_learning_variable
		}
		remove_variable = education_learning_variable
	}
}

remove_childhoood_traits_effect = {
	if = {
		limit = { has_trait = curious }
		remove_trait = curious
	}
	if = {
		limit = { has_trait = rowdy }
		remove_trait = rowdy
	}
	if = {
		limit = { has_trait = bossy }
		remove_trait = bossy
	}
	if = {
		limit = { has_trait = charming }
		remove_trait = charming
	}
	if = {
		limit = { has_trait = pensive }
		remove_trait = pensive
	}
}

#Save childhood trait as a variable flag
save_childhood_trait_as_variable_effect = {
	if = {
		limit = { has_trait = rowdy }
		set_variable = {
			name = childhood_trait_type
			value = flag:rowdy
		}
	}
	else_if = {
		limit = { has_trait = curious }
		set_variable = {
			name = childhood_trait_type
			value = flag:curious
		}
	}
	else_if = {
		limit = { has_trait = bossy }
		set_variable = {
			name = childhood_trait_type
			value = flag:bossy
		}
	}
	else_if = {
		limit = { has_trait = charming }
		set_variable = {
			name = childhood_trait_type
			value = flag:charming
		}
	}
	else_if = {
		limit = { has_trait = pensive }
		set_variable = {
			name = childhood_trait_type
			value = flag:pensive
		}
	}
}


#Display correct trait tooltip
display_correct_education_trait_gain_tooltip_effect = {
	if = {
		limit = { has_trait = education_diplomacy_1 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_diplomacy_1
		}
	}
	if = {
		limit = { has_trait = education_diplomacy_2 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_diplomacy_2
		}
	}
	if = {
		limit = { has_trait = education_diplomacy_3 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_diplomacy_3
		}
	}
	if = {
		limit = { has_trait = education_diplomacy_4 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_diplomacy_4
		}
	}
	if = {
		limit = { has_trait = education_diplomacy_5 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_diplomacy_5
		}
	}
	if = {
		limit = { has_trait = education_martial_1 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_1
		}
	}
	if = {
		limit = { has_trait = education_martial_2 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_2
		}
	}
	if = {
		limit = { has_trait = education_martial_3 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_3
		}
	}
	if = {
		limit = { has_trait = education_martial_4 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_4
		}
	}
	if = {
		limit = { has_trait = education_martial_5 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_5
		}
	}
	if = {
		limit = { has_trait = education_stewardship_1 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_stewardship_1
		}
	}
	if = {
		limit = { has_trait = education_stewardship_2 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_stewardship_2
		}
	}
	if = {
		limit = { has_trait = education_stewardship_3 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_stewardship_3
		}
	}
	if = {
		limit = { has_trait = education_stewardship_4 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_stewardship_4
		}
	}
	if = {
		limit = { has_trait = education_stewardship_5 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_stewardship_5
		}
	}
	if = {
		limit = { has_trait = education_intrigue_1 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_intrigue_1
		}
	}
	if = {
		limit = { has_trait = education_intrigue_2 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_intrigue_2
		}
	}
	if = {
		limit = { has_trait = education_intrigue_3 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_intrigue_3
		}
	}
	if = {
		limit = { has_trait = education_intrigue_4 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_intrigue_4
		}
	}
	if = {
		limit = { has_trait = education_intrigue_5 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_intrigue_5
		}
	}
	if = {
		limit = { has_trait = education_learning_1 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_learning_1
		}
	}
	if = {
		limit = { has_trait = education_learning_2 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_learning_2
		}
	}
	if = {
		limit = { has_trait = education_learning_3 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_learning_3
		}
	}
	if = {
		limit = { has_trait = education_learning_4 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_learning_4
		}
	}
	if = {
		limit = { has_trait = education_learning_5 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_learning_5
		}
	}
	if = { # Knighthood innovation
		limit = { has_trait = education_martial_prowess_1 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_prowess_1
		}
	}
	if = {
		limit = { has_trait = education_martial_prowess_2 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_prowess_2
		}
	}
	if = {
		limit = { has_trait = education_martial_prowess_3 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_prowess_3
		}
	}
	if = {
		limit = { has_trait = education_martial_prowess_4 }
		show_as_tooltip = {
			add_trait_force_tooltip = education_martial_prowess_4
		}
	}
	if = { # Esotericism Tenet
		limit = { has_trait = lifestyle_mystic }
		show_as_tooltip = {
			add_trait_force_tooltip = lifestyle_mystic
		}
	}
	if = {
		limit = {
			has_trait = logistician
		}
		show_as_tooltip = {
			add_trait_force_tooltip = logistician
		}
	}
	if = {
		limit = {
			has_trait = military_engineer
		}
		show_as_tooltip = {
			add_trait_force_tooltip = military_engineer
		}
	}
	if = {
		limit = {
			has_trait = aggressive_attacker
		}
		show_as_tooltip = {
			add_trait_force_tooltip = aggressive_attacker
		}
	}
	if = {
		limit = {
			has_trait = unyielding_defender
		}
		show_as_tooltip = {
			add_trait_force_tooltip = unyielding_defender
		}
	}
	if = {
		limit = {
			has_trait = forder
		}
		show_as_tooltip = {
			add_trait_force_tooltip = forder
		}
	}
	if = {
		limit = {
			has_trait = flexible_leader
		}
		show_as_tooltip = {
			add_trait_force_tooltip = flexible_leader
		}
	}
	if = {
		limit = {
			has_trait = desert_warrior
		}
		show_as_tooltip = {
			add_trait_force_tooltip = desert_warrior
		}
	}
	if = {
		limit = {
			has_trait = jungle_stalker
		}
		show_as_tooltip = {
			add_trait_force_tooltip = jungle_stalker
		}
	}
	if = {
		limit = {
			has_trait = winter_soldier
		}
		show_as_tooltip = {
			add_trait_force_tooltip = winter_soldier
		}
	}
	if = {
		limit = {
			has_trait = reaver
		}
		show_as_tooltip = {
			add_trait_force_tooltip = reaver
		}
	}
	if = {
		limit = {
			has_trait = reckless
		}
		show_as_tooltip = {
			add_trait_force_tooltip = reckless
		}
	}
	if = {
		limit = {
			has_trait = holy_warrior
		}
		show_as_tooltip = {
			add_trait_force_tooltip = holy_warrior
		}
	}
	if = {
		limit = {
			has_trait = rough_terrain_expert
		}
		show_as_tooltip = {
			add_trait_force_tooltip = rough_terrain_expert
		}
	}
	if = {
		limit = { has_trait = organizer }
		show_as_tooltip = { add_trait_force_tooltip = organizer }
	}
	if = {
		limit = { has_trait = forest_fighter }
		show_as_tooltip = { add_trait_force_tooltip = forest_fighter }
	}
	if = {
		limit = { has_trait = cautious_leader }
		show_as_tooltip = { add_trait_force_tooltip = cautious_leader }
	}
	if = {
		limit = { has_trait = open_terrain_expert }
		show_as_tooltip = { add_trait_force_tooltip = open_terrain_expert }
	}
	if = {
		limit = { has_trait = education_republican_knowledge_1 }
		show_as_tooltip = { add_trait_force_tooltip = education_republican_knowledge_1 }
	}
	if = {
		limit = { has_trait = education_republican_knowledge_2 }
		show_as_tooltip = { add_trait_force_tooltip = education_republican_knowledge_2 }
	}
	if = {
		limit = { has_trait = education_republican_knowledge_3 }
		show_as_tooltip = { add_trait_force_tooltip = education_republican_knowledge_3 }
	}
	if = {
		limit = { has_trait = education_republican_knowledge_4 }
		show_as_tooltip = { add_trait_force_tooltip = education_republican_knowledge_4 }
	}
}


#To run every time a guardian/ward relationship is set
guardian_add_opinion_effect = {
	$GUARDIAN$ = {
		if = {
			limit = {
				NOT = { this = $WARD_LIEGE$ }
				$WARD_LIEGE$ = { is_alive = yes }
				is_ai = yes
			}

			#For educator
			if = {
				limit = {
					$WARD_LIEGE$ = { player_heir = $WARD$ }
					liege ?= $WARD_LIEGE$
					is_ruler = yes
					has_vassal_stance = parochial
				}
				add_opinion = {
					target = $WARD_LIEGE$
					modifier = guardian_of_heir_parochial_opinion
				}
			}
			else_if = {
				limit = { $WARD_LIEGE$ = { player_heir = $WARD$ } }
				add_opinion = {
					target = $WARD_LIEGE$
					modifier = guardian_of_heir_opinion
				}
			}
			else_if = {
				limit = {
					$WARD_LIEGE$ = { is_close_family_of = $WARD$ }
					liege ?= $WARD_LIEGE$
					is_ruler = yes
					has_vassal_stance = parochial
				}
				add_opinion = {
					target = $WARD_LIEGE$
					modifier = guardian_of_relative_parochial_opinion
				}
			}
			else_if = {
				limit = { $WARD_LIEGE$ = { is_close_family_of = $WARD$ } }
				add_opinion = {
					target = $WARD_LIEGE$
					modifier = guardian_of_relative_opinion
				}
			}

			#For educator liege, if educator is courtier
			if = {
				limit = {
					liege ?= {
						is_ai = yes
						is_alive = yes
					}
					is_ruler = no
					NOT = { liege = $WARD_LIEGE$ }
				}
				liege = {
					if = {
						limit = {
							$WARD_LIEGE$ = { player_heir = $WARD$ }
							liege ?= $WARD_LIEGE$
							is_ruler = yes
							has_vassal_stance = parochial
						}
						add_opinion = {
							target = $WARD_LIEGE$
							modifier = guardian_of_heir_parochial_opinion
						}
					}
					else_if = {
						limit = { $WARD_LIEGE$ = { player_heir = $WARD$ } }
						add_opinion = {
							target = $WARD_LIEGE$
							modifier = guardian_of_heir_opinion
						}
					}
					else_if = {
						limit = {
							$WARD_LIEGE$ = { is_close_family_of = $WARD$ }
							liege ?= $WARD_LIEGE$
							is_ruler = yes
							has_vassal_stance = parochial
						}
						add_opinion = {
							target = $WARD_LIEGE$
							modifier = guardian_of_relative_parochial_opinion
						}
					}
					else_if = {
						limit = { $WARD_LIEGE$ = { is_close_family_of = $WARD$ } }
						add_opinion = {
							target = $WARD_LIEGE$
							modifier = guardian_of_relative_opinion
						}
					}
					save_scope_as = guardian_liege
					$WARD$ = {
						set_variable = {
							name = guardian_liege
							value = scope:guardian_liege
						}
					}
				}
			}
		}
	}
}

#To run every time a guardian/ward relationship is ended (should be in all decisions/event options etc. where the relation is removed, but is also run through the on_remove_relation_guardian on_action just in case)
guardian_remove_opinion_effect = {
	if = {
		limit = {
			exists = $GUARDIAN$
			exists = $WARD$
			exists = $WARD_LIEGE$
		}
		$GUARDIAN$ = {
			if = {
				limit = {
					has_opinion_modifier = {
						modifier = guardian_of_heir_opinion
						target = $WARD_LIEGE$
					}
				}
				remove_opinion = {
					modifier = guardian_of_heir_opinion
					target = $WARD_LIEGE$
				}
			}
			else_if = {
				limit = {
					has_opinion_modifier = {
						modifier = guardian_of_relative_opinion
						target = $WARD_LIEGE$
					}
					NOT = { # They're not still guardian of a relative
						any_relation = {
							type = ward
							is_close_family_of = $WARD_LIEGE$
						}
					}
				}
				remove_opinion = {
					modifier = guardian_of_relative_opinion
					target = $WARD_LIEGE$
				}
			}
			if = {
				limit = {
					has_opinion_modifier = {
						modifier = guardian_of_heir_parochial_opinion
						target = $WARD_LIEGE$
					}
				}
				remove_opinion = {
					modifier = guardian_of_heir_parochial_opinion
					target = $WARD_LIEGE$
				}
			}
			else_if = {
				limit = {
					has_opinion_modifier = {
						modifier = guardian_of_relative_parochial_opinion
						target = $WARD_LIEGE$
					}
					NOT = { # They're not still guardian of a relative
						any_relation = {
							type = ward
							is_close_family_of = $WARD_LIEGE$
						}
					}
				}
				remove_opinion = {
					modifier = guardian_of_relative_parochial_opinion
					target = $WARD_LIEGE$
				}
			}
		}
		$WARD$ = {
			if = {
				limit = {
					exists = var:guardian_liege
					var:guardian_liege = { is_alive = yes }
				}
				var:guardian_liege = {
					if = {
						limit = {
							has_opinion_modifier = {
								modifier = guardian_of_heir_opinion
								target = $WARD_LIEGE$
							}
						}
						remove_opinion = {
							modifier = guardian_of_heir_opinion
							target = $WARD_LIEGE$
						}
					}
					else_if = {
						limit = {
							has_opinion_modifier = {
								modifier = guardian_of_relative_opinion
								target = $WARD_LIEGE$
							}
							NOT = { # They're not still guardian of a relative
								any_relation = {
									type = ward
									is_close_family_of = $WARD_LIEGE$
								}
							}
						}
						remove_opinion = {
							modifier = guardian_of_relative_opinion
							target = $WARD_LIEGE$
						}
					}
					if = {
						limit = {
							has_opinion_modifier = {
								modifier = guardian_of_heir_parochial_opinion
								target = $WARD_LIEGE$
							}
						}
						remove_opinion = {
							modifier = guardian_of_heir_parochial_opinion
							target = $WARD_LIEGE$
						}
					}
					else_if = {
						limit = {
							has_opinion_modifier = {
								modifier = guardian_of_relative_parochial_opinion
								target = $WARD_LIEGE$
							}
							NOT = { # They're not still guardian of a relative
								any_relation = {
									type = ward
									is_close_family_of = $WARD_LIEGE$
								}
							}
						}
						remove_opinion = {
							modifier = guardian_of_relative_parochial_opinion
							target = $WARD_LIEGE$
						}
					}
				}
				remove_variable = guardian_liege
			}
		}
		#if = {
		#	limit = {
		#		exists = liege
		#		liege = $WARD_LIEGE$
		#		has_vassal_stance = parochial
		#	}
		#	add_opinion = {
		#		target = $WARD_LIEGE$
		#		modifier = insult_opinion
		#		opinion = -30
		#	}
		#}
	}
}

#Additional effects run to wrap up education
wrap_up_education_effect = {
	#no educator memory creation
	if = {
		limit = {
			NOT = { exists = scope:educator }
			exists = root.court_owner.capital_province
		}
		create_character_memory = {
			type = childhood_education_no_guardian
		}
		scope:new_memory = {
			save_scope_as = education_memory
			set_variable = {
				name = education_realm
				value = root.court_owner.primary_title
			}
			if = {
				limit = {
					root.court_owner = { is_landed = no }
				}
				set_variable = {
					name = education_landless
					value = yes
				}
			}
			set_variable = {
				name = education_location
				value = root.court_owner.capital_province
			}
			set_variable = {
				name = education_location_culture
				value = root.court_owner.capital_province.culture
			}
			set_variable = {
				name = education_host_faith
				value = root.court_owner.faith
			}
			set_variable = {
				name = education_host_culture
				value = root.court_owner.culture
			}
		}
	}
	#has educator memory creation
	else_if = {
		limit = {
			exists = root.court_owner.capital_province
		}
		create_character_memory = {
			type = childhood_education_guardian
			participants = {
				guardian = scope:educator
			}
		}
		scope:new_memory = {
			save_scope_as = education_memory
			set_variable = {
				name = education_realm
				value = root.court_owner.primary_title
			}
			set_variable = {
				name = education_location
				value = root.court_owner.capital_province
			}
			set_variable = {
				name = education_location_culture
				value = root.court_owner.capital_province.culture
			}
			set_variable = {
				name = education_host_faith
				value = root.court_owner.faith
			}
			set_variable = {
				name = education_host_culture
				value = root.court_owner.culture
			}
		}
	}

	if = {
		limit = { exists = scope:educator }
		scope:educator = {
			create_character_memory = {
				type = ward_education_completed
				participants = {
					ward = root
				}
			}
		}
		remove_guardian_effect = {
			GUARDIAN = scope:educator
			WARD = root
			RETURN_WARD = yes
			HIDE_OPINION = no
		}
		if = {
			limit = {
				exists = root.house
				exists = scope:educator.house
			}
			root.house = {
				change_house_relation_effect = {
					HOUSE = scope:educator.house
					VALUE = house_relation_improve_minor_value
					REASON = educated
					CHAR = root
					TARGET_CHAR = scope:educator
					TITLE = scope:dummy_gender
				}
			}
		}
	}
	else = { return_ward_travel_effect = yes }
}

return_guardian_travel_effect = {
	if = {
		limit = {
			is_foreign_court_guest = yes
			NOR = {
				host = liege
				is_playable_character = yes
				any_relation = { #They're not at another ward's court
					type = ward
					is_playable_character = yes
					this = $GUARDIAN$.host
				}
			}
		}
		show_as_tooltip = { return_to_court = yes }
		location ?= { save_scope_as = starting_location }
		set_variable = {
			name = ward_educated
			value = $WARD$
			years = 3
		}
		set_variable = {
			name = ward_educated_realm
			value = host.primary_title
			years = 3
		}
		# Actually return guardian last
		hidden_effect = {
			set_location = scope:starting_location
			start_travel_plan = {
				destination = liege.capital_province
				on_start_on_action = on_guardian_depart_for_home
				on_travel_planner_cancel_on_action = on_guardian_depart_travel_planner_exit
				on_arrival_on_action = on_guardian_arrive_at_home
				on_arrival_destinations = last
				return_trip = no # One way
			}
		}
	}
}

return_ward_travel_effect = {
	if = {
		limit = {
			is_foreign_court_guest = yes
			exists = liege
			host != liege
		}
		show_as_tooltip = { return_to_court = yes }
		location ?= { save_scope_as = starting_location }
		if = {
			limit = { exists = scope:educator }
			set_variable = {
				name = guardian_educated
				value = scope:educator
				years = 3
			}
			set_variable = {
				name = guardian_educated_realm
				value = host.primary_title
				years = 3
			}
		}
		# Actually return guardian last
		hidden_effect = {
			set_location = scope:starting_location
			start_travel_plan = {
				destination = liege.capital_province
				on_start_on_action = on_ward_depart_for_home
				on_travel_planner_cancel_on_action = on_ward_depart_travel_planner_exit
				on_arrival_on_action = on_ward_arrive_at_home
				on_arrival_destinations = last
				return_trip = no # One way
			}
		}
	}
}

rank_up_education_effect = {
	if = {
		limit = { has_education_rank_4_trigger = no }
		if = {
			limit = { has_trait = education_diplomacy }
			change_trait_rank = {
				trait = education_diplomacy
				rank = 1
			}
		}
		else_if = {
			limit = { has_trait = education_martial }
			change_trait_rank = {
				trait = education_martial
				rank = 1
			}
		}
		else_if = {
			limit = { has_trait = education_stewardship }
			change_trait_rank = {
				trait = education_stewardship
				rank = 1
			}
		}
		else_if = {
			limit = { has_trait = education_intrigue }
			change_trait_rank = {
				trait = education_intrigue
				rank = 1
			}
		}
		else_if = {
			limit = { has_trait = education_learning }
			change_trait_rank = {
				trait = education_learning
				rank = 1
			}
		}
	}
}

results_of_university_education_points_effect = {
	if = {
		limit = {
			has_character_flag = studying_at_university
		}
		#Adding the points to the current education
		if = {
			limit = { has_focus = education_diplomacy }
			random_list = {
				60 = {
					change_variable = {
						name = education_diplomacy_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_diplomacy_variable
						add = 3
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_martial }
			random_list = {
				60 = {
					change_variable = {
						name = education_martial_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_martial_variable
						add = 3
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_stewardship }
			random_list = {
				60 = {
					change_variable = {
						name = education_stewardship_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_stewardship_variable
						add = 3
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_intrigue }
			random_list = {
				60 = {
					change_variable = {
						name = education_intrigue_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_intrigue_variable
						add = 3
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_learning }
			random_list = {
				60 = {
					change_variable = {
						name = education_learning_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_learning_variable
						add = 3
					}
				}
			}
		}
		remove_character_flag = studying_at_university
		add_character_flag = studied_at_university

		if = {
			limit = {
				NOT = {
					has_trait = drunkard
				}
			}
			hidden_effect = {
				random = {
					chance = 2
					add_trait = drunkard
				}
			}
		}
		if = {
			limit = {
				NOT = { has_character_flag = studying_confucian_education }
			}
			#Adding the points to the current education
			if = {
				limit = { has_trait = confucian_education }
				add_trait_xp = {
					trait = confucian_education
					value = {
						value = 20
						add = {
							value = "scope:educator.has_trait_xp(confucian_education)"
							multiply = 0.25
						}
						if = {
							limit = {
								has_religion = religion:confucianism_religion
							}
							add = 20 
						}
						round = yes
					}
				}
			}
			else = {
				add_trait = confucian_education
				add_trait_xp = {
					trait = confucian_education
					value = {
						value = 20
						add = {
							value = "scope:educator.has_trait_xp(confucian_education)"
							multiply = 0.1
						}
						if = {
							limit = {
								has_religion = religion:confucianism_religion
							}
							add = 10 
						}
						round = yes
					}
				}
			}
		}
	}
}
#Ward learned from a Confucian scholar
results_of_confucian_education_effect = {
	if = {
		limit = {
			has_character_flag = studying_confucian_education
		}
		#Adding the points to the current education
		if = {
			limit = { has_trait = confucian_education }
			add_trait_xp = {
				trait = confucian_education
				value = {
					value = 0
					if = {
						limit = {
							exists = scope:educator
						}
						add = {
							value = "scope:educator.has_trait_xp(confucian_education)"
							multiply = 0.25
						}
					}
					if = {
						limit = {
							has_religion = religion:confucianism_religion
						}
						add = 20 
					}
					if = {
						limit = {
							has_character_flag = studied_at_university
						}
						add = 20
					}
				}
			}
		}
		else = {
			add_trait = confucian_education
			add_trait_xp = {
				trait = confucian_education
				value = {
					value = 0
					if = {
						limit = {
							exists = scope:educator
						}
						add = {
							value = "scope:educator.has_trait_xp(confucian_education)"
							multiply = 0.1
						}
					}
					if = {
						limit = {
							has_religion = religion:confucianism_religion
						}
						add = 10 
					}
					if = {
						limit = {
							has_character_flag = studied_at_university
						}
						add = 20
					}
					round = yes
				}
			}
		}
		if = {
			limit = {
				exists = scope:educator
			}
			save_scope_as = educated_child
			random = {
				chance = 10
				set_elder_relation_effect = {
					ELDER = scope:educator
					DISCIPLE = scope:educated_child
					MERIT = minor_merit_gain
				}
			}
		}
		remove_character_flag = studying_confucian_education
		add_character_flag = studied_confucian_education
	}	
}

dynasty_legacy_education_boost_effect = {
	if = {
		limit = {
			has_dynasty = yes
			dynasty = { has_dynasty_perk = kin_legacy_2 }
		}

		if = {
			limit = { has_focus = education_diplomacy }
			random_list = {
				60 = {
					change_variable = {
						name = education_diplomacy_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_diplomacy_variable
						add = 3
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_martial }
			random_list = {
				60 = {
					change_variable = {
						name = education_martial_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_martial_variable
						add = 3
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_stewardship }
			random_list = {
				60 = {
					change_variable = {
						name = education_stewardship_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_stewardship_variable
						add = 3
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_intrigue }
			random_list = {
				60 = {
					change_variable = {
						name = education_intrigue_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_intrigue_variable
						add = 3
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_learning }
			random_list = {
				60 = {
					change_variable = {
						name = education_learning_variable
						add = 2
					}
				}
				40 = {
					change_variable = {
						name = education_learning_variable
						add = 3
					}
				}
			}
		}
	}
}

cultural_traditions_education_boost_effect = {
	# FP3 Beacon of Learning
	if = {
		limit = {
			any_relation = {
				type = guardian
				culture = { has_cultural_parameter = guardian_education_better_outcomes }
			}
		}
		if = {
			limit = { exists = var:education_diplomacy_variable }
			change_variable = {
				name = education_diplomacy_variable
				add = {
					value = var:education_diplomacy_variable
					divide = 4
					round = yes
					max = 3 # This effect shouldn't be better than a good court tutor
				}
			}
		}
		else_if = {
			limit = { exists = var:education_martial_variable }
			change_variable = {
				name = education_martial_variable
				add = {
					value = var:education_martial_variable
					divide = 4
					round = yes
					max = 3
				}
			}
		}
		else_if = {
			limit = { exists = var:education_intrigue_variable }
			change_variable = {
				name = education_intrigue_variable
				add = {
					value = var:education_intrigue_variable
					divide = 4
					round = yes
					max = 3
				}
			}
		}
		else_if = {
			limit = { exists = var:education_stewardship_variable }
			change_variable = {
				name = education_stewardship_variable
				add = {
					value = var:education_stewardship_variable
					divide = 4
					round = yes
					max = 3
				}
			}
		}
		else_if = {
			limit = { exists = var:education_learning_variable }
			change_variable = {
				name = education_learning_variable
				add = {
					value = var:education_learning_variable
					divide = 4
					round = yes
					max = 3
				}
			}
		}
	}
	if = {
		limit = {
			culture = {
				has_cultural_parameter = diplomacy_education_better_outcomes
			}
			has_focus = education_diplomacy
		}

		random_list = {
			60 = {
				change_variable = {
					name = education_diplomacy_variable
					add = 1
				}
			}
			40 = {
				change_variable = {
					name = education_diplomacy_variable
					add = 0
				}
			}
		}
	}
	if = {
		limit = {
			culture = {
				has_cultural_parameter = martial_education_worse_outcomes
			}
			has_focus = education_martial
			exists = var:education_martial_variable
			var:education_martial_variable > 0
		}

		change_variable = {
			name = education_martial_variable
			add = -1
		}
	}
}

court_tutor_education_boost_effect = {
	if = {
		limit = {
			court_owner ?= {
				OR = {
					AND = {
						employs_court_position = court_tutor_court_position
						any_court_position_holder = {
							type = court_tutor_court_position
						}
					}
					AND = {
						employs_court_position = court_guru_court_position
						any_court_position_holder = {
							type = court_guru_court_position
						}
					}
				}
			}
		}
		# Let's save the court tutor or guru with the highest aptitude
		# we can use the court tutor aptitude checks for Gurus because they are nearly identical for what matters in these calculations
		court_owner = {
			if = {
				limit = {
					employs_court_position = court_tutor_court_position
				}				
				random_court_position_holder = {
					type = court_tutor_court_position
					limit = { 
						var:booner_target ?= root
					}
					alternative_limit = { aptitude:court_tutor_court_position >= 4 }
					alternative_limit = { aptitude:court_tutor_court_position >= 3 }
					alternative_limit = { aptitude:court_tutor_court_position >= 2 }
					alternative_limit = { aptitude:court_tutor_court_position >= 1 }
					alternative_limit = { always = yes }
					save_scope_as = court_tutor
				}
			}
			else = {
				random_court_position_holder = {
					type = court_guru_court_position
					limit = { 
						var:booner_target ?= root
					}
					alternative_limit = { aptitude:court_guru_court_position >= 4 }
					alternative_limit = { aptitude:court_guru_court_position >= 3 }
					alternative_limit = { aptitude:court_guru_court_position >= 2 }
					alternative_limit = { aptitude:court_guru_court_position >= 1 }
					alternative_limit = { always = yes }
					save_scope_as = court_tutor
				}
			}
		}

		if = {
			limit = { has_focus = education_diplomacy }
			random_list = {
				10 = { # Small chance for a GREAT boost
					trigger = {
						OR = {
							scope:court_tutor.aptitude:court_tutor_court_position = 4
							scope:court_tutor.var:booner_target ?= root
						}
					}
					change_variable = {
						name = education_diplomacy_variable
						add = 4
					}
				}
				40 = {
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 4
					}
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 3
					}
					modifier = {
						add = 10
						scope:court_tutor.var:booner_target ?= root
					}
					change_variable = {
						name = education_diplomacy_variable
						add = 3
					}
				}
				50 = {
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 2
					}
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 1
					}
					change_variable = {
						name = education_diplomacy_variable
						add = 2
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_martial }
			random_list = {
				10 = { # Small chance for a GREAT boost
					trigger = {
						scope:court_tutor.aptitude:court_tutor_court_position = 4
						scope:court_tutor.var:booner_target ?= root
					}
					change_variable = {
						name = education_martial_variable
						add = 4
					}
				}
				40 = {
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 4
					}
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 3
					}
					modifier = {
						add = 10
						scope:court_tutor.var:booner_target ?= root
					}
					change_variable = {
						name = education_martial_variable
						add = 3
					}
				}
				50 = {
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 2
					}
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 1
					}
					change_variable = {
						name = education_martial_variable
						add = 2
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_stewardship }
			random_list = {
				10 = { # Small chance for a GREAT boost
					trigger = {
						scope:court_tutor.aptitude:court_tutor_court_position = 4
						scope:court_tutor.var:booner_target ?= root
						scope:court_tutor = { has_trait = confucian_education }
					}
					change_variable = {
						name = education_stewardship_variable
						add = 4
					}
				}
				40 = {
					modifier = {
						add = 20
						scope:court_tutor = { has_trait = confucian_education }
					}
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 4
					}
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 3
					}
					modifier = {
						add = 10
						scope:court_tutor.var:booner_target ?= root
					}
					change_variable = {
						name = education_stewardship_variable
						add = 3
					}
				}
				50 = {
					trigger = {
						NOT = {
							scope:court_tutor = { has_trait = confucian_education }
						}
					}
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 2
					}
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 1
					}
					change_variable = {
						name = education_stewardship_variable
						add = 2
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_intrigue }
			random_list = {
				10 = { # Small chance for a GREAT boost
					trigger = {
						scope:court_tutor.aptitude:court_tutor_court_position = 4
						scope:court_tutor.var:booner_target ?= root
					}
					change_variable = {
						name = education_intrigue_variable
						add = 4
					}
				}
				40 = {
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 4
					}
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 3
					}
					modifier = {
						add = 10
						scope:court_tutor.var:booner_target ?= root
					}
					change_variable = {
						name = education_intrigue_variable
						add = 3
					}
				}
				50 = {
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 2
					}
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 1
					}
					change_variable = {
						name = education_intrigue_variable
						add = 2
					}
				}
			}
		}
		else_if = {
			limit = { has_focus = education_learning }
			random_list = {
				10 = { # Small chance for a GREAT boost
					trigger = {
						scope:court_tutor.aptitude:court_tutor_court_position = 4
						scope:court_tutor.var:booner_target ?= root
						scope:court_tutor = { has_trait = confucian_education }
					}
					change_variable = {
						name = education_learning_variable
						add = 4
					}
				}
				40 = {
					modifier = {
						add = 20
						scope:court_tutor = { has_trait = confucian_education }
					}
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 4
					}
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 3
					}
					modifier = {
						add = 10
						scope:court_tutor.var:booner_target ?= root
					}
					change_variable = {
						name = education_learning_variable
						add = 3
					}
				}
				50 = {
					trigger = {
						NOT = {
							scope:court_tutor = { has_trait = confucian_education }
						}
					}
					modifier = {
						add = 10
						scope:court_tutor.aptitude:court_tutor_court_position = 2
					}
					modifier = {
						add = 20
						scope:court_tutor.aptitude:court_tutor_court_position = 1
					}
					change_variable = {
						name = education_learning_variable
						add = 2
					}
				}
			}
		}
	}
}

huntperson_camp_officer_education_boost_effect = {
	if = {
		limit = {
			court_owner ?= {
				employs_court_position = huntperson_camp_officer
				any_court_position_holder = {
					type = huntperson_camp_officer
				}
			}
		}
		#Let's save the huntperson with the highest aptitude
		court_owner = {
			random_court_position_holder = {
				type = huntperson_camp_officer
				limit = { aptitude:huntperson_camp_officer >= 5 }
				alternative_limit = { aptitude:huntperson_camp_officer >= 4 }
				alternative_limit = { aptitude:huntperson_camp_officer >= 3 }
				alternative_limit = { aptitude:huntperson_camp_officer >= 2 }
				alternative_limit = { always = yes }
				save_scope_as = huntperson
			}
		}
		if = {
			limit = { has_focus = education_martial }
			random_list = {
				10 = { # Small chance for a GREAT boost
					trigger = {
						scope:huntperson.aptitude:huntperson_camp_officer = 5
					}
					change_variable = {
						name = education_martial_variable
						add = 4
					}
				}
				40 = {
					modifier = {
						add = 20
						scope:huntperson.aptitude:huntperson_camp_officer = 5
					}
					modifier = {
						add = 10
						scope:huntperson.aptitude:huntperson_camp_officer = 4
					}
					change_variable = {
						name = education_martial_variable
						add = 3
					}
				}
				50 = {
					modifier = {
						add = 10
						scope:huntperson.aptitude:huntperson_camp_officer = 2
					}
					modifier = {
						add = 20
						scope:huntperson.aptitude:huntperson_camp_officer = 1
					}
					change_variable = {
						name = education_martial_variable
						add = 2
					}
				}
			}
		}
	}
}

post_education_bonuses_effect = {
	if = {
		limit = {
			exists = scope:educator
			character_has_commander_trait_scope_does_not = scope:educator
			scope:educator = {
				culture = {
					has_cultural_parameter = guardians_can_transfer_commander_traits
				}
			}
		}
		culture_randomize_commander_trait_effect = yes
	}
}

culture_randomize_commander_trait_effect = {
	random_list = {
		100 = {
			trigger = {
				NOT = { has_trait = rough_terrain_expert }
				scope:educator = {
					has_trait = rough_terrain_expert
				}
			}
			add_trait = rough_terrain_expert
		}
		100 = {
			trigger = {
				NOT = { has_trait = logistician }
				scope:educator = {
					has_trait = logistician
				}
			}
			add_trait = logistician
		}
		100 = {
			trigger = {
				NOT = { has_trait = military_engineer }
				scope:educator = {
					has_trait = military_engineer
				}
			}
			add_trait = military_engineer
		}
		100 = {
			trigger = {
				NOT = { has_trait = aggressive_attacker }
				scope:educator = {
					has_trait = aggressive_attacker
				}
			}
			add_trait = aggressive_attacker
		}
		100 = {
			trigger = {
				NOT = { has_trait = unyielding_defender }
				scope:educator = {
					has_trait = unyielding_defender
				}
			}
			add_trait = unyielding_defender
		}
		100 = {
			trigger = {
				NOT = { has_trait = forder }
				scope:educator = {
					has_trait = forder
				}
			}
			add_trait = forder
		}
		100 = {
			trigger = {
				NOT = { has_trait = flexible_leader }
				scope:educator = {
					has_trait = flexible_leader
				}
			}
			add_trait = flexible_leader
		}
		100 = {
			trigger = {
				NOT = { has_trait = desert_warrior }
				scope:educator = {
					has_trait = desert_warrior
				}
			}
			add_trait = desert_warrior
		}
		100 = {
			trigger = {
				NOT = { has_trait = jungle_stalker }
				scope:educator = {
					has_trait = jungle_stalker
				}
			}
			add_trait = jungle_stalker
		}
		100 = {
			trigger = {
				NOT = { has_trait = winter_soldier }
				scope:educator = {
					has_trait = winter_soldier
				}
			}
			add_trait = winter_soldier
		}
		100 = {
			trigger = {
				NOT = { has_trait = reaver }
				scope:educator = {
					has_trait = reaver
				}
			}
			add_trait = reaver
		}
		100 = {
			trigger = {
				NOT = { has_trait = reckless }
				scope:educator = {
					has_trait = reckless
				}
			}
			add_trait = reckless
		}
		100 = {
			trigger = {
				NOT = { has_trait = holy_warrior }
				scope:educator = {
					has_trait = holy_warrior
				}
			}
			add_trait = holy_warrior
		}
		100 = {
			trigger = {
				NOT = { has_trait = organizer }
				scope:educator = {
					has_trait = organizer
				}
			}
			add_trait = organizer
		}
		100 = {
			trigger = {
				NOT = { has_trait = forest_fighter }
				scope:educator = {
					has_trait = forest_fighter
				}
			}
			add_trait = forest_fighter
		}
		100 = {
			trigger = {
				NOT = { has_trait = cautious_leader }
				scope:educator = {
					has_trait = cautious_leader
				}
			}
			add_trait = cautious_leader
		}
		100 = {
			trigger = {
				NOT = { has_trait = open_terrain_expert }
				scope:educator = {
					has_trait = open_terrain_expert
				}
			}
			add_trait = open_terrain_expert
		}
	}
}


dynasty_perk_secondary_education_trait_effect = {
	if = {
		limit = {
			OR = {
				dynasty ?= { has_dynasty_perk = fp2_urbanism_legacy_2 }
				AND = {
					exists = scope:educator
					scope:educator = {
						dynasty ?= { has_dynasty_perk = fp2_urbanism_legacy_2 }
					}
				}
			}
		}

		# Assign a trait, chance based on the development of the location
		set_variable = {
			name = chance_for_extra_trait
			value = location.county.development_level
		}

		random_list = {
			# Success
			0 = {
				modifier = {
					exists = var:chance_for_extra_trait
					add = var:chance_for_extra_trait
				}

				# Select trait now
				random_list = {
					# Level 1: from 50% to 0%
					50 = {
						modifier = {
							add = {
								value =  var:chance_for_extra_trait
								multiply = -0.5
							}
						}
						add_trait = education_republican_knowledge_1
					}

					# Level 2: from 35% to 50%
					35 = {
						modifier = {
							add = {
								value =  var:chance_for_extra_trait
								multiply = 0.05
							}
						}
						add_trait = education_republican_knowledge_2
					}

					# Level 3: from 15% to 30%
					15 = {
						modifier = {
							add = {
								value =  var:chance_for_extra_trait
								multiply = 0.5
							}
						}
						add_trait = education_republican_knowledge_3
					}

					# Level 4: from 0 to 20% chance
					0 = {
						modifier = {
							add = {
								value =  var:chance_for_extra_trait
								multiply = 0.5
							}
						}
						add_trait = education_republican_knowledge_4
					}
				}
			}

			# Failing -  There will be a:
			# 84% chance at development 5
			# 66% chance at development 10
			# 50% chance at development 15
			# 0% chance  once  development level 30 is reached
			30 = {
				modifier = {
					exists = var:chance_for_extra_trait
					add = {
						value = var:chance_for_extra_trait
						multiply = -1
					}
				}
				#nothing happens
			}
		}
		# remove the variable now that it has been used
		remove_variable = chance_for_extra_trait
	}
}

ward_depart_effect = {
	scope:guardian = { add_to_list = toast_list }
	scope:ward = { add_to_list = toast_list }
	scope:guardian_liege = { add_to_list = toast_list }
	scope:ward_liege = { add_to_list = toast_list }
	# Set variables
	scope:ward = {
		set_variable = {
			name = character_making_education_request
			value = scope:actor
			years = 10
		}
		# Remove existing guardian if relevant
		if = {
			limit = {
				exists = scope:offer_guardianship_interaction
				any_relation = { type = guardian }
			}
			random_relation = {
				type = guardian
				save_scope_as = guardian_to_remove
			}
			remove_guardian_effect = {
				GUARDIAN = scope:guardian_to_remove
				WARD = scope:ward
				RETURN_WARD = no
				HIDE_OPINION = no
			}
		}
		remove_character_flag = under_offer_as_ward_flag
	}
	if = { # No travel necessary
		limit = {
			OR = {
				scope:ward = scope:guardian.host
				scope:guardian = scope:ward.host
				scope:ward.host = scope:guardian.host
				#allow landed ruler to landed ruler education
				AND = {
					scope:ward = {
						is_landed_or_landless_administrative = yes
					}
					scope:guardian = {
						is_landed_or_landless_administrative = yes
					}
				}
			}
		}
		hidden_effect = { #to prevent doubling of "becomes guardian of x" effect in the interaction confirmation window
			if = {
				limit = {
					NOT = {
						scope:guardian = { has_relation_ward = scope:ward }
					}
				}
				scope:guardian = { set_relation_ward = scope:ward }
			}
		}
		#Opinions
		guardian_add_opinion_effect = {
			GUARDIAN = scope:guardian
			WARD_LIEGE = scope:ward_liege
			WARD = scope:ward
		}
		# Convert culture setup
		scope:ward = {
			if = {
				limit = { has_character_flag = convert_culture }
				scope:guardian = {
					add_relation_flag = {
						relation = ward
						target = scope:ward
						flag = convert_culture
					}
				}
				remove_character_flag = convert_culture
			}
			# Convert faith setup
			if = {
				limit = { has_character_flag = convert_faith }
				scope:guardian = {
					add_relation_flag = {
						relation = ward
						target = scope:ward
						flag = convert_faith
					}
				}
				remove_character_flag = convert_faith
			}
		}
	}
	else = {
		if = { # Guardian heads to landed Ward
			limit = {
				scope:ward = { is_playable_character = yes }
			}
			scope:guardian = {
				set_variable = {
					name = guardian_travelling_to_ward
					years = 2
					value = scope:ward
				}
				start_travel_plan = {
					destination = scope:ward.capital_province
					on_start_on_action = on_guardian_depart_for_ward
					on_travel_planner_cancel_on_action = on_guardian_depart_travel_planner_exit
					on_arrival_on_action = on_guardian_arrive_at_ward
					on_arrival_destinations = last
					return_trip = no # One way
				}
			}
			hidden_effect = {
				every_in_list = {
					list = toast_list
					send_interface_toast = {
						title = guardian_departs_title
						left_icon = scope:guardian
						right_icon = scope:ward
						custom_tooltip = guardian_departs_tt
					}
				}
			}
			custom_tooltip = guardian_leaves_for_ward_tt
			scope:ward = {
				set_variable = {
					name = ward_waiting_for_guardian
					years = 2
					value = scope:guardian
				}
			}
		}
		else = {
			scope:ward = {
				if = {
					limit = { # Ward heads to landed Guardian
						is_playable_character = no
						scope:guardian = { is_playable_character = yes }
						scope:guardian != host
					}
					scope:guardian.capital_province = { save_scope_as = destination_province }
				}
				else_if = { # Ward heads to Guardian's host
					limit = { exists = scope:guardian.host.capital_province }
					scope:guardian.host.capital_province = { save_scope_as = destination_province }
				}
				else = {
					scope:guardian.location = { save_scope_as = destination_province }
				}
				set_variable = {
					name = ward_travelling_to_guardian
					years = 2
					value = scope:guardian
				}
				start_travel_plan = {
					destination = scope:destination_province
					on_start_on_action = on_ward_depart_for_guardian
					on_travel_planner_cancel_on_action = on_ward_depart_travel_planner_exit
					on_arrival_on_action = on_ward_arrive_at_guardian
					on_arrival_destinations = last
					return_trip = no # One way
				}
			}
			hidden_effect = {
				every_in_list = {
					list = toast_list
					send_interface_toast = {
						title = ward_departs_title
						left_icon = scope:ward
						right_icon = scope:guardian
						custom_tooltip = ward_departs_tt
					}
				}
			}
			custom_tooltip = ward_leaves_for_guardian_tt
			scope:guardian = {
				set_variable = {
					name = guardian_waiting_for_ward
					years = 2
					value = scope:ward
				}
			}
		}
	}
}

remove_guardian_effect = {
	$GUARDIAN$ = {
		remove_relation_ward = $WARD$
		return_guardian_travel_effect = {
			GUARDIAN = $GUARDIAN$
			WARD = $WARD$
		}
	}
	if = {
		limit = { always = $RETURN_WARD$ }
		$WARD$ = { return_ward_travel_effect = yes }
	}
	if = {
		limit = { always = $HIDE_OPINION$ }
		hidden_effect = {
			guardian_remove_opinion_effect = {
				GUARDIAN = $GUARDIAN$
				WARD = $WARD$
				WARD_LIEGE = $WARD$.liege
			}
		}
	}
	else = {
		guardian_remove_opinion_effect = {
			GUARDIAN = $GUARDIAN$
			WARD = $WARD$
			WARD_LIEGE = $WARD$.liege
		}
	}
}

knight_teacher_effect = {
	if = {
		limit = {
			scope:educator = { has_character_modifier = knight_teacher_modifier }
		}
		change_variable = {
			name = education_martial_variable
			add = { integer_range = { min = 1 max = 3 } }
		}
	}
}
