From c33314a20a047850178e5d86c869b7f178e2d237 Mon Sep 17 00:00:00 2001
From: hexall90 <hexall90@gmail.com>
Date: Sat, 11 Nov 2017 21:53:03 +0100
Subject: [PATCH] fixes

---
 src/SecExp/SecExpBackwardCompatibility.tw |   3 +
 src/SecExp/attackGenerator.tw             |  10 +-
 src/SecExp/secExpOptions.tw               | 146 +++++++++++++-
 src/SecExp/secInit.tw                     |   1 +
 src/SecExp/transportHub.tw                |  41 ++++
 src/SecExp/unitsRebellionReport.tw        | 235 +++++++++++-----------
 src/SecExp/weaponsManufacturing.tw        |  26 +--
 7 files changed, 332 insertions(+), 130 deletions(-)

diff --git a/src/SecExp/SecExpBackwardCompatibility.tw b/src/SecExp/SecExpBackwardCompatibility.tw
index 432927f1c1f..6cd4232d65b 100644
--- a/src/SecExp/SecExpBackwardCompatibility.tw
+++ b/src/SecExp/SecExpBackwardCompatibility.tw
@@ -75,6 +75,9 @@
 <<if ndef $battlesEnabled>>
 <<set $battlesEnabled = 1>>
 <</if>>
+<<if ndef $battlesEnabledOceanic>>
+<<set $battlesEnabledOceanic = 0>>
+<</if>>
 <<if ndef $majorBattlesEnabled>>
 <<set $majorBattlesEnabled = 1>>
 <</if>>
diff --git a/src/SecExp/attackGenerator.tw b/src/SecExp/attackGenerator.tw
index d515ad5f3eb..22b275ce829 100644
--- a/src/SecExp/attackGenerator.tw
+++ b/src/SecExp/attackGenerator.tw
@@ -2,7 +2,7 @@
 
 /* _attackChance value is the chance out of 100 of an attack happening this week */
 /* attacks are deactivated if battles are not enabled, the arcology is in the middle of the ocean, security drones are not around yet, there is not a rebellion this week or the last attack/rebellion happened within 3 weeks */
-<<if $battlesEnabled == 0 || $terrain == "oceanic" || $arcologyUpgrade.drones != 1 || $lastAttackWeeks <= 3 || $citizenRebellion == 1 || $slaveRebellion == 1 || $lastRebellionWeeks <= 3>>
+<<if $battlesEnabled == 0 || ($terrain == "oceanic" && $battlesEnabledOceanic == 0) || $arcologyUpgrade.drones != 1 || $lastAttackWeeks <= 3 || $citizenRebellion == 1 || $slaveRebellion == 1 || $lastRebellionWeeks <= 3>>
 	<<set _attackChance = 0>>
 <<else>>
 	<<if $week < 30>>
@@ -119,6 +119,8 @@
 			<<set $battleTerrain = either("mountains","outskirts","hills","wasteland")>>
 		<<elseif $terrain == "marine">>
 			<<set $battleTerrain = either("coast","outskirts","hills","wasteland")>>
+		<<elseif $terrain == "oceanic">>
+			<<set $battleTerrain = either("coast","outskirts","hills","wasteland")>>
 		<<else>>
 			<<set $battleTerrain = "err">>
 		<</if>>
@@ -152,6 +154,8 @@
 			<<set $battleTerrain = either("mountains","outskirts","hills","wasteland")>>
 		<<elseif $terrain == "marine">>
 			<<set $battleTerrain = either("coast","outskirts","hills","wasteland")>>
+		<<elseif $terrain == "oceanic">>
+			<<set $battleTerrain = either("coast","outskirts","hills","wasteland")>>
 		<<else>>
 			<<set $battleTerrain = "err">>
 		<</if>>
@@ -185,6 +189,8 @@
 			<<set $battleTerrain = either("mountains","outskirts","hills","wasteland")>>
 		<<elseif $terrain == "marine">>
 			<<set $battleTerrain = either("coast","outskirts","hills","wasteland")>>
+		<<elseif $terrain == "oceanic">>
+			<<set $battleTerrain = either("coast","outskirts","hills","wasteland")>>
 		<<else>>
 			<<set $battleTerrain = "err">>
 		<</if>>
