
buildings_build_building = {
	planet_devastation < 10
	NOT = {
		planet = {
			has_current_purge = yes
		}
	}
	OR = {
		has_modifier = planet_population_control
		has_modifier = planet_population_control_gestalt
		has_modifier = planet_robot_assembly_control
		has_modifier = planet_growth_discouraged
		free_district_slots = 0
	}
	NAND = {
		exists = owner
		owner = { is_lithoid_devouring_swarm = yes }
		is_lithoid_devouring_swarm_consumption_world = yes
	}
}

country_uses_food = {
	OR = {
		if = {
			limit = {
				# Check if we have an uninitialized economy, then return true to be safe because we don't know
				resource_expenses_compare = {
					resource = food
					value = 0
				}
				resource_expenses_compare = {
					resource = minerals
					value = 0
				}
				resource_expenses_compare = {
					resource = energy
					value = 0
				}
			}
		}
		else = {
			resource_expenses_compare = {
				resource = food
				value > 0
			}
		}
		country_uses_bio_ships = yes
	}
}

country_uses_food_game_start = { # A separate trigger as resource_expenses_compare does not work at game start, after game start use country_uses_food
	OR = {
		any_owned_species = {
			has_trait = trait_organic
		}
		country_uses_bio_ships = yes
		is_catalytic_empire = yes
	}
}

country_uses_consumer_goods = {
	if = {
		limit = {
			# Check if we have an uninitialized economy, then return true to be safe because we don't know
			resource_expenses_compare = {
				resource = food
				value = 0
			}
			resource_expenses_compare = {
				resource = minerals
				value = 0
			}
			resource_expenses_compare = {
				resource = energy
				value = 0
			}
		}
	}
	else = {
		OR = {
			has_valid_civic = civic_machine_obsessional_directive
			resource_expenses_compare = {
				resource = consumer_goods
				value > 0
			}
		}
	}
}

country_uses_consumer_goods_game_start = { # A separate trigger as resource_expenses_compare does not work at game start, after game start use country_uses_consumer_goods
	OR = {
		is_gestalt = no
		has_valid_civic = civic_machine_obsessional_directive
		has_valid_civic = civic_machine_servitor
	}
}

buildings_difficulty = {
	is_difficulty > 2
	years_passed > 20
	has_resource = { type = energy amount > 1000 }
	has_resource = { type = minerals amount > 2000 }
}

buildings_stop_pop = {
	exists = owner
	free_housing < -400
	free_district_slots = 0
}

districts_good_energy = {
	planet = {
		OR = {
			has_modifier = hazardous_weather
			has_modifier = divine_algorithm
			has_modifier = energy_relic
			has_modifier = gas_rich_planet_fo_realz
			has_carrier_flag = buildings_good_energy
		}
	}
}

districts_good_minerals = {
	planet = {
		OR = {
			has_modifier = extensive_moon_system
			has_modifier = carbon_world
			has_modifier = mineral_rich
			has_modifier = ultra_rich
			has_modifier = asteroid_belt
			has_modifier = minerals_relic
			has_carrier_flag = buildings_good_minerals
		}
	}
}

districts_good_food = {
	planet = {
		OR = {
			has_modifier = lush_planet
			has_carrier_flag = buildings_good_food
		}
	}
}

jobs_work_minerals_goods = {
	exists = owner
	owner = {
		is_ai = yes
		has_monthly_income = {
			resource = minerals
			value < 50
		}
		OR = {
			AND = {
				has_resource = {
					type = minerals
					amount < 5000
				}
				has_resource = {
					type = consumer_goods
					amount > 1500
				}
			}
			AND = {
				has_resource = {
					type = minerals
					amount < 3000
				}
				has_resource = {
					type = consumer_goods
					amount > 750
				}
			}
			AND = {
				has_resource = {
					type = minerals
					amount < 501
				}
				has_resource = {
					type = consumer_goods
					amount > 500
				}
			}
		}
	}
}#If true makes the AI really value mining jobs and stops organics from working factory jobs.

buildings_has_motes = {
	exists = owner
	OR = {
		owner = {
			has_monthly_income = {
				resource = volatile_motes
				value >= 3
			}
		}
		AND = {
			free_building_slots > 1
			owner = {
				has_monthly_income = {
					resource = volatile_motes
					value > 0
				}
			}
		}
	}
}#Used in the buildings file to determine if the country has the needed Strategic Resource.

buildings_has_crystals = {
	exists = owner
	OR = {
		owner = {
			has_monthly_income = {
				resource = rare_crystals
				value >= 3
			}
		}
		AND = {
			free_building_slots > 1
			owner = {
				has_monthly_income = {
					resource = rare_crystals
					value > 0
				}
			}
		}
	}
}#Used in the buildings file to determine if the country has the needed Strategic Resource.

