﻿# EOTM V1 Learning death inheritance implementation.
#
# Learning established the validated inheritance baseline. It grants perks/final unlocks, never lifestyle XP, and
# only runs for the current player ruler through the debug decision or guarded
# death hook.

eotm_count_parent_learning_normal_perks = {
	# Compatibility temp variable name retained; value is total visible Learning perk nodes, including final perks.
	set_variable = {
		name = eotm_parent_learning_normal_perk_count
		value = 0
	}
	if = { limit = { has_perk = anatomical_studies_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = carefree_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = mental_resilience_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = restraint_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = know_thyself_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = wash_your_hands_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = iron_constitution_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = healthy_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = whole_of_body_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = pedagogy_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = open_minded_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = apostate_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = scientific_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = planned_cultivation_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = scholarly_circles_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = learn_on_the_job_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = sanctioned_loopholes_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = scholar_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = faithful_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = zealous_proselytizer_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = religious_icon_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = prophet_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = clerical_justifications_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = church_and_state_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = radiant_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = defender_of_the_faith_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
	if = { limit = { has_perk = theologian_perk } change_variable = { name = eotm_parent_learning_normal_perk_count add = 1 } }
}

eotm_count_learning_visible_perks = {
	set_variable = { name = eotm_learning_visible_perk_count value = 0 }
	if = { limit = { has_perk = anatomical_studies_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = carefree_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = mental_resilience_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = restraint_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = know_thyself_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = wash_your_hands_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = iron_constitution_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = healthy_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = whole_of_body_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = pedagogy_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = open_minded_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = apostate_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = scientific_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = planned_cultivation_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = scholarly_circles_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = learn_on_the_job_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = sanctioned_loopholes_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = scholar_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = faithful_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = zealous_proselytizer_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = religious_icon_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = prophet_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = clerical_justifications_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = church_and_state_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = radiant_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = defender_of_the_faith_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
	if = { limit = { has_perk = theologian_perk } change_variable = { name = eotm_learning_visible_perk_count add = 1 } }
}

eotm_count_learning_final_visible_perks = {
	set_variable = { name = eotm_learning_final_visible_perk_count value = 0 }
	if = { limit = { has_perk = whole_of_body_perk } change_variable = { name = eotm_learning_final_visible_perk_count add = 1 } }
	if = { limit = { has_perk = scholar_perk } change_variable = { name = eotm_learning_final_visible_perk_count add = 1 } }
	if = { limit = { has_perk = theologian_perk } change_variable = { name = eotm_learning_final_visible_perk_count add = 1 } }
}

eotm_count_parent_learning_final_visible_perks = {
	set_variable = { name = eotm_parent_learning_final_visible_perk_count value = 0 }
	if = { limit = { has_perk = whole_of_body_perk } change_variable = { name = eotm_parent_learning_final_visible_perk_count add = 1 } }
	if = { limit = { has_perk = scholar_perk } change_variable = { name = eotm_parent_learning_final_visible_perk_count add = 1 } }
	if = { limit = { has_perk = theologian_perk } change_variable = { name = eotm_parent_learning_final_visible_perk_count add = 1 } }
}

eotm_debug_log_learning_parent_visible_count = {
	if = {
		limit = { exists = var:eotm_parent_learning_normal_perk_count }
		if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 0 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 1 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 2 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 3 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 4 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 5 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 6 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 7 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 8 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 9 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 10 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 11 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 12 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 13 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 14 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 15 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 16 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 17 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 18 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 19 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 20 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 21 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 22 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 23 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 24 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 25 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 26 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_normal_perk_count ?= 27 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else = {
		hidden_effect = { }
	}
}

eotm_debug_log_learning_parent_normal_count = {
	eotm_debug_log_learning_parent_visible_count = yes
}

eotm_debug_log_learning_visible_perk_count = {
	if = {
		limit = { exists = var:eotm_learning_visible_perk_count }
		if = { limit = { var:eotm_learning_visible_perk_count ?= 0 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 1 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 2 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 3 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 4 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 5 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 6 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 7 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 8 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 9 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 10 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 11 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 12 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 13 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 14 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 15 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 16 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 17 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 18 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 19 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 20 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 21 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 22 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 23 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 24 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 25 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 26 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_visible_perk_count ?= 27 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else = {
		hidden_effect = { }
	}
}

eotm_debug_log_learning_final_visible_perk_count = {
	if = {
		limit = { exists = var:eotm_learning_final_visible_perk_count }
		if = { limit = { var:eotm_learning_final_visible_perk_count ?= 0 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_final_visible_perk_count ?= 1 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_final_visible_perk_count ?= 2 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_final_visible_perk_count ?= 3 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else = {
		hidden_effect = { }
	}
}

eotm_debug_log_learning_parent_final_visible_count = {
	if = {
		limit = { exists = var:eotm_parent_learning_final_visible_perk_count }
		if = { limit = { var:eotm_parent_learning_final_visible_perk_count ?= 0 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_final_visible_perk_count ?= 1 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_final_visible_perk_count ?= 2 } hidden_effect = { } }
		else_if = { limit = { var:eotm_parent_learning_final_visible_perk_count ?= 3 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else = {
		hidden_effect = { }
	}
}

eotm_set_child_age_inheritance_percentage_40 = {
	if = {
		limit = { scope:eotm_deceased_parent = { age <= 5 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 250 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 10 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 500 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 15 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 1000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 20 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 1500 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 30 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 2000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 40 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 2500 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 50 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 3000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 60 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 3500 }
	}
	else = {
		set_variable = { name = eotm_child_age_inheritance_percentage value = 4000 }
	}
}

eotm_set_child_age_inheritance_percentage_60 = {
	if = {
		limit = { scope:eotm_deceased_parent = { age <= 5 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 375 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 10 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 750 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 15 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 1500 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 20 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 2250 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 30 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 3000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 40 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 3750 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 50 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 4500 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 60 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 5250 }
	}
	else = {
		set_variable = { name = eotm_child_age_inheritance_percentage value = 6000 }
	}
}

eotm_set_child_age_inheritance_percentage_80 = {
	if = {
		limit = { scope:eotm_deceased_parent = { age <= 5 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 500 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 10 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 1000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 15 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 2000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 20 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 3000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 30 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 4000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 40 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 5000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 50 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 6000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 60 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 7000 }
	}
	else = {
		set_variable = { name = eotm_child_age_inheritance_percentage value = 8000 }
	}
}

eotm_set_child_age_inheritance_percentage_100 = {
	if = {
		limit = { scope:eotm_deceased_parent = { age <= 5 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 625 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 10 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 1250 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 15 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 2500 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 20 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 3750 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 30 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 5000 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 40 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 6250 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 50 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 7500 }
	}
	else_if = {
		limit = { scope:eotm_deceased_parent = { age <= 60 } }
		set_variable = { name = eotm_child_age_inheritance_percentage value = 8750 }
	}
	else = {
		set_variable = { name = eotm_child_age_inheritance_percentage value = 10000 }
	}
}

eotm_set_child_age_inheritance_percentage = {
	if = {
		limit = { exists = scope:eotm_deceased_parent }
		if = {
			limit = { eotm_inheritance_strength_40_selected = yes }
			eotm_set_child_age_inheritance_percentage_40 = yes
		}
		else_if = {
			limit = { eotm_inheritance_strength_60_selected = yes }
			eotm_set_child_age_inheritance_percentage_60 = yes
		}
		else_if = {
			limit = { eotm_inheritance_strength_100_selected = yes }
			eotm_set_child_age_inheritance_percentage_100 = yes
		}
		else = {
			eotm_set_child_age_inheritance_percentage_80 = yes
		}
	}
	else = {
		set_variable = { name = eotm_child_age_inheritance_percentage value = 0 }
	}
	if = {
		limit = {
			has_variable = eotm_same_dynasty_fallback_inheritance_active
			exists = var:eotm_child_age_inheritance_percentage
		}
		if = {
			limit = { eotm_grandparent_inheritance_40_selected = yes }
			set_variable = {
				name = eotm_child_age_inheritance_percentage
				value = {
					value = var:eotm_child_age_inheritance_percentage
					multiply = 40
					divide = 100
					floor = yes
				}
			}
		}
		else_if = {
			limit = { eotm_grandparent_inheritance_80_selected = yes }
			set_variable = {
				name = eotm_child_age_inheritance_percentage
				value = {
					value = var:eotm_child_age_inheritance_percentage
					multiply = 80
					divide = 100
					floor = yes
				}
			}
		}
		else_if = {
			limit = { eotm_grandparent_inheritance_100_selected = yes }
			set_variable = {
				name = eotm_child_age_inheritance_percentage
				value = {
					value = var:eotm_child_age_inheritance_percentage
					multiply = 100
					divide = 100
					floor = yes
				}
			}
		}
		else = {
			set_variable = {
				name = eotm_child_age_inheritance_percentage
				value = {
					value = var:eotm_child_age_inheritance_percentage
					multiply = 60
					divide = 100
					floor = yes
				}
			}
		}
	}
}

eotm_debug_log_inheritance_strength_profile = {
	if = {
		limit = { eotm_inheritance_strength_40_selected = yes }
		hidden_effect = { }
	}
	else_if = {
		limit = { eotm_inheritance_strength_60_selected = yes }
		hidden_effect = { }
	}
	else_if = {
		limit = { eotm_inheritance_strength_100_selected = yes }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
}

eotm_debug_log_child_age_inheritance_percentage = {
	if = {
		limit = { eotm_inheritance_strength_40_selected = yes }
		if = { limit = { age <= 5 } hidden_effect = { } }
		else_if = { limit = { age <= 10 } hidden_effect = { } }
		else_if = { limit = { age <= 15 } hidden_effect = { } }
		else_if = { limit = { age <= 20 } hidden_effect = { } }
		else_if = { limit = { age <= 30 } hidden_effect = { } }
		else_if = { limit = { age <= 40 } hidden_effect = { } }
		else_if = { limit = { age <= 50 } hidden_effect = { } }
		else_if = { limit = { age <= 60 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else_if = {
		limit = { eotm_inheritance_strength_60_selected = yes }
		if = { limit = { age <= 5 } hidden_effect = { } }
		else_if = { limit = { age <= 10 } hidden_effect = { } }
		else_if = { limit = { age <= 15 } hidden_effect = { } }
		else_if = { limit = { age <= 20 } hidden_effect = { } }
		else_if = { limit = { age <= 30 } hidden_effect = { } }
		else_if = { limit = { age <= 40 } hidden_effect = { } }
		else_if = { limit = { age <= 50 } hidden_effect = { } }
		else_if = { limit = { age <= 60 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else_if = {
		limit = { eotm_inheritance_strength_100_selected = yes }
		if = { limit = { age <= 5 } hidden_effect = { } }
		else_if = { limit = { age <= 10 } hidden_effect = { } }
		else_if = { limit = { age <= 15 } hidden_effect = { } }
		else_if = { limit = { age <= 20 } hidden_effect = { } }
		else_if = { limit = { age <= 30 } hidden_effect = { } }
		else_if = { limit = { age <= 40 } hidden_effect = { } }
		else_if = { limit = { age <= 50 } hidden_effect = { } }
		else_if = { limit = { age <= 60 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else = {
		if = { limit = { age <= 5 } hidden_effect = { } }
		else_if = { limit = { age <= 10 } hidden_effect = { } }
		else_if = { limit = { age <= 15 } hidden_effect = { } }
		else_if = { limit = { age <= 20 } hidden_effect = { } }
		else_if = { limit = { age <= 30 } hidden_effect = { } }
		else_if = { limit = { age <= 40 } hidden_effect = { } }
		else_if = { limit = { age <= 50 } hidden_effect = { } }
		else_if = { limit = { age <= 60 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
}

eotm_calculate_child_learning_target_count = {
	eotm_set_child_age_inheritance_percentage = yes
	if = {
		limit = {
			exists = scope:eotm_deceased_parent
			exists = scope:eotm_deceased_parent.var:eotm_parent_learning_normal_perk_count
			exists = var:eotm_child_age_inheritance_percentage
		}
		set_variable = {
			name = eotm_learning_target_count
			value = {
				value = scope:eotm_deceased_parent.var:eotm_parent_learning_normal_perk_count
				multiply = var:eotm_child_age_inheritance_percentage
				divide = 10000
				floor = yes
			}
		}
	}
	else = {
		set_variable = { name = eotm_learning_target_count value = 0 }
		hidden_effect = { }
	}
}

eotm_debug_log_learning_child_age_years = {
	if = {
		limit = { age < 1 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 2 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 3 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 4 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 5 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 6 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 7 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 8 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 9 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 10 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 11 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 12 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 13 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 14 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 15 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 16 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 17 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 18 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 19 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 20 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 21 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 22 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 23 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 24 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 25 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 26 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 27 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 28 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 29 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 30 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 31 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 32 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 33 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 34 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 35 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 36 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 37 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 38 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 39 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 40 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 41 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 42 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 43 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 44 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 45 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 46 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 47 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 48 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 49 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 50 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 51 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 52 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 53 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 54 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 55 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 56 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 57 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 58 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 59 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 60 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 61 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 62 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 63 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 64 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 65 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 66 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 67 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 68 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 69 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 70 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 71 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 72 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 73 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 74 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 75 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 76 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 77 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 78 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 79 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 80 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 81 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 82 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 83 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 84 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 85 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 86 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 87 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 88 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 89 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 90 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 91 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 92 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 93 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 94 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 95 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 96 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 97 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 98 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 99 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 100 }
		hidden_effect = { }
	}
	else_if = {
		limit = { age < 101 }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
}

eotm_debug_log_learning_age_bracket_and_percentage = {
	eotm_debug_log_inheritance_strength_profile = yes
	if = {
		limit = { age <= 5 }
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
	else_if = {
		limit = { age <= 10 }
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
	else_if = {
		limit = { age <= 15 }
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
	else_if = {
		limit = { age <= 20 }
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
	else_if = {
		limit = { age <= 30 }
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
	else_if = {
		limit = { age <= 40 }
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
	else_if = {
		limit = { age <= 50 }
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
	else_if = {
		limit = { age <= 60 }
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
	else = {
		hidden_effect = { }
		eotm_debug_log_child_age_inheritance_percentage = yes
	}
}

eotm_debug_log_learning_target_count = {
	if = {
		limit = { exists = var:eotm_learning_target_count }
		if = { limit = { var:eotm_learning_target_count ?= 0 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 1 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 2 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 3 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 4 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 5 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 6 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 7 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 8 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 9 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 10 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 11 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 12 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 13 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 14 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 15 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 16 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 17 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 18 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 19 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 20 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 21 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 22 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 23 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_target_count ?= 24 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else = {
		hidden_effect = { }
	}
}

eotm_debug_log_learning_granted_count = {
	if = {
		limit = { exists = var:eotm_learning_granted_count }
		if = { limit = { var:eotm_learning_granted_count ?= 0 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 1 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 2 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 3 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 4 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 5 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 6 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 7 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 8 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 9 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 10 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 11 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 12 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 13 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 14 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 15 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 16 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 17 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 18 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 19 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 20 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 21 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 22 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 23 } hidden_effect = { } }
		else_if = { limit = { var:eotm_learning_granted_count ?= 24 } hidden_effect = { } }
		else = { hidden_effect = { } }
	}
	else = {
		hidden_effect = { }
	}
}

eotm_mark_learning_inheritance_grant_success = {
	if = {
		limit = { NOT = { exists = var:eotm_learning_granted_count } }
		set_variable = { name = eotm_learning_granted_count value = 0 }
	}
	if = {
		limit = { NOT = { exists = var:eotm_learning_granted_this_attempt } }
		set_variable = { name = eotm_learning_granted_this_attempt value = 0 }
	}
	change_variable = {
		name = eotm_learning_granted_count
		add = 1
	}
	if = {
		limit = { exists = var:eotm_debug_total_granted_count }
		change_variable = { name = eotm_debug_total_granted_count add = 1 }
	}
	set_variable = {
		name = eotm_learning_granted_this_attempt
		value = 1
	}
}

eotm_grant_learning_whole_of_body_final_unlock = {
	add_perk = whole_of_body_perk
	if = {
		limit = { NOT = { has_trait = whole_of_body } }
		add_trait = whole_of_body
	}
	eotm_mark_learning_inheritance_grant_success = yes
	eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_whole_of_body_perk_tt }
	hidden_effect = { }
}

eotm_grant_learning_scholar_final_unlock = {
	add_perk = scholar_perk
	if = {
		limit = { NOT = { has_trait = scholar } }
		add_trait = scholar
	}
	eotm_mark_learning_inheritance_grant_success = yes
	eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_scholar_perk_tt }
	hidden_effect = { }
}

eotm_grant_learning_theologian_final_unlock = {
	add_perk = theologian_perk
	if = {
		limit = { NOT = { has_trait = theologian } }
		add_trait = theologian
	}
	eotm_mark_learning_inheritance_grant_success = yes
	eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_theologian_perk_tt }
	hidden_effect = { }
}

eotm_try_grant_learning_final_unlock = {
	if = {
		limit = { eotm_any_learning_final_unlock_available = yes }
		random_list = {
			pick = 1
			unique = yes
			1 = {
				trigger = { eotm_can_inherit_learning_whole_of_body_final_unlock = yes }
				eotm_grant_learning_whole_of_body_final_unlock = yes
			}
			1 = {
				trigger = { eotm_can_inherit_learning_scholar_final_unlock = yes }
				eotm_grant_learning_scholar_final_unlock = yes
			}
			1 = {
				trigger = { eotm_can_inherit_learning_theologian_final_unlock = yes }
				eotm_grant_learning_theologian_final_unlock = yes
			}
		}
	}
}

eotm_grant_learning_anatomical_studies_perk = { add_perk = anatomical_studies_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_anatomical_studies_perk_tt } hidden_effect = { } }
eotm_grant_learning_carefree_perk = { add_perk = carefree_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_carefree_perk_tt } hidden_effect = { } }
eotm_grant_learning_mental_resilience_perk = { add_perk = mental_resilience_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_mental_resilience_perk_tt } hidden_effect = { } }
eotm_grant_learning_restraint_perk = { add_perk = restraint_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_restraint_perk_tt } hidden_effect = { } }
eotm_grant_learning_know_thyself_perk = { add_perk = know_thyself_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_know_thyself_perk_tt } hidden_effect = { } }
eotm_grant_learning_wash_your_hands_perk = { add_perk = wash_your_hands_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_wash_your_hands_perk_tt } hidden_effect = { } }
eotm_grant_learning_iron_constitution_perk = { add_perk = iron_constitution_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_iron_constitution_perk_tt } hidden_effect = { } }
eotm_grant_learning_healthy_perk = { add_perk = healthy_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_healthy_perk_tt } hidden_effect = { } }
eotm_grant_learning_pedagogy_perk = { add_perk = pedagogy_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_pedagogy_perk_tt } hidden_effect = { } }
eotm_grant_learning_open_minded_perk = { add_perk = open_minded_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_open_minded_perk_tt } hidden_effect = { } }
eotm_grant_learning_apostate_perk = { add_perk = apostate_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_apostate_perk_tt } hidden_effect = { } }
eotm_grant_learning_scientific_perk = { add_perk = scientific_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_scientific_perk_tt } hidden_effect = { } }
eotm_grant_learning_planned_cultivation_perk = { add_perk = planned_cultivation_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_planned_cultivation_perk_tt } hidden_effect = { } }
eotm_grant_learning_scholarly_circles_perk = { add_perk = scholarly_circles_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_scholarly_circles_perk_tt } hidden_effect = { } }
eotm_grant_learning_learn_on_the_job_perk = { add_perk = learn_on_the_job_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_learn_on_the_job_perk_tt } hidden_effect = { } }
eotm_grant_learning_sanctioned_loopholes_perk = { add_perk = sanctioned_loopholes_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_sanctioned_loopholes_perk_tt } hidden_effect = { } }
eotm_grant_learning_faithful_perk = { add_perk = faithful_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_faithful_perk_tt } hidden_effect = { } }
eotm_grant_learning_zealous_proselytizer_perk = { add_perk = zealous_proselytizer_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_zealous_proselytizer_perk_tt } hidden_effect = { } }
eotm_grant_learning_religious_icon_perk = { add_perk = religious_icon_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_religious_icon_perk_tt } hidden_effect = { } }
eotm_grant_learning_prophet_perk = { add_perk = prophet_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_prophet_perk_tt } hidden_effect = { } }
eotm_grant_learning_clerical_justifications_perk = { add_perk = clerical_justifications_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_clerical_justifications_perk_tt } hidden_effect = { } }
eotm_grant_learning_church_and_state_perk = { add_perk = church_and_state_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_church_and_state_perk_tt } hidden_effect = { } }
eotm_grant_learning_radiant_perk = { add_perk = radiant_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_radiant_perk_tt } hidden_effect = { } }
eotm_grant_learning_defender_of_the_faith_perk = { add_perk = defender_of_the_faith_perk eotm_mark_learning_inheritance_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_defender_of_the_faith_perk_tt } hidden_effect = { } }

eotm_grant_learning_medicine_normal_perk_in_order = {
	if = { limit = { eotm_can_inherit_learning_anatomical_studies_perk = yes } eotm_grant_learning_anatomical_studies_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_carefree_perk = yes } eotm_grant_learning_carefree_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_mental_resilience_perk = yes } eotm_grant_learning_mental_resilience_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_restraint_perk = yes } eotm_grant_learning_restraint_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_know_thyself_perk = yes } eotm_grant_learning_know_thyself_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_wash_your_hands_perk = yes } eotm_grant_learning_wash_your_hands_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_iron_constitution_perk = yes } eotm_grant_learning_iron_constitution_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_healthy_perk = yes } eotm_grant_learning_healthy_perk = yes }
}

eotm_grant_learning_scholar_normal_perk_in_order = {
	if = { limit = { eotm_can_inherit_learning_pedagogy_perk = yes } eotm_grant_learning_pedagogy_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_open_minded_perk = yes } eotm_grant_learning_open_minded_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_apostate_perk = yes } eotm_grant_learning_apostate_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_scientific_perk = yes } eotm_grant_learning_scientific_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_planned_cultivation_perk = yes } eotm_grant_learning_planned_cultivation_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_scholarly_circles_perk = yes } eotm_grant_learning_scholarly_circles_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_learn_on_the_job_perk = yes } eotm_grant_learning_learn_on_the_job_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_sanctioned_loopholes_perk = yes } eotm_grant_learning_sanctioned_loopholes_perk = yes }
}

eotm_grant_learning_theology_normal_perk_in_order = {
	if = { limit = { eotm_can_inherit_learning_faithful_perk = yes } eotm_grant_learning_faithful_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_zealous_proselytizer_perk = yes } eotm_grant_learning_zealous_proselytizer_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_religious_icon_perk = yes } eotm_grant_learning_religious_icon_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_prophet_perk = yes } eotm_grant_learning_prophet_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_clerical_justifications_perk = yes } eotm_grant_learning_clerical_justifications_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_church_and_state_perk = yes } eotm_grant_learning_church_and_state_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_radiant_perk = yes } eotm_grant_learning_radiant_perk = yes }
	else_if = { limit = { eotm_can_inherit_learning_defender_of_the_faith_perk = yes } eotm_grant_learning_defender_of_the_faith_perk = yes }
}

