# Vanilla scripted triggers from 00_scripted_triggers.txt except megastructures ones

uninhabitable_regular_planet = {
	OR = {
		merg_is_molten = yes
		merg_is_barren = yes
		merg_is_barren_cold = yes
		merg_is_toxic = yes
		merg_is_frozen = yes
		# All these worlds
		is_submerged = yes
	}
}

colonizable_planet = {
	OR = {
		merg_is_relic_world = yes
		merg_is_arcology = yes
		merg_is_nuked = yes
		merg_is_hive_world = yes
		merg_is_machine_world = yes
		habitable_structure = yes
		habitable_planet = yes
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_acot_fractured_planet_class = yes
				is_acot_awesome_planet_class = yes
			"
			toggle = @has_ancient_caches
		}
		# SOTS
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
					is_sots_soulsphere = yes
			"
			toggle = @has_sots_mod
		}
		# APSR: Anomalies, Planetary and Space Resources
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_apsr_habitable_planet = yes
			"
			toggle = @has_apsr
		}
		# Endless Frontier
		is_mzilli_shadow = yes
		# Nanite Machine and Distant Stars Overhaul
		is_nanite_forgeworld = yes
		# TimeMod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_gas_colony
				is_planet_class = pc_psionic
				is_planet_class = pc_nanites
			"
			toggle = @timemod
		}
	}
	NOT = { has_planet_flag = cant_be_colonized }
}

habitable_planet = {
	OR = {
		habitable_planet_not_urban = yes
		merg_is_relic_world = yes
		merg_is_arcology = yes
		# Merger of Rules
		has_planet_flag = merg_is_habitable_planet
	}
	NOT = { has_planet_flag = merg_is_uninhabitable_planet }
}

habitable_planet_not_urban = {
	OR = {
		merg_is_alpine = yes
		merg_is_arctic = yes
		merg_is_arid = yes
		merg_is_continental = yes
		merg_is_desert = yes
		merg_is_gaia = yes
		merg_is_ocean = yes
		merg_is_savannah = yes
		merg_is_tropical = yes
		merg_is_tundra = yes
		# Gigastructures
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_lifeless = yes
				giga_is_katzenland = yes
			"
			toggle = @has_gigastructures
		}
		# Planetary Diversity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				pd_is_planet_class_all = yes
			"
			toggle = @has_planetary_diversity
		}
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_hollow
			"
			toggle = @rs_compatch_var
		}
		# SW: UnknownWorld Shipgirls Story
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_swuss_swgs_engineer = yes
				is_swuss_swgs_engineer_ringworld_hab = yes
			"
			toggle = @swuss_mod
		}
		# Warship Girls R And MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				wg_compat_is_pc_wsg_port = yes
				wg_compat_is_pc_shenhai = yes
			"
			toggle = @wsg_mod
		}
	}
}

is_urban_planet = {
	OR = {
		is_planet_class = pc_city
		merg_is_relic_world = yes
	}
}

is_starting_planet_type = {
	OR = {
		merg_is_desert = yes
		merg_is_tropical = yes
		merg_is_arid = yes
		merg_is_continental = yes
		merg_is_ocean = yes
		merg_is_tundra = yes
		merg_is_arctic = yes
		merg_is_alpine = yes
		merg_is_savannah = yes
	}
}

can_have_habitable_deposits = {
	OR = {
		merg_is_nuked_basic = yes
		merg_is_desert = yes
		merg_is_tropical = yes
		merg_is_arid = yes
		merg_is_continental = yes
		merg_is_ocean = yes
		merg_is_tundra = yes
		merg_is_arctic = yes
		merg_is_alpine = yes
		merg_is_savannah = yes
		merg_is_gaia_basic = yes
		merg_is_relic_world = yes
		# Planetary Diversity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				pd_is_planet_class_all = yes
			"
			toggle = @has_planetary_diversity
		}
	}
}

# Enforcing proper use of this trigger. You don't need to overwrite it since 3.0!
habitable_structure = {
	is_artificial = yes
	OR = {
		is_colony = yes
		is_colonizable = yes
	}
}

has_encountered_other_species = {
	OR = {
		has_origin = origin_syncretic_evolution
		has_origin = origin_necrophage
		has_origin = origin_payback
		has_valid_civic = civic_machine_servitor
		# Ethics and Civics Classic and ECA FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = civic_slave_race
				has_valid_civic = civic_symbiotic_race
			"
			toggle = @[ has_ecc_cog + has_eca_funefork ]
		}
		# Ethics and Civics: Bug Branch
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_bugged_evolutionary_architects = yes
				is_bugged_slave_race = yes
			"
			toggle = @has_bug_branch
		}
		# Vanilla
		num_communications > 0
		any_owned_pop = {
			NOR = {
				has_trait = "trait_mechanical"
				is_same_species = prev
			}
		}
	}
}

