﻿# EOTM inheritance debug report effects.
#
# These effects are validation-only reporting helpers. They do not grant
# perks, remove perks, change formulas, or alter inheritance targets.

eotm_v1_debug_log_inheritance_summary_effect = {
	if = {
		limit = { NOT = { has_variable = eotm_v1_debug_report_emitted } }
		set_variable = { name = eotm_v1_debug_report_emitted value = 1 }
		debug_log = eotm_debug_report_header
		debug_log = eotm_debug_report_child
		debug_log = eotm_debug_report_mode_advanced
		eotm_v1_advanced_debug_log_report_effect = yes
		debug_log = eotm_debug_report_footer
	}
}

eotm_handle_player_inheritance_report_window_effect = {
	if = {
		limit = { age < 16 }
		eotm_store_pending_inheritance_report_window_effect = yes
	}
	else = {
		eotm_show_player_inheritance_report_window_effect = yes
	}
}

eotm_show_player_inheritance_report_window_effect = {
	eotm_store_inheritance_report_window_snapshot_effect = yes
	if = {
		limit = {
			NOT = { has_variable = eotm_inheritance_report_window_scheduled }
			exists = var:eotm_pending_report_total_granted_count
			var:eotm_pending_report_total_granted_count > 0
			NOT = {
				OR = {
					has_variable = eotm_pending_learning_activation_active
					has_variable = eotm_pending_martial_activation_active
					has_variable = eotm_pending_diplomacy_activation_active
					has_variable = eotm_pending_stewardship_activation_active
					has_variable = eotm_pending_intrigue_activation_active
					has_variable = eotm_pending_wanderer_activation_active
				}
			}
		}
		set_variable = { name = eotm_inheritance_report_window_scheduled value = 1 }
		trigger_event = {
			id = eotm_report_events.0102
			days = 1
		}
	}
}

eotm_store_pending_inheritance_report_window_effect = {
	set_variable = { name = eotm_pending_inheritance_report_window value = 1 }
	eotm_store_inheritance_report_window_snapshot_effect = yes
	if = {
		limit = { NOT = { has_variable = eotm_pending_inheritance_activation_retry_scheduled } }
		set_variable = { name = eotm_pending_inheritance_activation_retry_scheduled value = 1 }
		trigger_event = {
			id = eotm_report_events.0113
			days = 1
		}
		trigger_event = {
			id = eotm_report_events.0113
			days = 3
		}
		trigger_event = {
			id = eotm_report_events.0113
			days = 14
		}
	}
	if = {
		limit = { age < 16 }
		set_variable = { name = eotm_deferred_inheritance_notice_pending value = 1 }
		eotm_show_deferred_inheritance_notice_effect = yes
		trigger_event = {
			id = eotm_report_events.0111
			days = 3
		}
	}
}