@@ -218,6 +224,8 @@
 			<<set $battleTerrain = either("mountains","outskirts","hills","wasteland")>>
 		<<elseif $terrain == "marine">>
 			<<set $battleTerrain = either("coast","outskirts","hills","wasteland")>>
+		<<elseif $terrain == "oceanic">>
+			<<set $battleTerrain = either("coast","outskirts","hills","wasteland")>>
 		<<else>>
 			<<set $battleTerrain = "err">>
 		<</if>>
diff --git a/src/SecExp/secExpOptions.tw b/src/SecExp/secExpOptions.tw
index 6423b1cad50..d760e690f82 100644
--- a/src/SecExp/secExpOptions.tw
+++ b/src/SecExp/secExpOptions.tw
@@ -156,6 +156,122 @@
 				<<goto "secExpOptions">>
 			<</link>>
 		
+		<<else>>
+			Major battle guaranteed this week is @@.cyan;TRUE@@.
+		<<link "Do not force major engagement every week">>
+				<<set $forceMajorBattle = 0>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<</if>>
+		//Will force major battles to happen every week. //
+	<</if>>
+<<else>>
+	<br>
+	<br>
+	Oceanic arcologies are not by default subject to external attacks. You can however allow them to happen anyway, keep in mind, however, that descriptions and mechanics are not intended for naval combat but land combat.
+	<<if $arcologyUpgrade.drones == 1>>
+		<br>
+		<br>
+		<<if $battlesEnabledOceanic == 0>>
+			Battles are @@.red;DISABLED@@.
+			<<link "Enable battles">>
+				<<set $battlesEnabledOceanic = 1>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<<else>>
+			Battles are @@.cyan;ENABLED@@.
+		<<link "Disable battles">>
+				<<set $battlesEnabledOceanic = 0>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<</if>>
+		//Enable/disable battles.//
+	<</if>>
+	<<if $arcologyUpgrade.drones == 1 && $battlesEnabledOceanic == 1>>
+		<br>
+		<br>
+		<<if $majorBattlesEnabled == 0>>
+			Major battles are @@.red;DISABLED@@.
+			<<link "Enable major battles">>
+				<<set $majorBattlesEnabled = 1>>
+				<<set $battlesEnabledOceanic = 1>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<<else>>
+			Major battles are @@.cyan;ENABLED@@.
+		<<link "Disable major battles">>
+				<<set $majorBattlesEnabled = 0>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<</if>>
+		//Enable/disable late game large scale battles.//
+	<</if>>
+	<<if $arcologyUpgrade.drones == 1 && $battlesEnabledOceanic == 1>>
+		<br>
+		<br>
+		<<if $majorBattleGameOver == 0>>
+			Major battles can cause gameover is @@.red;FALSE@@.
+			<<link "Activate game loss in case of major battle defeat">>
+				<<set $majorBattleGameOver = 1>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<<else>>
+			Major battles can cause gameover is @@.cyan;TRUE@@.
+		<<link "Deactivate game loss in case of major battle defeat">>
+				<<set $majorBattleGameOver = 0>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<</if>>
+		//By default a total defeat in a major battle will cause a gameover.//
+	<</if>>
+	<br>
+	<br>
+	<<if $showBattleStatistics == 0 && $battlesEnabledOceanic == 1 && $arcologyUpgrade.drones == 1>>
+		Detailed battle statistics are @@.red;HIDDEN@@.
+		<<link "enable detailed battle statistics">>
+			<<set $showBattleStatistics = 1>>
+			<<goto "secExpOptions">>
+		<</link>>
+	<<else>>
+		Detailed battle statistics are @@.cyan;SHOWN@@.
+		<<link "enable detailed battle statistics">>
+			<<set $showBattleStatistics = 0>>
+			<<goto "secExpOptions">>
+		<</link>>
+	<</if>>
+	//Will show detailed statistics and battle turns.//
+	<<if $arcologyUpgrade.drones == 1 && $battlesEnabledOceanic == 1>>
+		<br>
+		<br>
+		<<if $forceBattle == 0>>
+			Battle guaranteed this week is @@.red;FALSE@@.
+			<<link "Force engagement every week">>
+				<<set $forceBattle = 1>>
+				<<goto "secExpOptions">>
+			<</link>>
+		
+		<<else>>
+			Battle guaranteed this week is @@.cyan;TRUE@@.
+		<<link "Do not force engagement every week">>
+				<<set $forceBattle = 0>>
+				<<goto "secExpOptions">>
+			<</link>>
+		<</if>>
+		//Will force battles to happen every week.//
+	<</if>>
+	<<if $arcologyUpgrade.drones == 1 && $battlesEnabledOceanic == 1>>
+		<br>
+		<br>
+		<<if $forceMajorBattle == 0>>
+			Major battle guaranteed this week is @@.red;FALSE@@.
+			<<link "Force major engagement every week">>
+				<<set $forceMajorBattle = 1>>
+				<<if $forceBattle == 0>>
+					<<set $forceBattle = 1>>
+				<</if>>
+				<<goto "secExpOptions">>
+			<</link>>
+		
 		<<else>>
 			Major battle guaranteed this week is @@.cyan;TRUE@@.
 		<<link "Do not force major engagement every week">>
