﻿# EOTM Diplomacy progression and death inheritance helpers.
#
# Mirrors the frozen Learning/Martial architecture. Base CK3 Diplomacy only;
# Wanderer/DLC lifestyle support is intentionally separate.

eotm_count_diplomacy_visible_perks = {
	set_variable = { name = eotm_diplomacy_visible_perk_count value = 0 }
	if = { limit = { has_perk = thoughtful_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = ducal_conquest_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = forced_vassalage_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = adaptive_traditions_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = flexible_truces_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = defensive_negotiations_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = embassies_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = accomplished_forger_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = diplomat_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = benevolent_intent_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = inspiring_rule_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = firm_hand_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = praetorian_guard_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = true_ruler_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = writing_history_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = a_life_of_glory_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = dignitas_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = august_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = befriend_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = confidants_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = flatterer_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = friendly_counsel_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = familial_familiar_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = groomed_to_rule_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = thicker_than_water_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = sound_foundations_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = family_man_perk } change_variable = { name = eotm_diplomacy_visible_perk_count add = 1 } }
}

eotm_count_parent_diplomacy_visible_perks = {
	set_variable = { name = eotm_parent_diplomacy_visible_perk_count value = 0 }
	if = { limit = { has_perk = thoughtful_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = ducal_conquest_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = forced_vassalage_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = adaptive_traditions_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = flexible_truces_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = defensive_negotiations_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = embassies_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = accomplished_forger_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = diplomat_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = benevolent_intent_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = inspiring_rule_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = firm_hand_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = praetorian_guard_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = true_ruler_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = writing_history_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = a_life_of_glory_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = dignitas_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = august_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = befriend_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = confidants_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = flatterer_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = friendly_counsel_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = familial_familiar_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = groomed_to_rule_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = thicker_than_water_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = sound_foundations_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
	if = { limit = { has_perk = family_man_perk } change_variable = { name = eotm_parent_diplomacy_visible_perk_count add = 1 } }
}

eotm_count_diplomacy_final_visible_perks = {
	set_variable = { name = eotm_diplomacy_final_visible_perk_count value = 0 }
	if = { limit = { has_perk = diplomat_perk } change_variable = { name = eotm_diplomacy_final_visible_perk_count add = 1 } }
	if = { limit = { has_perk = august_perk } change_variable = { name = eotm_diplomacy_final_visible_perk_count add = 1 } }
	if = { limit = { has_perk = family_man_perk } change_variable = { name = eotm_diplomacy_final_visible_perk_count add = 1 } }
}

eotm_count_parent_diplomacy_final_visible_perks = {
	set_variable = { name = eotm_parent_diplomacy_final_visible_perk_count value = 0 }
	if = { limit = { has_perk = diplomat_perk } change_variable = { name = eotm_parent_diplomacy_final_visible_perk_count add = 1 } }
	if = { limit = { has_perk = august_perk } change_variable = { name = eotm_parent_diplomacy_final_visible_perk_count add = 1 } }
	if = { limit = { has_perk = family_man_perk } change_variable = { name = eotm_parent_diplomacy_final_visible_perk_count add = 1 } }
}

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

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

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

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

eotm_debug_count_current_diplomacy_perks_for_clear = {
	set_variable = { name = eotm_debug_diplomacy_perks_removed_count value = 0 }
	if = { limit = { has_perk = thoughtful_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = ducal_conquest_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = forced_vassalage_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = adaptive_traditions_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = flexible_truces_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = defensive_negotiations_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = embassies_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = accomplished_forger_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = diplomat_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = benevolent_intent_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = inspiring_rule_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = firm_hand_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = praetorian_guard_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = true_ruler_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = writing_history_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = a_life_of_glory_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = dignitas_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = august_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = befriend_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = confidants_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = flatterer_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = friendly_counsel_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = familial_familiar_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = groomed_to_rule_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = thicker_than_water_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = sound_foundations_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
	if = { limit = { has_perk = family_man_perk } change_variable = { name = eotm_debug_diplomacy_perks_removed_count add = 1 } }
}

eotm_debug_count_current_diplomacy_final_perks_for_clear = {
	set_variable = { name = eotm_debug_diplomacy_final_perks_removed_count value = 0 }
	if = { limit = { has_perk = diplomat_perk } change_variable = { name = eotm_debug_diplomacy_final_perks_removed_count add = 1 } }
	if = { limit = { has_perk = august_perk } change_variable = { name = eotm_debug_diplomacy_final_perks_removed_count add = 1 } }
	if = { limit = { has_perk = family_man_perk } change_variable = { name = eotm_debug_diplomacy_final_perks_removed_count add = 1 } }
}

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

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

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

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

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

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

eotm_mark_diplomacy_grant_success = {
	if = { limit = { NOT = { exists = var:eotm_diplomacy_granted_count } } set_variable = { name = eotm_diplomacy_granted_count value = 0 } }
	if = { limit = { NOT = { exists = var:eotm_diplomacy_granted_this_attempt } } set_variable = { name = eotm_diplomacy_granted_this_attempt value = 0 } }
	change_variable = { name = eotm_diplomacy_granted_count add = 1 }
	set_variable = { name = eotm_diplomacy_granted_this_attempt value = 1 }
}

eotm_grant_diplomacy_foreign_affairs_final_unlock = {
	add_perk = diplomat_perk
	if = { limit = { NOT = { has_trait = diplomat } } add_trait = diplomat }
	eotm_mark_diplomacy_grant_success = yes
	eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_diplomat_perk_tt }
	hidden_effect = { }
}

eotm_grant_diplomacy_inheritance_foreign_affairs_final_unlock = {
	add_perk = diplomat_perk
	if = { limit = { NOT = { has_trait = diplomat } } add_trait = diplomat }
	eotm_mark_diplomacy_grant_success = yes
	hidden_effect = { }
}

eotm_grant_diplomacy_majesty_final_unlock = {
	add_perk = august_perk
	if = { limit = { NOT = { has_trait = august } } add_trait = august }
	eotm_mark_diplomacy_grant_success = yes
	eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_august_perk_tt }
	hidden_effect = { }
}

eotm_grant_diplomacy_inheritance_majesty_final_unlock = {
	add_perk = august_perk
	if = { limit = { NOT = { has_trait = august } } add_trait = august }
	eotm_mark_diplomacy_grant_success = yes
	hidden_effect = { }
}

eotm_grant_diplomacy_family_final_unlock = {
	add_perk = family_man_perk
	if = { limit = { NOT = { has_trait = family_first } } add_trait = family_first }
	eotm_mark_diplomacy_grant_success = yes
	eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_family_man_perk_tt }
	hidden_effect = { }
}

eotm_grant_diplomacy_inheritance_family_final_unlock = {
	add_perk = family_man_perk
	if = { limit = { NOT = { has_trait = family_first } } add_trait = family_first }
	eotm_mark_diplomacy_grant_success = yes
	hidden_effect = { }
}

eotm_grant_diplomacy_thoughtful_perk = { add_perk = thoughtful_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_thoughtful_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_ducal_conquest_perk = { add_perk = ducal_conquest_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_ducal_conquest_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_forced_vassalage_perk = { add_perk = forced_vassalage_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_forced_vassalage_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_adaptive_traditions_perk = { add_perk = adaptive_traditions_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_adaptive_traditions_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_flexible_truces_perk = { add_perk = flexible_truces_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_flexible_truces_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_defensive_negotiations_perk = { add_perk = defensive_negotiations_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_defensive_negotiations_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_embassies_perk = { add_perk = embassies_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_embassies_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_accomplished_forger_perk = { add_perk = accomplished_forger_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_accomplished_forger_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_benevolent_intent_perk = { add_perk = benevolent_intent_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_benevolent_intent_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_inspiring_rule_perk = { add_perk = inspiring_rule_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_inspiring_rule_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_firm_hand_perk = { add_perk = firm_hand_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_firm_hand_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_praetorian_guard_perk = { add_perk = praetorian_guard_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_praetorian_guard_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_true_ruler_perk = { add_perk = true_ruler_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_true_ruler_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_writing_history_perk = { add_perk = writing_history_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_writing_history_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_a_life_of_glory_perk = { add_perk = a_life_of_glory_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_a_life_of_glory_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_dignitas_perk = { add_perk = dignitas_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_dignitas_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_befriend_perk = { add_perk = befriend_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_befriend_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_confidants_perk = { add_perk = confidants_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_confidants_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_flatterer_perk = { add_perk = flatterer_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_flatterer_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_friendly_counsel_perk = { add_perk = friendly_counsel_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_friendly_counsel_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_familial_familiar_perk = { add_perk = familial_familiar_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_familial_familiar_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_groomed_to_rule_perk = { add_perk = groomed_to_rule_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_groomed_to_rule_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_thicker_than_water_perk = { add_perk = thicker_than_water_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_thicker_than_water_perk_tt } hidden_effect = { } }
eotm_grant_diplomacy_sound_foundations_perk = { add_perk = sound_foundations_perk eotm_mark_diplomacy_grant_success = yes eotm_lifestyle_auto_spend_send_perk_toast = { TOAST = eotm_lifestyle_auto_spend_toast_sound_foundations_perk_tt } hidden_effect = { } }

eotm_grant_diplomacy_inheritance_thoughtful_perk = { add_perk = thoughtful_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_ducal_conquest_perk = { add_perk = ducal_conquest_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_forced_vassalage_perk = { add_perk = forced_vassalage_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_adaptive_traditions_perk = { add_perk = adaptive_traditions_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_flexible_truces_perk = { add_perk = flexible_truces_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_defensive_negotiations_perk = { add_perk = defensive_negotiations_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_embassies_perk = { add_perk = embassies_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_accomplished_forger_perk = { add_perk = accomplished_forger_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_benevolent_intent_perk = { add_perk = benevolent_intent_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_inspiring_rule_perk = { add_perk = inspiring_rule_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_firm_hand_perk = { add_perk = firm_hand_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_praetorian_guard_perk = { add_perk = praetorian_guard_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_true_ruler_perk = { add_perk = true_ruler_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_writing_history_perk = { add_perk = writing_history_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_a_life_of_glory_perk = { add_perk = a_life_of_glory_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_dignitas_perk = { add_perk = dignitas_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_befriend_perk = { add_perk = befriend_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_confidants_perk = { add_perk = confidants_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_flatterer_perk = { add_perk = flatterer_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_friendly_counsel_perk = { add_perk = friendly_counsel_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_familial_familiar_perk = { add_perk = familial_familiar_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_groomed_to_rule_perk = { add_perk = groomed_to_rule_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_thicker_than_water_perk = { add_perk = thicker_than_water_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }
eotm_grant_diplomacy_inheritance_sound_foundations_perk = { add_perk = sound_foundations_perk eotm_mark_diplomacy_grant_success = yes hidden_effect = { } }

eotm_debug_try_grant_diplomacy_final_unlock = {
	if = {
		limit = { eotm_any_debug_diplomacy_final_unlock_available = yes }
		random_list = {
			pick = 1
			unique = yes
			1 = { trigger = { eotm_can_debug_grant_diplomacy_foreign_affairs_final_unlock = yes } eotm_grant_diplomacy_foreign_affairs_final_unlock = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_majesty_final_unlock = yes } eotm_grant_diplomacy_majesty_final_unlock = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_family_final_unlock = yes } eotm_grant_diplomacy_family_final_unlock = yes }
		}
	}
}

eotm_try_grant_diplomacy_final_unlock = {
	if = {
		limit = { eotm_any_diplomacy_final_unlock_available = yes }
		random_list = {
			pick = 1
			unique = yes
			1 = { trigger = { eotm_can_inherit_diplomacy_foreign_affairs_final_unlock = yes } eotm_grant_diplomacy_inheritance_foreign_affairs_final_unlock = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_majesty_final_unlock = yes } eotm_grant_diplomacy_inheritance_majesty_final_unlock = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_family_final_unlock = yes } eotm_grant_diplomacy_inheritance_family_final_unlock = yes }
		}
	}
}

eotm_debug_grant_curious_diplomacy_perk = {
	if = {
		limit = { eotm_has_any_valid_debug_diplomacy_normal_perk = yes }
		random_list = {
			pick = 1
			unique = yes
			1 = { trigger = { eotm_can_debug_grant_diplomacy_thoughtful_perk = yes } eotm_grant_diplomacy_thoughtful_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_ducal_conquest_perk = yes } eotm_grant_diplomacy_ducal_conquest_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_forced_vassalage_perk = yes } eotm_grant_diplomacy_forced_vassalage_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_adaptive_traditions_perk = yes } eotm_grant_diplomacy_adaptive_traditions_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_flexible_truces_perk = yes } eotm_grant_diplomacy_flexible_truces_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_defensive_negotiations_perk = yes } eotm_grant_diplomacy_defensive_negotiations_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_embassies_perk = yes } eotm_grant_diplomacy_embassies_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_accomplished_forger_perk = yes } eotm_grant_diplomacy_accomplished_forger_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_benevolent_intent_perk = yes } eotm_grant_diplomacy_benevolent_intent_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_inspiring_rule_perk = yes } eotm_grant_diplomacy_inspiring_rule_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_firm_hand_perk = yes } eotm_grant_diplomacy_firm_hand_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_praetorian_guard_perk = yes } eotm_grant_diplomacy_praetorian_guard_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_true_ruler_perk = yes } eotm_grant_diplomacy_true_ruler_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_writing_history_perk = yes } eotm_grant_diplomacy_writing_history_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_a_life_of_glory_perk = yes } eotm_grant_diplomacy_a_life_of_glory_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_dignitas_perk = yes } eotm_grant_diplomacy_dignitas_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_befriend_perk = yes } eotm_grant_diplomacy_befriend_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_confidants_perk = yes } eotm_grant_diplomacy_confidants_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_flatterer_perk = yes } eotm_grant_diplomacy_flatterer_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_friendly_counsel_perk = yes } eotm_grant_diplomacy_friendly_counsel_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_familial_familiar_perk = yes } eotm_grant_diplomacy_familial_familiar_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_groomed_to_rule_perk = yes } eotm_grant_diplomacy_groomed_to_rule_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_thicker_than_water_perk = yes } eotm_grant_diplomacy_thicker_than_water_perk = yes }
			1 = { trigger = { eotm_can_debug_grant_diplomacy_sound_foundations_perk = yes } eotm_grant_diplomacy_sound_foundations_perk = yes }
		}
	}
}

eotm_grant_curious_diplomacy_normal_perk = {
	if = {
		limit = { eotm_has_any_valid_diplomacy_normal_inheritance_perk = yes }
		random_list = {
			pick = 1
			unique = yes
			1 = { trigger = { eotm_can_inherit_diplomacy_thoughtful_perk = yes } eotm_grant_diplomacy_inheritance_thoughtful_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_ducal_conquest_perk = yes } eotm_grant_diplomacy_inheritance_ducal_conquest_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_forced_vassalage_perk = yes } eotm_grant_diplomacy_inheritance_forced_vassalage_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_adaptive_traditions_perk = yes } eotm_grant_diplomacy_inheritance_adaptive_traditions_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_flexible_truces_perk = yes } eotm_grant_diplomacy_inheritance_flexible_truces_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_defensive_negotiations_perk = yes } eotm_grant_diplomacy_inheritance_defensive_negotiations_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_embassies_perk = yes } eotm_grant_diplomacy_inheritance_embassies_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_accomplished_forger_perk = yes } eotm_grant_diplomacy_inheritance_accomplished_forger_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_benevolent_intent_perk = yes } eotm_grant_diplomacy_inheritance_benevolent_intent_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_inspiring_rule_perk = yes } eotm_grant_diplomacy_inheritance_inspiring_rule_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_firm_hand_perk = yes } eotm_grant_diplomacy_inheritance_firm_hand_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_praetorian_guard_perk = yes } eotm_grant_diplomacy_inheritance_praetorian_guard_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_true_ruler_perk = yes } eotm_grant_diplomacy_inheritance_true_ruler_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_writing_history_perk = yes } eotm_grant_diplomacy_inheritance_writing_history_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_a_life_of_glory_perk = yes } eotm_grant_diplomacy_inheritance_a_life_of_glory_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_dignitas_perk = yes } eotm_grant_diplomacy_inheritance_dignitas_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_befriend_perk = yes } eotm_grant_diplomacy_inheritance_befriend_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_confidants_perk = yes } eotm_grant_diplomacy_inheritance_confidants_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_flatterer_perk = yes } eotm_grant_diplomacy_inheritance_flatterer_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_friendly_counsel_perk = yes } eotm_grant_diplomacy_inheritance_friendly_counsel_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_familial_familiar_perk = yes } eotm_grant_diplomacy_inheritance_familial_familiar_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_groomed_to_rule_perk = yes } eotm_grant_diplomacy_inheritance_groomed_to_rule_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_thicker_than_water_perk = yes } eotm_grant_diplomacy_inheritance_thicker_than_water_perk = yes }
			1 = { trigger = { eotm_can_inherit_diplomacy_sound_foundations_perk = yes } eotm_grant_diplomacy_inheritance_sound_foundations_perk = yes }
		}
	}
}

