#############
# Resource buildings
#############

building_hydroponics_farm = {
	base_buildtime = @b1_time
	category = resource

	building_sets = {
		hydroponics
	}

	potential = {
		exists = owner
		owner = {
			OR = {
				country_uses_food = yes
				is_ai = no
			}
			is_wilderness_empire = no
		}
		NOT = { is_planet_class = pc_machine }
		NOT = { has_modifier = resort_colony }
		OR = {
			has_carrier_flag = ignore_ai_building_limitations
			owner = { is_ai = no }
			# AI is allowed to build up to two of these.
			num_buildings = { type = building_hydroponics_farm value < 2 }
		}
	}
	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				AND = {
					is_ai = yes
					country_uses_food = no
				}
				is_wilderness_empire = yes
			}
		}
	}

	inline_script = {
		script = jobs/farmers_add
		AMOUNT = @building_static_jobs
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = 2
		}
	}
	prerequisites = {
		"tech_hydroponics"
	}

	ai_weight_coefficient = @static_jobs_ai_weight_coefficient
}

building_food_processing_facility = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = resource

	building_sets = {
		farming
	}

	potential = {
		exists = owner
		owner = { is_wilderness_empire = no } # see 'building_massive_growth_3'
		NOR = {
			is_planet_class = pc_machine
			has_modifier = resort_colony
		}
		OR = {
			owner = { is_ai = no }
			has_any_farming_district_or_building = yes
		}
		owner = {
			OR = {
				is_ai = no
				country_uses_food = yes
			}
		}
	}
	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					AND = {
						is_ai = yes
						country_uses_food = no
					}
					is_wilderness_empire = yes
				}
			}
			is_planet_class = pc_machine
			has_modifier = resort_colony
			AND = {
				owner = { is_ai = yes }
				has_any_farming_district_or_building = no
			}
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = 2
		}
	}

	planet_modifier = {
		planet_farmers_food_produces_add = 0.5
	}

	upgrades = {
		building_food_processing_center
	}

	prerequisites = {
		"tech_food_processing_1"
	}

	ai_resource_production = {
		food = 10

		trigger = {
			has_any_agriculture_zone = yes
		}
	}


	show_tech_unlock_if = {
		is_wilderness_empire = no
	}
}

building_food_processing_center = {
	base_buildtime = @b2_time
	can_build = no
	category = resource

	building_sets = {
		farming
	}

	potential = {
		owner = { is_wilderness_empire = no } # see 'building_massive_growth_4'
	}
	allow = {
		exists = owner
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					AND = {
						is_ai = yes
						country_uses_food = no
					}
					is_wilderness_empire = yes
				}
			}
			AND = {
				owner = { is_ai = yes }
				has_any_farming_district_or_building = no
			}
			is_planet_class = pc_machine
			has_modifier = resort_colony
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_with_additional_trigger
			TRIGGER = "has_ringworld_output_boost = no"
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = exotic_gases
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = no
			}
			exotic_gases = @b2_rare_cost
		}
		inline_script = {
			script = buildings/nomadic_cost_switcher_with_additional_trigger
			TRIGGER = "has_ringworld_output_boost = yes"
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = exotic_gases
			COST = 900
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			exotic_gases = 200
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = no
			}
			energy = 2
			exotic_gases = @b2_rare_upkeep
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			energy = 5
			exotic_gases = 3
		}
	}

	planet_modifier = {
		planet_farmers_food_produces_add = 1.0
	}

	triggered_planet_modifier = {
		potential = {
			has_ringworld_output_boost = yes
		}
		modifier = {
			planet_farmers_food_produces_add = 0.5
		}
	}

	prerequisites = {
		"tech_food_processing_2"
	}

	ai_resource_production = {
		food = 15

		trigger = {
			has_any_agriculture_zone = yes
		}
	}

	show_tech_unlock_if = {
		is_wilderness_empire = no
	}
}

