# Quantum Catapult
quantum_catapult_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 1800
	resources = {
		category = megastructures
		cost = {
			alloys = 2000
			influence = 300
		}
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 2000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 2000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 2000
			mult = @halved_alloy_to_food_cost_ratio
		}

		upkeep = {
			energy = 25
		}
	}

	custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_QUANTUM_CATAPULT"

	prerequisites = { "tech_quantum_catapult" }

	possible = {
		inline_script = megastructures/system_ownership_or_waystation_check
		custom_tooltip = {
			fail_text = "requires_no_existing_megastructure"
			has_no_non_gate_megastructure = yes
			NOT = {
				any_system_planet = {
					is_planet_class = pc_cosmogenesis_world
				}
			}
		}
		inline_script = megastructures/system_surveyed_or_waystation_check
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = {
					has_anomaly = yes
				}
			}
			custom_tooltip = {
				fail_text = "requires_neutron_star_or_pulsar"
				is_star = yes
				if = {
					limit = {
						is_trinary_star = no
						is_binary_star = no
					}
					OR = {
						is_star_class = sc_neutron_star
						is_star_class = sc_pulsar
					}
				}
				else = {
					OR = {
						is_planet_class = pc_neutron_star
						is_planet_class = pc_pulsar
					}
				}
			}
		}
	}

	# root = system
	# from = country
	ai_weight = {
		factor = 15

		modifier = {
			factor = 0.1
			from = {
				is_nomadic = no
			}
			starbase = {
				NOT = {
					has_starbase_size >= starbase_starfortress
				}
			}
		}

		modifier = {
			factor = 0.1
			from = {
				is_nomadic = yes
			}
			NOT = {
				any_fleet_in_system = {
					is_ship_size = starbase_waystation_3
					owner? = {
						is_same_value = from
					}
				}
			}
		}

		modifier = {
			factor = 0.1
			from = {
				is_nomadic = yes
			}
			owner? = {
				NOT = {
					benefits_from_waystation_network = {
						NOMAD = from
						SYSTEM_OWNER = this
					}
				}
			}
		}

		modifier = {
			factor = 0
			from = {
				is_nomadic = no
				any_system_within_border = {
					distance = {
						source = root.solar_system
						use_bypasses = no
						min_jumps = 1
						max_jumps = 25
					}
					any_system_megastructure = {
						is_quantum_catapult_megastructure = yes
					}
				}
			}
		}

		modifier = {
			factor = 0
			from = {
				is_nomadic = yes
				OR = {
					any_owned_megastructure = {
						is_quantum_catapult_megastructure = yes
					}
					any_owned_fleet = {
						is_arkship_fleet = yes
						starbase? = {
							has_starbase_module = arkship_exodus_jump
						}
					}
				}
			}
		}
	}

	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		from = {
			if = {
				limit = {
					has_relic = r_contingency_core
					has_country_flag = built_quantum_catapult_site
				}
				set_country_flag = built_quantum_catapult_site_contingency
			}
			else_if = {
				limit = {
					NOT = {
						has_country_flag = built_quantum_catapult_site
					}
				}
				set_country_flag = built_quantum_catapult_site
				country_event = {
					id = tutorial.2126
				}
			}
		}
		fromfrom.planet = {
			if = {
				limit = {
					has_orbital_station = yes
				}
				orbital_station = {
					dismantle = yes
				}
			}
		}
	}
}

# Quantum Catapult 1
quantum_catapult_1 = {
	#entity = "quantum_catapult_stage_1_entity"
	#construction_entity = "quantum_catapult_stage_1_entity"
	entity = "quantum_catapult_stage_1_entity"
	construction_entity = "quantum_catapult_stage_1_entity"
	portrait = GFX_megastructure_quantum_catapult_background
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	build_time = 1800
	resources = {
		category = megastructures
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 3000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 3000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 3000
			mult = @halved_alloy_to_food_cost_ratio
		}


		upkeep = {
			energy = 50
		}
	}

	upgrade_from = {
		quantum_catapult_0
	}

	prerequisites = { "tech_quantum_catapult" }
	bypass_type = quantum_catapult

	country_modifier = {
		fleet_mia_time_mult = -0.1
	}

	station_modifier = {
		catapult_spread_base = 50
		catapult_range_base = 300
		quantum_catapult_megastructure_bypass_windup_mult = 0
	}

	on_build_complete = {
		from = {
			country_event = {
				id = over.1
			}
		}
	}
}

