############################################################
###                ESC buildings : general               ###
############################################################

# - Central Besearch Bureau			: mid-game superlab, provides scientist jobs and boosts local science production as well as empire's research speed
# - Culture Nexus					: superlab for society research; improves unity production
# - Cerebral Node					: organic hive-mind version of the Culture Nexus
# - Network Regulator				: machine intelligence version of the Culture Nexus
# - Advanced Materials Laboratory	: superlab for engineering research; improves armor and empire's mineral and alloy production
# - Technology Institute			: superlab for physics research; improves shields and empire's energy produciton
# - Watcher of Eternity				: end-game superlab, provides scientist jobs and boosts local science production as well as empire's research speed
# - Stellar Energy Tower			: special bulding that generates energy, physics and boosts local food production. requires empire to have killed Stellarite Devourer
# - Quantum Computation Node		: special lab building, provides scientist jobs and boosts local science production. requires resolved Infinity Machine event chain
# - Dragon Hatchery					: spawn ether drake hatchlings

############################################################
###                Central Research Bureau               ###
############################################################

esc_building_central_research_bureau = {
	base_buildtime = 540
	category = research
	icon = esc_building_centralresearchbureau
	empire_limit = { base = 1 }

	building_sets = {
		research
		government
		urban
	}

	potential = {
		NOT = { has_modifier = resort_colony }
		NOT = { has_modifier = slave_colony }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_central_research_bureau_forbidden }
	}
	destroy_trigger = {
		OR = {
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}
	allow = {
		has_major_upgraded_capital = yes
	}

	# resources cost / upkeep / production
	inline_script = {
		script = buildings/esc_human_player_variable_cost_3
		BASE_COST_MINERALS = 750
		HUMAN_PLAYER_INFLUENCE_COST = 15
		HUMAN_PLAYER_RARE_RESOURCE_COST_TYPE_1 = exotic_gases
		HUMAN_PLAYER_RARE_RESOURCE_COST_1 = 25
		HUMAN_PLAYER_RARE_RESOURCE_COST_TYPE_2 = volatile_motes
		HUMAN_PLAYER_RARE_RESOURCE_COST_2 = 25
		HUMAN_PLAYER_RARE_RESOURCE_COST_TYPE_3 = rare_crystals
		HUMAN_PLAYER_RARE_RESOURCE_COST_3 = 25
		BASE_UPKEEP_ENERGY = 10
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_TYPE_1 = exotic_gases
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_1 = 1
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_TYPE_2 = volatile_motes
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_2 = 1
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_TYPE_3 = rare_crystals
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_3 = 1
		PRODUCED_RESOURCE = influence
		RESOURCE_PRODUCTION = 0.25
	}

	planet_modifier = {
		planet_physicists_physics_research_produces_add = 2
		planet_biologists_society_research_produces_add = 2
		planet_engineers_engineering_research_produces_add = 2
		researcher_jobs_bonus_workforce_mult = 0.25
	}

	country_modifier = {
		all_technology_research_speed = 0.05
		num_tech_alternatives_add = 1
	}

	# jobs
	inline_script = {
		script = jobs/researchers_add
		AMOUNT = @building_static_jobs_very_high_3
		LARGE_AMOUNT = @building_static_jobs
	}

	show_tech_unlock_if = { NOT = { has_global_flag = ESC_GLOBAL_FLAG_central_research_bureau_forbidden } }
	prerequisites = { "esc_tech_grand_research_initiative" }
}

############################################################
###                     Culture Nexus                    ###
############################################################

