##################
# Unity buildings
##################

# Regular empire
building_autochthon_monument = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOR = {
			has_modifier = slave_colony
			has_modifier = penal_colony
		}
		owner = {
			is_gestalt = no
			is_megacorp = no
			can_have_default_memorial = yes
		}
		owner = {
			is_ai = no
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_gestalt = yes
					is_megacorp = yes
					can_have_default_memorial = no
				}
			}
		}
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 1
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.05
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_low
	}

	triggered_planet_modifier = {
		potential = { has_force_of_will_dlc = yes }
		pop_government_ethic_attraction = 0.50
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner = {
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	triggered_desc = {
		text = building_autochthon_monument_effect
	}

	prerequisites = {
		"tech_cultural_heritage"
	}

	convert_to = {
		building_corporate_monument
		building_simulation_1
		building_galactic_memorial_1
		building_sensorium_1
		building_lifecrypt_1
		building_lifecrypt_machine_1
		building_lifecrypt_hive_mind_1
		building_lifecrypt_corporate_1
		building_avatar_chamber_1
	}

	show_tech_unlock_if = {
		is_gestalt = no
		is_megacorp = no
		can_have_default_memorial = yes
	}

	ai_resource_production = {
		unity = 10
	}

	upgrades = {
		building_heritage_site
	}
}

building_heritage_site = {
	base_buildtime = @b2_time
	can_build = no
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOR = {
			has_modifier = slave_colony
			has_modifier = penal_colony
		}
		owner = {
			is_gestalt = no
			is_megacorp = no
			can_have_default_memorial = yes
		}
	}

	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_gestalt = yes
					is_megacorp = yes
					can_have_default_memorial = no
				}
			}
		}
	}

	convert_to = {
		building_corporate_site
		building_simulation_2
		building_galactic_memorial_2
		building_sensorium_2
		building_lifecrypt_2
		building_lifecrypt_machine_2
		building_lifecrypt_hive_mind_2
		building_lifecrypt_corporate_2
		building_avatar_chamber_2
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 2
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.10
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs
	}

	triggered_planet_modifier = {
		potential = { has_force_of_will_dlc = yes }
		pop_government_ethic_attraction = 0.50
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner? = {
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	triggered_desc = {
		text = building_heritage_site_effect
	}

	prerequisites = {
		"tech_heritage_site"
	}

	show_tech_unlock_if = {
		is_gestalt = no
		is_megacorp = no
		can_have_default_memorial = yes
	}

	ai_resource_production = {
		unity = 15
	}

	upgrades = {
		building_hypercomms_forum
	}
}

building_hypercomms_forum = {
	base_buildtime = @b3_time
	can_build = no

	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOR = {
			has_modifier = slave_colony
			has_modifier = penal_colony
		}
		owner = {
			is_gestalt = no
			is_megacorp = no
			can_have_default_memorial = yes
		}
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_gestalt = yes
					is_megacorp = yes
					can_have_default_memorial = no
				}
			}
		}
	}

	convert_to = {
		building_corporate_forum
		building_simulation_3
		building_galactic_memorial_3
		building_sensorium_3
		building_lifecrypt_3
		building_lifecrypt_machine_3
		building_lifecrypt_hive_mind_3
		building_lifecrypt_corporate_3
		building_avatar_chamber_3
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 3
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.15
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_medium
	}

	triggered_planet_modifier = {
		potential = { has_force_of_will_dlc = yes }
		pop_government_ethic_attraction = 0.50
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner? = {
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	triggered_desc = {
		text = building_hypercomms_forum_effect
	}

	prerequisites = {
		"tech_hypercomms_forum"
	}

	ai_resource_production = {
		unity = 20
	}

	show_tech_unlock_if = {
		is_gestalt = no
		is_megacorp = no
		can_have_default_memorial = yes
	}
}

##################
# Bureaucrats
##################

building_bureaucratic_1 = {
	can_build = yes
	base_buildtime = @b1_time
	exempt_from_ai_planet_specialization = no

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_regular_empire = yes
			is_spiritualist = no
			has_make_spiritualist_perk = no
		}
		NOR = {
			has_modifier = penal_colony
			has_modifier = slave_colony
			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_bureaucratic_1 value < 2 }
		}
	}

	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_regular_empire = no
				is_spiritualist = yes
				has_make_spiritualist_perk = yes
			}
		}
	}

	allow = {
	}

	ai_weight_coefficient = @static_jobs_ai_weight_coefficient

	convert_to = {
		building_temple
		building_hive_node
		building_uplink_node
	}

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

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

	prerequisites = {
		"tech_planetary_government"
	}

	show_tech_unlock_if = {
		is_regular_empire = yes
		is_spiritualist = no
		has_make_spiritualist_perk = no
	}
}

building_bureaucratic_2 = {
	base_buildtime = @b2_time
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_regular_empire = yes
			is_spiritualist = no
			has_make_spiritualist_perk = no
		}
		NOR = {
			has_modifier = slave_colony
			has_modifier = resort_colony
		}
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_regular_empire = no
				is_spiritualist = yes
				has_make_spiritualist_perk = yes
			}
		}
	}

	convert_to = {
		building_holotemple
		building_hive_cluster
		building_network_junction
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
		}
		cost = {
			rare_crystals = @b2_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
	}

	planet_modifier = {
		planet_bureaucrats_upkeep_mult = -0.10
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = no
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_bureaucrat_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_manager_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_worker_coop_empire = yes
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_steward_add = @building_static_jobs
		}
	}
	
	upgrades = {
		"building_bureaucratic_3"
	}

	prerequisites = {
		"tech_colonial_bureaucracy"
	}

	show_tech_unlock_if = {
		is_regular_empire = yes
		is_spiritualist = no
		has_make_spiritualist_perk = no
	}
}

