namespace = distar

#################################
#
# Anomaly Events
# by Dee Majek
#
#################################

# root = ship scope
# from = planet scope

### GAME_START EVENTS
### Create Sealed System
event = {
	id = distar.290
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_distar = yes
	}

	immediate = {
		set_spawn_system_batch = begin
		no_scope = {
			# makes system positions originate from galactic core
			#set_spawn_system_batch = begin
			# batch-processes the spawn_system effects between "begin" and "end",
			# so caches are recalculated only once rather than for every system spawned

			#Spawn Sealed System Entry System
			random_system = {
				limit = {
					NOR = {
						is_fe_cluster = yes
						has_star_flag = empire_cluster
					}
				}
				spawn_system = {
					min_distance >= 20
					max_distance <= 50
					initializer = "distar_sealed_1_1"
				}
			}
			#Spawn Sealed System
			event_target:sealed_entry_system = {
				spawn_system = {
					min_distance >= 20
					max_distance <= 30
					max_jumps = 30
					initializer = "distar_sealed_1_2"
				}
			}
			#Isolate Sealed System
			if = {
				limit = { exists = event_target:sealed_system }
				event_target:sealed_system = {
					isolate_system = yes
					#Create Shroud Country
					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 = {
							save_global_event_target_as = shroud_country
						}
					}
					#Create Miniboss
					create_fleet = {
						name = "NAME_Psionic_Entity"
						settings = {
							spawn_debris = no
							is_boss = yes
						}
						effect = {
							set_owner = event_target:shroud_country
							create_ship = {
								name = "NAME_Psionic_Entity"
								design = "NAME_Corrupted_Avatar"
							}
							set_location = {
								target = prev.star
								distance = 100
								angle = random
							}
							set_fleet_stance = aggressive
							set_aggro_range_measure_from = return_point
							set_aggro_range = 2000
							save_global_event_target_as = sealed_psionic_entity
						}
					}
				}
			}
		}
		set_spawn_system_batch = end

		#Spawn Special Wormholes
		event_target:sealed_entry_system = {
			event_target:sealed_system = {
				prev = { # done this way to ensure we don't spawn "orphan wormholes (wormholes that aren't linked to anything)
					spawn_natural_wormhole = {
						bypass_type = wormhole
						random_pos = no
						orbit_angle = 360
					}
				}
				spawn_natural_wormhole = {
					bypass_type = wormhole
					random_pos = no
					orbit_angle = 270
				}
				link_wormholes = prev
			}
		}
	}
}

### GAME_START
### Ensure Hyperlanes actually connect the three Ratling Systems
event = {
	id = distar.295
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_distar = yes
		any_system = {
			has_star_flag = ratling_home_system
		}
		any_system = {
			has_star_flag = ratling_system
			NOT = { has_star_flag = ratling_home_system }
		}
	}

	immediate = {
		set_spawn_system_batch = begin
		random_system = {
			limit = { has_star_flag = ratling_home_system }
			every_system = {
				limit = {
					has_star_flag = ratling_system
					NOT = {
						has_star_flag = ratling_home_system
						has_hyperlane_to = prev
					}
				}
				add_hyperlane = { from = this to = prev }
			}
		}
		set_spawn_system_batch = end
	}
}

carrier_event = { #Changing Ratling planetview image back to nuked on colonization
	id = distar.300
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_planet_flag = ratling_planet
		is_planet_class = pc_nuked
		NOT = { has_carrier_flag = changed_planetview_image }
	}

	immediate = {
		set_planet_entity = {
			picture = pc_nuked
		}
		set_carrier_flag = changed_planetview_image
	}
}

event = {
	id = distar.301
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = event_target:ratling_pre_space_country
		any_playable_country = {
			NOR = {
				has_communications = event_target:ratling_pre_space_country
				is_same_value = event_target:ratling_pre_space_country
			}
		}
	}

	immediate = {
		random_playable_country = {
			limit = {
				NOR = {
					has_communications = event_target:ratling_pre_space_country
					is_same_value = event_target:ratling_pre_space_country
				}
			}
			establish_communications_no_message = event_target:ratling_pre_space_country
			establish_contact = { who = this location = this.capital_scope }
		}
	}
}

country_event = { #Atomic Clock follow-up: Selection
	id = distar.310
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		FROMFROM.solar_system = {
			save_global_event_target_as = atomic_clock_system
		}

		random_list = {
			0 = {
				modifier = {
					add = 1
					FROMFROM.solar_system = {
						any_system_planet = {
							habitable_planet = no
							has_anomaly = no
							planet_size > 8
							planet_size < 25
							NOR = {
								is_planet_class = "pc_broken"
								is_planet_class = "pc_astral_scar"
								has_planet_flag = has_megastructure
							}
							is_star = no
						}
					}
				}
				country_event = { id = distar.311 } #System planet is terraformed
			}
			0 = {
				modifier = {
					add = 1
					FROMFROM.solar_system = {
						has_access_fleet = root
					}
				}
				country_event = { id = distar.315 } #Useable Gray Goo ship is built
			}
			0 = {
				modifier = {
					add = 1
					FROMFROM.solar_system = {
						any_system_planet = {
							habitable_planet = no
							has_anomaly = no
							is_star = no
						}
					}
				}
				country_event = { id = distar.320 } #Unmanned research facilities built (Phys + Eng)
			}
			0 = {
				modifier = {
					add = 1
					FROMFROM.solar_system = {
						any_system_planet = {
							has_anomaly = no
							exists = owner
							owner = {
								is_primitive = yes
							}
							NOT = { is_planet_class = pc_ringworld_habitable }
						}
					}
				}
				country_event = { id = distar.330 } #Primitive planet is nuked
			}
			0 = {
				modifier = {
					add = 1
					FROMFROM.solar_system = {
						any_system_planet = {
							habitable_planet = yes
							is_colony = no
							is_under_colonization = no
							has_anomaly = no
						}
					}
				}
				country_event = { id = distar.335 } #Habitable planet is nuked
			}
		}
	}
}

country_event = { #Atomic Clock follow-up: A system planet is terraformed
	id = distar.311
	title = distar.311.name
	desc = distar.311.desc
	picture = GFX_evt_clocks
	show_sound = event_activating_unknown_technology
	location = FROMFROMFROM

	is_triggered_only = yes

	immediate = {
		FROMFROMFROM.solar_system = {
			random_system_planet = {
				limit = {
					habitable_planet = no
					has_anomaly = no
					planet_size > 8
					planet_size < 25
					NOR = {
						is_planet_class = "pc_broken"
						is_planet_class = "pc_astral_scar"
						has_planet_flag = has_megastructure
					}
					is_star = no
				}
				save_event_target_as = atomic_clock_planet
			}
		}
	}

	option = {
		name = "distar.311.a"
		hidden_effect = { country_event = { id = distar.312 days = 30 } }
	}

	option = {
		trigger = {
			event_target:atomic_clock_planet.solar_system = {
				any_ship_in_system = {
					owner = { is_same_value = root }
					OR = {
						is_ship_class = shipclass_military_station
						is_ship_class = shipclass_military
					}
				}
			}
		}
		name = "distar.311.b"
		custom_tooltip = "distar.311.b.tooltip"
		add_monthly_resource_mult = {
			resource = influence
			value = @tier1influencereward
			min = @tier1influencemin
			max = @tier1influencemax
		}
		hidden_effect = { country_event = { id = distar.313 days = 10 } } #They gray goo the planet
	}
}

country_event = { #A system planet is terraformed
	id = distar.312
	title = distar.312.name
	desc = distar.312.desc
	picture = GFX_evt_gray_gooed_planet
	show_sound = event_mystic_reveal
	location = event_target:atomic_clock_planet

	is_triggered_only = yes

	specimen = peerless_atomic_clock

	option = {
		name = INCREDIBLE
		event_target:atomic_clock_planet = {
			change_pc = pc_gaia
			hidden_effect = { reroll_planet = yes }
			add_modifier = { modifier = mineral_rich days = -1 }
			hidden_effect = {
				switch = {
					trigger = has_modifier
					mineral_poor = { remove_modifier = mineral_poor }
					ultra_rich = { remove_modifier = ultra_rich }
					titanic_life = { remove_modifier = titanic_life }
					dangerous_wildlife = { remove_modifier = dangerous_wildlife }

				}
				every_deposit = {
					limit = { is_deposit_type = d_dangerous_wildlife_blocker }
					clear_blocker = yes
				}
			}
		}
		generate_lcluster_clue = yes
	}
}

country_event = { #A system planet is gray gooed
	id = distar.313
	title = distar.313.name
	desc = distar.313.desc
	picture = GFX_evt_gray_goo
	show_sound = event_mystic_reveal
	location = event_target:atomic_clock_planet

	is_triggered_only = yes

	specimen = peerless_atomic_clock

	immediate = {
		event_target:atomic_clock_planet = {
			if = {
				limit = { has_deposit_for = shipclass_mining_station }
				clear_deposits = yes
			}
			if = {
				limit = { has_mining_station = yes }
				mining_station = { dismantle = yes }
				create_research_station = { owner = root }
			}
		}
	}

	option = {
		name = DISCONCERTING
		event_target:atomic_clock_planet = {
			change_pc = pc_gray_goo
			set_deposit = d_engineering_4
		}
		generate_lcluster_clue = yes
	}
}

country_event = { #A useable Gray Goo Ship is built
	id = distar.315
	title = distar.315.name
	desc = distar.315.desc
	picture = GFX_evt_mining_station
	show_sound = event_mystic_reveal
	location = event_target:nanite_ship_fleet

	is_triggered_only = yes

	specimen = peerless_atomic_clock

	immediate = {
		create_country = {
			name = "NAME_Nanite_Ship"
			type = nice_faction
			auto_delete = yes
			flag = {
				icon = {
					category = "special"
					file = "unknown.dds"
				}
				background = {
					category = "backgrounds"
					file = "00_solid.dds"
				}
				colors = {
					"dark_grey"
					"dark_grey"
					"null"
					"null"
				}
			}
			effect = {
				set_faction_hostility = {
					target = root
					set_hostile = no
					set_neutral = yes
					set_friendly = no
				}
				create_fleet = {
					name = "NAME_Nanite_Interdictor"
					effect = {
						set_owner = prev
						create_ship = {
							name = random
							design = "NAME_Nanite_Interdictor"
							prefix = no
							upgradable = no
						}
						set_location = {
							target = FROMFROMFROM
							distance = 2
							angle = random
						}
						set_fleet_stance = passive
						save_event_target_as = nanite_ship_fleet
					}
					settings = {
						can_upgrade = yes
						can_disband = yes
						can_change_composition = yes
						can_change_leader = yes
						uses_naval_capacity = yes
						spawn_debris = no
					}
				}
				save_event_target_as = nanite_ship_country
			}
		}
	}

	option = {
		name = INCREDIBLE
		event_target:nanite_ship_fleet = {
			set_owner = root
		}
		generate_lcluster_clue = yes
		hidden_effect = {
			event_target:nanite_ship_country = {
				destroy_country = yes
			}
		}
	}

	option = {
		name = SCRAPIT
		event_target:nanite_ship_fleet = {
			delete_fleet = this
		}
		add_resource = { alloys = 1500 }
		generate_lcluster_clue = yes
		hidden_effect = {
			event_target:nanite_ship_country = {
				destroy_country = yes
			}
		}
	}
}


country_event = { #An unmanned computer network is built
	id = distar.320
	title = distar.320.name
	desc = distar.320.desc
	picture = GFX_evt_ancient_alien_temple
	show_sound = event_mystic_reveal
	location = FROMFROMFROM

	is_triggered_only = yes

	specimen = peerless_atomic_clock

	immediate = {
	}

	option = {
		name = INCREDIBLE
		FROMFROMFROM.solar_system = {
			random_system_planet = {
				limit = {
					habitable_planet = no
					has_anomaly = no
					is_star = no
				}
				if = {
					limit = { has_deposit_for = shipclass_mining_station }
					clear_deposits = yes
				}
				if = {
					limit = { has_mining_station = yes }
					mining_station = { dismantle = yes }
					create_research_station = { owner = root }
				}
				hidden_effect = {
					add_modifier = { modifier = nanite_network days = -1 }
				}
				add_deposit = d_engineering_10
			}
		}
	}
}

country_event = { #A primitive planet is nuked
	id = distar.330
	title = distar.330.name
	desc = distar.330.desc
	picture = GFX_evt_exploding_planet
	show_sound = event_mystic_reveal
	location = event_target:nuked_primitive_planet

	is_triggered_only = yes

	immediate = {
		FROMFROMFROM.solar_system = {
			random_system_planet = {
				limit = {
					exists = owner
					owner = {
						is_primitive = yes
					}
					has_anomaly = no
				}
				owner = { save_event_target_as = nuked_primitives }
				save_event_target_as = nuked_primitive_planet
				nuke_pre_ftls_toxic_effect = yes
				if = {
					limit = { has_observation_outpost = yes }
					observation_outpost = {
						dismantle = yes
					}
				}
			}
		}
	}
	option = {
		name = REMARKABLE
		exclusive_trigger = {
			OR = {
				has_ai_personality = exterminators
				is_xenophobe = yes
			}
		}
	}
	option = {
		name = UNFORTUNATE
	}
	option = {
		name = distar.330.a.phile
		exclusive_trigger = {
			is_xenophile = yes
		}
	}
}
country_event = { #A habitable planet is nuked
	id = distar.335
	title = distar.335.name
	desc = distar.335.desc
	picture = GFX_evt_exploding_planet
	show_sound = event_mystic_reveal
	location = event_target:nuked_planet

	is_triggered_only = yes

	immediate = {
		FROMFROMFROM.solar_system = {
			random_system_planet = {
				limit = {
					has_anomaly = no
					habitable_planet = yes
					is_colony = no
					is_under_colonization = no
				}
				destroy_colony = yes
				save_event_target_as = nuked_planet
				change_pc = pc_toxic
				reset_planet = yes
			}
		}
	}

	option = {
		name = UNFORTUNATE
	}
}

#################################
#
# Anomaly Events
# by Miranda van den Brink
# anomaly.1000 - 2999
#
#################################

# ROOT = ship scope
# FROM = planet scope

##### VECTHAR ZAVONIA CHAIN ######

# Discovering the Vechtar Zavonia Generation Ship
ship_event = {
	id = distar.1000
	title = "distar.1000.name"
	desc = "distar.1000.desc"
	picture = GFX_evt_ship_in_orbit
	show_sound = event_ship_bridge
	location = FROM
	trackable = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			NOT = {
				any_country = {
					has_country_flag = vechtar_zavonia_chain
				}
			}
		}
	}

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
			set_country_flag = vechtar_zavonia_chain
		}
		leader = {
			save_global_event_target_as = vechtar_zavonia_leader_name
		}
	}

	option = {
		name = distar.1000.a
		from = {
			enable_special_project = {
				name = "GENERATION_SHIP"
				location = from
				owner = root.owner
			}
		}
	}

	option = {
		name = distar.1000.b
		owner = { add_resource = { influence = 50 } }
	}
}

# Project Followup
country_event = {
	id = distar.1001
	title = "distar.1001.name"
	desc = "distar.1001.desc"
	picture = GFX_evt_ship_in_orbit
	show_sound = event_ship_bridge
	location = event_target:utopian_planet

	is_triggered_only = yes

	immediate = {
		#random_galaxy_planet = {
		#	limit = {
		#		#is_colonizable = no
		#		has_owner = no
		#		#is_colony = no
		#		#uninhabitable_regular_planet = yes
		#		is_planet_class = pc_nuked
		#		has_anomaly = no
		#	}
		#	save_global_event_target_as = utopian_planet
		#}
		save_global_event_target_as = country_that_discovered_mardak_vol
		event_target:vechtar_zavonia_leader_name = {
			add_or_level_up_veteran_trait_effect = {
				TRAIT = leader_trait_maniacal
			}
		}
	}

	option = {
		tooltip = {
			event_target:vechtar_zavonia_leader_name = {
				add_or_level_up_veteran_trait_effect = {
					TRAIT = leader_trait_maniacal
				}
			}
		}
		name = distar.1001.a
		hidden_effect = {
			closest_system = {
				spawn_system = {
					min_distance >= 29
					max_distance <= 31
					# 45
					min_orientation_angle = 24
					max_orientation_angle = 66
					initializer = vechtar_zavonia_system
				}
			}
			add_extra_hyperlane_to_spawned_system_effect = yes
		}
		begin_event_chain = {
			event_chain = "generation_ship_chain"
			target = this
		}
		hidden_effect = {
			create_point_of_interest = {
				id = mardak_hidden_planet #The Rubricator was also using the hidden_planet id
				name = "hidden_planet_poi"
				desc = hidden_planet_desc
				event_chain = generation_ship_chain
				location = event_target:utopian_planet
			}
		}
	}

	option = {
		tooltip = {
			event_target:vechtar_zavonia_leader_name = {
				add_or_level_up_veteran_trait_effect = {
					TRAIT = leader_trait_maniacal
				}
			}
		}
		add_resource = { influence = 250 }
		name = distar.1001.b
	}
}
# Triggers on entering paradise planet system
fleet_event = {
	id = distar.1002
	title = "distar.1002.name"
	desc = "distar.1002.desc"
	picture = GFX_evt_cold_barren
	show_sound = event_ship_bridge
	location = event_target:utopian_planet
	trackable = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			has_event_chain = generation_ship_chain
			NOT = {
				has_country_flag = discovered_hidden_planet
			}
		}
		exists = event_target:utopian_planet
		event_target:utopian_planet = {
			NOT = { has_carrier_flag = triggered_vol_transmission }
		}
		solar_system = {
			any_system_planet = {
				is_same_value = event_target:utopian_planet
			}
		}
	}

	immediate = {
		owner = {
			set_country_flag = discovered_hidden_planet
			remove_point_of_interest = hidden_planet_poi
			add_event_chain_counter = {
				event_chain = "generation_ship_chain"
				counter = "planet_found"
				amount = 1
			}
		}
	}

	option = {
		name = distar.1002.a
		owner = {
			enable_special_project = {
				name = "HIDDEN_PLANET"
				location = event_target:utopian_planet
				owner = root.owner
			}
		}
	}

	option = {
		name = distar.1002.b
		owner = {
			end_event_chain = "generation_ship_chain"
			add_resource = { influence = 50 }
		}
	}
}
# Project followup: Uncovering the paradise planet
country_event = {
	id = distar.1003
	title = "distar.1003.name"
	desc = "distar.1003.desc"
	picture = GFX_evt_alien_cavemen
	show_sound = event_mystic_reveal
	location = event_target:utopian_planet

	is_triggered_only = yes

	immediate = {
		end_event_chain = "generation_ship_chain"
		event_target:utopian_planet = {
			set_surveyed = {
				surveyed = yes
				surveyor = root
			}
			change_pc = pc_gaia
			set_planet_size = 25
			set_name = "NAME_Paridayda"
			clear_planet_modifiers = yes
			add_modifier = {
				modifier = paradise_planet
			}
			add_deposit = d_underwater_vent
			add_deposit = d_tempestous_mountain
			add_deposit = d_ore_rich_caverns
			add_deposit = d_ore_rich_caverns
			add_deposit = d_submerged_ore_veins
			add_deposit = d_lush_jungle
			add_deposit = d_teeming_reef
			add_deposit = d_black_soil
			add_deposit = d_dust_caverns
			add_deposit = d_crystal_forest
			add_deposit = d_active_volcano

			random_list = {
				33 = { add_deposit = d_frozen_gas_lake }
				33 = { add_deposit = d_prosperous_mesa }
				33 = { add_deposit = d_fertile_lands }
			}
			random_list = {
				33 = { add_deposit = d_dust_desert }
				33 = { add_deposit = d_bubbling_swamp }
				33 = { add_deposit = d_crystal_reef }
			}

			create_species = {
				name = "NAME_Mardak_Vol"
				class = FUN
				portrait = fun4
				traits = {
					trait = random_traits
				}
				homeworld = this
			}
			create_country = {
				name = random
				authority = random
				civics = {
					civic = civic_secret_of_fire
					civic = civic_the_wheel
				}
				species = last_created_species
				ethos = random
				origin = origin_default_pre_ftl
				flag = {
					icon = {
						category = "pre_ftl"
						file = "preftl_stone_age.dds"
					}
					background= {
						category = "backgrounds"
						file = "new_dawn.dds"
					}
					colors = {
						"turquoise"
						"green"
						"null"
						"null"
					}
				}
				type = primitive
				effect = {
					set_country_flag = stone_age
					set_pre_ftl_age = stone_age
					save_event_target_as = mardak_vol_country
					set_graphical_culture = preindustrial_01
					species = {
						save_global_event_target_as = mardak_vol_species
					}
				}
			}

			set_owner = last_created_country
			set_capital = yes
			every_deposit = {
				limit = { is_deposit_type = d_dangerous_wildlife_blocker }
				clear_blocker = yes
			}
			while = {
				count = 4
				create_pop_group = {
					species = last_created_species
				}
			}
			set_timed_carrier_flag = {
				flag = ignore_ai_building_limitations
				days = 1
			}
			add_building = building_crude_huts
			add_building = building_crude_huts
		}
		establish_communications_no_message = event_target:mardak_vol_country
		if = {
			limit = {
				event_target:utopian_planet = {
					solar_system = {
						exists = owner
						owner = {
							NOT = {
								is_same_value = root
							}
						}
					}
				}
			}
			event_target:utopian_planet = {
				solar_system = {
					owner = {
						country_event = { id = distar.1004 days = 10 }
					}
				}
			}
		}
		event_target:utopian_planet = {
			carrier_event = { id = distar.1010 days = 20 } # Triggers Vol's return
		}
	}

	option = {
		name = distar.1003.a
	}

	option = {
		name = distar.1003.b
	}
}
# Notifying potential planet owners that their tomb world is actually a gaia world
country_event = {
	id = distar.1004
	title = "distar.1004.name"
	desc = "distar.1004.desc"
	picture = GFX_evt_alien_cavemen
	show_sound = event_mystic_reveal
	location = event_target:utopian_planet

	is_triggered_only = yes

	immediate = {
		establish_communications_no_message = event_target:mardak_vol_country
		event_target:utopian_planet = { save_event_target_as = primitive_planet }
		country_event = { id = story.6 days = 10 }
	}

	option = {
		name = distar.1004.a
	}
}
# Triggers continuation of event chain upon building a starbase
ship_event = {
	id = distar.1007
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:utopian_planet
		exists = event_target:mardak_vol_species
		event_target:utopian_planet = {
			NOT = { has_carrier_flag = triggered_vol_transmission }
			any_owned_pop_group = {
				species = { is_same_value = event_target:mardak_vol_species }
			}
		}
		FROM = {
			solar_system = {
				any_system_planet = {
					is_same_value = event_target:utopian_planet
				}
			}
		}
	}

	immediate = {
		random_galaxy_planet = {
			limit = {
				is_same_value = event_target:utopian_planet
			}
			carrier_event = { id = distar.1010 days = 20 } # Triggers Vol's return
		}
	}
}
######## ADDS CONTINUATION OF EVENT CHAIN
# Triggers Vol return event for planet owner
carrier_event = {
	id = distar.1010
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		solar_system = {
			exists = owner
		}
		any_owned_pop_group = {
			species = { is_same_value = event_target:mardak_vol_species }
		}
		NOT = { has_carrier_flag = triggered_vol_transmission }
	}

	immediate = {
		solar_system = {
			owner = {
				country_event = { id = distar.1005 }
				save_event_target_as = country_that_owns_mardak_vol_planet
			}
		}
		set_carrier_flag = triggered_vol_transmission
	}
}

