#	Example:
#
#	example_trigger = {
#		is_country_type = default
#		num_communications > 0
#	}
#
#
#	In a script file:
#
#	trigger = {
#		example_trigger = yes
#	}
#

print_scope_trigger = {
    log = "------------------------------"
    log = "- Printing the current scopes (trigger) -"
    log = "- This: \\[This.GetName]"
    log = "- Root: \\[Root.GetName]"
    log = "- Prev: \\[Prev.GetName]"
    log = "- PrevPrev: \\[PrevPrev.GetName]"
    log = "- PrevPrevPrev: \\[PrevPrevPrev.GetName]"
    log = "- PrevPrevPrevPrev: \\[PrevPrevPrevPrev.GetName]"
    log = "- From: \\[From.GetName]"
    log = "- FromFrom: \\[FromFrom.GetName]"
    log = "- FromFromFrom: \\[FromFromFrom.GetName]"
    log = "- FromFromFromFrom: \\[FromFromFromFrom.GetName]"
    log = "- Root's Solar System / Star Name: \\[Root.Solar_System.GetName] / [Root.GetStarName]"
    log = "- Root's Owner's Name: \\[Root.Owner.GetName]"
    log = "- Root's Owner's Capital's Name: \\[Root.Owner.Capital.GetName]"
    log = "------------------------------"
}

is_pirate_system = {
	any_fleet_in_system = {
		is_ship_size = pirate_station
	}
}

is_shackled_robot_species_rights = {
	OR = {
		has_trait = trait_mechanical
		has_trait = trait_machine_unit
	}
	species_rights_robot_full_rights_check = no
}

is_free_robot_species_rights = {
	OR = {
		has_trait = trait_mechanical
		has_trait = trait_machine_unit
	}
	species_rights_robot_full_rights_check = yes
}

species_rights_robot_full_rights_check = {
	exists = from
	from = {
		OR = {
			has_policy_flag = ai_full_rights
			is_mechanical_empire = yes
			has_origin = origin_synthetic_fertility
		}
	}
}

is_free_robot = { # The pop is a free robot with citizen rights
	has_trait = "trait_mechanical"
	exists = owner
	owner = {
		has_technology = "tech_synthetic_workers"
		OR = {
			has_policy_flag = ai_full_rights
			is_mechanical_empire = yes
		}
	}
}

# should always match country_has_shackled_robots
is_shackled_robot = { # The pop is a non-free robot
	has_trait = "trait_mechanical"
	NAND = {
		exists = owner
		owner = {
			OR = {
				AND = {
					has_policy_flag = ai_full_rights
					OR = {
						has_technology = "tech_synthetic_workers" #Robits don't get rights until they are Synths
						has_country_flag = robots_have_souls #syndaw.545
					}
				}
				is_mechanical_empire = yes
			}
		}
	}
}

# make sure this means the same as is_shackled_robot
country_has_shackled_robots = {
	NOR = {
		AND = {
			has_policy_flag = ai_full_rights
			OR = {
				has_technology = "tech_synthetic_workers" #Robits don't get rights until they are Synths
				has_country_flag = robots_have_souls #syndaw.545
			}
		}
		is_mechanical_empire = yes
	}
	any_owned_species = {
		has_trait = "trait_mechanical"
	}
}

is_non_sapient_robot = { # The pop is a non-sapient robot
	has_trait = "trait_mechanical"
	NAND = {
		exists = owner
		owner = {
			has_technology = "tech_synthetic_workers"
			NOT = { has_policy_flag = ai_outlawed }
		}
	}
	AND = {
		exists = owner
		owner = {
			is_machine_empire = no
		}
	}
}

is_non_menial_laborer = {
	OR = {
		is_enslaved = no
		NOT = { has_slavery_type = { country = from type = slavery_normal } }
	}
	is_non_sapient_robot = no
	is_sapient = yes
}

wears_clothes = { # The species uses the portrait that wears clothes
	OR = {
		is_human_species = yes
		species_portrait = humanoid_02
		species_portrait = humanoid_03
		species_portrait = humanoid_04
		species_portrait = humanoid_05
		species_portrait = humanoid_hp_01
		species_portrait = humanoid_hp_02
		species_portrait = humanoid_hp_06
		species_portrait = humanoid_hp_07
		species_portrait = humanoid_hp_08
		species_portrait = humanoid_hp_09
		species_portrait = humanoid_hp_10
		species_portrait = humanoid_hp_11
		species_portrait = humanoid_hp_12
		species_portrait = humanoid_hp_13
		species_portrait = mam1
		species_portrait = mam2
		species_portrait = mam3
		species_portrait = mam4
		species_portrait = mam5
		species_portrait = mam6
		species_portrait = mam7
		species_portrait = mam8
		species_portrait = mam9
		species_portrait = mam10
		species_portrait = mam11
		species_portrait = mam12
		species_portrait = mam13
		species_portrait = mam14
		species_portrait = mam15
		species_portrait = mam16
		species_portrait = mam17
		species_portrait = mam_rat
		species_portrait = rep1
		species_portrait = rep2
		species_portrait = rep3
		species_portrait = rep4
		species_portrait = rep5
		species_portrait = rep6
		species_portrait = rep7
		species_portrait = rep8
		species_portrait = rep9
		species_portrait = rep10
		species_portrait = rep11
		species_portrait = rep12
		species_portrait = rep13
		species_portrait = rep15
		species_portrait = rep16
		species_portrait = avi1
		species_portrait = avi2
		species_portrait = avi4
		species_portrait = avi5
		species_portrait = avi6
		species_portrait = avi8
		species_portrait = avi9
		species_portrait = avi10
		species_portrait = avi11
		species_portrait = avi12
		species_portrait = avi13
		species_portrait = avi14
		species_portrait = avi15
		species_portrait = avi16
		species_portrait = art6
		species_portrait = art7
		species_portrait = art8
		species_portrait = art9
		species_portrait = art10
		species_portrait = mol1
		species_portrait = mol2
		species_portrait = mol3
		species_portrait = mol4
		species_portrait = mol5
		species_portrait = mol11
		species_portrait = mol12
		species_portrait = mol13
		species_portrait = mol14
		species_portrait = mol15
		species_portrait = fun6
		species_portrait = fun7
		species_portrait = fun8
		species_portrait = fun9
		species_portrait = fun10
		species_portrait = pla6
		species_portrait = pla7
		species_portrait = pla8
		species_portrait = pla9
		species_portrait = pla10
		species_portrait = aqu4
		species_portrait = aqu5
		species_portrait = aqu6
		species_portrait = nec10
		species_portrait = nec11
		species_portrait = nec12
		species_portrait = nec13
		species_portrait = nec14
		species_portrait = nec15
		species_portrait = tox2
		species_portrait = tox3
		species_portrait = tox6
		species_portrait = tox8
		species_portrait = tox10
		species_portrait = tox11
		species_portrait = tox12
		species_portrait = tox14
		species_portrait = tox15
		species_portrait = cyb8
		species_portrait = cyb1
		species_portrait = cyb2
		species_portrait = cyb3
		species_portrait = cyb6
		species_portrait = cyb7
		species_portrait = cyb4
		species_portrait = cyb10
		species_portrait = cyb5
		species_portrait = season_10_portrait
	}
}

is_fallen_empire_hive = {
	OR = {
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
	}
	is_hive_empire = yes
}

is_fallen_empire_machine = {
	OR = {
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
	}
	is_machine_empire = yes
}

is_fallen_empire_berserk_machine = {
	is_fallen_empire_machine = yes
	has_valid_civic = civic_malfunctioning_custodian
}

is_fallen_empire_materialist = {
	OR = {
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
	}
	is_fanatic_materialist = yes
}

is_fallen_empire_spiritualist = {
	OR = {
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
	}
	is_fanatic_spiritualist = yes
}

is_fallen_empire_xenophobe = {
	OR = {
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
	}
	has_ethic = ethic_fanatic_xenophobe
}

is_fallen_empire_xenophile = {
	OR = {
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
	}
	is_fanatic_xenophile = yes
}

is_valid_fallen_empire_for_task = {
	is_country_type = fallen_empire
	is_at_war = no
	fleet_power > 60000
	OR = {
		is_fanatic_spiritualist = yes
		is_fanatic_xenophile = yes
		is_fanatic_materialist = yes
		is_machine_empire = yes
	}
}

is_fe_cluster = {
	OR = {
		is_in_cluster = fe1_cluster
		is_in_cluster = fe2_cluster
		is_in_cluster = fe3_cluster
		is_in_cluster = fe4_cluster
		is_in_cluster = fe_mach_cluster
		is_in_cluster = scion_fe1_cluster
		is_in_cluster = scion_fe2_cluster
		is_in_cluster = fe_hive_cluster
	}
}

is_marauder_cluster = {
	OR = {
		is_in_cluster = marauder_1_cluster
		is_in_cluster = marauder_2_cluster
		is_in_cluster = marauder_3_cluster
	}
}

empire_design_never = {
	optimize_memory
	always = no
}

has_leviathans = {
	optimize_memory
	host_has_dlc = "Leviathans Story Pack"
}

has_plantoids = {
	optimize_memory
	host_has_dlc = "Plantoids Species Pack"
}

has_lithoids = {
	optimize_memory
	host_has_dlc = "Lithoids Species Pack"
}

has_federations_dlc = {
	optimize_memory
	host_has_dlc = "Federations"
}

has_necroids = {
	optimize_memory
	host_has_dlc = "Necroids Species Pack"
}

has_nemesis = {
	optimize_memory
	host_has_dlc = "Nemesis"
}

has_aquatics = {
	optimize_memory
	host_has_dlc = "Aquatics Species Pack"
}

has_apocalypse_dlc = {
	optimize_memory
	host_has_dlc = "Apocalypse"
}

has_space_monster_dlc = {
	OR = {
		host_has_dlc = "Leviathans Story Pack"		# Ether Drake
		host_has_dlc = "Distant Stars Story Pack"	# Tiyanki Martriarch, Voidspawn
		host_has_dlc = "Ancient Relics Story Pack"	# Shard
		host_has_dlc = "Aquatics Species Pack"		# Sky Dragon
	}
}

has_genetic_dlc = {
	OR = {
		host_has_dlc = "Plantoids Species Pack"		# Plantoid Traits
		host_has_dlc = "Lithoids Species Pack"		# Lithoid Traits
		has_space_monster_dlc = yes
	}
}

harvested_leviathan_dna = {
	OR = {
		has_country_flag = harvested_voidspawn_dna
		has_country_flag = harvested_dragon_dna
		has_country_flag = harvested_tiyanki_dna
	}
}

has_overlord_dlc = {
	optimize_memory
	host_has_dlc = "Overlord"
}

has_toxoids = {
	optimize_memory
	host_has_dlc = "Toxoids Species Pack"
}

has_first_contact_dlc = {
	optimize_memory
	host_has_dlc = "First Contact Story Pack"
}

has_astral_planes_dlc = {
	optimize_memory
	host_has_dlc = "Astral Planes"
}

has_cosmic_storms_dlc = {
	optimize_memory
	host_has_dlc = "Cosmic Storms"
}

has_machine_age_dlc = {
	optimize_memory
	host_has_dlc = "The Machine Age"
}

has_not_machine_age_dlc = {
	optimize_memory
	NOT = {
		host_has_dlc = "The Machine Age"
	}
}

has_grand_archive_dlc = {
	optimize_memory
	host_has_dlc = "Grand Archive"
}

has_rick_the_cube_dlc = {
	optimize_memory
	host_has_dlc = "Rick The Cube Species Portrait"
}

has_stargazer_dlc = {
	optimize_memory
	host_has_dlc = "Stargazer Species Portrait"
}

#Season 10
has_season_10_dlc = {
	optimize_memory
	host_has_dlc = "Stargazer Species Portrait" #change to season 10 dlc
}

has_vipra_the_vapor_dlc = {
	optimize_memory
	host_has_dlc = "Vipra the Vapor Species Portrait"
}

has_biogenesis_dlc = {
	optimize_memory
	host_has_dlc = "BioGenesis"
}

has_shroud_dlc = {
	optimize_memory
	host_has_dlc = "Shadows of the Shroud"
}

has_shroud_dlc_not_machine_age = {
	optimize_memory
	host_has_dlc = "Shadows of the Shroud"
	NOT = {
		host_has_dlc = "The Machine Age"
	}
}

has_shroud_dlc_and_machine_age = {
	optimize_memory
	host_has_dlc = "Shadows of the Shroud"
	host_has_dlc = "The Machine Age"
}

has_infernals = {
	optimize_memory
	host_has_dlc = "Infernals Species Pack"
}

uninhabitable_regular_planet = {
	OR = {
		is_planet_class = pc_molten
		is_planet_class = pc_barren
		is_planet_class = pc_barren_cold
		is_planet_class = pc_toxic
		is_planet_class = pc_frozen
	}
}

colonizable_planet = {
	OR = {
		is_planet_class = pc_city
		is_planet_class = pc_relic
		is_planet_class = pc_nuked
		is_planet_class = pc_hive
		is_planet_class = pc_machine
		habitable_structure = yes
		habitable_planet = yes
	}
}

habitable_planet = {
	OR = {
		habitable_planet_not_urban = yes
		is_planet_class = pc_relic
		is_planet_class = pc_city
	}
}

habitable_planet_not_urban = {
	OR = {
		is_planet_class = pc_desert
		is_planet_class = pc_tropical
		is_planet_class = pc_arid
		is_planet_class = pc_continental
		is_planet_class = pc_ocean
		is_planet_class = pc_tundra
		is_planet_class = pc_arctic
		is_planet_class = pc_alpine
		is_planet_class = pc_savannah
		is_planet_class = pc_gaia
		is_planet_class = pc_volcanic
	}
}

is_urban_planet = {
	OR = {
		is_planet_class = pc_city
		is_planet_class = pc_relic
	}
}

is_starting_planet_type = {
	OR = {
		is_planet_class = pc_desert
		is_planet_class = pc_tropical
		is_planet_class = pc_arid
		is_planet_class = pc_continental
		is_planet_class = pc_ocean
		is_planet_class = pc_tundra
		is_planet_class = pc_arctic
		is_planet_class = pc_alpine
		is_planet_class = pc_savannah
		is_planet_class = pc_volcanic
	}
}

can_have_habitable_deposits = {
	OR = {
		is_planet_class = pc_nuked
		is_planet_class = pc_desert
		is_planet_class = pc_tropical
		is_planet_class = pc_arid
		is_planet_class = pc_continental
		is_planet_class = pc_ocean
		is_planet_class = pc_tundra
		is_planet_class = pc_arctic
		is_planet_class = pc_alpine
		is_planet_class = pc_savannah
		is_planet_class = pc_gaia
		is_planet_class = pc_relic
		is_planet_class = pc_volcanic
	}
}

habitable_structure = {
	is_artificial = yes
	OR = {
		is_colony = yes
		is_colonizable = yes
	}
}

has_ringworld_output_boost = {
	is_ringworld = yes
}

is_guardian_country = {
	OR = {
		is_country_type = guardian
		is_country_type = guardian_dragon
		is_country_type = guardian_sphere
		is_country_type = guardian_wraith
		is_country_type = guardian_horror
		is_country_type = guardian_fortress
		is_country_type = guardian_hiver
		is_country_type = guardian_stellarite
		is_country_type = guardian_dreadnought
		is_country_type = guardian_scavenger_bot
		is_country_type = guardian_elderly_tiyanki
		is_country_type = guardian_hatchling
		is_country_type = guardian_toxic_god
		is_country_type = guardian_opus_sentinel
	}
}

is_curator_guardian_poi = {
	OR = {
		is_point_of_interest = {
			id = curator_poi_dragon
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_technosphere
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_wraith
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_horror
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_fortress
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_hiver
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_stellarite
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_dreadnought
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_hatchling
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_tiyanki
			owner = root
			event_chain = curator_poi_chain
		}
		is_point_of_interest = {
			id = curator_poi_scavenger_bot
			owner = root
			event_chain = curator_poi_chain
		}
	}
}

has_encountered_other_species = {
	OR = {
		has_origin = origin_syncretic_evolution
		has_origin = origin_necrophage
		has_origin = origin_payback
		has_civic = civic_machine_servitor
		num_communications > 0
		any_owned_species = {
			NOT = { has_trait = "trait_mechanical" }
			NOT = { is_same_species = prev }
		}
	}
}

# has_citizenship_rights = { #handled in code now
# 	OR = {
# 		has_citizenship_type = { type = citizenship_full }
# 		has_citizenship_type = { type = citizenship_full_machine }
# 	}
# }

allows_alien_leaders = {
	any_owned_species = {
		NOT = { is_same_species = root }
		has_citizenship_rights = yes
	}
}

can_be_leader = {
	OR = {
		has_citizenship_rights = yes
		has_citizenship_type = { type = citizenship_shroud_touched country = root }
	}
	# Rule out Traits for servitude & lack of free will
	can_think = yes
	NOT = { has_trait = trait_syncretic_proles }
	OR = {
		is_robot_pop_group = no
		root = {
			OR = {
				has_technology = tech_synthetic_leaders
				is_machine_empire = yes
				is_mechanical_empire = yes
				is_individual_machine = yes
				has_country_flag = synthetic_fertility_no_bodies_left
			}
		}
	}
	OR = {
		is_same_species = root
		root = {
			NAND = {
				has_origin = origin_necrophage
				has_trait = trait_necrophage
			}
		}
	}
}

