code:
:: rebellionHandler [nobr]

<<set $nextButton = " ", $nextLink = "attackReport", $showEncyclopedia = 0>>

<<set _turn = 0>>
<<set _turns = $maxTurns * 2>>
<<set _attack = 0>>
<<set _defense = 0>>
<<set _morale = 0>>
<<set _hp = 0>>
<<set _baseHp = 0>>
<<set _enemyAttack = 0>>
<<set _enemyDefense = 0>>
<<set _enemyMorale = 0>>
<<set _enemyHp = 0>>
<<set _enemyBaseHp = 0>>
<<set _woundChance = 5>>								/* leader has a base chance of 5% to get wounded */
<<set _tacChance = 0.5>>								/* by default tactics have a 50% chance of succeeding */
<<set _expBonus = 0>>
<<set _loyaltyBonus = 0>>
<<set _irregularMod = 0>>
<<set _armyMod = 0>>

/* calculates PC army stats */
<<if $engageRule == 0>>
	<<set _engageMod = 0.5>>
<<elseif $engageRule == 1>>
	<<set _engageMod = 0.75>>
<<elseif $engageRule == 2>>
	<<set _engageMod = 1>>
<<else>>
	<<set _engageMod = 1.4>>
<</if>>

<<if $week <= 30>>
	<<set _irregularMod = $irregulars / 60>>
<<elseif $week <= 60>>
	<<set _irregularMod = $irregulars / 50>>
<<elseif $week <= 90>>
	<<set _irregularMod = $irregulars / 40>>
<<elseif $week <= 120>>
	<<set _irregularMod = $irregulars / 30>>
<<else>>
	<<set _irregularMod = $irregulars / 20>>
<</if>>
<<if $irregulars > 0>>
	<<set $deployingMilitia = 1>>
	<<set _irregularMod = Math.trunc(_irregularMod)>>
	<<set _attack += (($militiaBaseAttack - $humanUpgrade.attack) + ($militiaBaseAttack - $humanUpgrade.attack) * $attackEquip * $equipMod) * _irregularMod * 0.80>>
	<<set _defense += (($militiaBaseDefense - $humanUpgrade.defense) + ($militiaBaseDefense - $humanUpgrade.defense) * $attackEquip * $equipMod) * _irregularMod * 0.80>>
	<<set _hp += $militiaBaseHp * $irregulars>>
<</if>>

<<if $secBots.active == 1>>
	<<set _attack += ($secBotsBaseAttack + $secBotsBaseAttack * $secBots.equip * $equipMod)>>
	<<set _defense += ($secBotsBaseDefense + $secBotsBaseDefense * $secBots.equip * $equipMod)>>
	<<set _hp += $secBotsBaseHp * $secBots.troops>>
	<<set $deployedUnits++>>
<</if>>

<<for _i = 0; _i < $militiaUnits.length; _i++>>
	<<if $militiaUnits[_i].active == 1 && $loyalID.includes($militiaUnits[_i].ID)>>
		<<set $deployingMilitia = 1>>
		<<set $deployedUnits++>>
		<<if $militiaUnits[_i].training <= 10>>
			<<set _expBonus = 0>>
		<<elseif $militiaUnits[_i].training <= 33>>
			<<set _expBonus = 0.10>>
		<<elseif $militiaUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<if $militiaUnits[_i].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $militiaUnits[_i].loyalty <= 33>>
			<<set _loyaltyBonus = 0.10>>
		<<elseif $militiaUnits[_i].loyalty <= 66>>
			<<set _loyaltyBonus = 0.20>>
		<<else>>
			<<set _loyaltyBonus = 0.30>>
		<</if>>
		<<set _attack += ($militiaBaseAttack + $militiaBaseAttack * $militiaUnits[_i].equip * $equipMod + $militiaBaseAttack * _expBonus + $militiaBaseAttack * _loyaltyBonus + $militiaBaseAttack * $militiaUnits[_i].SF * 0.20 + $militiaUnits[_i].cyber)>>
		<<set _defense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod + $militiaBaseDefense * _expBonus + $militiaBaseDefense * _loyaltyBonus + $militiaBaseDefense * $militiaUnits[_i].SF * 0.20 + $militiaUnits[_i].cyber)>>
		<<set _hp += ($militiaBaseHp + $militiaUnits[_i].cyber + $militiaBaseHp * $militiaUnits[_i].medics * 0.25) * $militiaUnits[_i].troops>>
	<</if>>
<</for>>
<<for _i = 0; _i < $slaveUnits.length; _i++>>
	<<if $slaveUnits[_i].active == 1 && $loyalID.includes($slaveUnits[_i].ID)>>
		<<set $deployingSlaves = 1>>
		<<set $deployedUnits++>>
		<<if $slaveUnits[_i].training <= 33>>
			<<set _expBonus = 0>>
		<<elseif $slaveUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<if $slaveUnits[_i].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $slaveUnits[_i].loyalty <= 33>>
			<<set _loyaltyBonus = 0.10>>
		<<elseif $slaveUnits[_i].loyalty <= 66>>
			<<set _loyaltyBonus = 0.20>>
		<<else>>
			<<set _loyaltyBonus = 0.30>>
		<</if>>
		<<set _attack += ($slaveBaseAttack + $slaveBaseAttack * $slaveUnits[_i].equip * $equipMod + $slaveBaseAttack * _expBonus + $slaveBaseAttack * _loyaltyBonus + $slaveBaseAttack * $slaveUnits[_i].SF * 0.20 + $slaveUnits[_i].cyber)>>
		<<set _defense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod + $slaveBaseDefense * _expBonus + $slaveBaseDefense * _loyaltyBonus + $slaveBaseDefense * $slaveUnits[_i].SF * 0.20 + $slaveUnits[_i].cyber)>>
		<<set _hp += ($slaveBaseHp + $slaveUnits[_i].cyber + $slaveBaseHp * $slaveUnits[_i].medics * 0.25) * $slaveUnits[_i].troops>>
	<</if>>
<</for>>
<<for _i = 0; _i < $mercUnits.length; _i++>>
	<<if $mercUnits[_i].active == 1 && $loyalID.includes($mercUnits[_i].ID)>>
		<<set $deployingMercs = 1>>
		<<set $deployedUnits++>>
		<<if $mercUnits[_i].training <= 33>>
			<<set _expBonus = 0>>
		<<elseif $mercUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<if $mercUnits[_i].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $mercUnits[_i].loyalty <= 33>>
			<<set _loyaltyBonus = 0.10>>
		<<elseif $mercUnits[_i].loyalty <= 66>>
			<<set _loyaltyBonus = 0.20>>
		<<else>>
			<<set _loyaltyBonus = 0.30>>
		<</if>>
		<<set _attack += ($mercBaseAttack + $mercBaseAttack * $mercUnits[_i].equip * $equipMod + $mercBaseAttack * _expBonus + $mercBaseAttack * _loyaltyBonus + $mercBaseAttack * $mercUnits[_i].SF * 0.20 + $mercUnits[_i].cyber)>>
		<<set _defense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod + $mercBaseDefense * _expBonus + $mercBaseDefense * _loyaltyBonus + $mercBaseDefense * $mercUnits[_i].SF * 0.20 + $mercUnits[_i].cyber)>>
		<<set _hp += ($mercBaseHp + $mercUnits[_i].cyber + $mercBaseHp * $mercUnits[_i].medics * 0.25) * $mercUnits[_i].troops>>
	<</if>>
<</for>>

<<if $SF.Toggle && $SF.Active >= 1>>
	<<set $SFatk = 0>>
	<<set $SFdef = 0>>
	<<set $SFhp = 0>>
	<<calcSFStatistics>>
	<<set _attack += $SFatk>>
	<<set _defense += $SFdef>>
	<<set _hp += $SFhp>>
<</if>>

<<set _attack *= _engageMod>>
<<set _defense *= _engageMod>>
<<set _hp *= _engageMod>>

<<if $garrison.assistant == 1>>
	<<set _attack *= 0.95>>
	<<set _defense *= 0.95>>
	<<set _hp *= 0.95>>
<</if>>
<<if $garrison.reactor == 1>>
	<<set _attack *= 0.95>>
	<<set _defense *= 0.95>>
	<<set _hp *= 0.95>>
<</if>>
<<if $garrison.penthouse == 1>>
	<<set _attack *= 0.95>>
	<<set _defense *= 0.95>>
	<<set _hp *= 0.95>>
<</if>>
<<if $garrison.waterway == 1>>
	<<set _attack *= 0.95>>
	<<set _defense *= 0.95>>
	<<set _hp *= 0.95>>
<</if>>

<<set $troopCount = 0>>
<<calcTroopCount>>
<<set _moraleTroopMod = Math.clamp($troopCount / 100,1,10)>>

/* morale and baseHp calculation */
<<set _morale = ($secBotsMorale * $secBots.active + $militiaBaseMorale * $deployingMilitia + $slaveBaseMorale * $deployingSlaves + $mercBaseMorale * $deployingMercs + $SFBaseMorale * $SF.Active) / ($secBots.active + $deployingMilitia +$deployingSlaves + $deployingMercs + $SF.Active)>>
<<set _morale = _morale + _morale * $secBarracksUpgrades.luxury * 0.05>>	/* barracks bonus */
<<set _morale *= _moraleTroopMod>>
<<set _baseHp = ($secBotsBaseHp * $secBots.active + $militiaBaseHp * $deployingMilitia + $slaveBaseHp * $deployingSlaves + $mercBaseHp * $deployingMercs + $SFBaseHp * $SF.Active) / ($secBots.active + $deployingMilitia +$deployingSlaves + $deployingMercs + $SF.Active)>>