@@ -171,7 +287,7 @@
 <br>
 
 __Debug/cheats:__
-<br><<link "Stabilize loyalty">>
+<br><<link "Stabilize average">>
 	<<for _i = 0; _i < $militiaUnits.length; _i++>>
 		<<set $militiaUnits[_i].loyalty = random(40,60)>>
 	<</for>>
@@ -185,6 +301,34 @@ __Debug/cheats:__
 	<</for>>
 	<<goto "secExpOptions">>
 <</link>>
+<br><<link "Set loyalty high">>
+	<<for _i = 0; _i < $militiaUnits.length; _i++>>
+		<<set $militiaUnits[_i].loyalty = random(80,100)>>
+	<</for>>
+
+	<<for _i = 0; _i < $slaveUnits.length; _i++>>
+		<<set $slaveUnits[_i].loyalty = random(80,100)>>
+	<</for>>
+	
+	<<for _i = 0; _i < $mercUnits.length; _i++>>
+		<<set $mercUnits[_i].loyalty = random(80,100)>>
+	<</for>>
+	<<goto "secExpOptions">>
+<</link>>
+<br><<link "Set loyalty low">>
+	<<for _i = 0; _i < $militiaUnits.length; _i++>>
+		<<set $militiaUnits[_i].loyalty = random(20)>>
+	<</for>>
+
+	<<for _i = 0; _i < $slaveUnits.length; _i++>>
+		<<set $slaveUnits[_i].loyalty = random(20)>>
+	<</for>>
+	
+	<<for _i = 0; _i < $mercUnits.length; _i++>>
+		<<set $mercUnits[_i].loyalty = random(20)>>
+	<</for>>
+	<<goto "secExpOptions">>
+<</link>>
 <br><<link "Give Authority">>
 	<<set $authority = Math.clamp($authority + 1000, 0, 20000)>>
 	<<goto "secExpOptions">>
diff --git a/src/SecExp/secInit.tw b/src/SecExp/secInit.tw
index 709a28b4d05..2e7f4f778b6 100644
--- a/src/SecExp/secInit.tw
+++ b/src/SecExp/secInit.tw
@@ -27,6 +27,7 @@
 <<set $forceMajorBattle = 0>>
 <<set $foughtThisWeek = 0>>
 <<set $battlesEnabled = 1>>
+<<set $battlesEnabledOceanic = 0>>
 <<set $majorBattlesEnabled = 1>>
 <<set $majorBattleGameOver = 1>>
 <<set $rebellionsEnabled = 1>>
diff --git a/src/SecExp/transportHub.tw b/src/SecExp/transportHub.tw
index 0515267548f..9bd15a8f1ec 100644
--- a/src/SecExp/transportHub.tw
+++ b/src/SecExp/transportHub.tw
@@ -5,3 +5,44 @@
 <strong>The transport hub</strong>
 <hr>
 
