code:
:: battleWidgets [widget nobr]

<<widget "calcSFStatistics">>
	<<if $slaveRebellion != 1 || $citizenRebellion != 1>>
		/* atk, def */
		<<set _upgradesSum = $SFUnit.Armoury + $SFUnit.Drugs + ($SFUnit.AA+$SFUnit.TA < 1) + ($SFUnit.AV+$SFUnit.TV)>>
		<<if !isInt(_upgradesSum)>>
			<<set _upgradesSum = random(10,15)>>
		<</if>>
		<<set $SFatk = Math.trunc(0.65 * _upgradesSum)>>
		<<set $SFdef = Math.trunc(0.40 * _upgradesSum)>>
		/* hp */
		<<set $carriableSoldiers = 125 * ($securityForceAC130 + $securityForceVehiclePower)>>
		<<if !isInt($carriableSoldiers)>>
			<<set $carriableSoldiers = $SFUnit.Troops / 10>>
		<</if>>
		<<if $SFUnit.Troops > $carriableSoldiers>>
			<<set $SFhp = $carriableSoldiers * $SFBaseHp>>
		<<else>>
			<<set $carriableSoldiers = $SFUnit.Troops>>
			<<set $SFhp = $carriableSoldiers * $SFBaseHp>>
		<</if>>
	<<else>>
		/* atk, def */
		<<set _upgradesSum = $SFUnit.Armoury + $SFUnit.Drugs + ($SFUnit.AA+$SFUnit.TA < 1) + ($SFUnit.AV+$SFUnit.TV)>>
		<<if !isInt(_upgradesSum)>>
			<<set _upgradesSum = random(10,15)>>
		<</if>>
		<<set $SFatk = Math.trunc(0.75 * _upgradesSum)>>
		<<set $SFdef = Math.trunc(0.50 * _upgradesSum)>>
		/* hp */
		<<set $SFhp = $SFUnit.Troops * $SFBaseHp>>
	<</if>>
<</widget>>

<<widget "removeUnits">>
	/* args[0] is the array of IDs of units to be eliminated */

	<<set _newMilitia = []>>
	<<set _newSlave = []>>
	<<set _newMerc = []>>

	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<if !($args[0].includes($militiaUnits[_i].ID))>>
			<<set _newMilitia.push($militiaUnits[_i])>>
		<</if>>
	<</for>>
	<<set $militiaUnits = _newMilitia>>

	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<if !($args[0].includes($slaveUnits[_i].ID))>>
			<<set _newSlave.push($slaveUnits[_i])>>
		<</if>>
	<</for>>
	<<set $slaveUnits = _newSlave>>

	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<if !($args[0].includes($mercUnits[_i].ID))>>
			<<set _newMerc.push($mercUnits[_i])>>
		<</if>>
	<</for>>
	<<set $mercUnits = _newMerc>>
<</widget>>

<<widget "calcTroopCount">>
	<<set _troops = 0>>
	<<if $attackThisWeek == 1>>
		<<if $deployingBots == 1>>
			<<set _troops += $secBots.troops>>
		<</if>>
		<<for _i = 0; _i < $militiaUnits.length; _i++>>
			<<if $militiaUnits[_i].isDeployed == 1>>
				<<set _troops += $militiaUnits[_i].troops>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $slaveUnits.length; _i++>>
			<<if $slaveUnits[_i].isDeployed == 1>>
				<<set _troops += $slaveUnits[_i].troops>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $mercUnits.length; _i++>>
			<<if $mercUnits[_i].isDeployed == 1>>
				<<set _troops += $mercUnits[_i].troops>>
			<</if>>
		<</for>>
		<<if $SF.Toggle && $SF.Active >= 1 && $SFIntervention>>
			<<set _troops += $carriableSoldiers>>
		<</if>>
		<<set $troopCount = _troops>>

	<<elseif $slaveRebellion == 1 || $citizenRebellion == 1>>

		<<if $irregulars > 0>>
			<<set _troops += $irregulars>>
		<</if>>
		<<if $secBots.active == 1>>
			<<set _troops += $secBots.troops>>
		<</if>>
		<<for _i = 0; _i < $militiaUnits.length; _i++>>
			<<if $militiaUnits[_i].active == 1 && $loyalID.includes($militiaUnits[_i].ID)>>
				<<set _troops += $militiaUnits[_i].troops>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $slaveUnits.length; _i++>>
			<<if $slaveUnits[_i].active == 1 && $loyalID.includes($slaveUnits[_i].ID)>>
				<<set _troops += $slaveUnits[_i].troops>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $mercUnits.length; _i++>>
			<<if $mercUnits[_i].active == 1 && $loyalID.includes($mercUnits[_i].ID)>>
				<<set _troops += $mercUnits[_i].troops>>
			<</if>>
		<</for>>
		<<if $securityForceCreate == 1>>
			<<set _troops += $carriableSoldiers>>
		<</if>>
		<<set $troopCount = _troops>>

	<<else>>
		<br>@@.red;Error: widget called outside battle@@
	<</if>>
<</widget>>

<<widget "calcBribe">>
	<<if $week <= 30>>
		<<set $bribeCost = 5000 + $baseBribePerAttacker * $attackTroops>>
	<<elseif $week <= 30>>
		<<set $bribeCost = 10000 + $baseBribePerAttacker * $attackTroops>>
	<<elseif $week <= 30>>
		<<set $bribeCost = 15000 + $baseBribePerAttacker * $attackTroops>>
	<<elseif $week <= 30>>
		<<set $bribeCost = 20000 + $baseBribePerAttacker * $attackTroops>>
	<<elseif $week <= 30>>
		<<set $bribeCost = 25000 + $baseBribePerAttacker * $attackTroops>>
	<</if>>
	<<if $majorBattle == 1>>
		<<set $bribeCost *= 3>>
	<</if>>
	<<set $bribeCost = Math.trunc(Math.clamp($bribeCost,0,1000000))>>
<</widget>>


code:
:: miscSecExpWidgets [widget nobr]

<<widget "calcInitialTrade">>
	<<set _initialTrade = random(20,30)>>
	<<if $terrain == "urban">>
		<<set _initialTrade += random(10)>>
	<</if>>
	<<if $terrain == "ravine">>
		<<set _initialTrade -= random(5)>>
	<</if>>
	<<if $PC.career == "wealth" || $PC.career == "capitalist" || $PC.career == "celebrity" || $PC.career == "BlackHat">>
		<<set _initialTrade += random(5)>>
	<<elseif $PC.career == "escort" || $PC.career == "servant" || $PC.career == "gang">>
		<<set _initialTrade -= random(5)>>
	<</if>>
	<<set $trade = _initialTrade>>
<</widget>>

<<widget "recalcManpower">>
	<<if $wasToggledBefore == 0>>
		<<if $mercenaries == 1>>
			<<set $mercFreeManpower = random(5,20)>>
		<<elseif $mercenaries > 1>>
			<<set $mercFreeManpower = random(10,30)>>
		<</if>>
	<</if>>

	<<set _correctEmployedMP = 0>>
	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<set _correctEmployedMP += $slaveUnits[_i].troops>>
	<</for>>

	<<if $slavesEmployedManpower != _correctEmployedMP>>
		<<set $slavesEmployedManpower = _correctEmployedMP>>
	<</if>>

	<<set _correctEmployedMP = 0>>
	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<set _correctEmployedMP += $militiaUnits[_i].troops>>
	<</for>>

	<<if $militiaEmployedManpower != _correctEmployedMP>>
		<<set $militiaEmployedManpower = _correctEmployedMP>>
	<</if>>

	<<set _correctEmployedMP = 0>>
	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<set _correctEmployedMP += $mercUnits[_i].troops>>
	<</for>>

	<<if $mercEmployedManpower != _correctEmployedMP>>
		<<set $mercEmployedManpower = _correctEmployedMP>>
	<</if>>

	<<set $militiaTotalManpower = $militiaEmployedManpower + $militiaFreeManpower>>
	<<set $mercTotalManpower = $mercEmployedManpower + $mercFreeManpower>>
<</widget>>

<<widget "recalcSecRestPoint">>
	<<set _newRest = 0>>
	<<set _baseRest = 30>>
	<<if $secUpgrades.nanoCams == 1>>
		<<set _newRest += 15>>
	<</if>>
	<<if $secUpgrades.cyberBots == 1>>
		<<set _newRest += 15>>
	<</if>>
	<<if $secUpgrades.eyeScan == 1>>
		<<set _newRest += 20>>
	<</if>>
	<<if $secUpgrades.cryptoAnalyzer == 1>>
		<<set _newRest += 20>>
	<</if>>
	<<set _newRest += _baseRest>>
	<<set $secRestPoint = _newRest>>
<</widget>>

<<widget "recalcCrimeCap">>
	<<set _baseCap = 100>>
	<<set _newCap = _baseCap>>
	<<if $crimeUpgrades.autoTrial == 1>>
		<<set _newCap -= 10>>
	<</if>>
	<<if $crimeUpgrades.autoArchive == 1>>
		<<set _newCap -= 10>>
	<</if>>
	<<if $crimeUpgrades.worldProfiler == 1>>
		<<set _newCap -= 15>>
	<</if>>
	<<if $crimeUpgrades.advForensic == 1>>
		<<set _newCap -= 15>>
	<</if>>
	<<set $crimeCap = _newCap>>
<</widget>>

<<widget "recalcReqHelots">>
	<<set _newReq = 0>>
	<<set _baseReq = 20>>
	<<if $secUpgrades.nanoCams == 1>>
		<<set _newReq += 5>>
	<</if>>
	<<if $secUpgrades.cyberBots == 1>>
		<<set _newReq += 5>>
	<</if>>
	<<if $secUpgrades.eyeScan == 1>>
		<<set _newReq += 10>>
	<</if>>
	<<if $secUpgrades.cryptoAnalyzer == 1>>
		<<set _newReq += 10>>
	<</if>>
	<<if $crimeUpgrades.autoTrial == 1>>
		<<set _newReq += 5>>
	<</if>>
	<<if $crimeUpgrades.autoArchive == 1>>
		<<set _newReq += 5>>
	<</if>>
	<<if $crimeUpgrades.worldProfiler == 1>>
		<<set _newReq += 10>>
	<</if>>
	<<if $crimeUpgrades.advForensic == 1>>
		<<set _newReq += 10>>
	<</if>>
	<<if $intelUpgrades.sensors == 1>>
		<<set _newReq += 5>>
	<</if>>
	<<if $intelUpgrades.signalIntercept == 1>>
		<<set _newReq += 5>>
	<</if>>
	<<if $intelUpgrades.radar == 1>>
		<<set _newReq += 10>>
	<</if>>
	<<if $readinessUpgrades.rapidVehicles == 1>>
		<<set _newReq += 5>>
	<</if>>
	<<if $readinessUpgrades.rapidPlatforms == 1>>
		<<set _newReq += 10>>
	<</if>>
	<<if $readinessUpgrades.earlyWarn == 1>>
		<<set _newReq += 10>>
	<</if>>
	<<if $SFSupportLevel >= 1>>
		<<set _newReq -= 5 * $SFSupportLevel>>
	<</if>>
	<<if $secUpgrades.coldstorage >= 1>>
		<<set _newReq -= 10 * $secUpgrades.coldstorage>>
	<</if>>
	<<set _newReq += _baseReq>>
	<<set $reqHelots = _newReq>>
<</widget>>

<<widget "recalcEdictsUpkeep">>
	/* authority cost */
	<<set _newAuthUpkeep = 0>>

	<<if $sellData == 1>>
		<<set _newAuthUpkeep += 10>>
	<</if>>

	<<if $slaveSoldierPrivilege == 1>>
		<<set _newAuthUpkeep += 10>>
	<</if>>

	<<if $weaponsLaw == 0>>
		<<set _newAuthUpkeep += 30>>
	<<elseif $weaponsLaw == 2>>
		<<set _newAuthUpkeep += 10>>
	<<elseif $weaponsLaw == 1>>
		<<set _newAuthUpkeep += 20>>
	<</if>>

	<<if $slavesOfficers == 1>>
		<<set _newAuthUpkeep += 10>>
	<</if>>

	/* cash cost */
	<<set _newUpkeep = 0>>

	<<if $slaveWatch == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $subsidyChurch == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $martialSchool == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $legionTradition == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $pharaonTradition == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $eagleWarriors == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $ronin == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $mamluks == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $sunTzu == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<if $tradeLegalAid == 1>>
		<<set _newUpkeep += 1000>>
	<</if>>

	<<set $edictsUpkeep = _newUpkeep>>
	<<set $edictsAuthUpkeep = _newAuthUpkeep>>
<</widget>>

<<widget "recalcUnits">>
	<<set $maxUnits = 6 + $secBarracksUpgrades.size * 2>>
	<<set $activeUnits = $militiaUnits.length + $slaveUnits.length + $mercUnits.length>>
<</widget>>

<<widget "fixBrokenUnits">>
	<<if ndef $secBots.ID>>
		<<set $secBots.ID = -1>>
	<</if>>
	<<if $secBots.maxTroops < 30>>

Fixed security bots wrong max troop count.
		<<set $secBots.maxTroops = 30>>
	<</if>>
	<<if !isInt($secBots.troops)>>

Fixed security bots wrong max troop count.
		<<set $secBots.troops = $secBots.maxTroops>>
	<</if>>
	<<if $secBots.troops > 0 && $secBots.active != 1>>

Fixed security bots wrong "active" flag.
		<<set $secBots.active = 1>>
	<</if>>

	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<if ndef $militiaUnits[_i].SF>>

Set militia missing flag
			<<set $militiaUnits[_i].SF = 0>>
		<</if>>
		<<if ndef $militiaUnits[_i].ID>>

