# Scripted triggers from mods, expanded to acknowledge other mods.

############################### Additional Vanilla Buildings ###############################
has_any_organic_assembly_building = {
	OR = {
		merg_has_cloning_building = yes
		merg_has_clone_army_building = yes
	}
}
has_upgraded_capital_4 = {
    if = {
        limit = { has_modifier = resort_colony }
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
				    fail_text = requires_building_resort_capital_3
				"
				toggle = @has_avb_mod
			}
			has_building = building_ancient_palace
			# ACOT
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = building_acot_dm_ancient_palace
					has_building = building_acot_ae_ancient_palace
					has_building = building_phanon_tower
					has_building = building_acot_ruined_giga_fortress
				"
				toggle = @has_ancient_caches
			}
			# ACOT SBTG
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
						has_sbtg_upgraded_capital = yes
				"
				toggle = @has_sbtg_mod
			}
			# AOT
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = building_stellarite_palace
					has_building = building_stellarite_control_center
					has_building = building_stellarite_hive_cluster
					has_building = building_phanon_palace
				"
				toggle = @has_acquisition_of_tech
			}
			# AVB
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = building_avb_resort_capital_3
				"
				toggle = @has_avb_mod
			}
			# EDA
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = eda_building_imperial_capital
				"
				toggle = @eda_mod
			}
			# Star Wars: Kuat Ancient Empire
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
						has_building = building_kuat_command_center
					"
				toggle = @sw_kuat_mod
			}
			# Twinks Atlantean
			has_building = building_ancient_palace_at
			# Twinks Eternal Empire
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = building_eternal_palace
				"
				toggle = @has_eternal_empire
			}
			# Twinks Kaldorei
			has_building = building_nightelf_palace
	    }
    }
    else_if = {
        limit = { has_modifier = slave_colony }
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
		            fail_text = requires_building_slave_capital_3
				"
				toggle = @has_avb_mod
			}
			has_building = building_ancient_palace
			# ACOT
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = building_acot_dm_ancient_palace
					has_building = building_acot_ae_ancient_palace
					has_building = building_phanon_tower
					has_building = building_acot_ruined_giga_fortress
				"
				toggle = @has_ancient_caches
			}
			# ACOT SBTG
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
						has_sbtg_upgraded_capital = yes
				"
				toggle = @has_sbtg_mod
			}
			# AOT
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = building_stellarite_palace
					has_building = building_stellarite_control_center
					has_building = building_stellarite_hive_cluster
					has_building = building_phanon_palace
				"
				toggle = @has_acquisition_of_tech
			}
			# AVB
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = building_avb_slave_capital_3
				"
				toggle = @has_avb_mod
			}
			# EDA
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = eda_building_imperial_capital
				"
				toggle = @eda_mod
			}
			# Star Wars: Kuat Ancient Empire
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
						has_building = building_kuat_command_center
					"
				toggle = @sw_kuat_mod
			}
			# Twinks Atlantean
			has_building = building_ancient_palace_at
			# Twinks Eternal Empire
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					has_building = building_eternal_palace
				"
				toggle = @has_eternal_empire
			}
			# Twinks Kaldorei
			has_building = building_nightelf_palace
        }
    }
    else_if = {
		limit = { uses_habitat_capitals = yes }
		custom_tooltip = {
			fail_text = "requires_building_hab_capital"
			OR = {
				has_building = building_imperial_capital
				has_building = building_imperial_machine_capital
				has_building = building_imperial_hive_capital
				has_building = building_ancient_palace
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_palace
						has_building = building_acot_ae_ancient_palace
						has_building = building_acot_dm_ancient_hive_cluster
						has_building = building_acot_ae_ancient_hive_cluster
						has_building = building_acot_dm_ancient_control_center
						has_building = building_acot_ae_ancient_control_center
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_palace
						has_building = building_stellarite_control_center
						has_building = building_stellarite_hive_cluster
						has_building = building_phanon_palace
						has_building = building_phanon_hive_cluster
						has_building = building_phanon_control_center
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_avb_hab_capital_4
					"
					toggle = @has_avb_mod
				}
				# Dawn of the Republic
				has_building = building_galactic_senate
				# EDA
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = eda_building_imperial_capital
					"
					toggle = @eda_mod
				}
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
				# Twinks Atlantean
				has_building = building_ancient_palace_at
				# Twinks Kaldorei
				has_building = building_nightelf_palace
				# Twinks Eternal
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_eternal_nexus_ai
						has_building = building_eternal_palace
					"
					toggle = @has_eternal_empire
				}
				# Wula Fallen Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_wula_archive
						has_building = building_all_is_dust
						has_building = building_wula_order_keep
						has_building = building_wula_gene_bank
					"
					toggle = @wula_compatch_var
				}
			}
		}
	}
    else_if = {
        limit = { owner = { is_hive_empire = yes } }
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
		            fail_text = requires_building_hive_capital_3
				"
				toggle = @has_avb_mod
			}
		    OR = {
		    	has_building = building_imperial_hive_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_hive_cluster
						has_building = building_acot_ae_ancient_hive_cluster
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# All That Is GRIMDARK
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_hive_major_capital_sick
					"
					toggle = @has_allthatisgrimdark_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_hive_cluster
						has_building = building_phanon_hive_cluster
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_avb_hive_capital_3
						has_building = building_avb_hive_capital_4
					"
					toggle = @has_avb_mod
				}
				# EDA
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = eda_building_imperial_capital
					"
					toggle = @eda_mod
				}
				# galacot
				has_building = building_stellarite_galactic_hive_capital
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
		    }
        }
    }
    else_if = {
        limit = { owner = { is_machine_empire = yes } }
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					fail_text = requires_building_machine_capital_4
				"
				toggle = @has_avb_mod
			}
            OR = {
				has_building = building_imperial_machine_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_control_center
						has_building = building_acot_ae_ancient_control_center
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_control_center
						has_building = building_phanon_control_center
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_avb_machine_capital_4
						has_building = building_avb_machine_capital_5
						has_building = building_avb_machine_capital_6
					"
					toggle = @has_avb_mod
				}
				# galacot
				has_building = building_stellarite_galactic_machine_capital
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
				# Twinks Eternal
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_eternal_nexus_ai
					"
					toggle = @has_eternal_empire
				}
			}
        }
    }
    else = {
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
		            fail_text = requires_building_capital_4
				"
				toggle = @has_avb_mod
			}
            OR = {
			    has_building = building_imperial_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_palace
						has_building = building_acot_ae_ancient_palace
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# All That Is GRIMDARK
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_system_capital_gr
					"
					toggle = @has_allthatisgrimdark_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_palace
						has_building = building_phanon_palace
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_avb_capital_4
						has_building = building_avb_capital_5
						has_building = building_avb_capital_6
					"
					toggle = @has_avb_mod
				}
				# Azur Lane Stellaris DLC
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = azur_building_mind_capital
						has_building = azur_building_mind_net_capital
					"
					toggle = @azl_mod
				}
				# Dawn of the Republic
				has_building = building_galactic_senate
				# EDA
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = eda_building_imperial_capital
					"
					toggle = @eda_mod
				}
				# Nirvana Empire Project
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_nirvana_empire_palace
					"
					toggle = @nirvana_mod
				}
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
				# Twinks Atlantean
				has_building = building_ancient_palace_at
				# Twinks Kaldorei
				has_building = building_nightelf_palace
				# Twinks Eternal
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_eternal_palace
					"
					toggle = @has_eternal_empire
				}
				# galacot
				has_building = building_stellarite_galactic_capital
				has_building = building_stellarite_galactic_hive_capital
				has_building = building_stellarite_galactic_machine_capital
				# Wula Fallen Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_wula_archive
						has_building = building_all_is_dust
						has_building = building_wula_order_keep
						has_building = building_wula_gene_bank
					"
					toggle = @wula_compatch_var
				}
            }
        }
    }
}
has_upgraded_capital_5 = {
    if = {
        limit = { owner = { is_hive_empire = yes } }
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
		            fail_text = requires_building_hive_capital_3
				"
				toggle = @has_avb_mod
			}
		    OR = {
		    	has_building = building_imperial_hive_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_hive_cluster
						has_building = building_acot_ae_ancient_hive_cluster
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# All That Is GRIMDARK
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_hive_major_capital_sick
					"
					toggle = @has_allthatisgrimdark_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_hive_cluster
						has_building = building_phanon_hive_cluster
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_avb_hive_capital_3
						has_building = building_avb_hive_capital_4
					"
					toggle = @has_avb_mod
				}
				# EDA
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = eda_building_imperial_capital
					"
					toggle = @eda_mod
				}
				# galacot
				has_building = building_stellarite_galactic_hive_capital
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
		    }
        }
    }
    else_if = {
        limit = { owner = { is_machine_empire = yes } }
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					fail_text = requires_building_machine_capital_5
				"
				toggle = @has_avb_mod
			}
			OR = {
				has_building = building_imperial_machine_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_control_center
						has_building = building_acot_ae_ancient_control_center
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_control_center
						has_building = building_phanon_control_center
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_avb_machine_capital_5
						has_building = building_avb_machine_capital_6
					"
					toggle = @has_avb_mod
				}
				# galacot
				has_building = building_stellarite_galactic_machine_capital
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
				# Twinks Eternal
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_eternal_nexus_ai
					"
					toggle = @has_eternal_empire
				}
			}
        }
    }
    else = {
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
		            fail_text = requires_building_capital_5
				"
				toggle = @has_avb_mod
			}
            OR = {
			    has_building = building_imperial_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_palace
						has_building = building_acot_ae_ancient_palace
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# All That Is GRIMDARK
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_system_capital_gr
					"
					toggle = @has_allthatisgrimdark_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_palace
						has_building = building_phanon_palace
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_avb_capital_5
						has_building = building_avb_capital_6
					"
					toggle = @has_avb_mod
				}
				# Azur Lane Stellaris DlC
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = azur_building_mind_capital
						has_building = azur_building_mind_net_capital
					"
					toggle = @azl_mod
				}
				# Dawn of the Republic
				has_building = building_galactic_senate
				# EDA
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = eda_building_imperial_capital
					"
					toggle = @eda_mod
				}
				# Nirvana Empire Project
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_nirvana_empire_palace
					"
					toggle = @nirvana_mod
				}
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
				# Twinks Atlantean
				has_building = building_ancient_palace_at
				# Twinks Kaldorei
				has_building = building_nightelf_palace
				# Twinks Eternal
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_eternal_palace
					"
					toggle = @has_eternal_empire
				}
				# galacot
				has_building = building_stellarite_galactic_capital
				has_building = building_stellarite_galactic_hive_capital
				has_building = building_stellarite_galactic_machine_capital
				# Wula Fallen Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_wula_archive
						has_building = building_all_is_dust
						has_building = building_wula_order_keep
						has_building = building_wula_gene_bank
					"
					toggle = @wula_compatch_var
				}
            }
        }
    }
}
has_upgraded_capital_6 = {
    if = {
        limit = { owner = { is_hive_empire = yes } }
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
		            fail_text = requires_building_hive_capital_4
				"
				toggle = @has_avb_mod
			}
		    OR = {
		    	has_building = building_imperial_hive_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_hive_cluster
						has_building = building_acot_ae_ancient_hive_cluster
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# All That Is GRIMDARK
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_hive_major_capital_sick
					"
					toggle = @has_allthatisgrimdark_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_hive_cluster
						has_building = building_phanon_hive_cluster
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
				    	has_building = building_avb_hive_capital_4
					"
					toggle = @has_avb_mod
				}
				# EDA
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = eda_building_imperial_capital
					"
					toggle = @eda_mod
				}
				# galacot
				has_building = building_stellarite_galactic_hive_capital
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
		    }
        }
    }
    else_if = {
        limit = { owner = { is_machine_empire = yes } }
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					fail_text = requires_building_machine_capital_6
				"
				toggle = @has_avb_mod
			}
			OR = {
				has_building = building_imperial_machine_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_control_center
						has_building = building_acot_ae_ancient_control_center
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_control_center
						has_building = building_phanon_control_center
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_avb_machine_capital_6
					"
					toggle = @has_avb_mod
				}
				# galacot
				has_building = building_stellarite_galactic_machine_capital
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
				# Twinks Eternal
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_eternal_nexus_ai
					"
					toggle = @has_eternal_empire
				}
			}
        }
    }
    else = {
        custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					fail_text = requires_building_machine_capital_6
				"
				toggle = @has_avb_mod
			}
            OR = {
			    has_building = building_imperial_capital
				# ACOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_acot_dm_ancient_palace
						has_building = building_acot_ae_ancient_palace
						has_building = building_phanon_tower
						has_building = building_acot_ruined_giga_fortress
					"
					toggle = @has_ancient_caches
				}
				# ACOT SBTG
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_sbtg_upgraded_capital = yes
					"
					toggle = @has_sbtg_mod
				}
				# All That Is GRIMDARK
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_system_capital_gr
					"
					toggle = @has_allthatisgrimdark_mod
				}
				# AOT
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_stellarite_palace
						has_building = building_phanon_palace
					"
					toggle = @has_acquisition_of_tech
				}
				# AVB
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
					    has_building = building_avb_capital_6
					"
					toggle = @has_avb_mod
				}
				# Azur Lane Stellaris DlC
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = azur_building_mind_capital
						has_building = azur_building_mind_net_capital
					"
					toggle = @azl_mod
				}
				# Dawn of the Republic
				has_building = building_galactic_senate
				# EDA
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = eda_building_imperial_capital
					"
					toggle = @eda_mod
				}
				# Nirvana Empire Project
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_nirvana_empire_palace
					"
					toggle = @nirvana_mod
				}
				# Star Wars: Kuat Ancient Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_kuat_command_center
					"
					toggle = @sw_kuat_mod
				}
				# Twinks Atlantean
				has_building = building_ancient_palace_at
				# Twinks Kaldorei
				has_building = building_nightelf_palace
				# Twinks Eternal
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_eternal_palace
					"
					toggle = @has_eternal_empire
				}
				# galacot
				has_building = building_stellarite_galactic_capital
				has_building = building_stellarite_galactic_hive_capital
				has_building = building_stellarite_galactic_machine_capital
				# Wula Fallen Empire
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_building = building_wula_archive
						has_building = building_all_is_dust
						has_building = building_wula_order_keep
						has_building = building_wula_gene_bank
					"
					toggle = @wula_compatch_var
				}
            }
        }
    }
}
is_building_similar_to_clone_vats = {
	planet = {
		if = {
			limit = {
				exists = owner
				owner = { is_machine_empire = no }
			}
			custom_tooltip = {
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						fail_text = avb_orb_is_building_similar_to_clone_vats_fail
					"
					toggle = @has_avb_mod
				}
				merg_has_cloning_building = yes
			}
		}
	}
}
is_building_similar_to_foundry = {
	planet = {
		custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					fail_text = avb_orb_is_building_similar_to_foundry_fail
				"
				toggle = @has_avb_mod
			}
			merg_has_foundry_building = yes
		}
	}
}
is_building_similar_to_factory = {
	planet = {
		custom_tooltip = {
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					fail_text = avb_orb_is_building_similar_to_factory_fail
				"
				toggle = @has_avb_mod
			}
			merg_has_manufacturing_building = yes
		}
	}
}