can_be_leader = {
	has_citizenship_rights = yes
	# Rule out Traits for servitude & lack of free will
	NOR = {
		has_trait = trait_syncretic_proles
		can_think = no
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_rooted_living_architecture = yes
			"
			toggle = @has_diagraphers_trait_mod
		}
	}
	OR = {
		is_robot_pop = no
		root = {
			OR = {
				has_technology = tech_synthetic_leaders
				is_machine_empire = yes
				is_mechanical_empire = yes
				is_individual_machine = yes
				# Maiden Frontier Gunstar Story Collection
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						GF_allow_doll_leaders = yes
					"
					toggle = @GF_OGAS_leveled_thread_add_start_after_level
				}
			}
		}
	}
	OR = {
		is_same_species = root
		root = {
			NAND = {
				has_origin = origin_necrophage
				has_trait = trait_necrophage
			}
		}
		# Girls Frontline
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				AND = {
					has_trait = GF_trait_doll
					root = {
						OR = {
							has_policy_flag = GF_doll_right_full
							has_policy_flag = GF_doll_right_limited
						}
					}
				}
			"
			toggle = @gf_compatch_var
		}
	}
}

can_be_military_leader = {
	is_enslaved = no
	is_sapient = yes
	OR = {
		is_robot_pop = no
		owner = { has_policy_flag = ai_full_rights }
		owner = { is_machine_empire = yes }
		owner = { is_individual_machine = yes }
	}
	OR = {
		AND = { # MIs only accept Fully Integrated leaders
			owner = { is_machine_empire = yes }
			has_citizenship_type = { type = citizenship_full_machine country = owner }
			has_military_service_type = { type = military_service_full }
		}
		AND = { # non-MIs accept whatever
			NOT = { owner = { is_machine_empire = yes } }
			has_military_service_type = { type = military_service_full }
		}
		# Girls Frontline
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				AND = {
					has_trait = GF_trait_doll
					owner = {
						OR = {
							has_policy_flag = GF_doll_right_full
							has_policy_flag = GF_doll_right_limited
						}
					}
				}
			"
			toggle = @gf_compatch_var
		}
	}
}

has_any_megastructure_in_empire = {
	any_owned_megastructure = {
		exists = this
		NOR = {
			merg_is_gate_mega = yes
			merg_is_habitat_mega = yes
			is_megastructure_type = orbital_ring
			is_megastructure_type = orbital_ring_ruined
			is_megastructure_type = orbital_ring_restored
			# Gigastructural Engineering & More
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					is_kilostructure = yes
				"
				toggle = @has_gigastructures
			}
			# Machine & Robot Expansion
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					xvcv_mdlc_is_non_gate_mega = yes
				"
				toggle = @oxr_mdlc_mod
			}
		}
	}
}

is_crisis_faction = {
	OR = {
		is_country_type = swarm
		is_country_type = extradimensional
		is_country_type = extradimensional_2
		is_country_type = extradimensional_3
		is_country_type = ai_empire
		is_country_type = gray_goo
		is_country_type = awakened_marauders
		is_country_type = synth_queen
		is_country_type = awakened_synth_queen
		is_country_type = synth_queen_storm
		is_country_type = voidworms_crisis
		# ACOT SBTG
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = sbtg_stellarborne_empire
			"
			toggle = @has_sbtg_mod
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_giga_crisis_faction = yes
			"
			toggle = @has_gigastructures
		}
		# Destiny: The Darkness Crisis
		is_country_type = darkness_country
		# Shroud Rising
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = shroud_horrors
				is_country_type = shroud_entities
				is_country_type = shroud_cult
			"
			toggle = @has_shroud_rising_mod
		}
		# The Sleeper
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = berserker_awoken_hive
			"
			toggle = @has_the_sleeper_mod
		}
		# Timemod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = dimensional_horror_crisis
			"
			toggle = @timemod
		}

	}
}

planet_can_be_liberated_from_owner = {
	owner = {
		NOR = {
			is_hive_empire = yes
			is_machine_empire = yes
			is_country_type = awakened_fallen_empire
			is_country_type = fallen_empire
			# ACOT SBTG
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					is_progenitor_empires = yes
					is_country_type = sbtg_light_seeker
				"
				toggle = @has_sbtg_mod
			}
			# Twinks Eternal Empire
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					is_country_type = eternal_empire
				"
				toggle = @has_eternal_empire
			}
			# ZOFE
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					is_country_type = ascended_empire
					is_country_type = lost_empire
				"
				toggle = @has_zofe_vanilla
			}
		}
	}
}