Set militia missing ID
			<<generateUnitID $militiaUnits[_i]>>
		<</if>>
		<<if ndef $militiaUnits[_i].cyber>>

Set militia missing flag
			<<set $militiaUnits[_i].cyber = 0>>
		<</if>>
		<<if ndef $militiaUnits[_i].commissars>>

Set militia missing flag
			<<set $militiaUnits[_i].commissars = 0>>
		<</if>>
		<<if $militiaUnits[_i].maxTroops < 30>>

Fixed militia unit wrong max troop count.
			<<set $militiaUnits[_i].maxTroops = 30>>
		<</if>>
		<<if !isInt($militiaUnits[_i].troops)>>
			<<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>>

Fixed militia unit wrong troop count.
		<</if>>
		<<if $militiaUnits[_i].troops > 0 && $militiaUnits[_i].active != 1>>

Fixed militia unit wrong "active" flag.
			<<set $militiaUnits[_i].active = 1>>
		<</if>>
	<</for>>

	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<if ndef $slaveUnits[_i].SF>>

Set slave missing flag
			<<set $slaveUnits[_i].SF = 0>>
		<</if>>
		<<if ndef $slaveUnits[_i].ID>>

Set slave missing ID
			<<generateUnitID $slaveUnits[_i]>>
		<</if>>
		<<if ndef $slaveUnits[_i].cyber>>

Set slave missing flag
			<<set $slaveUnits[_i].cyber = 0>>
		<</if>>
		<<if ndef $slaveUnits[_i].commissars>>

Set slave missing flag
			<<set $slaveUnits[_i].commissars = 0>>
		<</if>>
		<<if $slaveUnits[_i].maxTroops < 30>>

Fixed slave unit wrong max troop count.
			<<set $slaveUnits[_i].maxTroops = 30>>
		<</if>>
		<<if !isInt($slaveUnits[_i].troops)>>
			<<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>>

Fixed slave unit wrong troop count.
		<</if>>
		<<if $slaveUnits[_i].troops > 0 && $slaveUnits[_i].active != 1>>

Fixed slave unit wrong "active" flag.
			<<set $slaveUnits[_i].active = 1>>
		<</if>>
	<</for>>

	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<if ndef $mercUnits[_i].SF>>

Set merc missing flag
			<<set $mercUnits[_i].SF = 0>>
		<</if>>
		<<if ndef $mercUnits[_i].ID>>

Set merc missing ID
			<<generateUnitID $mercUnits[_i]>>
		<</if>>
		<<if ndef $mercUnits[_i].cyber>>

Set merc missing flag
			<<set $mercUnits[_i].cyber = 0>>
		<</if>>
		<<if ndef $mercUnits[_i].commissars>>

Set merc missing flag
			<<set $mercUnits[_i].commissars = 0>>
		<</if>>
		<<if $mercUnits[_i].maxTroops < 30>>

Fixed merc unit wrong max troop count.
			<<set $mercUnits[_i].maxTroops = 30>>
		<</if>>
		<<if !isInt($mercUnits[_i].troops)>>
			<<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>>

Fixed merc unit wrong troop count.
		<</if>>
		<<if $mercUnits[_i].troops > 0 && $mercUnits[_i].active != 1>>

Fixed merc unit wrong "active" flag.
			<<set $mercUnits[_i].active = 1>>
		<</if>>
	<</for>>
<</widget>>

<<widget "fixBrokenStats">>
	<<if !isInt($totalKills)>>
		<<set $totalKills = 0>>
	<</if>>
	<<if !isInt($mercTotalCasualties)>>
		<<set $mercTotalCasualties = 0>>
	<</if>>
	<<if !isInt($mercEmployedManpower)>>
		<<set $mercEmployedManpower = 0>>
	<</if>>
	<<if !isInt($mercTotalManpower)>>
		<<set $mercTotalManpower = 0>>
	<</if>>
	<<if !isInt($slavesTotalCasualties)>>
		<<set $slavesTotalCasualties = 0>>
	<</if>>
	<<if !isInt($slavesEmployedManpower)>>
		<<set $slavesEmployedManpower = 0>>
	<</if>>
	<<if !isInt($militiaTotalCasualties)>>
		<<set $militiaTotalCasualties = 0>>
	<</if>>
	<<if !isInt($militiaEmployedManpower)>>
		<<set $militiaEmployedManpower = 0>>
	<</if>>
	<<if !isInt($militiaFreeManpower)>>
		<<set $militiaFreeManpower = 0>>
	<</if>>
	<<if !isInt($militiaTotalManpower)>>
		<<set $militiaTotalManpower = 0>>
	<</if>>
	<<if !isInt($battlesCount)>>
		<<set $battlesCount = 0>>
	<</if>>
<</widget>>

<<widget "fixBrokenFS">>
	<<if $arcologies[0].FSSubjugationist !== "unset" && !Number.isFinite($arcologies[0].FSSubjugationist)>>
		<<set $arcologies[0].FSSubjugationist = 10>>

Fixed NaN FS value for FSSubjugationist
	<</if>>
	<<if $arcologies[0].FSGenderRadicalist !== "unset" && !Number.isFinite($arcologies[0].FSGenderRadicalist)>>
		<<set $arcologies[0].FSGenderRadicalist = 10>>

Fixed NaN FS value for FSGenderRadicalist
	<</if>>
	<<if $arcologies[0].FSRestart !== "unset" && !Number.isFinite($arcologies[0].FSRestart)>>
		<<set $arcologies[0].FSRestart = 10>>

Fixed NaN FS value for FSRestart
	<</if>>
	<<if $arcologies[0].FSRepopulationFocus !== "unset" && !Number.isFinite($arcologies[0].FSRepopulationFocus)>>
		<<set $arcologies[0].FSRepopulationFocus = 10>>

Fixed NaN FS value for FSRepopulationFocus
	<</if>>
	<<if $arcologies[0].FSSupremacist !== "unset" && !Number.isFinite($arcologies[0].FSSupremacist)>>
		<<set $arcologies[0].FSSupremacist = 10>>

Fixed NaN FS value for FSSupremacist
	<</if>>
	<<if $arcologies[0].FSBodyPurist !== "unset" && !Number.isFinite($arcologies[0].FSBodyPurist)>>
		<<set $arcologies[0].FSBodyPurist = 10>>

Fixed NaN FS value for FSBodyPurist
	<</if>>
	<<if $arcologies[0].FSPaternalist !== "unset" && !Number.isFinite($arcologies[0].FSPaternalist)>>
		<<set $arcologies[0].FSPaternalist = 10>>

Fixed NaN FS value for FSPaternalist
	<</if>>
	<<if $arcologies[0].FSSlimnessEnthusiast !== "unset" && !Number.isFinite($arcologies[0].FSSlimnessEnthusiast)>>
		<<set $arcologies[0].FSSlimnessEnthusiast = 10>>

Fixed NaN FS value for FSSlimnessEnthusiast
	<</if>>
	<<if $arcologies[0].FSGenderFundamentalist !== "unset" && !Number.isFinite($arcologies[0].FSGenderFundamentalist)>>
		<<set $arcologies[0].FSGenderFundamentalist = 10>>

Fixed NaN FS value for FSGenderFundamentalist
	<</if>>
	<<if $arcologies[0].FSMaturityPreferentialist !== "unset" && !Number.isFinite($arcologies[0].FSMaturityPreferentialist)>>
		<<set $arcologies[0].FSMaturityPreferentialist = 10>>

Fixed NaN FS value for FSMaturityPreferentialist
	<</if>>
	<<if $arcologies[0].FSYouthPreferentialist !== "unset" && !Number.isFinite($arcologies[0].FSYouthPreferentialist)>>
		<<set $arcologies[0].FSYouthPreferentialist = 10>>

Fixed NaN FS value for FSYouthPreferentialist
	<</if>>
	<<if $arcologies[0].FSTransformationFetishist !== "unset" && !Number.isFinite($arcologies[0].FSTransformationFetishist)>>
		<<set $arcologies[0].FSTransformationFetishist = 10>>

Fixed NaN FS value for FSTransformationFetishist
	<</if>>
	<<if $arcologies[0].FSHedonisticDecadence !== "unset" && !Number.isFinite($arcologies[0].FSHedonisticDecadence)>>
		<<set $arcologies[0].FSHedonisticDecadence = 10>>

Fixed NaN FS value for FSHedonisticDecadence
	<</if>>
	<<if $arcologies[0].FSPhysicalIdealist !== "unset" && !Number.isFinite($arcologies[0].FSPhysicalIdealist)>>
		<<set $arcologies[0].FSPhysicalIdealist = 10>>

Fixed NaN FS value for FSPhysicalIdealist
	<</if>>
	<<if $arcologies[0].FSPastoralist !== "unset" && !Number.isFinite($arcologies[0].FSPastoralist)>>
		<<set $arcologies[0].FSPastoralist = 10>>

Fixed NaN FS value for FSPastoralist
	<</if>>
	<<if $arcologies[0].FSAssetExpansionist !== "unset" && !Number.isFinite($arcologies[0].FSAssetExpansionist)>>
		<<set $arcologies[0].FSAssetExpansionist = 10>>

Fixed NaN FS value for FSAssetExpansionist
	<</if>>
	<<if $arcologies[0].FSDegradationist !== "unset" && !Number.isFinite($arcologies[0].FSDegradationist)>>
		<<set $arcologies[0].FSDegradationist = 10>>

Fixed NaN FS value for FSDegradationist
	<</if>>
	<<if $arcologies[0].FSRomanRevivalist !== "unset" && !Number.isFinite($arcologies[0].FSRomanRevivalist)>>
		<<set $arcologies[0].FSRomanRevivalist = 10>>

Fixed NaN FS value for FSRomanRevivalist
	<</if>>
	<<if $arcologies[0].FSChattelReligionist !== "unset" && !Number.isFinite($arcologies[0].FSChattelReligionist)>>
		<<set $arcologies[0].FSChattelReligionist = 10>>

Fixed NaN FS value for FSChattelReligionist
	<</if>>
	<<if $arcologies[0].FSChineseRevivalist !== "unset" && !Number.isFinite($arcologies[0].FSChineseRevivalist)>>
		<<set $arcologies[0].FSChineseRevivalist = 10>>

Fixed NaN FS value for FSChineseRevivalist
	<</if>>
	<<if $arcologies[0].FSArabianRevivalist !== "unset" && !Number.isFinite($arcologies[0].FSArabianRevivalist)>>
		<<set $arcologies[0].FSArabianRevivalist = 10>>

Fixed NaN FS value for FSArabianRevivalist
	<</if>>
	<<if $arcologies[0].FSEdoRevivalist !== "unset" && !Number.isFinite($arcologies[0].FSEdoRevivalist)>>
		<<set $arcologies[0].FSEdoRevivalist = 10>>

Fixed NaN FS value for FSEdoRevivalist
	<</if>>
	<<if $arcologies[0].FSEgyptianRevivalist !== "unset" && !Number.isFinite($arcologies[0].FSEgyptianRevivalist)>>
		<<set $arcologies[0].FSEgyptianRevivalist = 10>>

Fixed NaN FS value for FSEgyptianRevivalist
	<</if>>
	<<if $arcologies[0].FSAztecRevivalist !== "unset" && !Number.isFinite($arcologies[0].FSAztecRevivalist)>>
		<<set $arcologies[0].FSAztecRevivalist = 10>>

Fixed NaN FS value for FSAztecRevivalist
	<</if>>
<</widget>>

<<widget "recalcBaseStats">>
	<<if $secBotsBaseAttack != 7 + $droneUpgrades.attack>>
		<<set $secBotsBaseAttack = 7 + $droneUpgrades.attack>>
	<</if>>
	<<if $secBotsBaseDefense != 3 + $droneUpgrades.defense>>
		<<set $secBotsBaseDefense = 3 + $droneUpgrades.defense>>
	<</if>>
	<<if $secBotsMorale != 200>>
		<<set $secBotsMorale = 200>>
	<</if>>
	<<if $secBotsBaseHp != 3 + $droneUpgrades.hp>>
		<<set $secBotsBaseHp = 3 + $droneUpgrades.hp>>
	<</if>>
	<<if $militiaBaseAttack != 7 + $humanUpgrade.attack>>
		<<set $militiaBaseAttack = 7 + $humanUpgrade.attack>>
	<</if>>
	<<if $militiaBaseDefense != 5 + $humanUpgrade.defense>>
		<<set $militiaBaseDefense = 5 + $humanUpgrade.defense>>
	<</if>>
	<<if $militiaBaseMorale != 140 + $humanUpgrade.morale>>
		<<set $militiaBaseMorale = 140 + $humanUpgrade.morale>>
	<</if>>
	<<if $militiaBaseHp != 3 + $humanUpgrade.hp>>
		<<set $militiaBaseHp = 3 + $humanUpgrade.hp>>
	<</if>>
	<<if $slaveBaseAttack != 8 + $humanUpgrade.attack>>
		<<set $slaveBaseAttack = 8 + $humanUpgrade.attack>>
	<</if>>
	<<if $slaveBaseDefense != 3 + $humanUpgrade.defense>>
		<<set $slaveBaseDefense = 3 + $humanUpgrade.defense>>
	<</if>>
	<<if $slaveBaseMorale != 110 + $humanUpgrade.morale>>
		<<set $slaveBaseMorale = 110 + $humanUpgrade.morale>>
	<</if>>
	<<if $slaveBaseHp != 3 + $humanUpgrade.hp>>
		<<set $slaveBaseHp = 3 + $humanUpgrade.hp>>
	<</if>>
	<<if $mercBaseAttack != 8 + $humanUpgrade.attack>>
		<<set $mercBaseAttack = 8 + $humanUpgrade.attack>>
	<</if>>
	<<if $mercBaseDefense != 4 + $humanUpgrade.defense>>
		<<set $mercBaseDefense = 4 + $humanUpgrade.defense>>
	<</if>>
	<<if $mercBaseMorale != 125 + $humanUpgrade.morale>>
		<<set $mercBaseMorale = 125 + $humanUpgrade.morale>>
	<</if>>
	<<if $mercBaseHp != 4 + $humanUpgrade.hp>>
		<<set $mercBaseHp = 4 + $humanUpgrade.hp>>
	<</if>>
	<<if $SFBaseAttack != 8 + $humanUpgrade.attack>>
		<<set $SFBaseAttack = 8 + $humanUpgrade.attack>>
	<</if>>
	<<if $SFBaseDefense != 4 + $humanUpgrade.defense>>
		<<set $SFBaseDefense = 4 + $humanUpgrade.defense>>
	<</if>>
	<<if $SFBaseMorale != 140 + $humanUpgrade.morale>>
		<<set $SFBaseMorale = 140 + $humanUpgrade.morale>>
	<</if>>
	<<if $SFBaseHp != 4 + $humanUpgrade.hp>>
		<<set $SFBaseHp = 4 + $humanUpgrade.hp>>
	<</if>>
