############################################
# HORIZON SIGNAL - THE WORM-IN-WAITING		#
# Written and designed by Alexis Kennedy	#
# Scripted and edited by Maximilian Olbers #
############################################

namespace = akx

# Designate Horizon Signal system
event = {
	id = akx.8000
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		random_system = {
			limit = {
				is_star_class = sc_black_hole
				is_fe_cluster = no
				NOR = {
					exists = starbase
					has_star_flag = guardian
					has_star_flag = empire_cluster
				}
			}
			set_star_flag = horizonsignal_spawn
		}
	}
}

# debug
fleet_event = {
	id = akx.8888
	title = akx.9000.name
	desc = {
		trigger = {
			text = akx.9000.desc
		}
	}
	picture = GFX_evt_black_hole
	show_sound = event_alien_signal
	location = event_target:horizonsignal_black_hole
	trackable = yes
	is_test_event = yes

	trigger = { always = no }

	immediate = {
		set_global_flag = akx.9000.fired
		solar_system = {
			set_star_flag = horizonsignal_system
			random_system_planet = {
				limit = {
					is_star = yes
				}
				save_global_event_target_as = horizonsignal_black_hole
			}
			save_global_event_target_as = horizonsignal_system
		}
	}

	option = {
		name = OK
		solar_system = {
			random_system_planet = {
				limit = {
					is_star = yes
				}
				enable_special_project = {
					name = HORIZON_SIGNAL_PROJECT
					location = this
					owner = root.owner
				}
			}
		}
	}
}

# triggered by on_entering_system_fleet
# chance to trigger the first time a player enters a black hole system
fleet_event = {
	id = akx.9000
	title = akx.9000.name
	desc = akx.9000.desc
	picture = GFX_evt_black_hole
	show_sound = event_alien_signal
	location = event_target:horizonsignal_black_hole
	trackable = yes

	is_triggered_only = yes

	fire_only_once = yes

	trigger = {
		NOT = { has_global_flag = akx.9000.fired }
		owner = {
			is_ai = no
			NOR = {
				has_ethic = ethic_gestalt_consciousness
				is_nomadic = yes
			}
		}
		from = { # solar system scope
			is_star_class = sc_black_hole
			NOT = { has_star_flag = guardian }
			has_star_flag = horizonsignal_spawn
		}
		exists = leader
		leader = {
			leader_class = scientist
		}
	}

	immediate = {
		set_global_flag = akx.9000.fired
		solar_system = {
			set_star_flag = horizonsignal_system
			random_system_planet = {
				limit = {
					is_star = yes
				}
				save_global_event_target_as = horizonsignal_black_hole
			}
			save_global_event_target_as = horizonsignal_system
		}
		owner = { observer_event = { id = observer.70 } }
	}

	option = {
		name = OK
		from = {
			random_system_planet = {
				limit = {
					is_star = yes
				}
				enable_special_project = {
					name = HORIZON_SIGNAL_PROJECT
					location = this
					owner = root.owner
				}
			}
		}
	}
}

ship_event = {
	id = akx.9001
	title = akx.9001.name
	desc = akx.9001.desc
	picture = GFX_evt_black_hole
	show_sound = event_radio_chatter
	location = this

	is_triggered_only = yes

	immediate = {
		leader = {
			save_event_target_as = horizonsignal_firstleader
		}
	}

	option = {
		name = akx.9001.a
		begin_event_chain = {
			event_chain = WORM_CHAIN_1
			target = root.owner
		}
		hidden_effect = {
			ship_event = { id = akx.9005 }
		}
	}

	option = {
		name = akx.9001.b
		custom_tooltip = akx.9001.b.tooltip
		hidden_effect = { ship_event = { id = akx.9006 } }
	}
}

ship_event = {
	id = akx.9005
	title = akx.9005.name
	desc = akx.9005.desc
	picture = GFX_evt_black_hole
	show_sound = event_activating_unknown_technology
	location = this

	is_triggered_only = yes

	immediate = {
		fleet = {
			set_event_locked = yes
			leader = { save_global_event_target_as = horizonsignal_firstleader }
			exile_leader_as = exiled_horizonsignal_firstleader
		}
	}

	after = {
		owner = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = 36
				min = 600
				max = 3000
			}
			hidden_effect = {
				country_event = { id = akx.9010 days = 320 random = 40 }
			}
		}
		fleet = {
			hidden_effect = { set_event_locked = no }
			delete_fleet = this
		}
	}

	option = {
		name = akx.9005.a.spiritualist
		trigger = {
			owner = {
				is_spiritualist = yes
			}
		}
	}

	option = {
		name = akx.9005.a.materialist
		trigger = {
			owner = {
				is_materialist = yes
			}
		}
	}

	option = {
		name = akx.9005.a.neutral
		trigger = {
			owner = {
				is_spiritualist = no
				is_materialist = no
			}
		}
	}
}

ship_event = {
	id = akx.9006
	title = akx.9006.name
	desc = akx.9006.desc
	picture = GFX_evt_throne_room
	show_sound = event_ship_bridge
	location = this

	is_triggered_only = yes

	after = {
		owner = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = 6
				min = 200
				max = 500
			}
		}
		leader = {
			if = {
				limit = {
					leader_class = scientist
				}
				add_trait = {
					trait = leader_trait_expertise_field_manipulation
				}
			}
			add_trait = {
				trait = leader_trait_substance_abuser
			}
		}
	}

	option = {
		name = akx.9006.a
	}

	option = {
		name = akx.9006.b
	}
}

country_event = {
	id = akx.9010
	title = akx.9010.name
	desc = akx.9010.desc
	picture = GFX_evt_black_hole
	show_sound = event_ship_bridge
	location = event_target:horizonsignal_system

	is_triggered_only = yes

	trigger = {
		any_owned_leader = {
			is_ruler = no
		}
	}

	immediate = {
		random_owned_leader = {
			limit = {
				is_ruler = no
			}
			set_leader_flag = horizonsignal_secondleader
			save_global_event_target_as = horizonsignal_secondleader
		}
	}

	option = {
		name = akx.9010.a.collective
		custom_tooltip = akx.9010.a.tooltip
		trigger = {
			is_authoritarian = yes
		}
		# Update event chain with PoI
		hidden_effect = {
			set_country_flag = secondleader_sent
			event_target:horizonsignal_secondleader = {
				exile_leader_as = exiled_horizonsignal_secondleader
			}
			country_event = { id = akx.9011 days = 30 }
		}
	}

	option = {
		name = akx.9010.a.notcollective
		custom_tooltip = akx.9010.a.tooltip
		trigger = {
			is_authoritarian = no
		}
		# Update event chain with PoI
		hidden_effect = {
			set_country_flag = secondleader_sent
			event_target:horizonsignal_secondleader = {
				exile_leader_as = exiled_horizonsignal_secondleader
			}
			country_event = { id = akx.9011 days = 30 }
		}
	}

	option = {
		name = akx.9010.b.collective
		custom_tooltip = akx.9010.a.tooltip
		trigger = {
			is_authoritarian = yes
		}
		# Update event chain with PoI
		hidden_effect = {
			set_country_flag = secondleader_bomb
			event_target:horizonsignal_secondleader = {
				exile_leader_as = exiled_horizonsignal_secondleader
			}
			country_event = { id = akx.9012 days = 30 }
		}
	}

	option = {
		name = akx.9010.b.notcollective
		custom_tooltip = akx.9010.a.tooltip
		trigger = {
			is_authoritarian = no
		}
		# Update event chain with PoI
		hidden_effect = {
			set_country_flag = secondleader_bomb
			event_target:horizonsignal_secondleader = {
				exile_leader_as = exiled_horizonsignal_secondleader
			}
			country_event = { id = akx.9012 days = 30 }
		}
	}

	option = {
		name = akx.9010.c
		hidden_effect = {
			country_event = { id = akx.9013 }
		}
	}
}


country_event = {
	id = akx.9011
	title = akx.9011.name
	desc = akx.9011.desc
	picture = GFX_evt_black_hole
	show_sound = event_ship_bridge
	location = event_target:horizonsignal_system

	is_triggered_only = yes

	immediate = {

	}

	after = {
		hidden_effect = { country_event = { id = akx.9020 days = 320 random = 40 } }
	}

	option = {
		name = akx.9011.a
	}
	option = {
		name = akx.9011.b
	}
	option = {
		name = akx.9011.c
	}
}

country_event = {
	id = akx.9012
	title = akx.9012.name
	desc = akx.9012.desc
	picture = GFX_evt_debris
	show_sound = event_ship_explosion
	location = event_target:horizonsignal_system
	trackable = yes

	is_triggered_only = yes

	immediate = {
		event_target:horizonsignal_system = {
			create_ambient_object = {
				type = loop_debris_01_object
				location = this
			}
		}
		last_created_ambient_object = {
			save_event_target_as = horizon_debris_object_1
		}
		capital_scope = {
			colony_event = { id = akx.9100 days = 320 random = 40 }
		}
	}

	after = {
		event_target:horizon_debris_object_1 = {
			enable_special_project = {
				name = HORIZON_DEBRIS_PROJECT
				location = this
				owner = root
			}
		}
	}

	option = {
		name = akx.9012.a
	}
}