can_be_military_leader = {
	is_enslaved = no
	is_sapient = yes
	OR = {
		is_robot_pop_group = no
		owner = { has_policy_flag = ai_full_rights }
		owner = { is_machine_empire = yes }
		owner = { is_individual_machine = yes }
	}
	OR = {
		AND = { # MIs only accept Fully Integrated leaders
			owner = { is_machine_empire = yes }
			OR = {
				has_citizenship_type = { type = citizenship_full_machine country = owner }
				has_citizenship_type = { type = citizenship_cruise_crew country = owner }
				has_citizenship_type = { type = citizenship_shroud_touched country = root }
			}
			has_military_service_type = { type = military_service_full }
		}
		AND = { # non-MIs accept whatever
			NOT = { owner = { is_machine_empire = yes } }
			has_military_service_type = { type = military_service_full }
		}
	}
}

can_be_soldier = {
	is_sapient = yes
	exists = prev.owner
	NOT = { has_trait = trait_tankbound }
	OR = {
		has_military_service_type = { type = military_service_full country = prev.owner }
		has_military_service_type = { type = military_service_limited country = prev.owner }
	}
}

allows_slavery = {
	OR = {
		has_policy_flag = slavery_allowed
		has_ethic = ethic_gestalt_consciousness
	}
}

allows_purge = {
	OR = {
		has_policy_flag = purge_allowed
		has_ethic = ethic_gestalt_consciousness
		has_valid_civic = civic_fanatic_purifiers
	}
}

allows_preftl_exploitation = {
	OR = {
		has_policy_flag = interference_aggressive
		has_policy_flag = interference_active
	}
}

can_build_megastructure_on_planet = {
	has_any_megastructure = no
	NOR = {
		has_planet_flag = megastructure
		has_planet_flag = has_megastructure
		solar_system = {
			has_star_flag = ring_world_built
		}
	}
}

# The bodies a completed Dyson Sphere freezes.
is_frozen_by_dyson_sphere = {
	OR = {
		is_planet_class = pc_molten
		is_planet_class = pc_toxic
		habitable_planet = yes
	}
}

# A megastructure upgrade and a terraform both read their conditions only when they
# are ordered, so a body either one would transform cannot be trusted to survive.
is_consumed_by_action_in_progress = {
	OR = {
		is_terraforming = yes
		AND = {
			is_star = no
			solar_system = {
				any_system_megastructure = {
					is_upgrading = yes
					is_megastructure_type = ring_world_1
				}
			}
		}
		AND = {
			is_frozen_by_dyson_sphere = yes
			solar_system = {
				any_system_megastructure = {
					is_upgrading = yes
					OR = {
						is_megastructure_type = dyson_sphere_4
						is_megastructure_type = dyson_sphere_ruined
					}
				}
			}
		}
	}
}

has_generic_government = {
	OR = {
		has_government = gov_despotic_empire
		has_government = gov_feudal_empire
		has_government = gov_constitutional_dictatorship
		has_government = gov_plutocratic_oligarchy
		has_government = gov_representative_democracy
	}
}

has_spiritualist_government = {
	OR = {
		has_government = gov_theocratic_monarchy
		has_government = gov_theocratic_dictatorship
		has_government = gov_theocratic_oligarchy
		has_government = gov_theocratic_republic
		has_government = gov_divine_empire
		has_government = gov_holy_tribunal
		has_government = gov_mortal_empire
		has_government = gov_grim_council
		has_government = gov_megachurch
		has_government = gov_sacrificial_megachurch
		has_government = gov_dimensional_covenant
		AND = {
			has_advanced_government = yes
			is_spiritualist = yes
		}
	}
}

has_militarist_government = {
	OR = {
		has_government = gov_star_empire
		has_government = gov_military_dictatorship
		has_government = gov_military_junta
		has_government = gov_military_commissariat
		has_government = gov_martial_empire
		has_government = gov_martial_dictatorship
		has_government = gov_war_council
		has_government = gov_assembly_of_clans
		has_government = gov_citizen_stratocracy
		has_government = gov_citizen_republic
		has_government = gov_band_blood
		has_government = gov_defensive_union
		AND = {
			has_advanced_government = yes
			is_militarist = yes
		}
	}
}

has_pacifist_government = {
	OR = {
		has_government = gov_irenic_monarchy
		has_government = gov_irenic_dictatorship
		has_government = gov_irenic_bureaucracy
		has_government = gov_moral_democracy
		has_government = gov_celestial_empire
		AND = {
			has_advanced_government = yes
			is_pacifist = yes
		}
	}
}

has_materialist_government = {
	OR = {
		has_government = gov_despotic_hegemony
		has_government = gov_totalitarian_regime
		has_government = gov_executive_committee
		has_government = gov_direct_democracy
		has_government = gov_illuminated_autocracy
		has_government = gov_technocratic_dictatorship
		has_government = gov_science_directorate
		has_government = gov_rational_consensus
		AND = {
			has_advanced_government = yes
			is_materialist = yes
		}
	}
}

has_purifier_government = {
	OR = {
		has_government = gov_purification_committee
		has_government = gov_purity_assembly
		has_government = gov_purity_order
		has_government = gov_blood_court
	}
}

has_primitive_government = {
	OR = {
		has_government = gov_feudal_realms
		has_government = gov_fragmented_nation_states
	}
}

has_advanced_government = {
	OR = {
		has_cyber_government = yes
		has_synth_government = yes
		has_transcendent_government = yes
		has_corporeal_government = yes
	}
}

has_cyber_government = {
	OR = {
		has_government = gov_cyber_democracy_individualist
		has_government = gov_cyber_democracy_collectivist
		has_government = gov_cyber_oligarchy_individualist
		has_government = gov_cyber_oligarchy_collectivist
		has_government = gov_cyber_dictatorial_individualist
		has_government = gov_cyber_dictatorial_collectivist
		has_government = gov_cyber_imperial_individualist
		has_government = gov_cyber_imperial_collectivist
		has_government = gov_cyber_corporate_collectivist
		has_government = gov_cyber_hive_volitional
		has_government = gov_cyber_hive_integrated
	}
}

has_synth_government = {
	OR = {
		has_government = gov_synth_democracy_physical
		has_government = gov_synth_democracy_virtual
		has_government = gov_synth_oligarchy_physical
		has_government = gov_synth_oligarchy_virtual
		has_government = gov_synth_dictatorship_physical
		has_government = gov_synth_dictatorship_virtual
		has_government = gov_synth_imperial_physical
		has_government = gov_synth_imperial_virtual
		has_government = gov_synth_corporate_physical
		has_government = gov_synth_corporate_virtual
	}
}

has_transcendent_government = {
	OR = {
		has_government = gov_shroud_transcendent_democracy
		has_government = gov_shroud_transcendent_oligarchy
		has_government = gov_shroud_transcendent_dictatorial
		has_government = gov_shroud_transcendent_imperial
		has_government = gov_shroud_transcendent_corporate
		has_government = gov_shroud_transcendent_hive
		has_government = gov_shroud_transcendent_machine
	}
}

has_corporeal_government = {
	OR = {
		has_government = gov_shroud_corporeal_democracy
		has_government = gov_shroud_corporeal_oligarchy
		has_government = gov_shroud_corporeal_dictatorial
		has_government = gov_shroud_corporeal_imperial
		has_government = gov_shroud_corporeal_corporate
		has_government = gov_shroud_corporeal_hive
		has_government = gov_shroud_corporeal_machine
	}
}

prefers_scientist_governors = {
	OR = {
		has_valid_civic = civic_technocracy
	}
}

prefers_commander_governors = {
	OR = {
		has_valid_civic = civic_barbaric_despoilers
	}
}

#Works in species scope, with a country in from
is_lonely_hive_mind_pop = {
	has_trait = trait_hive_mind
	OR = {
		has_biogenesis_dlc = no			# New Species Rights unlocked for disconnected drones if BioGenesis is enabled
		from = {
			is_machine_empire = yes
		}
	}
	from = {
		is_hive_empire = no
		is_fallen_empire = no
	}
}

#Works in species scope, with a country in from
is_disconnected_drone_pop = {
	has_biogenesis_dlc = yes			# New Species Rights unlocked for disconnected drones if BioGenesis is enabled
	has_trait = trait_hive_mind
	from = {
		is_gestalt = no
		NOR = {
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
		}
	}
}

#Works in species scope, with a country in from
is_disconnected_machine_pop = {
	has_trait = trait_machine_unit
	from = {
		NOR = {
			is_machine_empire = yes
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
			is_individual_machine = yes
		}
	}
}

#deprecated
has_culture_shock = {
	OR = {
		has_modifier = culture_shock_stone_age
		has_modifier = culture_shock_bronze_age
		has_modifier = culture_shock_iron_age
		has_modifier = culture_shock_late_medieval_age
		has_modifier = culture_shock_renaissance_age
		has_modifier = culture_shock_steam_age
		has_modifier = culture_shock_industrial_age
		has_modifier = culture_shock_machine_age
		has_modifier = culture_shock_atomic_age
		has_modifier = culture_shock_early_space_age
		has_modifier = planet_culture_shock
	}
}

has_any_megastructure_in_empire = {
	any_system_within_border = {
		OR = {
			has_megastructure = spy_orb_1
			has_megastructure = spy_orb_2
			has_megastructure = spy_orb_3
			has_megastructure = spy_orb_4
			has_megastructure = think_tank_1
			has_megastructure = think_tank_2
			has_megastructure = think_tank_3
			has_megastructure = think_tank_4
			has_megastructure = dyson_sphere_1
			has_megastructure = dyson_sphere_2
			has_megastructure = dyson_sphere_3
			has_megastructure = dyson_sphere_4
			has_megastructure = dyson_sphere_5
			has_megastructure = ring_world_2_intermediate
			has_megastructure = dyson_sphere_ruined
			has_megastructure = dyson_sphere_restored
			has_megastructure = spy_orb_ruined
			has_megastructure = spy_orb_restored
			has_megastructure = think_tank_ruined
			has_megastructure = think_tank_restored
			has_megastructure = ring_world_ruined
			has_megastructure = ring_world_restored
			has_megastructure = matter_decompressor_1
			has_megastructure = matter_decompressor_2
			has_megastructure = matter_decompressor_3
			has_megastructure = matter_decompressor_4
			has_megastructure = matter_decompressor_ruined
			has_megastructure = matter_decompressor_restored
			has_megastructure = strategic_coordination_center_1
			has_megastructure = strategic_coordination_center_2
			has_megastructure = strategic_coordination_center_3
			has_megastructure = strategic_coordination_center_ruined
			has_megastructure = strategic_coordination_center_restored
			has_megastructure = mega_art_installation_1
			has_megastructure = mega_art_installation_2
			has_megastructure = mega_art_installation_3
			has_megastructure = mega_art_installation_ruined
			has_megastructure = mega_art_installation_restored
			has_megastructure = mega_art_installation_restored_2
			has_megastructure = interstellar_assembly_1
			has_megastructure = interstellar_assembly_2
			has_megastructure = interstellar_assembly_3
			has_megastructure = interstellar_assembly_4
			has_megastructure = interstellar_assembly_ruined
			has_megastructure = interstellar_assembly_restored
			has_megastructure = mega_shipyard_1
			has_megastructure = mega_shipyard_2
			has_megastructure = mega_shipyard_3
			has_megastructure = mega_shipyard_ruined
			has_megastructure = mega_shipyard_restored
			has_megastructure = crisis_sphere_0
			has_megastructure = crisis_sphere_1
			has_megastructure = crisis_sphere_2
			has_megastructure = crisis_sphere_3
			has_megastructure = crisis_sphere_4
			has_megastructure = quantum_catapult_0
			has_megastructure = quantum_catapult_1
			has_megastructure = quantum_catapult_2
			has_megastructure = quantum_catapult_3
			has_megastructure = quantum_catapult_ruined
			has_megastructure = quantum_catapult_restored
			has_megastructure = quantum_catapult_ruined_slingshot
			has_megastructure = quantum_catapult_restored_slingshot
			has_megastructure = galactic_crucible_0
			has_megastructure = galactic_crucible_1
			has_megastructure = galactic_crucible_2
			has_megastructure = galactic_crucible_3
			has_megastructure = galactic_crucible_4
			has_megastructure = galactic_crucible_5
			has_megastructure = galactic_crucible_ruined
		}
	}
}

is_binary_star = {
	OR = {
		is_star_class = sc_binary_1
		is_star_class = sc_binary_2
		is_star_class = sc_binary_3
		is_star_class = sc_binary_4
		is_star_class = sc_binary_5
		is_star_class = sc_binary_6
		is_star_class = sc_binary_7
		is_star_class = sc_binary_8
		is_star_class = sc_binary_9
		is_star_class = sc_binary_10
		is_star_class = sc_crisis_binary_1
		is_star_class = sc_crisis_binary_2
		is_star_class = sc_crisis_binary_5
		is_star_class = sc_crisis_binary_7_8_9
		is_star_class = sc_crisis_binary_10
		solar_system = {
			has_star_flag = vela_system
		}
	}
}

# Use: owner_has_resolution = { RES = resolution_ecology_integrated_gardens }
owner_has_resolution = {
	exists = owner
	owner = {
		is_galactic_community_member = yes
		is_active_resolution = $RES$
	}
}

has_ambition = {
	OR = {
		has_ascension_perk = ap_defender_of_the_galaxy_nomads
		has_ascension_perk = ap_become_the_crisis
		has_ascension_perk = ap_cosmogenesis
		has_ascension_perk = ap_behemoths
		has_ascension_perk = ap_galactic_hyperthermia
	}
}

has_defender_of_the_galaxy_ap = {
	OR = {
		has_ascension_perk = ap_defender_of_the_galaxy
		has_ascension_perk = ap_defender_of_the_galaxy_nomads
	}
}

is_under_crisis_bombardment = {
	has_orbital_bombardment = yes
	any_fleet_in_orbit = {
		exists = owner
		owner = {
			is_crisis_faction = yes
		}
	}
}

is_crisis_faction = {
	OR = {
		is_country_type = swarm
		is_country_type = extradimensional
		is_country_type = extradimensional_2
		is_country_type = extradimensional_3
		is_country_type = ai_empire
		is_country_type = gray_goo
		is_country_type = awakened_marauders
		is_country_type = synth_queen
		is_country_type = awakened_synth_queen
		is_country_type = synth_queen_storm
		is_country_type = voidworms_crisis
	}
}

has_crisis = {
	OR = {
		has_global_flag = crisis_stage_1
		has_global_flag = crisis_stage_2
		has_global_flag = crisis_stage_3
		has_global_flag = crisis_stage_4
	}
}

# Use: has_crisis_stage = { STAGE = 3}
# Default value 1.
# Use default value: has_crisis_stage = yes
has_crisis_stage ={
	has_global_flag = crisis_stage_$STAGE|1$
}

has_crisis_stage_1 ={
	has_global_flag = crisis_stage_1
}

has_crisis_stage_2 ={
	has_global_flag = crisis_stage_2
}

has_crisis_stage_3 ={
	has_global_flag = crisis_stage_3
}

has_crisis_stage_4 ={
	has_global_flag = crisis_stage_4
}

endgame_crisis_large_size_trigger = {
	OR = {
		galaxy_percentage > 0.15
		count_system_within_border = { count > 90 } #15% of a medium galaxy
	}
}

crisis_happened_and_defeated = { #Excluding Marauders/The Khan and Gray Tempest
	OR = {
		AND = {
			has_global_flag = ai_invasion_happened
			has_global_flag = ai_invasion_defeated
		}
		AND = {
			has_global_flag = extradimensional_invasion_happened
			has_global_flag = extradimensional_invasion_defeated
		}
		AND = {
			has_global_flag = prethoryn_invasion_happened
			has_global_flag = prethoryn_invasion_defeated
		}
		AND = {
			has_global_flag = synth_queen_happened
			has_global_flag = synth_queen_defeated
		}
	}
}

is_pre_sapient_livestock = {
	is_sapient = no
	has_citizenship_type = { type = citizenship_slavery	country = owner }
	has_slavery_type = { type = slavery_livestock }
}

is_livestock = {
	has_slavery_type = { type = slavery_livestock country = root }
}

is_synthetic_empire = {
	OR = {
		has_country_flag = synthetic_empire
		is_machine_empire = yes
		is_individual_machine = yes
	}
}

is_trinary_star = {
	OR = {
		is_star_class = sc_trinary_1
		is_star_class = sc_trinary_2
		is_star_class = sc_trinary_3
		is_star_class = sc_trinary_4
		is_star_class = sc_crisis_trinary_1
		is_star_class = sc_crisis_trinary_2
		is_star_class = sc_crisis_trinary_3
		is_star_class = sc_crisis_trinary_4
	}
}

planet_can_be_liberated_from_owner = {
	owner = {
		NOR = {
			is_country_type = awakened_fallen_empire
			is_country_type = fallen_empire
			is_hive_empire = yes
			is_machine_empire = yes
		}
	}
}

is_cyborg_empire = { # used primarily for Ascension Paths, Opinion Modifiers and flavour text
	owner_species = {
		has_cyber_trait = yes
	}
}

has_cyber_trait = {
	OR = {
		has_trait = trait_cybernetic
		has_unplugged_positive_trait = yes
	}
}

is_unplugged_cyborg_empire = {
	owner_species = {
		has_unplugged_positive_trait = yes
	}
}

is_mechanical_empire = {
	OR = {
		owner_species = { has_trait = trait_mechanical }
		has_country_flag = synthetic_empire
	}
}

is_robot_empire = {
	OR = {
		owner_species = { has_trait = trait_mechanical }
		owner_species = { has_trait = trait_machine_unit }
		has_country_flag = synthetic_empire
		is_machine_empire = yes
	}
}

# Scopes: country, leader, pop, army, (colony) ship
is_mechanical_species = {
	species = {
		OR = {
			has_trait = trait_machine_unit # Machine Intelligence
			has_trait = trait_mechanical # Robots & Synthetically-ascended Pops
		}
	}
}