building_bureaucratic_3 = {
	base_buildtime = @b3_time
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_regular_empire = yes
			is_spiritualist = no
			has_make_spiritualist_perk = no
		}
		NOR = {
			has_modifier = slave_colony
			has_modifier = resort_colony
		}
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_regular_empire = no
				is_spiritualist = yes
				has_make_spiritualist_perk = yes
			}
		}
	}

	convert_to = {
		building_sacred_nexus
		building_hive_confluence
		building_system_conflux
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
		}
		cost = {
			rare_crystals = @b3_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b3_upkeep
			rare_crystals = @b3_rare_upkeep
		}
	}

	planet_modifier = {
		pop_bureaucrat_bonus_workforce_mult = 0.10
	}


	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = no
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_bureaucrat_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_manager_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_worker_coop_empire = yes
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_steward_add = @building_static_jobs
		}
	}


	triggered_planet_modifier = {
		potential = {
			exists = owner.federation
			owner = {
				federation = {
					has_federation_perk = all_the_priests_2
				}
			}
		}
		job_politician_add = @building_static_jobs_low
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner.federation
			owner = {
				federation = {
					has_tradition = tr_plentiful_aspiration_3
				}
			}
		}
		job_politician_add = @building_static_jobs_low
	}

	prerequisites = {
		"tech_galactic_bureaucracy"
	}

	show_tech_unlock_if = {
		is_regular_empire = yes
		is_spiritualist = no
		has_make_spiritualist_perk = no
	}
}

##################
# Spiritualists
##################

building_temple = {
	base_buildtime = @b1_time
	exempt_from_ai_planet_specialization = no

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			OR = {
				is_spiritualist = yes
				AND = {
					is_gestalt = no
					has_make_spiritualist_perk = yes
				}
			}
		}
		NOT = { has_modifier = slave_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_temple value < 2 }
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					AND = {
						is_spiritualist = no
						has_make_spiritualist_perk = no
					}
					is_gestalt = yes
				}
			}
			has_modifier = slave_colony
		}
	}

	allow = {
	}

	ai_weight_coefficient = @static_jobs_ai_weight_coefficient

	convert_to = {
		building_bureaucratic_1
		building_hive_node
		building_uplink_node
	}

	resources = {
		category = planet_buildings_temples
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b1_minerals
		}
		upkeep = {
			energy = @b1_upkeep
		}
	}

	planet_modifier = {
		pop_ethic_spiritualist_attraction_mult = 0.05
	}

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

	prerequisites = {
		"tech_planetary_government"
	}

	show_tech_unlock_if = {
		OR = {
			is_spiritualist = yes
			AND = {
				is_gestalt = no
				has_make_spiritualist_perk = yes
			}
		}
	}
}

building_holotemple = {
	base_buildtime = @b2_time
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			OR = {
				is_spiritualist = yes
				AND = {
					is_gestalt = no
					has_make_spiritualist_perk = yes
				}
			}
		}
		NOT = { has_modifier = slave_colony }
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					AND = {
						is_spiritualist = no
						has_make_spiritualist_perk = no
					}
					is_gestalt = yes
				}
			}
			has_modifier = slave_colony
		}
	}

	convert_to = {
		building_bureaucratic_2
		building_hive_cluster
		building_network_junction
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
		}
		cost = {
			rare_crystals = @b2_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
	}

	planet_modifier = {
		pop_ethic_spiritualist_attraction_mult = 0.10
		planet_bureaucrats_upkeep_mult = -0.10
	}


	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = no
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_priest_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_manager_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = yes
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_steward_add = @building_static_jobs
		}
	}
	

	prerequisites = {
		"tech_holographic_rituals"
	}

	show_tech_unlock_if = {
		OR = {
			is_spiritualist = yes
			AND = {
				is_gestalt = no
				has_make_spiritualist_perk = yes
			}
		}
	}
}

building_sacred_nexus = {
	base_buildtime = @b3_time
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			OR = {
				is_spiritualist = yes
				AND = {
					is_gestalt = no
					has_make_spiritualist_perk = yes
				}
			}
		}
		NOT = { has_modifier = slave_colony }
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					AND = {
						is_spiritualist = no
						has_make_spiritualist_perk = no
					}
					is_gestalt = yes
				}
			}
			has_modifier = slave_colony
		}
	}

	convert_to = {
		building_bureaucratic_3
		building_hive_confluence
		building_system_conflux
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
		}
		cost = {
			rare_crystals = @b3_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b3_upkeep
			rare_crystals = @b3_rare_upkeep
		}
	}

	planet_modifier = {
		pop_ethic_spiritualist_attraction_mult = 0.15
		pop_bureaucrat_bonus_workforce_mult = 0.10
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = no
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_priest_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_manager_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = yes
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_steward_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner.federation
			owner.federation = { has_federation_perk = all_the_priests_2 }
			owner.federation = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		job_high_priest_add = @building_static_jobs
	}	

	prerequisites = {
		"tech_consecration_fields"
	}

	show_tech_unlock_if = {
		OR = {
			is_spiritualist = yes
			AND = {
				is_gestalt = no
				has_make_spiritualist_perk = yes
			}
		}
	}
}

##################
# Machine
##################

building_uplink_node = {
	base_buildtime = @b1_time
	icon = building_autochthon_monument

	exempt_from_ai_planet_specialization = no

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_machine_empire = yes
			NOT = {
				has_valid_civic = civic_machine_servitor
			}
		}
		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_uplink_node value < 2 }
		}
	}

	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_machine_empire = no
				has_valid_civic = civic_machine_servitor
			}
		}
	}

	ai_weight_coefficient = @static_jobs_ai_weight_coefficient

	convert_to = {
		building_bureaucratic_1
		building_temple
		building_hive_node
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b1_minerals
		}
		upkeep = {
			energy = @b1_upkeep
		}
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_machine_empire = yes }
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_coordinator_add = @building_static_jobs
		}
	}

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

	prerequisites = {
		"tech_planetary_government"
	}

	show_tech_unlock_if = {
		is_machine_empire = yes
		NOT = {
			has_valid_civic = civic_machine_servitor
		}
	}
}

building_network_junction = {
	base_buildtime = @b2_time
	icon = building_heritage_site
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_machine_empire = yes
			NOT = {
				has_valid_civic = civic_machine_servitor
			}
		}
	}

	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_machine_empire = no
				has_valid_civic = civic_machine_servitor
			}
		}
	}

	convert_to = {
		building_bureaucratic_2
		building_holotemple
		building_hive_cluster
		building_commensal_clearing_3
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
		}
		cost = {
			rare_crystals = @b2_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_machine_empire = yes }
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_coordinator_add = @building_static_jobs
		}
	}

	planet_modifier = {
		planet_bureaucrats_upkeep_mult = -0.10
	}

	prerequisites = {
		"tech_colonial_bureaucracy"
	}

	show_tech_unlock_if = {
		is_machine_empire = yes
		NOT = {
			has_valid_civic = civic_machine_servitor
		}
	}
}