############################### All these worlds ###############################
is_fallen_empire_planet = {
	owner = {
		OR = {
			merg_is_fallen_empire = yes
			merg_is_awakened_fe = yes
		}
	}
}
exists_collapsed_star = {
	solar_system = { any_system_planet = { merg_is_standard_dense_star = yes } }
}
is_collapsed_star = {
	optimize_memory
	merg_is_standard_dense_star = yes
}

############################### Ancient Empire ###############################
ag_is_gateway_megastructure = {
	merg_is_gate_mega = yes
}
ag_is_habitat = {
	optimize_memory
	merg_is_habitat = yes
}
ag_is_compact_star = {
	optimize_memory
	OR = {
		merg_is_standard_dense_star = yes
		# Hypothetical Stars
		is_hypo_stars_black_dwarf_star = yes
		is_hypo_stars_strange_star = yes
		is_hypo_stars_white_hole = yes
		# 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
		}
	}
}
ag_is_common_country = {
	optimize_memory
	OR = {
		merg_is_default_empire = yes
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
		is_country_type = awakened_marauders
		is_country_type = primitive
		is_country_type = ratlings
	}
}
ag_is_special_constructable_shipyard = {
	optimize_memory
	custom_tooltip = {
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				fail_text = ag_need_ancient_construction_facilities
			"
			toggle = @ag_null_edict_length
		}
		OR = {
			can_build_precursor_ship = yes
			AND = { is_scope_type = starbase
				OR = {
					inline_script = {
						script = merger_of_rules/toggled_code
						code = "
							has_starbase_size = ag_gamma_station_hostile
							has_starbase_size = ag_gamma_station_0
							has_starbase_size = ag_gamma_station_1
						"
						toggle = @ag_null_edict_length
					}
					inline_script = {
						script = merger_of_rules/toggled_code
						code = "
							has_starbase_size = swfo_supremacy
							has_starbase_size = exe_megastructure_starbase
						"
						toggle = @sw_kuat_mod
					}
				}
			}
			AND = { is_scope_type = megastructure
				OR = {
					inline_script = {
						script = merger_of_rules/toggled_code
						code = "
							is_megastructure_type = ag_ancient_construction_section
						"
						toggle = @ag_null_edict_length
					}
					has_megastructure_flag = ag_ancient_construction_section_megashipyard
					is_megastructure_type = StarForge
					inline_script = {
						script = merger_of_rules/toggled_code
						code = "
							is_megastructure_type = exe_black_hole_restore
							is_megastructure_type = exe_black_hole_facility
						"
						toggle = @sw_kuat_mod
					}
				}
			}
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					AND = { exists = owner owner = { has_modifier = ag_debug_modifier_buff_common } }
				"
				toggle = @ag_null_edict_length
			}
		}
	}
}
ag_has_planetary_shield = {
	optimize_memory
	merg_has_planetary_shield = yes
}
ag_is_star_killer_special_system = {
	optimize_memory
	OR = {
		has_star_flag = ag_no_star_killer_target_system
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				kuat_is_kuat_system = yes
			"
			toggle = @sw_kuat_mod
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_star_flag = ehof_compound_system
				has_star_flag = giga_core_03
			"
			toggle = @has_gigastructures
		}
	}
}