building_farming_districts_1 = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = resource

	building_sets = {
		farming
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_farming_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_farming_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b1_upkeep
		}
	}

	planet_modifier = {
		district_farming_max_add = @b1_max_districts_add
	}

	upgrades = {
		building_farming_districts_2
	}

	prerequisites = {
		tech_industrial_farming
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_farming_districts_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = resource

	building_sets = {
		farming
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_farming_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_farming_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			exotic_gases = @b2_rare_cost
		}
		upkeep = {
			energy = @b2_upkeep
			exotic_gases = @b2_rare_upkeep
		}
	}

	planet_modifier = {
		district_farming_max_add = @b2_max_districts_add
	}

	upgrades = {
		building_farming_districts_3
	}

	prerequisites = {
		tech_eco_simulation
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_farming_districts_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = resource

	building_sets = {
		farming
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_farming_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_farming_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b3_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			exotic_gases = @b3_rare_cost
		}
		upkeep = {
			energy = @b3_upkeep
			exotic_gases = @b3_rare_upkeep
		}
	}

	planet_modifier = {
		district_farming_max_add = @b3_max_districts_add
	}

	upgrades = {
		building_farming_districts_4
	}

	prerequisites = {
		tech_gene_crops
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_farming_districts_4 = {
	base_buildtime = @b4_time
	can_build = no
	category = resource

	building_sets = {
		farming
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_farming_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_farming_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b4_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			exotic_gases = @b4_rare_cost
		}
		upkeep = {
			energy = @b4_upkeep
			exotic_gases = @b4_rare_upkeep
		}
	}

	planet_modifier = {
		district_farming_max_add = @b4_max_districts_add
	}

	prerequisites = {
		tech_nano_vitality_crops
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_baol_organic_plant = {
	base_buildtime = @b2_time
	planet_limit = 1
	category = resource

	building_sets = {
		farming
		factory
	}

	potential = {
		NOR = {
			is_planet_class = pc_machine
			has_modifier = resort_colony
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_ai = yes
				country_uses_food = no
			}
			is_planet_class = pc_machine
			has_modifier = resort_colony
		}
	}

	inline_script = {
		script = jobs/farmers_add
		AMOUNT = @building_static_jobs
	}
	# for exceptions to the above (i.e. Wilderness):
	inline_script = {
		script = buildings/planet_job_resource_produces_add
		JOB = farmers
		RESOURCE = food
		AMOUNT = 0.25
	}

	# Additional farmer output (non-Archaeoengineering)
	triggered_planet_modifier = {
		potential = {
			owner = {
				country_uses_consumer_goods = yes
			}
		}
		planet_farmers_consumer_goods_produces_add = 0.10
	}
	triggered_planet_modifier = {
		potential = {
			owner = {
				country_uses_consumer_goods = no
			}
		}
		planet_farmers_energy_produces_add = 0.25
	}

	# Additional farmer output (with Archaeoengineering)
	triggered_planet_modifier = {
		potential = {
			owner = {
				country_uses_consumer_goods = yes
				has_ascension_perk = ap_archaeoengineers
			}
		}
		planet_farmers_consumer_goods_produces_add = 0.125
	}
	triggered_planet_modifier = {
		potential = {
			owner = {
				country_uses_consumer_goods = no
				has_ascension_perk = ap_archaeoengineers
			}
		}
		planet_farmers_energy_produces_add = 0.25
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			minor_artifacts = 25
		}
		cost = {
			trigger = {
				owner = { is_wilderness_empire = yes }
			}
			biomass = @b3_biomass
		}
		upkeep = {
			energy = 2
		}
	}

	ai_resource_production = {
		food = 10

		trigger = {
			has_any_agriculture_zone = yes
		}
	}

	inline_script = {
		script = buildings/on_all_wilderness_buildings_districts
	}

	prerequisites = {
		"tech_secrets_baol"
	}
}

building_mine_generic = {
	base_buildtime = @b1_time
	category = resource

	building_sets = {
		mining
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
		}
		NOT = { has_modifier = resort_colony }
		planet = {
			planet_is_habitat_equivalent = no
			planet_is_ring_world_equivalent = no
		}
		OR = {
			has_carrier_flag = ignore_ai_building_limitations
			owner = { is_ai = no }
			# AI is allowed to build up to two of these.
			num_buildings = { type = building_mine_generic value < 2 }
		}
	}
	destroy_trigger = {
		exists = owner
		owner = {
			is_wilderness_empire = yes
		}
	}

	inline_script = {
		script = jobs/miners_add
		AMOUNT = @building_static_jobs
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = 2
		}
	}
	prerequisites = {
		"tech_mechanized_mining"
	}

	ai_weight_coefficient = @static_jobs_ai_weight_coefficient
}