/* calculates rebelling army stats */
<<if $week <= 30>>
	<<set _armyMod = $attackTroops / 100>>
<<elseif $week <= 60>>
	<<set _armyMod = $attackTroops / 90>>
<<elseif $week <= 90>>
	<<set _armyMod = $attackTroops / 80>>
<<elseif $week <= 120>>
	<<set _armyMod = $attackTroops / 70>>
<<else>>
	<<set _armyMod = $attackTroops / 60>>
<</if>>
<<set _armyMod = Math.trunc(_armyMod)>>

<<if $slaveRebellion == 1>>
	<<set $rebellingSlaves = 1>>
	<<set _enemyAttack += (($slaveBaseAttack - $humanUpgrade.attack) + ($slaveBaseAttack - $humanUpgrade.attack) * $attackEquip * $equipMod) * _armyMod>>
	<<set _enemyDefense += (($slaveBaseDefense - $humanUpgrade.defense) + ($slaveBaseDefense - $humanUpgrade.defense) * $attackEquip * $equipMod) * _armyMod>>
	<<set _enemyHp += $slaveBaseHp * $attackTroops>>
<<else>>
	<<set $rebellingMilitia = 1>>
	<<set _enemyAttack += (($militiaBaseAttack - $humanUpgrade.attack) + ($militiaBaseAttack - $humanUpgrade.attack) * $attackEquip * $equipMod) * _armyMod>>
	<<set _enemyDefense += (($militiaBaseDefense - $humanUpgrade.defense) + ($militiaBaseDefense - $humanUpgrade.defense) * $attackEquip * $equipMod) * _armyMod>>
	<<set _enemyHp += $militiaBaseHp * $attackTroops>>
<</if>>

<<for _i = 0; _i < $militiaUnits.length; _i++>>
	<<if $militiaUnits[_i].active == 1 && $rebellingID.includes($militiaUnits[_i].ID)>>
		<<set $rebellingMilitia = 1>>
		<<set $attackTroops += $militiaUnits[_i].troops>>
		<<if $militiaUnits[_i].training <= 10>>
			<<set _expBonus = 0>>
		<<elseif $militiaUnits[_i].training <= 33>>
			<<set _expBonus = 0.10>>
		<<elseif $militiaUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<set _enemyAttack += ($militiaBaseAttack + $militiaBaseAttack * $militiaUnits[_i].equip * $equipMod + $militiaBaseAttack * _expBonus + $militiaBaseAttack * $militiaUnits[_i].SF * 0.20 + $militiaUnits[_i].cyber)>>
		<<set _enemyDefense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod + $militiaBaseDefense * _expBonus + $militiaBaseDefense * $militiaUnits[_i].SF * 0.20 + $militiaUnits[_i].cyber)>>
		<<set _enemyHp += ($militiaBaseHp + $militiaUnits[_i].cyber + $militiaBaseHp * $militiaUnits[_i].medics * $equipMod) * $militiaUnits[_i].troops>>
	<</if>>
<</for>>
<<for _i = 0; _i < $slaveUnits.length; _i++>>
	<<if $slaveUnits[_i].active == 1 && $rebellingID.includes($slaveUnits[_i].ID)>>
		<<set $rebellingSlaves = 1>>
		<<set $attackTroops += $slaveUnits[_i].troops>>
		<<if $slaveUnits[_i].training <= 33>>
			<<set _expBonus = 0>>
		<<elseif $slaveUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<set _enemyAttack += ($slaveBaseAttack + $slaveBaseAttack * $slaveUnits[_i].equip * $equipMod + $slaveBaseAttack * _expBonus + $slaveBaseAttack * $slaveUnits[_i].SF * 0.20 + $slaveUnits[_i].cyber)>>
		<<set _enemyDefense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod + $slaveBaseDefense * _expBonus + $slaveBaseDefense * $slaveUnits[_i].SF * 0.20 + $slaveUnits[_i].cyber)>>
		<<set _enemyHp += ($slaveBaseHp + $slaveUnits[_i].cyber + $slaveBaseHp * $slaveUnits[_i].medics * 0.25) * $slaveUnits[_i].troops>>
	<</if>>
<</for>>
<<for _i = 0; _i < $mercUnits.length; _i++>>
	<<if $mercUnits[_i].active == 1 && $rebellingID.includes($mercUnits[_i].ID)>>
		<<set $rebellingMercs = 1>>
		<<set $attackTroops += $mercUnits[_i].troops>>
		<<if $mercUnits[_i].training <= 33>>
			<<set _expBonus = 0>>
		<<elseif $mercUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<set _enemyAttack += ($mercBaseAttack + $mercBaseAttack * $mercUnits[_i].equip * $equipMod + $mercBaseAttack * _expBonus + $mercBaseAttack * $mercUnits[_i].SF * 0.20 + $mercUnits[_i].cyber)>>
		<<set _enemyDefense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod + $mercBaseDefense * _expBonus + $mercBaseDefense * $mercUnits[_i].SF * 0.20 + $mercUnits[_i].cyber)>>
		<<set _enemyHp += ($mercBaseHp + $mercUnits[_i].cyber + $mercBaseHp * $mercUnits[_i].medics * 0.25) * $mercUnits[_i].troops>>
	<</if>>
<</for>>

<<set _enemyMoraleTroopMod = Math.clamp($attackTroops / 100,1,10)>>

<<set _enemyMorale = 1.5 * ($militiaBaseMorale * $rebellingMilitia + $slaveBaseMorale * $rebellingSlaves + $mercBaseMorale * $rebellingMercs) / ($rebellingMilitia + $rebellingSlaves + $rebellingMercs)>>
<<set _enemyMorale *= _enemyMoraleTroopMod>>
<<set _enemyBaseHp = ($militiaBaseHp * $rebellingMilitia + $slaveBaseHp * $rebellingSlaves + $mercBaseHp * $rebellingMercs) / ($rebellingMilitia +$rebellingSlaves + $rebellingMercs)>>

<<if isNaN(_attack)>>

@@.red;Error: attack value reported NaN@@
<</if>>
<<if isNaN(_defense)>>

@@.red;Error: defense value reported NaN@@
<</if>>
<<if isNaN(_hp)>>

@@.red;Error: hp value reported NaN@@
<</if>>
<<if isNaN(_morale)>>

@@.red;Error: morale value reported NaN@@
<</if>>
<<if isNaN(_enemyAttack)>>

@@.red;Error: enemy attack value reported NaN@@
<</if>>
<<if isNaN(_enemyDefense)>>

@@.red;Error: enemy defense value reported NaN@@
<</if>>
<<if isNaN(_enemyHp)>>

@@.red;Error: enemy hp value reported NaN@@
<</if>>
<<if isNaN(_enemyMorale)>>

@@.red;Error: enemy morale value reported NaN@@
<</if>>

/* difficulty */
<<set _enemyAttack *= $difficulty>>
<<set _enemyDefense *= $difficulty>>
<<set _enemyMorale *= $difficulty>>
<<set _enemyHp *= $difficulty>>
<<set _enemyBaseHp *= $difficulty>>

<<if $showBattleStatistics == 1>>
<<set _engageMod -= 1>>
<<set _engageMod = Math.round(_engageMod * 100)>>
<<set _difficulty = ($difficulty -1) * 100>>

__Difficulty__:

<<if $difficulty == 0.5>>
	Very easy
<<elseif $difficulty == 0.75>>
	Easy
<<elseif $difficulty == 1>>
	Normal
<<elseif $difficulty == 1.25>>
	Hard
<<else>>
	Very hard
<</if>>

__Army__:

troops: <<print num(Math.round($troopCount))>>

attack: <<print num(Math.round(_attack))>>

defense: <<print num(Math.round(_defense))>>

engagement rule modifier: <<if _engageMod > 0>>+<</if>><<print _engageMod>>%

Hp: <<print num(Math.round(_hp))>>

base HP: <<print num(Math.round(_baseHp))>>

morale: <<print num(Math.round(_morale))>>
<<if _enemyMoraleTroopMod > 0>>

morale increase due to troop numbers: +<<print _moraleTroopMod>>%
<</if>>

__Rebels__:

enemy troops: <<print num(Math.round($attackTroops))>>

enemy attack: <<print num(Math.round(_enemyAttack))>>

enemy defense: <<print num(Math.round(_enemyDefense))>>

enemy Hp: <<print num(Math.round(_enemyHp))>>

enemy base Hp: <<print num(Math.round(_enemyBaseHp))>>

enemy morale: <<print num(Math.round(_enemyMorale))>>
<<if _enemyMoraleTroopMod > 0>>

enemy morale increase due to troop numbers: +<<print _enemyMoraleTroopMod>>%
<</if>>

Difficulty modifier: <<if _difficulty > 0>>+<</if>><<print _difficulty>>%
<</if>>

/* simulates the combat by pitting attk against def */
<<for _i = 0; _i < _turns; _i++>>

	<<if $showBattleStatistics == 1>> turn: <<print _i + 1>><</if>>
	/* player army attacks */
	<<set _damage = Math.clamp(_attack - _enemyDefense,_attack * 0.1,_attack)>>

	<<if $showBattleStatistics == 1>> player damage: <<print num(Math.round(_damage))>><</if>>
	<<set _enemyHp -= _damage>>

	<<if $showBattleStatistics == 1>> remaining enemy Hp: <<print num(Math.round(_enemyHp))>><</if>>
	<<set $enemyLosses += _damage / _enemyBaseHp>>
	<<set _moraleDamage = Math.clamp(_damage/ 2 + _damage / _enemyBaseHp,0,_damage*1.5)>>
	<<set _enemyMorale -= _moraleDamage>>

	<<if $showBattleStatistics == 1>> remaining enemy morale: <<print num(Math.round(_enemyMorale))>><</if>>
	<<if _enemyHp <= 0 || _enemyMorale <= 0>>
		<<if $showBattleStatistics == 1>>