############################### Assault Lily ###############################
is_planet_habitable = {
	optimize_memory
	AND = {
		is_artificial = no
		colonizable_planet = yes
	}
}
has_active_al_factory_building = {
	OR = {
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_lily_couture
			"
			toggle = @change_planet_size_bullet_num
		}
		has_active_building = building_factory_1
		has_active_building = building_factory_2
		has_active_building = building_factory_3
		has_active_building = building_affluence_center
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_fe_factory
				has_active_building = building_acot_ae_factory
				has_active_building = building_acot_ae_affluence_center
			"
			toggle = @has_ancient_caches
		}
		# AOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_fe_affluence_center
				has_active_building = building_phanon_affluence_center
				has_active_building = building_phanon_civilian_factory
				has_active_building = building_stellarite_affluence_center
			"
			toggle = @has_acquisition_of_tech
		}
		# AVB
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_avb_factory_4
				has_active_building = building_avb_factory_5
				has_active_building = building_avb_factory_6
			"
			toggle = @has_avb_mod
		}
		# EDA
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = eda_building_factory
			"
			toggle = @eda_mod
		}
		# GPM
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = gpm_building_manufactory_hub
			"
			toggle = @has_guillis_planet_modifiers
		}
		# Warship Girls R and MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_sep_foundry
				has_active_building = building_gray_nano_factory
			"
			toggle = @wsg_mod
		}
	}
}
has_active_al_foundry_building = {
	OR = {
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_lily_construction_group
			"
			toggle = @change_planet_size_bullet_num
		}
		has_active_building = building_foundry_1
		has_active_building = building_foundry_2
		has_active_building = building_foundry_3
		has_active_building = building_nano_forge
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_fe_alloy_forge
				has_active_building = building_acot_ae_alloy_forge
				has_active_building = building_acot_ae_nano_forge
			"
			toggle = @has_ancient_caches
		}
		# AOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_fe_nano_forge
				has_active_building = building_phanon_nano_forge
				has_active_building = building_phanon_alloy_forge
				has_active_building = building_stellarite_nano_forge
				has_active_building = building_stellarite_alloy_forge
			"
			toggle = @has_acquisition_of_tech
		}
		# AVB
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_avb_foundry_4
				has_active_building = building_avb_foundry_5
				has_active_building = building_avb_foundry_6
			"
			toggle = @has_avb_mod
		}
		# EDA
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = eda_building_alloy_foundry
			"
			toggle = @eda_mod
		}
		# Protoss
		has_active_building = protoss_building_bf
		# Warship Girls R and MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_sep_foundry
				has_active_building = building_wsg_foundry
				has_active_building = building_gray_nano_foundry
				has_active_building = building_sh_foundry
				has_active_building = building_sep_foundry2
				has_active_building = building_wsg_foundry
				has_active_building = building_gray_nano_foundry2
				has_active_building = building_sh_foundryU
			"
			toggle = @wsg_mod
		}
		# Wula Fallen Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_wula_foundry
			"
			toggle = @wula_compatch_var
		}
	}
}
is_huge_can_colony_planet = {
	OR = {
		uninhabitable_regular_planet = yes
		merg_is_basic_habitable = yes
		can_build_lily_garden = yes
	}
}

############################### City World Flavour ###############################
ef_is_ecu = {
	OR = {
		merg_is_arcology_non_gestalt = yes
		# Sparble's Stellar Hyperconstructs
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_shellworld_core_city
				is_planet_class = pc_edersphere
				is_planet_class = pc_black_hole_shellworld
				is_planet_class = pc_habitable_dyson
			"
			toggle = @has_stellar_hyperconstructs
		}
	}
}

############################### Darkspace ###############################
ds_hyperlane_create = {
	NOR = {
		is_same_value = prev
		has_hyperlane_to = prev
		has_star_flag = ds_se_system_fixed
		has_star_flag = ds_galactic_core
		has_star_flag = empire_home_system
		has_star_flag = marauder_system
		has_star_flag = marauder_capital_1
		has_star_flag = empire_cluster
		has_star_flag = fallen_shrouded
		has_star_flag = fallen_shielded_1
		has_star_flag = fallen_shielded_2
		has_star_flag = fallen_shielded_3
		has_star_flag = holy_system_1
		has_star_flag = holy_system_2
		has_star_flag = holy_system_3
		has_star_flag = holy_system_4
		has_star_flag = holy_system_5
		has_star_flag = fe_xeno_zoo
		has_star_flag = fallen_shield_world
		has_star_flag = fallen_empire_world
		has_star_flag = scfe_shaded_colony_system
		merg_is_isolated_system = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_core_system = yes
				cohesive_system = yes
				compound_cluster = yes
				annihilator_system = yes
				urmazin_system = yes
			"
			toggle = @has_gigastructures
		}
	}
}
ds_modded_invalid_planet = {
	OR = {
		merg_is_forbidden_target = yes
		# Darkspace
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_constructor_ark
				is_planet_class = pc_stellar_engine
				is_planet_class = pc_ds_xeelee_holosphere
				is_planet_class = pc_kompass
			"
			toggle = @has_darkspace_installed
		}
		merg_is_shielded = yes
		is_ringworld = yes
		merg_is_habitat = yes
		merg_is_broken = yes
		merg_is_gas_giant = yes
		is_asteroid = yes
	}
}
ds_modded_valid_planet = {
	is_artificial = no
	OR = {
		is_planet_class = pc_infested
		merg_is_basic_planet = yes
		merg_is_hive_world = yes
		merg_is_machine_world = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_ds_stahl
				is_planet_class = pc_immortal
			"
			toggle = @has_darkspace_installed
		}
	}
}

