From be7b6ad486cc9701e2444c07e52074c5841b06c8 Mon Sep 17 00:00:00 2001
From: hexall90 <hexall90@gmail.com>
Date: Tue, 31 Oct 2017 21:29:11 +0100
Subject: [PATCH] Merge remote-tracking branch 'upstream/pregmod-master' into
 SecExp

updating fork

finished rebellion logic
---
 src/SecExp/SecExpBackwardCompatibility.tw |  20 +-
 src/SecExp/attackHandler.tw               |   2 +-
 src/SecExp/rebellionGenerator.tw          |  29 +-
 src/SecExp/rebellionHandler.tw            | 647 ++++++++--------------
 src/SecExp/rebellionOptions.tw            | 120 ++--
 src/SecExp/rebellionReport.tw             |  17 +
 src/SecExp/riotControlCenter.tw           |   6 +-
 src/SecExp/secBarracks.tw                 |   6 +-
 src/SecExp/secExpOptions.tw               |  41 +-
 src/SecExp/secInit.tw                     |   8 +-
 10 files changed, 394 insertions(+), 502 deletions(-)

diff --git a/src/SecExp/SecExpBackwardCompatibility.tw b/src/SecExp/SecExpBackwardCompatibility.tw
index 9b09dd9c7f2..3061514180c 100644
--- a/src/SecExp/SecExpBackwardCompatibility.tw
+++ b/src/SecExp/SecExpBackwardCompatibility.tw
@@ -82,7 +82,10 @@
 <<set $majorBattleGameOver = 1>>
 <</if>>
 <<if ndef $rebellionsEnabled>>
-<<set $rebellionsEnabled = 0>>
+<<set $rebellionsEnabled = 1>>
+<</if>>
+<<if ndef $forceRebellion>>
+<<set $forceRebellion = 0>>
 <</if>>
 
 /* edicts */
@@ -321,6 +324,21 @@
 <<if ndef $notInvolved>>
 <<set $notInvolved = 0>>
 <</if>>