# Debris research project followup, 10% entropic recursion
ship_event = {
	id = akx.9095
	title = akx.9095.name
	desc = akx.9095.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = root

	is_triggered_only = yes

	immediate = {
		fromfrom = {
			destroy_ambient_object = this
		}
	}

	option = {
		name = OK
		owner = {
			if = {
				limit = {
					has_technology = tech_akx_worm_1
				}
			}
			else = {
				add_tech_progress = {
					tech = tech_akx_worm_1
					progress = 0.1
				}
				if = {
					limit = {
						NOT = {
							has_tech_option = tech_akx_worm_1
						}
					}
					add_research_option = tech_akx_worm_1
				}
			}
		}
	}
}

country_event = {
	id = akx.9013
	title = akx.9013.name
	desc = akx.9013.desc
	picture = GFX_evt_black_hole
	show_sound = event_ship_bridge
	location = root.capital_scope

	is_triggered_only = yes

	after = {
		end_event_chain = WORM_CHAIN_1
		add_monthly_resource_mult = {
			resource = physics_research
			value = 6
			min = 200
			max = 500
		}
		event_target:horizonsignal_secondleader = {
			if = {
				limit = {
					leader_class = scientist
				}
				add_trait = {
					trait = leader_trait_expertise_field_manipulation
				}
			}
			add_trait = {
				trait = leader_trait_substance_abuser
			}
		}
	}

	option = {
		name = akx.9013.a
	}

	option = {
		name = akx.9013.b
	}
}

country_event = {
	id = akx.9020
	title = akx.9020.name
	desc = akx.9020.desc
	picture = GFX_evt_black_hole
	show_sound = event_mystic_reveal
	location = event_target:horizonsignal_black_hole

	is_triggered_only = yes

	immediate = {
		random_owned_leader = {
			limit = { is_ruler = no }
			save_global_event_target_as = horizonsignal_thirdleader
		}
	}

	option = {
		name = akx.9020.a
		custom_tooltip = akx.9020.a.tooltip
		hidden_effect = {
			set_country_flag = thirdleader_sent
			event_target:horizonsignal_thirdleader = {
				exile_leader_as = exiled_horizonsignal_thirdleader
			}
			country_event = { id = akx.9021 days = 30 }
		}
	}

	option = {
		name = akx.9020.b
		custom_tooltip = akx.9020.a.tooltip
		hidden_effect = {
			set_country_flag = thirdleader_bomb
			event_target:horizonsignal_thirdleader = {
				exile_leader_as = exiled_horizonsignal_thirdleader
			}
			country_event = { id = akx.9022 days = 30 }
		}
	}

	option = {
		name = akx.9020.c
		hidden_effect = {
			country_event = { id = akx.9023 }
		}
	}
}

country_event = {
	id = akx.9021
	title = akx.9021.name
	desc = akx.9021.desc
	picture = GFX_evt_black_hole
	show_sound = event_ship_bridge
	location = event_target:horizonsignal_black_hole

	is_triggered_only = yes

	immediate = {
		capital_scope = {
			colony_event = { id = akx.9100 days = 320 random = 40 }
		}
	}

	option = {
		name = akx.9021.a
		if = {
			limit = {
				has_technology = tech_akx_worm_1
			}
		}
		else = {
			add_tech_progress = {
				tech = tech_akx_worm_1
				progress = 0.10
			}
			if = {
				limit = {
					NOT = {
						has_tech_option = tech_akx_worm_1
					}
				}
				add_research_option = tech_akx_worm_1
			}
		}
		# physics bump
		create_fleet = {
			name = "NAME_Foundling"
			settings = { spawn_debris = no }
			effect = {
				set_owner = root
				create_ship_design = {
					design = "NAME_Returned_Science_Ship"
				}
				create_ship = {
					name = NAME_Foundling
					design = last_created_design
					graphical_culture = root
					upgradable = no
				}
				set_location = {
					target = event_target:horizonsignal_black_hole
					distance = 50
				}
				set_fleet_stance = evasive
			}
		}
	}
}

country_event = {
	id = akx.9022
	title = akx.9022.name
	desc = akx.9022.desc
	picture = GFX_evt_debris
	show_sound = event_ship_explosion
	location = event_target:horizonsignal_system
	trackable = yes

	is_triggered_only = yes

	immediate = {
		capital_scope = {
			colony_event = { id = akx.9100 days = 320 random = 40 }
		}
		event_target:horizonsignal_system = {
			create_ambient_object = {
				type = loop_debris_01_object
				location = this
			}
		}
		last_created_ambient_object = {
			set_ambient_object_flag = horizon_debris_2
			save_event_target_as = debris_2
		}
	}

	option = {
		name = akx.9022.a
		event_target:debris_2 = {
			enable_special_project = {
				name = HORIZON_DEBRIS_PROJECT
				location = this
				owner = root
			}
		}
	}
}

country_event = {
	id = akx.9023
	title = akx.9023.name
	desc = akx.9023.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = root.capital_scope

	is_triggered_only = yes

	after = {
		end_event_chain = WORM_CHAIN_1
		add_monthly_resource_mult = {
			resource = physics_research
			value = 6
			min = 200
			max = 500
		}
		event_target:horizonsignal_thirdleader = {
			if = {
				limit = {
					leader_class = scientist
				}
				add_trait = {
					trait = leader_trait_expertise_field_manipulation
				}
			}
			if = {
				limit = {
					NOT = { has_trait_tier1or2 = { TRAIT = leader_trait_substance_abuser } }
				}
				add_trait = {
					trait = leader_trait_substance_abuser
				}
			}
		}
	}

	option = {
		name = akx.9013.b
	}

	option = {
		name = akx.9006.b
	}
}

colony_event = {
	id = akx.9100
	title = akx.9100.name
	desc = akx.9100.desc
	picture = GFX_evt_in_the_dark
	show_sound = event_mystic_reveal
	location = root
	trackable = yes

	is_triggered_only = yes

	after = {
		enable_special_project = {
			name = LOOP_TEMPLE_PROJECT
			location = this
			owner = root.owner
		}
	}

	option = {
		name = akx.9100.spiritual.a
		trigger = {
			owner = {
				is_spiritualist = yes
			}
		}
	}

	option = {
		name = akx.9100.neutral.a
		trigger = {
			owner = {
				is_spiritualist = no
			}
		}
	}

	option = {
		name = akx.9100.b
	}
}

carrier_event = {
	id = akx.9101
	title = akx.9101.name
	desc = akx.9101.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = root

	is_triggered_only = yes

	option = {
		name = akx.9101.a.notspiritual
		custom_tooltip = akx.9101.a.notspiritual.tooltip
		trigger = {
			owner = {
				is_spiritualist = no
			}
		}
		add_modifier = {
			modifier = happy_with_open_loop_temple
			days = -1
		}
		owner = {
			hidden_effect = {
				set_country_flag = worm_events_available
			}
			if = {
				limit = {
					has_technology = tech_akx_worm_2
				}
				break = yes
			}
			if = {
				limit = {
					NOT = {
						has_tech_option = tech_akx_worm_2
					}
				}
				add_research_option = tech_akx_worm_2
			}
			add_tech_progress = {
				tech = tech_akx_worm_2
				progress = 0.20
			}
		}
	}

	option = {
		name = akx.9101.a.spiritual
		custom_tooltip = akx.9101.a.spiritual.tooltip
		trigger = {
			owner = {
				is_spiritualist = yes
			}
		}
		add_modifier = {
			modifier = spiritual_happy_with_open_loop_temple
			days = -1
		}
		owner = {
			hidden_effect = {
				set_country_flag = worm_events_available
			}
			if = {
				limit = {
					has_technology = tech_akx_worm_2
				}
				break = yes
			}
			if = {
				limit = {
					NOT = {
						has_tech_option = tech_akx_worm_2
					}
				}
				add_research_option = tech_akx_worm_2
			}
			add_tech_progress = {
				tech = tech_akx_worm_2
				progress = 0.20
			}
		}
	}

	option = {
		name = akx.9101.b
		custom_tooltip = akx.9101.b.tooltip
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = 4
				min = 300
				max = 2000
			}
			hidden_effect = {
				set_country_flag = worm_events_available
			}
			if = {
				limit = {
					has_technology = tech_akx_worm_2
				}
				break = yes
			}
			if = {
				limit = {
					NOT = {
						has_tech_option = tech_akx_worm_2
					}
				}
				add_research_option = tech_akx_worm_2
			}
			add_tech_progress = {
				tech = tech_akx_worm_2
				progress = 0.20
			}
		}
	}

	option = {
		name = akx.9101.c
		custom_tooltip = akx.9101.c.tooltip
		owner = {
			end_event_chain = WORM_CHAIN_1
			add_monthly_resource_mult = {
				resource = influence
				value = 3
				min = 100
				max = 600
			}
		}
	}
}

# on_entering_system
fleet_event = {
	id = akx.9200
	title = akx.9200.name
	desc = akx.9200.desc
	picture = GFX_evt_space_debris
	show_sound = event_ship_bridge
	location = event_target:horizon_pod
	trackable = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
			has_country_flag = worm_events_available
			NOT = { has_country_flag = messenger_pod_found }
		}
		from = {
			NOR = {
				has_star_flag = guardian
				has_star_flag = hostile_system
			}
		}
	}

	immediate = {
		owner = { set_country_flag = messenger_pod_found }
		create_ambient_object = {
			type = loop_debris_02_object
			location = from
		}
		last_created_ambient_object = {
			save_event_target_as = horizon_pod
		}
	}

	option = {
		name = INTERESTING
		event_target:horizon_pod = {
			enable_special_project = {
				name = MESSENGER_POD_PROJECT_1
				location = this
				owner = root.owner
			}
		}
	}
}

