From 81223ba66a235e261044c653f2043d70e9f0095d Mon Sep 17 00:00:00 2001
From: hexall90 <hexall90@gmail.com>
Date: Sun, 1 Oct 2017 21:42:38 +0200
Subject: [PATCH] working on security report

---
 TODO.txt                                      |   3 +-
 src/SecExp/SecExpBackwardCompatibility.tw     |  68 +--
 src/SecExp/attackHandler.tw                   |  46 ++-
 src/SecExp/attackOptions.tw                   |  13 +-
 src/SecExp/secBarracks.tw                     | 386 ++++++++++++++++--
 src/SecExp/secInit.tw                         |  72 ++--
 src/SecExp/securityHQ.tw                      |  17 +-
 src/SecExp/securityReport.tw                  |  44 +-
 src/SecExp/seeUnit.tw                         | 151 ++++++-
 src/SecExp/weaponsManufactoring.tw            |   1 +
 src/SecExp/widgets/unitsDescriptionWidgets.tw |  97 ++++-
 src/uncategorized/pMercenaries.tw             |   4 +
 12 files changed, 754 insertions(+), 148 deletions(-)
 create mode 100644 src/SecExp/weaponsManufactoring.tw

diff --git a/TODO.txt b/TODO.txt
index 5ed4f50f298..51c5d5840a0 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -2,4 +2,5 @@
 -sea attacks
 -randomize the battle day, so that it is not always the same day the turn is given
 -add fortifications
--add casualties to the counters
\ No newline at end of file
+-add casualties to the counters
+-add upkeep costs
\ No newline at end of file
diff --git a/src/SecExp/SecExpBackwardCompatibility.tw b/src/SecExp/SecExpBackwardCompatibility.tw
index f8d904c9610..b6f8a904cff 100644
--- a/src/SecExp/SecExpBackwardCompatibility.tw
+++ b/src/SecExp/SecExpBackwardCompatibility.tw
@@ -11,7 +11,7 @@
 	<<set $secRestPoint = 40>>
 <</if>>
 <<if ndef $crime>>
-	<<set $crime = 0>>
+	<<set $crime = 20>>
 <</if>>
 <<if ndef $crimeCap>>
 	<<set $crimeCap = 100>>
@@ -20,7 +20,7 @@
 	<<set $readiness = 1>>
 <</if>>
 <<if ndef $maxUnits>>
-	<<set $maxUnits = 10>>
+	<<set $maxUnits = 6>>
 <</if>>
 <<if ndef $activeUnits>>
 	<<set $activeUnits = 0>>
@@ -51,6 +51,12 @@
 <<if ndef $secBarracks>>
 	<<set $secBarracks = 0>>
 <</if>>
+<<if ndef $secBarracksUpgrades>>
+	<<set $secBarracksUpgrades ={
+	size: 0,
+	luxury: 0,
+	training: 0}>> 
+<</if>>
 <<if ndef $secHelots>>
 	<<set $secHelots = 0>>
 <</if>>
@@ -85,6 +91,21 @@
 <</if>>
 
 /* armed forces stats */
+<<if ndef $targetUnit>>
+<<set $targetUnit = 0>>
+<</if>>
+<<if ndef $targetIndex>>
+<<set $targetIndex = 0>>
+<</if>>
+<<if ndef $secBotsCost>>
+<<set $secBotsCost = 500>>
+<</if>>
+<<if ndef $secBotsUpgradeCost>>
+<<set $secBotsUpgradeCost = 250>>
+<</if>>
+<<if ndef $equipUpgradeCost>>
+<<set $equipUpgradeCost = 250>>
+<</if>>
 <<if ndef $maxTroops>>
 <<set $maxTroops = 30>>
 <</if>>
@@ -118,8 +139,17 @@
 <<if ndef $slavesMaxTroops>>
 <<set $slavesMaxTroops = 30>>
 <</if>>
-<<if ndef $mercManpower>>
-<<set $mercManpower = 0>>
+<<if ndef $mercTotalManpower>>
+<<set $mercTotalManpower = 0>>
+<</if>>
+<<if ndef $mercFreeManpower>>
+<<set $mercFreeManpower = 0>>
+<</if>>
+<<if ndef mercEmployedManpower>>
+<<set $mercEmployedManpower = 0>>
+<</if>>
+<<if ndef $mercTotalCasualties>>
+<<set $mercTotalCasualties = 0>>
 <</if>>
 <<if ndef $militiaLoyalty>>
 <<set $militiaLoyalty = 0>>
@@ -282,40 +312,10 @@
 
 <<if ndef $militiaUnits>>
 	<<set $militiaUnits = []>>
-	<<set $militiaUnits[0] = {
-	active: 0,
-	isDeployed: 0,
-	troops: 0,
-	maxTroops: 0,
-	equip: 0,
-	training: 0,
-	loyalty: 0,
-	medics: 0,
-	escorts: 0}>>
 <</if>>
 <<if ndef $slaveUnits>>
 	<<set $slaveUnits = []>>
-	<<set $slaveUnits[0] = {
-	active: 0,
-	isDeployed: 0,
-	troops: 0,
-	maxTroops: 0,
-	equip: 0,
-	training: 0,
-	loyalty: 0,
-	medics: 0,
-	escorts: 0}>>
 <</if>>
 <<if ndef $mercUnits>>
 	<<set $mercUnits = []>>
-	<<set $mercUnits[0] = {
-	active: 0,
-	isDeployed: 0,
-	troops: 0,
-	maxTroops: 0,
-	equip: 0,
-	training: 0,
-	loyalty: 0,
-	medics: 0,
-	escorts: 0}>>
 <</if>>
\ No newline at end of file
diff --git a/src/SecExp/attackHandler.tw b/src/SecExp/attackHandler.tw
index e05571ba466..f250b5ba0e5 100644
--- a/src/SecExp/attackHandler.tw
+++ b/src/SecExp/attackHandler.tw
@@ -22,6 +22,7 @@
 <<set _slaveMod = 1>>
 <<set _mercMod = 1>>
 <<set _enemyMod = 1>>
+<<set _expBonus = 0>>
 
 /* Leaders */
 <<if $leadingTroops == "PC">>
@@ -723,7 +724,6 @@
 <<set _militiaMorale = 0>>
 <<set _slaveMorale = 0>>
 <<set _mercMorale = 0>>
-<<set _escortBonus = 0>>
 
 /* calculates PC army stats */
 <<if $secBots.isDeployed == 1>>
@@ -733,38 +733,50 @@
 <</if>>
 <<for _i = 0; _i < _mL; _i++>>
 	<<if $militiaUnits[_i].isDeployed == 1>>
-		<<set _attack += ($militiaBaseAttack + $militiaBaseAttack * $militiaUnits[_i].equip * $equipMod) * _atkMod>>
-		<<set _defense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod) * _defMod>>
-		<<set _hp += ($militiaBaseHp + $militiaBaseHp * $militiaUnits[_i].medics * $equipMod) * $militiaUnits[_i].troops>>
-		<<if $militiaUnits[_i].escorts == 1>>
-			<<set _escortBonus++>>
+		<<if $militiaUnits[_i].training <= 33>>
+			<<set _expBonus = 0>>
+		<<elseif $militiaUnits[_i].training <= 66>>
+			<<set _expBonus = 0.25>>
+		<<else>>
+			<<set _expBonus = 0.50>>
 		<</if>>
+		<<set _attack += ($militiaBaseAttack + $militiaBaseAttack * $militiaUnits[_i].equip * $equipMod + $militiaBaseAttack * _expBonus) * _atkMod>>
+		<<set _defense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod + $militiaBaseDefense * _expBonus) * _defMod>>
+		<<set _hp += ($militiaBaseHp + $militiaBaseHp * $militiaUnits[_i].medics * $equipMod) * $militiaUnits[_i].troops>>
 	<</if>>
 <</for>>
 <<for _i = 0; _i < _sL; _i++>>
 	<<if $slaveUnits[_i].isDeployed == 1>>
-		<<set _attack += ($slaveBaseAttack + $slaveBaseAttack * $slaveUnits[_i].equip * $equipMod) * _atkMod>>
-		<<set _defense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod) * _defMod>>
-		<<set _hp += ($slaveBaseHp + $slaveBaseHp * $slaveUnits[_i].medics * 0.25) * $slaveUnits[_i].troops>>
-		<<if $slaveUnits[_i].escorts == 1>>
-			<<set _escortBonus++>>
+		<<if $slaveUnits[_i].training <= 33>>
+			<<set _expBonus = 0>>
+		<<elseif $slaveUnits[_i].training <= 66>>
+			<<set _expBonus = 0.25>>
+		<<else>>
+			<<set _expBonus = 0.50>>
 		<</if>>
