From c1bef3ac586f3200646be25cf888c356ad0f9d9a Mon Sep 17 00:00:00 2001
From: hexall90 <hexall90@gmail.com>
Date: Sun, 5 Nov 2017 17:32:58 +0100
Subject: [PATCH] Merge remote-tracking branch 'upstream/pregmod-master' into
 SecExp

updating fork

finishing up rebellions code
---
 src/SecExp/SecExpBackwardCompatibility.tw |  31 +++-
 src/SecExp/authorityReport.tw             |  34 +---
 src/SecExp/rebellionEvents.tw             |  10 +-
 src/SecExp/rebellionGenerator.tw          |  89 +++++-----
 src/SecExp/rebellionOptions.tw            |  22 ++-
 src/SecExp/rebellionReport.tw             |  35 ++--
 src/SecExp/riotControlCenter.tw           | 193 +++++++++++++++++++++-
 src/SecExp/secInit.tw                     |  15 +-
 src/SecExp/securityReport.tw              |  28 ++++
 src/events/gameover.tw                    |   6 +
 src/uncategorized/arcmgmt.tw              |  13 ++
 src/uncategorized/manageArcology.tw       |  11 ++
 src/uncategorized/nextWeek.tw             |   4 +
 src/uncategorized/persBusiness.tw         |   6 +
 14 files changed, 375 insertions(+), 122 deletions(-)

diff --git a/src/SecExp/SecExpBackwardCompatibility.tw b/src/SecExp/SecExpBackwardCompatibility.tw
index b0467878321..efa8b055192 100644
--- a/src/SecExp/SecExpBackwardCompatibility.tw
+++ b/src/SecExp/SecExpBackwardCompatibility.tw
@@ -269,6 +269,33 @@
 <<if ndef $upgradeUpkeep>>
 <<set $upgradeUpkeep = 50>>
 <</if>>
+<<if ndef $riotCenter>>
+<<set $riotCenter = 0>>
+<</if>>
+<<if ndef $riotUpgrades>>
+<<set $riotUpgrades = {
+	freeMedia: 0,
+	rapidUnit: 0,
+	rapidUnitSpeed: 0}>>
+<</if>>
+<<if ndef $fort>>
+<<set $fort = {
+	reactor: 0,
+	waterway: 0,
+	assistant:0}>>
+<</if>>
+<<if ndef $sentUnitCooldown>>
+<<set $sentUnitCooldown = 0>>
+<</if>>
+<<if ndef $advancedRiotEquip>>
+<<set $advancedRiotEquip = 0>>
+<</if>>
+<<if ndef $brainImplant>>
+<<set $brainImplant = -1>>
+<</if>>
+<<if ndef $brainImplantProject>>
+<<set $brainImplantProject = 0>>
+<</if>>
 
 /* events */
 <<if ndef $smilingManProgress>>
@@ -348,9 +375,6 @@
 <<if ndef $arcRepairTime>>
 <<set $arcRepairTime = 0>>
 <</if>>
-<<if ndef $arcRepairCost>>
-<<set $arcRepairCost = 1000>>
-<</if>>
 <<if ndef $rebelDefeatAftermath>>
 <<set $rebelDefeatAftermath = 0>>
 <</if>>
@@ -360,7 +384,6 @@
 	reactor: 0,
 	assistant: 0,
 	waterway: 0,
-	penthouseTime: 0,
 	reactorTime: 0,
 	assistantTime: 0,
 	waterwayTime: 0 }>>
diff --git a/src/SecExp/authorityReport.tw b/src/SecExp/authorityReport.tw
index 793c3cf84da..4de9ff33a72 100644
--- a/src/SecExp/authorityReport.tw
+++ b/src/SecExp/authorityReport.tw
@@ -164,38 +164,6 @@ This week
 <<if $rebellionsEnabled == 1>>
 /* rebellions */
 	<br>
-	<br>
-
-	<<if $tension <= 33>>
-		Tensions are the arcology is 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 $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>>
-
-	<br>
-	<br>
-	
+	<br>	
 	<<include "rebellionGenerator">>
 <</if>>
\ No newline at end of file
diff --git a/src/SecExp/rebellionEvents.tw b/src/SecExp/rebellionEvents.tw
index 17c45ba722b..00690f7c6eb 100644
--- a/src/SecExp/rebellionEvents.tw
+++ b/src/SecExp/rebellionEvents.tw
@@ -69,16 +69,14 @@
 	<</if>>
 	<<set $tension += random(10,15)>>
 <<case 4>>
-	random citizen event, low tension
+	random citizen mini event, low tension
 	<<set $tension += random(1,5)>>
 <<case 5>>
-	random citizen event, med tension
+	random citizen mini event, med tension
 	<<set $tension += random(5,10)>>
 <<case 6>>
-	random citizen event, high tension
+	random citizen mini event, high tension
 	<<set $tension += random(10,15)>>
 <</switch>>
 
