##################
# Lifecrypt
##################

# ========== Normal ==========
building_lifecrypt_1 = {
	base_buildtime = @b1_time
	base_cap_amount = 1
	category = unity

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers }
		}
	}

	inline_script = shroud/buildings/lifecrypt_1_conditions
	inline_script = shroud/buildings/lifecrypt_1_resources
	inline_script = shroud/buildings/lifecrypt_1_modifiers

	triggered_desc = {
		trigger = {
			exists = owner
		}
		text = job_civilian_ethics_effect
	}

	upgrades = {
		building_lifecrypt_2
	}
}

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

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers }
		}
	}

	inline_script = shroud/buildings/lifecrypt_2_conditions
	inline_script = shroud/buildings/lifecrypt_2_resources
	inline_script = shroud/buildings/lifecrypt_2_modifiers

	triggered_desc = {
		trigger = {
			exists = owner
		}
		text = job_civilian_ethics_effect
	}

	upgrades = {
		building_lifecrypt_3
	}
}

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

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers }
		}
	}

	inline_script = shroud/buildings/lifecrypt_3_conditions
	inline_script = shroud/buildings/lifecrypt_3_resources
	inline_script = shroud/buildings/lifecrypt_3_modifiers

	triggered_desc = {
		trigger = {
			exists = owner
		}
		text = job_civilian_ethics_effect
	}
}

# ========== Machine ==========
building_lifecrypt_machine_1 = {
	base_buildtime = @b1_time
	base_cap_amount = 1
	category = unity
	icon = building_lifecrypt_1

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_machine
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_machine
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_machine }
		}
	}

	inline_script = shroud/buildings/lifecrypt_1_conditions
	inline_script = shroud/buildings/lifecrypt_1_resources
	inline_script = shroud/buildings/lifecrypt_1_modifiers_gestalt

	upgrades = {
		building_lifecrypt_machine_2
	}
}

building_lifecrypt_machine_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = unity
	icon = building_lifecrypt_2

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_machine
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_machine
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_machine }
		}
	}

	inline_script = shroud/buildings/lifecrypt_2_conditions
	inline_script = shroud/buildings/lifecrypt_2_resources
	inline_script = shroud/buildings/lifecrypt_2_modifiers_gestalt

	upgrades = {
		building_lifecrypt_machine_3
	}
}

building_lifecrypt_machine_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = unity
	icon = building_lifecrypt_3

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_machine
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_machine
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_machine }
		}
	}

	inline_script = shroud/buildings/lifecrypt_3_conditions
	inline_script = shroud/buildings/lifecrypt_3_resources
	inline_script = shroud/buildings/lifecrypt_3_modifiers_gestalt
}

# ========== Hive Mind ==========
building_lifecrypt_hive_mind_1 = {
	base_buildtime = @b1_time
	base_cap_amount = 1
	category = unity
	icon = building_lifecrypt_1

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_hive_mind
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_hive_mind
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_hive_mind }
		}
	}

	inline_script = shroud/buildings/lifecrypt_1_conditions
	inline_script = shroud/buildings/lifecrypt_1_resources
	inline_script = shroud/buildings/lifecrypt_1_modifiers_gestalt

	upgrades = {
		building_lifecrypt_hive_mind_2
	}
}

building_lifecrypt_hive_mind_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = unity
	icon = building_lifecrypt_2

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_hive_mind
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_hive_mind
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_hive_mind }
		}
	}

	inline_script = shroud/buildings/lifecrypt_2_conditions
	inline_script = shroud/buildings/lifecrypt_2_resources
	inline_script = shroud/buildings/lifecrypt_2_modifiers_gestalt

	upgrades = {
		building_lifecrypt_hive_mind_3
	}
}

building_lifecrypt_hive_mind_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = unity
	icon = building_lifecrypt_3

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_hive_mind
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_hive_mind
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_hive_mind }
		}
	}

	inline_script = shroud/buildings/lifecrypt_3_conditions
	inline_script = shroud/buildings/lifecrypt_3_resources
	inline_script = shroud/buildings/lifecrypt_3_modifiers_gestalt
}