+		<<set _attack += ($slaveBaseAttack + $slaveBaseAttack * $slaveUnits[_i].equip * $equipMod + $slaveBaseAttack * _expBonus) * _atkMod>>
+		<<set _defense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod + $slaveBaseDefense * _expBonus) * _defMod>>
+		<<set _hp += ($slaveBaseHp + $slaveBaseHp * $slaveUnits[_i].medics * 0.25) * $slaveUnits[_i].troops>>
 	<</if>>
 <</for>>
 <<for _i = 0; _i < _meL; _i++>>
 	<<if $mercUnits[_i].isDeployed == 1>>
-		<<set _attack += ($mercBaseAttack + $mercBaseAttack * $mercUnits[_i].equip * $equipMod) * _atkMod>>
-		<<set _defense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod) * _defMod>>
-		<<set _hp += ($mercBaseHp + $mercBaseHp * $mercUnits[_i].medics * 0.25) * $mercUnits[_i].troops>>
-		<<if $mercUnits[_i].escorts == 1>>
-			<<set _escortBonus++>>
+		<<if $mercUnits[_i].training <= 33>>
+			<<set _expBonus = 0>>
+		<<elseif $mercUnits[_i].training <= 66>>
+			<<set _expBonus = 0.25>>
+		<<else>>
+			<<set _expBonus = 0.50>>
 		<</if>>
+		<<set _attack += ($mercBaseAttack + $mercBaseAttack * $mercUnits[_i].equip * $equipMod + $mercBaseAttack * _expBonus) * _atkMod>>
+		<<set _defense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod + $mercBaseDefense * _expBonus) * _defMod>>
+		<<set _hp += ($mercBaseHp + $mercBaseHp * $mercUnits[_i].medics * 0.25) * $mercUnits[_i].troops>>
 	<</if>>
 <</for>>
 
 /* morale and baseHp calculation */
 <<set _morale = ($secBotsMorale * $deployingBots + _militiaMorale * _militiaMod * $deployingMilitia + $slaveBaseMorale * _slaveMod * $deployingSlaves + $mercBaseMorale * _mercMod * $deployingMercs) / ($deployingBots + $deployingMilitia +$deployingSlaves + $deployingMercs)>>
-<<set _morale = _morale + _morale * _escortBonus * 0.05>>	/* each escort upgrade gives +5% morale */
+<<set _morale = _morale + _morale * $secBarracksUpgrades.luxury * 0.05>>	/* barracks bonus */
 <<set _baseHp = ($secBotsBaseHp * $deployingBots + $militiaBaseHp * $deployingMilitia + $slaveBaseHp * $deployingSlaves + $mercBaseHp * $deployingMercs) / ($deployingBots + $deployingMilitia +$deployingSlaves + $deployingMercs)>>
 				
 /* calculates enemy army stats */
diff --git a/src/SecExp/attackOptions.tw b/src/SecExp/attackOptions.tw
index e9a0d64fd6f..545160825a9 100644
--- a/src/SecExp/attackOptions.tw
+++ b/src/SecExp/attackOptions.tw
@@ -1,7 +1,5 @@
 :: attackOptions [nobr]
 
-
-
 <strong>Attack Imminent</strong>
 <hr>
 The ominous message dominates the screens of your office, <<print $assistantName>> quickly gathers all information available to prepare your arcology for battle.
@@ -151,14 +149,6 @@ They seems to be
 
 You quickly lay down a plan of action:
 <br>
-<<link "Let the assistant handle this attack">>
-	<<if $assistantPower == 2>>
-	<<elseif $assistantPower == 1>>
-	<<else>>
-	<</if>>
-<</link>>
-
-<br>&nbsp;&nbsp;&nbsp;&nbsp;//$assistantName will handle leaders, tactics and troop deployment to the best of her abilities. To be implemented//
 
 <br><br>
 
@@ -205,7 +195,8 @@ You quickly lay down a plan of action:
 
 /* troop deployment */
 <br><br>
-With your current readiness level you can <<if $deployedUnits > 0>>still<</if>> send <strong><<print $deployableUnits>></strong>. Available units:
+With your current readiness level you can <<if $deployedUnits > 0>>still<</if>> send <strong><<print $deployableUnits>></strong> units.
+<br>
 
 <<set _mL = $militiaUnits.length>>
 <<set _sL = $slaveUnits.length>>
diff --git a/src/SecExp/secBarracks.tw b/src/SecExp/secBarracks.tw
index 36d642d7b84..84af5992c8e 100644
--- a/src/SecExp/secBarracks.tw
+++ b/src/SecExp/secBarracks.tw
@@ -2,20 +2,153 @@
 
 The Barracks
 <hr>
+__Upgrades__
+<br>
+While for many a sore sight in a free city, the barracks stand proud before you.
+<<if $secBarracksUpgrades.size == 0>>
+	The building is relatively small and able to house a limited number of units.
+<<elseif $secBarracksUpgrades.size == 1>>
+	The building has been expanded and can now house more units comfortably.
+<<elseif $secBarracksUpgrades.size == 2>>
+	The building has been greatly expanded and can now house a small army.
+<</if>>
+<<if $secBarracksUpgrades.luxury == 0>>
+	The barracks are a spartan building, with little to make the day to day lives of your soldiers pleasant.
+<<elseif $secBarracksUpgrades.luxury == 1>>
+	The barracks have been made more comfortable by installing high tech furniture.
+<<elseif $secBarracksUpgrades.luxury == 2>>
+	The barracks have been made more comfortable by installing high tech furniture and advanced kitchen facilities.
+<<elseif $secBarracksUpgrades.luxury == 3>>
+	The barracks have been made more comfortable by installing high tech furniture and advanced kitchen facilities. It also provides free access to any digital media.
+<<else>>
+	The barracks have been made more comfortable by installing high tech furniture and advanced kitchen facilities. It also provides free access to any digital media. A small limited access brothel has been added to the structure.
+<</if>>
+<<if $secBarracksUpgrades.training == 0>>
+	The building lacks the space and the equipment to train your units.
+<<elseif $secBarracksUpgrades.training == 1>>
+	A training facility has been set up, allowing your units to better their skills with time.
+<<else>>
+	The training facility has been filled with specialized equipment and skilled trainers.
+<</if>>
+<br>
+<br>
+<<if $secBarracksUpgrades.size < 2>>
+	<<link "Increase the size of the barracks">>
+		<<set $secBarracksUpgrades.size += 1>>
+		<<set $maxUnits += 2>>
+		<<set $cash -= 10000>>
+		<<goto "secBarracks">>
+	<</link>>
+	<br>//Costs ¤10000 and will increase the maximum number of units by 2.//
+<<else>>
+	You've expanded the barracks to their maximum.
+<</if>>
+<br>
+<<if $secBarracksUpgrades.luxury == 0>>
+	<<link "Increase the quality of life of your soldiers by installing high tech furniture and appliances.">>
+		<<set $secBarracksUpgrades.luxury += 1>>
+		<<set $cash -= 5000>>
+		<<goto "secBarracks">>
+	<</link>>
+	<br>//Costs ¤5000 and will provide a 5% bonus to morale.//
+<<elseif $secBarracksUpgrades.luxury == 1>>
+	<<link "Further increase the quality of life of your soldiers by installing advanced kitchen equipment and hiring skilled chefs.">>
+		<<set $secBarracksUpgrades.luxury += 1>>
+		<<set $cash -= 10000>>
+		<<goto "secBarracks">>
+	<</link>>
+	<br>//Costs ¤10000 and will provide a 5% bonus to morale, for a total of +10%.//
+<<elseif $secBarracksUpgrades.luxury == 2>>
+	<<link "Further increase the quality of life of your soldiers by providing high speed, free access to digital media">>
+		<<set $secBarracksUpgrades.luxury += 1>>
+		<<set $cash -= 10000>>
+		<<goto "secBarracks">>
+	<</link>>
+	<br>//Costs ¤10000 and will provide a 5% bonus to morale, for a total of +15%.//
+<<elseif $secBarracksUpgrades.luxury == 3>>
+	<<link "Further increase the quality of life of your soldiers by adding and staffing an exclusive brothel to the structure">>
+		<<set $secBarracksUpgrades.luxury += 1>>
+		<<set $cash -= 15000>>
+		<<goto "secBarracks">>
+	<</link>>
+	<br>//Costs ¤15000 and will provide a 5% bonus to morale, for a total of +20%.//
+<<else>>
+	You've made life in your barracks as good as it can get.
+<</if>>
+<br>
+<<if $secBarracksUpgrades.training == 0>>
+	<<link "Add a training facility to the barracks">>
+		<<set $secBarracksUpgrades.training += 1>>
+		<<set $cash -= 10000>>
+		<<goto "secBarracks">>
+	<</link>>
+	<br>//Costs ¤10000 and will allow units to accumulate some experience each week.//
+<<elseif $secBarracksUpgrades.training == 1>>
+	<<link "Improve the training facility with modern equipment and skilled personnel">>
+		<<set $secBarracksUpgrades.training += 1>>
+		<<set $cash -= 20000>>
+		<<goto "secBarracks">>
+	<</link>>
+	<br>//Costs ¤20000 and will allow units to accumulate experience each week.//
+<<else>>
+	You have improved the training facility to the limit.
+<</if>>
+
+<br>
+<br>
+
+__Units__
+<br>
+Your maximum number of units is <<print $maxUnits>>, currently you have <<print $activeUnits>>. <<if $secBarracksUpgrades.luxury > 0>>The barracks provide <<print $secBarracksUpgrades.luxury * 5>>% bonus morale in case of a battle.<</if>><<if $secBarracksUpgrades.training > 0>> The training facility will increase the effectiveness of your units with time.<</if>>
+
+<br>
+<br>
+
+/* drones */
+<<if $secBots.active == 1>>
+	<hr>
+	<<secBotsDescription>>
+	<br>
+	<<link "Review Equipment and upgrades">>
+		<<set $targetUnit = "secBots">>
+		<<goto "seeUnit">>
+	<</link>>
+	<<if $secBots.troops < $secBots.maxTroops>>
+	|
+		<<link "Replenish the unit">>
+			<<set $cash -= ($secBots.maxTroops - $secBots.troops) * $secBotsCost>>
+			<<set $secBots.troops = $secBots.maxTroops>>
+			<<goto "secBarracks">>
+		<</link>>
+	<</if>>
+<<else>>
+	You have lost too many security drones to be able to field them again.
+	<<link "Reform the unit">>
+			<<set $cash -= ($secBots.maxTroops - $secBots.troops) * $secBotsCost>>
+			<<set $secBots.troops = $secBots.maxTroops>>
+			<<set $secBots.active == 1>>
+			<<goto "secBarracks">>
+		<<goto "secBarracks">>
+	<</link>>
+<</if>>
+
+<br>
+<br>
 
 /* slaves */
 You are free to organize your menial slaves into fighting units. Currently you have <<print $helots>> slaves available, while <<print $slavesEmployedManpower>> are already employed as soldiers. During all your battles you lost a total of <<print $slavesTotalCasualties>>.
