	#############
# Robot buildings
#############

building_robot_assembly_plant = {
	base_buildtime = @b1_time
	planet_limit = 1

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		owner = {
			is_regular_empire = yes
			is_individual_machine = no
			NOT = { has_policy_flag = robots_outlawed }
			OR = {
				is_ai = no
				NOT = { has_ascension_perk = ap_engineered_evolution }
				is_materialist = yes
			}
		}
		NOT = {	has_modifier = resort_colony }
	}

	convert_to = {
		building_machine_assembly_plant
	}

	upgrades = {
		building_robot_assembly_complex
	}

	allow = {
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				NAND = {
					free_district_slots = 0
					free_building_slots <= 1
					free_housing <= 0
					free_jobs <= 0
				}
			}
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					is_regular_empire = no
					has_policy_flag = robots_outlawed
				}
			}
			AND = {
				owner = { is_ai = yes }
				free_district_slots = 0
				free_building_slots = 0
				free_housing <= 0
				free_jobs <= 0
			}
			owner = {
				is_ai = yes
				has_ascension_perk = ap_engineered_evolution
				is_materialist = no
			}
		}
	}

	inline_script = {
		script = jobs/roboticist_add
		AMOUNT = @building_static_jobs_low
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				OR = {
					has_origin = origin_mechanists
					is_individual_machine = yes
					has_country_flag = synthetic_empire
				}
			}
			any_owned_pop_group = {
				has_auto_modding_trait = yes
			}
		}
		modifier = {
			auto_mod_monthly_add = 200
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_unscheduled_updates
			}
		}
		modifier = {
			planet_pop_assembly_mult = 0.1
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_safe_updates
			}
		}
		modifier = {
			planet_pop_assembly_mult = -0.1
			planet_stability_add = 2
		}
	}

	### JOB STRATA FOCUS MODIFIERS ###
	triggered_planet_modifier = { # Synth ruler focus
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_focus_rulers
			}
		}
		modifier = {
			planet_jobs_ruler_produces_mult = 0.15
		}
	}

	triggered_planet_modifier = { # Synth specialist focus
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_focus_specialists
			}
		}
		modifier = {
			planet_jobs_specialist_produces_mult = 0.05
		}
	}

	triggered_planet_modifier = { # Synth worker focus
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_focus_workers
			}
		}
		modifier = {
			planet_jobs_worker_produces_mult = 0.10
		}
	}

	triggered_planet_modifier = { # Synth upkeep focus
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_focus_upkeep
			}
		}
		modifier = {
			planet_jobs_upkeep_mult = -0.05
		}
	}

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

	prerequisites = {
		"tech_robotic_workers"
	}
}

building_robot_assembly_complex = {
	icon = building_machine_assembly_complex
	base_buildtime = @b3_time
	can_build = no

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		owner = {
			is_regular_empire = yes
			is_individual_machine = no
			NOT = { has_policy_flag = robots_outlawed }
			OR = {
				is_ai = no
				NOT = { has_ascension_perk = ap_engineered_evolution }
				is_materialist = yes
			}
		}
	}

	convert_to = {
		building_machine_assembly_complex
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					is_regular_empire = no
					has_policy_flag = robots_outlawed
				}
			}
			AND = {
				owner = { is_ai = yes }
				free_district_slots = 0
				free_building_slots = 0
				free_housing <= 0
				free_jobs <= 0
			}
			owner = {
				is_ai = yes
				has_ascension_perk = ap_engineered_evolution
				is_materialist = no
			}
		}
	}

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

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				OR = {
					has_origin = origin_mechanists
					is_individual_machine = yes
					has_country_flag = synthetic_empire
				}
			}
			any_owned_pop_group = {
				has_auto_modding_trait = yes
			}
		}
		modifier = {
			auto_mod_monthly_add = 400
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_unscheduled_updates
			}
		}
		modifier = {
			planet_pop_assembly_mult = 0.1
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_safe_updates
			}
		}
		modifier = {
			planet_pop_assembly_mult = -0.1
			planet_stability_add = 2
		}
	}

	### JOB STRATA FOCUS MODIFIERS ###
	triggered_planet_modifier = { # Synth ruler focus
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_focus_rulers
			}
		}
		modifier = {
			planet_jobs_ruler_produces_mult = 0.15
		}
	}

	triggered_planet_modifier = { # Synth specialist focus
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_focus_specialists
			}
		}
		modifier = {
			planet_jobs_specialist_produces_mult = 0.05
		}
	}

	triggered_planet_modifier = { # Synth worker focus
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_focus_workers
			}
		}
		modifier = {
			planet_jobs_worker_produces_mult = 0.10
		}
	}

	triggered_planet_modifier = { # Synth upkeep focus
		potential = {
			exists = owner
			owner = {
				has_country_flag = synth_focus_upkeep
			}
		}
		modifier = {
			planet_jobs_upkeep_mult = -0.05
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			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
		}
	}

	prerequisites = {
		tech_robot_assembly_complex
	}
}

