From da23475ac3a3668705eba58e11da1edfc5ce1119 Mon Sep 17 00:00:00 2001
From: hexall90 <hexall90@gmail.com>
Date: Tue, 26 Sep 2017 22:45:41 +0200
Subject: [PATCH] starting work on secHQ

---
 src/SecExp/SecExpBackwardCompatibility.tw |  8 +++++
 src/SecExp/attackGenerator.tw             |  2 +-
 src/SecExp/attackHandler.tw               | 12 +++++--
 src/SecExp/attackOptions.tw               |  6 +---
 src/SecExp/attackReport.tw                | 31 +++++++++---------
 src/SecExp/secInit.tw                     |  4 +++
 src/SecExp/securityHQ.tw                  | 40 ++++++++++++++++++++++-
 src/uncategorized/managePenthouse.tw      | 11 +++++++
 8 files changed, 89 insertions(+), 25 deletions(-)

diff --git a/src/SecExp/SecExpBackwardCompatibility.tw b/src/SecExp/SecExpBackwardCompatibility.tw
index 2fbd9ea8442..d2dd396823f 100644
--- a/src/SecExp/SecExpBackwardCompatibility.tw
+++ b/src/SecExp/SecExpBackwardCompatibility.tw
@@ -7,6 +7,9 @@
 <<if ndef $security>>
 	<<set $security = 50>>
 <</if>>
+<<if ndef $crime>>
+	<<set $crime = 0>>
+<</if>>
 <<if ndef $readiness>>
 	<<set $readiness = 0>>
 <</if>>
@@ -31,6 +34,11 @@
 <<if ndef $PClossStreak>>
 <<set $PClossStreak = 0>>
 <</if>>
+
+/* buildings */
+<<if ndef $secHQ>>
+	<<set $secHQ = 0>>
+<</if>>
 	
 /* upgrades */
 <<if ndef $riskSim>>
diff --git a/src/SecExp/attackGenerator.tw b/src/SecExp/attackGenerator.tw
index 00c516da946..21401910dd5 100644
--- a/src/SecExp/attackGenerator.tw
+++ b/src/SecExp/attackGenerator.tw
@@ -32,7 +32,7 @@
 	<<set $lastAttackWeeks = 0>>
 	<<set $leadingTroops = "assistant">>
 	<<set $deployableUnits = 1 + $readiness>> /* +1 is for testing */
-	<<set $chosenTactic = either("Bait and Bleed", "Guerrilla", "choke Points", "Interior Lines", "Pincer Manouver", "Defense In Depth", "Blitzkrieg", "Human Wave")>>
+	<<set $chosenTactic = either("Bait and Bleed", "Guerrilla", "Choke Points", "Interior Lines", "Pincer Manouver", "Defense In Depth", "Blitzkrieg", "Human Wave")>>
 	
 	/* _type is the chance out of 100 of an attack of that type happening */
 	<<set _raider = 25>>
diff --git a/src/SecExp/attackHandler.tw b/src/SecExp/attackHandler.tw
index bf6f8423730..e05571ba466 100644
--- a/src/SecExp/attackHandler.tw
+++ b/src/SecExp/attackHandler.tw
@@ -88,7 +88,8 @@
 	/* 80% chance of increasing warfare */
 	<<if $PC.warfare < 100 && random(1,100) <= 80>>
 		<<set $PC.warfare += 10>>
-		<<set $PC.warfare = Math.clamp($PC.warfare,-100,100)
+		<<set $PC.warfare = Math.clamp($PC.warfare,-100,100)>>
+	<</if>>
 <<elseif $leadingTroops == "assistant">>
 	<<if $rep < 10000 && $authority < 10000>>
 		<<set _militiaMod -= 0.15>>
@@ -208,7 +209,11 @@
 		<<elseif $woundType == 3>>
 			<<set $Bodyguard.amp = 1>>
 		<<elseif $woundType >= 4>>
-			<<set $Bodyguard.health -= 40>>
+			<<if $Bodyguard.health >= -60>>
+				<<set $Bodyguard.health -= 40>>
+			<<else>>
+				<<set $Bodyguard.health -= Math.abs(100 + $Bodyguard.health)>>
+			<</if>>
 		<</if>>
 	<</if>>
 	/* 60% chance of getting combat skill if nto already have it */