is_country_type_with_subjects = {
	OR = {
		is_country_type = default
		is_country_type = awakened_fallen_empire
		is_country_type = awakened_marauders
		# ACOT SBTG
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_progenitor_empires = yes
			"
			toggle = @has_sbtg_mod
		}
		# Twinks Eternal Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = eternal_empire
			"
			toggle = @has_eternal_empire
		}
		# 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_country = yes
			"
			toggle = @has_zofe_vanilla
		}
	}
}

is_regular_empire = {
	OR = {
		merg_is_standard_empire = yes
		is_country_type = awakened_marauders
		# Nanite Machines and Distant Stars Overhaul
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = gate_builders
			"
			toggle = @dso_pnm
		}
	}
	is_gestalt = no
}

is_default_or_fallen = {
	OR = {
		merg_is_default_empire = yes
		is_fallen_empire = yes
	}
}

is_megacorp = {
	OR = {
		has_authority = auth_corporate
		has_valid_civic = civic_galactic_sovereign_megacorp
		has_government = gov_imperial_domain_megacorp
		# Ethics and Civics - Bug Branch
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_bugged_megacorp = yes
			"
			toggle = @has_bug_branch
		}
		# Expanded Traits, Civics, Pops, and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_exp_private_auth = yes
				is_exp_cooperative = yes
			"
			toggle = @expops_compatch_var
		}
		# E&C FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_corporate_imperial_auth = yes
			"
			toggle = @has_eca_funefork
		}
		# Girls Frontline
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = GF_civic_GK
			"
			toggle = @gf_compatch_var
		}
		# More Corporate Authorities
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_mca_auth_cooperative = yes
				has_mca_auth_private = yes
			"
			toggle = @has_more_corporate_authorities
		}
		# Warship Girls R And MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				wg_compat_has_auth_warshipgirls = yes
			"
			toggle = @wsg_mod
		}
	}
}

is_autocracy = {
	OR = {
		is_gestalt = yes
		is_imperial_authority = yes
		is_dictatorial_authority = yes
		# Ethics and Civics Bug Branch
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_bugged_dynastic_enterprise = yes
			"
			toggle = @has_bug_branch
		}
		# Expanded Traits, Civics, Pops, and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_exp_private_auth = yes
			"
			toggle = @expops_compatch_var
		}
		# E&C FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_imperial = yes
				is_dictatorial = yes
			"
			toggle = @has_eca_funefork
		}
		# More Corporate Authorities
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_mca_auth_private = yes
			"
			toggle = @has_more_corporate_authorities
		}
	}
}

is_oligarchy = {
	OR = {
		is_oligarchic_authority = yes
		AND = {
			is_megacorp = yes
			OR = {
				merg_has_mca = yes
				merg_has_expanded_pops = yes
				is_egalitarian = no
			}
		}
	}
}

is_democracy = {
	OR = {
		has_authority = auth_democratic
		inline_script = {
			script = merger_of_rules/toggled_code_inverse
			code = "
				AND = {
					is_megacorp = yes
					is_egalitarian = yes
				}
			"
			toggle = @[ expops_compatch_var + has_eca_funefork + has_more_corporate_authorities ]
		}
		# Ethics and Civics Bug Branch
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_bugged_megacorp = yes
			"
			toggle = @has_bug_branch
		}
		# Ethics and Civics Classic
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_ecc_direct_democracy = yes
			"
			toggle = @has_ecc_cog
		}
		# Expanded Traits, Civics, Pops, and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_exp_cooperative = yes
			"
			toggle = @expops_compatch_var
		}
		# E&C FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_strict_democratic_auth = yes
				AND = {
					has_dict_democratic_auth = yes
					is_egalitarian = yes
				}
			"
			toggle = @has_eca_funefork
		}
	}
}

can_set_ai_policy = {
	is_mechanical_empire = no
	# Maiden Frontier Gunstar
	inline_script = {
		script = merger_of_rules/toggled_code
		code = "
			is_GF_authority = no
		"
		toggle = @GF_OGAS_leveled_thread_add_start_after_level
	}
	# Vanilla
	OR = {
		has_technology = tech_synthetic_workers
		has_technology = tech_sapient_ai
		any_relation = {
			has_communications = prev
			OR = {
				has_technology = tech_synthetic_workers
				has_technology = tech_sapient_ai
				is_machine_empire = yes
			}
			OR = {
				merg_is_default_empire = yes
				has_ai_personality_behaviour = robot_exploiter
				has_ai_personality_behaviour = robot_liberator
			}
		}
	}
}

has_comms_with_alien_empire = {
	any_relation = {
		has_communications = root
		OR = {
			merg_is_default_empire = yes
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
			# ACOT SBTG
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					is_progenitor_empires = yes
					is_country_type = sbtg_light_seeker
				"
				toggle = @has_sbtg_mod
			}
		}
	}
}