eotm_grant_diplomacy_foreign_affairs_normal_perk_in_order = {
	if = { limit = { eotm_can_inherit_diplomacy_thoughtful_perk = yes } eotm_grant_diplomacy_inheritance_thoughtful_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_ducal_conquest_perk = yes } eotm_grant_diplomacy_inheritance_ducal_conquest_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_forced_vassalage_perk = yes } eotm_grant_diplomacy_inheritance_forced_vassalage_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_adaptive_traditions_perk = yes } eotm_grant_diplomacy_inheritance_adaptive_traditions_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_flexible_truces_perk = yes } eotm_grant_diplomacy_inheritance_flexible_truces_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_defensive_negotiations_perk = yes } eotm_grant_diplomacy_inheritance_defensive_negotiations_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_embassies_perk = yes } eotm_grant_diplomacy_inheritance_embassies_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_accomplished_forger_perk = yes } eotm_grant_diplomacy_inheritance_accomplished_forger_perk = yes }
}

eotm_grant_diplomacy_majesty_normal_perk_in_order = {
	if = { limit = { eotm_can_inherit_diplomacy_benevolent_intent_perk = yes } eotm_grant_diplomacy_inheritance_benevolent_intent_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_inspiring_rule_perk = yes } eotm_grant_diplomacy_inheritance_inspiring_rule_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_firm_hand_perk = yes } eotm_grant_diplomacy_inheritance_firm_hand_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_praetorian_guard_perk = yes } eotm_grant_diplomacy_inheritance_praetorian_guard_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_true_ruler_perk = yes } eotm_grant_diplomacy_inheritance_true_ruler_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_writing_history_perk = yes } eotm_grant_diplomacy_inheritance_writing_history_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_a_life_of_glory_perk = yes } eotm_grant_diplomacy_inheritance_a_life_of_glory_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_dignitas_perk = yes } eotm_grant_diplomacy_inheritance_dignitas_perk = yes }
}

