code:
:: secBarracks [nobr]

<<set $nextButton = "Back", $nextLink = "Manage Arcology", $returnTo = "Manage Arcology">>

The Barracks

__Upgrades__

While this a sore sight for many citizens of $arcologies[0].name, the barracks stand proud before you.
<<if $secBarracksUpgrades.size == 0>>
	The building is relatively small and able to house a limited number of units.
<<elseif $secBarracksUpgrades.size == 1>>
	The building has been expanded and can now house more units comfortably.
<<elseif $secBarracksUpgrades.size == 2>>
	The building has been further expanded and can now house a high number of units.
<<elseif $secBarracksUpgrades.size == 3>>
	The building has been greatly expanded and can now house a sizable military.
<<elseif $secBarracksUpgrades.size == 4>>
	The building has been greatly expanded and can now house a small army.
<<else>>
	The building has been greatly expanded and can now house an army worthy of an old world nation.
<</if>>
<<if $secBarracksUpgrades.luxury == 0>>
	The barracks are a spartan building, with little to make the day to day lives of your soldiers pleasant.
<<elseif $secBarracksUpgrades.luxury == 1>>
	The barracks have been made more comfortable by installing high tech furniture.
<<elseif $secBarracksUpgrades.luxury == 2>>
	The barracks have been made more comfortable by installing high tech furniture and advanced kitchen facilities.
<<elseif $secBarracksUpgrades.luxury == 3>>
	The barracks have been made more comfortable by installing high tech furniture and advanced kitchen facilities. It also provides free access to any digital media.
<<else>>
	The barracks have been made more comfortable by installing high tech furniture and advanced kitchen facilities. It also provides free access to any digital media. A small limited access brothel has been added to the structure.
<</if>>
<<if $secBarracksUpgrades.training == 0>>
	The building lacks the space and the equipment to train your units.
<<elseif $secBarracksUpgrades.training == 1>>
	A training facility has been set up, allowing your units to better their skills with time.
<<else>>
	The training facility has been filled with specialized equipment and skilled trainers.
<</if>>
<<if $secBarracksUpgrades.loyaltyMod == 0>>
	The barracks lack an indoctrination facility.
<<elseif $secBarracksUpgrades.loyaltyMod == 1>>
	The barracks have been fitted with an indoctrination facility.
<<else>>
	The barracks have been fitted with an advanced indoctrination facility.
<</if>>

<<if $secBarracksUpgrades.size < 5>>
	<<link "Increase the size of the barracks" "secBarracks">>
		<<run cashX(forceNeg(Math.trunc((5000 * ($secBarracksUpgrades.size + 1))*$upgradeMultiplierArcology)), "capEx")>>
		<<set $secBarracksUpgrades.size += 1>>
		<<set $maxUnits += 2>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat((5000 * ($secBarracksUpgrades.size + 1))*$upgradeMultiplierArcology)>> and will increase the maximum number of units by 2.//
<<else>>
	You've expanded the barracks to their maximum.
<</if>>

<<if $secBarracksUpgrades.luxury == 0>>
	<<link "Increase the quality of life of your soldiers by installing high tech furniture and appliances." "secBarracks">>
		<<set $secBarracksUpgrades.luxury += 1>>
		<<run cashX(forceNeg(Math.trunc(5000*$upgradeMultiplierTrade)), "capEx")>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierTrade))>> and will provide a 5% bonus to morale.//
<<elseif $secBarracksUpgrades.luxury == 1>>
	<<link "Further increase the quality of life of your soldiers by installing advanced kitchen equipment and hiring skilled chefs." "secBarracks">>
		<<set $secBarracksUpgrades.luxury += 1>>
		<<run cashX(forceNeg(Math.trunc(10000*$upgradeMultiplierTrade)), "capEx")>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierTrade))>> and will provide a 5% bonus to morale, for a total of +10%.//
<<elseif $secBarracksUpgrades.luxury == 2>>
	<<link "Further increase the quality of life of your soldiers by providing high speed, free access to digital media" "secBarracks">>
		<<set $secBarracksUpgrades.luxury += 1>>
		<<run cashX(forceNeg(Math.trunc(10000*$upgradeMultiplierTrade)), "capEx")>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierTrade))>> and will provide a 5% bonus to morale, for a total of +15%.//
<<elseif $secBarracksUpgrades.luxury == 3>>
	<<link "Further increase the quality of life of your soldiers by adding and staffing an exclusive brothel to the structure" "secBarracks">>
		<<set $secBarracksUpgrades.luxury += 1>>
		<<run cashX(forceNeg(Math.trunc(15000*$upgradeMultiplierArcology)), "capEx")>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology))>> and will provide a 5% bonus to morale, for a total of +20%.//
<<else>>
	You've made life in your barracks as good as it can get.
<</if>>

<<if $secBarracksUpgrades.training == 0>>
	<<link "Add a training facility to the barracks" "secBarracks">>
		<<set $secBarracksUpgrades.training += 1>>
		<<run cashX(forceNeg(Math.trunc(10000*$upgradeMultiplierArcology)), "capEx")>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology))>> and will allow units to accumulate some experience each week.//
<<elseif $secBarracksUpgrades.training == 1>>
	<<link "Improve the training facility with modern equipment and skilled personnel" "secBarracks">>
		<<set $secBarracksUpgrades.training += 1>>
		<<run cashX(forceNeg(Math.trunc(20000*$upgradeMultiplierTrade)), "capEx")>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat(Math.trunc(20000*$upgradeMultiplierTrade))>> and will allow units to accumulate experience each week.//
<<else>>
	You have improved the training facility to the limit.
<</if>>

<<if $secBarracksUpgrades.loyaltyMod == 0>>
	<<link "Add an indoctrination facility to the barracks" "secBarracks">>
		<<set $secBarracksUpgrades.loyaltyMod += 1>>
		<<run cashX(forceNeg(Math.trunc(10000*$upgradeMultiplierArcology)), "capEx")>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology))>> and will slowly raise loyalty of all units//
<<elseif $secBarracksUpgrades.loyaltyMod == 1>>
	<<link "Improve the indoctrination facility with advanced equipment and skilled personnel" "secBarracks">>
		<<set $secBarracksUpgrades.loyaltyMod += 1>>
		<<run cashX(forceNeg(Math.trunc(20000*$upgradeMultiplierTrade)), "capEx")>>
		<<set $secBarracksUpkeep += $upgradeUpkeep>>
	<</link>>

//Costs <<print cashFormat(Math.trunc(20000*$upgradeMultiplierTrade))>> and will raise loyalty of all units faster.//
<<else>>
	You have improved the indoctrination facility to the limit.
<</if>>

__Units__

Your current maximum number of units is <<print $maxUnits>> (<<print num($secBots.maxTroops+(50*$maxUnits))>> troops), <<print $activeUnits>> (<<print num($secBots.maxTroops+($slavesEmployedManpower)+($militiaEmployedManpower)+($mercEmployedManpower))>> troops) are active and <<print (2 * $readiness)>> units can be deployed. <<if $secBarracksUpgrades.luxury > 0>>The barracks provides <<print $secBarracksUpgrades.luxury * 5>>% bonus morale when battle occurs.<</if>> <<if $secBarracksUpgrades.training > 0>>The training facility will increase the effectiveness of your units with time.<</if>>
<<if $activeUnits >= $maxUnits>>

You have reached the maximum number of units. You'll have to disband one or enlarge the barracks before forming a new unit.
<</if>>
<<if $arcologies[0].FSRomanRevivalist != "unset" || $arcologies[0].FSChineseRevivalist != "unset" || $arcologies[0].FSArabianRevivalist != "unset" || $arcologies[0].FSEdoRevivalist != "unset" || $arcologies[0].FSEgyptianRevivalist != "unset" || $arcologies[0].FSAztecRevivalist != "unset">>
<</if>>

<<replenishAllUnits>>

__Security Drones__
/* drones */

<<secBotsDescription>>

<<if $secBots.active == 1>>
	<<link "Review Equipment and upgrades" "seeUnit">>
		<<set $targetUnit = "secBots">>
	<</link>>
	<<if $secBots.troops < $secBots.maxTroops>>
		|
		<<link "Replenish the unit" "secBarracks">>
			<<run cashX(forceNeg(($secBots.maxTroops - $secBots.troops) * $secBotsCost), "securityExpansion")>>
			<<set $secBots.troops = $secBots.maxTroops>>
		<</link>>
	<</if>>
<<else>>
	<<link "Rebuild the unit" "secBarracks">>
		<<run cashX(forceNeg(($secBots.maxTroops - $secBots.troops) * $secBotsCost), "securityExpansion")>>
		<<set $secBots.troops = $secBots.maxTroops>>
		<<set $secBots.active = 1>>
	<</link>>
<</if>>

__Slaves__

/* slaves */
You are free to organize your menial slaves into fighting units. Currently you have <<print num($menials)>> slaves available, while <<print num($slavesEmployedManpower)>> are already employed as soldiers. During all your battles you lost a total of <<print num($slavesTotalCasualties)>>.
<<run MenialPopCap()>>
<<set _menialPrice = menialSlaveCost()>>
<<set _bulkMax = $PopCap-$menials-$fuckdolls-$menialBioreactors>>
<<if $cash > _menialPrice>>
	<<if _bulkMax > 0>>

		[[Buy|secBarracks][$menials+=1,$menialSupplyFactor-=1,cashX(forceNeg(_menialPrice), "menialTransfer")]]
		<<if $cash > (menialSlaveCost(10))*10>>
			[[(x10)|secBarracks][$menials+=10,$menialSupplyFactor-=10,cashX(forceNeg((menialSlaveCost(10))*10), "menialTransfer")]]
		<</if>>
		<<if $cash > (menialSlaveCost(100))*100>>
			[[(x100)|secBarracks][$menials+=100,$menialSupplyFactor-=100,cashX(forceNeg((menialSlaveCost(100))*100), "menialTransfer")]]
		<</if>>
		<<if $cash > (_menialPrice+1)*2>>
			<<set _menialBulkPremium = Math.trunc(1 + Math.clamp($cash/_menialPrice,0,_bulkMax)/400)>>
			[[(max)|secBarracks][$menials+=Math.trunc(Math.clamp($cash/(_menialPrice+_menialBulkPremium),0,_bulkMax)),$menialSupplyFactor-=Math.trunc(Math.clamp($cash/(_menialPrice+_menialBulkPremium),0,_bulkMax)),cashX(forceNeg(Math.trunc(Math.clamp($cash/(_menialPrice+_menialBulkPremium),0,_bulkMax)*(_menialPrice+_menialBulkPremium))), "menialTransfer")]]
		<</if>>
		//Bulk transactions may require offering a premium.//
	<</if>>
<</if>>

<<set _sL = $slaveUnits.length>>
<<if $menials > 0 && $activeUnits < $maxUnits>>

	<<link "Form a new unit" "secBarracks">>
		<<set _newUnit = {
			ID: 0,
			platoonName: ordinalSuffix(++$createdSlavesUnits) + " slave platoon",
			active: 1,
			isDeployed: 0,
			troops: Math.min($maxTroops, $menials),
			maxTroops: $maxTroops,
			equip: 0,
			training: 0,
			loyalty: random(40,60),
			cyber: 0,
			medics: 0,
			SF: 0,
			commissars: 0,
			battlesFought: 0}>>
		<<generateUnitID _newUnit>>
		<<set $slaveUnits.push(_newUnit)>>
		<<set $menials -= _newUnit.troops>>
		<<set $slavesEmployedManpower += _newUnit.troops>>
		<<set $activeUnits++>>
	<</link>>