has_comms_with_alien_civilization = {
	any_relation = {
		has_communications = root
		OR = {
			merg_is_default_empire = yes
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
			is_country_type = enclave
			is_country_type = nomad
			is_country_type = dormant_marauders
			is_country_type = awakened_marauders
			# ACOT SBTG
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					is_progenitor_empires = yes
					is_country_type = sbtg_light_seeker
				"
				toggle = @has_sbtg_mod
			}
			# Scripted Trigger Undercoat
			has_country_flag = stu_counts_as_civilization_for_comms
		}
	}
}

has_total_war_cb = {
	OR = {
		#attacker checks
		AND = {
			OR = {
				merg_is_default_empire = yes
				is_fallen_empire = yes
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						is_progenitor_empires = yes
					"
					toggle = @has_sbtg_mod
				}
			}
			OR = {
				is_country_type = awakened_fallen_empire
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_machine_assimilator
				AND = {
					has_valid_civic = civic_machine_terminator
					from = {
						NOR = {
							has_country_flag = synthetic_empire
							is_machine_empire = yes
							is_individual_machine = yes
						}
					}
				}
				AND = {
					has_valid_civic = civic_fanatic_purifiers
					NOT = { is_same_species = from }
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						is_progenitor_empires = yes
					"
					toggle = @has_sbtg_mod
				}
				# Expanded Traits, Civics, Pops, and More
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_valid_civic = civic_infestation
					"
					toggle = @expops_compatch_var
				}
				# Kek's Origins+
				has_valid_civic = KO_hive_asm
				# Loud but Deadly
				has_country_flag = lbd_dathnak_country
			}
		}
		#end threat checks
		AND = {
			OR = {
				merg_is_default_empire = yes
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						is_progenitor_empires = yes
					"
					toggle = @has_sbtg_mod
				}
			}
			OR = {
				NOR = {
					is_country_type = awakened_fallen_empire
					is_homicidal = yes
					has_valid_civic = civic_machine_assimilator
					# Kek's Origins+
					has_valid_civic = KO_hive_asm
				}
			}
			from = {
				OR = {
					is_country_type = awakened_fallen_empire
					is_homicidal = yes
					has_valid_civic = civic_machine_assimilator
					# ACOT SBTG
					inline_script = {
						script = merger_of_rules/toggled_code
						code = "
							is_progenitor_empires = yes
						"
						toggle = @has_sbtg_mod
					}
					# Loud but Deadly
					has_country_flag = lbd_dathnak_country
					is_machine_assimilator = yes
					# Kek's Origins+
					has_valid_civic = KO_hive_asm
				}
			}
		}
	}
}

is_homicidal = {
	OR = {
		has_valid_civic = civic_fanatic_purifiers
		has_valid_civic = civic_machine_terminator
		has_valid_civic = civic_hive_devouring_swarm
		# Darkspace
		has_country_flag = is_homicidal_empire
		# Electroids Species Pack
		has_valid_civic = civic_elec_stellar_devourers
		# Expanded Traits, Civics, Pops, and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = civic_infestation
			"
			toggle = @expops_compatch_var
		}
	}
}

is_unfriendly = {
	OR = {
		is_homicidal = yes
		has_valid_civic = civic_barbaric_despoilers
		# Darkspace
		has_country_flag = is_unfriendly_empire
		# Expanded Traits, Civics, Pops, and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = civic_living_hosts
			"
			toggle = @expops_compatch_var
		}
	}
}

is_wet = {
	OR = {
		has_climate = wet
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_wet = yes
			"
			toggle = @has_gigastructures
		}
		# Wandering Witch: Voyagers
		has_planet_flag = wet_planet
	}
}

is_dry = {
	has_climate = dry
	merg_is_arcology = no
}

# Overwriting with vanilla for a correct use of the triggers
is_cold = {
	has_climate = cold
}

is_fallen_empire = {
	OR = {
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
		# A Deadly Tempest
		AND = {
			merg_has_deadly_tempest = yes
			is_country_type = awakened_gate_builders
		}
		# AshArms Aquarius History
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = LsE_fallen_empire
			"
			toggle = @asharm_mod
		}
		# Nanite Machines and Distant Stars Overhaul
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = gate_builders
			"
			toggle = @dso_pnm
		}
		# SW:KUAT ANCIENT EMPIRE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = kuat_fallen_empire
				is_country_type = kuat_awakened_fallen_empire
				is_country_type = awakened_return_kuat_empire
			"
			toggle = @sw_kuat_mod
		}
		# The Empty Vagrant
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = fallen_empire_ev
				is_country_type = awakened_fallen_empire_ev
			"
			toggle = @homeless_class_trait_weight
		}
		# Wula Fallen Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = first_emperor_awakened_fallen_empire
			"
			toggle = @wula_compatch_var
		}
	}
}