building_mineral_purification_plant = {
	desc = {
		trigger = {
			NOT = { is_planet_class = pc_shattered_ring_habitable }
		}
		text = building_mineral_purification_plant_desc
	}
	desc = {
		trigger = { is_planet_class = pc_shattered_ring_habitable }
		text = building_scrap_processing_plant_desc
	}

	base_buildtime = @b1_time
	planet_limit = 1
	category = resource

	building_sets = {
		mining
		harvest
	}

	potential = {
		owner = { is_wilderness_empire = no } # see 'building_churning_tunnels_3'
		NOR = {
			has_modifier = resort_colony
			is_planet_class = pc_ringworld_habitable
			is_planet_class = pc_cybrex
		}
		OR = {
			NOT = { is_planet_class = pc_habitat }
			AND = {
				is_planet_class = pc_habitat
				check_modifier_value = {
					modifier = district_hab_mining_max_add
					value > 0
				}
			}
		}
		OR = {
			has_carrier_flag = ignore_ai_building_limitations
			owner = { is_ai = no }
			has_any_mining_district_or_building = yes
			owner = { is_nomadic = yes }
		}
	}

	destroy_trigger = {
		OR = {
			has_modifier = resort_colony
			AND = {
				exists = owner
				owner = { is_ai = yes }
				has_any_mining_district_or_building = no
			}
			AND = {
				exists = owner
				owner = { is_wilderness_empire = yes }
			}
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = 200
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = 2
		}
	}

	triggered_planet_modifier = {
		potential = {
			owner? = { is_nomadic = no }
		}
		planet_miners_minerals_produces_add = 0.5
	}

	triggered_planet_modifier = {
		potential = {
			owner? = {
				is_nomadic = yes
				is_gestalt = no
			}
		}
		job_ark_harvester_add = @building_static_jobs
	}

	triggered_planet_modifier = {
		potential = {
			owner? = {
				is_nomadic = yes
				is_gestalt = yes
			}
		}
		job_ark_harvester_gestalt_add = @building_static_jobs
	}

	upgrades = {
		building_mineral_purification_hub
	}

	prerequisites = {
		tech_mineral_purification_1
	}

	ai_resource_production = {
		minerals = 10

		trigger = {
			has_any_mining_zone = yes
		}
	}

	ai_resource_production = {
		minerals = 5
		energy = 10

		trigger = {
			has_zone = {
				zone = zone_betharian
			}
		}
	}

	show_tech_unlock_if = {
		is_wilderness_empire = no
	}
}

building_mineral_purification_hub = {
	desc = {
		trigger = { NOT = { is_planet_class = pc_shattered_ring_habitable } }
		text = building_mineral_purification_hub_desc
	}

	desc = {
		trigger = { is_planet_class = pc_shattered_ring_habitable }
		text = building_scrap_processing_hub_desc
	}

	base_buildtime = @b2_time
	can_build = no
	category = resource

	building_sets = {
		mining
		harvest
	}

	potential = {
		exists = owner
		owner = { is_wilderness_empire = no } # see 'building_churning_tunnels_4'
		OR = {
			owner = { is_ai = no }
			has_any_mining_district_or_building = yes
			owner = { is_nomadic = yes }
		}
	}
	allow = {
		has_upgraded_capital = yes
		NOT = { has_modifier = resort_colony }
	}
	destroy_trigger = {
		OR = {
			has_modifier = resort_colony
			AND = {
				exists = owner
				owner = { is_ai = yes }
				has_any_mining_district_or_building = no
			}
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_with_additional_trigger
			TRIGGER = "has_ringworld_output_boost = no"
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = no
			}
			volatile_motes = @b2_rare_cost
		}
		inline_script = {
			script = buildings/nomadic_cost_switcher_with_additional_trigger
			TRIGGER = "has_ringworld_output_boost = yes"
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = 900
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			volatile_motes = 200
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = no
			}
			energy = 2
			volatile_motes = @b2_rare_upkeep
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			energy = 5
			volatile_motes = 3
		}
	}

	triggered_planet_modifier = {
		potential = {
			owner? = { is_nomadic = no }
			NOT = { is_planet_class = pc_shattered_ring_habitable }
		}
		modifier = {
			planet_miners_minerals_produces_add = 1.0
		}
	}

	triggered_planet_modifier = {
		potential = {
			owner? = { is_nomadic = no }
			is_planet_class = pc_shattered_ring_habitable
		}
		modifier = {
			planet_miners_minerals_produces_add = 0.5
			planet_miners_alloys_produces_add = 0.2
		}
	}

	triggered_planet_modifier = {
		potential = {
			owner? = { is_nomadic = no }
			has_ringworld_output_boost = yes
		}
		modifier = {
			planet_miners_minerals_produces_add = 0.5
		}
	}

	triggered_planet_modifier = {
		potential = {
			owner? = {
				is_nomadic = yes
				is_gestalt = no
			}
		}
		job_ark_harvester_add = @building_static_jobs_high
	}

	triggered_planet_modifier = {
		potential = {
			owner? = {
				is_nomadic = yes
				is_gestalt = yes
			}
		}
		job_ark_harvester_gestalt_add = @building_static_jobs_high
	}

	prerequisites = {
		tech_mineral_purification_2
	}

	ai_resource_production = {
		minerals = 15

		trigger = {
			has_any_mining_zone = yes
		}
	}

	ai_resource_production = {
		minerals = 7.5
		energy = 15

		trigger = {
			has_zone = {
				zone = zone_betharian
			}
		}
	}

	show_tech_unlock_if = {
		is_wilderness_empire = no
	}
}