<</if>>
<<for _i = 0; _i < _sL; _i++>>
	<<capture _i>>
	<<if $slaveUnits[_i].active == 1>>

		<<slaveUnitsDescription $slaveUnits[_i]>>

		<<link "Disband the unit" "secBarracks">>
			<<set $menials += $slaveUnits[_i].troops>>
			<<set $slavesEmployedManpower -= $slaveUnits[_i].troops>>
			<<set $slaveUnits.deleteAt(_i)>>
			<<set $activeUnits-->>
		<</link>>
		|
		<<link "Review Equipment and upgrades" "seeUnit">>
			<<set $targetUnit = "slaveUnits">>
			<<set $targetIndex = _i>>
		<</link>>

		<<if $slaveUnits[_i].troops < $slaveUnits[_i].maxTroops && $menials > 0>>
			|
			<<link "Replenish unit" "secBarracks">>
				<<if $menials >= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
					<<set $menials -= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
					<<set $slavesEmployedManpower += $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
					<<set _expLoss = ($slaveUnits[_i].maxTroops - $slaveUnits[_i].troops) / $slaveUnits[_i].troops>>
					<<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>>
					<<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>>
				<<else>>
					<<set $slavesEmployedManpower += $menials>>
					<<set _expLoss = $menials / $slaveUnits[_i].troops>>
					<<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>>
					<<set $slaveUnits[_i].troops += $menials>>
					<<set $menials = 0>>
				<</if>>
			<</link>>
		<</if>>

	<<else>>

		$slaveUnits[_i].platoonName lost too many operatives to be considered active.

		<<link "Disband the unit" "secBarracks">>
			<<set _elimUnit = $slaveUnits[_i]>>
			<<set _newSlaveUnits = []>>
			<<for _y = 0; _y < _sL; _y++>>
				<<if $slaveUnits[_y] != _elimUnit>>
					<<set _newSlaveUnits.push($slaveUnits[_y])>>
				<</if>>
			<</for>>
			<<set $slaveUnits = _newSlaveUnits>>
			<<set $activeUnits-->>
		<</link>>

		<<if $menials > 0>>
			|
			<<link "Reform the unit" "secBarracks">>
				<<if $menials >= $slaveUnits[_i].maxTroops>>
					<<set $slavesEmployedManpower += $slaveUnits[_i].maxTroops>>
					<<set $menials -= $slaveUnits[_i].maxTroops>>
					<<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>>
					<<set $slaveUnits[_i].training = 0>>
				<<else>>
					<<set $slavesEmployedManpower += $menials>>
					<<set $slaveUnits[_i].troops += $menials>>
					<<set $menials = 0>>
					<<set $slaveUnits[_i].training = 0>>
				<</if>>
				<<set $slaveUnits[_i].active = 1>>
			<</link>>
		<</if>>
	<</if>>
	<</capture>>
<</for>>

<<if $militiaFounded == 1>>

__Militia__

/* militia */
	You founded the $arcologies[0].name free militia. You are now able to organize your citizens in fighting units.
	<<if $recruitVolunteers == 1>>
		The militia is composed entirely of volunteers, your manpower is approximately 1.5% of the citizens population of your arcology.
	<<elseif $conscription == 1>>
		With the establishment of conscription, your available manpower has increased to now approximately 3% of the arcology's citizens population.
	<<elseif $militaryService == 1>>
		By establishing obligatory military service to obtain citizenship you have enlarged your manpower pool to be approximately 5% of the arcology's citizens population.
	<<elseif $militarizedSociety == 1>>
		With the adoption of a militarized society, your available manpower has swelled to be approximately 15% of the arcology's citizens population.
	<</if>>
	Your current total manpower is <<print num($militiaTotalManpower)>>, of which <<print num($militiaEmployedManpower)>> is in active duty. You lost in total <<print num($militiaTotalCasualties)>> citizens, leaving you with <<print num($militiaFreeManpower)>> available citizens.

	<<set _mL = $militiaUnits.length>>
	<<if $militiaFreeManpower > 0 && $activeUnits < $maxUnits>>

		<<link "Form a new unit" "secBarracks">>
			<<set _newUnit = {
				ID: 0,
				platoonName: ordinalSuffix(++$createdMilitiaUnits) + " citizens' platoon",
				active: 1,
				isDeployed: 0,
				troops: Math.min($maxTroops, $militiaFreeManpower),
				maxTroops: $maxTroops,
				equip: 0,
				training: 0,
				loyalty: random(40,60),
				cyber: 0,
				medics: 0,
				SF: 0,
				commissars: 0,
				battlesFought: 0}>>
			<<generateUnitID _newUnit>>
			<<set $militiaUnits.push(_newUnit)>>
			<<set $militiaFreeManpower -= _newUnit.troops>>
			<<set $militiaEmployedManpower += _newUnit.troops>>
			<<set $activeUnits++>>
		<</link>>
	<</if>>
	<<for _i = 0; _i < _mL; _i++>>
		<<capture _i>>
		<<if $militiaUnits[_i].active == 1>>

			<<militiaUnitsDescription $militiaUnits[_i]>>

			<<link "Disband the unit" "secBarracks">>
				<<set $militiaFreeManpower += $militiaUnits[_i].troops>>
				<<set $militiaEmployedManpower -= $militiaUnits[_i].troops>>
				<<set $militiaUnits.deleteAt(_i)>>
				<<set $activeUnits-->>
			<</link>>
			|
			<<link "Review Equipment and upgrades" "seeUnit">>
				<<set $targetUnit = "militiaUnits">>
				<<set $targetIndex = _i>>
			<</link>>

			<<if $militiaUnits[_i].troops < $militiaUnits[_i].maxTroops && $militiaFreeManpower > 0>>
				|
				<<link "Replenish unit" "secBarracks">>
					<<if $militiaFreeManpower >= $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>>
						<<set $militiaFreeManpower -= $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>>
						<<set $militiaEmployedManpower += $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>>
						<<set _expLoss = ($militiaUnits[_i].maxTroops - $militiaUnits[_i].troops) / $militiaUnits[_i].troops>>
						<<set $militiaUnits[_i].training -= $militiaUnits[_i].training * _expLoss>>
						<<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>>
					<<else>>
						<<set $militiaEmployedManpower += $militiaFreeManpower>>
						<<set _expLoss = $militiaFreeManpower / $militiaUnits[_i].troops>>
						<<set $militiaUnits[_i].training -= $militiaUnits[_i].training * _expLoss>>
						<<set $militiaUnits[_i].troops += $militiaFreeManpower>>
						<<set $militiaFreeManpower = 0>>
					<</if>>
				<</link>>
			<</if>>
		<<else>>

			$militiaUnits[_i].platoonName lost too many operatives to be considered active.

			<<link "Disband the unit" "secBarracks">>
				<<set $militiaFreeManpower += $militiaUnits[_i].troops>>
				<<set $militiaEmployedManpower -= $militiaUnits[_i].troops>>
				<<set _elimUnit = $militiaUnits[_i]>>
				<<set _newMilitiaUnits = []>>
				<<for _y = 0; _y < _sL; _y++>>
					<<if $militiaUnits[_y] != _elimUnit>>
						<<set _newMilitiaUnits.push($militiaUnits[_y])>>
					<</if>>
				<</for>>
				<<set $militiaUnits = _newMilitiaUnits>>
				<<set $activeUnits-->>
			<</link>>

			<<if $militiaFreeManpower > 0>>
				|
				<<link "Reform the unit" "secBarracks">>
					<<if $militiaFreeManpower >= $militiaUnits[_i].maxTroops>>
						<<set $militiaEmployedManpower += $militiaUnits[_i].maxTroops>>
						<<set $militiaFreeManpower -= $militiaUnits[_i].maxTroops>>
						<<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>>
						<<set $militiaUnits[_i].training = 0>>
					<<else>>
						<<set $militiaEmployedManpower += $militiaFreeManpower>>
						<<set $militiaUnits[_i].troops += $militiaFreeManpower>>
						<<set $militiaFreeManpower = 0>>
						<<set $militiaUnits[_i].training = 0>>
					<</if>>
					<<set $militiaUnits[_i].active = 1>>
				<</link>>
			<</if>>
		<</if>>
		<</capture>>
	<</for>>

<<else>>

	You have not yet founded the militia, you will not be able to form citizens units.
<</if>>

<<if $mercenaries >= 1>>

__Mercenaries__

/* mercenaries */
	With the installation of a mercenary company in the arcology, many other are attracted to your free city, hoping to land a contract with you.
	You are able to organize them in units to use in the defense of the arcology. Excluding the defense force you set up, there are <<print num($mercTotalManpower)>> mercenaries in your arcology, of which <<print num($mercEmployedManpower)>> actively employed and <<print $mercFreeManpower>> not yet under contract. In total <<print num($mercTotalCasualties)>> mercenaries have died defending your arcology.

	<<set _meL = $mercUnits.length>>
	<<if $mercFreeManpower > 0 && $activeUnits < $maxUnits>>

		<<link "Form a new unit" "secBarracks">>
			<<set _newUnit = {
				ID: 0,
				platoonName: ordinalSuffix(++$createdMercUnits) + " mercenary platoon",
				active: 1,
				isDeployed: 0,
				troops: Math.min($maxTroops, $mercFreeManpower),
				maxTroops: $maxTroops,
				equip: 0,
				training: 0,
				loyalty: random(40,60),
				cyber: 0,
				medics: 0,
				SF: 0,
				commissars: 0,
				battlesFought: 0}>>
			<<generateUnitID _newUnit>>
			<<set $mercUnits.push(_newUnit)>>
			<<set $mercFreeManpower -= _newUnit.troops>>
			<<set $mercEmployedManpower += _newUnit.troops>>
			<<set $activeUnits++>>
		<</link>>
	<</if>>
	<<for _i = 0; _i < _meL; _i++>>
		<<capture _i>>
		<<if $mercUnits[_i].active == 1>>

			<<mercUnitsDescription $mercUnits[_i]>>

			<<link "Disband the unit" "secBarracks">>
				<<set $mercFreeManpower += $mercUnits[_i].troops>>
				<<set $mercEmployedManpower -= $mercUnits[_i].troops>>
				<<set $mercUnits.deleteAt(_i)>>
				<<set $activeUnits-->>
			<</link>>
			|
			<<link "Review Equipment and upgrades" "seeUnit">>
				<<set $targetUnit = "mercUnits">>
				<<set $targetIndex = _i>>
			<</link>>

			<<if $mercUnits[_i].troops < $mercUnits[_i].maxTroops && $mercFreeManpower > 0>>
				|
				<<link "Replenish unit" "secBarracks">>
					<<if $mercFreeManpower >= $mercUnits[_i].maxTroops - $mercUnits[_i].troops>>
						<<set $mercFreeManpower -= $mercUnits[_i].maxTroops - $mercUnits[_i].troops>>
						<<set $mercEmployedManpower += $mercUnits[_i].maxTroops - $mercUnits[_i].troops>>
						<<set _expLoss = ($mercUnits[_i].maxTroops - $mercUnits[_i].troops) / $mercUnits[_i].troops>>
						<<set $mercUnits[_i].training -= $mercUnits[_i].training * _expLoss>>
						<<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>>
					<<else>>
						<<set $mercEmployedManpower += $mercFreeManpower>>
						<<set _expLoss = $mercFreeManpower / $mercUnits[_i].troops>>
						<<set $mercUnits[_i].training -= $mercUnits[_i].training * _expLoss>>
						<<set $mercUnits[_i].troops += $mercFreeManpower>>
						<<set $mercFreeManpower = 0>>
					<</if>>
				<</link>>
			<</if>>

		<<else>>

			$mercUnits[_i].platoonName lost too many operatives to be considered active.

			<<link "Disband the unit" "secBarracks">>
				<<set _elimUnit = $mercUnits[_i]>>
				<<set _newMercUnits = []>>
				<<for _y = 0; _y < _sL; _y++>>
					<<if $mercUnits[_y] != _elimUnit>>
						<<set _newMercUnits.push($mercUnits[_y])>>
					<</if>>
				<</for>>
				<<set $mercUnits = _newMercUnits>>
				<<set $activeUnits-->>
			<</link>>

			<<if $mercFreeManpower > 0>>
				|
				<<link "Reform the unit" "secBarracks">>
					<<if $mercFreeManpower >= $mercUnits[_i].maxTroops>>
						<<set $mercEmployedManpower += $mercUnits[_i].maxTroops>>
						<<set $mercFreeManpower -= $mercUnits[_i].maxTroops>>
						<<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>>
						<<set $mercUnits[_i].training = 0>>
					<<else>>
						<<set $mercEmployedManpower += $mercFreeManpower>>
						<<set $mercUnits[_i].troops += $mercFreeManpower>>
						<<set $mercFreeManpower = 0>>
						<<set $mercUnits[_i].training = 0>>
					<</if>>
					<<set $mercUnits[_i].active = 1>>
				<</link>>
			<</if>>
		<</if>>
		<</capture>>
	<</for>>
