﻿# EOTM Learning death inheritance triggers.
#
# V1 scope: player ruler death/debug simulation to direct living same-dynasty
# children only. All perk checks are explicit base CK3 Learning IDs.

eotm_is_valid_learning_death_inheritance_child = {
	exists = scope:eotm_deceased_parent
	exists = scope:eotm_deceased_parent.dynasty
	exists = dynasty
	is_alive = yes
	NOT = { this = scope:eotm_deceased_parent }
	any_parent = { this = scope:eotm_deceased_parent }
	dynasty = scope:eotm_deceased_parent.dynasty
}

eotm_parent_has_learning_whole_of_body_final_unlock = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = whole_of_body_perk }
		has_variable = eotm_pending_parent_had_learning_whole_of_body_perk
	}
}

eotm_parent_has_learning_scholar_final_unlock = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = scholar_perk }
		has_variable = eotm_pending_parent_had_learning_scholar_perk
	}
}

eotm_parent_has_learning_theologian_final_unlock = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = theologian_perk }
		has_variable = eotm_pending_parent_had_learning_theologian_perk
	}
}

eotm_child_has_learning_medicine_normal_branch_perks = {
	has_perk = anatomical_studies_perk
	has_perk = carefree_perk
	has_perk = mental_resilience_perk
	has_perk = restraint_perk
	has_perk = know_thyself_perk
	has_perk = wash_your_hands_perk
	has_perk = iron_constitution_perk
	has_perk = healthy_perk
}

eotm_child_has_learning_scholar_normal_branch_perks = {
	has_perk = pedagogy_perk
	has_perk = open_minded_perk
	has_perk = apostate_perk
	has_perk = scientific_perk
	has_perk = planned_cultivation_perk
	has_perk = scholarly_circles_perk
	has_perk = learn_on_the_job_perk
	has_perk = sanctioned_loopholes_perk
}

eotm_child_has_learning_theology_normal_branch_perks = {
	has_perk = faithful_perk
	has_perk = zealous_proselytizer_perk
	has_perk = religious_icon_perk
	has_perk = prophet_perk
	has_perk = clerical_justifications_perk
	has_perk = church_and_state_perk
	has_perk = radiant_perk
	has_perk = defender_of_the_faith_perk
}

eotm_can_inherit_learning_whole_of_body_final_unlock = {
	eotm_parent_has_learning_whole_of_body_final_unlock = yes
	eotm_child_has_learning_medicine_normal_branch_perks = yes
	NOT = { has_perk = whole_of_body_perk }
}

eotm_can_inherit_learning_scholar_final_unlock = {
	eotm_parent_has_learning_scholar_final_unlock = yes
	eotm_child_has_learning_scholar_normal_branch_perks = yes
	NOT = { has_perk = scholar_perk }
}

eotm_can_inherit_learning_theologian_final_unlock = {
	eotm_parent_has_learning_theologian_final_unlock = yes
	eotm_child_has_learning_theology_normal_branch_perks = yes
	NOT = { has_perk = theologian_perk }
}

eotm_any_learning_final_unlock_available = {
	OR = {
		eotm_can_inherit_learning_whole_of_body_final_unlock = yes
		eotm_can_inherit_learning_scholar_final_unlock = yes
		eotm_can_inherit_learning_theologian_final_unlock = yes
	}
}

eotm_can_inherit_learning_anatomical_studies_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = anatomical_studies_perk }
		has_variable = eotm_pending_parent_had_learning_anatomical_studies_perk
	}
	NOT = { has_perk = anatomical_studies_perk }
}

eotm_can_inherit_learning_carefree_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = carefree_perk }
		has_variable = eotm_pending_parent_had_learning_carefree_perk
	}
	NOT = { has_perk = carefree_perk }
	has_perk = anatomical_studies_perk
}

eotm_can_inherit_learning_mental_resilience_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = mental_resilience_perk }
		has_variable = eotm_pending_parent_had_learning_mental_resilience_perk
	}
	NOT = { has_perk = mental_resilience_perk }
	has_perk = carefree_perk
}

eotm_can_inherit_learning_restraint_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = restraint_perk }
		has_variable = eotm_pending_parent_had_learning_restraint_perk
	}
	NOT = { has_perk = restraint_perk }
	has_perk = anatomical_studies_perk
}