eotm_grant_diplomacy_family_normal_perk_in_order = {
	if = { limit = { eotm_can_inherit_diplomacy_befriend_perk = yes } eotm_grant_diplomacy_inheritance_befriend_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_confidants_perk = yes } eotm_grant_diplomacy_inheritance_confidants_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_flatterer_perk = yes } eotm_grant_diplomacy_inheritance_flatterer_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_friendly_counsel_perk = yes } eotm_grant_diplomacy_inheritance_friendly_counsel_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_familial_familiar_perk = yes } eotm_grant_diplomacy_inheritance_familial_familiar_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_groomed_to_rule_perk = yes } eotm_grant_diplomacy_inheritance_groomed_to_rule_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_thicker_than_water_perk = yes } eotm_grant_diplomacy_inheritance_thicker_than_water_perk = yes }
	else_if = { limit = { eotm_can_inherit_diplomacy_sound_foundations_perk = yes } eotm_grant_diplomacy_inheritance_sound_foundations_perk = yes }
}

eotm_ensure_focused_diplomacy_focus = {
	if = {
		limit = { NOT = { eotm_one_way_diplomacy_focus_can_continue = yes } }
		remove_variable = eotm_one_way_diplomacy_focus
		random_list = {
			pick = 1
			unique = yes
			1 = {
				trigger = { eotm_has_valid_diplomacy_foreign_affairs_normal_inheritance_perk = yes }
				set_variable = { name = eotm_one_way_diplomacy_focus value = 1 }
				hidden_effect = { }
			}
			1 = {
				trigger = { eotm_has_valid_diplomacy_majesty_normal_inheritance_perk = yes }
				set_variable = { name = eotm_one_way_diplomacy_focus value = 2 }
				hidden_effect = { }
			}
			1 = {
				trigger = { eotm_has_valid_diplomacy_family_normal_inheritance_perk = yes }
				set_variable = { name = eotm_one_way_diplomacy_focus value = 3 }
				hidden_effect = { }
			}
		}
	}
}