+<br>
 <<set _sL = $slaveUnits.length>>
 <<if $helots > 0 && $activeUnits < $maxUnits>>
 	<<link "Form a new unit">>
-		<<if _sL == 0>>
-			<<set _name = _sL + "st slave platoon">>
-		<<elseif _sL == 1>>
-			<<set _name = _sL + "nd slave platoon">>
-		<<elseif _sL == 2>>
-			<<set _name = _sL + "rd slave platoon">>
+		<<if $slaveUnits.length == 0>>
+			<<set _name = (1+$slaveUnits.length) + "st slave platoon">>
+		<<elseif $slaveUnits.length == 1>>
+			<<set _name = (1+$slaveUnits.length) + "nd slave platoon">>
+		<<elseif $slaveUnits.length == 2>>
+			<<set _name = (1+$slaveUnits.length) + "rd slave platoon">>
 		<<else>>
-			<<set _name = _sL + "th slave platoon">>
+			<<set _name = (1+$slaveUnits.length) + "th slave platoon">>
 		<</if>>
 		<<if $helots >= $maxTroops>>
 			<<set _newUnit = {
@@ -28,7 +161,7 @@ You are free to organize your menial slaves into fighting units. Currently you h
 			training: 0,
 			loyalty: 0,
 			medics: 0,
-			escorts: 0}>>
+			battlesFought: 0}>>
 			<<set $slaveUnits.push(_newUnit)>>
 			<<set $helots -= 30>>
 			<<set $slavesEmployedManpower += 30>>
@@ -43,7 +176,7 @@ You are free to organize your menial slaves into fighting units. Currently you h
 			training: 0,
 			loyalty: 0,
 			medics: 0,
-			escorts: 0}>>
+			battlesFought: 0}>>
 			<<set $slaveUnits.push(_newUnit)>>
 			<<set $slavesEmployedManpower += _newUnit.troops>>
 			<<set $helots = 0>>
@@ -51,23 +184,35 @@ You are free to organize your menial slaves into fighting units. Currently you h
 		<<set $activeUnits++>>
 		<<goto "secBarracks">>
 	<</link>>
+<<elseif $helots > 0>>
+	You have reached the maximum number of units. You'll have to disband one or enlarge the barracks before forming a new unit.
+<<elseif $activeUnits < $maxUnits>>
+	You don't have any free menial slave with which to form a new unit.
 <</if>>
-<br>
 <<for _i = 0; _i < _sL; _i++>>
+	<<capture _i>>
 	<<if $slaveUnits[_i].active == 1>>
-		<br>
+		<hr>
 		<<slaveUnitsDescription $slaveUnits[_i]>>
 		<br>
 		<<link "Disband the unit">>
 			<<set $helots += $slaveUnits[_i].troops>>
 			<<set $slavesEmployedManpower -= $slaveUnits[_i].troops>>
-			<<set $slaveUnits.deleteAt(_i)>>
+			<<set _elimUnit = $slaveUnits[_i]>>
+			<<set _newSlaveUnits = []>>
+			<<for _y = 0; _y < _sL; _y++>>
+				<<if $slaveUnits[_y] != _elimUnit>>
+					<<set _newSlaveUnits.push($slaveUnits[_y])>>
+				<</if>>
+			<</for>>
+			<<set $slaveUnits = _newSlaveUnits>>
 			<<set $activeUnits-->>
 			<<goto "secBarracks">>
 		<</link>>
 		|
-		<<link "Review Equipment">>
-			<<set $targetUnit = $slaveUnits[_i]>>
+		<<link "Review Equipment and upgrades">>
+			<<set $targetUnit = "slaveUnits">>
+			<<set $targetIndex = _i>>
 			<<goto "seeUnit">>
 		<</link>>
 		|
@@ -76,20 +221,32 @@ You are free to organize your menial slaves into fighting units. Currently you h
 				<<if $helots >= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
 					<<set $helots -= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
 					<<set $slavesEmployedManpower += $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>>
+					<<set _expLoss = ($slaveUnits[_i].maxTroops - $slaveUnits[_i].troops) / $slaveUnits[_i].troops>>
+					<<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>>
 					<<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>>
 				<<else>>
 					<<set $slavesEmployedManpower += $helots>>
+					<<set _expLoss = $helots / $slaveUnits[_i].troops>>
+					<<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>>
 					<<set $slaveUnits[_i].troops += $helots>>
 					<<set $helots = 0>>
 				<</if>>
 				<<goto "secBarracks">>
 			<</link>>
 		<</if>>
+		
 	<<else>>
 		$slaveUnits[_i].platoonName lost too many operatives to be considered active.
 		<br>
 		<<link "Disband the unit">>
-			<<set $slaveUnits.deleteAt(_i)>>
+			<<set _elimUnit = $slaveUnits[_i]>>
+			<<set _newSlaveUnits = []>>
+			<<for _y = 0; _y < _sL; _y++>>
+				<<if $slaveUnits[_y] != _elimUnit>>
+					<<set _newSlaveUnits.push($slaveUnits[_y])>>
+				<</if>>
+			<</for>>
+			<<set $slaveUnits = _newSlaveUnits>>
 			<<set $activeUnits-->>
 			<<goto "secBarracks">>
 		<</link>>
@@ -100,15 +257,19 @@ You are free to organize your menial slaves into fighting units. Currently you h
 					<<set $slavesEmployedManpower += $slaveUnits[_i].maxTroops>>
 					<<set $helots -= $slaveUnits[_i].maxTroops>>
 					<<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>>
+					<<set $slaveUnits[_i].training = 0>>
 				<<else>>
 					<<set $slavesEmployedManpower += $helots>>
 					<<set $slaveUnits[_i].troops += $helots>>
 					<<set $helots = 0>>