building_mining_districts_1 = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = resource

	building_sets = {
		mining
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_mining_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_mining_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b1_upkeep
		}
	}

	planet_modifier = {
		district_mining_max_add = @b1_max_districts_add
	}

	upgrades = {
		building_mining_districts_2
	}

	prerequisites = {
		tech_mechanized_mining
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_mining_districts_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = resource

	building_sets = {
		mining
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_mining_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_mining_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			volatile_motes = @b2_rare_cost
		}
		upkeep = {
			energy = @b2_upkeep
			volatile_motes = @b2_rare_upkeep
		}
	}

	planet_modifier = {
		district_mining_max_add = @b2_max_districts_add
	}

	upgrades = {
		building_mining_districts_3
	}

	prerequisites = {
		tech_mining_1
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_mining_districts_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = resource

	building_sets = {
		mining
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_mining_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_mining_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b3_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			volatile_motes = @b3_rare_cost
		}
		upkeep = {
			energy = @b3_upkeep
			volatile_motes = @b3_rare_upkeep
		}
	}

	planet_modifier = {
		district_mining_max_add = @b3_max_districts_add
	}

	upgrades = {
		building_mining_districts_4
	}

	prerequisites = {
		tech_mining_2
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_mining_districts_4 = {
	base_buildtime = @b4_time
	can_build = no
	category = resource

	building_sets = {
		mining
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_mining_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_mining_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b4_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			volatile_motes = @b4_rare_cost
		}
		upkeep = {
			energy = @b4_upkeep
			volatile_motes = @b4_rare_upkeep
		}
	}

	planet_modifier = {
		district_mining_max_add = @b4_max_districts_add
	}

	prerequisites = {
		tech_mining_3
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_generator_generic = {
	base_buildtime = @b1_time
	category = resource

	building_sets = {
		generator
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
		}
		NOT = { has_modifier = resort_colony }
		OR = {
			has_carrier_flag = ignore_ai_building_limitations
			owner = { is_ai = no }
			# AI is allowed to build up to two of these.
			num_buildings = { type = building_generator_generic value < 2 }
		}
	}
	destroy_trigger = {
		exists = owner
		owner = {
			is_wilderness_empire = yes
		}
	}

	inline_script = {
		script = jobs/technicians_add
		AMOUNT = @building_static_jobs
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = 2
		}
	}
	prerequisites = {
		"tech_power_plant_1"
	}

	ai_weight_coefficient = @static_jobs_ai_weight_coefficient
}