buildings_has_exotic_gases = {
	exists = owner
	OR = {
		owner = {
			has_monthly_income = {
				resource = exotic_gases
				value >= 3
			}
		}
		AND = {
			free_building_slots > 1
			owner = {
				has_monthly_income = {
					resource = exotic_gases
					value > 0
				}
			}
		}
	}
}#Used in the buildings file to determine if the country has the needed Strategic Resource.

has_farming_designation = {
	OR = {
		has_designation = col_farming
		has_designation = col_ring_farming
		has_designation = col_habitat_farming
		has_designation = col_habitat_gestalt_farming
		has_designation = col_nomad_farming
	}
}

has_fortress_designation = {
	or = {
		has_designation = col_fortress
		has_designation = col_habitat_fortress
		has_designation = col_nomad_fortress
	}
}

has_capital_urban_designation = {
	OR = {
		has_designation = col_capital
		has_designation = col_capital_hive
		has_designation = col_capital_machine
		has_designation = col_capital_nomad
	}
}

has_urban_designation = {
	OR = {
		has_designation = col_city
		has_designation = col_hive
		has_designation = col_nexus
		has_designation = col_nomad_city
		has_designation = col_nomad_hive
		has_designation = col_nomad_nexus
	}
}

has_factory_designation = {
	OR = {
		has_designation = col_capital_factory
		has_designation = col_factory
		has_designation = col_mac_factory
		has_designation = col_ecu_factory
		has_designation = col_habitat_factory
		has_designation = col_nomad_factory
		has_designation = col_capital_nomad_factory
	}
}

has_foundry_designation = {
	OR = {
		has_designation = col_capital_foundry
		has_designation = col_foundry
		has_designation = col_ecu_foundry
		has_designation = col_habitat_foundry
		has_designation = col_mac_foundry
		has_designation = col_hiv_foundry
		has_designation = col_nomad_foundry
		has_designation = col_capital_nomad_foundry
	}
}

has_generator_designation = {
	OR = {
		has_designation = col_generator
		has_designation = col_habitat_energy
		has_designation = col_ring_generator
		has_designation = col_nomad_generator
	}
}

has_industrial_designation = {
	OR = {
		has_designation = col_industrial
		has_designation = col_habitat_industrial
		has_designation = col_ecu_industrial
		has_designation = col_nomad_industrial
	}
}

has_mining_designation = {
	OR = {
		has_designation = col_habitat_mining
		has_designation = col_mining
	}
}

has_research_designation = {
	OR = {
		has_designation = col_research
		has_designation = col_ring_research
		has_designation = col_habitat_research
		has_designation = col_ecu_research
		has_designation = col_nomad_research
	}
}

has_unity_designation = {
	OR = {
		has_designation = col_bureau
		has_designation = col_habitat_bureau
		has_designation = col_bureau_machine
		has_designation = col_trophy_machine
		has_designation = col_habitat_bureau_machine
		has_designation = col_bureau_hive
		has_designation = col_habitat_bureau_hive
		has_designation = col_bureau_spiritualist
		has_designation = col_habitat_bureau_spiritualist
		has_designation = col_nomad_bureau
		has_designation = col_nomad_bureau_spiritualist
		has_designation = col_nomad_bureau_machine
		has_designation = col_nomad_bureau_hive
		has_designation = col_nomad_trophy_machine
	}
}

has_rural_designation = {
	OR = {
		has_designation = col_capital_extraction
		has_designation = col_hiv
	}
}

has_trade_designation = {
	OR = {
		has_designation = col_capital_trade
		has_designation = col_city
		has_designation = col_habitat_trade
		has_designation = col_ring_trade
		has_designation = col_ecu_mix
		has_designation = col_nexus
		has_designation = col_trade_machine
		has_designation = col_nomad_city
		has_designation = col_nomad_nexus
		has_designation = col_capital_nomad_trade
	}
}

meets_basic_energy_threshold = {
	OR = {
		has_monthly_income = { resource = energy value > @economic_plan_energy_target }
		resource_stockpile_compare = {
			resource = energy
			value > @economic_plan_stockpile_threshold
		}
		any_situation = {
			is_situation_type = situation_nomad_economy
			nomad_in_reserve_crisis = no
		}
	}
}

meets_basic_minerals_threshold = {
	OR = {
		has_monthly_income = { resource = minerals value > @economic_plan_mineral_target }
		resource_stockpile_compare = {
			resource = minerals
			value > @economic_plan_stockpile_threshold
		}
		any_situation = {
			is_situation_type = situation_nomad_economy
			nomad_in_reserve_crisis = no
		}
	}
}

meets_basic_food_threshold = {
	OR = {
		country_uses_food = no
		has_monthly_income = { resource = food value > @economic_plan_food_target }
		resource_stockpile_compare = {
			resource = food
			value > @economic_plan_stockpile_threshold
		}
	}
}