#############
# Machine buildings
#############

building_machine_assembly_plant = {
	icon = building_robot_assembly_plant
	base_buildtime = @b1_time
	planet_limit = 1

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		owner = {
			OR = {
				is_machine_empire = yes
				is_individual_machine = yes
				is_hive_empire_with_machines = yes
			}
		}
		NOT = {
			has_modifier = resort_colony
		}
	}

	convert_to = {
		building_robot_assembly_plant
	}

	allow = {
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				NAND = {
					free_district_slots = 0
					free_building_slots <= 1
					free_housing <= 0
					free_jobs <= 0
				}
			}
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_robot_empire = no
				is_hive_empire_with_machines = no
			}
			AND = {
				owner = { is_ai = yes }
				free_district_slots = 0
				free_building_slots = 0
				free_housing <= 0
				free_jobs <= 0
			}
		}
	}

	inline_script = {
		script = jobs/roboticist_add
		AMOUNT = @building_static_jobs_low
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				OR = {
					is_machine_empire = yes
					is_individual_machine = yes
				}
			}
			any_owned_pop_group = {
				has_auto_modding_trait = yes
			}
		}
		modifier = {
			auto_mod_monthly_add = 200
		}
	}

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

	upgrades = {
		building_machine_assembly_complex
	}

	prerequisites = {

	}

}

building_machine_assembly_complex = {
	base_buildtime = @b3_time
	can_build = no

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		owner = {
			OR = {
				is_machine_empire = yes
				is_individual_machine = yes
				is_hive_empire_with_machines = yes
			}
		}
		NOT = {
			has_modifier = resort_colony
		}
	}

	convert_to = {
		building_robot_assembly_complex
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_robot_empire = no
				is_hive_empire_with_machines = no
			}
			AND = {
				owner = { is_ai = yes }
				free_district_slots = 0
				free_building_slots = 0
				free_housing <= 0
				free_jobs <= 0
			}
		}
	}

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

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				OR = {
					is_machine_empire = yes
					is_individual_machine = yes
				}
			}
			any_owned_pop_group = {
				has_auto_modding_trait = yes
			}
		}
		modifier = {
			auto_mod_monthly_add = 400
		}
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			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
		}
	}

	prerequisites = {
		tech_mega_assembly
	}
}

#############
# Hive buildings
#############

building_spawning_pool = {
	base_buildtime = @b1_time
	planet_limit = 1

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		owner = {
			is_hive_empire = yes
			is_wilderness_empire = no
			NOT = { has_origin = origin_progenitor_hive }
		}
	}

	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_hive_empire = no
				has_origin = origin_progenitor_hive
			}
		}
	}

	inline_script = {
		script = jobs/spawning_drone_add
		AMOUNT = @building_static_jobs_low
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_technology = tech_gene_tailoring
			}
			any_owned_pop_group = {
				has_auto_modding_trait = yes
			}
		}
		modifier = {
			auto_mod_monthly_add = 200
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				game_start_auto_mod_empire = yes
			}
			any_owned_pop_group = {
				has_auto_modding_trait = yes
			}
		}
		modifier = {
			auto_mod_monthly_add = 200
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { has_active_tradition = tr_cybernetics_synaptic_sub_processing }
		}
		modifier = {
			job_augmentor_drone_add = 200
		}
	}

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

	convert_to = {
		building_offspring_nest
	}

	triggered_desc = {
		text = spawning_pool_tooltip
	}
}

