oeo_orbital_arcology_build_site_0 = {
    entity = "oeo_planetary_ringworld_construction_test_entity"
	construction_entity = "oeo_planetary_ringworld_construction_test_entity"
	place_entity_on_planet_plane = yes
	build_outside_gravity_well = no
	scales_with_planet = yes
	build_time = @oeo_orbitalarc_build_time
	show_in_outliner = no
	show_galactic_map_icon = no
	construction_blocks_and_blocked_by = none
	resources = {
		category = megastructures
		cost = {
			influence = @oeo_orbitalarc_influence_cost
		}
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = @oeo_orbitalarc_alloy_cost
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = @oeo_orbitalarc_alloy_cost
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = @oeo_orbitalarc_alloy_cost
			mult = @halved_alloy_to_food_cost_ratio
		}
		upkeep = {
			alloys = @oeo_orbitalarc_alloy_upkeep
		}
	}
	dismantle_cost = {
		category = megastructures
		cost = {
			energy = @oeo_orbitalarc_alloy_cost
		}
	}
	
	dismantle_time = 360

	dismantle_potential = {
		always = yes
	}
	on_dismantle_start = {
		fromfrom.planet = {
			set_planet_flag = oeo_not_cancelled
			planet_event = { id = oeo_individual_dismantle.1 days = 361 }
		}
	}
	on_dismantle_cancel = {
		fromfrom.planet = {
			remove_planet_flag = oeo_not_cancelled
		}
	}
	on_dismantle_complete = {
		from = {
			add_resource = {
				alloys = @oeo_orbitalarc_alloy_cost
				mult = modifier:megastructure_dismantle_refund_mult
			}
		}
	}
	potential = { 
		has_technology = tech_oeo_orbital_arcology
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
	}

	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_colonized_planet_orbital_ring"
				is_colony = yes
				exists = owner
				exists = controller
				controller = { is_same_value = prev.owner }
			}
			custom_tooltip = {
				fail_text = "requires_not_hostile_or_primitive"
				NOR = {
					planet_is_hostile_or_crisis = yes
					AND = {
						exists = owner
						owner = {
							is_country_type = primitive
						}
					}
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				#can_build_megastructure_on_planet = yes
				NOR = {
					has_planet_flag = oeo_ring_built
					solar_system = {
						has_star_flag = ring_world_built
					}
					is_artificial = yes
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_orbital_debris"
				NOR = {
					has_planet_flag = has_orbital_debris
				}
			}
			custom_tooltip = {
				fail_text = "oeo_planet_too_small"
				planet_size > 14
			}
			custom_tooltip = {
				fail_text = "oeo_planet_too_big"
				planet_size < 52
			}
			if = {
				limit = {
					from = { is_ai = yes }
				}
				pop_amount >= 2500
			}
		}
	}

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

		modifier = {
			factor = 3
			solar_system = {
				exists = owner
				is_same_value = owner.capital_scope.solar_system
			}
		}
		modifier = {
			factor = 2
			any_neighbor_system = {
				exists = owner
				is_same_value = owner.capital_scope.solar_system
			}
		}

		modifier = {
			factor = 0.1
			any_neighbor_system = {
				exists = owner
				owner = { NOT = { is_same_value = from } }
			}
		}
		modifier = {
			factor = 3
			any_system_colony = {
				pop_amount >= 5000
				NOT = { exists = orbital_defence }
			}
		}
	}
	
	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		fromfrom.planet = {
			save_event_target_as = oeo_ring_target
			set_planet_flag = oeo_ring_built
			if = {
				limit = { has_orbital_station = yes }
				orbital_station = {
					dismantle = yes
				}
			}	
		}
		spawn_planet = {
			class = "pc_oeo_planetary_ringworld"
			location = event_target:oeo_ring_target
			orbit_location = yes
			orbit_angle_offset = 0
			orbit_distance_offset = 0
			init_effect = {
				set_name = "Orbital Arcology Ring"
				save_event_target_as = oeo_ring
				set_planet_entity = {
					entity = "oeo_planetary_ringworld"
					graphical_culture = fromfrom
				}
				set_surveyed = {
					surveyed = yes
					surveyor = FROM
				}
				set_all_comms_surveyed = yes
				clear_blockers = yes
				trigger_megastructure_icon = no
				set_planet_flag = megastructure
				set_planet_flag = has_megastructure
				#add_modifier = { modifier = "oeo_arc_ring_mod" days = -1 }
				event_target:oeo_ring_target = {
					set_planet_flag = oeo_ring@fromfrom.planet
				}
				event_target:oeo_ring = {
					set_planet_flag = oeo_ring@fromfrom.planet
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 14
								planet_size = 15
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 4
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 16
								planet_size = 17
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 5
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 18
								planet_size = 19
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 6
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 20
								planet_size = 21
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 7
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 22
								planet_size = 23
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 8
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 24
								planet_size = 25
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 9
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 26
								planet_size = 27
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 10
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 28
								planet_size = 29
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 11
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 30
								planet_size = 31
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 12
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 32
								planet_size = 33
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 13
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 34
								planet_size = 35
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 14
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 36
								planet_size = 37
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 15
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 38
								planet_size = 39
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 16
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 40
								planet_size = 41
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 17
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 42
								planet_size = 43
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 18
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 44
								planet_size = 45
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 19
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 46
								planet_size = 47
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 20
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 48
								planet_size = 49
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 21
					}
				}
				if = {
					limit = {
						event_target:oeo_ring_target = {
							OR = {
								planet_size = 50
								planet_size = 51
							}
						}
					}
					event_target:oeo_ring = {
						set_planet_size = 22
					}
				}
			}
		}
		remove_megastructure = fromfrom
	}
}