country_event = {
	id = akx.9201
	title = akx.9201.name
	desc = akx.9201.desc
	picture = GFX_evt_throne_room
	location = root
	trackable = yes

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				any_owned_leader = {
					is_head_of_research = yes
					is_same_species = root
				}
			}
			random_owned_leader = {
				limit = {
					is_head_of_research = yes
					is_same_species = root
				}
				save_global_event_target_as = researchingscientist
			}
		}
		else = {
			random_owned_leader = {
				limit = {
					leader_class = scientist
				}
				save_global_event_target_as = researchingscientist
			}
		}
	}

	option = {
		name = akx.9201.militarist.a
		#custom_tooltip = 9201.militarist.a.tooltip
		trigger = {
			is_militarist = yes
		}
		capital_scope = {
			enable_special_project = {
				name = MESSENGER_POD_PROJECT_2_UNLEASHED
				location = this
				owner = root
			}
		}
		if = {
			limit = {
				has_technology = tech_genome_mapping
			}
		}
		else = {
			add_tech_progress = {
				tech = tech_genome_mapping
				progress = 0.15
			}
			if = {
				limit = {
					NOT = { has_tech_option = tech_genome_mapping }
				}
				add_research_option = tech_genome_mapping
			}
		}
	}

	option = {
		name = akx.9201.notmilitarist.b
		capital_scope = {
			enable_special_project = {
				name = MESSENGER_POD_PROJECT_2_LEASHED
				location = this
				owner = root
			}
		}
		if = {
			limit = {
				has_technology = tech_genome_mapping
			}
			break = yes
		}
		if = {
			limit = {
				NOT = { has_tech_option = tech_genome_mapping }
			}
			add_research_option = tech_genome_mapping
		}
		add_tech_progress = {
			tech = tech_genome_mapping
			progress = 0.15
		}
	}

	option = {
		name = akx.9201.c
		custom_tooltip = akx.9201.c.tooltip
		if = {
			limit = {
				has_technology = tech_genome_mapping
			}
			break = yes
		}
		if = {
			limit = {
				NOT = { has_tech_option = tech_genome_mapping }
			}
			add_research_option = tech_genome_mapping
		}
		add_tech_progress = {
			tech = tech_genome_mapping
			progress = 0.30
		}
	}
}

country_event = {
	id = akx.9210
	title = akx.9210.name
	desc = akx.9210.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = capital_scope

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { exists = event_target:researchingscientist }
			# nothing
		}
		else = {
			random_owned_leader = {
				limit = { leader_class = scientist }
				save_global_event_target_as = researchingscientist
			}
		}
		event_target:researchingscientist = {
			make_unleashed_messenger = yes
		}
	}

	option = {
		name = akx.9210.a
		event_target:researchingscientist = {
			kill_leader = { show_notification = no }
		}
		if = {
			limit = {
				has_technology = tech_akx_worm_2
			}
			break = yes
		}
		if = {
			limit = {
				NOT = {
					has_tech_option = tech_akx_worm_2
				}
			}
			add_research_option = tech_akx_worm_2
		}
		add_tech_progress = {
			tech = tech_akx_worm_2
			progress = 0.20
		}
	}

	option = {
		name = akx.9210.b
		event_target:researchingscientist = {
			kill_leader = { show_notification = no }
		}
	}

	option = {
		name = akx.9210.c
		custom_tooltip = akx.9220.c.tooltip
		hidden_effect = { country_event = { id = akx.9211 days = 320 random = 40 } }
		if = {
			limit = {
				has_technology = tech_akx_worm_2
			}
			break = yes
		}
		if = {
			limit = {
				NOT = {
					has_tech_option = tech_akx_worm_2
				}
			}
			add_research_option = tech_akx_worm_2
		}
		add_tech_progress = {
			tech = tech_akx_worm_2
			progress = 0.20
		}
	}
}

country_event = {
	id = akx.9211
	title = akx.9211.name
	desc = akx.9211.desc
	picture = GFX_evt_genetic_modification
	location = capital_scope

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { exists = event_target:researchingscientist }
			# nothing
		}
		else = {
			random_owned_leader = {
				limit = { leader_class = scientist }
				save_global_event_target_as = researchingscientist
			}
			event_target:researchingscientist = {
				make_unleashed_messenger = yes
			}
		}
	}

	option = {
		name = akx.9211.a
		custom_tooltip = akx.9211.a.tooltip
		hidden_effect = {
			capital_scope = {
				every_owned_pop_group = {
					limit = {
						is_same_species = root
						has_any_ethic = yes
					}
					make_intelligent = yes
					make_unleashed_messenger = yes
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_pacifist
						PERCENTAGE = 1 # 100%
						RANDOM = 0
					}
					set_timed_pop_group_flag = { flag = changed_pop days = 2 }
				}
				weighted_random_owned_pop_group = {
					limit = { has_pop_group_flag = changed_pop }
					root = { change_dominant_species = { species = prev } }
				}
			}
		}
	}

	option = {
		name = akx.9211.b
		custom_tooltip = akx.9211.b.tooltip
		trigger = {
			is_authoritarian = yes
		}
		hidden_effect = {
			capital_scope = {
				while = {
					limit = {
						count_owned_pop_amount = {
							limit = { is_same_species = root }
							count >= 200
						}
					}
					random_owned_pop_group = {
						kill_single_pop = yes
					}
				}
			}
		}
	}

	option = {
		name = akx.9211.c
		custom_tooltip = akx.9211.c.tooltip
		hidden_effect = {
			every_owned_leader = {
				limit = { is_same_species = root }
				make_unleashed_messenger = yes
			}
			every_owned_pop_group = {
				limit = {
					is_same_species = root
					has_any_ethic = yes
				}
				make_unleashed_messenger = yes
				make_intelligent = yes
				pop_group_add_ethic_effect = {
					POP_GROUP = this
					ETHOS = ethic_pacifist
					PERCENTAGE = 1 # 100%
					RANDOM = 0
				}
				set_timed_pop_group_flag = { flag = changed_pop days = 2 }
			}
			weighted_random_owned_pop_group = {
				limit = { has_pop_group_flag = changed_pop }
				root = { change_dominant_species = { species = prev } }
			}
		}
	}
}

country_event = {
	id = akx.9220
	title = akx.9220.name
	desc = akx.9220.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = capital_scope

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { exists = event_target:researchingscientist }
			event_target:researchingscientist = {
				save_global_event_target_as = researchingscientist9220
			}
		}
		else = {
			random_owned_leader = {
				limit = { leader_class = scientist }
				save_global_event_target_as = researchingscientist9220
			}
		}
		event_target:researchingscientist9220 = {
			make_leashed_messenger = yes
		}
	}

	option = {
		name = akx.9220.a
		event_target:researchingscientist9220 = {
			kill_leader = { show_notification = no }
		}
		if = {
			limit = {
				has_technology = tech_akx_worm_2
			}
			break = yes
		}
		if = {
			limit = {
				NOT = {
					has_tech_option = tech_akx_worm_2
				}
			}
			add_research_option = tech_akx_worm_2
		}
		add_tech_progress = {
			tech = tech_akx_worm_2
			progress = 0.20
		}
	}

	option = {
		name = akx.9220.b
		event_target:researchingscientist9220 = {
			kill_leader = { show_notification = no }
		}
	}

	option = {
		name = akx.9220.c
		custom_tooltip = akx.9220.c.tooltip
		hidden_effect = { country_event = { id = akx.9221 days = 320 random = 40 } }
		if = {
			limit = {
				has_technology = tech_akx_worm_2
			}
			break = yes
		}
		if = {
			limit = {
				NOT = {
					has_tech_option = tech_akx_worm_2
				}
			}
			add_research_option = tech_akx_worm_2
		}
		add_tech_progress = {
			tech = tech_akx_worm_2
			progress = 0.20
		}
	}
}

country_event = {
	id = akx.9221
	title = akx.9221.name
	desc = akx.9221.desc
	picture = GFX_evt_genetic_modification
	location = capital_scope

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { exists = event_target:researchingscientist9220 }
		}
		else = {
			random_owned_leader = {
				limit = { leader_class = scientist }
				save_global_event_target_as = researchingscientist9220
			}
			event_target:researchingscientist9220 = {
				make_leashed_messenger = yes
			}
		}
	}

	option = {
		name = akx.9221.a
		custom_tooltip = akx.9221.a.tooltip
		hidden_effect = {
			capital_scope = {
				every_owned_pop_group = {
					limit = {
						is_same_species = root
						has_any_ethic = yes
					}
					make_resilient = yes
					make_leashed_messenger = yes
					pop_group_add_ethic_effect = {
						POP_GROUP = this
						ETHOS = ethic_militarist
						PERCENTAGE = 1 # 100%
						RANDOM = 0
					}
					set_timed_pop_group_flag = { flag = changed_pop days = 2 }
				}
				weighted_random_owned_pop_group = {
					limit = { has_pop_group_flag = changed_pop }
					root = { change_dominant_species = { species = prev } }
				}
			}
		}
	}

	option = {
		name = akx.9221.b
		custom_tooltip = akx.9221.b.tooltip
		trigger = {
			is_authoritarian = yes
		}
		hidden_effect = {
			capital_scope = {
				while = {
					limit = {
						count_owned_pop_amount = {
							limit = { is_same_species = root }
							count >= 200
						}
					}
					random_owned_pop_group = {
						kill_single_pop = yes
					}
				}
			}
		}
	}

	option = {
		name = akx.9221.c
		custom_tooltip = akx.9221.c.tooltip
		hidden_effect = {
			every_owned_leader = {
				limit = { is_same_species = root }
				make_leashed_messenger = yes
			}
			every_owned_pop_group = {
				limit = {
					is_same_species = root
					has_any_ethic = yes
				}
				make_leashed_messenger = yes
				make_resilient = yes
				pop_group_add_ethic_effect = {
					POP_GROUP = this
					ETHOS = ethic_militarist
					PERCENTAGE = 1 # 100%
					RANDOM = 0
				}
				set_timed_pop_group_flag = { flag = changed_pop days = 2 }
			}
			weighted_random_owned_pop_group = {
				limit = { has_pop_group_flag = changed_pop }
				root = { change_dominant_species = { species = prev } }
			}
		}
	}
}