@@ -800,7 +805,8 @@ Debug:
 <br>militiaMod: _militiaMod
 <br>slaveMod: _slaveMod
 <br>mercMod: _mercMod
-<br>tacticSuccessful: $tacticsSuccessful
+<br>tacChance: _tacChance
+<br>tactic Successful?: <<if $tacticsSuccessful == 1>> yes <<else>> no<</if>>
 <br>enemyAttack: _enemyAttack
 <br>enemyDefense: _enemyDefense
 <br>enemyMorale: _enemyMorale
diff --git a/src/SecExp/attackOptions.tw b/src/SecExp/attackOptions.tw
index 47d2b3934fb..44581476d34 100644
--- a/src/SecExp/attackOptions.tw
+++ b/src/SecExp/attackOptions.tw
@@ -345,11 +345,7 @@ Units about to be deployed:
 <br><br>
 
 /* tactics */
-<<if $leadingTroops != "PC">>
-	For this battle you command your chosen leaders to follow <span id="tactic"><strong><<print $chosenTactic>></strong></span> tactics.
-<<else>>
-	For this battle you choose to follow <span id="tactic"><strong><<print $chosenTactic>></strong></span> tactics.
-<</if>>
+For this battle you choose to follow <span id="tactic"><strong><<print $chosenTactic>></strong></span> tactics.
 <br><br>
 Defensive tactics
 <br>
diff --git a/src/SecExp/attackReport.tw b/src/SecExp/attackReport.tw
index fe58899d46f..462b619a5db 100644
--- a/src/SecExp/attackReport.tw
+++ b/src/SecExp/attackReport.tw
@@ -78,7 +78,7 @@
 			.
 		<</if>>
 	<<elseif $battleResult == 2>>
-		The fight was long and hard, but in the end our men managed to repel the raiders, though without making any significant gain.  
+		The fight was long and hard, but in the end our men managed to repel the raiders, though not without difficulty.  
 	<<elseif $battleResult == -2>>
 		The fight was long and hard. Our men in the end had to yield to the horde raiders, which was fortunately unable to capitalized on their victory.
 	<<elseif $battleResult == -1>>
@@ -137,7 +137,7 @@
 			.
 		<</if>>
 	<<elseif $battleResult == 2>>
-		The fight was long and hard, but in the end our men managed to repel the mercenaries, though without making any significant gain.  
+		The fight was long and hard, but in the end our men managed to repel the mercenaries, though not without difficulty.
 	<<elseif $battleResult == -2>>
 		The fight was long and hard. Our men in the end had to yield to the slavers, which were fortunately unable to capitalized on their victory.
 	<<elseif $battleResult == -1>>
@@ -196,7 +196,7 @@
 			.
 		<</if>>
 	<<elseif $battleResult == 2>>
-			The fight was long and hard, but in the end our men managed to repel the freedom fighters, though without making any significant gain.  
+			The fight was long and hard, but in the end our men managed to repel the freedom fighters, though not without difficulty.
 	<<elseif $battleResult == -2>>
 		The fight was long and hard. Our men in the end had to yield to the freedom figthers, which were fortunately unable to capitalized on their victory.
 	<<elseif $battleResult == -1>>
@@ -255,7 +255,7 @@
 			.
 		<</if>>
 	<<elseif $battleResult == 2>>
-		The fight was long and hard, but in the end our men managed to repel the old world soldiers, though without making any significant gain.  
+		The fight was long and hard, but in the end our men managed to repel the old world soldiers, though not without difficulty.
 	<<elseif $battleResult == -2>>
 		The fight was long and hard. Our men in the end had to yield to the old world soldiers, which were fortunately unable to capitalized on their victory.
 	<<elseif $battleResult == -1>>
@@ -300,7 +300,7 @@
 		<<set _captives = ($attackTroops - $enemyLosses) * 0.1 * random(1,3)>>
 	<</if>>
 	and some of their equipment, which once sold produced
-	<<if attackEquip == 0>>
+	<<if $attackEquip == 0>>
 		@@.yellowgreen;a small amount of cash.@@
 		<<set $cash += 1000>>
 	<<elseif $attackEquip == 1>>
@@ -838,7 +838,7 @@
 <<elseif $chosenTactic == "Interior Lines">>
 	chose to employ "interior lines" tactics or exploiting the defender's shorter front to quickly disengage and concentrate troops when and where needed.
 <<elseif $chosenTactic == "Pincer Manouver">>