+<<if $airport == 1>>
+	The arcology's airport is relatively small underequipped. It can handle some traffic, but nothing noteworthy.
+<<elseif $airport == 2>>
+	The arcology's airport is relatively small, but well equipped. It can handle some traffic, but nothing too serious.
+<<elseif $airport == 3>>
+	The arcology's airport is good sized and well equipped. It can handle a good amount of traffic.
+<<elseif $airport == 4>>
+	The arcology's airport is good sized and very well equipped. It can handle a lot of traffic.
+<<else>>
+	The arcology's airport is huge and very well equipped. It can handle an impressive amount of traffic.
+<</if>>
+
+<<if $terrain != "oceanic" || $terrain != "marine">>
+	<br>
+	<<if $railway == 1>>
+		The railway network is old and limited. It can handle some traffic, but not sustain commercial activity.
+	<<elseif $railway == 2>>
+		The railway network is modern and efficient, but limited in reach. It can handle some traffic, but not sustain commercial activity of significant size.
+	<<elseif $railway == 2>>
+		The railway network is modern, efficient and expansive. It can handle a significant amount of traffic.
+	<<else>>
+		The railway network is high tech and very far reaching. It can handle an enormous amount of traffic.
+	<</if>>
+<<else>>
+	<br>
+	<<if $docks == 1>>
+
+	<<elseif $docks == 2>>
+
+	<<elseif $docks == 2>>
+
+	<<else>>
+
+	<</if>>
+<</if>>
+
+/* airport */
+
+/* trainyard/dockyard */
+
+/* security */
\ No newline at end of file
diff --git a/src/SecExp/unitsRebellionReport.tw b/src/SecExp/unitsRebellionReport.tw
index b785a76bc0d..5cc79f3fe68 100644
--- a/src/SecExp/unitsRebellionReport.tw
+++ b/src/SecExp/unitsRebellionReport.tw
@@ -268,7 +268,7 @@
 				<<else>>
 					catastrofic casualties
 				<</if>>
-				<<set _med = Math.round(Math.clamp(_loss * $militiaUnits[_j].medics * 0.25,1,_loss))>>
+				<<set _med = Math.round(Math.clamp(_loss * $mercUnits[_j].medics * 0.25,1,_loss))>>
 				<<if $mercUnits[_j].medics == 1>>
 					, however some men were saved by the medics attached to this unit.
 				<<else>>
@@ -306,147 +306,152 @@
 				<<set _militiaManpower += Math.clamp($militiaUnits[_j].troops - random(_averageLosses),0,$militiaUnits[_j].troops)>>
 			<</if>>
 		<</for>>
-		had the gall to betray you and join your enemies.
 		<<if _militiaRebelled.length > 0>>
+			had the gall to betray you and join your enemies.
 			<span id="militiaResult">