eotm_can_inherit_learning_know_thyself_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = know_thyself_perk }
		has_variable = eotm_pending_parent_had_learning_know_thyself_perk
	}
	NOT = { has_perk = know_thyself_perk }
	has_perk = restraint_perk
}

eotm_can_inherit_learning_wash_your_hands_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = wash_your_hands_perk }
		has_variable = eotm_pending_parent_had_learning_wash_your_hands_perk
	}
	NOT = { has_perk = wash_your_hands_perk }
	has_perk = anatomical_studies_perk
}

eotm_can_inherit_learning_iron_constitution_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = iron_constitution_perk }
		has_variable = eotm_pending_parent_had_learning_iron_constitution_perk
	}
	NOT = { has_perk = iron_constitution_perk }
	has_perk = wash_your_hands_perk
}

eotm_can_inherit_learning_healthy_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = healthy_perk }
		has_variable = eotm_pending_parent_had_learning_healthy_perk
	}
	NOT = { has_perk = healthy_perk }
	has_perk = mental_resilience_perk
	has_perk = know_thyself_perk
	has_perk = iron_constitution_perk
}

eotm_can_inherit_learning_pedagogy_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = pedagogy_perk }
		has_variable = eotm_pending_parent_had_learning_pedagogy_perk
	}
	NOT = { has_perk = pedagogy_perk }
}

eotm_can_inherit_learning_open_minded_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = open_minded_perk }
		has_variable = eotm_pending_parent_had_learning_open_minded_perk
	}
	NOT = { has_perk = open_minded_perk }
	has_perk = pedagogy_perk
}

eotm_can_inherit_learning_apostate_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = apostate_perk }
		has_variable = eotm_pending_parent_had_learning_apostate_perk
	}
	NOT = { has_perk = apostate_perk }
	has_perk = open_minded_perk
}

eotm_can_inherit_learning_scientific_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = scientific_perk }
		has_variable = eotm_pending_parent_had_learning_scientific_perk
	}
	NOT = { has_perk = scientific_perk }
}

eotm_can_inherit_learning_planned_cultivation_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = planned_cultivation_perk }
		has_variable = eotm_pending_parent_had_learning_planned_cultivation_perk
	}
	NOT = { has_perk = planned_cultivation_perk }
	has_perk = scientific_perk
}

eotm_can_inherit_learning_scholarly_circles_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = scholarly_circles_perk }
		has_variable = eotm_pending_parent_had_learning_scholarly_circles_perk
	}
	NOT = { has_perk = scholarly_circles_perk }
	has_perk = planned_cultivation_perk
}

eotm_can_inherit_learning_learn_on_the_job_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = learn_on_the_job_perk }
		has_variable = eotm_pending_parent_had_learning_learn_on_the_job_perk
	}
	NOT = { has_perk = learn_on_the_job_perk }
	has_perk = apostate_perk
	has_perk = scholarly_circles_perk
}

eotm_can_inherit_learning_sanctioned_loopholes_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = sanctioned_loopholes_perk }
		has_variable = eotm_pending_parent_had_learning_sanctioned_loopholes_perk
	}
	NOT = { has_perk = sanctioned_loopholes_perk }
	has_perk = learn_on_the_job_perk
}

eotm_can_inherit_learning_faithful_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = faithful_perk }
		has_variable = eotm_pending_parent_had_learning_faithful_perk
	}
	NOT = { has_perk = faithful_perk }
}

eotm_can_inherit_learning_zealous_proselytizer_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = zealous_proselytizer_perk }
		has_variable = eotm_pending_parent_had_learning_zealous_proselytizer_perk
	}
	NOT = { has_perk = zealous_proselytizer_perk }
	has_perk = faithful_perk
}

eotm_can_inherit_learning_religious_icon_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = religious_icon_perk }
		has_variable = eotm_pending_parent_had_learning_religious_icon_perk
	}
	NOT = { has_perk = religious_icon_perk }
	has_perk = zealous_proselytizer_perk
}

eotm_can_inherit_learning_prophet_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = prophet_perk }
		has_variable = eotm_pending_parent_had_learning_prophet_perk
	}
	NOT = { has_perk = prophet_perk }
	has_perk = religious_icon_perk
}

eotm_can_inherit_learning_clerical_justifications_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = clerical_justifications_perk }
		has_variable = eotm_pending_parent_had_learning_clerical_justifications_perk
	}
	NOT = { has_perk = clerical_justifications_perk }
	has_perk = faithful_perk
}