# on fleet entering system
fleet_event = {
	id = akx.9300
	title = akx.9300.name
	desc = akx.9300.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = root

	is_triggered_only = yes

	trigger = {
		owner = {
			has_country_flag = worm_events_available
			NOT = { has_country_flag = syzygy_encountered }
			any_owned_leader = {
				leader_class = commander
			}
		}
	}

	immediate = {
		from = { save_global_event_target_as = syzygy_system }
		owner = {
			random_owned_leader = {
				limit = {
					leader_class = commander
				}
				save_global_event_target_as = mirrored_syzygy_admiral
			}
			set_country_flag = syzygy_encountered
		}
	}

	option = {
		name = akx.9300.a.admiralabsent
		custom_tooltip = akx.9300.a.admiralabsent.tooltip
		trigger = {
			OR = {
				NOT = { exists = leader }
				NOT = {
					leader = {
						is_same_value = event_target:mirrored_syzygy_admiral
					}
				}
			}
		}
		hidden_effect = {
			owner = { country_event = { id = akx.9310 } }
		}
	}

	option = {
		name = akx.9300.a.admiralpresent
		custom_tooltip = akx.9300.a.admiralabsent.tooltip
		trigger = {
			exists = leader
			leader = {
				is_same_value = event_target:mirrored_syzygy_admiral
			}
		}
		hidden_effect = {
			owner = { country_event = { id = akx.9310 } }
		}
	}

	option = {
		name = akx.9300.b
		hidden_effect = {
			owner = { country_event = { id = akx.9315 } }
		}
	}
}

country_event = {
	id = akx.9310
	title = akx.9310.name
	desc = akx.9310.desc
	diplomatic = yes

	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:mirrored_syzygy_admiral
		room = ethic_spaceship_room
	}

	option = {
		name = akx.9310.a
		#custom_tooltip = akx.9310.a.tooltip
		is_dialog_only = yes
		response_text = akx.9310.a.response
		if = {
			limit = {
				NOT = {
					has_country_flag = akx.9310.a.flag
				}
			}
			add_monthly_resource_mult = {
				resource = physics_research
				value = 6
				min = 150
				max = 800
			}
			hidden_effect = {
				set_country_flag = akx.9310.a.flag
				if = {
					limit = {
						NOT = {
							has_country_flag = worm_rendezvous_first_response_complete
						}
					}
					set_country_flag = worm_rendezvous_first_response_complete
				}
			}
		}
	}

	option = {
		name = akx.9310.b
		#custom_tooltip = akx.9310.b.tooltip
		is_dialog_only = yes
		response_text = akx.9310.b.response
		if = {
			limit = {
				NOT = {
					has_country_flag = akx.9310.b.flag
				}
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = 6
				min = 150
				max = 800
			}
			hidden_effect = {
				set_country_flag = akx.9310.b.flag
				if = {
					limit = {
						NOT = {
							has_country_flag = worm_rendezvous_first_response_complete
						}
					}
					set_country_flag = worm_rendezvous_first_response_complete
				}
			}
		}
	}

	option = {
		name = akx.9310.c
		is_dialog_only = yes
		response_text = akx.9310.c.response
		if = {
			limit = {
				NOT = {
					has_country_flag = akx.9310.c.flag
				}
			}
			add_monthly_resource_mult = {
				resource = physics_research
				value = 6
				min = 150
				max = 800
			}
			hidden_effect = {
				set_country_flag = akx.9310.c.flag
				if = {
					limit = {
						NOT = {
							has_country_flag = worm_rendezvous_second_response_complete
						}
					}
					set_country_flag = worm_rendezvous_second_response_complete
				}
			}
		}
	}

	option = {
		name = akx.9310.d.notpacifist
		#is_dialog_only = yes
		response_text = akx.9310.d.notpacifist.response
		trigger = {
			is_pacifist = no
		}
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = worm_rendezvous_second_response_complete
					}
				}
				set_country_flag = worm_rendezvous_second_response_complete
			}
			country_event = { id = akx.9315 }
		}
	}

	option = {
		name = akx.9310.d.fanaticpacifist
		#custom_tooltip = akx.9310.d.fanaticpacifist.tooltip
		#is_dialog_only = yes
		response_text = akx.9310.d.fanaticpacifist.response
		trigger = {
			is_fanatic_pacifist = yes
		}
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = worm_rendezvous_second_response_complete
					}
				}
				set_country_flag = worm_rendezvous_second_response_complete
			}
			create_fleet = {
				name = "NAME_Reclaimed_Ship"
				settings = { spawn_debris = no }
				effect = {
					set_owner = root
					create_ship_design = {
						design = NAME_Corsair
					}
					create_ship = {
						design = last_created_design
						graphical_culture = pirate_01
						name = NAME_Syzygy
						upgradable = no
					}
				}
			}
		}
	}

	option = {
		name = akx.9310.e
		response_text = akx.9310.e.response
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = worm_rendezvous_second_response_complete
					}
				}
				set_country_flag = worm_rendezvous_second_response_complete
			}
			country_event = { id = akx.9315 }
		}
	}

	option = {
		name = akx.9310.e.materialistic
		response_text = akx.9310.e.materialistic.response
		trigger = {
			is_materialist = yes
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = 6
			min = 150
			max = 800
		}
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = worm_rendezvous_second_response_complete
					}
				}
				set_country_flag = worm_rendezvous_second_response_complete
			}
			country_event = { id = akx.9315 }
		}
	}

	option = {
		name = akx.9310.e.spiritual
		response_text = akx.9310.e.spiritual.response
		trigger = {
			is_spiritualist = yes
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = 6
			min = 150
			max = 800
		}
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = worm_rendezvous_second_response_complete
					}
				}
				set_country_flag = worm_rendezvous_second_response_complete
			}
			country_event = { id = akx.9315 }
		}
	}

	option = {
		name = akx.9310.e.militarist
		response_text = akx.9310.e.militarist.response
		trigger = {
			is_militarist = yes
		}
		add_monthly_resource_mult = {
			resource = influence
			value = 6
			min = 150
			max = 300
		}
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = worm_rendezvous_second_response_complete
					}
				}
				set_country_flag = worm_rendezvous_second_response_complete
			}
			country_event = { id = akx.9315 }
		}
	}

	option = {
		name = akx.9310.e
		#response_text = akx.9310.e.fanaticauthoritarian.response
		trigger = {
			is_fanatic_authoritarian = yes
		}
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = worm_rendezvous_second_response_complete
					}
				}
				set_country_flag = worm_rendezvous_second_response_complete
			}
			country_event = { id = akx.9312 }
		}
	}

	option = {
		name = akx.9310.f
		custom_tooltip = akx.9310.f.tooltip
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = worm_rendezvous_second_response_complete
					}
				}
				set_country_flag = worm_rendezvous_second_response_complete
			}
			country_event = { id = akx.9315 }
		}
	}
}

country_event = {
	id = akx.9312
	title = akx.9310.name
	desc = akx.9310.e.response

	is_triggered_only = yes

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:mirrored_syzygy_admiral
		room = ethic_spaceship_room
	}

	option = {
		name = DOTDOTDOT
		hidden_effect = {
			country_event = { id = akx.9315 }
		}
	}
}

country_event = {
	id = akx.9315
	title = akx.9315.name
	desc = akx.9315.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = event_target:syzygy_system

	is_triggered_only = yes

	immediate = {
		event_target:syzygy_system = {
			random_system_planet = {
				limit = { is_star = yes }
				save_event_target_as = syzygy_spawn_location
			}
		}
		create_country = {
			name = "NAME_Looped_Syzygy"
			type = faction
			auto_delete = no
			flag = {
				icon= {
					category = "special"
					file = "extradimensional_02.dds"
				}
				background= {
					category = "backgrounds"
					file = "circle.dds"
				}
				colors={
					"black"
					"red"
					"null"
					"null"
				}
			}
			effect = {
				set_country_flag = syzygy_country
				establish_communications_no_message = root
				create_fleet = {
					name = "NAME_Looped_Syzygy"
					settings = { spawn_debris = no }
					effect = {
						set_owner = prev
						create_ship = {
							name = "NAME_Syzygy"
							design = NAME_Corsair
							graphical_culture = pirate_01
							prefix = no
						}
						set_location = {
							target = event_target:syzygy_spawn_location
							distance = 50
						}
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 20
					}
				}
				set_faction_hostility = { target = root set_hostile = yes }
			}
		}
	}

	option = {
		name = BATTLESTATIONS
	}
}