+					<<set $slaveUnits[_i].training = 0>>
 				<</if>>
+				<<set $slaveUnits[_i].active == 1>>
 				<<goto "secBarracks">>
 			<</link>>
 		<</if>>
 	<</if>>
+	<</capture>>
 <</for>>
 
 <br>
@@ -129,14 +290,14 @@ You are free to organize your menial slaves into fighting units. Currently you h
 	<<set _mL = $militiaUnits.length>>
 	<<if $militiaFreeManpower > 0 && $activeUnits < $maxUnits>>
 		<<link "Form a new unit">>
-			<<if _mL == 0>>
-				<<set _name = _mL + "st citizens' platoon">>
-			<<elseif _mL == 1>>
-				<<set _name = _mL + "nd citizens' platoon">>
-			<<elseif _mL == 2>>
-				<<set _name = _mL + "rd citizens' platoon">>
+			<<if $militiaUnits.length == 0>>
+				<<set _name = (1+$militiaUnits.length) + "st citizens' platoon">>
+			<<elseif $militiaUnits.length == 1>>
+				<<set _name = (1+$militiaUnits.length) + "nd citizens' platoon">>
+			<<elseif $militiaUnits.length == 2>>
+				<<set _name = (1+$militiaUnits.length) + "rd citizens' platoon">>
 			<<else>>
-				<<set _name = _mL + "th citizens' platoon">>
+				<<set _name = (1+$militiaUnits.length) + "th citizens' platoon">>
 			<</if>>
 			<<if $militiaFreeManpower >= $maxTroops>>
 				<<set _newUnit = {
@@ -149,7 +310,7 @@ You are free to organize your menial slaves into fighting units. Currently you h
 				training: 0,
 				loyalty: 0,
 				medics: 0,
-				escorts: 0}>>
+				battlesFought: 0}>>
 				<<set $militiaUnits.push(_newUnit)>>
 				<<set $militiaFreeManpower -= 30>>
 				<<set $militiaEmployedManpower += 30>>
@@ -164,7 +325,7 @@ You are free to organize your menial slaves into fighting units. Currently you h
 				training: 0,
 				loyalty: 0,
 				medics: 0,
-				escorts: 0}>>
+				battlesFought: 0}>>
 				<<set $militiaUnits.push(_newUnit)>>
 				<<set $militiaEmployedManpower += _newUnit.troops>>
 				<<set $militiaFreeManpower = 0>>
@@ -172,23 +333,36 @@ You are free to organize your menial slaves into fighting units. Currently you h
 			<<set $activeUnits++>>
 			<<goto "secBarracks">>
 		<</link>>
+	<<elseif $militiaFreeManpower > 0>>
+		You have reached the maximum number of units. You'll have to disband one or enlarge the barracks before forming a new unit.
+	<<elseif $activeUnits < $maxUnits>>
+		You don't have any free recruits with which to form a new unit.
 	<</if>>
 	<br>
 	<<for _i = 0; _i < _mL; _i++>>
+		<<capture _i>>
 		<<if $militiaUnits[_i].active == 1>>
-			<br>
+			<hr>
 			<<militiaUnitsDescription $militiaUnits[_i]>>
 			<br>
 			<<link "Disband the unit">>
 				<<set $militiaFreeManpower += $militiaUnits[_i].troops>>
 				<<set $militiaEmployedManpower -= $militiaUnits[_i].troops>>
-				<<set $militiaUnits.deleteAt(_i)>>
+				<<set _elimUnit = $militiaUnits[_i]>>
+				<<set _newMilitiaUnits = []>>
+				<<for _y = 0; _y < _sL; _y++>>
+					<<if $slaveUnits[_y] != _elimUnit>>
+						<<set _newMilitiaUnits.push($militiaUnits[_y])>>
+					<</if>>
+				<</for>>
+				<<set $militiaUnits = _newMilitiaUnits>>
 				<<set $activeUnits-->>
 				<<goto "secBarracks">>
 			<</link>>
 			|
-			<<link "Review Equipment">>
-				<<set $targetUnit = $militiaUnits[_i]>>
+			<<link "Review Equipment and upgrades">>
+				<<set $targetUnit = "militiaUnits">>
+				<<set $targetIndex = _i>>
 				<<goto "seeUnit">>
 			<</link>>
 			|
@@ -197,9 +371,13 @@ You are free to organize your menial slaves into fighting units. Currently you h
 					<<if $militiaFreeManpower >= $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>>
 						<<set $militiaFreeManpower -= $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>>
 						<<set $militiaEmployedManpower += $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>>
+						<<set _expLoss = ($militiaUnits[_i].maxTroops - $militiaUnits[_i].troops) / $militiaUnits[_i].troops>>
+						<<set $militiaUnits[_i].training -= $militiaUnits[_i].training * _expLoss>>
 						<<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>>
 					<<else>>
 						<<set $militiaEmployedManpower += $militiaFreeManpower>>
+						<<set _expLoss = $militiaFreeManpower / $militiaUnits[_i].troops>>
+						<<set $militiaUnits[_i].training -= $militiaUnits[_i].training * _expLoss>>
 						<<set $militiaUnits[_i].troops += $militiaFreeManpower>>
 						<<set $militiaFreeManpower = 0>>
 					<</if>>
@@ -212,7 +390,14 @@ You are free to organize your menial slaves into fighting units. Currently you h
 			<<link "Disband the unit">>
 				<<set $militiaFreeManpower += $militiaUnits[_i].troops>>
 				<<set $militiaEmployedManpower -= $militiaUnits[_i].troops>>
-				<<set $militiaUnits.deleteAt(_i)>>
+				<<set _elimUnit = $militiaUnits[_i]>>
+				<<set _newMilitiaUnits = []>>
+				<<for _y = 0; _y < _sL; _y++>>
+					<<if $slaveUnits[_y] != _elimUnit>>
+						<<set _newMilitiaUnits.push($militiaUnits[_y])>>
+					<</if>>
+				<</for>>
+				<<set $militiaUnits = _newMilitiaUnits>>
 				<<set $activeUnits-->>
 				<<goto "secBarracks">>
 			<</link>>
@@ -223,18 +408,161 @@ You are free to organize your menial slaves into fighting units. Currently you h
 						<<set $militiaEmployedManpower += $militiaUnits[_i].maxTroops>>
 						<<set $militiaFreeManpower -= $militiaUnits[_i].maxTroops>>
 						<<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>>
+						<<set $militiaUnits[_i].training = 0>>
 					<<else>>
 						<<set $militiaEmployedManpower += $militiaFreeManpower>>
 						<<set $militiaUnits[_i].troops += $militiaFreeManpower>>
 						<<set $militiaFreeManpower = 0>>
+						<<set $militiaUnits[_i].training = 0>>
 					<</if>>
+					<<set $militiaUnits[_i].active == 1>>
 					<<goto "secBarracks">>
 				<</link>>
 			<</if>>
 		<</if>>
+		<</capture>>
 	<</for>>
 	<br>
 <<else>>
 	You have not yet founded the militia, you will not be able to form citizens units.
 <</if>>
 