<<else>>

	Mercenaries are not allowed inside the arcology. You will not be able to recruit mercenary units.
<</if>>


code:
:: secExpOptions [nobr]

<<set $showEncyclopedia = 1, $encyclopedia = "Security Expansion", $nextButton = "Back to Options", $nextLink = "Options">>

__Battles__:
<<if $terrain != "oceanic">>

<<if $battlesEnabled == 0>>
		Battles are @@.red;DISABLED.@@
		<<link "Enable battles" "secExpOptions">>
			<<set $battlesEnabled = 1>>
		<</link>>
	<<else>>
		Battles are @@.cyan;ENABLED.@@
		<<link "Disable battles" "secExpOptions">>
			<<set $battlesEnabled = 0>>
		<</link>>
	<</if>>

    //Enable/disable battles.//
	<<if $battlesEnabled == 1>>

		<<if $majorBattlesEnabled == 0>>
			Major battles are @@.red;DISABLED.@@
			<<link "Enable major battles" "secExpOptions">>
				<<set $majorBattlesEnabled = 1>>
				<<set $battlesEnabled = 1>>
			<</link>>
		<<else>>
			Major battles are @@.cyan;ENABLED.@@
			<<link "Disable major battles" "secExpOptions">>
				<<set $majorBattlesEnabled = 0>>
			<</link>>
		<</if>>

    //Enable/disable late game large scale battles.//

		<<if $majorBattleGameOver == 0>>
			Major battles can cause gameover is @@.red;FALSE.@@
			<<link "Activate game loss in case of major battle defeat" "secExpOptions">>
				<<set $majorBattleGameOver = 1>>
			<</link>>
		<<else>>
			Major battles can cause gameover is @@.cyan;TRUE.@@
			<<link "Deactivate game loss in case of major battle defeat" "secExpOptions">>
				<<set $majorBattleGameOver = 0>>
			<</link>>
		<</if>>

    //By default a total defeat in a major battle will cause a gameover.//

		<<if $forceBattle == 0>>
			Battle guaranteed this week is @@.red;FALSE.@@
			<<link "Force engagement every week" "secExpOptions">>
				<<set $forceBattle = 1>>
			<</link>>

		<<else>>
			Battle guaranteed this week is @@.cyan;TRUE.@@
			<<link "Do not force engagement every week" "secExpOptions">>
				<<set $forceBattle = 0>>
				<<set $forceMajorBattle = 0>>
			<</link>>
		<</if>>

    //Will force battles to happen every week.//

		<<if $forceMajorBattle == 0>>
			Major battle guaranteed this week is @@.red;FALSE.@@
			<<link "Force major engagement every week" "secExpOptions">>
				<<set $forceMajorBattle = 1>>
				<<set $forceBattle = 1>>
			<</link>>
		<<else>>
			Major battle guaranteed this week is @@.cyan;TRUE.@@
			<<link "Do not force major engagement every week" "secExpOptions">>
				<<set $forceMajorBattle = 0>>
			<</link>>
		<</if>>

    //Will force major battles to happen every week. //
	<</if>>
<<else>>

Oceanic arcologies are not by default subject to external attacks. You can however allow them to happen anyway. If you choose to do so please keep in mind that descriptions and mechanics are not intended for naval combat but land combat.

	<<if $battlesEnabled == 0>>
		Battles are @@.red;DISABLED.@@
		<<link "Enable battles" "secExpOptions">>
			<<set $battlesEnabled = 1>>
		<</link>>
	<<else>>
		Battles are @@.cyan;ENABLED.@@
		<<link "Disable battles" "secExpOptions">>
			<<set $battlesEnabled = 0>>
		<</link>>
	<</if>>

    //Enable/disable battles.//
	<<if $battlesEnabled == 1>>

		<<if $majorBattlesEnabled == 0>>
			Major battles are @@.red;DISABLED.@@
			<<link "Enable major battles" "secExpOptions">>
				<<set $majorBattlesEnabled = 1>>
				<<set $battlesEnabled = 1>>
			<</link>>
		<<else>>
			Major battles are @@.cyan;ENABLED.@@
			<<link "Disable major battles" "secExpOptions">>
				<<set $majorBattlesEnabled = 0>>
			<</link>>
		<</if>>

    //Enable/disable late game large scale battles.//

		<<if $majorBattleGameOver == 0>>
			Major battles can cause gameover is @@.red;FALSE.@@
			<<link "Activate game loss in case of major battle defeat" "secExpOptions">>
				<<set $majorBattleGameOver = 1>>
			<</link>>
		<<else>>
			Major battles can cause gameover is @@.cyan;TRUE.@@
			<<link "Deactivate game loss in case of major battle defeat" "secExpOptions">>
				<<set $majorBattleGameOver = 0>>
			<</link>>
		<</if>>

    //By default a total defeat in a major battle will cause a gameover.//

		<<if $forceBattle == 0>>
			Battle guaranteed this week is @@.red;FALSE.@@
			<<link "Force engagement every week" "secExpOptions">>
				<<set $forceBattle = 1>>
			<</link>>
		<<else>>
			Battle guaranteed this week is @@.cyan;TRUE.@@
			<<link "Do not force engagement every week" "secExpOptions">>
				<<set $forceBattle = 0>>
			<</link>>
		<</if>>

    //Will force battles to happen every week.//

		<<if $forceMajorBattle == 0>>
			Major battle guaranteed this week is @@.red;FALSE.@@
			<<link "Force major engagement every week" "secExpOptions">>
				<<set $forceMajorBattle = 1>>
				<<set $forceBattle = 1>>
			<</link>>
		<<else>>
			Major battle guaranteed this week is @@.cyan;TRUE.@@
			<<link "Do not force major engagement every week" "secExpOptions">>
				<<set $forceMajorBattle = 0>>
			<</link>>
		<</if>>

    //Will force major battles to happen every week. //
	<</if>>
<</if>>

__Rebellions__:

	<<if $rebellionsEnabled == 0>>
		Rebellions are @@.red;DISABLED.@@
		<<link "Enable rebellions" "secExpOptions">>
			<<set $rebellionsEnabled = 1>>
		<</link>>
	<<else>>
		Rebellions are @@.cyan;ENABLED.@@
		<<link "Disable rebellions" "secExpOptions">>
			<<set $rebellionsEnabled = 0>>
		<</link>>
	<</if>>

    //Enable/disable rebellions.//

	<<if $rebellionsEnabled == 1>>
		<<if $rebellionGameOver == 0>>
			Rebellions can cause gameover is @@.red;FALSE.@@
			<<link "Activate game loss in case of rebellions succeeding" "secExpOptions">>
				<<set $rebellionGameOver = 1>>
			<</link>>
		<<elseif $rebellionGameOver == 1>>
			Rebellions can cause gameover is @@.cyan;TRUE.@@
			<<link "Deactivate game loss in case of rebellions succeeding" "secExpOptions">>
				<<set $rebellionGameOver = 0>>
			<</link>>
		<</if>>

    //Determines whether a total defeat in a rebellion will cause a gameover.//

		<<if $forceRebellion == 0>>
			Rebellions guaranteed this week is @@.red;FALSE.@@
			<<link "Force engagement every week" "secExpOptions">>
				<<set $forceRebellion = 1>>
			<</link>>
		<<else>>
			Rebellions guaranteed this week is @@.cyan;TRUE.@@
			<<link "Do not force engagement every week" "secExpOptions">>
				<<set $forceRebellion = 0>>
			<</link>>
		<</if>>

    //Will force rebellions to happen every week. Rebellions will take precedence over battles.//
	<</if>>

<<if $showBattleStatistics == 0 &&($battlesEnabled == 1 || $rebellionsEnabled == 1)>>

	Detailed battle statistics are @@.red;HIDDEN.@@
	<<link "Enable detailed battle statistics" "secExpOptions">>
		<<set $showBattleStatistics = 1>>
	<</link>>

    //Will show detailed statistics and battle turns.//

<<elseif ($battlesEnabled == 1 || $rebellionsEnabled == 1)>>

	Detailed battle statistics are @@.cyan;SHOWN.@@
	<<link "Disable detailed battle statistics" "secExpOptions">>
		<<set $showBattleStatistics = 0>>
	<</link>>

    //Will show detailed statistics and battle turns.//
<</if>>

<<if $allowPrestigeFromBattles == 0 && $battlesEnabled == 1>>

	Battles can give prestige to slaves is @@.red;DISABLED.@@
	<<link "enable prestige from battles for slaves" "secExpOptions">>
		<<set $allowPrestigeFromBattles = 1>>
	<</link>>

    //If enabled, slaves will gain a rank of prestige for every 10 victories scored under their command.//

<<elseif $battlesEnabled == 1>>

	Battles can give prestige to slaves is @@.cyan;ENABLED.@@
	<<link "Disable prestige from battles for slaves" "secExpOptions">>
		<<set $allowPrestigeFromBattles = 0>>
	<</link>>

    //If enabled, slaves will gain a rank of prestige for every 10 victories scored under their command.//
<</if>>

__Battles/Rebellions Difficulty__:

Difficulty is set to:
<<if $difficulty == 0.5>>
	@@.green;Very easy@@
<<elseif $difficulty == 0.75>>
	@@.limegreen;Easy@@
<<elseif $difficulty == 1>>
	@@.yellow;Normal@@
<<elseif $difficulty == 1.25>>
	@@.red;Hard@@
<<else>>
	@@.darkred;Very hard@@
<</if>>

<<link "Very easy">>
	<<set $difficulty = 0.5>>
	<<replace "#difficulty">>
		@@.green;Very easy@@
	<</replace>>
<</link>>
| <<link "Easy">>
	<<set $difficulty = 0.75>>
	<<replace "#difficulty">>
		@@.limegreen;Easy@@
	<</replace>>
<</link>>
| <<link "Normal">>
	<<set $difficulty = 1>>
	<<replace "#difficulty">>
		@@.yellow;Normal@@
	<</replace>>
<</link>>
| <<link "Hard">>
	<<set $difficulty = 1.25>>
	<<replace "#difficulty">>
		@@.red;Hard@@
	<</replace>>
<</link>>
| <<link "Very hard">>
	<<set $difficulty = 1.5>>
	<<replace "#difficulty">>
		@@.darkred;Very hard@@
	<</replace>>
<</link>>

__Battles frequency__:

Battle frequency is set to:
<<if $battleFrequency == 0.5>>
	@@.green;Very infrequent@@
<<elseif $battleFrequency == 0.75>>
	@@.limegreen;Infrequent@@
<<elseif $battleFrequency == 1>>
	@@.yellow;Normal@@
<<elseif $battleFrequency == 1.25>>
	@@.red;Frequent@@
<<else>>
	@@.darkred;Very frequent@@
<</if>>

<<link "Very infrequent">>
	<<set $battleFrequency = 0.5>>
	<<replace "#battleFrequency">>
		@@.green;Very infrequent@@
	<</replace>>
<</link>>
| <<link "Infrequent">>
	<<set $battleFrequency = 0.75>>
	<<replace "#battleFrequency">>
		@@.limegreen;Infrequent@@
	<</replace>>
<</link>>
| <<link "Normal">>
	<<set $battleFrequency = 1>>
	<<replace "#battleFrequency">>
		@@.yellow;Normal@@
	<</replace>>
<</link>>
| <<link "Frequent">>
	<<set $battleFrequency = 1.25>>
	<<replace "#battleFrequency">>
		@@.red;Frequent@@
	<</replace>>
<</link>>
| <<link "Very frequent">>
	<<set $battleFrequency = 1.5>>
	<<replace "#battleFrequency">>
		@@.darkred;Very frequent@@
	<</replace>>