eotm_ensure_focused_learning_focus = {
	if = {
		limit = { NOT = { eotm_one_way_learning_focus_can_continue = yes } }
		remove_variable = eotm_one_way_learning_focus
		random_list = {
			pick = 1
			unique = yes
			1 = {
				trigger = { eotm_has_valid_learning_medicine_normal_inheritance_perk = yes }
				set_variable = { name = eotm_one_way_learning_focus value = 1 }
				hidden_effect = { }
			}
			1 = {
				trigger = { eotm_has_valid_learning_scholar_normal_inheritance_perk = yes }
				set_variable = { name = eotm_one_way_learning_focus value = 2 }
				hidden_effect = { }
			}
			1 = {
				trigger = { eotm_has_valid_learning_theology_normal_inheritance_perk = yes }
				set_variable = { name = eotm_one_way_learning_focus value = 3 }
				hidden_effect = { }
			}
		}
	}
}

eotm_grant_focused_learning_normal_perk = {
	eotm_ensure_focused_learning_focus = yes
	if = {
		limit = { eotm_one_way_learning_focus_is_medicine = yes }
		eotm_grant_learning_medicine_normal_perk_in_order = yes
	}
	else_if = {
		limit = { eotm_one_way_learning_focus_is_scholar = yes }
		eotm_grant_learning_scholar_normal_perk_in_order = yes
	}
	else_if = {
		limit = { eotm_one_way_learning_focus_is_theology = yes }
		eotm_grant_learning_theology_normal_perk_in_order = yes
	}
}