-<<set $tension = Math.clamp($tension,0,100)>>
-
-<br>Debug: tension: $tension
+<<set $tension = Math.clamp($tension,0,100)>>
\ No newline at end of file
diff --git a/src/SecExp/rebellionGenerator.tw b/src/SecExp/rebellionGenerator.tw
index 859985db42d..d3303d1d24d 100644
--- a/src/SecExp/rebellionGenerator.tw
+++ b/src/SecExp/rebellionGenerator.tw
@@ -6,113 +6,113 @@
 
 /* slaves */
 <<if $authority <= 3000>>
-	<<set _slave += 30>>
+	Your very low authority allows slaves to think too freely.<<set _slave += 30>>
 <<elseif $authority <= 6000>>
-	<<set _slave += 25>>
+	Your low authority allows slaves to think too freely.<<set _slave += 25>>
 <<elseif $authority <= 9000>>
-	<<set _slave += 20>>
+	Your moderate authority allows slaves to think a bit too freely.<<set _slave += 20>>
 <<elseif $authority <= 12000>>
-	<<set _slave += 15>>
+	Your good authority does not allow slaves to think too freely.<<set _slave += 15>>
 <<elseif $authority <= 15000>>
-	<<set _slave += 10>>
+	Your high authority does not allow slaves to think too freely.<<set _slave += 10>>
 <<elseif $authority <= 18000>>
-	<<set _slave += 5>>
+	Your very high authority does not allow slaves to think too freely.<<set _slave += 5>>
 <</if>>
 <<if _CSratio <= 0.2>>
-	<<set _slave += 30>>
+	There are a lot more slaves than citizens, making some doubt their masters are strong enough to stop them.<<set _slave += 30>>
 <<elseif _CSratio <= 0.4>>
-	<<set _slave += 25>>
+	There are a lot more slaves than citizens, making some doubt their masters are strong enough to stop them.<<set _slave += 25>>
 <<elseif _CSratio <= 0.6>>
-	<<set _slave += 20>>
+	There are more slaves than citizens, making some doubt their masters are strong enough to stop them.<<set _slave += 20>>
 <<elseif _CSratio <= 0.8>>
-	<<set _slave += 15>>
+	There are more slaves than citizens, making some doubt their masters are strong enough to stop them.<<set _slave += 15>>
 <<elseif _CSratio <= 1>>
-	<<set _slave += 10>>
+	There are less slaves than citizens, making some doubt they would be strong enough to defeat their masters.<<set _slave += 10>>
 <<elseif _CSratio >= 1.2>>
-	<<set _slave -= 5>>
+	There are less slaves than citizens, making some doubt they would be strong enough to defeat their masters.<<set _slave -= 5>>
 <</if>>
 <<if $security <= 10>>
-	<<set _slave += 30>>
+	The very low security of the arcology leaves free space for slaves to organize and agitate.<<set _slave += 30>>
 <<elseif $security <= 30>>
-	<<set _slave += 20>>
+	The low security of the arcology leaves free space for slaves to organize and agitate.<<set _slave += 20>>
 <<elseif $security <= 60>>
-	<<set _slave += 10>>
+	The moderate security of the arcology does not allow free space for slaves to organize and agitate.<<set _slave += 10>>
 <<elseif $security >= 90>>
-	<<set _slave -= 5>>
+	The high security of the arcology does not allow free space for slaves to organize and agitate.<<set _slave -= 5>>
 <</if>>
 <<if $arcologies[0].FSDegradationist != "unset">>
-	<<set _slave += 30>>
+	Many slaves are so disgusted by your degradationist society, that are willing to rise up against their masters to escape.<<set _slave += 30>>
 <<elseif $arcologies[0].FSPaternalist != "unset">>
-	<<set _slave -= 5>>
+	Many slaves are content to live in your paternalist society.<<set _slave -= 5>>
 <<else>>
 	<<set _slave += 5>>
 <</if>>
 <<if $arcologies[0].FSRestart != "unset">>
-	<<set _slave += 30>>
+	Many slaves are worried by your eugenics projects and some are pushed towards radicalization.<<set _slave += 30>>
 <<elseif $arcologies[0].FSRepopulationFocus != "unset">>
-	<<set _slave -= 5>>
+	Many slaves are pleasantly happy of your repopulation effort, affording them the freedom to reproduce.<<set _slave -= 5>>
 <<else>>
 	<<set _slave += 5>>
 <</if>>
-	
+<br>
 /* citizens */
 <<if $authority <= 3000>>
-	<<set _citizen += 30>>
+	Your very low authority allows your citizens to think too freely.<<set _citizen += 30>>
 <<elseif $authority <= 6000>>
-	<<set _citizen += 25>>
+	Your very low authority allows your citizens to think too freely.<<set _citizen += 25>>
 <<elseif $authority <= 9000>>
-	<<set _citizen += 20>>
+	Your moderate authority allows your citizens to think a bit too freely.<<set _citizen += 20>>
 <<elseif $authority <= 12000>>