<</widget>>

<<widget "replenishAllUnits">>
	<<set _hasLossesM = 0>>
	<<set _hasLossesS = 0>>
	<<set _hasLossesMe = 0>>

	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<if $militiaUnits[_i].troops < $militiaUnits[_i].maxTroops && $militiaFreeManpower > 0>>
			<<set _hasLossesM = 1>>
			<<break>>
		<</if>>
	<</for>>

	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<if $slaveUnits[_i].troops < $slaveUnits[_i].maxTroops && $helots > 0>>
			<<set _hasLossesS = 1>>
			<<break>>
		<</if>>
	<</for>>

	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<if $mercUnits[_i].troops < $mercUnits[_i].maxTroops && $mercFreeManpower > 0>>
			<<set _hasLossesMe = 1>>
			<<break>>
		<</if>>
	<</for>>

	<<if _hasLossesM == 1 && $militiaFreeManpower > 0 || _hasLossesS == 1 && $helots > 0 || _hasLossesMe == 1 && $mercFreeManpower > 0>>

		<<link "Replenish all units">>

			<<if _hasLossesM == 1>>
				<<for _i = 0; _i < $militiaUnits.length; _i++>>
					<<if $militiaUnits[_i].troops < $militiaUnits[_i].maxTroops && $militiaFreeManpower > 0>>
						<<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>>
					<</if>>
				<</for>>
			<</if>>

			<<if _hasLossesS == 1>>
				<<for _i = 0; _i < $slaveUnits.length; _i++>>
					<<if $slaveUnits[_i].troops < $slaveUnits[_i].maxTroops && $helots > 0>>
						<<if $helots >= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
							<<set $helots -= $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 += $helots>>
							<<set _expLoss = $helots / $slaveUnits[_i].troops>>
							<<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>>
							<<set $slaveUnits[_i].troops += $helots>>
							<<set $helots = 0>>
						<</if>>
					<</if>>
				<</for>>
			<</if>>

			<<if _hasLossesMe == 1>>
				<<for _i = 0; _i < $mercUnits.length; _i++>>
					<<if $mercUnits[_i].troops < $mercUnits[_i].maxTroops && $mercFreeManpower > 0>>
						<<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>>
					<</if>>
				<</for>>
			<</if>>

			<<if $slaveRebellion == 1 || $citizenRebellion == 1>>
				<<goto "rebellionOptions">>
			<<elseif $attackThisWeek == 1>>
				<<goto "attackOptions">>
			<<else>>
				<<goto "secBarracks">>
			<</if>>

		<</link>>

//Will replenish units as long as manpower is available
	<</if>>

<</widget>>


code:
:: unitsWidgets [widget nobr]

<<widget "militiaUnitsDescription">>
	<<if $args[0].active == 1>>
		$args[0].platoonName <<if $args[0].battlesFought > 1>> participated in $args[0].battlesFought battles and is ready to face the enemy once more at your command.<<elseif $args[0].battlesFought == 1>>is ready to face the enemy once more at your command.<<else>>is ready to face the enemy in battle.<</if>>
		Its $args[0].troops men and women are all proud citizens of your arcology, willing to put their lives on the line to protect their home.
		<<if $args[0].troops < $args[0].maxTroops>> The unit is not at its full strength of $args[0].maxTroops operatives.<</if>>
		<<if $args[0].equip == 0>>
			They are issued with simple, yet effective equipment: firearms, a few explosives and standard uniforms, nothing more.
		<<elseif $args[0].equip == 1>>
			They are issued with good, modern equipment: firearms, explosives and a few specialized weapons like sniper rifles and machine guns. They also carry simple body armor.
		<<elseif $args[0].equip == 2>>
			They are issued with excellent, high tech equipment: modern firearms, explosives, specialized weaponry and modern body armor. They are also issued with modern instruments like night vision and portable radars.
		<<else>>
			They are equipped with the best the modern world has to offer: modern firearms, explosives, specialized weaponry, experimental railguns, adaptive body armor and high tech recon equipment.
		<</if>>
		<<if $args[0].training <= 33>>
			They lack the experience to be considered consummate professionals, but their eagerness to defend the arcology makes up for it.
		<<elseif $args[0].training <= 66>>
			They have trained <<if $args[0].battlesFought > 0>>and fought<</if>> enough to be considered disciplined, professional soldiers, ready to face the battlefield.
		<<else>>
			They are consummate veterans, with a wealth of experience and perfectly trained. On the battlefield they are a well oiled war machine capable of facing pretty much anything.
		<</if>>
		<<if $args[0].loyalty < 10>>
			The unit is extremely disloyal. Careful monitoring of their activities and relationships should be implemented.
		<<elseif $args[0].loyalty < 33>>
			Their loyalty is low. Careful monitoring of their activities and relationships is advised.
		<<elseif $args[0].loyalty < 66>>
			Their loyalty is not as high as it can be, but they are not actively working against their arcology owner.
		<<elseif $args[0].loyalty < 90>>
			Their loyalty is high and strong. The likelihood of this unit betraying the arcology is low to non-existent.
		<<else>>
			The unit is fanatically loyal. They would prefer death over betrayal.
		<</if>>
		<<if $args[0].cyber == 1>>
			The soldiers of the unit have been enhanced with numerous cyberaugmentations which greatly increase their raw power.
		<</if>>
		<<if $args[0].medics == 1>>
			The unit has a dedicated squad of medics that will follow them in battle.
		<</if>>
		<<if $SF.Toggle && $SF.Active >= 1 && $args[0].SF>>
			The unit has attached advisors from $SF.Lower that will help the squad remain tactically aware and active.
		<</if>>
	<<else>>
		$args[0].platoonName lost too many operatives in the $args[0].battlesFought it fought and can no longer be considered a unit at all.
	<</if>>
<</widget>>

<<widget "slaveUnitsDescription">>
	<<if $args[0].active == 1>>
		$args[0].platoonName <<if $args[0].battlesFought > 1>> participated in $args[0].battlesFought battles and is ready to face the enemy once more at your command.<<elseif $args[0].battlesFought == 1>>is ready to face the enemy once more at your command.<<else>>is ready to face the enemy in battle.<</if>>
		Its $args[0].troops men and women are slaves in your possession, tasked with the protection of their owner and their arcology.
		<<if $args[0].troops < $args[0].maxTroops>> The unit is not at its full strength of $args[0].maxTroops operatives.<</if>>
		<<if $args[0].equip == 0>>
			They are issued with simple, yet effective equipment: firearms, a few explosives and standard uniforms, nothing more.
		<<elseif $args[0].equip == 1>>
			They are issued with good, modern equipment: firearms, explosives and a few specialized weapons like sniper rifles and machine guns. They also carry simple body armor.
		<<elseif $args[0].equip == 2>>
			They are issued with excellent, high tech equipment: modern firearms, explosives, specialized weaponry and modern body armor. They are also issued with modern instruments like night vision and portable radars.
		<<else>>
			They are equipped with the best the modern world has to offer: modern firearms, explosives, specialized weaponry, experimental railguns, adaptive body armor and high tech recon equipment.
		<</if>>
		<<if $args[0].training <= 33>>
			They lack the experience to be considered professionals, but their eagerness to prove themselves makes up for it.
		<<elseif $args[0].training <= 66>>
			They have trained <<if $args[0].battlesFought > 0>>and fought<</if>> enough to be considered disciplined, professional soldiers, ready to face the battlefield.
		<<else>>
			They are consummate veterans, with a wealth of experience and perfectly trained. On the battlefield they are a well oiled war machine capable of facing pretty much anything.
		<</if>>
		<<if $args[0].loyalty < 10>>
			The unit is extremely disloyal. Careful monitoring of their activities and relationships should be implemented.
		<<elseif $args[0].loyalty < 33>>
			Their loyalty is low. Careful monitoring of their activities and relationships is advised.
		<<elseif $args[0].loyalty < 66>>
			Their loyalty is not as high as it can be, but they are not actively working against their arcology owner.
		<<elseif $args[0].loyalty < 90>>
			Their loyalty is high and strong. The likelihood of this unit betraying the arcology is low to non-existent.
		<<else>>
			The unit is fanatically loyal. They would prefer death over betrayal.
		<</if>>
		<<if $args[0].cyber == 1>>
			The soldiers of the unit have been enhanced with numerous cyberaugmentations which greatly increase their raw power.
		<</if>>
		<<if $args[0].medics == 1>>
			The unit has a dedicated squad of medics that will follow them in battle.
		<</if>>
		<<if $SF.Toggle && $SF.Active >= 1 && $args[0].SF>>
			The unit has attached advisors from $SF.Lower that will help the squad remain tactically aware and active.
		<</if>>
	<<else>>
		$args[0].platoonName lost too many operatives in the $args[0].battlesFought it fought and can no longer be considered a unit at all.
	<</if>>
<</widget>>

<<widget "mercUnitsDescription">>
	<<if $args[0].active == 1>>
		$args[0].platoonName <<if $args[0].battlesFought > 1>> participated in $args[0].battlesFought battles and is ready to face the enemy once more at your command.<<elseif $args[0].battlesFought == 1>>is ready to face the enemy once more at your command.<<else>>is ready to face the enemy in battle.<</if>>
		Its $args[0].troops men and women are mercenaries contracted to defend the arcology against external threats.
		<<if $args[0].troops < $args[0].maxTroops>> The unit is not at its full strength of $args[0].maxTroops operatives.<</if>>
		<<if $args[0].equip == 0>>
			They are issued with simple, yet effective equipment: firearms, a few explosives and standard uniforms, nothing more.
		<<elseif $args[0].equip == 1>>
			They are issued with good, modern equipment: firearms, explosives and a few specialized weapons like sniper rifles and machine guns. They also carry simple body armor.
		<<elseif $args[0].equip == 2>>
			They are issued with excellent, high tech equipment: modern firearms, explosives, specialized weaponry and modern body armor. They are also issued with modern instruments like night vision and portable radars.
		<<else>>
			They are equipped with the best the modern world has to offer: modern firearms, explosives, specialized weaponry, experimental railguns, adaptive body armor and high tech recon equipment.
		<</if>>
		<<if $args[0].training <= 33>>
			They lack the experience to be considered professionals, but they're trained more than enough to still be an effective unit.
		<<elseif $args[0].training <= 66>>
			They have trained <<if $args[0].battlesFought > 0>>and fought<</if>> enough to be considered disciplined, professional soldiers, ready to face the battlefield.
		<<else>>
			They are consummate veterans, with a wealth of experience and perfectly trained. On the battlefield they are a well oiled war machine capable of facing pretty much anything.
		<</if>>
		<<if $args[0].loyalty < 10>>
			The unit is extremely disloyal. Careful monitoring of their activities and relationships should be implemented.
		<<elseif $args[0].loyalty < 33>>
			Their loyalty is low. Careful monitoring of their activities and relationships is advised.
		<<elseif $args[0].loyalty < 66>>
			Their loyalty is not as high as it can be, but they are not actively working against their arcology owner.
		<<elseif $args[0].loyalty < 90>>
			Their loyalty is high and strong. The likelihood of this unit betraying the arcology is low to non-existent.
		<<else>>
			The unit is fanatically loyal. They would prefer death over betrayal.
		<</if>>
		<<if $args[0].cyber == 1>>
			The soldiers of the unit have been enhanced with numerous cyberaugmentations which greatly increase their raw power.
		<</if>>
		<<if $args[0].medics == 1>>
			The unit has a dedicated squad of medics that will follow them in battle.
		<</if>>
		<<if $SF.Toggle && $SF.Active >= 1 && $args[0].SF>>
			The unit has attached advisors from $SF.Lower that will help the squad remain tactically aware and active.
		<</if>>
	<<else>>
		$args[0].platoonName lost too many operatives in the $args[0].battlesFought it fought and can no longer be considered a unit at all.
	<</if>>
<</widget>>

<<widget "secBotsDescription">>
	<<if $secBots.active == 1>>
		The <<print $secBots.troops>> security drones are assembled in an ordered line in front of you, absolutely silent and ready to receive their orders.
		<<if $secBots.troops < $secBots.maxTroops>> The unit is not at its full strength of $secBots.maxTroops drones.<</if>>
		<<if $secBots.equip == 0>>
			They are equipped with light weaponry, mainly anti-riot non lethal weapons. Not particularly effective in battle.
		<<elseif $secBots.equip == 1>>
			They are equipped with light firearms, not an overwhelming amount of firepower, but with their mobility good enough to be effective.
		<<elseif $secBots.equip == 2>>
			They are equipped with powerful, modern firearms and simple armor mounted around their frames. They do not make for a pretty sight, but on the battlefield they are a dangerous weapon.
		<<else>>
			They are equipped with high energy railguns and adaptive armor. They are a formidable force on the battlefield, even for experienced soldiers.
		<</if>>
	<<else>>
		There are too few security drones left to be able to deploy them on the battlefield.
	<</if>>