building_offspring_nest = {
	base_buildtime = @b1_time
	planet_limit = 1

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	potential = {
		owner? = {
			has_origin = origin_progenitor_hive
		}
	}

	allow = {
		NOT = {
			fleet.starbase? = {
				has_starbase_building = arkship_offspring_outlook
			}
		}
	}

	destroy_trigger = {
		OR = {
			owner? = {
				NOT = {
					has_origin = origin_progenitor_hive
				}
			}
			fleet.starbase? = {
				has_starbase_building = arkship_offspring_outlook
			}
		}
	}

	#ruined_trigger = {
	#	has_carrier_flag = offspring_defeated
	#}

	inline_script = {
		script = jobs/spawning_drone_add
		AMOUNT = @building_static_jobs_low
	}

	convert_to = {
		building_spawning_pool
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { has_active_tradition = tr_cybernetics_synaptic_sub_processing }
		}
		modifier = {
			job_augmentor_drone_add = 200
		}
	}

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

	triggered_desc = {
		text = offspring_nest_tooltip
	}
}

#######################################
# Necrophage "consumption" buildings
#######################################

building_necrophage_elevation_chamber = {
	icon = building_chamber_of_elevation_1
	base_buildtime = @b1_time
	planet_limit = 1
	position_priority = 100
	skip_automation_upgrading = yes #colony automation will not try to upgrade this

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	desc = {
		trigger = {
			OR = {
				NOT = { exists = owner }
				owner = { is_hive_empire = no }
			}
		}
		text = building_necrophage_elevation_chamber_desc
	}
	desc = {
		trigger = {
			exists = owner
			owner = { is_hive_empire = yes }
		}
		text = building_necrophage_elevation_chamber_desc_hive
	}

	potential = {
		exists = owner
		owner = {
			has_origin = origin_necrophage
			has_trait = trait_necrophage
			NOR = {
				has_valid_civic = civic_fanatic_purifiers
				has_valid_civic = civic_hive_devouring_swarm
			}
		}
	}

	allow = {
		custom_tooltip = {
			fail_text = NO_CULTURE_SHOCK
			NOT = { has_modifier = planet_culture_shock }
		}
		if = {
			limit = { owner = { is_hive_empire = no } }
			NOT = { is_planet_class = pc_hive }
		}
		NOT = { is_planet_class = pc_machine }
		hidden_trigger = {
			if = {
				limit = {
					owner = { is_ai = yes }
				}
				any_owned_species = {
					species_can_be_necrophaged = yes
				}
				pop_amount > 500
			}
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					NOT = { has_origin = origin_necrophage }
					NOT = { has_trait = trait_necrophage }
				}
			}
			AND = {
				owner = { is_ai = yes }
				NOT = {
					any_owned_species = {
						species_can_be_necrophaged = yes
					}
				}
			}
		}
	}

	planet_modifier = {
		job_necro_apprentice_add = 100
	}

	#you are not meant to run out of necrophaging pops on a planet with this building
	triggered_planet_modifier = {
		potential = {
			organic_pops_last_month_growth >= 1
		}
		job_necro_apprentice_add = 100
	}
	triggered_planet_modifier = {
		potential = {
			organic_pops_last_month_growth >= 2
		}
		job_necro_apprentice_add = 100
	}

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

	upgrades = {
		building_necrophage_house_of_apotheosis
	}

	prerequisites = {
	}

	triggered_desc = {
		text = necrophage_elevation_timer_tooltip
		trigger = {
			has_carrier_flag = necrophage_elevation_timer
		}
	}

	triggered_desc = {
		text = building_necrophage_elevation_chamber_scaling_tooltip
	}

	triggered_desc = {
		text = disables_necrophage_growth
	}

	is_essential = yes
}