# The Vol have discovered Mardak on your planets
country_event = {
	id = distar.1005
	title = "distar.1005.name"
	# country that discovered mardak vol own the planet
	desc = {
		trigger = {
			exists = event_target:country_that_discovered_mardak_vol
			is_same_value = event_target:country_that_discovered_mardak_vol
		}
		text = distar.1005.desc_a
	}
	# the planet is still owned by the country that owned it when the primitives were first discovered
	desc = {
		trigger = {
			NAND = {
				exists = event_target:country_that_discovered_mardak_vol
				is_same_value = event_target:country_that_discovered_mardak_vol
			}
		}

		text = distar.1005.desc_b
	}

	picture = GFX_evt_star_chart
	show_sound = event_radio_chatter
	location = event_target:utopian_planet

	is_triggered_only = yes

	trigger = {
		#exists = event_target:country_that_discovered_mardak_vol
		#is_same_value = event_target:country_that_discovered_mardak_vol
		event_target:utopian_planet = {
			solar_system = {
				exists = owner
			}
			any_owned_pop_group = {
				is_same_species = event_target:mardak_vol_species
			}
		}
	}

	immediate = {
		create_species = { # No homeworld set as they don't originate from a known planet
			name = "NAME_Vol"
			class = MAM
			portrait = mam5
			traits = {
				trait = random_traits
			}
			effect = {
				save_global_event_target_as = vol
			}
		}
		create_country = {
			name = "NAME_mardak_vol_haters"
			type = vol
			authority = auth_democratic
			civics = {
				civic = civic_fanatic_purifiers
				civic = civic_cutthroat_politics
			}
			ethos = {
				ethic = ethic_fanatic_xenophobe
				ethic = ethic_militarist
			}
			flag = {
				icon = {
					category = "domination"
					file = "domination_14.dds"
				}
				background = {
					category = "backgrounds"
					file = "00_solid.dds"
				}
				colors = {
					"black"
					"black"
					"black"
					"black"
				}
			}
			species = event_target:vol
			effect = {
				save_global_event_target_as = mardak_vol_haters_country
				set_country_flag = mardak_vol_haters_country
				every_country = {
					establish_communications_no_message = event_target:mardak_vol_haters_country
				}
			}
		}
		event_target:mardak_vol_haters_country = {
			set_policy = {
				policy = orbital_bombardment
				option = orbital_bombardment_armageddon
				cooldown = no
			}
			create_leader = {
				class = commander
				species = event_target:vol
				name = random
				skill = 5
			}
			set_leader = last_created_leader
		}
	}

	option = {
		name = ONSCREEN
		hidden_effect = {
			country_event = { id = distar.1006 }
		}
	}
}

## Vol - Transmission
country_event = {
	id = distar.1006
	title = "TRANSMISSION"
	desc = "distar.1006.desc"

	diplomatic = yes
	picture_event_data = {
		portrait = event_target:mardak_vol_haters_country
		room = "ethic_spaceship_room"
	}

	is_triggered_only = yes

	option = {
		name = distar.1006.a
		hidden_effect = {
		country_event = { id = distar.1008 }
		}
	}

	option = {
		name = distar.1006.b
		hidden_effect = {
			country_event = { id = distar.1009 }
			country_event = { id = distar.1011 days = 60 random = 20 }
			#country_event = { id = distar.1011 days = 5 }
		}
	}

	option = {
		name = distar.1006.c
		trigger = {
			is_species_class = FUN
		}
		hidden_effect = {
			country_event = { id = distar.1009 }
			country_event = { id = distar.1011 days = 60 random = 20 }
		}
	}
}
# Vol cleanse planet
country_event = {
	id = distar.1008
	title = "TRANSMISSION"
	desc = "distar.1008.desc"

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:mardak_vol_haters_country
		room = "ethic_spaceship_room"
	}

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				exists = event_target:mardak_vol_country
			}
			event_target:mardak_vol_country = {
				destroy_country = yes
			}
		}
		if = {
			limit = {
				event_target:utopian_planet = {
					has_observation_outpost = yes
				}
			}
			event_target:utopian_planet = {
				observation_outpost = {
					dismantle = yes
				}
			}
		}
		if = {
			limit = {
				any_owned_colony = {
					any_owned_pop_group = {
						is_same_species = event_target:mardak_vol_species
					}
				}
			}
			every_owned_colony = {
				limit = {
					any_owned_pop_group = {
						is_same_species = event_target:mardak_vol_species
					}
				}
				every_owned_pop_group = {
					limit = { is_same_species = event_target:mardak_vol_species }
					kill_all_pop = yes
				}
				add_deposit = d_fungoid_extermination
			}
		}
	}

	option = {
		name = distar.1008.a
	}

	option = {
		name = distar.1008.b
		country_event = {
			id = distar.1013
		}
	}
}

country_event = {
	id = distar.1013
	title = "TRANSMISSION"
	desc = "distar.1013.desc"

	diplomatic = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	is_triggered_only = yes

	option = {
		name = distar.1013.a
	}
}

country_event = {
	id = distar.1009
	title = "TRANSMISSION"
	desc = "distar.1009.desc"

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:mardak_vol_haters_country
		room = "ethic_spaceship_room"
	}

	is_triggered_only = yes

	option = {
		name = distar.1009.a
	}
}
## Vol attack
country_event = {
	id = distar.1011
	title = "distar.1011.name"
	desc = "distar.1011.desc"
	picture = GFX_evt_federation_fleet
	show_sound = event_red_alert
	location = event_target:mardak_vol_haters_fleet

	is_triggered_only = yes
	trigger = {
		event_target:utopian_planet = {
			solar_system = {
				exists = owner
			}
			any_owned_pop_group = {
				is_same_species = event_target:mardak_vol_species
			}
		}
	}

	immediate = {
		event_target:mardak_vol_haters_country = {
			create_leader = {
				class = commander
				species = event_target:vol
				name = random
				skill = 4
				leader_age_min = 45
				leader_age_max = 60
				traits = {
					0 = leader_trait_unyielding
				}
				effect = {
					save_event_target_as = mardak_vol_haters_leader
				}
			}
		}
		create_fleet = {
			name = "NAME_mardak_vol_haters_fleet"
			settings = {
				spawn_debris = no
				uses_naval_capacity = no
			}
			effect = {
				set_fleet_flag = vol_exterminators
				set_owner = event_target:mardak_vol_haters_country
				set_fleet_bombardment_stance = armageddon
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_corvette"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_destroyer"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_destroyer"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_destroyer"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_destroyer"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_destroyer"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_destroyer"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_destroyer"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_cruiser"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_cruiser"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_cruiser"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_cruiser"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_cruiser"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_cruiser"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_cruiser"
					graphical_culture = "mammalian_01"
				}
				create_ship = {
					name = "NAME_Mardak_Purger"
					design = "NAME_mardak_vol_haters_cruiser"
					graphical_culture = "mammalian_01"
				}
				set_location = {
					target = event_target:utopian_planet
					distance = 200
					angle = 150
				}
				set_fleet_formation = {
					position = { x = -10.0	y = 8.5		} #11
					position = { x = -1.6	y = 15.0	} #10
					position = { x = 14.0	y = -3.0	} #9
					position = { x = 1.3	y = -11.0	} #8
					position = { x = -10.5	y = 1.0		} #7
					position = { x = 3.0	y = 8.0		} #6
					position = { x = -4.3	y = -7.0	} #5
					position = { x = 8.0	y = 9.0		} #4
					position = { x = -4.0	y = 7.3		} #3
					position = { x = 7.5	y = -10.5	} #2
					position = { x = 0.0	y = 0.0		} #1
				}
				set_fleet_stance = passive
				set_aggro_range_measure_from = self
				set_aggro_range = 1
				save_global_event_target_as = mardak_vol_haters_fleet
				auto_move_to_planet = {
					target = event_target:utopian_planet
					clear_auto_move_on_arrival = no
				}
				set_leader = event_target:mardak_vol_haters_leader
			}
		}
	}
	option = {
		name = distar.1011.a
	}
}
# On Completion of Vol Orbital Bombardment of Paridayda the mardak vol country is destroyed
carrier_event = {
	id = distar.1015
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:utopian_planet
		is_same_value = event_target:utopian_planet
	}

	immediate = {
		remove_modifier = paradise_planet
		add_deposit = d_fungoid_extermination
		add_deposit = d_fungoid_extermination
		add_deposit = d_fungoid_extermination
		add_deposit = d_fungoid_extermination
		closest_system = {
			min_steps = 1
			use_bypasses = yes
			random_system_planet = {
				save_event_target_as = new_target
			}
		}
		solar_system = {
			random_fleet_in_system = {
				limit = {
					has_fleet_flag = vol_exterminators
				}
				auto_move_to_planet = {
					target = event_target:new_target
					clear_auto_move_on_arrival = no
				}
				set_fleet_flag = mardak_vol_purgers_die # Flags the ship for destruction now that their mission is done
			}
		}
		if = {
			limit = {
				has_observation_outpost = yes
			}
			observation_outpost = {
				dismantle = yes
			}
		}
		if = {
			limit = {
				any_owned_pop_group = {
					is_same_species = event_target:mardak_vol_species
				}
			}
			owner = {
				every_owned_colony = {
					limit = {
						any_owned_pop_group = {
							is_same_species = event_target:mardak_vol_species
						}
					}
					every_owned_pop_group = {
						limit = { is_same_species = event_target:mardak_vol_species }
						kill_all_pop = yes
					}
					add_deposit = d_fungoid_extermination
				}
			}
		}
		solar_system = {
			owner = {
				country_event = { id = distar.1016 days = 1 }
			}
		}
	}
}

# Notification to planet owner/ system owner when paridayda is destroyed
country_event = {
	id = distar.1016
	title = "distar.1016.name"
	desc = "distar.1016.desc"
	picture = GFX_evt_death_from_above
	show_sound = event_celebration
	location = event_target:utopian_planet

	is_triggered_only = yes

	option = {
		name = distar.1016.a
	}
}

country_event = {
	id = distar.1017
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		from = {
			has_fleet_flag = vol_exterminators
			has_fleet_flag = mardak_vol_purgers_die
		}
	}

	immediate = {
		from = {
			delete_fleet = this
			create_ambient_object = {
				location = this
				type = horror_spawn_object
			}
		}
		event_target:mardak_vol_haters_country = {
			destroy_country = yes
		}
	}
}


# Notification on colonizing Paridayda
carrier_event = {
	id = distar.1014
	title = "distar.1014.name"
	desc = "distar.1014.desc"
	picture = GFX_evt_gaia
	show_sound = event_celebration
	location = event_target:utopian_planet

	is_triggered_only = yes

	trigger = {
		exists = event_target:utopian_planet
		is_same_value = event_target:utopian_planet
		owner = {
			is_same_value = event_target:country_that_discovered_mardak_vol
		}
	}

	immediate = {
		owner = {
			add_modifier = {
				modifier = in_paradise
				days = 3600
			}
		}
	}
	option = {
		name = distar.1014.a
		tooltip = {
			owner = {
				add_modifier = {
					modifier = in_paradise
					days = 3600
				}
			}
		}
	}
	option = {
		name = distar.1014.b
		tooltip = {
			owner = {
				add_modifier = {
					modifier = in_paradise
					days = 3600
				}
			}
		}
	}
}

##### STAR LIFTING ######
ship_event = {
	id = distar.1020
	title = "distar.1020.name"
	desc = "distar.1020.desc"
	picture = GFX_evt_star_pulsar
	show_sound = event_laboratory_sound
	location = FROM
	trackable = yes

	is_triggered_only = yes

	immediate = {
		Owner = {
			country_event = { id = story.5 days = 30 }
			set_country_flag = star_lifting
		}
		from = { save_event_target_as = star_lifting_star }
		leader = {
			save_event_target_as = star_lifting_leader
		}
		save_event_target_as = star_lifting_ship
	}

	option = {
		name = distar.1020.a
		from = {
			enable_special_project = {
				name = "STAR_LIFTING"
				location = from
				owner = root.owner
			}
			hidden_effect = {
				set_carrier_flag = star_lifting_star@root.owner
			}
		}
	}

	option = {
		name = distar.1020.c
		trigger = {
			owner = {
				NAND = {
					has_technology = tech_lasers_1
					has_technology = tech_lasers_2
					has_technology = tech_lasers_3
					has_technology = tech_lasers_4
					has_technology = tech_lasers_5
				}
			}
		}
		From = {
			enable_special_project = {
				name = "STAR_LIFTING_WEAPONS"
				location = from
				owner = root.owner
			}
		}
	}

	option = {
		name = distar.1020.b
	}
}
# Followup Platform
country_event = {
	id = distar.1021
	title = "distar.1021.name"
	desc = "distar.1021.desc"
	picture = GFX_evt_star_pulsar
	show_sound = event_laboratory_sound
	location = fromfrom

	is_triggered_only = yes

	immediate = {
		event_target:broken_star_lifting_platform = {
			destroy_ambient_object = this
		}
		fromfrom = {
			create_ambient_object = {
				type = star_lifting_platform
			}
			last_created_ambient_object = {
				set_location = {
					target = prev
					distance = 20
				}
			}
			clear_deposits = yes
		}
	}

	option = {
		fromfrom = {
			add_deposit = d_energy_6
		}
		name = distar.1021.a
	}

	option = {
		trigger = {
			NOT = {
				is_species_class = MOL
			}
		}
		fromfrom = {
			add_deposit = d_energy_6
		}
		name = distar.1021.b
	}
}

# Followup Weapons
country_event = {
	id = distar.1022
	title = "distar.1022.name"
	desc = {
		text = "distar.1022.desc.a"
		trigger = {
			NAND = {
				has_technology = tech_lasers_1
				has_technology = tech_lasers_2
				has_technology = tech_lasers_3
				has_technology = tech_lasers_4
				has_technology = tech_lasers_5
			}
		}
	}
	desc = {
		text = "distar.1022.desc.b"
		trigger = {
			has_technology = tech_lasers_1
			has_technology = tech_lasers_2
			has_technology = tech_lasers_3
			has_technology = tech_lasers_4
			has_technology = tech_lasers_5
		}
	}
	picture = GFX_evt_engineering_research
	show_sound = event_laboratory_sound
	location = fromfrom

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_technology = tech_lasers_1
				has_technology = tech_lasers_2
				has_technology = tech_lasers_3
				has_technology = tech_lasers_4
				has_technology = tech_lasers_5
			}
			event_target:broken_star_lifting_platform = {
				destroy_ambient_object = this
			}
		}
	}

	option = {
		name = distar.1022.a
		trigger = {
			NAND = {
				has_technology = tech_lasers_1
				has_technology = tech_lasers_2
				has_technology = tech_lasers_3
				has_technology = tech_lasers_4
				has_technology = tech_lasers_5
			}
		}
		inverted_switch = {
			trigger = has_technology
			tech_lasers_1 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_1
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
			tech_lasers_2 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_2
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
			tech_lasers_3 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_3
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
			tech_lasers_4 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_4
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
			tech_lasers_5 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_5
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
		}
		event_target:star_lifting_star = {
			add_deposit = d_physics_1
		}
	}

	option = {
		name = distar.1022.b
		trigger = {
			AND = {
				has_technology = tech_lasers_1
				has_technology = tech_lasers_2
				has_technology = tech_lasers_3
				has_technology = tech_lasers_4
				has_technology = tech_lasers_5
			}
		}
		event_target:star_lifting_star = {
			add_deposit = d_physics_3
		}
	}
	option = {
		name = distar.1022.c
		trigger = {
			has_technology = tech_lasers_1
			has_technology = tech_lasers_2
			has_technology = tech_lasers_3
			has_technology = tech_lasers_4
			has_technology = tech_lasers_5
			NOT = {
				is_species_class = MOL
			}
			is_xenophobe = yes
		}
		event_target:star_lifting_star = {
			add_deposit = d_physics_3
		}
	}
}

##### ABANDONED OBSERVATION OUTPOST ######
ship_event = {
	id = distar.1030
	title = "distar.1030.name"
	desc = "distar.1030.desc"
	picture = GFX_evt_city_ruins
	show_sound = event_alien_signal
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
		}
	}

	option = {
		name = distar.1030.a
		From = {
			enable_special_project = {
				name ="BIG_RIP"
				location = from
				owner = root.owner
			}
		}
	}
	option = {
		name = distar.1030.b
		owner = {
			add_resource = { influence = 50 }
		}
	}
}

country_event = {
	id = distar.1031
	title = "distar.1031.name"
	desc = "distar.1031.desc"
	picture = GFX_evt_city_ruins
	show_sound = event_ghost_town
	location = FROMFROM

	is_triggered_only = yes

	option = {
		name = distar.1031.a
		exclusive_trigger = {
			is_xenophobe = yes
		}
		hidden_effect = {
			set_country_flag = lcluster_clue_desc_2
			pop_lcluster_event = yes
		}

		add_monthly_resource_mult = {
			resource = society_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}
	}

	option = {
		name = distar.1031.b
		hidden_effect = {
			set_country_flag = lcluster_clue_desc_2
			pop_lcluster_event = yes
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}
	}
}

##### Bunker-Bot ######
ship_event = {
	id = distar.1040
	title = "distar.1040.name"
	desc = "distar.1040.desc"
	picture = GFX_evt_sapient_AI
	show_sound = event_alien_signal
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
		}
	}

	option = {
		name = distar.1040.a
		custom_tooltip = distar.1040.a.tooltip
		hidden_effect = {
			owner = { pop_lcluster_event = yes }
		}
		owner = {
			add_resource = { alloys = 100 }
			add_resource = { rare_crystals = 50 }
			add_resource = { volatile_motes = 50 }
		}
	}
	option = {
		name = distar.1040.b
		custom_tooltip = distar.1040.b.tooltip
		hidden_effect = {
			owner = { pop_lcluster_event = yes }
		}
		owner = {
			add_modifier = {
				modifier = mega_computer
				days = 3600
			}
		}
	}
	option = {
		name = distar.1040.c
		custom_tooltip = distar.1040.c.tooltip
		hidden_effect = {
			owner = { pop_lcluster_event = yes }
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier4unityreward
				min = @tier4unitymin
				max = @tier4unitymax
			}
		}
	}
}

##### ATOMIC CLOCK ######
ship_event = {
	id = distar.1045
	title = "distar.1045.name"
	desc = "distar.1045.desc"
	picture = GFX_evt_clocks
	show_sound = event_mystic_reveal
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
			set_country_flag = atomic_clock
		}
	}

	option = {
		name = distar.1045.a
		custom_tooltip = distar.1045.a.tooltip
		owner = {
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
			hidden_effect = {
				country_event = { id = distar.310 days = 15323 }
			}
		}
	}
	option = {
		name = distar.1045.b
		custom_tooltip = distar.1045.b.tooltip
		owner = {
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}
}