eotm_count_child_learning_branch_normal_perks = {
	set_variable = { name = eotm_balanced_medicine_count value = 0 }
	set_variable = { name = eotm_balanced_scholar_count value = 0 }
	set_variable = { name = eotm_balanced_theology_count value = 0 }
	if = { limit = { has_perk = anatomical_studies_perk } change_variable = { name = eotm_balanced_medicine_count add = 1 } }
	if = { limit = { has_perk = carefree_perk } change_variable = { name = eotm_balanced_medicine_count add = 1 } }
	if = { limit = { has_perk = mental_resilience_perk } change_variable = { name = eotm_balanced_medicine_count add = 1 } }
	if = { limit = { has_perk = restraint_perk } change_variable = { name = eotm_balanced_medicine_count add = 1 } }
	if = { limit = { has_perk = know_thyself_perk } change_variable = { name = eotm_balanced_medicine_count add = 1 } }
	if = { limit = { has_perk = wash_your_hands_perk } change_variable = { name = eotm_balanced_medicine_count add = 1 } }
	if = { limit = { has_perk = iron_constitution_perk } change_variable = { name = eotm_balanced_medicine_count add = 1 } }
	if = { limit = { has_perk = healthy_perk } change_variable = { name = eotm_balanced_medicine_count add = 1 } }
	if = { limit = { has_perk = pedagogy_perk } change_variable = { name = eotm_balanced_scholar_count add = 1 } }
	if = { limit = { has_perk = open_minded_perk } change_variable = { name = eotm_balanced_scholar_count add = 1 } }
	if = { limit = { has_perk = apostate_perk } change_variable = { name = eotm_balanced_scholar_count add = 1 } }
	if = { limit = { has_perk = scientific_perk } change_variable = { name = eotm_balanced_scholar_count add = 1 } }
	if = { limit = { has_perk = planned_cultivation_perk } change_variable = { name = eotm_balanced_scholar_count add = 1 } }
	if = { limit = { has_perk = scholarly_circles_perk } change_variable = { name = eotm_balanced_scholar_count add = 1 } }
	if = { limit = { has_perk = learn_on_the_job_perk } change_variable = { name = eotm_balanced_scholar_count add = 1 } }
	if = { limit = { has_perk = sanctioned_loopholes_perk } change_variable = { name = eotm_balanced_scholar_count add = 1 } }
	if = { limit = { has_perk = faithful_perk } change_variable = { name = eotm_balanced_theology_count add = 1 } }
	if = { limit = { has_perk = zealous_proselytizer_perk } change_variable = { name = eotm_balanced_theology_count add = 1 } }
	if = { limit = { has_perk = religious_icon_perk } change_variable = { name = eotm_balanced_theology_count add = 1 } }
	if = { limit = { has_perk = prophet_perk } change_variable = { name = eotm_balanced_theology_count add = 1 } }
	if = { limit = { has_perk = clerical_justifications_perk } change_variable = { name = eotm_balanced_theology_count add = 1 } }
	if = { limit = { has_perk = church_and_state_perk } change_variable = { name = eotm_balanced_theology_count add = 1 } }
	if = { limit = { has_perk = radiant_perk } change_variable = { name = eotm_balanced_theology_count add = 1 } }
	if = { limit = { has_perk = defender_of_the_faith_perk } change_variable = { name = eotm_balanced_theology_count add = 1 } }
}

