orbital_arc_furnace_1 = {
	entity = "arc_crucible_stage_1_entity"
	construction_entity = "arc_crucible_stage_1_entity"
	#to avoid z-fighting of consrucion entity with the base entity
	construction_scale = 1.02
	portrait = "GFX_megastructure_arc_furnace_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	rotate_to_center = no
	scale_offset = yes
	use_planet_resource = yes
	scales_with_planet = yes
	build_time = 360 # 1 year
	resources = {
		category = megastructures_oeo_arc_furnace
		cost = { 
			####Unity replaced with influence for 1st stage####
			influence = 200
		}
		cost = {
			trigger = { country_uses_bio_ships = no }
			alloys = 500
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			alloys = 500
			mult = 0.5
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			food = 500
			mult = @halved_alloy_to_food_cost_ratio
		}
		upkeep = { trade = @oeo_arc1_trade_upkeep }
	}
	construction_blocks_and_blocked_by = self_type
	build_system_tooltip = arc_furnace_tooltip
	dismantle_cost = {
		category = megastructures
		cost = { energy = 500 }
	}
	dismantle_time = 360
	dismantle_potential = { always = yes }
	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = tech_orbital_arc_furnace
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = { 
				has_modifier = orbital_arc_furnace_1_mod
			}
			dismantle_arc_furnace_effect = yes
		}
		random_system_planet = {
			limit = { has_planet_flag = has_arc_furnace }
			set_planet_entity = { entity = pc_molten }
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_arc_furnace
		}
		from = {
			add_resource = {
				alloys = 500
				mult = modifier:megastructure_dismantle_refund_mult
			}
		}
	}
	prerequisites = { "tech_orbital_arc_furnace" }
	potential = { always = yes }
	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_dyson_sphere"
			system_has_dyson_sphere = no
		}
		custom_tooltip = {
			fail_text = "requires_no_dyson_sphere_construction"
			if = {
				limit = { system_has_dyson_sphere = no }
				NOT = {
					solar_system = { has_star_flag = dyson_sphere_construction }
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_arc_furnace"
			system_has_arc_furnace = no
		}
	}
	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
			is_planet_class = pc_molten
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				NOR = {
					has_planet_flag = megastructure
					has_planet_flag = has_megastructure
				}
			}
			if = {
				limit = {
					from = { is_ai = yes }
				}
				solar_system = {
					count_system_planet = {
						count >= 8
						limit = {
							NOT = { has_deposit_for = shipclass_research_station }
							is_star = no
							is_astral_scar = no
							colonizable_planet = no
						}
					}
				}
			}
		}
	}
	custom_tooltip_requirements = "oeo_MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_KILOSTRUCTURE_LIMIT"
	country_modifier = { custom_tooltip = orbital_arc_furnace_1_mod_tooltip }
	# root = system
	# from = country
	ai_weight = {
		factor = 5
		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 }
				}
			}
		}
		modifier = {
			factor = 0
			from = {
				count_owned_megastructure = {
					limit = { is_oeo_arc_category = yes }
					count > from.value:oeo_ai_system_limiter
				}
			}
		}
		modifier = {
			factor = 0
		 	from = { has_country_flag = oeo_kilo_cooldown }
		}
	}
	on_build_start = {
		set_star_flag = arc_furnace_construction
		from = { set_timed_country_flag = { flag = oeo_kilo_cooldown days = @oeo_kilo_cooldown_time } }
	}
	on_build_cancel = { remove_star_flag = arc_furnace_construction }
	on_build_complete = {
		remove_star_flag = arc_furnace_construction
		fromfrom.planet = {
			set_planet_flag = has_megastructure
			set_planet_flag = has_arc_furnace
			if = {
				limit = { has_orbital_station = yes }
				orbital_station = {
					dismantle = yes
				}
			}
			set_planet_entity = { entity = invisible_turret_entity }
		}
		from = {
			country_event = { id = cybernetics.1000 }
			country_event = { 
				id = machine_age.3405 #2nd Arc Furnace built 
			}
		}
	}
}
orbital_arc_furnace_2 = {
	entity = "arc_crucible_stage_2_entity"
	construction_entity = "arc_crucible_stage_2_entity"
	construction_scale = 1.02 #to avoid z-fighting of consrucion entity with the base entity
	portrait = "GFX_megastructure_arc_furnace_background"
	entity_offset = { x = 0 y = 0 }
	rotate_to_center = no
	scale_offset = yes
	use_planet_resource = yes
	scales_with_planet = yes
	build_time = 1080 # 3 years
	resources = {
		category = megastructures_oeo_arc_furnace
		cost = { unity = 1000 }
		cost = {
			trigger = { country_uses_bio_ships = no }
			alloys = 1000
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			alloys = 1000
			mult = 0.5
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			food = 1000
			mult = @halved_alloy_to_food_cost_ratio
		}
		upkeep = { trade = @oeo_arc2_trade_upkeep }
	}
	construction_blocks_and_blocked_by = none
	dismantle_cost = {
		category = megastructures
		cost = { energy = 1000 }
	}
	dismantle_time = 360
	dismantle_potential = { always = yes }
	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = tech_orbital_arc_furnace
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = {
				has_modifier = orbital_arc_furnace_2_mod
			}
			dismantle_arc_furnace_effect = yes
		}
		random_system_planet = {
			limit = { has_planet_flag = has_arc_furnace }
			set_planet_entity = { entity = pc_molten }
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_arc_furnace
			planet_event = { id = oeo_orbital_dismantle.1 }
		}
		from = {
			add_resource = {
				alloys = 1000
				mult = modifier:megastructure_dismantle_refund_mult
			}
		}
	}
	upgrade_from = { orbital_arc_furnace_1 }
	prerequisites = { "tech_orbital_arc_furnace" }
	potential = { always = yes }
	country_modifier = { custom_tooltip = orbital_arc_furnace_2_mod_tooltip }
	on_build_start = { set_star_flag = arc_furnace_construction }
	on_build_cancel = { remove_star_flag = arc_furnace_construction }
	on_build_complete = {
		remove_star_flag = arc_furnace_construction
		from = { country_event = { id = cybernetics.1005 } }
	}
}
# Orbital arc furnace Third Stage
orbital_arc_furnace_3 = {
	entity = "arc_crucible_stage_3_entity"
	construction_entity = "arc_crucible_stage_3_entity"
	construction_scale = 1.02 #to avoid z-fighting of consrucion entity with the base entity
	portrait = "GFX_megastructure_arc_furnace_background"
	entity_offset = { x = 0 y = 0 }
	rotate_to_center = no
	scale_offset = yes
	place_entity_on_planet_plane = yes
	#show_in_outliner = no
	use_planet_resource = yes
	scales_with_planet = yes
	build_time = 1080 # 3 years
	resources = {
		category = megastructures_oeo_arc_furnace
		cost = { unity = 2000 }
		cost = {
			trigger = { country_uses_bio_ships = no }
			alloys = 1500
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			alloys = 1500
			mult = 0.5
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			food = 1500
			mult = @halved_alloy_to_food_cost_ratio
		}
		upkeep = { trade = @oeo_arc3_trade_upkeep }
	}
	construction_blocks_and_blocked_by = none
	dismantle_cost = {
		category = megastructures
		cost = { energy = 1500 }
	}
	dismantle_time = 360
	dismantle_potential = { always = yes }
	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = tech_orbital_arc_furnace
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = { has_modifier = orbital_arc_furnace_3_mod }
			dismantle_arc_furnace_effect = yes
		}
		random_system_planet = {
			limit = { has_planet_flag = has_arc_furnace }
			set_planet_entity = { entity = pc_molten }
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_arc_furnace
			planet_event = { id = oeo_orbital_dismantle.1 }
		}
		from = {
			add_resource = {
				alloys = 1500
				mult = modifier:megastructure_dismantle_refund_mult
			}
		}
	}
	upgrade_from = { orbital_arc_furnace_2 }
	prerequisites = { "tech_orbital_arc_furnace" }
	potential = { always = yes }
	country_modifier = { custom_tooltip = orbital_arc_furnace_3_mod_tooltip }
	on_build_start = { set_star_flag = arc_furnace_construction }
	on_build_cancel = { remove_star_flag = arc_furnace_construction }
	on_build_complete = {
		remove_star_flag = arc_furnace_construction
		from = { country_event = { id = cybernetics.1010 } }
	}
}
# Orbital arc furnace Final Stage
orbital_arc_furnace_4 = {
	entity = "arc_crucible_stage_4_entity"
	construction_entity = "arc_crucible_stage_4_entity"
	construction_scale = 1.02 #to avoid z-fighting of consrucion entity with the base entity
	portrait = "GFX_megastructure_arc_furnace_background"
	entity_offset = { x = 0 y = 0 }
	rotate_to_center = no
	scale_offset = yes
	place_entity_on_planet_plane = yes
	outliner_trigger = {
		exists = owner
		owner = {
			NOT = { has_country_flag = oeo_arc_furnace_outliner }
		}
	}
	use_planet_resource = yes
	scales_with_planet = yes
	build_time = 1080 # 3 years
	resources = {
		category = megastructures_oeo_arc_furnace
		cost = { unity = 4000 }
		cost = {
			trigger = { country_uses_bio_ships = no }
			alloys = 2000
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			alloys = 2000
			mult = 0.5
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			food = 2000
			mult = @halved_alloy_to_food_cost_ratio
		}
		upkeep = { trade = @oeo_arc4_trade_upkeep }
	}
	construction_blocks_and_blocked_by = none
	dismantle_cost = {
		category = megastructures
		cost = { energy = 2000 }
	}
	dismantle_time = 360
	dismantle_potential = { always = yes }
	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = tech_orbital_arc_furnace
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = { has_modifier = orbital_arc_furnace_4_mod }
			dismantle_arc_furnace_effect = yes
		}
		random_system_planet = {
			limit = { has_planet_flag = has_arc_furnace }
			set_planet_entity = { entity = pc_molten }
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_arc_furnace
			planet_event = { id = oeo_orbital_dismantle.1 }
		}
		from = {
			add_resource = {
				alloys = 2000
				mult = modifier:megastructure_dismantle_refund_mult
			}
		}
	}
	upgrade_from = { orbital_arc_furnace_3 }
	prerequisites = { "tech_orbital_arc_furnace" }
	potential = { always = yes }
	country_modifier = { custom_tooltip = orbital_arc_furnace_4_mod_tooltip }
	on_build_start = { set_star_flag = arc_furnace_construction }
	on_build_cancel = { remove_star_flag = arc_furnace_construction }
	on_build_complete = {
		remove_star_flag = arc_furnace_construction
		from = {
			country_event = { id = cybernetics.1015 }
			country_event = { id = focus.535 }
		}
		if = {
			limit = {
				any_system_megastructure = { is_megastructure_type = dyson_swarm_3 }
			}
			from = { set_country_flag = burning_brightly_achievement }
		}
	}
}
# Orbital arc furnace Restored Stage
orbital_arc_furnace_restored = {
	entity = "arc_crucible_stage_4_entity"
	construction_entity = "arc_crucible_stage_4_entity"
	construction_scale = 1.02 #to avoid z-fighting of consrucion entity with the base entity
	portrait = "GFX_megastructure_arc_furnace_background"
	entity_offset = { x = 0 y = 0 }
	rotate_to_center = no
	scale_offset = yes
	place_entity_on_planet_plane = yes
	outliner_trigger = {
		exists = owner
		owner = {
			NOT = { has_country_flag = oeo_arc_furnace_outliner }
		}
	}
	use_planet_resource = yes
	scales_with_planet = yes
	build_time = 720 # 2 years
	resources = {
		category = megastructures_oeo_arc_furnace
		cost = { unity = 4000 }
		cost = {
			trigger = { country_uses_bio_ships = no }
			alloys = 3000
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			alloys = 2000
			mult = 0.5
		}
		cost = {
			trigger = { country_uses_bio_ships = yes }
			food = 2000
			mult = @halved_alloy_to_food_cost_ratio
		}
		upkeep = { trade = @oeo_arc4_trade_upkeep }
	}
	construction_blocks_and_blocked_by = none
	dismantle_cost = {
		category = megastructures
		cost = { energy = 2000 }
	}
	dismantle_time = 360
	dismantle_potential = { always = yes }
	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = tech_orbital_arc_furnace
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = { has_modifier = orbital_arc_furnace_4_mod }
			dismantle_arc_furnace_effect = yes
		}
		random_system_planet = {
			limit = { has_planet_flag = has_arc_furnace }
			set_planet_entity = { entity = pc_molten }
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_arc_furnace
			planet_event = { id = oeo_orbital_dismantle.1 }
		}
		from = {
			add_resource = {
				alloys = 2000
				mult = modifier:megastructure_dismantle_refund_mult
			}
		}
	}
	upgrade_from = { orbital_arc_furnace_destroyed }
	prerequisites = { "tech_orbital_arc_furnace" }
	potential = { always = yes }
	country_modifier = { custom_tooltip = orbital_arc_furnace_4_mod_tooltip }
	on_build_start = { set_star_flag = arc_furnace_construction }
	on_build_cancel = { remove_star_flag = arc_furnace_construction }
	on_build_complete = {
		remove_star_flag = arc_furnace_construction
		from = { country_event = { id = cybernetics.1016 } }
		fromfrom.planet = {
			set_planet_entity = { entity = invisible_turret_entity }
		}
		if = {
			limit = {
				any_system_megastructure = { is_megastructure_type = dyson_swarm_3 }
			}
			from = { set_country_flag = burning_brightly_achievement }
		}
	}
}