building_system_conflux = {
	base_buildtime = @b3_time
	icon = building_hypercomms_forum
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_machine_empire = yes
			NOT = {
				has_valid_civic = civic_machine_servitor
			}
		}
	}

	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_machine_empire = no
				has_valid_civic = civic_machine_servitor
			}
		}
	}

	convert_to = {
		building_bureaucratic_3
		building_sacred_nexus
		building_hive_confluence
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
		}
		cost = {
			rare_crystals = @b3_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b3_upkeep
			rare_crystals = @b3_rare_upkeep
		}
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_machine_empire = yes }
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_coordinator_add = @building_static_jobs
		}
	}

	planet_modifier = {
		pop_coordinator_bonus_workforce_mult = 0.10
	}

	prerequisites = {
		"tech_galactic_bureaucracy"
	}

	show_tech_unlock_if = {
		is_machine_empire = yes
		NOT = {
			has_valid_civic = civic_machine_servitor
		}
	}
}

##################
# Hive Minds
##################
building_hive_node = {
	base_buildtime = @b1_time

	exempt_from_ai_planet_specialization = no

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_hive_empire = yes
			is_wilderness_empire = 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_hive_node value < 2 }
		}
	}
	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_hive_empire = no
				is_wilderness_empire = yes
			}
		}
	}
	convert_to = {
		building_bureaucratic_1
		building_temple
		building_uplink_node
		building_commensal_clearing_1
	}

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

	ai_weight_coefficient = @static_jobs_ai_weight_coefficient

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b1_minerals
		}
		upkeep = {
			energy = @b1_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					has_edict = synaptic_reinforcement
				}
			}
			energy = 2
		}
	}

	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_synapse_drone_add = @building_static_jobs
		}
	}

	prerequisites = {
		"tech_hive_node"
	}
}

building_hive_cluster = {
	base_buildtime = @b2_time
	planet_limit = 1
	exempt_from_ai_planet_specialization = no

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_hive_empire = yes
			is_wilderness_empire = no
		}
	}
	allow = {
		has_upgraded_capital = yes
	}
	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_hive_empire = no
				is_wilderness_empire = yes
			}
		}
	}
	convert_to = {
		building_bureaucratic_2
		building_holotemple
		building_commensal_clearing_3
		building_network_junction
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
		}
		cost = {
			exotic_gases = @b2_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b2_upkeep
			exotic_gases = @b2_rare_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					has_edict = synaptic_reinforcement
				}
			}
			energy = 2
		}
	}

	planet_modifier = {}

	triggered_planet_modifier = {
		potential = {
			exists = owner
		}
		job_coordinator_add = @b2_jobs
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_active_tradition = tr_domination_synaptic_extensions
			}
		}
		modifier = {
			planet_housing_add = 200
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_synapse_drone_add = @building_static_jobs
		}
	}

	planet_modifier = {
		planet_bureaucrats_upkeep_mult = -0.10
	}

	prerequisites = {
		"tech_hive_cluster"
	}
}

building_hive_confluence = {
	base_buildtime = @b3_time
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_hive_empire = yes
			is_wilderness_empire = no
		}
	}
	allow = {
		has_major_upgraded_capital = yes
	}
	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_hive_empire = no
				is_wilderness_empire = yes
			}
		}
	}
	convert_to = {
		building_bureaucratic_3
		building_sacred_nexus
		building_commensal_clearing_4
		building_system_conflux
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
		}
		cost = {
			exotic_gases = @b3_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b3_upkeep
			exotic_gases = @b3_rare_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					has_edict = synaptic_reinforcement
				}
			}
			energy = 2
		}
	}

	planet_modifier = {}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_synapse_drone_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_active_tradition = tr_domination_synaptic_extensions
			}
		}
		modifier = {
			planet_housing_add = 200
		}
	}

	planet_modifier = {
		pop_coordinator_bonus_workforce_mult = 0.10

	}

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

##################
# Death Cult
##################

# Sacrificial Temple (basic)
building_sacrificial_temple_1 = {
	base_buildtime = @b1_time
	position_priority = 100

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_death_cult_empire = yes
		}
		NOT = { has_modifier = slave_colony }
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_death_cult_empire = no
			}
			has_modifier = slave_colony
		}
	}

	allow = {
	}

	convert_to = {
		building_bureaucratic_1
		building_temple
		building_hive_node
		building_uplink_node
	}

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

	planet_modifier = {
		pop_ethic_spiritualist_attraction_mult = 0.05
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_death_priest_add = @building_static_jobs
			job_mortal_initiate_add = @building_static_jobs
		}
	}

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

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

	prerequisites = {
		"tech_planetary_government"
	}

	show_tech_unlock_if = {
		is_death_cult_empire = yes
	}
}

# Grim Holotemple
building_sacrificial_temple_2 = {
	base_buildtime = @b2_time
	position_priority = 100
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_death_cult_empire = yes
		}
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = { is_death_cult_empire = no }
			has_modifier = slave_colony
		}
	}

	convert_to = {
		building_bureaucratic_2
		building_holotemple
		building_hive_cluster
		building_network_junction
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b2_minerals
		}
		cost = {
			exotic_gases = @b2_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b2_upkeep
			exotic_gases = @b2_rare_upkeep
		}
	}

	planet_modifier = {
		pop_ethic_spiritualist_attraction_mult = 0.1
		planet_bureaucrats_produces_mult = 0.05
	}

	inline_script = {
		script = jobs/mortal_initiates_add
		AMOUNT = @building_static_jobs
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = no
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_death_priest_add = @building_static_jobs
			job_mortal_initiate_add = @building_static_jobs
		}
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_manager_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = yes
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_steward_add = @building_static_jobs
		}
	}
	
	prerequisites = {
		"tech_holographic_rituals"
	}

	show_tech_unlock_if = {
		is_death_cult_empire = yes
	}
}