esc_building_culture_nexus = {
	base_buildtime = 360
	icon = esc_building_culture_nexus
	category = unity
	empire_limit = { base = 1 }

	building_sets = {
		unity
		government
		urban
	}

	potential = {
		NOT = { has_modifier = slave_colony }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_culture_nexus_forbidden }
		exists = owner
		owner = { is_regular_empire = yes }
	}
	destroy_trigger = {
		has_modifier = slave_colony
	}
	allow = {
		has_major_upgraded_capital = yes
	}

	convert_to = {
		esc_building_cerebral_node
		esc_building_network_regulator
	}

	# resources cost / upkeep / production
	inline_script = {
		script = buildings/esc_human_player_variable_cost_1
		BASE_COST_MINERALS = 750
		HUMAN_PLAYER_INFLUENCE_COST = 15
		HUMAN_PLAYER_RARE_RESOURCE_COST_TYPE = rare_crystals
		HUMAN_PLAYER_RARE_RESOURCE_COST = 25
		BASE_UPKEEP_ENERGY = 10
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_TYPE = rare_crystals
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP = 1
		PRODUCED_RESOURCE = influence
		RESOURCE_PRODUCTION = 0.25
	}

	country_modifier = {
		pop_government_ethic_attraction = 0.3
		species_leader_exp_gain = 0.25
		country_society_tech_research_speed = 0.05
	}

	planet_modifier = {
		pop_happiness = 0.05
		planet_amenities_add = 2000
		planet_jobs_unity_produces_mult = 0.15
	}

	inline_script = {
		script = jobs/entertainers_add
		AMOUNT = @ESC_job_count_1
	}

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

	show_tech_unlock_if = {
		owner = { is_regular_empire = yes }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_culture_nexus_forbidden }
	}
	prerequisites = { "esc_tech_culture_nexus" }

}

############################################################
###                     Cerebral Node                    ###
############################################################

esc_building_cerebral_node = {
	base_buildtime = 360
	icon = esc_building_culture_nexus
	category = unity
	empire_limit = { base = 1 }

	building_sets = {
		unity
		government
		urban
	}

	potential = {
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_culture_nexus_forbidden }
		exists = owner
		owner = { is_hive_empire = yes }
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	convert_to = {
		esc_building_culture_nexus
		esc_building_network_regulator
	}

	# resources cost / upkeep / production
	inline_script = {
		script = buildings/esc_human_player_variable_cost_1
		BASE_COST_MINERALS = 750
		HUMAN_PLAYER_INFLUENCE_COST = 15
		HUMAN_PLAYER_RARE_RESOURCE_COST_TYPE = rare_crystals
		HUMAN_PLAYER_RARE_RESOURCE_COST = 25
		BASE_UPKEEP_ENERGY = 10
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_TYPE = rare_crystals
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP = 1
		PRODUCED_RESOURCE = influence
		RESOURCE_PRODUCTION = 0.25
	}

	country_modifier = {
		leader_skill_levels = 1
		pop_environment_tolerance = 0.05
		country_society_tech_research_speed = 0.05
	}

	planet_modifier = {
		planet_amenities_no_happiness_add = 2000
		planet_jobs_unity_produces_mult = 0.15
	}

	### non-chronicler biological hives
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { ESC_TRIGGER_country_uses_chronicle_drones = no }
		}
		job_esc_mind_walker_add = @ESC_job_count_3
		job_maintenance_drone_add = @ESC_job_count_2
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { ESC_TRIGGER_country_uses_chronicle_drones = no }
		}
		text = esc_cerebral_node_effect_regular
	}

	### death chronicler biological hives
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { ESC_TRIGGER_country_uses_chronicle_drones = yes }
		}
		job_chronicle_drone_add = @ESC_job_count_3
		job_maintenance_drone_add = @ESC_job_count_2
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { ESC_TRIGGER_country_uses_chronicle_drones = yes }
		}
		text = esc_cerebral_node_effect_death_chronicle
	}

	show_tech_unlock_if = {
		owner = { is_hive_empire = yes }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_culture_nexus_forbidden }
	}
	prerequisites = { "esc_tech_culture_nexus" }
}

############################################################
###                   Network Regulator                  ###
############################################################