-	<<set _citizen += 15>>
+	Your good authority does not allow your citizens to think too freely.<<set _citizen += 15>>
 <<elseif $authority <= 15000>>
-	<<set _citizen += 10>>
+	Your high authority does not allow your citizens to think too freely.<<set _citizen += 10>>
 <<elseif $authority <= 18000>>
-	<<set _citizen += 5>>
+	Your very high authority does not allow your citizens to think too freely.<<set _citizen += 5>>
 <</if>>
 <<if $crime >= 90>>
-	<<set _citizen += 30>>
+	The very high crime level of the arcology breeds extreme discontent between your citizens.<<set _citizen += 30>>
 <<elseif $crime >= 60>>
-	<<set _citizen += 15>>
+	The high crime level of the arcology breeds high discontent between your citizens.<<set _citizen += 15>>
 <<elseif $crime >= 30>>
-	<<set _citizen += 5>>
+	The low crime level of the arcology leaves your citizens happy and satisfied.<<set _citizen += 5>>
 <<else>>
-	<<set _citizen -= 5>>
+	The very low crime level of the arcology leaves your citizens happy and satisfied.<<set _citizen -= 5>>
 <</if>>
 <<if $militiaFounded == 1>>
 	<<if ($arcologies[0].FSRomanRevivalist == "unset" && $arcologies[0].FSAztecRevivalist == "unset" && $arcologies[0].FSEgyptianRevivalist == "unset" && $arcologies[0].FSEdoRevivalist == "unset" && $arcologies[0].FSArabianRevivalist == "unset" && $arcologies[0].FSChineseRevivalist == "unset")>>
 		<<if $militarizedSociety == 1>>
-			<<set _citizen += 20>>
+			Many of your citizens are offended by your extreme militarization of the arcology's society.<<set _citizen += 20>>
 		<<elseif $militaryService == 1>>
-			<<set _citizen += 15>>
+			Many of your citizens are offended by your militarization of the arcology's society.<<set _citizen += 15>>
 		<<else>>
 			<<set _citizen += 10>>
 		<</if>>
 	<<else>>
 		<<if $militarizedSociety == 1>>
-			<<set _citizen += 10>>
+			Some of your citizens are offended by your extreme militarization of the arcology's society<<set _citizen += 10>>
 		<<elseif $militaryService == 1>>
-			<<set _citizen += 5>>
+			Some of your citizens are offended by your militarization of the arcology's society<<set _citizen += 5>>
 		<<else>>
 			<<set _citizen -= 5>>
 		<</if>>
 	<</if>>	
 <</if>>
 <<if $arcologies[0].FSNull != "unset">>
-	<<set _citizen += either(20,30)>>
+	Many of your more conservative citizens do not enjoy the cultural freedom you afford the residents of the arcology.<<set _citizen += either(20,30)>>
 <</if>>
 <<if $arcologies[0].FSRestart != "unset">>
 	<<if _CSratio > 1>>
-		<<set _citizen +=20>>
+		Your citizens are not happy with the noticeable lack of slaves compared to their numbers.<<set _citizen +=20>>
 	<<elseif _CSratio > 0.5>>
-		<<set _citizen += 15>>
+		Your citizens are not happy with the lack of slaves compared to their numbers.<<set _citizen += 15>>
 	<<elseif _CSratio < 0.2>>
 		<<set _citizen -= 5>>
 	<</if>>
 <<elseif $arcologies[0].FSRepopulationFocus != "unset">>
 	<<if _CSratio < 0.5>>
-		<<set _citizen +=20>>
+		Your citizens are not happy of being outbred by the slaves of the arcology<<set _citizen +=20>>
 	<<elseif _CSratio < 1>>
-		<<set _citizen += 15>>
+		Your citizens are not happy of being outbred by the slaves of the arcology<<set _citizen += 15>>
 	<<elseif _CSratio > 1.4>>
 		<<set _citizen += 5>>
 	<</if>>
@@ -130,6 +130,9 @@
 	<<set _citizen = 95>>
 <</if>>
 <<set _roll = random(1,_slave + _citizen)>>
+<<if $brainImplant == 106>>
+	<<set _slave = Math.trunc(_slave * 0.3), _citizen = Math.trunc(_citizen * 0.3)>>
+<</if>>
 <<if _roll <= _slave>>
 	<<if random(1,100) < _slave>>
 		<<set $slaveRebellionEventFires = 1>>
@@ -152,8 +155,12 @@
 	<</if>>
 <</if>>
 
+/* if there is an advancement selects a random mini event */
 <<if $slaveRebellionEventFires == 1 || $citizenRebellionEventFires == 1>>
+	<br>
+	<br>
 	<<include "rebellionEvents">>
+	/* and resets flags */
 	<<set $slaveRebellionEventFires = 0>>
 	<<set $citizenRebellionEventFires = 0>>
 <</if>>
@@ -187,6 +194,7 @@
 <</if>>
 
 <<if $slaveRebellion == 1>>