is_crossbreeding_possible = {
	is_sapient = yes
	NOR = {
		has_trait = trait_machine_unit
		has_trait = trait_mechanical
		has_trait = trait_hive_mind
		has_trait = trait_self_modified
		has_trait = trait_clone_soldier_infertile
		has_trait = trait_clone_soldier_infertile_full_potential
		# Expanded Traits, Civics, Pops, and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_exp_clone = yes
				is_half_species = any
				AND = {
					count_galaxy_species = {
						count > 7
						limit = { is_half_species = PREV }
					}
				}
			"
			toggle = @expops_compatch_var
		}
		# Ethics and Civics Infinity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_eci_fallen_god = yes
			"
			toggle = @post_revolutionary_re_revolution_years
		}
	}
}

is_special_colony_type = {
	OR = {
		has_modifier = penal_colony
		has_modifier = resort_colony
		has_modifier = slave_colony
		has_modifier = gestation_colony
		# Girls Frontline
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_GF_automated_city
			"
			toggle = @gf_compatch_var
		}
		# Real Space - Planetary Stations
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_planet_flag = planetary_station
			"
			toggle = @rs_compatch_var
		}
	}
}

# Country scope
has_precursor_intro = {
	OR = {
		merg_has_precursor_intro = yes
		# Still in the early stages of 'On the Shoulders of Giants'
		AND = {
			has_origin = origin_shoulders_of_giants
			NOT = { has_country_flag = origin_shoulders_closure }
		}
		# Gigas exclusion
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_origin = origin_incohesive
			"
			toggle = @has_gigastructures
		}
	}
}

# Merging and fixing
default_endgame_early_start_triggers = {
	AND = {
		OR = {
			NOT = {
				any_country = {
					OR = {
						merg_is_fallen_empire = yes
						merg_is_awakened_fe = yes
					}
				}
			}
			has_global_flag = no_war_in_heaven
			AND = {
				has_global_flag = war_in_heaven_started
				OR = {
					has_global_flag = war_in_heaven_ended
					NOT = {
						has_global_flag = war_in_heaven_recently_started
					}
				}
			}
		}
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				OR = {
					has_global_flag = acot_dangerous_forbidden
					NOR = {
						has_global_flag = acot_war_in_hell_active
						has_global_flag = active_sofe_crisis
					}
				}
			"
			toggle = @has_ancient_caches
		}
		# Nirvana Empire Project
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				NOT = { has_global_flag = difficult_exe_invasion }
			"
			toggle = @nirvana_mod
		}
		# Star Wars: UnknownWorld Shipgirls Story
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				NOT = { has_global_flag = afk_crisis_real }
			"
			toggle = @swuss_mod
		}
		# Warship Girls R And MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				NOT = { has_global_flag = wg_crisis_insane }
			"
			toggle = @wsg_mod
		}
	}
}

no_resource_for_component = {
	exists = event_target:global_event_country # used to reduce the heavy cpu usage on the empire creation screen.
	merg_is_default_empire = yes
	OR = {
		NOT = { can_buy_on_market = $RESOURCE$ }
		AND = {
			is_ai = yes
			has_monthly_income = { resource = $RESOURCE$ value < -2 }
			resource_stockpile_compare = { resource = $RESOURCE$ value < 150 }
		}
	}
}

