code:
:: unitsRebellionReport [nobr]

<<if $losses == 0>>
	<<if $irregulars > 0>>
		The volunteering citizens were quickly organized into an irregular militia unit and deployed in the arcology. No casualties suffered.
	<</if>>
	<<if App.SecExp.conflict.deployedUnits('bots') >= 1>>

		Security drones: no casualties suffered.
	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1>>

$SF.Lower, <<print num($SF.Squad.Troops)>> strong, was called to join the battle: no casualties suffered.
	<</if>>
	<<set _count = 0>>
	<<if $loyalID.length > 0>>

		<<for _i = 0; _i < $militiaUnits.length; _i++>>
			<<if $militiaUnits[_i].active == 1 && ($loyalID.includes($militiaUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $loyalID.length>>
					$militiaUnits[_i].platoonName,
				<<else>>
					$militiaUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $slaveUnits.length; _i++>>
			<<if $slaveUnits[_i].active == 1 && ($loyalID.includes($slaveUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $loyalID.length>>
					$slaveUnits[_i].platoonName,
				<<else>>
					$slaveUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $mercUnits.length; _i++>>
			<<if $mercUnits[_i].active == 1 && ($loyalID.includes($mercUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $loyalID.length>>
					$mercUnits[_i].platoonName,
				<<else>>
					$mercUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		participated in the battle without taking any casualties. They remained loyal until the end.
	<</if>>
	<<if $rebellingID.length > 0 && $battleResult != -1>>

		/* militia */
		<<set _militiaRebelledID = []>>
		<<set _militiaManpower = 0>>
		<<for _j = 0; _j < $militiaUnits.length; _j++>>
			<<if $militiaUnits[_j].active == 1 && $rebellingID.includes($militiaUnits[_j].ID)>>
				$militiaUnits[_j].platoonName,
				<<set _militiaRebelledID.push($militiaUnits[_j].ID)>>
				<<set _militiaManpower += Math.clamp($militiaUnits[_j].troops - random(_averageLosses),0,$militiaUnits[_j].troops)>>
			<</if>>
		<</for>>
		<<if _militiaRebelledID.length > 0>>
			had the gall to betray you and join your enemies.

<<link "Dissolve the units">>
					<<run removeUnits(_militiaRebelledID)>>
					<<set $militiaFreeManpower += _militiaManpower>>
					<<for _i = 0; _i < $militiaUnits.length; _i++>>
						<<if $militiaUnits[_i].active == 1>>
							<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty - random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#militiaResult">>

Units dissolved.
					<</replace>>
				<</link>>

//Manpower will be refunded, but will negatively influence the loyalty of the other units//

<<link "Purge the dissidents and dissolve the units">>
					<<run removeUnits(_militiaRebelledID)>>
					<<set $militiaFreeManpower += _militiaManpower * 0.5>>
					<<recalcManpower>>
					<<replace "#militiaResult">>

Dissidents purged and units dissolved.
					<</replace>>
				<</link>>

//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//

<<link "Execute them all">>
					<<run removeUnits(_militiaRebelledID)>>
					<<for _i = 0; _i < $militiaUnits.length; _i++>>
						<<if $militiaUnits[_i].active == 1>>
							<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty + random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#militiaResult">>

Units executed. Dissent will not be tolerated.
					<</replace>>
				<</link>>

//Will positively influence the loyalty of the other units, but no manpower will be refunded.//

		<</if>>

		/* slaves */
		<<set _slaveRebelledID = []>>
		<<set _slaveManpower = 0>>

		<<for _j = 0; _j < $slaveUnits.length; _j++>>
			<<if $slaveUnits[_j].active == 1 && $rebellingID.includes($slaveUnits[_j].ID)>>
				$slaveUnits[_j].platoonName,
				<<set _slaveRebelledID.push($slaveUnits[_j].ID)>>
				<<set _slaveManpower += Math.clamp($slaveUnits[_j].troops - random(_averageLosses),0,$slaveUnits[_j].troops)>>
			<</if>>
		<</for>>
		<<if _slaveRebelledID.length > 0>>
			decided in their blind arrogance to betray you.

<<link "Dissolve the units">>
					<<run removeUnits(_slaveRebelledID)>>
					<<set $menials += _slaveManpower>>
					<<for _i = 0; _i < $slaveUnits.length; _i++>>
						<<if $slaveUnits[_i].active == 1>>
							<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty - random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#slaveResult">>

Units dissolved.
					<</replace>>
				<</link>>

//Manpower will be refunded, but will negatively influence the loyalty of the other units//

<<link "Purge the dissidents and dissolve the units">>
					<<run removeUnits(_slaveRebelledID)>>
					<<set $menials += _slaveManpower * 0.5>>
					<<recalcManpower>>
					<<replace "#slaveResult">>

Dissidents purged and units dissolved.
					<</replace>>
				<</link>>

//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//

<<link "Execute them all">>
					<<run removeUnits(_slaveRebelledID)>>
					<<for _i = 0; _i < $slaveUnits.length; _i++>>
						<<if $slaveUnits[_i].active == 1>>
							<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty + random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#slaveResult">>

Units executed. Dissent will not be tolerated.
					<</replace>>
				<</link>>

//Will positively influence the loyalty of the other units, but no manpower will be refunded.//

		<</if>>

		/* mercs */
		<<set _mercRebelledID = []>>
		<<set _mercManpower = 0>>

		<<for _j = 0; _j < $mercUnits.length; _j++>>
			<<if $mercUnits[_j].active == 1 && $rebellingID.includes($mercUnits[_j].ID)>>
				$mercUnits[_j].platoonName,
				<<set _mercRebelledID.push($mercUnits[_j].ID)>>
				<<set _mercManpower += Math.clamp($mercUnits[_j].troops - random(_averageLosses),0,$mercUnits[_j].troops)>>
			<</if>>
		<</for>>
		<<if _mercRebelledID.length > 0>>
			made the grave mistake of betraying you.

<<link "Dissolve the units">>
					<<run removeUnits(_mercRebelledID)>>
					<<set $mercFreeManpower += _mercManpower>>
					<<for _i = 0; _i < $mercUnits.length; _i++>>
						<<if $mercUnits[_i].active == 1>>
							<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty - random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#mercResult">>

Units dissolved.
					<</replace>>
				<</link>>

//Manpower will be refunded, but will negatively influence the loyalty of the other units//

<<link "Purge the dissidents and dissolve the units">>
					<<run removeUnits(_mercRebelledID)>>
					<<set $mercFreeManpower += _mercManpower * 0.5>>
					<<recalcManpower>>
					<<replace "#mercResult">>

Dissidents purged and units dissolved.
					<</replace>>
				<</link>>

//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//

<<link "Execute them all">>
					<<run removeUnits(_mercRebelledID)>>
					<<for _i = 0; _i < $mercUnits.length; _i++>>
						<<if $mercUnits[_i].active == 1>>
							<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty + random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#mercResult">>

Units executed. Dissent will not be tolerated.
					<</replace>>
				<</link>>

//Will positively influence the loyalty of the other units, but no manpower will be refunded.//

		<</if>>
	<<elseif $rebellingID.length > 0>>
		<<set _militiaRebelledID = []>>
		<<for _j = 0; _j < $militiaUnits.length; _j++>>
			<<if $militiaUnits[_j].active == 1 && $rebellingID.includes($militiaUnits[_j].ID)>>
				<<set _militiaRebelledID.push($militiaUnits[_j].ID)>>
				$militiaUnits[_j].platoonName,
			<</if>>
		<</for>>
		<<if _militiaRebelledID.length > 0>>
			had the gall to betray you and join your enemies. They participated in the looting following the rebellion, then vanished in the wastes.
		<</if>>
		<<run cashX(forceNeg(1000 * _militiaRebelledID.length), "war")>>

		<<run removeUnits(_militiaRebelledID)>>
		<<set _slaveRebelledID = []>>
		<<for _j = 0; _j < $slaveUnits.length; _j++>>
			<<if $slaveUnits[_j].active == 1 && $rebellingID.includes($slaveUnits[_j].ID)>>
				<<set _slaveRebelledID.push($slaveUnits[_j].ID)>>
				$slaveUnits[_j].platoonName,
			<</if>>
		<</for>>
		<<if _slaveRebelledID.length > 0>>
			decided in their blind arrogance to betray you. They participated in the looting following the rebellion, then vanished in the wastes.
		<</if>>
		<<run cashX(forceNeg(1000 * _slaveRebelledID.length), "war")>>
		<<run removeUnits(_slaveRebelledID)>>

		<<set _mercRebelledID = []>>
		<<set _count = 0>>
		<<for _j = 0; _j < $mercUnits.length; _j++>>
			<<if $mercUnits[_j].active == 1 && $rebellingID.includes($mercUnits[_j].ID)>>
				<<set _mercRebelledID.push($mercUnits[_j].ID)>>
				<<set _count++>>
				$mercUnits[_j].platoonName,
			<</if>>
		<</for>>
		<<if _mercRebelledID.length > 0>>
			made the grave mistake of betraying you. They participated in the looting following the rebellion, then vanished in the wastes.
		<</if>>
		<<run cashX(forceNeg(1000 * _mercRebelledID.length), "war")>>
		<<run removeUnits(_mercRebelledID)>>
		<<recalcManpower>>
	<</if>>

<<elseif $losses > 0>>
	/* if the losses are more than zero */
	/* generates a list of randomized losses, from which each unit picks one at random */
	<<set _averageLosses = Math.trunc($losses / App.SecExp.conflict.deployedUnits())>>
	<<set _lossesList = []>>
	<<for _i = 0; _i < App.SecExp.conflict.deployedUnits(); _i++>>
		<<set _assignedLosses = Math.trunc(Math.clamp(_averageLosses + random(-5,5), 0, 100))>>
		<<if _assignedLosses > $losses>>
			<<set _assignedLosses = $losses>>
			<<set $losses = 0>>
		<<else>>
			<<set $losses -= _assignedLosses>>
		<</if>>
		<<set _lossesList.push(_assignedLosses)>>
	<</for>>
	<<if $losses > 0>>
		<<set _lossesList[random(_lossesList.length - 1)] += $losses>>
	<</if>>
	<<set _lossesList.shuffle()>>

	/* sanity check for losses */
	<<set _count = 0>>
	<<for _i = 0; _i < _lossesList.length; _i++>>
		<<if !Number.isInteger(_lossesList[_i])>>
			<<set _lossesList[_i] = 0>>
		<</if>>
		<<set _count += _lossesList[_i]>>
	<</for>>
	<<if _count < $losses>>
		<<set _rand = random(_lossesList.length - 1)>>
		<<set _lossesList[_rand] += $losses - _count>>
	<<elseif _count > $losses>>
		<<set _diff = _count - $losses>>
		<<set _rand = random(_lossesList.length - 1)>>
		<<set _lossesList[_rand] = Math.trunc(_lossesList[_rand]-_diff,0,100)>>
	<</if>>

	/* assigns the losses and notify the player */
	<<if $irregulars > 0>>

		<<set _loss = _lossesList.pluck()>>
		<<if _loss > $ACitizens * 0.95>>
			<<set _loss = Math.trunc($ACitizens * 0.95)>> /* this is unlikely to happen, but might as well be safe*/
		<</if>>
		The volunteering citizens were quickly organized into an irregular militia unit and deployed in the arcology:
		<<if _loss <= 0>>
			no casualties
		<<elseif _loss <= 10>>
			light casualties
		<<elseif _loss <= 30>>
			moderate casualties
		<<elseif _loss <= 60>>
			heavy casualties
		<<else>>
			catastrophic casualties
		<</if>>
		suffered.
		<<if _loss > $lowerClass * 0.95>> /*I suspect only lower class ever get to fight/die, but being safe*/
			<<set $lowerClass = Math.trunc($lowerClass * 0.05),
			_loss -= Math.trunc($lowerClass * 0.95)>>
			<<if _loss > $middleClass * 0.95>>
				<<set $middleClass = Math.trunc($middleClass * 0.05),
				_loss -= Math.trunc($middleClass *0.95)>>
				<<if _loss > $upperClass * 0.95>>
					<<set $upperClass = Math.trunc($upperClass * 0.05),
					_loss -= Math.trunc($upperClass * 0.95)>>
					<<if _loss > $topClass * 0.95>>
						<<set $topClass = Math.trunc($topClass * 0.05)>>
					<<else>>
						<<set $topClass -= _loss>>
					<</if>>
				<<else>>
					<<set $upperClass -= _loss>>
				<</if>>
			<<else>>
				<<set $middleClass -= _loss>>
			<</if>>
		<<else>>
			<<set $lowerClass -= _loss>>
		<</if>>
	<</if>>
	<<if $secBots.active == 1>>

		<<set _loss = _lossesList.pluck()>>
		<<set _loss = Math.clamp(_loss,0,$secBots.troops)>>
		<<set $secBots.troops -= _loss>>
		Security drones:
		<<if _loss <= 0>>
			no casualties
		<<elseif _loss <= 10>>
			light casualties
		<<elseif _loss <= 30>>
			moderate casualties
		<<elseif _loss <= 60>>
			heavy casualties
		<<else>>
			catastrophic casualties
		<</if>>
		suffered.
		<<if $secBots.troops <= 0>>
			<<set $secBots.active = 0>>
			Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. It will take quite the investment to rebuild them.
		<<elseif $secBots.troops <= 10>>
			The unit has very few operatives left, it risks complete annihilation if deployed again.
		<</if>>
	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1>>

		<<set _loss = _lossesList.pluck()>>
		<<set _loss = Math.clamp(_loss,0,$SF.Squad.Troops)>>
		$SF.Lower, $SF.Squad.Troops strong, is called to join the battle:
		<<set $SF.Squad.Troops -= _loss>>
		<<if _loss <= 0>>
			no casualties
		<<elseif _loss <= 10>>
			light casualties
		<<elseif _loss <= 30>>
			moderate casualties
		<<elseif _loss <= 60>>
			heavy casualties
		<<else>>
			catastrophic casualties
		<</if>>
		suffered.
	<</if>>
	<<if App.SecExp.conflict.deployedUnits('militia') >= 1>>
		<<for _j = 0; _j < $militiaUnits.length; _j++>>
			<<if $militiaUnits[_j].active == 1 && $loyalID.includes($militiaUnits[_j].ID)>>

				<<set $militiaUnits[_j].battlesFought++>>
				<<set _loss = _lossesList.pluck()>>
				<<set _loss = Math.clamp(_loss,0,$militiaUnits[_j].troops)>>
				$militiaUnits[_j].platoonName participated in the battle. They remained loyal to you.
				<<if _loss <= 0>>
					No casualties
				<<elseif _loss <= $militiaUnits[_j].troops * 0.2>>
					Light casualties
				<<elseif _loss <= $militiaUnits[_j].troops * 0.4>>
					Moderate casualties
				<<elseif _loss <= $militiaUnits[_j].troops * 0.6>>
					Heavy casualties
				<<else>>
					Catastrophic casualties
				<</if>>
				suffered.
				<<set _med = Math.round(Math.clamp(_loss * $militiaUnits[_j].medics * 0.25,1,_loss))>>
				<<if $militiaUnits[_j].medics == 1 && _loss > 0>>
					Some men were saved by their medics.
				<</if>>
				<<set $militiaUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$militiaUnits[_j].maxTroops))>>
				<<set $militiaEmployedManpower -= Math.trunc(_loss - _med)>>
				<<set $militiaTotalCasualties += Math.trunc(_loss - _med)>>
				<<set $militiaTotalManpower -= Math.trunc(_loss - _med)>>
				<<if $militiaUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience has increased.
						<<set $militiaUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
				<<if $militiaUnits[_j].troops <= 0>>
					<<set $militiaUnits[_j].active = 0>>

Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The remnants will be sent home honored as veterans or reorganized in a new unit.
				<<elseif $militiaUnits[_j].troops <= 10>>

The unit has very few operatives left, it risks complete annihilation if deployed again.
				<</if>>
			<</if>>
		<</for>>
	<</if>>
	<<if App.SecExp.conflict.deployedUnits('slaves') >= 1>>
		<<set _med = 0>>
		<<for _j = 0; _j < $slaveUnits.length; _j++>>
			<<if $slaveUnits[_j].active == 1 && $loyalID.includes($slaveUnits[_j].ID)>>

				<<set $slaveUnits[_j].battlesFought++>>
				<<set _loss = _lossesList.pluck()>>
				<<if !(Number.isInteger(_loss))>>

@@.red;Error: failed to assign losses, input was negative or NaN@@
					<<break>>
				<</if>>
				<<set _loss = Math.clamp(_loss,0,$slaveUnits[_j].troops)>>
				$slaveUnits[_j].platoonName participated in the battle. They remained loyal to you.
				<<if _loss <= 0>>
					No casualties
				<<elseif _loss <= $slaveUnits[_j].troops * 0.2>>
					Light casualties
				<<elseif _loss <= $slaveUnits[_j].troops * 0.4>>
					Moderate casualties
				<<elseif _loss <= $slaveUnits[_j].troops * 0.6>>
					Heavy casualties
				<<else>>
					Catastrophic casualties
				<</if>>
				suffered.
				<<set _med = Math.round(Math.clamp(_loss * $slaveUnits[_j].medics * 0.25,1,_loss))>>
				<<if $slaveUnits[_j].medics == 1 && _loss > 0>>
					Some men were saved by their medics.
				<</if>>
				<<set $slaveUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$slaveUnits[_j].maxTroops))>>
				<<set $slavesEmployedManpower -= _loss - _med>>
				<<set $slavesTotalCasualties += _loss - _med>>
				<<set $menials -= Math.trunc(_loss - _med)>>
				<<if $slaveUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience gained.
						<<set $slaveUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
				<<if $slaveUnits[_j].troops <= 0>>
					<<set $slaveUnits[_j].active = 0>>

Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The survivors will be sent home honored as veterans or reorganized in a new unit.
				<<elseif $slaveUnits[_j].troops <= 10>>

The unit has very few operatives left, it risks complete annihilation if deployed again.
				<</if>>
			<</if>>
		<</for>>
	<</if>>
	<<if App.SecExp.conflict.deployedUnits('mercs') >= 1>>
		<<for _j = 0; _j < $mercUnits.length; _j++>>
			<<if $mercUnits[_j].active == 1 && $loyalID.includes($mercUnits[_j].ID)>>

				<<set $mercUnits[_j].battlesFought++>>
				<<set _loss = _lossesList.pluck()>>
				<<set _loss = Math.clamp(_loss,0,$mercUnits[_j].troops)>>
				$mercUnits[_j].platoonName participated in the battle. They remained loyal to you.
				<<if _loss <= 0>>
					No casualties
				<<elseif _loss <= $mercUnits[_j].troops * 0.2>>
					Light casualties
				<<elseif _loss <= $mercUnits[_j].troops * 0.4>>
					Moderate casualties
				<<elseif _loss <= $mercUnits[_j].troops * 0.6>>
					Heavy casualties
				<<else>>
					Catastrophic casualties
				<</if>>
				suffered.
				<<set _med = Math.round(Math.clamp(_loss * $mercUnits[_j].medics * 0.25,1,_loss))>>
				<<if $mercUnits[_j].medics == 1 && _loss > 0>>
					Some men were saved by their medics.
				<</if>>
				<<set $mercUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$mercUnits[_j].maxTroops))>>
				<<set $mercEmployedManpower -= Math.trunc(_loss - _med)>>
				<<set $mercTotalCasualties += Math.trunc(_loss - _med)>>
				<<set $mercTotalManpower -= Math.trunc(_loss - _med)>>
				<<if $mercUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience gained.
						<<set $mercUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
				<<if $mercUnits[_j].troops <= 0>>
					<<set $mercUnits[_j].active = 0>>

Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The remnants will be sent home honored as veterans or reorganized in a new unit.
				<<elseif $mercUnits[_j].troops <= 10>>