###### EAT OR BE EATEN ######
ship_event = {
	id = distar.1050
	title = "distar.1050.name"
	picture = GFX_evt_space_debris
	show_sound = event_alien_nature
	location = FROM

	is_triggered_only = yes

	desc = {
		trigger = { owner = { is_lithoid_empire = no } }
		text = distar.1050.desc
	}
	desc = {
		trigger = { owner = { is_lithoid_empire = yes } }
		text = distar.1050.desc_lithoid
	}

	trigger = {
		any_playable_country = {
			is_country_type = default
			NOR = {
				is_same_value = root.owner
				has_country_flag = lost_colony_parent
				has_country_flag = chosen_empire
				is_machine_empire = yes
				is_synthetic_empire = yes
				owner_species = {
					NOT = { is_archetype = BIOLOGICAL }
				}
			}
		}
	}
	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
			set_country_flag = eat_or_be_eaten
		}
		random_playable_country = {
			limit = {
				NOR = {
					is_same_value = root.owner
					has_country_flag = lost_colony_parent
					has_country_flag = chosen_empire
					is_machine_empire = yes
					is_synthetic_empire = yes
					owner_species = {
						NOT = { is_archetype = BIOLOGICAL }
					}
				}
			}
			weights = {
				base = 1
				modifier = {
					factor = 10
					has_communications = root.owner
				}
			}
			establish_communications = root.owner
			save_event_target_as = delicious_aliens
			root.owner = { set_country_flag = establishing_delicious_comms }
		}
	}

	option = {
		name = distar.1050.a
		hidden_effect = {
			if = {
				limit = {
					root.owner = { has_country_flag = establishing_delicious_comms }
				}
				custom_tooltip = distar.1050.a.tooltip
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}

	option = {
		exclusive_trigger = { owner = { has_origin = origin_evolutionary_predators } }
		name = distar.1050.b.evopred
		hidden_effect = {
			if = {
				limit = {
					root.owner = { has_country_flag = establishing_delicious_comms }
				}
				custom_tooltip = distar.1050.a.tooltip
			}
		}
		owner = {
			give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = large }
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}
}
##### THE CUBE ######
ship_event = {
	id = distar.1055
	title = "distar.1055.name"
	desc = "distar.1055.desc"
	picture = GFX_evt_space_debris
	show_sound = event_mystic_reveal
	location = FROM

	is_triggered_only = yes

	immediate = {
		leader = {
			save_event_target_as = cube_science_officer
		}
		owner = {
			country_event = { id = story.5 days = 30 }
		}
	}

	option = {
		name = distar.1055.a
		enable_special_project = {
			name = "THE_CUBE"
			location = from
			owner = root.owner
		}
	}
	option = {
		name = distar.1055.b
	}
}

country_event = {
	id = distar.1056
	title = "distar.1056.name"
	desc = "distar.1056.desc"
	picture = GFX_evt_space_debris
	show_sound = event_mystic_reveal
	location = FROMFROM

	is_triggered_only = yes

	trigger = {

	}

	immediate = {
		from.leader = {
			save_event_target_as = cube_science_officer
			add_or_level_up_veteran_trait_effect = {
				TRAIT = leader_trait_maniacal
			}
		}
	}
	option = {
		name = distar.1056.a
		custom_tooltip = distar.1056.a.tooltip
		tooltip = {
			from.leader = {
				add_or_level_up_veteran_trait_effect = {
					TRAIT = leader_trait_maniacal
				}
		}
		}
	}
}

##### HONEYMOONERS ######
ship_event = {
	id = distar.1060
	title = "distar.1060.name"
	desc = "distar.1060.desc"
	picture = GFX_evt_alien_nature
	show_sound = event_alien_nature
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
		}
	}

	option = {
		name = distar.1060.a
		trigger = {
			owner = {
				is_xenophile = yes
			}
		}
		owner = {
			add_modifier = {
				modifier = a_hitchikers_guide_to_the_galaxy
				days = 3600
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}
	option = {
		name = distar.1060.b
		trigger = {
			owner = {
				is_xenophobe = yes
			}
		}
		owner = {
			add_modifier = {
				modifier = littering_loitering_liability
				days = 3600
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}
	option = {
		name = distar.1060.c
		trigger = {
			hidden_trigger = {
				owner = {
					OR = {
						is_xenophile = yes
						is_xenophobe = yes
					}
				}
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}
	option = {
		name = distar.1060.d
		trigger = {
			owner = {
				NOR = {
					is_xenophile = yes
					is_xenophobe = yes
				}
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}
	option = {
		name = FASCINATING
		trigger = {
			owner = {
				NOR = {
					is_xenophile = yes
					is_xenophobe = yes
				}
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}
}

##### HOLOGRAM ######
ship_event = {
	id = distar.1065
	title = "distar.1065.name"
	desc = "distar.1065.desc"
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_desert
			}
		}
		picture = GFX_evt_desert
	}
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_tropical
			}
		}
		picture = GFX_evt_tropical
	}
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_arid
			}
		}
		picture = GFX_evt_arid
	}
	picture = {
		trigger = {
			from = {
				OR = {
					is_planet_class = pc_continental
					is_planet_class = pc_gaia
					is_planet_class = pc_alpine
					is_planet_class = pc_savannah
				}
			}
		}
		picture = GFX_evt_continental
	}
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_ocean
			}
		}
		picture = GFX_evt_ocean
	}
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_tundra
			}
		}
		picture = GFX_evt_tundra
	}
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_arctic
			}
		}
		picture = GFX_evt_arctic
	}
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_gas_giant
			}
		}
		picture = GFX_evt_gas_giant
	}
	picture = {
		trigger = {
			from = {
				NOR = {
					is_planet_class = pc_arctic
					is_planet_class = pc_desert
					is_planet_class = pc_tropical
					is_planet_class = pc_arid
					is_planet_class = pc_continental
					is_planet_class = pc_gaia
					is_planet_class = pc_alpine
					is_planet_class = pc_savannah
					is_planet_class = pc_ocean
					is_planet_class = pc_tundra
					is_planet_class = pc_arctic
				}
			}
		}
		picture = GFX_evt_ship_in_orbit_2
	}
	show_sound = event_mystic_reveal
	location = root

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
		From = {
			remove_planet = yes
		}
	}

	option = {
		name = distar.1065.a
		tooltip = {
			owner = {
				add_monthly_resource_mult = {
					resource = engineering_research
					value = @tier1researchreward
					min = @tier1researchmin
					max = @tier1researchmax
				}
			}
		}
	}
}

##### STAR CRAZY ######
ship_event = {
	id = distar.1070
	title = "distar.1070.name"
	desc = "distar.1070.desc"
	inline_script = {
		script = events/biogenesis_event_art
		OWNER = owner
		REGULAR_PICTURE = GFX_evt_ship_in_orbit_2
		BIOSHIP_PICTURE = GFX_evt_bio_ships_orbiting
	}
	show_sound = event_mystic_reveal
	location = From

	is_triggered_only = yes

	immediate = {
		leader = {
			save_global_event_target_as = crazy_science_officer
		}
		owner = {
			set_country_flag = star_crazy
		}
		save_event_target_as = crazy_scientist_ship
	}

	option = {
		name = distar.1070.a
		hidden_effect = {
			from.solar_system = {
				closest_system = {
					min_steps = 2
					max_steps = 20
					limit = {
						NOR = {
							exists = space_owner
							has_star_flag = hostile_system
						}
						star = {
							NOR = {
								is_star_class = sc_black_hole
								has_deposit_for = shipclass_mining_station
							}
						}
					}
					save_event_target_as = anomalous_star_system
					star = {
						save_global_event_target_as = anomalous_star
					}
				}
			}
			### Fallback Version with lighter requirements
			if = {
				limit = {
					NOT = { exists = event_target:anomalous_star_system }
				}
				from.solar_system ={
					closest_system = {
						min_steps = 2
						max_steps = 30
						limit = {
							NOT = {
								has_star_flag = hostile_system
							}
							star = {
								NOT = { is_star_class = sc_black_hole }
							}
						}
						save_event_target_as = anomalous_star_system
						star = {
							save_global_event_target_as = anomalous_star
						}
					}
				}
			}
			### Fallback Version that creates an entirely new system for the event
			ELSE_IF = {
				limit = {
					NOT = { exists = event_target:anomalous_star_system }
				}
				owner = {
					random_system_within_border = {
						spawn_system = {
							min_distance = 10
							max_distance = 30
							max_jumps = 0
							initializer = "star_crazy_fallback_system"
							effect = {
								save_event_target_as = anomalous_star_system
								star = {
									save_global_event_target_as = anomalous_star
								}
							}
						}
						add_extra_hyperlane_to_spawned_system_effect = yes
					}
				}
			}
		}
		if = {
			limit = {
				exists = event_target:anomalous_star_system
			}
			enable_special_project = {
				name = "STAR_CRAZY"
				location = event_target:anomalous_star
				owner = root.owner
			}
		}
		ELSE = {
			hidden_effect = {
				ship_event = { id = distar.1071 days = 3 }
			}
		}
	}

	option = {
		name = distar.1070.b
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier1unityreward
				min = @tier1unitymin
				max = @tier1unitymax
			}
		}
	}
}

### Fallback solution to failed system find/create in distar.1070
ship_event = {
	id = distar.1071
	title = "distar.1071.name"
	desc = "distar.1071.desc"
	picture = GFX_evt_star_chart
	show_sound = event_mystic_reveal
	location = event_target:crazy_scientist_ship

	is_triggered_only = yes

	immediate = {
	}

	after = {
		owner = {
			remove_country_flag = star_crazy
		}
		clear_global_event_target = crazy_science_officer
	}

	option = {
		name = distar.1071.a
		from.leader = {
			add_experience = 350
		}
	}
}

country_event = {
	id = distar.1072
	title = "distar.1072.name"
	desc = "distar.1072.desc"
	inline_script = {
		script = events/biogenesis_event_art
		OWNER = owner
		REGULAR_PICTURE = GFX_evt_ship_in_orbit_2
		BIOSHIP_PICTURE = GFX_evt_bio_ships_orbiting
	}

	show_sound = event_alien_nature
	location = From.From

	is_triggered_only = yes

	immediate = {
		event_target:anomalous_star = {
			set_surveyed = {
				surveyed = yes
				surveyor = root
			}
		}
	}

	option = {
		name = distar.1072.a
		from.leader = {
			add_trait = {
				trait = leader_trait_meticulous
			}
			add_experience = 200
		}
		event_target:anomalous_star = {
			hidden_effect = {
				if = {
					limit = { NOT = { has_deposit_for = shipclass_mining_station } }
					clear_deposits = yes
				}
			}
			add_deposit = d_energy_8
		}
	}
}

country_event = {
	id = distar.1073
	title = "distar.1073.name"
	desc = "distar.1073.desc"
	picture = GFX_evt_surreal_visions
	show_sound = event_ghost_town
	location = From.From

	is_triggered_only = yes

	immediate = {
		event_target:anomalous_star = {
			set_surveyed = {
				surveyed = yes
				surveyor = root
			}
		}
	}

	option = {
		name = distar.1073.a
		custom_tooltip = distar.1070.a.tooltip
	}
	option = {
		name = distar.1073.b
	}

	after = {
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier1researchreward
			min = @tier1researchmin
			max = @tier1researchmax
		}

		hidden_effect = {
			if = {
				limit = {
					exists = event_target:crazy_science_officer
				}
				event_target:crazy_science_officer = {
					kill_leader = {
						show_notification = no
					}
				}
			}
		}
	}
}

##### AZIZIANS #####
ship_event = {
	id = distar.1080
	title = "distar.1080.name"
	desc = {
		trigger = { owner = { has_technology = tech_cloning } }
		text = distar.1080.desc.b
	}
	desc = {
		trigger = { NOT = { owner = { has_technology = tech_cloning } } }
		text = distar.1080.desc.c
	}
	picture = GFX_evt_space_debris
	show_sound = event_mystic_reveal
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
		}
	}

	option = {
		trigger = {
			owner = {
				has_technology = tech_cloning
			}
		}
		name = distar.1080.a
		enable_special_project = {
			name = "ICE_ALIEN"
			location = owner.capital_scope
			owner = root.owner
		}
	}
	option = {
		name = distar.1080.b
		owner = {
			add_resource = { influence = 50 }
		}
	}
	option = {
		name = distar.1080.c
		owner = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
		}
	}
	option = {
		name = distar.1080.d
		trigger = {
			owner = {
				 NOR = {
					has_technology = tech_cloning
					has_origin = origin_evolutionary_predators
				}
			}
		}
		hidden_effect = {
			owner = {
				set_country_flag = stored_azizian_dna
			}
		}
	}
	option = {
		name = distar.1080.d.evopred
		trigger = {
			owner = {
				NOT = { has_technology = tech_cloning }
				has_origin = origin_evolutionary_predators
			}
		}
		owner = {
			give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = small TYPE = molluscoid }
			hidden_effect = {
				set_country_flag = stored_azizian_dna
			}
		}
	}
}

country_event = {
	id = distar.1081
	title = "distar.1081.name"
	desc = "distar.1081.desc"
	picture = GFX_evt_genetic_modification
	show_sound = event_mystic_reveal
	location = FROM

	is_triggered_only = yes

	immediate = {
		random_owned_planet = {
			limit = {
				is_colony = yes
				sapient_pop_amount > 100
			}
			weights = {
				base = 1
				modifier = {
					add = 5
					free_housing > 0
				}
				modifier = {
					add = 10
					free_housing > 300
				}
			}
			save_event_target_as = target_planet
		}
	}

# spawns pops
	option = {
		name = distar.1081.a
		event_target:target_planet = {
			hidden_effect = {
				create_species = {
					name = "NAME_Azizians"
					class = MOL
					portrait = mol8
					traits = {
						ideal_planet_class = pc_arctic
						trait = trait_presapient_proles
					}
					homeworld = this
					effect = {
						set_species_flag = azizans_@root
						set_global_flag = spawned_azizans_@root
						save_event_target_as = azizians_species
					}
				}
				while = {
					count = 4
					#limit = { free_housing > 0 }
					create_pop_group = {
						species = event_target:azizians_species
					}
				}
				set_carrier_flag = azizian_pops_planet
			}
			custom_tooltip = distar.1081.a.tooltip
		}
	}
# Gives pets
	option = {
		name = distar.1081.b
		event_target:target_planet = {
			add_deposit = d_alien_pets_deposit
			add_deposit = d_alien_pets_deposit
			hidden_effect = { set_carrier_flag = azizian_pet_planet }
		}
	}
# Adds Azizian army
	option = {
		name = distar.1081.c
		custom_tooltip = distar.1080.c.tooltip
		event_target:target_planet = {
			set_carrier_flag = titanic_azizian_can_build
		}
		set_country_flag = titanic_azizian_soldiers
	}
# Get rid of them
	option = {
		name = distar.1081.d
		trigger = {
			NOT = { has_origin = origin_evolutionary_predators }
			is_xenophile = no
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier1researchreward
			min = @tier1researchmin
			max = @tier1researchmax
		}
	}
# Get rid of them
	option = {
		name = distar.1081.d.evopred
		trigger = {
			has_origin = origin_evolutionary_predators
			is_xenophile = no
		}
		give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = medium TYPE = molluscoid }
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier1researchreward
			min = @tier1researchmin
			max = @tier1researchmax
		}
	}
}

# Followup for pops and pets
event = {
	id = distar.1082
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_playable_country = {
			any_owned_planet = {
				OR = {
					AND = {
						has_carrier_flag = azizian_pet_planet
						has_deposit = d_alien_pets_deposit
						NOT = { has_carrier_flag = azizians_escape_zoo }
					}
					AND = {
						has_carrier_flag = azizian_pops_planet
						any_owned_species = {
							has_species_flag = azizans_@prevprev
						}
						NOT = { has_carrier_flag = azizians_burrow }
					}
				}
			}
		}
	}
	immediate = {
	# pets
		if = {
			limit = {
				any_playable_country = {
					any_owned_planet = {
						has_carrier_flag = azizian_pet_planet
						has_deposit = d_alien_pets_deposit
						NOT = { has_carrier_flag = azizians_escape_zoo }
					}
				}
			}
			random_list = {
				20 = {
					random_galaxy_planet = {
						limit = {
							has_owner = yes
							has_carrier_flag = azizian_pet_planet
							has_deposit = d_alien_pets_deposit
						}
						carrier_event = { id = distar.1083 }
						set_carrier_flag = azizians_escape_zoo
					}
				}
				80 = {}
			}
		}
		# pops
		else_if = {
			limit = {
				any_playable_country = {
					any_owned_planet = {
						has_carrier_flag = azizian_pops_planet
						any_owned_species = {
							has_species_flag = azizans_@prevprev
						}
					}
				}
			}
			random_list = {
				20 = {
					random_galaxy_planet = {
						limit = {
							has_owner = yes
							has_carrier_flag = azizian_pops_planet
							any_owned_species = {
								has_species_flag = azizans_@prev.owner
							}
						}
						carrier_event = { id = distar.1084 }
						set_carrier_flag = azizians_burrow
					}
				}
				80 = {}
			}
		}
	}
}
# Azizians escape from Zoo
carrier_event = {
	id = distar.1083
	title = "distar.1083.name"
	desc = "distar.1083.desc"
	picture = GFX_evt_interior_battle
	show_sound = event_mystic_reveal
	location = Root

	is_triggered_only = yes

	trigger = {
		has_owner = yes
		has_carrier_flag = azizian_pet_planet
		has_deposit = d_alien_pets_deposit
	}
	immediate = {
		add_planet_devastation = 10
		add_modifier = { modifier = dangerous_wildlife days = -1 }
	}
	option = {
		name = distar.1083.a
		tooltip = {
			add_planet_devastation = 10
			add_modifier = { modifier = dangerous_wildlife days = -1 }
		}
	}
}

# Azizians change
carrier_event = {
	id = distar.1084
	title = "distar.1084.name"
	desc = "distar.1084.desc"
	picture = GFX_evt_genetic_modification
	show_sound = event_mystic_reveal
	location = Root

	is_triggered_only = yes

	trigger = {
		has_owner = yes
		has_carrier_flag = azizian_pops_planet
		any_owned_pop_group = {
			species = { has_species_flag = azizans_@root.owner }
			is_being_purged = no
		}
		owner = {
			NOT = { has_country_flag = azizians_changed }
		}
	}

	immediate = {
		every_owned_pop_group = {
			limit = {
				species = { has_species_flag = azizans_@root.owner }
			}
			modify_species = {
				species = this
				remove_trait = trait_presapient_proles
				ideal_planet_class = "pc_frozen"
				add_trait = trait_agrarian
				add_trait = trait_very_strong
				add_traits_at_start_of_list = yes
			}
		}
		owner = {
			set_country_flag = azizians_changed
		}
	}
	option = {
		name = distar.1083.b
	}
}
# On researching cloning
country_event = {
	id = distar.1085
	title = "distar.1085.name"
	desc = "distar.1085.desc"
	picture = GFX_evt_society_research

	is_triggered_only = yes

	trigger = {
		has_country_flag = stored_azizian_dna
		last_increased_tech = tech_cloning
	}

	option = {
		name = distar.1085.a
		enable_special_project = {
			name = "ICE_ALIEN"
			location = root.capital_scope
			owner = root
		}
	}

	option = {
		name = distar.1085.b
		add_resource = { influence = 50 }
	}
}


##### Harvesters #####
ship_event = {
	id = distar.1090
	title = "distar.1090.name"
	desc = "distar.1090.desc"
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_tropical
			}
		}
		picture = GFX_evt_tropical
	}
	picture = {
		trigger = {
			from = {
				is_planet_class = pc_continental
			}
		}
		picture = GFX_evt_continental
	}

	picture = {
		trigger = {
			from = {
				NOR = {
					is_planet_class = pc_continental
					is_planet_class = pc_tropical
				}
			}
		}
		picture = GFX_evt_animal_wildlife
	}

	show_sound = event_construction
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = { country_event = { id = story.5 days = 30 } }
		From = {
			add_deposit = d_harvester_fields
			add_modifier = { modifier = ancient_harvesters days = -1 }
		}
	}

	option = {
		name = distar.1090.a
	}

	option = {
		name = distar.1090.b
	}
}

##### LOCUSTS #####
ship_event = {
	id = distar.1095
	title = "distar.1095.name"
	desc = "distar.1095.desc"
	picture = GFX_evt_warm_barren
	show_sound = event_ghost_town
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = { country_event = { id = story.1 days = 30 } }
		From = {
			change_pc = pc_barren
			add_modifier = {
				modifier = "terraforming_candidate"
				days = -1
			}
		}
	}

	option = {
		name = distar.1095.a
	}
	option = {
		name = distar.1095.b.evopred
		exclusive_trigger = { owner = { has_origin = origin_evolutionary_predators } }
		owner = { give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = medium TYPE = arthropoid }}
	}
}

##### SHATTERED WORLD #####
ship_event = {
	id = distar.2000
	title = "distar.2000.name"
	desc = "distar.2000.desc"
	picture = GFX_evt_space_debris
	show_sound = event_ghost_town
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = { country_event = { id = story.5 days = 30 } }
	}

	option = {
		name = FASCINATING
		From = {
			add_deposit = d_minerals_5
		}
	}
}

##### WEAPON TESTING #####
ship_event = {
	id = distar.2005
	title = "distar.2005.name"
	desc = "distar.2005.desc"
	picture = GFX_evt_toxic
	show_sound = event_ghost_town
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = { country_event = { id = story.5 days = 30 } }
		leader = {
			save_event_target_as = science_leader
		}
	}

	option = {
		name = distar.2005.a
		owner = {
			enable_special_project = {
				name = "WEAPONS_TESTING"
				location = from
				owner = root.owner
			}
		}
	}
	option = {
		name = distar.2005.b
	}
}
# Followup
country_event = {
	id = distar.2006
	title = "distar.2006.name"
	desc = {
		text = "distar.2006.desc.a"
		trigger = {
			NAND = {
				has_technology = tech_ship_armor_1
				has_technology = tech_ship_armor_2
				has_technology = tech_ship_armor_3
				has_technology = tech_ship_armor_4
				has_technology = tech_ship_armor_5
				has_technology = tech_lasers_1
				has_technology = tech_lasers_2
				has_technology = tech_lasers_3
				has_technology = tech_lasers_4
				has_technology = tech_lasers_5
			}
		}
	}
	desc = {
		text = "distar.2006.desc.b"
		trigger = {
			has_technology = tech_ship_armor_1
			has_technology = tech_ship_armor_2
			has_technology = tech_ship_armor_3
			has_technology = tech_ship_armor_4
			has_technology = tech_ship_armor_5
			has_technology = tech_lasers_1
			has_technology = tech_lasers_2
			has_technology = tech_lasers_3
			has_technology = tech_lasers_4
			has_technology = tech_lasers_5
		}
	}
	picture = GFX_evt_engineering_research
	show_sound = event_mystic_reveal
	location = fromfromfrom

	is_triggered_only = yes

	option = {
		name = distar.2006.a
		trigger = {
			NAND = {
				has_technology = tech_lasers_1
				has_technology = tech_lasers_2
				has_technology = tech_lasers_3
				has_technology = tech_lasers_4
				has_technology = tech_lasers_5
			}
		}
		inverted_switch = {
			trigger = has_technology
			tech_lasers_1 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_1
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
			tech_lasers_2 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_2
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
			tech_lasers_3 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_3
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
			tech_lasers_4 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_4
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
			tech_lasers_5 = {
				add_tech_option_or_research_effect = {
					TECH = tech_lasers_5
					PROGRESS = 0.2
					CATEGORY = physics_research
				}
			}
		}
	}

	option = {
		name = distar.2006.b
		trigger = {
			NAND = {
				has_technology = tech_ship_armor_1
				has_technology = tech_ship_armor_2
				has_technology = tech_ship_armor_3
				has_technology = tech_ship_armor_4
				has_technology = tech_ship_armor_5
			}
		}
		inverted_switch = {
			trigger = has_technology
			tech_ship_armor_1 = {
				add_tech_option_or_research_effect = {
					TECH = tech_ship_armor_1
					PROGRESS = 0.2
					CATEGORY = engineering_research
				}
			}
			tech_ship_armor_2 = {
				add_tech_option_or_research_effect = {
					TECH = tech_ship_armor_2
					PROGRESS = 0.2
					CATEGORY = engineering_research
				}
			}
			tech_ship_armor_3 = {
				add_tech_option_or_research_effect = {
					TECH = tech_ship_armor_3
					PROGRESS = 0.2
					CATEGORY = engineering_research
				}
			}
			tech_ship_armor_4 = {
				add_tech_option_or_research_effect = {
					TECH = tech_ship_armor_4
					PROGRESS = 0.2
					CATEGORY = engineering_research
				}
			}
			tech_ship_armor_5 = {
				add_tech_option_or_research_effect = {
					TECH = tech_ship_armor_5
					PROGRESS = 0.2
					CATEGORY = engineering_research
				}
			}
		}
	}

	option = {
		name = distar.2006.c
		trigger = {
			has_technology = tech_lasers_1
			has_technology = tech_lasers_2
			has_technology = tech_lasers_3
			has_technology = tech_lasers_4
			has_technology = tech_lasers_5
			has_technology = tech_shields_1
			has_technology = tech_shields_2
			has_technology = tech_shields_3
			has_technology = tech_shields_4
			has_technology = tech_shields_5
		}
		add_resource = {
			influence = 50
			unity = 50
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier1researchreward
			min = @tier1researchmin
			max = @tier1researchmax
		}
	}
}