has_research_building = {
	OR = {
		has_building = building_research_lab_1
		has_building = building_research_lab_2
		has_building = building_research_lab_3
		has_building = building_institute
		has_building = building_supercomputer
		has_building = building_astrometeorology_observation_center
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_building = building_acot_dm_enigmatic_lab
				has_building = building_acot_dm_institute
				has_building = building_acot_ae_enigmatic_lab
				has_building = building_acot_ae_institute
			"
			toggle = @has_ancient_caches
		}
		# Ad Astra Technology Mod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_building = building_grand_academy
				has_building = building_cynosural_beacon
				has_building = building_cynosural_lighthouse
				has_building = building_academy_district
				has_building = building_expedition_headquarters
				has_building = building_deep_research_hives
				has_building = building_cynosural_nexus
				has_building = building_cynosural_link
				has_building = building_orbital_research_hive
				has_building = building_expedition_vault
				has_building = building_omni_network_nodes
				has_building = building_cynosural_uplink_node
				has_building = building_cynosural_uplink_nexus
				has_building = building_orbital_research_uplink
				has_building = building_cynosural_singularity
			"
			toggle = @has_ad_astra_tech_mod
		}
		# AOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_building = building_phanon_enigmatic_lab
				has_building = building_phanon_institute
				has_building = building_stellarite_enigmatic_lab
				has_building = building_stellarite_institute
			"
			toggle = @has_acquisition_of_tech
		}
		# Ancient Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_building = ag_ancient_structure
				has_building = ag_ancient_lab
				has_building = ag_ancient_lab_corp
				has_building = ag_ancient_lab_overlord
			"
			toggle = @ag_null_edict_length
		}
		# APSR
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_apsr_produce_science = yes
			"
			toggle = @has_apsr
		}
		# Additional Vanilla Buildings
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_avb_research_building = yes
			"
			toggle = @has_avb_mod
		}
		# District Overhaul - FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_do3f_nature_reserve
				has_district = district_do3f_research_complex
				has_district = district_do3f_scrapyard
				has_district = district_02_workshops
				has_district = district_02_university
			"
			toggle = @has_do3f_mod
		}
		# EDA
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_building = eda_building_research_lab
			"
			toggle = @eda_mod
		}
		# EUTAB
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				eutab_has_research_building = yes
			"
			toggle = @has_eutab_unofficial
		}
		# Extra Districts
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				ED_has_research_district = yes
			"
			toggle = @is_ED_enabled
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_has_research_building = yes
			"
			toggle = @has_gigastructures
		}
		# GPM
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_building = gpm_precursor_research_center
			"
			toggle = @has_guillis_planet_modifiers
		}
		# More Standard Districts
		has_district = district_standard_cm_science
		# Planetary Diversity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_building = building_storm_lab
				has_district = district_pdhab_science
				has_district = district_arcology_research_complex
				has_district = district_machine_research_district
				has_district = district_bioforge_brain
				has_district = district_archive_science
				has_district = district_scrapyard_recyclers
			"
			toggle = @has_planetary_diversity
		}
		# Plentiful Traditions
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_building = building_plentiful_traditions_university_of_wisdom
				has_building = building_plentiful_traditions_cybernetics_facility
				has_building = building_plentiful_traditions_experimental_weapons_facility
				has_building = building_plentiful_traditions_biogenesis_lab
			"
			toggle = @plentrad_compatch_var
		}
	}
}

can_have_sensory_readings = {
	OR = {
		is_asteroid = yes
		merg_is_frozen = yes
		merg_is_barren = yes
		merg_is_barren_cold = yes
		merg_is_desert = yes
		merg_is_tropical = yes
		merg_is_arid = yes
		merg_is_continental = yes
		merg_is_ocean = yes
		merg_is_tundra = yes
		merg_is_arctic = yes
		merg_is_alpine = yes
		merg_is_savannah = yes
		merg_is_gaia = yes
		merg_is_relic_world = yes
		merg_is_arcology = yes
	}
}

is_reanimator = {
	OR = {
		has_valid_civic = civic_reanimated_armies
		has_valid_civic = civic_permanent_employment
		has_valid_civic = civic_hive_cordyceptic_drones
		has_ascension_perk = ap_mechromancy
		# All That Is GRIMDARK
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = civic_hive_reanimated_armies
				has_origin = origin_bioreformers
			"
			toggle = @has_allthatisgrimdark_mod
		}
		# Libra: Gestalt Age
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_origin = origin_libra_ghost_mechanist
			"
			toggle = @libra_mod
		}
	}
}

is_organic_controllable_ship = {
	OR = {
		is_ship_size = space_amoeba
		is_ship_size = space_amoeba_mother
		is_ship_size = space_amoeba_centenarian
		is_ship_size = large_ship_swarm
		is_ship_size = small_ship_swarm
		is_ship_size = large_ship_carrier_swarm
		AND = { # cloned space fauna
			is_space_fauna = yes
			is_reanimated = no
			owner = {
				is_fauna_country = no
			}
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_vat_normal = yes
			"
			toggle = @has_gigastructures
		}
	}
}

has_any_industry_district = {
	OR = {
		has_district = district_industrial
		has_district = district_hab_industrial
		has_district = district_rw_industrial
		has_district = district_arcology_arms_industry
		has_district = district_arcology_civilian_industry
		# District Overhaul - FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_02_local_industry
				has_district = district_02_production_hub
			"
			toggle = @has_do3f_mod
		}
		# Extra Districts
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_ED_industrialist
				has_any_ED_industry_combined_district = yes
			"
			toggle = @is_ED_enabled
		}
		# Gigastructures
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_has_any_industrial_district = yes
			"
			toggle = @has_gigastructures
		}
		# GPM
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_gpm_precursor_manufactorium
			"
			toggle = @has_guillis_planet_modifiers
		}
		# Nanite Machines & Distant Stars Overhaul
		has_district = district_nanite_forgeworld_industry
		# Real Space - Planetary Stations
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_foundry_plant
			"
			toggle = @rs_compatch_var
		}
		# Warship Girls R and MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_dr_industrial
			"
			toggle = @wsg_mod
		}
		# Wula Fallen Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_wandering_knight_order_industry
			"
			toggle = @wula_compatch_var
		}
	}
}