building_energy_grid = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = resource

	building_sets = {
		generator
	}

	potential = {
		NOT = { has_modifier = resort_colony }
		exists = owner
		owner = {
			is_wilderness_empire = no # see 'building_bioelectric_stimulator_3'
		}
		OR = {
			NOT = { is_planet_class = pc_habitat }
			AND = {
				is_planet_class = pc_habitat
				check_modifier_value = {
					modifier = district_hab_energy_max_add
					value > 0
				}
			}
		}
		OR = {
			owner = { is_ai = no }
			has_any_generator_district_or_building = yes
		}
	}
	destroy_trigger = {
		OR = {
			has_modifier = resort_colony
			AND = {
				exists = owner
				owner = { is_ai = yes }
				has_any_generator_district_or_building = no
			}
			AND = {
				exists = owner
				owner = { is_wilderness_empire = yes }
			}
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = 2
		}
	}

	planet_modifier = {
		planet_technician_energy_produces_add = 0.5
	}

	prerequisites = {
		tech_power_hub_1
	}

	upgrades = {
		building_energy_nexus
	}

	ai_resource_production = {
		energy = 10

		trigger = {
			has_any_generator_zone = yes
		}
	}

	show_tech_unlock_if = {
		is_wilderness_empire = no
	}
}

building_energy_nexus = {
	base_buildtime = @b2_time
	can_build = no
	category = resource

	building_sets = {
		generator
	}

	potential = {
		NOT = { has_modifier = resort_colony }
		exists = owner
		owner = { is_wilderness_empire = no }
		OR = {
			owner = { is_ai = no }
			has_any_generator_district_or_building = yes
		}
	}
	destroy_trigger = {
		OR = {
			has_modifier = resort_colony
			AND = {
				exists = owner
				owner = { is_ai = yes }
				has_any_generator_district_or_building = no
			}
			AND = {
				exists = owner
				owner = { is_wilderness_empire = yes } # see 'building_bioelectric_stimulator_4'
			}
		}
	}
	allow = {
		has_upgraded_capital = yes
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_with_additional_trigger
			TRIGGER = "has_ringworld_output_boost = no"
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = no
			}
			rare_crystals = @b2_rare_cost
		}
		inline_script = {
			script = buildings/nomadic_cost_switcher_with_additional_trigger
			TRIGGER = "has_ringworld_output_boost = yes"
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = 900
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			rare_crystals = 200
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = no
			}
			energy = 2
			rare_crystals = @b2_rare_upkeep
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			energy = 5
			rare_crystals = 3
		}
	}

	planet_modifier = {
		planet_technician_energy_produces_add = 1.0
	}

	triggered_planet_modifier = {
		potential = {
			has_ringworld_output_boost = yes
		}
		modifier = {
			planet_technician_energy_produces_add = 0.5
		}
	}

	prerequisites = {
		tech_power_hub_2
	}

	ai_resource_production = {
		energy = 15

		trigger = {
			has_any_generator_zone = yes
		}
	}

	show_tech_unlock_if = {
		is_wilderness_empire = no
	}
}

building_generator_districts_1 = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = resource

	building_sets = {
		generator
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_generator_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_generator_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b1_upkeep
		}
	}

	planet_modifier = {
		district_generator_max_add = @b1_max_districts_add
	}

	upgrades = {
		building_generator_districts_2
	}

	prerequisites = {
		tech_power_plant_1
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_generator_districts_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = resource

	building_sets = {
		generator
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_generator_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_generator_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			rare_crystals = @b2_rare_cost
		}
		upkeep = {
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
	}

	planet_modifier = {
		district_generator_max_add = @b2_max_districts_add
	}

	upgrades = {
		building_generator_districts_3
	}

	prerequisites = {
		tech_power_plant_2
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_generator_districts_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = resource

	building_sets = {
		generator
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_generator_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_generator_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b3_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			rare_crystals = @b3_rare_cost
		}
		upkeep = {
			energy = @b3_upkeep
			rare_crystals = @b3_rare_upkeep
		}
	}

	planet_modifier = {
		district_generator_max_add = @b3_max_districts_add
	}

	upgrades = {
		building_generator_districts_4
	}

	prerequisites = {
		tech_power_plant_3
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_generator_districts_4 = {
	base_buildtime = @b4_time
	can_build = no
	category = resource

	building_sets = {
		generator
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			is_nomadic = no
		}
		has_any_capped_planet_generator_district = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_wilderness_empire = yes
			}
			has_any_capped_planet_generator_district = no
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b4_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			rare_crystals = @b4_rare_cost
		}
		upkeep = {
			energy = @b4_upkeep
			rare_crystals = @b4_rare_upkeep
		}
	}

	planet_modifier = {
		district_generator_max_add = @b4_max_districts_add
	}

	prerequisites = {
		tech_power_plant_4
	}

	show_tech_unlock_if = {
		is_nomadic = no
	}
}