+<<if ndef $engageRule>>
+<<set $engageRule = 0>>
+<</if>>
+<<if ndef $irregulars>>
+<<set $irregulars = 0>>
+<</if>>
+<<if ndef $rebellingMilitia>>
+<<set $rebellingMilitia = 0>>
+<</if>>
+<<if ndef $rebellingSlaves>>
+<<set $rebellingSlaves = 0>>
+<</if>>
+<<if ndef $rebellingMercs>>
+<<set $rebellingMercs = 0>>
+<</if>>
 <<if ndef $garrison>>
 <<set $garrison = {
 	penthouse: 0,
diff --git a/src/SecExp/attackHandler.tw b/src/SecExp/attackHandler.tw
index b025d37e906..ff9f8a1131e 100644
--- a/src/SecExp/attackHandler.tw
+++ b/src/SecExp/attackHandler.tw
@@ -944,7 +944,7 @@
 <</if>>
 <<if _SFMod < 0.5>>
 	<<set _SFMod = 0.5>>
-<<<elseif _SFMod > 1.5>>
+<<elseif _SFMod > 1.5>>
 	<<set _SFMod = 1.5>>
 <</if>>
 <<set _morale = ($secBotsMorale * $deployingBots + $militiaBaseMorale * _militiaMod * $deployingMilitia + $slaveBaseMorale * _slaveMod * $deployingSlaves + $mercBaseMorale * _mercMod * $deployingMercs + $SFBaseMorale * $SFIntervention * _SFMod) / ($deployingBots + $deployingMilitia +$deployingSlaves + $deployingMercs + $SFIntervention)>>
diff --git a/src/SecExp/rebellionGenerator.tw b/src/SecExp/rebellionGenerator.tw
index 3de464467dc..17023090c91 100644
--- a/src/SecExp/rebellionGenerator.tw
+++ b/src/SecExp/rebellionGenerator.tw
@@ -176,8 +176,9 @@
 	<</if>>
 <</if>>
 
-/* testing */
-<<set $slaveRebellion = 1>>
+<<if $forceRebellion == 1>>
+	<<set $slaveRebellion = 1>>
+<</if>>
 
 <br>Debug: slave chance: _slave
 <br>Debug: citizen chance: _citizen
@@ -192,10 +193,14 @@
 	<<set $lastRebellionWeeks = 0>>
 	<<set $leadingTroops = "assistant">>
 	/* calc how many slaves participate */
-	<<set _authFactor = $authority / 20000>>
-	<<set _repFactor  = $rep / 20000>>
-	<<set _notInvolved = $ASlaves * (1 - Math.clamp(_repFactor,0.4,0.6))>> 						/* a percentage of slave will not be involved in the rebellion, depending on reputation, the higher the more slaves stand aside */
-	<<set $rebels = ($ASlaves - _notInvolved) * (1 - Math.clamp(_authFactor,0.4,0.6))>>		/* a percentage of slave will actively participate in the rebellion, depending on authority, the higher the fewer slaves join */
+	<<set _authFactor = Math.clamp($authority / 20000,0.4,0.6)>>
+	<<set _repFactor  = Math.clamp($rep / 20000,0.4,0.6)>>
+	<<set $notInvolved = Math.round(($ASlaves * (1 - _repFactor)))>> 								/* a percentage of slave will not be involved in the rebellion, depending on reputation, the higher the more slaves stand aside */
+	<<set $notInvolved = Math.clamp($notInvolved - random(1,100),0,$ASlaves)>>
+	<<set $attackTroops = Math.round((($ASlaves - $notInvolved) * (1 - _authFactor)))>>				/* a percentage of slave will actively participate in the rebellion, depending on authority, the higher the fewer slaves join */
+	<<set $attackTroops = Math.clamp($attackTroops - random(1,100),0,$ASlaves)>>
+	<<set $irregulars = Math.round((($ACitizens  - $ACitizens * (1 - Math.clamp(_repFactor,0.5,0.7))) * (1 - Math.clamp(_repFactor,0.4,0.6))) * 0.2)>>		/* citizens participating on the side of the player.
+	<<set $irregulars = Math.clamp($irregulars - random(1,100),0,$ACitizens)>>
 	/* calc if units participate */
 	<<for _i = 0; _i < $slaveUnits.length; _i++>>
 		<<if $slaveUnits[_i].loyalty < 3>>
@@ -219,15 +224,19 @@
 			<</if>>
 		<</if>>
 	<</for>>
-	<<set $rebelsEquip = $weaponsLaw + 1>>	
+	<<set $attackEquip = Math.clamp($weaponsLaw + random(-1,1),0,4)>>
 <<elseif $citizenRebellion == 1>>
 	<<set $lastRebellionWeeks = 0>>
 	<<set $leadingTroops = "assistant">>
-	/* calc how many slaves participate */
+	/* calc how many citizens participate */
 	<<set _authFactor = $authority / 20000>>
 	<<set _repFactor  = $rep / 20000>>
-	<<set $notInvolved = $ACitizens * (1 - Math.clamp(_repFactor,0.4,0.6))>> 						/* a percentage of citizens will not be involved in the rebellion, depending on reputation, the higher the more slaves stand aside */
-	<<set $attackTroops = ($ACitizens - $notInvolved) * (1 - Math.clamp(_authFactor,0.4,0.6))>>		/* a percentage of citizens will actively participate in the rebellion, depending on authority, the higher the fewer slaves join */
+	<<set $notInvolved = Math.round($ACitizens * (1 - Math.clamp(_repFactor,0.5,0.7)))>> 							/* a percentage of citizens will not be involved in the rebellion, depending on reputation, the higher the more slaves stand aside */
+	<<set $notInvolved = Math.clamp($notInvolved - random(1,100),0,$ACitizens)>>
+	<<set $attackTroops = Math.round(($ACitizens - $notInvolved) * (1 - Math.clamp(_authFactor,0.4,0.6)))>>			/* a percentage of citizens will actively participate in the rebellion, depending on authority, the higher the fewer slaves join */
+	<<set $attackTroops = Math.clamp($attackTroops - random(1,100),0,$ACitizens)>>
+	<<set $irregulars = Math.round((($ACitizens - $notInvolved) * (1 - Math.clamp(_repFactor,0.4,0.6))) * 0.5)>>	/* citizens joining the player */
+	<<set $irregulars = Math.clamp($irregulars - random(1,100),0,$ACitizens)>>
 	/* calc if units participate */
 	<<for _i = 0; _i < $militiaUnits.length; _i++>>
 		<<if $militiaUnits[_i].loyalty < 3>>
diff --git a/src/SecExp/rebellionHandler.tw b/src/SecExp/rebellionHandler.tw
index 8a80ef5ff64..8948fb63459 100644
--- a/src/SecExp/rebellionHandler.tw
+++ b/src/SecExp/rebellionHandler.tw
@@ -3,6 +3,7 @@
 <<set $nextButton = " ", $nextLink = "attackReport", $showEncyclopedia = 0>>
 
 <<set _turn = 0>>
+<<set _turns = $maxTurns * 2>>
 <<set _attack = 0>>
 <<set _defense = 0>>
 <<set _morale = 0>>
@@ -15,403 +16,49 @@
 <<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 _atkMod = 1>>
-<<set _defMod = 1>>
-<<set _militiaMod = 1>>
-<<set _slaveMod = 1>>
-<<set _mercMod = 1>>
-<<set _enemyMod = 1>>
-<<set _SFMod = 1>>
 <<set _expBonus = 0>>
+<<set _irregularMod = 0>>
 <<set _armyMod = 0>>
 
-<<if $leadingTroops == "PC">>
-	<<if $authority <= 2500 && $authority > 1000>>
-		<<set _slaveMod -= 0.10>>
-	<<elseif $authority <= 1000>>
-		<<set _slaveMod -= 0.25>>
-	<<elseif $authority >= 5000 && $authority < 15000>>
-		<<set _slaveMod += 0.10>>
-	<<elseif $authority >= 15000>>
-		<<set _slaveMod += 0.25>>
-	<</if>>
-	<<if $PC.career == "escort" || $PC.career == "servant">>
-		<<set _slaveMod += 0.10>>
-	<<elseif $PC.career == "slaver">>
-		<<set _slaveMod -= 0.10>>
-	<</if>>
-	<<if $rep <= 2500 && $rep > 1000>>
-		<<set _militiaMod -= 0.10>>
-	<<elseif $rep <= 1000>>
-		<<set _militiaMod -= 0.25>>
-	<<elseif $rep >= 5000 && $rep < 15000>>
-		<<set _militiaMod += 0.10>>
-	<<elseif $rep >= 15000>>
-		<<set _militiaMod += 0.25>>
-	<</if>>
-	<<if $PC.career == "celebrity" || $PC.career == "capitalist">>
-		<<set _militiaMod += 0.10>>
-	<<elseif $PC.career == "gang" || $PC.career == "escort">>
-		<<set _militiaMod -= 0.10>>
-	<</if>>
-	<<if $mercLoyalty <= 25>>
-		<<set _mercMod -= 0.10>>
-	<<elseif $mercLoyalty <= 10>>
-		<<set _mercMod -= 0.25>>
-	<<elseif $mercLoyalty >= 50 && $mercLoyalty < 75>>
-		<<set _mercMod += 0.10>>
-	<<elseif $mercLoyalty >= 75>>
-		<<set _mercMod += 0.25>>
-	<</if>>
-	<<if $PC.career == "mercenary">>
-		<<set _mercMod += 0.10>>
-		<<set _SFMod += 0.10>>
-	<<elseif $PC.career == "wealth" || $PC.career == "servant">>
-		<<set _mercMod -= 0.10>>
-		<<set _SFMod -= 0.10>>
-	<</if>>
-	<<if $rep >= 15000>>
-		<<set _enemyMod -= 0.10>>
-	<</if>>
-	<<if $PC.warfare <= 25 && $PC.warfare > 10>>
-		<<set _atkMod -= 0.15>>
-	<<elseif $PC.warfare <= 10>>
-		<<set _atkMod -= 0.20>>
-		<<set _defMod -= 0.10>>
-	<<elseif $PC.warfare >= 50 && $PC.warfare >= 50>>
-		<<set _atkMod += 0.15>>
-	<<elseif $PC.warfare >= 75>>
-		<<set _atkMod += 0.20>>
-		<<set _defMod += 0.10>>
-	<</if>>
-	/* 80% chance of increasing warfare */
-	<<if $PC.warfare < 100 && random(1,100) <= 80>>
-		<<set $gainedWarfare = 1>>
-		<<set $PC.warfare += 10>>
-		<<set $PC.warfare = Math.clamp($PC.warfare,-100,100)>>
-	<</if>>
-		/* does the PC get wounded? */
-	<<if $PC.career == "mercenary" || $PC.career == "gang">>
-		<<set _woundChance -= 3>>
-	<</if>>
-	<<if $PC.physicalAge >= 60>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $PC.belly > 5000>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $PC.boobsBonus >= 2>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $PC.butt >= 2>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $PC.preg >= 30>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $PC.balls == 2>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $PC.ballsImplant >= 2>>
-		<<set _woundChance += 1>>
-	<</if>>	
-	<<if random(1,100) <= _woundChance>>
-		<<set $leaderWounded = 1>>
-		<<set _militiaMod -= 0.2>>
-		<<set _slaveMod -= 0.2>>
-		<<set _mercMod -= 0.2>>
-		<<set _SFMod -= 0.2>>
-		<<set _enemyMod += 0.2>>
-		<<set $PCWounded = 1>>
-	<</if>>
-<<elseif $leadingTroops == "assistant">>
-	<<if $rep < 10000 && $authority < 10000>>
-		<<set _militiaMod -= 0.15>>
-		<<set _slaveMod -= 0.15>>
-		<<set _mercMod -= 0.15>>
-		<<set _SFMod -= 0.15>>
-	<</if>>
-	<<if $assistantPower == 0>>
-		<<set _atkMod -= 0.10>>
-		<<set _defMod -= 0.10>>
-	<<elseif $assistantPower == 2>>
-		<<set _atkMod += 0.15>>
-		<<set _defMod += 0.15>>
-	<</if>>
-<<elseif $leadingTroops == "bodyguard">>
-	<<if $Bodyguard.devotion < -20>>
-		<<set _slaveMod -= 0.15>>
-	<<elseif $Bodyguard.devotion >= 50>>
-		<<set _slaveMod += 0.15>>
-	<</if>>
-	<<if ($rep < 10000 && $authority < 10000) || $Bodyguard.prestige < 1>>
-		<<set _militiaMod -= 0.15>>
-		<<set _mercMod -= 0.15>>
-		<<set _SFMod -= 0.15>>
-	<<elseif $Bodyguard.prestige >= 2>>
-		<<set _militiaMod += 0.10>>
-		<<set _mercMod += 0.10>>
-		<<set _SFMod += 0.10>>
-	<</if>>
-	<<if (setup.bodyguardCareers.includes($Bodyguard.career) || setup.HGCareers.includes($Bodyguard.career)) && $Bodyguard.intelligence == 3>>
-		<<set _atkMod += 0.25>>
-		<<set _defMod += 0.25>>
-	<<elseif $Bodyguard.intelligence == 3>>
-		<<set _atkMod += 0.20>>
-		<<set _defMod += 0.15>>
-	<<elseif (setup.bodyguardCareers.includes($Bodyguard.career) || setup.HGCareers.includes($Bodyguard.career)) && $Bodyguard.intelligence == 2>>
-		<<set _atkMod += 0.15>>
-		<<set _defMod += 0.10>>
-	<<elseif $Bodyguard.intelligence == 2>>
-		<<set _atkMod += 0.10>>
-		<<set _defMod += 0.10>>
-	<<elseif setup.bodyguardCareers.includes($Bodyguard.career) || setup.HGCareers.includes($Bodyguard.career) && $Bodyguard.intelligence >= 1>>
-		<<set _atkMod += 0.10>>
-		<<set _defMod += 0.05>>
-	<<elseif !(setup.bodyguardCareers.includes($Bodyguard.career) && setup.HGCareers.includes($Bodyguard.career)) || $Bodyguard.intelligence <= -2>>
-		<<set _atkMod -= 0.15>>
-		<<set _defMod -= 0.15>>
-	<<elseif $Bodyguard.intelligence <= -2>>
-		<<set _atkMod -= 0.15>>
-		<<set _defMod -= 0.10>>
-	<<elseif !(setup.bodyguardCareers.includes($Bodyguard.career) && setup.HGCareers.includes($Bodyguard.career)) || $Bodyguard.intelligence <= -1>>
-		<<set _atkMod -= 0.10>>
-		<<set _defMod -= 0.10>>
-	<<elseif $Bodyguard.intelligence <= -1>>
-		<<set _atkMod -= 0.10>>
-		<<set _defMod -= 0.05>>
-	<</if>>
-		/* does she get wounded? */
-	<<if $Bodyguard.combatSkill == 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.preg >= 30>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $Bodyguard.dick >= 8>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $Bodyguard.balls >= 8>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $Bodyguard.intelligence <= -3>>
-		<<set _woundChance += 1>>
-	<</if>>	
-	<<if random(1,100) <= _woundChance>>
-		<<set $leaderWounded = 1>>
-		<<set _militiaMod -= 0.2>>
-		<<set _slaveMod -= 0.2>>
-		<<set _mercMod -= 0.2>>
-		<<set _SFMod -= 0.2>>
-		<<set _enemyMod += 0.2>>
-		<<set $woundType = random(1,10)>>
-		<<if $woundType == 1>>
-			<<set $Bodyguard.voice = 0>>
-		<<elseif $woundType == 2>>
-			<<set $Bodyguard.eyes = -2>>
-		<<elseif $woundType == 3>>
-			<<set $Bodyguard.amp = 1>>
-		<<elseif $woundType >= 4>>
-			<<if $Bodyguard.health >= -60>>
-				<<set $Bodyguard.health -= 30>>
-			<<else>>
-				<<set $Bodyguard.health -= Math.abs(90 - $Bodyguard.health)>>
-			<</if>>
-		<</if>>
-	<</if>>
-	/* 60% chance of getting combat skill if not already have it */
-	<<if $Bodyguard.combatSkill == 0 && random(1,100) <= 60>>
-		<<set $gainedCombat = 1>>
-		<<set $Bodyguard.combatSkill = 1>>
-	<</if>>
-<<elseif $leadingTroops == "headGirl">>
-	<<if $HeadGirl.devotion < -20>>
-		<<set _slaveMod -= 0.15>>
-	<<elseif $HeadGirl.devotion > 51>>
-		<<set _slaveMod += 0.15>>
-	<</if>>
-	<<if ($rep < 10000 && $authority < 10000) || $HeadGirl.prestige < 1>>
-		<<set _militiaMod -= 0.15>>
-		<<set _mercMod -= 0.15>>
-		<<set _SFMod -= 0.15>>
-	<<elseif $HeadGirl.prestige >= 2>>
-		<<set _militiaMod += 0.10>>
-		<<set _mercMod += 0.10>>
-		<<set _SFMod += 0.10>>
-	<</if>>
-	<<if (setup.bodyguardCareers.includes($HeadGirl.career) || setup.HGCareers.includes($HeadGirl.career)) && $HeadGirl.intelligence == 3>>
-		<<set _atkMod += 0.25>>
-		<<set _defMod += 0.25>>
-	<<elseif $HeadGirl.intelligence == 3>>
-		<<set _atkMod += 0.20>>
-		<<set _defMod += 0.15>>
-	<<elseif (setup.bodyguardCareers.includes($HeadGirl.career) || setup.HGCareers.includes($HeadGirl.career)) && $HeadGirl.intelligence == 2>>
-		<<set _atkMod += 0.15>>
-		<<set _defMod += 0.10>>
-	<<elseif $HeadGirl.intelligence == 2>>
-		<<set _atkMod += 0.10>>
-		<<set _defMod += 0.10>>
-	<<elseif setup.bodyguardCareers.includes($HeadGirl.career) || setup.HGCareers.includes($HeadGirl.career) && $HeadGirl.intelligence >= 1>>
-		<<set _atkMod += 0.10>>
-		<<set _defMod += 0.05>>
-	<<elseif !(setup.bodyguardCareers.includes($HeadGirl.career) && setup.HGCareers.includes($HeadGirl.career)) || $HeadGirl.intelligence <= -2>>
-		<<set _atkMod -= 0.15>>
-		<<set _defMod -= 0.15>>
-	<<elseif $HeadGirl.intelligence <= -2>>
-		<<set _atkMod -= 0.15>>
-		<<set _defMod -= 0.10>>
-	<<elseif !(setup.bodyguardCareers.includes($HeadGirl.career) && setup.HGCareers.includes($HeadGirl.career)) || $HeadGirl.intelligence <= -1>>
-		<<set _atkMod -= 0.10>>
-		<<set _defMod -= 0.10>>
-	<<elseif $HeadGirl.intelligence <= -1>>
-		<<set _atkMod -= 0.10>>
-		<<set _defMod -= 0.05>>
-	<</if>>
-	/* does she get wounded? */
-	<<if $HeadGirl.combatSkill == 1>>
-		<<set _woundChance -= 3>>
-	<</if>>
-	<<if $HeadGirl.amp >= -4>>
-		<<set _woundChance -= 1>>
-	<</if>>
-	<<if $HeadGirl.health >= 50>>
-		<<set _woundChance -= 2>>
-	<</if>>
-	<<if $HeadGirl.weight > 130>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.muscles < -30>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.eyes <= -2>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.heels == 1>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.boobs >= 1400>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.butt >= 6>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.preg >= 30>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.dick >= 8>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.balls >= 8>>
-		<<set _woundChance += 1>>
-	<</if>>
-	<<if $HeadGirl.intelligence <= -3>>
-		<<set _woundChance += 1>>
-	<</if>>	
-	<<if random(1,100) <= _woundChance>>
-		<<set $leaderWounded = 1>>
-		<<set _militiaMod -= 0.2>>
-		<<set _slaveMod -= 0.2>>
-		<<set _mercMod -= 0.2>>
-		<<set _SFMod -= 0.2>>
-		<<set _enemyMod += 0.2>>
-		<<set $woundType = random(1,10)>>
-		<<if $woundType == 1>>
-			<<set $HeadGirl.voice = 0>>
-		<<elseif $woundType == 2>>
-			<<set $HeadGirl.eyes = -2>>
-		<<elseif $woundType == 3>>
-			<<set $HeadGirl.amp = 1>>
-		<<elseif $woundType >= 4>>
-			<<set $HeadGirl.health -= 40>>
-		<</if>>
-	<</if>>
-	/* 60% chance of getting combat skill if nto already have it */
-	<<if $HeadGirl.combatSkill == 0 && random(1,100) <= 60>>
-		<<set $gainedCombat = 1>>
-		<<set $HeadGirl.combatSkill = 1>>
-	<</if>>
-<<elseif $leadingTroops == "citizen">>
-	<<if $arcologies[0].FSDegradationist == "unset" && $arcologies[0].FSPaternalist == "unset">>
-		<<set _militiaMod += 0.15>>
-		<<set _slaveMod -= 0.15>>
-	<<elseif $arcologies[0].FSPaternalist != "unset">>
-		<<set _militiaMod += 0.15>>
-		<<set _slaveMod += 0.10>>
-	<<elseif $arcologies[0].FSDegradationist != "unset">>
-		<<set _militiaMod += 0.15>>
-		<<set _slaveMod -= 0.35>>
-	<</if>>
-	<<if $arcologies[0].FSRomanRevivalist != "unset">>
-		<<set _mercMod += 0.10>>
-		<<set _SFMod += 0.10>>
-	<<else>>
-		<<set _mercMod -= 0.10>>
-		<<set _SFMod -= 0.10>>
-	<</if>>
-	<<set _atkMod += either(-1,1) * random(10) * 0.1>>
-	<<set _defMod += either(-1,1) * random(10) * 0.1>>
-<<elseif $leadingTroops == "mercenary">>
-	<<set _mercMod += 0.10>>
-	<<set _SFMod += 0.10>>
-	<<if $arcologies[0].FSRomanRevivalist != "unset">>
-		<<set _militiaMod += 0.10>>
-	<<else>>
-		<<set _militiaMod -= 0.10>>
-	<</if>>
-	<<if $arcologies[0].FSDegradationist != "unset">>
-		<<set _slaveMod -= 0.35>>
-	<</if>>
-	<<set _atkMod += random(15) * 0.1>>
-	<<set _defMod += random(15) * 0.1>>
-<<elseif $leadingTroops == "colonel">>
-	<<set _mercMod += 0.10>>
-	<<set _SFMod += 0.15>>
-	<<if $arcologies[0].FSRomanRevivalist != "unset">>
-		<<set _militiaMod += 0.10>>
-	<<else>>
-		<<set _militiaMod -= 0.10>>
-	<</if>>
-	<<if $arcologies[0].FSDegradationist != "unset">>
-		<<set _slaveMod -= 0.35>>
-	<</if>>
-	<<set _atkMod += random(30) * 0.1>>
-	<<set _defMod += random(30) * 0.1>>
+/* 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>>
 
-/* calculates PC army stats */
-<<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 + $militiaBaseAttack * $attackEquip * $equipMod) * _irregularMod * 0.80>>
+	<<set _defense += ($militiaBaseDefense + $militiaBaseDefense * $attackEquip * $equipMod) * _irregularMod * 0.80>>
+	<<set _hp += $militiaBaseHp * $irregulars>>
+<</if>>
 
 <<if $secBots.active == 1>>