The unit has very few operatives left, it risks complete annihilation if deployed again.
				<</if>>
			<</if>>
		<</for>>
	<</if>>

	<<if $rebellingID.length > 0 && $battleResult >= 2>>
		/* win */
		/* militia */
		<<set _militiaRebelledID = []>>
		<<set _militiaManpower = 0>>
		<<for _j = 0; _j < $militiaUnits.length; _j++>>
			<<if $militiaUnits[_j].active == 1 && $rebellingID.includes($militiaUnits[_j].ID)>>
				$militiaUnits[_j].platoonName,
				<<set _militiaRebelledID.push($militiaUnits[_j].ID)>>
				<<set _militiaManpower += Math.clamp($militiaUnits[_j].troops - random(_averageLosses),0,$militiaUnits[_j].troops)>>
			<</if>>
		<</for>>
		<<if _militiaRebelledID.length > 0>>
			had the gall to betray you and join your enemies.

<<link "Dissolve the units">>
					<<run removeUnits(_militiaRebelledID)>>
					<<set $militiaFreeManpower += _militiaManpower>>
					<<for _i = 0; _i < $militiaUnits.length; _i++>>
						<<if $militiaUnits[_i].active == 1>>
							<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty - random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#militiaResult">>

Units dissolved.
					<</replace>>
				<</link>>