eotm_grant_focused_diplomacy_normal_perk = {
	eotm_ensure_focused_diplomacy_focus = yes
	if = {
		limit = { eotm_one_way_diplomacy_focus_is_foreign_affairs = yes }
		eotm_grant_diplomacy_foreign_affairs_normal_perk_in_order = yes
	}
	else_if = {
		limit = { eotm_one_way_diplomacy_focus_is_majesty = yes }
		eotm_grant_diplomacy_majesty_normal_perk_in_order = yes
	}
	else_if = {
		limit = { eotm_one_way_diplomacy_focus_is_family = yes }
		eotm_grant_diplomacy_family_normal_perk_in_order = yes
	}
}

eotm_count_child_diplomacy_branch_normal_perks = {
	set_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count value = 0 }
	set_variable = { name = eotm_balanced_diplomacy_majesty_count value = 0 }
	set_variable = { name = eotm_balanced_diplomacy_family_count value = 0 }
	if = { limit = { has_perk = thoughtful_perk } change_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count add = 1 } }
	if = { limit = { has_perk = ducal_conquest_perk } change_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count add = 1 } }
	if = { limit = { has_perk = forced_vassalage_perk } change_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count add = 1 } }
	if = { limit = { has_perk = adaptive_traditions_perk } change_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count add = 1 } }
	if = { limit = { has_perk = flexible_truces_perk } change_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count add = 1 } }
	if = { limit = { has_perk = defensive_negotiations_perk } change_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count add = 1 } }
	if = { limit = { has_perk = embassies_perk } change_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count add = 1 } }
	if = { limit = { has_perk = accomplished_forger_perk } change_variable = { name = eotm_balanced_diplomacy_foreign_affairs_count add = 1 } }
	if = { limit = { has_perk = benevolent_intent_perk } change_variable = { name = eotm_balanced_diplomacy_majesty_count add = 1 } }
	if = { limit = { has_perk = inspiring_rule_perk } change_variable = { name = eotm_balanced_diplomacy_majesty_count add = 1 } }
	if = { limit = { has_perk = firm_hand_perk } change_variable = { name = eotm_balanced_diplomacy_majesty_count add = 1 } }
	if = { limit = { has_perk = praetorian_guard_perk } change_variable = { name = eotm_balanced_diplomacy_majesty_count add = 1 } }
	if = { limit = { has_perk = true_ruler_perk } change_variable = { name = eotm_balanced_diplomacy_majesty_count add = 1 } }
	if = { limit = { has_perk = writing_history_perk } change_variable = { name = eotm_balanced_diplomacy_majesty_count add = 1 } }
	if = { limit = { has_perk = a_life_of_glory_perk } change_variable = { name = eotm_balanced_diplomacy_majesty_count add = 1 } }
	if = { limit = { has_perk = dignitas_perk } change_variable = { name = eotm_balanced_diplomacy_majesty_count add = 1 } }
	if = { limit = { has_perk = befriend_perk } change_variable = { name = eotm_balanced_diplomacy_family_count add = 1 } }
	if = { limit = { has_perk = confidants_perk } change_variable = { name = eotm_balanced_diplomacy_family_count add = 1 } }
	if = { limit = { has_perk = flatterer_perk } change_variable = { name = eotm_balanced_diplomacy_family_count add = 1 } }
	if = { limit = { has_perk = friendly_counsel_perk } change_variable = { name = eotm_balanced_diplomacy_family_count add = 1 } }
	if = { limit = { has_perk = familial_familiar_perk } change_variable = { name = eotm_balanced_diplomacy_family_count add = 1 } }
	if = { limit = { has_perk = groomed_to_rule_perk } change_variable = { name = eotm_balanced_diplomacy_family_count add = 1 } }
	if = { limit = { has_perk = thicker_than_water_perk } change_variable = { name = eotm_balanced_diplomacy_family_count add = 1 } }
	if = { limit = { has_perk = sound_foundations_perk } change_variable = { name = eotm_balanced_diplomacy_family_count add = 1 } }
}