has_any_farming_district_or_buildings = {
	OR = {
		has_district = district_farming
		has_district = district_rw_farming
		has_district = district_farming_uncapped
		merg_has_food_building = yes
		# District Overhaul - FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_f_nature_farms
				has_district = district_f_ocean_farms
				has_district = district_f_exotic_farms
				has_district = district_f_oasis_farms
				has_district = district_f_cave_farms
				has_district = district_f_industrial_farms
				has_district = district_02_hydroponic_bay
			"
			toggle = @has_do3f_mod
		}
		# Extra Districts
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				ED_has_farming_district = yes
			"
			toggle = @is_ED_enabled
		}
		# Gigastructures
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_has_any_farming_district_or_buildings = yes
			"
			toggle = @has_gigastructures
		}
	}
}

has_any_mining_district = {
	OR = {
		has_district = district_mining
		has_district = district_hab_mining
		has_district = district_mining_uncapped
		# District Overhaul - FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_m_unstable_mining
				has_district = district_m_stable_mining
				has_district = district_m_surface_mining
				has_district = district_m_deep_mining
				has_district = district_m_mountain_mining
				has_district = district_do3f_rw_asteroid_belt_mining
			"
			toggle = @has_do3f_mod
		}
		# Extra Districts
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				ED_has_mining_district = yes
			"
			toggle = @is_ED_enabled
		}
		# Gigastructures
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_has_any_mining_district = yes
			"
			toggle = @has_gigastructures
		}
		# Real Space - Planetary Stations
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_mining_complex
				has_district = district_ore_processing_complex
				has_district = district_mining_bay
			"
			toggle = @rs_compatch_var
		}
		# Wula Fallen Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_wula_abandon_forge_world_core
			"
			toggle = @wula_compatch_var
		}
	}
}

has_any_generator_district_or_building = {
	OR = {
		has_district = district_generator
		has_district = district_hab_energy
		has_district = district_generator_uncapped
		has_district = district_rw_generator
		merg_has_energy_building = yes
		# District Overhaul - FunEFork
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_e_fusion_generator
				has_district = district_e_fossil_fuel_generator
				has_district = district_e_wind_turbines
				has_district = district_e_geothermal_generator
				has_district = district_e_solar_generator
				has_district = district_e_tidal_generator
				has_district = district_e_biomass_generator
			"
			toggle = @has_do3f_mod
		}
		# Extra Districts
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				ED_has_generator_district = yes
			"
			toggle = @is_ED_enabled
		}
		# Gigastructures
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_has_any_generator_district_or_building = yes
			"
			toggle = @has_gigastructures
		}
		# GPM
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_gpm_precursor_power_plant
			"
			toggle = @has_guillis_planet_modifiers
		}
		# Real Space - Planetary Stations
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_geothermal_power_plant
				has_district = district_hydrocarbon_power_plant
				has_district = district_solar_power_plant
				has_district = district_atmospheric_power_plant
			"
			toggle = @rs_compatch_var
		}
		# Wula Fallen Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_district = district_wula_abandon_forge_world_surface
			"
			toggle = @wula_compatch_var
		}
	}
}

uses_habitat_capitals = {
	OR = {
		is_planet_class = pc_habitat
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_uses_habitat_capitals = yes
				has_planet_flag = giga_habitat_capital_compat
			"
			toggle = @has_gigastructures
		}
		# Others
		uses_district_set = habitat
	}
}

