###########################
# Hall of Echoes (ap_hall_of_echoes)
###########################
namespace = apb_echo

# A leader died.
# Hook: on_leader_death. This = Country, From = Leader.
# Leaders removed by script without a death notice (swaps, culled gestalt nodes)
# are marked in apb_echo.4, dismissed leaders in apb_echo.5; neither counts.
country_event = {
	id = apb_echo.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_hall_of_echoes
		exists = from
		from = {
			has_base_skill >= 5
			OR = {
				leader_class = scientist
				leader_class = commander
				leader_class = official
			}
			NOR = {
				has_leader_flag = apb_echo_dismissed
				has_leader_flag = apb_echo_silent_death
				has_leader_flag = apb_echo_counted
				has_leader_flag = culled_node
			}
		}
	}

	immediate = {
		from = { set_leader_flag = apb_echo_counted }
		if = {
			limit = { from = { leader_class = scientist } }
			apb_hoe_echo_from_dead_leader = { CLASS = scientist EVENT = apb_echo.10 }
		}
		else_if = {
			limit = { from = { leader_class = commander } }
			apb_hoe_echo_from_dead_leader = { CLASS = commander EVENT = apb_echo.11 }
		}
		else_if = {
			limit = { from = { leader_class = official } }
			apb_hoe_echo_from_dead_leader = { CLASS = official EVENT = apb_echo.12 }
		}
	}
}

# An immortal leader reached level 10: one echo, once per leader.
# Hook: on_leader_level_up. Scope = Country, From = Leader.
country_event = {
	id = apb_echo.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_hall_of_echoes
		exists = from
		from = {
			is_immortal = yes
			has_base_skill >= 10
			OR = {
				leader_class = scientist
				leader_class = commander
				leader_class = official
			}
			NOR = {
				has_leader_flag = apb_echo_counted
				apb_is_forked_instance = yes
			}
		}
	}

	immediate = {
		from = { set_leader_flag = apb_echo_counted }
		if = {
			limit = { from = { leader_class = scientist } }
			apb_hoe_add_echo = { CLASS = scientist AMOUNT = 1 EVENT = apb_echo.13 }
		}
		else_if = {
			limit = { from = { leader_class = commander } }
			apb_hoe_add_echo = { CLASS = commander AMOUNT = 1 EVENT = apb_echo.14 }
		}
		else_if = {
			limit = { from = { leader_class = official } }
			apb_hoe_add_echo = { CLASS = official AMOUNT = 1 EVENT = apb_echo.15 }
		}
	}
}

# Perk taken: set up the counters and give echoes for immortal leaders
# who are already level 10 or more. Fired from the perk's on_enabled.
country_event = {
	id = apb_echo.3
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_owned_leader = {
			limit = {
				is_immortal = yes
				has_base_skill >= 10
				leader_class = scientist
				NOR = {
					has_leader_flag = apb_echo_counted
					apb_is_forked_instance = yes
				}
			}
			set_leader_flag = apb_echo_counted
			root = { apb_hoe_add_echo = { CLASS = scientist AMOUNT = 1 } }
		}
		every_owned_leader = {
			limit = {
				is_immortal = yes
				has_base_skill >= 10
				leader_class = commander
				NOR = {
					has_leader_flag = apb_echo_counted
					apb_is_forked_instance = yes
				}
			}
			set_leader_flag = apb_echo_counted
			root = { apb_hoe_add_echo = { CLASS = commander AMOUNT = 1 } }
		}
		every_owned_leader = {
			limit = {
				is_immortal = yes
				has_base_skill >= 10
				leader_class = official
				NOR = {
					has_leader_flag = apb_echo_counted
					apb_is_forked_instance = yes
				}
			}
			set_leader_flag = apb_echo_counted
			root = { apb_hoe_add_echo = { CLASS = official AMOUNT = 1 } }
		}
		# Make sure all three counters exist for the event text.
		if = {
			limit = { NOT = { is_variable_set = apb_echoes_scientist } }
			set_variable = { which = apb_echoes_scientist value = 0 }
		}
		if = {
			limit = { NOT = { is_variable_set = apb_echoes_commander } }
			set_variable = { which = apb_echoes_commander value = 0 }
		}
		if = {
			limit = { NOT = { is_variable_set = apb_echoes_official } }
			set_variable = { which = apb_echoes_official value = 0 }
		}
	}
}

# A leader is about to die without a death notice (removed by script: clone swaps,
# culled gestalt nodes and the like). Mark them so apb_echo.1 skips them.
# Hook: on_leader_death_no_notify (fires just before on_leader_death). This = Country, From = Leader.
country_event = {
	id = apb_echo.4
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_hall_of_echoes
		exists = from
	}

	immediate = {
		from = { set_leader_flag = apb_echo_silent_death }
	}
}

# A leader was dismissed. Mark them so a dismissal never counts as a death.
# Hook: on_leader_fired. This = Country, From = Leader.
country_event = {
	id = apb_echo.5
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_hall_of_echoes
		exists = from
	}

	immediate = {
		from = { set_leader_flag = apb_echo_dismissed }
	}
}

###########################
# Player notifications
###########################

# Death echoes
country_event = {
	id = apb_echo.10
	title = apb_echo.10.name
	desc = apb_echo.10.desc
	picture = GFX_evt_legendary_leader
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_echo.10.a
	}
}

country_event = {
	id = apb_echo.11
	title = apb_echo.11.name
	desc = apb_echo.11.desc
	picture = GFX_evt_legendary_leader
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_echo.10.a
	}
}

country_event = {
	id = apb_echo.12
	title = apb_echo.12.name
	desc = apb_echo.12.desc
	picture = GFX_evt_legendary_leader
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_echo.10.a
	}
}

# Level 10 echoes (immortal leaders)
country_event = {
	id = apb_echo.13
	title = apb_echo.13.name
	desc = apb_echo.13.desc
	picture = GFX_evt_legendary_leader
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_echo.13.a
	}
}

country_event = {
	id = apb_echo.14
	title = apb_echo.14.name
	desc = apb_echo.14.desc
	picture = GFX_evt_legendary_leader
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_echo.13.a
	}
}

country_event = {
	id = apb_echo.15
	title = apb_echo.15.name
	desc = apb_echo.15.desc
	picture = GFX_evt_legendary_leader
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_echo.13.a
	}
}