Victory!<</if>>
		<<set $battleResult = 3>>
		<<set $battleTurns = _i>>
		<<break>>
	<</if>>

	/* attacker army attacks */
	<<set _damage = _enemyAttack - _defense>>
	<<if _damage < _enemyAttack * 0.1>>
		<<set _damage = _enemyAttack * 0.1>>
	<</if>>

	<<if $showBattleStatistics == 1>> enemy damage: <<print num(Math.round(_damage))>><</if>>
	<<if $SFGear>> <<set _S = .85>> <<else>> <<set _S = 1>> <</if>>
	<<set _hp -= _damage*_S>>

	<<if $showBattleStatistics == 1>> remaining hp: <<print num(Math.round(_hp))>><</if>>
	<<set $losses += _damage / _baseHp>>
	<<set _moraleDamage = Math.clamp(_damage / 2 + _damage / _baseHp,0,_damage*1.5)>>
	<<set _morale -= _moraleDamage>>

	<<if $showBattleStatistics == 1>> remaining morale: <<print num(Math.round(_morale))>><</if>>
	<<if _hp <= 0 || _morale <= 0>>
		<<if $showBattleStatistics == 1>>
Defeat!<</if>>
		<<set $battleResult = -3>>
		<<set $battleTurns = _i>>
		<<break>>
	<</if>>
<</for>>
<<if $battleResult != 3 && $battleResult != -3>>
	<<if _morale > _enemyMorale>>
		<<if $showBattleStatistics == 1>>
Partial victory!<</if>>
		<<set $battleResult = 2>>
	<<elseif _morale < _enemyMorale>>
		<<if $showBattleStatistics == 1>>
Partial defeat!<</if>>
		<<set $battleResult = -2>>
	<</if>>
<</if>>

<<if $battleResult > 3 || $battleResult < -3>>

@@.red;Error: failed to determine battle result@@
<</if>>

<<if $showBattleStatistics == 1 && $rebellionGameOver == 1 && $battleResult == -3>>

	<<link "Proceed" "Gameover">>
		<<set $gameover = "Rebellion defeat">>
	<</link>>
<<elseif $rebellionGameOver == 1 && $battleResult == -3>>
	<<set $gameover = "Rebellion defeat">>
	<<goto "Gameover">>
<<elseif $showBattleStatistics == 1>>

	<<link "Proceed" "rebellionReport">>
	<</link>>
<<else>>
	<<goto "rebellionReport">>
<</if>>


code:
:: rebellionOptions [nobr]

<<set $nextButton = " ", $nextLink = "rebellionOptions", $showEncyclopedia = 1, $encyclopedia = "Battles">>

<<if $slaveRebellion == 1>>
	Slave Rebellion!
<<else>>
	Citizen Rebellion!
<</if>>