building_necrophage_house_of_apotheosis = {
	icon = building_chamber_of_elevation_2
	base_buildtime = @b3_time
	can_build = no
	position_priority = 100

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	desc = {
		trigger = {
			OR = {
				NOT = { exists = owner }
				owner = { is_hive_empire = no }
			}
		}
		text = building_necrophage_house_of_apotheosis_desc
	}
	desc = {
		trigger = {
			exists = owner
			owner = { is_hive_empire = yes }
		}
		text = building_necrophage_house_of_apotheosis_desc_hive
	}

	potential = {
		exists = owner
		owner = {
			has_origin = origin_necrophage
			has_trait = trait_necrophage
			NOR = {
				has_valid_civic = civic_fanatic_purifiers
				has_valid_civic = civic_hive_devouring_swarm
			}
			is_ai = no #the AI will just kill all its necrophytes
		}
	}

	allow = {
		hidden_trigger = {
			if = {
				limit = {
					owner = { is_ai = yes }
				}
				any_owned_species = {
					species_can_be_necrophaged = yes
				}
			}
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					NOT = { has_origin = origin_necrophage }
					NOT = { has_trait = trait_necrophage }
				}
			}
			AND = {
				owner = { is_ai = yes }
				NOT = {
					any_owned_species = {
						species_can_be_necrophaged = yes
					}
				}
			}
		}
	}

	planet_modifier = {
		job_necro_apprentice_add = 600
	}

	triggered_planet_modifier = {
		potential = {
			is_planet_class = pc_hive
			exists = owner
			owner = { is_hive_empire = yes }
		}
		job_necro_apprentice_add = 400
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			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
		}
	}

	prerequisites = {
		tech_glandular_acclimation
	}

	show_tech_unlock_if = {
		has_origin = origin_necrophage
		has_trait = trait_necrophage
	}

	triggered_desc = {
		text = disables_necrophage_growth
	}

	triggered_desc = {
		text = necrophage_elevation_timer_tooltip
		trigger = {
			has_carrier_flag = necrophage_elevation_timer
		}
	}
}

#############
# Clone vats
#############