eotm_can_inherit_learning_church_and_state_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = church_and_state_perk }
		has_variable = eotm_pending_parent_had_learning_church_and_state_perk
	}
	NOT = { has_perk = church_and_state_perk }
	has_perk = clerical_justifications_perk
}

eotm_can_inherit_learning_radiant_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = radiant_perk }
		has_variable = eotm_pending_parent_had_learning_radiant_perk
	}
	NOT = { has_perk = radiant_perk }
	has_perk = church_and_state_perk
}

eotm_can_inherit_learning_defender_of_the_faith_perk = {
	OR = {
		scope:eotm_deceased_parent ?= { has_perk = defender_of_the_faith_perk }
		has_variable = eotm_pending_parent_had_learning_defender_of_the_faith_perk
	}
	NOT = { has_perk = defender_of_the_faith_perk }
	has_perk = radiant_perk
	has_perk = prophet_perk
}

eotm_has_valid_learning_medicine_normal_inheritance_perk = {
	OR = {
		eotm_can_inherit_learning_anatomical_studies_perk = yes
		eotm_can_inherit_learning_carefree_perk = yes
		eotm_can_inherit_learning_mental_resilience_perk = yes
		eotm_can_inherit_learning_restraint_perk = yes
		eotm_can_inherit_learning_know_thyself_perk = yes
		eotm_can_inherit_learning_wash_your_hands_perk = yes
		eotm_can_inherit_learning_iron_constitution_perk = yes
		eotm_can_inherit_learning_healthy_perk = yes
	}
}

eotm_has_valid_learning_scholar_normal_inheritance_perk = {
	OR = {
		eotm_can_inherit_learning_pedagogy_perk = yes
		eotm_can_inherit_learning_open_minded_perk = yes
		eotm_can_inherit_learning_apostate_perk = yes
		eotm_can_inherit_learning_scientific_perk = yes
		eotm_can_inherit_learning_planned_cultivation_perk = yes
		eotm_can_inherit_learning_scholarly_circles_perk = yes
		eotm_can_inherit_learning_learn_on_the_job_perk = yes
		eotm_can_inherit_learning_sanctioned_loopholes_perk = yes
	}
}

eotm_has_valid_learning_theology_normal_inheritance_perk = {
	OR = {
		eotm_can_inherit_learning_faithful_perk = yes
		eotm_can_inherit_learning_zealous_proselytizer_perk = yes
		eotm_can_inherit_learning_religious_icon_perk = yes
		eotm_can_inherit_learning_prophet_perk = yes
		eotm_can_inherit_learning_clerical_justifications_perk = yes
		eotm_can_inherit_learning_church_and_state_perk = yes
		eotm_can_inherit_learning_radiant_perk = yes
		eotm_can_inherit_learning_defender_of_the_faith_perk = yes
	}
}

eotm_has_any_valid_learning_normal_inheritance_perk = {
	OR = {
		eotm_has_valid_learning_medicine_normal_inheritance_perk = yes
		eotm_has_valid_learning_scholar_normal_inheritance_perk = yes
		eotm_has_valid_learning_theology_normal_inheritance_perk = yes
	}
}

eotm_any_learning_inheritance_candidate_available = {
	OR = {
		eotm_any_learning_final_unlock_available = yes
		eotm_has_any_valid_learning_normal_inheritance_perk = yes
	}
}

eotm_can_debug_grant_learning_whole_of_body_final_unlock = {
	eotm_child_has_learning_medicine_normal_branch_perks = yes
	NOT = { has_perk = whole_of_body_perk }
}

eotm_can_debug_grant_learning_scholar_final_unlock = {
	eotm_child_has_learning_scholar_normal_branch_perks = yes
	NOT = { has_perk = scholar_perk }
}

eotm_can_debug_grant_learning_theologian_final_unlock = {
	eotm_child_has_learning_theology_normal_branch_perks = yes
	NOT = { has_perk = theologian_perk }
}

eotm_any_debug_learning_final_unlock_available = {
	OR = {
		eotm_can_debug_grant_learning_whole_of_body_final_unlock = yes
		eotm_can_debug_grant_learning_scholar_final_unlock = yes
		eotm_can_debug_grant_learning_theologian_final_unlock = yes
	}
}

eotm_can_debug_grant_learning_anatomical_studies_perk = {
	NOT = { has_perk = anatomical_studies_perk }
}