-			<br><<link "Dissolve the units">>
-				<<set $militiaUnits.delete(_militiaRebelled)>>
-				<<set $militiaFreeManpower += _militiaManpower>>
-				<<for _i = 0; _i < $militiaUnits.length; _i++>>
-					<<if $militiaUnits[_i].active == 1>>
-						<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty - random(10,40),0,100)>>
-					<</if>>
-				<</for>>
-				<<recalcManpower>>
-				<<replace "#militiaResult">>
-					<br>Units dissolved.
-				<</replace>>
-			<</link>>
-			<br>//Manpower will be refunded, but will negatvely influence the loyalty of the other units//
-			<br><<link "Purge the dissidents and dissolve the units">>
-				<<set $militiaUnits.delete(_militiaRebelled)>>
-				<<set $militiaFreeManpower += _militiaManpower * 0.5>>
-				<<recalcManpower>>
-				<<replace "#militiaResult">>
-					<br>Dissidents purged and units dissolved.
-				<</replace>>
-			<</link>>
-			<br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//
-			<br><<link "Execute them all">>
-				<<set $militiaUnits.delete(_militiaRebelled)>>
-				<<for _i = 0; _i < $militiaUnits.length; _i++>>
-					<<if $militiaUnits[_i].active == 1>>
-						<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty + random(10,40),0,100)>>
-					<</if>>
-				<</for>>
-				<<recalcManpower>>
-				<<replace "#militiaResult">>
-					<br>Units executed. Dissent will not be tolerated.
-				<</replace>>
-			<</link>>
-			<br>//Will positively influence the loyalty of the other units, but no manpower will be refunded.//
+				<br><<link "Dissolve the units">>
+					<<set $militiaUnits.delete(_militiaRebelled)>>
+					<<set $militiaFreeManpower += _militiaManpower>>
+					<<for _i = 0; _i < $militiaUnits.length; _i++>>
+						<<if $militiaUnits[_i].active == 1>>
+							<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty - random(10,40),0,100)>>
+						<</if>>
+					<</for>>
+					<<recalcManpower>>
+					<<replace "#militiaResult">>
+						<br>Units dissolved.
+					<</replace>>
+				<</link>>
+				<br>//Manpower will be refunded, but will negatvely influence the loyalty of the other units//
+				<br><<link "Purge the dissidents and dissolve the units">>
+					<<set $militiaUnits.delete(_militiaRebelled)>>
+					<<set $militiaFreeManpower += _militiaManpower * 0.5>>
+					<<recalcManpower>>
+					<<replace "#militiaResult">>
+						<br>Dissidents purged and units dissolved.
+					<</replace>>
+				<</link>>
+				<br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//
+				<br><<link "Execute them all">>
+					<<set $militiaUnits.delete(_militiaRebelled)>>
+					<<for _i = 0; _i < $militiaUnits.length; _i++>>
+						<<if $militiaUnits[_i].active == 1>>
+							<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty + random(10,40),0,100)>>
+						<</if>>
+					<</for>>
+					<<recalcManpower>>
+					<<replace "#militiaResult">>
+						<br>Units executed. Dissent will not be tolerated.
+					<</replace>>
+				<</link>>
+				<br>//Will positively influence the loyalty of the other units, but no manpower will be refunded.//
+			</span>
 		<</if>>
 		
 		/* slaves */
 		<<set _slaveRebelled = []>>
 		<<set _slaveManpower = 0>>
+		<br>
 		<<for _j = 0; _j < $slaveUnits.length; _j++>>
 			<<if $slaveUnits[_j].active == 1 && _rebellingID.includes($slaveUnits[_j].ID)>>
-				<br>$slaveUnits[_j].platoonName,
+				$slaveUnits[_j].platoonName,
 				<<set _slaveRebelled.push($slaveUnits[_j])>>
 				<<set _slaveManpower += Math.clamp($slaveUnits[_j].troops - random(_averageLosses),0,$slaveUnits[_j].troops)>>
 			<</if>>
 		<</for>>
-		decided in their blind arrogance to betray you.
 		<<if _slaveRebelled.length > 0>>
+			decided in their blind arrogance to betray you.
 			<span id="slaveResult">