-	<<set _attack += ($secBotsBaseAttack + $secBotsBaseAttack * $secBots.equip * $equipMod) * _atkMod>>
-	<<set _defense += ($secBotsBaseDefense + $secBotsBaseDefense * $secBots.equip * $equipMod) * _defMod>>
+	<<set _attack += ($secBotsBaseAttack + $secBotsBaseAttack * $secBots.equip * $equipMod)>>
+	<<set _defense += ($secBotsBaseDefense + $secBotsBaseDefense * $secBots.equip * $equipMod)>>
 	<<set _hp += $secBotsBaseHp * $secBots.troops>>
 <</if>>
+
 <<for _i = 0; _i < $militiaUnits.length; _i++>>
-	<<if $militiaUnits[_i].active == 1 && !($rebellingUnits.contains($militiaUnits[_i]))>>
+	<<if $militiaUnits[_i].active == 1 && !($rebellingUnits.includes($militiaUnits[_i]))>>
+		<<set $deployingMilitia = 1>>
 		<<if $militiaUnits[_i].training <= 10>>
 			<<set _expBonus = 0>>
 		<<elseif $militiaUnits[_i].training <= 33>>
@@ -421,13 +68,14 @@
 		<<else>>
 			<<set _expBonus = 0.50>>
 		<</if>>
