##########################
# Cosmic storm buildings #
##########################

building_storm_attraction_center = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = research

	building_sets = {
		research
		physics
	}

	potential = {
		NOR = {
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
		exists = owner
		owner = { is_wilderness_empire = no }
	}

	allow = {
		custom_tooltip =  {
			fail_text = storm_attracting_allow
			solar_system? = {
				system_has_storm_repelling_tech = no
			}
		}
	}

	resources = {
		category = planet_buildings_storm_tech
		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
		}
		cost = {
			trigger = {
				exists = owner
				NOT = { owner = { has_origin = origin_storm_chasers } }
			}
			rare_crystals = 25
		}
		upkeep = {
			energy = @b1_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				NOT = { owner = { has_origin = origin_storm_chasers } }
			}
			rare_crystals = 0.75
		}
	}

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

	custom_tooltip = "building_cosmic_storm_attraction_center_tt"

	upgrades = {
		"building_advanced_storm_attraction_center"
	}

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

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	planet_modifier = {
		storm_attraction_field_modifier = 0.4
	}

	on_built = {
		create_influence_field_if_needed = yes
	}

	on_enabled = {
		create_influence_field_if_needed = yes
	}

	custom_storm_ai_weight = {
		weight = 0
		modifier = {
			add = 2
			AND = {
				exists = owner
				owner = { has_origin = origin_storm_chasers }
			}
		}

		modifier = {
			add = 10
			AND = {
				exists = owner
				owner = { is_astrometeorologist_empire = yes  }
			}
		}

		modifier = {
			add = 2
			AND = {
				exists = owner
				owner = { is_storm_callers_empire = yes  }
			}
		}

		modifier = {
			set = 0
			solar_system? = {
				cosmic_storm_influence_value > 0.75
			}
		}
	}
}

building_advanced_storm_attraction_center = {
	base_buildtime = @b2_time
	can_build = no
	category = research

	building_sets = {
		research
		physics
	}

	potential = {
		exists = owner
		owner = { is_wilderness_empire = no }
	}

	resources = {
		category = planet_buildings_storm_tech
		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 = {
			trigger = {
				exists = owner
				NOT = { owner = { has_origin = origin_storm_chasers } }
			}
			rare_crystals = 50
		}
		upkeep = {
			energy = @b1_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				NOT = { owner = { has_origin = origin_storm_chasers } }
			}
			rare_crystals = 2.25
		}
	}

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

	allow = {
		custom_tooltip =  {
			fail_text = storm_attracting_allow
			solar_system? = {
				system_has_storm_repelling_tech = no
			}
		}
	}

	planet_modifier = {
		storm_attraction_field_modifier = 0.6
	}

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

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	custom_storm_ai_weight = {
		weight = 1
		modifier = {
			add = 10
			AND = {
				exists = owner
				owner = { has_origin = origin_storm_chasers }
			}
		}
	}

	custom_tooltip = "building_cosmic_storm_advanced_attraction_center_tt"
}

building_storm_repellent_center = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = research

	building_sets = {
		research
		physics
	}

	prerequisites = {
		"tech_storm_manipulation"
	}

	potential = {
		exists = owner
		owner = { is_wilderness_empire = no }
	}

	allow = {
		custom_tooltip =  {
			fail_text = storm_repellent_allow
			solar_system? = {
				system_has_storm_attraction_tech = no
			}
		}
	}

	resources = {
		category = planet_buildings_storm_tech
		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
		}
		cost = {
			rare_crystals = 25
		}
		upkeep = {
			energy = @b1_upkeep
			rare_crystals = 0.75
		}
	}

	upgrades = {
		"building_advanced_storm_repellent_center"
	}

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

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	planet_modifier = {
		storm_repelling_field_modifier = 0.4
	}

	on_built = {
		create_influence_field_if_needed = yes
	}

	on_enabled = {
		create_influence_field_if_needed = yes
	}

	custom_storm_ai_weight = {
		weight = 0

		modifier = {
			add = 1
			AND = {
				exists = owner
				owner = { num_cosmic_storms_encountered >= 2 }
				solar_system? = {
					is_on_border = yes
				}
			}
		}
	}

	custom_tooltip = "building_cosmic_storm_repellent_center_tt"
}

building_advanced_storm_repellent_center = {
	base_buildtime = @b2_time
	can_build = no
	category = research

	building_sets = {
		research
		physics
	}

	resources = {
		category = planet_buildings_storm_tech
		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 = 50
		}
		upkeep = {
			energy = @b1_upkeep
			rare_crystals = 2.25
		}
	}

	prerequisites = {
		"tech_advanced_storm_manipulation"
	}

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

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	planet_modifier = {
		storm_repelling_field_modifier = 0.6
	}

	custom_tooltip = "building_cosmic_storm_advanced_repellent_center_tt"
}