# Quantum Catapult 2
quantum_catapult_2 = {
	#entity = "quantum_catapult_stage_2_entity"
	#construction_entity = "quantum_catapult_stage_2_entity"
	entity = "quantum_catapult_stage_2_entity"
	construction_entity = "quantum_catapult_stage_2_entity"
	portrait = GFX_megastructure_quantum_catapult_background
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	build_time = 1800
	resources = {
		category = megastructures
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 3000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 3000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 3000
			mult = @halved_alloy_to_food_cost_ratio
		}

		upkeep = {
			energy = 60
		}
	}

	upgrade_from = {
		quantum_catapult_1
	}

	possible = {
		from = {
			has_technology = tech_quantum_catapult
		}
	}

	prerequisites = { "tech_quantum_catapult" }

	country_modifier = {
		fleet_mia_time_mult = -0.2
	}

	station_modifier = {
		catapult_spread_base = 35
		catapult_range_base = 450
		quantum_catapult_megastructure_bypass_windup_mult = -0.25
	}

	on_build_complete = {
		from = {
			country_event = {
				id = over.5
			}
		}
	}
	bypass_type = quantum_catapult
}

# Quantum Catapult 3
quantum_catapult_3 = {
	#entity = "quantum_catapult_stage_3_entity"
	#construction_entity = "quantum_catapult_stage_3_entity"
	entity = "quantum_catapult_stage_3_entity"
	construction_entity = "quantum_catapult_stage_3_entity"
	portrait = GFX_megastructure_quantum_catapult_background
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	build_time = 1800
	resources = {
		category = megastructures
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 10000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 10000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 10000
			mult = @halved_alloy_to_food_cost_ratio
		}

		upkeep = {
			energy = 75
		}
	}

	upgrade_from = {
		quantum_catapult_2
	}

	possible = {
		from = {
			has_technology = tech_mega_engineering
		}
	}

	prerequisites = { "tech_quantum_catapult" }
	show_prereqs = yes

	country_modifier = {
		fleet_mia_time_mult = -0.3
	}

	station_modifier = {
		catapult_spread_base = 25
		catapult_range_base = 750
		quantum_catapult_megastructure_bypass_windup_mult = -0.5
	}

	on_build_complete = {
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = {
				id = over.10
			}
		}
	}
	bypass_type = quantum_catapult
}

# Ruined Quantum Catapult
quantum_catapult_ruined = {
	entity = "quantum_catapult_01_destroyed_entity"
	construction_entity = "quantum_catapult_01_destroyed_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	nomad_reactivatable = yes
	entity_offset = { x = 0 y = 0 }
	upgrade_from = {
	}

	potential = {
		always = no
	}
}

# Restored Quantum Catapult
quantum_catapult_restored = {
	#entity = "quantum_catapult_stage_4_entity"
	#construction_entity = "quantum_catapult_stage_4_entity"
	entity = "quantum_catapult_stage_3_entity"
	construction_entity = "quantum_catapult_stage_3_entity"
	portrait = "GFX_megastructure_quantum_catapult_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 10000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 10000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 10000
			mult = @halved_alloy_to_food_cost_ratio
		}

		upkeep = {
			energy = 50
		}
	}

	upgrade_from = {
		quantum_catapult_ruined
	}

	possible = {
		from = {
			has_technology = tech_quantum_catapult
			has_technology = tech_mega_engineering
		}
	}

	country_modifier = {
		fleet_mia_time_mult = -0.3
	}

	station_modifier = {
		catapult_spread_base = 25
		catapult_range_base = 750
		quantum_catapult_megastructure_bypass_windup_mult = -0.5
	}

	on_build_start = {
		fromfrom = {
			set_graphical_culture = root.from
		}
	}

	on_build_complete = {
		set_star_flag = quantum_catapult_built
		every_system_ambient_object = {
			limit = {
				OR = {
					is_ambient_object_type = large_debris_object
					is_ambient_object_type = medium_debris_01_object
					is_ambient_object_type = medium_debris_02_object
				}
			}
			destroy_ambient_object = this
		}
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = {
				id = over.25
			}
			country_event = {
				id = tutorial.2126
			}
		}
	}
	bypass_type = quantum_catapult
}

