# see README.txt for example

ring_world_1 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -7 y = -7 }
	build_time = 1800
	build_cost = {
		minerals = 10000
		influence = 300
	}
	
	construction_blocks_others = no

	maintenance = {
		energy = 5
	}

	potential = {
		has_ascension_perk = ap_the_circle_of_life
	}
	
	possible = {
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_habitable_planets"
			NOT = {
				any_planet = {
					AND = {
						AND = {
							habitable_planet = yes
							OR = {
								is_colony = yes
								is_under_colonization = yes
							}	
						}
						NOT = {
							is_planet_class = pc_habitat
						}
					}
				}
			}
		}
		
		custom_tooltip = {
			fail_text = "requires_no_existing_megastructure"
			NOR = { 
				any_planet = {
					is_planet_class = pc_ringworld_habitable
				}
				has_star_flag = ring_world_built
			}
		}
	}
	
	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 }
			}
			custom_tooltip = {
			fail_text = "requires_planets_for_material"
			hidden:solar_system = { any_planet = { NOT = { is_star = yes } } }
			}
		}
	}
	
	ai_weight = {
		factor = 5
	}
	
	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		set_star_flag = ring_world_built
	}
}

# Temporarily used for creating specific habitable or structural sections.
ring_world_2_intermediate = {
	entity = ""
	construction_entity = "ringworld_seam_entity_01_full_entity"
	portrait = "GFX_megastructure_construction_background"
	upgrade_from = {
		ring_world_1
	}
	
	build_time = 4800
	build_cost = {
		minerals = 20000
	}
	
	construction_blocks_others = no
	
	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		every_system_planet = { 
			limit = {
				AND = {
					is_star = no 
					NOT = { 
						is_planet_class = pc_habitat
					}
				}
			}
			remove_planet = yes 
		}
		asteroids_distance = 0
		remove_megastructure = fromfrom
		spawn_megastructure = {
			name = "Ring Section A"
			type = "ring_world_2"
			orbit_angle = 0
			orbit_distance = 45
			owner = from
			graphical_culture = fromfrom
			location = planet
		}
		spawn_megastructure = {
			name = "Ring Section B"
			type = "ring_world_2"
			orbit_angle = 90
			orbit_distance = 45
			owner = from
			graphical_culture = fromfrom
			location = planet
		}
		spawn_megastructure = {
			name = "Ring Section C"
			type = "ring_world_2"
			orbit_angle = 180
			orbit_distance = 45
			owner = from
			graphical_culture = fromfrom
			location = planet
		}
		spawn_megastructure = {
			name = "Ring Section D"
			type = "ring_world_2"
			orbit_angle = 270
			orbit_distance = 45
			owner = from
			graphical_culture = fromfrom
			location = planet
		}
	}
}

ring_world_2 = {
	entity = "ringworld_3x_seams_entity"
	portrait = "GFX_megastructure_construction_background"
	potential = {
		always = no #used from script only
	}
	upgrade_from = {
		ring_world_2_intermediate
	}
}

ring_world_3_intermediate = {
	entity = ""
	construction_entity = "ringworld_phase_3_construction_entity"
	portrait = "GFX_megastructure_construction_background"
	upgrade_from = {
		ring_world_2
	}
	build_time = 2700
	build_cost = {
		minerals = 20000
	}
	
	construction_blocks_others = no
	
	on_build_complete = {
		spawn_planet = {
			class = "pc_ringworld_tech"
			location = fromfrom
			orbit_angle_offset = 30
			init_effect = {
				set_name = "Ring Section"
				set_planet_entity = {
					entity = "ringworld_tech_entity_01_entity"
					graphical_culture = fromfrom
				}
				surveyed = {
					set_surveyed = yes
					surveyor = FROM
				}
				set_planet_flag = megastructure
			}
		}
		spawn_planet = {
			class = "pc_ringworld_seam"
			location = fromfrom
			init_effect = {
				set_name = "Ring Section"
				set_planet_entity = {
					entity = "ringworld_seam_entity_01_entity"
					graphical_culture = fromfrom
				}
				surveyed = {
					set_surveyed = yes
					surveyor = FROM
				}
				set_planet_flag = megastructure
			}
		}
		spawn_planet = {
			class = "pc_ringworld_habitable"
			location = fromfrom
			orbit_angle_offset = -30
			init_effect = {
				set_name = "Habitable Section A"
				set_planet_entity = {
					entity = "ringworld_habitable_entity_01_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
					}
				}
				save_event_target_as = ring_section
				trigger_megastructure_icon = yes
				set_planet_flag = megastructure
			}
		}
		fromfrom.planet = {
			set_planet_flag = has_megastructure
		}
		remove_megastructure = fromfrom
		if = {
			limit = {
				NOT = { has_star_flag = ring_section_1 }
			}
			set_star_flag = ring_section_1
			event_target:ring_section = { set_name = "Habitable Section A" }
			break = yes
		}
		if = {
			limit = {
				has_star_flag = ring_section_1
				NOT = { has_star_flag = ring_section_2 }
			}
			set_star_flag = ring_section_2
			event_target:ring_section = { set_name = "Habitable Section B" }
			break = yes
		}
		if = {
			limit = {
				has_star_flag = ring_section_2
				NOT = { has_star_flag = ring_section_3 }
			}
			set_star_flag = ring_section_3
			event_target:ring_section = { set_name = "Habitable Section C" }
			break = yes
		}
		if = {
			limit = { has_star_flag = ring_section_3 }
			remove_star_flag = ring_section_1
			remove_star_flag = ring_section_2
			remove_star_flag = ring_section_3
			event_target:ring_section = { set_name = "Habitable Section D" }
			break = yes
		}
	}
}