+	<<set $engageRule = 0>>
 	<<set $lastRebellionWeeks = 0>>
 	<<set $leadingTroops = "assistant">>
 	/* calc how many slaves participate */
@@ -224,6 +232,7 @@
 	<</for>>
 	<<set $attackEquip = Math.clamp($weaponsLaw + random(-1,1),0,4)>>
 <<elseif $citizenRebellion == 1>>
+	<<set $engageRule = 0>>
 	<<set $lastRebellionWeeks = 0>>
 	<<set $leadingTroops = "assistant">>
 	/* calc how many citizens participate */
diff --git a/src/SecExp/rebellionOptions.tw b/src/SecExp/rebellionOptions.tw
index 2d4e5163c41..e4c5df770f2 100644
--- a/src/SecExp/rebellionOptions.tw
+++ b/src/SecExp/rebellionOptions.tw
@@ -85,15 +85,19 @@ In order to preserve the structural integrity of the building and the lives of o
 		<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>
+
+<<if $advancedRiotEquip == 1>>
+	<br><<link "Advanced riot 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 with little to no collateral damage.
+		<</replace>>
+	<</link>>
+<</if>>
+
+<span id="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.
+</span>
 
 <br>
 <br>
diff --git a/src/SecExp/rebellionReport.tw b/src/SecExp/rebellionReport.tw
index 20b2a4b4f8b..3159d08946c 100644
--- a/src/SecExp/rebellionReport.tw
+++ b/src/SecExp/rebellionReport.tw
@@ -125,7 +125,7 @@
 		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
 		<<set $rep -= random(800,1000)>>
 		<<set $authority -= random(800,1000)>>
-		<br>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 wil bear the scars of this day for a long time.
+		<br>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 $ACitizens -= random(50,100)>>
 		<<set $ASlaves -= Math.trunc(($attackTroops - $enemyLosses) * 0.8)>>
 		<<set $rebelDefeatAftermath = 5>>
@@ -133,7 +133,7 @@
 		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
 		<<set $rep -= random(600,800)>>
 		<<set $authority -= random(600,800)>>
-		<br>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 wil bear the scars of this day for a long time.
+		<br>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 $ACitizens -= random(40,80)>>
 		<<set $ASlaves -= Math.trunc(($attackTroops - $enemyLosses) * 0.6)>>
 		<<set $rebelDefeatAftermath = 3>>
@@ -171,7 +171,7 @@
 			<<set $ASlaves -= random(230)>>
 			<<set $arcologies[0].prosperity -= random(25)>>
 		<</if>>
-		<br>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 wil bear the scars of this day for a long time.
+		<br>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 $ACitizens -= random(50,100)>>
 		<<set $ASlaves -= Math.trunc(($attackTroops - $enemyLosses) * 0.8)>>
 		<<set $rebelDefeatAftermath = 5>>
@@ -385,10 +385,10 @@
 
 /* garrisons */
 <<if $garrison.reactor == 0>>
-	<<if random(1,100) <= 75>>
+	<<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,1)>>
+		<<set $garrison.reactorTime = $repairTime + random(1) - $fort.reactor>>
 		<<set $cash -= 2000>>
 	<<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.
@@ -397,10 +397,10 @@
 	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>>
+	<<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,1)>>
+		<<set $garrison.waterwayTime = $repairTime + random(1) - $fort.waterway>>
 		<<set $cash -= 2000>>
 	<<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.
@@ -409,10 +409,10 @@
 	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>>
+	<<if random(1,100) <= (75 - ($fort.assistant * 25))>>
 		Unfortunately during the fighting a group of slaves infiltrated the facility housing $assistantName 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.waterwayTime = $repairTime + random(-1,1)>>
+		<<set $garrison.assistantTime = $repairTime + random(1) - $fort.assistant>>
 		<<set $cash -= 2000>>
 	<<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.
@@ -421,7 +421,7 @@
 	The garrison assigned to the facility housing $assistantName mainframe prevented any sabotage attempt.
 <</if>>
 <<if $garrison.penthouse == 1 && $Bodyguard != 0>>
-	The garrison assigned to the penthouse together with your loyal bodyguard stopped any assault against your penthouse with ease.
+	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.
@@ -512,7 +512,7 @@
 					a splinter hit her face, severely damaging her eyes. 
 					<<set $Concubine.eyes = -2>>
 				<<elseif $woundType == 3>>
-					an explosion near her casued the loss of all her limbs.
+					an explosion near her caused the loss of all her limbs.
 					<<set $Concubine.amp = 1>>
 				<<elseif $woundType >= 4>>
 					a stray shot severely wounded her.
@@ -575,7 +575,7 @@
 				A splinter hit her face, severely damaging her eyes. 
 				<<set $Bodyguard.eyes = -2>>
 			<<elseif $woundType == 3>>
-				An explosion near her casued the loss of all her limbs.
+				An explosion near her caused the loss of all her limbs.
 				<<set $Bodyguard.amp = 1>>
 			<<elseif $woundType >= 4>>
 				A stray shot severely wounded her.
