# =============================================================================
# Giga + Age of Wonder Compatibility Patch — Dyson Swarm  [TIER 2 / divergent]
# "TWO BUILD BUTTONS, Giga primary" — same architecture as zzzz_compat_dyson_sphere.txt.
#
# AOW's vanilla-override `dyson_swarm_1` is a fresh build that redirects by star
# spectral class to AOW_MEGA_dyson_swarm_1_<class> in on_build_complete. Giga
# keeps the vanilla dyson_swarm_1/2/3 (wins by load order); AOW's entry is
# re-homed here to a new directly-buildable `AOW_MEGA_dyson_swarm_entry` (faithful
# copy of AOW's dyson_swarm_1, new ID — all AOW refs it makes remain valid).
# AOW's `AOW_MEGA_dyson_swarm_*` variants keep their unique IDs and coexist.
# Mutual exclusion via AOW_trgr_PLNT_existing_megastructure = no.
# =============================================================================

AOW_MEGA_dyson_swarm_entry = {
	entity = "dyson_swarm_phase_1_entity"
	construction_entity = "dyson_swarm_phase_1_entity"
	portrait = "GFX_megastructure_dyson_swarm_background"
	entity_offset = { x = -0.1 y = -0.1 }
	rotate_to_center = no
	scale_offset = yes
	place_entity_on_planet_plane = yes
	use_planet_resource = yes
	build_time = 1080 # 3 years
	custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_DYSON_SPHERE"
	resources = {
		category = megastructures
		cost = {
			unity = 1000
		}
		cost = {
			alloys = 500
		}
		upkeep = {
			alloys = 5
		}
	}
	construction_blocks_and_blocked_by = none
	inline_script = {
		script = megastructures/dismantle_megastructure_with_effects
		time = 360
		tech = tech_dyson_swarm
		category = megastructures
		key = dyson_swarm
		alloys = 500
		minerals = 0 vm = 0 eg = 0 rc = 0 lm = 0 zo = 0 dm = 0
	}
	prerequisites = { "tech_dyson_swarm" }
	potential = { always = no } # COMPAT: AOW Dyson Swarm build disabled — use the Giga Dyson Swarm instead.
	possible = {
		hidden_trigger = { exists = starbase }
		custom_tooltip = {#on_build_start
			fail_text = "AOW_mega_requires_CNTR_no_more_megastructure"
			from = { NOT = { has_country_flag = AOW_flag_CNTR_no_more_dyson_swarm } }
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
	}
	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "AOW_mega_requires_PLNT_obafgkm_star_rift_star"
				OR = {
					AOW_trgr_PLNT_obafgkm_star = yes
					is_planet_class = pc_rift_star
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
			custom_tooltip = {#放置处不能有巨构
				fail_text = "requires_no_existing_megastructure"
				AOW_trgr_PLNT_existing_megastructure = no
			}
			if = {
				limit = {
					from = { is_ai = yes }
				}
				NOR = {
					has_deposit = d_energy_1
					has_deposit = d_energy_2
				}
			}
		}
	}
	country_modifier = {
		custom_tooltip = dyson_swarm_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 }
				}
			}
		}
	}
	on_build_start = {
		AOW_effect_check_mega_cap = {
			key = dyson_swarm
			constructing = dyson_swarm_1
		}
	}
	on_build_cancel = {}
	on_build_complete = {
		from = {
			change_variable = { which = dyson_swarm_counter value = 1 }
		}
		fromfrom.planet = {
			AOW_eft_PLNT_dismantle_orbital_station = yes
			remove_modifier = dyson_swarm_1_mod
			remove_modifier = dyson_swarm_2_mod
			remove_modifier = dyson_swarm_3_mod
			add_modifier = {
				modifier = dyson_swarm_1_mod
				days = -1
			}
		}
		fromfrom = {
			planet = { AOW_eft_PLNT_dismantle_orbital_station = yes }
			set_megastructure_flag = dyson_swarm
			set_megastructure_flag = AOW_flag_MEGA_dyson_swarm_@owner
			if = {
				limit = { planet = { AOW_trgr_PLNT_hyper_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_hyper
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_super_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_super
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_o_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_o
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_b_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_b
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_giant_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_giant
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_a_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_a
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_f_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_f
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_g_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_g
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_k_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_k
				finish_upgrade = yes
			}
			else_if = {
				limit = { planet = { AOW_trgr_PLNT_m_star = yes } }
				upgrade_megastructure_to = AOW_MEGA_dyson_swarm_1_m
				finish_upgrade = yes
			}
			else = {}
		}
	}
}