//Manpower will be refunded, but will negatively influence the loyalty of the other units//

<<link "Purge the dissidents and dissolve the units">>
					<<run removeUnits(_militiaRebelledID)>>
					<<set $militiaFreeManpower += _militiaManpower * 0.5>>
					<<recalcManpower>>
					<<replace "#militiaResult">>

Dissidents purged and units dissolved.
					<</replace>>
				<</link>>

//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//

<<link "Execute them all">>
					<<run removeUnits(_militiaRebelledID)>>
					<<for _i = 0; _i < $militiaUnits.length; _i++>>
						<<if $militiaUnits[_i].active == 1>>
							<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty + random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#militiaResult">>

Units executed. Dissent will not be tolerated.
					<</replace>>
				<</link>>

//Will positively influence the loyalty of the other units, but no manpower will be refunded.//

		<</if>>

		/* slaves */
		<<set _slaveRebelledID = []>>
		<<set _slaveManpower = 0>>

		<<for _j = 0; _j < $slaveUnits.length; _j++>>
			<<if $slaveUnits[_j].active == 1 && $rebellingID.includes($slaveUnits[_j].ID)>>
				$slaveUnits[_j].platoonName,
				<<set _slaveRebelledID.push($slaveUnits[_j].ID)>>
				<<set _slaveManpower += Math.clamp($slaveUnits[_j].troops - random(_averageLosses),0,$slaveUnits[_j].troops)>>
			<</if>>
		<</for>>
		<<if _slaveRebelledID.length > 0>>
			decided in their blind arrogance to betray you.