<<if $slaveRebellion == 1>>
	In the end it happened, the slaves of your arcology dared took up arms and rose up against their betters. Your penthouse is flooded with reports from all over the arcology of small skirmishes between the rioting slaves and the security forces.
	It appears <<print num(Math.trunc($attackTroops))>> rebels are in the streets right now, building barricades and freeing their peers. They are
	<<if $attackEquip <= 0>>
		poorly armed.
	<<elseif $attackEquip == 1>>
		lightly armed.
	<<elseif $attackEquip == 2>>
		decently armed.
	<<elseif $attackEquip == 3>>
		well armed.
	<<elseif $attackEquip >= 4>>
		extremely well armed.
	<</if>>
	<<if $irregulars > 0>>
		<<print num(Math.trunc($irregulars))>> of your citizens took up arms to defend their arcology owner.
	<</if>>
	<<set _count = 0>>
	<<if $rebellingID.length > 0>>

		<<for _i = 0; _i < $militiaUnits.length; _i++>>
			<<if $militiaUnits[_i].active == 1 && ($rebellingID.includes($militiaUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $rebellingID.length>>
					$militiaUnits[_i].platoonName,
				<<else>>
					$militiaUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $slaveUnits.length; _i++>>
			<<if $slaveUnits[_i].active == 1 && ($rebellingID.includes($slaveUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $rebellingID.length>>
					$slaveUnits[_i].platoonName,
				<<else>>
					$slaveUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $mercUnits.length; _i++>>
			<<if $mercUnits[_i].active == 1 && ($rebellingID.includes($mercUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $rebellingID.length>>
					$mercUnits[_i].platoonName,
				<<else>>
					$mercUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		betrayed you and joined the insurrection.
	<</if>>
	<<set _count = 0>>
	<<if $loyalID.length > 0>>

		<<if $arcologyUpgrade.drones == 1>>Your security drones,<</if>>
		<<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>>
	<<if $SF.Toggle && $SF.Active >= 1>>and $SF.Lower, <<print num($SF.Squad.Troops)>> strong<</if>>
		are called to defend the arcology from this menace.
	<<else>>
		<<if $arcologyUpgrade.drones == 1>>Your security drones<<if $SF.Toggle && $SF.Active >= 1>>and $SF.Lower, <<print num($SF.Squad.Troops)>> strong<</if>> <</if>>
		are called to defend the arcology from this menace.
	<</if>>

<<else>>
	In the end it happened, the citizens of your arcology dared took up arms and rose up against their betters. Your penthouse is flooded with reports from all over the arcology of small skirmishes between the rioting residents and the security forces.
	It appears <<print num(Math.trunc($attackTroops))>> rebels are in the streets right now, building barricades and destroying your property. They are
	<<if $attackEquip <= 0>>
		poorly armed.
	<<elseif $attackEquip == 1>>
		lightly armed.
	<<elseif $attackEquip == 2>>
		decently armed.
	<<elseif $attackEquip == 3>>
		well armed.
	<<elseif $attackEquip >= 4>>
		extremely well armed.
	<</if>>
	<<if $irregulars > 0>>
		<<print num(Math.trunc($irregulars))>> of your citizens took up arms to defend their arcology owner.
	<</if>>
	<<set _count = 0>>

	<<if $rebellingID.length > 0>>

		<<for _i = 0; _i < $militiaUnits.length; _i++>>
			<<if $militiaUnits[_i].active == 1 && ($rebellingID.includes($militiaUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $rebellingID.length>>
					$militiaUnits[_i].platoonName,
				<<else>>
					$militiaUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $slaveUnits.length; _i++>>
			<<if $slaveUnits[_i].active == 1 && ($rebellingID.includes($slaveUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $rebellingID.length>>
					$slaveUnits[_i].platoonName,
				<<else>>
					$slaveUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		<<for _i = 0; _i < $mercUnits.length; _i++>>
			<<if $mercUnits[_i].active == 1 && ($rebellingID.includes($mercUnits[_i].ID))>>
				<<set _count++>>
				<<if _count < $rebellingID.length>>
					$mercUnits[_i].platoonName,
				<<else>>
					$mercUnits[_i].platoonName
				<</if>>
			<</if>>
		<</for>>
		betrayed you and joined the insurrection.
	<</if>>

	<<set _count = 0>>
	<<if $loyalID.length > 0>>

		<<if $arcologyUpgrade.drones == 1>>Your security drones,<</if>>
		<<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>>
		<<if $SF.Toggle && $SF.Active >= 1>>and $SF.Lower, <<print num($SF.Squad.Troops)>> strong<</if>>
		are called to defend the arcology from this menace.
	<<else>>
		<<if $arcologyUpgrade.drones == 1>>Your security drones<<if $SF.Toggle && $SF.Active >= 1>>and $SF.Lower, <<print num($SF.Squad.Troops)>> strong<</if>><</if>>
		are called to defend the arcology from this menace.
	<</if>>

<</if>>

The confined spaces of the arcology and the number of vital yet delicate systems within its walls do not allow a lot of tactical flexibility. This will be a long and strenuous fight, street after street, barricade after barricade.
In order to preserve the structural integrity of the building and the lives of our civilians, we will have to limit our firepower.

<<link "Only light firearms and nonlethal weapons">>
	<<set $engageRule = 0>>
	<<replace "#engage">>

Your troops will use only nonlethal weapons or light firearms to limit to the maximum the collateral damage. This will however weaken our troops considerably.
	<</replace>>
<</link>>

<<link "No heavy ordnance">>
	<<set $engageRule = 1>>
	<<replace "#engage">>

Your troops will limit the use of explosives and heavy weapons to limit considerably the collateral damage. This will however weaken our troops.
	<</replace>>
<</link>>

<<link "Normal engagement rules">>
	<<set $engageRule = 2>>
	<<replace "#engage">>

Your troops will not limit their arsenal. This will put the structure and your citizens at risk, but our troops will be at full capacity.
	<</replace>>
<</link>>

<<if $advancedRiotEquip == 1>>

<<link "Advanced riot protocol">>
		<<set $engageRule = 3>>
		<<replace "#engage">>

Your troops will make use of the special weaponry, equipment and infrastructure developed by the riot control center to surgically eliminate rebels and dissidents with little to no collateral damage.
		<</replace>>
	<</link>>
<</if>>

Your troops will use only nonlethal weapons or light firearms to limit to the maximum the collateral damage. This will however weaken our troops considerably.

We can dedicate some of our forces to the protection of the vital parts of the arcology, doing so will prevent the failure of said systems, but will also take away strength from our assault.
<<if $garrison.penthouse == 0>>

<<link "Garrison the penthouse" "rebellionOptions">>
		<<set $garrison.penthouse = 1>>
	<</link>>
<<else>>

Troops will be dispatched to the penthouse.
	<<link "Discard the order" "rebellionOptions">>
		<<set $garrison.penthouse = 0>>
	<</link>>
<</if>>
<<if $garrison.reactor == 0>>

<<link "Garrison the reactors" "rebellionOptions">>
		<<set $garrison.reactor = 1>>
	<</link>>
<<else>>

Troops will be dispatched to the reactors.
	<<link "Discard the order" "rebellionOptions">>
		<<set $garrison.reactor = 0>>
	<</link>>
<</if>>
<<if $garrison.assistant == 0>>

<<link "Garrison the assistant's central CPU" "rebellionOptions">>
		<<set $garrison.assistant = 1>>
	<</link>>
<<else>>

Troops will be dispatched to the assistant's central CPU.
	<<link "Discard the order" "rebellionOptions">>
		<<set $garrison.assistant = 0>>
	<</link>>
<</if>>
<<if $garrison.waterway == 0>>

<<link "Garrison the waterways" "rebellionOptions">>
		<<set $garrison.waterway = 1>>
	<</link>>
<<else>>

Troops will be dispatched to the waterways.
	<<link "Discard the order" "rebellionOptions">>
		<<set $garrison.waterway = 0>>
	<</link>>
<</if>>

<<replenishAllUnits>>

<<link "Proceed" "rebellionHandler">>
	<<set $battleResult = 4>>						/* sets $battleResult value outside accepted range to avoid evaluation problems */
	<<if $hasFoughtOnce == 0>>
		<<set $hasFoughtOnce = 1>>
	<</if>>
	<<set $foughtThisWeek = 1>>
<</link>>

<<link "Surrender" "rebellionHandler">>
	<<set $battleResult = -1>>
	<<if $hasFoughtOnce == 0>>
		<<set $hasFoughtOnce = 1>>
	<</if>>
	<<set $foughtThisWeek = 1>>
<</link>>

repo_name: AmbrosiaCheesecake/fc


code:
:: rebellionReport [nobr]

<<set $nextButton = "Continue", $nextLink = "Scheduled Event", $showEncyclopedia = 1, $encyclopedia = "Battles">>
<<set _oldRep = $rep>>
<<set _oldAuth = $authority>>
<<set $enemyLosses = Math.trunc($enemyLosses)>>
<<if $enemyLosses > $attackTroops>>
	<<set $enemyLosses = $attackTroops>>
<</if>>
<<set $totalKills += $enemyLosses>>
<<set $losses = Math.trunc($losses)>>
<<set $rebellionsCount++>>
<<if $battleResult == 3>>
	Victory!
	<<set $PCrebWon++>>
<<elseif $battleResult == -3>>
	Defeat!
	<<set $PCrebLoss++>>
<<elseif $battleResult == 2>>
	Partial victory!
	<<set $PCrebWon++>>
	<<elseif $battleResult == -2>>
	Partial defeat!
	<<set $PCrebLoss++>>
<<elseif $battleResult == -1>>
	We surrendered
	<<set $PCrebLoss++>>
<</if>>
<<set _day = $day + random(0,7)>>
<<set _month = $month>>
<<set _year = $year>>
<<switch _month>>
<<case "January">>
<<if _day > 31>>
	<<set _day -= 31, _month = "February">>
<</if>>
<<case "February">>
<<if _day > 28>>
	<<set _day -= 28, _month = "March">>
<</if>>
<<case "March">>
<<if _day > 31>>
	<<set _day -= 31, _month = "April">>
<</if>>
<<case "April">>
<<if _day > 30>>
	<<set _day -= 30, _month = "May">>
<</if>>
<<case "May">>
<<if _day > 31>>
	<<set _day -= 31, _month = "June">>
<</if>>
<<case "June">>
<<if _day > 30>>
	<<set _day -= 30, _month = "July">>
<</if>>
<<case "July">>
<<if _day > 31>>
	<<set _day -= 31, _month = "August">>
<</if>>
<<case "August">>
<<if _day > 31>>
	<<set _day -= 31, _month = "September">>
<</if>>
<<case "September">>
<<if _day > 30>>
	<<set _day -= 30, _month = "October">>
<</if>>
<<case "October">>
<<if _day > 31>>
	<<set _day -= 31, _month = "November">>
<</if>>
<<case "November">>
<<if _day > 30>>
	<<set _day -= 30, _month = "December">>
<</if>>
<<default>>
<<if _day > 31>>
	<<set _day -= 31, _month = "January", _year += 1>>
<</if>>
<</switch>>

<<if $slaveRebellion == 1>>
	Today, the _day of _month _year, our arcology was inflamed by the fires of rebellion. <<print num(Math.trunc($attackTroops))>> rebels from all over the structure dared rise up against their owners and conquer their freedom through blood. Our defense force, <<print num(Math.trunc($troopCount))>> strong, fought with them street by street
	<<if $enemyLosses != $attackTroops>>
		inflicting <<print num(Math.trunc($enemyLosses))>> casualties, while sustaining <<if $losses > 1>> <<print num(Math.trunc($losses))>> casualties <<else>> a casualty<</if>> themselves.
	<<else>>
		completely annihilating their troops, while sustaining <<if $losses > 1>> <<print num(Math.trunc($losses))>> casualties <<else>> a casualty.<</if>>
	<</if>>
	<<if $SFGear>>
		More units were able to survive thanks to wearing $SF.Lower's combat armor suits.
	<</if>>
	<<set $NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * $enemyLosses),
	$menials -= Math.trunc(($menials / $ASlaves) * $enemyLosses),
	$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * $enemyLosses),
	$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * $enemyLosses)>>
	<<if $battleResult == 3>>
		<<if $battleTurns <= 5>>
			The fight was quick and one sided, our men easily stopped the disorganized revolt in a few well aimed assaults.
		<<elseif $battleTurns <= 7>>
			The fight was hard, but in the end our men stopped the disorganized revolt with several well aimed assaults.
		<<else>>
			The fight was long and hard, but in the end our men stopped the revolt before it could accumulate momentum.
		<</if>>
	<<elseif $battleResult == -3>>
		<<if $battleTurns <= 5>>
			The fight was quick and one sided, our men were easily crushed by the furious charge of the rebels.
		<<elseif $battleTurns <= 7>>
			The fight was hard and in the end the rebels proved too much to handle for our men.
		<<else>>
			The fight was long and hard, but despite their bravery the rebels proved too much for our men.
		<</if>>
	<<elseif $battleResult == 2>>
		The fight was long and hard, but in the end our men managed to stop the revolt, though not without difficulty.
	<<elseif $battleResult == -2>>
		The fight was long and hard. Our men in the end had to yield to the rebelling slaves, which were fortunately unable to capitalize on their victory.
	<<elseif $battleResult == -1>>
		You gave your troops the order to surrender; they obediently stand down.
	<</if>>

	/* effects */
	<<if $battleResult == 3>>
		Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased.
		<<run repX(random(800,1000), "war")>>
		<<set $authority += random(800,1000)>>

Many of the rebelling slaves were recaptured and punished. The instigators were executed one after another in a public trial that lasted for almost three days.
		<<set $NPCSlaves -= random(10,30)>>
	<<elseif $battleResult == -3>>
		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
		<<run repX(random(-800,-1000), "war")>>
		<<set $authority -= random(800,1000)>>

After the battle most of the rebelling slaves managed to escape, while others remained in the arcology for days looting and hunting their former masters. The arcology will bear the scars of this day for a long time.
		<<set $lowerClass -= random(50,100)>>
		<<set _lostSlaves = Math.trunc(($attackTroops - $enemyLosses) * 0.8),
		$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
		$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
		$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
		$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
		<<set $rebelDefeatAftermath = 5>>
	<<elseif $battleResult == -2>>
		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
		<<run repX(random(-600,-800), "war")>>
		<<set $authority -= random(600,800)>>

After the battle most of the rebelling slaves managed to escape, while others remained in the arcology for days looting and hunting their former masters. The arcology will bear the scars of this day for a long time.
		<<set $lowerClass -= random(40,80)>>
		<<set _lostSlaves = Math.trunc(($attackTroops - $enemyLosses) * 0.8),
		$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
		$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
		$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
		$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
		<<set $rebelDefeatAftermath = 3>>
	<<elseif $battleResult == 2>>
		Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased.
		<<run repX(random(600,180), "war")>>
		<<set $authority += random(600,800)>>

Many of the rebelling slaves were recaptured and punished. The instigators were executed one after another in a public trial that lasted for almost three days.
		<<set $NPCSlaves -= random(10,30)>>
	<<elseif $battleResult == -1>>
		Rather than waste the lives of your men you decided to surrender, hoping the rebels will cause less damage if you indulge them, this is however a big hit to your status. Your @@.red;reputation@@ and @@.red;authority@@ are significantly impacted.
		<<run repX(random(-1000,-1200), "war")>>
		<<set $authority -= random(1000,1200)>>

		The surrender allows the arcology to survive @@.yellow;mostly intact,@@ however reports of @@.red;mass looting and killing of citizens@@ flood your office for a few days.
		<<run cashX(-1000, "war")>>
		<<if $week <= 30>>
			<<set $lowerClass -= random(100)>>
			<<set _lostSlaves = random(150),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(5)>>
		<<elseif $week <= 60>>
			<<set $lowerClass -= random(120)>>
			<<set _lostSlaves = random(170),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(10)>>
		<<elseif $week <= 90>>
			<<set $lowerClass -= random(140)>>
			<<set _lostSlaves = random(190),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(15)>>
		<<elseif $week <= 120>>
			<<set $lowerClass -= random(160)>>
			<<set _lostSlaves = random(210),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(20)>>
		<<else>>
			<<set $lowerClass -= random(180)>>
			<<set _lostSlaves = random(230),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(25)>>
		<</if>>

After the battle most of the rebelling slaves managed to escape, while others remained in the arcology for days looting and hunting their former masters. The arcology will bear the scars of this day for a long time.
		<<set $lowerClass -= random(50,100)>>
		<<set _lostSlaves = Math.trunc(($attackTroops - $enemyLosses) * 0.8),
		$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
		$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
		$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
		$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
		<<set $rebelDefeatAftermath = 5>>
	<</if>>
<<else>>
	Today, the _day of _month _year, our arcology was inflamed by the fires of rebellion. <<print num(Math.trunc($attackTroops))>> rebels from all over the structure dared rise up to dethrone their arcology owner. Our defense force, <<print num($troopCount)>> strong, fought with them street by street
	<<if $enemyLosses != $attackTroops>>
		inflicting <<print num(Math.trunc($enemyLosses))>> casualties, while sustaining <<if $losses > 1>> <<print num(Math.trunc($losses))>> casualties <<else>> a casualty<</if>> themselves.
	<<else>>
		completely annihilating their troops, while sustaining <<if $losses > 1>> <<print num(Math.trunc($losses))>> casualties <<else>> a casualty.<</if>>
	<</if>>
	<<if $SFGear>>
		More units were able to survive thanks to wearing $SF.Lower's combat armor suits.
	<</if>>
	<<set $NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * $enemyLosses),
	$menials -= Math.trunc(($menials / $ASlaves) * $enemyLosses),
	$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * $enemyLosses),
	$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * $enemyLosses)>>
	<<if $battleResult == 3>>
		<<if $battleTurns <= 5>>
			The fight was quick and one sided, our men easily stopped the disorganized revolt in a few well aimed assaults.
		<<elseif $battleTurns <= 7>>
			The fight was hard, but in the end our men stopped the disorganized revolt with several well aimed assaults.
		<<else>>
			The fight was long and hard, but in the end our men stopped the revolt before it could accumulate momentum.
		<</if>>
	<<elseif $battleResult == -3>>
		<<if $battleTurns <= 5>>
			The fight was quick and one sided, our men were easily crushed by the furious charge of the rebels.
		<<elseif $battleTurns <= 7>>
			The fight was hard and in the end the rebels proved too much to handle for our men.
		<<else>>
			The fight was long and hard, but despite their bravery the rebels proved too much for our men.
		<</if>>
	<<elseif $battleResult == 2>>
		The fight was long and hard, but in the end our men managed to stop the revolt, though not without difficulty.
	<<elseif $battleResult == -2>>
		The fight was long and hard. Our men in the end had to yield to the rebelling slaves, which were fortunately unable to fully capitalize on their victory.
	<<elseif $battleResult == -1>>
		You gave your troops the order to surrender, obediently they stand down.
	<</if>>

	/* effects */
	<<if $battleResult == 3>>
		Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased.
		<<run repX(random(800,1000), "war")>>
		<<set $authority += random(800,1000)>>

Many of the rebelling citizens were captured and punished, many others enslaved. The instigators were executed one after another in a public trial that lasted for almost three days.
		<<set $lowerClass -= random(10,30)>>
	<<elseif $battleResult == -3>>
		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
		<<run repX(random(-800,-1000), "war")>>
		<<set $authority -= random(800,1000)>>

After the battle most of the rebelling citizens remained in the arcology for days looting and hunting their former arcology. We will bear the scars of this day for a long time.
		<<set $lowerClass -= Math.trunc(($attackTroops - $enemyLosses) * 0.8)>>
		<<set $rebelDefeatAftermath = 5>>
	<<elseif $battleResult == -2>>
		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
		<<run repX(random(-600,-800), "war")>>
		<<set $authority -= random(600,800)>>

After the battle most of the rebelling citizens remained in the arcology for days looting and hunting their former arcology. We will bear the scars of this day for a long time.
		<<set $lowerClass -= random(40,80)>>
		<<set _lostSlaves = Math.trunc(($attackTroops - $enemyLosses) * 0.6),
		$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
		$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
		$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
		$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
		<<set $rebelDefeatAftermath = 3>>
	<<elseif $battleResult == 2>>
		Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased.
		<<run repX(random(600,180), "war")>>
		<<set $authority += random(600,800)>>

Many of the rebelling citizens were captured and punished, many others enslaved. The instigators were executed one after another in a public trial that lasted for almost three days.
		<<set $NPCSlaves -= random(10,30)>>
	<<elseif $battleResult == -1>>
		Rather than waste the lives of your men you decided to surrender, hoping the rebels will cause less damage if you indulge them, this is however a big hit to your status. Your @@.red;reputation@@ and @@.red;authority@@ are significantly impacted.
		<<run repX(random(-1000,-1200), "war")>>
		<<set $authority -= random(1000,1200)>>

		The surrender allows the arcology to survive @@.yellow;mostly intact,@@ however reports of @@.red;mass looting and killing of citizens@@ flood your office for a few days.
		<<run cashX(-1000, "war")>>
		<<if $week <= 30>>
			<<set $lowerClass -= random(100)>>
			<<set _lostSlaves = random(150),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(5)>>
		<<elseif $week <= 60>>
			<<set $lowerClass -= random(120)>>
			<<set _lostSlaves = random(170),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(10)>>
		<<elseif $week <= 90>>
			<<set $lowerClass -= random(140)>>
			<<set _lostSlaves = random(190),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(15)>>
		<<elseif $week <= 120>>
			<<set $lowerClass -= random(160)>>
			<<set _lostSlaves = random(210),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(20)>>
		<<else>>
			<<set $lowerClass -= random(180)>>
			<<set _lostSlaves = random(230),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(25)>>
		<</if>>

After the battle most of the rebelling citizens remained in the arcology for days looting and hunting their former arcology. We will bear the scars of this day for a long time.
		<<set $lowerClass -= random(50,100)>>
		<<set _lostSlaves = Math.trunc(($attackTroops - $enemyLosses) * 0.8),
		$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
		$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
		$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
		$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
		<<set $rebelDefeatAftermath = 5>>
	<</if>>
<</if>>

/* engage rules */
<<if $battleResult != -1>>
	<<if $engageRule == 0>>
		Since you ordered your troops to limit their weaponry to low caliber or nonlethal, the arcology reported only @@.red;minor damage.@@ Most citizens and non involved slaves remained unharmed, though some casualties between the civilians were inevitable.
		A few businesses were looted and burned, but the damage was pretty limited.
		<<set $arcRepairTime += 3, IncreasePCSkills('engineering', 0.1)>>
		<<if $week <= 30>>
			<<set $lowerClass -= random(40)>>
			<<set _lostSlaves = random(65),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(2)>>
		<<elseif $week <= 60>>
			<<set $lowerClass -= random(50)>>
			<<set _lostSlaves = random(75),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(5)>>
		<<elseif $week <= 90>>
			<<set $lowerClass -= random(60)>>
			<<set _lostSlaves = random(85),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(7)>>
		<<elseif $week <= 120>>
			<<set $lowerClass -= random(70)>>
			<<set _lostSlaves = random(95),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(10)>>
		<<else>>
			<<set $lowerClass -= random(80)>>
			<<set _lostSlaves = random(105),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(12)>>
		<</if>>
	<<elseif $engageRule == 1>>
		You ordered your troops to limit their weaponry to non-heavy, non-explosive, because of this the arcology reported @@.red;moderate damage.@@ Most citizens and non involved slaves remained unharmed or only lightly wounded, but many others did not make it. Unfortunately casualties between the civilians were inevitable.
		A few businesses were looted and burned, but the damage was pretty limited.
		<<set $arcRepairTime += 5, IncreasePCSkills('engineering', 0.1)>>
		<<if $week <= 30>>
			<<set $lowerClass -= random(60)>>
			<<set _lostSlaves = random(85),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(4)>>
		<<elseif $week <= 60>>
			<<set $lowerClass -= random(70)>>
			<<set _lostSlaves = random(95),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(7)>>
		<<elseif $week <= 90>>
			<<set $lowerClass -= random(80)>>
			<<set _lostSlaves = random(105),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(9)>>
		<<elseif $week <= 120>>
			<<set $lowerClass -= random(90)>>
			<<set _lostSlaves = random(115),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(12)>>
		<<else>>
			<<set $lowerClass -= random(100)>>
			<<set _lostSlaves = random(125),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(14)>>
		<</if>>
	<<elseif $engageRule == 2>>
		Since you did not apply any restriction on the weapons your forces should use, the arcology reported @@.red;heavy damage.@@ Many citizens and uninvolved slaves are reported killed or missing. Casualties between the civilians were inevitable.
		Many businesses were damaged during the battle either by the fight itself, by fires which spread unchecked for hours or by looters.
		<<set $arcRepairTime += 7, IncreasePCSkills('engineering', 0.1)>>
		<<if $week <= 30>>
			<<set $lowerClass -= random(100)>>
			<<set _lostSlaves = random(150),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(5)>>
		<<elseif $week <= 60>>
			<<set $lowerClass -= random(120)>>
			<<set _lostSlaves = random(170),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(10)>>
		<<elseif $week <= 90>>
			<<set $lowerClass -= random(140)>>
			<<set _lostSlaves = random(190),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(15)>>
		<<elseif $week <= 120>>
			<<set $lowerClass -= random(160)>>
			<<set _lostSlaves = random(210),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(20)>>
		<<else>>
			<<set $lowerClass -= random(180)>>
			<<set _lostSlaves = random(230),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(25)>>
		<</if>>
	<<else>>
		Thanks to the advance riot control weaponry developed by your experts, the rebels were mostly subdued or killed with @@.yellow;little to no collateral damage to the arcology@@ and its inhabitants.
		A few businesses were looted, but the damage was very limited.
		<<set $arcRepairTime += 2, IncreasePCSkills('engineering', 0.1)>>
		<<run cashX(-1000, "war")>>
		<<if $week <= 30>>
			<<set $lowerClass -= random(20)>>
			<<set _lostSlaves = random(45),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(2)>>
		<<elseif $week <= 60>>
			<<set $lowerClass -= random(30)>>
			<<set _lostSlaves = random(55),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(4)>>
		<<elseif $week <= 90>>
			<<set $lowerClass -= random(40)>>
			<<set _lostSlaves = random(65),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(6)>>
		<<elseif $week <= 120>>
			<<set $lowerClass -= random(50)>>
			<<set _lostSlaves = random(75),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(8)>>
		<<else>>
			<<set $lowerClass -= random(60)>>
			<<set _lostSlaves = random(85),
			$NPCSlaves -= Math.trunc(($NPCSlaves / $ASlaves) * _lostSlaves),
			$menials -= Math.trunc(($menials / $ASlaves) * _lostSlaves),
			$fuckdolls -= Math.trunc(($fuckdolls / $ASlaves) * _lostSlaves),
			$menialBioreactors -= Math.trunc(($menialBioreactors / $ASlaves) * _lostSlaves)>>
			<<set $arcologies[0].prosperity -= random(10)>>
		<</if>>
	<</if>>
<</if>>
<<if $lowerClass < 0>>
	<<set $lowerClass = 0>>
<</if>>
<<if $NPCSlaves < 0>>
	<<set $NPCSlaves = 0>>
<</if>>

/* garrisons */
<<if $garrison.reactor == 0>>
	<<if random(1,100) <= (75 - ($fort.reactor * 25))>>
		Unfortunately during the fighting a group of slaves infiltrated the reactor complex and sabotaged it, causing massive power fluctuations and blackouts.
		It will take @@.red;time and money to repair the damage.@@
		<<set $garrison.reactorTime = $repairTime + random(1) - $fort.reactor, IncreasePCSkills('engineering', 0.1)>>
		<<run cashX(-2000, "war")>>
	<<else>>
		While the reactor was left defenseless without a garrison, there was no attempt at sabotage. Let's hope we'll always be this lucky.
	<</if>>
<<else>>
	The garrison assigned to the reactor protected it from the multiple sabotage attempts carried out by the rebels.
<</if>>
<<if $garrison.waterway == 0>>
	<<if random(1,100) <= (75 - ($fort.waterway * 25))>>
		Unfortunately during the fighting a group of slaves infiltrated the water management complex and sabotaged it, causing huge water leaks throughout the arcology and severely limiting the water supply.
		It will take @@.red;time and money to repair the damage.@@
		<<set $garrison.waterwayTime = $repairTime + random(1) - $fort.waterway, IncreasePCSkills('engineering', 0.1)>>
		<<run cashX(-2000, "war")>>
	<<else>>
		While the water management complex was left defenseless without a garrison, there was no attempt at sabotage. Let's hope we'll always be this lucky.
	<</if>>
<<else>>
	The garrison assigned to the water management complex protected it from the sabotage attempt of the rebels.
<</if>>
<<if $garrison.assistant == 0>>
	<<if random(1,100) <= (75 - ($fort.assistant * 25))>>
		Unfortunately during the fighting a group of slaves infiltrated the facility housing $assistantName's mainframe and sabotaged it. Without its AI the arcology will be next to impossible to manage.
		It will take @@.red;time and money to repair the damage.@@
		<<set $garrison.assistantTime = $repairTime + random(1) - $fort.assistant, IncreasePCSkills('engineering', 0.1)>>
		<<run cashX(-2000, "war")>>
	<<else>>
		While the $assistantName's mainframe was left defenseless without a garrison, there was no attempt at sabotage. Let's hope we'll always be this lucky.
	<</if>>
<<else>>
	The garrison assigned to the facility housing $assistantName's mainframe prevented any sabotage attempt.
<</if>>
<<if $garrison.penthouse == 1 && $Bodyguard != 0>>
	<<setLocalPronouns $Bodyguard 2>>
	The garrison assigned to the penthouse together with your loyal bodyguard stopped all assaults against your penthouse with ease.
<<elseif $Bodyguard != 0>>
	<<if random(1,100) <= 75>>
		During the fighting a group of slaves assaulted the penthouse. Your bodyguard, $Bodyguard.slaveName, stood strong against the furious attack.
		<<set _woundChance = 0>>
		<<if $PC.career == "mercenary" || $PC.career == "gang">>
			<<set _woundChance -= 5>>
		<<elseif $PC.warfare >= 75>>
			<<set _woundChance -= 3>>
		<</if>>
		<<if $personalArms >= 1>>
			<<set _woundChance -= 5>>
		<</if>>
		<<if $PC.physicalAge >= 60>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.belly > 5000>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.boobsBonus >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.butt >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.preg >= 30>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.balls == 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.ballsImplant >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if random(1,100) <= _woundChance>>
			A lucky shot managed to find its way to you, leaving a painful, but thankfully not lethal, wound.
			<<set $PCWounded = 1>>
			<<set $PCWoundCooldown = 3>>
		<<else>>
			Fortunately you managed to avoid injury.
		<</if>>
		<<if $Concubine != 0>>
			<<setLocalPronouns $Concubine>>
			<<set _woundChance = 0>>
			<<if $Concubine.skill.combat == 1>>
				<<set _woundChance -= 2>>
			<</if>>
			<<if $Concubine.amp >= -4>>
				<<set _woundChance -= 1>>
			<</if>>
			<<if $Concubine.health >= 50>>
				<<set _woundChance -= 1>>
			<</if>>
			<<if $Concubine.weight > 130>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.muscles < -30>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.eyes <= -2>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.heels == 1>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.boobs >= 1400>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.butt >= 6>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.belly >= 10000>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.dick >= 8>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.balls >= 8>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.intelligence+$Concubine.intelligenceImplant < -95>>
				<<set _woundChance += 1>>
			<</if>>
			<<set _woundChance *= random(2,4)>>
			<<if random(1,100) <= _woundChance>>
				Your concubine was unfortunately caught in the crossfire and
				<<set $woundType = random(1,10)>>
				<<if $woundType == 1>>
					a splinter pierced $his throat, severing $his vocal cords.
					<<set $Concubine.voice = 0>>
				<<elseif $woundType == 2>>
					a splinter hit $his face, severely damaging $his eyes.
					<<set $Concubine.eyes = -2>>
				<<elseif $woundType == 3>>
					an explosion near $him caused the loss of all $his limbs.
					<<set $Concubine.amp = 1>>
				<<elseif $woundType >= 4>>
					a stray shot severely wounded $him.
					<<if $Concubine.health >= -60>>
						<<set $Concubine.health -= 30>>
					<<else>>
						<<set $Concubine.health = -90>>
					<</if>>
				<</if>>
			<</if>>
		<</if>>
		<<set _woundChance = 0>>
		<<if $Bodyguard.skill.combat == 1>>
			<<set _woundChance -= 2>>
		<</if>>
		<<if $Bodyguard.amp >= -4>>
			<<set _woundChance -= 1>>
		<</if>>
			<<if $Bodyguard.health >= 50>>
			<<set _woundChance -= 1>>
		<</if>>
		<<if $Bodyguard.weight > 130>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.muscles < -30>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.eyes <= -2>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.heels == 1>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.boobs >= 1400>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.butt >= 6>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.belly >= 10000>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.dick >= 8>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.balls >= 8>>
			<<set _woundChance += 1>>
		<</if>>
		<<if $Bodyguard.intelligence+$Bodyguard.intelligenceImplant < -95>>
			<<set _woundChance += 1>>
		<</if>>
		<<set _woundChance *= random(2,4)>>
		<<if random(1,100) <= _woundChance>>
			During one of the assaults your bodyguard was hit.
			<<set $woundType = random(1,10)>>
			<<if $woundType == 1>>
				A splinter pierced _his2 throat, severing _his2 vocal cords.
				<<set $Bodyguard.voice = 0>>
			<<elseif $woundType == 2>>
				A splinter hit _his2 face, severely damaging _his2 eyes.
				<<set $Bodyguard.eyes = -2>>
			<<elseif $woundType == 3>>
				An explosion near _him2 caused the loss of all _his2 limbs.
				<<set $Bodyguard.amp = 1>>
			<<elseif $woundType >= 4>>
				A stray shot severely wounded _him2.
				<<if $Bodyguard.health >= -60>>
					<<set $Bodyguard.health -= 30>>
				<<else>>
					<<set $Bodyguard.health = -90>>
				<</if>>
			<</if>>
		<</if>>
		The damage to the structure will be @@.red;costly to repair.@@
		<<= IncreasePCSkills('engineering', 0.1)>>
		<<run cashX(-2000, "war")>>
	<<else>>
		While the penthouse was left without a sizable garrison, there was no dangerous assault against it. Let's hope we'll always be this lucky.
	<</if>>
<<elseif $garrison.penthouse == 1>>
	<<if random(1,100) <= 75>>
		During the fighting a group of slaves assaulted the penthouse. The garrison stood strong against the furious attack.
		<<set _woundChance = 0>>
		<<if $PC.career == "mercenary" || $PC.career == "gang">>
			<<set _woundChance -= 5>>
		<<elseif $PC.warfare >= 75>>
			<<set _woundChance -= 3>>
		<</if>>
		<<if $personalArms >= 1>>
			<<set _woundChance -= 5>>
		<</if>>
		<<if $PC.physicalAge >= 60>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.belly > 5000>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.boobsBonus >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.butt >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.preg >= 30>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.balls == 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.ballsImplant >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<set _woundChance *= random(1,2)>>
		<<if random(1,100) <= _woundChance>>
			A lucky shot managed to find its way to you, leaving a painful, but thankfully nonlethal, wound.
			<<set $PCWounded = 1>>
			<<set $PCWoundCooldown = 3>>
		<<else>>
			Fortunately you managed to avoid injury.
		<</if>>
		<<if $Concubine != 0>>
			<<setLocalPronouns $Concubine>>
			<<set _woundChance = 0>>
			<<if $Concubine.skill.combat == 1>>
				<<set _woundChance -= 2>>
			<</if>>
			<<if $Concubine.amp >= -4>>
				<<set _woundChance -= 1>>
			<</if>>
			<<if $Concubine.health >= 50>>
				<<set _woundChance -= 1>>
			<</if>>
			<<if $Concubine.weight > 130>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.muscles < -30>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.eyes <= -2>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.heels == 1>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.boobs >= 1400>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.butt >= 6>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.belly >= 10000>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.dick >= 8>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.balls >= 8>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.intelligence+$Concubine.intelligenceImplant < -95>>
				<<set _woundChance += 1>>
			<</if>>
			<<set _woundChance *= random(2,4)>>
			<<if random(1,100) <= _woundChance>>
				Your concubine was unfortunately caught in the crossfire and
				<<set $woundType = random(1,10)>>
				<<if $woundType == 1>>
					a splinter pierced $his throat, severing $his vocal cords.
					<<set $Concubine.voice = 0>>
				<<elseif $woundType == 2>>
					a splinter hit $his face, severely damaging $his eyes.
					<<set $Concubine.eyes = -2>>
				<<elseif $woundType == 3>>
					an explosion near $him caused the loss of all $his limbs.
					<<set $Concubine.amp = 1>>
				<<elseif $woundType >= 4>>
					a stray shot severely wounded $him.
					<<if $Concubine.health >= -60>>
						<<set $Concubine.health -= 30>>
					<<else>>
						<<set $Concubine.health = -90>>
					<</if>>
				<</if>>
			<</if>>
		<</if>>
		The damage to the structure will be @@.red;costly to repair.@@
		<<= IncreasePCSkills('engineering', 0.1)>>
		<<run cashX(-2000, "war")>>
	<<else>>
		There was no sizable assault against the penthouse. Let's hope we'll always be this lucky.
	<</if>>
<<else>>
	<<if random(1,100) <= 75>>
		During the fighting a group of slaves assaulted the penthouse. Isolated and alone, you stood strong against the furious attack.
		<<set _woundChance = 0>>
		<<if $PC.career == "mercenary" || $PC.career == "gang">>
			<<set _woundChance -= 5>>
		<<elseif $PC.warfare >= 75>>
			<<set _woundChance -= 3>>
		<</if>>
		<<if $personalArms >= 1>>
			<<set _woundChance -= 5>>
		<</if>>
		<<if $PC.physicalAge >= 60>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.belly > 5000>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.boobsBonus >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.butt >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.preg >= 30>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.balls == 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<if $PC.ballsImplant >= 2>>
			<<set _woundChance += random(1,5)>>
		<</if>>
		<<set _woundChance *= random(1,2)>>
		<<if random(1,100) <= _woundChance>>
			A lucky shot managed to find its way to you, leaving a painful, but thankfully nonlethal, wound.
			<<set $PCWounded = 1>>
			<<set $PCWoundCooldown = 3>>
		<<else>>
			Fortunately you managed to avoid injury.
		<</if>>
		<<if $Concubine != 0>>
			<<setLocalPronouns $Concubine>>
			<<set _woundChance = 0>>
			<<if $Concubine.skill.combat == 1>>
				<<set _woundChance -= 2>>
			<</if>>
			<<if $Concubine.amp >= -4>>
				<<set _woundChance -= 1>>
			<</if>>
			<<if $Concubine.health >= 50>>
				<<set _woundChance -= 1>>
			<</if>>
			<<if $Concubine.weight > 130>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.muscles < -30>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.eyes <= -2>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.heels == 1>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.boobs >= 1400>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.butt >= 6>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.belly >= 10000>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.dick >= 8>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.balls >= 8>>
				<<set _woundChance += 1>>
			<</if>>
			<<if $Concubine.intelligence+$Concubine.intelligenceImplant < -95>>
				<<set _woundChance += 1>>
			<</if>>
			<<set _woundChance *= random(2,4)>>
			<<if random(1,100) <= _woundChance>>
				Your concubine was unfortunately caught in the crossfire and
				<<set $woundType = random(1,10)>>
				<<if $woundType == 1>>
					a splinter pierced $his throat, severing $his vocal cords.
					<<set $Concubine.voice = 0>>
				<<elseif $woundType == 2>>
					a splinter hit $his face, severely damaging $his eyes.
					<<set $Concubine.eyes = -2>>
				<<elseif $woundType == 3>>
					an explosion near $him caused the loss of all $his limbs.
					<<set $Concubine.amp = 1>>
				<<elseif $woundType >= 4>>
					a stray shot severely wounded $him.
					<<if $Concubine.health >= -60>>
						<<set $Concubine.health -= 30>>
					<<else>>
						<<set $Concubine.health = -90>>
					<</if>>
				<</if>>
			<</if>>
		<</if>>
	<<else>>
		There was no sizable assault against the penthouse. Let's hope we'll always be this lucky.
	<</if>>
<</if>>

<<include "unitsRebellionReport">>

/* resets variables and flags */
<<recalcManpower>>
<<recalcUnits>>
<<set $attackTroops = 0>>
<<set $attackEquip = 0>>
<<set $enemyLosses = 0>>
<<set $losses = 0>>
<<set $battleTurns = 0>>
<<set $irregulars = 0>>
<<set $deployingMilitia = 0>>
<<set $deployingSlaves = 0>>
<<set $deployingMercs = 0>>
<<if $slaveRebellion == 1>>
	<<set $slaveProgress = 0>>
	<<set $citizenProgress = Math.clamp($citizenProgress - random(50,100), 0, 100)>>
<<else>>
	<<set $citizenProgress = 0>>
	<<set $slaveProgress = Math.clamp($slaveProgress - random(50,100), 0, 100)>>
<</if>>
<<set $slaveRebellion = 0>>
<<set $citizenRebellion = 0>>
<<set $tension = Math.clamp($tension - random(50,100), 0, 100)>>


code:
:: riotControlCenter [nobr]

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

Riot Control Center

The riot control center opens its guarded doors to you. The great chamber inside is dominated by massive screens filled with vital information and propaganda being tested.

<<if $tension <= 33>>
	Tensions in the arcology are low. Political and ideological opposition against the arcology owner is almost unheard of.
<<elseif $tension <= 66>>
	Tensions in the arcology are rising, political and ideological opposition against the arcology owner are becoming a part of the daily life of the arcology.
<<else>>
	Tensions are high. Opposition to the arcology owner is a sentiment shared by many and armed resistance is on the rise.
<</if>>

<<if $riotUpgrades.freeMedia == 0>>
	[[Provide free media access in all the arcology|riotControlCenter][cashX(forceNeg(Math.trunc(5000*$upgradeMultiplierArcology)), "capEx"), $riotUpgrades.freeMedia = 1, $riotUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology))>>. Will slowly lower tensions in the arcology, but will incur in upkeep costs.//
<<else>>
	You are providing free access to many mass media in the arcology.
	<<if $riotUpgrades.freeMedia < 5>>

<<link "Invest more resources in the free media project" "riotControlCenter">>
			<<set $riotUpgrades.freeMedia += 1>>
			<<run cashX(forceNeg(((5000 * $upgradeMultiplierArcology * ($riotUpgrades.freeMedia + 1)*$HackingSkillMultiplier))), "capEx")>>
			<<= IncreasePCSkills('hacking', 0.5)>>
			<<set $riotUpkeep += $upgradeUpkeep>>
		<</link>>

Invest more resources into the project to increase its effectiveness.

//Costs <<print cashFormat(Math.trunc((5000 * $upgradeMultiplierArcology * ($riotUpgrades.freeMedia + 1)*$HackingSkillMultiplier)))>>. Will accelerate the tension decay, but will increase upkeep costs.//
	<<else>>
		You upgraded your free media scheme to its limits.
	<</if>>
<</if>>

<<if $slaveProgress <= 25>>
	There is very low unrest between slaves in the arcology. The chances of a rebellion igniting are extremely low.
<<elseif $slaveProgress <= 50>>
	There is some unrest between the slaves. No major movement is forming yet, but it might be time to consider preventive measures.
<<elseif $slaveProgress <= 75>>
	Unrest is getting high between the slaves of the arcology. Preventive measures are necessary if we want to prevent a violent rebellion.
<<else>>
	Unrest is extremely high between slaves. The chances of a rebellion happening in the near future are extremely high.
<</if>>

<<if $citizenProgress <= 25>>
	There is very low unrest between the citizens of the arcology. The chances of a rebellion igniting are extremely low.
<<elseif $citizenProgress <= 50>>
	There is some unrest between the citizens. No major movement is forming yet, but it might be time to consider preventive measures.
<<elseif $citizenProgress <= 75>>
	Unrest is getting high between the citizens of the arcology. Preventive measures are necessary if we want to prevent a violent rebellion.
<<else>>
	Unrest is extremely high between citizens. The chances of a rebellion happening in the near future are extremely high.
<</if>>

<<if $riotUpgrades.rapidUnit == 0>>
	[[Create rapid deployment riot units|riotControlCenter][cashX(forceNeg(Math.trunc(7500*$upgradeMultiplierArcology)), "capEx"), $riotUpgrades.rapidUnit = 1, $riotUpkeep += $upgradeUpkeep]]

//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology))>>. Will allow spending authority or reputation to lower the progress of rebellions.//
<<else>>
	You created a rapid deployment riot unit.
	<<if $riotUpgrades.rapidUnit < 5>>

<<link "Invest more resources in the rapid deployment unit" "riotControlCenter">>
			<<set $riotUpgrades.rapidUnit += 1>>
			<<run cashX(forceNeg(5000 * $upgradeMultiplierArcology * ($riotUpgrades.rapidUnit + 1)), "capEx")>>
			<<set $riotUpkeep += $upgradeUpkeep>>
		<</link>>

Invest more resources into the project to increase its effectiveness.

//Costs <<print cashFormat(Math.trunc(5000 * $upgradeMultiplierArcology * ($riotUpgrades.rapidUnit + 1)))>>. Will lower action costs.//
	<<else>>

You upgraded your rapid deployment unit to its limits.
	<</if>>
	<<if $riotUpgrades.rapidUnitSpeed < 2>>

<<link "Enhance the internal informants network" "riotControlCenter">>
			<<set $riotUpgrades.rapidUnitSpeed += 1>>
			<<run cashX(forceNeg(5000 * $upgradeMultiplierArcology * ($riotUpgrades.rapidUnitSpeed + 1)), "capEx")>>
			<<set $riotUpkeep += $upgradeUpkeep>>
		<</link>>

Invest more resources into the effectiveness of the informants network.

//Costs <<print cashFormat(Math.trunc(5000 * $upgradeMultiplierArcology * ($riotUpgrades.rapidUnitSpeed + 1)))>>. Will reduce cooldown of the rapid deployment riot unit.//
	<<else>>

You enhanced your informants network to its limits.
	<</if>>

You can send out the squad to slow down the progress of hostile groups within the arcology:
	<<link "spend authority" "riotControlCenter">>
		<<set $riotUpgrades.rapidUnitCost = 0>>
	<</link>> |
	<<link "spend reputation" "riotControlCenter">>
		<<set $riotUpgrades.rapidUnitCost = 1>>
	<</link>>

	Your
	<<if $riotUpgrades.rapidUnitCost == 0>>
		authority
	<<else>>
		reputation
	<</if>>
	will be leveraged to suppress the rebels.

		<<if $sentUnitCooldown == 0>>

<<link "Deploy the unit against slaves rebel leaders">>
				<<if $riotUpgrades.rapidUnitCost == 0>>
					<<set $authority -= 1000 + 50 * $riotUpgrades.rapidUnit>>
				<<else>>
					<<run repX(forceNeg(1000 + 50 * $riotUpgrades.rapidUnit), "war")>>
				<</if>>
				<<set _change = random(15) + random(1,2) * $riotUpgrades.rapidUnit>>
				<<set $slaveProgress = Math.clamp($slaveProgress - _change,0,100)>>
				<<set $sentUnitCooldown = 3 - $riotUpgrades.rapidUnitSpeed>>
				<<replace "#result">>
					Slave rebellion progress set back by <<print _change>>%.
					The unit will be able to deployed again in $sentUnitCooldown weeks.
				<</replace>>
			<</link>>

<<link "Deploy the unit against citizens rebel leaders">>
				<<if $riotUpgrades.rapidUnitCost == 0>>
					<<set $authority -= 1000 + 50 * $riotUpgrades.rapidUnit>>
				<<else>>
					<<run repX(forceNeg(1000 + 50 * $riotUpgrades.rapidUnit), "war")>>
				<</if>>
				<<set _change = random(15) + random(1,2) * $riotUpgrades.rapidUnit>>
				<<set $citizenProgress = Math.clamp($citizenProgress - _change,0,100)>>
				<<set $sentUnitCooldown = 3 - $riotUpgrades.rapidUnitSpeed>>
				<<replace "#result">>
					Citizen rebellion progress set back by <<print _change>>%.
					The unit will be able to deployed again in $sentUnitCooldown weeks.
				<</replace>>
			<</link>>
		<<else>>

The unit cannot be deployed again for $sentUnitCooldown weeks.
		<</if>>

<</if>>

<<if $brainImplant < 106>>
	<<if $brainImplantProject == 0>>
		<<link "Start secretly installing brain implants in your citizens and resident slaves" "riotControlCenter">>
			<<set $brainImplantProject = 1>>
			<<set $brainImplant = 0>>
			<<set $riotUpkeep += 5000>>
		<</link>>

//Will take weeks of work and will cost <<print cashFormat(5000)>> each week, but once finished rebellions will progress a lot slower.//
	<<elseif $brainImplantProject < 5>>
		<<link "Invest more resources in the brain implant project" "riotControlCenter">>
			<<set $brainImplantProject += 1>>
			<<run cashX(forceNeg(50000 * $upgradeMultiplierArcology * $brainImplantProject*$HackingSkillMultiplier), "capEx")>>
			<<= IncreasePCSkills('hacking', 1)>>
			<<set $riotUpkeep += 5000>>
		<</link>>

Invest more resources into the project to increase its speed.

//One-time cost of <<print cashFormat(Math.trunc(50000 * $upgradeMultiplierArcology * $brainImplantProject*$HackingSkillMultiplier))>> with an additional <<print cashFormat(5000)>> each week in maintenance. Will shorten the time required to complete the project.//
	<<else>>
		You sped up the project to its maximum.
	<</if>>
	<<if $brainImplant != -1>>

The great brain implant project is underway. Estimated time to completion: <<print Math.trunc((100 - $brainImplant) / $brainImplantProject)>>
	<</if>>
<<else>>
	The great brain implant project is completed, rebellions against you will be extremely difficult to organize.
<</if>>

<<if $advancedRiotEquip == 0>>
	<<link "Develop advanced anti-riot equipment" "riotControlCenter">>
		<<set $advancedRiotEquip = 1>>
		<<run cashX(forceNeg(30000 * $upgradeMultiplierTrade), "capEx")>>
	<</link>>

//Costs <<print cashFormat(30000 * $upgradeMultiplierTrade)>>. Will allow the selection of advanced riot equipment in case of a rebellion, which will let your troops fight at full effectiveness while doing reduced collateral damage.//
<<else>>
	You developed advanced riot equipment, which allows your troops to fight within the confines of your arcology without the fear of doing major collateral damage.
<</if>>

<<if $fort.reactor == 0>>
	<<link "Reinforce the reactor complex" "riotControlCenter">>
		<<set $fort.reactor = 1>>
		<<run cashX(forceNeg(10000 * $upgradeMultiplierArcology), "capEx")>>
	<</link>>

//Costs <<print cashFormat(10000 * $upgradeMultiplierArcology)>>. Will add protection to the reactor building, making it less likely to be damaged and speeding up repairs if our defensive efforts should fail.//
<<else>>
	You have installed additional protection layers and redundant systems in the reactor complex.
<</if>>

<<if $fort.waterway == 0>>
	<<link "Reinforce the waterways" "riotControlCenter">>
		<<set $fort.waterway = 1>>
		<<run cashX(forceNeg(10000 * $upgradeMultiplierArcology), "capEx")>>
	<</link>>

//Costs <<print cashFormat(10000 * $upgradeMultiplierArcology)>>. Will add protection to the waterways, making it less likely to be damaged and speeding up repairs if our defensive efforts should fail.//
<<else>>
	You have installed additional protection layers and redundant systems in the waterways.
<</if>>

<<if $fort.assistant == 0>>
	<<link "Reinforce the assistant CPU core" "riotControlCenter">>
		<<set $fort.assistant = 1>>
		<<run cashX(forceNeg(10000 * $upgradeMultiplierArcology), "capEx")>>
	<</link>>

//Costs <<print cashFormat(10000 * $upgradeMultiplierArcology)>>. Will add protection to the assistant CPU core, making it less likely to be damaged and speeding up repairs if our defensive efforts should fail.//
<<else>>
	You have installed additional protection layers and redundant systems in the assistant CPU core.
<</if>>

<<if $SF.Toggle && $SF.Active >= 1>>
	<<if $SFSupportLevel >= 4 && !$SFGear && $SF.Squad.Armoury >= 8>> <<= App.SF.Count()>>

 <<link "Give the riot unit access to the combat armor suits of $SF.Lower.""riotControlCenter">> <<set $SFGear = 1,$riotUpkeep += 15000,cashX(forceNeg(Math.ceil(500000*_Env*(1.15+($SF.Squad.Armoury/10)))), "capEx")>> <</link>>

//Costs <<print cashFormat(Math.ceil(500000*_Env*(1.15+($SF.Squad.Armoury/10))))>>
	<<else>>

//You have given the riot unit access to the combat armor suits of $SF.Lower.//
	<</if>>
<</if>>