building_clone_vats = {
	base_buildtime = @b1_time

	category = pop_assembly

	planet_limit = {
		base = 1
		modifier = {
			exists = owner
			owner = {
				has_tradition = tr_cloning_finish
			}
			has_upgraded_capital = yes
			add = 1
		}
		modifier = {
			exists = owner
			owner = {
				has_tradition = tr_cloning_finish
			}
			has_major_upgraded_capital = yes
			add = 1
		}
		modifier = {
			exists = owner
			owner = {
				has_tradition = tr_cloning_finish
			}
			has_fully_upgraded_capital = yes
			add = 1
		}
	}

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		NOT = { has_modifier = resort_colony }
		OR = {
			owner = { is_ai = no }
			NAND = {
				free_district_slots = 0
				free_building_slots <= 1
				free_housing <= 0
				free_jobs <= 0
			}
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			AND = {
				owner = { is_ai = yes }
				free_district_slots = 0
				free_building_slots = 0
				free_housing <= 0
				free_jobs <= 0
			}
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_technology = tech_gene_tailoring
			}
			any_owned_pop_group = {
				has_auto_modding_trait = yes
			}
		}
		modifier = {
			auto_mod_monthly_add = 200
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				game_start_auto_mod_empire = yes
			}
			any_owned_pop_group = {
				has_auto_modding_trait = yes
			}
		}
		modifier = {
			auto_mod_monthly_add = 200
		}
	}

	inline_script = {
		script = output/bonus_pop_growth
		TRIGGER = "owner? = {
			has_cloning_tradition = no
		}"
		AMOUNT = 1.5
	}

	inline_script = {
		script = output/bonus_pop_growth
		TRIGGER = "owner? = {
			has_cloning_tradition = yes
			NOT = {
				has_tradition = tr_genetics_efficient_cloning
			}
		}"
		AMOUNT = 3
	}

	inline_script = {
		script = output/bonus_pop_growth
		TRIGGER = "owner? = {
			has_cloning_tradition = yes
			has_tradition = tr_genetics_efficient_cloning
		}"
		AMOUNT = 4.5
	}

	inline_script = {
		script = output/bonus_pop_growth
		TRIGGER = "owner? = {
			has_country_flag = has_hall_module_propagation
		}"
		AMOUNT = @galactic_hall_module_propagation_assembly
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_country_flag = clone_army_full_potential
				has_active_tradition = tr_cloning_adopt_clone_army
			}
		}
		clone_soldiers_sustained = @clones_sustained_low
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_country_flag = clone_army_full_potential
				has_active_tradition = tr_cloning_finish_clone_army
			}
		}
		clone_soldiers_sustained = @clones_sustained_low
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_ascension_perk = ap_total_assimilation
			}
		}
		modifier = {
			bonus_pop_growth = 2
		}
	}

	resources = {
		category = planet_buildings_clone_vats

		# Base cost
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = 500
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		# Organic/Lithoid/infernal cost
		cost = {
			trigger = {
				exists = owner
				owner = { is_lithoid_or_infernal_empire = no }
				NOT = {
					owner = { has_ascension_perk = ap_plentiful_traditions_vast_slave_procreation }
					OR = {
						has_building = building_plentiful_traditions_advanced_slave_processing
						has_building = building_slave_processing
					}
				}
			}
			food = 500
		}
		cost = {
			trigger = {
				exists = owner
				owner = { is_lithoid_or_infernal_empire = yes }
				NOT = {
					owner = { has_ascension_perk = ap_plentiful_traditions_vast_slave_procreation }
					OR = {
						has_building = building_plentiful_traditions_advanced_slave_processing
						has_building = building_slave_processing
					}
				}
			}
			energy = 500
		}
		
				# Org/Lith cost mit Perk etc.
		cost = {
			trigger = {
				exists = owner
				owner = { is_lithoid_or_infernal_empire = no }
				owner = { has_ascension_perk = ap_plentiful_traditions_vast_slave_procreation }
				OR = {
					has_building = building_plentiful_traditions_advanced_slave_processing
					has_building = building_slave_processing
				}
			}
			food = 250
		}
		inline_script = {
			script = buildings/nomadic_cost_switcher_with_additional_trigger
			TRIGGER = "owner? = { is_lithoid_or_infernal_empire = yes }"
			REGULAR_RESOURCE = energy
			NOMADIC_RESOURCE = rare_crystals
			COST = 500
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}

		# Base upkeep
		upkeep = {
			energy = 2
		}
		# Organic/Lithoid/infernal upkeep
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_lithoid_or_infernal_empire = no
				}
				NOT = {
					owner = { has_ascension_perk = ap_plentiful_traditions_vast_slave_procreation }
					OR = {
						has_building = building_plentiful_traditions_advanced_slave_processing
						has_building = building_slave_processing
					}
				}
			}
			food = 15
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_lithoid_or_infernal_empire = no
					has_cloning_tradition = yes
				}
				NOT = {
					owner = { has_ascension_perk = ap_plentiful_traditions_vast_slave_procreation }
					OR = {
						has_building = building_plentiful_traditions_advanced_slave_processing
						has_building = building_slave_processing
					}
				}
			}
			food = 15
		}
		# Org/Lith upkeep mit Perk
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_lithoid_or_infernal_empire = no
					has_cloning_tradition = yes
				}
				owner = { has_ascension_perk = ap_plentiful_traditions_vast_slave_procreation }
				OR = {
					has_building = building_plentiful_traditions_advanced_slave_processing
					has_building = building_slave_processing
				}
			}
			food = 15
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_lithoid_or_infernal_empire = yes
				}
				owner = { has_ascension_perk = ap_plentiful_traditions_vast_slave_procreation }
				OR = {
					has_building = building_plentiful_traditions_advanced_slave_processing
					has_building = building_slave_processing
				}
			}
			minerals = 15
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_infernal_empire = yes
				}
			}
			alloys = @b2_alloy_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_infernal_empire = yes
					has_cloning_tradition = yes
				}
			}
			alloys = @b2_alloy_upkeep
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_cloning_authority = yes
				is_megacorp = yes
			}
		}
		planet_jobs_trade_produces_mult = @replicatory_association_trade_mult
		planet_amenities_add = @replicatory_association_amenities_add
	}

	prerequisites = {
		tech_cloning
	}

}