# Temple of Grand Sacrifice
building_sacrificial_temple_3 = {
	base_buildtime = @b3_time
	position_priority = 100
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_death_cult_empire = yes
		}
		NOT = { has_modifier = slave_colony }
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = { is_death_cult_empire = no }
			has_modifier = slave_colony
		}
	}

	convert_to = {
		building_bureaucratic_3
		building_sacred_nexus
		building_system_conflux
		building_hive_confluence
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher_unitary_admin
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = rare_crystals
			COST = @b3_minerals
		}
		cost = {
			exotic_gases = @b3_rare_cost
			mult = value:unitary_admin_building_cost_mult
		}
		upkeep = {
			energy = @b3_upkeep
			exotic_gases = @b3_rare_upkeep
		}
	}

	planet_modifier = {
		pop_ethic_spiritualist_attraction_mult = 0.15
		pop_mortal_initiate_bonus_workforce_mult = 0.10
	}

	inline_script = {
		script = jobs/mortal_initiates_add
		AMOUNT = @building_static_jobs_high
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = no
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_death_priest_add = @building_static_jobs
			job_mortal_initiate_add = @building_static_jobs
		}
	}
	
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = no
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_manager_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_megacorp = yes
				is_worker_coop_empire = yes
			}
			owner = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		modifier = {
			job_steward_add = @building_static_jobs
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner.federation
			owner.federation = { has_federation_perk = all_the_priests_2 }
			owner.federation = {
				has_tradition = tr_plentiful_aspiration_3
			}
		}
		job_high_priest_add = @building_static_jobs
	}
	
	prerequisites = {
		"tech_consecration_fields"
	}

	show_tech_unlock_if = {
		is_death_cult_empire = yes
	}
}

##################
# Memorialists
##################

#Sanctuary of Repose
building_galactic_memorial_1 = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_memorialist_empire = yes
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				is_memorialist_empire = no
			}
		}
	}

	convert_to = {
		building_autochthon_monument
		building_corporate_monument
		building_simulation_1
		building_sensorium_1
		building_avatar_chamber_1
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 1
			multiplier = owner.trigger:num_ascension_perks
		}
		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 = {
			minerals = @b1_upkeep
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.05
		planet_bureaucrats_upkeep_mult = -0.05
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner? = {
				is_gestalt = no
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_low
	}

	triggered_desc = {
		text = building_autochthon_monument_effect
	}

	prerequisites = {
		"tech_cultural_heritage"
	}

	#Tomb/Relic worlds
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = no }
			OR = {
				is_planet_class = pc_nuked
				is_planet_class = pc_relic
			}
		}
		pop_government_ethic_attraction = 0.20
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = yes }
			OR = {
				is_planet_class = pc_nuked
				is_planet_class = pc_relic
			}
		}
		planet_crime_no_happiness_add = -20
	}

	upgrades = {
		building_galactic_memorial_2
	}

	show_tech_unlock_if = {
		is_memorialist_empire = yes
	}

	ai_resource_production = {
		unity = 10
	}
}

#Pillar of Quietus
building_galactic_memorial_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_memorialist_empire = yes
		}
	}

	allow = {
		exists = owner
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				is_memorialist_empire = no
			}
		}
	}

	convert_to = {
		building_heritage_site
		building_corporate_site
		building_simulation_2
		building_sensorium_2
		building_avatar_chamber_2
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 2
			multiplier = owner.trigger:num_ascension_perks
		}
		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 = {
			minerals = @b2_upkeep
			exotic_gases = @b2_rare_upkeep
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.10
		planet_bureaucrats_upkeep_mult = -0.10
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner = {
				is_gestalt = no
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs
	}

	triggered_desc = {
		text = building_heritage_site_effect
	}

	prerequisites = {
		"tech_heritage_site"
	}

	#Tomb/Relic worlds
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = no }
			OR = {
				is_planet_class = pc_nuked
				is_planet_class = pc_relic
			}
		}
		pop_government_ethic_attraction = 0.20
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = yes }
			OR = {
				is_planet_class = pc_nuked
				is_planet_class = pc_relic
			}
		}
		planet_crime_no_happiness_add = -20
	}

	upgrades = {
		building_galactic_memorial_3
	}

	show_tech_unlock_if = {
		is_memorialist_empire = yes
	}

	ai_resource_production = {
		unity = 15
	}
}

#Galactic Memorial
building_galactic_memorial_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_memorialist_empire = yes
		}
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = { is_memorialist_empire = no }
		}
	}

	convert_to = {
		building_hypercomms_forum
		building_corporate_forum
		building_simulation_3
		building_sensorium_3
		building_avatar_chamber_3
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 3
			multiplier = owner.trigger:num_ascension_perks
		}
		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 = {
			exotic_gases = @b3_rare_cost
		}
		upkeep = {
			minerals = @b3_upkeep
			exotic_gases = @b3_rare_upkeep
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.15
		planet_bureaucrats_upkeep_mult = -0.15
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner = {
				is_gestalt = no
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_medium
	}

	triggered_desc = {
		text = building_hypercomms_forum_effect
	}

	prerequisites = {
		"tech_hypercomms_forum"
	}

	#Tomb/Relic worlds
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = no }
			OR = {
				is_planet_class = pc_nuked
				is_planet_class = pc_relic
			}
		}
		pop_government_ethic_attraction = 0.20
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = yes }
			OR = {
				is_planet_class = pc_nuked
				is_planet_class = pc_relic
			}
		}
		planet_crime_no_happiness_add = -20
	}

	show_tech_unlock_if = {
		is_memorialist_empire = yes
	}

	ai_resource_production = {
		unity = 20
	}
}


##########################
# Machine Empire Memorial
##########################
building_simulation_1 = {
	base_buildtime = @b1_time
	planet_limit = 1

	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_machine_empire = yes
			can_have_default_memorial = yes
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_machine_empire = no
					can_have_default_memorial = no
				}
			}
		}
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 1
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.05
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_low
	}

	triggered_desc = {
		text = building_autochthon_monument_effect
	}

		prerequisites = {
		"tech_cultural_heritage"
	}

	convert_to = {
		building_autochthon_monument
		building_corporate_monument
		building_galactic_memorial_1
		building_sensorium_1
		building_lifecrypt_1
		building_lifecrypt_machine_1
		building_lifecrypt_hive_mind_1
		building_lifecrypt_corporate_1
	}

	show_tech_unlock_if = {
		is_machine_empire = yes
		can_have_default_memorial = yes
	}

	ai_resource_production = {
		unity = 10
		trade = 5
	}

	upgrades = {
		building_simulation_2
	}
}