@@ -682,7 +682,7 @@
 					a splinter hit her face, severely damaging her eyes. 
 					<<set $Concubine.eyes = -2>>
 				<<elseif $woundType == 3>>
-					an explosion near her casued the loss of all her limbs.
+					an explosion near her caused the loss of all her limbs.
 					<<set $Concubine.amp = 1>>
 				<<elseif $woundType >= 4>>
 					a stray shot severely wounded her.
@@ -790,7 +790,7 @@
 					a splinter hit her face, severely damaging her eyes. 
 					<<set $Concubine.eyes = -2>>
 				<<elseif $woundType == 3>>
-					an explosion near her casued the loss of all her limbs.
+					an explosion near her caused the loss of all her limbs.
 					<<set $Concubine.amp = 1>>
 				<<elseif $woundType >= 4>>
 					a stray shot severely wounded her.
@@ -812,12 +812,7 @@
 
 <<include "unitsRebellionReport">>
 
-
-
-
-
-
-/* resets variables */
+/* resets variables and flags */
 <<set $attackTroops = 0>>
 <<set $attackEquip = 0>>
 <<set $enemyLosses = 0>>
diff --git a/src/SecExp/riotControlCenter.tw b/src/SecExp/riotControlCenter.tw
index 60b909a71b0..0de5bc3e7e0 100644
--- a/src/SecExp/riotControlCenter.tw
+++ b/src/SecExp/riotControlCenter.tw
@@ -1,11 +1,188 @@
 :: riotControlCenter [nobr]
 
+Riot Control Center
+<hr>
 
