# Merger of Rules scripted triggers
# These triggers are also meant as a library for modders who want to reuse them in their own mods.

merg_is_standard_empire = {
	OR = {
		is_country_type = default
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
		# Ethics & 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
		has_country_flag = is_empire
		# The Empty Vagrant
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_default_ev_country_type = yes
				is_country_type = fallen_empire_ev
				is_country_type = awakened_fallen_empire_ev
			"
			toggle = @homeless_class_trait_weight
		}
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_zofe_country = yes
			"
			toggle = @has_zofe_vanilla
		}
	}
}

# Expanded version of country_type = default
merg_is_default_empire = {
	OR = {
		is_country_type = default
		# Ethics & 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
		}
	}
}

# List of dormant/standard Fallen Empires
merg_is_fallen_empire = {
	OR = {
		is_country_type = fallen_empire
		# AshArms Aquarius History
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = LsE_fallen_empire
			"
			toggle = @asharm_mod
		}
		# SW:KUAT ANCIENT EMPIRE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = kuat_fallen_empire
			"
			toggle = @sw_kuat_mod
		}
		# The Empty Vagrant
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = fallen_empire_ev
			"
			toggle = @homeless_class_trait_weight
		}
	}
}

# List of awakened Fallen Empires
merg_is_awakened_fe = {
	OR = {
		is_country_type = awakened_fallen_empire
		# A Deadly Tempest
		AND = {
			merg_has_deadly_tempest = yes
			is_country_type = awakened_gate_builders
		}
		# SW:KUAT ANCIENT EMPIRE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				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 = awakened_fallen_empire_ev
				is_country_type = awakened_fallen_empire_event
			"
			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
		}
	}
}

# List of all habitable ringworld sections
merg_is_hab_ringworld = {
	is_ringworld = yes
	OR = {
		is_colonizable = yes
		is_colony = yes
	}
}

# Crisis trigger
merg_is_true_ringworld = {
	OR = {
		is_planet_class = pc_ringworld_habitable
		is_planet_class = pc_shattered_ring_habitable
		is_planet_class = pc_cybrex
		# 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
		}
		# Darkspace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_ds_ancient_ringworld = yes
				is_ds_ringworld_spectrals = yes
			"
			toggle = @has_darkspace_installed
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_giga_maginot_ringworld
				is_planet_class = pc_ringworld_city
				is_planet_class = pc_ringworld_machine
				is_planet_class = pc_ringworld_hive
			"
			toggle = @has_gigastructures
		}
		# Warship Girls and MIST species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_ringworld_habitable_uf
				is_planet_class = pc_ringworld_habitable_auto_uf
				is_planet_class = pc_ringworld_habitable_sh
				is_planet_class = pc_ringworld_habitable_wsg
				is_planet_class = pc_ringworld_habitable_swim
			"
			toggle = @wsg_mod
		}
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_utopian_ringworld
			"
			toggle = @has_zofe_vanilla
		}
	}
}

# Listing habitats
merg_is_habitat = {
	OR = {
		is_planet_class = pc_habitat
		# Acquisition of Technology
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_aot_habitat = yes
			"
			toggle = @has_acquisition_of_tech
		}
		# DarkSpace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_ds_skycatcher = yes
			"
			toggle = @has_darkspace_installed
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_giga_elysium = yes
				giga_is_pc_giga_orbital = yes
			"
			toggle = @has_gigastructures
		}
		# Genshin Impact
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_tiankongdao
			"
			toggle = @trait_shijianzhe_sci_amt
		}
		# Girls Frontline
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_GFnytp_habitis
			"
			toggle = @gf_compatch_var
		}
		# Habitation
		has_planet_flag = hab_init
		# Living Space
		has_planet_flag = stpg_planetary_habitat
		# More Events Mod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_pc_mem_vazuran_habitat = yes
			"
			toggle = @has_more_events_mod
		}
		# Twinks Atlantean
		# uses_district_set = skypalace
		# Wula Fallen Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_fallen_empire_rogue_trader_habitat
			"
			toggle = @wula_compatch_var
		}
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_utopian_habitat
			"
			toggle = @has_zofe_vanilla
		}
	}
}