# ========== Corporate ==========
building_lifecrypt_corporate_1 = {
	base_buildtime = @b1_time
	base_cap_amount = 1
	category = unity
	icon = building_lifecrypt_1

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_corporate
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_corporate
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_corporate }
		}
	}

	inline_script = shroud/buildings/lifecrypt_1_conditions
	inline_script = shroud/buildings/lifecrypt_1_resources
	inline_script = shroud/buildings/lifecrypt_1_modifiers

	triggered_desc = {
		trigger = {
			exists = owner
		}
		text = job_civilian_ethics_effect
	}

	upgrades = {
		building_lifecrypt_corporate_2
	}
}

building_lifecrypt_corporate_2 = {
	base_buildtime = @b2_time
	can_build = no
	category = unity
	icon = building_lifecrypt_2

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_corporate
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_corporate
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_corporate }
		}
	}

	inline_script = shroud/buildings/lifecrypt_2_conditions
	inline_script = shroud/buildings/lifecrypt_2_resources
	inline_script = shroud/buildings/lifecrypt_2_modifiers

	triggered_desc = {
		trigger = {
			exists = owner
		}
		text = job_civilian_ethics_effect
	}

	upgrades = {
		building_lifecrypt_corporate_3
	}
}

building_lifecrypt_corporate_3 = {
	base_buildtime = @b3_time
	can_build = no
	category = unity
	icon = building_lifecrypt_3

	building_sets = {
		unity
	}

	potential = {
		exists = owner
		owner = {
			has_civic = civic_entropy_drinkers_corporate
		}
	}

	show_tech_unlock_if = {
		has_civic = civic_entropy_drinkers_corporate
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOT = { has_civic = civic_entropy_drinkers_corporate }
		}
	}

	inline_script = shroud/buildings/lifecrypt_3_conditions
	inline_script = shroud/buildings/lifecrypt_3_resources
	inline_script = shroud/buildings/lifecrypt_3_modifiers

	triggered_desc = {
		trigger = {
			exists = owner
		}
		text = job_civilian_ethics_effect
	}
}


#################################
# Experimentation Chambers
#################################

building_experimentation_chambers_1 = {
	base_buildtime = @b1_time
	exempt_from_ai_planet_specialization = no
	category = research

	building_sets = {
		research
	}

	potential = {
		exists = owner
		owner = {
			is_twisted_experimenters_empire = yes
		}
		NOR = {
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}

	destroy_trigger = {
		OR = {
			owner? = {
				is_twisted_experimenters_empire = no
			}
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = no }
		}
		pop_ethic_materialist_attraction_mult = 0.05
	}

	inline_script = {
		script = shroud/buildings/experimentation_chambers_jobs
		TEST_SUBJECT_JOBS = 200
		EXPERIMENTER_JOBS = 200
		PENAL_JOBS = 100
	}

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

	upgrades = {
		"building_experimentation_chambers_2"
	}

	prerequisites = {
		"tech_basic_science_lab_1"
	}
	show_tech_unlock_if = {
		is_twisted_experimenters_empire = yes
	}
}

building_experimentation_chambers_2 = {
	base_buildtime = @b2_time
	can_build = no

	category = research
	building_sets = {
		research
	}

	allow = {
		has_upgraded_capital = yes
	}

	destroy_trigger = {
		OR = {
			owner? = {
				is_twisted_experimenters_empire = no
			}
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = no }
		}
		pop_ethic_materialist_attraction_mult = 0.1
	}

	inline_script = {
		script = shroud/buildings/experimentation_chambers_jobs
		TEST_SUBJECT_JOBS = 400
		EXPERIMENTER_JOBS = 200
		PENAL_JOBS = 200
	}

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

	upgrades = {
		"building_experimentation_chambers_3"
	}

	prerequisites = {
		"tech_basic_science_lab_2"
	}
	show_tech_unlock_if = {
		is_twisted_experimenters_empire = yes
	}
}

building_experimentation_chambers_3 = {
	base_buildtime = @b3_time
	can_build = no

	category = research
	building_sets = {
		research
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	destroy_trigger = {
		OR = {
			owner? = {
				is_twisted_experimenters_empire = no
			}
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_gestalt = no }
		}
		pop_ethic_materialist_attraction_mult = 0.15
	}

	inline_script = {
		script = shroud/buildings/experimentation_chambers_jobs
		TEST_SUBJECT_JOBS = 600
		EXPERIMENTER_JOBS = 200
		PENAL_JOBS = 300
	}

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

	prerequisites = {
		"tech_basic_science_lab_3"
	}
	show_tech_unlock_if = {
		is_twisted_experimenters_empire = yes
	}
}