-
-
-
-
-
--possibility of accepting demands of rebels.
--extermination protocol
--brain chips
\ No newline at end of file
+The riot control center opens its guarded doors to you. The great chanber inside is dominated by massive screens filled with vital information and propaganda being tested.
+<br>
+<br>
+<<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>>
+<br>
+<<if $riotUpgrades.freeMedia == 0>>
+	[[Provide free media acces|riotControlCenter][$cash -= Math.trunc(5000*$upgradeMultiplierArcology), $riotUpgrades.freeMedia = 1, $riotUpkeep += $upgradeUpkeep]]
+	<br>//Costs ¤<<print 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">>
+			<<set $riotUpgrades.freeMedia += 1>>
+			<<set $cash -= 5000 * $upgradeMultiplierArcology * ($riotUpgrades.freeMedia + 1)>>
+			<<set $riotUpkeep += $upgradeUpkeep>>
+			<<goto "riotControlCenter">>
+		<</link>>
+		<br>Invest more resources into the project to increase its effectiveness.
+		<br>//Costs ¤<<print Math.trunc(5000 * $upgradeMultiplierArcology * ($riotUpgrades.freeMedia + 1))>>. Will accelerate the tension decay, but will increase upkeep costs.//
+	<<else>>
+		You upgraded your free media scheme to its limits.
+	<</if>>
+<</if>>
+<br>
+<br>
+<<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>>
+<br>
+<<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>>
+<br>
+<<if $riotUpgrades.rapidUnit == 0>>
+	[[Create rapid deployment riot units|riotControlCenter][$cash -= Math.trunc(7500*$upgradeMultiplierArcology), $riotUpgrades.rapidUnit = 1, $riotUpkeep += $upgradeUpkeep]]
+	<br>//Costs ¤<<print 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">>
+			<<set $riotUpgrades.rapidUnit += 1>>
+			<<set $cash -= 5000 * $upgradeMultiplierArcology * ($riotUpgrades.rapidUnit + 1)>>
+			<<set $riotUpkeep += $upgradeUpkeep>>
+			<<goto "riotControlCenter">>
+		<</link>>
+		<br>Invest more resources into the project to increase its effectiveness.
+		<br>//Costs ¤<<print Math.trunc(5000 * $upgradeMultiplierArcology * ($riotUpgrades.rapidUnit + 1))>>. Will lower action costs.//
+	<<else>>
+		<br>You upgraded your rapid deployment unit to its limits.
+	<</if>>
+	<<if $riotUpgrades.rapidUnitSpeed < 2>>
+		<<link "Enhance the internal informants network">>
+			<<set $riotUpgrades.rapidUnitSpeed += 1>>
+			<<set $cash -= 5000 * $upgradeMultiplierArcology * ($riotUpgrades.rapidUnitSpeed + 1)>>
+			<<set $riotUpkeep += $upgradeUpkeep>>
+			<<goto "riotControlCenter">>
+		<</link>>
+		<br>Invest more resources into the effectivenes of the informants network.
+		<br>//Costs ¤<<print Math.trunc(5000 * $upgradeMultiplierArcology * ($riotUpgrades.rapidUnitSpeed + 1))>>. Will reduce cooldown of the rapid deployment riot unit.//
+	<<else>>
+		<br>You enhanced your informants network to its limits.
+	<</if>>
+	<br>You can send out the squad to slow down the progress of hostile groups within the arcology: <<link "spend authority">>
+		<<set $riotUpgrades.rapidUnitCost = 0>>
+	<</link>>|
+	<<link "spend reputation">>
+		<<set $riotUpgrades.rapidUnitCost = 1>>
+	<</link>>
+	<br>
+	<<if $sentUnitCooldown == 0>>
+		<br><<link "Deploy the unit against slaves rebel leaders">>
+			<<if $riotUpgrades.rapidUnitCost == 0>>
+				<<set $authority -= 1000 + 50 * $riotUpgrades.rapidUnit>>
+			<<else>>
+				<<set $reputation -= 1000 + 50 * $riotUpgrades.rapidUnit>>
+			<</if>>
+			<<set $slaveProgress = Math.clamp($slaveProgress -random(10) + random(1,2) * $riotUpgrades.rapidUnit,0,100)>>
+			<<set $sentUnitCooldown = 3 - $riotUpgrades.rapidUnitSpeed>>
+			<<goto "riotControlCenter">>
+		<</link>>
+		<br><<link "Deploy the unit against citizens rebel leaders">>
+			<<if $riotUpgrades.rapidUnitCost == 0>>
+				<<set $authority -= 1000 + 50 * $riotUpgrades.rapidUnit>>
+			<<else>>
+				<<set $reputation -= 1000 + 50 * $riotUpgrades.rapidUnit>>
+			<</if>>
+			<<set $citizenProgress = Math.clamp($citizenProgress -random(10) + random(1,2) * $riotUpgrades.rapidUnit,0,100)>>
+			<<set $sentUnitCooldown = 3 - $riotUpgrades.rapidUnitSpeed>>
+			<<goto "riotControlCenter">>
+		<</link>>
+	<<else>>
+		The unit cannot be deployed again for $sentUnitCooldown weeks.
+	<</if>>
+<</if>>
+<br>
+<<if $brainImplant == -1>>
+	<<if $brainImplantProject == 0>>
+		<<link "Start secretly installing brain implants in your citizens and resident slaves">>
+			<<set $brainImplantProject = 1>>
+			<<set $riotUpkeep += $10000>>
+		<</link>>
+		<br>//Will take weeks of work and will cost 10000 each, but once finished rebellions will progress a lot slower.//
+	<<else>>
+		<if $brainImplantProject < 5>>
+		<<link "Invest more resources in the brain implant project">>
+			<<set $brainImplantProject += 1>>
+			<<set $cash -= 50000 * $upgradeMultiplierArcology * $brainImplantProject>>
+			<<set $riotUpkeep += $upgradeUpkeep * 100>>
+			<<goto "riotControlCenter">>
+		<</link>>
+		<br>Invest more resources into the project to increase its speed.
+		<br>//Costs ¤<<print Math.trunc(50000 * $upgradeMultiplierArcology * $brainImplantProject>>. Will shorten the time required to complete the project.//
+	<<else>>
+		<br>You sped up the project to its maximum.
+	<</if>>
+<<elseif $brainImplant == 106>>
+	The great brain implant project is underway. Estimated time to completion: <<print Math.trunc(100 - $brainImplant / $brainImplantProject)>>
+<<else>>
+	The great brain implant project is completed, rebellions against you will be extremely difficult to organize.
+<</if>>
+<br>
+<br>
+<<if $advancedRiotEquip == 0>>
+	<<link "Develop advanced anti-riot equipment">>
+		<<set $advancedRiotEquip = 1>>
+		<<set $cash -= 30000>>
+		<<goto "riotControlCenter">>
+	<</link>>
+	<br>//Costs ¤30000. 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 confies of your arcology without the fear of doing major collateral damage.
+<</if>>
+<br>
+<<if $fort.reactor == 0>>
+	<<link "Reinforce the reactor complex">>
+		<<set $fort.reactor = 1>>
+		<<set $cash -= 10000 * $upgradeMultiplierArcology>>
+		<<goto "riotControlCenter">>
+	<</link>>
+	<br>//Costs ¤<<print 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>>
+<br>
+<<if $fort.waterway == 0>>
+	<<link "Reinforce the waterways">>
+		<<set $fort.waterway = 1>>
+		<<set $cash -= 10000 * $upgradeMultiplierArcology>>
+		<<goto "riotControlCenter">>
+	<</link>>
+	<br>//Costs ¤<<print 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>>
+<br>
+<<if $fort.assistant == 0>>
+	<<link "Reinforce the assistant CPU core">>
+		<<set $fort.assistant = 1>>
+		<<set $cash -= 10000 * $upgradeMultiplierArcology>>
+		<<goto "riotControlCenter">>
+	<</link>>
+	<br>//Costs ¤<<print 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>>
\ No newline at end of file
diff --git a/src/SecExp/secInit.tw b/src/SecExp/secInit.tw
index d261199976f..6148026ff70 100644
--- a/src/SecExp/secInit.tw
+++ b/src/SecExp/secInit.tw
@@ -107,6 +107,19 @@
 <<set $secretService = 0>>
 <<set $blackOps = 0>>
 <<set $marketInfiltration = 0>>