-		<<set _attack += ($militiaBaseAttack + $militiaBaseAttack * $militiaUnits[_i].equip * $equipMod + $militiaBaseAttack * _expBonus + $militiaUnits[_i].SF) * _atkMod>>
-		<<set _defense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod + $militiaBaseDefense * _expBonus + $militiaUnits[_i].SF) * _defMod>>
+		<<set _attack += ($militiaBaseAttack + $militiaBaseAttack * $militiaUnits[_i].equip * $equipMod + $militiaBaseAttack * _expBonus + $militiaUnits[_i].SF)>>
+		<<set _defense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod + $militiaBaseDefense * _expBonus + $militiaUnits[_i].SF)>>
 		<<set _hp += ($militiaBaseHp + $militiaBaseHp * $militiaUnits[_i].medics * $equipMod) * $militiaUnits[_i].troops>>
 	<</if>>
 <</for>>
 <<for _i = 0; _i < $slaveUnits.length; _i++>>
-	<<if $slaveUnits[_i].active == 1 && !($rebellingUnits.contains($slaveUnits[_i]))>>
+	<<if $slaveUnits[_i].active == 1 && !($rebellingUnits.includes($slaveUnits[_i]))>>
+		<<set $deployingSlaves = 1>>
 		<<if $slaveUnits[_i].training <= 33>>
 			<<set _expBonus = 0>>
 		<<elseif $slaveUnits[_i].training <= 66>>