<</widget>>

<<widget "generateUnitID">>
	<<set _newID = 0>>

	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<if $militiaUnits[_i].ID >= _newID>>
			<<set _newID = $militiaUnits[_i].ID + 1>>
		<</if>>
	<</for>>

	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<if $slaveUnits[_i].ID >= _newID>>
			<<set _newID = $slaveUnits[_i].ID + 1>>
		<</if>>
	<</for>>

	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<if $mercUnits[_i].ID >= _newID>>
			<<set _newID = $mercUnits[_i].ID + 1>>
		<</if>>
	<</for>>

	<<set $args[0].ID = _newID>>
<</widget>>


code:
:: CheatEdit [nobr]
<<set $nextButton = "Back to $SF.Lower's Firebase", $nextLink = "Firebase", $returnTo = "Firebase">>
<<= Count()>>__Upgrades__: $SF.Units/_max
<<if $SF.Units >= 30>><<set _T1 = 1>><<else>><<set _T1 = 0>><</if>>

''Firebase:'' <<textbox "$SFUnit.Firebase" $SFUnit.Firebase "CheatEdit">>/_FU

''Armory:'' <<textbox "$SFUnit.Armoury" $SFUnit.Armoury "CheatEdit">>/_AU

''Drug Lab:'' <<textbox "$SFUnit.Drugs" $SFUnit.Drugs "CheatEdit">>/_DrugsU
<<if $SFUnit.Firebase >= 2>>

''Drone Bay:'' <<textbox "$SFUnit.Drones" $SFUnit.Drones "CheatEdit">>/_DU<</if>>

<<if $SFUnit.Firebase >= 1 && $terrain !== "oceanic">>

''Garage:''

 ''Vehicles:''

  ''Attack:'' <<textbox "$SFUnit.AV" $SFUnit.AV "CheatEdit">>/_AVU

  ''Transport:'' <<textbox "$SFUnit.TV" $SFUnit.TV "CheatEdit">>/_TVU
	<<if _T1>>

 ''Prototype Goliath Tank:'' <<textbox "$SFUnit.PGT" $SFUnit.PGT "CheatEdit">>/_PGTU<</if>>
<</if>>

<<if $SFUnit.Firebase >= 4>>

''Hangar:''

 ''Aircraft:''

  ''Attack:'' <<textbox "$SFUnit.AA" $SFUnit.AA "CheatEdit">>/_AAU

  ''Transport:'' <<textbox "$SFUnit.TA" $SFUnit.TA "CheatEdit">>/_TAU
	<<if _T1>>

 ''Spaceplane'': <<textbox "$SFUnit.SpacePlane" $SFUnit.SpacePlane "CheatEdit">>/_SPU

 ''Gunship:'' <<textbox "$SFUnit.GunS" $SFUnit.GunS "CheatEdit">>/_GunSU

''Launch Bay:''

 ''Satellite:'' <<textbox "$SFUnit.Satellite" $SFUnit.Satellite "CheatEdit">>/_SatU
		<<if $terrain !== "oceanic">>

 ''Giant Robot:'' <<textbox "$SFUnit.GiantRobot" $SFUnit.GiantRobot "CheatEdit">>/_GRU<</if>>

 ''Cruise Missile:'' <<textbox "$SFUnit.MissileSilo" $SFUnit.MissileSilo "CheatEdit">>/_MSU
<<if $terrain === "oceanic" || $terrain === "marine">>

''Naval Yard:''

 ''Aircraft Carrier:'' <<textbox "$SFUnit.AircraftCarrier" $SFUnit.AircraftCarrier "CheatEdit">>/_ACU

 ''Submarine:'' <<textbox "$SFUnit.Sub" $SFUnit.Sub "CheatEdit">>/_SubU

 ''Amphibious Transport:'' <<textbox "$SFUnit.HAT" $SFUnit.HAT "CheatEdit">>/_HATU
<</if>><</if>><</if>>


code:
:: SFColonelSexDec
<<switch $SFColonel.Core>>
<<case "shell shocked">>

	The entire time it is obvious that The Colonel is reliving a horrible event.

<<link "Try to bring her back">>
	<<replace "#result7">>
	"You made an attempt to try to bring her back to the present."
	<</replace>>
	<</link>>

<<link "Leave her be">>
	<<replace "#result7">>
	"It is probably better that she tries to deal with her demons alone"
	<</replace>>
	<</link>>

<<default>>
	Inset sex noises here.
<</switch>>


code:
:: Firebase [nobr]

	<<if ndef $Tour>> <<set $Tour = 0>> <</if>>

	<<if $Tour === 0>>

		<<= Count()>> <<if $SF.Lower != "the special force">>

			<<set $SF.Caps = $SF.Lower.replace("the ", "The ")>> <</if>>

		<<switch _Env>> <<case 4>>

				<<set _EnvCash2 = 450,_EnvCash3 = 200,_EnvCash4 = 100,_EnvProsp = 3>>

			<<case 3>>

				<<set _EnvCash2 = 500,_EnvCash3 = 250,_EnvCash4 = 150,_EnvProsp = 5>>

			<<case 2>>

				<<set _EnvCash2 = 550,_EnvCash3 = 300,_EnvCash4 = 200,_EnvProsp = 7>>

		<</switch>> <<set $nextButton = "Back to Main",$nextLink = "Main",$returnTo = "Firebase">>

		<<if $cheatMode > 0>> <<link "Cheat edit""CheatEdit">> <</link>>
 <</if>>

		The firebase of $arcologies[0].name's <<textbox "$SF.Lower" $SF.Lower "Firebase">> is located in the lower levels, occupying unneeded warehouse space. It is not accessible to the general citizenry, but your personal elevator has express service to it. As you step off, two soldiers in combat armor manning the entry checkpoint tense before recognizing their Marshal and stepping aside with a sharp salute.

<<if $SFTradeShow.CanAttend === 1 || ($SFColonel.Fun + $SFColonel.Talk >= 1)>>

			You make your way to the operations center, <<print SFC()>> is handling a minor issue. As you enter, she salutes. <<if $SFTradeShow.CanAttend == 1>> The Colonel is away at her merc meetup, so <<print SFC()>> will assist you.<</if>>

		<<elseif random(1,100) > 5>>

			You make your way to the operations center. The Colonel is

				<<if random(1,100) > 50>>glancing between her tablet and the large wallscreen, occasionally taking notes or barking orders.

				<<else>>examining a table with a map of the surrounding area, planning manuevers in the event of an attack.<</if>>

			 She notices your entrance and turns her attention to you.

			<<if $SFColonel.Core == "brazen">>

				She gives a textbook salute. "<<= properTitle()>>, how can I help you?"

			<<else>>

			"Hey boss, what do you need?"<</if>>

		<<else>>

			You make your way to the operations center, finding it empty. A short walk takes you through the barracks to the Colonel's quarters. As you approach, the Colonel <<print ColonelQuarters()>>

		<</if>>

		<<if ndef $SFTradeShow.View && ($SFColonel.Fun + $SFColonel.Talk < 1)>>

Her expression changes as something jogs her memory. "Before we begin <<if $SFColonel.Core == "brazen">><<= properTitle()>><<else>>boss<</if>>, back when I was a merc me and a couple of my old friends would have a meetup every several months. Drinking, fucking, drugs... a little poker. It eventually grew into a whole thing, and now we bring our latest and greatest toys to show off, maybe make some money off selling the schematics. I'd like to continue going, for old times' sake."

[[Grant leave|Firebase][$SFTradeShow.CanAttend = 1,$SFTradeShow.View = 1]]

[[Request she remain on base|Firebase][$SFTradeShow.CanAttend = -2,$SFTradeShow.View = 0]]

		<</if>>

			<<if $SFTradeShow.History >= 1 && (Math.trunc($week/24) === ($week/24)) && $SFTradeShow.CanAttend === -1>>

Her expression changes as something jogs her memory. "Before we begin <<if $SFColonel.Core == "brazen">><<= properTitle()>><<else>>boss<</if>>, that biannual merc meetup has come around again. You've already gave me leave to attend, but I just wanted to be sure I'm still clear to go."

[[Grant leave.|Firebase][$SFTradeShow.CanAttend = 1]]

[[Request she remain on site.|Firebase][$SFTradeShow.CanAttend = -1]]

		<</if>>

		<<if $SFTradeShow.History >= 1 && ((Math.trunc(($week-1)/24) === ($week-1)/24) || (Math.trunc(($week-2)/24) === ($week-2)/24) || (Math.trunc(($week-3)/24) === ($week-3)/24))>>

			While at the recent merc meetup, the Colonel made @@.yellowgreen;<<print cashFormat(Math.ceil($SFTradeShow.Income))>>@@  selling generic schematics to her friends, <<print commaNum($SFTradeShow.Helots)>> menial slaves were won in a poker game, and <<print commaNum($SFTradeShow.TotalMercs)>> mercenaries were persuaded to join $SF.Lower.

Total earnings thus far: @@.yellowgreen;<<print cashFormat(Math.ceil($SFTradeShow.Revenue))>>@@ in income, <<print commaNum($SFTradeShow.TotalHelots)>> menial slaves and <<print commaNum($SFTradeShow.Mercs)>> mercenaries joined across $SFTradeShow.History meetups.

		<</if>>

		<<print Interactions()>>

		<<include "WC">>

		<<if $SpecOpsLock < 1>>

<<switch $SF.SpecOps>>

			<<case 0>>

No soldiers are working undercover. [[Lock your choice in|Firebase][$SpecOpsLock = 1]]

[[Reassign soldiers|Firebase][$SF.SpecOps = -1]]

			<<case 1>>

A small section of soldiers are working undercover. [[Lock your choice in|Firebase][$SpecOpsLock = 1]]

[[Reassign soldiers|Firebase][$SF.SpecOps = -1]]

			<<case 2>>

A large section of soldiers are working undercover. [[Lock your choice in|Firebase][$SpecOpsLock = 1]]

[[Reassign soldiers|Firebase][$SF.SpecOps = -1]]

			<<default>>

Would you like to assign soldiers to undercover duty?

[[Do not assign soldiers to work undercover|Firebase][$SF.SpecOps = 0]]

[[Assign a small section of soldiers to work undercover|Firebase][$SF.SpecOps = 1]]

[[Assign a large section of soldiers to work undercover|Firebase][$SF.SpecOps = 2]]

			<</switch>>
		<<else>>

 <<if $SF.SpecOps < 1>>''Zero''<<elseif $SF.SpecOps < 2>>A ''small'' section<<else>>A ''large'' section<</if>> of the special force is assigned to undercover work. [[Unock your choice|Firebase][$SpecOpsLock = 0]]
		<</if>>

		<<if $SFUnit.Firebase > 5 && $secExp > 0 && $SFSupportLevel >= 4 && $maxUnits === 16 && $readiness <= 10>>

[[Provide the security force with their own section.|Firebase][$maxUnits += 4,$readiness = 10,$cash -= Math.ceil((750000*(1.15+($SF.Units/1000))*(1.15+($SFUnit.Firebase/10)))*_Env)]]

			@@.yellowgreen;<<print cashFormat(Math.ceil((750000*(1.15+($SF.Units/1000))*(1.15+($SFUnit.Firebase/10)))*_Env))>>@@

		<</if>>

		<<include "Upgrades">>

<<link "Tour the firebase" "Firebase">><<set $Tour = 1>><</link>>

	<</if>>

	<<if $Tour === 1>> <<set $nextButton = " ">>

		<<=Count()>><<include "FlavourText">>

		[[Return to Operations|Firebase][$Tour = 0]]

	<</if>>


code:
:: Security Force Naming-Colonel [nobr]
<<set $nextButton = " ">> <<if ndef $NamingColonel>> <<set $NamingColonel = 0>> <</if>>
<<if $NamingColonel === 0>>
	It's been a short while since you told your citizens that you were going to talk to them about their security, and by all accounts, they've turned out in force to watch your address over the arcology's internal communications system. You wake up early, relieve your frustrations on a few slaves woken out of deep sleep, and take position behind your desk. You also call over a slave and push her under your desk. The unspoken instruction is clear, and she begins enthusiastically
	<<if $PC.dick == 1>>
			sucking your cock, taking it as deep as she can without gagging.
	<<else>>
			eating you out, pressing her face into your pussy and forcing her tongue deep inside you.
	<</if>>

A blinking light tells you that the channel is open. You take a deep breath, and begin. You greet your citizens and explain that while you believe deeply in the underlying principles of the Free Cities, recent events have forced you to modify some of your views. The Old World attack from the outside and the more recent assault by the Daughters of Liberty from within has proven that some form of permanent, organized standing force is needed to ensure the personal safety of the citizen body.

You tell them that the Old World continues to deteriorate. You tell them that it is only a matter of time before the poor, diseased, starving, and unwashed masses try their hand at invading the arcology again. You tell them that such a force would be good for business, securing trade routes and conducting slaving raids far greater in scale than those performed by private slaving corporations. And finally, to quell their greatest fear, you tell them that you would personally support the force financially.

As you speak, you carefully monitor the citizens' opinions as indicated on their communication devices. It is uniformly positive - they know whom they have to thank for their continued survival and dominance. You also monitor your arousal given the ministrations of your slave. A few small movements on your part communicate to your citizens what is happening without being too obvious. Free Cities business etiquette respects business conducted while being subtly serviced (and your doing so during such a public and important broadcast signals how seriously you are taking it), but a climax would be seen as a serious lack of discipline.