+/* mercenaries */
+<<if $mercenaries >= 1>>
+	With the installation of a mercenary company in the arcology, many other are attracted to your free city, hoping to land a contract with you.
+	You are able to organize them in units to use in the defense of the arcology. Excluding the defense force you set up, there are <<print $mercTotalManpower>> mercenaries in your arcology, of which <<print $mercEmployedManpower>> actively employed and <<print $mercFreeManpower>> not yet under contract. In total <<print $mercTotalCasualties>> mercenaries have died defending your arcology.
+	<br>
+	<<set _meL = $mercUnits.length>>
+	<<if $mercFreeManpower > 0 && $activeUnits < $maxUnits>>
+		<<link "Form a new unit">>
+			<<if $mercUnits.length == 0>>
+				<<set _name = (1+$mercUnits.length) + "st mercenary platoon">>
+			<<elseif $mercUnits.length == 1>>
+				<<set _name = (1+$mercUnits.length) + "nd mercenary platoon">>
+			<<elseif $mercUnits.length == 2>>
+				<<set _name = (1+$mercUnits.length) + "rd mercenary platoon">>
+			<<else>>
+				<<set _name = (1+$mercUnits.length) + "th mercenary platoon">>
+			<</if>>
+			<<if $mercManpower >= $maxTroops>>
+				<<set _newUnit = {
+				platoonName: _name,
+				active: 1,
+				isDeployed: 0,
+				troops: $maxTroops,
+				maxTroops: $maxTroops,
+				equip: 0,
+				training: 0,
+				loyalty: 0,
+				medics: 0,
+				battlesFought: 0}>>
+				<<set $mercUnits.push(_newUnit)>>
+				<<set $mercFreeManpower -= 30>>
+				<<set $mercEmployedManpower += 30>>
+			<<else>>
+				<<set _newUnit = {
+				platoonName: _name,
+				active: 1,
+				isDeployed: 0,
+				troops: $mercFreeManpower,
+				maxTroops: $maxTroops,
+				equip: 0,
+				training: 0,
+				loyalty: 0,
+				medics: 0,
+				battlesFought: 0}>>
+				<<set $mercUnits.push(_newUnit)>>
+				<<set $mercEmployedManpower += _newUnit.troops>>
+				<<set $mercFreeManpower = 0>>
+			<</if>>
+			<<set $activeUnits++>>
+			<<goto "secBarracks">>
+		<</link>>
+	<<elseif $mercFreeManpower > 0>>
+		You have reached the maximum number of units. You'll have to disband one or enlarge the barracks before forming a new unit.
+	<<elseif $activeUnits < $maxUnits>>
+		You don't have any free mercenaries with which to form a new unit.
+	<</if>>
+	<<for _i = 0; _i < _meL; _i++>>
+		<<capture _i>>
+		<<if $mercUnits[_i].active == 1>>
+			<hr>
+			<<mercUnitsDescription $mercUnits[_i]>>
+			<br>
+			<<link "Disband the unit">>
+				<<set $mercFreeManpower += $mercUnits[_i].troops>>
+				<<set $mercEmployedManpower -= $mercUnits[_i].troops>>
+				<<set _elimUnit = $mercUnits[_i]>>
+				<<set _newMercUnits = []>>
+				<<for _y = 0; _y < _meL; _y++>>
+					<<if $mercUnits[_y] != _elimUnit>>
+						<<set _newMercUnits.push($mercUnits[_y])>>
+					<</if>>
+				<</for>>
+				<<set $mercUnits = _newMercUnits>>
+				<<set $activeUnits-->>
+				<<goto "secBarracks">>
+			<</link>>
+			|
+			<<link "Review Equipment and upgrades">>
+				<<set $targetUnit = "mercUnits">>
+				<<set $targetIndex = _i>>
+				<<goto "seeUnit">>
+			<</link>>
+			|
+			<<if $mercUnits[_i].troops < $mercUnits[_i].maxTroops && $mercFreeManpower > 0>>
+				<<link "Replenish unit">>
+					<<if $mercFreeManpower >= $mercUnits[_i].maxTroops - $mercUnits[_i].troops>>
+						<<set $mercFreeManpower -= $mercUnits[_i].maxTroops - $mercUnits[_i].troops>>
+						<<set $mercEmployedManpower += $mercUnits[_i].maxTroops - $mercUnits[_i].troops>>
+						<<set _expLoss = ($mercUnits[_i].maxTroops - $mercUnits[_i].troops) / $mercUnits[_i].troops>>
+						<<set $mercUnits[_i].training -= $mercUnits[_i].training * _expLoss>>
+						<<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>>
+					<<else>>
+						<<set $mercEmployedManpower += $mercFreeManpower>>
+						<<set _expLoss = $mercFreeManpower / $mercUnits[_i].troops>>
+						<<set $mercUnits[_i].training -= $mercUnits[_i].training * _expLoss>>
+						<<set $mercUnits[_i].troops += $mercFreeManpower>>
+						<<set $mercFreeManpower = 0>>
+					<</if>>
+					<<goto "secBarracks">>
+				<</link>>
+			<</if>>
+			
+		<<else>>
+			$mercUnits[_i].platoonName lost too many operatives to be considered active.
+			<br>
+			<<link "Disband the unit">>
+				<<set _elimUnit = $mercUnits[_i]>>
+				<<set _newMercUnits = []>>
+				<<for _y = 0; _y < _sL; _y++>>
+					<<if $mercUnits[_y] != _elimUnit>>
+						<<set _newMercUnits.push($mercUnits[_y])>>
+					<</if>>
+				<</for>>
+				<<set $mercUnits = _newMercUnits>>
+				<<set $activeUnits-->>
+				<<goto "secBarracks">>
+			<</link>>
+			|
+			<<if $mercFreeManpower > 0>>
+				<<link "Reform the unit">>
+					<<if $mercFreeManpower >= $mercUnits[_i].maxTroops>>
+						<<set $mercEmployedManpower += $mercUnits[_i].maxTroops>>
+						<<set $mercFreeManpower -= $mercUnits[_i].maxTroops>>
+						<<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>>
+						<<set $mercUnits[_i].training = 0>>
+					<<else>>
+						<<set $mercEmployedManpower += $mercFreeManpower>>
+						<<set $mercUnits[_i].troops += $mercFreeManpower>>
+						<<set $mercFreeManpower = 0>>
+						<<set $mercUnits[_i].training = 0>>
+					<</if>>
+					<<set $mercUnits[_i].active == 1>>
+					<<goto "secBarracks">>
+				<</link>>
+			<</if>>
+		<</if>>
+		<</capture>>
+	<</for>>
+<</if>>
\ No newline at end of file
diff --git a/src/SecExp/secInit.tw b/src/SecExp/secInit.tw
index abcda3522f7..73e3a17c2d4 100644
--- a/src/SecExp/secInit.tw
+++ b/src/SecExp/secInit.tw
@@ -7,7 +7,7 @@
 <<set $crime = 20>>
 <<set $crimeCap = 100>>
 <<set $readiness = 1>>
-<<set $maxUnits = 10>>
+<<set $maxUnits = 6>>
 <<set $activeUnits = 0>>
 <<set $attackType = "none">>
 <<set $attackThisWeek = 0>>
@@ -21,6 +21,10 @@
 /* buildings */
 <<set $secHQ = 0>>
 <<set $secBarracks = 0>>
+<<set $secBbarracksUpgrades ={
+	size: 0,
+	luxury: 0,
+	training: 0}>>
 <<set $secHelots = 0>>
 <<set $reqHelots = 20>>
 <<set $secUpgrades = {
@@ -40,10 +44,15 @@
 <<set $readinessUpgrades = {
 	earlyWarn: 0,
 	rapidPlatforms: 0,
-	pathways: 0}>>
-	
+	pathways: 0,
+	rapidVehicles: 0}>>
 
 /* armed forces stats */
+<<set $targetUnit = 0>>
+<<set $targetIndex = 0>>
+<<set $secBotsCost = 500>>
+<<set $secBotsUpgradeCost = 250>>
+<<set $equipUpgradeCost = 250>>
 <<set $maxTroops = 30>>
 <<set $militiaFounded = 0>>
 <<set $militiaRecruitment = 0>>
@@ -54,8 +63,10 @@
 <<set $slavesOfficers = 0>>
 <<set $slavesEmployedManpower = 0>>
 <<set $slavesTotalCasualties = 0>>
-<<set $slavesMaxTroops = 30>>
-<<set $mercManpower = 0>>
+<<set $mercTotalManpower = 0>>
+<<set $mercFreeManpower = 0>>
+<<set $mercEmployedManpower = 0>>
+<<set $mercTotalCasualties = 0>>
 <<set $militiaLoyalty = 0>>
 <<set $slaveArmyLoyalty = 0>>
 <<set $mercLoyalty = 0>>
@@ -165,26 +176,15 @@
 		<<set $militiaUnits[_i].training = 0>>
 		<<set $militiaUnits[_i].loyalty = 0>>
 		<<set $militiaUnits[_i].medics = 0>>
-		<<set $militiaUnits[_i].escorts = 0>>
+		<<set $militiaUnits[_i].battlesFought = 0>>
 	<</for>>
 <<else>>
 	<<set $militiaUnits = []>>
-	<<set $militiaUnits[0] = {
-	platoonName: "1st citizens' platoon",
-	active: 0,
-	isDeployed: 0,
-	troops: 0,
-	maxTroops: 0,
-	equip: 0,
-	training: 0,
-	loyalty: 0,
-	medics: 0,
-	escorts: 0} >>	
 <</if>>
 
 <<if def $slaveUnits>>
-	<<set _mL = $slaveUnits.length>>
-	<<for _i = 0; _i < _mL; _i++>>
+	<<set _sL = $slaveUnits.length>>
+	<<for _i = 0; _i < _sL; _i++>>
 		<<if _i == 0>>
 			<<set $slaveUnits[_i].platoonName = _i + "st slave platoon">>
 		<<elseif _i == 1>>