@@ -435,13 +83,14 @@
 		<<else>>
 			<<set _expBonus = 0.50>>
 		<</if>>
-		<<set _attack += ($slaveBaseAttack + $slaveBaseAttack * $slaveUnits[_i].equip * $equipMod + $slaveBaseAttack * _expBonus + $slaveUnits[_i].SF) * _atkMod>>
-		<<set _defense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod + $slaveBaseDefense * _expBonus + $slaveUnits[_i].SF) * _defMod>>
+		<<set _attack += ($slaveBaseAttack + $slaveBaseAttack * $slaveUnits[_i].equip * $equipMod + $slaveBaseAttack * _expBonus + $slaveUnits[_i].SF)>>
+		<<set _defense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod + $slaveBaseDefense * _expBonus + $slaveUnits[_i].SF)>>
 		<<set _hp += ($slaveBaseHp + $slaveBaseHp * $slaveUnits[_i].medics * 0.25) * $slaveUnits[_i].troops>>
 	<</if>>
 <</for>>
 <<for _i = 0; _i < $mercUnits.length; _i++>>
-	<<if $mercUnits[_i].active == 1 && !($rebellingUnits.contains($mercUnits[_i]))>>
+	<<if $mercUnits[_i].active == 1 && !($rebellingUnits.includes($mercUnits[_i]))>>
+		<<set $deployingMercs = 1>>
 		<<if $mercUnits[_i].training <= 33>>
 			<<set _expBonus = 0>>
 		<<elseif $mercUnits[_i].training <= 66>>
@@ -449,13 +98,13 @@
 		<<else>>
 			<<set _expBonus = 0.50>>
 		<</if>>
-		<<set _attack += ($mercBaseAttack + $mercBaseAttack * $mercUnits[_i].equip * $equipMod + $mercBaseAttack * _expBonus + $mercUnits[_i].SF) * _atkMod>>
-		<<set _defense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod + $mercBaseDefense * _expBonus + $mercUnits[_i].SF) * _defMod>>
+		<<set _attack += ($mercBaseAttack + $mercBaseAttack * $mercUnits[_i].equip * $equipMod + $mercBaseAttack * _expBonus + $mercUnits[_i].SF)>>
+		<<set _defense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod + $mercBaseDefense * _expBonus + $mercUnits[_i].SF)>>
 		<<set _hp += ($mercBaseHp + $mercBaseHp * $mercUnits[_i].medics * 0.25) * $mercUnits[_i].troops>>
 	<</if>>
 <</for>>
 
-<<if $SFIntervention == 1>>
+<<if $securityForceCreate == 1>>
 	<<set _SFatk = 0>>
 	<<set _SFdef = 0>>
 	<<set _SFhp = 0>>
@@ -465,29 +114,193 @@
 	<<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>>
+
 /* morale and baseHp calculation */
-/* minimum modifier is -50%, maximum is +50% */
-<<if _militiaMod < 0.5>>
-	<<set _militiaMod = 0.5>>
-<<elseif _militiaMod > 1.5>>
-	<<set _militiaMod = 1.5>>
+<<set _morale = ($secBotsMorale * $secBots.active + $militiaBaseMorale * $deployingMilitia + $slaveBaseMorale * $deployingSlaves + $mercBaseMorale * $deployingMercs + $SFBaseMorale * $securityForceCreate) / ($secBots.active + $deployingMilitia +$deployingSlaves + $deployingMercs + $securityForceCreate)>>
+<<set _baseHp = ($secBotsBaseHp * $secBots.active + $militiaBaseHp * $deployingMilitia + $slaveBaseHp * $deployingSlaves + $mercBaseHp * $deployingMercs + $SFBaseHp * $securityForceCreate) / ($secBots.active + $deployingMilitia +$deployingSlaves + $deployingMercs + $securityForceCreate)>>
+				
+/* calculates rebelling army stats */
+<<if $week <= 30>>
+	<<set _armyMod = $attackTroops / 60>>
+<<elseif $week <= 60>>
+	<<set _armyMod = $attackTroops / 50>>
+<<elseif $week <= 90>>
+	<<set _armyMod = $attackTroops / 40>>
+<<elseif $week <= 120>>
+	<<set _armyMod = $attackTroops / 30>>
+<<else>>
+	<<set _armyMod = $attackTroops / 20>>
 <</if>>
-<<if _slaveMod < 0.5>>
-	<<set _slaveMod = 0.5>>
-<<elseif _slaveMod > 1.5>>
-	<<set _slaveMod = 1.5>>
+<<set _armyMod = Math.trunc(_armyMod)>>
+
+<<if $slaveRebellion == 1>>
+	<<set $rebellingSlaves = 1>>
+	<<set _enemyAttack += ($slaveBaseAttack + $slaveBaseAttack * $attackEquip * $equipMod) * _armyMod>>
+	<<set _enemyDefense += ($slaveBaseDefense + $slaveBaseDefense * $attackEquip * $equipMod) * _armyMod>>
+	<<set _enemyHp += $slaveBaseHp * $attackTroops>>
+<<else>>
+	<<set $rebellingMilitia = 1>>
+	<<set _enemyAttack += ($militiaBaseAttack + $militiaBaseAttack * $attackEquip * $equipMod) * _armyMod>>
+	<<set _enemyDefense += ($militiaBaseDefense + $militiaBaseDefense * $attackEquip * $equipMod) * _armyMod>>
+	<<set _enemyHp += $militiaBaseHp * $attackTroops>>
 <</if>>