building_cradle_sanctum = {
	base_buildtime = @b3_time
	category = government

	building_sets = {
		government
		unity
	}

	empire_limit = {
		base = 1
	}

	potential = {
		has_shroud_dlc = yes
		exists = owner
		owner = {
			has_country_flag = trust_accord
		}
		NOR = {
			has_designation = col_resort
			has_modifier = slave_colony
		}
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	destroy_trigger = {
		exists = owner
		owner = {
			has_shroud_dlc = yes
			NOT = {
				has_country_flag = trust_accord
			}
		}
	}

	inline_script = {
		script = jobs/telepaths_add
		AMOUNT = 300
	}

	country_modifier = {
		country_influence_produces_mult = 0.20
		envoy_improve_relations_mult = 0.20
	}

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

building_psionic_suppressor = {
	base_buildtime = @b3_time
	category = unity
	base_cap_amount = 1

	building_sets = {
		unity
		urban
	}

	potential = {
		has_shroud_dlc = yes
	}

	prerequisites = {
		"tech_psionic_suppression"
	}

	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 = {
			sr_zro = @b2_rare_upkeep
		}
	}

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

	triggered_desc = {
		text = building_psionic_suppressor_tt
	}

	on_built = {
		add_eotc_aura_psionic_suppressor = yes
	}

	on_destroy = {
		remove_eotc_aura_psionic_suppressor = yes
	}

	on_repaired = {
		add_eotc_aura_psionic_suppressor = yes
	}
}

building_ancient_ward_1 = {
	base_buildtime = @b3_time
	category = army
	can_build = no
	can_demolish = no

	empire_limit = {
		base = 1
	}

	building_sets = {
		government
		fortress
	}

	potential = {
		has_shroud_dlc = yes
		exists = owner
		owner = {
			has_origin = origin_mindwardens
		}
	}

	planet_modifier = {
		planet_orbital_bombardment_damage = -0.25
	}

	inline_script = {
		script = jobs/soldiers_add
		AMOUNT = 200
	}

	upgrades = {
		building_ancient_ward_2
	}
}

building_ancient_ward_2 = {
	base_buildtime = @b3_time
	category = army
	can_build = no
	can_demolish = no

	building_sets = {
		government
		fortress
	}

	potential = {
		has_shroud_dlc = yes
		exists = owner
		owner = {
			has_origin = origin_mindwardens
			has_country_flag = unlocked_ancient_ward_upgrade
		}
	}

	planet_modifier = {
		planet_orbital_bombardment_damage = -0.5
	}

	inline_script = {
		script = jobs/soldiers_add
		AMOUNT = 200
	}

	system_modifier = {
		mindwarden_aura_immunity = 1
	}

	triggered_desc = {
		text = psionic_auras_immunity
	}

	on_built = {
		if = {
			limit = {
				exists = owner
				owner = { has_origin = origin_mindwardens }
			}
			owner = {
				if = {
					limit = {
						has_event_chain = ancient_ward_upgrade_chain
					}
					add_event_chain_counter = {
						event_chain = ancient_ward_upgrade_chain
						counter = ancient_ward_upgraded
						amount = 1
					}
					if = {
						limit = {
							has_completed_event_chain_counter = {
								event_chain = ancient_ward_upgrade_chain
								counter = ancient_ward_upgraded
							}
						}
						country_event = { id = shroud.6215 }
					}
				}
			}
		}
		add_eotc_aura_grand_ward = yes
	}

	on_destroy = {
		remove_eotc_aura_grand_ward = yes
	}

	on_repaired = {
		add_eotc_aura_grand_ward = yes
	}
}

building_materiality_engine = {
	base_buildtime = @b2_time
	category = manufacturing
	can_be_ruined = no
	can_be_disabled = no

	building_sets = {
		government
		urban
	}

	potential = {
		has_shroud_dlc = yes
		exists = owner
		owner = { has_origin = origin_shroud_forged }
	}

	empire_limit = {
		base = 1
		modifier = {
			add = materiality_engine_available
			check_variable = {
				which = materiality_engine_available
				value > 0
			}
		}
	}

	prerequisites = {
		"tech_materiality_engine"
	}

	resources = {
		category = planet_buildings
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			sr_zro = @b1_rare_cost
		}
		produces = {
			alloys = 6
			minerals = 12
		}
		upkeep = {
			sr_zro = @b2_rare_upkeep
		}
	}

	inline_script = {
		script = jobs/physicists_add
		AMOUNT = @building_static_jobs_high
	}

	country_modifier = {
		damage_vs_psionic_empires_mult = 0.05
	}

	triggered_desc = {
		text = physics_unit_is_extradimensional_research_unit_tt
	}
	triggered_desc = {
		text = NEW_LINE
	}
	triggered_desc = {
		text = building_materiality_engine_tt
	}

	on_built = {
		materiality_engine_on_built_effect = yes
	}
	on_destroy = {
		if = {
			limit = { exists = event_target:mindwarden_enclave_country }
			event_target:mindwarden_enclave_country = {
				add_trust = {
					who = root.owner
					amount = @mindwarden_opinion_lost_materiality_engine
				}
			}
		}
	}
}