You finally wrap up your speech, declaring yourself Marshal of the newly-formed <<textbox "$SF.Lower" $SF.Lower>>

You close the link to the communication system and read a message from your assistant that appeared during the last moments of your address. In consultation with major figures in the mercenary community, a suitable candidate for day-to-day command of the new unit has been found. Your instructions were to keep you in the dark about them so as to avoid prejudgment. They are waiting outside your office.

[[Invite them inside|Security Force Naming-Colonel][$NamingColonel = 1]]
<</if>>
<<if $NamingColonel === 1>>
	The figure that enters is not what you were expecting, given your previous experiences with the mercenary groups that work with the arcology owners of the Free Cities. Most mercenaries you've worked with have been grizzled stout men, veterans of the Old World militaries that finally had too much and went private. Instead, a woman walks in.
	<<if $SFColonel.Core == "">>
		She strikes you as someone who is likely to be:

[[Kind|Security Force Naming-Colonel][$SFColonel.Core = "kind"]]

[[Cruel and psychopathic|Security Force Naming-Colonel][$SFColonel.Core = "cruel"]]

[[A brazen warmonger|Security Force Naming-Colonel][$SFColonel.Core = "brazen"]]

[[Jaded|Security Force Naming-Colonel][$SFColonel.Core = "jaded"]]

[[Shell-shocked|Security Force Naming-Colonel][$SFColonel.Core = "shell shocked"]]
	<</if>>
	<<if $SFColonel.Core !== "">>
		She is likely to be ''$SFColonel.Core''.

She strides in, stopping in front of your desk,
		<<switch $SFColonel.Core>>
			<<case "kind">>
				pulling off a laid-back salute with an easy grin.
			<<case "cruel">>
				her eyes flashing a hard glare in an instant before quickly softening into those of someone who wants something you have.
			<<case "brazen">>
				snapping off a textbook salute that decades of hard service grills into a veteran.
			<<default>>
				not bothering to put on even the semi-military air (complete with salute) that most mercenaries tend to adopt when meeting new clients.
		<</switch>>
		She is very tall and wearing the pants, boots, gloves, and the tank top undershirt of a standard female combat uniform. Her bare arms and upper body are corded with muscle, and through the tank top's thin fabric you can see both the shape of her muscled abdomen and the curves of her small but perky breasts, complete with what your experience tells you are barbell nipple piercings. Her eyes are alive with intelligence, and you can see her scanning your office, clearly impressed by its opulence. Her hair is shaved close to the scalp, and her ears and nose are heavily pierced. You can make out three long, ugly scars running over top of the mottled tissue of a previous, severe burn along one side of her face, as well as numerous smaller scars and burns on her bare arms. She's been disarmed prior to meeting you; the pistol holster on her hip lies empty, as do at least three knife holsters about her person.

Returning your gaze to her face, she crosses her arms underneath her chest, pressing her breasts up and forward. You have her measure. Given the generally patriarchal nature of both the mercenary community, and the same nature combined with the heavily sexualized lifestyle of the Free Cities, she's decided to embrace her position rather than fight it.

"So," she begins, "you're the boss." You invite her to sit down. "No thanks, boss. Besides,"
		<<switch $SFColonel.Core>>
			<<case "kind">>
				she playfully
			<<case "shell shocked">>
				she uncomfortably
			<<default>>
				she
		<</switch>>
		indicates the slave under your desk, "you look a little occupied." She nods at the camera across from you. "Saw the speech. Very nice. I'd heard you crazy bastards do business while getting
		<<if $PC.dick == 1>>
				sucked off,
		<<else>>
				eaten out,
		<</if>>
		but I've never seen anyone actually do it. Hell, most of you people don't want to have to have too much to do with a merc like me. I usually get my instructions remotely."
		<<switch $SFColonel.Core>>
			<<case "jaded" "brazen">>
				A short, harsh laugh escapes her. "But I guess it keeps you focused. Can't have the entire arcology seeing you cum."
			<<case "kind">>
				She grins. "That kind of thing doesn't really bother me though."
			<<case "cruel">>
				She frowns. "The client always seems to be happier that way."
		<</switch>>

She moves a step closer. "Your computer-helper-thing told me you wanted me to be a surprise, so I guess I'll tell you why you want me to run the $SF.Lower for you. I'm a killer, pure and simple,<<if $SFColonel.Core === "cruel">>" she smiles, "<</if>>and you need that. I looked into those attacks you've suffered. Nasty business. I'll make sure that an attack like that never happens again. I was a soldier out there, in charge of about a thousand men when the Free Cities first started going up, and I knew they were the future. Eventually I deserted, found the first refugee convoy I could, killed the moron protecting it, sold the girls off to slavers, and bought enough gear to start killing for people like you. Ran my own merc crew, did well till we tried to take on a bigger one and everyone died."
		<<switch $SFColonel.Core>>
			<<case "shell shocked">>
				She looks away, caught in her own memories. It takes a solid minute before she starts again.
			<<case "cruel">>
				Her smile grows.
			<<default>>
				She pauses for a moment.
		<</switch>>
		"Joined with another big outfit, became the number two, then shit went bad and I had to run. Been a solo fighter and slaver ever since. I know my work, and I know I can make this work."

You feel your climax approaching and hold up a finger. The merc pauses while you
		<<if $PC.dick == 1>>
			grab the slave's head, forcing your cock roughly down her throat while you cum. She swallows as much as she can before pulling away, coughing.
		<<else>>
			grip the slave's head tightly with your thighs, pressing her face tightly against your pussy as you cum. When you release her, she pulls away, coughing.
		<</if>>

		<<if $SFColonel.Core === "shell shocked">>
			The merc looks away again, letting the girl settle down before continuing.
		<<else>>
			The merc laughs again. "I could get used to a place like this."
		<</if>>
		She waves her hand around the office. "I bet you want to know why I'd be trustworthy for something like this." You don't correct her. "Thought so." Her demeanor softens, and you can detect a hit of nervousness. "I would say that I've never turned on a client and leave it at that, but this is different. It's getting worse out there. I'm sure you know that." You give her a slight nod. "Four times now I've woken up in the middle of the night and had to kill someone.<<if $SFColonel.Core === "shell shocked">>"<<else>> Two of them were the people I'd taken to bed. You can't even trust your drunken fucks anymore.
		<<switch $SFColonel.Core>>
			<<case "kind">>
				It's a shame, but that's the world we live in."
			<<case "cruel">>
				Then again, who doesn't like a good hard fuck and stab?"
			<<default>>
				But what else is new?"
		<</switch>><</if>>

		<<if $SFColonel.Core === "jaded" || $SFColonel.Core === "shell shocked">>
			"All I know how to do at this point is fight, and that's kept me alive this far.
		<<else>>
			"I like fighting, but I want to live somewhere where I can relax from life out there.
		<</if>>
		You give me the job and a place to live, let me hang up the uncertainty of being a merc, and I'll die for you if it comes to that. I promise the people I recruit will feel the same. Besides," she grins, "I could get used to
		<<switch $SFColonel.Core>>
			<<case "brazen">>
				crushing any enemy that looks our way."
			<<case "cruel">>
				having my own stable to abuse as I see fit. A terrified little slavegirl locked between my legs, struggling to breathe?"
			<<default>>
				spending my R&R time with a cold beer in one hand, a few lines of coke or a stack of pills in front of me."
		<</switch>>
		A glint runs through her eyes. "Sounds like a good fucking time."

You quickly decide she'll do. You tap a few commands on your desk's console, assigning her personal quarters on the arcology's higher levels and transferring her first stipend to her new account. You also ask her what title she wants.

"Title?" Another short laugh. "I guess I do need one, given that I'm all official and shit now." She thinks for a moment. "I was a major before I went freelance, and I think I'd like a promotion. Colonel sounds good." You make a note of this in her file. "You people don't seal contracts with a fuck do you?" Reassuring her you don't, she laughs again. "Good. I make it a point never to fuck the boss. It's bad for business." She turns around. "Well, I guess I'd better get to it. Your helper-thing assigned me space on the lower levels for the firebase. I brought a few squads of guys I know from the old days to start, but we'll grow fast once I put the word out, I guarantee it."

[[Let her leave|Security Force Naming-Colonel][$NamingColonel = 2]]
	<</if>>
<</if>>
<<if $NamingColonel === 2>>
	<<set $nextLink = "Next Week",$nextButton = "Continue">> <<unset $NamingColonel>>
	She turns and leaves, and you chase the slave out after her. A few minutes later, a soft chime announces the arrival of a message. It's from the Colonel.

//Hey boss, just wanted to mention something else. In your speech you said that you were going to be paying for $SF.Lower. In my mind that means it's yours, no matter what anyone else here might think. I do what you tell me to do. I make sure the troops behave as you want them to behave. I've worked for some 'nice guys' in the past, and I can do that job if you want. It's boring, but sustainable, and I'll have the $SF.Lower turning a profit and supporting the arcology in good order. But if you let me <<if $SFColonel.Core === "cruel">>off the leash<<else>>do what I do<</if>> and throw any Old World complaints in the trash where they belong, I promise you'll have money pouring into your coffers, even accounting for the good amounts me and my boys will pocket along the way. You'll have an empire in short order.
	<<if $mercenaries > 1>>
		Either way, I'll keep my hands off those mercs you've already installed. I figure that you've reasons for having two different death squads under contract.
	<</if>>

Oh, one last thing. I know you've got some kind of grand social experiment going on up there like all the other arco owners, and that's your own deal, but I'd appreciate it if you could keep that stuff out of the new barracks. I'll have a hard time approaching potential recruits and telling them they should come live in a Roman apartment, an Egyptian temple, a goddamn Japanese teahouse, or some of the other crazy shit I've seen in the past. They're hard, nasty people, and trust me, I can tell you from experience that changing that is just not going to happen. Like I said, though, I can hold them back a bit if you like.

Talk to you later, boss.// <<set $SF.Active = 2>>
<</if>>


code:
:: Security Force Proposal [nobr]
<<if $SF.Active === -1 && passage() !== "New Game Plus">>

	The Free Cities were founded on the principles of unrestrained anarcho-capitalism. To those with such beliefs, the very idea of possessing an armed force, a key tool of government control, or weapons at all, was anathema.

In the period since, however, your citizens have seen the value in weaponry. They watched on their news-feed as some Free Cities were sacked by the armies and mobs of the Old World, driven by their hatred of the citizens' luxurious lifestyles. They've seen other Cities toppled from within, by slave conspiracies or infighting among citizen groupings with differing beliefs. They've witnessed the distressingly rapid rise of fanatical anti-slavery organizations, who would like nothing more than to see them slowly bled by their own chattel. They are learned people, and they know what happens to slaveowners who lose their power.

They've also seen the results of your policies. Your actions towards the arming of both yourself and the arcology proved critical, and ensured their safety when the Old World came for them. And your victory over the Daughters of Liberty, who the citizens know would have executed every single one of them, has created an opportunity. If you insisted upon the creation of a standing 'special' force for the arcology, many would support you and, more importantly, nobody of note would object.

Such a force would solve many problems. More soldiers would mean more control, which is very good for you. More soldiers would mean more security for the arcology and the approaches to it, which is very good for business. More soldiers would mean more obedience from rebellious slaves who can see how powerless they truly are, which is very good for everybody. The force would be tiny compared to the Old World militaries that still exist, but money and technology can, of course, overcome massive numerical inferiority. This being the Free Cities, they would have other uses besides security. Perhaps, in time, you could exert some manner of influence on the Old World itself.

''This is a unique and very important opportunity'', and is possible only because of your recent victory over the Daughters. If you do not seize it, the memories and fears of your citizens will fade,and you will not be able to raise the matter again.

	<<set _price = 20000>> <<if $PC.warfare >= 100>> <<set _price = _price*.5>>
	<<elseif $PC.warfare >= 50||$PC.career === "arcology owner">>
	<<set _price = _price*.75>> <</if>>

<<link "Prepare for an announcement.""Security Force Proposal">> <<replace "#result">>

		You instruct $assistantName to announce to the arcology's citizenry that you will be making an important announcement in the near future regarding the security situation. Given the damage still present from the Daughters' attack, everyone will be tuning in. You also instruct your assistant to begin quietly investigating potential leadership figures for the force itself.

	<<run Object.assign($SF, {Active:1, Depravity:0, Units:0, MWU:0, U:0, WG:0, SpecOps:0, SpecOpsLock:0,
		ROE:"hold", Target:"recruit", Regs:"strict", Caps:"The Special Force",
		Lower:"the special force", Subsidy:1})>> <<set $cash -= _price>>
	<<set $SFUnit = Object.assign({}, $SFUnit, {Troops:40, Armoury:0, Firebase:0, AV:0, TV:0, Drones:0,
		Drugs:0, PGT:0, AA:0, TA:0, SpacePlane:0, GunS:0, Satellite:0, GiantRobot:0, MissileSilo:0,
		AircraftCarrier:0, Sub:0, HAT:0})>> <<set $arcologies[0].SFRaid = 1,$arcologies[0].SFRaidTarget = -1>>
		<<set $SFColonel = Object.assign({}, $SFColonel, {Core:"", Talk:0, Fun:0, Status:0})>>
		<<set $SFTradeShow = Object.assign({}, $SFTradeShow, {History:0, CanAttend:0,
		Income:0, Revenue:0, Helots:0, TotalHelots:0, Mercs:0, TotalMercs:0})>>
		<<set $SatLaunched = 0>>
		<<set $SF.Facility = Object.assign({}, $SF.Facility, {Toggle:0, Active:0, LC:0, Workers:0, Max:5, Caps:"Special force support facility", Lower:"special force support facility", Decoration:"standard", Speed:0, Upgrade:0, IDs:[]})>>
		<</replace>> <</link>>