is_virtual_empire = {
	owner_species = { has_virtual_species_trait = yes }
}

is_lithoid_empire = {
	owner_species = { is_lithoid = yes }
}

is_organic_empire = { #I know this is confusing with is_organic_species, I am sorry.
	owner_species = { has_trait = trait_organic }
}

is_lithoid_devouring_swarm = {
	is_lithoid_empire = yes
	has_valid_civic = civic_hive_devouring_swarm
	NOT = { has_origin = origin_wilderness } #Wilderness are not Terravores
}
has_devouring_swarm_government = {
	has_government = "gov_devouring_swarm"
	has_government = "gov_blood_forest"
}

is_lithoid_devouring_swarm_consumption_world = { # planet scope
	exists = owner
	NOR = {
		is_ideal_planet_class = {
			who = owner
			status = yes
		}
		AND = {
			planet_size > 13
			owner = {
				any_owned_species = {
					NOR = {
						has_citizenship_type = { country = prev type = citizenship_purge }
						has_citizenship_type = { country = prev type = citizenship_purge_machine }
					}
					prevprev = { habitability = { who = prev value >= 0.9 } }
				}
			}
		}
	}
}

is_country_type_with_subjects = {
	OR = {
		is_country_type = default
		is_country_type = awakened_fallen_empire
		is_country_type = awakened_marauders
	}
}

is_valid_target_fe_stop_atrocities = {
	OR = {
		allows_slavery = yes
		allows_purge = yes
	}
	NOT = { has_ethic = ethic_gestalt_consciousness }
	NOR = {
		has_valid_civic = civic_machine_terminator
		has_valid_civic = civic_hive_devouring_swarm
		has_valid_civic = civic_fanatic_purifiers
	}
}

is_valid_target_fe_stop_ai = {
	NOT = { has_policy_flag = ai_outlawed }
	NOT = { has_ethic = ethic_gestalt_consciousness }
	has_technology = tech_synthetic_workers
	is_mechanical_empire = no
}

is_valid_target_fe_cleanse_holy_worlds = {
	NOT = { has_relic = r_severed_head }
	OR = {
		any_owned_planet = {
			has_modifier = "holy_planet"
		}
		any_subject = {
			any_owned_planet = {
				has_modifier = "holy_planet"
			}
			NOT = { has_relic = r_severed_head }
		}
	}
}

has_sapient_combat_computer = {
	OR = {
		has_component = COMBAT_COMPUTER_SWARM_SAPIENT
		has_component = COMBAT_COMPUTER_LINE_SAPIENT
		has_component = COMBAT_COMPUTER_PICKET_SAPIENT
		has_component = COMBAT_COMPUTER_ARTILLERY_SAPIENT
		has_component = COMBAT_COMPUTER_CARRIER_SAPIENT
		has_component = COMBAT_COMPUTER_PLATFORM_SAPIENT
	}
}

has_autonomous_combat_computer = {
	OR = {
		has_component = COMBAT_COMPUTER_SWARM_AUTONOMOUS
		has_component = COMBAT_COMPUTER_LINE_AUTONOMOUS
		has_component = COMBAT_COMPUTER_PICKET_AUTONOMOUS
		has_component = COMBAT_COMPUTER_ARTILLERY_AUTONOMOUS
		has_component = COMBAT_COMPUTER_CARRIER_AUTONOMOUS
		has_component = COMBAT_COMPUTER_PLATFORM_AUTONOMOUS
	}
}

# This can replace all the specific ones.
is_ethics_aligned = {
	is_$ARG1$ = yes
}

has_opposing_ethics = {
	OR = {
		AND = {
			$COUNTRY1$ = { is_pacifist = yes }
			$COUNTRY2$ = { is_militarist = yes }
		}
		AND = {
			$COUNTRY1$ = { is_militarist = yes }
			$COUNTRY2$ = { is_pacifist = yes }
		}
		AND = {
			$COUNTRY1$ = { is_xenophobe = yes }
			$COUNTRY2$ = { is_xenophile = yes }
		}
		AND = {
			$COUNTRY1$ = { is_xenophile = yes }
			$COUNTRY2$ = { is_xenophobe = yes }
		}
		AND = {
			$COUNTRY1$ = { is_egalitarian = yes }
			$COUNTRY2$ = { is_authoritarian = yes }
		}
		AND = {
			$COUNTRY1$ = { is_authoritarian = yes }
			$COUNTRY2$ = { is_egalitarian = yes }
		}
		AND = {
			$COUNTRY1$ = { is_spiritualist = yes }
			$COUNTRY2$ = { is_materialist = yes }
		}
		AND = {
			$COUNTRY1$ = { is_materialist = yes }
			$COUNTRY2$ = { is_spiritualist = yes }
		}
	}
}

has_alternative_ethics = { # Consider THIS_SCOPE as the entity you are checking (e.g. a Pop), and REF_SCOPE as the reference point (e.g. an empire) you're checking against for ethical drift. Note that this trigger ignores directly opposing ethics.
	OR = {
		AND = {
			$THIS_SCOPE$ = {
				is_pacifist = yes
			}
			$REF_SCOPE$ = {
				is_pacifist = no
				is_militarist = no
			}
		}
		AND = {
			$THIS_SCOPE$ = {
				is_militarist = yes
			}
			$REF_SCOPE$ = {
				is_militarist = no
				is_pacifist = no
			}
		}
		AND = {
			$THIS_SCOPE$ = {
				is_xenophobe = yes
			}
			$REF_SCOPE$ = {
				is_xenophobe = no
				is_xenophile = no
			}
		}
		AND = {
			$THIS_SCOPE$ = {
				is_xenophile = yes
			}
			$REF_SCOPE$ = {
				is_xenophile = no
				is_xenophobe = no
			}
		}
		AND = {
			$THIS_SCOPE$ = {
				is_egalitarian = yes
			}
			$REF_SCOPE$ = {
				is_egalitarian = no
				is_authoritarian = no
			}
		}
		AND = {
			$THIS_SCOPE$ = {
				is_authoritarian = yes
			}
			$REF_SCOPE$ = {
				is_authoritarian = no
				is_egalitarian = no
			}
		}
		AND = {
			$THIS_SCOPE$ = {
				is_spiritualist = yes
			}
			$REF_SCOPE$ = {
				is_spiritualist = no
				is_materialist = no
			}
		}
		AND = {
			$THIS_SCOPE$ = {
				is_materialist = yes
			}
			$REF_SCOPE$ = {
				is_materialist = no
				is_spiritualist = no
			}
		}
	}
}

is_fanatic = {
	OR = {
		is_fanatic_authoritarian = yes
		is_fanatic_egalitarian = yes
		is_fanatic_materialist = yes
		is_fanatic_militarist = yes
		is_fanatic_pacifist = yes
		is_fanatic_spiritualist = yes
		is_fanatic_xenophile = yes
		is_fanatic_xenophobe = yes
	}
}

is_pacifist = {
	OR = {
		has_ethic = ethic_pacifist
		is_fanatic_pacifist = yes
	}
}

is_fanatic_pacifist = {
	has_ethic = ethic_fanatic_pacifist
}

is_militarist = {
	OR = {
		has_ethic = ethic_militarist
		is_fanatic_militarist = yes
	}
}

is_fanatic_militarist = {
	has_ethic = ethic_fanatic_militarist
}

is_materialist = {
	OR = {
		has_ethic = ethic_materialist
		has_ethic = ethic_fanatic_materialist
	}
}

is_fanatic_materialist = {
	has_ethic = ethic_fanatic_materialist
}

is_spiritualist = {
	OR = {
		has_ethic = ethic_spiritualist
		is_fanatic_spiritualist = yes
	}
}

is_fanatic_spiritualist = {
	has_ethic = ethic_fanatic_spiritualist
}

is_egalitarian = {
	OR = {
		has_ethic = ethic_egalitarian
		is_fanatic_egalitarian = yes
	}
}

is_fanatic_egalitarian = {
	has_ethic = ethic_fanatic_egalitarian
}

is_authoritarian = {
	OR = {
		has_ethic = ethic_authoritarian
		is_fanatic_authoritarian = yes
	}
}

is_fanatic_authoritarian = {
	has_ethic = ethic_fanatic_authoritarian
}

is_xenophile = {
	OR = {
		has_ethic = ethic_xenophile
		is_fanatic_xenophile = yes
	}
}

is_fanatic_xenophile = {
	has_ethic = ethic_fanatic_xenophile
}

is_xenophobe = {
	OR = {
		has_ethic = ethic_xenophobe
		is_fanatic_xenophobe = yes
	}
}

is_fanatic_xenophobe = {
	has_ethic = ethic_fanatic_xenophobe
}

is_regular_empire = {
	OR = {
		is_country_type = default
		#for checks in buildings and districts
		is_country_type = awakened_marauders
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
		is_country_type = exiled
	}
	NOT = { has_ethic = ethic_gestalt_consciousness	}
}

is_default_or_fallen = {
	OR = {
		is_country_type = default
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire #for checks in buildings
	}
}

is_capitalist = {
	OR = {
		is_megacorp = yes
		has_civic = civic_corporate_dominion
		has_civic = civic_merchant_guilds
	}
}

is_megacorp = {
	has_authority = auth_corporate
}

has_corporate_government = {
	OR = {
		is_megacorp = yes
		has_civic = civic_galactic_sovereign_megacorp
	}
}

is_gestalt = {
	has_ethic = ethic_gestalt_consciousness
}

is_hive_empire = {
	has_authority = auth_hive_mind
	# NOTE: also includes Wilderness Authority; see 'is_wilderness_empire'
}

is_machine_empire = {
	has_authority = auth_machine_intelligence
}

is_wilderness_empire = {
	# NOTE: presents as an 'advanced_authority_swap' from auth_hive_mind
	has_origin = origin_wilderness
}

is_infernal_empire = {
	owner_species = { has_trait = trait_infernal }
}

is_lithoid_or_infernal_empire = {
	OR = {
		is_lithoid_empire = yes
		is_infernal_empire = yes
	}
}

is_autocracy = { #Power of one
	OR = {
		has_ethic = ethic_gestalt_consciousness
		is_imperial_authority = yes
		is_dictatorial_authority = yes
	}
}

is_oligarchy = { #Power of few
	OR = {
		is_oligarchic_authority = yes
		is_megacorp = yes
	}
	is_egalitarian = no
}

is_democracy = { #Power of many
	OR = {
		is_democratic_authority = yes
		AND = {
			is_megacorp = yes
			is_egalitarian = yes
		}
	}
}

is_democratic_authority = {
	has_authority = auth_democratic
}

is_oligarchic_authority = {
	has_authority = auth_oligarchic
}

is_imperial_authority = {
	has_authority = auth_imperial
}

is_dictatorial_authority = {
	has_authority = auth_dictatorial
}

is_cyber_democracy = {
	is_democratic_authority = yes
	OR = {
		has_country_flag = cyber_individualist
		has_country_flag = cyber_collectivist
	}
}

is_cyber_oligarchy = {
	is_oligarchic_authority = yes
	OR = {
		has_country_flag = cyber_individualist
		has_country_flag = cyber_collectivist
	}
}

is_cyber_dictatorial = {
	is_dictatorial_authority = yes
	OR = {
		has_country_flag = cyber_individualist
		has_country_flag = cyber_collectivist
	}
}

is_cyber_imperial = {
	is_imperial_authority = yes
	OR = {
		has_country_flag = cyber_individualist
		has_country_flag = cyber_collectivist
	}
}

is_cyber_corporate = {
	is_megacorp = yes
	OR = {
		has_country_flag = cyber_individualist
		has_country_flag = cyber_collectivist
	}
}

is_synth_democracy = {
	is_democratic_authority = yes
	OR = {
		has_country_flag = synth_physical
		has_country_flag = synth_virtual
	}
}

is_synth_oligarchy = {
	is_oligarchic_authority = yes
	OR = {
		has_country_flag = synth_physical
		has_country_flag = synth_virtual
	}
}

is_synth_dictatorial = {
	is_dictatorial_authority = yes
	OR = {
		has_country_flag = synth_physical
		has_country_flag = synth_virtual
	}
}

is_synth_imperial = {
	is_imperial_authority = yes
	OR = {
		has_country_flag = synth_physical
		has_country_flag = synth_virtual
	}
}

is_synth_corporate = {
	is_megacorp = yes
	OR = {
		has_country_flag = synth_physical
		has_country_flag = synth_virtual
	}
}

can_set_ai_policy = {
	is_mechanical_empire = no
	OR = {
		has_technology = tech_synthetic_workers
		has_technology = tech_sapient_ai
		any_relation = {
			has_communications = prev
			OR = {
				has_technology = tech_synthetic_workers
				has_technology = tech_sapient_ai
				is_machine_empire = yes
				is_individual_machine = yes
			}
			OR = {
				is_country_type = default
				has_ai_personality_behaviour = robot_exploiter
				has_ai_personality_behaviour = robot_liberator
			}
		}
	}
}

has_met_primitives = {
	OR = {
		has_country_flag = encountered_first_primitive
		any_relation = {
			has_communications = root
			is_country_type = primitive
		}
	}
}

has_comms_with_alien_empire = {
	custom_tooltip = {
		fail_text = has_comms_with_alien_empire_tooltip
		any_relation = {
			has_communications = root
			OR = {
				is_country_type = default
				is_country_type = fallen_empire
				is_country_type = awakened_fallen_empire
			}
		}
	}
}

has_comms_with_alien_civilization = {
	any_relation = {
		has_communications = root
		OR = {
			is_country_type = default
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
			is_enclave_country = yes
			is_country_type = nomad
			is_country_type = dormant_marauders
			is_country_type = awakened_marauders
		}
	}
}

has_total_war_cb = {
	OR = {
		#attacker checks
		AND = {
			OR = {
				is_country_type = default
				is_country_type = awakened_fallen_empire
				is_country_type = fallen_empire
			}
			OR = {
				is_country_type = awakened_fallen_empire
				has_valid_civic = civic_hive_devouring_swarm
				has_menace_perk = menp_behemoth_ever_hungry
				has_valid_civic = civic_machine_assimilator
				has_valid_civic = civic_scorched_earth
				has_valid_civic = civic_hive_scorched_earth
				AND = {
					has_valid_civic = civic_machine_terminator
					from = {
						NOR = {
							has_country_flag = synthetic_empire
							is_machine_empire = yes
							is_individual_machine = yes
						}
					}
				}
				AND = {
					has_valid_civic = civic_fanatic_purifiers
					NOT = { is_same_species = from }
				}
			}
		}
		#end threat checks
		AND = {
			is_country_type = default
			NOR = {
				is_country_type = awakened_fallen_empire
				has_valid_civic = civic_fanatic_purifiers
				has_valid_civic = civic_hive_devouring_swarm
				has_valid_civic = civic_machine_assimilator
				has_valid_civic = civic_machine_terminator
				has_valid_civic = civic_scorched_earth
				has_valid_civic = civic_hive_scorched_earth
			}
			from = {
				is_valid_end_threat_target = yes
			}
		}
		# EotC Total War
		has_country_flag = reached_eotc_situation_stage2
		# Total War against EotC
		AND = {
			has_country_flag = can_declare_total_war_to_eotc
			from = { has_covenant_with_end_of_the_cycle = yes }
		}
	}
}

is_valid_end_threat_target = {
	OR = {
		is_country_type = awakened_fallen_empire
		is_country_type = synth_queen
		has_valid_civic = civic_fanatic_purifiers
		has_valid_civic = civic_hive_devouring_swarm
		has_valid_civic = civic_machine_assimilator
		has_valid_civic = civic_machine_terminator
		has_valid_civic = civic_scorched_earth
		has_valid_civic = civic_hive_scorched_earth
		has_menace_perk = menp_behemoth_ever_hungry
		has_country_flag = heir_of_the_khan_khan
		AND = {
			root = { has_country_flag = heir_of_the_khan_khan }
			OR = {
				is_galactic_emperor = yes
				is_galactic_custodian = yes
				has_been_declared_crisis = yes
			}
		}
	}
}

has_isolated_system = {
	any_system_within_border = {
		any_neighbor_system = {
			root = {
				intel_level = {
					level > none
					system = prev
				}
			}
			NOR = {
				has_star_flag = precursor_system
				has_star_flag = enclave
				any_fleet_in_system = {
					exists = owner
					owner = { is_hostile = root }
				}
				any_fleet_in_system = {
					is_ship_size = constructor
					is_constructing = starbase
				}
				any_fleet_in_system = {
					fleet_power > 1000
				}
			}
			NOT = { exists = space_owner }
			any_neighbor_system = {
				exists = space_owner
				NOT = {
					space_owner = { NOT = { is_same_value = root } }
				}
			}
			NOT = {
				any_neighbor_system = {
					NOT = { exists = space_owner }
				}
			}
		}
	}
}

has_bordering_system = {
	any_system_within_border = {
		any_neighbor_system = {
			root = {
				intel_level = {
					level > none
					system = prev
				}
			}
			NOR = {
				has_star_flag = precursor_system
				has_star_flag = enclave
				any_fleet_in_system = {
					exists = owner
					owner = { is_hostile = root }
				}
				any_ship_in_system = {
					is_ship_size = constructor
					is_constructing = starbase
				}
				any_fleet_in_system = {
					fleet_power > 1000
				}
			}
			NOT = { exists = space_owner }
		}
	}
}

# this: system
# root: great khan's horde (country)
is_potential_diadochi_system = {
	exists = starbase
	starbase = { owner = { is_same_value = root } }
	NOR = {
		has_star_flag = first_diadochi_system
		has_star_flag = second_diadochi_system
		has_star_flag = third_diadochi_system
		has_star_flag = fourth_diadochi_system
	}
}