############################### Destiny: Hive Portraits ###############################
is_valid_pop_for_TAKING = {
	NOR = {
		merg_has_hive_trait = yes
		has_trait = trait_mechanical
		has_trait = trait_machine_unit
	}
}

############################### District Overhaul - FunEFork ###############################
do3f_is_hive_planet = {
	optimize_memory
	merg_is_hive_world = yes
}
do3f_is_machine_planet = {
	optimize_memory
	merg_is_machine_world = yes
}
do3f_is_ringworld = {
	optimize_memory
	merg_is_hab_ringworld = yes
}
do3f_is_habitable_structure = {
	optimize_memory
	OR = { merg_is_hab_ringworld = yes merg_is_habitat = yes }
}
do3f_can_have_random_districts = {
	optimize_memory
	OR = {
		merg_is_basic_habitable = yes
		# Lithoid Supremacy
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_geode_world = yes
			"
			toggle = @has_lithoid_mod
		}
		# Real Space: New Frontiers
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_tidallylocked
				is_planet_class = pc_sterile
				is_planet_class = pc_tidallylocked
			"
			toggle = @rs_compatch_var
		}
		can_have_habitable_deposits = yes
	}
	inline_script = {
		script = merger_of_rules/toggled_code
		code = "
			NOR = {
				do3f_is_habitable_asteroid = yes
				do3f_is_habitable_barren = yes
			}
		"
		toggle = @has_do3f_mod
	}
}
do3f_can_have_random_housing_districts = {
	optimize_memory
	do3f_can_have_random_districts = yes
	NOR = {
		# Vanilla
		merg_is_habitat = yes
		merg_is_arcology = yes
		merg_is_hab_ringworld = yes
	}
}

############################### Dynamic Political Events ###############################
cc_has_happiness = { merg_has_happiness = yes }

############################### Electroids ###############################
elec_hyperlane_create = {
	NOR = {
		is_same_value = prev
		has_hyperlane_to = prev
		has_star_flag = ds_se_system_fixed
		has_star_flag = empire_home_system
		has_star_flag = empire_cluster
		has_star_flag = fallen_shield_world
		has_star_flag = fallen_empire_world
		merg_is_isolated_system = yes
		# Darkspace
		has_star_flag = darkspace_void_control
		# Forgotten Empires
		has_star_flag = scfe_shaded_colony_system
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_core_system = yes
				cohesive_system = yes
				compound_cluster = yes
				annihilator_system = yes
				urmazin_system = yes
			"
			toggle = @has_gigastructures
		}
	}
}

############################### Empires Expanded ###############################
is_symbiosis_world_positive = {
	OR = {
		merg_is_hive_world = yes
		merg_is_gaia = yes
		merg_is_hab_ringworld = yes
	}
}
is_symbiosis_world_negative = {
	OR = {
		merg_is_nuked = yes
		merg_is_arcology = yes
	}
}
is_caretakers_world_positive = {
	OR = {
		merg_is_gaia = yes
		merg_is_hab_ringworld = yes
		# Planetary Diversity
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				pd_is_planet_class_superhabitable = yes
			"
			toggle = @has_planetary_diversity
		}

	}
}
is_caretakers_world_negative = {
	OR = {
		merg_is_nuked = yes
		merg_is_arcology = yes
	}
}

############################### Ethics and Civics Alternative - FunEFork/Classics ###############################
is_toxic_planet = {
	optimize_memory
	merg_is_toxic = yes
}
is_barren_planet = {
	optimize_memory
	merg_is_barren = yes
}
is_nuked_planet = {
	optimize_memory
    merg_is_nuked_basic = yes
}

############################### Ethics and Civics Bug Branch ###############################
is_bugged_starbase = {
	OR = {
		has_starbase_size >= starbase_starport
		# ACOT/AOT/SOTS
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_precursor_starbase = yes
			"
			toggle = @has_ancient_caches
		}
	}
}

############################### Ethics and Civics Infinity ###############################
has_clinic = { merg_has_hospital = yes }

############################### Exalted Domination ###############################
exalted_is_valid_as_vassal = {
	OR = {
		is_country_type = default
		# The Empty Vagrant
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_default_ev_country_type = yes
			"
			toggle = @homeless_class_trait_weight
		}
		# Darkspace
		is_country_type = ds_nomads
	}
}

############################### Expanded Events ###############################
is_regular_star = {
	optimize_memory
	is_star = yes
	merg_is_forbidden_target = no
	NOR = {
		is_planet_class = pc_t_star
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class_pc_ae_star = yes
				is_planet_class_pc_collapsar = yes
				is_planet_class_pc_magnetar = yes
				is_rs_compat_microquasar = yes
				is_planet_class_pc_d_star = yes
				is_planet_class = pc_fu_star
				is_planet_class_pc_l_star = yes
				is_planet_class_pc_nova_1 = yes
				is_planet_class_pc_nova_2 = yes
				is_planet_class_pc_protostar = yes
				is_planet_class_pc_tt_red_star = yes
				is_planet_class_pc_tt_orange_star = yes
				is_planet_class_pc_tt_white_star = yes
				is_planet_class_pc_y_star = yes
			"
			toggle = @rs_compatch_var
		}
	}
}
terraforming_candidate_solar_system_check = {
	optimize_memory
	NOR = {
		merg_is_standard_dense_star = yes
		is_star_class = sc_b
		is_star_class = sc_a
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_star_class = sc_nova_1
				is_star_class = sc_nova_2
				is_star_class = sc_protostar
				is_star_class = sc_l
				is_star_class = sc_d
				is_star_class = sc_s_giant
				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_o_super
				is_star_class = sc_o_hyper
				is_star_class = sc_b_super
				is_star_class = sc_a_super
				is_star_class = sc_f_super
				is_star_class = sc_g_super
				is_star_class = sc_k_super
				is_star_class = sc_m_super
				is_star_class = sc_m_hyper
				is_star_class = sc_collapsar
				is_star_class = sc_lbv_blue
				is_star_class = sc_lbv_green
				is_star_class = sc_lbv_red
				is_star_class = sc_o
				is_star_class = sc_c_giant
				is_star_class = sc_tt_red
				is_star_class = sc_tt_orange
				is_star_class = sc_tt_white
				is_star_class = sc_ae
				is_star_class = sc_p_purple
				is_star_class = sc_p_green
				is_star_class = sc_p_red
				is_star_class = sc_magnetar
			"
			toggle = @rs_compatch_var
		}
		merg_is_void_system = yes
	}
}
living_metal_candidate = {
	NOT = { has_deposit_for = shipclass_research_station }
	OR = {
		merg_is_barren = yes
		merg_is_barren_cold = yes
		is_asteroid = yes
	}
}

############################### Expanded Mods Base ###############################
is_city = {
	merg_is_arcology = yes
}

############################### Extra Districts ###############################
ED_is_pc_relic = { merg_is_relic_world = yes }

############################### Extra Ship Components NEXT ###############################
ESC_TRIGGER_is_city_planet = {
    OR = {
        merg_is_arcology = yes
        # district overhaul compatibility
        AND = {
            merg_is_relic_world = yes
            has_district = district_ascended_housing
        }
    }
}
ESC_TRIGGER_is_naked_mantle_planet = {
	OR = {
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_equatorial_shipyard = yes
			"
			toggle = @has_gigastructures
		}
		# Girls Frontline
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_GF_nyto_devil_furnace
			"
			toggle = @gf_compatch_var
		}
		# Real Space - Planetary Stations
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_molten_station
			"
			toggle = @rs_compatch_var
		}
		# Real Space - New Frontiers
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_modifier = infernal_world
				has_modifier = lava_world
				has_modifier = volcanic_world
			"
			toggle = @rs_compatch_var
		}
	}
}