building_storm_resistant_production = { # see also 'building_wilderness_storm_relief'
	base_buildtime = @b1_time
	planet_limit = 1
	category = resource

	building_sets = {
		urban
		generator
		mining
		farming
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			NOT = { has_origin = origin_storm_chasers }
		}
		OR = {
			owner = { is_ai = no }
			solar_system? = {
				system_has_storm_repelling_tech = no
			}
		}
	}

	resources = {
		category = planet_buildings_storm_tech
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = alloys
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = @b1_upkeep
		}
		upkeep = {
			trigger = {
				has_modifier = storm_hunkered_down_modifier
			}
			energy = @b1_upkeep
		}
	}

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

	upgrades = {
		"building_advanced_storm_resistant_production"
	}

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			solar_system? = {
				has_star_flag = storm_system
			}
		}
		modifier = {
			planet_miners_minerals_produces_add = 0.5
			planet_farmers_food_produces_add = 0.5
			planet_technician_energy_produces_add = 0.5
		}
	}

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

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_galactic_community_member = yes
			}
		}
		modifier = {
			planet_miners_produces_mult = 1
			planet_farmers_produces_mult = 1
			planet_technician_produces_mult = 1
		}
		mult = value:storm_building_production_multiplier
	}

	custom_tooltip = "building_storm_resistant_production_tt"

	custom_storm_ai_weight = {
		weight = 0

		modifier = {
			add = 1
			AND = {
				exists = owner
				owner = { num_unique_cosmic_storms_encountered >= 2 }
			}
		}
	}
	destroy_trigger = {
		influence_building_destruction_trigger = yes
	}
}

building_advanced_storm_resistant_production = { # see also 'building_wilderness_storm_relief' (non-upgradeable)
	base_buildtime = @b2_time
	can_build = no
	category = resource

	building_sets = {
		urban
		generator
		mining
		farming
	}

	potential = {
		exists = owner
		owner = {
			OR = {
				is_wilderness_empire = no
				NOT = { has_origin = origin_storm_chasers }
			}
		}
		if = {
			limit = { owner = { is_ai = yes } }
			solar_system? = {
				system_has_storm_repelling_tech = no
			}
		}
	}

	resources = {
		category = planet_buildings_storm_tech
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = alloys
			COST = @b2_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		cost = {
			rare_crystals = @b2_rare_cost
		}
		upkeep = {
			energy = @b2_upkeep
		}
		upkeep = {
			trigger = {
				has_modifier = storm_hunkered_down_modifier
			}
			energy = @b2_upkeep
		}
	}

	prerequisites = {
		"tech_advanced_industrial_storm_protection"
	}

	triggered_planet_modifier = {
		potential = {
			exists = owner
			solar_system? = {
				is_inside_storm = yes
			}
		}
		modifier = {
			planet_miners_minerals_produces_add = 1
			planet_farmers_food_produces_add = 1
			planet_technician_energy_produces_add = 1
		}
	}

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

	triggered_planet_modifier = {
		potential = {
			exists = owner
			owner = {
				is_galactic_community_member = yes
			}
		}
		modifier = {
			planet_miners_produces_mult = 1
			planet_farmers_produces_mult = 1
			planet_technician_produces_mult = 1
		}
		mult = value:storm_building_production_multiplier
	}

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	custom_tooltip = "building_advanced_storm_resistant_production_tt"

	custom_storm_ai_weight = {
		weight = 0

		modifier = {
			add = 2
			AND = {
				exists = owner
				owner = { num_unique_cosmic_storms_encountered >= 3 }
			}
		}
	}

	destroy_trigger = {
		influence_building_destruction_trigger = yes
	}
}

building_adakkaria_patriotic_institute = {
	base_buildtime = @b3_time
	planet_limit = 1
	category = resource

	building_sets = {
		government
		research
		physics
		society
		engineering
	}

	can_build = yes
	can_demolish = no
	can_be_disabled = yes

	potential = {
		exists = owner
		owner = {
			has_country_flag = adakkaria_world_found
		}
		has_carrier_flag = adSul_capital
	}

	country_modifier = {
		ship_shield_damage_mult = 0.1
	}

	inline_script = {
		script = jobs/researchers_add
		AMOUNT = 1200
	}

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

	triggered_desc = {
		trigger = {
			NAND = {
				exists = owner
				owner = { has_country_flag = patriotic_institute_supercharged }
			}
		}
		text = "building_adakkaria_patriotic_institute_effect_desc"
	}
	triggered_desc = {
		trigger = {
			exists = owner
			owner = { has_country_flag = patriotic_institute_supercharged }
		}
		text = "adakkaria_patriotic_institute_desc.supercharged"
	}

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	on_built = {
		start_patriotic_institute_spawn_storm_repeated = yes
	}

	on_destroy = {
		remove_carrier_flag = patriotic_institute_spawning_storms
	}
}

