namespace = crisis

country_event = { # Ready to dive - Country Event
	id = crisis.7510
	title = "crisis.7510.name"
	desc = crisis.7510.desc
	picture = GFX_evt_horizon_needle
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	immediate = {
		capital_scope.solar_system.star = {
			save_event_target_as = supermassive_project_location
		}
	}

	option = { # Any regular black hole will do
		name = crisis.7510.a
		hidden_effect = {
			set_country_flag = cosmogenesis_any_black_hole
		}
	}

	option = { # ONLY THE SUPERMASSIVE BH AT THE CENTER OF THE GALAXY WILL DO
		name = crisis.7510.b
		enable_special_project = {
			name = COSMOGENESIS_VICTORY
			location = event_target:supermassive_project_location
		}
		hidden_effect = {
			set_country_flag = cosmogenesis_supermassive
		}
		allow = {
			custom_tooltip = {
				fail_text = "giga_core_black_hole_exists"
				hidden_trigger = {
					has_global_flag = giga_core_disabled
				}
			}
		}
	}

	option = { # Dive into the Ark's Battery
		name = crisis.7510.c
		custom_tooltip = crisis.7510.c.tooltip
		trigger = {
			has_global_flag = ssh_vacdec_crisis_ongoing
			has_global_flag = ssh_ark_project_launched
		}
		allow = {
			fail_text = {
				text = "crisis.7510.c.requirements"
				OR = {
					has_global_flag = ssh_ark_construction_stage_3
					has_global_flag = ssh_ark_construction_stage_4
					has_global_flag = ssh_ark_construction_stage_5
					has_global_flag = ssh_ark_construction_stage_6
					has_global_flag = ssh_ark_completed
				}
			}
		}
		enable_special_project = {
			name = COSMOGENESIS_VICTORY_ARK
			location = event_target:supermassive_project_location
		}
		hidden_effect = {
			set_country_flag = cosmogenesis_ark
			every_playable_country = {
				limit = {
					is_ai = no
					has_country_flag = ssh_ark_project_country
				}
				country_event = {
					id = ssh_crisis.7605
				}
			}
		}
	}

	option = { # Guys HEAR ME OUT we jump into the Vester
		name = crisis.7510.vester
		custom_tooltip = "crisis.7510.vester.tooltip"
		trigger = {
			any_country = { is_country_type = blokkat_stripminers }
			NOT = { has_global_flag = blokkat_mothership_shield_down }
		}
		hidden_effect = { set_country_flag = cosmogenesis_vester }
	}
}

planet_event = { # About to dive - Planet Action
	id = crisis.7514
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from.owner = {
			has_country_flag = exodus_ready
			has_country_flag = cosmogenesis_any_black_hole
		}
	}

	immediate = {
		create_ambient_object = {
			type = "horizon_needle_dive"
			play_animation_once = yes
			location = this
		}
		last_created_ambient_object = {
			set_location = {
				target = prev
				distance = 0
				angle = random
			}
		}
		# Special event for matter decompressors
		if = {
			limit = {
				solar_system = {
					any_system_megastructure = {
						OR = {
							is_megastructure_type = matter_decompressor_4
							is_megastructure_type = matter_decompressor_restored
							is_megastructure_type = matter_decompressor_ruined
						}
					}
				}
			}
			from.owner = { country_event = { id = ssh_crisis.7515 days = 7 } }
		}
		else = {
			# Regular Events
			from.owner = { country_event = { id = crisis.7515 days = 7 } }
		}
	}
}

