# 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_oeo_megastructures
		cost = {
			alloys = 2000
			influence = 500
		}
		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 = {
			trade = @oeo_catapult1_trade_upkeep
		}
	}
	
	custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_QUANTUM_CATAPULT"

	prerequisites = { "tech_quantum_catapult" }

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				#can_build_megastructure_on_planet = yes
				NOR = {
					has_planet_flag = has_megastructure
					has_planet_flag = megastructure
				}
			}
			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
			starbase = { NOT = { has_starbase_size >= starbase_starfortress } }
		}

		modifier = {
			factor = 0.1
			any_neighbor_system = {
				exists = owner
				NOT = {
					owner = { is_same_value = from }
				}
			}
		}

		modifier = {
			factor = 0
			from = {
				any_system_within_border = {
					distance = {
						source = root.solar_system
						use_bypasses = no
						min_jumps = 1
						max_jumps = 25
					}
					any_system_megastructure = {
						OR = {
							is_megastructure_type = quantum_catapult_0
							is_megastructure_type = quantum_catapult_1
							is_megastructure_type = quantum_catapult_2
							is_megastructure_type = quantum_catapult_3
							is_megastructure_type = quantum_catapult_ruined
							is_megastructure_type = quantum_catapult_restored
							is_megastructure_type = quantum_catapult_ruined_slingshot
							is_megastructure_type = quantum_catapult_restored_slingshot
							is_megastructure_type = quantum_catapult_improved_slingshot
						}
					}
				}
			}
		}
	}

	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
				}
			}
			set_planet_flag = megastructure
			set_planet_flag = has_megastructure
		}
	}
}

# 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_oeo_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 = {
			trade = @oeo_catapult2_trade_upkeep
		}
	}
	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_oeo_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 = {
			trade = @oeo_catapult3_trade_upkeep
		}
	}
	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 }
	outliner_trigger = {
		exists = owner
		owner = {
			NOT = { has_country_flag = oeo_catapult_outliner}
		}
	}
	build_time = 1800
	resources = {
		category = megastructures_oeo_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 = {
			trade = @oeo_catapult4_trade_upkeep
		}
	}
	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
}

# 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 }
	outliner_trigger = {
		exists = owner
		owner = {
			NOT = { has_country_flag = oeo_catapult_outliner}
		}
	}
	build_time = 3600
	resources = {
		category = megastructures_oeo_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 = {
			trade = @oeo_catapult4_trade_upkeep
		}
	}
	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
		}
		fromfrom.planet = {
			if = {
				limit = { has_orbital_station = yes }
				orbital_station = {
					dismantle = yes
				}
			}
			set_planet_flag = megastructure
			set_planet_flag = has_megastructure
		}
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = { id = over.25 }
			country_event = { id = tutorial.2126 }
		}
	}
	bypass_type = quantum_catapult
}

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

# 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_oeo_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 = {
			trade = @oeo_catapult2_trade_upkeep
		}
	}
	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
		}
		fromfrom.planet = {
			if = {
				limit = { has_orbital_station = yes }
				orbital_station = {
					dismantle = yes
				}
			}
			set_planet_flag = megastructure
			set_planet_flag = has_megastructure
		}
		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 }
	outliner_trigger = {
		exists = owner
		owner = {
			NOT = { has_country_flag = oeo_catapult_outliner}
		}
	}
	build_time = 3600
	resources = {
		category = megastructures_oeo_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 = {
			trade = @oeo_catapult3_trade_upkeep
		}
	}
	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
}