<<link "Dissolve the units">>
					<<run removeUnits(_slaveRebelledID)>>
					<<set $menials += _slaveManpower>>
					<<for _i = 0; _i < $militiaUnits.length; _i++>>
						<<if $slaveUnits[_i].active == 1>>
							<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty - random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#slaveResult">>

Units dissolved.
					<</replace>>
				<</link>>

//Manpower will be refunded, but will negatively influence the loyalty of the other units//

<<link "Purge the dissidents and dissolve the units">>
					<<run removeUnits(_slaveRebelledID)>>
					<<set $menials += _slaveManpower * 0.5>>
					<<recalcManpower>>
					<<replace "#slaveResult">>

Dissidents purged and units dissolved.
					<</replace>>
				<</link>>

//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//

<<link "Execute them all">>
					<<run removeUnits(_slaveRebelledID)>>
					<<for _i = 0; _i < $slaveUnits.length; _i++>>
						<<if $slaveUnits[_i].active == 1>>
							<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty + random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#slaveResult">>

Units executed. Dissent will not be tolerated.
					<</replace>>
				<</link>>

//Will positively influence the loyalty of the other units, but no manpower will be refunded.//

		<</if>>

		/* mercs */
		<<set _mercRebelledID = []>>
		<<set _mercManpower = 0>>

		<<for _j = 0; _j < $mercUnits.length; _j++>>
			<<if $mercUnits[_j].active == 1 && $rebellingID.includes($mercUnits[_j].ID)>>
				$mercUnits[_j].platoonName,
				<<set _mercRebelledID.push($mercUnits[_j].ID)>>
				<<set _mercManpower += Math.clamp($mercUnits[_j].troops - random(_averageLosses),0,$mercUnits[_j].troops)>>
			<</if>>
		<</for>>
		<<if _mercRebelledID.length > 0>>
			made the grave mistake of betraying you.

<<link "Dissolve the units">>
					<<run removeUnits(_mercRebelledID)>>
					<<set $mercFreeManpower += _mercManpower>>
					<<for _i = 0; _i < $militiaUnits.length; _i++>>
						<<if $mercUnits[_i].active == 1>>
							<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty - random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#mercResult">>

Units dissolved.
					<</replace>>
				<</link>>

//Manpower will be refunded, but will negatively influence the loyalty of the other units//

<<link "Purge the dissidents and dissolve the units">>
					<<run removeUnits(_mercRebelledID)>>
					<<set $mercFreeManpower += _mercManpower * 0.5>>
					<<recalcManpower>>
					<<replace "#mercResult">>

Dissidents purged and units dissolved.
					<</replace>>
				<</link>>

//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//

<<link "Execute them all">>
					<<run removeUnits(_mercRebelledID)>>
					<<for _i = 0; _i < $mercUnits.length; _i++>>
						<<if $mercUnits[_i].active == 1>>
							<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty + random(10,40),0,100)>>
						<</if>>
					<</for>>
					<<recalcManpower>>
					<<replace "#mercResult">>

Units executed. Dissent will not be tolerated.
					<</replace>>
				<</link>>

//Will positively influence the loyalty of the other units, but no manpower will be refunded.//

		<</if>>

	/* loss */
	<<elseif $rebellingID.length > 0>>
		<<set _militiaRebelledID = []>>
		<<for _j = 0; _j < $militiaUnits.length; _j++>>
			<<if $militiaUnits[_j].active == 1 && $rebellingID.includes($militiaUnits[_j].ID)>>
				<<set _militiaRebelledID.push($militiaUnits[_j].ID)>>
				$militiaUnits[_j].platoonName,
			<</if>>
		<</for>>
		<<if _militiaRebelledID.length > 0>>
			had the gall to betray you and join your enemies. They participated in the looting following the battle, then vanished in the wastes.
		<</if>>
		<<run cashX(forceNeg(1000 * _militiaRebelledID.length), "war")>>

		<<run removeUnits(_militiaRebelledID)>>
		<<set _slaveRebelledID = []>>
		<<for _j = 0; _j < $slaveUnits.length; _j++>>
			<<if $slaveUnits[_j].active == 1 && $rebellingID.includes($slaveUnits[_j].ID)>>
				<<set _slaveRebelledID.push($slaveUnits[_j].ID)>>
				$slaveUnits[_j].platoonName,
			<</if>>
		<</for>>
		<<if _slaveRebelledID.length > 0>>
			decided in their blind arrogance to betray you. They participated in the looting following the battle, then vanished in the wastes.
		<</if>>
		<<run cashX(forceNeg(1000 * _slaveRebelledID.length), "war")>>
		<<run removeUnits(_slaveRebelledID)>>

		<<set _mercRebelledID = []>>
		<<set _count = 0>>
		<<for _j = 0; _j < $mercUnits.length; _j++>>
			<<if $mercUnits[_j].active == 1 && $rebellingID.includes($mercUnits[_j].ID)>>
				<<set _mercRebelledID.push($mercUnits[_j].ID)>>
				<<set _count++>>
				$mercUnits[_j].platoonName,
			<</if>>
		<</for>>
		<<if _mercRebelledID.length > 0>>
			made the grave mistake of betraying you. They participated in the looting following the battle, then vanished in the wastes.
		<</if>>
		<<run cashX(forceNeg(1000 * _mercRebelledID.length), "war")>>
		<<run removeUnits(_mercRebelledID)>>
		<<recalcManpower>>
	<</if>>