#on_fleet_destroyed_perp
country_event = {
	id = akx.9318
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		#has_country_flag = worm_events_available
		from = {
			has_country_flag = syzygy_country
		}
	}

	immediate = {
		if = {
			limit = {
				has_country_flag = worm_events_available
				exists = event_target:mirrored_syzygy_admiral
				fromfrom = {
					OR = {
						NOT = { exists = leader }
						AND = {
							exists = leader
							leader = { NOT = { is_same_value = event_target:mirrored_syzygy_admiral } }
						}
					}
				}
			}
			country_event = { id = akx.9321 }
		}
		else_if = {
			limit = {
				has_country_flag = worm_events_available
				exists = event_target:mirrored_syzygy_admiral
				fromfrom = {
					exists = leader
					leader = {
						is_same_value = event_target:mirrored_syzygy_admiral
					}
				}
			}
			country_event = { id = akx.9320 }
		}
		else = {
			random_country = {
				limit = {
					has_country_flag = worm_events_available
				}
				root.fromfrom.solar_system = {
					random_system_planet = {
						limit = { is_star = no }
						save_event_target_as = syzygy_location
					}
				}
				country_event = { id = akx.9319 }
			}
		}
		from = { destroy_country = yes }
	}
}

country_event = {
	id = akx.9319
	title = akx.9319.name
	desc = akx.9319.desc
	picture = GFX_evt_debris
	location = event_target:syzygy_location
	trackable = yes

	is_triggered_only = yes

	immediate = {
		event_target:syzygy_location = {
			create_ambient_object = {
				type = "NAME_Syzygy_Remains"
				location = this
			}
		}
		last_created_ambient_object = {
			save_event_target_as = syzygy_debris_01
		}
	}

	after = {
		event_target:syzygy_debris_01 = {
			enable_special_project = {
				name = SYZYGY_DEBRIS_PROJECT
				location = this
				owner = root
			}
		}
	}

	option = {
		name = OK
	}
}

country_event = {
	id = akx.9320
	title = akx.9320.name
	desc = akx.9320.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = fromfromfrom

	is_triggered_only = yes

	option = {
		name = OK
		event_target:mirrored_syzygy_admiral = {
			add_trait = {
				trait = leader_trait_foredoomed_to_a_rendezvous
			}
			add_experience = 900
		}
	}
}

country_event = {
	id = akx.9321
	title = akx.9321.name
	desc = akx.9321.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = fromfromfrom

	is_triggered_only = yes

	after = {
		event_target:mirrored_syzygy_admiral = {
			add_trait = {
				trait = leader_trait_foredoomed_to_a_rendezvous
			}
		}
	}

	option = {
		name = akx.9321.a
	}
	option = {
		name = akx.9321.b
	}
}

# on leader death
country_event = {
	id = akx.9330
	title = akx.9330.name
	desc = akx.9330.desc
	picture = GFX_evt_star_chart

	is_triggered_only = yes

	trigger = {
		has_country_flag = worm_events_available
		from = {
			has_trait = leader_trait_foredoomed_to_a_rendezvous
		}
	}

	option = {
		name = akx.9330.a
	}
	option = {
		name = akx.9330.b
	}
}

# syzygy debris project followup
ship_event = {
	id = akx.9340
	title = akx.9340.name
	desc = akx.9340.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge

	is_triggered_only = yes

	option = {
		name = OK
		owner = {
			if = {
				limit = {
					NOT = { has_technology = tech_akx_worm_1 }
				}
				if = {
					limit = {
						NOT = { has_tech_option = tech_akx_worm_1 }
					}
					add_research_option = tech_akx_worm_1
				}
				add_tech_progress = {
					tech = tech_akx_worm_1
					progress = 0.20
				}
			}
		}
	}
}

# observation missions
carrier_event = {
	id = akx.9399
	hide_window = yes

	pre_triggers = {
		has_owner = yes
	}

	trigger = {
		has_observation_outpost = yes
		owner = {
			is_country_type = primitive
			OR = {
				has_country_flag = renaissance_age
				has_country_flag = steam_age
				has_country_flag = industrial_age
				has_country_flag = machine_age
				has_country_flag = atomic_age
				has_country_flag = early_space_age
			}
		}
		observation_outpost_owner = {
			is_ai = no
			has_country_flag = worm_events_available
			NOT = { has_country_flag = coils_of_god }
		}
	}

	mean_time_to_happen = {
		months = 600
	}

	immediate = {
		save_global_event_target_as = coils_planet
		observation_outpost_owner = {
			set_country_flag = coils_of_god
			country_event = { id = akx.9400 }
		}
	}
}


# observation missions
country_event = {
	id = akx.9400
	title = akx.9400.name
	desc = akx.9400.desc
	picture = GFX_evt_medieval_alien_civilization
	show_sound = event_ship_bridge
	location = from

	is_triggered_only = yes

	option = {
		name = akx.9400.a
		hidden_effect = {
			random_list = {
				75 = { country_event = { id = akx.9410 days = 360 } }
				25 = { country_event = { id = akx.9420 days = 360 } }
			}
		}
	}

	option = {
		name = akx.9400.b
		add_monthly_resource_mult = {
			resource = society_research
			value = 6
			min = 100
			max = 600
		}
		hidden_effect = { country_event = { id = akx.9450 days = 360 } }
	}
}

country_event = {
	id = akx.9410
	title = akx.9410.name
	desc = akx.9410.desc
	picture = GFX_evt_medieval_alien_civilization
	show_sound = event_ship_bridge
	location = event_target:coils_planet

	is_triggered_only = yes

	trigger = {
		event_target:coils_planet = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
	}

	option = {
		name = OK
	}
}

country_event = {
	id = akx.9420
	title = akx.9420.name
	desc = akx.9420.desc
	picture = GFX_evt_medieval_alien_civilization
	show_sound = event_ship_bridge
	location = event_target:coils_planet

	is_triggered_only = yes

	trigger = {
		event_target:coils_planet = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
	}

	option = {
		name = OK
		hidden_effect = {
			country_event = { id = akx.9450 days = 320 random = 40 }
		}
	}
}

country_event = {
	id = akx.9450
	title = akx.9450.name
	desc = akx.9450.desc
	picture = GFX_evt_medieval_alien_civilization
	location = event_target:coils_planet
	trackable = yes

	is_triggered_only = yes

	trigger = {
		event_target:coils_planet = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
	}

	option = {
		name = akx.9450.a
		#custom_tooltip = akx.9450.a.tooltip
		event_target:coils_planet = {
			enable_special_project = {
				name = COILS_GOD_PROJECT_DISRUPT
				location = this
				owner = root
			}
		}
	}

	option = {
		name = akx.9450.b
		#custom_tooltip = akx.9450.b.tooltip
		event_target:coils_planet = {
			enable_special_project = {
				name = COILS_GOD_PROJECT_PREVENT
				location = this
				owner = root
			}
		}
	}

	option = {
		name = akx.9450.c
		#custom_tooltip = akx.9450.c.tooltip
		event_target:coils_planet = {
			enable_special_project = {
				name = COILS_GOD_PROJECT_PARTICIPATE
				location = this
				owner = root
			}
		}
	}

	option = {
		name = akx.9450.d
		#custom_tooltip = akx.9450.d.tooltip
		hidden_effect = { country_event = { id = akx.9490 days = 360 } }
	}
}

country_event = {
	id = akx.9460
	title = akx.9460.name
	desc = akx.9460.desc
	picture = GFX_evt_medieval_alien_civilization
	location = event_target:coils_planet

	is_triggered_only = yes

	trigger = {
		event_target:coils_planet = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
	}

	immediate = {
		set_country_flag = coils_god_halted
	}

	after = {
		if = {
			limit = {
				has_technology = tech_akx_worm_2
			}
		}
		else = {
			add_tech_progress = {
				tech = tech_akx_worm_2
				progress = 0.1
			}
			if = {
				limit = {
					NOT = {
						has_tech_option = tech_akx_worm_2
					}
				}
				add_research_option = tech_akx_worm_2
			}
		}
	}

	option = {
		name = akx.9460.a
	}
	option = {
		name = akx.9460.b
	}
}

country_event = {
	id = akx.9465
	title = akx.9465.name
	desc = akx.9465.desc
	picture = GFX_evt_medieval_alien_civilization
	location = event_target:coils_planet

	is_triggered_only = yes

	trigger = {
		event_target:coils_planet = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
	}

	after = {
		if = {
			limit = {
				has_technology = tech_akx_worm_2
			}
		}
		else = {
			add_tech_progress = {
				tech = tech_akx_worm_2
				progress = 0.1
			}
			if = {
				limit = {
					NOT = {
						has_tech_option = tech_akx_worm_2
					}
				}
				add_research_option = tech_akx_worm_2
			}
		}
	}

	option = {
		name = akx.9465.a
	}

	option = {
		name = akx.9465.b
	}
}

country_event = {
	id = akx.9470
	title = akx.9470.name
	desc = akx.9470.desc
	picture = GFX_evt_medieval_alien_civilization
	location = event_target:coils_planet

	is_triggered_only = yes

	trigger = {
		event_target:coils_planet = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
	}

	immediate = {
		set_country_flag = coils_god_halted
	}

	after = {
		event_target:coils_planet = {
			observation_outpost = {
				if = {
					limit = {
						mission_progress > 0.1
					}
					add_mission_progress = -0.5
				}
			}
		}
		if = {
			limit = {
				has_technology = tech_akx_worm_2
			}
			break = yes
		}
		else = {
			add_tech_progress = {
				tech = tech_akx_worm_2
				progress = 0.1
			}
			if = {
				limit = {
					NOT = {
						has_tech_option = tech_akx_worm_2
					}
				}
				add_research_option = tech_akx_worm_2
			}
		}
	}

	option = {
		name = akx.9470.a
	}

	option = {
		name = akx.9470.b
	}
}