esc_building_network_regulator = {
	base_buildtime = 360
	icon = esc_building_culture_nexus
	category = unity
	empire_limit = { base = 1 }

	building_sets = {
		unity
		government
		urban
	}

	potential = {
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_culture_nexus_forbidden }
		exists = owner
		owner = { is_machine_empire = yes }
	}

	allow = {
		has_major_upgraded_capital = yes
	}

	convert_to = {
		esc_building_culture_nexus
		esc_building_cerebral_node
	}

	# resources cost / upkeep / production
	inline_script = {
		script = buildings/esc_human_player_variable_cost_1
		BASE_COST_MINERALS = 750
		HUMAN_PLAYER_INFLUENCE_COST = 15
		HUMAN_PLAYER_RARE_RESOURCE_COST_TYPE = rare_crystals
		HUMAN_PLAYER_RARE_RESOURCE_COST = 25
		BASE_UPKEEP_ENERGY = 10
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_TYPE = rare_crystals
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP = 1
		PRODUCED_RESOURCE = influence
		RESOURCE_PRODUCTION = 0.25
	}

	country_modifier = {
		leader_skill_levels = 1
		country_society_tech_research_speed = 0.05
	}

	planet_modifier = {
		planet_amenities_no_happiness_add = 2000
		planet_jobs_unity_produces_mult = 0.15
	}

	### non-chronicler machines
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { ESC_TRIGGER_country_uses_chronicle_drones = no }
		}
		job_evaluator_add = @ESC_job_count_3
		job_maintenance_drone_add = @ESC_job_count_2
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { ESC_TRIGGER_country_uses_chronicle_drones = no }
		}
		text = esc_network_regulator_effect_regular
	}

	### death chronicler machines
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { ESC_TRIGGER_country_uses_chronicle_drones = yes }
		}
		job_chronicle_drone_add = @ESC_job_count_3
		job_maintenance_drone_add = @ESC_job_count_2
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { ESC_TRIGGER_country_uses_chronicle_drones = yes }
		}
		text = esc_network_regulator_effect_death_chronicle
	}

	show_tech_unlock_if = {
		owner = { is_machine_empire = yes }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_culture_nexus_forbidden }
	}
	prerequisites = { "esc_tech_culture_nexus" }
}

############################################################
###             Advanced Materials Laboratory            ###
############################################################

esc_building_materials_laboratory = {
	base_buildtime = 360
	icon = esc_building_materials_laboratory
	category = research
	empire_limit = { base = 1 }

	building_sets = {
		research
		government
		urban
	}

	potential = {
		NOT = { has_modifier = slave_colony }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_advanced_materials_laboratory_forbidden }
	}
	destroy_trigger = {
		has_modifier = slave_colony
	}
	allow = {
		has_major_upgraded_capital = yes
	}

	# resources cost / upkeep / production
	inline_script = {
		script = buildings/esc_human_player_variable_cost_1
		BASE_COST_MINERALS = 750
		HUMAN_PLAYER_INFLUENCE_COST = 15
		HUMAN_PLAYER_RARE_RESOURCE_COST_TYPE = volatile_motes
		HUMAN_PLAYER_RARE_RESOURCE_COST = 25
		BASE_UPKEEP_ENERGY = 10
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_TYPE = volatile_motes
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP = 1
		PRODUCED_RESOURCE = influence
		RESOURCE_PRODUCTION = 0.25
	}

	country_modifier = {
		ship_armor_damage_mult = 0.1
		country_engineering_tech_research_speed = 0.05
	}

	# jobs
	inline_script = {
		script = jobs/researchers_add
		AMOUNT = @ESC_job_count_2
	}

	show_tech_unlock_if = { NOT = { has_global_flag = ESC_GLOBAL_FLAG_advanced_materials_laboratory_forbidden } }
	prerequisites = { "esc_tech_advanced_materials_lab" }
}

############################################################
###                 Technology Institute                 ###
############################################################