############################### Guilli's Planetary Modifiers ###############################
gpm_is_planet_class_normal_uninhabitable = {
	optimize_memory
	uninhabitable_regular_planet = yes
}
gpm_is_asteroid = {
	optimize_memory
	is_asteroid = yes
}
gpm_is_planet_class_barren = {
	optimize_memory
	OR = {
		merg_is_barren = yes
		merg_is_barren_cold = yes
	}
}
gpm_is_planet_class_molten = {
	optimize_memory
	merg_is_molten = yes
}
gpm_is_planet_class_toxic = {
	optimize_memory
	merg_is_toxic = yes
}
gpm_is_planet_class_frozen = {
	optimize_memory
	merg_is_frozen = yes
}
gpm_is_planet_class_normal_habitable = {
	optimize_memory
	merg_is_standard_habitable = yes
}
gpm_is_planet_class_nuked = {
	optimize_memory
	merg_is_nuked_basic = yes
}
gpm_is_planet_class_gas_giant = {
	optimize_memory
	merg_is_gas_giant = yes
}
gpm_is_planet_class_city = {
	optimize_memory
	OR = {
		merg_is_arcology = yes
		merg_is_relic_world = yes
	}
}
gpm_is_planet_class_machine = {
	optimize_memory
	merg_is_machine_world = yes
}
gpm_is_planet_class_hive = {
	optimize_memory
	merg_is_hive_world = yes
}
gpm_is_planet_class_habitat = {
	optimize_memory
	merg_is_habitat = yes
}
gpm_is_planet_class_ringworld = {
	optimize_memory
	merg_is_hab_ringworld = yes
}
gpm_is_planet_fallen_empire = {
	exists = owner
	owner = {
		OR = {
			merg_is_fallen_empire = yes
			merg_is_awakened_fe = yes
		}
	}
}
gpm_is_fallen_empire_space_owner = {
	exists = space_owner
	space_owner = {
		OR = {
			merg_is_fallen_empire = yes
			merg_is_awakened_fe = yes
		}
	}
}
eligible_for_rare_crystals = {
	NOR = {
		has_deposit_for = shipclass_research_station
		has_planet_flag = has_dark_matter_deposit
		has_planet_flag = has_negative_mass_deposit
		has_planet_flag = has_zro_deposit
		has_planet_flag = has_living_metal_deposit
		has_planet_flag = has_physics_deposit
		has_planet_flag = has_society_deposit
		has_planet_flag = has_engineering_deposit
		event_target:current_system_creator = { NOT = { has_technology = tech_mine_rare_crystals } }
		merg_is_gas_giant = yes
		is_star = yes
	}
}
eligible_for_volatile_motes = {
	NOR = {
		has_deposit_for = shipclass_research_station
		has_planet_flag = has_dark_matter_deposit
		has_planet_flag = has_negative_mass_deposit
		has_planet_flag = has_zro_deposit
		has_planet_flag = has_living_metal_deposit
		has_planet_flag = has_physics_deposit
		has_planet_flag = has_society_deposit
		has_planet_flag = has_engineering_deposit
		event_target:current_system_creator = { NOT = { has_technology = tech_mine_volatile_motes } }
		merg_is_gas_giant = yes
		is_star = yes
	}
}
eligible_for_alloys = {
	NOR = {
		has_deposit_for = shipclass_research_station
		has_planet_flag = has_dark_matter_deposit
		has_planet_flag = has_negative_mass_deposit
		has_planet_flag = has_zro_deposit
		has_planet_flag = has_living_metal_deposit
		has_planet_flag = has_physics_deposit
		has_planet_flag = has_society_deposit
		has_planet_flag = has_engineering_deposit
		merg_is_gas_giant = yes
		is_star = yes
	}
}
eligible_for_zro = {
	NOR = {
		has_deposit_for = shipclass_research_station
		solar_system = {
			NOT = {
				any_system_planet = {
					OR = {
						has_planet_flag = has_living_metal_deposit
						has_planet_flag = has_zro_deposit
					}
				}
			}
		}
		event_target:current_system_creator = { NOT = { has_technology = tech_mine_zro } }
		event_target:current_system_creator = { has_country_flag = recently_spawned_zro }
		has_planet_flag = has_dark_matter_deposit
		has_planet_flag = has_negative_mass_deposit
		has_planet_flag = has_living_metal_deposit
		merg_is_gas_giant = yes
		is_star = yes
	}
}
eligible_for_living_metal = {
	NOR = {
		has_deposit_for = shipclass_research_station
		solar_system = {
			NOT = {
				any_system_planet = {
					OR = {
						has_planet_flag = has_living_metal_deposit
						has_planet_flag = has_zro_deposit
					}
				}
			}
		}
		event_target:current_system_creator = { NOT = { has_technology = tech_mine_living_metal } }
		event_target:current_system_creator = { has_country_flag = recently_spawned_lm }
		has_planet_flag = has_zro_deposit
		has_planet_flag = has_dark_matter_deposit
		has_planet_flag = has_negative_mass_deposit
		merg_is_gas_giant = yes
		is_star = yes
	}
}
gpm_has_required_terraform_modifier = {
	is_terraforming_candidate = yes
	NOT = { has_planet_flag = gpm_solidified_planet_core }
}
gpm_is_country_type_default = { merg_is_default_empire = yes }
gpm_is_country_type_fallen_empire = { merg_is_fallen_empire = yes }
gpm_is_country_type_awakened_fallen_empire = { merg_is_awakened_fe = yes }
gpm_engine_forbidden_planets = {
	optimize_memory
	NOR = {
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				solar_system = {
					exists = space_owner
					space_owner = { has_origin = origin_gpm_death_world }
				}
				solar_system = {
					exists = space_owner
					space_owner = { has_origin = origin_gpm_fallen_empire_colony }
				}
				solar_system = {
					exists = space_owner
					space_owner = { has_origin = origin_gpm_precursor_world }
				}
			"
			toggle = @has_guillis_planet_modifiers
		}
		has_planet_flag	= hoard_planet
		AND = {
			is_planet_class = pc_relic
			solar_system = { has_star_flag = mechanocalibrator_system }
		}
		merg_is_forbidden_target = yes
	}
}

############################### Harvest Engine Crisis ###############################
harvester_is_crackable = {
	optimize_memory
	merg_is_forbidden_target = no
	AND = {
		OR = {
			num_minerals >= 1
			# Will always treat colonies as crackable, unless they are habitats or ringworlds
			AND = {
				is_colony = yes
				is_artificial = no
			}
		}
		NOR = {
			is_star = yes
			is_asteroid = yes
			merg_is_broken = yes
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_content_world = no
			"
			toggle = @harvester_beamcage_ship_count
		}
	}
}

############################### Infinity Stones ###############################
infmod_is_relevant = {
	OR = {
		merg_is_default_empire = yes
		merg_is_fallen_empire = yes
		merg_is_awakened_fe = yes
	}
}

############################### Legendary Worlds ###############################
legw_planet_uninhabitable = {
	optimize_memory
	uninhabitable_regular_planet = yes
}
legw_planet_habitable = {
	optimize_memory
	AND = {
		colonizable_planet = yes
		is_artificial = no
	}
}
legw_megaplanet = {
	optimize_memory
	OR = {
		is_artificial = yes
		merg_is_machine_world = yes
		is_planet_class = pc_cybrex
		# Maiden Frontier Gunstar Story Collection
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				msgsc_GF_sf_machine = yes
			"
			toggle = @GF_OGAS_leveled_thread_add_start_after_level
		}
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_giga_planetary_computer = yes
			"
			toggle = @has_gigastructures
		}
		# Origin - F.C.S.S & M.C.S.S
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_awaken_ai
			"
			toggle = @fcss_mod
		}
		# ZOFE
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_utopian_machine
			"
			toggle = @has_zofe_vanilla
		}
	}
}
legw_is_dry = { is_dry = yes }
legw_is_wet = { is_wet = yes }
legw_is_cold = { is_cold = yes }
legw_fallen_empire_planet = {
	owner = {
		OR = {
			merg_is_fallen_empire = yes
			merg_is_awakened_fe = yes
		}
	}
}