eotm_store_inheritance_report_window_snapshot_effect = {
	set_variable = { name = eotm_pending_inheritance_report_mode value = 2 }
	if = { limit = { exists = var:eotm_learning_target_count } set_variable = { name = eotm_pending_report_learning_target_count value = { value = var:eotm_learning_target_count } } }
	if = { limit = { exists = var:eotm_martial_target_count } set_variable = { name = eotm_pending_report_martial_target_count value = { value = var:eotm_martial_target_count } } }
	if = { limit = { exists = var:eotm_diplomacy_target_count } set_variable = { name = eotm_pending_report_diplomacy_target_count value = { value = var:eotm_diplomacy_target_count } } }
	if = { limit = { exists = var:eotm_stewardship_target_count } set_variable = { name = eotm_pending_report_stewardship_target_count value = { value = var:eotm_stewardship_target_count } } }
	if = { limit = { exists = var:eotm_intrigue_target_count } set_variable = { name = eotm_pending_report_intrigue_target_count value = { value = var:eotm_intrigue_target_count } } }
	if = { limit = { exists = var:eotm_wanderer_target_count } set_variable = { name = eotm_pending_report_wanderer_target_count value = { value = var:eotm_wanderer_target_count } } }
	if = { limit = { exists = var:eotm_learning_granted_count } set_variable = { name = eotm_pending_report_learning_granted_count value = { value = var:eotm_learning_granted_count } } }
	if = { limit = { exists = var:eotm_martial_granted_count } set_variable = { name = eotm_pending_report_martial_granted_count value = { value = var:eotm_martial_granted_count } } }
	if = { limit = { exists = var:eotm_diplomacy_granted_count } set_variable = { name = eotm_pending_report_diplomacy_granted_count value = { value = var:eotm_diplomacy_granted_count } } }
	if = { limit = { exists = var:eotm_stewardship_granted_count } set_variable = { name = eotm_pending_report_stewardship_granted_count value = { value = var:eotm_stewardship_granted_count } } }
	if = { limit = { exists = var:eotm_intrigue_granted_count } set_variable = { name = eotm_pending_report_intrigue_granted_count value = { value = var:eotm_intrigue_granted_count } } }
	if = { limit = { exists = var:eotm_wanderer_granted_count } set_variable = { name = eotm_pending_report_wanderer_granted_count value = { value = var:eotm_wanderer_granted_count } } }
	set_variable = { name = eotm_pending_report_total_granted_count value = 0 }
	if = { limit = { exists = var:eotm_pending_report_learning_granted_count } change_variable = { name = eotm_pending_report_total_granted_count add = var:eotm_pending_report_learning_granted_count } }
	if = { limit = { exists = var:eotm_pending_report_martial_granted_count } change_variable = { name = eotm_pending_report_total_granted_count add = var:eotm_pending_report_martial_granted_count } }
	if = { limit = { exists = var:eotm_pending_report_diplomacy_granted_count } change_variable = { name = eotm_pending_report_total_granted_count add = var:eotm_pending_report_diplomacy_granted_count } }
	if = { limit = { exists = var:eotm_pending_report_stewardship_granted_count } change_variable = { name = eotm_pending_report_total_granted_count add = var:eotm_pending_report_stewardship_granted_count } }
	if = { limit = { exists = var:eotm_pending_report_intrigue_granted_count } change_variable = { name = eotm_pending_report_total_granted_count add = var:eotm_pending_report_intrigue_granted_count } }
	if = { limit = { exists = var:eotm_pending_report_wanderer_granted_count } change_variable = { name = eotm_pending_report_total_granted_count add = var:eotm_pending_report_wanderer_granted_count } }
	if = { limit = { exists = var:eotm_v1_advanced_overflow_count } set_variable = { name = eotm_pending_report_advanced_overflow_count value = { value = var:eotm_v1_advanced_overflow_count } } }
	if = { limit = { exists = var:eotm_v1_advanced_base_total_target_count } set_variable = { name = eotm_pending_report_base_total_target_count value = { value = var:eotm_v1_advanced_base_total_target_count } } }
}

eotm_v1_advanced_debug_log_report_effect = {
	debug_log = "EOTM report: parent influence split = father/deceased parent 60%, other parent 40%"
	eotm_v1_advanced_debug_log_trait_hits_effect = yes
	debug_log = eotm_debug_report_advanced_preview_weights
	debug_log = eotm_debug_report_advanced_base_targets
	debug_log = eotm_debug_report_advanced_distribution_targets
	debug_log = eotm_debug_report_advanced_bonus_targets
	debug_log = eotm_debug_report_advanced_penalty_targets
	debug_log = eotm_debug_report_advanced_overflow
	debug_log = eotm_debug_report_advanced_final_targets
	debug_log = "EOTM report: rounding rule = floor((target * abs(preview_weight) + 500) / 1000); 0.49 down, 0.50 up"
	debug_log = "EOTM report: bonus cap = +3 total target points; penalty cap = -3 total target points; lifestyle cap = 27"
	eotm_v1_advanced_distribution_audit_report_effect = yes
}