##### WETWARE COMPUTER #####
ship_event = {
	id = distar.2010
	title = "distar.2010.name"
	desc = "distar.2010.desc"
	picture = GFX_evt_ocean
	show_sound = event_alien_nature
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = { country_event = { id = story.1 days = 30 } }
	}

	option = {
		name = FASCINATING
		FROM = {
			add_deposit = d_wetware_computer
		}
	}
}

##### PRIMORDIAL SOUP #####
ship_event = {
	id = distar.2015
	title = "distar.2015.name"
	desc = {
		text = distar.2015.desc
		trigger = {
			owner = {
				NOT = { has_valid_civic = civic_machine_terminator }
			}
		}
	}
	desc = {
		text = distar.2015.desc.terminator
		trigger = {
			owner = {
				has_valid_civic = civic_machine_terminator
			}
		}
	}
	picture = GFX_evt_microscopic_life
	show_sound = event_alien_nature
	location = from

	is_triggered_only = yes

	option = {
		name = FASCINATING
		trigger = {
			owner = {
				NOR = {
					has_valid_civic = civic_machine_terminator
					has_origin = origin_evolutionary_predators
				}
			}
		}
		from = {
			add_deposit = d_society_3
		}
	}
	option = {
		name = distar.2015.A.machine
		trigger = {
			owner = {
				is_machine_empire = yes
				NOT = { has_civic = civic_machine_servitor }
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier3unityreward
			}
		}
	}

	option = {
		name = distar.2015.b.evopred
		trigger = {
			owner = {
				has_origin = origin_evolutionary_predators
			}
		}
		owner = { give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = large } }
		from = {
			add_deposit = d_society_5
		}
	}
}

##### Single-Minded #####
ship_event = {
	id = distar.2020
	title = "distar.2020.name"
	desc = {
		trigger = {
			owner = {
				is_hive_empire = no
			}
		}
		text = "distar.2020.desc"
	}
	desc = {
		trigger = {
			owner = {
				is_hive_empire = yes
			}
		}
		text = "distar.2020.desc.hive"
	}

	picture = GFX_evt_aggressive_flora
	show_sound = event_alien_nature
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = { country_event = { id = story.1 days = 30 } }
	}

	option = {
		name = FASCINATING
		from = {
			add_deposit = d_dangerous_wildlife_blocker
			add_deposit = d_savage_wildlands
			add_modifier = {
				modifier = dangerous_wildlife
				days = -1
			}
		}
	}
}

##### Artificial Moon #####
ship_event = {
	id = distar.2025
	title = "distar.2025.name"
	desc = "distar.2025.desc"
	inline_script = {
		script = events/biogenesis_event_art
		OWNER = owner
		REGULAR_PICTURE = GFX_evt_ship_in_orbit
		BIOSHIP_PICTURE = GFX_evt_bio_ships_orbiting
	}
	show_sound = event_administrative_work
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = { country_event = { id = story.5 days = 30 } }
		from = {
			clear_deposits = yes
			solar_system = {
				random_system_planet = {
					limit = {
						has_moon = yes
						any_moon = {
							is_same_value = from
						}
					}
					save_event_target_as = artificial_moon_planet
				}
			}
		}
	}
	option = {
		name = FASCINATING
		from = {
			add_deposit = d_minerals_3
		}
	}
}

###### Time-Loop World ######
ship_event = {
	id = distar.2030
	title = "distar.2030.name"
	desc = "distar.2030.desc"
	picture = GFX_evt_metropolis
	show_sound = event_mystic_reveal
	location = FROM

	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = researched_time_loop_anomaly
		}
	}

	option = {
		name = distar.2030.a
		if = {
			limit = {
				owner = {
					is_materialist = yes
				}
			}
			#custom_tooltip = distar.2030.a.tooltip.mat
		}
		else_if = {
			limit = {
				owner = {
					is_materialist = no
				}
			}
			custom_tooltip = distar.2030.a.tooltip
		}
		enable_special_project = {
			name = MEND_SHIELD
			location = from
			owner = root.owner
		}
	}
	option = {
		name = distar.2030.b
		enable_special_project = {
			name = STOP_TIME_LOOP
			location = from
			owner = root.owner
		}
	}
	option = {
		name = distar.2030.c
		owner = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier1researchreward
				min = @tier1researchmin
				max = @tier1researchmax
			}
			hidden_effect = {
				country_event = { id = distar.2038 days = 1800 random = 3600 }
			}
		}
	}
}

# Shield Repaired
country_event = {
	id = distar.2031
	title = "distar.2031.name"
	desc = "distar.2031.desc"
	picture = GFX_evt_shielded_planet
	show_sound = event_mystic_reveal
	location = FROM

	is_triggered_only = yes

	immediate = {
		event_target:time_loop_world = {
			clear_deposits = yes
			set_planet_flag = repaired_time_loop_shield
			carrier_event = { id = distar.2034 days = 7200 random = 14400 }
		}
	}
	option = {
		name = EXCELLENT
		event_target:time_loop_world = {
			add_deposit = d_physics_8
			add_deposit = d_society_4
		}
	}
}
## Lizards dead from overheating
carrier_event = {
	id = distar.2034
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		set_planet_flag = time_loop_lizards_dead
		clear_deposits = yes
		if = {
			limit = {
				exists = orbital_station
			}
			orbital_station = {
				dismantle = yes
			}
		}
		if = {
			limit = {
				solar_system = {
					exists = space_owner
				}
			}
			solar_system = {
				owner = {
					country_event = { id = distar.2035 }
				}
			}
		}
	}
}

country_event = {
	id = distar.2035
	title = "distar.2035.name"
	desc = "distar.2035.desc"
	picture = GFX_evt_shielded_planet
	show_sound = event_mystic_reveal
	location = event_target:time_loop_world

	is_triggered_only = yes
	option = {
		name = distar.2035.a
	}
}
# When players who didn't have the anomaly claim ownership of timeloop system with repaired shield
ship_event = {
	id = distar.2036
	title = "distar.2036.name"
	desc = "distar.2036.desc"
	picture = GFX_evt_shielded_planet
	show_sound = event_mystic_reveal
	location = event_target:time_loop_world

	is_triggered_only = yes

	trigger = {
		exists = event_target:time_loop_world
		exists = solar_system
		solar_system = {
			any_system_planet = {
				is_same_value = event_target:time_loop_world
			}
		}
		event_target:time_loop_world = {
			has_planet_flag = repaired_time_loop_shield
			NOT = {
				has_planet_flag = time_loop_lizards_dead
			}
		}
		owner = {
			NOR = {
				has_country_flag = researched_time_loop_anomaly
				has_country_flag = discovered_time_loop_world
			}
		}
	}

	immediate = {
		owner = {
			set_country_flag = discovered_time_loop_world
		}
	}
	option = {
		name = FASCINATING
	}
}

### Interrupted Time Loop
# They Die
country_event = {
	id = distar.2032
	title = "distar.2032.name"
	desc = "distar.2032.desc"
	picture = GFX_evt_large_explosion
	show_sound = event_super_explosion
	location = event_target:time_loop_world

	is_triggered_only = yes

	immediate = {
		event_target:time_loop_world = {
			change_pc = pc_nuked
			set_planet_flag = nuked_planet_anomalies_disabled
		}
	}

	option = {
		name = distar.2032.a
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}
	}
}

# They are freed
country_event = {
	id = distar.2033
	title = "distar.2033.name"
	desc = "distar.2033.desc"
	picture = GFX_evt_metropolis
	show_sound = event_mystic_reveal
	location = event_target:time_loop_world

	is_triggered_only = yes

	immediate = {
		event_target:time_loop_world = {
			change_pc = pc_desert
			set_name = "NAME_Gish"
			clear_planet_modifiers = yes
			if = {
				limit = {
					root = { NOT = { species_portrait = rep16 } }
				}
				log = "limit passed"
				create_species = {
					name = "NAME_Prikki"
					plural = "NAME_Prikki"
					class = REP
					portrait = rep16
					namelist = REP4
					traits = {
						ideal_planet_class = pc_desert
						trait = trait_industrious
						trait = trait_solitary
						trait = trait_decadent
					}
					homeworld = this
					effect = {
						save_event_target_as = prikki_species
					}
				}
			}
			else_if = {
				limit = {
					root = { species_portrait = rep16 }
				}
				create_species = {
					name = "NAME_Prikki"
					plural = "NAME_Prikki"
					class = REP
					portrait = rep12
					namelist = REP4
					traits = {
						ideal_planet_class = pc_desert
						trait = trait_industrious
						trait = trait_solitary
						trait = trait_decadent
					}
					homeworld = this
					effect = {
						save_event_target_as = prikki_species
					}
				}
			}
			create_country = {
				name = "NAME_Prikkiki_Ti"
				adjective = "NAME_Prikki"
				authority = random
				civics = {
					civic = civic_fanatic_purifiers
					civic = civic_cutthroat_politics
				}
				species = last_created_species
				ethos = {
					ethic = ethic_fanatic_xenophobe
					ethic = ethic_militarist
				}
				flag = {
					icon = {
						category = "domination"
						file = "domination_1.dds"
					}
					background= {
						category = backgrounds
						file = "v.dds"
					}
					colors = {
						"teal"
						"orange"
						"null"
						"null"
					}
				}
				type = default
				effect = {
					save_global_event_target_as = time_loop_country
					species = {
						save_global_event_target_as = time_loop_species
					}
					establish_communications_no_message = root

					##Copy technology
					IF = {
						LIMIT = {
							any_neighbor_country = {
								exists = this
								is_country_type = default
							}
						}
						random_neighbor_country = {
							limit = { is_country_type = default }
							save_event_target_as = tech_country
						}
						copy_techs_from = {
							target = event_target:tech_country
							except = {
								# Horizon Signal
								tech_akx_worm_1
								tech_akx_worm_2
								tech_akx_worm_3
							}
						}
					}
					ELSE_IF = {
						LIMIT = {
							any_country = {
								is_ai = no
							}
						}
						random_country = {
							limit = { is_ai = no }
							save_event_target_as = tech_country
						}
						copy_techs_from = {
							target = event_target:tech_country
							except = {
								# Horizon Signal
								tech_akx_worm_1
								tech_akx_worm_2
								tech_akx_worm_3
							}
						}
					}
					ELSE = {
						random_country = {
							limit = { is_country_type = default	}
							save_event_target_as = tech_country
						}
						copy_techs_from = {
							target = event_target:tech_country
							except = {
								# Horizon Signal
								tech_akx_worm_1
								tech_akx_worm_2
								tech_akx_worm_3
							}
						}
					}
					IF = {
						limit = {
							event_target:tech_country = {
								has_technology = tech_maulers
							}
						}
						give_technology = { tech = tech_corvettes }
						give_technology = { tech = tech_torpedoes_1 }

					}
					IF = {
						limit = {
							event_target:tech_country = {
								has_technology = tech_weavers
							}
						}
						give_technology = { tech = tech_destroyers }
					}
					IF = {
						limit = {
							event_target:tech_country = {
								has_technology = tech_stingers
							}
						}
						give_technology = { tech = tech_battleships }
					}
					IF = {
						limit = {
							event_target:tech_country = {
								has_technology = tech_harbingers
							}
						}
						give_technology = { tech = tech_cruisers }
					}
					##Add some new technologies
					inverted_switch = {
						trigger = has_technology
						tech_starbase_2 = { give_technology = { tech = tech_starbase_2 } }
						tech_starbase_3 = { give_technology = { tech = tech_starbase_3 } }
						tech_starbase_4 = { give_technology = { tech = tech_starbase_4 } }
						tech_starbase_5 = { give_technology = { tech = tech_starbase_5 } }
						tech_power_plant_4 = { give_technology = { tech = tech_power_plant_4 } }
						tech_mining_3 = { give_technology = { tech = tech_mining_3 } }
						tech_power_hub_1 = { give_technology = { tech = tech_power_hub_1 } }
					}

					##Add resources
					add_resource = { minerals = 10000 }
					add_resource = { energy = 10000 }
					add_resource = { food = 3000 }
					add_resource = { consumer_goods = 3000 }
					add_resource = { alloys = 7000 }
					add_resource = { influence = 1000 }
					add_resource = { unity = 27000 }

					##Create fleets
					if = {
						limit = {
							has_technology = tech_destroyers
						}
						create_fleet = {
							effect = {
								set_owner = event_target:time_loop_country
								while = {
									count = 8
									create_ship = {
										name = random
										random_existing_design = destroyer
										graphical_culture = "reptilian_01"
									}
								}
								set_location = {
									target = event_target:time_loop_world
									distance = 10
									angle = random
								}
							}
						}
					}
					if = {
						limit = {
							has_technology = tech_cruisers
						}
						create_fleet = {
							effect = {
								set_owner = event_target:time_loop_country
								while = {
									count = 6
									create_ship = {
										name = random
										random_existing_design = cruiser
										graphical_culture = "reptilian_01"
									}
								}
								set_location = {
									target = event_target:time_loop_world
									distance = 10
									angle = random
								}
							}
						}
					}
					if = {
						limit = {
							has_technology = tech_battleships
						}
						create_fleet = {
							effect = {
								set_owner = event_target:time_loop_country
								while = {
									count = 2
									create_ship = {
										name = random
										random_existing_design = battleship
										graphical_culture = "reptilian_01"
									}
								}
								set_location = {
									target = event_target:time_loop_world
									distance = 10
									angle = random
								}
							}
						}
					}
					create_fleet = {
						effect = {
							set_owner = event_target:time_loop_country
							while = {
								count = 10
								create_ship = {
									name = random
									random_existing_design = corvette
									graphical_culture = "reptilian_01"
								}
							}
						}
					}
				}
			}
			set_owner = event_target:time_loop_country
			set_timed_carrier_flag = {
				flag = ignore_ai_building_limitations
				days = 1
			}
			set_capital = yes
			while = {
				count = 52
				create_pop_group = {
					species = event_target:time_loop_species
				}
			}
			while = {
				count = 3
				add_district_and_planet_size_if_needed_effect = {
					district = district_city
				}
			}
			while = {
				count = 4
				add_district_and_planet_size_if_needed_effect = {
					district = district_farming
				}
			}
			while = {
				count = 4
				add_district_and_planet_size_if_needed_effect = {
					district = district_mining
				}
			}
			while = {
				count = 5
				add_district_and_planet_size_if_needed_effect = {
					district = district_generator
				}
			}
			add_building = building_system_capital
			add_building = building_research_lab_1
			add_building = building_foundry_1
			add_building = building_food_processing_facility
			add_building = building_energy_grid
			add_building = building_mineral_purification_plant
			add_building = building_bureaucratic_1
			add_building = building_bureaucratic_1

			while = {
				count = 10
				create_army = {
					name = random
					owner = event_target:time_loop_country
					species = event_target:time_loop_species
					type = defense_army
				}
			}

			solar_system = {
				event_target:time_loop_country = {
					inverted_switch = { # If you don't have the technology for it build the simpler starbase.
						trigger = has_technology
						tech_starbase_3 = {
							prev = {
								create_starbase = {
									size = starbase_starport
									module = shipyard
									module = shipyard
									owner = event_target:time_loop_country
								}
							}
						}
						tech_starbase_4 = {
							prev = {
								create_starbase = {
									size = starbase_starhold
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									owner = event_target:time_loop_country
								}
							}
						}
						tech_starbase_5 = {
							prev = {
								create_starbase = {
									size = starbase_starfortress
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									owner = event_target:time_loop_country
								}
							}
						}
						default = {
							prev = {
								create_starbase = {
									size = starbase_citadel
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									owner = event_target:time_loop_country
								}
							}
						}
					}
				}
			}
		}
		establish_communications_no_message = last_created_country
	}

	option = {
		name = distar.2033.a
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}
	}

	option = {
		name = distar.2033.b
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}
	}
}

#### If shielded planet is left alone