# Crisis triggers
merg_is_habitat_non_PD = {
	OR = {
		is_planet_class = pc_habitat
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_giga_elysium = yes
				giga_is_pc_giga_orbital = yes
			"
			toggle = @has_gigastructures
		}
		# Acquisition of Technology
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_aot_habitat = yes
			"
			toggle = @has_acquisition_of_tech
		}
		# More Events Mod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_pc_mem_vazuran_habitat = yes
			"
			toggle = @has_more_events_mod
		}
		# Nyto Species Pack
		# uses_district_set = GF_nyto_devil_furnace_world
		# SRA
		# uses_district_set = SRA_city_world
		# Twinks Atlantean
		# uses_district_set = skypalace
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_utopian_habitat
			"
			toggle = @has_zofe_vanilla
		}
	}
}

# These can't be infested by the Prethoryn
merg_is_special_colony = {
	OR = {
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_ehof_habitat = yes
				is_regular_giga_maginot_world = yes
				giga_is_pc_giga_planetary_computer = yes
				giga_is_pc_flat_world = yes
				giga_is_pc_interstellar_ringworld_habitable = yes
				giga_is_pc_interstellar_habitat = yes
				giga_is_pc_gigaorbital_ring = yes
				giga_is_pc_giga_penrose_habitable = yes
				giga_is_pc_equatorial_shipyard = yes
				giga_is_pc_squareworld_habitable = yes
				is_giga_habitable_gas_giant = yes
				giga_is_alderson_disk = yes
				giga_is_birch_world = yes
			"
			toggle = @has_gigastructures
		}
		# Warship Girls R and MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_habitat_wg = yes
				is_ringworld_wg = yes
			"
			toggle = @wsg_mod
		}
	}
}

merg_has_hive_trait = {
	OR = {
		has_trait = trait_hive_mind
		# Ethics and Civics - Bug Branch
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_bugged_happy_drone = yes
			"
			toggle = @has_bug_branch
		}
		# Trait Diversity
		is_td_multi_hiveminded = yes
	}
}

merg_is_nebulae = {
	optimize_memory
	OR = {
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_collapsar
				is_star_class = sc_p_purple
				is_star_class = sc_p_green
				is_star_class = sc_p_red
				is_star_class = sc_nova_1
				is_star_class = sc_nova_2
				is_star_class = sc_w_azure
				is_star_class = sc_w_red
				is_star_class = sc_w_green
				is_star_class = sc_w_purple
				is_star_class = sc_lbv_blue
				is_star_class = sc_lbv_green
				is_star_class = sc_lbv_red
			"
			toggle = @rs_compatch_var
		}
	}
}

# List of dense stars for planet killers
merg_is_dense_star = {
	optimize_memory
	OR = {
		is_planet_class = pc_black_hole
		is_planet_class = pc_neutron_star
		is_planet_class = pc_pulsar
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_acot_void_hole = yes
			"
			toggle = @has_ancient_caches
		}
		# Astro's Stellaris Overhaul - Galaxy Generation
		is_aso_gg_white_hole = yes
		# Darkspace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_ds_zeitriss_gc = yes
			"
			toggle = @has_darkspace_installed
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_birch_world = yes
				giga_is_black_hole = yes
				giga_is_white_hole = yes
			"
			toggle = @has_gigastructures
		}
		# Hypothetical Stars
		is_hypo_stars_black_dwarf_star = yes
		is_hypo_stars_strange_star = yes
		is_hypo_stars_white_hole = yes
		# Star Wars: Kuat Ancient Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_kuat_white_hole
			"
			toggle = @sw_kuat_mod
		}
		# MEM
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_pc_mem_micro_black_hole = yes
			"
			toggle = @has_more_events_mod
		}
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class_pc_collapsar = yes
				is_planet_class_pc_magnetar = yes
				is_rs_compat_microquasar = yes
			"
			toggle = @rs_compatch_var
		}
		# Solar Storm
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_ss_abyssal_black_hole
			"
			toggle = @ss_abyssal_laser_hull_damage
		}
		# Sparble's Stellar Hyperconstructs
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_white_dwarf_star
				is_planet_class = pc_black_dwarf_star
				is_planet_class = pc_quark_star
			"
			toggle = @has_stellar_hyperconstructs
		}
		# TimeMod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_time_black_hole_planet_class = yes
			"
			toggle = @timemod
		}
		# Voyage to Eternity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_KZ_VOY_micro_black_hole = yes
			"
			toggle = @vte_mod
		}
	}
}

