# see README.txt for example

@central_orbital_build_time = 1800
@central_orbital_alloy_cost = 1500
@central_orbital_influence_cost = 200

@major_orbital_build_time = 720
@major_orbital_alloy_cost = 200

@minor_orbital_build_time = 180
@minor_orbital_alloy_cost = 50

# Habitat Central Complex
RG_habitat_central_complex = {
	entity = "gatebuilder_01_space_station_entity"
	construction_entity = "habitat_phase_03_entity"
	portrait = "GFX_megastructure_habitat_background"
	place_entity_on_planet_plane = no
	show_galactic_map_icon = no
	hide_name = yes
	show_in_outliner = no
	entity_offset = { x = 7 y = -7 }
	build_time = @central_orbital_build_time

	resources = {
		category = megastructures_habitat
		cost = {
			nanites = 7500
			influence = 200
		}
	}

	prerequisites = {
	}

	construction_blocks_and_blocked_by = self_type

	potential = {
		has_tradition = tr_rg_nanotech_2
		# OR = {
		# 	has_technology = tech_habitat_1
		# 	has_civic = civic_diadochi
		# 	has_civic = civic_great_khans_legacy
		# 	has_country_flag = democratic_khanate_flag
		# }
	}

	possible = {
		exists = starbase
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_not_habitat_central_complex"
			NOT = {
				OR = {
					any_system_planet = {
						has_planet_flag = habitat
					}
					has_megastructure = habitat_central_complex_ruined
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_orbital_debris"
			NOT = {
				any_system_planet = {
					has_planet_flag = has_orbital_debris
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_surveyed_planet"
				is_surveyed = {			# prevent leaking habitability information
					who = prev.from
					status = yes
				}
			}
			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 = {
					solar_system = {
						OR = {
							has_star_flag = ithomes_gate
						}
					}
					is_planet_class = pc_habitat
				}
			}

			# balance for habitats
			custom_tooltip = {
				fail_text = "requires_not_minor_planetary_body"
				NOR = {
					is_asteroid = yes
					is_moon = yes
				}
			}
			custom_tooltip = {
				fail_text = "requires_not_solarpunk"
				NOT = {
					solar_system = {
						has_star_flag = solarpunk_system_02
					}
				}
			}
			if = {
				limit = {
					from = { is_ai = yes }
				}
				or = {
					has_deposit_for = shipclass_mining_station
					has_deposit_for = shipclass_research_station
				}
			}
		} # use these for all non-star megastructures
	}

	# root = system
	# from = country
	ai_weight = {
		factor = 0
	}

	on_build_complete = {
		fromfrom.planet = {
			save_event_target_as = target_planet
		}
		if = {
			limit = {
				fromfrom.planet = {
					is_star = yes
				}
			}
			spawn_rg_habitat_effect = {
				DISTANCE = 19.798
			}
		}
		else = {
			spawn_rg_habitat_effect = {
				DISTANCE = 9.899
			}
		}

		fromfrom.solar_system = {
			set_star_flag = has_habitat
		}

		if = {
			limit = {
				event_target:target_planet = {
					OR = {
						has_deposit_for = shipclass_research_station
						has_deposit_for = shipclass_mining_station
					}

				}
			}
			on_orbital_complete_effect = {
				BODY = major
				TYPE = resource
			}
		}

		else = {
			on_orbital_complete_effect = {
				BODY = major
				TYPE = generic
			}
		}

		remove_megastructure = fromfrom
		from = { country_event = { id = megastructures.10 } }
	}
}