building_clone_army_clone_vat = {
	icon = building_ancient_relics
	base_buildtime = 90
	position_priority = 100

	empire_limit = {
		base = 5
	}

	category = pop_assembly

	building_sets = {
		origin
	}

	potential = {
		exists = owner
		owner = {
			has_origin = origin_clone_army
			NOT = {
				has_country_flag = clone_army_fertility_unlocked
			}
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					NOT = { has_origin = origin_clone_army }
					is_synthetic_empire = yes
					has_country_flag = clone_army_fertility_unlocked
				}
			}
		}
	}

	planet_modifier = {
		clone_soldiers_sustained = @clones_sustained_high
	}

	# Add growth from 0 to 20 depending on 'clone_pops_missing_per_vat'.
	triggered_planet_pop_group_modifier_for_species = {
		potential = {
			has_infertile_clone_soldier_trait = yes
			planet = {
				check_variable = { which = clone_pops_missing_per_vat value > 2200 }
			}
		}
		bonus_pop_growth = 20
	}
	triggered_planet_modifier = {
		potential = {
			check_variable = { which = clone_pops_missing_per_vat value > 2200 }
		}
		fake_pop_growth_mod = 20
	}

	inline_script = {
		script = buildings/clone_army_vat_output
		UPPER_LIMIT = 2200
		LOWER_LIMIT = 2000
		GROWTH = 19
	}

	inline_script = {
		script = buildings/clone_army_vat_output
		UPPER_LIMIT = 2000
		LOWER_LIMIT = 1800
		GROWTH = 17
	}

	inline_script = {
		script = buildings/clone_army_vat_output
		UPPER_LIMIT = 1800
		LOWER_LIMIT = 1600
		GROWTH = 14
	}

	inline_script = {
		script = buildings/clone_army_vat_output
		UPPER_LIMIT = 1600
		LOWER_LIMIT = 1400
		GROWTH = 12
	}

	inline_script = {
		script = buildings/clone_army_vat_output
		UPPER_LIMIT = 1400
		LOWER_LIMIT = 1200
		GROWTH = 9
	}

	inline_script = {
		script = buildings/clone_army_vat_output
		UPPER_LIMIT = 1200
		LOWER_LIMIT = 1000
		GROWTH = 7
	}

	inline_script = {
		script = buildings/clone_army_vat_output
		UPPER_LIMIT = 1000
		LOWER_LIMIT = 800
		GROWTH = 5
	}

	inline_script = {
		script = buildings/clone_army_vat_output
		UPPER_LIMIT = 800
		LOWER_LIMIT = 600
		GROWTH = 4
	}

	triggered_planet_pop_group_modifier_for_species = {
		potential = {
			has_infertile_clone_soldier_trait = yes
			planet = {
				check_variable = { which = clone_pops_missing_per_vat value <= 600 }
			}
		}
		bonus_pop_growth = 2
	}
	triggered_planet_modifier = {
		potential = {
			check_variable = { which = clone_pops_missing_per_vat value <= 600 }
		}
		fake_pop_growth_mod = 2
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_cloning_authority = yes
				is_megacorp = yes
			}
		}
		planet_jobs_trade_produces_mult = @replicatory_association_trade_mult
		planet_amenities_add = @replicatory_association_amenities_add
		mult = 2
	}

	resources = {
		category = planet_buildings_clone_vats
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b2_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_lithoid_or_infernal_empire = no
				}
			}
			food = @b2_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_lithoid_empire = yes
				}
			}
			minerals = @b2_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					is_infernal_empire = yes
				}
			}
			alloys = @b2_alloy_upkeep
		}
	}

	upgrades = {
	}

	prerequisites = {
	}

	triggered_desc = {
		text = building_clone_army_clone_vat_effect_desc
	}

	is_essential = yes
	ai_estimate_without_unemployment = yes
}