//Initial costs are @@.yellowgreen;<<print cashFormat(_price)>>@@ and upon establishment the force will have significant support costs until it is self-sufficient.//

<<link "The current measures are enough.""Next Week">> <<replace "#result">> <<run Object.assign(, $SF, {Active:0})>> <</replace>> <</link>>
<<elseif $SF.Active === 1>>
	<<include "Security Force Naming-Colonel">>
<<elseif $SF.Active !== -1 && passage() === "New Game Plus">>
		<<run Object.assign($SF, {Active:-1, Depravity:0, Units:0, MWU:0, U:0, WG:0, SpecOps:0, SpecOpsLock:0, ROE:"hold", Target:"recruit", Regs:"strict", Caps:"The Special Force", Lower:"the special force", Subsidy:1})>>
	<<set $SFUnit = Object.assign({}, $SFUnit, {Troops:40, Armoury:0, Firebase:0, AV:0, TV:0, Drones:0, Drugs:0, PGT:0, AA:0, TA:0, SpacePlane:0, GunS:0, Satellite:0, GiantRobot:0, MissileSilo:0, AircraftCarrier:0, Sub:0, HAT:0})>>
		<<set $SatLaunched = 0>>
	<<set $arcologies[0].SFRaid = 1,$arcologies[0].SFRaidTarget = -1>> <<set $SFColonel = Object.assign({}, $SFColonel, {Core:"", Talk:0, Fun:0, Status:0})>>
	<<set $SFTradeShow = Object.assign({}, $SFTradeShow, {History:0, CanAttend:0, Income:0, Revenue:0, Helots:0, TotalHelots:0, Mercs:0, TotalMercs:0})>>
	<<run Object.assign($SF.Facility, {Toggle:0, Active:0, LC:0, Workers:0, Max:5, Caps:"Special force support facility", Lower:"special force support facility", Decoration:"standard", Speed:0, Upgrade:0, IDs:[]})>>
<</if>>


code:
:: SF_Report [nobr]

<<silently>><<= Count()>>
<<if $SFUnit.Troops > 2000>> <<set $SFUnit.Troops = random(1955,1999)>> <</if>>
<<if $SFUnit.Troops < 100>> <<set $SFUnit.Troops += Math.ceil(random(2,5))>>
<<elseif $SFUnit.Troops < 2000>>
	<<if $SF.Target == "recruit">>
		<<set $SFUnit.Troops += Math.ceil(random(-1*$SFUnit.Troops/100,0))>>
	<<elseif $SF.Target == "raiding">>
		<<set $SFUnit.Troops += Math.ceil(random(-3*$SFUnit.Troops/100,-4*$SFUnit.Troops/100))>>
	<<else>>
		<<set $SFUnit.Troops += Math.ceil(random(-2*$SFUnit.Troops/100,-3*$SFUnit.Troops/100))>>
	<</if>>
<</if>>
<<set _SFIncome = 75000,_actionMultiplier = 1,_troopMultiplier = 1,_unitMultiplier = 1,_depravityMultiplier = 1,_SFupkeep = 0,_FNGs = 10,_Trade = 0.025>>
<<if $SF.SpecOps > 0>>
	<<if $SF.SpecOps === 1>> <<set $SFUC = Math.ceil($SFUnit.Troops*.1),$SFUnit.Troops-$SFUC>>
	<<else>> <<set $SFUC = Math.ceil($SFUnit.Troops*.25),$SFUnit.Troops-$SFUC>> <</if>>
<</if>>
<<if $SFUnit.Troops > 200>> <<set _Trade += 0.05*(Math.ceil($SFUnit.Troops/100))>>
	<<set _troopMultiplier = $SFUnit.Troops/200, _SFupkeep += $SFUnit.Troops*25>>
	<<if $secExp > 0>>
		<<set $authority += 25*(Math.ceil($SFUnit.Troops/200)),$authority = Math.clamp($authority, 0, 20000)>>
	<</if>>
<</if>>

<<if $SFUnit.Firebase > 0>>
	<<set _FNGs += $SFUnit.Firebase,_Trade += 0.5*$SFUnit.Firebase,_unitMultiplier += 7.5*$SFUnit.Firebase+2*Math.pow($SFUnit.Firebase,2),_SFupkeep += 500*(10+$SFUnit.Firebase)>>
<</if>>
<<if $SFUnit.Armoury > 0>>
	<<set _FNGs += (2*$SFUnit.Armoury),_Trade += 0.25*$SFUnit.Armoury,_unitMultiplier += 7.5*$SFUnit.Armoury+2*Math.pow($SFUnit.Armoury,2), _SFupkeep += 100*$SFUnit.Armoury>>
<</if>>
<<if $SFUnit.Drugs > 0>>
	<<set _FNGs += $SFUnit.Drugs,_Trade += 0.25*$SFUnit.Drugs,_unitMultiplier += 7.5*$SFUnit.Drugs+2*Math.pow($SFUnit.Drugs,2),_SFupkeep += 300*$SFUnit.Drugs>>
<</if>>
<<if $SFUnit.Firebase >= 1>>
	<<if $SFUnit.AV > 0>>
		<<set _FNGs += $SFUnit.AV,_Trade += 0.25*$SFUnit.AV,_unitMultiplier += 7.5*$SFUnit.AV+2*Math.pow($SFUnit.AV,2),_SFupkeep += 1000*$SFUnit.AV>>
	<</if>>
	<<if $SFUnit.TV > 0>>
		<<set _FNGs += $SFUnit.TV,_Trade += 0.25*$SFUnit.TV,_unitMultiplier += 7.5*$SFUnit.TV+2*Math.pow($SFUnit.TV,2), _SFupkeep += 800*$SFUnit.TV>>
	<</if>>
	<<if $SFUnit.PGT > 0>>
		<<set _Trade  += 0.25*($SFUnit.PGT),_unitMultiplier += 15*$SFUnit.PGT+3*Math.pow($SFUnit.PGT,2),_SFupkeep += 5000+1000*$SFUnit.PGT>>
	<</if>>
<</if>>
<<if $SFUnit.Firebase >= 2 && $SFUnit.Drones > 0>>
	<<set _FNGs += $SFUnit.Drones,_Trade += 0.5*$SFUnit.Drones,_unitMultiplier += 7.5*$SFUnit.Drones+2*Math.pow($SFUnit.Drones,2),_SFupkeep += 500*$SFUnit.Drones>>
<</if>>

<<if $SFUnit.Firebase >= 4>>
	<<if $SFUnit.AA > 0>>
		<<set _FNGs += $SFUnit.AA,_Trade += 0.25*$SFUnit.AA,_unitMultiplier += 7.5*$SFUnit.AA+2*Math.pow($SFUnit.AA,2),_SFupkeep += 1000*$SFUnit.AA>>
	<</if>>
	<<if $SFUnit.TA > 0>>
		<<set _FNGs += $SFUnit.TA,_Trade += 0.25*$SFUnit.TA,_unitMultiplier += 7.5*$SFUnit.TA+2*Math.pow($SFUnit.TA,2),_SFupkeep += 800*$SFUnit.TA>>
	<</if>>
	<<if $SFUnit.SpacePlane > 0>>
		<<set _FNGs += $SFUnit.SpacePlane,_Trade += 0.25*$SFUnit.SpacePlane,_unitMultiplier += 7.5*$SFUnit.SpacePlane+2*Math.pow($SFUnit.SpacePlane,2),_SFupkeep += 1000*$SFUnit.SpacePlane>>
	<</if>>
	<<if $SFUnit.GunS > 0>>
		<<set _FNGs += $SFUnit.GunS,_Trade  += 0.25*$SFUnit.GunS,_unitMultiplier += 12*$SFUnit.GunS+3*Math.pow($SFUnit.GunS,2),_SFupkeep += 3000+700*$SFUnit.GunS>>
	<</if>>
	<<if $SFUnit.Satellite > 0>>
		<<set _FNGs += $SFUnit.Satellite,_Trade  += 0.25*$SFUnit.Satellite,_unitMultiplier += 15*$SFUnit.Satellite+5*Math.pow($SFUnit.Satellite,2)>>
	<</if>>
	<<if $SFUnit.GiantRobot > 0>>
		<<set _FNGs += $SFUnit.GiantRobot,_Trade  += 0.25*$SFUnit.GiantRobot,_unitMultiplier += 15*$SFUnit.GiantRobot+5*Math.pow($SFUnit.GiantRobot,2),_SFupkeep += 10000+1500*$SFUnit.GiantRobot>>
	<</if>>
	<<if $SFUnit.MissileSilo > 0>>
		<<set _Trade += 0.25*$SFUnit.MissileSilo,_unitMultiplier += 15*$SFUnit.MissileSilo+5*Math.pow($SFUnit.MissileSilo,2),_SFupkeep += 1000*$SFUnit.MissileSilo>>
<</if>>
<</if>>

<<if $SFUnit.AircraftCarrier > 0>>
	<<set _FNGs += $SFUnit.AircraftCarrier,_Trade  += 0.25*$SFUnit.AircraftCarrier,_unitMultiplier += 9*$SFUnit.AircraftCarrier+3*Math.pow($SFUnit.AircraftCarrier,2),_SFupkeep += 800*$SFUnit.AircraftCarrier>>
<</if>>
<<if $SFUnit.Sub > 0>>
	<<set _FNGs += $SFUnit.Sub,_Trade  += 0.25*$SFUnit.Sub,_unitMultiplier += 7.5*$SFUnit.Sub+2*Math.pow($SFUnit.Sub,2),_SFupkeep += 900*$SFUnit.Sub>>
<</if>>
<<if $SFUnit.HAT > 0>>
	<<set _Trade += 0.25*$SFUnit.HAT,_unitMultiplier += 7.5*$SFUnit.HAT+2*Math.pow($SFUnit.HAT,2),_SFupkeep += 700*$SFUnit.HAT>>
<</if>>

<<set _SFD = $SF.Depravity>>
<<switch $SFColonel.Core>>
	<<case "kind">>
		<<set _FNGs += 10,_Trade += 0.15,_SFD -= 0.15>>
	<<case "cruel">>
		<<set _Trade -= 0.15,_SFD += 0.15>>
	<<case "brazen">>
		<<set _FNGs += 15,_unitMultiplier += 0.5>>
	<<case "jaded">>
		<<set _Trade -= 0.05,_SFD += 0.05>>
	<<case "shell shocked">>
		<<set _Trade += 0.05,_SFD -= 0.05,_unitMultiplier -= 0.5>>
<</switch>>
<<if $SF.Target == "raiding">> <<set _SFD += 0.05,_actionMultiplier += 0.5>>
<<elseif $SF.Target == "secure">> <<set _SFD -= 0.05,_actionMultiplier += 0.2>>
<<else>><<set _SFD -= 0.1,_actionMultiplier -= 0.5>><</if>>
<<if $SF.ROE == "free">> <<set _actionMultiplier *= 0.8,_SFD += 0.05,_Trade += _Trade*.95>>
<<elseif $SF.ROE == "hold">> <<set _actionMultiplier *= 1.1,_SFD -= 0.05,_Trade += _Trade*1.05>> <</if>>
<<if $SF.Regs == "none">> <<set _actionMultiplier *= 0.8,_SFD += 0.05,_Trade += _Trade*.95>>
<<elseif $SF.Regs == "strict">> <<set _actionMultiplier *= 1.1,_SFD -= 0.05,_Trade += _Trade*1.05>> <</if>>
<<set _depravityMultiplier = 1+_SFD>>
<<if _SFD != 0>>
<<set _Trade *= 1+_SFD/2>><</if>>

<<if $SF.Target == "recruit">> <<set _FNGs += Math.ceil((_FNGs)*.95)>>
<<else>> <<set _FNGs += Math.ceil((_FNGs)*.25)>> <</if>>
<<if $SF.Target == "secure">> <<set $rep += Math.ceil($rep*((_Trade/100)*.95))>>
	<<set $arcologies[0].prosperity = Math.ceil(($arcologies[0].prosperity+(_Trade/10)*.95))>>
<<else>> <<set $rep += Math.ceil($rep*((_Trade/100)*.25))>>
	<<set $arcologies[0].prosperity = Math.ceil(($arcologies[0].prosperity+(_Trade/10)*.25))>>
<</if>>
<<if $secExp > 0>> <<set $authority += $SF.Units*10,$authority = Math.clamp($authority, 0, 20000)>> <</if>>

<<set _SFIncome = Math.ceil(_SFIncome*_troopMultiplier*_unitMultiplier*_actionMultiplier*_depravityMultiplier-_SFupkeep),$SFUnit.Troops += Math.round(_FNGs/2)>>
/*Remove below line if hard mode ever gets fixed*/
<<if $economy < 100>><<set _SFIncome = Math.ceil(_SFIncome*(1+($week/10)))>><</if>>
<<if $SFUnit.Troops > 2000>> <<set $SFUnit.Troops = random(1955,1999)>> <</if>>
<<if $rep > 20000>> <<set $rep = 20000>> <</if>>
<<if $arcologies[0].prosperity > $AProsperityCap>>
	<<set $arcologies[0].prosperity = $AProsperityCap>> <</if>>
<<if _SFIncome >= 100000>>
	<<set _Profitable = 1,$SF.Subsidy = 0,$cash += _SFIncome>>
<<else>> <<set _Profitable = 0>> <</if>>

<<if $SFUnit.Drugs >= 8 || $SFUnit.Drugs >= 10>> <<set _Deaths = 0,_SurvivalChance = 50>>
	<<if $SFUnit.Drugs >= 8>> <<set _SurvivalChance -= 5>> <<elseif $SFUnit.Drugs >= 10>>
		<<set _SurvivalChance += 5>> <</if>>
	<<if random(0,100) > _SurvivalChance>>
		<<set _Deaths = random(0,(($SFUnit.Drugs*2)+4))>> <</if>>
	<<if _Deaths > 0>> <<set $SFUnit.Troops -= _Deaths>> <</if>>