<</link>>

__Major battle multiplier__:

Major battle multiplier is set to:
<<if $majorBattleMult == 0.5>>
	@@.green;Very low@@
<<elseif $majorBattleMult == 0.75>>
	@@.limegreen;Low@@
<<elseif $majorBattleMult == 1>>
	@@.yellow;Normal@@
<<elseif $majorBattleMult == 1.25>>
	@@.red;high@@
<<else>>
	@@.darkred;Very high@@
<</if>>

<<link "Very low">>
	<<set $majorBattleMult = 0.5>>
	<<replace "#majorBattleMult">>
		@@.green;Very low@@
	<</replace>>
<</link>>
| <<link "Low">>
	<<set $majorBattleMult = 0.75>>
	<<replace "#majorBattleMult">>
		@@.limegreen;Low@@
	<</replace>>
<</link>>
| <<link "Normal">>
	<<set $majorBattleMult = 1>>
	<<replace "#majorBattleMult">>
		@@.yellow;Normal@@
	<</replace>>
<</link>>
| <<link "High">>
	<<set $majorBattleMult = 1.25>>
	<<replace "#majorBattleMult">>
		@@.red;High@@
	<</replace>>
<</link>>
| <<link "Very high">>
	<<set $majorBattleMult = 1.5>>
	<<replace "#majorBattleMult">>
		@@.darkred;Very high@@
	<</replace>>
<</link>>

__Rebellions buildup speed__:

Rebellion speed is set to:
<<if $rebellionSpeed == 0.5>>
	@@.green;Very slow@@
<<elseif $rebellionSpeed == 0.75>>
	@@.limegreen;Slow@@
<<elseif $rebellionSpeed == 1>>
	@@.yellow;Normal@@
<<elseif $rebellionSpeed == 1.25>>
	@@.red;Fast@@
<<else>>
	@@.darkred;Very fast@@
<</if>>

<<link "Very slow">>
	<<set $rebellionSpeed = 0.5>>
	<<replace "#rebellionSpeed">>
		@@.green;Very slow@@
	<</replace>>
<</link>>
| <<link "Slow">>
	<<set $rebellionSpeed = 0.75>>
	<<replace "#rebellionSpeed">>
		@@.limegreen;Slow@@
	<</replace>>
<</link>>
| <<link "Normal">>
	<<set $rebellionSpeed = 1>>
	<<replace "#rebellionSpeed">>
		@@.yellow;Normal@@
	<</replace>>
<</link>>
| <<link "Fast">>
	<<set $rebellionSpeed = 1.25>>
	<<replace "#rebellionSpeed">>
		@@.red;Fast@@
	<</replace>>
<</link>>
| <<link "Very fast">>
	<<set $rebellionSpeed = 1.5>>
	<<replace "#rebellionSpeed">>
		@@.darkred;Very fast@@
	<</replace>>
<</link>>

__Debug/cheats:__
<<run MenialPopCap()>>

<<link "Set loyalty high" "secExpOptions">>
	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<set $militiaUnits[_i].loyalty = random(80,100)>>
	<</for>>

	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<set $slaveUnits[_i].loyalty = random(80,100)>>
	<</for>>

	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<set $mercUnits[_i].loyalty = random(80,100)>>
	<</for>>
<</link>>
| <<link "Set loyalty average" "secExpOptions">>
	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<set $militiaUnits[_i].loyalty = random(40,60)>>
	<</for>>

	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<set $slaveUnits[_i].loyalty = random(40,60)>>
	<</for>>

	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<set $mercUnits[_i].loyalty = random(40,60)>>
	<</for>>
<</link>>
| <<link "Set loyalty low" "secExpOptions">>
	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<set $militiaUnits[_i].loyalty = random(20)>>
	<</for>>

	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<set $slaveUnits[_i].loyalty = random(20)>>
	<</for>>

	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<set $mercUnits[_i].loyalty = random(20)>>
	<</for>>
<</link>>
| <<link "Randomize loyalty" "secExpOptions">>
	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<set $militiaUnits[_i].loyalty = random(100)>>
	<</for>>

	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<set $slaveUnits[_i].loyalty = random(100)>>
	<</for>>

	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<set $mercUnits[_i].loyalty = random(100)>>
	<</for>>
<</link>>

<<link "Give Authority" "secExpOptions">>
	<<set $authority = Math.clamp($authority + 1000, 0, 20000)>>
<</link>>
| <<link "Remove Authority" "secExpOptions">>
	<<set $authority = Math.clamp($authority - 1000, 0, 20000)>>
<</link>>

<<link "Raise security" "secExpOptions">>
	<<set $security = Math.clamp($security + 5, 0, 100)>>
<</link>>
| <<link "Lower security" "secExpOptions">>
	<<set $security = Math.clamp($security - 5, 0, 100)>>
<</link>>

<<link "Raise crime" "secExpOptions">>
	<<set $crime = Math.clamp($crime + 5, 0, 100)>>
<</link>>
| <<link "Lower crime" "secExpOptions">>
	<<set $crime = Math.clamp($crime - 5, 0, 100)>>
<</link>>

<<link "Give menial slaves" "secExpOptions">>
	<<set $menials = Math.clamp($menials + 30, 0, $PopCap)>>
<</link>>
| <<link "Remove menial slaves" "secExpOptions">>
	<<set $menials = Math.clamp($menials - 30, 0, $PopCap)>>
<</link>>

<<link "Give militia manpower" "secExpOptions">>
	<<set $militiaFreeManpower += 30>>
	<<recalcManpower>>
<</link>>
| <<link "Remove militia manpower" "secExpOptions">>
	<<set $militiaFreeManpower = Math.clamp($militiaFreeManpower - 30, 0, $militiaFreeManpower)>>
	<<recalcManpower>>
<</link>>

<<link "Give mercs manpower" "secExpOptions">>
	<<set $mercFreeManpower += 30>>
	<<recalcManpower>>
<</link>>
| <<link "Remove mercs manpower" "secExpOptions">>
	<<set $mercFreeManpower = Math.clamp($mercFreeManpower - 30, 0, $mercFreeManpower)>>
	<<recalcManpower>>
<</link>>

<<link "Add citizens" "secExpOptions">> /*Will no longer work as intended due to population changes*/
	<<set $lowerClass += 200>>
<</link>>
| <<link "Remove citizens" "secExpOptions">> /*also no longer properly functional*/
	<<set $lowerClass -= 200>>
	<<if $lowerClass < 0>>
		<<set $lowerClass = 0>>
	<</if>>
<</link>>

<<link "Add slaves" "secExpOptions">> /*Will work to a limited degree, minimums and maximums for slaves are set through population*/
	<<set $NPCSlaves += 200>>
<</link>>
| <<link "Remove slaves" "secExpOptions">> /*Will work to a limited degree*/
	<<set $NPCSlaves -= 200>>
	<<if $NPCSlaves < 0>>
		<<set $NPCSlaves = 0>>
	<</if>>
<</link>>

<<link "Raise prosperity" "secExpOptions">>
	<<set $arcologies[0].prosperity = Math.clamp($arcologies[0].prosperity + 10, 0, 1000)>>
<</link>>
| <<link "Lower prosperity" "secExpOptions">>
	<<set $arcologies[0].prosperity = Math.clamp($arcologies[0].prosperity - 10, 0, 1000)>>
<</link>>


code:
:: secExpSmilingMan [nobr]

The Smiling Man

<<setAssistantPronouns>>
<<if $smilingManProgress == 0>>
	<<set $nextButton = "Continue", $nextLink = "Random Nonindividual Event">>

	/* TODO: fix grammatical errors and clean this block up */
	During your morning routine, you come across a peculiar report: it's been several weeks now that your arcology has been the victim of a series of cyber-crimes conducted by a mysterious figure.
	The egocentric criminal took great pride in their acts, to the point of signing his acts with their peculiar symbol: a stylized smiling face. Your arcology was not the only one under assault by the
	machinations of the one the media quickly nicknamed //the Smiling Man//.

Despite the sheer damage this criminal was doing, you cannot help but admire the skill with which every misdeed is carried — the worst white collar crimes of the century, carried out with such elegance
	that they almost seemed the product of natural laws, rather than the masterful manipulation of the digital market.
	While you sift through the pages of the report, $assistantName remains strangely quiet. "I'm worried, <<= properTitle()>> — this individual seems to be able to penetrate whichever system garners his attention. I... feel vulnerable," _heA says. "It's not something I'm used to."

Fortunately you have not been hit directly by this criminal — not yet at least. Still, the repercussions of numerous bankruptcies take their toll on your arcology, whose @@.red;prosperity suffers.@@

<<set $arcologies[0].prosperity *= random(80,90) * 0.01>>

	<<if $cash >= 10000>>
		<<link "Devote funds to the search for this dangerous criminal">>
			<<run cashX(-10000, "event")>>
			<<set $investedFunds = 1>>
			<<set $relationshipLM += 1>>
			<<set $smilingManProgress += 1>>
			<<replace "#result">>
				You devote funds to capture and neutralize the threat. You cannot help but wonder what the end game of this "smiling man" is. Money? Fame? Or is he on an ideological crusade?
			<</replace>>
		<</link>>

		<<link "Attempt to contact the mysterious figure">>
			<<run cashX(-10000, "event")>>
			<<set $investedFunds = 1>>
			<<set $relationshipLM += 2>>
			<<set $smilingManProgress += 1>>
			<<replace "#result">>
				You devote funds to an attempt at communicating with the smiling man. You cannot help but wonder what the end game of this "smiling man" is. Money? Fame? Or is he on an ideological crusade?
			<</replace>>
		<</link>>

		<<link "Invest funds to increase the cyber-security of the arcology">>
			<<run cashX(-10000, "event")>>
			<<set $investedFunds = 1>>
			<<set $relationshipLM += random(5,10)>>
			<<set $smilingManProgress += 1>>
			<<replace "#result">>
				You devote funds to the improvement of the cyber-security of your arcology. You cannot help but wonder what the end game of this "smiling man" is. Money? Fame? Or is he on an ideological crusade?
			<</replace>>
		<</link>>
	<<else>>
		Not enough funds to take further action.
	<</if>>

	<<link "Ignore the issue">>
		<<set $smilingManProgress += 1>>
		<<replace "#result">>
			You do not consider this individual a threat.
		<</replace>>
	<</link>>

<<elseif $smilingManProgress == 1>>
	<<set $nextButton = "Continue", $nextLink = "Random Nonindividual Event">>

	You have just reached your penthouse when your faithful assistant appears in front of you, evidently excited.
	"<<= properTitle()>>, I have just received news of a new attack by the Smiling Man. It appears a few hours ago he infiltrated another arcology and caused a catastrophic failure of its power plant.
	Between old debts and the loss of value for his shares, the owner went bankrupt in minutes. It seems the Smiling Man managed to keep a small auxiliary generator functioning enough to project a giant holographic picture of his symbol on the arcology's walls.
	Say what you will about his actions, but you can't deny he has style... Anyways, this opens up a great opportunity to gain control of the structure for ourselves."
	It is indeed a great opportunity, one you cannot resist. You quickly organize the affair and in a few minutes a message reaches your assistant.

"Should I open it?" your assistant asks. You silently nod.

Suddenly the room flashes red, while your assistant fades for half a second. When _heA reappears, _hisA face has been replaced by a stylized smiling face.

"Hello, my dear $PC.name. I can call you $PC.name, right? I've been keeping an eye on you for so long now, it feels like we're friends! I am terribly sorry for my unannounced visit, but I wanted to meet face to face... well, face to hologram." it says, letting out a childlike giggle.
	"I'm sure you're aware of my recent activities around this rock of ours, and, well, to put it simply, it's your turn to contribute to my great project! You'll love it when you see it, I'm sure! By the way, thanks for the offer — it's so nice to see people contribute to a worthy cause so generously! Well, I've taken enough of your time, see you soon!"

The lights flicker once more and an instant later your assistant returns to _hisA usual self.

"I... I — I couldn't stop him! I'm sorry, <<= properTitle()>>."