-			<br><<link "Dissolve the units">>
-				<<set $slaveUnits.delete(_slaveRebelled)>>
-				<<set $helots += _slaveManpower>>
-				<<for _i = 0; _i < $militiaUnits.length; _i++>>
-					<<if $slaveUnits[_i].active == 1>>
-						<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty - random(10,40),0,100)>>
-					<</if>>
-				<</for>>
-				<<recalcManpower>>
-				<<replace "#slaveResult">>
-					<br>Units dissolved.
-				<</replace>>
-			<</link>>
-			<br>//Manpower will be refunded, but will negatively influence the loyalty of the other units//
-			<br><<link "Purge the dissidents and dissolve the units">>
-				<<set $slaveUnits.delete(_slaveRebelled)>>
-				<<set $helots += _slaveManpower * 0.5>>
-				<<recalcManpower>>
-				<<replace "#slaveResult">>
-					<br>Dissidents purged and units dissolved.
-				<</replace>>
-			<</link>>
-			<br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//
-			<br><<link "Execute them all">>
-				<<set $slaveUnits.delete(_slaveRebelled)>>
-				<<for _i = 0; _i < $slaveUnits.length; _i++>>
-					<<if $slaveUnits[_i].active == 1>>
-						<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty + random(10,40),0,100)>>
-					<</if>>
-				<</for>>
-				<<recalcManpower>>
-				<<replace "#slaveResult">>
-					<br>Units executed. Dissent will not be tolerated.
-				<</replace>>
-			<</link>>
-			<br>//Will positively influence the loyalty of the other units, but no manpower will be refunded.//
+				<br><<link "Dissolve the units">>
+					<<set $slaveUnits.delete(_slaveRebelled)>>
+					<<set $helots += _slaveManpower>>
+					<<for _i = 0; _i < $militiaUnits.length; _i++>>
+						<<if $slaveUnits[_i].active == 1>>
+							<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty - random(10,40),0,100)>>
+						<</if>>
+					<</for>>
+					<<recalcManpower>>
+					<<replace "#slaveResult">>
+						<br>Units dissolved.
+					<</replace>>
+				<</link>>
+				<br>//Manpower will be refunded, but will negatively influence the loyalty of the other units//
+				<br><<link "Purge the dissidents and dissolve the units">>
+					<<set $slaveUnits.delete(_slaveRebelled)>>
+					<<set $helots += _slaveManpower * 0.5>>
+					<<recalcManpower>>
+					<<replace "#slaveResult">>
+						<br>Dissidents purged and units dissolved.
+					<</replace>>
+				<</link>>
+				<br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//
+				<br><<link "Execute them all">>
+					<<set $slaveUnits.delete(_slaveRebelled)>>
+					<<for _i = 0; _i < $slaveUnits.length; _i++>>
+						<<if $slaveUnits[_i].active == 1>>
+							<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty + random(10,40),0,100)>>
+						<</if>>
+					<</for>>
+					<<recalcManpower>>
+					<<replace "#slaveResult">>
+						<br>Units executed. Dissent will not be tolerated.
+					<</replace>>
+				<</link>>
+				<br>//Will positively influence the loyalty of the other units, but no manpower will be refunded.//
+			</span>
 		<</if>>
 		
 		/* mercs */
 		<<set _mercRebelled = []>>
 		<<set _mercManpower = 0>>
+		<br>
 		<<for _j = 0; _j < $mercUnits.length; _j++>>
 			<<if $mercUnits[_j].active == 1 && _rebellingID.includes($mercUnits[_j].ID)>>
-				<br>$mercUnits[_j].platoonName,
+				$mercUnits[_j].platoonName,
 				<<set _mercRebelled.push($mercUnits[_j])>>
 				<<set _mercManpower += Math.clamp($mercUnits[_j].troops - random(_averageLosses),0,$mercUnits[_j].troops)>>
 			<</if>>
 		<</for>>
-		made the grave mistake of betraying you.
 		<<if _mercRebelled.length > 0>>
+			made the grave mistake of betraying you.
 			<span id="mercResult">
-			<br><<link "Dissolve the units">>
-				<<set $mercUnits.delete(_mercRebelled)>>
-				<<set $mercFreeManpower += _mercManpower>>
-				<<for _i = 0; _i < $militiaUnits.length; _i++>>
-					<<if $mercUnits[_i].active == 1>>
-						<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty - random(10,40),0,100)>>
-					<</if>>
-				<</for>>
-				<<recalcManpower>>
-				<<replace "#mercResult">>
-					<br>Units dissolved.
-				<</replace>>
-			<</link>>
-			<br>//Manpower will be refunded, but will negatively influence the loyalty of the other units//
-			<br><<link "Purge the dissidents and dissolve the units">>
-				<<set $mercUnits.delete(_mercRebelled)>>
-				<<set $mercFreeManpower += _mercManpower * 0.5>>
-				<<recalcManpower>>
-				<<replace "#mercResult">>
-					<br>Dissidents purged and units dissolved.
-				<</replace>>
-			<</link>>
-			<br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//
-			<br><<link "Execute them all">>
-				<<set $mercUnits.delete(_mercRebelled)>>
-				<<for _i = 0; _i < $mercUnits.length; _i++>>
-					<<if $mercUnits[_i].active == 1>>
-						<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty + random(10,40),0,100)>>
-					<</if>>
-				<</for>>
-				<<recalcManpower>>
-				<<replace "#mercResult">>
-					<br>Units executed. Dissent will not be tolerated.
-				<</replace>>
-			<</link>>
-			<br>//Will positively influence the loyalty of the other units, but no manpower will be refunded.//
+				<br><<link "Dissolve the units">>
+					<<set $mercUnits.delete(_mercRebelled)>>
+					<<set $mercFreeManpower += _mercManpower>>
+					<<for _i = 0; _i < $militiaUnits.length; _i++>>
+						<<if $mercUnits[_i].active == 1>>
+							<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty - random(10,40),0,100)>>
+						<</if>>
+					<</for>>
+					<<recalcManpower>>
+					<<replace "#mercResult">>
+						<br>Units dissolved.
+					<</replace>>
+				<</link>>
+				<br>//Manpower will be refunded, but will negatively influence the loyalty of the other units//
+				<br><<link "Purge the dissidents and dissolve the units">>
+					<<set $mercUnits.delete(_mercRebelled)>>
+					<<set $mercFreeManpower += _mercManpower * 0.5>>
+					<<recalcManpower>>
+					<<replace "#mercResult">>
+						<br>Dissidents purged and units dissolved.
+					<</replace>>
+				<</link>>
+				<br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.//
+				<br><<link "Execute them all">>
+					<<set $mercUnits.delete(_mercRebelled)>>
+					<<for _i = 0; _i < $mercUnits.length; _i++>>
+						<<if $mercUnits[_i].active == 1>>
+							<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty + random(10,40),0,100)>>
+						<</if>>
+					<</for>>
+					<<recalcManpower>>
+					<<replace "#mercResult">>
+						<br>Units executed. Dissent will not be tolerated.
+					<</replace>>
+				<</link>>
+				<br>//Will positively influence the loyalty of the other units, but no manpower will be refunded.//
+			</span>
 		<</if>>
 		
 	/* loss */