has_no_non_gate_megastructure = {
	OR = {
		has_any_megastructure = no
		NOT = {
			has_star_flag = ring_world_built
			any_system_megastructure = { # exclude gateways
				OR = {
					is_megastructure_type = dyson_sphere_0
					is_megastructure_type = dyson_sphere_1
					is_megastructure_type = dyson_sphere_2
					is_megastructure_type = dyson_sphere_3
					is_megastructure_type = dyson_sphere_4
					is_megastructure_type = dyson_sphere_5
					is_megastructure_type = dyson_sphere_ruined
					is_megastructure_type = dyson_sphere_restored

					is_megastructure_type = ring_world_1
					is_megastructure_type = ring_world_2_intermediate
					is_megastructure_type = ring_world_2
					is_megastructure_type = ring_world_3_intermediate
					is_megastructure_type = ring_world_ruined
					is_megastructure_type = ring_world_restored

					is_megastructure_type = think_tank_0
					is_megastructure_type = think_tank_1
					is_megastructure_type = think_tank_2
					is_megastructure_type = think_tank_3
					is_megastructure_type = think_tank_4
					is_megastructure_type = think_tank_ruined
					is_megastructure_type = think_tank_restored

					is_megastructure_type = spy_orb_0
					is_megastructure_type = spy_orb_1
					is_megastructure_type = spy_orb_2
					is_megastructure_type = spy_orb_3
					is_megastructure_type = spy_orb_4
					is_megastructure_type = spy_orb_ruined
					is_megastructure_type = spy_orb_restored

					is_megastructure_type = habitat_central_complex

					is_megastructure_type = matter_decompressor_0
					is_megastructure_type = matter_decompressor_1
					is_megastructure_type = matter_decompressor_2
					is_megastructure_type = matter_decompressor_3
					is_megastructure_type = matter_decompressor_4
					is_megastructure_type = matter_decompressor_ruined
					is_megastructure_type = matter_decompressor_restored

					is_megastructure_type = strategic_coordination_center_0
					is_megastructure_type = strategic_coordination_center_1
					is_megastructure_type = strategic_coordination_center_2
					is_megastructure_type = strategic_coordination_center_3
					is_megastructure_type = strategic_coordination_center_ruined
					is_megastructure_type = strategic_coordination_center_restored

					is_megastructure_type = mega_art_installation_0
					is_megastructure_type = mega_art_installation_1
					is_megastructure_type = mega_art_installation_2
					is_megastructure_type = mega_art_installation_3
					is_megastructure_type = mega_art_installation_ruined
					is_megastructure_type = mega_art_installation_restored

					is_megastructure_type = interstellar_assembly_0
					is_megastructure_type = interstellar_assembly_1
					is_megastructure_type = interstellar_assembly_2
					is_megastructure_type = interstellar_assembly_3
					is_megastructure_type = interstellar_assembly_4
					is_megastructure_type = interstellar_assembly_ruined
					is_megastructure_type = interstellar_assembly_restored

					is_megastructure_type = mega_shipyard_0
					is_megastructure_type = mega_shipyard_1
					is_megastructure_type = mega_shipyard_2
					is_megastructure_type = mega_shipyard_3
					is_megastructure_type = mega_shipyard_ruined
					is_megastructure_type = mega_shipyard_restored

					is_megastructure_type = crisis_sphere_0
					is_megastructure_type = crisis_sphere_1
					is_megastructure_type = crisis_sphere_2
					is_megastructure_type = crisis_sphere_3
					is_megastructure_type = crisis_sphere_4

					is_quantum_catapult_megastructure = yes

					is_megastructure_type = orbital_ring
					is_megastructure_type = orbital_ring_restored

					is_megastructure_type = dyson_swarm_1
					is_megastructure_type = dyson_swarm_2
					is_megastructure_type = dyson_swarm_3

					is_megastructure_type = orbital_arc_furnace_1
					is_megastructure_type = orbital_arc_furnace_2
					is_megastructure_type = orbital_arc_furnace_3
					is_megastructure_type = orbital_arc_furnace_4

					is_megastructure_type = cosmogenesis_world_0

					is_megastructure_type = grand_archive_0

					is_megastructure_type = galactic_crucible_0
					is_megastructure_type = galactic_crucible_1
					is_megastructure_type = galactic_crucible_2
					is_megastructure_type = galactic_crucible_3
					is_megastructure_type = galactic_crucible_4
					is_megastructure_type = galactic_crucible_5
					is_megastructure_type = galactic_crucible_ruined

					is_megastructure_type = dyson_gun_0
					is_megastructure_type = dyson_gun_1
					is_megastructure_type = dyson_gun_2
					is_megastructure_type = dyson_gun_3
					is_megastructure_type = dyson_gun_ruined
					is_megastructure_type = dyson_gun_0_restored


					#Gateway+Hyper relay is omitted on purpose
					#deepspace Citadel, shroud_seal, lgate, habitat_central_complex_ruined, habitat_central_complex_restored  is omitted on purpose?
				}
			}
		}
	}
}

# this = country; true if it owns (regular) or has a waystation co-located with an L-Gate
owns_lgate_megastructure = {
	OR = {
		any_owned_megastructure = { is_megastructure_type = lgate_base }
		any_owned_nonprimary_starbase = {
			is_waystation_starbase = yes
			solar_system = {
				any_system_megastructure = { is_megastructure_type = lgate_base }
			}
		}
	}
}

system_has_dyson_sphere = {
	solar_system = {
		any_system_megastructure = {
			OR = {
				is_megastructure_type = dyson_sphere_0
				is_megastructure_type = dyson_sphere_1
				is_megastructure_type = dyson_sphere_2
				is_megastructure_type = dyson_sphere_3
				is_megastructure_type = dyson_sphere_4
				is_megastructure_type = dyson_sphere_5
				is_megastructure_type = dyson_sphere_ruined
				is_megastructure_type = dyson_sphere_restored
			}
		}
	}
}

is_homicidal = {
	OR = {
		has_valid_civic = civic_fanatic_purifiers
		has_valid_civic = civic_machine_terminator
		has_valid_civic = civic_hive_devouring_swarm
		has_valid_civic = civic_scorched_earth
		has_valid_civic = civic_hive_scorched_earth
		has_menace_perk = menp_behemoth_ever_hungry
	}
}

is_unfriendly = {
	OR = {
		has_valid_civic = civic_fanatic_purifiers
		has_valid_civic = civic_machine_terminator
		has_valid_civic = civic_hive_devouring_swarm
		has_valid_civic = civic_barbaric_despoilers
		has_valid_civic = civic_scorched_earth
		has_valid_civic = civic_hive_scorched_earth
	}
}

is_slaver = {
	OR = {
		has_valid_civic = civic_barbaric_despoilers
		has_ascension_perk = ap_nihilistic_acquisition
	}
}

is_diplomatic = {
	is_homicidal = no
	NOT = { has_valid_civic = civic_inwards_perfection }
}

# country scope | see 'triggered_opinion_xenophage'
is_xenophage = {
	OR = {
		allows_purge = yes
		allows_slavery = yes
	}
	any_owned_species = {
		is_sapient = yes
		OR = {
			AND = {
				has_citizenship_type = { country = prev type = citizenship_slavery }
				OR = {
					has_slavery_type = { country = prev type = slavery_livestock }
					has_slavery_type = { country = prev type = slavery_matrix }
				}
			}
			AND = {
				OR = {
					has_citizenship_type = { country = prev type = citizenship_purge_machine }
					has_citizenship_type = { country = prev type = citizenship_purge }
				}
				OR = {
					has_purge_type = { country = prev type = purge_processing }
					has_purge_type = { country = prev type = purge_matrix }
				}
			}
		}
	}
}

has_active_xuracorp_trade = {
	OR = {
		has_modifier = enclave_trade_1_xur
		has_modifier = enclave_trade_2_xur
		has_modifier = enclave_trade_3_xur
		has_modifier = enclave_trade_4_xur
		has_modifier = enclave_trade_5_xur
	}
}

has_active_riggan_trade = {
	OR = {
		has_modifier = enclave_trade_1_rig
		has_modifier = enclave_trade_2_rig
		has_modifier = enclave_trade_3_rig
		has_modifier = enclave_trade_4_rig
		has_modifier = enclave_trade_5_rig
	}
}

has_active_muutagan_trade = {
	OR = {
		has_modifier = enclave_trade_1_mut
		has_modifier = enclave_trade_2_mut
		has_modifier = enclave_trade_3_mut
		has_modifier = enclave_trade_4_mut
		has_modifier = enclave_trade_5_mut
	}
}


has_distar = {
	host_has_dlc = "Distant Stars Story Pack"
}

#########################################
# Planetary body triggers (planet scope)
#########################################

is_wet = {
	has_climate = wet
}

is_dry = {
	has_climate = dry
	NOR = {
		is_planet_class = pc_city
		is_planet_class = pc_relic
	}
}

is_barren = {
	OR = {
		is_planet_class = pc_barren
		is_planet_class = pc_barren_cold
		is_planet_class = pc_asteroid
	}
}

is_cold = {
	has_climate = cold
}

can_have_mineral_deposits = {
	OR = {
		is_planet_class = pc_asteroid
		is_planet_class = pc_molten
		is_planet_class = pc_toxic
		is_planet_class = pc_frozen
		is_planet_class = pc_barren
		is_planet_class = pc_barren_cold
		is_planet_class = pc_broken
		is_planet_class = pc_shattered
		is_planet_class = pc_shattered_2
		is_planet_class = pc_junk
	}
}

can_have_energy_deposits = {
	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
		is_planet_class = pc_m_giant_star
		is_planet_class = pc_t_star
		is_planet_class = pc_gas_giant
		is_planet_class = pc_molten
		is_planet_class = pc_ice_asteroid
	}
}

can_have_society_deposits = {
	OR = {
		is_planet_class = pc_toxic
		is_planet_class = pc_shrouded
		is_planet_class = pc_gas_giant
	}
}

can_have_minor_physics_deposits = {
	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
		is_planet_class = pc_m_giant_star
		is_planet_class = pc_t_star
	}
}

can_have_physics_deposits = {
	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
		is_planet_class = pc_m_giant_star
		is_planet_class = pc_t_star
		is_planet_class = pc_protostar
		is_planet_class = pc_neutron_star
		is_planet_class = pc_pulsar
		is_planet_class = pc_black_hole
		has_planet_flag = can_have_physics_deposits
	}
}

can_have_minor_engineering_deposits = {
	OR = {
		is_planet_class = pc_frozen
		is_planet_class = pc_gas_giant
	}
}

can_have_engineering_deposits = {
	OR = {
		is_planet_class = pc_frozen
		is_planet_class = pc_gas_giant
		is_planet_class = pc_protostar
		is_planet_class = pc_neutron_star
		is_planet_class = pc_pulsar
		is_planet_class = pc_black_hole
	}
}

can_have_trade_deposits = {
	OR = {
		is_planet_class = pc_gas_giant
		is_planet_class = pc_molten
		is_planet_class = pc_toxic
		is_asteroid = yes
	}
}

can_have_volatile_motes_deposits = {
	OR = {
		is_planet_class = pc_molten
		is_planet_class = pc_asteroid
		is_planet_class = pc_toxoid_star
	}
}

can_have_rare_crystals_deposits = {
	OR = {
		is_planet_class = pc_frozen
		is_planet_class = pc_ice_asteroid
		is_planet_class = pc_rare_crystal_asteroid
		is_planet_class = pc_crystal_asteroid
	}
}

can_have_exotic_gases_deposits = {
	OR = {
		is_planet_class = pc_gas_giant
		is_planet_class = pc_toxic
		is_planet_class = pc_ice_asteroid
		is_planet_class = pc_toxoid_star
	}
}

can_have_alloys_deposits = {
	OR = {
		is_planet_class = pc_asteroid
		is_planet_class = pc_molten
		is_planet_class = pc_junk
		is_planet_class = pc_broken
		is_planet_class = pc_shattered
		is_planet_class = pc_shattered_2
	}
}

can_have_zro_deposits = {
	OR = {
		is_planet_class = pc_toxic
		is_planet_class = pc_shrouded
	}
}

can_have_food_deposits = {
	OR = {
		is_planet_class = pc_ice_asteroid
		is_planet_class = pc_frozen
		is_planet_class = pc_gas_giant
	}
}

can_have_dark_matter_deposits = {
	is_planet_class = pc_black_hole
}

is_fallen_empire = {
	OR = {
		is_country_type = fallen_empire
		is_country_type = awakened_fallen_empire
	}
}

is_marauder_clans = {
	OR = {
		is_country_type = dormant_marauders
		is_country_type = awakened_marauders
		is_country_type = ruined_marauders
	}
}

has_galactic_wonders = {
	OR = {
		has_ascension_perk = ap_galactic_wonders
		has_ascension_perk = ap_galactic_wonders_utopia
		has_ascension_perk = ap_galactic_wonders_megacorp
		has_ascension_perk = ap_galactic_wonders_utopia_and_megacorp
	}
}

can_build_megastructures = {
	OR = {
		has_technology = tech_gateway_construction
		has_technology = tech_ring_world
		has_technology = tech_orbital_ring_tier_1
		has_technology = tech_hyper_relays
		has_technology = tech_quantum_catapult
		has_technology = tech_cosmogenesis_world
		can_build_unity_megastructures = yes
	}
}

can_build_unity_megastructures = {
	OR = {
		has_technology = tech_science_nexus
		has_technology = tech_sentry_array
		has_technology = tech_strategic_coordination
		has_technology = tech_interstellar_assembly
		has_technology = tech_mega_art
		has_technology = tech_dyson_sphere
		has_technology = tech_matter_decompressor
		has_technology = tech_mega_shipyard
		has_technology = tech_orbital_arc_furnace
		has_technology = tech_dyson_swarm
		has_technology = tech_deep_space_citadel
	}
}

can_build_fallen_empire_buildings = {
	OR = {
		is_fallen_empire = yes
		has_country_flag = affluence_emporium_can_build
		has_country_flag = nourishment_complex_can_build
		has_country_flag = dimensional_replicator_can_build
		has_country_flag = class_3_singularity_can_build
		has_country_flag = micro_forge_can_build
		has_country_flag = fe_sky_dome_can_build
		has_country_flag = fe_fortress_can_build
		has_country_flag = fe_administration_1_can_build
		has_country_flag = fe_administration_hive_1_can_build
		has_country_flag = fe_administration_machine_1_can_build
		has_country_flag = fe_assembly_1_can_build
		has_country_flag = affluence_center_can_build
		has_country_flag = fe_clinic_1_can_build
		has_country_flag = fe_security_1_can_build
		has_country_flag = fe_market_1_can_build
		has_country_flag = fe_silo_1_can_build
		has_country_flag = fe_entertainment_1_can_build
		has_country_flag = fe_lab_1_can_build
		has_country_flag = fe_mine_1_can_build
		has_country_flag = nano_forge_can_build
		has_country_flag = skydome_can_build
		has_country_flag = dimensional_fabricator_can_build
		has_country_flag = affluence_center_can_build
		has_country_flag = nourishment_center_can_build
		has_country_flag = class_4_singularity_can_build
		has_technology = tech_fe_affluence_1
		has_technology = tech_fe_nourishment_1
		has_technology = tech_fe_fabricator_1
		has_technology = tech_fe_singularity_1
		has_technology = tech_fe_forge_1
		has_technology = tech_fe_dome_1
		has_technology = tech_fe_fortress_1
		has_technology = tech_fe_administration_1
		has_technology = tech_fe_assembly_1
		has_technology = tech_fe_clinic_1
		has_technology = tech_fe_security_1
		has_technology = tech_fe_market_1
		has_technology = tech_fe_silo_1
		has_technology = tech_fe_entertainment_1
		has_technology = tech_fe_lab_1
		has_technology = tech_fe_mine_1
	}
}

has_gw_ring_world = {
	OR = {
		has_ascension_perk = ap_galactic_wonders
		has_ascension_perk = ap_galactic_wonders_utopia
		has_ascension_perk = ap_galactic_wonders_utopia_and_megacorp
	}
}

has_gw_dyson_sphere = {
	OR = {
		has_ascension_perk = ap_galactic_wonders
		has_ascension_perk = ap_galactic_wonders_utopia
		has_ascension_perk = ap_galactic_wonders_utopia_and_megacorp
	}
}

has_gw_think_tank = {
	has_technology = tech_science_nexus
}

has_gw_spy_orb = {
	has_technology = tech_sentry_array
}

has_gw_matter_decompressor = {
	OR = {
		has_ascension_perk = ap_galactic_wonders
		has_ascension_perk = ap_galactic_wonders_megacorp
		has_ascension_perk = ap_galactic_wonders_utopia_and_megacorp
	}
}

has_gw_strategic_coordination_center = {
	has_technology = tech_strategic_coordination
}

has_gw_mega_art_installation = {
	has_technology = tech_mega_art
}

has_gw_interstellar_assembly = {
	has_technology = tech_interstellar_assembly
}

can_generate_trade_value = {
	exists = owner
	owner = { is_country_type = default }
}

# is_crossbreeding_possible - this is referenced by code. Do not rename the scripted trigger
is_crossbreeding_possible = {
	is_sapient = yes
	NOR = {
		has_trait = trait_machine_unit
		has_trait = trait_mechanical
		has_trait = trait_hive_mind
		has_trait = trait_self_modified
		has_trait = trait_clone_soldier_infertile
		has_trait = trait_clone_soldier_infertile_full_potential
	}
}

