
### Apocalypse Events

namespace = apoc

# Encountered Abandoned Gateway
ship_event = {
	id = apoc.1
	title = "apoc.1.name"
	desc = {
		text = apoc.1.desc
		trigger = {
			NOT = {
				owner = { has_country_flag = encountered_first_lgate }
			}
		}
	}
	desc = {
		text = apoc.1.b.desc
		trigger = {
			owner = { has_country_flag = encountered_first_lgate }
		}
	}
	picture = GFX_evt_drifting_gateway
	show_sound = event_radio_chatter
	location = FROM

	is_triggered_only = yes

	trigger = {
		owner = {
			NOT = { has_country_flag = encountered_first_gateway }
		}
		FROM = {
			has_star_flag = abandoned_gateway
			any_system_megastructure = { is_megastructure_type = gateway_ruined }
		}
	}

	immediate = {
		FROM = { save_event_target_as = gateway_system }
		owner = {
			set_country_flag = encountered_first_gateway
			add_seen_bypass_type = gateway
		}
	}

	option = {
		name = INTRIGUING
	}
}

# Encountered L-Gate
ship_event = {
	id = apoc.3
	title = "apoc.1.name"
	desc = {
		text = apoc.3.desc
		trigger = {
			NOT = {
				owner = { has_country_flag = encountered_first_gateway }
			}
		}
	}
	desc = {
		text = apoc.3.b.desc
		trigger = {
			owner = { has_country_flag = encountered_first_gateway }
		}
	}
	picture = GFX_evt_l-gateway
	show_sound = event_radio_chatter
	location = FROM

	is_triggered_only = yes

	trigger = {
		owner = {
			NOR = {
				has_country_flag = encountered_first_lgate
				has_event_chain = "l_cluster_chain"
			}
		}
		FROM = {
			has_star_flag = lgate
			any_system_megastructure = { is_megastructure_type = lgate_base }
		}
	}

	immediate = {
		FROM = { save_event_target_as = gateway_system }
		owner = { set_country_flag = encountered_first_lgate }
	}

	option = {
		name = INTRIGUING
		owner = {
			start_lcluster_chain = yes
		}
	}
}

# Encountered Natural Wormhole
# Via on_entering_system_first_time | this = Ship; from = System; fromfrom = Country
ship_event = {
	id = apoc.5
	title = apoc.5.name
	desc = "apoc.5.desc"
	picture = GFX_evt_wormhole
	show_sound = event_radio_chatter
	location = FROM

	is_triggered_only = yes

	trigger = {
		owner = {
			NOT = {
				has_country_flag = encountered_first_wormhole
			}
		}
		FROM = {
			has_natural_wormhole = yes
			NOR = {
				has_star_flag = shroud_tunnel_nexus
				has_star_flag = shroud_tunnel_node
				has_star_flag = formless_system
				has_star_flag = crystal_sphere_system
			}
		}
	}

	immediate = {
		FROM = { save_event_target_as = wormhole_system }
		owner = {
			set_country_flag = encountered_first_wormhole
			add_seen_bypass_type = wormhole
		}
	}

	option = {
		name = apoc.5.a
	}
}