You waste no time in rushing to the console and checking your finances. It's as you feared, @@.red;you have been robbed.@@
	<<set _lostCash = Math.clamp(50000 * Math.trunc($week / 20), 50000, 1000000)>>
	<<if $assistantPower == 1>>
		<<set _lostCash -= 20000>>

Fortunately, the computing power available to $assistantName allowed _himA to somewhat limit the losses.
	<<elseif $assistantPower == 2>>
		<<set _lostCash -= 30000>>

Fortunately, the computing power available to $assistantName allowed _himA to limit the losses.
	<</if>>
	<<if $secUpgrades.cyberBots == 1>>
		<<set _lostCash -= 30000>>
		The additional cyber defenses acquired and running in the security HQ <<if _lostCash < 200000>>further<</if>> limit the damage.
	<</if>>
	<<if $investedFunds == 1>>
		<<set _lostCash -= 20000>>
		The funding you dedicated to the Smiling Man case saved some of the assets that would have been otherwise lost.
	<</if>>
	<<run cashX(forceNeg(_lostCash), "event")>>

	<<link ""I want him dead. Now."">>
		<<set $relationshipLM -= 1>>
		<<set $smilingManProgress += 1>>
		<<replace "#result">>
			You command your loyal operatives to double down on the search and elimination of the threat.
		<</replace>>
	<</link>>

	<<link ""I want him, dead or alive!"">>
		<<set $relationshipLM += 1>>
		<<set $smilingManProgress += 1>>
		<<replace "#result">>
			You command your loyal operatives to double down on the search and capture of the threat.
		<</replace>>
	<</link>>

	<<link ""If we don't find him soon, we will regret it."">>
		<<set $relationshipLM += 2>>
		<<set $smilingManProgress += 1>>
		<<replace "#result">>
			You command your loyal operatives to double down on the search and neutralization of the threat.
		<</replace>>
	<</link>>

	<<link ""He got what he wanted. Hopefully, we will be left in peace."">>
		<<set $smilingManProgress += 1>>
		<<set $nextButton = "Continue", $nextLink = "Random Nonindividual Event">>
		<<replace "#result">>
			You take no further action. Hopefully this ordeal is over.
		<</replace>>
	<</link>>

<<elseif $smilingManProgress == 2>>
	<<set $nextButton = "Continue", $nextLink = "Random Nonindividual Event">>

	<<set $smilingManWeek = $week>>
	When $assistantName violently wakes you up, _hisA worried expression can mean only one thing: the Smiling Man had been back. "Today at midnight a new site popped up in the web: it's a very simple site, no visuals, no text; only a countdown ticking away. It will reach zero this evening." your assistant says.
	This is troubling, yet somewhat exciting. The Smiling Man never failed to cause damage, but his ego had gotten the best of him this time — having time to prepare before their attack will give you a chance to find them. For the rest of the day you do your best to plan, prepare and focus.

Evening came faster than you anticipated. Your security team was already at full alert, waiting for any signal on the horizon. The die was cast.

Suddenly all the computers in the room begin to act strangely, then it happened. On all of the screens across the arcology the Smiling Man's icon appears, then every speaker begins broadcasting the same voice, one that you have already heard once before:

"Hello citizens of $arcologies[0].name! I am here on this special day to relay to you a very important message: we find ourselves in very peculiar times, times of strife and suffering! But these are also times of change and regeneration! Indeed, I say humanity itself is regenerating, turning into a new being for which the
	ideals of the old world no longer hold meaning. A new blank page from which humanity can begin to prosper again.

Alas, my friends, not all is good, as in this rebirth a great injustice is being perpetrated. If we truly want to ascend to this new form of humanity the old must give way to the new. If we must cleanse our mind of old ideas, our world must cleanse itself of them as well.
	It's to fix this injustice, that I worked so hard all this time! To cleanse the world of the old, we must get rid of our precious, precious data. At the end of this message every digital device will see its memory erased, every archive cleaned, every drive deleted.

It will be a true rebirth! A true new beginning! No longer will the chains of the past keep humanity anchored!"

The voice stopped for a second.

"Have a good day," it simply concluded.

Then it happened.

In little more than seconds all the data collected in the years past vanished. It's a disaster.
	<<if $cash < 0>>
		The vast majority of currency is digital, so the actions of the Smiling Man have a devastating effect on the money supply. Luckily for you this means that your @@.yellowgreen;debt is reduced.@@
	<<else>>
		The vast majority of currency is digital, so the actions of the Smiling Man have a devastating effect on the money supply. Unfortunately this means that your @@.red;cash reserves are gutted.@@
	<</if>>
	<<run cashX(($cash * 0.2)-$cash, "event")>>
	You are not the only one affected by this however. @@.red;The economy of the entire world is severely affected@@ by the loss of vast quantities of currency. Who knows how long will it take for the global economy to recover.
	<<set $globalCrisisWeeks = random(8,16)>>
	Trade is @@.red;severely affected.@@
	<<set $trade *= 0.2>>
	With the loss of so much information, most of your accomplishments are simply forgotten, so @@.red;your reputation suffers.@@
	<<run repX(($rep * 0.6)-$rep, "event")>>

	<<if $arcologies[0].ownership >= 60>>
		<<if $authority <= 10000>>
			<<for _i = 1; _i < $sectors.length; _i++>>
				<<if $sectors[_i].ownership == 1>>
					<<if $sectors[_i].type != "Brothel">>
					<<if $sectors[_i].type != "Club">>
					<<if $sectors[_i].type != "Arcade">>
					<<if $sectors[_i].type != "Dairy">>
					<<if $sectors[_i].type != "Pit">>
					<<if $sectors[_i].type != "Sweatshops">>
					<<if $sectors[_i].type != "Pens">>
					<<if $sectors[_i].type != "Barracks">>
					<<if random(1,100) >= 66>>
						<<set $sectors[_i].ownership = 0>>
						Vast amount of data relative to the ownership of the arcology is lost. You lost all legal claims to one of the sectors.
						<<break>>
					<</if>>
					<</if>>
					<</if>>
					<</if>>
					<</if>>
					<</if>>
					<</if>>
					<</if>>
					<</if>>
				<</if>>
			<</for>>
			Vast amount of data relative to the ownership of the arcology is lost. You would've run the risk of losing ownership of one of the sectors, but fortunately your authority is so high your citizens do not dare question your claims even in the absence of a valid legal case.
		<</if>>
	<</if>>
	<<if $secUpgrades.coldstorage > 3>>
		Your cold storage facility has ensured that the Smiling Man's destruction of the primary archives was unable to damage the security of your arcology.
	<<elseif $secUpgrades.coldstorage == 0>>
		Your security department sees its archives butchered by the Smiling Man. Almost all data on criminals, citizens, and operations are lost. The @@.red;security of the arcology is greatly reduced.@@ Criminals, on the other hand, with their past erased, cannot wait to join this new world, so @@.red;crime will inevitably increase.@@
		<<set $security = Math.clamp($security * 0.2,0,100)>>
		<<set $crime = Math.clamp($crime * 1.5, 20,100)>>
	<</if>>

A short, meek man approaches you with a weak smile. "Not all is lost, <<= properTitle()>>. We have a lead on him — he is here, in $arcologies[0].name."

Despite the bleak situation, you cannot help but smile back.

	<<link ""Eliminate the threat, once and for all."">>
		<<set $relationshipLM -= 1>>
		<<set $smilingManProgress += 1>>
		<<replace "#result">>
			You command your loyal operatives to prepare for a manhunt.
		<</replace>>
	<</link>>

	<<link ""Bring him to me."">>
		<<set $relationshipLM += 1>>
		<<set $smilingManProgress += 1>>
		<<replace "#result">>
			You command your loyal operatives to prepare for a manhunt.
		<</replace>>
	<</link>>

	<<link ""Such skill on my side would be a great boon. Find him."">>
		<<set $relationshipLM += 2>>
		<<set $smilingManProgress += 1>>
		<<replace "#result">>
			You command your loyal operatives to prepare for a manhunt.
		<</replace>>
	<</link>>

	<<link ""He finally got what he always wanted. Let him have his victory, we have better things to do."">>
		<<set $smilingManProgress += 1>>
		<<set $nextButton = "Continue", $nextLink = "Random Nonindividual Event">>
		<<replace "#result">>
			You take no further action. Hopefully this ordeal is finally over.
		<</replace>>
	<</link>>

<<elseif $smilingManProgress == 3>>
	<<set $nextButton = " ">>

	<<set $activeSlaveOneTimeMinAge = 16>>
	<<set $activeSlaveOneTimeMaxAge = 18>>
	<<set $one_time_age_overrides_pedo_mode = 1>>
	<<set $oneTimeDisableDisability = 1>>
	<<set $fixedRace = "asian">>
	<<set $fixedNationality = "Japanese">>
	<<if $seeDicks != 100>>
		<<set $activeSlave = GenerateNewSlave("XX")>>
		<<set $activeSlave.faceShape = "cute">>
		<<set $activeSlave.boobShape = "perky">>
		<<set $activeSlave.nipples = "cute">>
		<<set $activeSlave.boobs = 450>>
		<<set $activeSlave.vagina = 0>>
		<<set $activeSlave.ovaries = 1>>
	<<else>>
		<<set $activeSlave = GenerateNewSlave("XY")>>
		<<set $activeSlave.boobs = 250>>
		<<set $activeSlave.faceShape = "androgynous">>
		<<set $activeSlave.boobShape = "perky">>
	<</if>>
	<<set $activeSlave.origin = "She was a criminal mastermind, captured shortly after completing her master plan.">>
	<<set $activeSlave.career = "a student from a private school">>
	<<set $activeSlave.intelligence = 100>>
	<<set $activeSlave.intelligenceImplant = 30>>
	<<set $activeSlave.slaveSurname = "Yamadera">>
	<<set $activeSlave.birthSurname = "Yamadera">>
	<<set $activeSlave.skin = "pale">>
	<<set $activeSlave.devotion = 5 * $relationshipLM>>
	<<set $activeSlave.trust = 5 * $relationshipLM>>
	<<set $activeSlave.face = random(10,50)>>
	<<set $activeSlave.health = 70>>
	<<set $activeSlave.teeth = "normal">>
	<<set $activeSlave.nipples = "cute">>
	<<set $activeSlave.areolae = 0>>
	<<set $activeSlave.anus = 0>>
	<<set $activeSlave.butt = 3>>
	<<set $activeSlave.lips = 15>>
	<<set $activeSlave.behavioralFlaw = "odd">>
	<<set $activeSlave.skill.vaginal = 0>>
	<<set $activeSlave.skill.oral = 0>>
	<<set $activeSlave.skill.anal = 0>>
	<<set $activeSlave.skill.whoring = 0>>
	<<set $activeSlave.skill.entertainment = 0>>
	<<set $activeSlave.birthWeek = random(0,50)>>
	<<set $activeSlave.voice = 2>>
	<<set $activeSlave.weight = -20>>
	<<set $activeSlave.muscles = 0>>
	<<set $activeSlave.shoulders = -1>>
	<<set $activeSlave.hips = 0>>
	<<set $activeSlave.clit = 0>>
	<<set $activeSlave.labia = 0>>
	<<set $activeSlave.waist = 10>>
	<<set $activeSlave.preg = 0>>
	<<set $activeSlave.prestige = 3>>
	<<set $activeSlave.prestigeDesc = "She was the famous Smiling Man.">>
	<<set $activeSlave.clothes = "a military uniform">> /*closest thing to commie/punk we have at the moment*/
	<<setLocalPronouns $activeSlave>>

	The day has come to finally put an end to this story. Your men are ready to go, waiting only on your signal. You quickly don your protective gear and proceed down the busy streets of your arcology.
	You carefully planned the day so that nothing could exit the arcology without being scanned at least three times and poked twice. The Smiling Man has no escape.

After a short walk you are in front of the criminal's lair, a rundown old apartment in a scarcely populated part of the arcology. You give the order to breach and your men rush inside without problems.
	After a couple of seconds pass without a single noise coming from the apartment, you begin to worry. Then you hear the captain