eotm_grant_harmonious_diplomacy_normal_perk = {
	eotm_count_child_diplomacy_branch_normal_perks = yes
	random_list = {
		pick = 1
		unique = yes
		1 = {
			trigger = { eotm_balanced_diplomacy_foreign_affairs_is_lowest_valid_branch = yes }
			eotm_grant_diplomacy_foreign_affairs_normal_perk_in_order = yes
		}
		1 = {
			trigger = { eotm_balanced_diplomacy_majesty_is_lowest_valid_branch = yes }
			eotm_grant_diplomacy_majesty_normal_perk_in_order = yes
		}
		1 = {
			trigger = { eotm_balanced_diplomacy_family_is_lowest_valid_branch = yes }
			eotm_grant_diplomacy_family_normal_perk_in_order = yes
		}
	}
}

eotm_grant_profile_selected_diplomacy_normal_perk = {
	if = {
		limit = { eotm_child_has_one_way_profile = yes }
		eotm_grant_focused_diplomacy_normal_perk = yes
	}
	else_if = {
		limit = { eotm_child_has_balanced_profile = yes }
		eotm_grant_harmonious_diplomacy_normal_perk = yes
	}
	else_if = {
		limit = { eotm_child_has_random_profile = yes }
		eotm_grant_curious_diplomacy_normal_perk = yes
	}
	else = { hidden_effect = { } }
}