# Ancient Gateway Reactivated
country_event = {
	id = apoc.10
	title = "apoc.10.name"
	desc = {
		text = apoc.10.desc.1
		trigger = {
			num_active_gateways = 2
			NOT = { has_country_flag = did_not_repair_gateway }
		}
	}
	desc = {
		text = apoc.10.desc.2
		trigger = {
			num_active_gateways > 2
			NOT = { has_country_flag = did_not_repair_gateway }
		}
	}
	desc = {
		text = apoc.10.desc.3
		trigger = {
			has_country_flag = did_not_repair_gateway
			has_technology = "tech_gateway_activation"
		}
	}
	desc = {
		text = apoc.10.desc.4
		trigger = {
			has_country_flag = did_not_repair_gateway
			NOT = { has_technology = "tech_gateway_activation" }
		}
	}
	picture = GFX_evt_drifting_gateway
	show_sound = event_radio_chatter
	location = from

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_country_flag = gateway_reactivated
			has_country_flag = gateway_built
		}
		NAND = {
			has_origin = origin_galactic_doorstep
			NOT = { has_technology = tech_gateway_construction }
			NOT = { has_tech_option = tech_gateway_construction }
			fromfromfrom = { has_megastructure_flag = doorstep_gateway@root }
		}
	}

	immediate = {
		from = { save_event_target_as = gateway_system }
		set_country_flag = gateway_reactivated
	}

	#did_not_repair_gateway is cleared in action.120

	option = {
		name = EXCELLENT
		trigger = {
			NOT = { has_country_flag = did_not_repair_gateway }
		}
	}
	option = {
		name = INTERESTING
		trigger = {
			has_country_flag = did_not_repair_gateway
			has_technology = "tech_gateway_activation"
		}
	}
	option = {
		name = apoc.10.a
		trigger = {
			has_country_flag = did_not_repair_gateway
			NOT = { has_technology = "tech_gateway_activation" }
		}
		if = {
			limit = {
				NOT = { has_tech_option = tech_gateway_activation }
			}
			add_research_option = tech_gateway_activation
		}
	}
}

# New Gateway Constructed
country_event = {
	id = apoc.11
	title = "apoc.11.name"
	desc = "apoc.11.desc"
	picture = GFX_evt_drifting_gateway
	show_sound = event_radio_chatter
	location = from

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_country_flag = gateway_reactivated
			has_country_flag = gateway_built
		}
		fromfromfrom = {
			NOT = {
				has_megastructure_flag = doorstep_gateway@root
			}
		}
	}

	immediate = {
		from = { save_event_target_as = gateway_system }
		set_country_flag = gateway_built
	}

	option = {
		name = EXCELLENT
	}
}

# Additional Gateways Reactivated
country_event = {
	id = apoc.12
	title = "apoc.10.name"
	desc = "apoc.12.desc"
	picture = GFX_evt_drifting_gateway
	show_sound = event_radio_chatter
	location = from

	is_triggered_only = yes

	trigger = {
		OR = {
			has_country_flag = gateway_reactivated
			has_country_flag = gateway_built
		}
		fromfromfrom = {
			NOR = {
				has_megastructure_flag = doorstep_gateway@root
				has_megastructure_flag = paragon_gateway_dude_homegate_flag
			}
		}
	}

	immediate = {
		from = { save_event_target_as = gateway_system }
	}

	option = {
		name = EXCELLENT
	}
}

# Additional Gateways Constructed
country_event = {
	id = apoc.13
	title = "apoc.11.name"
	desc = "apoc.13.desc"
	picture = GFX_evt_drifting_gateway
	show_sound = event_radio_chatter
	location = from

	is_triggered_only = yes

	trigger = {
		OR = {
			has_country_flag = gateway_reactivated
			has_country_flag = gateway_built
		}
	}

	immediate = {
		from = { save_event_target_as = gateway_system }
	}

	option = {
		name = EXCELLENT
	}
}

# Gateway Construction Site Finished
country_event = {
	id = apoc.14
	title = "apoc.14.name"
	desc = "apoc.14.desc"
	picture = GFX_evt_megastructure_construction
	show_sound = event_radio_chatter
	location = from

	is_triggered_only = yes

	immediate = {
		from = { save_event_target_as = gateway_system }
	}

	option = {
		name = GOOD
	}
}

country_event = {
	id = apoc.101
	hide_window = yes
	is_test_event = yes

	trigger = { always = no }

	immediate = {
		give_technology = {
			tech = tech_destroyers
			message = no
		}
		give_technology = {
			tech = tech_cruisers
			message = no
		}
		give_technology = {
			tech = tech_battleships
			message = no
		}
		give_technology = {
			tech = tech_titans
			message = no
		}
	}
}