# Permanently Ruined Quantum Catapult
quantum_catapult_permanently_ruined = {
	entity = "quantum_catapult_01_destroyed_entity"
	construction_entity = "quantum_catapult_01_destroyed_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	show_galactic_map_icon = no
	show_in_outliner = no
	upgrade_from = {
	}

	potential = {
		always = no
	}
}

################################
# Slingshot to the Stars Origin
################################

# Ruined Quantum Catapult
quantum_catapult_ruined_slingshot = {
	entity = "quantum_catapult_01_destroyed_entity"
	construction_entity = "quantum_catapult_01_destroyed_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	nomad_reactivatable = yes
	entity_offset = { x = 0 y = 0 }
	upgrade_from = {
	}

	potential = {
		always = no
	}
}

# Restored Quantum Catapult
quantum_catapult_restored_slingshot = {
	entity = "quantum_catapult_stage_2_entity"
	construction_entity = "quantum_catapult_stage_2_entity"
	portrait = "GFX_megastructure_quantum_catapult_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 2500
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 2500
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 2500
			mult = @halved_alloy_to_food_cost_ratio
		}

		upkeep = {
			energy = 30
		}
	}

	upgrade_from = {
		quantum_catapult_ruined_slingshot
	}

	possible = {
		from = {
			OR = {
				has_technology = tech_quantum_catapult
				has_origin = origin_star_slingshot
			}
		}
	}

	country_modifier = {
		fleet_mia_time_mult = -0.2
	}

	station_modifier = {
		catapult_spread_base = 35
		catapult_range_base = 450
		quantum_catapult_megastructure_bypass_windup_mult = -0.3
	}

	on_build_start = {
		fromfrom = {
			set_graphical_culture = root.from
		}
	}

	on_build_complete = {
		every_system_ambient_object = {
			limit = {
				OR = {
					is_ambient_object_type = large_debris_object
					is_ambient_object_type = medium_debris_01_object
					is_ambient_object_type = medium_debris_02_object
				}
			}
			destroy_ambient_object = this
		}
		from = {
			country_event = {
				id = over.25
			}
			country_event = {
				id = tutorial.2126
			}
		}
	}
	bypass_type = quantum_catapult
}

# Quantum Catapult Improved
quantum_catapult_improved_slingshot = {
	entity = "quantum_catapult_stage_3_entity"
	construction_entity = "quantum_catapult_stage_3_entity"
	portrait = "GFX_megastructure_quantum_catapult_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 10000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 10000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 10000
			mult = @halved_alloy_to_food_cost_ratio
		}

		upkeep = {
			energy = 50
		}
	}

	upgrade_from = {
		quantum_catapult_restored_slingshot
	}

	possible = {
		from = {
			has_technology = tech_mega_engineering
		}
	}

	prerequisites = { "tech_quantum_catapult" }
	show_prereqs = no

	country_modifier = {
		fleet_mia_time_mult = -0.3
	}

	station_modifier = {
		catapult_spread_base = 25
		catapult_range_base = 750
		quantum_catapult_megastructure_bypass_windup_mult = -0.6
	}

	on_build_complete = {
		set_star_flag = quantum_catapult_built
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = {
				id = over.10
			}
		}
	}
	bypass_type = quantum_catapult
}