# Lizards break free
country_event = {
	id = distar.2038
	title = "distar.2038.name"
	desc = "distar.2038.desc"
	picture = GFX_evt_metropolis
	show_sound = event_mystic_reveal
	location = event_target:time_loop_world

	is_triggered_only = yes

	trigger = {
		event_target:time_loop_world = {
			solar_system = {
				NOT = { exists = space_owner }
			}
		}
	}

	immediate = {
		event_target:time_loop_world = {
			change_pc = pc_desert
			set_name = "NAME_Gish"
			clear_planet_modifiers = yes
			create_species = {
				name = "NAME_Prikki"
				plural = "NAME_Prikki"
				class = REP
				portrait = rep16
				namelist = REP4
				traits = {
					ideal_planet_class = pc_desert
					trait = trait_industrious
					trait = trait_solitary
					trait = trait_decadent
				}
				homeworld = this
			}
			create_country = {
				name = "NAME_Prikkiki_Ti"
				authority = random
				civics = {
					civic = civic_fanatic_purifiers
					civic = civic_cutthroat_politics
				}
				species = last_created_species
				ethos = {
					ethic = ethic_fanatic_xenophobe
					ethic = ethic_militarist
				}
				flag = {
					icon = {
						category = "domination"
						file = "domination_1.dds"
					}
					background= {
						category = backgrounds
						file = "v.dds"
					}
					colors = {
						"teal"
						"orange"
						"null"
						"null"
					}
				}
				type = default
				exclude_day_zero_contact = root #will not establish contact with this country or its federation allies
				effect = {
					establish_communications_no_message = root
					save_global_event_target_as = time_loop_country
					species = {
						save_global_event_target_as = time_loop_species
					}
					root = {
						every_federation_ally = {
							establish_communications = event_target:time_loop_country
						}
					}
					##Copy technology
					IF = {
						LIMIT = {
							any_neighbor_country = {
								exists = this
								is_country_type = default
							}
						}
						random_neighbor_country = {
							limit = { is_country_type = default }
							save_event_target_as = tech_country
						}
						copy_techs_from = {
							target = event_target:tech_country
							except = {
								# Horizon Signal
								tech_akx_worm_1
								tech_akx_worm_2
								tech_akx_worm_3
							}
						}
					}
					ELSE_IF = {
						LIMIT = {
							any_country = {
								is_ai = no
							}
						}
						random_country = {
							limit = { is_ai = no }
							save_event_target_as = tech_country
						}
						copy_techs_from = {
							target = event_target:tech_country
							except = {
								# Horizon Signal
								tech_akx_worm_1
								tech_akx_worm_2
								tech_akx_worm_3
							}
						}
					}
					ELSE = {
						random_country = {
							limit = { is_country_type = default	}
							save_event_target_as = tech_country
						}
						copy_techs_from = {
							target = event_target:tech_country
							except = {
								# Horizon Signal
								tech_akx_worm_1
								tech_akx_worm_2
								tech_akx_worm_3
							}
						}
					}
					IF = {
						limit = {
							from = {
								has_technology = tech_maulers
							}
						}
						give_technology = { tech = tech_corvettes }
						give_technology = { tech = tech_torpedoes_1 }

					}
					IF = {
						limit = {
							event_target:tech_country = {
								has_technology = tech_weavers
							}
						}
						give_technology = { tech = tech_destroyers }
					}
					IF = {
						limit = {
							event_target:tech_country = {
								has_technology = tech_stingers
							}
						}
						give_technology = { tech = tech_battleships }
					}
					IF = {
						limit = {
							event_target:tech_country = {
								has_technology = tech_harbingers
							}
						}
						give_technology = { tech = tech_cruisers }
					}
					##Add some new technologies
					inverted_switch = {
						trigger = has_technology
						tech_starbase_2 = { give_technology = { tech = tech_starbase_2 } }
						tech_starbase_3 = { give_technology = { tech = tech_starbase_3 } }
						tech_starbase_4 = { give_technology = { tech = tech_starbase_4 } }
						tech_starbase_5 = { give_technology = { tech = tech_starbase_5 } }
						tech_power_plant_4 = { give_technology = { tech = tech_power_plant_4 } }
						tech_mining_3 = { give_technology = { tech = tech_mining_3 } }
						tech_power_hub_1 = { give_technology = { tech = tech_power_hub_1 } }
					}

					##Add resources
					add_resource = { minerals = 10000 }
					add_resource = { energy = 10000 }
					add_resource = { food = 3000 }
					add_resource = { consumer_goods = 3000 }
					add_resource = { alloys = 7000 }
					add_resource = { influence = 1000 }
					add_resource = { unity = 27000 }

					##Create fleets
					if = {
						limit = {
							has_technology = tech_destroyers
						}
						create_fleet = {
							effect = {
								set_owner = event_target:time_loop_country
								while = {
									count = 8
									create_ship = {
										name = random
										random_existing_design = destroyer
										graphical_culture = "reptilian_01"
									}
								}
								set_location = {
									target = event_target:time_loop_world
									distance = 10
									angle = random
								}
							}
						}
					}
					if = {
						limit = {
							has_technology = tech_cruisers
						}
						create_fleet = {
							effect = {
								set_owner = event_target:time_loop_country
								while = {
									count = 6
									create_ship = {
										name = random
										random_existing_design = cruiser
										graphical_culture = "reptilian_01"
									}
								}
								set_location = {
									target = event_target:time_loop_world
									distance = 10
									angle = random
								}
							}
						}
					}
					if = {
						limit = {
							has_technology = tech_battleships
						}
						create_fleet = {
							effect = {
								set_owner = event_target:time_loop_country
								while = {
									count = 2
									create_ship = {
										name = random
										random_existing_design = battleship
										graphical_culture = "reptilian_01"
									}
								}
								set_location = {
									target = event_target:time_loop_world
									distance = 10
									angle = random
								}
							}
						}
					}
					create_fleet = {
						effect = {
							set_owner = event_target:time_loop_country
							while = {
								count = 10
								create_ship = {
									name = random
									random_existing_design = corvette
									graphical_culture = "reptilian_01"
								}
							}
						}
					}
				}
			}

			set_owner = event_target:time_loop_country
			set_timed_carrier_flag = {
				flag = ignore_ai_building_limitations
				days = 1
			}
			set_capital = yes
			while = {
				count = 52
				create_pop_group = {
					species = event_target:time_loop_species
				}
			}

			while = {
				count = 3
				add_district_and_planet_size_if_needed_effect = {
					district = district_city
				}
			}
			while = {
				count = 4
				add_district_and_planet_size_if_needed_effect = {
					district = district_farming
				}
			}
			while = {
				count = 4
				add_district_and_planet_size_if_needed_effect = {
					district = district_mining
				}
			}
			while = {
				count = 6
				add_district_and_planet_size_if_needed_effect = {
					district = district_generator
				}
			}
			add_building = building_system_capital
			add_building = building_research_lab_1
			add_building = building_foundry_1
			add_building = building_food_processing_facility
			add_building = building_energy_grid
			add_building = building_mineral_purification_plant
			add_building = building_bureaucratic_1
			add_building = building_bureaucratic_1

			while = {
				count = 10
				create_army = {
					name = random
					owner = event_target:time_loop_country
					species = event_target:time_loop_species
					type = defense_army
				}
			}
			solar_system = {
				event_target:time_loop_country = {
					inverted_switch = {
						trigger = has_technology
						tech_starbase_3 = {
							prev = {
								create_starbase = {
									size = starbase_starport
									module = shipyard
									module = shipyard
									owner = event_target:time_loop_country
								}
							}
						}
						tech_starbase_4 = {
							prev = {
								create_starbase = {
									size = starbase_starhold
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									owner = event_target:time_loop_country
								}
							}
						}
						tech_starbase_5 = {
							prev = {
								create_starbase = {
									size = starbase_starfortress
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									owner = event_target:time_loop_country
								}
							}
						}
						default = {
							prev = {
								create_starbase = {
									size = starbase_citadel
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									module = shipyard
									owner = event_target:time_loop_country
								}
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = distar.2038.a
	}
}


##### THE ENIGMATIC CACHE ######

event = {
	id = distar.2050
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		has_distar = yes
		NOT = {
			any_system = {
				has_star_flag = enigmatic_cache_system
			}
		}
		any_playable_country = {
			is_ai = no
		}
	}
	immediate = {
		# spawn tube by random gateway
		random_system = {
			limit = {
				any_system_megastructure = {
					OR = {
						is_megastructure_type = gateway_ruined
						is_megastructure_type = gateway_restored
						is_megastructure_type = gateway_final
						is_megastructure_type = lgate_base
					}
				}
			}
			star = {
				carrier_event = { id = distar.20501 }
			}
		}
	}
}

carrier_event = {
	id = distar.20501
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		# Finding a target planet to scan and spawning enigmatic cache system
		if = {
			limit = {
				any_system = {
					exists = owner
					owner = {
						is_country_type = default
						is_at_war = no
					}
					any_system_planet = {
						exists = owner
						owner = { is_country_type = default }
						NOT = { has_carrier_flag = has_been_scanned }
					}
				}
			}
			if = {
				limit = {
					any_system = {
						exists = owner
						owner = {
							is_ai = no
							is_country_type = default
							is_at_war = no
						}
						any_system_planet = {
							exists = owner
							owner = { is_country_type = default }
							NOT = { has_carrier_flag = has_been_scanned }
						}
					}
				}
				closest_system = {
					limit = {
						exists = owner
						owner = {
							is_country_type = default
							is_at_war = no
							is_ai = no
						}
						any_system_planet = {
							exists = owner
							owner = { is_country_type = default }
							NOT = { has_carrier_flag = has_been_scanned }
						}
					}
					random_system_planet = {
						limit = {
							exists = owner
							owner = { is_country_type = default }
							NOT = { has_carrier_flag = has_been_scanned }
						}
						#set_carrier_flag = has_been_scanned
						save_event_target_as = new_location
						solar_system = { set_star_flag = enigmatic_cache_system }
					}
				}
			}
			else = {
				closest_system = {
					limit = {
						exists = owner
						owner = {
							is_country_type = default
							is_at_war = no
						}
						any_system_planet = {
							exists = owner
							owner = { is_country_type = default }
							NOT = { has_carrier_flag = has_been_scanned }
						}
					}
					random_system_planet = {
						limit = {
							exists = owner
							owner = { is_country_type = default }
							NOT = { has_carrier_flag = has_been_scanned }
						}
						#set_carrier_flag = has_been_scanned
						save_event_target_as = new_location
						solar_system = { set_star_flag = enigmatic_cache_system }
					}
				}
			}
		}
		else = {
			closest_system = {
				limit = {
					exists = owner
					owner = {
						is_country_type = default
					}
					any_system_planet = {
						exists = owner
					}
				}
				random_system_planet = {
					limit = { exists = owner }
					#set_carrier_flag = has_been_scanned
					save_event_target_as = new_location
					solar_system = { set_star_flag = enigmatic_cache_system }
				}
			}
		}
		create_country = {
			name = "NAME_enigmatic_cache"
			type = enigmatic_cache
			flag = {
				icon = {
					category = spherical
					file = flag_spherical_4.dds
				}
				background = {
					category = backgrounds
					file = "00_solid.dds"
				}
				colors = {
					"black"
					"black"
					"null"
					"null"
				}
			}
			effect = {
				save_global_event_target_as = enigmatic_cache_country
			}
		}
		event_target:enigmatic_cache_country = {
			set_graphical_culture = guardian_01
			create_enigmatic_cache_fleet = yes
		}
		every_country = {
			establish_communications_no_message = event_target:enigmatic_cache_country
		}
	}
}

# when clear_auto_move_on_arrival is set to no the fleet will return to planet even if its orbit is interrupted until it is given another auto_move order.

# ON arrival to its new target the Enigmatic Cache "scans the planet"
country_event = {
	id = distar.5054
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			has_fleet_flag = enigmatic_cache_fleet
		}
		NOT = { has_global_flag = cache_returned }
	}
	immediate = {
		if = {
			limit = {
				from.orbit = {
					is_colony = yes
				}
			}
			from.orbit = {
				if = {
					limit = {
						NOT = {
							has_modifier = enigmatic_cache_in_orbit
						}
					}
					add_modifier = {
						modifier = enigmatic_cache_in_orbit
					}
				}
				carrier_event = { id = distar.5057 }
			}
		}
		# Sets new location for cache
		country_event = { id = distar.5052 days = 3600 } #In effect, sets a duration for the Cache's planet-scanning modifiers.
	}
}

# Notification the first time the cache scans one of your planets
carrier_event = {
	id = distar.5057
	title = distar.5057.name
	desc = distar.5057.desc
	picture = GFX_evt_enigmatic_cache
	show_sound = event_mystic_reveal
	location = Root

	is_triggered_only = yes
	trigger = {
		exists = owner
		owner = {
			NOT = {
				has_country_flag = discovered_enigmatic_cache
			}
		}
	}

	immediate = {
		if = {
			limit = {
				root.owner = {
					is_xenophobe = yes
				}
			}
			every_owned_pop_group = {
				limit = {
					is_xenophobe = yes
				}
				add_modifier = {
					modifier = enigmatic_cache_in_orbit_phobe
					days = -1
				}
			}
		}
		owner = { set_country_flag = discovered_enigmatic_cache }
	}

	option = {
		name = distar.5057.a
		enable_special_project = {
			name = "ENIGMATIC_CACHE_PROJECT"
			location = root
			owner = root.owner
		}
	}

	option = {
		name = distar.5057.b
		owner = {
			add_resource = { influence = 50 }
		}
	}
}

# Enigmatic Cache Project Followup
country_event = {
	id = distar.5058
	title = distar.5058.name
	desc = distar.5058.desc
	picture = GFX_evt_enigmatic_cache
	show_sound = event_mystic_reveal
	location = fromfrom

	is_triggered_only = yes

	immediate = {
		set_country_flag = lcluster_clue_desc_1
	}
	option = {
		name = distar.5058.a
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}
		hidden_effect = {
			pop_lcluster_event = yes
		}
	}
}


# Enigmatic Cache moves if it can find a new location
country_event = {
	id = distar.5052
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_global_flag = cache_returned
			any_controlled_ship = {
				has_ship_flag = enigmatic_cache_ship
				exists = orbit
				exists = orbit.owner
				orbit.owner = {
					is_researching_special_project = ENIGMATIC_CACHE_PROJECT
				}
			}
		}
	}

	immediate = {
	# Runs check to remove enigmatic_cache_in_orbit modifier
		random_controlled_ship = {
			limit = {
				has_ship_flag = enigmatic_cache_ship
				exists = orbit
			}
			orbit = {
				carrier_event = { id = distar.5056 days = 2 }
				save_event_target_as = cache_present_location
				if = {
					limit = {
						exists = owner
					}
					owner = { save_event_target_as = enigmatic_cache_present_host }
				}
				# sets 'scanned' planet flag on present location
				if = {
					limit = {
						NOT = {
							has_carrier_flag = has_been_scanned
						}
					}
					set_carrier_flag = has_been_scanned
				}
			}
		}
		# Cache searches for new location:
		# Tries to find a player controlled country
		if = {
			limit = {
				any_playable_country = {
					is_ai = no
					is_at_war = no
					NOR = {
						is_hostile = root
						root = { is_hostile = prev }
					}
					any_owned_planet = {
						NOT = { has_carrier_flag = has_been_scanned }
					}
				}
			}
			random_controlled_ship = {
				limit = {
					has_ship_flag = enigmatic_cache_ship
				}
				solar_system = {
					closest_system = {
						use_bypasses = yes
						limit = {
							exists = owner
							owner = {
								is_ai = no
								is_country_type = default
								is_at_war = no
								NOR = {
									is_hostile = root
									root = { is_hostile = prev }
								}
							}
							NOT = {
								any_fleet_in_system = {
									exists = owner
									owner = {
										is_hostile = root
									}
								}
							}
							any_system_planet = {
								is_colony = yes
								NOT = { has_carrier_flag = has_been_scanned }
							}
						}
						random_system_planet = {
							limit = {
								is_colony = yes
								NOT = { has_carrier_flag = has_been_scanned }
							}
							save_event_target_as = new_location
						}
					}
				}
				auto_move_to_planet = {
					target = event_target:new_location
					clear_auto_move_on_arrival = no	# distar. sets a new auto move target
				}
			}
		}
		else_if = {
			limit = {
				any_playable_country = {
					is_at_war = no
					NOR = {
						is_hostile = root
						root = { is_hostile = prev }
					}
					any_owned_planet = {
						NOT = { has_carrier_flag = has_been_scanned }
					}
				}
			}
			random_controlled_ship = {
				limit = {
					has_ship_flag = enigmatic_cache_ship
				}
				solar_system = {
					closest_system = {
						use_bypasses = yes
						limit = {
							exists = owner
							owner = {
								is_country_type = default
								is_at_war = no
								NOR = {
									is_hostile = root
									root = { is_hostile = prev }
								}
							}
							any_system_planet = {
								is_colony = yes
								NOT = { has_carrier_flag = has_been_scanned }
							}
						}
						random_system_planet = {
							limit = {
								is_colony = yes
								NOT = { has_carrier_flag = has_been_scanned }
							}
							#set_carrier_flag = has_been_scanned
							save_event_target_as = new_location
						}
					}
				}
				auto_move_to_planet = {
					target = event_target:new_location
					clear_auto_move_on_arrival = no	# istar. sets a new auto move target
				}
			}
		}

		# Attempts to move again later if no suitable location
		else = {
			country_event = { id = distar.5052 days = 100 }
		}
		# Set flag if cache is moving to planet within same country
		if = {
			limit = {
				exists = event_target:new_location
				exists = event_target:enigmatic_cache_present_host
				event_target:new_location = { is_owned_by = event_target:enigmatic_cache_present_host }
				NOT = {
					has_country_flag = enigmatic_cache_host_country
				}
			}
			event_target:enigmatic_cache_present_host = {
				set_country_flag = enigmatic_cache_host_country
			}
		}
		# remove flag if cache is moving to planet in different country
		else_if = {
			limit = {
				OR = {
					NOT = { exists = event_target:new_location }
					NOT = {
						event_target:new_location = {
							owner = {
								exists = event_target:enigmatic_cache_present_host
								is_same_value = event_target:enigmatic_cache_present_host
							}
						}
					}
				}
				has_country_flag = enigmatic_cache_host_country
			}
			event_target:enigmatic_cache_present_host = {
				remove_country_flag = enigmatic_cache_host_country
			}
		}
	}
}

# Cache leaves: removes enigmatic_cache_in_orbit modifier and triggers notification
carrier_event = {
	id = distar.5056
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = owner
		has_modifier = enigmatic_cache_in_orbit
		NOT = {
			any_fleet_in_orbit = {
				exists = owner
				owner = { is_same_value = event_target:enigmatic_cache_country }
			}
		}
	}
	immediate = {
		if = {
			limit = {
				owner = {
					has_special_project = ENIGMATIC_CACHE_PROJECT
					NOT = {
						has_country_flag = enigmatic_cache_host_country
					}
				}
				has_modifier = enigmatic_cache_in_orbit
				NOT = {
					any_fleet_in_orbit = {
						exists = owner
						owner = { is_same_value = event_target:enigmatic_cache_country }
					}
				}
			}
			owner = { abort_special_project = { type = ENIGMATIC_CACHE_PROJECT } }
		}
		remove_modifier = enigmatic_cache_in_orbit
		every_owned_pop_group = {
			limit = {
				has_modifier = enigmatic_cache_in_orbit_phobe
			}
			remove_modifier = enigmatic_cache_in_orbit_phobe
		}
		carrier_event = { id = distar.5059 days = 1 }
	}
}

# Notifies planet owner the first time the cache leaves
carrier_event = {
	id = distar.5059
	title = distar.5059.name
	desc = {
		trigger = {
			owner = {
				has_country_flag = enigmatic_cache_host_country
			}
		}
		text = distar.5059.desc.b
	}
	desc = {
		trigger = {
			owner = {
				NOT = { has_country_flag = enigmatic_cache_host_country }
			}
		}
		text = distar.5059.desc
	}
	picture = GFX_evt_enigmatic_cache
	show_sound = event_mystic_reveal
	location = this

	is_triggered_only = yes

	trigger = {
		owner = {
			NOT = {
				has_country_flag = cache_has_changed_location
			}
		}
	}

	immediate = {
		owner = {
			set_country_flag = cache_has_changed_location
		}
	}

	option = {
		name = distar.5059.a
	}
	option = {
		name = distar.5059.b
	}
}

##### Enigmatic Cache Flees
ship_event = {
	id = distar.5053
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_ship_flag = enigmatic_cache_ship
	}

	immediate = {
		From.owner = { save_event_target_as = cache_killers }
		solar_system = {
			save_event_target_as = cache_current_location
		}
		create_ambient_object = {
			location = this
			type = horror_spawn_object
		}
		# Removes enigmatic_cache_in_orbit modifier if orbiting a planet
		if = {
			limit = {
				exists = orbit
				orbit = {
					has_modifier = enigmatic_cache_in_orbit
				}
			}
			orbit = {
				remove_modifier = enigmatic_cache_in_orbit
				every_owned_pop_group = {
					limit = {
						OR = {
							has_modifier = enigmatic_cache_in_orbit_phobe
						}
					}
					remove_modifier = enigmatic_cache_in_orbit_phobe
				}
				# Aborts enigmatic research project
				if = {
					limit = {
						owner = {
							has_special_project = ENIGMATIC_CACHE_PROJECT
						}
					}
					owner = { abort_special_project = { type = ENIGMATIC_CACHE_PROJECT } }
				}
			}
		}
		# Alerts Players with active Uplifting Project
		if = {
			limit = {
				any_playable_country = {
					is_researching_special_project = ENIGMATIC_UPLIFTING
					NOT = { is_same_value = FROM } # Aggressor is not country that is being uplifted
				}
			}
			random_playable_country = {
				limit = {
					is_researching_special_project = ENIGMATIC_UPLIFTING
				}
				country_event = { id = distar.5070 days = 20 }
			}
		}
		# Removes Inactive Enigmatic Uplift Project
		if = {
			limit = {
				any_playable_country = {
					has_special_project = ENIGMATIC_UPLIFTING
				}
			}
			random_playable_country = {
				limit = { has_special_project = ENIGMATIC_UPLIFTING }
				abort_special_project = { type = ENIGMATIC_UPLIFTING }
			}
			delete_ship = this
			break = yes # If the cache is interrupted while uplifting it will never come back.
		}

		# Finds another country to scan
		if = {
			limit = {
				any_playable_country = {
					is_at_war = no
					NOT = { is_hostile = root.owner }
					any_owned_planet = {
						NOT = { has_carrier_flag = has_been_scanned }
						solar_system = {
							NOT = {
								is_same_value = event_target:cache_current_location
							}
						}
					}
				}
			}
			closest_system = {
				limit = {
					exists = owner
					owner = {
						is_at_war = no
						NOT = { is_hostile = root.owner }
					}
					any_system_planet = {
						is_colony = yes
						NOT = { has_carrier_flag = has_been_scanned }
					}
				}
				random_system_planet = {
					limit = {
						is_colony = yes
						NOT = { has_carrier_flag = has_been_scanned }
						solar_system = {
							NOT = {
								is_same_value = event_target:cache_current_location
							}
						}
					}
					save_event_target_as = new_location
					solar_system = {
						set_star_flag = enigmatic_cache_system
					}
				}
			}
			create_enigmatic_cache_fleet = yes
		}
		# Finds a gateway if there are no viable countries
		else_if = {
			limit = {
				any_system = {
					any_system_megastructure = {
						OR = {
							is_megastructure_type = gateway_ruined
							is_megastructure_type = gateway_restored
							is_megastructure_type = gateway_final
						}
					}
					NOT = {
						is_same_value = event_target:cache_current_location
					}
				}
			}
			closest_system = {
				limit = {
					any_system_megastructure = {
						OR = {
							is_megastructure_type = gateway_ruined
							is_megastructure_type = gateway_restored
							is_megastructure_type = gateway_final
						}
					}
					NOT = {
						is_same_value = event_target:cache_current_location
					}
				}
				random_system_megastructure = {
					limit = {
						OR = {
							is_megastructure_type = gateway_ruined
							is_megastructure_type = gateway_restored
							is_megastructure_type = gateway_final
						}
					}
					save_event_target_as = new_location
					solar_system = {
						set_star_flag = enigmatic_cache_system
					}
				}
			}
			create_enigmatic_cache_fleet = yes
		}
		# Finds a random system without an owner
		else_if = {
			limit = {
				any_system = {
					has_owner = no
					NOR = {
						has_star_flag = guardian
						has_star_flag = hostile_system
						is_same_value = event_target:cache_current_location
					}
				}
			}
			closest_system = {
				limit = {
					has_owner = no
					NOR = {
						has_star_flag = guardian
						has_star_flag = hostile_system
						is_same_value = event_target:cache_current_location
					}
				}
				random_system_planet = {
					limit = {
						has_owner = no
					}
					save_event_target_as = new_location
					solar_system = {
						set_star_flag = enigmatic_cache_system
					}
				}
			}
			create_enigmatic_cache_fleet = yes
		}
		# Tries to spawn again later if it can't find good target location
		else = {
			owner = { country_event = { id = distar.5055 days = 500 } }
		}
		delete_ship = this
	}
}

# Attempts to create new enigmatic cache at safe location
country_event = {
	id = distar.5055
	hide_window = yes

	is_triggered_only = yes

	trigger = {
	# Shouldn't trigger if the enigmatic cache country already has an enigmatic cache in rotation
		NOT = {
			any_controlled_ship = {
				has_ship_flag = enigmatic_cache_ship
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_playable_country = {
					is_ai = no
					is_at_war = no
					NOT = { is_hostile = root.owner }
					any_owned_planet = {
						NOT = { has_carrier_flag = has_been_scanned }
					}
				}
			}
			closest_system = {
				limit = {
					exists = owner
					owner = {
						is_ai = no
						is_at_war = no
						NOT = { is_hostile = root.owner }
					}
					any_system_planet = {
						is_colony = yes
						NOT = { has_carrier_flag = has_been_scanned }
					}
				}
				random_system_planet = {
					limit = {
						is_colony = yes
						NOT = { has_carrier_flag = has_been_scanned }
					}
					save_event_target_as = new_location
					solar_system = {
						set_star_flag = enigmatic_cache_system
					}
				}
			}
			create_enigmatic_cache_fleet = yes
		}
		# A gateway
		else_if = {
			limit = {
				any_system = {
					any_system_megastructure = {
						OR = {
							is_megastructure_type = gateway_ruined
							is_megastructure_type = gateway_restored
							is_megastructure_type = gateway_final
							is_megastructure_type = lgate_base
						}
					}
				}
			}
			closest_system = {
				limit = {
					any_system_megastructure = {
						OR = {
							is_megastructure_type = gateway_ruined
							is_megastructure_type = gateway_restored
							is_megastructure_type = gateway_final
							is_megastructure_type = lgate_base
						}
					}
				}
				random_system_megastructure = {
					limit = {
						OR = {
							is_megastructure_type = gateway_ruined
							is_megastructure_type = gateway_restored
							is_megastructure_type = gateway_final
							is_megastructure_type = lgate_base
						}
					}
					save_event_target_as = new_location
					solar_system = {
						set_star_flag = enigmatic_cache_system
					}
				}
			}
			create_enigmatic_cache_fleet = yes
		}
		# A non hostile system without an owner
		else_if = {
			limit = {
				any_system = {
					has_owner = no
					NOR = {
						has_star_flag = guardian
						has_star_flag = hostile_system
					}
				}
			}
			random_system = {
				limit = {
					has_owner = no
					NOR = {
						has_star_flag = guardian
						has_star_flag = hostile_system
					}
				}
				random_system_planet = {
					limit = {
						has_owner = no
					}
					save_event_target_as = new_location
					solar_system = {
						set_star_flag = enigmatic_cache_system
					}
				}
			}
			create_enigmatic_cache_fleet = yes
		}
		else = {
			country_event = { id = distar.5055 days = 500 }
		}
	}
}

#### THE ENIGMATIC CACHE RETURNS ####