eotm_debug_count_standalone_diplomacy_candidates = {
	set_variable = { name = eotm_debug_diplomacy_candidate_count value = 0 }
	if = { limit = { eotm_can_debug_grant_diplomacy_foreign_affairs_final_unlock = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_majesty_final_unlock = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_family_final_unlock = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_thoughtful_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_ducal_conquest_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_forced_vassalage_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_adaptive_traditions_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_flexible_truces_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_defensive_negotiations_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_embassies_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_accomplished_forger_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_benevolent_intent_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_inspiring_rule_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_firm_hand_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_praetorian_guard_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_true_ruler_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_writing_history_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_a_life_of_glory_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_dignitas_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_befriend_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_confidants_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_flatterer_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_friendly_counsel_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_familial_familiar_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_groomed_to_rule_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_thicker_than_water_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
	if = { limit = { eotm_can_debug_grant_diplomacy_sound_foundations_perk = yes } change_variable = { name = eotm_debug_diplomacy_candidate_count add = 1 } }
}

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

eotm_debug_log_standalone_diplomacy_candidate_state = {
	if = { limit = { has_perk = diplomat_perk } hidden_effect = { } } else_if = { limit = { NOT = { eotm_child_has_diplomacy_foreign_affairs_normal_branch_perks = yes } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = august_perk } hidden_effect = { } } else_if = { limit = { NOT = { eotm_child_has_diplomacy_majesty_normal_branch_perks = yes } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = family_man_perk } hidden_effect = { } } else_if = { limit = { NOT = { eotm_child_has_diplomacy_family_normal_branch_perks = yes } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = thoughtful_perk } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = ducal_conquest_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = thoughtful_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = forced_vassalage_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = ducal_conquest_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = adaptive_traditions_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = thoughtful_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = flexible_truces_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = adaptive_traditions_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = defensive_negotiations_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = thoughtful_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = embassies_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = defensive_negotiations_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = accomplished_forger_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = forced_vassalage_perk } } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = flexible_truces_perk } } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = embassies_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = benevolent_intent_perk } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = inspiring_rule_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = benevolent_intent_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = firm_hand_perk } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = praetorian_guard_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = firm_hand_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = true_ruler_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = inspiring_rule_perk } } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = praetorian_guard_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = writing_history_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = true_ruler_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = a_life_of_glory_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = writing_history_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = dignitas_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = writing_history_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = befriend_perk } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = confidants_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = befriend_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = flatterer_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = confidants_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = friendly_counsel_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = flatterer_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = familial_familiar_perk } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = groomed_to_rule_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = familial_familiar_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = thicker_than_water_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = groomed_to_rule_perk } } hidden_effect = { } } else = { hidden_effect = { } }
	if = { limit = { has_perk = sound_foundations_perk } hidden_effect = { } } else_if = { limit = { NOT = { has_perk = thicker_than_water_perk } } hidden_effect = { } } else = { hidden_effect = { } }
}

eotm_debug_test_diplomacy_randomizer_x10_effect = {
	if = {
		limit = { is_ai = no }
		hidden_effect = { }
		hidden_effect = { }
		hidden_effect = { }
		set_variable = { name = eotm_diplomacy_granted_count value = 0 }
		set_variable = { name = eotm_debug_diplomacy_randomizer_attempt_count value = 0 }
		eotm_count_diplomacy_visible_perks = yes
		hidden_effect = { }
		eotm_debug_log_diplomacy_visible_perk_count = yes
		remove_variable = eotm_diplomacy_visible_perk_count
		eotm_count_diplomacy_final_visible_perks = yes
		hidden_effect = { }
		eotm_debug_log_diplomacy_final_visible_perk_count = yes
		remove_variable = eotm_diplomacy_final_visible_perk_count

		while = {
			limit = {
				exists = var:eotm_debug_diplomacy_randomizer_attempt_count
				var:eotm_debug_diplomacy_randomizer_attempt_count < 10
				eotm_any_debug_diplomacy_candidate_available = yes
			}
			change_variable = { name = eotm_debug_diplomacy_randomizer_attempt_count add = 1 }
			hidden_effect = { }
			eotm_debug_count_standalone_diplomacy_candidates = yes
			eotm_debug_log_standalone_diplomacy_candidate_count = yes
			eotm_debug_log_standalone_diplomacy_candidate_state = yes
			remove_variable = eotm_debug_diplomacy_candidate_count
			set_variable = { name = eotm_diplomacy_granted_this_attempt value = 0 }
			eotm_debug_try_grant_diplomacy_final_unlock = yes
			if = { limit = { var:eotm_diplomacy_granted_this_attempt ?= 0 } eotm_debug_grant_curious_diplomacy_perk = yes }
			if = { limit = { var:eotm_diplomacy_granted_this_attempt ?= 0 } hidden_effect = { } set_variable = { name = eotm_debug_diplomacy_randomizer_attempt_count value = 10 } }
		}

		if = { limit = { NOT = { eotm_any_debug_diplomacy_candidate_available = yes } } hidden_effect = { } }
		eotm_debug_log_diplomacy_granted_count = yes
		eotm_count_diplomacy_visible_perks = yes
		hidden_effect = { }
		eotm_debug_log_diplomacy_visible_perk_count = yes
		eotm_count_diplomacy_final_visible_perks = yes
		hidden_effect = { }
		eotm_debug_log_diplomacy_final_visible_perk_count = yes
		hidden_effect = { }
		remove_variable = eotm_diplomacy_visible_perk_count
		remove_variable = eotm_diplomacy_final_visible_perk_count
		remove_variable = eotm_diplomacy_granted_count
		remove_variable = eotm_diplomacy_granted_this_attempt
		remove_variable = eotm_debug_diplomacy_randomizer_attempt_count
		remove_variable = eotm_debug_diplomacy_candidate_count
	}
	else = { hidden_effect = { } }
}

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