<<link "calling you inside.">>
	<<replace "#continue">>

		/* 000-250-006 */
		<<if $seeImages == 1>>
			<<if $imageChoice == 1>>

<<SlaveArt $activeSlave 2 0>>

			<<else>>

<<SlaveArt $activeSlave 2 0>>

			<</if>>
		<</if>>
		/* 000-250-006 */

		calling you inside.

"So it was you to find me first.
		<<if $relationshipLM > 2>>
			I was hoping you would be the one!
		<<else>>
			I expected you would be the one.
		<</if>>
		Well, I hope I'm everything you expected," you hear a voice say. Despite recognizing it, you struggle to convince yourself that the little $girl in front of you is indeed the famous criminal mastermind.

"As you can see, I have no intention of escaping. I knew my life was over the second my plan went into effect. I accepted my end a long time ago, so feel free to do your worst; my life has already ended in triumph."

You evaluate the situation: the burning desire of vengeance for all the damage that little twerp caused is hard to ignore, but equally so is the admiration for $his skill and determination. Indeed, $he would be a great addition to your court, as a free individual or not.
	<</replace>>
<</link>>

	<<link "Offer $him a new life">>
		<<set $smilingManFate = 0>>
		<<replace "#result">>
			You decide it would be criminally wasteful to throw away such talent. You offer $him a new life at your side. $His expertise will surely guarantee safety, if not supremacy, to your arcology in cyberspace, while $he will have safety and luxury in the physical world.

			<<link "Continue">>
				<<set $smilingManProgress += 1>>
				<<goto "secExpSmilingMan">>
			<</link>>
		<</replace>>
	<</link>>

	<<link "Make $him pay">>
		<<set $smilingManFate = 1>>
		<<replace "#result">>
			You decide to end $his pitiful life. $He has crossed the wrong master of the new world $he worked so hard to create. No mercy was asked for and no mercy will be given.

			<<link "Continue">>
				<<set $smilingManProgress += 1>>
				<<goto "secExpSmilingMan">>
			<</link>>
		<</replace>>
	<</link>>

	<<link "Enslave $him">>
		<<set $smilingManFate = 2>>
		<<replace "#result">>
			You decide to enslave the $girl. $His skill may be great, $his crimes equally so, which makes it all the sweeter to turn $him into an obedient little toy to play with.

			<<link "Continue">>
				<<set $smilingManProgress += 1>>
				<<goto "secExpSmilingMan">>
			<</link>>
		<</replace>>
	<</link>>

<<else>>
	<<set $nextButton = "Continue", $nextLink = "Random Nonindividual Event">>

	<<if $smilingManFate == 0>>
		/* 000-250-006 */
		<<if $seeImages == 1>>
			<<if $imageChoice == 1>>

<<SlaveArt $activeSlave 2 0>>

			<<else>>

<<SlaveArt $activeSlave 2 0>>

			<</if>>
		<</if>>
		/* 000-250-006 */
		<<if $relationshipLM >= 4>>
			The $girl asks for a few minutes to think about your offer, but $he quickly comes to terms with the situation and accepts. In the following weeks $he will get acquainted with the security network of the arcology and work to protect $his new home in the new world $he has created.
			The world will never find out the truth of the Smiling Man and his legend will only grow with time, outliving his creator and maybe even $his new employer.
		<<else>>
			The $girl asks for a few minutes to think about your offer, and after some time $he reluctantly accepts. In the following weeks $he will get acquainted with the security network of the arcology and work to protect $his new home in the new world $he has created.
			The world will never find out the truth of the Smiling Man and his legend will only grow with time, outliving his creator and maybe even $his new employer.
		<</if>>

The collaboration of the ex-Smiling Man permanently increases @@.green;security and the rate of prosperity growth.@@ @@.limegreen;Cash will be also provided,@@ but you're better off not knowing the sources.
	<<elseif $smilingManFate == 1>>
		<<set $activeSlave.clothes = "no clothing">>
		/* 000-250-006 */
		<<if $seeImages == 1>>
			<<if $imageChoice == 1>>

<<SlaveArt $activeSlave 2 0>>

			<<else>>

<<SlaveArt $activeSlave 2 0>>

			<</if>>
		<</if>>
		/* 000-250-006 */
		For such a criminal a simple execution is not enough. You order the $girl captured and crucified outside the city, with a mask resembling $his famous symbol. Your men quickly obey. $He never once shows sign of pain or fear, remaining stoic and proud to the end.
		Once $his life ends, you order a statue erected in commemoration of the death of the Smiling Man. From this day forward the statue of the crucified criminal will adorn your arcology and his legend will be forever entangled with yours.

Having dealt with the Smiling Man will provide @@.green;a large boost to your reputation, as well as a moderate amount of reputation each week.@@
	<<elseif $smilingManFate == 2>>
		<<set $activeSlave.clothes = "no clothing">>
		<<if $relationshipLM >= 4>>
			Your men move to immobilize $him. Terror flashes through $his eyes for a second, but $he quickly recovers $his usual demeanor.
		<<else>>
			Your men move to immobilize $him. Terror flashes through $his eyes for a second — $he barely manages to recover $his usual demeanor.
		<</if>>

		<<set $saleDescription = 0, $applyLaw = 0>>
		<<include "Long Slave Description">>

		<<include "New Slave Intro">>
	<</if>>
<</if>>


code:
:: secInit [nobr]

/* base vars */
<<set $authority = 0>>
<<set $security = 30>>
<<set $secRestPoint = 30>>
<<set $crime = 30>>
<<set $crimeCap = 100>>
<<set $readiness = 1>>
<<set $recon = 0>>
<<set $maxUnits = 6>>
<<set $trade = 0>>
<<set $activeUnits = 0>>
<<set $attackType = "none">>
<<set $attackThisWeek = 0>>
<<set $lastAttackWeeks = 0>>
<<set $lastRebellionWeeks = 0>>
<<set $hasFoughtOnce = 0>>
<<set $hasFoughtMajorBattleOnce = 0>>
<<set $hasRebelledOnce = 0>>
<<set $majorBattle = 0>>
<<set $PCvictoryStreak = 0>>
<<set $PCvictories = 0>>
<<set $PClossStreak = 0>>
<<set $PClosses = 0>>
<<set $oldFlux = 0>>
<<set $showBattleStatistics = 0>>
<<set $forceBattle = 0>>
<<set $forceMajorBattle = 0>>
<<set $foughtThisWeek = 0>>
<<set $battlesEnabled = 1>>
<<set $battlesEnabledOceanic = 0>>
<<set $majorBattlesEnabled = 1>>
<<set $majorBattleGameOver = 1>>
<<set $rebellionsEnabled = 1>>
<<set $forceRebellion = 0>>
<<set $rebellionGameOver = 1>>
<<set $allowPrestigeFromBattles = 1>>
<<set $battleFrequency = 1>>
<<set $rebellionSpeed = 1>>
<<set $majorBattleMult = 1>>

/* edicts */
<<set $edictsUpkeep = 0>>
<<set $edictsAuthUpkeep = 0>>
<<set $alternativeRents = 0>>
<<set $enslavementRights = 0>>
<<set $securityExemption = 0>>
<<set $sellData = 0>>
<<set $propCampaignBoost = 0>>
<<set $slaveWatch = 0>>
<<set $subsidyChurch = 0>>
<<set $limitImmigration = 0>>
<<set $openBorders = 0>>
<<set $limitSubhumans = 0>>
<<set $slavesOfficers = 0>>
<<set $martialSchool = 0>>
<<set $discountMercenaries = 0>>
<<set $militiaFounded = 0>>
<<set $recruitVolunteers = 0>>
<<set $conscription = 0>>
<<set $militaryService = 0>>
<<set $militarizedSociety = 0>>
<<set $militaryExemption = 0>>
<<set $lowerRquirements = 0>>
<<set $noSubhumansInArmy = 0>>
<<set $pregExemption = 0>>
<<set $eliteOfficers = 0>>
<<set $liveTargets = 0>>
<<set $legionTradition = 0>>
<<set $eagleWarriors = 0>>
<<set $ronin = 0>>
<<set $sunTzu = 0>>
<<set $mamluks = 0>>
<<set $pharaonTradition = 0>>
<<set $weaponsLaw = 3>>
<<set $soldierWages = 1>>
<<set $militiaSoldierPrivilege = 0>>
<<set $slaveSoldierPrivilege = 0>>
<<set $mercSoldierPrivilege = 0>>
<<set $tradeLegalAid = 0>>
<<set $taxTrade = 0>>

/* proclamations */
<<set $proclamationsCooldown = 0>>
<<set $proclamationCurrency = "authority">>
<<set $proclamationType = "none">>

/* buildings */
<<set $upgradeUpkeep = 40>>
<<set $secHQ = 0>>
<<set $secHQUpkeep = $facilityCost * 5>>
<<set $secBarracks = 0>>
<<set $secBarracksUpkeep = $facilityCost * 5>>
<<set $secBarracksUpgrades ={
	size: 0,
	luxury: 0,
	training: 0,
	loyaltyMod: 0}>>
<<set $secMenials = 0>>
<<set $reqMenials = 20>>
<<set $secUpgrades = {
	nanoCams: 0,
	cyberBots: 0,
	eyeScan: 0,
	cryptoAnalyzer: 0,
	coldstorage: 0}>>
<<set $crimeUpgrades = {
	autoTrial: 0,
	autoArchive: 0,
	worldProfiler: 0,
	advForensic: 0}>>
<<set $intelUpgrades = {
	sensors: 0,
	radar: 0,
	signalIntercept: 0}>>
<<set $readinessUpgrades = {
	earlyWarn: 0,
	rapidPlatforms: 0,
	pathways: 0,
	rapidVehicles: 0}>>
<<set $propHub = 0>>
<<set $propHubUpkeep = $facilityCost * 5>>
<<set $propCampaign = 0>>
<<set $propFocus = "none">>
<<set $miniTruth = 0>>
<<set $fakeNews = 0>>
<<set $controlLeaks = 0>>
<<set $secretService = 0>>
<<set $blackOps = 0>>
<<set $marketInfiltration = 0>>
<<set $riotCenter = 0>>
<<set $riotUpkeep = $facilityCost * 5>>
<<set $riotUpgrades = {
	freeMedia: 0,
	rapidUnit: 0,
	rapidUnitSpeed: 0}>>
<<set $fort = {
	reactor: 0,
	waterway: 0,
	assistant:0}>>
<<set $sentUnitCooldown = 0>>
<<set $advancedRiotEquip = 0>>
<<set $brainImplant = -1>>
<<set $brainImplantProject = 0>>
<<set $weapManu = 0>>
<<set $weapMenials = 0>>
<<set $weapProductivity = 1>>
<<set $weapLab = 1>>
<<set $baseUpgradeTime = 10>>
<<set $currentUpgrade = {
	name: " ",
	unit: 0,
	type: 0,
	time: 0}>>
<<set $droneUpgrades = {
	attack: 0,
	defense: 0,
	hp:0}>>
<<set $humanUpgrade = {
	attack: 0,
	defense: 0,
	hp:0,
	morale: 0}>>
<<set $sellTo = {
	citizen: 1,
	raiders: 1,
	oldWorld: 1,
	FC: 1}>>
<<set $completedUpgrades = []>>
<<set $transportHub = 0>>
<<set $airport = 0>>
<<set $railway = 0>>
<<set $docks = 0>>
<<set $hubSecurity = 1>>

/* events */
<<set $smilingManProgress = 0>>
<<set $investedFunds = 0>>
<<set $relationshipLM = 0>>
<<set $captureRoute = 0>>
<<set $collaborationRoute = 0>>
<<set $smilingManWeek = 0>>
<<set $globalCrisisWeeks = 0>>
<<set $smilingManFate = 4>>