eotm_can_debug_grant_learning_carefree_perk = {
	NOT = { has_perk = carefree_perk }
	has_perk = anatomical_studies_perk
}

eotm_can_debug_grant_learning_mental_resilience_perk = {
	NOT = { has_perk = mental_resilience_perk }
	has_perk = carefree_perk
}

eotm_can_debug_grant_learning_restraint_perk = {
	NOT = { has_perk = restraint_perk }
	has_perk = anatomical_studies_perk
}

eotm_can_debug_grant_learning_know_thyself_perk = {
	NOT = { has_perk = know_thyself_perk }
	has_perk = restraint_perk
}

eotm_can_debug_grant_learning_wash_your_hands_perk = {
	NOT = { has_perk = wash_your_hands_perk }
	has_perk = anatomical_studies_perk
}

eotm_can_debug_grant_learning_iron_constitution_perk = {
	NOT = { has_perk = iron_constitution_perk }
	has_perk = wash_your_hands_perk
}

eotm_can_debug_grant_learning_healthy_perk = {
	NOT = { has_perk = healthy_perk }
	has_perk = mental_resilience_perk
	has_perk = know_thyself_perk
	has_perk = iron_constitution_perk
}

eotm_can_debug_grant_learning_pedagogy_perk = {
	NOT = { has_perk = pedagogy_perk }
}

eotm_can_debug_grant_learning_open_minded_perk = {
	NOT = { has_perk = open_minded_perk }
	has_perk = pedagogy_perk
}

eotm_can_debug_grant_learning_apostate_perk = {
	NOT = { has_perk = apostate_perk }
	has_perk = open_minded_perk
}

eotm_can_debug_grant_learning_scientific_perk = {
	NOT = { has_perk = scientific_perk }
}

eotm_can_debug_grant_learning_planned_cultivation_perk = {
	NOT = { has_perk = planned_cultivation_perk }
	has_perk = scientific_perk
}

eotm_can_debug_grant_learning_scholarly_circles_perk = {
	NOT = { has_perk = scholarly_circles_perk }
	has_perk = planned_cultivation_perk
}

eotm_can_debug_grant_learning_learn_on_the_job_perk = {
	NOT = { has_perk = learn_on_the_job_perk }
	has_perk = apostate_perk
	has_perk = scholarly_circles_perk
}

eotm_can_debug_grant_learning_sanctioned_loopholes_perk = {
	NOT = { has_perk = sanctioned_loopholes_perk }
	has_perk = learn_on_the_job_perk
}

eotm_can_debug_grant_learning_faithful_perk = {
	NOT = { has_perk = faithful_perk }
}

eotm_can_debug_grant_learning_zealous_proselytizer_perk = {
	NOT = { has_perk = zealous_proselytizer_perk }
	has_perk = faithful_perk
}

eotm_can_debug_grant_learning_religious_icon_perk = {
	NOT = { has_perk = religious_icon_perk }
	has_perk = zealous_proselytizer_perk
}

eotm_can_debug_grant_learning_prophet_perk = {
	NOT = { has_perk = prophet_perk }
	has_perk = religious_icon_perk
}

eotm_can_debug_grant_learning_clerical_justifications_perk = {
	NOT = { has_perk = clerical_justifications_perk }
	has_perk = faithful_perk
}

eotm_can_debug_grant_learning_church_and_state_perk = {
	NOT = { has_perk = church_and_state_perk }
	has_perk = clerical_justifications_perk
}

eotm_can_debug_grant_learning_radiant_perk = {
	NOT = { has_perk = radiant_perk }
	has_perk = church_and_state_perk
}

eotm_can_debug_grant_learning_defender_of_the_faith_perk = {
	NOT = { has_perk = defender_of_the_faith_perk }
	has_perk = radiant_perk
	has_perk = prophet_perk
}

eotm_has_valid_debug_learning_medicine_normal_perk = {
	OR = {
		eotm_can_debug_grant_learning_anatomical_studies_perk = yes
		eotm_can_debug_grant_learning_carefree_perk = yes
		eotm_can_debug_grant_learning_mental_resilience_perk = yes
		eotm_can_debug_grant_learning_restraint_perk = yes
		eotm_can_debug_grant_learning_know_thyself_perk = yes
		eotm_can_debug_grant_learning_wash_your_hands_perk = yes
		eotm_can_debug_grant_learning_iron_constitution_perk = yes
		eotm_can_debug_grant_learning_healthy_perk = yes
	}
}