############################### More Events Mod ###############################
mem_is_spherical_world = {
	optimize_memory
	NOR = {
		habitable_structure = yes
		merg_is_habitat = yes
		merg_is_hab_ringworld = yes
		# Gigastructural Engineering & More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_habitable_structure = yes
			"
			toggle = @has_gigastructures
		}
	}
}
mem_has_happiness = { merg_has_happiness = yes }
mem_has_shield_building = {
	merg_has_planetary_shield = yes
}
mem_imperialist_intimidation_valid_bully = {
	is_ai = yes
	merg_is_default_empire = yes
	has_ai_personality_behaviour = conqueror
	NOR = {
		has_country_flag = mem_imperialist_intimidation_actor@root
		is_overlord_to = root
		ROOT = {
			is_overlord_to = prev
		}
	}
	OR = {
		is_rival = root
		is_hostile_to = root
		is_domineering_to = root
		root = {
			is_rival = prev
		}
	}
	NOT = {
		relative_power = {
			who = root
			value = pathetic
		}
	}
}
mem_trigger = { is_homicidal = no }

############################### More Precursors ###############################
FHMP_is_valid_precursor_planet = {
	optimize_memory
	OR = {
		merg_is_barren = yes
		merg_is_barren_cold = yes
		merg_is_frozen = yes
		merg_is_nuked_basic = yes
	}
}
FHMP_is_valid_werediran_planet = {
	optimize_memory
	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_nuked_basic = yes
		merg_is_ocean = yes
		merg_is_savannah = yes
		merg_is_tropical = yes
		merg_is_tundra = yes
	}
}

############################### Omega's Stellaris Traditions ###############################
has_planetary_shield_building = {
	merg_has_planetary_shield = yes
}

############################### Origin Beings ###############################
darhmod_seres_digsite_spawn_rules = {
	has_access_fleet = root.owner
	OR = {
		has_owner = no
		owner = { is_same_value = root.owner }
	}
	NOR = {
		is_same_value = root.solar_system
		any_system_planet = {
			is_capital = yes
			has_planet_flag = precursor_world
			has_planet_flag = darhmod_seres_colony
		}
	}
	solar_system = { exists = star }
	any_system_planet = {
		is_star = no
		has_anomaly = no
		is_capital = no
		NOR = {
			exists = archaeological_site
			merg_is_shielded = yes
			merg_is_gas_giant = yes
			merg_is_empty_space = yes
		}
	}
	NOT = {
		any_neighbor_system = {
			any_system_planet = {
				OR = {
					has_planet_flag = precursor_world
					has_planet_flag = darhmod_seres_colony
				}
			}
		}
	}
}

############################### Planet States ###############################
is_appropriate_planet_state_system = {
	NOR = {
		is_fe_cluster = yes
		has_star_flag = empire_home_system
		has_star_flag = empire_cluster
		has_star_flag = enclave
		has_star_flag = guardian
		has_star_flag = hostile_system
		has_star_flag = marauder_system
		has_star_flag = caravaneer_home
		has_star_flag = primitive_system
		has_star_flag = chosen_system
		merg_is_void_system = yes
		has_special_star_flag_trigger = yes
	}
	any_system_planet = {
		uninhabitable_regular_planet = yes
		has_anomaly = no
	}
}

############################### Primitive Conquest Enhancements ###############################
pce_planet_uses_district_farming_uncapped = {
	OR = {
		merg_is_hive_world = yes
		is_planet_class = pc_shattered_ring_habitable
		AND = {
			merg_is_ocean = yes
			exists = owner
			owner = { is_anglers_empire = yes }
		}
	}
}

############################### Real Space ###############################
has_mineral_deposit = {
	OR = {
		has_deposit = d_veiny_cliffs
		has_deposit = d_mineral_fields
		has_deposit = d_prosperous_mesa
		has_deposit = d_ore_rich_caverns
		has_deposit = d_rich_mountain
		has_deposit = d_submerged_ore_veins
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_deposit = d_offshore_fields
				has_deposit = d_abundant_atoll
				has_deposit = d_rich_lodes
			"
			toggle = @rs_compatch_var
		}
		# GPM
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_deposit = gpm_d_spaceship_graveyard
				has_deposit = gpm_d_unusual_formations
				has_deposit = gpm_d_floating_rocks
				has_deposit = gpm_d_super_volcano
				has_deposit = gpm_d_obsidian_fields
				has_deposit = gpm_d_rich_crater
				has_deposit = gpm_d_surface_mineral_veins
				has_deposit = gpm_d_dense_metal_veins
				has_deposit = gpm_d_iron_mountain
				has_deposit = gpm_d_garbage_patch
				has_deposit = gpm_d_fossilized_egg_sacks
				has_deposit = gpm_d_fossilized_structures
				has_deposit = gpm_d_fossilized_creep
				has_deposit = gpm_d_giant_skeleton
			"
			toggle = @has_guillis_planet_modifiers
		}
	}
}
is_mineral_deposit = {
	OR = {
		is_deposit_type = d_veiny_cliffs
		is_deposit_type = d_mineral_fields
		is_deposit_type = d_prosperous_mesa
		is_deposit_type = d_ore_rich_caverns
		is_deposit_type = d_rich_mountain
		is_deposit_type = d_submerged_ore_veins
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_deposit_type = d_offshore_fields
				is_deposit_type = d_abundant_atoll
				is_deposit_type = d_rich_lodes
			"
			toggle = @rs_compatch_var
		}
		# GPM
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_deposit_type = gpm_d_spaceship_graveyard
				is_deposit_type = gpm_d_unusual_formations
				is_deposit_type = gpm_d_floating_rocks
				is_deposit_type = gpm_d_super_volcano
				is_deposit_type = gpm_d_obsidian_fields
				is_deposit_type = gpm_d_rich_crater
				is_deposit_type = gpm_d_surface_mineral_veins
				is_deposit_type = gpm_d_dense_metal_veins
				is_deposit_type = gpm_d_iron_mountain
				is_deposit_type = gpm_d_garbage_patch
				is_deposit_type = gpm_d_fossilized_egg_sacks
				is_deposit_type = gpm_d_fossilized_structures
				is_deposit_type = gpm_d_fossilized_creep
				is_deposit_type = gpm_d_giant_skeleton
			"
			toggle = @has_guillis_planet_modifiers
		}
	}
}
planetary_catastrophe_is_possible = {
	is_colony = yes
	num_pops > 0
	OR = {
		merg_is_desert = yes
		merg_is_arid = yes
		merg_is_savannah = yes
		merg_is_tropical = yes
		merg_is_ocean = yes
		merg_is_continental = yes
		merg_is_arctic = yes
		merg_is_alpine = yes
		merg_is_tundra = yes
		merg_is_gaia = yes
		merg_is_nuked_basic = yes
		merg_is_hive_world = yes
		merg_is_arcology = yes
		merg_is_relic_world = yes
		merg_is_hab_ringworld = yes
		merg_is_habitat = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class = pc_sterile
			"
			toggle = @rs_compatch_var
		}
	}
	NOR = {
		has_planet_flag = colony_event
		has_planet_flag = planetary_disaster
		solar_system = { has_star_flag = star_disaster }
	}
	merg_is_forbidden_target = no
}
star_catastrophe_is_possible = {
	is_primary_star = yes
	OR = {
		is_planet_class = pc_k_star
		is_planet_class = pc_g_star
		is_planet_class = pc_f_star
		is_planet_class = pc_m_giant_star
		is_planet_class = pc_a_star
		is_planet_class = pc_b_star
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_planet_class_pc_k_giant_star = yes
				is_planet_class_pc_g_giant_star = yes
			"
			toggle = @rs_compatch_var
		}
	}
	solar_system = {
		NOR = {
			has_star_flag = star_disaster
			has_star_flag = dyson_sphere_built
			has_star_flag = AI_hub
			has_star_flag = cybrex_beta
			has_star_flag = guardian
			has_star_flag = guardians_of_zanaam
			has_star_flag = sanctuary_system
			has_star_flag = hyacinth_system
			has_star_flag = ai_system
			has_star_flag = sentinel_system
			has_star_flag = vultaumar
			has_star_flag = yuhtaan
			has_star_flag = fen_habbanis
			has_star_flag = irass
			has_star_flag = cybrex
			has_star_flag = ruined_dyson_system
			has_special_star_flag_trigger = yes
			AND = {
				has_star_flag = ruined_ring_system
				any_system_megastructure = { is_megastructure_type = ring_world_ruined }
			}
		}
		any_system_planet = { planetary_catastrophe_is_possible = yes }
	}
}

