#############
# Army buildings
#############
building_military_academy = {
	base_buildtime = @b2_time
	empire_limit = 1
	can_be_ruined = no
	category = army

	building_sets = {
		fortress
	}

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = no
			NOT = { has_valid_civic = civic_reanimated_armies }
		}
		NOR = {
			has_modifier = resort_colony
			has_modifier = penal_colony
		}
	}

	allow = {
		OR = {
			has_major_upgraded_capital = yes
			AND = {
				exists = owner
				owner = {
					has_valid_civic = civic_machine_tactical_algorithms
				}
			}
		}
	}

	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = { has_valid_civic = civic_machine_tactical_algorithms }

		}
		ship_evasion_mult = 0.02
		ship_tracking_mult = 0.01
		ship_shield_penetration_add = 0.05
		ship_armor_penetration_add = 0.05
		mult = owner.value:tactical_algorithms_scaling_mult
	}
	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = { has_valid_civic = civic_machine_tactical_algorithms }

		}
		ship_shield_hardening_add = 0.1
		mult = owner.value:tactical_algorithms_enclave_scaling_mult
	}

	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = {
				is_gestalt = no
			}
		}
		pop_soldier_bonus_workforce_mult = 0.15
	}

	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = {
				is_gestalt = yes
			}
		}
		pop_warrior_drone_bonus_workforce_mult = 0.15
	}

	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = {
				has_origin = origin_toxic_knights
			}
		}
		pop_knight_bonus_workforce_mult = 0.05
		pop_knight_commander_bonus_workforce_mult = 0.025
	}

	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 = {
			trigger = {
				exists = owner
				owner = {
					NOT = { has_valid_civic = civic_machine_tactical_algorithms }
				}
			}
			volatile_motes = @b2_rare_cost
		}
		upkeep = {
			energy = @b2_upkeep
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					NOT = { has_valid_civic = civic_machine_tactical_algorithms }
				}
			}
			volatile_motes = @b2_rare_upkeep
		}
	}

	prerequisites = {
		"tech_centralized_command"
	}

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

building_dread_encampment = {
	base_buildtime = @b2_time
	planet_limit = 1
	can_be_ruined = no
	category = army

	building_sets = {
		government
		fortress
	}

	potential = {
		exists = owner
		owner = {
			has_valid_civic = civic_reanimated_armies
		}
	}

	allow = {
		has_upgraded_capital = yes
	}

	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
		}
		upkeep = {
			energy = @b1_upkeep
		}
	}

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

	planet_modifier = {
		planet_soldiers_society_research_produces_add = 0.5
		planet_soldiers_engineering_research_produces_add = 0.5
		planet_soldiers_consumer_goods_upkeep_add = 0.5
	}

	triggered_desc = {
		text = building_dread_encampment_tt
	}
}

building_stronghold = {
	base_buildtime = 240
	position_priority = 100
	can_be_ruined = no
	exempt_from_ai_planet_specialization = no

	category = army

	building_sets = {
		government
		fortress
	}

	potential = {
		exists = owner
		NOT = { has_modifier = resort_colony }
		owner = { is_wilderness_empire = no } # see 'building_planetary_carapace'
	}

	allow = {
		exists = owner
		OR = {
			has_carrier_flag = ignore_ai_building_limitations
			owner = {
				is_ai = no
			}

			# AI is allowed to build up to two of these unless they have a fortress zone. (This can result in three under certain upgrade sequences.)
			has_any_fortress_zone = yes
			AND = {
				num_buildings = { type = building_stronghold value < 2 }
				num_buildings = { type = building_fortress value < 2 }
			}
		}
	}

	resources = {
		category = planet_buildings_strongholds
		inline_script = {
			script = buildings/nomadic_cost_switcher
			REGULAR_RESOURCE = minerals
			NOMADIC_RESOURCE = volatile_motes
			COST = @b1_minerals
			NOMADIC_COST_MULT = @nomadic_minerals_to_strategic_ratio
		}
		upkeep = {
			energy = 1
		}
	}

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

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

	upgrades = {
		building_fortress
	}
}

building_fortress = {
	base_buildtime = @b1_time
	can_build = no
	planetary_ftl_inhibitor = yes
	position_priority = 100
	can_be_ruined = no
	category = army

	building_sets = {
		government
		fortress
	}

	potential = {
		exists = owner
		owner = { is_wilderness_empire = no } # see 'building_planetary_carapace_2'
	}
	allow = {
		has_upgraded_capital = yes
	}

	resources = {
		category = planet_buildings_strongholds
		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 = {
			volatile_motes = @b2_rare_cost
		}
		upkeep = {
			energy = 1
			volatile_motes = @b2_rare_upkeep
		}
	}

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

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

building_planetary_shield_generator = {
	base_buildtime = @b3_time
	planet_limit = 1
	position_priority = 100
	can_be_ruined = no
	category = army

	building_sets = {
		government
		fortress
	}

	potential = {
		exists = owner
		owner = { 
			is_wilderness_empire = no
			is_nomadic = no
		} # see 'building_ozone_thickener'
	}
	allow = {
		has_upgraded_capital = yes
		orbital_ring_and_arkship_equivalent_absent = {
			RING = ring_orbital_shield_generator
			ARKSHIP = arkship_shield_generator
		}
	}

	prerequisites = {
		"tech_planetary_shield_generator"
	}
	show_tech_unlock_if = {
		is_wilderness_empire = no
		is_nomadic = no
	}

	planet_modifier = {
		planet_orbital_bombardment_damage = -0.5
	}
	triggered_planet_modifier = {
		potential = { has_cosmic_storms_dlc = yes }
		planet_storm_devastation_mult = -0.5
	}

	inline_script = {
		script = cosmic_storms/StormBuildingModifiers
	}

	inline_script = { # on_built & on_destroy behaviors
		script = cosmic_storms/PlanetaryShieldOnBuiltDestroy
	}

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

	custom_storm_ai_weight = {
		weight = 0
		modifier = {
			add = 5
			has_designation = col_fortress
		}
		modifier = {
			add = 5
			AND = {
				exists = owner
				solar_system? = {
					exists = owner
					owner = { num_cosmic_storms_encountered >= 2 }
				}
			}
		}
	}
}