eotm_v1_advanced_distribution_audit_report_effect = {
	debug_log = "=== EOTM Advanced Inheritance Distribution Audit Report ==="
	debug_log = "EOTM Advanced Audit: child scope inspected"
	if = { limit = { eotm_child_has_one_way_profile = yes } debug_log = "EOTM Advanced Audit: inheritance profile = Focused" }
	else_if = { limit = { eotm_child_has_balanced_profile = yes } debug_log = "EOTM Advanced Audit: inheritance profile = Harmonious" }
	else_if = { limit = { eotm_child_has_random_profile = yes } debug_log = "EOTM Advanced Audit: inheritance profile = Curious" }
	else = { debug_log = "EOTM Advanced Audit: inheritance profile = missing or invalid" }
	debug_log = "EOTM Advanced Audit: current version = V1 Advanced"
	debug_log = "EOTM Advanced Audit: source parent perks are counted before base target calculation; underage cases store parent-owned perk snapshots."
	debug_log = eotm_debug_report_advanced_base_targets
	debug_log = eotm_debug_report_advanced_preview_weights
	debug_log = "EOTM Advanced Audit: weighted allocation weights use base target * 100 plus trait preview weight; negative allocation weights clamp to 0."
	debug_log = "EOTM Advanced Audit: weighted distribution targets use floor(base total * allocation weight / total allocation weight), then strongest-weight leftovers."
	debug_log = eotm_debug_report_advanced_distribution_targets
	debug_log = "EOTM Advanced Audit: positive adjustments are rounded with +500/1000 and capped by +3 total target points."
	debug_log = eotm_debug_report_advanced_bonus_targets
	debug_log = "EOTM Advanced Audit: negative adjustments use absolute negative weight, rounded with +500/1000 and capped by -3 total target points."
	debug_log = eotm_debug_report_advanced_penalty_targets
	debug_log = "EOTM Advanced Audit: 27-cap enforcement clamps each lifestyle before overflow redirect."
	debug_log = eotm_debug_report_advanced_overflow
	if = { limit = { eotm_wanderer_content_available = yes } debug_log = "EOTM Advanced Audit: Wanderer branch = DLC feature available" }
	else = { debug_log = "EOTM Advanced Audit: Wanderer branch = skipped/blocked because DLC feature is unavailable" }
	debug_log = eotm_debug_report_advanced_final_targets
	debug_log = "EOTM Advanced Audit: final values are handed back to existing V1 distribution and validation; no named perk grants occur in the Advanced resolver."
	debug_log = "=== End EOTM Advanced Inheritance Distribution Audit Report ==="
}