<<else>>

@@.red;Error: losses are a negative number or NaN@@
<</if>>


code:
:: weaponsManufacturing [nobr]

<<set $nextButton = "Back", $nextLink = "Main">>

This sector of the arcology has been dedicated to weapons manufacturing. These factories supply
<<if $militiaUnits.length > 0>> your militia and<</if>>
<<if $slaveUnits.length > 0>> your slave soldiers and<</if>>
<<if $mercenaries > 0>> your mercenaries and<</if>>
many small old world nations as the advanced technology that Free Cities have available is hard to come by otherwise.

<<if $weapProductivity == 1>>
	Production is completely manned by human workers. The complex has close to zero automation.
<<elseif $weapProductivity == 2>>
	Production is mostly handled by human workers. A few of the most tiresome tasks are handled by robots.
<<elseif $weapProductivity == 3>>
	A good part of production is handled by robots with humans handling the most complex tasks.
<<elseif $weapProductivity == 4>>
	Almost all production is handled by robots, with humans acting as support for the machines.
<<else>>
	All production here is handled by robots. The few humans working in the complex occupy themselves exclusively with management and quality assurance.
<</if>>

<<if $weapLab == 1>>
	There's a very Spartan lab attached to the complex that occupies itself mainly with weapons testing and small adjustments to the manufacturing process.
<<elseif $weapLab == 2>>
	There's a lab attached to the complex. It mainly test weapons effectiveness and manufacturing efficiency, but has enough equipment and personnel to develop new technology.
<<else>>
	There's a large lab attached to the complex. The complement of equipment and personnel makes it a great beacon of military science in an otherwise ignorant world.
<</if>>

<<if $weapMenials> 0>>Assigned here are $weapMenials slaves working to produce as much equipment as possible.<<else>>There are no assigned menial slaves here. The spaces is manned exclusively by low rank citizens.<</if>>
You own <<print num($menials)>> free menial slaves. This manufacturing complex can house 500 at most, with <<print 500 - $weapMenials>> free slots.

<<run MenialPopCap()>>
<<set _menialPrice = menialSlaveCost()>>
<<set _bulkMax = $PopCap-$menials-$fuckdolls-$menialBioreactors>>
<<if $cash > _menialPrice>>
	<<if _bulkMax > 0 || $menials+$fuckdolls+$menialBioreactors == 0>>

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

<<if $weapMenials < 500>>
	<<if $menials >= 1>>
		<<link "Transfer a menial slave">>
			<<set $menials-->>
			<<set $weapMenials++>>
			<<goto "weaponsManufacturing">>
		<</link>>
	<</if>>
	<<if $menials >= 10 && $weapMenials <= 490>>
		|
		<<link "Transfer 10 menial slaves">>
			<<set $menials -= 10>>
			<<set $weapMenials += 10>>
			<<goto "weaponsManufacturing">>
		<</link>>
	<</if>>
	<<if $menials > 0>>
		|
		<<link "Transfer all free menial slaves">>
			<<if $menials > 500 - $weapMenials>>
				<<set $menials -= 500 - $weapMenials>>
				<<set $weapMenials = 500>>
			<<else>>
				<<set $weapMenials += $menials>>
				<<set $menials = 0>>
			<</if>>
			<<goto "weaponsManufacturing">>
		<</link>>
	<</if>>
	<<if $weapMenials > 0>>

		<<link "Transfer out all menial slaves">>
			<<set $menials += $weapMenials>>
			<<set $weapMenials = 0>>
			<<goto "weaponsManufacturing">>
		<</link>>
	<</if>>
<<else>>
	The complex does not require more workers.

	<<link "Transfer out all menial slaves">>
		<<set $menials += $weapMenials>>
		<<set $weapMenials = 0>>
		<<goto "weaponsManufacturing">>
	<</link>>
<</if>>

<<if $weapProductivity < 5>>
	<<link "Invest in automating the complex">>
		<<run cashX(forceNeg(10000 * $weapProductivity), "capEx")>>
		<<set $weapProductivity++>>
		<<if $currentUpgrade.time > 0>>
			<<set _percentComplete = $currentUpgrade.time / ($baseUpgradeTime / ($weapProductivity - 1))>>
			<<set _newTime = Math.ceil(_percentComplete * $baseUpgradeTime / $weapProductivity)>>
			<<set $currentUpgrade.time = _newTime>>
		<</if>>
		<<goto "weaponsManufacturing">>
	<</link>>
	//Will cost <<print cashFormat(10000 * $weapProductivity)>> and will increase the facility income in addition to speeding up upgrade production.//
<<elseif $weapLab < 3>>
	You have fully automated the complex.
<</if>>

<<if $weapLab < 3>>
	<<link "Invest in research and development">>
		<<run cashX(forceNeg(10000 * $weapLab), "capEx")>>
		<<set $weapLab++>>
		<<goto "weaponsManufacturing">>
	<</link>>
	//Will cost <<print cashFormat(10000 * $weapLab)>> and will increase the facility income as well as unlock upgrades for our troops//
<<elseif $weapProductivity < 5>>
	You have fully upgraded and funded the R&D department
<</if>>
<<if $weapLab >= 3 && $weapProductivity >= 5>>
	The facility is completely automated and its R&D department is fully upgraded and funded.
<</if>>

__Markets__:
//You are free to sell to whoever you please, but expect hostile forces of a certain kind to be stronger if we'll ever meet in battle.//

<<if $sellTo.citizen == 1>>
	We are currently selling our weapons to the domestic market of the arcology.
	<<link "Forbid">>
		<<set $sellTo.citizen = 0>>
		<<goto "weaponsManufacturing">>
	<</link>>
<<else>>
	We are not selling our weaponry to our citizens.
	<<link "Allow">>
		<<set $sellTo.citizen = 1>>
		<<goto "weaponsManufacturing">>
	<</link>>
<</if>>

<<if $sellTo.raiders == 1>>
	We are currently selling our weapons to various groups of outlaws, also known as raiders.
	<<link "Forbid">>
		<<set $sellTo.raiders = 0>>
		<<goto "weaponsManufacturing">>
	<</link>>
<<else>>
	We are not selling our weaponry to raiders.
	<<link "Allow">>
		<<set $sellTo.raiders = 1>>
		<<goto "weaponsManufacturing">>
	<</link>>