+<<set $riotCenter = 0>>
+<<set $riotUpgrades = {
+	freeMedia: 0,
+	rapidUnit: 0,
+	rapidUnitSpeed: 0}>>
+<<set $fort = {
+	reactor: 0,
+	waterway: 0,
+	assistant:0}>>
+<<set $sentUnitCooldown = 0>>
+<<set $advancedRiotEquip = 0>>
+<<set $brainImplant = -1>>
+<<set $brainImplantProject = 0>>
 
 /* events */
 <<set $smilingManProgress = 0>>
@@ -136,14 +149,12 @@
 <<set $rebellingMercs = 0>>
 <<set $repairTime = 3>>
 <<set $arcRepairTime = 0>>
-<<set $arcRepairCost = 1000>>
 <<set $rebelDefeatAftermath = 0>>
 <<set $garrison = {
 	penthouse: 0,
 	reactor: 0,
 	assistant: 0,
 	waterway: 0,
-	penthouseTime: 0,
 	reactorTime: 0,
 	assistantTime: 0,
 	waterwayTime: 0 }>>
diff --git a/src/SecExp/securityReport.tw b/src/SecExp/securityReport.tw
index 1a1389703bc..6619ae36908 100644
--- a/src/SecExp/securityReport.tw
+++ b/src/SecExp/securityReport.tw
@@ -102,6 +102,14 @@
 	Your black ops team proves to be a formidable tool against anyone threatening the security of your arcology.
 	<<set _secGrowth += 0.5 * random(1,2)>>
 <</if>>
+
+<<if $garrison.assistantTime > 0>>
+	With the central CPU core of the assistant down, managing security is a much harder task. Inevitably some little but important details will slip past your agents.
+	It will still take <<if $garrison.assistantTime> 1>>$garrison.assistantTime weeks<<else>>a week<</if>> to finish repair works.
+	<<set _secGrowth-->>
+	<<set _crimeGrowth++>>
+	<<set $garrison.assistantTime-->>
+<</if>>
 	
 <<if $SFSupportLevel >= 3>>
 	The two squads of $securityForceName assigned to the Security HQ provide an essential help to the security department.
@@ -446,4 +454,24 @@
 			<</for>>
 		<</if>>
 	<</if>>
+<</if>>
+
+<br>
+<br>
+<<if $brainImplantProject > 0 && $brainImplant == 106>>
+	<<set $brainImplant += $brainImplantProject>>
+	<<if 100 - $brainImplant <= 0>>
+		The project has been completed!
+		<<set $brainImplant = 101>>
+	<<else>>
+		The great brain implant project is proceeding steadily. This week we made
+		<<if $brainImplantProject <= 2>>
+			some small
+		<<elseif $brainImplantProject <= 4>>
+			some
+		<<else>>
+			good
+		<</if>>
+		progress
+	<</if>>
 <</if>>
\ No newline at end of file
diff --git a/src/events/gameover.tw b/src/events/gameover.tw
index 01582750a04..f2b21b5515e 100644
--- a/src/events/gameover.tw
+++ b/src/events/gameover.tw
@@ -49,6 +49,7 @@
 	<<goto "eliteTakeOver">>
 
 <<elseif $gameover == "major battle defeat">>
+	<<set $ui = "start">>
 	<<if $attackType == "raiders">>
 		As the horde of raiders breaks the battlelines and enter the arcology, all hell break loose. You citizens are raped, your slaves captured and abused, your penthouse burned.
 		As for you, you are quickly captured and brought in front of the warlord himself. With a satisfied smile he aims his pistol to your forehead and squeezes the trigger.
@@ -63,7 +64,10 @@
 		Your personal story may continue, but that part of it worthy of retelling has now ended.
 	<</if>>
 	
+	<br><br>
+	''GAME OVER''
 <<elseif $gameover == "Rebellion defeat">>
+	<<set $ui = "start">>
 	<<if $slaveRebellion == 1>>
 		As the furious horde of slaves invade your penthouse you are left a few precious seconds to decide your fate. You embrace for the last time your faithful revolver and just as the rebels break through your doors you squeeze the trigger.
 		The end of your story has come and your arcology is now in the hands of whoever will take control of the vermins that dared rise up this day.
@@ -72,6 +76,8 @@
 		The end of your story has come and your arcology is now in the hands of whoever will take control of the vermins that dared rise up this day.
 	<</if>>
 	
+	<br><br>
+	''GAME OVER''
 <<else>>
 	<<set $ui = "start">>
 	Since you are without slaves, Free Cities society no longer considers you a citizen of the first rank. Your personal story may continue, but that part of it worthy of retelling has now ended.