building_simulation_2 = {
	base_buildtime = @b2_time
	can_build = no

	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_machine_empire = yes
			can_have_default_memorial = yes
		}
	}

	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_machine_empire = no
					can_have_default_memorial = no
				}
			}
		}
	}

	convert_to = {
		building_corporate_site
		building_heritage_site
		building_galactic_memorial_2
		building_sensorium_2
		building_lifecrypt_2
		building_lifecrypt_machine_2
		building_lifecrypt_hive_mind_2
		building_lifecrypt_corporate_2
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 2
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.10
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs
	}

	triggered_desc = {
		text = building_heritage_site_effect
	}

	prerequisites = {
		"tech_heritage_site"
	}

	show_tech_unlock_if = {
		is_machine_empire = yes
		can_have_default_memorial = yes
	}

	ai_resource_production = {
		unity = 15
		trade = 5
	}

	upgrades = {
		building_simulation_3
	}
}

building_simulation_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_machine_empire = yes
			can_have_default_memorial = yes
		}
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_machine_empire = no
					can_have_default_memorial = no
				}
			}
		}
	}

	convert_to = {
		building_corporate_forum
		building_hypercomms_forum
		building_galactic_memorial_3
		building_sensorium_3
		building_lifecrypt_3
		building_lifecrypt_machine_3
		building_lifecrypt_hive_mind_3
		building_lifecrypt_corporate_3
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 3
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.15
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_medium
	}

	prerequisites = {
		"tech_hypercomms_forum"
	}

	ai_resource_production = {
		unity = 20
		trade = 5
	}

	show_tech_unlock_if = {
		is_machine_empire = yes
		can_have_default_memorial = yes
	}
}

####################
# Megacorp Memorial
####################
building_corporate_monument = {
	base_buildtime = @b1_time
	planet_limit = 1
	icon = building_autochthon_monument

	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_megacorp = yes
			can_have_default_memorial = yes
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_megacorp = no
					can_have_default_memorial = no
				}
			}
		}
	}

	convert_to = {
		building_autochthon_monument
		building_simulation_1
		building_galactic_memorial_1
		building_sensorium_1
		building_lifecrypt_1
		building_lifecrypt_machine_1
		building_lifecrypt_hive_mind_1
		building_lifecrypt_corporate_1
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 1
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.05
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_low
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner = {
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	triggered_desc = {
		text = building_autochthon_monument_effect
	}

	prerequisites = {
		"tech_cultural_heritage"
	}

	show_tech_unlock_if = {
		is_megacorp = yes
		can_have_default_memorial = yes
	}

	ai_resource_production = {
		unity = 10
	}

	upgrades = {
		building_corporate_site
	}
}

building_corporate_site = {
	base_buildtime = @b2_time
	icon = building_heritage_site
	can_build = no
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_megacorp = yes
			can_have_default_memorial = yes
		}
	}

	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_megacorp = no
					can_have_default_memorial = no
				}
			}
		}
	}

	convert_to = {
		building_heritage_site
		building_galactic_memorial_2
		building_simulation_2
		building_sensorium_2
		building_lifecrypt_2
		building_lifecrypt_machine_2
		building_lifecrypt_hive_mind_2
		building_lifecrypt_corporate_2
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 2
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.10
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner = {
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	triggered_desc = {
		text = building_heritage_site_effect
	}

	prerequisites = {
		"tech_heritage_site"
	}

	show_tech_unlock_if = {
		is_megacorp = yes
		can_have_default_memorial = yes
	}

	ai_resource_production = {
		unity = 15
	}

	upgrades = {
		building_corporate_forum
	}
}

building_corporate_forum = {
	base_buildtime = @b3_time
	icon = building_hypercomms_forum
	can_build = no
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_megacorp = yes
			can_have_default_memorial = yes
		}
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_megacorp = no
					can_have_default_memorial = no
				}
			}
		}
	}

	convert_to = {
		building_hypercomms_forum
		building_simulation_3
		building_galactic_memorial_3
		building_sensorium_3
		building_lifecrypt_3
		building_lifecrypt_machine_3
		building_lifecrypt_hive_mind_3
		building_lifecrypt_corporate_3
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 3
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.15
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_medium
	}

	# Homogeneity Tenet - Non Gestalt
	triggered_planet_modifier = {
		potential = {
			owner = {
				has_active_tenet = tenet_homogeneity
			}
		}
		founder_species_growth_mult = 1
		mult = owner.modifier:non_gestalt_memorials_species_growth_mult
	}

	triggered_desc = {
		text = building_hypercomms_forum_effect
	}

	prerequisites = {
		"tech_hypercomms_forum"
	}

	ai_resource_production = {
		unity = 20
	}

	show_tech_unlock_if = {
		is_megacorp = yes
		can_have_default_memorial = yes
	}
}

#######################
# Hive Empire Memorial
#######################
building_sensorium_1 = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_hive_empire = yes
			can_have_default_memorial = yes
			is_wilderness_empire = no # see 'building_avatar_chamber_1'
		}
	}
	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_hive_empire = no
					can_have_default_memorial = no
				}
			}
		}
	}
	convert_to = {
		building_autochthon_monument
		building_corporate_monument
		building_galactic_memorial_1
		building_simulation_1
		building_avatar_chamber_1
		building_lifecrypt_1
		building_lifecrypt_machine_1
		building_lifecrypt_hive_mind_1
		building_lifecrypt_corporate_1
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 1
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.05
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_low
	}

	triggered_desc = {
		text = building_autochthon_monument_effect
	}

	prerequisites = {
		"tech_cultural_heritage"
	}
	show_tech_unlock_if = {
		is_hive_empire = yes
		can_have_default_memorial = yes
	}

	ai_resource_production = {
		unity = 10
		trade = 5
	}

	upgrades = {
		building_sensorium_2
	}
}