############################### Real Space New Frontiers ###############################
is_moon_of_gas_giant = {
	is_scope_type = planet
	exists = orbit
	OR = {
		orbit = { merg_is_gas_giant = yes }
		orbit = { merg_is_gas_giant_habitable = yes }
		has_planet_flag = gas_giant_moon
	}
}

############################### Reworked Advanced Ascension ###############################
# Fixing the trigger and removing obsolete code
AAR_trgr_cntr_playable = {
	OR = {
		merg_is_default_empire = yes
		merg_is_fallen_empire = yes
		merg_is_awakened_fe = yes
	}
}
AAR_trgr_ship_SB_valid = {
	OR = {
		AND = {
			is_ship_class = shipclass_starbase
			fleet = { is_mobile = no }
			NOT = { is_ship_size = starbase_outpost }
		}
		is_orbital_ring = yes
	}
}

############################### Shroud Rising ###############################
is_shroud_rift_planet = {
	is_star = no
	is_moon = no
	is_colony = no
	planet_size > 17
	OR = {
		merg_is_nuked = yes
		merg_is_gas_giant = yes
		is_planet_class = pc_shrouded
		habitable_planet_not_urban = yes
		can_have_mineral_deposits = yes
	}
}

############################### Sparble's Stellar Hyperconstructs ###############################
ssh_is_any_gas_giant = {
	OR = {
		merg_is_gas_giant = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_gigabrown_dwarf = yes
			"
			toggle = @has_gigastructures
		}
	}
}

############################### Star Wars: Kuat Ancient Empire ###############################
kuat_is_common_country = {
	OR = {
		merg_is_standard_empire = yes
		is_country_type = awakened_marauders
		is_country_type = primitive
		is_country_type = ratlings
	}
}
kuat_is_defense_galaxy_fleet = {
	any_country = {
		OR = {
			is_crisis_faction = yes
			# Ancient Empire
			inline_script = {
				script = merger_of_rules/toggled_code
				code = "
					is_country_type = ag_ancient_gamma_guardian
					is_country_type = ag_zeta_crisis_country
					is_country_type = ag_ancient_primitive_crisis
				"
				toggle = @ag_null_edict_length
			}
		}
	}
}
kuat_is_ringworld = {
	OR = {
		is_ringworld = yes
		merg_is_hab_ringworld = yes
	}
}
kuat_is_habitat = {
	merg_is_habitat = yes
}
kuat_is_event_borderment_ringworld = {
	OR = {
		merg_is_hab_ringworld = yes
		merg_is_habitat = yes
		AND = {
			has_global_flag = has_ancient_empire_mod
			OR = {
				has_modifier = "holy_planet"
				inline_script = {
					script = merger_of_rules/toggled_code
					code = "
						has_modifier = ag_shattered_holy_planet
					"
					toggle = @ag_null_edict_length
				}
			}
		}
	}
}
kuat_is_playable_country = {
	OR = {
		merg_is_default_empire = yes
		is_country_type = enclave_mercenary
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = eternal_empire
			"
			toggle = @has_eternal_empire
		}
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_sbtg_playable_country = yes
   			"
			toggle = @has_sbtg_mod
		}
		is_country_type = star_fantasy_empire
		is_country_type = endtime_star_fantasy_empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = ascended_empire
			"
			toggle = @has_zofe_vanilla
		}
	}
}

############################### StellarRegulator Array ###############################
SRA_is_compact_star = {
	merg_is_dense_star = yes
}
SRA_is_common_country = {
	merg_is_standard_empire = yes
}

############################### Stellaris Chronicles - Forgotten Empires ###############################
scfe_is_valid_star = {
	merg_is_dense_star = no
	merg_is_forbidden_target = no
}

############################### ThaumStellaris ###############################
tc_element_shard_candidate = {
	NOT = { has_deposit_for = shipclass_research_station }
	OR = {
		uninhabitable_regular_planet = yes
		is_asteroid = yes
		merg_is_broken = yes
	}
}

############################### THE ABYSS CONTRACT ###############################
TAC_is_pc_desert = { merg_is_desert = yes }
TAC_is_pc_arid = { merg_is_arid = yes }
TAC_is_pc_savannah = { merg_is_savannah = yes }
TAC_is_pc_tropical = { merg_is_tropical = yes }
TAC_is_pc_continental = { merg_is_continental = yes }
TAC_is_pc_ocean = { merg_is_ocean = yes }
TAC_is_pc_tundra = { merg_is_tundra = yes }
TAC_is_pc_arctic = { merg_is_arctic = yes }
TAC_is_pc_alpine = { merg_is_alpine = yes }
TAC_is_pc_molten = { merg_is_molten = yes }
TAC_is_pc_barren = { merg_is_barren = yes }
TAC_is_pc_barren_cold = { merg_is_barren_cold = yes }
TAC_is_pc_toxic = { merg_is_toxic = yes }
TAC_is_pc_frozen = { merg_is_frozen = yes }
TAC_is_pc_nuked = { merg_is_nuked_basic = yes }
TAC_is_pc_hive = { merg_is_hive_world = yes }
TAC_is_pc_machine = { merg_is_machine_world = yes }
TAC_is_pc_gaia = { merg_is_gaia_basic = yes }
TAC_is_pc_city = { merg_is_arcology = yes }
TAC_is_pc_relic = { merg_is_relic_world = yes }

# ###########
# Special Planets
# ###########
TAC_is_pc_nuked = { is_planet_class = pc_nuked }
TAC_is_pc_hive = { is_planet_class = pc_hive }
TAC_is_pc_machine = { is_planet_class = pc_machine }
TAC_is_pc_shielded = { is_planet_class = pc_shielded }
TAC_is_pc_ai = { is_planet_class = pc_ai }
TAC_is_pc_infested = { is_planet_class = pc_infested }
TAC_is_pc_gaia = { is_planet_class = pc_gaia }
TAC_is_pc_shrouded = { is_planet_class = pc_shrouded }
TAC_is_pc_broken = { is_planet_class = pc_broken }
TAC_is_pc_shattered = { is_planet_class = pc_shattered }
TAC_is_pc_shrouded = { is_planet_class = pc_shrouded }
TAC_is_pc_gray_goo = { is_planet_class = pc_gray_goo }
TAC_is_pc_city = { is_planet_class = pc_city }
TAC_is_pc_relic = { is_planet_class = pc_relic }


############################### The Empty Vagrant ###############################
can_be_ev_investment_country = {
	OR = {
		is_country_type = default
		# Darkspace
		is_country_type = ds_nomads
	}
	is_hive_empire = no
	is_machine_empire = no
	num_owned_planets > 0
	opinion = {
		who = root
		value > -99
	}
	NOT = {
		is_at_war_with = root
	}
	NOR = {
		has_ethic = ethic_fanatic_xenophobe
		is_homicidal = yes
		# Expanded Traits, Civics, Pops, and More
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_valid_civic = civic_infestation
			"
			toggle = @expops_compatch_var
		}
	}
	has_communications = ROOT
	NOT = {
		has_country_flag = ev_received_an_investment
	}
	is_ai = yes
}

############################### Unique Ascension Perks ###############################
is_common_empire = {
	is_regular_empire = yes
	is_megacorp = no
	is_hive_empire = no
}

############################### The Sleeper ###############################
is_marauder = {
	OR = {
		is_country_type = dormant_marauders
		is_country_type = ruined_marauders
		is_country_type = awakened_marauders
		is_country_type = marauder_raiders
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_country_type = awakened_marauders_ev
			"
			toggle = @homeless_class_trait_weight
		}
	}
}