@@ -194,32 +194,23 @@
 		<<else>>
 			<<set $slaveUnits[_i].platoonName = _i + "th slave platoon">>
 		<</if>>
+		<<set $slaveUnits[_i].active = 0>>
 		<<set $slaveUnits[_i].isDeployed = 0>>
 		<<set $slaveUnits[_i].troops = 0>>
+		<<set $slaveUnits[_i].maxTroops = 0>>
 		<<set $slaveUnits[_i].equip = 0>>
 		<<set $slaveUnits[_i].training = 0>>
 		<<set $slaveUnits[_i].loyalty = 0>>
 		<<set $slaveUnits[_i].medics = 0>>
-		<<set $slaveUnits[_i].escorts = 0>>
+		<<set $slaveUnits[_i].battlesFought = 0>>
 	<</for>>
 <<else>>
 	<<set $slaveUnits = []>>
-	<<set $slaveUnits[0] = {
-	platoonName: "1st slave platoon",
-	active: 0,
-	isDeployed: 0,
-	troops: 0,
-	maxTroops: 0,
-	equip: 0,
-	training: 0,
-	loyalty: 0,
-	medics: 0,
-	escorts: 0} >>	
 <</if>>
 
 <<if def $mercUnits>>
-	<<set _mL = $mercUnits.length>>
-	<<for _i = 0; _i < _mL; _i++>>
+	<<set _meL = $mercUnits.length>>
+	<<for _i = 0; _i < _meL; _i++>>
 		<<if _i == 0>>
 			<<set $mercUnits[_i].platoonName = _i + "st mercenary platoon">>
 		<<elseif _i == 1>>
@@ -229,25 +220,16 @@
 		<<else>>
 			<<set $mercUnits[_i].platoonName = _i + "th mercenary platoon">>
 		<</if>>
+		<<set $mercUnits[_i].active = 0>>
 		<<set $mercUnits[_i].isDeployed = 0>>
 		<<set $mercUnits[_i].troops = 0>>
+		<<set $mercUnits[_i].maxTroops = 0>>
 		<<set $mercUnits[_i].equip = 0>>
 		<<set $mercUnits[_i].training = 0>>
 		<<set $mercUnits[_i].loyalty = 0>>
 		<<set $mercUnits[_i].medics = 0>>
-		<<set $mercUnits[_i].escorts = 0>>
+		<<set $mercUnits[_i].battlesFought = 0>>
 	<</for>>
 <<else>>
 	<<set $mercUnits = []>>
-	<<set $mercUnits[0] = {
-	platoonName: "1st mercenary platoon",
-	active: 0,
-	isDeployed: 0,
-	troops: 0,
-	maxTroops: 0,
-	equip: 0,
-	training: 0,
-	loyalty: 0,
-	medics: 0,
-	escorts: 0} >>
 <</if>>
\ No newline at end of file
diff --git a/src/SecExp/securityHQ.tw b/src/SecExp/securityHQ.tw
index 0962bd16266..68f6e65eda7 100644
--- a/src/SecExp/securityHQ.tw
+++ b/src/SecExp/securityHQ.tw
@@ -1,6 +1,6 @@
 :: securityHQ [nobr]
 
-<<set $nextButton = "Back", $nextLink = "Manage Penthouse">>
+<<set $nextButton = "Back", $nextLink = "Manage Arcology">>
 
 Security headquarters
 <hr>
@@ -229,16 +229,23 @@ Considering the current upgrades, prosperity and demographics of your arcology,
 	You have built specialized pathways inside the arcology to quickly move troops around the structure.
 <</if>>
 <br>
+<<if $readinessUpgrades.rapidVehicles == 0>>
+	[[Buy rapid armored transport vehicles|securityHQ][$cash -= Math.trunc(7500*$upgradeMultiplierArcology), $readinessUpgrades.rapidVehicles = 1, $readiness += 1, $reqHelots += 5]]
+	<br>//Costs ¤<<print Math.trunc(75000*$upgradeMultiplierArcology)>>. Will increase readiness, but will require 5 extra slaves in the headquarters and increases upkeep.//
+<<else>>
+	You have bought rapid armored transport vehicles able to bring your troops to battle much quicker than before.
+<</if>>
+<br>
 <<if $readinessUpgrades.rapidPlatforms == 0>>
-	[[Build rapid deployment platforms|securityHQ][$cash -= Math.trunc(7500*$upgradeMultiplierArcology), $readinessUpgrades.rapidPlatforms = 1, $readiness += 1, $reqHelots += 5]]
-	<br>//Costs ¤<<print Math.trunc(7500*$upgradeMultiplierArcology)>>. Will increase readiness, but will require 5 extra slaves in the headquarters and increases upkeep.//
+	[[Build rapid deployment platforms|securityHQ][$cash -= Math.trunc(10000*$upgradeMultiplierArcology), $readinessUpgrades.rapidPlatforms = 1, $readiness += 1, $reqHelots += 5]]
+	<br>//Costs ¤<<print Math.trunc(10000*$upgradeMultiplierArcology)>>. Will increase readiness, but will require 5 extra slaves in the headquarters and increases upkeep.//
 <<else>>
 	You have built rapid deployment platforms able to equip and deploy units within very limited time windows.
 <</if>>
 <br>
 <<if $readinessUpgrades.earlyWarn == 0>>
-	[[Institute early warning systems|securityHQ][$cash -= Math.trunc(1000*$upgradeMultiplierArcology), $readinessUpgrades.earlyWarn = 1, $readiness += 1, $reqHelots += 10]]
-	<br>//Costs ¤<<print Math.trunc(10000*$upgradeMultiplierArcology)>>. Will increase readiness, but will require 10 extra slaves in the headquarters and increases upkeep.//
+	[[Institute early warning systems|securityHQ][$cash -= Math.trunc(15000*$upgradeMultiplierArcology), $readinessUpgrades.earlyWarn = 1, $readiness += 1, $reqHelots += 10]]
+	<br>//Costs ¤<<print Math.trunc(15000*$upgradeMultiplierArcology)>>. Will increase readiness, but will require 10 extra slaves in the headquarters and increases upkeep.//
 <<else>>
 	You have created early warning systems that constantly analyze in real time data to determine the likeness of an attack.
 <</if>>
\ No newline at end of file
diff --git a/src/SecExp/securityReport.tw b/src/SecExp/securityReport.tw
index c929ff1cc11..ef0f3dee5de 100644
--- a/src/SecExp/securityReport.tw
+++ b/src/SecExp/securityReport.tw
@@ -2,5 +2,47 @@
 
 <<if $useTabs == 0>>__Arcology Management__<</if>>
 <br>
+<<if $secHelots > 0>>
+	<<print $secHelots>> work tirelessly to improve the security of your arcology.
+<<elseif $secHQ == 1>>
+	Your security HQ lies empty, it's not going to help improving the security of the arcology.
+<</if>>
+<<if $ACitizens + $ASlaves <= 2000>>
+	The small number of residents makes their job easier. <<set _residentMod = 1>>
+<<elseif $ACitizens + $ASlaves <= 4000>>
+	The relatively low number of residents makes their job a little easier. <<set _residentMod = 0.5>>
+<<elseif $ACitizens + $ASlaves <= 6000>>
+	The relatively high number of residents makes their job a little harder. <<set _residentMod = -0.2>>
+<<elseif $ACitizens + $ASlaves <= 8000>>
+	The high number of residents makes their job harder.<<set _residentMod = -0.5>>
+<<else>>
+	The extremely high number of residents makes their job a lot harder.<<set _residentMod = -1>>
+<</if>>
+<<if $lastAttackWeeks < 3>>
+	The recent attack has a negative effect on the security of the arcology.<<set _attackMod = -1>>
+<<elseif $lastAttackWeeks < 5>>
+	While some time has passed, the last attack still has a negative effect on the security of the arcology.<<set _attackMod = -0.5>>
+<<else>>
+	The arcology has not been attacked in a while, which has a positive effect on security.<<set _attackMod = 0.5>>
+<</if>>
 