<</if>>
<</silently>>
__Status and Activities of $SF.Lower __:

This week, $SF.Lower focused their <<print commaNum($SFUnit.Troops)>> troops on
<<if $SF.Target == "recruit">>
recruiting and training more personnel. Smaller parties ventured out to protect the arcology's trade routes and strike targets of opportunity.
<<elseif $SF.Target == "secure">>
securing the trade routes between the arcology and the surrounding area. Smaller parties ventured out to strike targets of opportunity and process new recruits.
<<elseif $SF.Target == "raiding">>
locating and striking targets of opportunity, capturing both material loot and new slaves. Smaller parties secured the most important of the arcology's trade routes and processed new recruits.
<</if>>
<<if $SF.SpecOps > 0>>
A <<if $SF.SpecOps <2>>small<<else>>large<</if>> portion of the force was assigned as <<if $SF.SpecOps <2>>part<<else>>full<</if>> time undercover officers.<</if>>

<<if _Deaths > 0>>
<<print (_Deaths)>> soldiers fatally overdosed on the drug cocktail
	<<if $SFTradeShow.CanAttend === -1>>
		, The Colonel's much heavier than average drug use saves her from this side effect
	<</if>>.
<</if>>
These activities have, overall, @@.green;improved@@ your arcology's prosperity.
The goods procured by the $SF.Lower this week, after accounting for the spoils retained by individual soldiers were
<<if _Profitable>>
@@.green;more than sufficient@@ to cover expenses. Excess materiel and human assets totaling @@.yellowgreen;<<print cashFormat(_SFIncome)>>@@ (after liquidation) were transferred to your accounts.
<<else>>
@@.red;barely enough@@ to cover expenses. More growth will be needed to ensure profitability.
<</if>>
$SF.Caps managed to recruit <<print Math.round(_FNGs/2)>> new soldiers this week, and your reputation has @@.green;increased@@ through the improvement of trade security.

    //Your instructions to <<print SFC()>>://

      Deployment focus:
	 <<if $SF.Target == "recruit">> ''Recruiting and Training''<<elseif $SF.Target == "secure">> ''Securing Trade Routes''<<else>> ''Raiding and Slaving''<</if>>.
	<<link "Recruit and Train">> <<set $SF.Target = "recruit">>
		<<replace "#focus">> ''Recruiting and Training'' <</replace>> <</link>>
	| <<link "Secure Trade Routes">> <<set $SF.Target = "secure">>
		<<replace "#focus">> ''Securing Trade Routes'' <</replace>> <</link>>
	| <<link "Raiding and Slaving">> <<set $SF.Target = "raiding">>
		<<replace "#focus">> ''Raiding and Slaving'' <</replace>> <</link>>

      Rules of Engagement:
	 <<if $SF.ROE === "hold">> ''Hold Fire''<<elseif $SF.ROE === "limited">> ''Limited Fire''<<else>> ''Free Fire''<</if>>.
		<<link "Hold Fire">> <<set $SF.ROE = "hold">> <<replace "#roe">> ''Hold Fire''
			<</replace>> <</link>>
		| <<link "Limited Fire">> <<set $SF.ROE = "limited">> <<replace "#roe">>
			'Limited Fire'' <</replace>> <</link>>
		| <<link "Free Fire">> <<set $SF.ROE = "free">> <<replace "#roe">> ''Free Fire''
			<</replace>> <</link>>

      Accountability:
	 <<if $SF.Regs === "strict">> ''Strict Accountability''<<elseif $SF.Regs === "some">> ''Some Accountability''<<else>>''No Accountability''<</if>>.
		<<link "Strict Accountability">> <<set $SF.Regs = "strict">>
		<<replace "#accountability">> ''Strict Accountability'' <</replace>> <</link>>
		| <<link "Some Accountability">> <<set $SF.Regs = "some">>
			<<replace "#accountability">> ''Some Accountability'' <</replace>> <</link>>
		| <<link "No Accountability">> <<set $SF.Regs = "none">>
		<<replace "#accountability">> ''No Accountability'' <</replace>> <</link>>
<<if $SFTradeShow.View > 0 && $SFTradeShow.CanAttend === 1>>
''TradeShow'':
	<<set $SFTradeShow.Income = 0,$SFTradeShow.Helots = 0>>
	<<set _TradeShowAttendes = 200,_MenialSlavesPerAttendee = 5>>
	<<set _MenialSlaves = Math.ceil(random(1,((_TradeShowAttendes*_MenialSlavesPerAttendee)/10)))>>
	<<set _TSProfit = Math.ceil(500000*(1+($SF.Units/1000))*(1+($arcologies[0].prosperity/1000))*_Env)>>
	During a break, The Colonel managed to sell some generic schematics to the _TradeShowAttendes  attendes, some decided to also give her some menial slaves as a bonus.

	<<set $helots = $helots+_MenialSlaves>>
	<<set $SFTradeShow.Helots += _MenialSlaves,$SFTradeShow.TotalHelots += _MenialSlaves>>
	<<set $cash = $cash+_TSProfit,$SFTradeShow.Income += _TSProfit>>
	<<set $SFTradeShow.Revenue += _TSProfit>>
	<<if $secExp > 0 && $mercenaries > 0>> <<set $SFTradeShow.Mercs = 0>>
		<<set _NewMercs = random(1,(_TradeShowAttendes/10))>>
		<<set $mercFreeManpower += _NewMercs,$SFTradeShow.TotalMercs += _NewMercs>>
		<<set $SFTradeShow.Mercs += _NewMercs>>
	<</if>> <<set $SFTradeShow.History += 1>>
<</if>><<if $SF.SpecOps === 1 && !$SF.SpecOpsLock>> <<set $SF.SpecOps = 0>> <</if>>
<<set $SF.U = 0,$SF.WG = 0,$SFColonel.Talk = 0,$SFColonel.Fun = 0>>


code:
:: Trick Shot Night  [nobr]

<<set $nextButton = "Continue", $nextLink = "RIE Eligibility Check", $returnTo = "RIE Eligibility Check">>

Despite your direct elevator, interaction with the majority of your security force is relatively scarce. Aside from mutually exchanged nods in the firebase and the occasional briefing, your $SF.Lower enjoy a degree of autonomy.

On a particularly lackadaisical evening, you find yourself alerted to a message alert by $assistantName.
<<if $assistant > 0>>
	"<<if def $PC.customTitle>>$PC.customTitle<<elseif $PC.title != 0>>Master<<else>>Mistress<</if>>, a message from $SF.Lower." She pauses before continuing. "It seems they're asking if you'd like to join their trick shot night."
<<else>>
	It informs you that $SF.Lower have sent a message asking you to join them at their trick shot night.
<</if>>

  <<link "Politely decline">>
	<<replace "#result">>
		You inform $SF.Lower that you aren't planning to attend. A short while later, you receive a message from them stating that their invitation is an open one and that you're welcome to join in another night.
	<</replace>>
<</link>>

<<if $cash < 500000>>

//You lack the necessary funds to attend.//
<<else>> /* cash >= 500000 */

<<link "Attend the trick shot night">>
	<<replace "#result">> <<set $PC.warfare += 1>>
		You instruct to $assistantName to inform $SF.Lower that you will be attending their trick shot night, and after settling your affairs in the penthouse you head down to the firebase. The atmosphere in the firebase is casual, especially in comparison to the usual situations you meet them, though your security force still maintain some measure of decorum towards you as their employer. Eventually, you settle in at the table with a handful of $SF.Lower officers and cash in your @@.yellowgreen;<<print cashFormat(500000)>>@@ into bullets. All that remains is to decide your strategy for the night.

	<<link "Play it safe">>
		<<replace "#bountyresult">>
			<<if random(1,100) > 50>>
			Despite your attempts to mitigate risk and play the safest shots possible, it seems lady luck has conspired against you this evening. However, even when your last bullet is shot, your security force pitch you a few bullets to keep you in the game for the rest of the night. You may have lost most of your ¤, but it seems you've @@.green;made some friends.@@
			<<set $rep += 1000, $cash -= 250000>>
			<<else>>
			While a careful eye for accuracy has buoyed you through the evening, ultimately lady luck is the decider in handing you the win in a number of close shots. Unfortunately your meticulous play limited your chance at a larger payout, and you only come away from the evening with @@.yellowgreen;<<print cashFormat(100000)>>@@ more than you arrived with and @@.green;the respect of your security force.@@
			<<set $rep += 1000, $cash += 100000>>
			<</if>>
		<</replace>>
	<</link>>

 <<link "Up the ante">>
		<<replace "#bountyresult">>
			Some aggressive play and an eye for riling up your fellow players has resulted in an immense payout, and all but one of your adversaries have folded as the situation has escalated. The only player still in contention is a wily old mercenary, the veteran of her fair share of battles on the battlefield and at the firing range. She's short on bullets, however, and she'll have to buy in with something else as collateral.

				<<link "A year of servitude">>
					<<replace "#aliveresult">>
						<<if random(1,100) > 50>>
						For all your skillful maneuvering to reach this position, ultimately the win comes down to chance. This time, however, luck was not on your side. As the victor sweeps up her spoils, the other security force clap you on the back and offer their condolences for your defeat. Though you may have lost your ¤, it seems you've @@.green;made some friends.@@
						<<set $rep += 1000, $cash -= 500000>>
						<<else>>
						For all your skillful maneuvering to reach this position, ultimately the win comes down to chance. This time, however, luck has rendered you the victor. A silence falls over the room as the result is declared, but after some time your opponent breaks the hush by joking that life as your slave is probably easier than fighting for $arcologies[0].name. After some awkward laughter the night continues, and at the end your former mercenary joins you on your trip back to the penthouse to submit to processing and to begin her new life as your sexual servant. She's not young, but she's tough and not distrusting of you due to her service in $SF.Lower.

						<<set $activeSlaveOneTimeMinAge = 25>>
						<<set $activeSlaveOneTimeMaxAge = 35>>
						<<set $one_time_age_overrides_pedo_mode = 1>>
						<<if $arcologies[0].FSSupremacistLawME == 1>><<set $fixedRace = $arcologies[0].FSSupremacistRace>><</if>>
						<<include "Generate XX Slave">>
						<<set $activeSlave.origin = "$He put herself up as collateral at a trick shot game, and lost.">>
						<<set $activeSlave.career = "a soldier">>
						<<set $activeSlave.indentureRestrictions = 2>>
						<<set $activeSlave.indenture = 52>>
						<<if $activeSlave.eyes == -2>>
							<<set $activeSlave.eyes = -1>>
						<</if>>
						<<set $activeSlave.devotion = random(45,60)>>
						<<set $activeSlave.trust = random(55,65)>>
						<<set $activeSlave.health = random(60,80)>>
						<<set $activeSlave.muscles = 60>>
						<<if $activeSlave.weight > 130>>
							<<set $activeSlave.weight -= 100>>
							<<set $activeSlave.waist = random(-10,50)>>
						<</if>>
						<<set $activeSlave.anus = 0>>
						<<set $activeSlave.analSkill = 0>>
						<<set $activeSlave.whoreSkill = 0>>
						<<set $activeSlave.combatSkill = 1>>
						<<set $activeSlave.behavioralFlaw = "arrogant">>
						<<set $activeSlave.hStyle = "buzzcut">>
						<<include "New Slave Intro">>
						<</if>>
					<</replace>>
				<</link>>

 <<link "Dock her wages">>
					<<replace "#aliveresult">>
						<<if random(1,100) > 50>>
						For all your skillful maneuvering to reach this position, ultimately the win comes down to chance. This time, however, luck was not on your side. As the victor sweeps up her spoils, the other security force members clap you on the back and offer their condolences for your defeat. Though you may have lost your ¤, it seems you've @@.green;made some friends.@@
						<<set $rep += 1000, $cash -= 500000>>
						<<else>>
						For all your skillful maneuvering to reach this position, ultimately the win comes down to chance. This time, however, luck has rendered you the victor. Your opponent accepts her defeat with grace and jokes to her comrades that she'll be fighting in her underwear for the next few months, and their uproar of laughter fills the room. Though you take the lion's share of the ¤, your security force also @@.green;had a good time fraternizing with you.@@
						<<set $rep += 2000, $cash += 500000>>
						<</if>>
					<</replace>>
				<</link>>

		<</replace>>
	<</link>>

	<</replace>>
<</link>> // It will cost @@.yellowgreen;<<print cashFormat(500000)>>@@ to participate in the trick shot night.//
<</if>>


code:
:: Upgrades [nobr]

Total upgrade progress: <<print progress($SF.Units,_max)>>

	<<if $SF.MWU >= 1>>
Total multi week $SF.Lower upgrades: $SF.MWU <</if>>

	<<if $SF.U > 0 && $SF.MWU >= 0 && ($SF.Units !== _max)>>

[[Re-unlock upgrading.|Firebase][$SF.U = 0,$SF.MWU += 1,$cash -= Math.ceil(Math.abs($cash*.05*(1.25+($SF.Units/1000))))]]  @@.yellowgreen;<<print cashFormat(Math.ceil(Math.abs($cash*.05*(1.25+($SF.Units/1000)))))>><</if>>

	<<if ($SF.Units < 30 || $SF.Units !== _max) && $SF.U < 1>> <<set _T1 = $SF.Units >= 30>>