building_sensorium_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_hive_empire = yes
			can_have_default_memorial = yes
			is_wilderness_empire = no # see 'building_avatar_chamber_2'
		}
	}
	allow = {
		has_upgraded_capital = yes
	}
	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_hive_empire = no
					can_have_default_memorial = no
					is_wilderness_empire = yes
				}
			}
		}
	}
	convert_to = {
		building_corporate_site
		building_heritage_site
		building_galactic_memorial_2
		building_simulation_2
		building_lifecrypt_2
		building_lifecrypt_machine_2
		building_lifecrypt_hive_mind_2
		building_lifecrypt_corporate_2
		building_avatar_chamber_2
	}

	prerequisites = {
		"tech_heritage_site"
	}
	show_tech_unlock_if = {
		is_hive_empire = yes
		can_have_default_memorial = yes
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 2
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.10
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs
	}

	triggered_desc = {
		text = building_heritage_site_effect
	}

	ai_resource_production = {
		unity = 15
		trade = 5
	}

	upgrades = {
		building_sensorium_3
	}
}

building_sensorium_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = unity

	building_sets = {
		government
		unity
	}

	potential = {
		exists = owner
		NOT = { has_modifier = slave_colony }
		owner = {
			is_hive_empire = yes
			can_have_default_memorial = yes
			is_wilderness_empire = no # see 'building_avatar_chamber_3'
		}
	}
	allow = {
		has_major_upgraded_capital = yes
	}
	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_hive_empire = no
					can_have_default_memorial = no
					is_wilderness_empire = yes
				}
			}
		}
	}
	convert_to = {
		building_corporate_forum
		building_hypercomms_forum
		building_galactic_memorial_3
		building_simulation_3
		building_avatar_chamber_3
	}

	prerequisites = {
		"tech_hypercomms_forum"
	}
	show_tech_unlock_if = {
		is_hive_empire = yes
		is_wilderness_empire = no
		can_have_default_memorial = yes
	}

	resources = {
		category = planet_buildings
		produces = {
			trigger = { exists = owner }
			unity = 3
			multiplier = owner.trigger:num_ascension_perks
		}
		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
		}
	}

	planet_modifier = {
		planet_jobs_unity_produces_mult = 0.15
	}

	inline_script = {
		script = jobs/culture_workers_add
		COUNT = @building_static_jobs_medium
	}

	ai_resource_production = {
		unity = 20
		trade = 5
	}

	triggered_desc = {
		text = building_hypercomms_forum_effect
	}
}

##################
# Unity boosters
##################

building_autocurating_vault = {
	base_buildtime = @b2_time
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		is_special_colony_type = no
		owner = {
			is_machine_empire = no		# see 'building_alpha_hub'
			is_megacorp = no			# see 'building_corporate_vault'
			is_spiritualist = no		# see 'building_citadel_of_faith'
			is_wilderness_empire = no
			OR = {						# only Hive Minds may avoid effects and restrictions imposed by the 'make_spiritualist_1' Federation Perk
				is_hive_empire = yes
				has_make_spiritualist_perk = no
			}
		}
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_machine_empire = yes
					is_spiritualist = yes
					is_megacorp = yes
				}
			}
		}
	}

	convert_to = {
		building_citadel_of_faith
		building_alpha_hub
		building_corporate_vault
		building_trophy_vault
	}

	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 = 1200
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			rare_crystals = 375
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = no
			}
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			energy = 8
			rare_crystals = 3
		}
	}

	planet_modifier = {
		planet_bureaucrats_unity_produces_add = 0.25
		planet_bureaucrats_physics_research_produces_add = 0.1
		planet_bureaucrats_society_research_produces_add = 0.1
		planet_bureaucrats_engineering_research_produces_add = 0.1
	}

	triggered_planet_modifier = {
		potential = {
			has_ringworld_output_boost = yes
		}
		planet_bureaucrats_unity_produces_add = 0.1
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_gestalt = no
			}
		}
		planet_bureaucrats_consumer_goods_upkeep_add = 2
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_machine_empire = yes
			}
		}
		planet_bureaucrats_energy_upkeep_add = 4
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_lithoid_empire = no
				is_infernal_empire = no
			}
		}
		planet_bureaucrats_food_upkeep_add = 2
		planet_bureaucrats_energy_upkeep_add = 2
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_lithoid_empire = yes
			}
		}
		planet_bureaucrats_minerals_upkeep_add = 2
		planet_bureaucrats_energy_upkeep_add = 2
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_infernal_empire = yes
			}
		}
		planet_bureaucrats_alloys_upkeep_add = 0.75
		planet_bureaucrats_energy_upkeep_add = 3
	}

	prerequisites = {
		"tech_autocurating_vault"
	}

	show_tech_unlock_if = {
		is_machine_empire = no
		is_spiritualist = no
		is_megacorp = no
		is_wilderness_empire = no
		OR = {
			is_hive_empire = yes
			has_make_spiritualist_perk = no
		}
	}
}

building_citadel_of_faith = {
	base_buildtime = @b2_time
	planet_limit = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			OR = {
				is_spiritualist = yes
				AND = {
					is_gestalt = no
					has_make_spiritualist_perk = yes
				}
			}
		}
		NOR = {
			has_modifier = slave_colony
			has_modifier = penal_colony
		}
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				OR = {
					AND = {
						is_spiritualist = no
						has_make_spiritualist_perk = no
					}
					is_gestalt = yes
				}
			}
			has_modifier = slave_colony
		}
	}

	convert_to = {
		building_autocurating_vault
		building_alpha_hub
		building_corporate_vault
		building_trophy_vault
	}

	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 = 1200
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			rare_crystals = 375
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = no
			}
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			energy = 8
			rare_crystals = 3
		}
	}

	planet_modifier = {
		planet_bureaucrats_unity_produces_add = 1
	}

	triggered_planet_modifier = {
		potential = {
			has_ringworld_output_boost = yes
		}
		planet_bureaucrats_unity_produces_add = 0.5
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_gestalt = no
			}
		}
		planet_bureaucrats_consumer_goods_upkeep_add = 1
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_machine_empire = yes
			}
		}
		planet_bureaucrats_energy_upkeep_add = 4
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_lithoid_empire = no
				is_infernal_empire = no
			}
		}
		planet_bureaucrats_food_upkeep_add = 2
		planet_bureaucrats_energy_upkeep_add = 2
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_lithoid_empire = yes
			}
		}
		planet_bureaucrats_minerals_upkeep_add = 2
		planet_bureaucrats_energy_upkeep_add = 2
	}

	inline_script = {
		script = "jobs/politician_add_from_civic"
		AMOUNT = @building_static_jobs
		CIVIC = civic_exalted_priesthood
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_infernal_empire = yes
			}
		}
		planet_bureaucrats_alloys_upkeep_add = 0.75
		planet_bureaucrats_energy_upkeep_add = 3
	}

	prerequisites = {
		"tech_transcendent_faith"
	}
}

