namespace = MT_annihilation

# Executed whenever a pop is killed due to bombardment damages
# This = Colony where the pop was bombed to death
# From = Country which is raining down fire and brimstone
# FromFrom = Biggest fleet bombarding the planet (the one we used the bombardment stance from)
# local_kill_pop_amount = amount of pop killed
carrier_event = {
	id = MT_annihilation.1
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_designation = col_cosmogenesis_world
		}
		from = {
			exists = this
			has_tradition = tr_mt_annihilation_beauty_of_annihilation
			NOR = { has_active_tradition = tr_mt_annihilation_beauty_of_annihilation_necromancers }
		}
		owner = {
			exists = this
			# is_country_type = default
		}
	}

	immediate = {
		while = {
			#count = local_kill_pop_amount
			from = {
				if = {
					limit = {
						NOT = { is_variable_set = MT_annihiliation_pops_bombarded }
					}
					set_variable = {
						which = MT_annihiliation_pops_bombarded
						value = 0
					}
				}
				change_variable = {
					which = MT_annihiliation_pops_bombarded
					value = local_kill_pop_amount
				}
				while = {
					limit = {
						check_variable = {
							which = MT_annihiliation_pops_bombarded
							value >= 100
						}
					}
					subtract_variable = {
						which = MT_annihiliation_pops_bombarded
						value = 100
					}
					add_monthly_resource_mult = {
						resource = unity
						value = 1
						min = 10
						max = 1000000
					}
				}
			}
		}
	}
}

country_event = {
	id = MT_annihilation.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_tradition = tr_mt_annihilation_final_strike
	}

	immediate = {
		from = {
			country_event = { id = MT_annihilation.3 }
		}
	}
}

# Execute leader upon defeat
# A war has been lost
# This = Loser Warleader
# From = Winner Warleader
country_event = {
	id = MT_annihilation.3
	title = MT_annihilation.3.name
	desc = {
		trigger = { NOT = { has_country_flag = MT_annihilation_malevolence_triggered@from } }
		text = MT_annihilation.3.desc
	}
	desc = {
		trigger = {
			has_country_flag = MT_annihilation_malevolence_triggered@from
		}
		text = MT_annihilation.3.desc.again
	}
	picture = GFX_evt_surrender
	show_sound = event_planetary_riot
	location = root

	is_triggered_only = yes

	trigger = {
		NOT = { has_ethic = ethic_gestalt_consciousness }
		exists = ruler
	}

	immediate = {
		ruler = {
			save_event_target_as = rulername
			kill_leader = {
				ruler = yes
				show_notification = no
			}
		}
	}

	option = {
		name = MT_annihilation.3.a
		custom_tooltip = MT_annihilation.3.a.tooltip
		hidden_effect = {
			set_country_flag = MT_annihilation_malevolence_triggered@from
		}
	}
}