@@ -460,7 +465,6 @@
 				had the gall to betray you and join your enemies. They participated in the looting following the battle, then vanished in the wastes.
 			<</if>>
 		<</for>>
-		<<recalcManpower>>
 		<<set $cash -= 1000 * _militiaRebelled>>
 		<br>
 		<<set _slaveRebelled = 0>>
@@ -483,6 +487,7 @@
 			<</if>>
 		<</for>>
 		<<set $cash -= 1000 * _mercRebelled>>
+		<<recalcManpower>>
 	<</if>>
 <<else>>
 	<br>@@.red;Error: losses are a negative number or NaN@@
diff --git a/src/SecExp/weaponsManufacturing.tw b/src/SecExp/weaponsManufacturing.tw
index 2caf8d6e76e..9d33d52ebbe 100644
--- a/src/SecExp/weaponsManufacturing.tw
+++ b/src/SecExp/weaponsManufacturing.tw
@@ -28,7 +28,7 @@ many small old world nations as the advanced technology that free cities have av
 	There's a large lab attached to the complex. The complement of equipment and personnel makes it a great beacon of military science in an otherwise ignorant world.
 <</if>>
 <br>
-<<if $weapHelots> 0>>Assigned here are $weapHelots, working to produce as much equipment as possible<<else>>There are no assigned menial slaves here. The spaces is manned exclusively by low rank citizens.<</if>>
+<<if $weapHelots> 0>>Assigned here are $weapHelots slaves working to produce as much equipment as possible<<else>>There are no assigned menial slaves here. The spaces is manned exclusively by low rank citizens.<</if>>
 You own $helots free menial slaves. This manufacturing complex can house 500 at most, with <<print 500 - $weapHelots>> free slots.
 <br>
 <<silently>><<MenialPopCap>><</silently>>
@@ -179,40 +179,40 @@ __Upgrades__:
 			<<set $currentUpgrade = {
 				name: "dynamic battle aware AI",
 				unit: 0,
-				type: attack,
+				type: "attack",
 				time: _time,
 				ready: 1,
 				value: 1}>>
 			<<set $cash -= 10000>>
 			<<goto "weaponsManufacturing">>
 		<</link>>
-		<br>//Will take _time weeks, cost ¤10000 and will increase the base attack value of the security drones.//
+		<br>//Will take _time weeks, cost ¤10000 and will increase the base "attack" value of the security drones.//
 	<<elseif $weapLab >= 2 && $secBotsBaseDefense == 3>>
 		<<link "Develop adaptive armored frames">>
 			<<set $currentUpgrade = {
 				name: "adaptive armored frames",
 				unit: 0,
-				type: defense,
+				type: "defense",
 				time: _time,
 				value: 1}>>
 			<<set $cash -= 10000>>
 			<<goto "weaponsManufacturing">>
 		<</link>>