merg_is_black_or_white_hole = {
	optimize_memory
	OR = {
		is_planet_class = pc_black_hole
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_acot_void_hole = yes
			"
			toggle = @has_ancient_caches
		}
		# Astro's Stellaris Overhaul - Galaxy Generation
		is_aso_gg_white_hole = yes
		# Darkspace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_ds_zeitriss_gc = yes
			"
			toggle = @has_darkspace_installed
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_birch_world = yes
				giga_is_black_hole = yes
				giga_is_white_hole = yes
			"
			toggle = @has_gigastructures
		}
		# Hypothetical Stars
		is_hypo_stars_white_hole = yes
		# MEM
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_pc_mem_micro_black_hole = yes
			"
			toggle = @has_more_events_mod
		}
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_rs_compat_microquasar = yes
			"
			toggle = @rs_compatch_var
		}
		# Solar Storm
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_ss_abyssal_black_hole
			"
			toggle = @ss_abyssal_laser_hull_damage
		}
		# TimeMod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_time_black_hole_or_white_hole_planet_class = yes
			"
			toggle = @timemod
		}
		# Voyage to Eternity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_KZ_VOY_micro_black_hole = yes
			"
			toggle = @vte_mod
		}
	}
}

merg_is_standard_dense_star = {
	optimize_memory
	OR = {
		is_planet_class = pc_black_hole
		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
		}
	}
}

# List of void stars and planets for planet killers exclusion
merg_is_empty_space = {
	optimize_memory
	OR = {
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_acot_invisible_star = yes
			"
			toggle = @has_sbtg_mod
		}
		# Ancient Empires
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_ag_void = yes
			"
			toggle = @ag_null_edict_length
		}
		# AshArms Aquarius History
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_empty_space
			"
			toggle = @asharm_mod
		}
		# Darkspace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_ds_gc_star = yes
			"
			toggle = @has_darkspace_installed
		}
		# Forgotten Empires
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				scfe_is_empty_space = yes
			"
			toggle = @forgotten_empires
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_giga_empty_space = yes
			"
			toggle = @has_gigastructures
		}
		# LEX
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_bwm_star_dummy
				is_planet_class = pc_bwm_planet_dummy
			"
			toggle = @lex_compatch_var
		}
		# Secrets of the Shroud
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_sm_empty_space = yes
			"
			toggle = @has_sots_mod
		}
		# Some Events of Outside Cluster
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_star_void_dummy_01
			"
			toggle = @has_seooc_mod
		}
		# Sparble's Stellar Hyperconstructs
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_ssh_empty_space
			"
			toggle = @has_stellar_hyperconstructs
		}
		# Steven Universe Homeworld Gems
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_steven_no_star = yes
			"
			toggle = @has_f93_gem_mod
		}
		# ThaumStellaris
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_tc_invisible = yes
			"
			toggle = @has_tc_mod
		}
	}
}

merg_is_hole_star_class = {
	optimize_memory
	OR = {
		is_star_class = sc_black_hole
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_acot_void_star
			"
			toggle = @has_ancient_caches
		}
		# Astro's Stellaris Overhaul - Galaxy Generation
		is_star_class = sc_aso_gg_white_hole
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_birch
				is_star_class = sc_birch_built
				is_star_class = sc_quasar
				is_star_class = sc_ehof_black_hole
				is_star_class = sc_void_birch_built
				is_star_class = sc_white_hole
			"
			toggle = @has_gigastructures
		}
		# More Precursors
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_FHMP_1 #
			"
			toggle = @HAS_FHMP
		}
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_microquasar_1
				is_star_class = sc_microquasar_2
			"
			toggle = @rs_compatch_var
		}
		# Some Events of Outside Cluster
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_Aemethms
				is_star_class = sc_grand_seal
			"
			toggle = @has_seooc_mod
		}
		# Sparble's Stellar Hyperconstructs
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_ssh_binary_1
				is_star_class = sc_ssh_binary_2
			"
			toggle = @has_stellar_hyperconstructs
		}
		# TimeMod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_white_hole
				is_time_black_hole_star_class = yes
			"
			toggle = @timemod
		}
		# Unique Ascension Perks
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_whitte_hole
			"
			toggle = @has_uap_mod
		}
	}
}