-<<if _mercMod < 0.5>>
-	<<set _mercMod = 0.5>>
-<<elseif _mercMod > 1.5>>
-	<<set _mercMod = 1.5>>
+
+<<for _i = 0; _i < $militiaUnits.length; _i++>>
+	<<if $militiaUnits[_i].active == 1 && $rebellingUnits.includes($militiaUnits[_i])>>
+		<<set $rebellingMilitia = 1>>
+		<<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 + $militiaUnits[_i].SF)>>
+		<<set _enemyDefense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod + $militiaBaseDefense * _expBonus + $militiaUnits[_i].SF)>>
+		<<set _enemyHp += ($militiaBaseHp + $militiaBaseHp * $militiaUnits[_i].medics * $equipMod) * $militiaUnits[_i].troops>>
+	<</if>>
+<</for>>
+<<for _i = 0; _i < $slaveUnits.length; _i++>>
+	<<if $slaveUnits[_i].active == 1 && $rebellingUnits.includes($slaveUnits[_i])>>
+		<<set $rebellingSlaves = 1>>
+		<<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 + $slaveUnits[_i].SF)>>
+		<<set _enemyDefense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod + $slaveBaseDefense * _expBonus + $slaveUnits[_i].SF)>>
+		<<set _enemyHp += ($slaveBaseHp + $slaveBaseHp * $slaveUnits[_i].medics * 0.25) * $slaveUnits[_i].troops>>
+	<</if>>
+<</for>>
+<<for _i = 0; _i < $mercUnits.length; _i++>>
+	<<if $mercUnits[_i].active == 1 && $rebellingUnits.includes($mercUnits[_i])>>
+		<<set $rebellingMercs = 1>>
+		<<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 + $mercUnits[_i].SF)>>
+		<<set _enemyDefense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod + $mercBaseDefense * _expBonus + $mercUnits[_i].SF)>>
+		<<set _enemyHp += ($mercBaseHp + $mercBaseHp * $mercUnits[_i].medics * 0.25) * $mercUnits[_i].troops>>
+	<</if>>
+<</for>>
+
+<<set _enemyMorale = 1.5 * ($militiaBaseMorale * $rebellingMilitia + $slaveBaseMorale * $rebellingSlaves + $mercBaseMorale * $rebellingMercs) / ($rebellingMilitia + $rebellingSlaves + $rebellingMercs)>>
+<<set _enemyBaseHp = ($militiaBaseHp * $rebellingMilitia + $slaveBaseHp * $rebellingSlaves + $mercBaseHp * $rebellingMercs) / ($rebellingMilitia +$rebellingSlaves + $rebellingMercs)>>
+
+<<if $showBattleStatistics == 1>>
+<<set _engageMod -= 1>>
+<<set _engageMod = Math.round(_engageMod * 100)>>
+<br>attack: <<print Math.round(_attack)>>
+<br>defense: <<print Math.round(_defense)>>
+<br>engagement rule modifier: <<if _engageMod > 0>>+<</if>><<print _engageMod>>%
+<br>morale: <<print Math.round(_morale)>>
+<br>Hp: <<print Math.round(_hp)>>
+<br>base HP: <<print Math.round(_baseHp)>>
+<br>enemy attack: <<print Math.round(_enemyAttack)>>
+<br>enemy defense: <<print Math.round(_enemyDefense)>>
+<br>enemy morale: <<print Math.round(_enemyMorale)>>
+<br>enemy Hp: <<print Math.round(_enemyHp)>>
+<br>enemy base Hp: <<print Math.round(_enemyBaseHp)>>
 <</if>>
-<<if _SFMod < 0.5>>
-	<<set _SFMod = 0.5>>
-<<<elseif _SFMod > 1.5>>
-	<<set _SFMod = 1.5>>
+
+/* simulates the combat by pitting attk against def */
+<<for _i = 0; _i < _turns; _i++>>
+	<br><br>
+	<<if $showBattleStatistics == 1>> turn: <<print _i + 1>><</if>>
+	/* player army attacks */
+	<<set _damage = _attack - _enemyDefense>>
+	<<if _damage <= 0>>
+		<<set _damage = random(0,5)>>
+	<</if>>
+	<br>
+	<<if $showBattleStatistics == 1>> player damage: <<print Math.round(_damage)>><</if>>
+	<<set _enemyHp -= _damage>>
+	<br>
+	<<if $showBattleStatistics == 1>> remaining enemy Hp: <<print Math.round(_enemyHp)>><</if>>
+	<<set $enemyLosses +=  _damage / _enemyBaseHp>>
+	<<set _enemyMorale -= (_damage + _damage / _enemyBaseHp)>>
+	<br>
+	<<if $showBattleStatistics == 1>> remaining enemy morale: <<print Math.round(_enemyMorale)>><</if>>
+	<<if _enemyHp <= 0 || _enemyMorale <= 0>>
+		<<if $showBattleStatistics == 1>> <br>Victory!<</if>>
+		<<set $battleResult = 3>>
+		<<set $battleTurns = _i>>
+		<<break>>
+	<</if>>
+	
+	/* attacker army attacks */
+	<<set _damage = _enemyAttack - _defense>>
+	<<if _damage <= 0>>
+		<<set _damage = random(0,5)>>
+	<</if>>
+	<br>
+	<<if $showBattleStatistics == 1>> enemy damage: <<print Math.round(_damage)>><</if>>
+	<<set _hp -= _damage>>
+	<br>
+	<<if $showBattleStatistics == 1>> remaining hp: <<print Math.round(_hp)>><</if>>
+	<<set $losses = _damage / _baseHp>>
+	<<set _morale -= (_damage + _damage / _baseHp)>>
+	<br>
+	<<if $showBattleStatistics == 1>> remaining morale: <<print Math.round(_morale)>><</if>>
+	<<if _hp <= 0 || _morale <= 0>>
+		<<if $showBattleStatistics == 1>> <br>Defeat!<</if>>
+		<<set $battleResult = -3>>
+		<<set $battleTurns = _i>>
+		<<break>>
+	<</if>>
+<</for>>
+<<if $battleResult != 3 && $battleResult != -3>>
+	<<if _morale > _enemyMorale>>
+		<<if $showBattleStatistics == 1>> <br>Partial victory!<</if>>
+		<<set $battleResult = 2>>
+	<<elseif _morale < _enemyMorale>>
+		<<if $showBattleStatistics == 1>> <br>Partial defeat!<</if>>
+		<<set $battleResult = -2>>
+	<</if>>
 <</if>>
-<<set _morale = ($secBotsMorale * $deployingBots + $militiaBaseMorale * _militiaMod * $deployingMilitia + $slaveBaseMorale * _slaveMod * $deployingSlaves + $mercBaseMorale * _mercMod * $deployingMercs + $SFBaseMorale * $SFIntervention * _SFMod) / ($deployingBots + $deployingMilitia +$deployingSlaves + $deployingMercs + $SFIntervention)>>
-<<set _morale = _morale + _morale * $secBarracksUpgrades.luxury * 0.05>>	/* barracks bonus */
-<<set _baseHp = ($secBotsBaseHp * $deployingBots + $militiaBaseHp * $deployingMilitia + $slaveBaseHp * $deployingSlaves + $mercBaseHp * $deployingMercs + $SFBaseHp * $SFIntervention) / ($deployingBots + $deployingMilitia +$deployingSlaves + $deployingMercs + $SFIntervention)>>
-				
\ No newline at end of file
+
+<<if $battleResult > 3 || $battleResult < -3>>
+	<br>@@.red;Error: failed to determine battle result@@
+<</if>>
+
+<<if $showBattleStatistics == 1>>
+	<br><br>
+	<<link "Proceed">>
+		<<goto "rebellionReport">>
+	<</link>>
+<<else>>
+	<<goto "rebellionReport">>
+<</if>>
\ No newline at end of file
diff --git a/src/SecExp/rebellionOptions.tw b/src/SecExp/rebellionOptions.tw
index d7455ac9ef1..bcb0f4f6b05 100644
--- a/src/SecExp/rebellionOptions.tw
+++ b/src/SecExp/rebellionOptions.tw
@@ -7,108 +7,96 @@
 
 <<if $slaveRebellion == 1>>
 	In the end it happened, the slaves of your arcology dared took up arms and raised 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 $rebels rebels are in the streets right now, building barricades and freeing their peers. They are