eotm_grant_harmonious_learning_normal_perk = {
	eotm_count_child_learning_branch_normal_perks = yes
	random_list = {
		pick = 1
		unique = yes
		1 = {
			trigger = { eotm_balanced_learning_medicine_is_lowest_valid_branch = yes }
			eotm_grant_learning_medicine_normal_perk_in_order = yes
		}
		1 = {
			trigger = { eotm_balanced_learning_scholar_is_lowest_valid_branch = yes }
			eotm_grant_learning_scholar_normal_perk_in_order = yes
		}
		1 = {
			trigger = { eotm_balanced_learning_theology_is_lowest_valid_branch = yes }
			eotm_grant_learning_theology_normal_perk_in_order = yes
		}
	}
}

eotm_grant_curious_learning_normal_perk = {
	random_list = {
		pick = 1
		unique = yes
		1 = { trigger = { eotm_can_inherit_learning_anatomical_studies_perk = yes } eotm_grant_learning_anatomical_studies_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_carefree_perk = yes } eotm_grant_learning_carefree_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_mental_resilience_perk = yes } eotm_grant_learning_mental_resilience_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_restraint_perk = yes } eotm_grant_learning_restraint_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_know_thyself_perk = yes } eotm_grant_learning_know_thyself_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_wash_your_hands_perk = yes } eotm_grant_learning_wash_your_hands_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_iron_constitution_perk = yes } eotm_grant_learning_iron_constitution_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_healthy_perk = yes } eotm_grant_learning_healthy_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_pedagogy_perk = yes } eotm_grant_learning_pedagogy_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_open_minded_perk = yes } eotm_grant_learning_open_minded_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_apostate_perk = yes } eotm_grant_learning_apostate_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_scientific_perk = yes } eotm_grant_learning_scientific_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_planned_cultivation_perk = yes } eotm_grant_learning_planned_cultivation_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_scholarly_circles_perk = yes } eotm_grant_learning_scholarly_circles_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_learn_on_the_job_perk = yes } eotm_grant_learning_learn_on_the_job_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_sanctioned_loopholes_perk = yes } eotm_grant_learning_sanctioned_loopholes_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_faithful_perk = yes } eotm_grant_learning_faithful_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_zealous_proselytizer_perk = yes } eotm_grant_learning_zealous_proselytizer_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_religious_icon_perk = yes } eotm_grant_learning_religious_icon_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_prophet_perk = yes } eotm_grant_learning_prophet_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_clerical_justifications_perk = yes } eotm_grant_learning_clerical_justifications_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_church_and_state_perk = yes } eotm_grant_learning_church_and_state_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_radiant_perk = yes } eotm_grant_learning_radiant_perk = yes }
		1 = { trigger = { eotm_can_inherit_learning_defender_of_the_faith_perk = yes } eotm_grant_learning_defender_of_the_faith_perk = yes }
	}
}