esc_building_technology_institute = {
	base_buildtime = 360
	icon = esc_building_technology_institute
	category = research
	empire_limit = { base = 1 }

	building_sets = {
		research
		government
		urban
	}

	potential = {
		NOT = { has_modifier = slave_colony }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_technology_institute_forbidden }
	}
	destroy_trigger = {
		has_modifier = slave_colony
	}
	allow = {
		has_major_upgraded_capital = yes
	}

	# resources cost / upkeep / production
	inline_script = {
		script = buildings/esc_human_player_variable_cost_1
		BASE_COST_MINERALS = 750
		HUMAN_PLAYER_INFLUENCE_COST = 15
		HUMAN_PLAYER_RARE_RESOURCE_COST_TYPE = exotic_gases
		HUMAN_PLAYER_RARE_RESOURCE_COST = 25
		BASE_UPKEEP_ENERGY = 10
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP_TYPE = exotic_gases
		HUMAN_PLAYER_RARE_RESOURCE_UPKEEP = 1
		PRODUCED_RESOURCE = influence
		RESOURCE_PRODUCTION = 0.25
	}

	country_modifier = {
		ship_shield_damage_mult = 0.1
		country_physics_tech_research_speed = 0.05
	}

	# jobs
	inline_script = {
		script = jobs/researchers_add
		AMOUNT = @ESC_job_count_2
	}

	show_tech_unlock_if = { NOT = { has_global_flag = ESC_GLOBAL_FLAG_technology_institute_forbidden } }
	prerequisites = { "esc_tech_technology_institute" }
}

############################################################
###                 Watcher of Eternity                  ###
############################################################

esc_building_watcher = {
	base_buildtime = 540
	icon = esc_building_watcher
	category = research
	empire_limit = { base = 1 }

	building_sets = {
		research
		government
		urban
	}

	potential = {
		NOT = { has_modifier = resort_colony }
		NOT = { has_modifier = slave_colony }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_watcher_of_eternity_forbidden }
	}
	destroy_trigger = {
		OR = {
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}
	allow = {
		has_major_upgraded_capital = yes
	}

	resources = {
		category = planet_buildings
		cost = {
			minerals = 600
			influence = 15
			rare_crystals = 25
			exotic_gases = 25
			sr_dark_matter = 15
		}
		upkeep = {
			energy = 10
			sr_dark_matter = 2
		}
	}

	country_modifier = {
		all_technology_research_speed = 0.05
	}

	planet_modifier = {
		planet_physicists_physics_research_produces_add = 2
		planet_biologists_society_research_produces_add = 2
		planet_engineers_engineering_research_produces_add = 2
	}

	# jobs
	inline_script = {
		script = jobs/researchers_add
		AMOUNT = @building_static_jobs_very_high_3
		LARGE_AMOUNT = @building_static_jobs
	}

	show_tech_unlock_if = { NOT = { has_global_flag = ESC_GLOBAL_FLAG_watcher_of_eternity_forbidden } }
	prerequisites = { "esc_tech_watcher_of_eternity" }
}

############################################################
###                 Stellar Energy Tower                 ###
############################################################

esc_building_stellar_energy_tower = {
	base_buildtime = 360
	planet_limit = 1
	icon = esc_building_stellar_energy_tower
	category = resource

	building_sets = {
		farming
		generator
	}

	potential = {
		NOT = { has_modifier = resort_colony }
		NOT = { has_modifier = slave_colony }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_stellarite_tech_forbidden }
		exists = owner
		owner = { has_country_flag = ESC_COUNTRY_FLAG_killed_stellarite_devourer }
	}
	destroy_trigger = {
		OR = {
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}
	allow = {
		has_upgraded_capital = yes
	}

	resources = {
		category = planet_buildings
		cost = {
			minerals = 600
			rare_crystals = 25
			exotic_gases = 25
		}
		produces = {
			energy = 10
			unity = 3
		}
	}

	planet_modifier = {
		planet_jobs_food_produces_mult = 0.15
	}

	# research jobs
	inline_script = {
		script = jobs/researchers_add
		AMOUNT = @ESC_job_count_1
	}

	# regular empire
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_regular_empire = yes }
		}
		modifier = {
			job_technician_add = @ESC_job_count_1
			job_technician_per_pop = 0.05
		}
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { is_regular_empire = yes }
		}
		text = esc_stellar_tower_effect_regular
	}

	# hive mind
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_hive_empire = yes }
		}
		modifier = {
			job_technician_drone_add = @ESC_job_count_1
			job_technician_drone_per_pop = 0.05
		}
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { is_hive_empire = yes }
		}
		text = esc_stellar_tower_effect_hive
	}

	# machine empires
	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = { is_machine_empire = yes }
		}
		modifier = {
			job_technician_drone_add = @ESC_job_count_1
			job_technician_drone_per_pop = 0.05
		}
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { is_machine_empire = yes }
		}
		text = esc_stellar_tower_effect_machine
	}

	ai_resource_production = {
		energy = 10
		trigger = { has_any_generator_zone = yes }
	}

	show_tech_unlock_if = { NOT = { has_global_flag = ESC_GLOBAL_FLAG_stellarite_tech_forbidden } }
	prerequisites = { "esc_tech_stellar_energy_tower" }
}