#############
# Permanent Employment Building
#############

building_posthumous_employment_center = {
	base_buildtime = @b1_time
	planet_limit = 1

	category = pop_assembly

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		OR = {
			owner = { is_ai = no }
			NAND = {
				free_district_slots = 0
				free_building_slots <= 1
				free_housing <= 0
				free_jobs <= 0
			}
		}
		owner = {
			is_regular_empire = yes
			has_valid_civic = civic_permanent_employment
		}
	}

	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				NOT = { has_valid_civic = civic_permanent_employment }
			}
			AND = {
				owner = { is_ai = yes }
				free_district_slots = 0
				free_building_slots = 0
				free_housing <= 0
				free_jobs <= 0
			}
		}
	}

	planet_modifier = {
		job_reassigner_add = 100
	}

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

building_automation_technician_1 = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = pop_assembly
	icon = building_automation_1

	building_sets = {
		generator_automation
	}

	potential = {
		owner = {
			is_wilderness_empire = no
			is_tankbound_empire = no
		}
	}

	upgrades = {
		building_automation_technician_2
	}

	allow = {
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				NAND = {
					free_district_slots = 0
					free_building_slots <= 1
					free_housing <= 0
					free_jobs <= 0
				}
			}
		}
	}

	destroy_trigger = {
		owner = {
			OR = {
				is_wilderness_empire = yes
				is_tankbound_empire = yes
			}
		}
	}

	planet_modifier = {
		job_technician_automated_workforce_mult = 0.25
		job_technician_drone_automated_workforce_mult = 0.25
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b3_upkeep
		}
	}

	prerequisites = {
		tech_assembly_pattern
	}

	show_tech_unlock_if = {
		always = no
	}
}

building_automation_technician_2 = {
	base_buildtime = @b2_time
	can_build = no
	planet_limit = 1
	category = pop_assembly
	icon = building_automation_2

	building_sets = {
		generator_automation
	}

	potential = {
		owner = {
			is_wilderness_empire = no
			is_tankbound_empire = no
		}
	}

	allow = {
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				NAND = {
					free_district_slots = 0
					free_building_slots <= 1
					free_housing <= 0
					free_jobs <= 0
				}
			}
		}
	}

	destroy_trigger = {
		owner = {
			OR = {
				is_wilderness_empire = yes
				is_tankbound_empire = yes
			}
		}
	}

	planet_modifier = {
		job_technician_automated_workforce_mult = 0.50
		job_technician_drone_automated_workforce_mult = 0.50
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b4_upkeep
		}
	}

	prerequisites = {
		tech_construction_templates
	}

	show_tech_unlock_if = {
		always = no
	}
}

building_automation_miner_1 = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = pop_assembly
	icon = building_automation_1

	building_sets = {
		mining_automation
	}

	potential = {
		owner = {
			is_wilderness_empire = no
			is_tankbound_empire = no
		}
	}

	upgrades = {
		building_automation_miner_2
	}

	allow = {
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				NAND = {
					free_district_slots = 0
					free_building_slots <= 1
					free_housing <= 0
					free_jobs <= 0
				}
			}
		}
	}

	destroy_trigger = {
		owner = {
			OR = {
				is_wilderness_empire = yes
				is_tankbound_empire = yes
			}
		}
	}

	planet_modifier = {
		job_miner_automated_workforce_mult = 0.25
		job_mining_drone_automated_workforce_mult = 0.25
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b3_upkeep
		}
	}

	prerequisites = {
		tech_assembly_pattern
	}

	show_tech_unlock_if = {
		always = no
	}
}