-testing stuff
\ No newline at end of file
+
+
+$security  $secRestPoint
+
+
+
+
+
+
+what influences security?
+	-number of people
+	-recent attacks
+	-authority
+	-reputation
+	
+what influences crime?
+	-security
+	-authority
+	-reputation
+	-prosperity
\ No newline at end of file
diff --git a/src/SecExp/seeUnit.tw b/src/SecExp/seeUnit.tw
index f45a76dffd0..a331b75eeb4 100644
--- a/src/SecExp/seeUnit.tw
+++ b/src/SecExp/seeUnit.tw
@@ -1 +1,150 @@
-:: seeUnit [nobr]
\ No newline at end of file
+:: seeUnit [nobr]
+
+<<if $attackThisWeek == 1>>
+	<<set $nextButton = "Back", $nextLink = "attackOption">>
+<<else>>
+	<<set $nextButton = "Back", $nextLink = "secBarracks">>
+<</if>>
+
+<<if $targetUnit == "secBots">>
+	<<secBotsDescription>>
+	<br><br>
+	<<if $secBots.maxTroops < 80>>
+		<<link "Improve the digital control matrix">>|
+			<<set $secBots.maxTroops += 10>>
+			<<set $cash -= 5000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Invest in the development of more refined controls for your drones to increase the maximum number of drones in the unit.
+		<br>//Costs 5000 per upgrade and each will increase the max by 10//
+	<<else>>
+		There's little left to improve in the matrix. Your control systems are at top capacity and won't be able to handle bigger drone units.
+	<</if>>
+	<br>
+	<<if $secBots.equip < 3>>
+		<<link "Improve drone weaponry and armor">>|
+			<<set $secBots.equip += 1>>
+			<<set $cash -= (($secBotsUpgradeCost * $secBots.maxTroops) + 1000)>>
+			<<goto "seeUnit">>
+		<</link>>
+		Invest in better equipment for your drones to increase their battle effectiveness.
+		<br>//Costs <<print (($secBotsUpgradeCost * $secBots.maxTroops) + 1000)>> and will increase attack and defense value of the unit by 15% for every upgrade.//
+	<<else>>
+		Your drones are equipped with top tier weaponry and armor.
+	<</if>>
+	
+<<elseif $targetUnit == "militiaUnits">>
+	<<militiaUnitsDescription $militiaUnits[$targetIndex]>>
+	<br><br>
+	<<if $militiaUnits[$targetIndex].maxTroops < 50>>
+		<<link "Intensive officers training">>|
+			<<set $militiaUnits[$targetIndex].maxTroops += 10>>
+			<<set $cash -= 5000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Invest in the training of your officers to increase the maximum number of soldiers in the unit.
+		<br>//Costs 5000 per upgrade and each will increase the max by 10//
+	<<else>>
+		Your officers rached their peak. Further training will have little impact on the number of troops they can effectively lead.
+	<</if>>
+	<br>
+	<<if $militiaUnits[$targetIndex].equip < 3>>
+		<<link "Improve weaponry and equipment">>|
+			<<set $militiaUnits[$targetIndex].equip += 1>>
+			<<set $cash -= ($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 1000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Invest in better equipment for your soldiers to increase their battle effectiveness.
+		<br>//Costs <<print ($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 1000>> and will increase attack and defense value of the unit by 15% for every upgrade.//
+	<<else>>
+		The unit is equipped with state of the art weaponry and equipment.
+	<</if>>
+	<br>
+	<<if $militiaUnits[$targetIndex].medics == 0>>
+		<<link "Attach trained medics to the unit">>|
+			<<set $militiaUnits[$targetIndex].medics == 1>>
+			<<set $cash -= 10000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Attach a small squad of trained medics to the unit.
+		<br>//Costs <<print ($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 1000>> and will will decrease the number of casualties suffered during battle.//
+	<<else>>
+		The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers.
+	<</if>>
+<<elseif $targetUnit == "slaveUnits">>
+	<<slaveUnitsDescription $slaveUnits[$targetIndex]>>
+	<br><br>
+	<<if $slaveUnits[$targetIndex].maxTroops < 50>>
+		<<link "Intensive officers training">>|
+			<<set $slaveUnits[$targetIndex].maxTroops += 10>>
+			<<set $cash -= 5000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Invest in the training of your officers to increase the maximum number of soldiers in the unit.
+		<br>//Costs 5000 per upgrade and each will increase the max by 10//
+	<<else>>
+		Your officers rached their peak. Further training will have little impact on the number of troops they can effectively lead.
+	<</if>>
+	<br>
+	<<if $slaveUnits[$targetIndex].equip < 3>>
+		<<link "Improve weaponry and equipment">>|
+			<<set $slaveUnits[$targetIndex].equip += 1>>
+			<<set $cash -= ($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 1000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Invest in better equipment for your soldiers to increase their battle effectiveness.
+		<br>//Costs <<print ($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 1000>> and will increase attack and defense value of the unit by 15% for every upgrade.//
+	<<else>>
+		The unit is equipped with state of the art weaponry and equipment.
+	<</if>>
+	<br>
+	<<if $slaveUnits[$targetIndex].medics == 0>>|
+		<<link "Attach trained medics to the unit">>
+			<<set $slaveUnits[$targetIndex].medics == 1>>
+			<<set $cash -= 10000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Attach a small squad of trained medics to the unit.
+		<br>//Costs <<print ($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 1000>> and will decrease the number of casualties suffered during battle.//
+	<<else>>
+		The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers.
+	<</if>>
+<<elseif $targetUnit == "mercUnits">>
+	<<mercUnitsDescription $mercUnits[$targetIndex]>>
+	<br><br>
+	<<if $mercUnits[$targetIndex].maxTroops < 50>>
+		<<link "Intensive officers training">>|
+			<<set $mercUnits[$targetIndex].maxTroops += 10>>
+			<<set $cash -= 5000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Invest in the training of your officers to increase the maximum number of soldiers in the unit.
+		<br>//Costs 5000 per upgrade and each will increase the max by 10//
+	<<else>>
+		Your officers rached their peak. Further training will have little impact on the number of troops they can effectively lead.
+	<</if>>
+	<br>
+	<<if $mercUnits[$targetIndex].equip < 3>>|
+		<<link "Improve weaponry and equipment">>
+			<<set $mercUnits[$targetIndex].equip += 1>>
+			<<set $cash -= ($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 1000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Invest in better equipment for your soldiers to increase their battle effectiveness.
+		<br>//Costs <<print ($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 1000>> and will increase attack and defense value of the unit by 15% for every upgrade.//
+	<<else>>
+		The unit is equipped with state of the art weaponry and equipment.
+	<</if>>
+	<br>
+	<<if $mercUnits[$targetIndex].medics == 0>>
+		<<link "Attach trained medics to the unit">>|
+			<<set $mercUnits[$targetIndex].medics == 1>>
+			<<set $cash -= 10000>>
+			<<goto "seeUnit">>
+		<</link>>
+		Attach a small squad of trained medics to the unit.
+		<br>//Costs <<print ($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 1000>> and will decrease the number of casualties suffered during battle.//
+	<<else>>
+		The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers.
+	<</if>>
+<</if>>
\ No newline at end of file
diff --git a/src/SecExp/weaponsManufactoring.tw b/src/SecExp/weaponsManufactoring.tw
new file mode 100644
index 00000000000..ff62090a573
--- /dev/null
+++ b/src/SecExp/weaponsManufactoring.tw
@@ -0,0 +1 @@
+:: weaponsManufactoring [nobr]
\ No newline at end of file
diff --git a/src/SecExp/widgets/unitsDescriptionWidgets.tw b/src/SecExp/widgets/unitsDescriptionWidgets.tw
index c2494f37480..1c9eef79c27 100644
--- a/src/SecExp/widgets/unitsDescriptionWidgets.tw
+++ b/src/SecExp/widgets/unitsDescriptionWidgets.tw
@@ -1,17 +1,106 @@
 :: unitsDescriptionWidgets [widget nobr]
 
 <<widget "militiaUnitsDescription">>
-	militia
+	<<if $args[0].active == 1>>
+		<strong>$args[0].platoonName</strong> <<if $args[0].battlesFought > 1>> participated in $args[0].battlesFought battles and is ready to face the enemy once more at your command.<<elseif $args[0].battlesFought == 1>>is ready to face the enemy once more at your command.<<else>>is ready to face the enemy in battle.<</if>>
+		Its $args[0].troops men and women are all proud citizens of your arcology, willing to put their lives on the line to protect their home.
+		<<if $args[0].troops < $args[0].maxTroops>> The unit is not at its full strength of $args[0].maxTroops operatives.<</if>>
+		<<if $args[0].equip == 0>>
+			They are issued with simple, yet effective equipment: firearms, a few explosives and standard uniforms, nothing more.
+		<<elseif $args[0].equip == 1>>
+			They are issued with good, modern equipment: firearms, explosives and a few specialized weapons like sniper rifles and machine guns. They also carry simple body armor.
+		<<elseif $args[0].equip == 2>>
+			They are issued with excellent, high tech equipment: modern firearms, explosives, specialized weaponry and modern body armor. They are also issued with modern instruments like might visions and portable radars.
+		<<else>>
+			They are equipped with the best the modern world has to offer: modern firearms, explosives, specialized weaponry, experimental railguns, adaptive body armor and high tech recon equipment.
+		<</if>>
+		<<if $args[0].training <= 33>>
+			They lack the experience to be considered consumed professionals, but their eagerness to defend the arcology makes up for it.
+		<<elseif $args[0].training <= 66>>
+			They have trained <<if $args[0].battlesFought > 0>>and fought<</if>> enough to be considered disciplined, professional soldiers, ready to face the battlefield.
+		<<else>>
+			They are consumed veterans, with a wealth of experience and perfectly trained. On the battlefield they are a well oiled war machine capable of facing pretty much anything.
+		<</if>>
+		<<if $args[0].medics == 1>>
+			The unit has a dedicated squad of medics that will follow them in battle.
+		<</if>>
+	<<else>>
+		$args[0].platoonName lost too many operatives in the $args[0].battlesFought it fought and can no longer be considered a unit at all.
+	<</if>>
 <</widget>>
 
 <<widget "slaveUnitsDescription">>
-	slaves
+	<<if $args[0].active == 1>>
+		<strong>$args[0].platoonName</strong> <<if $args[0].battlesFought > 1>> participated in $args[0].battlesFought battles and is ready to face the enemy once more at your command.<<elseif $args[0].battlesFought == 1>>is ready to face the enemy once more at your command.<<else>>is ready to face the enemy in battle.<</if>>
+		Its $args[0].troops men and women are slaves in your possession, tasked with the protection of their owner and their arcology.
+		<<if $args[0].troops < $args[0].maxTroops>> The unit is not at its full strength of $args[0].maxTroops operatives.<</if>>
+		<<if $args[0].equip == 0>>
+			They are issued with simple, yet effective equipment: firearms, a few explosives and standard uniforms, nothing more.
+		<<elseif $args[0].equip == 1>>
+			They are issued with good, modern equipment: firearms, explosives and a few specialized weapons like sniper rifles and machine guns. They also carry simple body armor.
+		<<elseif $args[0].equip == 2>>
+			They are issued with excellent, high tech equipment: modern firearms, explosives, specialized weaponry and modern body armor. They are also issued with modern instruments like might visions and portable radars.
+		<<else>>
+			They are equipped with the best the modern world has to offer: modern firearms, explosives, specialized weaponry, experimental railguns, adaptive body armor and high tech recon equipment.
+		<</if>>
+		<<if $args[0].training <= 33>>
+			They lack the experience to be considered professionals, but their eagerness to prove themselves makes up for it.
+		<<elseif $args[0].training <= 66>>
+			They have trained <<if $args[0].battlesFought > 0>>and fought<</if>> enough to be considered disciplined, professional soldiers, ready to face the battlefield.
+		<<else>>
+			They are consumed veterans, with a wealth of experience and perfectly trained. On the battlefield they are a well oiled war machine capable of facing pretty much anything.
+		<</if>>
+		<<if $args[0].medics == 1>>
+			The unit has a dedicated squad of medics that will follow them in battle.
+		<</if>>
+	<<else>>
+		$args[0].platoonName lost too many operatives in the $args[0].battlesFought it fought and can no longer be considered a unit at all.
+	<</if>>
 <</widget>>
 
 <<widget "mercUnitsDescription">>
-	mercs
+	<<if $args[0].active == 1>>
+		<strong>$args[0].platoonName</strong> <<if $args[0].battlesFought > 1>> participated in $args[0].battlesFought battles and is ready to face the enemy once more at your command.<<elseif $args[0].battlesFought == 1>>is ready to face the enemy once more at your command.<<else>>is ready to face the enemy in battle.<</if>>
+		Its $args[0].troops men and women are mercenaries contracted to defend the arcology against external threats.
+		<<if $args[0].troops < $args[0].maxTroops>> The unit is not at its full strength of $args[0].maxTroops operatives.<</if>>
+		<<if $args[0].equip == 0>>
+			They are issued with simple, yet effective equipment: firearms, a few explosives and standard uniforms, nothing more.
+		<<elseif $args[0].equip == 1>>
+			They are issued with good, modern equipment: firearms, explosives and a few specialized weapons like sniper rifles and machine guns. They also carry simple body armor.
+		<<elseif $args[0].equip == 2>>
+			They are issued with excellent, high tech equipment: modern firearms, explosives, specialized weaponry and modern body armor. They are also issued with modern instruments like might visions and portable radars.
+		<<else>>
+			They are equipped with the best the modern world has to offer: modern firearms, explosives, specialized weaponry, experimental railguns, adaptive body armor and high tech recon equipment.
+		<</if>>
+		<<if $args[0].training <= 33>>
+			They lack the experience to be considered professionals, but they're trained more than enough to still be an effective unit.
+		<<elseif $args[0].training <= 66>>
+			They have trained <<if $args[0].battlesFought > 0>>and fought<</if>> enough to be considered disciplined, professional soldiers, ready to face the battlefield.
+		<<else>>
+			They are consumed veterans, with a wealth of experience and perfectly trained. On the battlefield they are a well oiled war machine capable of facing pretty much anything.
+		<</if>>
+		<<if $args[0].medics == 1>>
+			The unit has a dedicated squad of medics that will follow them in battle.
+		<</if>>
+	<<else>>
+		$args[0].platoonName lost too many operatives in the $args[0].battlesFought it fought and can no longer be considered a unit at all.
+	<</if>>
 <</widget>>
 	
 <<widget "secBotsDescription">>
-	bots
+	<<if $secBots.active == 1>>
+		<strong>The security drones</strong> assemble in an ordered line in front of you, ready to receive their orders.
+		<<if $secBots.troops < $secBots.maxTroops>> The unit is not at its full strength of $secBots.maxTroops drones.<</if>>
+		<<if $secBots.equip == 0>>
+			They are equipped with light weaponry, mainly anti-riot non lethal weapons. Not particularly effective in battle.
+		<<elseif $secBots.equip == 1>>
+			They are equipped with light firearms, not an overwhelming amount of firepower, but with their mobility good enough to be effective.
+		<<elseif $secBots.equip == 2>>
+			They are equipped with powerful, modern firearms and simple armor mounted around their frames. They do not make for a pretty sight, but on the battlefield they are a dangerous weapon.
+		<<else>>
+			They are equipped with high energy railguns and adaptive armor. They are a formidable force on the battlefield, even for experienced soldiers.
+		<</if>>
+	<<else>>
+		There are too few security drones left to be able to deploy them on the battlefield.
+	<</if>>
 <</widget>>
\ No newline at end of file
diff --git a/src/uncategorized/pMercenaries.tw b/src/uncategorized/pMercenaries.tw
index 222b683c8da..3d63cfdf5f6 100644
--- a/src/uncategorized/pMercenaries.tw
+++ b/src/uncategorized/pMercenaries.tw
@@ -29,6 +29,8 @@ The budgetary difficulty many old world countries are in has resulted in unemplo
 	<<set $rep -= 500>>
 	<<set $cash -= _price>>
 	<<set $mercenaries = 1>>
+	<<set $mercTotalManpower = 15>>
+	<<set $mercFreeManpower = 15>>
 	<</replace>>
 <</link>> <<if ($PC.warfare >= 50) || ($PC.career == "arcology owner")>>//This will cost ¤<<print _price>> and some upkeep, @@.springgreen;reduced by your mercenary contacts@@//<<else>>//This will cost ¤5000 and incur significant upkeep costs//<</if>>
 <br><<link "Install a full platoon">>
@@ -37,6 +39,8 @@ The budgetary difficulty many old world countries are in has resulted in unemplo
 	<<set $rep -= 1000>>
 	<<set $cash -= (_price*2)>>
 	<<set $mercenaries = 3>>
+	<<set $mercTotalManpower = 30>>
+	<<set $mercFreeManpower = 30>>
 	<</replace>>
 <</link>> <<if ($PC.warfare >= 50) || ($PC.career == "arcology owner")>>//This will cost ¤<<print (_price*2)>> and some upkeep, @@.springgreen;reduced by your mercenary contacts@@//<<else>>//This will cost ¤10000 and incur significant upkeep costs//<</if>>
 <br><<link "Do not quarter troops in your arcology">>
-- 
GitLab