-	<<if $rebelsEquip <= 0>>
+	It appears $attackTroops rebels are in the streets right now, building barricades and freeing their peers. They are
+	<<if $attackEquip <= 0>>
 		<strong>poorly armed</strong>.
-	<<elseif $rebelsEquip == 1>>
+	<<elseif $attackEquip == 1>>
 		<strong>lightly armed</strong>.
-	<<elseif $rebelsEquip == 2>>
+	<<elseif $attackEquip == 2>>
 		<strong>decently armed</strong>.
-	<<elseif $rebelsEquip == 3>>
+	<<elseif $attackEquip == 3>>
 		<strong>well armed</strong>. 
-	<<elseif $rebelsEquip >= 4>>
+	<<elseif $attackEquip >= 4>>
 		<strong>extremely well armed</strong>.
 	<</if>>
+	<<if $irregulars > 0>>
+		$irregulars of your citizens took up arms to defend their arcology owner.
+	<</if>>
 	<<if $rebellingUnits.length > 1>>
 		It seems that some of your military units betrayed you and joined the insurrection.
-	<<elseif  $rebellingUnits.length > 0>>
+	<<elseif $rebellingUnits.length > 0>>
 		It seems that one of your military units betrayed you and joined the insurrection.
 	<</if>>
-	<hr>
-	<br>You quickly asssemble your loyal citizens and <<if $mercenaries >= 1>> your mercenaries,<</if>>
+	
+	<br>You quickly assemble your loyal citizens and <<if $mercenaries >= 1>> your mercenaries,<</if>>
 	<<if $securityForceActive == 1>> your $securityForceName,<</if>>
 	<<if $slaveUnits.length > $rebellingUnits.length>>your units<<elseif $militiaUnits.length > 0>>your units<<elseif $mercUnits.length > 0>>your units<</if>>
 	<<if $arcologyUpgrade.drones == 1>>your drones<</if>> to face the menace.
+	<hr>
 <<else>>
 	In the end it happened, the citizens of your arcology dared took up arms and raised 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 $rebels rebels are in the streets right now, building barricades and destroying your property. They are
-	<<if $rebelsEquip <= 0>>
+	It appears $attackTroops rebels are in the streets right now, building barricades and destroying your property. They are
+	<<if $attackEquip <= 0>>
 		<strong>poorly armed</strong>.
-	<<elseif $rebelsEquip == 1>>
+	<<elseif $attackEquip == 1>>
 		<strong>lightly armed</strong>.
-	<<elseif $rebelsEquip == 2>>
+	<<elseif $attackEquip == 2>>
 		<strong>decently armed</strong>.
-	<<elseif $rebelsEquip == 3>>
+	<<elseif $attackEquip == 3>>
 		<strong>well armed</strong>. 
-	<<elseif $rebelsEquip >= 4>>
+	<<elseif $attackEquip >= 4>>
 		<strong>extremely well armed</strong>.
 	<</if>>
+	<<if $irregulars > 0>>
+		$irregulars of your citizens took up arms to defend their arcology owner.
+	<</if>>
 	<<if $rebellingUnits.length > 1>>
 		It seems that some of your military units betrayed you and joined the insurrection.
 	<<elseif  $rebellingUnits.length > 0>>
 		It seems that one of your military units betrayed you and joined the insurrection.
 	<</if>>
-	<hr>
+
 	<br>You quickly asssemble your loyal citizens and <<if $mercenaries >= 1>> your mercenaries,<</if>>
 	<<if $securityForceActive == 1>> your $securityForceName,<</if>>
 	<<if $slaveUnits.length > 0>>your units<<elseif $militiaUnits.length > $rebellingUnits.length>>your units<<elseif $mercUnits.length > 0>>your units<</if>>
 	<<if $arcologyUpgrade.drones == 1>>your drones<</if>> to face the menace.
+	<hr>
 <</if>>
 
 <br>
 <br>
+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 strenous fight, stree 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.
+<br><<link "Only light firearms and non lethal weapons">>
+	<<set $engageRule = 0>>
+	<<replace "#engage">>
+		<br>Your troops will use only non lethal weapons or light firearms to limit to the maximum the collateral damage. This will however weaken our troops considerably.
+	<</replace>>
+<</link>>
+<br><<link "No heavy ordnance">>
+	<<set $engageRule = 1>>
+	<<replace "#engage">>
+		<br>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>>
+<br><<link "Normal engagement rules">>
+	<<set $engageRule = 2>>
+	<<replace "#engage">>
+		<br>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>>
+<br><<link "Extermination protocol">>
+	<<set $engageRule = 3>>
+	<<replace "#engage">>
+		<br>Your troops will make use of the special weaponry, equipment and infrastructure developed by the riot control center to surgically eliminate rebels and dissidents.
+	<</replace>>
+<</link>>
+<span id="engage"></span>
 
-/* leader assignment */
-<span id="leader"><strong><<print $assistantName>></strong></span> will lead your troops.
-	<br>&nbsp;&nbsp;&nbsp;&nbsp;
-	<<link "Personally join the battle">>
-		<<set $leadingTroops = "PC">>
-		<<replace "#leader">><strong><<print $PC.name>></strong><</replace>>
-	<</link>>
-	|
-	<<link "Let $assistantName lead the troops">>
-		<<set $leadingTroops = "assistant">>
-		<<replace "#leader">><strong><<print $assistantName>></strong><</replace>>
-	<</link>>
-	<<if $Bodyguard != 0 && $slavesOfficers == 1>>
-	|
-	<<link "Let your bodyguard lead your troops">>
-		<<set $leadingTroops = "bodyguard">>
-		<<replace "#leader">><strong><<print $Bodyguard.slaveName>></strong><</replace>>
-	<</link>>
-	<</if>>
-	<<if $HeadGirl != 0 && $slavesOfficers == 1>>
-	|
-	<<link "Let your head girl lead your troops">>
-		<<set $leadingTroops = "headGirl">>
-		<<replace "#leader">><strong><<print $HeadGirl.slaveName>></strong><</replace>>
-	<</link>>
-	<</if>>
-	<<if $militiaFounded == 1>>
-	|
-	<<link "Let the citizens' militia officers lead the troops">>
-		<<set $leadingTroops = "citizen">>
-		<<replace "#leader">><strong>The citizens' militia commander</strong><</replace>>
-	<</link>>
-	<</if>>
-	<<if $mercenaries > 0>>
-	|
-	<<link "Let the mercenary officers lead the troops">>
-		<<set $leadingTroops = "mercenary">>
-		<<replace "#leader">><strong>The mercenary commander</strong><</replace>>
-	<</link>>
-	<</if>>
-	<<if $securityForceCreate == 1>>
-	|
-	<<link "Let the colonel lead the troops">>
-		<<set $leadingTroops = "colonel">>
-		<<replace "#leader">><strong>$securityForceName's colonel</strong><</replace>>
-	<</link>>
-	<</if>>
-	
-<br><br>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 strenous fight, stree after street, barricade after barricade.
-<br>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.
 <br>