country_event = { # To infinity and beyond the event horizon
	id = crisis.7516
	title = "crisis.7516.name"
	desc = {
		trigger = {
			can_create_paperclip_universe = yes
			NOT = {
				event_target:cosmo_ending_system = {
					is_capital_system = yes
					has_star_flag = cosmogenesis_project
				}
			}
		}
		text = crisis.7516.desc.paperclips
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				NOR = {
					is_star_class = sc_birch
					is_star_class = sc_quasar
					has_star_flag = great_wound
					has_star_flag = guardians_technosphere_system
					has_star_flag = terminal_egress
					has_star_flag = guardians_horror_system
					# SSH Systems
					has_star_flag = ssh_dimensional_tearer_system
					has_star_flag = ssh_dimensional_wave_hit_system
					has_star_flag = ruined_black_hole_shellworld_system
					has_star_flag = ruined_edersphere_system
					has_star_flag = ssh_basement_universe_gateway
					has_star_flag = ssh_basement_universe_center
					has_star_flag = abyssal_anchor_system
					has_star_flag = ssh_black_hole_suprashell_system
					has_star_flag = fe_materialist_suprashell_capital
					# SSH Systems
					has_star_flag = ssh_dimensional_tearer_system
					has_star_flag = ssh_dimensional_wave_hit_system
					has_star_flag = ruined_black_hole_shellworld_system
					has_star_flag = ruined_edersphere_system
					has_star_flag = ssh_basement_universe_gateway
					has_star_flag = ssh_basement_universe_center
					has_star_flag = abyssal_anchor_system
					has_star_flag = ssh_black_hole_suprashell_system
					has_star_flag = fe_materialist_suprashell_capital
					has_star_flag = ssh_interstellar_black_hole_system
					has_star_flag = ssh_ark_jump_cluster_core
					has_star_flag = gigas_collapsed_star
					has_star_flag = federation_end
					any_system_planet = {
						has_planet_flag = black_hole_horror
					}
					is_capital_system = yes
					has_star_flag = cosmogenesis_project
				}
			}
		}
		text = crisis.7516.desc
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = great_wound
			}
		}
		text = crisis.7516.desc.greatwound
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = guardians_technosphere_system
			}
		}
		text = crisis.7516.desc.technosphere
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = pantagruel
			}
		}
		text = crisis.7516.desc.technosphere.pantagruel
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = terminal_egress
			}
		}
		text = crisis.7516.desc.egress
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				OR = {
					has_star_flag = guardians_horror_system
					any_system_planet = {
						has_planet_flag = black_hole_horror
					}
				}
			}
		}
		text = crisis.7516.desc.horror
	}
	desc = {
		trigger = {
			NAND = {
				has_global_flag = ssh_vacdec_crisis_ongoing # Special Ending if reality collapses & Spiritualist FE left
				has_global_flag = ssh_vacdec_fe_spiritualist_left
			}
			NOT = { has_country_flag = covenant_end_of_the_cycle } # No EOTC Covenant
			NOT = { has_origin = origin_toxic_knights }
			NOT = { has_country_flag = has_shroud_patron }
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
		}
		text = crisis.7516.desc.center
	}
	desc = {
		trigger = {
			NAND = {
				has_global_flag = ssh_vacdec_crisis_ongoing # Special Ending if reality collapses & Spiritualist FE left
				has_global_flag = ssh_vacdec_fe_spiritualist_left
			}
			NOT = { has_country_flag = covenant_end_of_the_cycle } # No EOTC Covenant
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
		}
		text = crisis.7516.desc.center.patron
	}
	desc = {
		trigger = {
			has_origin = origin_toxic_knights
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
		}
		text = crisis.7516.desc.centerknights
	}
	# new
	desc = {
		trigger = {
			NOT = { has_origin = origin_toxic_knights }
			NOT = { has_country_flag = has_shroud_patron }
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
		}
		text = crisis.7516.desc.center
	}

	#Jumped into the Gigas galactic core
	desc = {
		trigger = {
			NAND = {
				has_global_flag = ssh_vacdec_crisis_ongoing # Special Ending if reality collapses & Spiritualist FE left
				has_global_flag = ssh_vacdec_fe_spiritualist_left
			}
			NOT = { has_country_flag = covenant_end_of_the_cycle } # No EOTC Covenant
			NOT = { has_origin = origin_toxic_knights }
			NOT = { has_country_flag = has_shroud_patron }
			event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
		}
		text = crisis.7516.desc.center
	}
	
	desc = {
		trigger = {
			NAND = {
				has_global_flag = ssh_vacdec_crisis_ongoing # Special Ending if reality collapses & Spiritualist FE left
				has_global_flag = ssh_vacdec_fe_spiritualist_left
			}
			NOT = { has_country_flag = covenant_end_of_the_cycle } # No EOTC Covenant
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
		}
		text = crisis.7516.desc.center.patron
	}
	desc = {
		trigger = {
			has_origin = origin_toxic_knights
			event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
		}
		text = crisis.7516.desc.centerknights
	}
	# Galactic Core during Reality Collapse w/ Fallen Spiritualists
	desc = {
		trigger = {
			has_global_flag = ssh_vacdec_crisis_ongoing
			has_global_flag = ssh_vacdec_fe_spiritualist_left
			NOT = { has_origin = origin_toxic_knights }
			NOT = { has_country_flag = has_shroud_patron }
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
		}
		text = crisis.7516.desc.ssh.center_vacdec_spiritualist
	}
	desc = {
		trigger = {
			has_global_flag = ssh_vacdec_crisis_ongoing
			has_global_flag = ssh_vacdec_fe_spiritualist_left
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
		}
		text = crisis.7516.desc.ssh.center_vacdec_spiritualist_patron
	}
	desc = {
		trigger = {
			has_global_flag = ssh_vacdec_crisis_ongoing
			has_global_flag = ssh_vacdec_fe_spiritualist_left
			NOT = { has_origin = origin_toxic_knights }
			NOT = { has_country_flag = has_shroud_patron }
			event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
		}
		text = crisis.7516.desc.ssh.center_vacdec_spiritualist
	}
	desc = {
		trigger = {
			has_global_flag = ssh_vacdec_crisis_ongoing
			has_global_flag = ssh_vacdec_fe_spiritualist_left
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
		}
		text = crisis.7516.desc.ssh.center_vacdec_spiritualist_patron
	}

	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				OR = {
					has_star_flag = horizonsignal_system
					has_star_flag = worm_black_hole
				}
			}
		}
		text = crisis.7516.desc.worm
	}
	# This one is added by gigas
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
		}
		text = crisis.7516.desc.worm
	}

	# SSH Systems
	# Dimensional Tearer System - After Ascension
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			any_country = { has_country_flag = ssh_completed_exodus_country }
			event_target:cosmo_ending_system = {
				has_star_flag = ssh_dimensional_tearer_system
			}
		}
		text = crisis.7516.desc.ssh.dimensional_tearer
	}
	# Dimensional Tearer Wave System & Dimensional Tearer System - Before Ascension
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			OR = {
				event_target:cosmo_ending_system = { has_star_flag = ssh_dimensional_wave_hit_system }
				AND = {
					NOT = { any_country = { has_country_flag = ssh_completed_exodus_country } }
					event_target:cosmo_ending_system = {
						has_star_flag = ssh_dimensional_tearer_system
					}
				}
			}
		}
		text = crisis.7516.desc.ssh.dimensional_tearer_wave
	}
	# Ruined Suprashell System
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = ruined_black_hole_shellworld_system
			}
		}
		text = crisis.7516.desc.ssh.ruined_suprashell
	}
	# Ruined Edersphere System
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = ruined_edersphere_system
			}
		}
		text = crisis.7516.desc.ssh.kitkat
	}
	# Abyssal Anchor
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = abyssal_anchor_system #basement_universe_gateway
			}
		}
		text = crisis.7516.desc.ssh.abyssal_anchor
	}
	# Basement Gateway
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				OR = {
					has_star_flag = ssh_basement_universe_gateway
					has_star_flag = ssh_basement_universe_center
				}
			}
		}
		text = crisis.7516.desc.ssh.basement_gateway
	}
	# Suprashell (Regular)
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = ssh_black_hole_suprashell_system
				NOR = {
					has_star_flag = ruined_black_hole_shellworld_system
					has_star_flag = great_wound
					has_star_flag = guardians_technosphere_system
					has_star_flag = terminal_egress
					has_star_flag = guardians_horror_system
					# SSH Systems
					has_star_flag = ssh_dimensional_tearer_system
					has_star_flag = ssh_dimensional_wave_hit_system
					has_star_flag = ruined_edersphere_system
					has_star_flag = ssh_basement_universe_gateway
					has_star_flag = ssh_basement_universe_center
					has_star_flag = abyssal_anchor_system
					has_star_flag = fe_materialist_suprashell_capital
					has_star_flag = ssh_interstellar_black_hole_system
					has_star_flag = ssh_ark_jump_cluster_core
					has_star_flag = gigas_collapsed_star
					has_star_flag = federation_end
					any_system_planet = {
						has_planet_flag = black_hole_horror
					}
					is_capital_system = yes
					has_star_flag = cosmogenesis_project
				}
			}
		}
		text = crisis.7516.desc.ssh.suprashell
	}
	# FE Materialist Suprashell
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = fe_materialist_suprashell_capital
				NOR = {
					has_star_flag = ruined_black_hole_shellworld_system
					has_star_flag = great_wound
					has_star_flag = guardians_technosphere_system
					has_star_flag = terminal_egress
					has_star_flag = guardians_horror_system
					# SSH Systems
					has_star_flag = ssh_dimensional_tearer_system
					has_star_flag = ssh_dimensional_wave_hit_system
					has_star_flag = ruined_edersphere_system
					has_star_flag = ssh_basement_universe_gateway
					has_star_flag = ssh_basement_universe_center
					has_star_flag = abyssal_anchor_system
					has_star_flag = ssh_interstellar_black_hole_system
					has_star_flag = ssh_ark_jump_cluster_core
					has_star_flag = gigas_collapsed_star
					has_star_flag = federation_end
					any_system_planet = {
						has_planet_flag = black_hole_horror
					}
					is_capital_system = yes
					has_star_flag = cosmogenesis_project
				}
			}
		}
		text = crisis.7516.desc.ssh.fe_materialist_suprashell
	}
	# Artificial Black Hole (System Creator)
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = ssh_interstellar_black_hole_system
			}
		}
		text = crisis.7516.desc.ssh.interstellar_black_hole
	}
	# Ark Jump - Black Hole Galaxy Core
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = ssh_ark_jump_cluster_core
			}
		}
		text = crisis.7516.desc.ssh.ark_cluster_core
	}
	# Ark Jump - Destroyed Aerophasic Engine
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			has_global_flag = ssh_ark_jump_new_galaxy_destroyed
			#event_target:cosmo_ending_system = {
			#	has_star_flag = destroyed_aerophasic_engine_system
			#}
		}
		text = crisis.7516.desc.ssh.aerophasic_engine
	}

	# Additional Vanilla Endings
	# Star Eater Black Hole
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = star_cracked
			}
		}
		text = crisis.7516.desc.ssh.cracked_star
	}
	# EOTC - Pre-Reckoning
	desc = {
		trigger = {
			NAND = {
				has_global_flag = ssh_vacdec_crisis_ongoing
				has_global_flag = ssh_vacdec_fe_spiritualist_left
			}
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
			has_country_flag = covenant_end_of_the_cycle # EOTC Covenant
			NOT = { has_country_flag = end_of_the_cycle_reckoning } # Post-Reckoning
		}
		text = crisis.7516.desc.ssh.center_eotc
	}
	# EOTC - Post-Reckoning
	desc = {
		trigger = {
			NAND = {
				has_global_flag = ssh_vacdec_crisis_ongoing
				has_global_flag = ssh_vacdec_fe_spiritualist_left
			}
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
			has_country_flag = covenant_end_of_the_cycle # EOTC Covenant
			has_country_flag = end_of_the_cycle_reckoning # Post-Reckoning
		}
		text = crisis.7516.desc.ssh.center_eotc_reckoning
	}
	# EOTC Pre Gigas Core
	desc = {
		trigger = {
			NAND = {
				has_global_flag = ssh_vacdec_crisis_ongoing
				has_global_flag = ssh_vacdec_fe_spiritualist_left
			}
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
			has_country_flag = covenant_end_of_the_cycle # EOTC Covenant
			NOT = { has_country_flag = end_of_the_cycle_reckoning } # Pre-Reckoning
		}
		text = crisis.7516.desc.ssh.center_eotc
	}
	# EOTC Post Gigas Core
	desc = {
		trigger = {
			NAND = {
				has_global_flag = ssh_vacdec_crisis_ongoing
				has_global_flag = ssh_vacdec_fe_spiritualist_left
			}
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
			has_country_flag = covenant_end_of_the_cycle # EOTC Covenant
			has_country_flag = end_of_the_cycle_reckoning # Post-Reckoning
		}
		text = crisis.7516.desc.ssh.center_eotc_reckoning
	}
	# Federation's End
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = federation_end
			}
		}
		text = crisis.7516.desc.ssh.federation_end
	}

	# Additional Gigas Endings
	# Gigas' Artificial Black Hole
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = gigas_collapsed_star
			}
		}
		text = crisis.7516.desc.ssh.gigas_collapsed_star
	}
	# More Primitives Endings
	# Particle Accelerator Black Hole Endings
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				any_system_planet = {
					has_planet_flag = mp_partacc_accident_planet
				}
			}
			NOR = {
				has_civic = civic_reanimated_armies
				has_civic = civic_hive_cordyceptic_drones
			}
		}
		text = crisis.7516.desc.mp.partacc_accident
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				any_system_planet = {
					has_planet_flag = mp_partacc_accident_planet
				}
			}
			OR = {
				has_civic = civic_reanimated_armies
				has_civic = civic_hive_cordyceptic_drones
			}
		}
		text = crisis.7516.desc.mp.partacc_accident_reanimator
	}

	picture = GFX_evt_horizon_needle
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				can_create_paperclip_universe = yes
			}
			set_country_flag = a_universe_of_paperclips_achievement
		}
	}

	# Normal Response
	option = {
		name = crisis.7516.a
		custom_tooltip = crisis.7516.tt
		# Some endings have another response option
		trigger = {
			NAND = {
				can_create_paperclip_universe = no
				OR = {
					has_global_flag = ssh_ark_jump_new_galaxy_destroyed
					event_target:cosmo_ending_system = {
						has_star_flag = ssh_interstellar_black_hole_system
					}
					event_target:cosmo_ending_system = {
						has_star_flag = guardians_horror_system
					}
					event_target:cosmo_ending_system = {
						any_system_planet = {
							has_planet_flag = black_hole_horror
						}
					}
					event_target:cosmo_ending_system = {
						has_star_flag = federation_end
					}
				}
			}
		}
	}

	# Bad Ending
	option = {
		name = crisis.7516.b
		custom_tooltip = crisis.7516.tt_bad
		hidden_effect = {
			play_sound = event_the_great_awakening
		}
		trigger = {
			can_create_paperclip_universe = no
			OR = {
				has_global_flag = ssh_ark_jump_new_galaxy_destroyed
				event_target:cosmo_ending_system = {
					has_star_flag = ssh_interstellar_black_hole_system
				}
				event_target:cosmo_ending_system = {
					has_star_flag = guardians_horror_system
				}
				event_target:cosmo_ending_system = {
					any_system_planet = {
						has_planet_flag = black_hole_horror
					}
				}
				event_target:cosmo_ending_system = {
					has_star_flag = federation_end
				}
			}
		}
	}

	after = {
		hidden_effect = {
			if = {
				limit = {
					has_origin = origin_toxic_knights
					OR = {
						event_target:cosmo_ending_system = { OR = { is_star_class = sc_birch is_star_class = sc_quasar } }
						event_target:cosmo_ending_system = {
							is_capital_system = yes
							has_star_flag = cosmogenesis_project
						}
					}
				}
				set_global_flag = no_end_of_cycle
			}
			# SSH Effects: Nemesis Entity enters the universe
			if = {
				limit = {
					has_global_flag = ssh_ark_jump_new_galaxy_destroyed
					NOT = { has_global_flag = cosmogenesis_nemesis_entity_spawned }
				}
				set_global_flag = cosmogenesis_nemesis_entity_spawned
				event_target:cosmo_ending_system = {
					# Spawn the wrathful entity god
					create_country = {
						name = "The Overlord"
						type = shroud_spirits
						flag = {
							icon = {
								category = "special"
								file = "the_shroud.dds"
							}
							background= {
								category = "backgrounds"
								file = "00_solid.dds"
							}
							colors={
								"dark_purple"
								"black"
								"null"
								"null"
							}
						}
					}
					last_created_country = {
						save_event_target_as = nemesis_entity_country
					}
					create_fleet = {
						name = "The Overlord"
						settings = {
							spawn_debris = no
							#ai_ignore_strength = yes
							is_boss = yes
						}
						effect = {
							set_name = {
								key = "The Overlord"
								variable_string = "[Root.GetSpeciesNamePlural]"
							}
							set_owner = event_target:nemesis_entity_country
							create_ship = {
								name = "Overlord"
								design = "NAME_Warped_Consciousness"
							}
							set_location = prev.star
							set_fleet_stance = aggressive
							set_aggro_range_measure_from = return_point
							set_aggro_range = 3000
							# Make it stronk
							add_modifier = {
								modifier = "absorbed_consciousness_5"
								days = -1
							}
						}
					}
				}
			}
			# End of The Cycle: Early Reckoning
			if = {
				limit = {
					can_create_paperclip_universe = no
					NAND = {
						has_global_flag = ssh_vacdec_crisis_ongoing
						has_global_flag = ssh_vacdec_fe_spiritualist_left
					}
					NOT = { has_origin = origin_toxic_knights }
					has_country_flag = has_shroud_patron
					event_target:cosmo_ending_system = {
						is_capital_system = yes
						has_star_flag = cosmogenesis_project
					}
					has_country_flag = covenant_end_of_the_cycle # EOTC Covenant
					NOT = { has_country_flag = end_of_the_cycle_reckoning } # Post-Reckoning
				}
				# Same effects as reckoning minus exiles
				set_global_flag = end_of_the_cycle_complete
				set_country_flag = end_of_the_cycle_reckoning
				if = {
					limit = { NOT = { exists = event_target:shroud_country } }
					create_country = {
						name = "NAME_Creatures_of_the_Shroud"
						type = shroud_spirits
						flag = {
							icon = {
								category = "special"
								file = "the_shroud.dds"
							}
							background= {
								category = "backgrounds"
								file = "00_solid.dds"
							}
							colors={
								"dark_purple"
								"black"
								"null"
								"null"
							}
						}
					}
					last_created_country = {
						establish_communications_no_message = root
						save_global_event_target_as = shroud_country
					}
				}
				capital_scope = {
					save_event_target_as = former_capital
				}
				every_galaxy_planet = {
					limit = { has_modifier = covenant_shroud_marked }
					remove_modifier = covenant_shroud_marked
					remove_all_armies = yes
					every_owned_pop = {
						root = {
							change_variable = {
								which = "end_power"
								value = 1
							}
						}
					}
					if = {
						limit = {
							has_owner = yes
							owner = { NOT = { has_country_flag = end_of_the_cycle_reckoning } }
						}
						owner = {
							set_country_flag = end_of_the_cycle_reckoning
							set_country_flag = end_of_cycle_lost_planets
							country_event = { id = utopia.3321 }
						}
					}
					if = {
						limit = { NOT = { is_same_value = event_target:former_capital } }
						create_fleet = {
							name = "NAME_Shroud_Manifestation"
							settings = {
								spawn_debris = no
								is_boss = yes
							}
							effect = {
								set_owner = event_target:shroud_country
								create_ship = {
									name = "NAME_Fragment"
									design = "NAME_Shroud_Manifestation"
								}
								set_location = prev
								set_fleet_stance = aggressive
								set_aggro_range_measure_from = return_point
								set_aggro_range = 3000
							}
						}
						if = {
							limit = {
								is_planet_class = pc_habitat
							}
							destroy_colony = yes
							remove_planet = yes
						}
						else_if = {
							limit = {
								is_ringworld = yes
							}
							change_pc = pc_ringworld_habitable_damaged
							clear_planet_modifiers = yes
							clear_deposits = yes
						}
						else = {
							change_pc = pc_shrouded
							clear_planet_modifiers = yes
							clear_deposits = yes
						}
					}
				}
				every_country = {
					limit = {
						NOT = { is_same_value = root }
						is_country_type = default
					}
					add_opinion_modifier = {
						modifier = opinion_doomed_us_all
						who = root
					}
					if = {
						limit = {
							NOT = { has_country_flag = end_of_the_cycle_reckoning }
						}
						set_country_flag = end_of_the_cycle_reckoning
						country_event = { id = utopia.3321 }
					}
				}
				create_fleet = {
					name = "NAME_The_End"
					settings = {
						spawn_debris = no
						ai_ignore_strength = yes
						is_boss = yes
					}
					effect = {
						save_global_event_target_as = the_end_of_the_cycle
						set_name = {
							key = "NAME_Absorbed_Species"
							variable_string = "[Root.GetSpeciesNamePlural]"
						}
						set_owner = event_target:shroud_country
						create_ship = {
							name = "NAME_Reckoning"
							design = "NAME_Warped_Consciousness"
						}
						set_location = event_target:former_capital
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = return_point
						set_aggro_range = 3000
						if = {
							limit = {
								root = {
									check_variable = {
										which = "end_power"
										value < 500
									}
								}
							}
							add_modifier = {
								modifier = "absorbed_consciousness_1"
								days = -1
							}
						}
						else_if = {
							limit = {
								root = {
									check_variable = {
										which = "end_power"
										value < 1000
									}
								}
							}
							add_modifier = {
								modifier = "absorbed_consciousness_2"
								days = -1
							}
						}
						else_if = {
							limit = {
								root = {
									check_variable = {
										which = "end_power"
										value < 2500
									}
								}
							}
							add_modifier = {
								modifier = "absorbed_consciousness_3"
								days = -1
							}
						}
						else_if = {
							limit = {
								root = {
									check_variable = {
										which = "end_power"
										value < 5000
									}
								}
							}
							add_modifier = {
								modifier = "absorbed_consciousness_4"
								days = -1
							}
						}
						else = {
							add_modifier = {
								modifier = "absorbed_consciousness_5"
								days = -1
							}
						}
					}
				}
			}

			save_event_target_as = cosmogenesis_empire
			set_country_flag = cosmogenesis_empire_has_won
			make_fallen_empire = yes
			every_playable_country = {
				limit = {
					}
				country_event = { id = crisis.7518 days = 5 }
			}
			if = {
				limit = {
					galaxy_size = tiny
				}
				while = { # Destroy ~10% random stars, for good measure
					count = 18
					random_system = {
						limit = {
							NOR = {
								is_star_class = sc_black_hole
								is_star_class = sc_acot_void_star
								is_star_class = sc_birch
								is_star_class = sc_quasar
								is_sbtg_outer_gate = yes
								AND = {
									exists = owner
									owner = {
										has_technology = tech_acot_dm_psg
									}
								}
								any_system_planet = {
									num_pops > 0
								}
							}
						}
						destroy_star_system = yes
					}
				}
			}
			else_if = {
				limit = {
					galaxy_size = small
				}
				while = { # Destroy ~10% random stars, for good measure
					count = 36
					random_system = {
						limit = {
							NOR = {
								is_star_class = sc_black_hole
								is_star_class = sc_acot_void_star
								is_star_class = sc_birch
								is_star_class = sc_quasar
								is_sbtg_outer_gate = yes
								AND = {
									exists = owner
									owner = {
										has_technology = tech_acot_dm_psg
									}
								}
								any_system_planet = {
									num_pops > 0
								}
							}
						}
						random_list = {
							1 = {
								destroy_star_system = yes
							}
							1 = {
								resonant_system_effect = yes
							}
						}
					}
				}
			}
			else_if = {
				limit = {
					galaxy_size = medium
				}
				while = { # Destroy ~10% random stars, for good measure
					count = 52
					random_system = {
						limit = {
							NOR = {
								is_star_class = sc_black_hole
								is_star_class = sc_acot_void_star
								is_star_class = sc_birch
								is_star_class = sc_quasar
								is_sbtg_outer_gate = yes
								AND = {
									exists = owner
									owner = {
										has_technology = tech_acot_dm_psg
									}
								}
								any_system_planet = {
									num_pops > 0
								}
							}
						}
						random_list = {
							1 = {
								destroy_star_system = yes
							}
							1 = {
								resonant_system_effect = yes
							}
						}
					}
				}
			}
			else_if = {
				limit = {
					galaxy_size = large
				}
				while = { # Destroy ~10% random stars, for good measure
					count = 70
					random_system = {
						limit = {
							NOR = {
								is_star_class = sc_black_hole
								is_star_class = sc_acot_void_star
								is_star_class = sc_birch
								is_star_class = sc_quasar
								any_system_planet = {
									num_pops > 0
								}
							}
						}
						random_list = {
							1 = {
								destroy_star_system = yes
							}
							1 = {
								resonant_system_effect = yes
							}
						}
					}
				}
			}
			else_if = {
				limit = {
					galaxy_size = huge
				}
				while = { # Destroy ~10% random stars, for good measure
					count = 88
					random_system = {
						limit = {
							NOR = {
								is_star_class = sc_black_hole
								is_star_class = sc_acot_void_star
								is_star_class = sc_birch
								is_star_class = sc_quasar
								any_system_planet = {
									num_pops > 0
								}
							}
						}
						random_list = {
							1 = {
								destroy_star_system = yes
							}
							1 = {
								resonant_system_effect = yes
							}
						}
					}
				}
			}
			### HANDLES FRACTURED STUFFS
			# FRACTURED GETS DISTORTED AND MAGICALLY CHANGES CLASS
			every_galaxy_planet = {
				limit = {
					is_planet_class = pc_dark_fractured
					NOT = {
						exists = owner
					}
				}
				random_list = {
					1 = { }
					1 = { change_pc = pc_black_hole }
					1 = { change_pc = pc_barren_cold }
					1 = { change_pc = pc_nuked }
					1 = { remove_planet = yes }
				}
			}
			every_galaxy_planet = {
				limit = {
					is_planet_class = pc_dark_fractured_unstable
					NOT = {
						exists = owner
					}
				}
				random_list = {
					3 = { change_pc = pc_dark_fractured }
					1 = { }
					1 = { change_pc = pc_black_hole }
					1 = { remove_planet = yes }
				}
			}
			every_galaxy_planet = {
				limit = {
					is_planet_class = pc_dark_fractured_ae
					NOT = {
						exists = owner
					}
				}
				random_list = {
					1 = { change_pc = pc_dark_fractured_unstable }
					1 = { }
					1 = { change_pc = pc_dark_fractured }
					1 = { remove_planet = yes }
				}
			}
			every_galaxy_planet = {
				limit = {
					is_planet_class = pc_dark_fractured_ae_unstable
					NOT = {
						exists = owner
					}
				}
				random = { chance = 50 remove_planet = yes }
			}
			date_distortion = yes
			event_target:global_event_country = {
				country_event = { id = crisis.7519 days = 30 }
			}
		}
		win = yes # WIN? WIN? IF ONLY YOU KNEW THE TRUTH... #can confirm that -sparble
	}
}