building_resource_silo = {
	base_buildtime = 180
	category = resource

	building_sets = {
		generator
		mining
		farming
		urban
		harvest
	}

	potential = {
		NOR = {
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
		exists = owner
		owner = { is_wilderness_empire = no } # see 'building_subterranean_cache'
	}

	allow = {
		exists = owner
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				AND = {
					NOT = { has_building = building_resource_silo }
					OR = {
						owner = {
							is_machine_empire = yes
							has_active_tradition = tr_domination_modular_depot
						}
						is_active_resolution = "resolution_greatergood_balance_in_the_middle"
						is_active_resolution = "resolution_greatergood_universal_prosperity_mandate"
						owner = {
							has_ascension_perk = ap_arcology_project
							NOT = { has_technology = tech_mega_engineering }
						}
						owner = { country_near_tangible_resource_cap = yes }
					}
				}
			}
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = 200
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = 1
		}
	}

	country_modifier = {
		country_resource_max_add = 5000
	}

	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = {
				has_technology = tech_construction_templates
			}
		}
		country_resource_max_add = 5000
	}

	triggered_country_modifier = {
		potential = {
			owner? = {
				is_nomadic = yes
			}
		}
		situation_nomad_economy_max_progress_add = 500
	}

	triggered_country_modifier = {
		potential = {
			owner? = {
				is_nomadic = yes
				has_technology = tech_construction_templates
			}
		}
		situation_nomad_economy_max_progress_add = 500
	}

	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = {
				has_valid_civic = civic_machine_obsessional_directive
			}
		}
		country_resource_max_consumer_goods_add = 5000
	}

	prerequisites = {
		"tech_basic_industry"
	}
	show_tech_unlock_if = {
		is_wilderness_empire = no
	}
}

building_bio_reactor = {
	base_buildtime = @b1_time
	planet_limit = 1

	category = resource

	building_sets = {
		farming
	}

	potential = {
		exists = owner
		owner = { is_wilderness_empire = no }
		NOR = {
			is_planet_class = pc_machine
			has_modifier = resort_colony
		}
		OR = {
			owner = {
				is_ai = no
			}
			has_any_farming_district_or_building = yes
		}
		owner = {
			OR = {
				is_ai = no
				country_uses_food = yes
			}
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_ai = yes
				country_uses_food = no
			}
			is_planet_class = pc_machine
			has_modifier = resort_colony
			AND = {
				owner = {
					is_ai = yes
				}
				has_any_farming_district_or_building = no
			}
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			food = @b1_upkeep
		}
	}

	planet_modifier = {
		planet_farmers_food_produces_add = -2
		planet_farmers_energy_produces_add = 2
	}

	upgrades = {
		building_bio_reactor_2
	}

	prerequisites = {
		"tech_bio_reactor"
	}
}

building_bio_reactor_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = resource

	building_sets = {
		farming
	}

	allow = {
		has_upgraded_capital = yes
	}

	potential = {
		exists = owner
		owner = { is_wilderness_empire = no }
		NOR = {
			is_planet_class = pc_machine
			has_modifier = resort_colony
		}
		OR = {
			owner = {
				is_ai = no
			}
			has_any_farming_district_or_building = yes
		}
		owner = {
			OR = {
				is_ai = no
				country_uses_food = yes
			}
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_ai = yes
				country_uses_food = no
			}
			is_planet_class = pc_machine
			has_modifier = resort_colony
			AND = {
				owner = {
					is_ai = yes
				}
				has_any_farming_district_or_building = no
			}
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			food = @b2_upkeep
		}
	}

	planet_modifier = {
		planet_farmers_food_produces_add = -3
		planet_farmers_energy_produces_add = 2
		planet_farmers_exotic_gases_produces_add = 0.1
	}

	prerequisites = {
		"tech_bio_reactor_2"
	}
}