event = {
	id = distar.5060
	hide_window = yes

	is_triggered_only = yes

	trigger = {
	### There are no other player empires that are eligible for scanning
		exists = event_target:enigmatic_cache_country
		NOR = {
			has_global_flag = cache_returned
			any_playable_country = {
				NOT = {
					any_owned_planet = {
						is_colony = yes
						has_carrier_flag = has_been_scanned
					}
				}
				NOR = {
					is_hostile = event_target:enigmatic_cache_country
					event_target:enigmatic_cache_country = { is_hostile = prev }
				}
				is_at_war = no
			}
		}
		### There is a player empire that has already been scanned
		any_playable_country = {
			any_owned_pop_group = {
				is_same_species = owner_species
				is_robot_pop_group = no
				is_sapient = yes
				NOT = { has_trait = trait_machine_unit }
			}
			any_owned_planet = {
				is_colony = yes
				has_carrier_flag = has_been_scanned
			}
			NOR = {
				is_hostile = event_target:enigmatic_cache_country
				event_target:enigmatic_cache_country = { is_hostile = prev }
			}
			is_at_war = no
			is_ai = no
		}
	}
	immediate = {
	# Attempts to find a player empire with no other technologically inferior empires
		if = {
			limit = {
				any_playable_country = {
					any_owned_pop_group = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOT = { has_trait = trait_machine_unit }
					}
					NOT = {
						any_playable_country = {
							is_country_type = default
							relative_power = {
								who = prev
								category = technology
								value <= inferior
							}
						}
					}
					any_owned_planet = {
						is_colony = yes
						has_carrier_flag = has_been_scanned
					}
					NOR = {
						is_hostile = event_target:enigmatic_cache_country
						event_target:enigmatic_cache_country = { is_hostile = prev }
					}
					is_at_war = no
					is_ai = no
				}
			}
			random_playable_country = {
				limit = {
					any_owned_pop_group = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOT = { has_trait = trait_machine_unit }
					}
					NOT = {
						any_playable_country = {
							is_country_type = default
							relative_power = {
								who = prev
								category = technology
								value <= inferior
							}
						}
					}
					any_owned_planet = {
						is_colony = yes
						has_carrier_flag = has_been_scanned
					}
					NOR = {
						is_hostile = event_target:enigmatic_cache_country
						event_target:enigmatic_cache_country = { is_hostile = prev }
					}
					is_at_war = no
					is_ai = no
				}
				save_global_event_target_as = enigmatic_caches_choice
				set_country_flag = enigmatic_caches_choice
				random_owned_planet = {
					limit = {
						is_homeworld = yes
					}
					save_event_target_as = new_location
				}
			}
			set_global_flag = cache_returned
			event_target:enigmatic_cache_fleet = {
				set_fleet_flag = cache_returning
				auto_move_to_planet = {
					target = event_target:new_location
					clear_auto_move_on_arrival = no
				}
			}
		}
		# Attempts to find a player empire regardless of technology level
		else_if = {
			limit = {
				any_playable_country = {
					any_owned_pop_group = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOT = { has_trait = trait_machine_unit }
					}
					any_owned_planet = {
						is_colony = yes
						has_carrier_flag = has_been_scanned
					}
					NOR = {
						is_hostile = event_target:enigmatic_cache_country
						event_target:enigmatic_cache_country = { is_hostile = prev }
					}
					is_at_war = no
					is_ai = no
				}
			}
			random_playable_country = {
				limit = {
					any_owned_pop_group = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOT = { has_trait = trait_machine_unit }
					}
					any_owned_planet = {
						is_colony = yes
						has_carrier_flag = has_been_scanned
					}
					NOR = {
						is_hostile = event_target:enigmatic_cache_country
						event_target:enigmatic_cache_country = { is_hostile = prev }
					}
					is_at_war = no
					is_ai = no
				}
				save_global_event_target_as = enigmatic_caches_choice
				set_country_flag = enigmatic_caches_choice
				random_owned_planet = {
					limit = {
						is_homeworld = yes
					}
					save_event_target_as = new_location
				}
			}
			set_global_flag = cache_returned
			event_target:enigmatic_cache_fleet = {
				set_fleet_flag = cache_returning
				auto_move_to_planet = { # Triggers distar.5061 from on_action
					target = event_target:new_location
					clear_auto_move_on_arrival = no
				}
			}
		}
	}
}
# Triggers Cache Return Notification
country_event = {
	id = distar.5061
	hide_window = yes

	is_triggered_only = yes
	trigger = {
		from = {
			has_fleet_flag = cache_returning
		}
		NOT = {
			any_playable_country = {
				has_country_flag = caches_choice_notified
			}
		}
	}

	immediate = {
		random_playable_country = {
			limit = {
				has_country_flag = enigmatic_caches_choice
			}
			country_event = { id = distar.5062 }
			set_country_flag = caches_choice_notified
		}
	}
}

# Cache Return Notification

country_event = {
	id = distar.5062
	title = "distar.5062.name"
	desc = "distar.5062.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	option = {
		name = distar.5062.a
		country_event = { id = distar.5064 }
	}
	option = {
		name = distar.5062.b
	}
}

# Cache Transmission
country_event = {
	id = distar.5064
	title = "distar.5064.name"
	desc = "distar.5064.desc"
	location = root.capital_scope
	trackable = yes

	diplomatic = yes

	is_triggered_only = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	option = {
		name = distar.5064.a
		response_text = distar.5064.a.response
		is_dialog_only = yes
	}
	option = {
		name = distar.5064.b
		response_text = distar.5064.b.response
		is_dialog_only = yes
	}
	option = {
		name = distar.5064.c
		response_text = distar.5064.c.response
		is_dialog_only = yes
	}
	option = {
		name = distar.5064.d
		response_text = distar.5064.d.response
		is_dialog_only = yes
	}
	option = {
		name = distar.5064.e
		trigger = {
			is_wilderness_empire = no # The wilderness cannot be uplifted
		}
		response_text = distar.5064.e.response
		custom_tooltip = distar.5064.e.tooltip
		enable_special_project = {
			name = "ENIGMATIC_UPLIFTING"
			location = root.capital_scope
			owner = root
		}
	}
	option = {
		name = distar.5064.f
		response_text = distar.5064.f.response
	}
}
# Gatekeeper - triggers Enigmatic Dreams
country_event = {
	id = distar.5066
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = triggered_enigmatic_dreams }
	}

	immediate = {
		country_event = { id = distar.5067 days = 60 random = 20 }
		random_list = {
			50 = { # if players are unintelligent things may go poorly
				modifier = {
					factor = 0
					owner_species = {
						OR = {
							has_trait = trait_intelligent
							has_trait = trait_erudite
							has_trait = trait_artificial_intelligence
							has_trait = trait_quick_learners
						}
					}
				}
				set_country_flag = enigmatically_unlucky
			}

			50 = { }
		}
	}
}
# Enigmatic Dreams
country_event = {
	id = distar.5067
	title = "distar.5067.name"
	desc = {
		trigger = {
			NOT = { has_country_flag = enigmatically_unlucky }
		}
		text = distar.5067.desc.a
	}
	desc = {
		trigger = {
			has_country_flag = enigmatically_unlucky
		}
		text = distar.5067.desc.b
	}
	picture = GFX_evt_surreal_visions
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	trigger = {
		is_researching_special_project = ENIGMATIC_UPLIFTING
		NOT = { has_country_flag = triggered_enigmatic_dreams }
	}
	immediate = {
		set_country_flag = triggered_enigmatic_dreams
		country_event = { id = distar.5071 days = 70 random = 20 }
	}
	option = {
		name = distar.5067.a
		custom_tooltip = distar.5067.a.tooltip
		trigger = {
			has_country_flag = enigmatically_unlucky
		}
		hidden_effect = {
			set_country_flag = enigmatic_fatigue
			while = {
				limit = {
					any_owned_pop_group = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOR = {
							has_modifier = enigmatic_fatigue
							has_trait = trait_machine_unit
						}
					}
				}
				count = 60
				weighted_random_owned_pop_group = {
					limit = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOR = {
							has_modifier = enigmatic_fatigue
							has_trait = trait_machine_unit
						}
					}
					add_modifier = {
						modifier = enigmatic_fatigue
					}
				}
			}
		}
	}
	option = {
		name = distar.5067.b
		trigger = {
			has_country_flag = enigmatically_unlucky
		}
		hidden_effect = {
			set_country_flag = aborted_enigmatic_uplift
		}
	}
	option = {
		name = FASCINATING
		trigger = {
			NOT = { has_country_flag = enigmatically_unlucky }
		}
	}
}
# Cache breaks
country_event = {
	id = distar.5071
	title = "distar.5071.name"
	desc = "distar.5071.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	trigger = {
		is_researching_special_project = ENIGMATIC_UPLIFTING
	}

	immediate = {
		set_country_flag = enigmatic_cache_broken
		set_country_flag = enigmatic_slumber
		while = {
			limit = {
				any_owned_pop_group = {
					is_same_species = owner_species
					is_robot_pop_group = no
					is_sapient = yes
					NOR = {
						has_modifier = enigmatic_slumber
						has_trait = trait_machine_unit
					}
				}
			}
			count = 4
			weighted_random_owned_pop_group = {
				limit = {
					is_same_species = owner_species
					is_robot_pop_group = no
					is_sapient = yes
					NOR = {
						has_modifier = enigmatic_slumber
						has_trait = trait_machine_unit
					}
				}
				if = {
					limit = {
						has_modifier = enigmatic_fatigue
					}
					remove_modifier = enigmatic_fatigue
				}
				add_modifier = {
					modifier = enigmatic_slumber
					days = -1
				}
			}
		}
	}
	option = {
		name = distar.5071.a
		custom_tooltip = distar.5071.tooltip
		country_event = { id = distar.5072 }
	}
# Repair Cache
	option = {
		name = distar.5071.b
		enable_special_project = {
			name = "ENIGMATIC_REPAIR"
			location = root.capital_scope
			owner = root
		}
		custom_tooltip = "distar.5071.tooltip"
	}
# Abort Ascension
	option = {
		name = distar.5071.c
		hidden_effect = {
			set_country_flag = aborted_enigmatic_uplift
			country_event = { id = distar.5069 days = 2 }
			every_owned_pop_group = {
				limit = {
					has_modifier = enigmatic_slumber
				}
				remove_modifier = enigmatic_slumber
			}
			every_owned_pop_group = {
				limit = {
					has_modifier = enigmatic_fatigue
				}
				remove_modifier = enigmatic_fatigue
			}
		}
	}

	option = {
		name = distar.5071.d
		custom_tooltip = "distar.5071.tooltip"
	}
}

# Broken Cache Transmission
country_event = {
	id = distar.5072
	title = "distar.5072.name"
	desc = "distar.5072.desc"
	location = root.capital_scope
	trackable = yes

	diplomatic = yes

	is_triggered_only = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	option = {
		name = distar.5072.a
		response_text = distar.5072.response
		is_dialog_only = yes
	}
	option = {
		name = distar.5072.b
		response_text = distar.5072.b.response
		is_dialog_only = yes
	}
	option = {
		name = distar.5072.c
		response_text = distar.5072.c.response
		is_dialog_only = yes
	}
	# Abort Ascension
	option = {
		name = distar.5072.d
		response_text = distar.5064.d.response
		hidden_effect = {
			set_country_flag = aborted_enigmatic_uplift
			country_event = { id = distar.5069 days = 2 }
		}
	}
	# Repair Cache
	option = {
		name = distar.5072.e
		response_text = distar.5072.e.response
		enable_special_project = {
			name = "ENIGMATIC_REPAIR"
			location = root.capital_scope
			owner = root
		}
	}
}

# Ascension Aborted
country_event = {
	id = distar.5069
	title = "distar.5069.name"
	desc = "distar.5069.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	immediate = {
		capital_scope = {
			solar_system = {
				random_fleet_in_system = {
					limit = {
						has_fleet_flag = enigmatic_cache_fleet
					}
					delete_fleet = this
					create_ambient_object = {
						location = this
						type = horror_spawn_object
					}
				}
			}
		}
		if = {
			limit = {
				has_country_flag = enigmatic_cache_broken
			}
			remove_country_flag = enigmatic_cache_broken
		}
	}
	option = {
		name = "distar.5069.a"
	}
}

# Repair Complete
country_event = {
	id = distar.5073
	title = "distar.5073.name"
	desc = "distar.5073.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_country_flag = enigmatic_cache_broken
			}
			remove_country_flag = enigmatic_cache_broken
		}
	}

	option = {
		name = EXCELLENT
	}
}

# Enigmatic Uplift Complete - Success
country_event = {
	id = distar.5063
	title = "distar.5063.name"
	desc = "distar.5063.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	immediate = {
		every_owned_pop_group = {
			limit = {
				is_same_species = owner_species
				is_robot_pop_group = no
				is_sapient = yes
				NOT = { has_trait = trait_machine_unit }
			}
			if = {
				limit = {
					NOT = { has_trait = trait_enigmatic_intelligence }
				}
				modify_species = {
					species = this
					add_trait = trait_enigmatic_intelligence
				}
				root = { set_country_flag = applied_enigmatic_intelligence }
			}
			if = {
				limit = {
					has_trait = trait_slow_learners
				}
				modify_species = {
					species = this
					remove_trait = trait_slow_learners
				}
			}
		}
		every_owned_pop_group = {
			limit = {
				has_modifier = enigmatic_fatigue
			}
			remove_modifier = enigmatic_fatigue
		}

		every_owned_pop_group = {
			limit = {
				has_modifier = enigmatic_slumber
			}
			remove_modifier = enigmatic_slumber
		}
	}

	option = {
		name = distar.5063.a
		if = {
			limit = {
				has_country_flag = applied_enigmatic_intelligence
			}
			custom_tooltip = applied_enigmatic_intelligence.tooltip
		}
	}
}

# Enigmatic Uplift Complete - Moderate Success
country_event = {
	id = distar.5068
	title = "distar.5068.name"
	desc = "distar.5068.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	immediate = {
		every_owned_pop_group = {
			limit = {
				is_same_species = owner_species
				is_robot_pop_group = no
				is_sapient = yes
				NOT = { has_trait = trait_machine_unit }
			}
			if = {
				limit = {
					NOT = { has_trait = trait_enigmatic_intelligence }
				}
				modify_species = {
					species = this
					add_trait = trait_enigmatic_intelligence
				}
				root = { set_country_flag = applied_enigmatic_intelligence }
			}
			if = {
				limit = {
					NOT = { has_modifier = enigmatic_sadness }
				}
				add_modifier = {
					modifier = enigmatic_sadness
					days = 3600
				}
				root = { set_country_flag = applied_enigmatic_sadness }
			}
			if = {
				limit = {
					has_trait = trait_slow_learners
				}
				modify_species = {
					species = this
					remove_trait = trait_slow_learners
				}
			}
		}
		change_dominant_species = {
			species = last_created_species
			change_all = yes
		}
		every_owned_pop_group = {
			limit = {
				has_modifier = enigmatic_fatigue
			}
			remove_modifier = enigmatic_fatigue
		}
		every_owned_pop_group = {
			limit = {
				has_modifier = enigmatic_slumber
			}
			remove_modifier = enigmatic_slumber
		}
	}

	option = {
		name = distar.5068.a
		if = {
			limit = { has_country_flag = applied_enigmatic_intelligence }
			custom_tooltip = applied_enigmatic_intelligence.tooltip
		}
		if = {
			limit = { has_country_flag = applied_enigmatic_sadness }
			custom_tooltip = applied_enigmatic_sadness.tooltip
		}
	}
}

# Enigmatic Uplift Complete - Failure
country_event = {
	id = distar.5074
	title = "distar.5074.name"
	desc = "distar.5074.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	immediate = {
		every_owned_pop_group = {
			limit = {
				is_same_species = owner_species
				is_robot_pop_group = no
				is_sapient = yes
				NOT = {
					has_trait = trait_machine_unit
				}
			}
			if = {
				limit = {
					NOR = {
						has_trait = trait_enigmatic_intelligence_poor
						has_modifier = enigmatic_slumber
					}
				}
				modify_species = {
					species = this
					add_trait = trait_enigmatic_intelligence_poor
				}
				root = { set_country_flag = applied_enigmatic_intelligence_poor }
			}
			if = {
				limit = {
					NOT = {
						has_modifier = enigmatic_madness
					}
				}
				add_modifier = {
					modifier = enigmatic_madness
					days = 3600
				}
				root = { set_country_flag = applied_enigmatic_madness }
			}

			if = {
				limit = {
					has_modifier = enigmatic_slumber
				}
				modify_species = {
					species = this
					add_trait = trait_enigmatic_intelligence_failed
				}
				remove_modifier = enigmatic_slumber
				root = { set_country_flag = applied_enigmatic_intelligence_failed }
			}

			if = {
				limit = {
					has_modifier = enigmatic_fatigue
				}
				remove_modifier = enigmatic_fatigue
			}
		}

		change_dominant_species = {
			species = last_created_species
			change_all = yes
		}
		#every_owned_pop_group = {
		#	limit = {
		#		has_trait = trait_machine_unit
		#	}
		#	if = {
		#		limit = {
		#			NOT = { has_trait = trait_natural_physicists }
		#		}
		#		modify_species = {
		#			species = this
		#			add_trait = trait_natural_physicists
		#		}
		#	}
		#}
	}

	option = {
		name = distar.5074.a
		if = {
			limit = { has_country_flag = applied_enigmatic_intelligence_poor }
			custom_tooltip = applied_enigmatic_intelligence_poor.tooltip
		}
		if = {
			limit = { has_country_flag = applied_enigmatic_madness }
			custom_tooltip = applied_enigmatic_madness.tooltip
		}
		if = {
			limit = { has_country_flag = applied_enigmatic_intelligence_failed }
			custom_tooltip = trait_enigmatic_intelligence_failed.tooltip
		}
	}
}

# Cache attacked during uplift
country_event = {
	id = distar.5070
	title = "distar.5070.name"
	desc = "distar.5070.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	option = {
		name = distar.5070.a
	}
}

# Uplifting Canceled
country_event = {
	id = distar.5075
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		every_owned_pop_group = {
			limit = {
				has_modifier = enigmatic_fatigue
			}
			remove_modifier = enigmatic_fatigue
		}
		every_owned_pop_group = {
			limit = {
				has_modifier = enigmatic_slumber
			}
			remove_modifier = enigmatic_slumber
		}
	}
}

# Uplifting Resumed
country_event = {
	id = distar.5076
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_country_flag = enigmatic_fatigue
			}
			while = {
				limit = {
					any_owned_pop_group = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOR = {
							has_modifier = enigmatic_fatigue
							has_trait = trait_machine_unit
						}
					}
				}
				count = 60
				weighted_random_owned_pop_group = {
					limit = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOR = {
							has_modifier = enigmatic_fatigue
							has_trait = trait_machine_unit
						}
					}
					add_modifier = {
						modifier = enigmatic_fatigue
					}
				}
			}
		}
		if = {
			limit = {
				has_country_flag = enigmatic_slumber
			}
			while = {
				limit = {
					any_owned_pop_group = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOR = {
							has_modifier = enigmatic_slumber
							has_trait = trait_machine_unit
						}
					}
				}
				count = 4
				weighted_random_owned_pop_group = {
					limit = {
						is_same_species = owner_species
						is_robot_pop_group = no
						is_sapient = yes
						NOR = {
							has_modifier = enigmatic_slumber
							has_trait = trait_machine_unit
						}
					}
					if = {
						limit = {
							has_modifier = enigmatic_fatigue
						}
						remove_modifier = enigmatic_fatigue
					}
					add_modifier = {
						modifier = enigmatic_slumber
						days = -1
					}
				}
			}
		}
	}
}

# Aborts enigmatic uplift if capital is lost
country_event = {
	id = distar.5077
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = event_target:enigmatic_cache_country
		from = { has_special_project = ENIGMATIC_UPLIFTING }
		fromfrom = {
			is_capital = yes
			any_fleet_in_orbit = {
				exists = owner
				owner = { is_same_value = event_target:enigmatic_cache_country }
			}
		}
	}

	immediate = {
		from = {
			abort_special_project = { type = ENIGMATIC_UPLIFTING }
			country_event = { id = distar.5078 days = 10 }
		}
		if = {
			limit = {
				exists = event_target:enigmatic_cache_ship
			}
			event_target:enigmatic_cache_ship = {
				create_ambient_object = {
					location = this
					type = horror_spawn_object
				}
				set_disabled = yes
			}
		}
	}
}


country_event = {
	id = distar.5078
	title = "distar.5078.name"
	desc = "distar.5078.desc"
	picture = GFX_evt_enigmatic_cache
	show_sound = event_ship_bridge
	location = root.capital_scope
	trackable = yes

	is_triggered_only = yes

	immediate = {
	}
	option = {
		name = distar.5078.a
	}
}

# INVISIBLE DEATH
ship_event = {
	id = distar.2040
	title = "distar.2040.name"
	desc = "distar.2040.desc"
	picture = GFX_evt_ship_in_orbit_2
	show_sound = event_ship_bridge
	location = from
	trackable = yes

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
		}
	}

	option = {
		name = distar.2040.a
		hidden_effect = {
			owner.capital_scope = {
				closest_system = {
					min_steps = 2
					limit = {
						has_access_fleet = root.owner
						NOT = {
							has_star_flag = guardian
						}
						any_system_planet = {
							is_asteroid = yes
						}
					}
					random_system_planet = {
						limit = {
							is_asteroid = yes
						}
						save_event_target_as = invisible_death_lab_planet
					}
				}
			}
		}
		from = {
			enable_special_project = {
				name = "INVISIBLE_DEATH"
				location = event_target:invisible_death_lab_planet
				owner = root.owner
			}
		}
	}

	option = {
		name = distar.2040.b
		owner = { add_resource = { influence = 50 } }
	}
}