merg_is_neutron_star_class = {
	optimize_memory
	OR = {
		is_star_class = sc_binary_2
		is_star_class = sc_neutron_star
	}
}

merg_is_pulsar_star_class = {
	optimize_memory
	OR = {
		is_star_class = sc_binary_1
		is_star_class = sc_pulsar
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_collapsar
				is_star_class = sc_magnetar
				is_star_class = sc_binary_pl_pl
				is_star_class = sc_binary_pl_n
			"
			toggle = @rs_compatch_var
		}
	}
}

# List of void systems
merg_is_void_system = {
	optimize_memory
	OR = {
		# ACOT SBTG
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sofe_outer_class
				is_star_class = sofe_inner_class
			"
			toggle = @has_sbtg_mod
		}
		# Ancient Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_ag_void
				is_star_class = sc_ag_void_alt
			"
			toggle = @ag_null_edict_length
		}
		# AshArms Aquarius History/Gigas
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_empty_space
			"
			toggle = @[ has_gigastructures + asharm_mod ]
		}
		# Darkspace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_gc
			"
			toggle = @has_darkspace_installed
		}
		# Forgotten Empires
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_scfe_empty_space
			"
			toggle = @forgotten_empires
		}
		# Gigas
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_blokkat_stripmined
			"
			toggle = @has_gigastructures
		}
		# Some Events of Outside Cluster
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_Arena
				is_star_class = sc_void_dummy
			"
			toggle = @has_seooc_mod
		}
		# Sparble's Stellar Hyperconstructs
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_ssh_space
			"
			toggle = @has_stellar_hyperconstructs
		}
		# Steven Universe Homeworld Gems
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_no_star
			"
			toggle = @has_f93_gem_mod
		}
		# ThaumStellaris
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_tc_void
			"
			toggle = @has_tc_mod
		}
		# Wild Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_dn
			"
			toggle = @has_wild_space_mod
		}
	}
}

merg_is_shielded = {
	optimize_memory
	OR = {
		merg_is_shielded_world = yes
		# AOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_phanon_psg
				has_active_building = building_stellarite_psg
			"
			toggle = @has_acquisition_of_tech
		}
	}
}

# ZOFE support
merg_has_pacifist_government = {
	OR = {
		has_pacifist_government = yes
		AND = {
			merg_is_default_empire = yes
			has_ethic = "ethic_fanatic_pacifist"
		}
	}
}
merg_has_militarist_government = {
	OR = {
		has_militarist_government = yes
		AND = {
			merg_is_default_empire = yes
			has_ethic = "ethic_fanatic_militarist"
		}
	}
}
merg_has_spiritualist_government = {
	OR = {
		has_spiritualist_government = yes
		AND = {
			merg_is_default_empire = yes
			has_ethic = "ethic_fanatic_spiritualist"
		}
	}
}
merg_has_materialist_government = {
	OR = {
		has_materialist_government = yes
		AND = {
			merg_is_default_empire = yes
			has_ethic = "ethic_fanatic_materialist"
		}
	}
}

merg_is_special_ship = {
	OR = {
		is_ship_size = psionic_avatar
		is_ship_size = corrupted_avatar
		is_ship_size = leviathan_01_elder_tiyanki
		is_ship_size = leviathan_01_voidspawn
		is_ship_size = nanite_space_dragon_baby
		is_ship_size = space_dragon_red
		is_ship_size = space_dragon_baby
		is_ship_size = space_dragon_blue #Shard
		is_ship_size = space_dragon_origin
		is_ship_size = space_dragon_origin_baby
		is_ship_size = stellarite
		is_ship_size = asteroid #Lithoid, reanimated
		#Worst case scenarios:
		is_ship_size = dimensional_horror
		is_ship_size = shroud_manifestation
		is_ship_size = warped_consciousness
		is_reanimated = yes
	}
}