############################### Voyage to Eternity ###############################
KZ_VOY_has_communications_normal_country = {
	OR = {
		merg_is_default_empire = yes
		merg_is_fallen_empire = yes
		merg_is_awakened_fe = yes
	}
	has_communications = prev
	NOT = { is_country = prev }
}
KZ_VOY_is_normal_habitable_planet = {
	OR = {
		merg_is_alpine = yes
		merg_is_arctic = yes
		merg_is_arid = yes
		merg_is_continental = yes
		merg_is_desert = yes
		merg_is_ocean = yes
		merg_is_savannah = yes
		merg_is_tropical = yes
		merg_is_tundra = yes
	}
}

############################### Warship Girls R and MIST Species ###############################
is_habitat_wg = {
	OR = {
		merg_is_habitat = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				giga_is_pc_flat_world = yes
				giga_is_pc_squareworld_habitable = yes
			"
			toggle = @has_gigastructures
		}
	}
}
is_default_and_fallen_country = {
	OR = {
		merg_is_default_empire = yes
		merg_is_fallen_empire = yes
		merg_is_awakened_fe = yes
	}
}
is_default_country_wg = {
	merg_is_default_empire = yes
}
has_active_wg_foundry_building = {
	OR = {
		has_active_wg_foundry_building_lv_low = yes
		has_active_wg_foundry_building_lv_high = yes
	}
}
has_active_wg_foundry_building_lv_low = {
	OR = {
		has_active_building = building_foundry_1
		has_active_building = building_foundry_2
		# Warship Girls R and MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_sep_foundry
				has_active_building = building_wsg_foundry
				has_active_building = building_gray_nano_foundry
				has_active_building = building_sh_foundry
			"
			toggle = @wsg_mod
		}
	}
}
has_active_wg_foundry_building_lv_high = {
	OR = {
		has_active_building = building_foundry_3
		has_active_building = building_nano_forge
		# ACOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_fe_alloy_forge
				has_active_building = building_acot_ae_alloy_forge
				has_active_building = building_acot_ae_nano_forge
			"
			toggle = @has_ancient_caches
		}
		# AOT
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_fe_nano_forge
				has_active_building = building_phanon_nano_forge
				has_active_building = building_phanon_alloy_forge
				has_active_building = building_stellarite_nano_forge
				has_active_building = building_stellarite_alloy_forge
			"
			toggle = @has_acquisition_of_tech
		}
		# AVB
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_avb_foundry_4
				has_active_building = building_avb_foundry_5
				has_active_building = building_avb_foundry_6
			"
			toggle = @has_avb_mod
		}
		# EDA
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = eda_building_alloy_foundry
			"
			toggle = @eda_mod
		}
		# Protoss
		has_active_building = protoss_building_bf
		# Warship Girls R and MIST Species
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_sep_foundry2
				has_active_building = building_wsg_foundry
				has_active_building = building_gray_nano_foundry2
				has_active_building = building_sh_foundryU
			"
			toggle = @wsg_mod
		}
		# Wula Fallen Empire
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				has_active_building = building_wula_foundry
			"
			toggle = @wula_compatch_var
		}
	}
}
has_active_wg_factory_building = {
	merg_has_manufacturing_building = yes
}
has_gate_megastructure = {
	merg_is_gate_mega = yes
}

############################### Wiirlak Additional Civics & Origins ###############################
wiirlak_ac_project_entropy_system_check = {
	is_surveyed = {
		who = ROOT
		status = yes
	}

	NOR = {
		merg_is_hole_star_class = yes
		merg_is_neutron_star_class = yes
		merg_is_pulsar_star_class = yes
		is_star_class = sc_toxoid_star

		has_star_flag = wiirlak_ac_flag_project_entropy_possible_target

		any_fleet_in_system = {
			owner = {
				OR = {
					is_country_type = caravaneer_home
					is_country_type = enclave
					is_country_type = enclave_mercenary
				}
			}
		}

		any_system_planet = {
			OR = {
				is_colony = yes
				habitable_planet = yes
				has_anomaly = yes
				is_terraforming = yes
				exists = archaeological_site
				has_modifier = wiirlak_ac_modifier_project_cradle
			}
		}
	}
}

############################### Wild Space ###############################
is_nebula_star = {
	merg_is_nebulae = yes
}

############################### WP's Mysterious Worlds ###############################
wp_mw_is_alpine = { merg_is_alpine = yes }
wp_mw_is_arctic = { merg_is_arctic = yes }
wp_mw_is_arid = { merg_is_arid = yes }
wp_mw_is_continental = { merg_is_continental = yes }
wp_mw_is_desert = { merg_is_desert = yes }
wp_mw_is_gaia = { merg_is_gaia_basic = yes }
wp_mw_is_nuked = { merg_is_nuked_basic = yes }
wp_mw_is_ocean = { merg_is_ocean = yes }
wp_mw_is_savannah = { merg_is_savannah = yes }
wp_mw_is_tropical = { merg_is_tropical = yes }
wp_mw_is_tundra = { merg_is_tundra = yes }

wp_mw_planets_affected_at_game_start = {
	is_colonizable = yes
	NOR = {
		AND = {
			is_capital = yes
			owner = { is_primitive = no }
		}
		merg_is_relic_world = yes
		merg_is_arcology = yes
		is_artificial = yes
		has_planet_flag = planet_earth
		has_planet_flag = wp_mw_ignore_planet_flag
	}
}

############################### WP's Planet View ###############################
wp_pv_is_clear_sky_planet = { # used to determine star visibility
	NAND = {
		exists = owner
		owner = {
			OR = {
				has_origin = origin_subterranean
				has_origin = origin_subterranean_machines
			}
		}
		is_colony = yes
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				pd_is_planet_class_cave = yes
			"
			toggle = @has_planetary_diversity
		}
	}
	OR = {
		merg_is_arid = yes
		merg_is_desert = yes
		merg_is_savannah = yes
		merg_is_alpine = yes
		merg_is_arctic = yes
		merg_is_tundra = yes
		merg_is_continental = yes
		merg_is_tropical = yes
		merg_is_ocean = yes
		merg_is_gaia_basic = yes

	}
	NOT = {
		has_planet_flag = planet_has_obscured_skies # other modders can set this flag to their planets to remove the stars from view
	}
}
wp_pv_is_not_binary_or_trinary = {
	NOR = {
		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
		}
		# 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
		}
		# Real Space
		inline_script = {
			script = merger_of_rules/toggled_code
			code = "
				is_binary = yes
				is_trinary = yes
				is_paired = yes
			"
			toggle = @rs_compatch_var
		}
	}
}

############################### WP's Planetary Features Expanded ###############################
planetary_feature_expansion_is_arid = { merg_is_arid = yes }
planetary_feature_expansion_is_savannah = { merg_is_savannah = yes }
planetary_feature_expansion_is_desert = { merg_is_desert = yes }
planetary_feature_expansion_is_alpine = { merg_is_alpine = yes }
planetary_feature_expansion_is_arctic = { merg_is_arctic = yes }
planetary_feature_expansion_is_tundra = { merg_is_tundra = yes }
planetary_feature_expansion_is_continental = { merg_is_continental = yes }
planetary_feature_expansion_is_tropical = { merg_is_tropical = yes }
planetary_feature_expansion_is_ocean = { merg_is_ocean = yes }
planetary_feature_expansion_is_nuked = { merg_is_nuked_basic = yes }
planetary_feature_expansion_is_gaia = { merg_is_gaia_basic = yes }

############################### Zenith of the Fallen Empires ###############################
# Overwriting this for ZOFE and comp mods
is_zofe_compatible = {
	merg_is_default_empire = yes
}

############################### Zer0's Infinity Stones ###############################
valid_to_recieve_infinity_stone = {
	merg_is_default_empire = yes
	is_subject = no
}
zero_is_targetable_empire_for_random_effects = {
	is_default_or_fallen = yes
}