country_event = {
	id = akx.9480
	title = akx.9480.name
	desc = akx.9480.desc
	picture = GFX_evt_medieval_alien_civilization
	location = event_target:coils_planet

	is_triggered_only = yes

	trigger = {
		event_target:coils_planet = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
	}

	immediate = {
		fromfrom = {
			save_event_target_as = coils_planet
			every_owned_pop_group = {
				limit = {
					owner = {
						is_same_value = event_target:coils_planet.owner
					}
				}
				kill_all_pop = yes
			}
			observation_outpost = {
				dismantle = yes
			}
			owner = {
				destroy_country = yes
			}
		}
		from = {
			leader = {
				kill_leader = { class = scientist show_notification = no }
			}
			fleet = {
				delete_fleet = this
			}
		}
	}

	after = {
		if = {
			limit = {
				has_technology = tech_akx_worm_2
			}
		}
		else = {
			add_tech_progress = {
				tech = tech_akx_worm_2
				progress = 0.3
			}
			if = {
				limit = {
					NOT = {
						has_tech_option = tech_akx_worm_2
					}
				}
				add_research_option = tech_akx_worm_2
			}
		}
	}

	option = {
		name = akx.9480.a
		custom_tooltip = akx.9480.a.tooltip
	}

	option = {
		name = akx.9480.b
		custom_tooltip = akx.9480.a.tooltip
	}
}


country_event = {
	id = akx.9490
	title = akx.9490.name
	desc = akx.9490.desc
	picture = GFX_evt_medieval_alien_civilization
	location = event_target:coils_planet

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = coils_god_halted
		}
		event_target:coils_planet = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
	}

	after = {
		add_monthly_resource_mult = {
			resource = society_research
			value = 12
			min = 600
			max = 3000
		}
		hidden_effect = {
			event_target:coils_planet = {
				every_owned_pop_group = {
					limit = {
						owner = {
							is_same_value = event_target:coils_planet.owner
						}
					}
					kill_all_pop = yes
				}
				observation_outpost = {
					dismantle = yes
				}
				owner = {
					destroy_country = yes
				}
			}
		}
	}

	option = {
		name = akx.9490.a
		custom_tooltip = akx.9490.a.tooltip
	}

	option = {
		name = akx.9490.b
		custom_tooltip = akx.9490.a.tooltip
	}
}

# on colonized
carrier_event = {
	id = akx.9499
	hide_window = yes

	is_triggered_only = yes

	pre_triggers = {
		has_owner = yes
	}

	trigger = {
		NOR = {
			is_planet_class = pc_habitat
			is_planet_class = pc_ringworld_habitable
			is_planet_class = pc_shattered_ring_habitable
			is_planet_class = pc_city
			is_planet_class = pc_relic
		}
		owner = {
			has_country_flag = worm_events_available
			NOT = {
				has_country_flag = waiting_world
			}
		}
	}

	immediate = {
		owner = {
			set_country_flag = waiting_world
		}
		carrier_event = { id = akx.9500 days = 30 }
	}
}

carrier_event = {
	id = akx.9500
	title = akx.9500.name
	desc = akx.9500.desc
	picture = GFX_evt_colony_settlement
	location = root

	is_triggered_only = yes

	immediate = {
		save_global_event_target_as = waiting_world
		add_deposit = d_mothballed_facilities
	}

	option = {
		name = akx.9500.a
		allow = {
			owner = {
				resource_stockpile_compare = { resource = minerals value >= 100 }
			}
		}
		owner = { add_resource = { minerals = -100 } }
		random_deposit = {
			limit = { is_deposit_type = d_mothballed_facilities }
			clear_blocker = yes
		}
		hidden_effect = {
			carrier_event = { id = akx.9510 days = 360 }
		}
	}

	option = {
		name = akx.9500.b
		custom_tooltip = akx.9500.b.tooltip
		hidden_effect = {
			remove_deposit = d_mothballed_facilities
			carrier_event = { id = akx.9505 }
		}
	}
}

carrier_event = {
	id = akx.9505
	title = akx.9505.name
	desc = akx.9505.desc
	picture = GFX_evt_colony_settlement
	location = root

	is_triggered_only = yes

	immediate = {
	}

	after = {
		tooltip = { remove_deposit = d_mothballed_facilities }
		add_modifier = {
			modifier = waiting_world_ruins
			days = -1
		}
	}

	option = {
		name = akx.9505.a
		custom_tooltip = akx.9505.a.tooltip
	}
	option = {
		name = akx.9505.b
		custom_tooltip = akx.9505.a.tooltip
	}
	option = {
		name = akx.9505.c
		custom_tooltip = akx.9505.a.tooltip
	}
}

carrier_event = {
	id = akx.9510
	title = akx.9510.name
	desc = akx.9510.desc
	picture = GFX_evt_colony_settlement
	location = root

	is_triggered_only = yes

	option = {
		name = akx.9510.a
		hidden_effect = {
			carrier_event = { id = akx.9520 days = 360 }
		}
	}

	option = {
		name = akx.9510.b
		custom_tooltip = akx.9510.b.tooltip
		hidden_effect = {
			carrier_event = { id = akx.9505 }
		}
	}
}

carrier_event = {
	id = akx.9520
	title = akx.9520.name
	desc = akx.9520.desc
	picture = GFX_evt_colony_settlement
	location = root

	is_triggered_only = yes

	trigger = {
		#free_housing > 0
	}

	immediate = {
		weighted_random_owned_pop_group = {
			limit = {
				exists = planet
				planet = { is_same_value = root }
			}
			save_event_target_as = waiting_world_species
		}
		while = {
			count = 3
			create_pop_group = {
				species = event_target:waiting_world_species
			}
		}
	}

	option = {
		name = akx.9520.a
		custom_tooltip = akx.9510.b.tooltip
		hidden_effect = {
			carrier_event = { id = akx.9505 }
		}
	}

	option = {
		name = akx.9520.b
		hidden_effect = {
			carrier_event = { id = akx.9525 days = 360 }
		}
	}
}

carrier_event = {
	id = akx.9525
	title = akx.9525.name
	desc = akx.9525.desc
	picture = GFX_evt_colony_settlement
	location = root

	is_triggered_only = yes

	trigger = {
		#free_housing > 0
	}

	immediate = {
		weighted_random_owned_pop_group = {
			limit = {
				exists = planet
				planet = { is_same_value = root }
			}
			save_event_target_as = waiting_world_species
		}
		while = {
			count = 5
			create_pop_group = {
				species = event_target:waiting_world_species
			}
		}
	}

	option = {
		name = akx.9525.a
		hidden_effect = {
			carrier_event = { id = akx.9505 }
		}
	}

	option = {
		name = akx.9525.b
		hidden_effect = {
			random_list = {
				25 = { carrier_event = { id = akx.9530 days = 360 } }
				75 = { carrier_event = { id = akx.9540 days = 360 } }
			}
		}
	}
}

carrier_event = {
	id = akx.9530
	title = akx.9530.name
	desc = akx.9530.desc
	picture = GFX_evt_colony_settlement
	location = root
	trackable = yes

	is_triggered_only = yes

	after = {
		destroy_colony = yes
	}

	option = {
		name = akx.9530.a
		enable_special_project = {
			name = WAITING_WORLD_DISAPPEARANCE
			location = this
			owner = root.owner
		}
	}

	option = {
		name = akx.9530.b
		custom_tooltip = akx.9530.b.tooltip
		add_modifier = {
			modifier = worm_quarantined
			days = -1
		}
		owner = {
			add_monthly_resource_mult = {
				resource = influence
				value = 24
				min = 200
				max = 1000
			}
		}
	}
}

ship_event = {
	id = akx.9535
	title = akx.9535.name
	desc = akx.9535.desc
	picture = GFX_evt_colony_settlement
	location = fromfrom

	is_triggered_only = yes

	option = {
		name = OK
		owner = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = 8
				min = 200
				max = 1000
			}
			if = {
				limit = {
					has_technology = tech_akx_worm_1
				}
				# nothing
			}
			else = {
				add_tech_progress = {
					tech = tech_akx_worm_1
					progress = 0.1
				}
				if = {
					limit = {
						NOT = {
							has_tech_option = tech_akx_worm_1
						}
					}
					add_research_option = tech_akx_worm_1
				}
			}
		}
	}
}

carrier_event = {
	id = akx.9540
	title = akx.9540.name
	desc = akx.9540.desc
	picture = GFX_evt_colony_settlement
	location = root
	trackable = yes

	is_triggered_only = yes

	option = {
		name = akx.9540.a
		custom_tooltip = akx.9540.a.tooltip
		hidden_effect = {
			create_country = {
				type = default
				released_by_country = root.owner
				released_from_country = root.owner
				name = "NAME_Rising_Manifold"
				name_list = root.owner
				ship_prefix = root.owner
				species = root.owner
				flag = random
				ethos = {
					ethic = random
					ethic = random
				}
				authority = random
				civics = random
				effect = {
					save_global_event_target_as = manifold_country
					root = {
						set_owner = prev
						set_controller = prev
					}
				}
			}
		}
	}

	option = {
		name = akx.9540.b
		trigger = {
			owner = {
				OR = {
					is_authoritarian = yes
					is_xenophobe = yes
				}
			}
		}
		enable_special_project = {
			name = WAITING_WORLD_PURGE
			location = this
			owner = root.owner
		}
	}

	option = {
		name = akx.9540.c
		enable_special_project = {
			name = WAITING_WORLD_HYPERAPPEARANCE
			location = this
			owner = root.owner
		}
	}
}

