############################################
#											#
# Nemesis Crisis Menace Objective Events #
#		 Written by Douglas Furen		 #
#											#
############################################

namespace = crisis

# Menace Objective - Destroy Empires
# Event for destroyed country
country_event = {
	id = crisis.4020
	hide_window = yes
	is_triggered_only = yes

	# This = destroyed country
	# From = optional, destroyer (country)

	trigger = {
		OR = {
			is_country_type = default
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
		}
		exists = from
		from = { has_ascension_perk = ap_become_the_crisis }
	}

	immediate = {
		from = { complete_crisis_objective = crisobj_destroy_empires }
	}
}


# Menace Objective - Destroy Enemy Ships
country_event = {
	id = crisis.4025
	hide_window = yes
	is_triggered_only = yes

	# This = owner of ship 1 (combatant)
	# From = owner of ship 2 (destroyed)
	# FromFrom = ship 1
	# FromFromFrom = ship 2

	trigger = {
		owner = {
			has_ascension_perk = ap_become_the_crisis
		}

		# check to exclude starbase kills in the future;
		# right now they're included and the starbase kill objective does nothing,
		# as the menace reward is the same

		fromfrom = {
			OR = {
				NOT = { is_ship_class = shipclass_starbase }
				fleet = { is_mobile = yes } #juggernauts
			}
		}
	}

	immediate = {
		owner = {
			complete_crisis_objective = crisobj_destroy_enemy_ships
		}
	}
}


# Menace Objective - Destroy Starbases
# Fired from on_action 'on_starbase_destroyed'
starbase_event = {
	id = crisis.4010
	hide_window = yes
	is_triggered_only = yes

	# This = Starbase
	# From = fleet that destroyed it

	trigger = {
		from = {
			owner = {
				has_ascension_perk = ap_become_the_crisis
			}
		}
	}

	immediate = {
		from = {
			owner = {
				# Note: crisobj_destroy_enemy_ships would do the same thing, disabled for starbases in crisis.4025
				complete_crisis_objective = crisobj_destroy_starbases
			}
		}
	}
}


# Menace Objective - Purge Pops
# Fired from on_action 'on_pop_purged'
carrier_event = {
	id = crisis.4030
	hide_window = yes
	is_triggered_only = yes

	# This = Colony
	# From = Country
	# FromFrom = Pop

	trigger = {
		from = {
			OR = {
				has_ascension_perk = ap_become_the_crisis
				has_ascension_perk = ap_cosmogenesis
			}
		}
		fromfrom = {
			NOT = {
				has_purge_type = { country = from type = purge_cosmogenesis_lathe_resettle }
			}
		}
	}

	immediate = {
		if = {
			limit = {
				from = {
					has_origin = origin_nomadic_purger
					exists = overlord
				}
			}
			while = {
				count = value:per_100_local_pop_amount
				from.overlord = {
					complete_crisis_objective = crisobj_purge_pops
				}
			}
		}
		else = {
			while = {
				count = value:per_100_local_pop_amount
				from = {
					complete_crisis_objective = crisobj_purge_pops
				}
			}
		}
	}
}


# Menace Objective - Destroy Worlds
# Fired from on_destroy_planet_with_PLANET_KILLER_CRACKER
carrier_event = {
	id = crisis.5015
	hide_window = yes
	is_triggered_only = yes

	# This/Root = planet that have been fired upon
	# From = fleet that fired

	trigger = {
		from.owner = { has_ascension_perk = ap_become_the_crisis }
		is_colony = yes
	}

	immediate = {
		from.owner = { complete_crisis_objective = crisobj_destroy_worlds }
		# if no other colonies, give empire destruction menace reward
		if = {
			limit = {
				exists = owner
				owner = {
					NOT = {
						any_owned_planet = {
							NOT = { is_same_value = root }
						}
					}
				}
			}
			from.owner = {
				complete_crisis_objective = crisobj_destroy_empires
			}
		}
	}
}

# Menace Objective - Conquer Worlds
# Fired from on_action 'on_colony_conquer'
carrier_event = {
	id = crisis.5010
	hide_window = yes
	is_triggered_only = yes

	# From = Country scope (new owner)
	# This = Planet scope

	trigger = {
		from = {
			has_ascension_perk = ap_become_the_crisis
		}
		OR = {
			is_colony = yes
			AND = {
				exists = owner
				owner = {
					is_primitive = yes
				}
			}
		}
	}

	immediate = {
		from = {
			complete_crisis_objective = crisobj_conquer_worlds
		}
	}
}

# Menace Objective - Vassalise Empires
# Fired from on_action 'on_becoming_subject'
country_event = {
	id = crisis.5020
	hide_window = yes
	is_triggered_only = yes

	# This = subject
	# From = subject's overlord

	trigger = {
		is_subject = yes
		NOT = { has_country_flag = has_become_crisis_vassal }
		from = {
			has_ascension_perk = ap_become_the_crisis
		}
	}

	immediate = {
		from = {
			complete_crisis_objective = crisobj_vassalise_empires
		}
		set_country_flag = has_become_crisis_vassal
	}
}


# Menace Objective - Have Vassals
# Fired from on_action 'on_yearly_pulse'
event = {
	id = crisis.5000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_country = {
			has_ascension_perk = ap_become_the_crisis
			is_overlord = yes
		}
	}

	immediate = {
		every_playable_country = {
			if = {
				limit = {
					has_ascension_perk = ap_become_the_crisis
					is_overlord = yes
				}
				every_subject = {
					prev = {
						complete_crisis_objective = crisobj_have_vassals
					}
				}
			}
		}
	}
}

# Menace Objective - Be in Breach of Galactic Law
# Fired from on_action 'on_yearly_pulse'
event = {
	id = crisis.5005
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_country = {
			has_ascension_perk = ap_become_the_crisis
			OR = {
				is_in_breach_of_any = yes
				has_country_flag = declared_crisis
			}
		}
	}

	immediate = {
		every_playable_country = {
			limit = {
				has_ascension_perk = ap_become_the_crisis
				OR = {
					is_in_breach_of_any = yes
					has_country_flag = declared_crisis
				}
			}
			complete_crisis_objective = crisobj_be_in_breach_of_galcom_law
		}
	}
}
