############################### Gigastructural Engineering & More ###############################

ehof_default_country = {
	merg_is_standard_empire = yes
}
can_use_ehof = {
	NOR = {
		AND = {
			is_ship_class = shipclass_constructor
			is_fleet_idle = no
		}
		fleet = { is_mobile = no }
	}
}
reshaper_eligible = {
	NOR = {
		has_planet_flag = paluushia
		merg_is_black_or_white_hole = yes
		is_asteroid = yes
		is_planet_class = pc_shrouded
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_habitable_structure = yes
			"
			toggle = @has_gigastructures
		}
		is_planet_class = pc_ringworld_habitable_damaged
		is_planet_class = pc_ringworld_tech
		is_planet_class = pc_ringworld_tech_damaged
		is_planet_class = pc_ringworld_seam
		is_planet_class = pc_ringworld_seam_damaged
		merg_is_habitat = yes
		merg_is_hab_ringworld = yes
		merg_is_forbidden_target = yes
	}
}
giga_valid_planet_wrecked_ship = {
	solar_system = {
		merg_is_void_system = no
		is_capital_system = no
	}
	is_star = no
	NOT = { has_planet_flag = has_giga_wrecked_ship }
}
is_maginotable_restricted = {
	OR = {
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_giga_planetary_computer = yes
			"
			toggle = @has_gigastructures
		}
		has_planet_flag = has_planet_pc_mega
		# Playable Katzenartig Imperium
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_pki_flusion_ecu = yes
			"
			toggle = @has_pki_mod
		}
		# APSR
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_planet_flag = apsr_planet
			"
			toggle = @has_apsr
		}
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_acot_awesome_planet_class = yes
			"
			toggle = @has_ancient_caches
		}
		# Ancient Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				ag_is_mod_habitable_ringworld = yes
			"
			toggle = @ag_null_edict_length
		}
		# Assault Lily
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_ringworld_habitable_lily
			"
			toggle = @change_planet_size_bullet_num
		}
		# AshArms Aquarius History
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_adf_academycomplex_ringworld_habitable
			"
			toggle = @asharm_mod
		}
		# Darkspace
		is_ds_ancient_ringworld = yes
		is_ds_constructor_ark = yes
		is_ds_prism_world = yes
		is_ds_ringworld_spectrals = yes
		is_ds_stellar_engine = yes
		# Merger of Rules
		has_planet_flag = merg_is_forbidden_target
		# Star Wars: Kuat Ancient Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_kuat_eternal_ringworld_habitable
			"
			toggle = @sw_kuat_mod
		}
		# Star Wars: UnknownWorld Shipgirls Story
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_swgs_engineer_ringworld_habitable
			"
			toggle = @swuss_mod
		}
		# ThaumStellaris
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_tc_alchemical_ringworld_habitable
				is_planet_class = pc_tc_advanced_alchemical_ringworld_habitable
			"
			toggle = @has_tc_mod
		}
		# Warship Girls and MIST species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_wg_upgraded_ringworld = yes
				is_planet_class = pc_ringworld_habitable_auto_uf
				is_planet_class = pc_dyson_ring
			"
			toggle = @wsg_mod
		}
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_utopian_ringworld
			"
			toggle = @has_zofe_vanilla
		}
	}
}
mega_blokkats_wont_stripmine = {
	OR = {
		is_megastructure_type = crisis_sphere_0
		is_megastructure_type = crisis_sphere_1
		is_megastructure_type = crisis_sphere_2
		is_megastructure_type = crisis_sphere_3
		is_megastructure_type = crisis_sphere_4
		is_megastructure_type = crisis_sphere_ruined
		merg_is_gate_mega = yes
	}
}
giga_planet_no_farming = {
	merg_is_machine_world = yes
}
giga_is_standard_country_type = {
	OR = {
		is_country_type = default
		is_country_type = ratlings
		# Darkspace
		is_country_type = ds_nomads
		# Ethics and Civics Infinity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = uo_une_member_active
			"
			toggle = @post_revolutionary_re_revolution_years
		}
		# The Empty Vagrant
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = default_ev
			"
			toggle = @homeless_class_trait_weight
		}
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_zofe_compatible = yes
			"
			toggle = @has_zofe_vanilla
		}
	}
}
giga_is_special_country_type = {
	OR = {
		merg_is_fallen_empire = yes
		merg_is_awakened_fe = yes
		is_country_type = primitive
	}
}
giga_country_uses_supertensiles = {
	OR = {
		merg_is_default_empire = yes
		merg_is_fallen_empire = yes
		merg_is_awakened_fe = yes
		# Scipted Triggers Undercoat
		has_country_flag = is_empire
		# fairly expensive check as it uses an any_country
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_playable_country = yes
			"
			toggle = @has_gigastructures
		}
	}
}
giga_compat_hyperlane_exclude = {
	OR = {
		has_star_flag = giga_no_lanes
		# Darkspace
		has_star_flag = darkspace_void_control
		# Forgotten Empires
		has_star_flag = scfe_shaded_colony_system
		# Merger of Rules
		merg_is_isolated_system = yes
	}
}
giga_is_neutron_type_star = {
	OR = {
		is_planet_class = pc_neutron_star
		is_planet_class = pc_pulsar
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class_pc_collapsar = yes
				is_planet_class_pc_magnetar = yes
			"
			toggle = @rs_compatch_var
		}
	}
}
giga_gas_giant = { # Soon obsolete
	merg_is_gas_giant = yes
}
giga_is_gas_giant = {
	merg_is_gas_giant = yes
}
giga_is_frozen = {
	merg_is_frozen = yes
}
giga_is_ocean = {
	merg_is_aquatic = yes
}
giga_is_tropical = {
	merg_is_tropical = yes
}
giga_is_hive = {
	merg_is_hive_world = yes
}
giga_is_machine = {
	merg_is_machine_world = yes
}
giga_is_gaia = {
	merg_is_gaia = yes
}
giga_is_nuked = {
	merg_is_nuked_basic = yes
}
giga_is_arcology = {
	merg_is_arcology = yes
}
gigas_is_toxic = {
	merg_is_toxic = yes
}
giga_country_gets_bank_include = {
	OR = {
		# Darkspace
		is_country_type = ds_nomads
		# Ethics and Civics Infinity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = uo_une_member_active
			"
			toggle = @post_revolutionary_re_revolution_years
		}
		# Scripted Triggers Undercoat
		has_country_flag = is_playable
		# The Empty Vagrant
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_default_ev_country_type = yes
			"
			toggle = @homeless_class_trait_weight
		}
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_zofe_country = yes
			"
			toggle = @has_zofe_vanilla
		}
	}
}
giga_country_gets_bank = {
	inline_script = {
		script = merger_of_rules/toggled_code
		code = "
			giga_country_gets_bank_exclude = no
		"
		toggle = @has_gigastructures
	}
	giga_mod_country_gets_bank_exclude = no
	OR = {
		is_country_type = default
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
		giga_country_gets_bank_include = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_playable_country = yes
			"
			toggle = @has_gigastructures
		}
	}
}
giga_mod_country_gets_bank_exclude = {
	OR = {
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				ag_is_mod_country = yes
			"
			toggle = @ag_null_edict_length
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = acot_crazed_stellarite
				is_country_type = void_lifeforms_1
				is_country_type = void_lifeforms_2
			"
			toggle = @has_ancient_caches
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = afk_crisis_country
			"
			toggle = @swuss_mod
		}
		is_country_type = awakened_gate_builders
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = berserker_awoken_hive
			"
			toggle = @has_the_sleeper_mod
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = awakened_marauders_ev
				is_country_type = ev_leviathans_crisis
			"
			toggle = @homeless_class_trait_weight
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = master_ai_country
			"
			toggle = @has_emex_mod
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = mem_ancestor_guardian
			"
			toggle = @lex_compatch_var
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = mem_surveyor_country_red
				is_country_type = mem_vazurans
			"
			toggle = @has_more_events_mod
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = nep_arena_hologram
				is_country_type = nep_bounty_hologram
				is_country_type = nep_phantom_passive
			"
			toggle = @has_wild_space_mod
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = planet_state
			"
			toggle = @planet_states_mod
		}
		is_country_type = replicators
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = shroud_entities
				is_country_type = shroud_horrors
			"
			toggle = @has_shroud_rising_mod
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = sbtg_sentinel_active
			"
			toggle = @has_sbtg_mod
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = throng_country
			"
			toggle = @crimson_throng_mod
		}
		is_country_type = vbp_machine
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = wg_crisis_country
				is_country_type = wg_Khan_country_type
				is_country_type = wg_Khan_country_type_auto_delete
			"
			toggle = @wsg_mod
		}
	}
}
is_ndb_immune_star_planet = {
	OR = {
		merg_is_black_or_white_hole = yes
		has_planet_flag = ndb_immune_planet
		# APSR
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_planet_flag = apsr_planet
			"
			toggle = @has_apsr
		}
		solar_system = {
			has_star_flag = ndb_immune_system
		}
	}
}
ndb_can_target_planet = {
	NOR = {
		AND = {
			is_capital = yes
			exists = owner
			owner = { is_same_value = root }
		}
		is_star = yes
		is_astral_scar = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_birch_world = yes
				giga_is_alderson_disk = yes
				giga_is_pc_squareworld_habitable = yes
			"
			toggle = @has_gigastructures
		}
		is_planet_class = pc_ai
		has_planet_flag = cant_build_here
		# Merger of Rules
		has_planet_flag = merg_is_forbidden_target
		has_planet_flag = merg_forbidden_target
		merg_is_empty_space = yes
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_acot_awesome_planet_class = yes
			"
			toggle = @has_ancient_caches
		}
		# Darkspace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_ds_holosphere = yes
				is_ds_stellar_engine = yes
				is_ds_gc_star = yes
			"
			toggle = @has_darkspace_installed
		}
	}
}
ndb_can_target_system = {
	inline_script = {
		script = merger_of_rules/toggled_code
		code = "
			cohesive_system = no
			compound_cluster = no
			urmazin_system = no
			everchanging_system = no
			annihilator_system = no
		"
		toggle = @has_gigastructures
	}
	merg_is_hole_star_class = no
	merg_is_void_system = no
	NOR = {
		has_star_flag = blokkat_system_being_stripmined
		has_star_flag = blokkat_stripmined_system
		any_fleet_in_system = {
			exists = owner
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					owner = {
						is_country_type = blokkat_stripminers
					}
				"
				toggle = @has_gigastructures
			}
		}
		AND = {
			any_ship_in_system = {
				OR = {
					is_acot_sbtg_arkship = yes
					inline_script = {
						script = merger_of_rules/toggled_code
						code = "
							is_acot_herculean = yes
						"
						toggle = @has_ancient_caches
					}
				}
			}
		}
	}
	NOT = {
		any_system_planet = {
			OR = {
				AND = {
					is_capital = yes
					exists = owner
					owner = { is_same_value = root }
				}
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						giga_is_birch_world = yes
						giga_is_alderson_disk = yes
						giga_is_pc_squareworld_habitable = yes
					"
					toggle = @has_gigastructures
				}
				is_planet_class = pc_ai
				has_planet_flag = cant_build_here
				has_planet_flag = cant_target_this_planet
				# Merger of Rules
				merg_is_untargetable = yes
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						is_acot_awesome_planet_class = yes
					"
					toggle = @has_ancient_caches
				}
			}
		}
	}
}
giga_are_habitats_available = {
	optimize_memory
	inline_script = {
		script = merger_of_rules/toggled_code
		code = "
			is_giga_one_planet_origin = no
		"
		toggle = @has_gigastructures
	}
	OR = {
		AND = {
			has_technology = tech_habitat_1
			OR = {
				NOT = { has_global_flag = giga_habitats_disabled }
				has_origin = origin_void_dwellers
				has_origin = origin_toxic_knights
			}
		}
		has_civic = civic_diadochi
		has_civic = civic_great_khans_legacy
		has_country_flag = democratic_khanate_flag
	}
}
is_ndb_vulnerable_mega = {
	NOR = {
		mega_blokkats_wont_stripmine = yes
		merg_is_gate_mega = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_megastructure_type = blokkat_harvester_charged_mothership
				is_megastructure_type = blokkat_harvester_charged
				is_megastructure_type = blokkat_harvester_charging_up_mothership
				is_megastructure_type = blokkat_harvester_charging_up
			"
			toggle = @has_gigastructures
		}
		has_megastructure_flag = ndb_immune_megastructure
	}
}
giga_is_bitrinary = {
	OR = {
		is_star_class = sc_binary_1
		is_star_class = sc_binary_2
		is_star_class = sc_binary_3
		is_star_class = sc_binary_4
		is_star_class = sc_binary_5
		is_star_class = sc_binary_6
		is_star_class = sc_binary_7
		is_star_class = sc_binary_8
		is_star_class = sc_binary_9
		is_star_class = sc_binary_10
		is_star_class = sc_trinary_1
		is_star_class = sc_trinary_2
		is_star_class = sc_trinary_3
		is_star_class = sc_trinary_4
		# Forgotten Empires
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_scfe_binary_1
			"
			toggle = @forgotten_empires
		}
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_binary = yes
				is_trinary = yes
				is_paired = yes
			"
			toggle = @rs_compatch_var
		}
	}
}