merg_is_isolated_system = {
	optimize_memory
	OR = {
		has_star_flag = abandoned_gateway
		has_star_flag = lcluster
		has_star_flag = sealed_system
		has_star_flag = surveillance_supercomputer_system
		has_star_flag = chosen_system
		has_star_flag = formless_system
		has_star_flag = ds_galactic_core
		has_star_flag = ds_se_system_fixed
		has_star_flag = extragalactic_cluster
		has_star_flag = miniature_universe
		# SEOOC
		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
		}
		# ACOT SBTG
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = outercluster
			"
			toggle = @has_sbtg_mod
		}
		# Ancient Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = ag_no_jump_in_system
			"
			toggle = @ag_null_edict_length
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = ark_isolated
			"
			toggle = @arknights_ANF
		}
		# LEX
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = lex_garden_cluster
			"
			toggle = @lex_compatch_var
		}
		# Star Wars: 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
			"
			toggle = @sw_kuat_mod
		}
		# More Events Mod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = mem_sadrell_extant_cluster
			"
			toggle = @has_more_events_mod
		}
		# Gigastructural Engineering and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = giga_grox_system
				has_star_flag = giga_system_six
				has_star_flag = giga_no_lanes
				has_star_flag = Paluush_system
			"
			toggle = @has_gigastructures
		}
		# 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
		}
	}
}

# Shortens two checks in game rules
merg_is_sapient = {
	NOR = {
		is_sapient = no
		has_trait = trait_zombie
	}
}

merg_has_happiness = {
	AND = {
		# Timemod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				TIME_RULE_trgr_Force_has_happiness = no
			"
			toggle = @timemod
		}
		# Vanilla
		NOR = {
			AND = {
				has_trait = trait_machine_unit
				exists = FROM
				FROM = { is_machine_empire = yes }
				# Ethics & Civics Bug Branch
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						FROM = {  is_bugged_happy_gestalt = no }
					"
					toggle = @has_bug_branch
				}
			}
			AND = {
				has_trait = trait_hive_mind
				# Ethics & Civics Bug Branch
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						FROM = {  is_bugged_happy_gestalt = no }
					"
					toggle = @has_bug_branch
				}
			}
			can_think = no
			# Diagrapher's Trait Mod
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					dtraits_happiness_restrictions = yes
				"
				toggle = @has_diagraphers_trait_mod
			}
			# ThaumStellaris
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					species = {
						OR = {
							is_archetype = TC_GOLEM
							is_archetype = TC_GOLEM_HIVE
							is_archetype = TC_GOLEM_MACHINE
						}
					}
				"
				toggle = @has_tc_mod
			}
			# Trait Diversity
			td_has_no_happiness = yes
			# Warship Girls R And MIST Species
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					wg_compat_has_sh_trait = yes
				"
				toggle = @wsg_mod
			}
			# Zob
			is_zob_uplifted = yes
			# Vanilla
			AND = {
				has_trait = trait_mechanical
				# Vanilla
				OR = {
					NOT = { exists = FROM }
					FROM = {
						OR = {
							is_machine_empire = yes
							NOT = { has_technology = tech_synthetic_workers }
							has_policy_flag = ai_outlawed
						}
					}
				}
			}
			AND = {
				has_trait = trait_cybernetic
				exists = FROM
				FROM = {
					OR = {
						AND = {
							is_machine_empire = yes
							has_civic = civic_machine_assimilator # Assimilator empire
						}
						AND = {
							is_democratic_authority = yes
							has_country_flag = cyber_collectivist
						}
					}
				}
			}
		}
	}
}
merg_is_slaver = {
	OR = {
		has_valid_civic = civic_slaver_guilds
		has_valid_civic = civic_indentured_assets
		has_valid_civic = civic_barbaric_despoilers
		# Ethics and Civics Alternative - FunEFork / Ethics & Civics: Bug Branch
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = civic_slaving_despots
				has_valid_civic = civic_slaving_despots_corpo
			"
			toggle = @[ has_eca_funefork + has_bug_branch ]
		}
		# Ethics and Civics Classic
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = civic_barbaric_despoilers_corporate
				has_valid_civic = civic_divine_order
			"
			toggle = @has_ecc_cog
		}
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = civic_master_race
			"
			toggle = @has_zofe_vanilla
		}
	}
}
merg_is_void_dweller = {
	OR = {
		has_origin = origin_void_dwellers
		has_origin = origin_void_machines
		# Freebooters
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_origin = origin_nsc_freebooter
				has_origin = origin_nsc_freebooter_federations
			"
			toggle = @has_nsc_freebooter_mod
		}
		# More Events Mod
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_origin = origin_mem_eden_protocol
			"
			toggle = @has_more_events_mod
		}
	}
}
merg_is_nomad = {
	OR = {
		# The Empty Vagrant
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = default_ev
			"
			toggle = @homeless_class_trait_weight
		}
		# Darkspace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = ds_nomads
			"
			toggle = @has_darkspace_installed
		}
		# None
		inline_script = {
			script = merger_of_rules/toggled_code_inverse
			code = "
				is_country_type = ds_nomads
			"
			toggle = @[ homeless_class_trait_weight + has_darkspace_installed ]
		}
	}
}
# Non-dense or failed stars (WIP)
merg_is_standard_star = {
	optimize_memory
	OR = {
		is_planet_class = pc_a_star
		is_planet_class = pc_b_star
		is_planet_class = pc_f_star
		is_planet_class = pc_g_star
		is_planet_class = pc_k_star
		is_planet_class = pc_m_star
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class_pc_a_super_star = yes
				is_planet_class_pc_ae_star = yes
				is_planet_class_pc_b_super_star = yes
				is_planet_class_pc_c_giant_star = yes
				is_planet_class_pc_d_star = yes
				is_planet_class_pc_f_super_star = yes
				is_planet_class_pc_g_giant_star = yes
				is_planet_class_pc_g_super_star = yes
				is_planet_class_pc_k_giant_star = yes
				is_planet_class_pc_k_super_star = yes
				is_planet_class_pc_l_star = yes
				is_planet_class_pc_lbv_blue_star = yes
				is_planet_class_pc_lbv_green_star = yes
				is_planet_class_pc_lbv_red_star = yes
				is_planet_class_pc_m_super_star = yes
				is_planet_class_pc_m_hyper_star = yes
				is_planet_class_pc_nova_1 = yes
				is_planet_class_pc_nova_2 = yes
				is_planet_class_pc_o_star = yes
				is_planet_class_pc_o_super_star = yes
				is_planet_class_pc_o_hyper_star = yes
				is_planet_class_pc_protostar = yes
				is_planet_class_pc_s_giant_star = yes
				is_planet_class_pc_tt_orange_star = yes
				is_planet_class_pc_tt_red_star = yes
				is_planet_class_pc_tt_white_star = yes
				is_planet_class_pc_w_azure_star = yes
				is_planet_class_pc_w_red_star = yes
				is_planet_class_pc_w_green_star = yes
				is_planet_class_pc_w_purple_star = yes
				is_planet_class_pc_y_star = yes
			"
			toggle = @rs_compatch_var
		}
	}
}