-		chose to employ "pince manouver" tactics or attempting to encircle the enemy by faking a collapsing centre front.
+		chose to employ "pincer manouver" tactics or attempting to encircle the enemy by faking a collapsing centre front.
 <<elseif $chosenTactic == "Defense In Depth">>
 	chose to employ "defense in depth" tactics or relying on mobility to disengage and exploit overextended enemy troops by attacking their freshly exposed flanks.
 <<elseif $chosenTactic == "Blitzkrieg">>
@@ -960,7 +960,7 @@
 	<<elseif $chosenTactic == "Guerrilla">>
 		While the wastelands are mostly open terrain, ther are enough hiding spots to make guerrilla tactics work well enough.
 	<<elseif $chosenTactic == "Choke Points">>
-		The wastelands are mostly open terrain, your men have  adifficult time setting up effective fortified positions.
+		The wastelands are mostly open terrain, your men have a difficult time setting up effective fortified positions.
 	<<elseif $chosenTactic == "Interior Lines">>
 		The wastelands, while rough, are mostly open terrain, where your men can exploit to the maximum the superior mobility of the defender.
 	<<elseif $chosenTactic == "Pincer Manouver">>
@@ -1022,7 +1022,7 @@
 	<<elseif $attackType == "old world">>
 		The discipline and numbers of old world armies make them quite difficult to encircle. 
 	<<elseif $attackType == "freedom fighters">>
-		While not particularly mobile, freedom figthers are used to fight against overwhelming odds.
+		While not particularly mobile, freedom figthers are used to fight against overwhelming odds, diminishing the effectiveness of the encirclement.
 	<</if>>
 <<elseif $chosenTactic == "Defense In Depth">>
 	<<if $attackType == "raiders">>
@@ -1056,9 +1056,9 @@
 	<</if>>
 <</if>>
 <<if $tacticsSuccessful == 1>>
-	In the end <<if $leading troops == "PC">>you<<else>>your commander<</if>> @@.green;was able to successfully employ <<print $chosenTactic>> tactics@@, greatly enhancing the efficacy of your army.
+	In the end <<if $leadingTroops == "PC">>you<<else>>your commander<</if>> @@.green;was able to successfully employ <<print $chosenTactic>> tactics@@, greatly enhancing the efficacy of your army.
 <<else>>
-	In the end <<if $leading troops == "PC">>you<<else>>your commander<</if>> @@.red;was not able to effectively employ <<print $chosenTactic>> tactics@@, greatly affecting the efficacy of your army.
+	In the end <<if $leadingTroops == "PC">>you<<else>>your commander<</if>> @@.red;was not able to effectively employ <<print $chosenTactic>> tactics@@, greatly affecting the efficacy of your army.
 <</if>>
 	
 <br>
@@ -1187,18 +1187,19 @@
 <<set _menialPrice = Math.clamp(_menialPrice, 500, 1500)>>
 
 <<if _captives > 0>>
+	<<set _captives = Math.trunc(_captives)>>
 	During the battle <<print _captives>> attackers were captured.
 	<<if random(1,100) <= 25>>
 		<<set _roll = random(1,100)>>
 		<<if _roll <= 33>>
-			Three of them appear to be decent sex slaves candidates.
+			Three of them have the potential to be sex slaves.
 			<<set _candidates = 3>>
 			
 		<<elseif _roll <= 66>>
-			Two of them appear to be decent sex slaves candidates.
+			Two of them have the potential to be sex slaves.
 			<<set _candidates = 2>>
 		<<else>>
-			One of them appears to be a decent sex slave candidate.
+			One of them have the potential to be sex slaves.
 			<<set _candidates = 1>>
 		<</if>>
 	<</if>>
@@ -1215,11 +1216,11 @@
 	<</link>>
 	<<if _candidates > 0>>
 		|
-		<<link "keep them and sell the rest|not implemented">>
+		<<link "keep them and sell the rest|not implemented yet">>
 		
 		<</link>>
 		|
-		<<link "keep them and keep the rest as menial slaves|not implemented">>
+		<<link "keep them and keep the rest as menial slaves|not implemented yet">>
 		
 		<</link>>
 	<</if>>
diff --git a/src/SecExp/secInit.tw b/src/SecExp/secInit.tw
index 11f1a56dcd5..3fc11e73499 100644
--- a/src/SecExp/secInit.tw
+++ b/src/SecExp/secInit.tw
@@ -3,6 +3,7 @@
 /* base vars */
 <<set $authority = 1000>>
 <<set $security = 50>>