eotm_debug_log_diplomacy_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 <= 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_debug_log_diplomacy_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_pending_diplomacy_candidate_rejections = {
	hidden_effect = { }
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = a_life_of_glory_perk } has_variable = eotm_pending_parent_had_diplomacy_a_life_of_glory_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = a_life_of_glory_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_a_life_of_glory_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = accomplished_forger_perk } has_variable = eotm_pending_parent_had_diplomacy_accomplished_forger_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = accomplished_forger_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_accomplished_forger_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = adaptive_traditions_perk } has_variable = eotm_pending_parent_had_diplomacy_adaptive_traditions_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = adaptive_traditions_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_adaptive_traditions_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = august_perk } has_variable = eotm_pending_parent_had_diplomacy_august_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = august_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_majesty_final_unlock = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = befriend_perk } has_variable = eotm_pending_parent_had_diplomacy_befriend_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = befriend_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_befriend_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = benevolent_intent_perk } has_variable = eotm_pending_parent_had_diplomacy_benevolent_intent_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = benevolent_intent_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_benevolent_intent_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = confidants_perk } has_variable = eotm_pending_parent_had_diplomacy_confidants_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = confidants_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_confidants_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = defensive_negotiations_perk } has_variable = eotm_pending_parent_had_diplomacy_defensive_negotiations_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = defensive_negotiations_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_defensive_negotiations_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = dignitas_perk } has_variable = eotm_pending_parent_had_diplomacy_dignitas_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = dignitas_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_dignitas_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = diplomat_perk } has_variable = eotm_pending_parent_had_diplomacy_diplomat_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = diplomat_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_foreign_affairs_final_unlock = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = ducal_conquest_perk } has_variable = eotm_pending_parent_had_diplomacy_ducal_conquest_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = ducal_conquest_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_ducal_conquest_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = embassies_perk } has_variable = eotm_pending_parent_had_diplomacy_embassies_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = embassies_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_embassies_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = familial_familiar_perk } has_variable = eotm_pending_parent_had_diplomacy_familial_familiar_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = familial_familiar_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_familial_familiar_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = family_man_perk } has_variable = eotm_pending_parent_had_diplomacy_family_man_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = family_man_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_family_final_unlock = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = firm_hand_perk } has_variable = eotm_pending_parent_had_diplomacy_firm_hand_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = firm_hand_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_firm_hand_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = flatterer_perk } has_variable = eotm_pending_parent_had_diplomacy_flatterer_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = flatterer_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_flatterer_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = flexible_truces_perk } has_variable = eotm_pending_parent_had_diplomacy_flexible_truces_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = flexible_truces_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_flexible_truces_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = forced_vassalage_perk } has_variable = eotm_pending_parent_had_diplomacy_forced_vassalage_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = forced_vassalage_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_forced_vassalage_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = friendly_counsel_perk } has_variable = eotm_pending_parent_had_diplomacy_friendly_counsel_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = friendly_counsel_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_friendly_counsel_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = groomed_to_rule_perk } has_variable = eotm_pending_parent_had_diplomacy_groomed_to_rule_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = groomed_to_rule_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_groomed_to_rule_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = inspiring_rule_perk } has_variable = eotm_pending_parent_had_diplomacy_inspiring_rule_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = inspiring_rule_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_inspiring_rule_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = praetorian_guard_perk } has_variable = eotm_pending_parent_had_diplomacy_praetorian_guard_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = praetorian_guard_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_praetorian_guard_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = sound_foundations_perk } has_variable = eotm_pending_parent_had_diplomacy_sound_foundations_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = sound_foundations_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_sound_foundations_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = thicker_than_water_perk } has_variable = eotm_pending_parent_had_diplomacy_thicker_than_water_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = thicker_than_water_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_thicker_than_water_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = thoughtful_perk } has_variable = eotm_pending_parent_had_diplomacy_thoughtful_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = thoughtful_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_thoughtful_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = true_ruler_perk } has_variable = eotm_pending_parent_had_diplomacy_true_ruler_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = true_ruler_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_true_ruler_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	if = {
		limit = { NOT = { OR = { scope:eotm_deceased_parent ?= { has_perk = writing_history_perk } has_variable = eotm_pending_parent_had_diplomacy_writing_history_perk } } }
		hidden_effect = { }
	}
	else_if = {
		limit = { has_perk = writing_history_perk }
		hidden_effect = { }
	}
	else_if = {
		limit = { NOT = { eotm_can_inherit_diplomacy_writing_history_perk = yes } }
		hidden_effect = { }
	}
	else = {
		hidden_effect = { }
	}
	hidden_effect = { }
}