Which facility or equipment do you wish to upgrade this week?

		<<if $SFUnit.Firebase < 5||_T1 && $SFUnit.Firebase < _FU>>

			<<set _cF = Math.ceil(100000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.Firebase/100)))>>

			<<if $cash >= _cF>>

				<<link "Upgrade Firebase">> <<set $SF.U = 1, $SFUnit.Firebase++, $cash -= _cF>><<goto "Firebase">><</link>>

			<<else>>//Cannot afford to upgrade the Firebase.//<</if>>

			 //Costs @@.yellowgreen;<<print cashFormat(_cF)>>@@ //

		<<elseif $SFUnit.Firebase == _FU>>//The Firebase has been fully upgraded.//

		<<else>>//More upgrades are required to unlock the next tier.//

		<</if>>	 <<print progress($SFUnit.Firebase)>>

		<<if $SFUnit.Armoury < 5||_T1 && $SFUnit.Armoury < _AU>>

			<<set _cA = Math.ceil(40000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.Armoury/100)))>>

			<<if $cash >= _cA>>

				<<link "Upgrade Armory">> <<set $SF.U = 1, $SFUnit.Armoury++, $cash -= _cA>> <<goto "Firebase">><</link>>

			<<else>>//Cannot afford to upgrade the Armory.//<</if>>

			 //Costs @@.yellowgreen;<<print cashFormat(_cA)>>@@ //

		<<elseif $SFUnit.Armoury == _AU>>//The Armory has been fully upgraded.//

		<<else>>//More upgrades are required to unlock the next tier.//

		<</if>>  <<print progress($SFUnit.Armoury)>>

		<<if $SFUnit.Drugs < 5||_T1 && $SFUnit.Drugs < _DrugsU>>

			<<set _cDrugs = Math.ceil(40000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.Drugs/100)))>>

			<<if $cash >= _cDrugs>>

				<<link "Upgrade Drug Lab">><<set $SF.U = 1, $SFUnit.Drugs++, $cash -= _cDrugs>> <<goto "Firebase">><</link>>

			<<else>>//Cannot afford to upgrade the Drug Lab.//<</if>>

			 //Costs @@.yellowgreen;<<print cashFormat(_cDrugs)>>@@ //

		<<elseif $SFUnit.Drugs == _DrugsU>>//The Drug Lab has been fully upgraded.//

		<<else>>//More upgrades are required to unlock the next tier.//

		<</if>>	 <<print progress($SFUnit.Drugs)>>

		<<if $SFUnit.Firebase >= 2 && ($SFUnit.Drones < 5 ||_T1 && $SFUnit.Drones < _DU)>>

			<<set _cDrones = Math.ceil(45000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.Drones/100))*HSM())>>

			<<if $cash >= _cDrones>>

				<<link "Upgrade Drone Bay">><<set $SF.U = 1, $SFUnit.Drones++, $cash -= _cDrones>> <<goto "Firebase">>	<</link>>

			<<else>>//Cannot afford to upgrade the Drone Bay.//<</if>>

			 //Costs @@.yellowgreen;<<print cashFormat(Math.ceil(45000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.Drones/100))*HSM()))>>@@ //  <<print progress($SFUnit.Drones)>>

		<<elseif $SFUnit.Drones == _DU>>//The Drone Bay has been fully upgraded.// <<print progress($SFUnit.Drones)>>

		<<elseif _T1 && $SFUnit.Drones == 5>>//More upgrades are required to unlock the next tier.// <<print progress($SFUnit.Drones)>> <</if>>

		<<if $SFUnit.Firebase >= 1 && $terrain !== "oceanic">>
''Garage''

<<if ($SFUnit.AV < 5||_T1 && $SFUnit.AV < _AVU)>>

				<<set _cAV = Math.ceil(60000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.AV/100)))>>

				<<if $cash >= _cAV>>

					<<link "Upgrade Attack Vehicle Fleet">><<set $SF.U = 1, $SFUnit.AV++, $cash -= _cAV>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade the Attack Vehicle Fleet.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cAV)>>@@//<<print progress($SFUnit.AV)>>

			<<elseif $SFUnit.AV == _AVU>>//The Attack Vehicle Fleet has been fully upgraded.//<<print progress($SFUnit.AV)>>

			<<else>>//More upgrades are required to unlock the next tier.//<<print progress($SFUnit.AV)>>

			<</if>>

<<if ($SFUnit.TV < 5||_T1 && $SFUnit.TV < _TVU)>>

				<<set _cTV = Math.ceil(60000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.TV/100)))>>

				<<if $cash >= _cTV>>

					<<link "Upgrade Transport Vehicle Fleet">><<set $SF.U = 1, $SFUnit.TV++, $cash -= _cTV>><<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Transport Vehicle Fleet.//<</if>>

					 //Costs @@.yellowgreen;<<print cashFormat(_cTV)>>@@//<<print progress($SFUnit.TV)>>

			<<elseif $SFUnit.TV == _TVU>>//The Transport Vehicle Fleet has been fully upgraded.//<<print progress($SFUnit.TV)>>

			<<else>>//More upgrades are required to unlock the next tier.// <<print progress($SFUnit.TV)>> <</if>>

<<if _T1 && $SFUnit.PGT < _PGTU>>

				<<set _cPGT = Math.ceil(735000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.PGT/100)))>>

				<<if $cash >= _cPGT>>

					<<link "Upgrade Prototype Goliath tank">><<set $SF.U = 1, $SFUnit.PGT++, $cash -= _cPGT>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Prototype Goliath Tank.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cPGT)>>@@ // <<print progress($SFUnit.PGT)>>

			<<elseif $SFUnit.PGT == _PGTU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.PGT)>>

			<<elseif $SFUnit.PGT == _PGTU>>//The Prototype Goliath Tank has been fully upgraded.// <<print progress($SFUnit.PGT)>> <</if>>
<</if>>

		<<if $SFUnit.Firebase >= 4>>''Hangar''

<<if $SFUnit.AA < 5||_T1 && $SFUnit.AA < _AAU>>

				<<set _cAA = Math.ceil(70000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.AA/100)))>>

				<<if $cash >= _cAA>>

					<<link "Upgrade Attack Aircraft Fleet">><<set $SF.U = 1, $SFUnit.AA++, $cash -= _cAA>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Attack Aircraft Fleet.//<</if>>

			 //Costs @@.yellowgreen;<<print cashFormat(_cAA)>>@@ // <<print progress($SFUnit.AA)>>

			<<elseif $SFUnit.AA == _AAU>>//The Attack Aircraft Fleet has been fully upgraded.// <<print progress($SFUnit.AA)>>

			<<else>>//More upgrades are required to unlock the next tier.// <<print progress($SFUnit.AA)>> <</if>>

<<if $SFUnit.TA < 5||_T1 && $SFUnit.TA < _TAU>>

				<<set _cTA = Math.ceil(70000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.TA/100)))>>

				<<if $cash >= _cTA>>

					<<link "Upgrade Transport Aircraft Fleet">><<set $SF.U = 1, $SFUnit.TA++, $cash -= _cTA>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade the Transport Aircraft Fleet.//<</if>>

				//Costs @@.yellowgreen;<<print cashFormat(_cTA)>>@@ // <<print progress($SFUnit.TA)>>

			<<elseif $SFUnit.TA == _TAU>>//The Transport Aircraft Fleet has been fully upgraded.// <<print progress($SFUnit.TA)>>

			<<else>>//More upgrades are required to unlock the next tier.// <<print progress($SFUnit.TA)>> <</if>>

<<if _T1 && $SFUnit.SpacePlane < _SPU>>

				<<set _cSP = Math.ceil(250000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.SpacePlane/100))*HSM())>>

				<<if $cash >= _cSP>>

					<<link "Upgrade Spaceplane">><<set $SF.U = 1, $SFUnit.SpacePlane++, $cash -= _cSP>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade the Spaceplane.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cSP)>>@@//<<print progress($SFUnit.SpacePlane)>>

			<<elseif $SFUnit.SpacePlane == _SPU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.SpacePlane)>>

			<<elseif $SFUnit.SpacePlane == _SPU>>//The Spaceplane has been fully upgraded.// <<print progress($SFUnit.SpacePlane)>> <</if>>

<<if _T1 && $SFUnit.GunS < _GunSU>>

				<<set _cGunS = Math.ceil(350000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.GunS/100))*HSM())>>

				<<if $cash >= _cGunS>>

					<<link "Upgrade Gunship">><<set $SF.U = 1, $SFUnit.GunS++, $cash -= _cGunS>><<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Gunship.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cGunS)>>@@ // <<print progress($SFUnit.GunS)>>

			<<elseif $SFUnit.GunS == _GunSU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.GunS)>>

			<<elseif $SFUnit.GunS == _GunSU>>//The Gunship has been fully upgraded.// <<print progress($SFUnit.GunS)>> <</if>>
<</if>>

		<<if _T1>>''Launch Bay''

<<if $SFUnit.Satellite < _SatU && $SatLaunched < 1>>

				<<set _cSat = Math.ceil(525000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.Satellite/100))*HSM())>>

				<<if $cash >= _cSat>>

					<<link "Upgrade Satellite">><<set $SF.U = 1, $SFUnit.Satellite++, $cash -= _cSat>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Satellite.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cSat)>>@@//<<print progress($SFUnit.Satellite)>>

			<<elseif $SFUnit.Satellite == _SatU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.Satellite)>>

			<<else>>//The Satellite has been fully upgraded.//<<print progress($SFUnit.Satellite)>><</if>>

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

<<if $SFUnit.GiantRobot < _GRU>>

				<<set _cGR = Math.ceil(550000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.GiantRobot/100))*HSM())>>

				<<if $cash >= _cGR>>

					<<link "Upgrade Giant Robot">><<set $SF.U = 1, $SFUnit.GiantRobot++, $cash -= _cGR>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade the Giant Robot.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cGR)>>@@//<<print progress($SFUnit.GiantRobot)>>

			<<elseif $SFUnit.GiantRobot == _GRU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.GiantRobot)>>

			<<else>>//The Giant Robot has been fully upgraded.// <<print progress($SFUnit.GiantRobot)>> <</if>>
<</if>>

<<if $SFUnit.MissileSilo < _MSU>>

				<<set _cMS = Math.ceil(565000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.MissileSilo/100))*HSM())>>

				<<if $cash >= _cMS>>

					<<link "Upgrade Cruise Missile">><<set $SF.U = 1, $SFUnit.MissileSilo++, $cash -= _cMS>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Cruise Missile.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cMS)>>@@ //<<print progress($SFUnit.MissileSilo)>>

			<<elseif $SFUnit.MissileSilo == _MSU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.MissileSilo)>>

			<<else>>//The Cruise Missile has been fully upgraded.// <<print progress($SFUnit.MissileSilo)>> <</if>>
<</if>>

		<<if _T1 && ($terrain == "oceanic" || $terrain == "marine")>>''Naval Yard''

<<if $SFUnit.AircraftCarrier < _ACU>>

				<<set _cAC = Math.ceil(650000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.AircraftCarrier/100))*HSM())>>

				<<if $cash >= _cAC>>

					<<link "Upgrade Aircraft Carrier">><<set $SF.U = 1, $SFUnit.AircraftCarrier++, $cash -= _cAC>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Aircraft Carrier.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(Math.ceil(650000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.AircraftCarrier/100))*HSM()))>>@@ // <<print progress($SFUnit.AircraftCarrier)>>

			<<elseif $SFUnit.AircraftCarrier == _ACU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.AircraftCarrier)>>

			<<else>>//The Aircraft Carrier has been fully upgraded.// <<print progress($SFUnit.AircraftCarrier)>> <</if>>

<<if $SFUnit.Sub < _SubU>>

				<<set _cSub = Math.ceil(700000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.Sub/100))*HSM())>>

				<<if $cash >= _cSub>>

					<<link "Upgrade Submarine">><<set $SF.U = 1, $SFUnit.Sub++, $cash -= _cSub>> <<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Submarine//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cSub)>>@@ // <<print progress($SFUnit.Sub)>>

			<<elseif $SFUnit.Sub == _SubU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.Sub)>>

			<<else>>//The Submarine has been fully upgraded.// <<print progress($SFUnit.Sub)>> <</if>>

<<if $SFUnit.HAT < _HATU>>

				<<set _cHAT = Math.ceil(665000*_Env*(1.15+($SF.Units/10))*(1.15+($SFUnit.HAT/100)))>>

				<<if $cash >= _cHAT>>

					<<link "Upgrade Amphibious Transport">><<set $SF.U = 1, $SFUnit.HAT++, $cash -= _cHAT>><<goto "Firebase">><</link>>

				<<else>>//Cannot afford to upgrade Amphibious Transport.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cHAT)>>@@ // <<print progress($SFUnit.HAT)>>

			<<elseif $SFUnit.HAT == _HATU && $PC.warfare < 75>>//Your warfare skill is not high enough unlock the next upgrade.// <<print progress($SFUnit.HAT)>>

			<<else>>//The Amphibious Transport has been fully upgraded.// <<print progress($SFUnit.HAT)>> <</if>>

		<</if>>

		<<if _T1 < 1>>//More firebase upgrades are required to unlock further upgrades.//<</if>>

	<</if>>

	/*
<<if _T1 && $SF.Facility.Toggle > 0 && $SF.Facility.Active < 1>>

				<<set _cSFF = Math.ceil(735000*_Env*(1.15+($SF.Units/10))*(1.15+($SF.Facility.Active/100)))>>

					<<if $cash >= _cSFF>>

						<<link "Build $SF.Lower's support facility">><<set $SF.U = 1, $SF.Facility.Active++, $cash -= _cSFF>><<goto "Firebase">><</link>>

					<<else>>//Cannot afford to build $SF.Lower's support facility.//<</if>>

				 //Costs @@.yellowgreen;<<print cashFormat(_cSFF)>>@@ //

				<</if>>*/