building_corporate_vault = {
	base_buildtime = @b2_time
	planet_limit = 1
	icon = building_autocurating_vault

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		NOR = {
			has_modifier = slave_colony
			has_modifier = penal_colony
		}
		owner = {
			is_megacorp = yes
			is_spiritualist = no
			has_make_spiritualist_perk = no
		}
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				OR = {
					is_megacorp = no
					is_spiritualist = yes
					has_make_spiritualist_perk = yes
				}
			}
		}
	}

	convert_to = {
		building_citadel_of_faith
		building_autocurating_vault
		building_alpha_hub
		building_trophy_vault
	}

	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 = 1200
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			rare_crystals = 375
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = no
			}
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			energy = 8
			rare_crystals = 3
		}
	}

	triggered_planet_modifier = {
		potential = {
			has_ringworld_output_boost = yes
		}
		planet_bureaucrats_unity_produces_add = 0.5
	}

	planet_modifier = {
		planet_bureaucrats_unity_produces_add = 0.5
		planet_bureaucrats_trade_produces_add = 2
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_gestalt = no
			}
		}
		planet_bureaucrats_consumer_goods_upkeep_add = 1
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_machine_empire = yes
			}
		}
		planet_bureaucrats_energy_upkeep_add = 4
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_lithoid_empire = no
				is_infernal_empire = no
			}
		}
		planet_bureaucrats_food_upkeep_add = 2
		planet_bureaucrats_energy_upkeep_add = 2
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_lithoid_empire = yes
			}
		}
		planet_bureaucrats_minerals_upkeep_add = 2
		planet_bureaucrats_energy_upkeep_add = 2
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_infernal_empire = yes
			}
		}
		planet_bureaucrats_alloys_upkeep_add = 0.75
		planet_bureaucrats_energy_upkeep_add = 3
	}

	prerequisites = {
		"tech_autocurating_vault"
	}

	show_tech_unlock_if = {
		is_megacorp = yes
		is_spiritualist = no
		has_make_spiritualist_perk = no
	}
}

building_alpha_hub = {
	base_buildtime = @b2_time
	planet_limit = 1
	icon = building_autocurating_vault

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			is_machine_empire = yes
			NOT = {
				has_valid_civic = civic_machine_servitor
			}
		}
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		owner = {
			OR = {
				is_machine_empire = no
				has_valid_civic = civic_machine_servitor
			}
		}
	}

	convert_to = {
		building_autocurating_vault
		building_citadel_of_faith
		building_corporate_vault
		building_trophy_vault
	}

	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 = 1200
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			rare_crystals = 375
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = no
			}
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
		upkeep = {
			trigger = {
				has_ringworld_output_boost = yes
			}
			energy = 8
			rare_crystals = 3
		}
	}

	planet_modifier = {
		planet_bureaucrats_unity_produces_add = 0.5
		planet_bureaucrats_physics_research_produces_add = 0.1
		planet_bureaucrats_society_research_produces_add = 0.1
		planet_bureaucrats_engineering_research_produces_add = 0.1
	}

	triggered_planet_modifier = {
		potential = {
			has_ringworld_output_boost = yes
		}
		planet_bureaucrats_unity_produces_add = 0.25
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_gestalt = no
			}
		}
		planet_bureaucrats_consumer_goods_upkeep_add = 1
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_machine_empire = yes
			}
		}
		planet_bureaucrats_energy_upkeep_add = 2
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_lithoid_empire = no
				is_infernal_empire = no
			}
		}
		planet_bureaucrats_food_upkeep_add = 1
		planet_bureaucrats_energy_upkeep_add = 1
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_lithoid_empire = yes
			}
		}
		planet_bureaucrats_minerals_upkeep_add = 1
		planet_bureaucrats_energy_upkeep_add = 1
	}
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_hive_empire = yes
				is_infernal_empire = yes
			}
		}
		planet_bureaucrats_alloys_upkeep_add = 0.75
		planet_bureaucrats_energy_upkeep_add = 3
	}

	prerequisites = {
		"tech_autocurating_vault"
	}

	show_tech_unlock_if = {
		is_machine_empire = yes
		NOT = {
			has_valid_civic = civic_machine_servitor
		}
	}
}

# Servitors
building_organic_sanctuary = {
	base_buildtime = @b1_time

	category = unity

	building_sets = {
		bio_trophy
		urban
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_valid_civic = civic_machine_servitor
			is_hospitality_servitor_empire = no
		}
	}

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				NOT = { owner = { has_valid_civic = civic_machine_servitor } }
			}
			AND = {
				owner = { is_ai = yes }
				count_owned_pop_amount = {
					limit = {
						has_citizenship_type = {
							type = citizenship_organic_trophy
							country = owner
						}
					}
					count <= 2000
				}
				num_buildings = { type = building_organic_sanctuary value > 3 }
			}
			AND = {
				owner = { is_ai = yes }
				count_owned_pop_amount = {
					limit = {
						has_citizenship_type = {
							type = citizenship_organic_trophy
							country = owner
						}
					}
					count <= 4000
				}
				num_buildings = { type = building_organic_paradise value > 5 }
			}
		}
	}

	convert_to = {
		building_luxury_residence
		building_communal_housing
	}

	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
		}
	}

	planet_modifier = {
		job_bio_trophy_add = 1500
	}

	upgrades = {
		"building_organic_paradise"
	}

	# We need to cheat here and tell AI that this will probably give some complex output since AI can not evaluate what this building does without the pops which it cant get without the building - chicken and egg
	ai_resource_production = {
		unity = 10
		physics_research = 10
		alloys = 5

		trigger = {
			NOT = { has_building = building_organic_sanctuary }
		}
	}

	ai_weight_coefficient = 1.2

	# Here we try to adress the second issue that the AI cant evaluate the pop job output of the bio trophy given the happiness trigger that was put inplace to guard against players exploiting bio trophies

	#science
	ai_resource_production = {
		unity = 10
		physics_research = 10

		trigger = {
			any_owned_pop_group = {
				is_pop_category = bio_trophy_unemployment
			}

			planet_resource_compare = {
				resource = physics_research
				value >= 100
				type = produces
			}
		}
	}

	#alloys
	ai_resource_production = {
		unity = 10
		alloys = 10

		trigger = {
			any_owned_pop_group = {
				is_pop_category = bio_trophy_unemployment
			}

			planet_resource_compare = {
				resource = alloys
				value >= 100
				type = produces
			}
		}
	}

	#cgs
	ai_resource_production = {
		unity = 10
		consumer_goods = 10

		trigger = {
			any_owned_pop_group = {
				is_pop_category = bio_trophy_unemployment
			}

			planet_resource_compare = {
				resource = consumer_goods
				value >= 100
				type = produces
			}
		}
	}
}