eotm_has_valid_debug_learning_scholar_normal_perk = {
	OR = {
		eotm_can_debug_grant_learning_pedagogy_perk = yes
		eotm_can_debug_grant_learning_open_minded_perk = yes
		eotm_can_debug_grant_learning_apostate_perk = yes
		eotm_can_debug_grant_learning_scientific_perk = yes
		eotm_can_debug_grant_learning_planned_cultivation_perk = yes
		eotm_can_debug_grant_learning_scholarly_circles_perk = yes
		eotm_can_debug_grant_learning_learn_on_the_job_perk = yes
		eotm_can_debug_grant_learning_sanctioned_loopholes_perk = yes
	}
}

eotm_has_valid_debug_learning_theology_normal_perk = {
	OR = {
		eotm_can_debug_grant_learning_faithful_perk = yes
		eotm_can_debug_grant_learning_zealous_proselytizer_perk = yes
		eotm_can_debug_grant_learning_religious_icon_perk = yes
		eotm_can_debug_grant_learning_prophet_perk = yes
		eotm_can_debug_grant_learning_clerical_justifications_perk = yes
		eotm_can_debug_grant_learning_church_and_state_perk = yes
		eotm_can_debug_grant_learning_radiant_perk = yes
		eotm_can_debug_grant_learning_defender_of_the_faith_perk = yes
	}
}

eotm_has_any_valid_debug_learning_normal_perk = {
	OR = {
		eotm_has_valid_debug_learning_medicine_normal_perk = yes
		eotm_has_valid_debug_learning_scholar_normal_perk = yes
		eotm_has_valid_debug_learning_theology_normal_perk = yes
	}
}

eotm_any_debug_learning_candidate_available = {
	OR = {
		eotm_any_debug_learning_final_unlock_available = yes
		eotm_has_any_valid_debug_learning_normal_perk = yes
	}
}

eotm_one_way_learning_focus_is_medicine = {
	has_variable = eotm_one_way_learning_focus
	var:eotm_one_way_learning_focus ?= 1
}

eotm_one_way_learning_focus_is_scholar = {
	has_variable = eotm_one_way_learning_focus
	var:eotm_one_way_learning_focus ?= 2
}

eotm_one_way_learning_focus_is_theology = {
	has_variable = eotm_one_way_learning_focus
	var:eotm_one_way_learning_focus ?= 3
}

eotm_one_way_learning_focus_can_continue = {
	OR = {
		AND = {
			eotm_one_way_learning_focus_is_medicine = yes
			eotm_has_valid_learning_medicine_normal_inheritance_perk = yes
		}
		AND = {
			eotm_one_way_learning_focus_is_scholar = yes
			eotm_has_valid_learning_scholar_normal_inheritance_perk = yes
		}
		AND = {
			eotm_one_way_learning_focus_is_theology = yes
			eotm_has_valid_learning_theology_normal_inheritance_perk = yes
		}
	}
}

eotm_balanced_learning_medicine_is_lowest_valid_branch = {
	eotm_has_valid_learning_medicine_normal_inheritance_perk = yes
	exists = var:eotm_balanced_medicine_count
	exists = var:eotm_balanced_scholar_count
	exists = var:eotm_balanced_theology_count
	var:eotm_balanced_medicine_count <= var:eotm_balanced_scholar_count
	var:eotm_balanced_medicine_count <= var:eotm_balanced_theology_count
}

eotm_balanced_learning_scholar_is_lowest_valid_branch = {
	eotm_has_valid_learning_scholar_normal_inheritance_perk = yes
	exists = var:eotm_balanced_medicine_count
	exists = var:eotm_balanced_scholar_count
	exists = var:eotm_balanced_theology_count
	var:eotm_balanced_scholar_count <= var:eotm_balanced_medicine_count
	var:eotm_balanced_scholar_count <= var:eotm_balanced_theology_count
}

eotm_balanced_learning_theology_is_lowest_valid_branch = {
	eotm_has_valid_learning_theology_normal_inheritance_perk = yes
	exists = var:eotm_balanced_medicine_count
	exists = var:eotm_balanced_scholar_count
	exists = var:eotm_balanced_theology_count
	var:eotm_balanced_theology_count <= var:eotm_balanced_medicine_count
	var:eotm_balanced_theology_count <= var:eotm_balanced_scholar_count
}