-		<br>//Will take _time weeks, cost ¤10000 and will increase the base defense value of the security drones.//
+		<br>//Will take _time weeks, cost ¤10000 and will increase the base "defense" value of the security drones.//
 	<<elseif $weapLab >= 3 && $secBotsBaseHp <= 3>>
 		<br>
 		<<link "Develop advanced synthetic alloys">>
 			<<set $currentUpgrade = {
 				name: "advanced synthetic alloys",
 				unit: 0,
-				type: hp,
+				type: "hp",
 				time: _time,
 				ready: 1,
 				value: 1}>>
 			<<set $cash -= 30000>>
 			<<goto "weaponsManufacturing">>
 		<</link>>
-		<br>//Will take _time weeks, cost ¤30000 and will increase the base hp value of the security drones.//
+		<br>//Will take _time weeks, cost ¤30000 and will increase the base "hp" value of the security drones.//
 	<<elseif $secBotsBaseDefense <= 3 || $secBotsBaseHp <= 3>>
 		Upgrade the research facility further to unlock more upgrades for the security drones.
 	<<else>>
@@ -231,7 +231,7 @@ __Upgrades__:
 			<<set $cash -= 30000>>
 			<<goto "weaponsManufacturing">>
 		<</link>>
-		<br>//Will take _time weeks, cost ¤30000 and will increase the base attack value of all human troops.//
+		<br>//Will take _time weeks, cost ¤30000 and will increase the base "attack" value of all human troops.//
 		<br>
 		<<link "Develop ceramo-metallic alloys">>
 			<<set $currentUpgrade = {
@@ -243,7 +243,7 @@ __Upgrades__:
 			<<set $cash -= 30000>>
 			<<goto "weaponsManufacturing">>
 		<</link>>
-		<br>//Will take _time weeks, cost ¤30000 and will increase the base defense value of all human troops.//
+		<br>//Will take _time weeks, cost ¤30000 and will increase the base "defense" value of all human troops.//
 	<<elseif $humanUpgrades <= 4 && $weapLab == 2>>
 		<br>
 		<<link "Develop rapid action stimulants">>
@@ -256,7 +256,7 @@ __Upgrades__:
 			<<set $cash -= 60000>>
 			<<goto "weaponsManufacturing">>
 		<</link>>
-		<br>//Will take _time weeks, cost ¤60000 and will increase the base hp value of all human troops.//
+		<br>//Will take _time weeks, cost ¤60000 and will increase the base "hp" value of all human troops.//
 		<br>
 		<<link "Develop fast response neural stimulant">>
 			<<set $currentUpgrade = {
@@ -282,7 +282,7 @@ __Upgrades__:
 			<<set $cash -= 120000>>
 			<<goto "weaponsManufacturing">>
 		<</link>>
-		<br>//Will take _time weeks, cost ¤120000 and will increase the base attack and defense value of all human troops.//
+		<br>//Will take _time weeks, cost ¤120000 and will increase the base "attack" and "defense" value of all human troops.//
 		<br>
 		<<link "Develop remote neural links">>
 			<<set $currentUpgrade = {
@@ -294,7 +294,7 @@ __Upgrades__:
 			<<set $cash -= 120000>>
 			<<goto "weaponsManufacturing">>
 		<</link>>
-		<br>//Will take _time weeks, cost ¤120000 and will increase the base hp and morale value of all human troops.//
+		<br>//Will take _time weeks, cost ¤120000 and will increase the base "hp" and morale value of all human troops.//
 	<<elseif $humanUpgrades <= 6>>
 		Upgrade the research facility further to unlock more upgrades for human troops.
 	<<else>>
@@ -308,7 +308,7 @@ __Upgrades__:
 	<<if $currentUpgrade.type == "attack">>
 		attack power.
 	<<elseif $currentUpgrade.type == "defense">>
-		defense capabilities.
+		defensive capabilities.
 	<<elseif $currentUpgrade.type == "hp">>
 		survivability.
 	<<elseif $currentUpgrade.type == "morale">>
-- 
GitLab