eotm_cleanup_diplomacy_inheritance_child_temp_variables = {
	remove_variable = eotm_child_age_inheritance_percentage
	remove_variable = eotm_diplomacy_target_count
	remove_variable = eotm_diplomacy_granted_count
	remove_variable = eotm_diplomacy_granted_this_attempt
	remove_variable = eotm_diplomacy_attempt_count
	remove_variable = eotm_diplomacy_visible_perk_count
	remove_variable = eotm_balanced_diplomacy_foreign_affairs_count
	remove_variable = eotm_balanced_diplomacy_majesty_count
	remove_variable = eotm_balanced_diplomacy_family_count
}

eotm_process_diplomacy_inheritance_child = {
	hidden_effect = { }
	hidden_effect = { }
	hidden_effect = { }
	hidden_effect = { }
	eotm_debug_log_diplomacy_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_diplomacy_activation_active has_variable = eotm_pending_diplomacy_target_count }
		set_variable = { name = eotm_diplomacy_target_count value = { value = var:eotm_pending_diplomacy_target_count } }
		hidden_effect = { }
		eotm_debug_log_diplomacy_target_count = yes
	}
	else = {
		eotm_calculate_child_diplomacy_target_count = yes
		eotm_debug_log_diplomacy_age_bracket_and_percentage = yes
		scope:eotm_deceased_parent = { eotm_debug_log_diplomacy_parent_visible_count = yes }
		hidden_effect = { }
		eotm_debug_log_diplomacy_target_count = yes
		eotm_apply_advanced_inheritance_resolver_insertion_points = yes
	}
	set_variable = { name = eotm_diplomacy_granted_count value = 0 }
	set_variable = { name = eotm_diplomacy_attempt_count value = 0 }
	if = {
		limit = { has_variable = eotm_pending_diplomacy_activation_active NOT = { eotm_any_diplomacy_inheritance_candidate_available = yes } }
		eotm_debug_log_pending_diplomacy_candidate_rejections = yes
	}
	if = {
		limit = { exists = var:eotm_diplomacy_granted_count exists = var:eotm_diplomacy_target_count exists = var:eotm_diplomacy_attempt_count var:eotm_diplomacy_target_count ?= 0 }
		hidden_effect = { }
	}
	else = {
		while = {
			limit = { exists = var:eotm_diplomacy_granted_count exists = var:eotm_diplomacy_target_count exists = var:eotm_diplomacy_attempt_count var:eotm_diplomacy_granted_count < var:eotm_diplomacy_target_count var:eotm_diplomacy_attempt_count < 60 eotm_any_diplomacy_inheritance_candidate_available = yes }
			change_variable = { name = eotm_diplomacy_attempt_count add = 1 }
			set_variable = { name = eotm_diplomacy_granted_this_attempt value = 0 }
			eotm_try_grant_diplomacy_final_unlock = yes
			if = { limit = { var:eotm_diplomacy_granted_this_attempt ?= 0 } eotm_grant_profile_selected_diplomacy_normal_perk = yes }
			if = { limit = { var:eotm_diplomacy_granted_this_attempt ?= 0 } hidden_effect = { } hidden_effect = { } set_variable = { name = eotm_diplomacy_attempt_count value = 60 } }
		}
		if = { limit = { exists = var:eotm_diplomacy_granted_count exists = var:eotm_diplomacy_target_count var:eotm_diplomacy_granted_count < var:eotm_diplomacy_target_count NOT = { eotm_any_diplomacy_inheritance_candidate_available = yes } } hidden_effect = { } hidden_effect = { } }
		if = { limit = { exists = var:eotm_diplomacy_granted_count exists = var:eotm_diplomacy_target_count exists = var:eotm_diplomacy_attempt_count var:eotm_diplomacy_granted_count < var:eotm_diplomacy_target_count var:eotm_diplomacy_attempt_count >= 60 eotm_any_diplomacy_inheritance_candidate_available = yes } hidden_effect = { } }
	}
	eotm_debug_log_diplomacy_inheritance_granted_count = yes
	eotm_count_diplomacy_visible_perks = yes
	hidden_effect = { }
	eotm_debug_log_diplomacy_visible_perk_count = yes
	eotm_show_player_inheritance_report_window_effect = yes
	hidden_effect = { }
	eotm_cleanup_diplomacy_inheritance_child_temp_variables = yes
}

eotm_execute_diplomacy_death_inheritance = {
	if = {
		limit = { is_ruler = yes is_ai = no }
		hidden_effect = { }
		save_scope_as = eotm_deceased_parent
		eotm_count_parent_diplomacy_visible_perks = yes
		eotm_count_parent_diplomacy_final_visible_perks = yes
		eotm_debug_log_diplomacy_parent_visible_count = yes
		eotm_debug_log_diplomacy_parent_final_visible_count = yes
		every_child = {
			limit = { eotm_is_valid_diplomacy_death_inheritance_child = yes }
			eotm_prepare_pending_diplomacy_inheritance_child = yes
		}
		remove_variable = eotm_parent_diplomacy_visible_perk_count
		remove_variable = eotm_parent_diplomacy_final_visible_perk_count
		hidden_effect = { }
	}
}