building_automation_miner_2 = {
	base_buildtime = @b2_time
	can_build = no
	planet_limit = 1
	category = pop_assembly
	icon = building_automation_2

	building_sets = {
		mining_automation
	}

	potential = {
		owner = {
			is_wilderness_empire = no
			is_tankbound_empire = no
		}
	}

	allow = {
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				NAND = {
					free_district_slots = 0
					free_building_slots <= 1
					free_housing <= 0
					free_jobs <= 0
				}
			}
		}
	}

	destroy_trigger = {
		owner = {
			OR = {
				is_wilderness_empire = yes
				is_tankbound_empire = yes
			}
		}
	}

	planet_modifier = {
		job_miner_automated_workforce_mult = 0.50
		job_mining_drone_automated_workforce_mult = 0.50
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b4_upkeep
		}
	}

	prerequisites = {
		tech_construction_templates
	}

	show_tech_unlock_if = {
		always = no
	}
}

building_automation_farmer_1 = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = pop_assembly
	icon = building_automation_1

	building_sets = {
		farming_automation
	}

	potential = {
		owner = {
			is_wilderness_empire = no
			is_tankbound_empire = no
		}
	}

	upgrades = {
		building_automation_farmer_2
	}

	allow = {
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				NAND = {
					free_district_slots = 0
					free_building_slots <= 1
					free_housing <= 0
					free_jobs <= 0
				}
			}
		}
	}

	destroy_trigger = {
		owner = {
			OR = {
				is_wilderness_empire = yes
				is_tankbound_empire = yes
			}
		}
	}

	planet_modifier = {
		job_farmer_automated_workforce_mult = 0.25
		job_agri_drone_automated_workforce_mult = 0.25
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b3_upkeep
		}
	}

	prerequisites = {
		tech_assembly_pattern
	}

	show_tech_unlock_if = {
		always = no
	}
}

building_automation_farmer_2 = {
	base_buildtime = @b2_time
	can_build = no
	planet_limit = 1
	category = pop_assembly
	icon = building_automation_2

	building_sets = {
		farming_automation
	}

	potential = {
		owner = {
			is_wilderness_empire = no
			is_tankbound_empire = no
		}
	}

	allow = {
		hidden_trigger = {
			OR = {
				owner = { is_ai = no }
				NAND = {
					free_district_slots = 0
					free_building_slots <= 1
					free_housing <= 0
					free_jobs <= 0
				}
			}
		}
	}

	destroy_trigger = {
		owner = {
			OR = {
				is_wilderness_empire = yes
				is_tankbound_empire = yes
			}
		}
	}

	planet_modifier = {
		job_farmer_automated_workforce_mult = 0.50
		job_agri_drone_automated_workforce_mult = 0.50
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b4_upkeep
		}
	}

	prerequisites = {
		tech_construction_templates
	}

	show_tech_unlock_if = {
		always = no
	}

	triggered_desc = {
		text = automation_2_tooltip
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { is_tankbound_empire = yes }
			NOT = { uses_district_set = ring_world }
		}
		text = automation_farming_tankbound_tooltip
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { is_tankbound_empire = yes }
			uses_district_set = ring_world
		}
		text = automation_rw_tankbound_tooltip
	}
}

building_automation_1 = { # exists for tech tooltip mostly
	base_buildtime = @b1_time
	district_limit = 1
	category = pop_assembly

	building_sets = {
		automation
	}

	potential = {
		always = no
	}

	upgrades = {
		building_automation_2
	}

	allow = {
		always = no
	}

	planet_modifier = {
		district_automated_workforce = 0.25
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b3_upkeep
		}
	}

	prerequisites = {
		tech_assembly_pattern
	}

	show_tech_unlock_if = {
		is_wilderness_empire = no
		is_tankbound_empire = no
	}

	triggered_desc = {
		text = automation_tooltip
	}
}

building_automation_2 = { # exists for tech tooltip mostly
	base_buildtime = @b2_time
	can_build = no
	category = pop_assembly

	building_sets = {
		government
		urban
		farming
		mining
		generator
	}

	potential = {
		always = no
	}

	allow = {
		always = no
	}

	planet_modifier = {
		district_automated_workforce = 0.5
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b4_upkeep
		}
	}

	prerequisites = {
		tech_construction_templates
	}

	show_tech_unlock_if = {
		is_wilderness_empire = no
		is_tankbound_empire = no
	}

	triggered_desc = {
		text = automation_2_tooltip
	}
}