meets_basic_alloys_threshold = {
	OR = {
		has_monthly_income = { resource = alloys value > @economic_plan_alloy_target }
		resource_stockpile_compare = {
			resource = alloys
			value > @economic_plan_stockpile_threshold
		}
	}
}

meets_basic_consumer_goods_threshold = {
	OR = {
		country_uses_consumer_goods = no
		has_monthly_income = { resource = consumer_goods value > @economic_plan_consumer_goods_target }
		resource_stockpile_compare = {
			resource = consumer_goods
			value > @economic_plan_stockpile_threshold
		}
	}
}

meets_basic_research_threshold = {
	has_monthly_income = { resource = physics_research value > @economic_plan_research_target }
	has_monthly_income = { resource = society_research value > @economic_plan_research_target }
	has_monthly_income = { resource = engineering_research value > @economic_plan_research_target }
}

meets_basic_resource_thresholds = {
	meets_basic_energy_threshold = yes
	meets_basic_minerals_threshold = yes
}

# Scope: Starbase
# Checks if the owner has the Archaeo-Engineers ascension perk
ai_owner_has_archaeoengineers = {
	owner? = {
		has_ascension_perk = ap_archaeoengineers
	}
}

# Scope: Starbase
# Checks if the owner's AI personality prefers armor
ai_owner_prefers_armor = {
	owner? = {
		ai_armor_ratio >= 0.4
	}
}

# Scope: Starbase
# Checks if the owner's AI personality prefers shields
ai_owner_prefers_shields = {
	owner? = {
		ai_shields_ratio >= 0.4
	}
}

# Scope: Starbase
# Checks if the owner's AI personality prefers energy weapons
ai_owner_prefers_energy_weapons = {
	owner? = {
		is_preferred_weapons = weapon_type_energy
	}
}

# Scope: Starbase
# Checks if the owner's AI personality prefers kinetic weapons
ai_owner_prefers_kinetic_weapons = {
	owner? = {
		is_preferred_weapons = weapon_type_kinetic
	}
}

# Scope: Starbase
# Checks if the owner's AI personality prefers explosive weapons
ai_owner_prefers_explosive_weapons = {
	owner? = {
		is_preferred_weapons = weapon_type_explosive
	}
}

# Scope: Starbase
# Checks if the owner's AI personality prefers strike craft
ai_owner_prefers_strike_craft = {
	owner? = {
		is_preferred_weapons = weapon_type_strike_craft
	}
}

has_orbital_ring_with_empty_building_slots = {
	any_owned_nonprimary_starbase = {
		exists = planet
		OR = {
			AND = {
				has_starbase_size = orbital_ring_tier_2
				count_starbase_buildings = {
					count = 0
				}
			}
			AND = {
				has_starbase_size = orbital_ring_tier_3
				count_starbase_buildings = {
					count < 2
				}
			}
		}
	}
}

has_capital_designation = {
	OR = {
		has_designation = col_capital
		has_designation = col_capital_hive
		has_designation = col_capital_machine
		has_designation = col_capital_nomad
		has_designation = col_capital_nomad_foundry
		has_designation = col_capital_nomad_factory
		has_designation = col_capital_nomad_trade
	}
}

has_spearhead_doctrine_personality = {
	OR = {
		has_ai_personality = hive_mind
		has_ai_personality = assimilators
		has_ai_personality = hyperthermia_empire
		has_ai_personality = metalhead
		has_ai_personality = rampant_wilderness
		has_ai_personality = fanatic_purifiers
		has_ai_personality = scorching_infernals
	}
}

has_battleline_doctrine_personality = {
	OR = {
		has_ai_personality = hegemonic_imperialists
		has_ai_personality = honorbound_warriors
		has_ai_personality = democratic_crusaders
		has_ai_personality = evangelising_zealots
		has_ai_personality = machine_intelligence
	}
}

has_barrage_doctrine_personality = {
	OR = {
		has_ai_personality = exterminators
		has_ai_personality = became_the_crisis
	}
}

has_strike_wing_doctrine_personality = {
	OR = {
		has_ai_personality = peaceful_traders
		has_ai_personality = migrating_flock
		has_ai_personality = hive_mind_friend
		has_ai_personality = fanatic_befrienders
		has_ai_personality = benevolent_wilderness
		has_ai_personality = devouring_swarm
	}
}

has_ambush_doctrine_personality = {
	OR = {
		has_ai_personality = erudite_explorers
		has_ai_personality = ruthless_capitalists
		has_ai_personality = slaving_despots
		has_ai_personality = decadent_capitalists
	}
}

has_phalanx_doctrine_personality = {
	OR = {
		has_ai_personality = spiritual_seekers
		has_ai_personality = federation_builders
		has_ai_personality = xenophobic_isolationists
		has_ai_personality = servitors
		has_ai_personality = harmonious_hierarchy
		has_ai_personality = imperial_origin_overlord_ai
		has_ai_personality = decadent_hierarchy
	}
}
