# see README.txt for example

habitat_0 = {
	entity = ""
	construction_entity = "orbital_habitat_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = -7 y = -7 }
	build_time = 1800
	build_cost = {
		minerals = 5000
		influence = 100
	}
	construction_blocks_others = no

	potential = {
		has_ascension_perk = ap_voidborn
	}

	possible = {
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				NOR = {
					has_planet_flag = megastructure
					has_planet_flag = has_megastructure
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_orbital_station"
				has_orbital_station = no
			}
			custom_tooltip = {
				fail_text = "requires_survey_not_habitable"
				is_surveyed = {			# prevent leaking habitability information
					who = prev.from
					status = yes
				}
				habitable_planet = no	# prevent the spaceport colliding with the 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_star"
				is_star = no
			}
		} # use these for all non-star megastructures
	}
	
	ai_weight = {
		factor = 5
	}
	
	on_build_start = {}
	on_build_cancel = {}
	
	on_build_complete = {
		spawn_planet = {
			class = "pc_habitat"
			location = fromfrom.planet
			orbit_location = yes
			orbit_angle_offset = 45
			orbit_distance_offset = 9.899
			size = 12
			has_ring = no
			
			init_effect = {
				set_name = "HABITAT_PLANET_NAME"
				set_planet_entity = {
					entity = "orbital_habitat_entity"
					graphical_culture = fromfrom
				}
				surveyed = {
					set_surveyed = yes
					surveyor = FROM
				}
				while = {
					limit = {
						any_tile = { has_blocker = yes }
					}
					random_tile = {
						limit = { has_blocker = yes }
						remove_blocker = yes
					}
				}
				copy_orbital_tile = fromfrom.planet
				set_planet_flag = megastructure
				set_planet_flag = habitat
			}
		}
		fromfrom.planet = {
			set_planet_flag = has_megastructure
		}
		remove_megastructure = fromfrom
	}
	
}