has_ancrel = {
	host_has_dlc = "Ancient Relics Story Pack"
}

simulation_1_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 4
	}
}

research_lab_1_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 4
	}
	OR = {
		AND = {
			is_hive_empire = yes
			has_monthly_income = {
				resource = minerals
				value > 12
			}
		}
		AND = {
			is_machine_empire = yes
			has_monthly_income = {
				resource = minerals
				value > 12
			}
		}
		AND = {
			is_regular_empire = yes
			has_monthly_income = {
				resource = consumer_goods
				value > 4
			}
		}
	}
}

foundry_1_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 4
	}
	has_monthly_income = {
		resource = volatile_motes
		value >= 1
	}
}

autochthon_monument_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 1
	}

	is_regular_empire = yes
	has_monthly_income = {
		resource = consumer_goods
		value > 4
	}
}

organic_sanctuary_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

holo_theatres_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
	OR = {
		AND = {
			has_valid_civic = civic_warrior_culture
			has_monthly_income = {
				resource = alloys
				value > 2
			}
		}
		AND = {
			NOT = { has_valid_civic = civic_warrior_culture }
			has_monthly_income = {
				resource = consumer_goods
				value > 2
			}
		}
	}
}

galactic_stock_exchange_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
}

robot_assembly_plant_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
	has_monthly_income = {
		resource = minerals
		value > 6
	}
}

precinct_house_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

clinic_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
	has_monthly_income = {
		resource = consumer_goods
		value > 2
	}
}

ministry_production_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
}

psi_corps_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
}

institute_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
}

machine_assembly_plant_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
	has_monthly_income = {
		resource = minerals
		value > 3
	}
}

maintenance_depot_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 1
	}
}

sentinel_posts_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

production_center_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
	OR = {
		AND = {
			is_hive_empire = yes
			has_monthly_income = {
				resource = food
				value > 2
			}
			has_monthly_income = {
				resource = energy
				value > 7	# building upkeep + 2
			}
		}
		AND = {
			is_machine_empire = yes
			has_monthly_income = {
				resource = energy
				value > 8	# building upkeep + 3
			}
		}
		AND = {
			is_regular_empire = yes
			always = yes
		}
	}
}

hive_node_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
	has_monthly_income = {
		resource = food
		value > 4
	}
}

uplink_node_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
	has_monthly_income = {
		resource = minerals
		value > 4
	}
}

food_processing_facility_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

luxury_residence_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

chemical_plant_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 3
	}
	# Both the regular job and gestalt job has the same upkeep
	has_monthly_income = {
		resource = minerals
		value > 10
	}
}

refinery_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 3
	}
	# Both the regular job and gestalt job has the same upkeep
	has_monthly_income = {
		resource = minerals
		value > 10
	}
}

crystal_plant_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 3
	}
	# Both the regular job and gestalt job has the same upkeep
	has_monthly_income = {
		resource = minerals
		value > 10
	}
}

bureaucracy_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

commercial_zone_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

spawning_pool_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
	has_monthly_income = {
		resource = food
		value > 5
	}
}

hive_warren_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

resource_silo_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 1
	}
}

energy_grid_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 1
	}
}

drone_storage_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

stronghold_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 1
	}
}

planetary_shield_generator_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
}

supercomputer_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 5
	}
	has_monthly_income = {
		resource = minerals
		value > 6
	}
}

mineral_purification_plant_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 1
	}
}

overseer_homes_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 1
	}
}

slave_huts_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 1
	}
}

hydroponics_farm_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

slave_processing_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

temple_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > 2
	}
}

embassy_upkeep_affordable = {
	has_monthly_income = {
		resource = energy
		value > @b2_upkeep
	}
	has_monthly_income = {
		resource = rare_crystals
		value >= @b2_rare_upkeep
	}
}

is_special_colony_type = {
	OR = {
		has_modifier = penal_colony
		has_modifier = resort_colony
		has_modifier = slave_colony
	}
}

scion_has_techs = {
	OR = {
		has_technology = tech_alloys_1
		NOT = { can_research_technology = tech_alloys_1 }
	}
	OR = {
		has_technology = tech_mineral_purification_2
		NOT = { can_research_technology = tech_mineral_purification_2 }
	}
	OR = {
		has_technology = tech_space_defense_station_improvement
		NOT = { can_research_technology = tech_space_defense_station_improvement }
	}
	OR = {
		has_technology = tech_battleships
		NOT = { can_research_technology = tech_battleships }
	}
	OR = {
		has_technology = tech_titan_hull_1
		NOT = { can_research_technology = tech_titan_hull_1 }
	}
	OR = {
		has_technology = tech_space_science_2
		NOT = { can_research_technology = tech_space_science_2 }
	}
	OR = {
		has_technology = tech_self_aware_logic
		NOT = { can_research_technology = tech_self_aware_logic }
	}
	OR = {
		has_technology = tech_antimatter_power
		NOT = { can_research_technology = tech_antimatter_power }
	}
	OR = {
		has_technology = tech_combat_computers_autonomous
		NOT = { can_research_technology = tech_combat_computers_autonomous }
	}
	OR = {
		has_technology = tech_jump_drive_1
		NOT = { can_research_technology = tech_jump_drive_1 }
	}
	OR = {
		has_technology = tech_eco_simulation
		NOT = { can_research_technology = tech_eco_simulation }
	}
	OR = {
		has_technology = tech_colonization_4
		NOT = { can_research_technology = tech_colonization_4 }
	}
	OR = {
		has_technology = tech_climate_restoration
		NOT = { can_research_technology = tech_climate_restoration }
	}
	OR = {
		has_technology = tech_ascension_theory
		NOT = { can_research_technology = tech_ascension_theory }
	}
}

# Country scope
has_precursor_intro = {
	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
		# Still in the early stages of 'On the Shoulders of Giants'
		AND = {
			has_origin = origin_shoulders_of_giants
			NOT = { has_country_flag = origin_shoulders_closure }
		}
	}
}

baol_colony_1_trigger = {
	has_access_fleet = root.owner
	is_capital_system = no
	NOR = {
		is_same_value = root.solar_system
		has_star_flag = first_grunur_site@root.owner
		has_star_flag = grunur_site@root.owner
		has_star_flag = sol_system
		is_star_class = sc_black_hole
	}
	OR = {
		has_owner = no
		owner = { is_same_value = root.owner }
	}
	any_system_planet = {
		is_planet_class = pc_barren
		has_anomaly = no
		NOT = { exists = archaeological_site }
		NOT = { has_planet_flag = suppress_archaeological_sites }
	}
}

baol_colony_2_trigger = {
	has_access_fleet = root.owner
	is_capital_system = no
	NOR = {
		is_same_value = root.solar_system
		has_star_flag = first_grunur_site@root.owner
		has_star_flag = grunur_site@root.owner
		has_star_flag = sol_system
		is_star_class = sc_black_hole
	}
	OR = {
		has_owner = no
		owner = { is_same_value = root.owner }
	}
	any_system_planet = {
		is_planet_class = pc_asteroid
		has_anomaly = no
		NOT = { exists = archaeological_site }
		NOT = { has_planet_flag = suppress_archaeological_sites }
	}
}

baol_colony_3_trigger = {
	has_access_fleet = root.owner
	is_capital_system = no
	NOR = {
		is_same_value = root.solar_system
		has_star_flag = first_grunur_site@root.owner
		has_star_flag = sol_system
		is_star_class = sc_black_hole
	}
	OR = {
		has_owner = no
		owner = { is_same_value = root.owner }
	}
	any_system_planet = {
		habitable_planet = yes
		is_urban_planet = no
		has_anomaly = no
		NOR = {
			exists = archaeological_site
			has_carrier_flag = colony_event
			has_planet_flag = suppress_archaeological_sites
		}
		OR = {
			is_colony = no
			sapient_pop_amount < 1000
		}
	}
}

baol_colony_3_fallback_trigger = {
	is_capital_system = no
	NOR = {
		is_same_value = root.solar_system
		has_star_flag = first_grunur_site@root.owner
		has_star_flag = grunur_site@root.owner
		has_star_flag = sol_system
		is_star_class = sc_black_hole
	}
	any_system_planet = {
		habitable_planet = yes
		is_urban_planet = no
		has_anomaly = no
		NOR = {
			exists = archaeological_site
			has_carrier_flag = colony_event
			has_planet_flag = suppress_archaeological_sites
		}
		OR = {
			is_colony = no
			sapient_pop_amount < 1000
		}
	}
}


lithoids_portrait = {
	OR = {
		species_portrait = lith1
		species_portrait = lith2
		species_portrait = lith3
		species_portrait = lith4
		species_portrait = lith5
		species_portrait = lith6
		species_portrait = lith7
		species_portrait = lith8
		species_portrait = lith9
		species_portrait = lith10
		species_portrait = lith11
		species_portrait = lith12
		species_portrait = lith13
		species_portrait = lith14
		species_portrait = lith15
	}
}

necroids_portrait = { #To establish default rooms and VO weights
	OR = {
		species_portrait = nec1
		species_portrait = nec2
		species_portrait = nec3
		species_portrait = nec4
		species_portrait = nec5
		species_portrait = nec6
		species_portrait = nec7
		species_portrait = nec8
		species_portrait = nec9
		species_portrait = nec10
		species_portrait = nec11
		species_portrait = nec12
		species_portrait = nec13
		species_portrait = nec14
		species_portrait = nec15
		species_portrait = season_10_portrait
	}
}

aquatics_portrait = { #To establish default rooms and VO weights
	OR = {
		species_portrait = aqu1
		species_portrait = aqu2
		species_portrait = aqu3
		species_portrait = aqu4
		species_portrait = aqu5
		species_portrait = aqu6
		species_portrait = aqu7
		species_portrait = aqu8
		species_portrait = aqu9
		species_portrait = aqu10
		species_portrait = aqu11
		species_portrait = aqu12
		species_portrait = aqu13
		species_portrait = aqu14
		species_portrait = aqu15
	}
}

toxoids_portrait = { #To establish default rooms and VO weights
	OR = {
		species_portrait = tox1
		species_portrait = tox2
		species_portrait = tox3
		species_portrait = tox4
		species_portrait = tox5
		species_portrait = tox6
		species_portrait = tox7
		species_portrait = tox8
		species_portrait = tox9
		species_portrait = tox10
		species_portrait = tox11
		species_portrait = tox12
		species_portrait = tox13
		species_portrait = tox14
		species_portrait = tox15
	}
}

cybernetic_portrait = { #To establish default rooms and VO weights
	OR = {
		species_portrait = cyb1
		species_portrait = cyb2
		species_portrait = cyb3
		species_portrait = cyb4
		species_portrait = cyb5
		species_portrait = cyb6
		species_portrait = cyb7
		species_portrait = cyb8
		species_portrait = cyb9
		species_portrait = cyb10
		species_portrait = cyb11
		species_portrait = cyb12
		species_portrait = cyb13
	}
}

synthetic_portrait = { #To establish default rooms and VO weights
	OR = {
		species_portrait = synth01
		species_portrait = synth02
		species_portrait = synth03
		species_portrait = synth04
		species_portrait = synth05
		species_portrait = synth06
		species_portrait = synth07
		species_portrait = synth08
		species_portrait = synth09
	}
}

is_owner_ethic_pop_faction = {
	switch = {
		trigger = is_pop_faction_type
		prosperity = {
			owner = { is_pacifist = yes }
		}
		progressive = {
			owner = { is_egalitarian = yes }
		}
		imperialist = {
			owner = { is_militarist = yes }
		}
		isolationist = {
			owner = { is_xenophobe = yes }
		}
		supremacist = {
			owner = { is_xenophobe = yes }
		}
		technologist = {
			owner = { is_materialist = yes }
		}
		totalitarian = {
			owner = { is_authoritarian = yes }
		}
		traditionalist = {
			owner = { is_spiritualist = yes }
		}
		xenoist = {
			owner = { is_xenophile = yes }
		}
		default = {
			always = yes
		}
	}
}

#species scope, prev has to be either country or something with an owner
species_can_be_necrophaged = {
	NOR = {
		is_archetype = MACHINE
		is_archetype = ROBOT
		is_archetype = PRESAPIENT
		is_same_species = prev.owner_species
		AND = {
			has_slavery_type = { type = slavery_livestock country = prev.owner }
			prev.owner = { is_hive_empire = no }
		}
		has_citizenship_type = { type = citizenship_purge country = prev.owner }
	}
	species_has_happiness_with_owner = prev.owner
}

is_amoeba_country_type = {
	OR = {
		is_country_type = amoeba
		is_country_type = amoeba_borderless
		is_country_type = amoeba_garrison
		is_country_type = amoeba_faction
	}
}

is_tiyanki_country_type = {
	OR = {
		is_country_type = tiyanki
		is_country_type = tiyanki_garrison
	}
}

is_crystal_country_type = {
	OR = {
		is_country_type = crystal
		is_country_type = crystal_faction
	}
}

is_drone_country_type = {
	OR = {
		is_country_type = drone
		is_country_type = drone_faction
	}
}

is_voidworms_country_type = {
	OR = {
		is_country_type = voidworms
		is_country_type = voidworms_crisis
		is_country_type = voidworms_treasure_hunters
	}
}

is_voidworms_hostile_country_type = {
	OR = {
		is_country_type = voidworms
		is_country_type = voidworms_crisis
	}
}

is_cutholoids_country_type = {
	is_country_type = cutholoids
}

is_capturable_space_critter_country_type = {
	OR = {
		is_tiyanki_country_type = yes
		is_amoeba_country_type = yes
		is_crystal_country_type = yes
		is_voidworms_country_type = yes
		is_cutholoids_country_type = yes
	}
}

is_pacified_space_critter_country_type = {
	OR = {
		is_country_type = tiyanki
		AND = {
			OR = {
				is_country_type = amoeba
				is_country_type = amoeba_borderless
			}
			root = { has_country_flag = pacified_amoebas }
		}
		AND = {
			is_country_type = crystal
			root = { has_country_flag = pacified_crystals }
		}
	}
}

#solar_system scope
is_valid_drone_expansion_destination_system = {
	NOR = {
		is_star_class = sc_black_hole
		has_star_flag = mining_drone_expansion_starting_system
		has_star_flag = aggressive_drone_expansion_starting_system
		has_star_flag = mining_drone_expansion_destination_system
		has_star_flag = aggressive_drone_expansion_destination_system
		has_star_flag = hostile_system
		has_star_flag = guardian
		has_star_flag = tiyanki_home_system
		has_star_flag = tiyanki_graveyard_system
		has_star_flag = amoeba_home_system
		has_star_flag = lcluster
		has_star_flag = sealed_system
		has_star_flag = voidworms_system
		has_star_flag = frenzied_voidworms_system
	}
	any_system_planet = {
		can_have_mineral_deposits = yes
	}
}

#solar_system scope
is_valid_crystal_splitter_system = {
	NOR = {
		exists = starbase
		is_star_class = sc_black_hole
		has_star_flag = crystal_splitter_starting_system
		has_star_flag = crystal_splitter_destination_system
		has_star_flag = hostile_system
		has_star_flag = guardian
		has_star_flag = tiyanki_home_system
		has_star_flag = tiyanki_graveyard_system
		has_star_flag = amoeba_home_system
		has_star_flag = lcluster
		has_star_flag = sealed_system
		has_star_flag = fruitful_colonization
		has_star_flag = voidworms_system
		has_star_flag = frenzied_voidworms_system
	}
	any_system_planet = { is_asteroid = yes }
}


separatism_joining_eligibility_trigger = {
	if = {
		limit = {
			$SPECIES$ = { has_trait = trait_hive_mind }
		}
		is_hive_empire = yes
	}
	else_if = {
		limit = {
			$SPECIES$ = { has_trait = trait_machine_unit }
		}
		is_machine_empire = yes
	}
	else = {
		is_regular_empire = yes
		OR = {
			is_same_species = $SPECIES$
			AND = {
				$SITUATION$ = { has_situation_flag = slave_revolt }
				is_fanatic_egalitarian = yes
			}
		}
	}
	NOT = { is_same_value = $SITUATION$.owner }
	is_subject = no
	NOR = {
		is_in_federation_with = $SITUATION$.owner
		has_defensive_pact = $SITUATION$.owner
		has_non_aggression_pact = $SITUATION$.owner
	}
	has_communications = $SITUATION$.owner
	is_country_type = default
}