+<br>
+
+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>>
 	<br><<link "Garrison the penthouse">>
 		<<set $garrison.penthouse = 1>>
diff --git a/src/SecExp/rebellionReport.tw b/src/SecExp/rebellionReport.tw
index bc948d40866..1875b12675e 100644
--- a/src/SecExp/rebellionReport.tw
+++ b/src/SecExp/rebellionReport.tw
@@ -1,2 +1,19 @@
 :: rebellionReport [nobr]
 
+<<set $nextButton = "Continue", $nextLink = "Scheduled Event", $showEncyclopedia = 1, $encyclopedia = "Battles">>
+
+<br>Debug: result: $battleResult
+
+
+
+/* resets variables */
+<<set $attackTroops = 0>>
+<<set $attackEquip = 0>>
+<<set $deployingMilitia = 0>>
+<<set $deployingSlaves = 0>>
+<<set $deployingMercs = 0>>
+<<set $enemyLosses = 0>>
+<<set $losses = 0>>
+<<set $battleTurns = 0>>
+<<set $slaveRebellion = 0>>
+<<set $citizenRebellion = 0>>
\ No newline at end of file
diff --git a/src/SecExp/riotControlCenter.tw b/src/SecExp/riotControlCenter.tw
index 5a1901110d3..0b6c2c5da90 100644
--- a/src/SecExp/riotControlCenter.tw
+++ b/src/SecExp/riotControlCenter.tw
@@ -1 +1,5 @@
-:: riotControlCenter [nobr]
\ No newline at end of file
+:: riotControlCenter [nobr]
+
+-possibility of accepting demands of rebels.
+-extermination protocol
+-brain chips
\ No newline at end of file
diff --git a/src/SecExp/secBarracks.tw b/src/SecExp/secBarracks.tw
index c87f27ee561..f834f012c44 100644
--- a/src/SecExp/secBarracks.tw
+++ b/src/SecExp/secBarracks.tw
@@ -184,7 +184,7 @@ You are free to organize your menial slaves into fighting units. Currently you h
 			maxTroops: $maxTroops,
 			equip: 0,
 			training: 0,
-			loyalty: 0,
+			loyalty: 7,
 			medics: 0,
 			SF: 0,
 			battlesFought: 0}>>
@@ -340,7 +340,7 @@ __Militia__
 				maxTroops: $maxTroops,
 				equip: 0,
 				training: 0,
-				loyalty: 0,
+				loyalty: 7,
 				medics: 0,
 				SF: 0,
 				battlesFought: 0}>>
@@ -497,7 +497,7 @@ __Mercenaries__
 				maxTroops: $maxTroops,
 				equip: 0,
 				training: 0,
-				loyalty: 0,
+				loyalty: 7,
 				medics: 0,
 				battlesFought: 0}>>
 				<<set $mercUnits.push(_newUnit)>>
diff --git a/src/SecExp/secExpOptions.tw b/src/SecExp/secExpOptions.tw
index cd0e99cdbdd..c4ab177f85d 100644
--- a/src/SecExp/secExpOptions.tw
+++ b/src/SecExp/secExpOptions.tw
@@ -1,10 +1,28 @@
 :: secExpOptions [nobr]
 
-<<set $showEncyclopedia = 1, $encyclopedia = "Security Expansion" $nextButton = "Back to Options", $nextLink = "Options">>
+<<set $showEncyclopedia = 1, $encyclopedia = "Security Expansion", $nextButton = "Back to Options", $nextLink = "Options">>
 
 <<if $terrain != "oceanic">>
 <br>
 <br>__Battle Options__:
+	<<if $arcologyUpgrade.drones == 1>>
+		<br>
+		<br>
+		<<if $rebellionsEnabled == 0>>
+			Rebellions are @@.red;DISABLED@@.
+			<<link "Enable rebellions">>
+				<<set $rebellionsEnabled = 1>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<<else>>
+			Rebellions are @@.cyan;ENABLED@@.
+		<<link "Disable rebellions">>
+				<<set $rebellionsEnabled = 0>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<</if>>
+		//Enable/disable rebellions.//
+	<</if>>
 	<<if $arcologyUpgrade.drones == 1>>
 		<br>
 		<br>
@@ -21,7 +39,7 @@
 				<<goto "secExpOptions">>
 			<</link>>
 		<</if>>
-		//Enable/disable late game large scale battles.//
+		//Enable/disable battles.//
 	<</if>>
 	<<if $arcologyUpgrade.drones == 1 && $battlesEnabled == 1>>
 		<br>
@@ -76,6 +94,25 @@
 		<</link>>
 	<</if>>
 	//Will show detailed statistics and battle turns. This is mainly for debugging and balance adjustments.//
+	<<if $arcologyUpgrade.drones == 1 && $rebellionsEnabled == 1>>
+		<br>
+		<br>
+		<<if $forceRebellion == 0>>
+			Rebellions guaranteed this week is @@.red;FALSE@@.
+			<<link "Force engagement every week">>
+				<<set $forceRebellion = 1>>
+				<<goto "secExpOptions">>
+			<</link>>
+		
+		<<else>>
+			Rebellions guaranteed this week is @@.cyan;TRUE@@.
+		<<link "Do not force engagement every week">>
+				<<set $forceRebellion = 0>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<</if>>
+		//Will force battles to happen every week. This is mainly for debugging.//
+	<</if>>
 	<<if $arcologyUpgrade.drones == 1 && $battlesEnabled == 1>>
 		<br>
 		<br>
diff --git a/src/SecExp/secInit.tw b/src/SecExp/secInit.tw
index 0b3cd4a150c..b96b554b115 100644
--- a/src/SecExp/secInit.tw
+++ b/src/SecExp/secInit.tw
@@ -29,7 +29,8 @@
 <<set $battlesEnabled = 1>>
 <<set $majorBattlesEnabled = 1>>
 <<set $majorBattleGameOver = 1>>
-<<set $rebellionsEnabled = 0>>
+<<set $rebellionsEnabled = 1>>
+<<set $forceRebellion = 0>>
 
 /* edicts */
 <<set $edictsUpkeep = 0>>
@@ -127,6 +128,11 @@
 <<set $citizenRebellion = 0>>
 <<set $rebellingUnits = []>>
 <<set $notInvolved = 0>>
+<<set $irregulars = 0>>
+<<set $engageRule = 0>>
+<<set $rebellingMilitia = 0>>
+<<set $rebellingSlaves = 0>>
+<<set $rebellingMercs = 0>>
 <<set $garrison = {
 	penthouse: 0,
 	reactor: 0,
-- 
GitLab