building_chamber_of_silence = {
	base_buildtime = @b2_time
	category = government
	can_be_disabled = no

	building_sets = {
		government
		urban
	}

	base_cap_amount = 1

	potential = {
		owner = {
			has_tradition = tr_psionics_shroud_psi_corps
			has_origin = origin_endbringers
		}
	}

	destroy_trigger = {
		exists = owner
		owner = {
			NOR = {
				has_tradition = tr_psionics_shroud_psi_corps
				has_origin = origin_endbringers
			}
		}
	}

	triggered_desc = {
		trigger = {
			if = {
				limit = {
					exists = owner
				}
				if = {
					limit = {
						owner = { has_modifier = endbringers_paranoia }
					}
					text = building_chamber_of_silence_paranoia_tt
				}
				if = {
					limit = {
						owner = { has_modifier = endbringers_madness_1 }
					}
					text = building_chamber_of_silence_madness_1_tt
				}
				else_if = {
					limit = {
						owner = { has_modifier = endbringers_madness_2 }
					}
					text = building_chamber_of_silence_madness_2_tt
				}
				else_if = {
					limit = {
						owner = { has_modifier = endbringers_madness_3 }
					}
					text = building_chamber_of_silence_madness_3_tt
				}
				if = {
					limit = {
						owner = {
							OR = {
								has_modifier = endbringers_paranoia
								has_modifier = endbringers_madness_1
								has_modifier = endbringers_madness_2
								has_modifier = endbringers_madness_3
							}
						}
					}
					text = newline
				}
				text = building_chamber_of_silence_destroyed_tt
			}

		}
	}

	inline_script = {
		script = jobs/telepaths_add
		AMOUNT = 200
	}

	planet_modifier = {
		planet_stability_add = 5
	}

	triggered_planet_modifier = {
		potential = {
			planet = {
				num_assigned_jobs = {
					job = telepath
					value > 0
				}
			}
		}
		psionic_pop_bonus_workforce_mult = 1
		mult = value:psionic_workforce_from_telepaths
		# This is on the building instead of the jobs to prevent an infinite workforce loop
	}

	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = {
				has_technology = tech_aura_intensification
			}
		}
		psionic_aura_intensity_mult = 0.05
	}

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

	on_built = {
		owner = {
			set_variable = {
				which = num_chambers_of_silence
				value = value:count_building_chamber_of_silence
			}
			refresh_endbringers_paranoia_modifier = yes
			refresh_endbringers_madness_modifier = yes
		}
	}

	on_destroy = {
		# Building here is already removed from the planet
		owner = {
			set_variable = {
				which = num_chambers_of_silence
				value = value:count_building_chamber_of_silence
			}
			refresh_endbringers_paranoia_modifier = yes
			refresh_endbringers_madness_modifier = yes
		}
	}

	on_repaired = {
		owner = {
			set_variable = {
				which = num_chambers_of_silence
				value = value:count_building_chamber_of_silence
			}
			refresh_endbringers_paranoia_modifier = yes
			refresh_endbringers_madness_modifier = yes
		}
	}
}