default_endgame_early_start_triggers = {
	OR = {
		NOT = {
			any_country = {
				OR = {
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
			}
		}
		has_global_flag = no_war_in_heaven
		AND = {
			has_global_flag = war_in_heaven_started
			OR = {
				has_global_flag = war_in_heaven_ended
				NOT = { has_global_flag = war_in_heaven_recently_started }
			}
		}
	}
}

should_ai_focus_on_trade = {
	is_ai = yes
	OR = {
		has_ai_personality = peaceful_traders
		has_ai_personality = ruthless_capitalists
	}
	owner_main_species = {
		OR = {
			has_trait = "trait_thrifty"
			has_trait = "trait_cyborg_trading_algorithms"
			has_trait = "trait_robot_trading_algorithms"
		}
	}
}

valid_curators_intel_trade_target = {
	is_country_type = default
	NOR = {
		is_same_value = root
		AND = {
			exists = event_target:curator_customer_1
			is_same_value = event_target:curator_customer_1
		}
		AND = {
			exists = event_target:curator_customer_2
			is_same_value = event_target:curator_customer_2
		}
		AND = {
			exists = event_target:curator_customer_3
			is_same_value = event_target:curator_customer_3
		}
	}
	root = {
		has_communications = prev
		NOR = {
			intel = { who = prev value = 100 }
			has_relation_flag = {
				who = prev
				flag = curator_bought_intel_on
			}
		}
	}
	OR = { # AI doesn't use Curators, but players can get protection against this by not using them
		AND = {
			is_ai = yes
			has_communications = event_target:curator_enclave_country
			OR = {
				is_galactic_community_member = yes
				any_system_within_border = {
					any_fleet_in_system = {
						is_owned_by = event_target:curator_enclave_country
					}
				}
			}
		}
		event_target:curator_enclave_country = {
			trust = {
				who = prev
				value >= 50
			}
		}
	}
}

normal_shroud_message = {
	NOR = {
		has_country_flag = shroud_intro
		any_playable_country = { has_country_flag = building_crisis_sphere }
	}
}

crisis_shroud_message = {
	NOT = { has_country_flag = shroud_intro }
	any_playable_country = { has_country_flag = building_crisis_sphere }
}

no_resource_for_component = {
	is_country_type = default
	if = {
		limit = {
			AND = {
				is_ai = no
				resource_stockpile_compare = {
					resource = $RESOURCE$
					value > 100000		# instant_build sets storage limit to 1000000, so we'll check for 10% of that
				}
			}
		}
		always = no
	}
	else_if = {
		# Nomads acquire strategic resources via harvesting, not monthly income.
		# Block the component only when the stockpile is too low to afford it.
		limit = {
			is_ai = yes
			is_nomadic = yes
		}
		resource_stockpile_compare = {
			resource = $RESOURCE$
			value < @ai_component_strategic_stockpile_min
		}
	}
	else = {
		OR = {
			NOT = {
				can_buy_on_market = $RESOURCE$ #i.e. has galactic market or positive income
			}
			AND = {
				is_ai = yes
				has_monthly_income = {
					resource = $RESOURCE$
					value < -2 #Reflexes to buy more tend to only kick in when below 0
				}
				resource_stockpile_compare = {
					resource = $RESOURCE$
					value < @ai_component_strategic_stockpile_min
				}
			}
		}
	}
}

# This = country, From = planet
should_terraform_trigger = {
	ideal_planet_class = $CLASS_TO$ #Technically not needed because the AI will pick the one with the highest habitability
									#Still useful as an early out, though.
	is_lithoid = no
	is_mechanical_empire = no
	is_cyborg_empire = no
	from = {
		OR = {
			is_colony = no
			AND = {
				any_owned_species = {
					ideal_planet_class = $CLASS_TO$
					is_sapient = yes
				}
				NOT = {
					any_owned_species = {
						ideal_planet_class = $CLASS_FROM$
						is_sapient = yes
					}
				}
			}
		}
	}
}

has_been_declared_crisis = {
	OR = {
		has_country_flag = declared_crisis
		has_crisis_level = crisis_level_5
	}
}

is_non_ruined_crisis_sphere = {
	OR = {
		is_megastructure_type = crisis_sphere_0
		is_megastructure_type = crisis_sphere_1
		is_megastructure_type = crisis_sphere_2
		is_megastructure_type = crisis_sphere_3
		is_megastructure_type = crisis_sphere_4
	}
}

is_crisis_sphere = {
	OR = {
		is_megastructure_type = crisis_sphere_0
		is_megastructure_type = crisis_sphere_1
		is_megastructure_type = crisis_sphere_2
		is_megastructure_type = crisis_sphere_3
		is_megastructure_type = crisis_sphere_4
		is_megastructure_type = crisis_sphere_ruined
	}
}

is_low_tech_start = {
	OR = {
		is_primitive = yes
		has_origin = origin_broken_shackles
		has_origin = origin_payback
		is_eager_explorer_empire = yes
	}
}

is_eager_explorer_empire = {
	OR = {
		has_civic = civic_eager_explorers
		has_civic = civic_privatized_exploration
		has_civic = civic_hive_stargazers
		has_civic = civic_machine_exploration_protocol
	}
}

is_pleasure_seeker_empire = {
	OR = {
		has_valid_civic = civic_pleasure_seekers
		has_valid_civic = civic_corporate_hedonism
	}
}

# scope: pop group
has_decadent_hedonist_growth = {
	exists = owner
	has_living_standard = {
		type = living_standard_decadent
	}
	NOT = {
		owner? = {
			has_deficit = consumer_goods
		}
	}
	planet = {
		free_housing > 0
		free_amenities > 0
	}
}

is_crafter_empire = {
	OR = {
		has_valid_civic = civic_crafters
		has_valid_civic = civic_corporate_crafters
	}
}

is_anglers_empire = {
	OR = {
		has_valid_civic = civic_anglers
		has_valid_civic = civic_corporate_anglers
		has_valid_civic = civic_machine_anglers
		has_valid_civic = civic_corporate_machine_anglers
	}
}

is_catalytic_empire = {
	OR = {
		has_valid_civic = civic_catalytic_processing
		has_valid_civic = civic_corporate_catalytic_processing
		has_valid_civic = civic_hive_catalytic_processing
		has_valid_civic = civic_machine_catalytic_processing
	}
}

is_curator_empire = {
	OR = {
		has_valid_civic = civic_galactic_curators
		has_valid_civic = civic_corporate_galactic_curators
		has_valid_civic = civic_hive_galactic_curators
		has_valid_civic = civic_machine_galactic_curators
	}
}

is_crowdsourcing_empire = {
	OR = {
		has_valid_civic = civic_crowdsourcing
		has_valid_civic = civic_corporate_crowdsourcing
	}
}

is_crusader_empire = {
	OR = {
		has_valid_civic = civic_crusader_spirit
		has_valid_civic = civic_crusader_spirit_corporate
	}
}

is_idyllic_bloom_empire = {
	OR = {
		has_valid_civic = civic_idyllic_bloom
		has_valid_civic = civic_hive_idyllic_bloom
		has_valid_civic = civic_life_seeded
	}
}

is_death_cult_empire = {
	OR = {
		has_valid_civic = civic_death_cult
		has_valid_civic = civic_death_cult_corporate
	}
}

is_worker_coop_empire = {
	has_valid_civic = civic_worker_coop
}

is_subterranean_empire = {
	OR = {
		has_origin = origin_subterranean
		has_origin = origin_subterranean_machines
	}
}

overlord_subject_event_trigger = {
	exists = event_target:overlord_empire
	exists = event_target:subject_empire
	event_target:overlord_empire = {
		is_overlord_to = event_target:subject_empire
	}
}

subject_pacifist_overlord_opposing = {
	is_pacifist = yes
	overlord = { is_militarist = yes }
}

subject_militarist_overlord_opposing = {
	is_militarist = yes
	overlord = { is_pacifist = yes }
}

subject_authoritarian_overlord_opposing = {
	is_authoritarian = yes
	overlord = { is_egalitarian = yes }
}

subject_egalitarian_overlord_opposing = {
	is_egalitarian = yes
	overlord = { is_authoritarian = yes }
}

subject_materialist_overlord_opposing = {
	is_materialist = yes
	overlord = { is_spiritualist = yes }
}

subject_spiritualist_overlord_opposing = {
	is_spiritualist = yes
	overlord = { is_materialist = yes }
}

subject_xenophile_overlord_opposing = {
	is_xenophile = yes
	overlord = { is_xenophobe = yes }
}

subject_xenophobe_overlord_opposing = {
	is_xenophobe = yes
	overlord = { is_xenophile = yes }
}

subject_overlord_opposing_ethics = {
	OR = {
		subject_pacifist_overlord_opposing = yes
		subject_militarist_overlord_opposing = yes
		subject_authoritarian_overlord_opposing = yes
		subject_egalitarian_overlord_opposing = yes
		subject_materialist_overlord_opposing = yes
		subject_spiritualist_overlord_opposing = yes
		subject_xenophile_overlord_opposing = yes
		subject_xenophobe_overlord_opposing = yes
	}
}

has_research_building = {
	OR = {
		has_building = building_research_lab_1
		has_building = building_research_lab_2
		has_building = building_research_lab_3
		has_building = building_institute
		has_building = building_supercomputer
		has_building = building_astrometeorology_observation_center
	}
}

is_orbital_ring = {
	has_starbase_size >= orbital_ring_tier_1
}

is_normal_starbase = {
	has_starbase_size >= starbase_outpost
}

is_faction_allowed = {
	OR = {
		AND = {
			years_passed > 10
			has_encountered_other_species = yes
		}
		AND = {
			days_passed > 30
			OR = {
				has_valid_civic = civic_parliamentary_system
				has_valid_civic = civic_media_conglomerate
				has_valid_civic = civic_crowdsourcing
				has_valid_civic = civic_corporate_crowdsourcing
			}
		}
		AND = {
			days_passed > 350
			OR = {
				has_origin = origin_broken_shackles
				AND = {
					has_origin = origin_unplugged
					has_country_flag = unplugged_faction_allowed
				}
			}
		}
	}
	NOR = {
		has_ethic = ethic_gestalt_consciousness
		has_country_flag = suppress_vanilla_factions
	}
}

has_non_hostile_origin_dragon_trigger = {
	any_system_within_border = {
		has_star_flag = here_be_dragons_system
		any_fleet_in_system = {
			is_ship_size = space_dragon_origin
			owner = {
				has_country_flag = here_be_the_dragon@prevprevprev
				NOT = { is_hostile = prevprevprev }
			}
		}
	}
}

is_dragon_breeder_country = {
	has_country_flag = dragon_breeders
	any_owned_ship = {
		is_ship_size = space_dragon_origin
	}
}

is_dragon = {
	OR = {
		is_ship_size = space_dragon_origin
		is_ship_size = space_dragon_origin_baby
		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
		is_ship_size = reanimated_space_dragon_red
		is_ship_size = reanimated_space_dragon_blue
		is_ship_size = reanimated_space_dragon_origin
	}
}

values_others = {
	AND = {
		OR = {
			is_xenophile = yes
			has_valid_civic = civic_hive_empath
			has_valid_civic = civic_machine_servitor
			has_valid_civic = civic_machine_exploration_protocol
			has_origin = origin_fruitful
			has_animal_handler_job = yes
			has_symbiosis_integrator_job = yes
			has_valid_civic = civic_hive_familiar_face
		}
		NOT = {
			has_menace_perk = menp_behemoth_ever_hungry
		}
	}
}

has_organic_pops = {
	any_owned_species = {
		OR = {
			is_archetype = BIOLOGICAL
			is_archetype = LITHOID
		}
	}
}

is_robotic_or_voidspawn_species = {
	OR = {
		is_robotic = yes
		has_trait = trait_voidling
	}
}

country_has_situation = {
	any_situation = {
		is_situation_type = $SITUATION$
	}
}

#has_deficit will look for deficit situations. This checks negative income and no resources
has_actual_deficit = {
	resource_stockpile_compare = {
		resource = $RESOURCE$
		value = 0
	}
	resource_income_compare = {
		resource = $RESOURCE$
		value < 0
	}
}

has_negative_income_with_stockpile = {
	resource_stockpile_compare = {
		resource = $RESOURCE$
		value > 0
	}
	resource_income_compare = {
		resource = $RESOURCE$
		value < 0
	}
}

is_situation_leviathan_biological = {
	OR = {
		has_situation_flag = celebration_ether_drake
		has_situation_flag = celebration_shard
		has_situation_flag = celebration_tiyanki_matriarch
		has_situation_flag = celebration_void_spawn
		has_situation_flag = celebration_spectral_wraith
		has_situation_flag = celebration_stellar_devourer
		has_situation_flag = celebration_dimensional_horror
		has_situation_flag = celebration_hrozgar
	}
}

can_have_sensory_readings = {
	OR = {
		is_planet_class = pc_asteroid
		is_planet_class = pc_frozen
		is_planet_class = pc_barren
		is_planet_class = pc_barren_cold
		is_planet_class = pc_desert
		is_planet_class = pc_tropical
		is_planet_class = pc_arid
		is_planet_class = pc_continental
		is_planet_class = pc_ocean
		is_planet_class = pc_tundra
		is_planet_class = pc_arctic
		is_planet_class = pc_alpine
		is_planet_class = pc_savannah
		is_planet_class = pc_gaia
		is_planet_class = pc_relic
		is_planet_class = pc_city
	}
}

can_have_resource_discovery = {
	OR = {
		is_planet_class = pc_asteroid
		is_planet_class = pc_ice_asteroid
		is_planet_class = pc_rare_crystal_asteroid
		is_planet_class = pc_crystal_asteroid
		is_planet_class = pc_frozen
		is_planet_class = pc_barren
		is_planet_class = pc_barren_cold
	}
}

is_reanimator = {
	OR = {
		has_valid_civic = civic_reanimated_armies
		has_valid_civic = civic_permanent_employment
		has_valid_civic = civic_hive_cordyceptic_drones
		has_ascension_perk = ap_mechromancy
	}
}

is_memorialist_empire = {
	OR = {
		has_valid_civic = civic_memorialist
		has_valid_civic = civic_hive_memorialist
		has_valid_civic = civic_machine_memorialist
	}
}

is_relentless_industrialist_empire = {
	OR = {
		has_valid_civic = civic_relentless_industrialists
		has_valid_civic = civic_corporate_relentless_industrialists
	}
}

uses_standard_ship_sizes = {
	OR = {
		is_country_type = default
		is_country_type = gdf
		is_mercenary = yes
		is_country_type = exiled
		has_country_flag = use_default_ships #for modders: apply this in on_country_created for new country types that you want to use corvettes etc
	}
	is_beastmasters_empire = no
	country_uses_bio_ships = no
}

uses_fauna_ship_sizes = {
	is_beastmasters_empire = yes
}

#Fleet scope | see also: fleet_can_be_scrapped = {}
is_organic_controllable_ship = {
	OR = {
		is_ship_size = space_amoeba #Lost Amoeba (juvenile)
		is_ship_size = space_amoeba_mother #Adult Amoeba ("Bubbles")
		is_ship_size = space_amoeba_centenarian
		is_ship_size = large_ship_swarm #Brood-Queen relic
		is_ship_size = small_ship_swarm #Brood-Queen relic
		is_ship_size = large_ship_carrier_swarm #Brood-Queen relic
		AND = { # cloned space fauna
			is_space_fauna = yes
			is_reanimated = no
			owner = {
				is_fauna_country = no
			}
		}
		is_ship_category = bio_ship
		#Not currently controllable, but potentially valid:
		# is_ship_size = large_ship_carrier_swarm
		# is_ship_size = queen_swarm
		# Crystal Entities (many)
		# is_ship_size = space_cloud
		# is_ship_size = space_amoeba
		# is_ship_size = space_whale_1
	}
}

is_organic_ship = {
	OR = {
		is_ship_category = bio_ship
		is_ship_category = space_amoeba
		is_ship_category = tiyanki
		is_ship_category = voidworm
		is_ship_category = cutholoid
		is_ship_category = crystalline_entity

		is_reanimated = yes
		is_space_fauna = yes
		is_ship_size = space_amoeba #Lost Amoeba (juvenile)
		is_ship_size = space_amoeba_mother #Adult Amoeba ("Bubbles")
		is_ship_size = space_amoeba_centenarian
		is_ship_size = large_ship_swarm #Brood-Queen relic
		is_ship_size = small_ship_swarm #Brood-Queen relic
		is_ship_size = large_ship_carrier_swarm #Brood-Queen relic
		is_ship_size = large_ship_carrier_swarm
		is_ship_size = queen_swarm
		#Leviathans
		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 = voidspawn_boss
		#Behemoths
		is_ship_size = behemoth_01
		is_ship_size = behemoth_02
		is_ship_size = behemoth_03
		is_ship_size = behemoth_04
	}
}

ai_should_build_habitats = {
	is_country_type = default
	OR = {
		is_at_war = no
		mid_game_years_passed > 0
	}
	has_technology = tech_habitat_1
	if = {
		limit = {
			is_void_dweller_empire = no #VDs should build habitats even if there are other planets available
		}
		ai_colonize_plans <= 0
		OR = {
			has_aquatic_trait = no
			has_ascension_perk = ap_hydrocentric
		}
	}
	NOT = {
		any_planet_within_border = {
			is_planet_class = pc_habitat
			is_colony = no
		}
	}
	NOT = {
		any_neighbor_country = {
			is_crisis_faction = yes
		}
	}
}


has_any_farming_district_or_building = {
	OR = {
		has_district = district_farming
		has_district = district_orchard_forests
		has_building = building_hydroponics_farm
		has_any_agriculture_zone = yes
	}
}

has_any_planet_farming_district = {
	OR = {
		has_district = district_farming
		has_district = district_rw_farming
		has_district = district_orchard_forests
	}
}

has_any_capped_planet_farming_district = {
	has_any_planet_farming_district = yes
	is_farming_district_uncapped = no
}

has_any_mining_district_or_building = {
	OR = {
		has_district = district_mining
		has_district = district_melting
		has_district = district_hab_mining
		has_district = district_hollow_mountains
		has_building = building_mine_generic
		has_any_mining_zone = yes
	}
}

has_any_capped_planet_mining_district = {
	OR = {
		has_district = district_mining
		has_district = district_melting
		has_district = district_hollow_mountains
	}
	is_mining_district_uncapped = no
}

has_any_generator_district_or_building = {
	OR = {
		has_district = district_generator
		has_district = district_geothermal
		has_district = district_hab_energy
		has_district = district_photosynthesis_fields
		has_building = building_generator_generic
		has_any_generator_zone = yes
	}
}

has_any_capped_planet_generator_district = {
	OR = {
		has_district = district_generator
		has_district = district_geothermal
		has_district = district_rw_generator
	}
	is_generator_district_uncapped = no
}

is_generator_district_uncapped = {
	OR = {
		is_planet_class = pc_volcanic
		uses_district_set = shattered_ring_world
		has_carrier_flag = uncapped_generator_districts 			# For Modders
	}
}

is_wilderness_generator_district_uncapped = {
	OR = {
		AND = {
			exists = owner_or_space_owner
			owner_or_space_owner = {
				has_uncapped_wilderness_districts = yes
			}
		}
		has_carrier_flag = uncapped_generator_districts 			# For Modders
	}
}

is_mining_district_uncapped = {
	OR = {
		uses_district_set = shattered_ring_world
		AND = {
			exists = owner_or_space_owner
			owner_or_space_owner = {
				is_subterranean_empire = yes
			}
		}
		has_carrier_flag = uncapped_mining_districts 			# For Modders
	}
}

is_wilderness_mining_district_uncapped = {
	OR = {
		AND = {
			exists = owner_or_space_owner
			owner_or_space_owner = {
				has_uncapped_wilderness_districts = yes
			}
		}
		has_carrier_flag = uncapped_mining_districts 			# For Modders
	}
}

is_farming_district_uncapped = {
	OR = {
		uses_district_set = shattered_ring_world
		AND = {
			exists = owner_or_space_owner
			owner_or_space_owner = { is_anglers_empire = yes }
			is_planet_class = pc_ocean
		}
		has_carrier_flag = uncapped_farming_districts 			# For Modders
	}
}

is_wilderness_farming_district_uncapped = {
	OR = {
		AND = {
			exists = owner_or_space_owner
			owner_or_space_owner = {
				has_uncapped_wilderness_districts = yes
			}
		}
		has_carrier_flag = uncapped_farming_districts 			# For Modders
	}
}

uses_habitat_capitals = {
	uses_district_set = habitat
}

# Scope: Country
# VALUE: Minimum how much Unity per Empire Size that is required.
has_unity_times_empire_size = {
	resource_stockpile_compare = { resource = unity value >= $VALUE$ mult = trigger:empire_size }
}


got_any_unprotected_drones = {
	if = { # if we're protecting simple drones, check for a complex drones
		limit = {
			current_situation_approach = protect_simple_drones
		}
		target = {
			any_owned_pop_group = {
				is_robot_pop_group = yes
				is_pop_category = complex_drone
			}
		}
	}
	else_if = { # if we're protecting complex drones, check for simple drones
		limit = {
			current_situation_approach = protect_complex_drones
		}
		target = {
			any_owned_pop_group = {
				is_robot_pop_group = yes
				is_pop_category = simple_drone
			}
		}
	}
	else = { # if not protecting anyone, check for any drone
		target = {
			any_owned_pop_group = {
				is_robot_pop_group = yes
			}
		}
	}
}

# This can replace all the specific ones.
has_councilor = {
	exists = owner
	owner = {
		any_owned_leader = {
			is_councilor = yes
			is_councilor_type = $COUNCILOR$
		}
	}
}

has_councilor_with_trait_tier1or2 = {
	exists = owner
	owner = {
		any_owned_leader = {
			is_councilor = yes
			is_councilor_type = $COUNCILOR$
			has_trait_tier1or2 = { TRAIT = $TRAIT$ }
		}
	}
}

has_enclave_councilor = {
	OR = {
		has_councilor = { COUNCILOR = councilor_shroudwalker_teacher }
		has_councilor = { COUNCILOR = councilor_master_salvager }
		has_councilor = { COUNCILOR = councilor_curator_archivist }
		has_councilor = { COUNCILOR = councilor_enclave_trader }
	}
}

is_enclave_councilor_type = {
	OR = {
		is_councilor_type = councilor_shroudwalker_teacher
		is_councilor_type = councilor_master_salvager
		is_councilor_type = councilor_curator_archivist
		is_councilor_type = councilor_enclave_trader
	}
}

is_gestalt_node = {
	OR = {
		is_councilor_type = councilor_gestalt_growth
		is_councilor_type = councilor_gestalt_cognitive
		is_councilor_type = councilor_gestalt_legion
		is_councilor_type = councilor_gestalt_regulatory
	}
}

is_gestalt_ruler = {
	OR = {
		is_councilor_type = councilor_ruler_hive_mind
		is_councilor_type = councilor_ruler_machine_intelligence
	}
}

has_special_star_flag_trigger = {
	OR = {
		# Start System Flags
		has_star_flag = empire_home_system
		has_star_flag = neighbor_t1
		has_star_flag = neighbor_t1_first_colony
		has_star_flag = neighbor_t2
		has_star_flag = neighbor_t2_second_colony
		has_star_flag = empire_cluster
		# Enclaves
		has_star_flag = enclave
		has_star_flag = caravaneer_home
		# L-Gate
		has_star_flag = lgate
		has_star_flag = lcluster1
		has_star_flag = lcluster2
		has_star_flag = lcluster3
		has_star_flag = lcluster4
		has_star_flag = lcluster5
		has_star_flag = lcluster_lgate
		has_star_flag = lgateguaranteed
		# Leviathans
		has_star_flag = tiyanki_home_system
		has_star_flag = amoeba_home_system
		has_star_flag = voidworms_system
		has_star_flag = frenzied_voidworms_system
		has_star_flag = crystal_system
		has_star_flag = crystal_splitter_starting_system
		has_star_flag = crystal_splitter_destination_system
		# Hostile Systems
		has_star_flag = marauder_system
		has_star_flag = hostile_system
		has_star_flag = guardian
		has_star_flag = sealed_system
		has_star_flag = starlit_sealed_system
		has_star_flag = exiled_system
		# Megastructures
		has_star_flag = abandoned_gateway
		has_star_flag = ruined_mega_shipyard_system
		has_star_flag = ruined_dyson_system
		has_star_flag = ruined_catapult_system
		has_star_flag = ruined_nexus_system
		has_star_flag = ruined_orbital_ring_system
		has_star_flag = ruined_sentry_system
		has_star_flag = ruined_ring_system
		# Others
		has_star_flag = mechanocalibrator_system
		has_star_flag = rubricator_system
		has_star_flag = last_baol_system
		has_star_flag = Zrocursor
		has_star_flag = overlord_empire_flag
	}
}

has_sacrificial_edict = {
	OR = {
		has_edict = sacrifice_bounty
		has_edict = sacrifice_bounty_zombie
		has_edict = sacrifice_harmony
		has_edict = sacrifice_togetherness
	}
}

can_think = {
	NOR = {
		has_trait = trait_nerve_stapled
		has_trait = trait_zombie
		has_trait = trait_robot_suppressed
	}
}

has_zroni_equilibrators = {
	count_owned_planet = {
		count >= 3
		limit = {
			has_building = building_zroni_equilibrator
			is_controlled_by = root
		}
	}
}

has_slave_origin = { # used specifically for "First Contact"/MSI purposes
	OR = {
		has_origin = origin_broken_shackles
		has_origin = origin_payback
	}
}

has_young_origin = { # for Origins with very short/recent histories
	OR = {
		has_origin = origin_broken_shackles
		has_origin = origin_payback
		has_origin = origin_unplugged
	}
}

has_reduced_pop_origin = {
	OR = {
		has_origin = origin_broken_shackles
		has_origin = origin_payback
		has_origin = origin_fear_of_the_dark
		has_origin = origin_wilderness
		has_origin = origin_cosmic_dawn
	}
}

has_specialist_subject_leader_trait = {
	OR = {
		has_trait = leader_trait_bulwark_watcher
		has_trait = leader_trait_bulwark_retaliator
		has_trait = leader_trait_bulwark_sentinel
		has_trait = leader_trait_scholarium_investigator
		has_trait = leader_trait_scholarium_explorer
		has_trait = leader_trait_scholarium_observer
		has_trait = leader_trait_prospectorium_extractor
		has_trait = leader_trait_prospectorium_optimizer
		has_trait = leader_trait_prospectorium_refiner
		has_trait = leader_trait_tactical_algorithms
	}
}

is_toxic_baths_empire = {
	OR = {
		has_valid_civic = civic_toxic_baths
		has_valid_civic = civic_corporate_toxic_baths
		has_valid_civic = civic_hive_toxic_baths
		has_valid_civic = civic_machine_toxic_baths
		has_valid_civic = civic_toxic_baths_individual_machine
		has_valid_civic = civic_corporate_toxic_baths_individual_machine
	}
}

has_toxic_baths_building = {
	OR = {
		has_active_building = building_toxic_bath
		has_active_building = building_toxic_bath_hive
		has_active_building = building_toxic_bath_machine
	}
}

is_human_species = {
	OR = {
		species_portrait = human
		species_portrait = human_legacy
		species_portrait = pla17
		species_portrait = cyb12
	}
}

is_human_prescripted_empire = {
	OR = {
		has_country_flag = human_1
		has_country_flag = human_2
		has_country_flag = human_3
	}
}

has_fallen_empire_subject_preset = {
	OR = {
		agreement_preset = preset_scion
		agreement_preset = preset_dominion
		agreement_preset = preset_satellite
		agreement_preset = preset_signatory
		agreement_preset = preset_thrall
	}
}

is_overtuned = {
	OR = {
		has_trait = trait_spliced_adaptability
		has_trait = trait_juiced_power
		has_trait = trait_farm_hands
		has_trait = trait_crack_miner
		has_trait = trait_technical_skill
		has_trait = trait_crafted_smiles
		has_trait = trait_low_maintenance
		has_trait = trait_artificial_intelligence
		has_trait = trait_gene_mentorship
		has_trait = trait_expressed_tradition
		has_trait = trait_elevated_synapses
		has_trait = trait_preplanned_growth
		has_trait = trait_excessive_endurance
	}
}

is_non_hostile_to_wraith = {
	OR = {
		is_country_type = nomad
		is_country_type = dormant_marauders
		is_country_type = ruined_marauders
		is_country_type = awakened_marauders
		is_country_type = enclave
		is_country_type = tiyanki
		is_country_type = tiyanki_garrison
		is_country_type = amoeba
		is_country_type = amoeba_borderless
		is_country_type = amoeba_garrison
		is_country_type = amoeba_faction
		is_country_type = crystal
		is_country_type = crystal_faction
		is_country_type = drone
		is_country_type = drone_faction
		is_country_type = cloud
		is_country_type = marauder_raiders
		is_country_type = debt_collectors
		is_country_type = enigmatic_cache
		is_country_type = vluur
		is_voidworms_country_type = yes
	}
}

is_preftl_but_not_special = {
	is_primitive = yes
	OR = {
		species = {
			NOR = {
				has_trait = trait_hive_mind
				has_trait = trait_pc_habitat_preference
	#			has_trait = pc_warden_guardian_preference
			}
		}
		capital_scope = {
			NOR = {
				has_planet_flag = haven_flag
				has_planet_flag = prescripted_ideal
			}
		}
	}
}

is_scavenger = {
	OR = {
		has_valid_civic = civic_scavengers
		has_valid_civic = civic_corporate_scavengers
	}
}

is_market_nominee_planet = {
	OR = {
		has_modifier = market_nominee_level_1
		has_modifier = market_nominee_level_2
		has_modifier = market_nominee_level_3
		has_modifier = market_nominee_level_4
		has_modifier = market_nominee_level_5
	}
}

has_chosen_covenant_trait_non_ruler = {
	OR = {
		has_trait = leader_trait_composer_chosen
		has_trait = leader_trait_eater_chosen
		has_trait = leader_trait_instrument_chosen
		has_trait = leader_trait_whisperers_chosen
	}
}

has_presapient_trait = {
	OR = {
		has_trait = trait_presapient_starborn
		has_trait = trait_presapient_earthbound
		has_trait = trait_presapient_natural_intellectuals
		has_trait = trait_presapient_proles
		has_trait = trait_presapient_conservative
		has_trait = trait_presapient_irradiated
		has_trait = trait_presapient_docile_livestock
		has_trait = trait_presapient_forcefully_devolved
		# NOTE: 'trait_presapient_wilderness' is likely unsuitable for where this trigger is employed
	}
}

is_memory_vault_empire = {
	OR = {
		has_valid_civic = civic_memory_vault
		has_valid_civic = civic_memory_vault_corporate
		has_valid_civic = civic_memory_vault_machine
		has_valid_civic = civic_memory_vault_hive
	}
}

has_federator_personality = {
	OR = {
		has_ai_personality = federation_builders
		has_ai_personality = spiritual_seekers
		has_ai_personality = migrating_flock
		has_ai_personality = peaceful_traders
		has_ai_personality = hive_mind_friend
	}
}

is_ascensionist_empire = {
	OR = {
		has_valid_civic = civic_ascensionists
		has_valid_civic = civic_corporate_ascensionists
		has_valid_civic = civic_hive_ascensionists
		has_valid_civic = civic_machine_ascensionists
	}
}

is_flora_species = {
	OR = {
		is_species_class = FUN
		is_species_class = PLANT
	}
}

is_rival_technologically_superior = {
	any_rival_country = {
		relative_power = {
			who = root
			category = technology
			value >= superior
		}
	}
}

is_rival_economically_superior = {
	any_rival_country = {
		relative_power = {
			who = root
			category = economy
			value >= superior
		}
	}
}

is_rival_militarily_superior = {
	any_rival_country = {
		relative_power = {
			who = root
			category = fleet
			value >= superior
		}
	}
}

blocks_disruptive_gameplay = { #In case we ever want to extend the effect to other game options
	is_difficulty = 0
}

is_void_dweller_empire = {
	OR = {
		has_ascension_perk = ap_voidborn
		has_void_dweller_origin = yes
	}
}

has_void_dweller_origin = {
	OR = {
		has_origin = origin_void_dwellers
		has_origin = origin_void_machines
	}
}

is_apocalyptic_empire = {
	OR = {
		has_origin = origin_post_apocalyptic
		has_origin = origin_post_apocalyptic_machines
	}
}

has_any_storm_building = {
	# All the storm related buildings (except Astrometeorology Observation Center) go here
	OR = {
		has_building = building_storm_attraction_center
		has_building = building_advanced_storm_attraction_center
		has_building = building_storm_repellent_center
		has_building = building_advanced_storm_repellent_center
		has_building = building_storm_resistant_production
		has_building = building_advanced_storm_resistant_production
		has_building = building_adakkaria_patriotic_institute
		has_building = building_storm_summoning_theater
		has_building = building_storm_holo_theater
		has_building = building_storm_grand_theater
	}
}

has_any_storm_repellent_building = {
	OR = {
		any_owned_planet = {
			OR = {
				has_building = building_storm_repellent_center
				has_building = building_advanced_storm_repellent_center
			}
		}
		any_owned_starbase = {
			has_starbase_building = storm_repelling_computer
		}
	}
}

has_any_storm_attracting_building = {
	OR = {
		any_owned_planet = {
			OR = {
				has_building = building_storm_attraction_center
				has_building = building_advanced_storm_attraction_center
			}
		}
		any_owned_starbase = {
			has_starbase_building = storm_attraction_computer
		}
	}
}

has_storm_resistant_production_building = {
	OR = {
		has_building = building_storm_resistant_production
		has_building = building_advanced_storm_resistant_production
		# Storm Chasers get the Storm Shelter effect from their capital instead of the building
		owner? = {
			AND = {
				has_origin = origin_storm_chasers
				has_technology = tech_industrial_storm_protection
			}
		}
	}
}

system_has_negating_storm_building = {
	solar_system? = {
		any_system_planet = {
			has_building = building_planetary_shield_generator
		}
	}
}

system_has_storm_repelling_tech = {
	OR = {
		any_system_planet = {
			OR = {
				has_building = building_storm_repellent_center
				has_building_construction = building_storm_repellent_center
				has_building = building_advanced_storm_repellent_center
				has_building_construction = building_advanced_storm_repellent_center
			}
		}
		any_starbase_in_system = {
			OR = {
				has_starbase_building = storm_repelling_computer
				is_starbase_building_building = storm_repelling_computer
			}
		}
	}
}

system_has_storm_attraction_tech = {
	OR = {
		any_system_planet = {
			OR = {
				has_building = building_storm_attraction_center
				has_building_construction = building_storm_attraction_center
				has_building = building_advanced_storm_attraction_center
				has_building_construction = building_advanced_storm_attraction_center
			}
		}
		any_starbase_in_system = {
			OR = {
				has_starbase_building = storm_attraction_computer
				is_starbase_building_building = storm_attraction_computer
			}
		}
	}
}

blocks_minister_of_state = {
	OR = {
		is_gestalt = yes
		has_valid_civic = civic_inwards_perfection
		has_valid_civic = civic_fanatic_purifiers
		has_valid_civic = civic_scorched_earth
	}
}

is_terraforming_candidate = {
	OR = {
		has_modifier = terraforming_candidate
		has_modifier = frozen_terraforming_candidate
		has_modifier = toxic_terraforming_candidate
	}
}

has_engineered_evolution_synergy = {
	OR = {
		has_origin = origin_syncretic_evolution
		has_origin = origin_life_seeded
		has_origin = origin_necrophage
		has_origin = origin_clone_army
		has_origin = origin_evolutionary_predators
	}
}

has_flesh_is_weak_anti_synergy = {
	is_materialist = no
}

has_organo_machine_interfacing_assimilator_synergy = {
	has_civic = civic_machine_assimilator
}

has_synthetic_evolution_synergy = {
	has_origin = origin_mechanists
}

has_synthetic_evolution_anti_synergy = {
	is_materialist = no
}

blocks_ai_synthetic_evolution = {
	OR = {
		has_policy_flag = ai_outlawed
		has_policy_flag = robots_outlawed
		has_origin = origin_necrophage
		has_origin = origin_clone_army
		has_origin = origin_overtuned
		has_origin = origin_slavers
		has_valid_civic = civic_idyllic_bloom
		has_valid_civic = civic_hive_idyllic_bloom
	}
}

has_mind_over_matter_synergy = {
	OR = {
		has_ascension_perk = ap_become_the_crisis
		has_origin = origin_demonic_incursion
		has_country_flag = knights_met_end_of_cycle
	}
}

has_mind_over_matter_anti_synergy = {
	is_spiritualist = no
	if = {
		limit = { has_shroud_dlc = yes }
		is_gestalt = no
	}
}

has_synthetic_age_anti_synergy = {
	has_civic = civic_machine_assimilator
}

has_ap_pending = {
	OR = {
		AND = {
			has_ascension_perk = ap_the_flesh_is_weak
			NOT = { has_tradition = tr_cybernetics_adopt }
		}
		AND = {
			has_ascension_perk = ap_organo_machine_interfacing
			NOT = { has_tradition = tr_cybernetics_adopt }
		}
		AND = {
			has_ascension_perk = ap_organo_machine_interfacing_assimilator
			NOT = { has_tradition = tr_cybernetics_assimilator_adopt }
		}
		AND = {
			has_ascension_perk = ap_engineered_evolution
			NOR = {
				has_tradition = tr_genetics_adopt
				has_tradition = tr_cloning_adopt
				has_tradition = tr_mutation_adopt
				has_tradition = tr_purity_adopt
			}
		}
		AND = {
			has_ascension_perk = ap_synthetic_evolution
			NOT = { has_tradition = tr_synthetics_adopt }
		}
		AND = {
			has_ascension_perk = ap_mind_over_matter
			NOR = {
				has_tradition = tr_psionics_adopt
				has_tradition = tr_psionics_shroud_adopt
			}
		}
		AND = {
			has_ascension_perk = ap_synthetic_age
			NOR = {
				has_tradition = tr_modularity_adopt
				has_tradition = tr_nanotech_adopt
				has_tradition = tr_virtuality_adopt
			}
		}
	}
}

has_auto_modding_trait = {
	OR = {
		has_trait = trait_auto_mod_biological
		has_trait = trait_auto_mod_cyborg
		has_trait = trait_auto_mod_robotic
		has_trait = trait_auto_mod_overtuned
		has_trait = trait_malleable_genes
		has_trait = trait_adaptive_mutations
	}
}

can_dismantle_megastructure = {
	from = {
		has_technology = $TECH$
		is_at_war = no
	}
}

is_astrometeorologist_empire = {
	OR = {
		has_civic = civic_astrometeorology
		has_civic = civic_astrometeorology_hive
		has_civic = civic_astrometeorology_machine
		has_civic = civic_astrometeorology_megacorp
	}
}

is_storm_callers_empire = {
	OR = {
		has_civic = civic_storm_callers
		has_civic = civic_storm_callers_megacorp
	}
}

has_storm_attraction_civic = {
	OR = {
		is_astrometeorologist_empire = yes
		is_storm_callers_empire = yes
	}
}

is_environmental_architects_empire = {
	OR = {
		has_civic = civic_environmental_architects
		has_civic = civic_environmental_architects_hive
		has_civic = civic_environmental_architects_machine
		has_civic = civic_environmental_architects_megacorp
	}
}

influence_building_destruction_trigger = {
	exists = owner
	owner = { is_ai = yes }
	solar_system? = {
		system_has_storm_repelling_tech = yes
	}
	owner = {
		has_storm_attraction_civic = no
		NOT = {
			has_origin = origin_storm_chasers
		}
	}
}

has_sr_deposit = {
	OR = {
		has_deposit = d_dust_caverns
		has_deposit = d_dust_desert
		has_deposit = d_bubbling_swamp
		has_deposit = d_fuming_bog
		has_deposit = d_crystalline_caverns
		has_deposit = d_crystal_forest
		has_deposit = d_crystal_reef
	}
}

can_obtain_volatile_motes = {
	custom_tooltip = {
		fail_text = must_have_access_to_volatile_motes_tt
		OR = {
			has_technology = tech_mine_volatile_motes
			has_technology = tech_volatile_motes
			has_country_flag = has_market_access
		}
	}
}

can_obtain_rare_crystals = {
	custom_tooltip = {
		fail_text = must_have_access_to_rare_crystals_tt
		OR = {
			has_technology = tech_mine_rare_crystals
			has_technology = tech_rare_crystals
			has_country_flag = has_market_access
		}
	}
}

very_first_contact_paragon = {
	NOR = {
		has_country_flag = first_contact_protocol_event_happened
		has_origin = origin_common_ground
		has_origin = origin_hegemon
	}
	years_passed < 15
}

is_legit_or_legal_criminal = {
	OR = {
		is_criminal_syndicate = no
		AND = {
			is_criminal_syndicate = yes
			OR = {
				# Have a Commercial  Pact
				has_commercial_pact = root.owner
				# Be in a Federation together
				is_in_federation_with = root.owner
				# Overlord/Subjects
				AND = {
					is_subject = yes
					overlord = {
						OR = {
							is_same_value = root.owner
							is_same_value = root.owner.overlord
						}
					}
				}
				root.owner = {
					is_subject = yes
					overlord = {
						OR = {
							is_same_value = prevprev
							is_same_value = prevprev.overlord
						}
					}
				}
				# ImperiCorp
				AND = {
					has_civic = civic_galactic_sovereign_megacorp
					root.owner = { is_galactic_community_member = yes }
				}
				# Imperial Charter
				AND = {
					has_modifier = imperial_charter
					root.owner = { is_galactic_community_member = yes }
				}
			}
		}
	}
}

is_illegal_criminal = {
	is_criminal_syndicate = yes
	NOT = {
		has_commercial_pact = root.owner
		is_in_federation_with = root.owner
		# Overlord/Subjects
		AND = {
			is_subject = yes
			overlord = {
				OR = {
					is_same_value = root.owner
					is_same_value = root.owner.overlord
				}
			}
		}
		root.owner = {
			is_subject = yes
			overlord = {
				OR = {
					is_same_value = prevprev
					is_same_value = prevprev.overlord
				}
			}
		}
		# ImperiCorp
		AND = {
			has_civic = civic_galactic_sovereign_megacorp
			root.owner = { is_galactic_community_member = yes }
		}
		# Imperial Charter
		AND = {
			has_modifier = imperial_charter
			root.owner = { is_galactic_community_member = yes }
		}
	}
}

weapon_tech_increased = {
	OR = {
#		last_increased_tech = tech_mass_drivers_1			# Starting Tech
		last_increased_tech = tech_mass_drivers_2
		last_increased_tech = tech_mass_drivers_3
		last_increased_tech = tech_mass_drivers_4
		last_increased_tech = tech_mass_drivers_5
		last_increased_tech = tech_archaeo_mass_drivers
		last_increased_tech = tech_kinetic_artillery_1
		last_increased_tech = tech_kinetic_artillery_2
		last_increased_tech = tech_mass_accelerator_1
		last_increased_tech = tech_mass_accelerator_2
		last_increased_tech = tech_archaeo_mass_accelerator
		last_increased_tech = tech_autocannons_1
		last_increased_tech = tech_autocannons_2
		last_increased_tech = tech_autocannons_3
		last_increased_tech = tech_nanite_autocannon
		last_increased_tech = tech_flak_batteries_1
		last_increased_tech = tech_flak_batteries_2
		last_increased_tech = tech_flak_batteries_3
		last_increased_tech = tech_nanite_flak_batteries
#		last_increased_tech = tech_missiles_1				# Starting Tech
		last_increased_tech = tech_missiles_2
		last_increased_tech = tech_missiles_3
		last_increased_tech = tech_missiles_4
		last_increased_tech = tech_missiles_5
		last_increased_tech = tech_archaeo_missiles
		last_increased_tech = tech_swarmer_missiles_1
		last_increased_tech = tech_swarmer_missiles_2
		last_increased_tech = tech_torpedoes_1
		last_increased_tech = tech_torpedoes_2
		last_increased_tech = tech_torpedoes_3
#		last_increased_tech = tech_lasers_1					# Starting Tech
		last_increased_tech = tech_lasers_2
		last_increased_tech = tech_lasers_3
		last_increased_tech = tech_lasers_4
		last_increased_tech = tech_lasers_5
		last_increased_tech = tech_archaeo_lasers
		last_increased_tech = tech_energy_lance_1
		last_increased_tech = tech_energy_lance_2
		last_increased_tech = tech_titans
		last_increased_tech = tech_archaeo_titan_beam
		last_increased_tech = tech_plasma_1
		last_increased_tech = tech_plasma_2
		last_increased_tech = tech_plasma_3
		last_increased_tech = tech_arc_emitter_1
		last_increased_tech = tech_arc_emitter_2
		last_increased_tech = tech_disruptors_1
		last_increased_tech = tech_disruptors_2
		last_increased_tech = tech_disruptors_3
		last_increased_tech = tech_energy_torpedoes_1
		last_increased_tech = tech_energy_torpedoes_2
		last_increased_tech = tech_pd_tracking_1
		last_increased_tech = tech_pd_tracking_2
		last_increased_tech = tech_pd_tracking_3
		last_increased_tech = tech_archaeo_point_defence
		last_increased_tech = tech_strike_craft_1
		last_increased_tech = tech_strike_craft_2
		last_increased_tech = tech_strike_craft_3
		last_increased_tech = tech_strike_craft_skrand
		last_increased_tech = tech_archaeo_strike_crafts
		last_increased_tech = tech_extradimensional_weapon_1
		last_increased_tech = tech_mining_drone_weapon_1
		last_increased_tech = tech_space_cloud_weapon_1
		last_increased_tech = null_void_beam
		last_increased_tech = tech_amoeba_strike_craft_1
		last_increased_tech = tech_swarm_strike_craft_1
		last_increased_tech = tech_scourge_missile_1
		last_increased_tech = tech_space_whale_weapon_1
		# BioGenesis Weapons
#		last_increased_tech = tech_maulers						# Starting Tech
		last_increased_tech = tech_mandibles_2
		last_increased_tech = tech_mandibles_3
		last_increased_tech = tech_weaver_bio_healing_1
		last_increased_tech = tech_weaver_bio_healing_2
		last_increased_tech = tech_weaver_bio_healing_3
		last_increased_tech = tech_weaver_bio_healing_4
		last_increased_tech = tech_weaver_bio_healing_5
		last_increased_tech = tech_weaver_bio_healing_6
		last_increased_tech = tech_weaver_bio_confuser_1
		last_increased_tech = tech_weaver_bio_confuser_2
		last_increased_tech = tech_weaver_bio_confuser_3
		last_increased_tech = tech_weaver_bio_confuser_4
		last_increased_tech = tech_weaver_bio_confuser_5
		last_increased_tech = tech_weaver_bio_confuser_6
#		last_increased_tech = tech_weaver_bio_anti_evasion_1	# Starting Tech
		last_increased_tech = tech_weaver_bio_anti_evasion_2
		last_increased_tech = tech_weaver_bio_anti_evasion_3
		last_increased_tech = tech_weaver_bio_anti_evasion_4
		last_increased_tech = tech_weaver_bio_anti_evasion_5
		last_increased_tech = tech_weaver_bio_anti_evasion_6
#		last_increased_tech = tech_weaver_bio_evasion_1			# Starting Tech
		last_increased_tech = tech_weaver_bio_evasion_2
		last_increased_tech = tech_weaver_bio_evasion_3
		last_increased_tech = tech_weaver_bio_evasion_4
		last_increased_tech = tech_weaver_bio_evasion_5
		last_increased_tech = tech_weaver_bio_evasion_6
		last_increased_tech = tech_weaver_bio_anti_fire_rate_1
		last_increased_tech = tech_weaver_bio_anti_fire_rate_2
		last_increased_tech = tech_weaver_bio_anti_fire_rate_3
		last_increased_tech = tech_weaver_bio_anti_fire_rate_4
		last_increased_tech = tech_weaver_bio_anti_fire_rate_5
		last_increased_tech = tech_weaver_bio_anti_fire_rate_6
		last_increased_tech = tech_weaver_bio_fire_rate_1
		last_increased_tech = tech_weaver_bio_fire_rate_2
		last_increased_tech = tech_weaver_bio_fire_rate_3
		last_increased_tech = tech_weaver_bio_fire_rate_4
		last_increased_tech = tech_weaver_bio_fire_rate_5
		last_increased_tech = tech_weaver_bio_fire_rate_6
	}
}

system_has_science_nexus = {
	solar_system = {
		any_system_megastructure = {
			OR = {
				is_megastructure_type = think_tank_1
				is_megastructure_type = think_tank_2
				is_megastructure_type = think_tank_3
				is_megastructure_type = think_tank_4
			}
		}
	}
}

has_any_rare_strategic_resource = {
	OR = {
		has_resource = astral_threads
		has_resource = sr_zro
		has_resource = exotic_gases
		has_resource = sr_dark_matter
		has_resource = sr_living_metal
		has_resource = rare_crystals
		has_resource = volatile_motes
		has_resource = nanites
	}
}

has_resource_for_discovery = {
	root.from = {
		has_resource = {
			amount > 0
			type = $RESOURCE$
		}
	}
	NOT = {
		has_country_flag = $RESOURCE$_found
	}
}

has_deficits = {
	OR = {
		has_deficit = minerals
		has_deficit = energy
		has_deficit = food
		has_deficit = consumer_goods
		has_deficit = alloys
		has_deficit = unity
		has_deficit = influence
		has_deficit = sr_zro
		has_deficit = exotic_gases
		has_deficit = sr_dark_matter
		has_deficit = sr_living_metal
		has_deficit = rare_crystals
		has_deficit = volatile_motes
		has_deficit = nanites
	}
}

is_holy_world = {
	OR = {
		has_carrier_flag = holy_world_1
		has_carrier_flag = holy_world_2
		has_carrier_flag = holy_world_3
		has_carrier_flag = holy_world_4
	}
}

fears_unplugged_empire = { # see also: 'triggered_opinion_cyborgs_normal'
	is_country_type = default
	NOR = {
		is_homicidal = yes
		has_origin = origin_cybernetic_creed # they don't fear Driven Assimilators
		has_young_origin = yes # too new to the galaxy; includes Unplugged
		is_fallen_empire = yes # fallen empires don't fear
		has_civic = civic_machine_assimilator
	}
}

can_have_slaves = {
	OR = {
		is_authoritarian = yes
		is_xenophobe = yes
		has_ethic = ethic_gestalt_consciousness
	}
	NOT = { has_origin = origin_broken_shackles }
}

has_natural_blocker = { # planet scope | see also 'add_random_natural_blocker_and_give_tech', 'wilderness_get_natural_blocker_name'
	OR = {
		has_deposit = d_deep_sinkhole
		has_deposit = d_quicksand_basin
		has_deposit = d_active_volcano
		has_deposit = d_mountain_range
		has_deposit = d_dangerous_wildlife_blocker
		has_deposit = d_dense_jungle
		has_deposit = d_toxic_kelp
		has_deposit = d_noxious_swamp
		has_deposit = d_massive_glacier
		has_deposit = d_radioactive_wasteland
		has_deposit = d_city_ruins
		has_deposit = d_raging_lavafalls
		has_deposit = d_rugged_landscape
	}
}

can_talk_to_prethoryn = {
	OR = {
		owner_species = { is_psionic_species = yes }
		owner_species = { has_trait = trait_hive_mind }
		has_menace_perk = menp_behemoth_mind_meld
	}
}

has_subspecies_civic_or_origin = {
	owner = {
		OR = {
			has_valid_civic = civic_machine_assimilator
			has_valid_civic = civic_machine_servitor
			has_valid_civic = civic_hive_bodysnatcher
			has_origin = origin_syncretic_evolution
			has_origin = origin_necrophage
			has_origin = origin_forever_cruise
			is_guided_sapience_empire = yes
		}
	}
}

has_machine_subspecies = {
	has_country_flag = machine_subspecies
}

is_hive_empire_with_machines = {
	is_hive_empire = yes
	has_machine_subspecies = yes
}

has_functional_civic = {
	OR = {
		has_valid_civic = civic_functional_architecture
		has_valid_civic = civic_machine_builder
	}
}

has_tech_or_functional_civic = {
	OR = {
		has_technology = $TECH$
		has_functional_civic = yes
	}
}

has_zone = {
	num_zones = {
		type = $zone$
		value > 0
	}
}


has_good_relationships = {
	any_relation = {
		is_country_type = default
		has_communications = ROOT
		opinion_level = {
			who = root
			level >= good
		}
	}
}

is_specialist_category = {
	is_pop_category = specialist
}

has_unity_blocker = {
	OR = {
		has_deposit = d_shroudstone
		has_deposit = d_aura_blocker
		has_deposit = d_shroudfall
		has_deposit = d_ruined_sanctum_of_the_lost
	}
}

# Scope: country. Fires if any tangible stockpile is at or above 90% of its (per-country, mods-included)
# storage cap. Used as an AI gate on storage-boost buildings (resource silo, subterranean cache) so the AI
# is allowed to build one only when real pressure exists. Scales naturally with empires that have already
# invested in storage mods -- they must actually approach their higher caps before this fires.
country_near_tangible_resource_cap = {
	OR = {
		resource_stockpile_percent = { resource = minerals value >= 0.9 }
		resource_stockpile_percent = { resource = energy value >= 0.9 }
		resource_stockpile_percent = { resource = food value >= 0.9 }
		resource_stockpile_percent = { resource = consumer_goods value >= 0.9 }
		resource_stockpile_percent = { resource = alloys value >= 0.9 }
		resource_stockpile_percent = { resource = exotic_gases value >= 0.9 }
		resource_stockpile_percent = { resource = volatile_motes value >= 0.9 }
		resource_stockpile_percent = { resource = rare_crystals value >= 0.9 }
	}
}