/* rebellions */
<<set $tension = 0>>
<<set $slaveProgress = 0>>
<<set $citizenProgress = 0>>
<<set $slaveRebellionEventFires = 0>>
<<set $citizenRebellionEventFires = 0>>
<<set $slaveRebellion = 0>>
<<set $citizenRebellion = 0>>
<<set $rebellingUnits = []>>
<<set $notInvolved = 0>>
<<set $irregulars = 0>>
<<set $engageRule = 0>>
<<set $rebellingMilitia = 0>>
<<set $rebellingSlaves = 0>>
<<set $rebellingMercs = 0>>
<<set $repairTime = 3>>
<<set $arcRepairTime = 0>>
<<set $rebelDefeatAftermath = 0>>
<<set $garrison = {
	penthouse: 0,
	reactor: 0,
	assistant: 0,
	waterway: 0,
	reactorTime: 0,
	assistantTime: 0,
	waterwayTime: 0 }>>
<<set $rebellionsCount = 0>>
<<set $PCrebWon = 0>>
<<set $PCrebLoss = 0>>

/* armed forces stats */
<<set $difficulty = 1>>
<<set $targetUnit = 0>>
<<set $targetIndex = 0>>
<<set $secBotsCost = 500>>
<<set $secBotsUpgradeCost = 250>>
<<set $equipUpgradeCost = 250>>
<<set $maxTroops = 30>>
<<set $militiaTotalManpower = 0>>
<<set $militiaFreeManpower = 0>>
<<set $militiaEmployedManpower = 0>>
<<set $militiaTotalCasualties = 0>>
<<set $slavesOfficers = 0>>
<<set $slavesEmployedManpower = 0>>
<<set $slavesTotalCasualties = 0>>
<<set $mercTotalManpower = 0>>
<<set $mercEmployedManpower = 0>>
<<set $mercTotalCasualties = 0>>
<<set $mercLoyalty = 0>>
<<set $soldierUpkeep = 10>>
<<set $createdSlavesUnits = 0>>
<<set $createdMilitiaUnits = 0>>
<<set $createdMercUnits = 0>>
<<set $mercFreeManpower = 0>>
<<if $wasToggledBefore == 0>>
	<<if $mercenaries == 1>>
		<<set $mercFreeManpower = random(5,20)>>
	<<elseif $mercenaries > 1>>
		<<set $mercFreeManpower = random(10,30)>>
	<</if>>
<</if>>

/* battle relevant variables */
<<set $troopCount = 0>>
<<set $slaveVictories = []>>
<<set $slaveIncreasedPrestige = 0>>
<<set $totalKills = 0>>
<<set $battlesCount = 0>>
<<set $majorBattlesCount = 0>>
<<set $chosenTactic = "none">>
<<set $leadingTroops = "none">>
<<set $attackTroops = 0>>
<<set $attackEquip = 0>>
<<set $deployableUnits = 0>>
<<set $deployedUnits = 0>>
<<set $deployingBots = 0>>
<<set $deployingMilitia = 0>>
<<set $deployingSlaves = 0>>
<<set $deployingMercs = 0>>
<<set $battleTerrain = "none">>
<<set $maxTurns = 10>>
<<set $battleResult = 4>> /* sets $battleResult value outside accepted range (-3,3) to avoid evaluation problems */
<<set $losses = 0>>
<<set $enemyLosses = 0>>
<<set $battleTurns = 0>>
<<set $bribeCost = 0>>
<<set $tacticsSuccessful = 0>>
<<set $leaderWounded = 0>>
<<set $woundType = 0>> /* 0=no wound, 1=mute, 2=blind, 3=amputee, 4<=health */
<<set $gainedCombat = 0>>
<<set $gainedWarfare = 0>>
<<set $PCWounded = 0>>
<<set $PCWoundCooldown = 0>>
<<set $expectedEquip = 0>>
<<set $estimatedMen = 0>>
<<set $SFIntervention = 0>>
<<set $carriableSoldiers = 0>>
<<set $SFatk = 0>>
<<set $SFdef = 0>>
<<set $SFhp = 0>>
<<set $rebellingID = []>>
<<set $saveValid = 0>>
<<set $lastSelection = []>>

/* statistics */
<<set $baseBribePerAttacker = 5>>
<<set $equipMod = 0.15>>
<<set $secBotsBaseAttack = 7>>
<<set $secBotsBaseDefense = 3>>
<<set $secBotsMorale = 200>>
<<set $secBotsBaseHp = 3>>
<<set $militiaBaseAttack = 7>>
<<set $militiaBaseDefense = 5>>
<<set $militiaBaseMorale = 140>>
<<set $militiaBaseHp = 3>>
<<set $slaveBaseAttack = 8>>
<<set $slaveBaseDefense = 3>>
<<set $slaveBaseMorale = 110>>
<<set $slaveBaseHp = 3>>
<<set $mercBaseAttack = 8>>
<<set $mercBaseDefense = 4>>
<<set $mercBaseMorale = 125>>
<<set $mercBaseHp = 4>>
<<set $SFBaseAttack = 8>>
<<set $SFBaseDefense = 4>>
<<set $SFBaseMorale = 140>>
<<set $SFBaseHp = 4>>

<<set $raBaseAttack = 7>>
<<set $raBaseDefense = 2>>
<<set $raBaseMorale = 100>>
<<set $raBaseHp = 2>>
<<set $fcBaseAttack = 6>>
<<set $fcBaseDefense = 4>>
<<set $fcBaseMorale = 130>>
<<set $fcBaseHp = 3>>
<<set $owBaseAttack = 8>>
<<set $owBaseDefense = 4>>
<<set $owBaseMorale = 110>>
<<set $owBaseHp = 2>>
<<set $ffBaseAttack = 9>>
<<set $ffBaseDefense = 2>>
<<set $ffBaseMorale = 160>>
<<set $ffBaseHp = 2>>

<<set $secBots = {
	active: 0,
	ID: -1,
	isDeployed: 0,
	troops: 0,
	maxTroops: 0,
	equip: 0} >>
<<set $militiaUnits = []>>
<<set $slaveUnits = []>>
<<set $mercUnits = []>>

/* SFanon additions */
<<set $SFSupportLevel = 0>>
<<set $SFSupportUpkeep = 0>>
<<set $SFGear = 0>>
<<set $SavedLeader = "none">>
<<set $SavedSFI = 0>>

/* helper widgets */
<<calcInitialTrade>>


code:
:: securityHQ [nobr]

<<if $career == "mercenary" || $career == "gang" || $career == "slaver">>
	<<set _HistoryDiscount = .5>>
<<else>>
	<<set _HistoryDiscount = 1>>
<</if>>

<<set $nextButton = "Back", $nextLink = "Manage Arcology", $returnTo = "Manage Arcology">>

Security Headquarters

The security headquarters stand in front of you. Innumerable screens flood with light the great central room. <<if $secMenials > 0>>Some slaves see you enter and interrupt their work to greet you.<</if>> From here you can build a safe and prosperous arcology.

/* security level. Slaves */
You have  <<print num($secMenials)>>  slaves working in the HQ. $reqMenials are required and you have  <<print num($menials)>>  free menial slaves.
<<if $secMenials < $reqMenials>>
	You do not have enough slaves here. You will not receive the full benefit of the installed upgrades.
<<else>>
	You have enough slaves to man all security systems.
<</if>>
<<run MenialPopCap()>>
<<set _menialPrice = menialSlaveCost()>>
<<set _bulkMax = $PopCap-$menials-$fuckdolls-$menialBioreactors>>
<<if $cash > _menialPrice>>
	<<if _bulkMax > 0 || $menials+$fuckdolls+$menialBioreactors == 0>>

		[[Buy|securityHQ][$menials += 1,$menialSupplyFactor -= 1, cashX(-_menialPrice, "menialTransfer")]]
		<<if $cash > (menialSlaveCost(10))*10>>
			[[(x10)|securityHQ][$menials += 10,$menialSupplyFactor -= 10, cashX(-(menialSlaveCost(10)*10), "menialTransfer")]]
		<</if>>
		<<if $cash > (menialSlaveCost(100))*100>>
			[[(x100)|securityHQ][$menials += 100,$menialSupplyFactor -= 100, cashX(-(menialSlaveCost(100)*100), "menialTransfer")]]
		<</if>>
		<<if $cash > (_menialPrice+1)*2>>
			<<set _menialBulkPremium = Math.trunc(1 + Math.clamp($cash/_menialPrice,0,_bulkMax)/400)>>
			<<set _maxMenials = Math.clamp($cash/(_menialPrice+_menialBulkPremium),0,_bulkMax)>>
			<<set _finalMaxCost = Math.trunc(_maxMenials*(_menialPrice+_menialBulkPremium))>>
			[[(max)|securityHQ][$menials += Math.trunc(_maxMenials), $menialSupplyFactor -= Math.trunc(_maxMenials), cashX(-_finalMaxCost, "menialTransfer")]]
		<</if>>
		//Bulk transactions may require offering a premium.//
	<</if>>
<</if>>
<<if $menials > 0>>

Transfer in:
	<<if $menials >= 5>>
		<<link "5">>
			<<set $menials -= 5>>
			<<set $secMenials += 5>>
			<<replace "#secHel">><<print $secMenials>><</replace>>
			<<replace "#hel">><<print $menials>><</replace>>
			<<if $menials < 5 || $secMenials >= $reqMenials || $secMenials == 5>>
				<<goto "securityHQ">>
			<</if>>
		<</link>>
	<</if>>
	<<if $menials >= 10>>
		|<<link "10">>
			<<set $menials -= 10>>
			<<set $secMenials += 10>>
			<<replace "#secHel">><<print $secMenials>><</replace>>
			<<replace "#hel">><<print $menials>><</replace>>
			<<if $menials < 10 || $secMenials >= $reqMenials || $secMenials == 10>>
				<<goto "securityHQ">>
			<</if>>
		<</link>>
	<</if>>
	<<if $menials >= 100>>
		|<<link "100">>
			<<set $menials -= 100>>
			<<set $secMenials += 100>>
			<<replace "#secHel">><<print $secMenials>><</replace>>
			<<replace "#hel">><<print $menials>><</replace>>
			<<if $menials < 100 || $secMenials >= $reqMenials || $secMenials == 100>>
				<<goto "securityHQ">>
			<</if>>
		<</link>>
	<</if>>
	<<if $menials >= 500>>
		|<<link "500">>
			<<set $menials -= 500>>
			<<set $secMenials += 500>>
			<<replace "#secHel">><<print $secMenials>><</replace>>
			<<replace "#hel">><<print $menials>><</replace>>
			<<if $menials < 500 || $secMenials >= $reqMenials || $secMenials == 500>>
				<<goto "securityHQ">>
			<</if>>
		<</link>>
	<</if>>
	<<if $menials >= 1000>>
		|<<link "1000">>
			<<set $menials -= 1000>>
			<<set $secMenials += 1000>>
			<<replace "#secHel">><<print $secMenials>><</replace>>
			<<replace "#hel">><<print $menials>><</replace>>
			<<if $menials < 1000 || $secMenials >= $reqMenials || $secMenials == 1000>>
				<<goto "securityHQ">>
			<</if>>
		<</link>>
	<</if>>

	<<if $secMenials > 0>>