eotm_v1_advanced_debug_log_trait_hits_effect = {
	debug_log = "EOTM report: TRAIT INFLUENCE"
	if = {
		limit = { exists = scope:eotm_deceased_parent }
		scope:eotm_deceased_parent = {
			debug_log = "EOTM report: deceased parent/father trait scan begins"
			if = { limit = { has_trait = brave } debug_log = "EOTM report: father brave -> Martial +6.0% effective" }
			if = { limit = { has_trait = deceitful } debug_log = "EOTM report: father deceitful -> Intrigue +6.0% effective" }
			if = { limit = { has_trait = diligent } debug_log = "EOTM report: father diligent -> Stewardship +2.4%, Learning +1.2% effective" }
			if = { limit = { has_trait = intellect_good_1 } debug_log = "EOTM report: father intellect_good_1 -> Learning +1.8% effective" }
			if = { limit = { has_trait = intellect_good_2 } debug_log = "EOTM report: father intellect_good_2 -> Learning +2.4%, Stewardship +1.2% effective" }
			if = { limit = { has_trait = intellect_good_3 } debug_log = "EOTM report: father intellect_good_3 -> Learning +3.6%, Stewardship +1.8%, Diplomacy +0.6% effective" }
			if = { limit = { has_trait = beauty_good_1 } debug_log = "EOTM report: father beauty_good_1 -> Diplomacy +1.8% effective" }
			if = { limit = { has_trait = beauty_good_2 } debug_log = "EOTM report: father beauty_good_2 -> Diplomacy +3.6% effective" }
			if = { limit = { has_trait = beauty_good_3 } debug_log = "EOTM report: father beauty_good_3 -> Diplomacy +6.0% effective" }
			if = { limit = { has_trait = lazy } debug_log = "EOTM report: father lazy -> Stewardship -3.0% effective" }
			if = { limit = { has_trait = craven } debug_log = "EOTM report: father craven -> Martial -3.0%, Intrigue -1.8% effective" }
			if = { limit = { has_trait = arbitrary } debug_log = "EOTM report: father arbitrary -> Intrigue -1.8%, Stewardship -1.2% effective" }
			if = { limit = { has_trait = lunatic } debug_log = "EOTM report: father lunatic -> Learning -3.0% effective" }
			if = { limit = { has_trait = gluttonous } debug_log = "EOTM report: father gluttonous -> Martial -1.2% effective" }
			if = { limit = { has_trait = callous } debug_log = "EOTM report: father callous -> Diplomacy -1.8% effective" }
			if = { limit = { has_trait = sadistic } debug_log = "EOTM report: father sadistic -> Intrigue +3.6%, Diplomacy -1.8% effective" }
			if = { limit = { has_trait = wrathful } debug_log = "EOTM report: father wrathful -> Martial +6.0%, Diplomacy -1.8% effective" }
			if = { limit = { has_trait = cynical } debug_log = "EOTM report: father cynical -> Learning +1.8% effective" }
			if = { limit = { has_trait = fickle } debug_log = "EOTM report: father fickle -> Intrigue -1.2% effective" }
			if = { limit = { has_trait = impatient } debug_log = "EOTM report: father impatient -> Learning -1.2% effective" }
			if = { limit = { has_trait = shy } debug_log = "EOTM report: father shy -> Diplomacy -1.2% effective" }
			if = { limit = { has_trait = paranoid } debug_log = "EOTM report: father paranoid -> Intrigue +1.8%, Learning -1.2% effective" }
			if = { limit = { has_trait = arrogant } debug_log = "EOTM report: father arrogant -> Diplomacy -1.2% effective" }
		}
	}
	else = {
		debug_log = "EOTM report: no deceased parent scope available for father trait scan"
	}

	save_scope_as = eotm_v1_advanced_report_child
	every_parent = {
		limit = { NOT = { this = scope:eotm_deceased_parent } }
		debug_log = "EOTM report: other parent/mother trait scan begins"
		if = { limit = { has_trait = brave } debug_log = "EOTM report: mother brave -> Martial +4.0% effective" }
		if = { limit = { has_trait = deceitful } debug_log = "EOTM report: mother deceitful -> Intrigue +4.0% effective" }
		if = { limit = { has_trait = diligent } debug_log = "EOTM report: mother diligent -> Stewardship +1.6%, Learning +0.8% effective" }
		if = { limit = { has_trait = intellect_good_1 } debug_log = "EOTM report: mother intellect_good_1 -> Learning +1.2% effective" }
		if = { limit = { has_trait = intellect_good_2 } debug_log = "EOTM report: mother intellect_good_2 -> Learning +1.6%, Stewardship +0.8% effective" }
		if = { limit = { has_trait = intellect_good_3 } debug_log = "EOTM report: mother intellect_good_3 -> Learning +2.4%, Stewardship +1.2%, Diplomacy +0.4% effective" }
		if = { limit = { has_trait = beauty_good_1 } debug_log = "EOTM report: mother beauty_good_1 -> Diplomacy +1.2% effective" }
		if = { limit = { has_trait = beauty_good_2 } debug_log = "EOTM report: mother beauty_good_2 -> Diplomacy +2.4% effective" }
		if = { limit = { has_trait = beauty_good_3 } debug_log = "EOTM report: mother beauty_good_3 -> Diplomacy +4.0% effective" }
		if = { limit = { has_trait = lazy } debug_log = "EOTM report: mother lazy -> Stewardship -2.0% effective" }
		if = { limit = { has_trait = craven } debug_log = "EOTM report: mother craven -> Martial -2.0%, Intrigue -1.2% effective" }
		if = { limit = { has_trait = arbitrary } debug_log = "EOTM report: mother arbitrary -> Intrigue -1.2%, Stewardship -0.8% effective" }
		if = { limit = { has_trait = lunatic } debug_log = "EOTM report: mother lunatic -> Learning -2.0% effective" }
		if = { limit = { has_trait = gluttonous } debug_log = "EOTM report: mother gluttonous -> Martial -0.8% effective" }
		if = { limit = { has_trait = callous } debug_log = "EOTM report: mother callous -> Diplomacy -1.2% effective" }
		if = { limit = { has_trait = sadistic } debug_log = "EOTM report: mother sadistic -> Intrigue +2.4%, Diplomacy -1.2% effective" }
		if = { limit = { has_trait = wrathful } debug_log = "EOTM report: mother wrathful -> Martial +4.0%, Diplomacy -1.2% effective" }
		if = { limit = { has_trait = cynical } debug_log = "EOTM report: mother cynical -> Learning +1.2% effective" }
		if = { limit = { has_trait = fickle } debug_log = "EOTM report: mother fickle -> Intrigue -0.8% effective" }
		if = { limit = { has_trait = impatient } debug_log = "EOTM report: mother impatient -> Learning -0.8% effective" }
		if = { limit = { has_trait = shy } debug_log = "EOTM report: mother shy -> Diplomacy -0.8% effective" }
		if = { limit = { has_trait = paranoid } debug_log = "EOTM report: mother paranoid -> Intrigue +1.2%, Learning -0.8% effective" }
		if = { limit = { has_trait = arrogant } debug_log = "EOTM report: mother arrogant -> Diplomacy -0.8% effective" }
	}
}