has_special_star_flag_trigger = {
	OR = {
		# Start System Flags
		has_star_flag = empire_home_system
		has_star_flag = neighbor_t1
		has_star_flag = neighbor_t1_first_colony
		has_star_flag = neighbor_t2
		has_star_flag = neighbor_t2_second_colony
		has_star_flag = empire_cluster
		# Enclaves
		has_star_flag = enclave
		has_star_flag = caravaneer_home
		# L-Gate
		has_star_flag = lgate
		has_star_flag = lcluster1
		has_star_flag = lcluster2
		has_star_flag = lcluster3
		has_star_flag = lcluster4
		has_star_flag = lcluster5
		has_star_flag = lcluster_lgate
		has_star_flag = lgateguaranteed
		# Leviathans
		has_star_flag = tiyanki_home_system
		has_star_flag = amoeba_home_system
		has_star_flag = voidworms_system
		has_star_flag = frenzied_voidworms_system
		has_star_flag = crystal_system
		has_star_flag = crystal_splitter_starting_system
		has_star_flag = crystal_splitter_destination_system
		# Hostile Systems
		has_star_flag = marauder_system
		has_star_flag = hostile_system
		has_star_flag = guardian
		has_star_flag = sealed_system
		has_star_flag = guardians_of_zanaam
		# Megastructures
		has_star_flag = abandoned_gateway
		has_star_flag = ruined_mega_shipyard_system
		has_star_flag = ruined_dyson_system
		has_star_flag = ruined_catapult_system
		has_star_flag = ruined_nexus_system
		has_star_flag = ruined_orbital_ring_system
		has_star_flag = ruined_sentry_system
		has_star_flag = ruined_ring_system
		# Others
		has_star_flag = mechanocalibrator_system
		has_star_flag = rubricator_system
		has_star_flag = last_baol_system
		has_star_flag = Zrocursor
		has_star_flag = overlord_empire_flag
		# Ancient Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = ag_no_jump_in_system
			"
			toggle = @ag_null_edict_length
		}
		# ACOT SBTG
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = outercluster
			"
			toggle = @has_sbtg_mod
		}
		# Assault Lily
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = al_huge_home_bed
			"
			toggle = @change_planet_size_bullet_num
		}
		# Battle for the Core
		has_star_flag = Midrimguardian
		# Fatherland
		has_star_flag = mil_relic_system
		# Gigastructural Engineering and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = flusion_system
				has_star_flag = giga_core_03
				has_star_flag = giga_system_one
				has_star_flag = giga_system_two
				has_star_flag = giga_system_three
				has_star_flag = giga_system_four
				has_star_flag = giga_system_five
				has_star_flag = giga_system_six
				has_star_flag = jupitwo_system
				has_star_flag = pouchkinn_system
			"
			toggle = @has_gigastructures
		}
		# LEX
		has_star_flag = lex_garden_cluster
		# More Events Mod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = mem_sadrell_extant_cluster
			"
			toggle = @has_more_events_mod
		}
		# Planetary Diversity Unique Worlds
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = floating_system
				has_star_flag = pdcrystal_system
				has_star_flag = biosynth_system
			"
			toggle = @has_planetary_diversity_unique_worlds
		}
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = star_disaster
			"
			toggle = @rs_compatch_var
		}
		# Scripted Trigger Undercoat
		has_star_flag = stu_has_special_star_flag
		# Some Events of Outside Cluster
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = nep_Krahen_cluster
				has_star_flag = nep_dragon_system
				has_star_flag = nep_heptagram_cluster
				has_star_flag = nep_Scrus_cluster
				has_star_flag = nep_seal_system
				has_star_flag = nep_highway_station_system
				has_star_flag = nep_highway_note_system
				has_star_flag = nep_Step_to_the_Void_1
				has_star_flag = nep_Step_to_the_Void_2
				has_star_flag = nep_Step_to_the_Void_3
				has_star_flag = nep_Step_to_the_Void_4
				has_star_flag = nep_Step_to_the_Void_5
				has_star_flag = nep_Step_to_the_Void_6
				has_star_flag = nep_Step_to_the_Void_7
				has_star_flag = nep_Step_to_the_Void_8
				has_star_flag = nep_Step_to_the_Void_9
				has_star_flag = nep_Step_to_the_Void_10
				has_star_flag = nep_wohp_system
				has_star_flag = nep_deus_system
				has_star_flag = nep_deus_system_2
				has_star_flag = nep_deus_system_3
				has_star_flag = nep_deus_system_4
				has_star_flag = nep_whitegoo_portal_1
				has_star_flag = nep_whitegoo_portal_2
				has_star_flag = nep_whitegoo_origin
				has_star_flag = nep_ugo_system
			"
			toggle = @has_seooc_mod
		}
		# SW:Kuat Ancient Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = Kuat_system
				has_star_flag = Kuat_system_1
				has_star_flag = Kuat_system_2
				has_star_flag = Kuat_system_3
				has_star_flag = kuat_initial_system
				has_star_flag = Kuat_system_int
				has_star_flag = Kuat_system_int_1
				has_star_flag = Kuat_system_int_2
				has_star_flag = Kuat_system_int_3
				has_star_flag = Kuat_system_int_4
				has_star_flag = starkiller_system
			"
			toggle = @sw_kuat_mod
		}
		# Warship Girls R And MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = wg_sealed_system
				has_star_flag = wg_psionic_systems
			"
			toggle = @wsg_mod
		}
		# Misc
		has_star_flag = extragalactic_cluster
	}
}

can_think = {
	NOR = {
		has_trait = trait_nerve_stapled
		has_trait = trait_zombie
		has_trait = trait_robot_suppressed
		# Expanded Events
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_exp_memorex_comatos = yes
			"
			toggle = @expevents_compatch_var
		}
		# V_Traits
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_v_non_thinking_trait = yes
			"
			toggle = @has_v_traits_mod
		}
	}
}

has_no_non_gate_megastructure = {
	OR = {
		has_any_megastructure = no
		NOR = {
			has_star_flag = ring_world_built
			AND = {
				has_any_megastructure = yes
				merg_has_gate_mega = no
			}
		}
	}
}

is_slaver = { merg_is_slaver = yes }