Transfer out
		<<if $secMenials >= 5>>
			<<link "5">>
				<<set $menials += 5>>
				<<set $secMenials -= 5>>
				<<replace "#secHel">><<print $secMenials>><</replace>>
				<<replace "#hel">><<print $menials>><</replace>>
				<<if $secMenials < 5>>
					<<goto "securityHQ">>
				<</if>>
				<<if $secMenials < $reqMenials>>
					<<goto "securityHQ">>
				<</if>>
			<</link>>
		<</if>>
		<<if $secMenials >= 10>>
			|<<link "10">>
				<<set $menials += 10>>
				<<set $secMenials -= 10>>
				<<replace "#secHel">><<print $secMenials>><</replace>>
				<<replace "#hel">><<print $menials>><</replace>>
				<<if $secMenials < 10>>
					<<goto "securityHQ">>
				<</if>>
				<<if $secMenials < $reqMenials>>
					<<goto "securityHQ">>
				<</if>>
			<</link>>
		<</if>>
		<<if $secMenials >= 100>>
			|<<link "100">>
				<<set $menials += 100>>
				<<set $secMenials -= 100>>
				<<replace "#secHel">><<print $secMenials>><</replace>>
				<<replace "#hel">><<print $menials>><</replace>>
				<<if $secMenials < 100>>
					<<goto "securityHQ">>
				<</if>>
				<<if $secMenials < $reqMenials>>
					<<goto "securityHQ">>
				<</if>>
			<</link>>
		<</if>>
		<<if $secMenials >= 500>>
			|<<link "500">>
				<<set $menials += 500>>
				<<set $secMenials -= 500>>
				<<replace "#secHel">><<print $secMenials>><</replace>>
				<<replace "#hel">><<print $menials>><</replace>>
				<<if $secMenials < 500>>
					<<goto "securityHQ">>
				<</if>>
				<<if $secMenials < $reqMenials>>
					<<goto "securityHQ">>
				<</if>>
			<</link>>
		<</if>>
		<<if $secMenials >= 1000>>
			|<<link "1000">>
				<<set $menials += 1000>>
				<<set $secMenials -= 1000>>
				<<replace "#secHel">><<print $secMenials>><</replace>>
				<<replace "#hel">><<print $menials>><</replace>>
				<<if $secMenials < 1000>>
					<<goto "securityHQ">>
				<</if>>
				<<if $secMenials < $reqMenials>>
					<<goto "securityHQ">>
				<</if>>
			<</link>>
		<</if>>
	<</if>>
<</if>>

<<if $secMenials != $reqMenials>>

<<link "Match the requirement">>
		<<if $menials >= $reqMenials - $secMenials>>
			<<set $menials -= $reqMenials - $secMenials>>
			<<set $secMenials = $reqMenials>>
		<<elseif $reqMenials < $secMenials>>
			<<set $menials += $secMenials - $reqMenials>>
			<<set $secMenials = $reqMenials>>
		<<else>>
			<<set $secMenials += $menials>>
			<<set $menials = 0>>
		<</if>>
		<<replace "#secHel">><<print $secMenials>><</replace>>
		<<replace "#hel">><<print $menials>><</replace>>
		<<if $secMenials == $reqMenials>>
			<<goto "securityHQ">>
		<</if>>
	<</link>>
<</if>>

/* security level and upgrades */
Your security level (@@.deepskyblue;$security@@)
<<if $security <= 20>>
	is dangerously low.
<<elseif $security <= 40>>
	is low.
<<elseif $security <= 60>>
	is decent.
<<elseif $security <= 80>>
	is good.
<<else>>
	is great.
<</if>>
Considering the current upgrades the resting level for security is <<print $secRestPoint>>, while the effective maximum level is <<print Math.trunc($secRestPoint * (Math.clamp($secMenials,0,$reqMenials) / $reqMenials))>>.

<<if $secUpgrades.nanoCams == 0>>
	[[Install a nano-camera system |securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.nanoCams = 1, $secRestPoint += 15, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep.//
<<else>>
	You have installed all across the arcology closed circuit nano-cameras to keep the arcology under your watchful eye.
<</if>>

<<if $secUpgrades.cyberBots == 0>>
	[[Buy cybersecurity algorithms|securityHQ][cashX(-Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.cyberBots = 1, $secRestPoint += 15, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep.//
<<else>>
	You have bought advanced cybersecurity algorithms that will defend your arcology against hack attempts or cyber frauds.
<</if>>

<<if $authority > 10000>>
	<<if $secUpgrades.eyeScan == 0>>
		[[Install invisible eye scanners|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.eyeScan = 1, $secRestPoint += 20, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep.//
	<<else>>
		You have installed numerous hidden eye scanners that accurately register the movements of everyone inside the arcology.
	<</if>>

	<<if $secUpgrades.cryptoAnalyzer == 0>>
		[[Buy and install crypto analyzers|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.cryptoAnalyzer = 1, $secRestPoint += 20, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep.//
	<<else>>
		You have bought and employed sophisticated crypto analyzing software to accurately track and archive every financial movement or transaction made inside the walls of your arcology.
	<</if>>
<<else>>

You lack the authority to access more advanced upgrades.
<</if>>

/* crime level and upgrades */
Your crime level (@@.orangered;$crime@@)
<<if $crime <= 20>>
	is very low.
<<elseif $crime <= $upgradeUpkeep>>
	is low.
<<elseif $crime <= 60>>
	is average.
<<elseif $crime <= $upgradeUpkeep>>
	is high.
<<else>>
	is extremely high.
<</if>>
Considering the current upgrades the maximum level of crime is <<print $crimeCap>>, while the effective maximum level is <<print Math.trunc(Math.clamp($crimeCap + ($crimeCap - $crimeCap * ($secMenials / $reqMenials)),0,100))>>.

<<if $crimeUpgrades.advForensic == 0>>
	[[Install advanced forensic equipment|securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.advForensic = 1, $crimeCap -= 10, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep.//
<<else>>
	You have installed advanced forensic equipment, able to extract every bit of precious information from any clue.
<</if>>

<<if $crimeUpgrades.autoArchive == 0>>
	[[Install auto-curating archiver|securityHQ][cashX(-Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.autoArchive = 1, $crimeCap -= 10, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep.//
<<else>>
	You have installed auto-curating archiver software, which will update in real time your data archives with any new relevant information on criminals residing in your arcology.
<</if>>

<<if $authority > 10000>>
	<<if $crimeUpgrades.autoTrial == 0>>
		[[Install automated trials software|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.autoTrial = 1, $crimeCap -= 15, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep.//
	<<else>>
		You have installed advanced legal algorithms that allows the handling of legal matters much quicker and much more accurately.
	<</if>>

	<<if $crimeUpgrades.worldProfiler == 0>>
		[[Install worldwide profilers|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.worldProfiler = 1, $crimeCap -= 15, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep.//
	<<else>>
		You have installed advanced profiler software, which will constantly scour every known data archive on the globe (legally or not) to gather as much information as possible on dangerous criminals.
	<</if>>
<<else>>

You lack the authority to access more advanced upgrades.
<</if>>

/* intelligence */

<<if $recon == 0>>
	Your reconnaissance capabilities are very limited. Very little information will be available if the arcology is attacked.
<<elseif $recon == 1>>
	You have limited reconnaissance capabilities. You'll have limited intel available in case of an attack.
<<elseif $recon == 2>>
	You have good reconnaissance capabilities. Good, reliable intel will be available if the arcology is attacked.
<<else>>
	You have great reconnaissance capabilities. You'll have very accurate information on the enemy if the arcology is attacked.
<</if>>

<<if $intelUpgrades.sensors == 0>>
	[[Install perimeter sensors|securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $intelUpgrades.sensors = 1, $recon += 1, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 5 extra slaves in the headquarters and increases upkeep.//
<<else>>
	You have installed perimeter seismic sensors able to detect movement with high accuracy.
<</if>>

<<if $intelUpgrades.signalIntercept == 0>>
	[[Create signal interception hub|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $intelUpgrades.signalIntercept = 1, $recon += 1, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 5 extra slaves in the headquarters and increases upkeep.//
<<else>>
	You have installed advanced signal interception equipment.
<</if>>

<<if $authority > 10000>>
	<<if $intelUpgrades.radar == 0>>
		[[Install advanced radar equipment|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $intelUpgrades.radar = 1, $recon += 1, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 10 extra slaves in the headquarters and increases upkeep.//
	<<else>>
		You have installed sophisticated radar equipment.
	<</if>>
<<else>>

You lack the authority to access more advanced upgrades.
<</if>>

/* readiness */

<<if $readiness == 1>>
	You have low readiness. You won't be able to mobilize many troops in time in case of an attack.
<<elseif $readiness == 2>>
	You have decent readiness. You will be able to muster up sufficient forces to handle an average attack.
<<elseif $readiness == 3>>
	You have good readiness. You will be able to mobilize a lot of troops in case of an attack.
<<else>>
	You have great readiness. You can mobilize a small army in very little time.
<</if>>

<<if $readinessUpgrades.pathways == 0>>
	[[Build specialized pathways in the arcology|securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount), "capEx"), $readinessUpgrades.pathways = 1, $readiness += 1, $secHQUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 1, but will increase upkeep.//
<<else>>
	You have built specialized pathways inside the arcology to quickly move troops around the structure.
<</if>>

<<if $readinessUpgrades.rapidVehicles == 0>>
	[[Buy rapid armored transport vehicles|securityHQ][cashX(-Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount), "capEx"), $readinessUpgrades.rapidVehicles = 1, $readiness += 2, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 5 extra slaves in the headquarters and increases upkeep.//
<<else>>
	You have bought rapid armored transport vehicles able to bring your troops to battle much quicker than before.
<</if>>

<<if $authority > 10000>>
	<<if $readinessUpgrades.rapidPlatforms == 0>>
		[[Build rapid deployment platforms|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount), "capEx"), $readinessUpgrades.rapidPlatforms = 1, $readiness += 2, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 5 extra slaves in the headquarters and increases upkeep.//
	<<else>>
		You have built rapid deployment platforms able to equip and deploy units within very limited time windows.
	<</if>>

	<<if $readinessUpgrades.earlyWarn == 0>>
		[[Institute early warning systems|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount), "capEx"), $readinessUpgrades.earlyWarn = 1, $readiness += 2, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 10 extra slaves in the headquarters and increases upkeep.//
	<<else>>
		You have created early warning systems that constantly analyze in real time data to determine the likeness of an attack.
	<</if>>
<<else>>

You lack the authority to access more advanced upgrades.
<</if>>

<<if $authority > 12000>>

__Cold Data Storage Facility__:
	<<if $secUpgrades.coldstorage == 6 && $authority >= 19500 && $reqMenials > 10>>

You have installed a cold storage facility for the Security HQ's archives with a data retention capability of two years.

		[[Expand the cold storage facility to increase data retention to three years|securityHQ][cashX(-Math.trunc(2400000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(2400000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
	<<elseif $secUpgrades.coldstorage == 5 && $authority >= 19500 && $reqMenials > 10>>

You have installed a cold storage facility for the Security HQ's archives with a data retention capability of one year.

		[[Expand the cold storage facility to increase data retention to two years|securityHQ][cashX(-Math.trunc(1200000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(1200000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
	<<elseif $secUpgrades.coldstorage == 4 && $authority >= 19500 && $reqMenials > 10>>

You have installed a cold storage facility for the Security HQ's archives with a data retention capability of nine months.

		[[Expand the cold storage facility to increase data retention to one year|securityHQ][cashX(-Math.trunc(900000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(900000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
	<<elseif $secUpgrades.coldstorage == 3 && $authority > 18000 && $reqMenials > 10>>

You have installed a cold storage facility for the Security HQ's archives with a data retention capability of six months.

		[[Expand the cold storage facility to increase data retention to nine months|securityHQ][cashX(-Math.trunc(600000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(600000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
	<<elseif $secUpgrades.coldstorage == 2 && $authority > 16000 && $reqMenials > 10>>

You have installed a cold storage facility for the Security HQ's archives with a data retention capability of three months.

		[[Expand the cold storage facility to increase data retention to six months|securityHQ][cashX(-Math.trunc(300000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(300000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
	<<elseif $secUpgrades.coldstorage == 1 && $authority > 14000 && $reqMenials > 10>>

You have installed a cold storage facility for the Security HQ's archives with a data retention capability of one month.

		[[Expand the cold storage facility to increase data retention to three months|securityHQ][cashX(-Math.trunc(100000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(100000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
	<<elseif $secUpgrades.coldstorage == 0 && $authority > 12000 && $reqMenials > 10>>
		[[Install a cold storage facility|securityHQ][cashX(-Math.trunc(50000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]

//Costs <<print cashFormat(Math.trunc(50000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by 10, but will increase upkeep.//
	<<elseif $secUpgrades.coldstorage > 6>>

You have installed a cold storage facility for the Security HQ's archives with a data retention capability of three years.
	<<elseif $reqMenials <= 10>>

Personnel cannot be further reduced.
	<<else>>

You lack the authority to access more advanced upgrades.
	<</if>>
<</if>>