# Colossus Project
country_event = {
	id = apoc.100
	title = "apoc.100.name"
	desc = {
		text = apoc.100.desc.purif
		trigger = {
			has_valid_civic = civic_fanatic_purifiers
		}
	}
	desc = {
		text = apoc.100.desc.termi
		trigger = {
			has_valid_civic = civic_machine_terminator
		}
	}
	desc = {
		text = apoc.100.desc.pacif
		trigger = {
			is_pacifist = yes
		}
	}
	desc = {
		text = apoc.100.desc.milit
		trigger = {
			is_militarist = yes
		}
	}
	desc = {
		text = apoc.100.desc.phobe
		trigger = {
			is_xenophobe = yes
		}
	}
	desc = {
		text = apoc.100.desc
		trigger = {
			NOR = {
				is_pacifist = yes
				is_militarist = yes
				is_xenophobe = yes
				has_valid_civic = civic_machine_terminator
				has_valid_civic = civic_hive_devouring_swarm
			}
		}
	}
	picture = GFX_evt_megastructure_construction
	show_sound = event_radio_chatter
	location = capital_scope

	is_triggered_only = yes

	option = {
		name = apoc.100.a
		capital_scope = {
			enable_special_project = {
				name = "COLOSSUS_PROJECT"
				location = this
				owner = root
			}
		}
	}
}

# Choose Planet-Killer Weapon on 50% project progress
country_event = {
	id = apoc.110
	title = apoc.110.name
	desc = {
		text = apoc.110.desc
		trigger = { NOT = { has_ethic = ethic_gestalt_consciousness } }
	}
	desc = {
		text = apoc.110.desc.machine
		trigger = { is_machine_empire = yes }
	}
	desc = {
		text = apoc.110.desc.hive
		trigger = { is_hive_empire = yes }
	}
	picture = GFX_evt_planet_beam
	show_sound = event_radio_chatter
	location = capital_scope

	is_triggered_only = yes

	option = {
		name = PLANET_KILLER_CRACKER
		custom_tooltip = apoc.110.cracker.tooltip
		hidden_effect = {
			set_country_flag = pk_cracker
		}

		trigger = {
			is_pacifist = no
		}
	}

	option = {
		name = PLANET_KILLER_SHIELDER
		custom_tooltip = apoc.110.shielder.tooltip
		hidden_effect = {
			set_country_flag = pk_shielder
		}

		trigger = {
			is_pacifist = yes
		}
	}

	option = {
		name = PLANET_KILLER_NEUTRON
		custom_tooltip = apoc.110.neutron.tooltip
		hidden_effect = {
			set_country_flag = pk_neutron
		}

		trigger = {
			is_pacifist = no
			# Available to spiritualists if Divine Enforcer is locked out
			OR = {
				is_spiritualist = no
				has_psionic_ascension = no
			}
		}
	}

	option = {
		name = PLANET_KILLER_GODRAY
		custom_tooltip = apoc.110.godray.tooltip
		hidden_effect = {
			set_country_flag = pk_godray
		}

		trigger = {
			is_spiritualist = yes
			has_psionic_ascension = yes
		}
	}

	option = {
		name = PLANET_KILLER_NANOBOTS
		custom_tooltip = apoc.110.nanobots.tooltip
		hidden_effect = {
			set_country_flag = pk_nanobots
		}

		trigger = {
			hidden_trigger = { has_ethic = ethic_gestalt_consciousness }
			has_valid_civic = civic_machine_assimilator
		}
	}

	option = {
		name = PLANET_KILLER_DEVOLUTION
		custom_tooltip = apoc.110.devolution.tooltip
		hidden_effect = {
			set_country_flag = pk_devolution
		}

		trigger = {
			OR = {
				has_technology = tech_archaeo_pk_devolving_beam
				has_tech_option = tech_archaeo_pk_devolving_beam
			}
		}
	}

	option = {
		name = PLANET_KILLER_SMELTER
		custom_tooltip = apoc.110.smelter.tooltip
		hidden_effect = {
			set_country_flag = pk_smelter
		}

		trigger = {
			can_get_planet_smelter = yes
		}
	}
}

