﻿namespace = asp

#a place where history has preserved #https://gall.dcinside.com/mgallery/board/view?id=stellaris&no=10399
#original motive #https://gall.dcinside.com/board/view/?id=europa&no=479503 #https://gall.dcinside.com/board/view/?id=europa&no=485460
#metallic desert
fleet_event = {
	id = asp.7
	title = "asp.7.name"
	desc = "asp.7.desc"
	picture = GFX_evt_relic_world_street
	show_sound = event_wind_ruins

	archaeology = yes

	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = {
		from = { set_site_progress_locked = no }
	}

	option = {
		name = DIG
		medium_artifact_reward = yes
	}
}
#remnants of the great war
fleet_event = {
	id = asp.8
	title = "asp.8.name"
	desc = "asp.8.desc"
	picture = GFX_evt_relic_world
	show_sound = event_ground_battle

	archaeology = yes

	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = {
		from = { set_site_progress_locked = no }
	}

	option = {
		name = DIG
		medium_artifact_reward = yes
	}
}
#huge ship with unknown purpose
fleet_event = {
	id = asp.9
	title = "asp.9.name"
	desc = "asp.9.desc"
	picture = GFX_evt_relic_shipyard
	show_sound = event_metal_fatigue

	archaeology = yes

	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = {
		from = { set_site_progress_locked = no }
	}

	option = {
		name = DIG
		medium_artifact_reward = yes
	}
}
#mysterious data storage
fleet_event = {
	id = asp.10
	title = "asp.10.name"
	desc = "asp.10.desc"
	picture = GFX_evt_ancient_databank
	show_sound = event_finding_loot

	archaeology = yes

	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = {
		from = { set_site_progress_locked = no }
	}

	option = {
		name = DIG
		from.planet = {
			hidden_effect = {
				save_global_event_target_as = asp_kessler_syndrome_world
			}
			enable_special_project = {
				name = ASP_KESSLER_SYNDROME_STORAGE_RESTORE_PROJECT
				location = THIS
				owner = root.owner
			}
		}
	}
}
#impenetrable wall
fleet_event = {
	id = asp.11
	title = "asp.11.name"
	desc = "asp.11.desc"
	picture = GFX_evt_shielded_planet
	show_sound = event_energy_field

	archaeology = yes

	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	after = {
		from = { set_site_progress_locked = no }
		if = {
			limit = { owner = { has_policy_flag = aspmod_archaeology_cleanup_active } }
			destroy_archaeological_site = from
		}
	}

	option = {
		name = asp.11.a
		medium_artifact_reward = yes
		hidden_effect = {
			from.planet = { set_planet_flag = ASP_kessler_syndrome_flag_1 }
			owner = { country_event = { id = asp.13 } }
		}
	}
}
#special project finished
country_event = {
	id = asp.12
	title = "asp.12.name"
	desc = "asp.12.desc"
	picture = GFX_evt_throne_room

	is_triggered_only = yes

	trigger = {
		exists = event_target:asp_kessler_syndrome_world
	}

	immediate = {
		event_target:asp_kessler_syndrome_world = {
			set_planet_flag = ASP_kessler_syndrome_flag_2
		}
		country_event = { id = asp.13 }
	}

	option = {
		name = asp.12.a
	}
}
country_event = {
	id = asp.13
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:asp_kessler_syndrome_world
	}

	immediate = {
		if = {
			limit = {
				event_target:asp_kessler_syndrome_world = {
					has_planet_flag = ASP_kessler_syndrome_flag_1
					has_planet_flag = ASP_kessler_syndrome_flag_2
				}
			}
			country_event = { id = asp.14 days = 10 }
		}
	}
}
country_event = {
	id = asp.14
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = { exists = event_target:asp_kessler_syndrome_world }
			event_target:asp_kessler_syndrome_world = {
				change_pc = pc_continental
				if = {
					limit = { has_global_flag = asp_kessler_syndrome_story_human_unlocked }
					set_name = "NAME_Unity"
					set_planet_entity = { entity = continental_planet_earth_entity }
				}
				clear_blockers = yes
				if = {
					limit = { has_global_flag = asp_kessler_syndrome_story_human_unlocked }
					create_species = {
						class = "HUM"
						portrait = "human"
						name = "PRESCRIPTED_species_name_humans2"
						plural = "PRESCRIPTED_species_plural_humans2"
						adjective = "PRESCRIPTED_species_adjective_humans2"
						namelist = "HUMAN2"
						traits = {
							trait = "trait_pc_continental_preference"
							trait = "trait_adaptive"
							trait = "trait_nomadic"
							trait = "trait_wasteful"
						}
						homeworld = event_target:asp_kessler_syndrome_world
						effect = { save_event_target_as = asp_kessler_syndrome_species }
					}
					else = {
						create_species = {
							class = random_non_machine
							portrait = random
							name = random
							traits = {
								trait = "trait_pc_continental_preference"
								trait = "trait_industrious"
								trait = "trait_adaptive"
								trait = "trait_deviants"
							}
							homeworld = event_target:asp_kessler_syndrome_world
							effect = { save_event_target_as = asp_kessler_syndrome_species }
						}
					}
				}
				create_country = {
					authority = auth_dictatorial
					civics = {
						civic = civic_fanatic_purifiers
						civic = civic_nationalistic_zeal
						civic = civic_distinguished_admiralty
					}
					origin = "origin_fallen_empire"
					species = event_target:asp_kessler_syndrome_species
					ethos = {
						ethic = ethic_fanatic_xenophobe
						ethic = ethic_militarist
					}
					flag = {
						icon= {
							category = "human"
							file = "flag_human_4.dds"
						}
						background= {
							category = "backgrounds"
							file = "stripe.dds"
						}
						colors={
							"red"
							"black"
							"null"
							"null"
						}
					}
					type = default
					effect = {
						if = {
							limit = { has_global_flag = asp_kessler_syndrome_story_human_unlocked }
							set_name = "asp_kessler_syndrome_empire_name"
						}
						set_graphical_culture = "humanoid_01"
						save_global_event_target_as = asp_kessler_syndrome_country
						establish_communications_no_message = root
						##Copy technology
						# Copy ownership state from the country that completed the chain.
						# The old random non-AI country picker could copy another human player's techs in multiplayer.
						copy_techs_from = {
							target = root
							except = {
								# Horizon Signal
								tech_akx_worm_1
								tech_akx_worm_2
								tech_akx_worm_3
							}
						}
						##Add some new technologies
						if = { limit = { NOT = { has_technology = tech_robotic_workers } } give_technology = { tech = tech_robotic_workers } }

						if = { limit = { NOT = { has_technology = tech_volatile_motes } } give_technology = { tech = tech_volatile_motes } }
						if = { limit = { NOT = { has_technology = tech_exotic_gases } } give_technology = { tech = tech_exotic_gases } }
						if = { limit = { NOT = { has_technology = tech_rare_crystals } } give_technology = { tech = tech_rare_crystals } }

						if = { limit = { NOT = { has_technology = tech_power_plant_2 } } give_technology = { tech = tech_power_plant_2 } }
						if = { limit = { NOT = { has_technology = tech_power_plant_3 } } give_technology = { tech = tech_power_plant_3 } }
						if = { limit = { NOT = { has_technology = tech_power_plant_4 } } give_technology = { tech = tech_power_plant_4 } }

						if = { limit = { NOT = { has_technology = tech_mining_1 } } give_technology = { tech = tech_mining_1 } }
						if = { limit = { NOT = { has_technology = tech_mining_2 } } give_technology = { tech = tech_mining_2 } }
						if = { limit = { NOT = { has_technology = tech_mining_3 } } give_technology = { tech = tech_mining_3 } }

						if = { limit = { NOT = { has_technology = tech_eco_simulation } } give_technology = { tech = tech_eco_simulation } }
						if = { limit = { NOT = { has_technology = tech_gene_crops } } give_technology = { tech = tech_gene_crops } }
						if = { limit = { NOT = { has_technology = tech_nano_vitality_crops } } give_technology = { tech = tech_nano_vitality_crops } }
						if = { limit = { NOT = { has_technology = tech_nutrient_replication } } give_technology = { tech = tech_nutrient_replication } }

						if = { limit = { NOT = { has_technology = tech_power_hub_1 } } give_technology = { tech = tech_power_hub_1 } }
						if = { limit = { NOT = { has_technology = tech_power_hub_2 } } give_technology = { tech = tech_power_hub_2 } }

						if = { limit = { NOT = { has_technology = tech_mineral_purification_1 } } give_technology = { tech = tech_mineral_purification_1 } }
						if = { limit = { NOT = { has_technology = tech_mineral_purification_2 } } give_technology = { tech = tech_mineral_purification_2 } }
						##Add resources
						add_resource = { minerals = 10000 }
						add_resource = { energy = 10000 }
						add_resource = { food = 6000 }
						add_resource = { consumer_goods = 6000 }
						add_resource = { alloys = 8000 }
						add_resource = { influence = 1000 }
						add_resource = { unity = 30000 }
						add_resource = { volatile_motes = 10000 }
						add_resource = { exotic_gases = 10000 }
						add_resource = { rare_crystals = 10000 }
					}
				}
				set_owner = event_target:asp_kessler_syndrome_country
				set_capital = yes
				clear_deposits = yes
				add_modifier = { modifier = mastery_of_nature }
				add_deposit = d_mesopotamian_urban_corridor
				add_deposit = d_boswash_metropolitan_axis
				add_deposit = d_mauritanian_security_zone
				add_deposit = d_great_albertan_crater
				add_deposit = d_scandinavian_reclamation_sector

				add_deposit = d_saharan_irrigation_project
				add_deposit = d_pearl_river_agglomerate
				add_deposit = d_great_pacific_garbage_patch
				add_deposit = d_failing_infrastructure_earth
				add_deposit = d_decrepit_dwellings

				clear_blockers = yes

				while = {
					add_district = district_city
					count = 6
				}
				while = {
					add_district = district_generator
					count = 4
				}
				while = {
					add_district = district_mining
					count = 4
				}
				while = {
					add_district = district_farming
					count = 3
				}

				add_building = building_capital
				add_building = building_research_lab_2
				add_building = building_bureaucratic_2
				add_building = building_commercial_megaplex
				add_building = building_foundry_2
				add_building = building_robot_assembly_plant

				while = {
					create_pop_group = { species = event_target:asp_kessler_syndrome_species }
					count = 46
				}
				while = {
					count = 10
					create_army = {
						name = random
						owner = event_target:asp_kessler_syndrome_country
						species = event_target:asp_kessler_syndrome_species
						type = defense_army
					}
				}
				solar_system = {
					if = {
						limit = { has_global_flag = asp_kessler_syndrome_story_human_unlocked }
						set_name = "NAME_Deneb"
						star = { set_name = "NAME_Deneb" }
					}
					random_fleet_in_system = {
						limit = {
							is_ship_class = shipclass_starbase
							is_mobile = no #starbases but not juggernauts
						}
						destroy_fleet = { target = this }
					}
					if = { #check the highest case first then the lower ones
						limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_starbase_5 } }
						create_starbase = {
							size = starbase_citadel
							module = shipyard
							module = shipyard
							building = crew_quarters
							owner = event_target:asp_kessler_syndrome_country
						}
					}
					else_if = {
						limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_starbase_4 } }
						create_starbase = {
							size = starbase_starfortress
							module = shipyard
							module = shipyard
							building = crew_quarters
							owner = event_target:asp_kessler_syndrome_country
						}
					}
					else_if = {
						limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_starbase_3 } }
						create_starbase = {
							size = starbase_starhold
							module = shipyard
							module = shipyard
							building = crew_quarters
							owner = event_target:asp_kessler_syndrome_country
						}
					}
					else_if = {
						limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_starbase_2 } }
						create_starbase = {
							size = starbase_starport
							module = shipyard
							module = shipyard
							building = crew_quarters
							owner = event_target:asp_kessler_syndrome_country
						}
					}
					else = {
						create_starbase = {
							size = starbase_outpost
							owner = event_target:asp_kessler_syndrome_country
						}
					}
					every_neighbor_system = {
						limit = {
							star = {
								OR = {
									is_planet_class = pc_b_star
									is_planet_class = pc_a_star
									is_planet_class = pc_f_star
									is_planet_class = pc_g_star
									is_planet_class = pc_k_star
									is_planet_class = pc_m_star
									is_planet_class = pc_t_star
									is_planet_class = pc_pulsar
									is_planet_class = pc_m_giant_star
									is_planet_class = pc_neutron_star
									is_planet_class = pc_black_hole
									is_binary_star = yes
									is_trinary_star = yes
								}
							}
							OR = {
								NOT = { exists = space_owner }
								space_owner = {
									NOR = {
										is_country_type = fallen_empire
										is_country_type = awakened_fallen_empire
									}
								}
							}
							NOT = { any_system_planet = { is_colony = yes } }
						}
						set_surveyed = {
							surveyed = yes
							surveyor = event_target:asp_kessler_syndrome_country
						}
						if = {
							limit = { exists = starbase }
							starbase = { set_owner = event_target:asp_kessler_syndrome_country }
							else = {
								if = {
									limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_starbase_4 } }
									create_starbase = {
										size = starbase_starfortress
										owner = event_target:asp_kessler_syndrome_country
									}
								}
								else_if = {
									limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_starbase_3 } }
									create_starbase = {
										size = starbase_starhold
										owner = event_target:asp_kessler_syndrome_country
									}
								}
								else_if = {
									limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_starbase_2 } }
									create_starbase = {
										size = starbase_starport
										owner = event_target:asp_kessler_syndrome_country
									}
								}
								else = {
									create_starbase = {
										size = starbase_outpost
										owner = event_target:asp_kessler_syndrome_country
									}
								}
							}
						}
					}
					##Create fleets
					create_fleet = {
						effect = {
							set_owner = event_target:asp_kessler_syndrome_country
							while = {
								count = 12
								create_ship = {
									name = random
									random_existing_design = corvette
									graphical_culture = "humanoid_01"
								}
							}
							set_location = {
								target = event_target:asp_kessler_syndrome_country.capital_scope
								distance = 1
								angle = random
							}
						}
					}
					if = {
						limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_destroyers } }
						create_fleet = {
							effect = {
								set_owner = event_target:asp_kessler_syndrome_country
								while = {
									count = 10
									create_ship = {
										name = random
										random_existing_design = destroyer
										graphical_culture = "humanoid_01"
									}
								}
								set_location = {
									target = event_target:asp_kessler_syndrome_country.capital_scope
									distance = 1
									angle = random
								}
							}
						}
					}
					if = {
						limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_cruisers } }
						create_fleet = {
							effect = {
								set_owner = event_target:asp_kessler_syndrome_country
								while = {
									count = 8
									create_ship = {
										name = random
										random_existing_design = cruiser
										graphical_culture = "humanoid_01"
									}
								}
								set_location = {
									target = event_target:asp_kessler_syndrome_country.capital_scope
									distance = 1
									angle = random
								}
							}
						}
					}
					if = {
						limit = { event_target:asp_kessler_syndrome_country = { has_technology = tech_battleships } }
						create_fleet = {
							effect = {
								set_owner = event_target:asp_kessler_syndrome_country
								while = {
									count = 4
									create_ship = {
										name = random
										random_existing_design = battleship
										graphical_culture = "humanoid_01"
									}
								}
								set_location = {
									target = event_target:asp_kessler_syndrome_country.capital_scope
									distance = 1
									angle = random
								}
							}
						}
					}
				}
				# Remove temporary Kessler debris markers once the restored system is rebuilt.
				solar_system = {
					every_system_ambient_object = {
						limit = { has_ambient_object_flag = asp_kessler_syndrome_debris_object }
						destroy_ambient_object = this
					}
				}
			}
			if = {
				limit = { has_global_flag = asp_kessler_syndrome_story_human_unlocked }
				country_event = { id = asp.140 }
				else = { country_event = { id = asp.141 } }
			}
			if = {
				limit = { exists = event_target:asp_kessler_syndrome_country }
				root = { establish_communications_no_message = event_target:asp_kessler_syndrome_country }
			}
			event_target:asp_kessler_syndrome_world = {
				remove_planet_flag = ASP_kessler_syndrome_flag_1
				remove_planet_flag = ASP_kessler_syndrome_flag_2
			}
			clear_global_event_target = asp_kessler_syndrome_world
			clear_global_event_target = asp_kessler_syndrome_country
		
		}
		else = {
			clear_global_event_target = asp_kessler_syndrome_world
			clear_global_event_target = asp_kessler_syndrome_country
		}
	}
}
#if there is no deneb system and human species
country_event = {
	id = asp.140
	title = "asp.140.name"
	desc = "asp.140.desc"
	picture = GFX_evt_unspeakable_horror
	is_triggered_only = yes

	option = {
		name = asp.140.a
		custom_tooltip = asp.140.a.tooltip
	}
}
#else
#desc and picture can be scripted to support triggers but the title isn't, so I just made a new event
country_event = {
	id = asp.141
	title = "asp.141.name"
	desc = "asp.141.desc"
	picture = GFX_evt_unspeakable_horror
	is_triggered_only = yes

	option = {
		name = asp.140.a
		custom_tooltip = asp.140.a.tooltip
	}
}
