# Mega Shipyard
mega_shipyard_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 = {
			unity = 2500
		}
		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 = 5
		}
	}

	custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_ONE_PER_COUNTRY"

	prerequisites = { "tech_mega_shipyard" }

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_no_existing_megastructure"
			from = {
				OR = {
					has_relic = r_contingency_core
					NOT = { has_country_flag = built_mega_shipyard_site }
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_existing_megastructure"
			from = { NOT = { has_country_flag = built_mega_shipyard_site_contingency } }
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_black_hole_neutron_star_pulsar"
			NOT = {
				is_star_class = sc_black_hole
				is_star_class = sc_neutron_star
				is_star_class = sc_pulsar
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_binary_trinary"
			NOR = {
				is_star_class = sc_binary_1
				is_star_class = sc_binary_2
				is_star_class = sc_binary_3
				is_star_class = sc_binary_4
				is_star_class = sc_binary_5
				is_star_class = sc_binary_6
				is_star_class = sc_binary_7
				is_star_class = sc_binary_8
				is_star_class = sc_binary_9
				is_star_class = sc_binary_10
				is_star_class = sc_trinary_1
				is_star_class = sc_trinary_2
				is_star_class = sc_trinary_3
				is_star_class = sc_trinary_4
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_existing_megastructure"
			has_no_non_gate_megastructure = yes
			NOT = {
				any_system_planet = {
					is_planet_class = pc_cosmogenesis_world
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "must_build_around_star"
				is_star = yes
			}
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
		}
	}

	# 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 }
				}
			}
		}
	}

	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		from = {
			if = {
				limit = {
					has_relic = r_contingency_core
					has_country_flag = built_mega_shipyard_site
				}
				set_country_flag = built_mega_shipyard_site_contingency
			}
			set_country_flag = built_mega_shipyard_site
		}
		fromfrom.planet = {
			if = {
				limit = { has_orbital_station = yes }
				orbital_station = {
					dismantle = yes
				}
			}
		}
	}
}

# mega_shipyard 1
mega_shipyard_1 = {
	entity = "mega_shipyard_01_stage_1_entity"
	construction_entity = "mega_shipyard_01_stage_1_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 = {
			unity = 2500
		}
		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 = 10
		}
	}

	upgrade_from = {
		mega_shipyard_0
	}

	prerequisites = { "tech_mega_shipyard" }

	ship_modifier = {
		ship_starting_experience_add = 100
	}

	station_modifier = {
		starbase_shipyard_capacity_add = 50
	}

	country_modifier = {
		starbase_shipyard_build_speed_mult = 0.33
	}

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

# mega_shipyard 2
mega_shipyard_2 = {
	entity = "mega_shipyard_01_stage_2_entity"
	construction_entity = "mega_shipyard_01_stage_2_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 = {
			unity = 2500
		}
		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 = 20
		}
	}

	upgrade_from = {
		mega_shipyard_1
	}

	prerequisites = { "tech_mega_shipyard" }

	ship_modifier = {
		ship_starting_experience_add = 100
	}

	station_modifier = {
		starbase_shipyard_capacity_add = 75
	}

	country_modifier = {
		starbase_shipyard_build_speed_mult = 0.67
	}

	on_build_complete = {
		from = { country_event = { id = feda.2 } }
	}
}

# mega_shipyard 3
mega_shipyard_3 = {
	entity = "mega_shipyard_01_stage_3_entity"
	construction_entity = "mega_shipyard_01_stage_3_entity"
	portrait = "GFX_megastructure_mega_shipyard_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 1800
	resources = {
		category = megastructures
		cost = {
			unity = 2500
		}
		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 = 40
		}
	}

	upgrade_from = {
		mega_shipyard_2
	}

	prerequisites = { "tech_mega_shipyard" }
	show_prereqs = yes

	ship_modifier = {
		ship_starting_experience_add = 100
	}

	station_modifier = {
		starbase_shipyard_capacity_add = 100
	}

	country_modifier = {
		starbase_shipyard_build_speed_mult = 1
	}

	on_build_complete = {
		set_star_flag = mega_shipyard_built
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = { id = feda.3 }
			country_event = { id = focus.665 }
		}
	}
}

# Permanently Ruined mega shipyard
mega_shipyard_permanently_ruined = {
	entity = "mega_shipyard_01_destroyed_entity"
	construction_entity = "mega_shipyard_01_destroyed_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	show_galactic_map_icon = no
	show_in_outliner = no
	upgrade_from = {
	}

	potential = {
		always = no
	}
}

# Ruined mega shipyard
mega_shipyard_ruined = {
	entity = "mega_shipyard_01_destroyed_entity"
	construction_entity = "mega_shipyard_01_destroyed_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	upgrade_from = {
	}

	potential = {
		always = no
	}
}

# Restored mega shipyard
mega_shipyard_restored = {
	entity = "mega_shipyard_01_stage_3_entity"
	construction_entity = "mega_shipyard_01_stage_3_entity"
	portrait = "GFX_megastructure_mega_shipyard_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			unity = 3200
		}
		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 = 40
		}
	}

	upgrade_from = {
		mega_shipyard_ruined
	}

	possible = {
		from = { has_technology = tech_mega_engineering }
	}

	ship_modifier = {
		ship_starting_experience_add = 100
	}

	station_modifier = {
		starbase_shipyard_capacity_add = 20
	}

	country_modifier = {
		starbase_shipyard_build_speed_mult = 1
	}

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

	on_build_complete = {
		set_star_flag = mega_shipyard_built
		every_system_ambient_object = {
			limit = {
				is_ambient_object_type = large_debris_object
			}
			destroy_ambient_object = this
		}
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = { id = feda.6 }
			country_event = { id = focus.665 }
		}
	}
}
