namespace = MT_desperation

# On system gained.
country_event = {
	id = MT_desperation.1
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_active_tradition = tr_mt_desperation_records
			}
			FROM = {
				if = {
					limit = { exists = starbase }
					starbase = { add_MT_desperation_aura = yes }
				}
			}
		}
	}
}

# On system lost.
country_event = {
	id = MT_desperation.2
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = { # checks if a new owner exists
			limit = { exists = FROMFROM }
			if = {
				limit = {
					has_active_tradition = tr_mt_desperation_records
					FROMFROM = {
						NOT = {
							has_active_tradition = tr_mt_desperation_records
						}
					}
				}
				FROM = {
					if = {
						limit = { exists = starbase }
						starbase = { remove_MT_desperation_aura = yes }
					}
				}
			}
		}
		else = { # if no new owner, always remove the thorns field (just a failsafe, systems with no onwer shouldn't have a starbase)
			FROM = {
				if = {
					limit = { exists = starbase }
					starbase = {
						remove_MT_desperation_aura = yes
					}
				}
			}
		}
	}
}

# On destroying enemy ship.
country_event = {
	id = MT_desperation.3
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_tradition = tr_mt_desperation_finish
		FROM = {
			OR = {
				is_country_type = swarm
				is_country_type = extradimensional
				is_country_type = extradimensional_2
				is_country_type = extradimensional_3
				is_country_type = ai_empire
				is_country_type = gray
				is_country_type = awakened_marauders
				is_country_type = synth_queen
				is_country_type = synth_queen_storm
				is_country_type = awakened_synth_queen
				is_country_type = synth_queen_convoys
				is_country_type = synth_queen_outposts
				has_ascension_perk = ap_become_the_crisis
				has_ascension_perk = ap_cosmogenesis
				has_ascension_perk = ap_behemoths
				has_ascension_perk = ap_galactic_hyperthermia
				has_origin = origin_endbringers
				has_covenant = end_of_the_cycle
			}
		}
	}

	immediate = {
		add_resource = {
			unity = 10
		}
	}
}