diff --git a/src/uncategorized/arcmgmt.tw b/src/uncategorized/arcmgmt.tw
index 6487d36a479..22be24430f6 100644
--- a/src/uncategorized/arcmgmt.tw
+++ b/src/uncategorized/arcmgmt.tw
@@ -120,6 +120,13 @@ This week, <<if _flux > 0>>few to none<<else>>many<</if>> of $arcologies[0].name
 			<<set _immigrants = 40>>
 		<</if>>
 	<</if>>
+	<<if $garrison.waterwayTime > 0>>
+		The damage caused to the water supply of the arcology discourages immigration and causes the death of some of the poorest residents.
+		It will still take <<if $garrison.waterwayTime > 1>>$garrison.waterwayTime weeks<<else>>a week<</if>> to finish repair works.
+		 <<set _immigrants = Math.clamp(_immigrants - random(40,60), 0 , _immigrants)>>
+		 <<set $ACitizens -= random(10,20), $ASlaves -= random(10,20)>>
+		 <<set $garrison.waterwayTime-->>
+	<</if>>
 <</if>>
 <<set $ACitizens += _immigrants>>
 <<if $ACitizens <= 100>>
@@ -541,6 +548,12 @@ earning you @@.yellowgreen;¤_earnings.@@
 			With the global economy recovering from the great crisis unleashed by the Smiling Man, there is plenty of room to grow. Your arcology's prosperity benefits from this greatly.
 			<<set _AWeekGrowth++>>
 		<</if>>
+		<<if $garrison.reactorTime > 0>>
+			The damage to the reactor caused by the last rebellion is extensive. Businesses and private citizens struggle to operate with the unreliable and limited energy production offered by the auxiliary generators.
+			It will still take <<if $garrison.reactorTime> 1>>$garrison.reactorTime weeks<<else>>a week<</if>> to finish repair works.
+			<<set _AWeekGrowth -= random(1,2)>>
+			<<set $garrison.reactorTime-->>			
+		<</if>>
 	<</if>>
 	<<set _AWeekGrowth = Math.trunc(0.5*_AWeekGrowth)>>
 	<<if _AWeekGrowth > 0>>
diff --git a/src/uncategorized/manageArcology.tw b/src/uncategorized/manageArcology.tw
index 898947aa673..2587820e2fb 100644
--- a/src/uncategorized/manageArcology.tw
+++ b/src/uncategorized/manageArcology.tw
@@ -109,6 +109,7 @@ __Construction__
 		<br>
 		The [[security HQ|securityHQ]] is constantly working to protect your arcology.
 	<</if>>
+	
 	<<if $arcologyUpgrade.drones == 1 && $secBarracks == 0>>
 		<br>
 		[[Set up the barracks|Manage Arcology][$cash -= Math.trunc(5000*$upgradeMultiplierArcology), $secBarracks = 1]]
@@ -118,6 +119,16 @@ __Construction__
 		<br>
 		The [[barracks|secBarracks]] patiently await your orders.
 	<</if>>
+
+	<<if $riotCenter == 0 && $rebellionsEnabled == 1>>
+		<br>
+		[[Set up the riot control center|Manage Arcology][$cash -= Math.trunc(5000*$upgradeMultiplierArcology), $riotCenter = 1]]
+		//Costs ¤<<print Math.trunc(5000*$upgradeMultiplierArcology)>>//
+		<br>//Building specialized in the management and suppression of rebellions.//
+	<<else>>
+		<br>
+		The [[Riot Control Center|riotControlCenter]] stands ready for action.
+	<</if>>
 <</if>>
 
 <br><br>
diff --git a/src/uncategorized/nextWeek.tw b/src/uncategorized/nextWeek.tw
index b1706aa0e78..cdf77a5e3c3 100644
--- a/src/uncategorized/nextWeek.tw
+++ b/src/uncategorized/nextWeek.tw
@@ -128,6 +128,10 @@
     <</if>>
 <</if>>
 
+<<if $sentUnitCooldown > 0>>
+	<<set $sentUnitCooldown-->>
+<</if>>
+
 <<if $week == $oldWeek>>
 	<<set $week += 1, $day += 7>>
 	<<switch $month>>
diff --git a/src/uncategorized/persBusiness.tw b/src/uncategorized/persBusiness.tw
index 8ac685121ad..50d772a223b 100644
--- a/src/uncategorized/persBusiness.tw
+++ b/src/uncategorized/persBusiness.tw
@@ -603,6 +603,12 @@
 	<<set $crime += random(0,2)>>
 <</if>>
 
+<<if $arcRepairTime > 0>>
+	The recent rebellion left the arcology wounded and it falls to its owner to fix it. It will still take <<if $arcRepairTime > 1>>$arcRepairTime weeks<<else>>a week<</if>> to finish repair works.
+	<<set $cash -= 5000>>
+	<<set $arcRepairTime-->>
+<</if>>
+
 Routine upkeep of your demesne costs @@.yellow;¤$costs.@@
 <<if $plot == 1>>
 <<if $week > 10>>
-- 
GitLab