carrier_event = {
	id = akx.9541
	title = akx.9541.name
	desc = akx.9541.desc
	picture = GFX_evt_colony_settlement
	location = root

	is_triggered_only = yes

	immediate = {
		# Other empires react to purge according to action.21
		weighted_random_owned_pop_group = {
			limit = {
				exists = planet
				planet = { is_same_value = root }
			}
			save_event_target_as = purged_species
		}
		every_country = {
			limit = {
				has_communications = root.owner
				NOT = { is_country = root.owner }
				NOT = { is_same_species = root.owner }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile
				}
			}
			add_opinion_modifier = { who = root.owner modifier = opinion_genocidal }
		}
		every_country = {
			limit = {
				has_communications = root.owner
				NOT = { is_country = root.owner }
				is_same_species = event_target:purged_species
			}
			add_opinion_modifier = { who = root.owner modifier = opinion_genocidal_our_species }
		}
	}

	after = {
		hidden_effect = {
			destroy_colony = yes
		}
	}

	option = {
		name = akx.9541.a
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier3unityreward
			}
		}
	}

	option = {
		name = akx.9541.b
		owner = {
			add_monthly_resource_mult = {
				resource = influence
				value = 24
				min = 200
				max = 1000
			}
			add_modifier = {
				modifier = unity_reduction_akx_9541
				days = 1800
			}
		}
	}
}

carrier_event = {
	id = akx.9545
	title = akx.9545.name
	desc = akx.9545.desc
	picture = GFX_evt_colony_settlement
	location = root

	is_triggered_only = yes

	after = {
		owner = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = 8
				min = 200
				max = 1000
			}
			if = {
				limit = {
					has_technology = tech_akx_worm_1
				}
				# nothing
			}
			else = {
				add_tech_progress = {
					tech = tech_akx_worm_1
					progress = 0.1
				}
				if = {
					limit = {
						NOT = {
							has_tech_option = tech_akx_worm_1
						}
					}
					add_research_option = tech_akx_worm_1
				}
			}
		}
	}

	option = {
		name = akx.9545.a
	}
	option = {
		name = akx.9545.b
	}
}

# The Retainer

# on fleet entering technosphere system
fleet_event = {
	id = akx.9600
	title = akx.9600.name
	desc = akx.9600.desc
	location = root
	is_triggered_only = yes
	diplomatic = yes

	trigger = {
		owner = {
			is_ai = no
			has_country_flag = worm_events_available
			from = {
				any_fleet_in_system = {
					exists = owner
					owner = {
						is_country_type = guardian_sphere
					}
				}
			}
			NOR = {
				has_country_flag = retainer_conversation
				has_country_flag = retainer_first_convo_concluded
			}
		}
	}

	picture_event_data = {
		room = technosphere_room
	}

	option = {
		name = akx.9600.a
		trigger = {
			owner = {
				NOT = { has_country_flag = retainer_questioned_brief }
			}
		}
		hidden_effect = {
			owner = { set_country_flag = retainer_questioned_brief }
			fleet_event = { id = akx.9601 }
		}
	}

	option = {
		name = akx.9600.b
		trigger = {
			owner = {
				NOT = { has_country_flag = retainer_questioned_loop }
			}
		}
		hidden_effect = {
			owner = { set_country_flag = retainer_questioned_loop }
			fleet_event = { id = akx.9602 }
		}
	}

	option = {
		name = akx.9600.c
		allow = {
			owner = {
				resource_stockpile_compare = { resource = energy value >= 800 }
				resource_stockpile_compare = { resource = minerals value >= 800 }
			}
		}
		owner = {
			add_resource = {
				energy = -800
				minerals = -800
			}
		}
		hidden_effect = {
			fleet_event = { id = akx.9620 }
		}
	}

	option = {
		name = akx.9600.d
		response_text = akx.9600.d.response
		default_hide_option = yes
		hidden_effect = {
			owner = {
				remove_country_flag = retainer_conversation
				set_country_flag = retainer_first_convo_concluded
			}
		}
	}

	option = {
		name = akx.9600.e
		response_text = akx.9600.e.response
		hidden_effect = {
			owner = {
				remove_country_flag = retainer_conversation
				set_country_flag = retainer_first_convo_concluded
			}
		}
	}
}

fleet_event = {
	id = akx.9601
	title = akx.9600.name
	desc = akx.9600.a.response
	location = root

	is_triggered_only = yes
	diplomatic = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	immediate = {
		owner = {
			set_country_flag = retainer_conversation
		}
	}

	option = {
		name = akx.9600.a
		trigger = {
			owner = {
				NOT = { has_country_flag = retainer_questioned_brief }
			}
		}
		hidden_effect = {
			owner = { set_country_flag = retainer_questioned_brief }
			fleet_event = { id = akx.9601 }
		}
	}

	option = {
		name = akx.9600.b
		trigger = {
			owner = {
				NOT = { has_country_flag = retainer_questioned_loop }
			}
		}
		hidden_effect = {
			owner = { set_country_flag = retainer_questioned_loop }
			fleet_event = { id = akx.9602 }
		}
	}

	option = {
		name = akx.9600.c
		allow = {
			owner = {
				resource_stockpile_compare = { resource = energy value >= 800 }
				resource_stockpile_compare = { resource = minerals value >= 800 }
			}
		}
		owner = {
			add_resource = {
				energy = -800
				minerals = -800
			}
		}
		hidden_effect = {
			fleet_event = { id = akx.9620 }
		}
	}

	option = {
		name = akx.9600.d
		response_text = akx.9600.d.response
		default_hide_option = yes
		hidden_effect = {
			owner = {
				remove_country_flag = retainer_conversation
				set_country_flag = retainer_first_convo_concluded
			}
		}
	}

	option = {
		name = akx.9600.e
		response_text = akx.9600.e.response
		hidden_effect = {
			owner = {
				remove_country_flag = retainer_conversation
				set_country_flag = retainer_first_convo_concluded
			}
		}
	}
}

fleet_event = {
	id = akx.9602
	title = akx.9600.name
	desc = akx.9600.b.response
	location = root
	is_triggered_only = yes
	diplomatic = yes

	picture_event_data = {
		room = technosphere_room
	}

	option = {
		name = akx.9600.a
		trigger = {
			owner = {
				NOT = { has_country_flag = retainer_questioned_brief }
			}
		}
		hidden_effect = {
			owner = { set_country_flag = retainer_questioned_brief }
			fleet_event = { id = akx.9601 }
		}
	}

	option = {
		name = akx.9600.b
		trigger = {
			owner = {
				NOT = { has_country_flag = retainer_questioned_loop }
			}
		}
		hidden_effect = {
			owner = { set_country_flag = retainer_questioned_loop }
			fleet_event = { id = akx.9602 }
		}
	}

	option = {
		name = akx.9600.c
		allow = {
			owner = {
				resource_stockpile_compare = { resource = energy value >= 800 }
				resource_stockpile_compare = { resource = minerals value >= 800 }
			}
		}
		owner = {
			add_resource = {
				energy = -800
				minerals = -800
			}
		}
		hidden_effect = {
			fleet_event = { id = akx.9620 }
		}
	}

	option = {
		name = akx.9600.d
		response_text = akx.9600.d.response
		default_hide_option = yes
		hidden_effect = {
			owner = {
				remove_country_flag = retainer_conversation
				set_country_flag = retainer_first_convo_concluded
			}
		}
	}

	option = {
		name = akx.9600.e
		response_text = akx.9600.e.response
		hidden_effect = {
			owner = {
				remove_country_flag = retainer_conversation
				set_country_flag = retainer_first_convo_concluded
			}
		}
	}
}

# again, on fleet entering technosphere system
fleet_event = {
	id = akx.9610
	title = akx.9610.name
	desc = akx.9610.desc
	location = root
	is_triggered_only = yes
	diplomatic = yes

	trigger = {
		from = {
			any_fleet_in_system = {
				exists = owner
				owner = {
					is_country_type = guardian_sphere
				}
			}
		}
		owner = {
			has_country_flag = worm_events_available
			NOT = {
				has_country_flag = retainer_conversation
			}
			has_country_flag = retainer_first_convo_concluded
		}
	}

	picture_event_data = {
		room = technosphere_room
	}

	option = {
		name = akx.9610.a
		allow = {
			owner = {
				resource_stockpile_compare = { resource = energy value >= 800 }
				resource_stockpile_compare = { resource = minerals value >= 800 }
			}
		}
		owner = {
			add_resource = {
				energy = -800
				minerals = -800
			}
		}
		hidden_effect = {
			fleet_event = { id = akx.9620 }
		}
	}

	option = {
		name = akx.9610.b
		response_text = akx.9610.b.response
		default_hide_option = yes
		hidden_effect = {
			owner = {
				remove_country_flag = retainer_conversation
			}
		}
	}

	option = {
		name = akx.9610.c
		response_text = akx.9610.c.response
		hidden_effect = {
			owner = {
				remove_country_flag = retainer_conversation
			}
		}
	}
}