############################################################
###               Quantum Computation Node               ###
############################################################

esc_building_quantum_node = {
	base_buildtime = 360
	planet_limit = 1
	icon = esc_building_quantum_node
	category = research

	building_sets = {
		research
		urban
	}

	potential = {
		NOT = { has_modifier = resort_colony }
		NOT = { has_modifier = slave_colony }
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_technosphere_tech_forbidden }
		exists = owner
		owner = { has_country_flag = technosphere_studied }
	}
	destroy_trigger = {
		OR = {
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}
	allow = { has_upgraded_capital = yes }

	resources = {
		category = planet_buildings
		cost = {
			minerals = 400
			rare_crystals = 25
		}
		produces = {
			physics_research = 5
			society_research = 5
			engineering_research = 5
			unity = 5
		}
		upkeep = {
			energy = 10
			rare_crystals = 2
		}
	}

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

		job_physicist_automated_workforce_mult = 0.5
		job_biologist_automated_workforce_mult = 0.5
		job_engineer_automated_workforce_mult = 0.5
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_gestalt = yes
				is_wilderness_empire = no
			}
		}

		job_calculator_physicist_automated_workforce_mult = 0.5
		job_calculator_biologist_automated_workforce_mult = 0.5
		job_calculator_engineer_automated_workforce_mult = 0.5
	}

	# jobs
	inline_script = {
		script = jobs/researchers_add
		AMOUNT = @ESC_job_count_2
	}

	show_tech_unlock_if = { NOT = { has_global_flag = ESC_GLOBAL_FLAG_technosphere_tech_forbidden } }
	prerequisites = { "esc_tech_quantum_node" }
}

############################################################
###                   Dragon Hatchery                    ###
############################################################

esc_building_dragon_hatchery = {
	base_buildtime = 720
	icon = esc_building_dragon_hatchery
	category = army
	empire_limit = { base = 1 }

	building_sets = {
		government
		urban
	}

	potential = {
		NOT = { has_global_flag = ESC_GLOBAL_FLAG_ether_dragon_tech_forbidden }
	}

	allow = {
		has_upgraded_capital = yes
	}

	resources = {
		category = planet_buildings
		# base cost
		cost = {
			influence = 50
			minerals = 2500
		}
		# cost modifier for empires that use food
		cost = {
			trigger = {
				exists = owner
				owner = { country_uses_food = yes }
			}
			food = 2500
		}
		# cost modifier for empires that don't use food
		cost = {
			trigger = {
				exists = owner
				owner = { country_uses_food = no }
			}
			minerals = 2500
		}
		# cost modifier for human players
		cost = {
			trigger = {
				exists = owner
				owner = { is_ai = no }
			}
			exotic_gases = 200
		}
		# base upkeep
		upkeep = {
			energy = 10
		}
		# upkeep modifier for empires that use food
		upkeep = {
			trigger = {
				exists = owner
				owner = { country_uses_food = yes }
			}
			food = 45
		}
		# upkeep modifier for empired that don't use food
		upkeep = {
			trigger = {
				exists = owner
				owner = { country_uses_food = no }
			}
			minerals = 45
		}
		# upkeep modifier for human players
		upkeep = {
			trigger = { owner = { is_ai = no } }
			exotic_gases = 3
		}
	}

	planet_modifier = {
		planet_jobs_society_research_produces_mult = 0.20
	}

	# jobs
	inline_script = {
		script = jobs/researchers_add
		AMOUNT = @ESC_job_count_2
	}

	show_tech_unlock_if = { NOT = { has_global_flag = ESC_GLOBAL_FLAG_ether_dragon_tech_forbidden } }
	prerequisites = { esc_tech_dragon_hatchery }

	ai_resource_production = {
		trigger = { always = yes }
		society_research = 20
	}
}