+<<set $crime = 0>>
 <<set $readiness = 0>>
 <<set $maxPlatoons = 0>>
 <<set $attackType = "none">>
@@ -12,6 +13,9 @@
 <<set $PCvictoryStreak = 0>>
 <<set $PClossStreak = 0>>
 
+/* buildings */
+<<set $secHQ = 0>>
+
 /* armed forces stats */
 <<set $militiaCreated = 0>>
 <<set $$slavesInArmy = 0>>
diff --git a/src/SecExp/securityHQ.tw b/src/SecExp/securityHQ.tw
index 5e15ae9fb80..57a4fc5c519 100644
--- a/src/SecExp/securityHQ.tw
+++ b/src/SecExp/securityHQ.tw
@@ -1 +1,39 @@
-:: securityHQ [nobr]
\ No newline at end of file
+:: securityHQ [nobr]
+
+<<set $nextButton = "Back", $nextLink = "Manage Penthouse">>
+
+Security headquarters
+<hr>
+
+/* security level. Effects and influences */
+<<if $security <= 20>>
+	Your security level is dangerously low. If measures are not taken crime will quickly become a big problem and your arcology will be highly susceptible to external attacks. Prosperity and immigration will be negatively affected quite severely by this level of security.
+<<elseif $security <= 40>>
+	Your security level is low. In the long run crime will slowly but inevitably grow and your arcology is open to attacks.  Prosperity and immigration will be negatively affected by this level of security.
+<<elseif $security <= 60>>
+	Your security level is decent. Crime will have difficulty growing, but it will also be hard to extirpate. Your arcology is reasonably safe from external attacks. Prosperity and immigration will not be noticeably affected by this level of security.
+<<elseif $security <= 80>>
+	Your security level is good. With time crime will slowly be eliminated and your arcology is highly secured agaist external attacks. Prosperity and immigration will be positively affected by this level of security.
+<<else>>
+	Your security level is great. You turned your arcology in a deadly trap for criminals and external attacks can be dealt with very effectively.  Prosperity and immigration will be positively affected quite strongly by this level of security. 
+<</if>>
+<br>
+	
+/* security level. Upgrades */
+	You have <<print $secHelots>> slaves constantly working in the HQ. To maintain the current level of security _reqHelots are required. 
+	<br>&nbsp;&nbsp;&nbsp;&nbsp;
+	<<if $helots >= 5>>
+		<<link "Increase them by 5">>
+		
+	
+	
+	[[Increase them by 10|securityHQ][$helots -= 10, $secHelots += 10]|[[Decrease them by 10|securityHQ][$helots += 10, $secHelots -= 10]]|[Match the requirement|securityHQ][$helots += $secHelots - _reqHelots, $secHelots = _reqHelots]]
+
+/* crime */
+
+/* readiness */
+
+/* intelligence */
+
+/* recruitment and units */
+
diff --git a/src/uncategorized/managePenthouse.tw b/src/uncategorized/managePenthouse.tw
index 8e6ca20b7d4..f2cb9c30f3b 100644
--- a/src/uncategorized/managePenthouse.tw
+++ b/src/uncategorized/managePenthouse.tw
@@ -245,6 +245,15 @@ __Penthouse Upgrades__
 
 <br>
 
+<<if $secHQ == 0>>
+	[[Set up the security headquarters|Manage Penthouse][$cash -= Math.trunc(5000*$upgradeMultiplierArcology), $secHQ = 1]]
+	//Costs ¤<<print Math.trunc(5000*$upgradeMultiplierArcology)>>//
+<<else>>
+	The [[security HQ|securityHQ]] is constantly working to protect your arcology.
+<</if>>
+	
+<br>
+
 <<if $studio == 0>>
 	[[Install a media hub to convert slave video feeds into pornography|Manage Penthouse][$cash -= Math.trunc(10000*$upgradeMultiplierArcology), $studio = 1]]
 	//Costs ¤<<print Math.trunc(10000*$upgradeMultiplierArcology)>>//
@@ -292,6 +301,8 @@ __Penthouse Upgrades__
 
 <br>
 
+
+
 <<if $cyberMod == 0>>
 	<<switch $prostheticsUpgrade>>
 	<<case 1>>
-- 
GitLab