fleet_event = {
	id = akx.9620
	title = akx.9620.name
	desc = akx.9620.desc
	picture = GFX_evt_technosphere
	location = root

	is_triggered_only = yes

	immediate = {
		solar_system = {
			random_system_planet = {
				limit = { is_star = yes }
				save_event_target_as = hole_pets
			}
		}
	}

	option = {
		name = akx.9620.a
		hidden_effect = {
			event_target:technosphere_ship = {
				# explosion ambient object?
				destroy_fleet = this
			}
		}
		event_target:hole_pets = {
			add_deposit = d_society_10
		}
	}
}

# Conclusion

# on omega alignment building complete
carrier_event = {
	id = akx.10000
	title = akx.10000.name
	desc = akx.10000.desc
	picture = GFX_evt_metropolis
	show_sound = event_ship_bridge
	location = root
	trackable = yes

	is_triggered_only = yes

	pre_triggers = {
		is_ai = no
	}

	trigger = {
		owner = {
			has_event_chain = WORM_CHAIN_1
			NOT = { has_country_flag = alignment_built }
		}
		has_building = building_akx_worm_3
	}

	immediate = {
		owner = {
			set_country_flag = alignment_built
		}
	}

	after = {
		owner = {
			end_event_chain = WORM_CHAIN_1
			begin_event_chain = {
				event_chain = WORM_CHAIN_2
				target = this
			}
		}
		enable_special_project = {
			name = WORM_ENTRY_POINT
			location = this
			owner = root.owner
		}
	}

	option = {
		name = akx.10000.a
	}
	option = {
		name = akx.10000.b
	}
}

carrier_event = {
	id = akx.10010
	title = akx.10010.name
	desc = akx.10010.desc
	picture = GFX_evt_dimensional_horror
	location = root

	is_triggered_only = yes

	option = {
		name = akx.10010.a
		hidden_effect = {
			carrier_event = { id = akx.10020 }
		}
	}

	option = {
		name = akx.10010.b
		hidden_effect = {
			solar_system = {
				random_system_planet = {
					limit = { is_star = yes }
					save_event_target_as = local_star
				}
				create_country = {
					name = "NAME_The_Loop"
					type = faction
					auto_delete = no
					flag = {
						icon= {
							category = "special"
							file = "extradimensional_02.dds"
						}
						background= {
							category = "backgrounds"
							file = "circle.dds"
						}
						colors={
							"black"
							"red"
							"null"
							"null"
						}
					}
					effect = {
						add_modifier = {
							modifier = worm_manifestation
							days = -1
						}
						establish_communications_no_message = root.owner
						establish_contact = { who = root.owner location = root }
						save_global_event_target_as = worm_enemy
						create_fleet = {
							name = "NAME_TIME_IS_SIGHT_GRAVITY_IS_DESIRE"
							settings = { spawn_debris = no }
							effect = {
								set_owner = event_target:worm_enemy
								create_ship_design = {
									design = "NAME_Dimensional_Horror"
								}
								create_ship = {
									design = last_created_design
									name = "NAME_Worm_in_Waiting"
								}
								set_location = {
									target = event_target:local_star
									distance = 30
								}
							}
						}
					}
				}
			}
			owner = { observer_event = { id = observer.72 } }
		}
	}
}

carrier_event = {
	id = akx.10020
	title = akx.10020.name
	desc = akx.10020.desc
	picture = GFX_evt_black_hole
	show_sound = event_activating_unknown_technology
	location = root

	is_triggered_only = yes

	pre_triggers = {
		is_ai = no
	}

	immediate = {
		solar_system = {
			every_system_planet = {
				limit = {
					NOR = {
						is_planet_class = pc_gas_giant
						is_planet_class = pc_shattered_ring_habitable
						is_planet_class = pc_ringworld_habitable
						is_planet_class = pc_ringworld_habitable_damaged
						is_planet_class = pc_ringworld_tech
						is_planet_class = pc_ringworld_tech_damaged
						is_planet_class = pc_ringworld_seam
						is_planet_class = pc_ringworld_seam_damaged
						is_planet_class = pc_habitat
						is_planet_class = pc_asteroid
						is_planet_class = pc_ice_asteroid
						is_planet_class = pc_city
						is_planet_class = pc_relic
						is_star = yes
					}
				}
				every_owned_pop_group = {
					limit = {
						is_sapient = yes
					}
					# add planet class to organics
					if = {
						limit = { is_robot_pop_group = no }
						modify_species = {
							species = this
							ideal_planet_class = pc_nuked
						}
					}
					# add planet classes to basic machines
					if = {
						limit = { has_trait = trait_wet_planet_preference }
						modify_species = {
							species = this
							remove_trait = trait_wet_planet_preference
							add_trait = trait_machine_pc_nuked_preference
						}
					}
					if = {
						limit = { has_trait = trait_dry_planet_preference }
						modify_species = {
							species = this
							remove_trait = trait_dry_planet_preference
							add_trait = trait_machine_pc_nuked_preference
						}
					}
					if = {
						limit = { has_trait = trait_cold_planet_preference }
						modify_species = {
							species = this
							remove_trait = trait_cold_planet_preference
							add_trait = trait_machine_pc_nuked_preference
						}
					}
					# add traits to organics
					if = {
						limit = {
							is_robot_pop_group = no
							NOT = {
								has_trait = trait_natural_physicists
							}
						}
						# remove opposite traits
						if = {
							limit = { has_trait = trait_natural_engineers }
							modify_species = {
								species = this
								remove_trait = trait_natural_engineers
							}
						}
						if = {
							limit = { has_trait = trait_natural_sociologists }
							modify_species = {
								species = this
								remove_trait = trait_natural_sociologists
							}
						}
						if = {
							limit = { has_trait = trait_nerve_stapled }
							modify_species = {
								species = this
								remove_trait = trait_nerve_stapled
							}
						}
						# add trait
						modify_species = {
							species = this
							add_trait = trait_natural_physicists
						}
					}
					if = {
						limit = {
							is_robot_pop_group = no
							NOT = {
								has_trait = trait_repugnant
							}
						}
						# remove opposite traits
						if = {
							limit = { has_trait = trait_charismatic }
							modify_species = {
								species = this
								remove_trait = trait_charismatic
							}
						}
						modify_species = {
							species = this
							add_trait = trait_repugnant
						}
					}
					#Add traits to machines
					if = {
						limit = {
							is_robot_pop_group = yes
							NOT = {
								has_trait = trait_robot_artificial_physicists
							}
						}
						# remove opposite traits
						if = {
							limit = { has_trait = trait_robot_artificial_engineers }
							modify_species = {
								species = this
								remove_trait = trait_robot_artificial_engineers
							}
						}
						if = {
							limit = { has_trait = trait_robot_artificial_sociologists }
							modify_species = {
								species = this
								remove_trait = trait_robot_artificial_sociologists
							}
						}
						# add trait
						modify_species = {
							species = this
							add_trait = trait_robot_artificial_engineers
						}
					}
					if = { #IM trait
						limit = {
							is_robot_pop_group = yes
							NOT = {
								has_trait = trait_robot_uncanny
							}
						}
						# remove opposite traits
						if = {
							limit = { has_trait = trait_robot_emotion_emulators }
							modify_species = {
								species = this
								remove_trait = trait_robot_emotion_emulators
							}
						}
						# add trait
						modify_species = {
							species = this
							add_trait = trait_robot_uncanny
						}
					}
				}
				change_pc = pc_nuked
				set_planet_flag = nuked_planet_anomalies_disabled
				reroll_planet = yes
			}
			every_system_planet = {
				limit = { is_star = yes }
				change_pc = pc_black_hole
			}
			set_star_flag = worm_black_hole
			set_star_class = sc_black_hole
		}
		owner = { observer_event = { id = observer.71 } }
	}

	after = {
		hidden_effect = {
			owner = {
				remove_country_flag = worm_events_available
				set_country_flag = worm_awaited
				set_country_flag = worm_tomb_ending
			}
		}
	}

	option = {
		name = akx.10020.a
		owner = { end_event_chain = WORM_CHAIN_2 }
	}
}

# on fleet destroyed perp
country_event = {
	id = akx.10030
	title = akx.10021.name
	desc = akx.10021.desc
	picture = GFX_evt_crisis_defeated
	show_sound = event_celebration
	location = root

	is_triggered_only = yes

	trigger = {
		has_country_flag = worm_events_available
		exists = event_target:worm_enemy
		from = {
			is_same_value = event_target:worm_enemy
		}
	}

	immediate = {
		event_target:worm_enemy = {
			destroy_country = yes
		}
	}

	after = {
		hidden_effect = {
			remove_country_flag = worm_events_available
			set_country_flag = worm_awaited
		}
	}

	option = {
		name = akx.10021.a
		end_event_chain = WORM_CHAIN_2
		add_monthly_resource_mult = {
			resource = energy
			value = 24
			min = 1500
			max = 3000
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = 36
			min = 1000
			max = 8000
		}
		if = {
			limit = { has_ancrel = yes }
			add_relic = r_worm_scales
		}
	}
	after = {
		if = {
			limit = {
				NOT = { has_country_flag = horrific_celebration }
			}
			set_country_flag = horrific_celebration
			generate_parade_city = yes
			start_situation = {
				type = leviathan_celebration_opportunity
				target = event_target:parade_city
				effect = {
					set_situation_flag = celebration_worm
					set_situation_flag = standard_unity_reward
				}
			}
		}
	}
}