building_astrometeorology_observation_center = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = research

	building_sets = {
		research
		physics
	}

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

	destroy_trigger = {
		exists = owner
		OR = {
			owner = {
				is_astrometeorologist_empire = no
			}
			has_modifier = resort_colony
			has_modifier = slave_colony
		}
	}

	resources = {
		category = planet_buildings_storm_tech
		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
		}
	}

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

	triggered_desc = {
		trigger = {
			exists = owner
			owner = { is_gestalt = no }
		}
		text = physicist_is_astrometeorologist_tt
	}

	triggered_desc = {
		trigger = {
			exists = owner
			owner = { is_machine_empire = yes }
		}
		text = physics_calculator_is_astrometeorologist_tt
	}

	triggered_desc = {
		trigger = {
			exists = owner
			owner = { is_hive_empire = yes }
		}
		text = physics_brain_drone_is_astrometeorologist_tt
	}

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	custom_storm_ai_weight = {
		weight = 0
		modifier = {
			add = 3
			solar_system? = {
				has_environmental_effects = yes
			}
		}
		modifier = {
			factor = 2
			AND = {
				exists = owner
				solar_system? = {
					system_has_storm_attraction_tech = yes
				}
			}
		}
	}
}

building_storm_summoning_theater = {
	base_buildtime = @b1_time
	planet_limit = 1
	category = amenity

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		owner = {
			is_storm_callers_empire = yes
		}
	}

	allow = {
		solar_system? = {
			system_has_storm_repelling_tech = no
		}
	}

	destroy_trigger = {
		exists = owner
		owner = {
			is_storm_callers_empire = no
		}
	}

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

	upgrades = {
		"building_storm_holo_theater"
	}

	planet_modifier = {
		planet_entertainers_physics_research_produces_add = 0.5
		planet_entertainers_consumer_goods_upkeep_add = 0.5
		storm_attraction_field_modifier = @cosmic_storm_minor_storm_attraction
	}

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

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	on_built = {
		create_influence_field_if_needed = yes
	}

	on_enabled = {
		create_influence_field_if_needed = yes
	}

	custom_tooltip = "building_cosmic_storm_storm_summoning_theater_tt"
}

building_storm_holo_theater = {
	base_buildtime = @b2_time
	category = amenity
	can_build = no

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		owner = {
			is_storm_callers_empire = yes
		}
	}

	allow = {
		exists = owner
		has_upgraded_capital = yes
		owner = {
			is_storm_callers_empire = yes
		}
		solar_system? = {
			system_has_storm_repelling_tech = no
		}
	}

	destroy_trigger = {
		exists = owner
		owner = {
			is_storm_callers_empire = no
		}
	}

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

	upgrades = {
		"building_storm_grand_theater"
	}

	planet_modifier = {
		storm_attraction_field_modifier = @cosmic_storm_medium_storm_attraction
		planet_entertainers_physics_research_produces_add = 1
		planet_entertainers_consumer_goods_upkeep_add = 1
	}

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

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	custom_storm_ai_weight = {
		weight = 0
		modifier = {
			add = 10
			AND = {
				exists = owner
				is_colony = yes
			}
		}
	}

	on_built = {
		create_influence_field_if_needed = yes
	}

	on_enabled = {
		create_influence_field_if_needed = yes
	}

	custom_tooltip = "building_cosmic_storm_storm_holo_theater_tt"
}

building_storm_grand_theater = {
	base_buildtime = @b3_time
	category = amenity
	can_build = no

	building_sets = {
		government
		urban
	}

	potential = {
		exists = owner
		owner = {
			is_storm_callers_empire = yes
		}
	}

	allow = {
		exists = owner
		has_major_upgraded_capital = yes
		owner = {
			is_storm_callers_empire = yes
		}
		solar_system? = {
			system_has_storm_repelling_tech = no
		}
	}

	destroy_trigger = {
		exists = owner
		owner = {
			is_storm_callers_empire = no
		}
	}

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

	planet_modifier = {
		storm_attraction_field_modifier = @cosmic_storm_severe_storm_attraction
		planet_entertainers_physics_research_produces_add = 1.5
		planet_entertainers_consumer_goods_upkeep_add = 1.5
	}

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

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	custom_storm_ai_weight = {
		weight = 0
		modifier = {
			add = 10
			exists = owner
		}
	}

	on_built = {
		create_influence_field_if_needed = yes
	}

	on_enabled = {
		create_influence_field_if_needed = yes
	}

	custom_tooltip = "building_cosmic_storm_storm_grand_theater_tt"
}

# When adding more buildings here be sure to also update the list in game/common/resolutions/04_resolutions_cosmic_storms_dlc.txt