ship_event = {
	id = distar.2041
	title = "distar.2041.name"
	desc = "distar.2041.desc"
	picture = GFX_evt_derelict_interior
	show_sound = event_ship_bridge
	location = from
	trackable = yes

	is_triggered_only = yes

	option = {
		name = distar.2041.a
		custom_tooltip = distar.2041.a.tooltip
		hidden_effect = {
			owner = {
				set_country_flag = lcluster_clue_desc_3
				pop_lcluster_event = yes
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
	}
}

# GATEWAY HIJACKING
ship_event = {
	id = distar.2045
	title = "distar.2045.name"
	desc = "distar.2045.desc"
	picture = GFX_evt_drifting_gateway
	show_sound = event_ship_bridge
	location = from
	trackable = yes

	is_triggered_only = yes

	immediate = {
		owner = {
			country_event = { id = story.5 days = 30 }
		}
	}

	option = {
		name = distar.2045.a
		enable_special_project = {
			name = GATEWAY_INTERFERENCE
			location = from
			owner = root.owner
		}
	}

	option = {
		name = distar.2045.b
	}
}

ship_event = {
	id = distar.2046
	title = "distar.2046.name"
	desc = "distar.2046.desc"
	picture = GFX_evt_drifting_gateway
	show_sound = event_ship_bridge
	location = fromfrom
	trackable = yes

	is_triggered_only = yes

	option = {
		name = distar.2046.a
		owner = {
			generate_lcluster_clue = yes
		}
	}
}

#################################
#
# Anomaly Events
# by Linus Dilén
# anomaly.3000 - 3999
#
#################################

# ROOT = ship scope
# FROM = planet scope

### Trojan Asteroid ###
ship_event = {
	id = distar.3000
	title = "distar.3000.name"
	desc = "distar.3000.desc"
	picture = GFX_evt_asteroid_field
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	immediate = {
		fromfrom = {
			save_event_target_as = trojan_asteroid
			# clear deposits so as not to conflict with energy added later
			clear_deposits = yes
		}
	}

	option = {
		name = distar.3000.a
		custom_tooltip = distar.3000.a.tooltip
		hidden_effect = {
			ship_event = { id = distar.3001 }
		}
	}

	option = {
		name = distar.3000.b
		custom_tooltip = distar.3000.b.tooltip
		hidden_effect = {
			ship_event = { id = distar.3002 }
		}
	}
}

ship_event = {
	id = distar.3001
	title = "trojan_asteroid_title"
	desc = "distar.3001.desc"
	picture = GFX_evt_asteroid_field
	show_sound = event_scanner
	location = event_target:trojan_asteroid

	is_triggered_only = yes

	option = {
		name = EXCELLENT

		event_target:trojan_asteroid = {
			add_deposit = d_energy_4
		}
	}
}

ship_event = {
	id = distar.3002
	title = "trojan_asteroid_title"
	desc = "distar.3002.desc"
	picture = GFX_evt_small_space_battle
	show_sound = event_scanner
	location = event_target:trojan_asteroid

	is_triggered_only = yes

	option = {
		name = OOPS
		hidden_effect = {
			if = {
				limit = {
					# Do this only if asteroid is not within alien borders
					event_target:trojan_asteroid.solar_system = {
						OR = {
							NOT = { exists = starbase }
							AND = {
								exists = starbase
								starbase.owner = {
									is_same_value = root.owner
								}
							}
						}
					}
				}
				owner = {
					# Spawn drones to attack science ship, but give player a fair chance to escape
					country_event = { id = distar.3004 days = 15 }
					# Trigger follow-up special project, via event
					country_event = { id = distar.3003 days = 90 }
				}
			}
		}

	}
}

country_event = {
	id = distar.3003
	title = "trojan_asteroid_title"
	desc = "distar.3003.desc"
	picture = GFX_evt_small_space_battle
	show_sound = event_scanner
	location = event_target:trojan_asteroid
	trackable = yes

	is_triggered_only = yes

	option = {
		name = OK
		event_target:trojan_asteroid = {
			enable_special_project = {
				name = "trojan_asteroid_project"
				location = event_target:trojan_asteroid
				owner = root.owner
			}
		}
	}
}

country_event = {
	id = distar.3004
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		create_country = {
			name = "NAME_Ancient_Drones"
			type = faction
			flag = {
				icon = {
					category = "pirate"
					file = "flag_pirate_3.dds"
				}
				background = {
					category = "backgrounds"
					file = "00_solid.dds"
				}
				colors = {
					"black"
					"black"
					"null"
					"null"
				}
			}
			effect = {
				set_faction_hostility = {
					target = root
					set_hostile = yes
					set_neutral = no
					set_friendly = no
				}
				create_fleet = {
					name = "NAME_Ancient_Drones"
					effect = {
						set_owner = prev
						while = {
							count = 10
							create_ship = {
								design = "NAME_Ancient_Mining_Drone"
								prefix = no
								upgradable = no
							}
						}
						set_location = {
							target = event_target:trojan_asteroid
							distance = 5
							angle = random
						}
						set_fleet_stance = aggressive
						save_event_target_as = ancient_drones_fleet
					}
					settings = {
						can_upgrade = no
						can_disband = no
						can_change_composition = no
						can_change_leader = no
						uses_naval_capacity = no
						spawn_debris = no
					}
				}
			}
		}
	}
}

ship_event = {
	id = distar.3005
	title = "trojan_asteroid_title"
	desc = "distar.3005.desc"
	picture = GFX_evt_asteroid_field
	show_sound = event_scanner
	location = event_target:trojan_asteroid

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		event_target:trojan_asteroid = {
			add_deposit = d_minerals_3
		}
	}
}

### Impossible Organism ###
ship_event = {
	id = distar.3010
	title = "impossible_organism_title"
	desc = "distar.3010.desc"
	picture = GFX_evt_toxic
	show_sound = event_scanner
	location = from
	trackable = yes

	is_triggered_only = yes

	immediate = {
		fromfrom = {
			save_event_target_as = impossible_organism_planet
			# clear deposits so as not to conflict with resources added later
			if = {
				limit = { has_deposit_for = shipclass_mining_station }
				clear_deposits = yes
			}
		}

		save_event_target_as = impossible_organism_science_ship
	}

	option = { # Yes, sample it.
		name = distar.3010.a
		enable_special_project = {
			name = "impossible_organism_project_1"
			location = root.owner.capital_scope
			owner = root.owner
		}
	}

	option = { # No. Study it from afar.
		name = distar.3010.b
		custom_tooltip = distar.3010.b.tooltip
		hidden_effect = {
			event_target:impossible_organism_planet = {
				add_deposit = d_society_4
			}
		}
	}
}

country_event = { # Organism growing fast
	id = distar.3011
	title = "impossible_organism_title"
	desc = "distar.3011.desc"
	picture = GFX_evt_microscopic_life
	show_sound = event_scanner
	location = from
	trackable = yes

	is_triggered_only = yes

	option = { # Amazing. Proceed.
		name = distar.3011.a
		trigger = {
			is_xenophobe = no
		}
		enable_special_project = {
			name = "impossible_organism_project_2"
			location = root.owner.capital_scope
			owner = root.owner
		}
	}

	option = { # Phobe
		name = distar.3011.a.phobe
		trigger = {
			is_xenophobe = yes
		}
		enable_special_project = {
			name = "impossible_organism_project_2"
			location = root.owner.capital_scope
			owner = root.owner
		}
	}

	option = { # This alien is too dangerous.
		name = distar.3011.b
		custom_tooltip = distar.3011.b.tooltip
		hidden_effect = {
			country_event = { id = distar.3014 days = 1700 random = 200 }
		}
	}
}

country_event = { # It's a fungoid
	id = distar.3012
	title = "distar.3012.name"
	desc = "distar.3012.desc"
	picture = GFX_evt_microscopic_life
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	option = { # Yes, proceed.
		name = distar.3012.a
		custom_tooltip = distar.3012.a.tooltip

		hidden_effect = {
			country_event = { id = distar.3013 days = 250 random = 50 }
		}
	}

	option = { # No, we must end this.
		name = distar.3012.b
		custom_tooltip = distar.3012.b.tooltip
		hidden_effect = {
			country_event = { id = distar.3014 days = 1300 random = 200 }
		}
	}
}

country_event = { # First words
	id = distar.3013
	title = "distar.3013.name"
	desc = "distar.3013.desc"
	picture = GFX_evt_microscopic_life
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	immediate = {
		random_owned_planet = {
			weights = {
				base = 1
				modifier = {
					add = 2
					free_housing > 0
				}
				modifier = {
					add = 5
					free_housing > 100
				}
				modifier = {
					add = 10
					free_housing > 500
				}
				modifier = {
					add = 10
					free_housing > 1000
				}
				modifier = {
					add = 5
					planet_size > 17
				}
				modifier = {
					add = 5
					planet_size > 21
				}
			}
			save_event_target_as = nivlac_joint_planet

			export_trigger_value_to_variable = {
				trigger = free_housing
				variable = new_pops
			}
			divide_variable = {
				which = new_pops
				value = 100
			}
			if = {
				limit = {
					OR = {
						check_variable = {
							which = new_pops
							value < 1
						}
						check_variable = {
							which = new_pops
							value > 7
						}
					}
				}
				set_variable = {
					which = new_pops
					value = 7
				}
			}
		}
	}

	option = { # Astonishing. Every species-X should have one!
		trigger = {
			is_xenophile = yes
		}

		allow = {
			#any_owned_planet = {
			#	free_housing > 0
			#}
		}

		name = distar.3013.a.xenophile
		custom_tooltip = distar.3013.a.tooltip

		hidden_effect = {
			create_nivlac_effect = yes
			event_target:nivlac_joint_planet = {
				while = {
					count = new_pops
					create_pop_group = {
						species = event_target:nivlac_species
					}
				}
			}
			country_event = { id = distar.3017 days = 10 }
		}
	}

	option = { # Excellent. Species-X society could use them.
		trigger = {
			NOR = {
				is_xenophile = yes
				has_ethic = ethic_gestalt_consciousness
			}
		}

		allow = {
			#any_owned_planet = {
			#	free_housing > 0
			#}
		}

		name = distar.3013.a
		custom_tooltip = distar.3013.a.tooltip

		hidden_effect = {
			create_nivlac_effect = yes
			event_target:nivlac_joint_planet = {
				while = {
					count = new_pops
					create_pop_group = {
						species = event_target:nivlac_species
					}
				}
			}
			country_event = { id = distar.3017 days = 10 }
		}
	}

	option = { # Servitor
		trigger = {
			has_civic = civic_machine_servitor
		}

		allow = {
			#any_owned_planet = {
			#	free_housing > 0
			#}
		}

		name = "distar.3013.a.serv"
		custom_tooltip = "distar.3013.a.tooltip"

		hidden_effect = {
			create_nivlac_effect = yes
			event_target:nivlac_joint_planet = {
				while = {
					count = new_pops
					create_pop_group = {
						species = event_target:nivlac_species
					}
				}
			}
			country_event = { id = distar.3017 days = 10 }
		}
	}

	option = { # Assimilator
		trigger = {
			has_civic = civic_machine_assimilator
		}

		allow = {
			#any_owned_planet = {
			#	free_housing > 0
			#}
		}

		name = "distar.3013.a.assi"
		custom_tooltip = "distar.3013.a.assi.tooltip"

		hidden_effect = {
			create_nivlac_effect = yes
			event_target:nivlac_species = {
				set_species_flag = nivlac_no_procreation # checked in can_species_procreate game rule
			}
			event_target:nivlac_joint_planet = {
				while = {
					count = new_pops
					create_pop_group = {
						species = event_target:nivlac_species
					}
				}
			}
			country_event = { id = distar.3017 days = 10 }
		}
	}

	option = { # No room, Assimilator
		name = "distar.3013.b.no_room.kill"
		custom_tooltip = "distar.3013.b.no_room.kill.tooltip"

		trigger = {
			has_civic = civic_machine_assimilator
		}
		add_monthly_resource_mult = {
			resource = influence
			value = @tier3influencereward
			min = @tier3influencemin
			max = @tier3influencemax
		}
	}

	option = { # Let's find them a home.
		name = "distar.3013.b"
		custom_tooltip = distar.3013.b.tooltip
		trigger = {
			NOT = { has_civic = civic_machine_assimilator }
		}
		hidden_effect = {
			country_event = { id = distar.3016 days = 720 random = 100 }
		}
	}

	after = {
		hidden_effect = {
			event_target:nivlac_joint_planet = {
				clear_variable = new_pops
			}
		}
	}
}

country_event = { # Planetfall on planet X after being shoot into deep space. Recalls our earlier disregard for their survival
	id = distar.3014
	title = "distar.3015.name"
	desc = "distar.3015.desc"
	picture = GFX_evt_alien_city
	show_sound = event_scanner
	location = event_target:nivlac_planet

	is_triggered_only = yes

	trigger = {
		any_system = {
			any_system_planet = {
				is_colonizable = yes
				has_owner = no
				is_colony = no
				habitable_planet = yes
				has_anomaly = no
				NOR = {
					has_modifier = "holy_planet"
					solar_system = {
						has_star_flag = hostile_system
					}
				}
				distance = {
					source = root.owner.capital_scope
					max_distance <= 300
					min_distance >= 50
				}
				solar_system = {
					NOT = { exists = starbase }
				}
			}
		}
	}

	immediate = {
		random_galaxy_planet = {
			limit = {
				is_colonizable = yes
				has_owner = no
				is_colony = no
				habitable_planet = yes
				has_anomaly = no
				NOR = {
					has_modifier = "holy_planet"
					solar_system = {
						has_star_flag = hostile_system
					}
				}
				distance = {
					source = root.owner.capital_scope
					max_distance <= 300
					min_distance >= 50
				}
				solar_system = {
					NOT = { exists = starbase }
				}
			}
			save_global_event_target_as = nivlac_planet
		}
		create_nivlac_effect = yes
		create_country = {
			name = NAME_Nivlac_Circle
			authority = random
			civics = random
			species = event_target:nivlac_species
			ignore_initial_colony_error = yes
			type = default
			ethos = random
			flag = random
			effect = {
				save_global_event_target_as = nivlac_country
				add_resource = { minerals = 1000 }
				add_resource = { energy = 1000 }
				add_resource = { food = 100 }
				add_resource = { influence = 50 }
			}
		}
		event_target:nivlac_planet = {
			solar_system = {
				create_starbase = {
					size = starbase_outpost
					owner = event_target:nivlac_country
				}
			}
			set_owner = event_target:nivlac_country
			set_timed_carrier_flag = {
				flag = ignore_ai_building_limitations
				days = 1
			}
			set_capital = yes
			clear_blockers = yes
			solar_system = {
				every_system_planet = {
					set_surveyed = {
						surveyed = yes
						surveyor = root.owner
					}
				}
			}
			while = {
				count = 22
				create_pop_group = {
					species = event_target:nivlac_species
				}
			}

			while = {
				count = 2
				add_district_and_planet_size_if_needed_effect = {
					district = district_city
				}
			}
			while = {
				count = 3
				add_district_and_planet_size_if_needed_effect = {
					district = district_farming
				}
			}
			while = {
				count = 2
				add_district_and_planet_size_if_needed_effect = {
					district = district_generator
				}
			}
			add_building = building_capital
			add_building = building_research_lab_1
			add_building = building_foundry_1
			add_building = building_bureaucratic_1

			while = {
				count = 2
				create_army = {
					name = random
					owner = event_target:nivlac_country
					species = event_target:nivlac_species
					type = defense_army
				}
			}
		}

		event_target:nivlac_country = {
			establish_communications_no_message = root
			add_opinion_modifier = {
				who = root
				modifier = opinion_discarded
			}
		}
	}

	option = {
		name = OOPS
	}
	after = {
		give_specimen = {
			key = declaration_of_animosity
			targets = { event_target:nivlac_country event_target:nivlac_species event_target:impossible_organism_planet this }
		}
	}
}

country_event = { # Helpful relocation was a success
	id = distar.3016
	title = "distar.3016.name"
	desc = "distar.3016.desc"
	picture = GFX_evt_alien_city
	show_sound = event_scanner
	location = event_target:nivlac_planet

	is_triggered_only = yes

	trigger = {
		any_system = {
			any_system_planet = {
				is_colonizable = yes
				has_owner = no
				is_colony = no
				habitable_planet = yes
				has_anomaly = no
				NOR = {
					has_modifier = "holy_planet"
					solar_system = {
						has_star_flag = hostile_system
					}
				}
				distance = {
					source = root.owner.capital_scope
					max_distance <= 300
					min_distance >= 50
				}
				solar_system = {
					NOT = { exists = starbase }
				}
			}
		}
	}

	immediate = {
		random_galaxy_planet = {
			limit = {
				is_colonizable = yes
				has_owner = no
				is_colony = no
				habitable_planet = yes
				has_anomaly = no
				NOR = {
					has_modifier = "holy_planet"
					solar_system = {
						has_star_flag = hostile_system
					}
				}
				distance = {
					source = root.owner.capital_scope
					max_distance <= 300
					min_distance >= 50
				}
				solar_system = {
					NOT = { exists = starbase }
				}
			}
			save_global_event_target_as = nivlac_planet
		}
		create_nivlac_effect = yes
		create_country = {
			name = NAME_Nivlac_Circle
			authority = random
			civics = random
			species = event_target:nivlac_species
			ignore_initial_colony_error = yes
			type = default
			ethos = random
			flag = random
			effect = {
				save_global_event_target_as = nivlac_country
				add_resource = { minerals = 1000 }
				add_resource = { energy = 1000 }
				add_resource = { food = 100 }
				add_resource = { influence = 50 }
				establish_communications_no_message = root
			}
		}
		event_target:nivlac_planet = {
			solar_system = {
				create_starbase = {
					size = starbase_outpost
					owner = event_target:nivlac_country
				}
			}
			set_owner = event_target:nivlac_country
			set_timed_carrier_flag = {
				flag = ignore_ai_building_limitations
				days = 1
			}
			set_capital = yes
			clear_blockers = yes
			while = {
				count = 22
				create_pop_group = {
					species = event_target:nivlac_species
				}
			}

			while = {
				count = 2
				add_district_and_planet_size_if_needed_effect = {
					district = district_city
				}
			}
			while = {
				count = 3
				add_district_and_planet_size_if_needed_effect = {
					district = district_farming
				}
			}
			while = {
				count = 2
				add_district_and_planet_size_if_needed_effect = {
					district = district_mining
				}
			}
			add_building = building_capital
			add_building = building_research_lab_1
			add_building = building_foundry_1
			add_building = building_bureaucratic_1

			while = {
				count = 2
				create_army = {
					name = random
					owner = event_target:nivlac_country
					species = event_target:nivlac_species
					type = defense_army
				}
			}
			solar_system = {
				every_system_planet = {
					set_surveyed = {
						surveyed = yes
						surveyor = root.owner
					}
				}
			}
		}
		event_target:nivlac_country = {
			add_opinion_modifier = {
				who = root
				modifier = opinion_nurtured
			}
		}
	}

	option = {
		name = EXCELLENT
	}
	after = {
		give_specimen = {
			key = declaration_of_friendship
			targets = { event_target:nivlac_country event_target:nivlac_planet event_target:nivlac_species this }
		}
	}
}

country_event = { # Releasing fungoids into society as pops was successful
	id = distar.3017
	title = "distar.3017.name"
	desc = {
		trigger = {
			NOR = {
				has_civic = civic_machine_assimilator
				has_civic = civic_machine_servitor
			}
		}
		text = "distar.3017.desc"
	}
	desc = {
		trigger = {
			has_civic = civic_machine_assimilator
		}
		text = "distar.3017.desc.assim"
	}
	picture = GFX_evt_colony_settlement
	show_sound = event_scanner
	location = event_target:nivlac_joint_planet

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		custom_tooltip = distar.3017.a.tooltip
	}
	option = {
		exclusive_trigger = {
			has_civic = civic_machine_assimilator
		}
		name = EXCELLENT
		custom_tooltip = distar.3017.a.assi.tooltip
	}
	option = {
		exclusive_trigger = {
			has_civic = civic_machine_servitor
		}
		name = EXCELLENT
		custom_tooltip = distar.3017.a.serv.tooltip
	}
}

### Stranded Scientist ###
ship_event = {
	id = distar.3020
	title = "distar.3020.name"
	desc = "distar.3020.desc"
	picture = GFX_evt_exploding_ship
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	immediate = {
		from = {
			save_event_target_as = stranded_scientist_asteroid
		}
		save_global_event_target_as = stranded_scientist_science_ship

		create_species = {
			name = random
			class = HUM
			portrait = "human"
			namelist = "HUM1"
			traits = random
			effect = {
				save_event_target_as = stranded_scientist_species
			}
		}
		create_country = {
			name = random
			type = faction
			flag = {
				icon = {
					category = "special"
					file = "unknown.dds"
				}
				background = {
					category = "backgrounds"
					file = "00_solid.dds"
				}
				colors = {
					"blue"
					"blue"
					"null"
					"null"
				}
			}
			effect = {
				save_event_target_as = stranded_scientist_country
			}
		}
		event_target:stranded_scientist_country = {
			create_leader = {
				class = scientist
				species = event_target:stranded_scientist_species
				name = random
				event_leader = yes
				leader_age_min = 30
				leader_age_max = 50
				randomize_traits = no
			}
		}
		last_created_leader = {
			add_trait = {
				trait = trait_ruler_eye_for_talent
				consume_selection = yes
			}
			add_trait = {
				trait = leader_trait_spark_of_genius_2
				consume_selection = yes
			}
			add_trait = {
				trait = subclass_scientist_councilor
				consume_selection = yes
			}
			add_trait = {
				trait = leader_trait_expertise_computing_2
				consume_selection = yes
			}
			set_gender = female
			save_global_event_target_as = stranded_scientist_leader
			exile_leader_as = stranded_scientist_leader
		}
	}

	option = { # Granted
		name = distar.3020.a
		custom_tooltip = distar.3020.a.tooltip

		hidden_effect = {
			owner = {
				clone_leader = {
					target = event_target:stranded_scientist_leader
					class = scientist
					background_planet = event_target:stranded_scientist_asteroid
					custom_description = "stranded_scientist_background"
					effect = {
						set_skill = 6
						save_global_event_target_as = stranded_scientist_leader_clone
					}
				}
				country_event = { id = distar.3021 days = 60 }
			}
			event_target:stranded_scientist_leader = {
				kill_leader = { class = scientist show_notification = no }
			}
		}
	}

	option = { # No. Leave her.
		name = distar.3020.b
		custom_tooltip = distar.3020.b.tooltip

		random_list = {
			1 = {
				leader = {
					add_trait = {
						trait = leader_trait_adaptable
					}
				}
			}
			1 = {
				leader = {
					add_trait = {
						trait = leader_trait_paranoid
					}
				}
			}
		}

		hidden_effect = {
			event_target:stranded_scientist_leader = {
				kill_leader = { class = scientist show_notification = no }
			}
		}
	}
}