building_organic_paradise = {
	base_buildtime = @b2_time
	can_build = no
	icon = building_paradise_dome

	category = unity

	building_sets = {
		bio_trophy
		urban
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_valid_civic = civic_machine_servitor
			is_hospitality_servitor_empire = no
		}
	}

	destroy_trigger = {
		exists = owner
		NOT = { owner = { has_valid_civic = civic_machine_servitor } }
	}

	convert_to = {
		building_paradise_dome
		building_communal_housing_large
	}

	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
		}
	}

	planet_modifier = {
		job_bio_trophy_add = 3000
	}

	prerequisites = { "tech_paradise_dome" }

	show_tech_unlock_if = {
		owner = { has_valid_civic = civic_machine_servitor }
	}

	ai_weight_coefficient = 1.2

	# Here we try to adress the second issue that the AI cant evaluate the pop job output of the bio trophy given the happiness trigger that was put inplace to guard against players exploiting bio trophies

	#science
	ai_resource_production = {
		unity = 20
		physics_research = 20

		trigger = {
			any_owned_pop_group = {
				is_pop_category = bio_trophy_unemployment
			}

			planet_resource_compare = {
				resource = physics_research
				value >= 100
				type = produces
			}
		}
	}

	#alloys
	ai_resource_production = {
		unity = 20
		alloys = 20

		trigger = {
			any_owned_pop_group = {
				is_pop_category = bio_trophy_unemployment
			}

			planet_resource_compare = {
				resource = alloys
				value >= 100
				type = produces
			}
		}
	}

	#cgs
	ai_resource_production = {
		unity = 20
		consumer_goods = 20

		trigger = {
			any_owned_pop_group = {
				is_pop_category = bio_trophy_unemployment
			}

			planet_resource_compare = {
				resource = consumer_goods
				value >= 100
				type = produces
			}
		}
	}
}

building_trophy_vault = {
	base_buildtime = @b2_time
	planet_limit = 1
	category = unity
	icon = building_autocurating_vault

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		is_special_colony_type = no
		owner = {
			has_valid_civic = civic_machine_servitor
		}
	}

	allow = {
	}

	destroy_trigger = {
		exists = owner
		OR = {
			has_modifier = slave_colony
			owner = {
				NOT = {
					has_valid_civic = civic_machine_servitor
				}
			}
		}
	}

	convert_to = {
		building_autocurating_vault
		building_citadel_of_faith
		building_alpha_hub
		building_corporate_vault
	}

	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 = {
			rare_crystals = @b2_rare_cost
		}
		upkeep = {
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
	}

	triggered_planet_modifier = {
		potential = {
			owner? = {
				OR = {
					NOT = { has_origin = origin_forever_cruise }
					has_country_flag = forever_cruise_over
				}
			}
		}
		planet_bio_trophies_unity_produces_add = 0.5
		planet_bio_trophies_consumer_goods_upkeep_add = 0.5
		pop_cat_bio_trophy_happiness = 0.10
	}

	# Forever Cruise servitors house their Bio-Trophies as cruise passengers, so boost that category instead
	triggered_planet_modifier = {
		potential = {
			owner? = {
				has_origin = origin_forever_cruise
				NOT = { has_country_flag = forever_cruise_over }
			}
		}
		planet_cruise_passengers_unity_produces_add = 0.5
		planet_cruise_passengers_consumer_goods_upkeep_add = 0.5
		pop_cat_cruise_passenger_happiness = 0.10
	}

	# The unity/consumer goods modifiers act on the planet_cruise_passengers category, which covers both passenger jobs, so spell out that Neglected Bio-Trophies also benefit
	triggered_desc = {
		trigger = {
			owner? = {
				has_origin = origin_forever_cruise
				NOT = { has_country_flag = forever_cruise_over }
			}
		}
		text = building_trophy_vault_forever_cruise_effect
	}

	prerequisites = {
		"tech_autocurating_vault"
	}

	show_tech_unlock_if = {
		has_valid_civic = civic_machine_servitor
	}
}

# Archaeotech
building_league_offices = {
	base_buildtime = @b2_time
	empire_limit = {
		base = 1
	}

	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_technology = tech_secrets_league
		}
		NOT = { has_modifier = slave_colony }
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	destroy_trigger = {
		has_modifier = slave_colony
	}

	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 = {
			rare_crystals = @b2_rare_cost
			minor_artifacts = 30
		}
		upkeep = {
			energy = @b2_upkeep
			rare_crystals = @b2_rare_upkeep
		}
		cost = {
			trigger = {
				owner = { is_wilderness_empire = yes }
			}
			biomass = @b3_biomass
		}
	}

	inline_script = {
		script = buildings/on_all_wilderness_buildings_districts
	}

	country_modifier = {
		country_edict_fund_add = 50
	}

	triggered_country_modifier = {
		potential = {
			owner = { has_ascension_perk = ap_archaeoengineers }
		}
		country_edict_fund_add = 50
	}

	planet_modifier = {
		planet_bureaucrats_unity_produces_add = 0.25
	}

	triggered_desc = {
		text = building_league_offices_effect
	}

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

	prerequisites = {
		"tech_secrets_league"
	}
}
