# Knights of the Toxic Gods Initial Setup
# Technologies Granted:
#	If Biological Species or Catalytic Empire
#	* Eco Simulation
#	* Hydroponics
#	Otherwise
#	* Powered Exoskeletons
#	* Zero-G Refineries
# Pop Changes: -700
# District Changes:
#	* -1 City District
#	* -1 Generator District
#	* -1 Agriculture District
# Blockers Added:
#	* A Blight Upon the Land
#	* Swarms of the Deity
#	* Pools Most Venemous
#	* Pestilential Wasteland
#	* Envenomed Seas
# Habitat Created:
#	* +400 Pops
#	Deposit Added:
#		* Order's X-Calibrator
#	Buildings Added:
#		* Habitat Central Control
#	Buildings Removed:
#		* Habitat Administration
#	District Added:
#		* +1 Habitatation District
#	Zones Added:
#		* Order's Demesne
#	Buildings Added:
#		* Order's Keep

if = {
	limit = {
		owner? = {
			has_origin = origin_toxic_knights
			is_nomadic = no
		}
	}

	owner = {
		save_event_target_as = toxic_knights_owner
		add_research_option = tech_habitat_1

	}

	remove_district = district_city
	change_variable = {
		which = energy_districts
		value = -1
	}
	change_variable = {
		which = farming_districts
		value = -1
	}

	add_deposit = d_toxic_god_blight_upon_the_land
	add_deposit = d_toxic_god_deitys_swarms
	add_deposit = d_toxic_god_pools_most_venemous
	add_deposit = d_toxic_god_pestilential_wasteland
	add_deposit = d_toxic_god_envenomed_seas

	solar_system = {
		random_system_planet = {
			limit = { has_planet_flag = toxic_knights_habitat }
			create_colony = {
				owner = event_target:toxic_knights_owner
				species = event_target:toxic_knights_owner
			}
			change_colony_foundation_date = -66112 # 2016.05.09
			while = {
				count = 8
				create_pop_group = {
					size = 100
					species = owner_main_species
				}
			}
			set_planet_size = 6
			set_carrier_flag = habitat_level_1
			set_planet_flag = habitat
			set_colony_type = col_habitat_fortress
			set_planet_entity = {
				entity = "habitat_phase_03_entity"
				graphical_culture = owner
			}
			add_deposit = d_knights_calibrator
			add_district_and_planet_size_if_needed_effect = {
				district = district_hab_housing
			}
			add_building = building_hab_major_capital
			remove_building = building_hab_capital
			increase_habitat_level_effect = yes
			add_zone = {
				district = district_hab_housing
				zone = zone_habitat_knights
			}
			add_building = {
				zone = zone_habitat_knights
				building = building_order_keep
			}
			event_target:toxic_knights_owner.capital_scope = {
				set_planet_flag = habitat@PREV
			}
		}
		every_system_planet = {
			limit = { has_deposit_for = shipclass_mining_station }
			create_mining_station = { owner = prevprev.owner }
		}
	}
}

# Nomadic Knights of the Toxic God Initial Setup
# Nomads have no homeworld; the knight content is placed on the capital Arkship,
# and a planet in the start system is turned into the Toxic God's toxic world.
# Arkship Changes:
#	* Replaces the default Ark City zone with Order's Demesne (zone_ark_knights)
#	* Adds Order's Keep
#	* Sets the col_arkship_fortress_knights designation
# Start System:
#	* One planet becomes a Toxic World carrying the five Toxic God blockers

if = {
	limit = {
		owner? = {
			has_origin = origin_toxic_knights
			is_nomadic = yes
		}
	}

	owner = {
		save_event_target_as = toxic_knights_owner
	}

	set_carrier_flag = toxic_knights_arkship

	add_zone = {
		district = district_ark_city
		zone = zone_ark_knights
		zone_slot = 1
		replace = yes
	}
	add_building = {
		zone = zone_ark_knights
		building = building_order_keep
	}
	set_colony_type = col_arkship_fortress_knights

	solar_system = {
		# Turn the former homeworld into the Toxic God's toxic world, flagged as a
		# Toxic terraforming candidate so it can one day be terraformed back.
		random_system_planet = {
			limit = {
				has_carrier_flag = toxic_knights_homeworld
			}
			change_pc = pc_toxic
			clear_deposits = yes
			clear_planet_modifiers = yes
			clear_blockers = yes
			set_planet_flag = toxic_god_world
			add_deposit = d_toxic_god_blight_upon_the_land
			add_deposit = d_toxic_god_deitys_swarms
			add_deposit = d_toxic_god_pools_most_venemous
			add_deposit = d_toxic_god_pestilential_wasteland
			add_deposit = d_toxic_god_envenomed_seas
			set_carrier_flag = toxic_terraforming_candidate
			add_modifier = {
				modifier = toxic_terraforming_candidate
			}
			event_target:toxic_knights_owner = {
				owner_species = {
					set_species_homeworld = prevprev
				}
			}
		}
		# Nomads live on the Arkship, so the Knights habitat moon is not needed.
		# Replace it in place with an uninhabitable toxic world instead of removing
		# the planet outright (which only clears after a game tick).
		random_system_planet = {
			limit = {
				has_planet_flag = toxic_knights_habitat
			}
			change_pc = pc_toxic
			reroll_planet = yes
			clear_blockers = yes
			remove_planet_flag = toxic_knights_habitat
			remove_planet_flag = megastructure
			remove_planet_flag = habitat
			if = {
				limit = {
					solar_system = {
						has_star_flag = sol
					}
				}
				set_name = "NAME_Aurora"	# The sister of Sol and Luna, goddess of Dawn.
			}
			# Why not?
			set_carrier_flag = toxic_terraforming_candidate
			add_modifier = {
				modifier = toxic_terraforming_candidate
			}
		}
	}
}