country_event = {
	id = distar.3021
	title = "distar.3021.name"
	desc = "distar.3021.desc"
	picture = GFX_evt_physics_research
	show_sound = event_scanner
	location = from

	trigger = {
		exists = event_target:stranded_scientist_leader_clone
	}

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		custom_tooltip = distar.3021.a.tooltip

		hidden_effect = {
			set_variable = { which = picked_tech value = 0 }
			if = {
				limit = {
					has_technology = tech_automated_exploration
					has_technology = tech_synchronized_defences
					has_technology = tech_sensors_3
				}
				add_monthly_resource_mult = {
					resource = physics_research
					value = @tier4researchreward
					min = @tier4researchmin
					max = @tier4researchmax
				}
			}
			else = {
				while = {
					limit = {
						check_variable = {
							which = picked_tech
							value < 2
						}
					}
					random_list = {
						1 = {
							modifier = {
								factor = 0
								has_technology = tech_automated_exploration
							}
							give_technology = { tech = tech_automated_exploration }
						}
						1 = {
							modifier = {
								factor = 0
								has_technology = tech_synchronized_defences
							}
							give_technology = { tech = tech_synchronized_defences }
						}
						1 = {
							modifier = {
								factor = 0
								has_technology = tech_sensors_3
							}
							give_technology = { tech = tech_sensors_3 }
						}
					}
					change_variable = { which = "picked_tech" value = 1 }
				}
			}
		}
	}
}


### Molluscoid Miners ###
ship_event = {
	id = distar.3030
	title = "distar.3030.name"
	desc = "distar.3030.desc"
	picture = GFX_evt_alien_cavemen
	show_sound = event_scanner
	location = from
	trackable = yes

	is_triggered_only = yes

	immediate = {
		fromfrom = {
			save_event_target_as = molluscoid_miners_planet
		}
	}

	option = { # Intriguing. Study them further.
		name = distar.3030.a

		enable_special_project = {
			name = "molluscoid_miners_project_1"
			location = event_target:molluscoid_miners_planet
			owner = root.owner
		}
	}

	option = { # Mine their minerals.
		name = distar.3030.b
		owner = {
			add_monthly_resource_mult = {
				resource = minerals
				value = @tier1materialreward
				min = @tier1materialmin
				max = @tier1materialmax
			}
			IF = {
				limit = {
					is_xenophile = yes
				}
				add_modifier = {
					modifier = disregard_for_alien_life
					days = 360
				}
			}
		}
	}

}

country_event = { # More info about the molluscs
	id = distar.3031
	title = "distar.3030.name"
	desc = "distar.3031.desc"
	picture = GFX_evt_alien_cavemen
	show_sound = event_scanner
	location = from
	trackable = yes

	is_triggered_only = yes

	option = { # Yes. Proceed with the integration.
		trigger = {		# Prevents Genocidal Empires from integrating molluscs
			is_homicidal = no
		}

		name = distar.3031.a

		enable_special_project = {
			name = "molluscoid_miners_project_2"
			location = root.owner.capital_scope
			owner = root.owner
		}
	}

	option = { # Yes. Proceed with the integration.
		trigger = {		# Prevents Genocidal Empires from integrating molluscs
			has_origin = origin_evolutionary_predators
			values_others = no
		}
		name = distar.3031.a.evopre
		give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = medium TYPE = molluscoid }
	}

	option = { # Yes, use this knowledge (to further our technology)
		name = distar.3031.b

		enable_special_project = {
			name = "molluscoid_miners_project_3"
			location = root.owner.capital_scope
			owner = root.owner
		}
	}

	option = { # No. Mine their planet.
		name = distar.3031.c
		add_monthly_resource_mult = {
			resource = minerals
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		IF = {
			limit = {
				is_xenophile = yes
			}
			add_modifier = {
				modifier = disregard_for_alien_life
				days = 360
			}
		}
	}
}

country_event = { # Integration into our society complete
	id = distar.3032
	title = "distar.3032.name"
	desc = "distar.3032.desc"
	picture = GFX_evt_colony_settlement
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	immediate = {
		create_species = {
			name = random
			class = MOL
			portrait = "mol6"
			namelist = "MOL2"
			traits = {
				trait = "trait_slow_learners"
				trait = "trait_industrious"
				trait = "trait_uplifted"
			}
			homeworld = root.capital_scope
			effect = {
				save_global_event_target_as = molluscoid_miners_species
			}
		}
		capital_scope = {
			while = {
				count = 6
				# housing cache doesn't update frequently enough atm
				#limit = {
				#	free_housing > 0
				#}
				create_pop_group = {
					species = event_target:molluscoid_miners_species
				}
			}
		}
		#else = {
		#	set_country_flag = no_space_for_miners
		#}
	}

	option = {
		name = EXCELLENT
		custom_tooltip = distar.3032.a.tooltip
		#trigger = {
		#	hidden_trigger = {
		#		NOT = { has_country_flag = no_space_for_miners }
		#	}
		#}
	}

	#option = {
	#	name = distar.3032.b
	#	custom_tooltip = distar.3032.b.tooltip
		#trigger = {
		#	hidden_trigger = {
		#		has_country_flag = no_space_for_miners
		#	}
		#}
	#}
	after = {
		give_specimen = {
			key = high_geode_of_the_molluscoids
			targets = { event_target:molluscoid_miners_species this }
		}
	}
}

country_event = { # Mineral mapping system implemented
	id = distar.3033
	title = "distar.3033.name"
	desc = "distar.3033.desc"
	picture = GFX_evt_physics_research
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		add_modifier = {
			modifier = mineral_mapping
			days = -1
		}
	}
}

### Alien Machine ###
ship_event = {
	id = distar.3040
	title = "distar.3040.name"
	desc = "distar.3040.desc"
	picture = GFX_evt_synth_sabotage
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	immediate = {
		from = { save_event_target_as = asteroid_target }
		event_target:asteroid_target = {
			clear_deposits = yes
		}
		save_event_target_as = unknown_machine_science_ship
		solar_system = { save_event_target_as = sol_sys }
	}

	option = { # Pull the lever
		name = distar.3040.a
		custom_tooltip = distar.3040.a.tooltip
		hidden_effect = {
			owner.capital_scope = {
				if = {
					limit = {
						closest_system = {
							limit = {
								has_natural_wormhole = no
								is_surveyed = { who = root.owner status = yes }
							}
							min_steps = 2
							max_steps = 8
							#exists = this
						}
						closest_system = {
							limit = {
								has_natural_wormhole = no
							}
							min_steps = 15
							max_steps = 50
							#exists = this
						}
					}
					closest_system = {
						limit = {
							has_natural_wormhole = no
							is_surveyed = { who = root.owner status = yes }
						}
						min_steps = 2
						max_steps = 8
						save_event_target_as = system_one
					}
					closest_system = {
						limit = {
							has_natural_wormhole = no
						}
						min_steps = 15
						max_steps = 50
						save_event_target_as = system_two
					}
					root.owner = { country_event = { id = distar.3042 days = 1 } }
				}
				else = { root = { ship_event = { id = distar.3041 days = 1 } } }
			}
		}
	}

	option = { # Take it apart.
		name = distar.3040.b
		custom_tooltip = distar.3040.b.tooltip
		owner = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
			add_monthly_resource_mult = {
				resource = minerals
				value = @tier1materialreward
				min = @tier1materialmin
				max = @tier1materialmax
			}
		}
	}
}

ship_event = {
	id = distar.3041
	title = "distar.3041.name"
	desc = "distar.3041.desc"
	picture = GFX_evt_binary_stars
	show_sound = event_scanner
	location = fromfrom

	is_triggered_only = yes

	option = { # How strange. Take it apart.
		name = distar.3041.a
		custom_tooltip = distar.3040.b.tooltip
		leader = { add_experience = 800 }
		owner = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier4researchreward
				min = @tier4researchmin
				max = @tier4researchmax
			}
			add_monthly_resource_mult = {
				resource = minerals
				value = @tier1materialreward
				min = @tier1materialmin
				max = @tier1materialmax
			}
		}
	}

	option = { # Intriguing. Research it further.
		name = distar.3041.b
		custom_tooltip = distar.3041.b.tooltip
		leader = { add_experience = 800 }
		hidden_effect = {
			event_target:asteroid_target = {
				add_deposit = d_physics_7
			}
		}
	}
}

country_event = { # Spike in energy readings from a nearby solar system observed
	id = distar.3042
	title = "distar.3042.name"
	desc = "distar.3042.desc"
	picture = GFX_evt_wormhole
	show_sound = event_scanner
	location = event_target:system_one

	is_triggered_only = yes

	trigger = {
		exists = event_target:system_one
	}

	immediate = {
		event_target:system_one = {
			event_target:system_two = {
				prev = {
					spawn_natural_wormhole = {
						bypass_type = wormhole
						random_pos = yes
						orbit_angle = 360
					}
				}
				spawn_natural_wormhole = {
					bypass_type = wormhole
					random_pos = yes
					orbit_angle = 360
				}
				link_wormholes = prev
			}
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = distar.3043 days = 3 }
		}
	}

	option = { # How strange. Take it apart.
		name = distar.3041.a
		custom_tooltip = distar.3040.b.tooltip
		from = {
			leader = { add_experience = 800 }
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
		add_monthly_resource_mult = {
			resource = minerals
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
	}

	option = { # Intriguing. Research it further.
		name = distar.3041.b
		custom_tooltip = distar.3041.b.tooltip
		from = {
			leader = { add_experience = 800 }
		}
		hidden_effect = {
			event_target:asteroid_target = {
				add_deposit = d_physics_7
			}
		}
	}
}

### Possible First Wormhole Encountered event due to event distar.3042
country_event = {
	id = distar.3043
	title = apoc.5.name
	desc = "apoc.5.desc"
	picture = GFX_evt_wormhole
	show_sound = event_radio_chatter
	location = event_target:system_one

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_origin = origin_shroudwalker_apprentice
			has_country_flag = encountered_first_wormhole
		}
	}

	immediate = {
		event_target:system_one = {
			save_event_target_as = wormhole_system
		}
		set_country_flag = encountered_first_wormhole
		add_seen_bypass_type = wormhole
	}

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

### Orbital Speed Demon ###
ship_event = {
	id = distar.3050
	title = "distar.3050.name"
	desc = "distar.3050.desc"
	picture = GFX_evt_ship_in_orbit
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	immediate = {
		from = {
			save_event_target_as = speed_demon_orbit_body
		}
	}

	option = { # Try to slow it down.
		name = distar.3050.a
		custom_tooltip = distar.3050.a.tooltip
		hidden_effect = {
			ship_event = { id = distar.3051 days = 5 }
		}
	}

	option = { # Attempt to halt it.
		name = distar.3050.b
		custom_tooltip = distar.3050.b.tooltip
		hidden_effect = {
			ship_event = { id = distar.3051 days = 5 }
			owner = { set_country_flag = option_2 }
		}
	}

	option = { # Get away from it.
		name = distar.3050.c
		custom_tooltip = distar.3050.c.tooltip
		leader = { add_experience = 200 }
	}
}

ship_event = { # Success
	id = distar.3051
	title = "distar.3051.name"
	desc = {
		trigger = {
			hidden:owner = {
				switch = {
					trigger = has_country_flag
					option_2 = { text = distar.3051.desc.1 }
					default = { text = distar.3051.desc }
				}
			}
		}
	}
	inline_script = {
		script = events/biogenesis_event_art
		OWNER = owner
		REGULAR_PICTURE = GFX_evt_ship_in_orbit
		BIOSHIP_PICTURE = GFX_evt_bio_ships_orbiting
	}
	show_sound = event_scanner
	trackable = yes

	is_triggered_only = yes

	option = { # Open it.
		name = distar.3051.a
		enable_special_project = {
			name = "speed_demon_open_box_project"
			location = root.owner.capital_scope
			owner = root.owner
		}
	}

	option = { # Learn more about it.
		name = distar.3051.b
		enable_special_project = {
			name = "speed_demon_learn_more_project"
			location = root.owner.capital_scope
			owner = root.owner
		}
		hidden_effect = {
			owner = { set_country_flag = alien_box_researched }
		}
	}

	option = { # Get rid of it.
		name = distar.3051.c
		custom_tooltip = distar.3051.c.tooltip
		leader = { add_experience = 300 }
	}
}

country_event = { # Alien Box opened
	id = distar.3055
	title = "distar.3055.name"
	desc = {
		trigger = {
			hidden:owner = {
				switch = {
					trigger = has_country_flag
					alien_box_researched = { text = distar.3055.desc.1 }
					default = { text = distar.3055.desc }
				}
			}
		}
	}
	picture = GFX_evt_genetic_modification
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	option = { # Use the red solution
		allow = {
			is_natural_design_empire = no
		}
		name = distar.3055.a
		custom_tooltip = distar.3055.a.tooltip
		hidden_effect = {
			add_red_solution = yes
			country_event = { id = distar.3057 days = 5 }
		}
	}

	option = { # Use the green solution
		allow = {
			is_natural_design_empire = no
		}
		name = distar.3055.b
		custom_tooltip = distar.3055.b.tooltip
		hidden_effect = {
			add_green_solution = yes
			country_event = { id = distar.3057 days = 5 }
		}
	}

	option = { # Use the blue solution
		allow = {
			is_natural_design_empire = no
		}
		name = distar.3055.c
		custom_tooltip = distar.3055.c.tooltip
		hidden_effect = {
			add_blue_solution = yes
			country_event = { id = distar.3057 days = 5 }
		}
	}

	option = {
		allow = {
			is_natural_design_empire = no
		}
		name = distar.3055.d.evopred
		custom_tooltip = distar.3055.d.evopred.tooltip
		hidden_effect = {
			random_list = {
				50 = {
					add_red_solution = yes
					add_green_solution = yes
					add_blue_solution = yes
					country_event = { id = distar.3057 days = 5 }
					remove_country_flag = strong_removed_verystrong_added
					remove_country_flag = weak_removed_strong_added
					remove_country_flag = verystrong_added
					remove_country_flag = adaptive_removed_extremelyadaptive_added
					remove_country_flag = nonadaptive_removed_adaptive_added
					remove_country_flag = extremelyadaptive_added
					remove_country_flag = enduring_removed_venerable_added
					remove_country_flag = fleeting_removed_enduring_added
					remove_country_flag = venerable_added
					set_country_flag = modification_all
				}
				50 = {
					country_event = { id = distar.3057 days = 5 }
				}
			}
		}
	}

	option = { # Sell them
		name = distar.3055.d
		custom_tooltip = distar.3055.d.tooltip
		add_monthly_resource_mult = {
			resource = energy
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		add_monthly_resource_mult = {
			resource = minerals
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
	}

	after = {
		hidden_effect = {
			update_node_portraits_if_gestalt_effect = yes
		}
		give_specimen = {
			key = centrifugal_container
			targets = { from }
		}
	}
}

country_event = { # Alien Box researched
	id = distar.3056
	title = "distar.3056.name"
	desc = "distar.3056.desc"
	picture = GFX_evt_physics_research
	show_sound = event_scanner
	location = from
	trackable = yes

	is_triggered_only = yes

	option = { # Open it.
		name = distar.3056.a
		enable_special_project = {
			name = "speed_demon_open_box_project"
			location = root.owner.capital_scope
			owner = root.owner
		}
		custom_tooltip = distar.3056.a.tooltip
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { # Sell it.
		trigger = {
			is_gestalt = no
		}
		name = distar.3056.b
		custom_tooltip = distar.3056.b.tooltip
		add_monthly_resource_mult = {
			resource = energy
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_monthly_resource_mult = {
			resource = minerals
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		custom_tooltip = distar.3056.a.tooltip
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier3researchreward
			min = @tier3researchmin
			max = @tier3researchmax
		}
	}
	option = { # Irradiate it.
		trigger = {
			is_gestalt = yes
		}
		name = distar.3056.c

		custom_tooltip = distar.3056.c.tooltip
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
	}
}

country_event = { # Genetic modifications applied
	id = distar.3057
	title = "distar.3057.name"
	desc = {
		trigger = {
			hidden:owner = {
				switch = {
					trigger = has_country_flag
					modification_all = { text = distar.3057.desc.all }
					modification_red = { text = distar.3057.desc.stronger }
					modification_green = { text = distar.3057.desc.adaptive }
					modification_blue = { text = distar.3057.desc.longlived }
					default = { text = distar.3057.desc }
				}
			}
		}
	}
	picture = GFX_evt_genetic_modification
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = strong_removed_verystrong_added
		}
		hidden_effect = { remove_country_flag = strong_removed_verystrong_added }
		tooltip = {
			modify_species = {
				species = this
				#remove_trait = trait_strong
				add_trait = trait_social_pheromones
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = weak_removed_strong_added
		}
		hidden_effect = { remove_country_flag = weak_removed_strong_added }
		tooltip = {
			modify_species = {
				species = this
				#remove_trait = trait_weak
				add_trait = trait_social_pheromones
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = verystrong_added
		}
		hidden_effect = { remove_country_flag = verystrong_added }
		tooltip = {
			modify_species = {
				species = this
				add_trait = trait_social_pheromones
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = adaptive_removed_extremelyadaptive_added
		}
		hidden_effect = { remove_country_flag = adaptive_removed_extremelyadaptive_added }
		tooltip = {
			modify_species = {
				species = this
				#remove_trait = trait_adaptive
				add_trait = trait_bioadaptability
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = nonadaptive_removed_adaptive_added
		}
		hidden_effect = { remove_country_flag = nonadaptive_removed_adaptive_added }
		tooltip = {
			modify_species = {
				species = this
				#remove_trait = trait_nonadaptive
				add_trait = trait_bioadaptability
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = extremelyadaptive_added
		}
		hidden_effect = { remove_country_flag = extremelyadaptive_added }
		tooltip = {
			modify_species = {
				species = this
				add_trait = trait_bioadaptability
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = enduring_removed_venerable_added
		}
		hidden_effect = { remove_country_flag = enduring_removed_venerable_added }
		tooltip = {
			modify_species = {
				species = this
				#remove_trait = trait_enduring
				add_trait = trait_limited_regeneration
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = fleeting_removed_enduring_added
		}
		hidden_effect = { remove_country_flag = fleeting_removed_enduring_added }
		tooltip = {
			modify_species = {
				species = this
				#remove_trait = trait_fleeting
				add_trait = trait_limited_regeneration
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = venerable_added
		}
		hidden_effect = { remove_country_flag = venerable_added }
		tooltip = {
			modify_species = {
				species = this
				add_trait = trait_limited_regeneration
			}
		}
	}

	option = {
		name = EXCELLENT
		exclusive_trigger = {
			has_country_flag = modification_all
		}
		hidden_effect = { remove_country_flag = modification_all }
		tooltip = {
			modify_species = {
				species = this
				add_trait = trait_limited_regeneration
				add_trait = trait_bioadaptability
				add_trait = trait_social_pheromones
			}
		}
	}

	option = {
		name = EXCELLENT
		trigger = {
			NOR = {
				has_country_flag = strong_removed_verystrong_added
				has_country_flag = weak_removed_strong_added
				has_country_flag = verystrong_added
				has_country_flag = adaptive_removed_extremelyadaptive_added
				has_country_flag = nonadaptive_removed_adaptive_added
				has_country_flag = extremelyadaptive_added
				has_country_flag = enduring_removed_venerable_added
				has_country_flag = fleeting_removed_enduring_added
				has_country_flag = venerable_added
			}
		}
	}
}

### Breathing Rift ###
ship_event = {
	id = distar.3060
	title = "distar.3060.name"
	desc = "distar.3060.desc"
	picture = GFX_evt_wormhole
	show_sound = event_scanner
	location = from

	is_triggered_only = yes

	immediate = {
		from = {
			save_event_target_as = breathing_rift_object
		}
	}

	option = { # Keep close watch until we know more.
		name = distar.3060.a
		custom_tooltip = distar.3060.a.tooltip
		enable_special_project = {
			name = "breathing_rift_project"
			location = root.owner.capital_scope
			owner = root.owner
		}
	}

	option = { # It can be studied from a safe distance.
		name = distar.3060.b
		event_target:breathing_rift_object = {
			add_deposit = d_physics_4
		}
	}

	option = { # Leave now.
		name = distar.3060.c
		leader = { add_experience = 300 }
	}
}

country_event = {
	id = distar.3061
	title = "distar.3061.name"
	desc = {
		trigger = {
			hidden:owner = {
				switch = {
					trigger = has_country_flag
					rift_spew_done = { text = distar.3061.desc.repeat }
					default = { text = distar.3061.desc }
				}
			}
		}
	}
	picture = GFX_evt_asteroid_field
	show_sound = event_scanner
	location = event_target:breathing_rift_object

	is_triggered_only = yes

	option = { # Excellent. Collect them swiftly.
		name = distar.3061.a
		add_monthly_resource_mult = {
			resource = minerals
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		hidden_effect = {
			random_list = {
				25 = { country_event = { id = distar.3061 days = 100 random = 100 } }
				25 = { country_event = { id = distar.3062 days = 100 random = 100 } }
				50 = { country_event = { id = distar.3064 days = 100 random = 50 } }
			}
			set_country_flag = rift_spew_done
		}
	}
}

country_event = {
	id = distar.3062
	title = "distar.3062.name"
	desc = {
		trigger = {
			hidden:owner = {
				switch = {
					trigger = has_country_flag
					rift_spew_done = { text = distar.3062.desc.repeat }
					default = { text = distar.3062.desc }
				}
			}
		}
	}
	picture = GFX_evt_space_debris
	show_sound = event_scanner
	location = event_target:breathing_rift_object

	is_triggered_only = yes

	option = { # Excellent. Collect it swiftly.
		name = distar.3062.a
		add_monthly_resource_mult = {
			resource = energy
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier1researchreward
			min = @tier1researchmin
			max = @tier1researchmax
		}
		hidden_effect = {
			random_list = {
				25 = { country_event = { id = distar.3061 days = 100 random = 100 } }
				25 = { country_event = { id = distar.3062 days = 100 random = 100 } }
				50 = { country_event = { id = distar.3064 days = 100 random = 50 } }
			}
			set_country_flag = rift_spew_done
		}
	}
}

country_event = {
	id = distar.3064
	title = "distar.3064.name"
	desc = "distar.3064.desc"
	picture = GFX_evt_wormhole
	show_sound = event_scanner
	location = event_target:breathing_rift_object

	is_triggered_only = yes

	option = { # Unfortunate.
		name = distar.3064.a
		custom_tooltip = distar.3064.a.tooltip
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier3researchreward
			min = @tier3researchmin
			max = @tier3researchmax
		}
	}
}