# Get Colossus and weapon tech on project completion
country_event = {
	id = apoc.120
	title = apoc.120.name
	desc = {
		text = apoc.120.desc
		trigger = { NOT = { has_ethic = ethic_gestalt_consciousness } }
	}
	desc = {
		text = apoc.120.desc.machine
		trigger = { is_machine_empire = yes }
	}
	desc = {
		text = apoc.120.desc.hive
		trigger = { is_hive_empire = yes }
	}
	picture = GFX_evt_megastructure_construction
	show_sound = event_radio_chatter
	location = capital_scope

	is_triggered_only = yes

	immediate = {
		set_country_flag = colossus_project
	}

	option = {
		name = OK
		give_technology = {
			tech = tech_colossus
			message = no
		}
		if = {
			limit = {
				has_country_flag = pk_cracker
				can_research_technology = tech_pk_cracker
			}
			give_technology = { tech = tech_pk_cracker message = no }
		}
		else_if = {
			limit = {
				has_country_flag = pk_shielder
				can_research_technology = tech_pk_shielder
			}
			give_technology = { tech = tech_pk_shielder message = no }
		}
		else_if = {
			limit = {
				has_country_flag = pk_neutron
				can_research_technology = tech_pk_neutron
			}
			give_technology = { tech = tech_pk_neutron message = no }
		}
		else_if = {
			limit = {
				has_country_flag = pk_godray
				can_research_technology = tech_pk_godray
			}
			give_technology = { tech = tech_pk_godray message = no }
		}
		else_if = {
			limit = {
				has_country_flag = pk_nanobots
				can_research_technology = tech_pk_nanobots
			}
			give_technology = { tech = tech_pk_nanobots message = no }
		}
		else_if = {
			limit = {
				has_country_flag = pk_devolution
				can_research_technology = tech_archaeo_pk_devolving_beam
			}
			give_technology = {
				tech = tech_archaeo_pk_devolving_beam
				message = no
			}
		}
		else_if = {
			limit = {
				has_country_flag = pk_smelter
				can_research_technology = tech_pk_smelter
			}
			give_technology = { tech = tech_pk_smelter message = no }
		}
		# fallback
		else = {
			switch = {
				trigger = can_research_technology
				tech_pk_cracker = { give_technology = { tech = tech_pk_cracker message = no } }
				tech_pk_shielder = { give_technology = { tech = tech_pk_shielder message = no } }
				tech_pk_neutron = { give_technology = { tech = tech_pk_neutron message = no } }
				tech_pk_godray = { give_technology = { tech = tech_pk_godray message = no } }
				tech_pk_nanobots = { give_technology = { tech = tech_pk_nanobots message = no } }
			}
		}
		hidden_effect = {
			every_playable_country = {
				limit = {
					has_communications = root
					NOT = { is_same_value = root }
					has_intel_level = {
						who = root
						category = military
						level >= 2
					}
				}
				country_event = { id = apoc.130 } # colossus researched notification
			}
			observer_event = { id = observer.69 }
		}
	}
}

country_event = {
	id = apoc.130
	title = apoc.130.name
	desc = apoc.130.desc
	picture = GFX_evt_planet_beam
	show_sound = event_radio_chatter
	location = from.capital_scope

	is_triggered_only = yes

	option = {
		name = apoc.130.a.weaker
		trigger = {
			is_pacifist = no
			relative_power = {
				who = from
				category = all
				value > inferior
			}
		}
	}

	option = {
		name = apoc.130.a.stronger
		trigger = {
			is_pacifist = no
			relative_power = {
				who = from
				category = all
				value < equivalent
			}
		}
	}

	option = {
		name = apoc.130.a.pacif
		trigger = {
			is_pacifist = yes
		}
	}
}

# Gain Gateway flag on researching tech
country_event = {
	id = apoc.300
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		last_increased_tech = "tech_gateway_activation"
	}

	immediate = {
		set_country_flag = encountered_first_gateway
	}
}

# Fix for savegames
event = {
	id = apoc.301
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		any_playable_country = {
			has_technology = "tech_gateway_activation"
			NOT = { has_country_flag = encountered_first_gateway }
		}
	}

	immediate = {
		random_playable_country = {
			limit = {
				has_technology = "tech_gateway_activation"
				NOT = { has_country_flag = encountered_first_gateway }
			}
			set_country_flag = encountered_first_gateway
		}
	}
}