<</if>>

<<if $sellTo.oldWorld == 1>>
	We are currently selling our weapons to many old world nations.
	<<link "Forbid">>
		<<set $sellTo.oldWorld = 0>>
		<<goto "weaponsManufacturing">>
	<</link>>
<<else>>
	We are not selling our weaponry to old world nations.
	<<link "Allow">>
		<<set $sellTo.oldWorld = 1>>
		<<goto "weaponsManufacturing">>
	<</link>>
<</if>>

<<if $sellTo.FC == 1>>
	We are currently selling our weapons to other Free Cities.
	<<link "Forbid">>
		<<set $sellTo.FC = 0>>
		<<goto "weaponsManufacturing">>
	<</link>>
<<else>>
	We are not selling our weaponry to other Free Cities.
	<<link "Allow">>
		<<set $sellTo.FC = 1>>
		<<goto "weaponsManufacturing">>
	<</link>>
<</if>>

<<set _time = Math.ceil($baseUpgradeTime / $weapProductivity)>>
Upgrades:
With our current industrial and research capabilities upgrades will be finished in _time weeks.

<<if $currentUpgrade.time <= 0>>

Security Drones:
	<<if $secBotsBaseDefense <= 3 || $droneUpgrades >= 3>>
		Upgrade the research facility further to unlock more upgrades for the security drones.

	<<else>>
		You have fully upgraded the security drones.
	<</if>>
	/* Drones upgrades */
	<<if !$completedUpgrades.includes(-1)>>
		<<link "Develop dynamic battle aware AI">>
			<<set $currentUpgrade = {
				ID: -1,
				name: "dynamic battle aware AI",
				unit: 0,
				type: "attack",
				time: _time}>>
			<<run cashX(forceNeg(10000*$HackingSkillMultiplier), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(10000*$HackingSkillMultiplier)>> and will increase the base attack value of the security drones.//
	<<elseif !$completedUpgrades.includes(-2) && $weapLab >= 2>>
		<<link "Develop adaptive armored frames">>
			<<set $currentUpgrade = {
				ID: -2,
				name: "adaptive armored frames",
				unit: 0,
				type: "defense",
				time: _time}>>
			<<run cashX(forceNeg(10000), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(10000)>> and will increase the base defense value of the security drones.//
	<<elseif !$completedUpgrades.includes(-3) && $weapLab >= 3>>

		<<link "Develop advanced synthetic alloys">>
			<<set $currentUpgrade = {
				ID: -3,
				name: "advanced synthetic alloys",
				unit: 0,
				type: "hp",
				time: _time}>>
			<<run cashX(forceNeg(30000), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(30000)>> and will increase the base hp value of the security drones.//
	<</if>>
	<<if $secBotsBaseDefense <= 3 || $droneUpgrades >= 3>>
 <</if>>

	/* human troops upgrades */

Troops:
	<<if $SF.Toggle && $SF.Active >= 1 && ($humanUpgrade.attack >= 4 || $humanUpgrade.hp >= 4 || $humanUpgrade.morale >= 40 || $humanUpgrade.defense >= 4)>>
		You have fully upgraded your human troops.
	<<elseif $humanUpgrade.attack >= 2 || $humanUpgrade.hp >= 2 || $humanUpgrade.morale >= 20 || $humanUpgrade.defense >= 2>>
		You have fully upgraded your human troops.
		<<if $SF.Toggle && $SF.Active >= 1 && ($humanUpgrade.attack < 4 || $humanUpgrade.hp < 4 || $humanUpgrade.morale < 40 || $humanUpgrade.defense < 4) && (($SFSupportLevel >= 2 && $SF.Squad.Firebase >= 7) || ($SFSupportLevel >= 4 && $SF.Squad.Drugs >= 8) || ($SFSupportLevel >= 5))>>
			With support from $SF.Lower, however, we may be able to further upgrade our troops.
		<</if>>
	<<elseif $weapLab < 3>>
		Upgrade the research facility further to unlock more upgrades for human troops.
	<</if>>
	<<if !$completedUpgrades.includes(0)>>

		<<link "Develop magnetic based ballistic weaponry">>
			<<set $currentUpgrade = {
				ID: 0,
				name: "magnetic based ballistic weaponry",
				unit: 1,
				type: "attack",
				time: _time}>>
			<<run cashX(forceNeg(30000), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(30000)>> and will increase the base attack value of human troops.//

	<</if>>
	<<if !$completedUpgrades.includes(1)>>
		<<link "Develop ceramo-metallic alloys">>
			<<set $currentUpgrade = {
				ID: 1,
				name: "ceramo-metallic alloys",
				unit: 1,
				type: "defense",
				time: _time}>>
			<<run cashX(forceNeg(30000), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(30000)>> and will increase the base defense value of human troops.//
	<</if>>
	<<if !$completedUpgrades.includes(2) && $weapLab >= 2>>

		<<link "Develop rapid action stimulants">>
			<<set $currentUpgrade = {
				ID: 2,
				name: "rapid action stimulants",
				unit: 1,
				type: "hp",
				time: _time}>>
			<<run cashX(forceNeg(60000), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(60000)>> and will increase the base hp value of human troops.//

	<</if>>
	<<if !$completedUpgrades.includes(3) && $weapLab >= 2>>
		<<link "Develop fast response neural stimulant">>
			<<set $currentUpgrade = {
				ID: 3,
				name: "fast response neural stimulant",
				unit: 1,
				type: "morale",
				time: _time}>>
			<<run cashX(forceNeg(60000), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(60000)>> and will increase the base morale value of human troops.//
	<</if>>
	<<if !$completedUpgrades.includes(4) && $weapLab >= 3>>

		<<link "Develop universal cyber enhancements">>
			<<set $currentUpgrade = {
				ID: 4,
				name: "universal cyber enhancements",
				unit: 1,
				type: "attackAndDefense",
				time: _time}>>
			<<run cashX(forceNeg(120000*$HackingSkillMultiplier), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(120000*$HackingSkillMultiplier)>> and will increase the base attack and "defense" values of human troops.//
	<</if>>
	<<if !$completedUpgrades.includes(5) && $weapLab >= 3>>

		<<link "Develop remote neural links">>
			<<set $currentUpgrade = {
				ID: 5,
				name: "remote neural links",
				unit: 1,
				type: "hpAndMorale",
				time: _time}>>
			<<run cashX(forceNeg(120000*$HackingSkillMultiplier), "capEx")>>
			<<goto "weaponsManufacturing">>
		<</link>>

//Will take _time weeks, cost <<print cashFormat(120000*$HackingSkillMultiplier)>> and will increase the base hp and morale values of human troops.//
	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1>>

		<<if !$completedUpgrades.includes(6) && $weapLab >= 2 && $SFSupportLevel >= 2 && $SF.Squad.Firebase >= 7>>

			<<link "Develop combined training regimens with $SF.Lower">>
				<<set $currentUpgrade = {
					ID: 6,
					name: "combined training regimens with the special force",
					unit: 1,
					type: "attackAndDefense",
					time: _time}>>
				<<goto "weaponsManufacturing">>
			<</link>>

//Will take _time weeks, and will increase the base attack and defense values of human troops.//
		<</if>>
		<<if !$completedUpgrades.includes(7) && $weapLab >= 2 && $SFSupportLevel >= 4 && $SF.Squad.Drugs >= 8>>

			<<link "Develop a variant of the stimulant cocktail that $SF.Lower created">>
				<<set $currentUpgrade = {
					ID: 7,
					name: "a variant of the stimulant cocktail that the special force created",
					unit: 1,
					type: "hpAndMorale",
					time: _time}>>
				<<run cashX(forceNeg(300000), "capEx")>>
				<<goto "weaponsManufacturing">>
			<</link>>

//Will take _time weeks, cost <<print cashFormat(300000)>> and will increase the base morale and hp values of human troops.//
		<</if>>
		<<if !$completedUpgrades.includes(8) && $weapLab >= 3 && $SFSupportLevel >= 5>>

			<<link "Create a mesh network based off the custom network of $SF.Lower">>
				<<set $currentUpgrade = {
					ID: 8,
					name: "a mesh network based off the custom network of the special force",
					unit: 1,
					type: "all",
					time: _time}>>
				<<run cashX(forceNeg(1000000*$HackingSkillMultiplier), "capEx")>>
				<<goto "weaponsManufacturing">>
			<</link>>

//Will take _time weeks, cost <<print cashFormat(1000000*$HackingSkillMultiplier)>> and will increase all base stats of human troops.//
		<</if>>
	<</if>>
<<else>>

	You are developing <<print $currentUpgrade.name>>.
	It is for <<if $currentUpgrade.unit == 0>> the security drones<<else>> our troops<</if>>. It will enhance their
	<<if $currentUpgrade.type == "attack">>
		attack power.
	<<elseif $currentUpgrade.type == "defense">>
		defensive capabilities.
	<<elseif $currentUpgrade.type == "hp">>
		survivability.
	<<elseif $currentUpgrade.type == "morale">>
		standing power.
	<<elseif $currentUpgrade.type == "attackAndDefense">>
		offensive and defensive effectiveness.
	<<elseif $currentUpgrade.type == "hpAndMorale">>
		morale and survivability.
	<<elseif $currentUpgrade.type == "all">>
		offensive, defensive effectiveness in addition to morale and survivability.
	<</if>>
	Estimated completion time is <<print $currentUpgrade.time>> weeks.
<</if>>
<<if $completedUpgrades.length > 0>>

	You have completed the following projects:
	<<for _i = 0; _i < $completedUpgrades.length; _i++>>
		<<if _i < $completedUpgrades.length - 2>>
			<<if $completedUpgrades[_i] == 0>>
				magnetic based ballistic weaponry,
			<<elseif $completedUpgrades[_i] == 1>>
				ceramo-metallic alloys,
			<<elseif $completedUpgrades[_i] == 2>>
				rapid action stimulants,
			<<elseif $completedUpgrades[_i] == 3>>
				fast response neural stimulant,
			<<elseif $completedUpgrades[_i] == 4>>
				universal cyber enhancements,
			<<elseif $completedUpgrades[_i] == 5>>
				remote neural links,
			<<elseif $completedUpgrades[_i] == 6>>
				combined training regimens with the special force,
			<<elseif $completedUpgrades[_i] == 7>>
				a variant of the stimulant cocktail that the special force created,
			<<elseif $completedUpgrades[_i] == 8>>
				a mesh network based off the custom network of the special force,
			<<elseif $completedUpgrades[_i] == -1>>
				dynamic battle aware AI,
			<<elseif $completedUpgrades[_i] == -2>>
				adaptive armored frames,
			<<elseif $completedUpgrades[_i] == -3>>
				advanced synthetic alloys,
			<</if>>
		<<else>>
			<<if $completedUpgrades[_i] == 0>>
				magnetic based ballistic weaponry.
			<<elseif $completedUpgrades[_i] == 1>>
				ceramo-metallic alloys.
			<<elseif $completedUpgrades[_i] == 2>>
				rapid action stimulants.
			<<elseif $completedUpgrades[_i] == 3>>
				fast response neural stimulant.
			<<elseif $completedUpgrades[_i] == 4>>
				universal cyber enhancements.
			<<elseif $completedUpgrades[_i] == 5>>
				remote neural links.
			<<elseif $completedUpgrades[_i] == 6>>
				combined training regimens with the special force.
			<<elseif $completedUpgrades[_i] == 7>>
				a variant of the stimulant cocktail that the special force created.
			<<elseif $completedUpgrades[_i] == 8>>
				a mesh network based off the custom network of the special force.
			<<elseif $completedUpgrades[_i] == -1>>
				dynamic battle aware AI.
			<<elseif $completedUpgrades[_i] == -2>>
				adaptive armored frames.
			<<elseif $completedUpgrades[_i] == -3>>
				advanced synthetic alloys.
			<</if>>
		<</if>>
	<</for>>
<</if>>

[[Return this sector to standard manufacturing|Main][cashX(forceNeg(Math.trunc(10000*$upgradeMultiplierArcology)), "capEx"), $sectors[$AS].type = "Manufacturing", $weapManu = 0]] //Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology))>>//

repo_name: IchthysdeKilt/fc

license: mit


code:
window.calcSFStatistics = function() {
	let upgradesSum = V.SF.Squad.Armoury + V.SF.Squad.Drugs + (V.SF.Squad.AA+V.SF.Squad.TA < 1) + (V.SF.Squad.AV+V.SF.Squad.TV);
	if (!Number.isInteger(upgradesSum)) {
		upgradesSum = jsRandom(10, 15);
	}

	if (V.slaveRebellion !== 1 || V.citizenRebellion !== 1) {
		/* atk, def */
		V.SFatk = Math.trunc(0.65 * upgradesSum);
		V.SFdef = Math.trunc(0.40 * upgradesSum);
		/* hp */
		V.carriableSoldiers = 125 * (V.SF.Squad.GunS + ((V.SF.Squad.AV + V.SF.Squad.TV)/2));
		if (!Number.isInteger(V.carriableSoldiers)) {
			V.carriableSoldiers = V.SF.Squad.Troops / 10;
		}
		if (V.SF.Squad.Troops > V.carriableSoldiers) {
			V.SFhp = V.carriableSoldiers * V.SFBaseHp;
		} else {
			V.carriableSoldiers = V.SF.Squad.Troops;
			V.SFhp = V.carriableSoldiers * V.SFBaseHp;
		}
	} else {
		/* atk, def */
		V.SFatk = Math.trunc(0.75 * upgradesSum);
		V.SFdef = Math.trunc(0.50 * upgradesSum);
		/* hp */
		V.SFhp = V.SF.Squad.Troops * V.SFBaseHp;
	}
};

/**
 * @param {Array<number>} rebellionIDs Array of unit IDs to be removed.
 */
window.removeUnits = function(rebellionIDs) {
	V.militiaUnits = V.militiaUnits.filter(unit => !rebellionIDs.includes(unit.ID));
	V.slaveUnits = V.slaveUnits.filter(unit => !rebellionIDs.includes(unit.ID));
	V.mercUnits = V.mercUnits.filter(unit => !rebellionIDs.includes(unit.ID));
};


code:
:: miscSecExpWidgets [widget nobr]

<<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 "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 !Number.isInteger($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 !Number.isInteger($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 !Number.isInteger($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 !Number.isInteger($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 !Number.isInteger($totalKills)>>
		<<set $totalKills = 0>>
	<</if>>
	<<if !Number.isInteger($mercTotalCasualties)>>
		<<set $mercTotalCasualties = 0>>
	<</if>>
	<<if !Number.isInteger($mercEmployedManpower)>>
		<<set $mercEmployedManpower = 0>>
	<</if>>
	<<if !Number.isInteger($mercTotalManpower)>>
		<<set $mercTotalManpower = 0>>
	<</if>>
	<<if !Number.isInteger($slavesTotalCasualties)>>
		<<set $slavesTotalCasualties = 0>>
	<</if>>
	<<if !Number.isInteger($slavesEmployedManpower)>>
		<<set $slavesEmployedManpower = 0>>
	<</if>>
	<<if !Number.isInteger($militiaTotalCasualties)>>
		<<set $militiaTotalCasualties = 0>>
	<</if>>
	<<if !Number.isInteger($militiaEmployedManpower)>>
		<<set $militiaEmployedManpower = 0>>
	<</if>>
	<<if !Number.isInteger($militiaFreeManpower)>>
		<<set $militiaFreeManpower = 0>>
	<</if>>
	<<if !Number.isInteger($militiaTotalManpower)>>
		<<set $militiaTotalManpower = 0>>
	<</if>>
	<<if !Number.isInteger($battlesCount)>>
		<<set $battlesCount = 0>>
	<</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 && $menials > 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 && $menials > 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 && $menials > 0>>
						<<if $menials >= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
							<<set $menials -= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
							<<set $slavesEmployedManpower += $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
							<<set _expLoss = ($slaveUnits[_i].maxTroops - $slaveUnits[_i].troops) / $slaveUnits[_i].troops>>
							<<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>>
							<<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>>
						<<else>>
							<<set $slavesEmployedManpower += $menials>>
							<<set _expLoss = $menials / $slaveUnits[_i].troops>>
							<<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>>
							<<set $slaveUnits[_i].troops += $menials>>
							<<set $menials = 0>>
						<</if>>
					<</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 "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:
:: art widgets [nobr widget]

<<widget "SlaveArtById">>
	<<set _s = getSlave($args[0])>>
	<<= SlaveArt(_s, $args[1])>>
<</widget>>


code:
:: Art_Vector_Body_Clothing_Control_ [nobr]

<<set _eyeBallColor = "#ffffff">>

<<if hasAnyEyes(_artSlave)>>
	<<set _eyeLens = hasLeftEye(_artSlave) ? getLeftEyePupil(_artSlave) : getRightEyePupil(_artSlave)>>
	<<if _eyeLens == "demonic">>
		<<set _eyeBallColor = hasLeftEye(_artSlave) ? getLeftEyeColor(_artSlave) : getRightEyeColor(_artSlave)>>
	<<elseif _eyeLens == "devilish">>
		<<set _eyeBallColor = "#000000">>
	<</if>>
<</if>>

<<set _muscles_value = _artSlave.muscles + 101>>
<<set _art_muscle_visibility = 0.910239*Math.log(0.02*_muscles_value) >>

<<set _showEyes = 1>>
<<set _showLips = 1>>
<<set _showMouth = 1>>
<<set _showPubic = 1>>
<<set _showPussy = (_artSlave.vagina >= 0)>>
<<set _showArmHair = 1>>
<<set _showHair = (_artSlave.hStyle != "shaved")>>
<<set _showBoobs = 1>>
<<set _showNipples = 1>>
<<set _showArmHighlight = 0>>
<<set _showTorsoHighlight = 0>>
<<set _showLegHighlight = 0>>
<<set _showBoobsHighlight = 0>>
<<set _showEyesHighlight = 1>>
<<set _showHeadHighlight = 1>>
<<set _showBellyPiercings = 1>>
<<set _showNipplePiercings = 1>>
<<set _chastityAnal = (_artSlave.chastityAnus == 1)>>

<<set _chastityVaginal = (_artSlave.chastityVagina == 1)>>

<<if _artSlave.fuckdoll > 0>>
	<<set _showEyes = 0>>
	<<set _showPubic = 0>>
	<<set _showArmHair = 0>>
	<<set _showHair = 0>>
	<<set _showArmHighlight = 1>>
	<<set _showTorsoHighlight = 1>>
	<<set _showBoobsHighlight = 1>>
	<<set _showLegHighlight = 1>>
	<<set _showHeadHighlight = 1>>
<</if>>

<<if _artSlave.clothes == "a nice maid outfit">>
	<<set _showPubic = 0>>
	<<set _showBoobs = 0>>
	<<set _showBellyPiercings = 0>>
	<<set _showNipplePiercings = 0>>
	<<set _showNipples = 0>>
<</if>>

<<if _artSlave.clothes == "a slutty maid outfit">>
	<<set _showBellyPiercings = 0>>
<</if>>

<<if _artSlave.clothes == "restrictive latex">>
	<<set _showEyes = 0>>
	<<set _showPubic = 0>>
	<<set _showArmHair = 0>>
	<<set _showHair = 0>>
	<<set _showArmHighlight = 1>>
	<<set _showTorsoHighlight = 1>>
	<<set _showLegHighlight = 1>>
	<<set _showHeadHighlight = 1>>
	<<set _showBellyPiercings = 0>>
<</if>>

<<if _artSlave.clothes == "a latex catsuit">>
	<<set _showPubic = 0>>
	<<set _showArmHair = 0>>
	<<set _showArmHighlight = 1>>
	<<set _showTorsoHighlight = 1>>
	<<set _showLegHighlight = 1>>
	<<set _showBoobsHighlight = 1>>
	<<set _showHeadHighlight = 1>>
	<<set _showBellyPiercings = 0>>
	<<set _showNipplePiercings = 0>>
	<<set _chastityAnal = 0>>
	<<set _chastityVaginal = 0>>
<</if>>

<<if $showBodyMods == 0>>
	<<set _showNipplePiercings = 0>>
<</if>>

<<if $seeVectorArtHighlights == 1>>
	<<set _showArmHighlight = 0>>
	<<set _showTorsoHighlight = 0>>
	<<set _showLegHighlight = 0>>
	<<set _showBoobsHighlight = 0>>
<</if>>