eotm_grant_profile_selected_learning_normal_perk = {
	if = {
		limit = { eotm_child_has_one_way_profile = yes }
		eotm_grant_focused_learning_normal_perk = yes
	}
	else_if = {
		limit = { eotm_child_has_balanced_profile = yes }
		eotm_grant_harmonious_learning_normal_perk = yes
	}
	else_if = {
		limit = { eotm_child_has_random_profile = yes }
		eotm_grant_curious_learning_normal_perk = yes
	}
	else = {
		hidden_effect = { }
	}
}

eotm_cleanup_learning_inheritance_child_temp_variables = {
	remove_variable = eotm_child_age_inheritance_percentage
	remove_variable = eotm_learning_target_count
	remove_variable = eotm_learning_granted_count
	remove_variable = eotm_learning_granted_this_attempt
	remove_variable = eotm_learning_attempt_count
	remove_variable = eotm_balanced_medicine_count
	remove_variable = eotm_balanced_scholar_count
	remove_variable = eotm_balanced_theology_count
}

eotm_process_learning_inheritance_child = {
	hidden_effect = { }
	hidden_effect = { }
	hidden_effect = { }
	hidden_effect = { }
	eotm_debug_log_learning_child_age_years = yes
	eotm_backfill_inheritance_profile_if_missing = yes

	if = { limit = { eotm_child_has_one_way_profile = yes } hidden_effect = { } }
	else_if = { limit = { eotm_child_has_balanced_profile = yes } hidden_effect = { } }
	else_if = { limit = { eotm_child_has_random_profile = yes } hidden_effect = { } }

	if = {
		limit = { has_variable = eotm_pending_learning_activation_active has_variable = eotm_pending_learning_target_count }
		set_variable = { name = eotm_learning_target_count value = { value = var:eotm_pending_learning_target_count } }
		hidden_effect = { }
		eotm_debug_log_learning_target_count = yes
	}
	else = {
		eotm_calculate_child_learning_target_count = yes
		eotm_debug_log_learning_age_bracket_and_percentage = yes
		scope:eotm_deceased_parent = { eotm_debug_log_learning_parent_visible_count = yes }
		hidden_effect = { }
		eotm_debug_log_learning_target_count = yes
		eotm_apply_advanced_inheritance_resolver_insertion_points = yes
	}

	set_variable = { name = eotm_learning_granted_count value = 0 }
	set_variable = { name = eotm_learning_attempt_count value = 0 }

	if = {
		limit = {
			exists = var:eotm_learning_granted_count
			exists = var:eotm_learning_target_count
			exists = var:eotm_learning_attempt_count
			var:eotm_learning_target_count ?= 0
		}
		hidden_effect = { }
	}
	else = {
		while = {
			limit = {
				exists = var:eotm_learning_granted_count
				exists = var:eotm_learning_target_count
				exists = var:eotm_learning_attempt_count
				var:eotm_learning_granted_count < var:eotm_learning_target_count
				var:eotm_learning_attempt_count < 60
				eotm_any_learning_inheritance_candidate_available = yes
			}
			change_variable = { name = eotm_learning_attempt_count add = 1 }
			set_variable = { name = eotm_learning_granted_this_attempt value = 0 }

			eotm_try_grant_learning_final_unlock = yes

			if = {
				limit = { var:eotm_learning_granted_this_attempt ?= 0 }
				eotm_grant_profile_selected_learning_normal_perk = yes
			}

			if = {
				limit = { var:eotm_learning_granted_this_attempt ?= 0 }
				hidden_effect = { }
				hidden_effect = { }
				set_variable = { name = eotm_learning_attempt_count value = 60 }
			}
		}

		if = {
			limit = {
				exists = var:eotm_learning_granted_count
				exists = var:eotm_learning_target_count
				var:eotm_learning_granted_count < var:eotm_learning_target_count
				NOT = { eotm_any_learning_inheritance_candidate_available = yes }
			}
			hidden_effect = { }
			hidden_effect = { }
		}

		if = {
			limit = {
				exists = var:eotm_learning_granted_count
				exists = var:eotm_learning_target_count
				exists = var:eotm_learning_attempt_count
				var:eotm_learning_granted_count < var:eotm_learning_target_count
				var:eotm_learning_attempt_count >= 60
				eotm_any_learning_inheritance_candidate_available = yes
			}
			hidden_effect = { }
		}
	}

	eotm_debug_log_learning_granted_count = yes
	eotm_count_learning_visible_perks = yes
	hidden_effect = { }
	eotm_debug_log_learning_visible_perk_count = yes
	remove_variable = eotm_learning_visible_perk_count
	eotm_show_player_inheritance_report_window_effect = yes
	hidden_effect = { }
	eotm_cleanup_learning_inheritance_child_temp_variables = yes
}

eotm_execute_learning_death_inheritance = {
	if = {
		limit = {
			is_ruler = yes
			is_ai = no
		}
		save_scope_as = eotm_deceased_parent
		eotm_count_parent_learning_normal_perks = yes
		eotm_debug_log_learning_parent_visible_count = yes

		every_child = {
			limit = { eotm_is_valid_learning_death_inheritance_child = yes }
			eotm_prepare_pending_learning_inheritance_child = yes
		}

		remove_variable = eotm_parent_learning_normal_perk_count
	}
}

eotm_debug_simulate_learning_death_inheritance_effect = {
	if = {
		limit = { is_ai = no }
		hidden_effect = { }
		eotm_execute_learning_death_inheritance = yes
		hidden_effect = { }
	}
}