merg_has_precursor_intro = {
	if = {
		limit = { has_ariphaos_assorted_precursors = no }
		OR = {
			has_country_flag = vultaum_intro
			has_country_flag = yuht_intro
			has_country_flag = first_league_intro
			has_country_flag = irassian_intro
			has_country_flag = cybrex_intro
			has_country_flag = zroni_intro
			has_country_flag = baol_intro
			has_country_flag = inetian_intro
			has_country_flag = adakkaria_intro
			# Forgotten History
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_country_flag = plexi_intro
					has_country_flag = lartia_intro
				"
				toggle = @HAS_AAA
			}
			# More Precursors
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_country_flag = ixardian_intro
					has_country_flag = ezentian_intro
					has_country_flag = werediran_intro
				"
				toggle = @HAS_FHMP
			}
			# Unavoidable Changes
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_country_flag = volgan_intro
				"
				toggle = @HAS_UCmod
			}
			# Forgotten Empires
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_country_flag = scfe_precursor_set_sless
					has_country_flag = scfe_precursor_set_coprean
					has_country_flag = scfe_precursor_set_astanine
					has_country_flag = scfe_vinarii_intro
				"
				toggle = @forgotten_empires
			}
		}
	}
	else = { always = no }
}
is_homicidal_no_terminator = {
	OR = {
		has_valid_civic = civic_fanatic_purifiers
		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
		}
	}
}
