From 46033c462c17285e97e8e66221901d6f87711308 Mon Sep 17 00:00:00 2001
From: hexall90 <hexall90@gmail.com>
Date: Mon, 2 Oct 2017 13:03:00 +0200
Subject: [PATCH] finishing up security report

---
 TODO.txt                          |   3 +-
 src/SecExp/attackReport.tw        |   4 +-
 src/SecExp/securityHQ.tw          |  12 +-
 src/SecExp/securityReport.tw      | 221 ++++++++++++++++++++++++++----
 src/uncategorized/arcmgmt.tw      |   1 +
 src/uncategorized/storyCaption.tw |  54 ++++++++
 6 files changed, 259 insertions(+), 36 deletions(-)

diff --git a/TODO.txt b/TODO.txt
index 51c5d5840a0..392261e714f 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -3,4 +3,5 @@
 -randomize the battle day, so that it is not always the same day the turn is given
 -add fortifications
 -add casualties to the counters
--add upkeep costs
\ No newline at end of file
+-add upkeep costs
+-add security/authority and crime choices to game creation
\ No newline at end of file
diff --git a/src/SecExp/attackReport.tw b/src/SecExp/attackReport.tw
index a437d838e91..366dbf29755 100644
--- a/src/SecExp/attackReport.tw
+++ b/src/SecExp/attackReport.tw
@@ -273,7 +273,7 @@
 <br><br>
 /* calculates effects on the city */
 <<if $battleResult == 3>>
-	Thanks to your victory, your @@.green;reputation@@ and @@.gray;authority@@ increased. You were also able to capture
+	Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased. You were also able to capture
 	<<if $attackType == "raiders">>
 		<<set $rep += 800>>
 		<<set $authority += 800>>
@@ -371,7 +371,7 @@
 		<<set $arcologies[0].prosperity -= 5>>
 	<</if>>
 <<elseif $battleResult == 2>>
-	Thanks to your victory, your @@.green;reputation@@ and @@.gray;authority@@ slightly increased. Our men were not able to capture any attacker, however some equipment was seized during the enemy hasty retreat, 
+	Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ slightly increased. Our men were not able to capture any attacker, however some equipment was seized during the enemy hasty retreat, 
 	<<if $attackType == "raiders">>
 		<<set $rep += 200>>
 		<<set $authority += 200>>
diff --git a/src/SecExp/securityHQ.tw b/src/SecExp/securityHQ.tw
index 68f6e65eda7..dfe38fba0e0 100644
--- a/src/SecExp/securityHQ.tw
+++ b/src/SecExp/securityHQ.tw
@@ -8,7 +8,7 @@ Security headquarters
 /* security level. Slaves */
 You have <span id="secHel"><<print $secHelots>></span> slaves working in the HQ. $reqHelots are required and you have <span id="hel"><<print $helots>></span> free menial slaves.
 <<if $secHelots < $reqHelots>>
-	You do not have enough slaves here. Security will slowly decay until you transfer enough.
+	You do not have enough slaves here. You will not receive the full benefit of the installed upgrades.
 <<else>>
 	You have enough slaves to man all security systems.
 <</if>>
@@ -78,13 +78,7 @@ You have <span id="secHel"><<print $secHelots>></span> slaves working in the HQ.
 <<else>>
 	Your security level (@@.deepskyblue;<<print $security>>@@) is great.
 <</if>>
-<<if $security < $secRestPoint>>
-	Your security is under its resting point (<<print $secRestPoint>>), with enough slaves in the headquarters it will increase in the coming weeks.
-<<elseif $security > $secRestPoint>>
-	Your security is over its resting point (<<print $secRestPoint>>), without investments in the infrastructure it will slowly decay.
-<<else>>
-	Your security is at its resting point (<<print $secRestPoint>>), without outside interference it will remain at this level.
-<</if>>
+Considering the current upgrades the resting level for security is <<print $secRestPoint>>, while the effective maximum level is <<print Math.trunc($secRestPoint * ($secHelots / $reqHelots))>>.
 
 <br>
 <br>
@@ -132,7 +126,7 @@ You have <span id="secHel"><<print $secHelots>></span> slaves working in the HQ.
 <<else>>
 	Your crime level (@@.orangered;<<print $crime>>@@) is extremely high.
 <</if>>
-Considering the current upgrades, prosperity and demographics of your arcology, the maximum level of crime is <<print $crimeCap>>.
+Considering the current upgrades the maximum level of crime is <<print $crimeCap>>, while the effective maximum level is <<print Math.trunc($crimeCap * ($secHelots / $reqHelots))>>.
 
 <br>
 <br>
diff --git a/src/SecExp/securityReport.tw b/src/SecExp/securityReport.tw
index ef0f3dee5de..296d7b9c5ee 100644
--- a/src/SecExp/securityReport.tw
+++ b/src/SecExp/securityReport.tw
@@ -1,48 +1,221 @@
 :: securityReport [nobr]
 
+/* init */
+<<set _immigration = $ACitizens - $oldACitizens>>
+<<set _secGrowth = 0>>
+<<set _secRest = 0>>
+<<set _restGrowth = 0>>
+<<set _newSec = 0>>
+<<set _crimeGrowth = 0>>
+<<set _crimeCap = 0>>
+<<set _newCrime = 0>>
+
 <<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>>
+
+/* security modifiers */
 <<if $ACitizens + $ASlaves <= 2000>>
-	The small number of residents makes their job easier. <<set _residentMod = 1>>
+	The small number of residents makes their job easier <<set _secGrowth += 2>>
+	<<if _immigration < 10>>
+		and the limited number of immigrants that reached the arcology this week does not have any sensible impact.<<set _secGrowth += 0.5>>
+	<<elseif _immigration < 30>>
+		, unfortunately the number of immigrants that reached the arcology this week is high enough to complicate security protocols.<<set _secGrowth -= 0.2>>
+	<<elseif _immigration < 60>>
+		, unfortunately the high number of immigrants that reached the arcology this week complicates security protocols.<<set _secGrowth -= 0.5>>
+	<<elseif _immigration < 80>>
+		, unfortunately the high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 1>>
+	<<else>>
+		, unfortunately the extremely high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 2>>
+	<</if>>
 <<elseif $ACitizens + $ASlaves <= 4000>>
-	The relatively low number of residents makes their job a little easier. <<set _residentMod = 0.5>>
+	The relatively low number of residents makes their job a little easier. <<set _secGrowth += 1>>
+	<<if _immigration < 10>>
+		and the limited number of immigrants that reached the arcology this week does not have any sensible impact.<<set _secGrowth += 0.5>>
+	<<elseif _immigration < 30>>
+		, unfortunately the number of immigrants that reached the arcology this week is high enough to complicate security protocols.<<set _secGrowth -= 0.2>>
+	<<elseif _immigration < 60>>
+		, unfortunately the high number of immigrants that reached the arcology this week complicates security protocols.<<set _secGrowth -= 0.5>>
+	<<elseif _immigration < 80>>
+		, unfortunately the high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 1>>
+	<<else>>
+		, unfortunately the extremely high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 2>>
+	<</if>>
 <<elseif $ACitizens + $ASlaves <= 6000>>
-	The relatively high number of residents makes their job a little harder. <<set _residentMod = -0.2>>
+	The relatively high number of residents makes their job a little harder. <<set _secGrowth -= -0.5>>
+	<<if _immigration < 10>>
+		, but the limited number of immigrants that reached the arcology this week does not have any sensible impact.<<set _secGrowth += 0.5>>
+	<<elseif _immigration < 30>>
+		. Furthermore, the number of immigrants that reached the arcology this week is high enough to complicate security protocols.<<set _secGrowth -= 0.2>>
+	<<elseif _immigration < 60>>
+		. Furthermore, the high number of immigrants that reached the arcology this week complicates security protocols.<<set _secGrowth -= 0.5>>
+	<<elseif _immigration < 80>>
+		. Furthermore, the high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 1>>
+	<<else>>
+		. Furthermore, the extremely high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 2>>
+	<</if>>
 <<elseif $ACitizens + $ASlaves <= 8000>>
-	The high number of residents makes their job harder.<<set _residentMod = -0.5>>
+	The high number of residents makes their job harder.<<set _secGrowth -= 1>>
+	<<if _immigration < 10>>
+		, but the limited number of immigrants that reached the arcology this week does not have any sensible impact.<<set _secGrowth += 0.5>>
+	<<elseif _immigration < 30>>
+		. Furthermore, the number of immigrants that reached the arcology this week is high enough to complicate security protocols.<<set _secGrowth -= 0.2>>
+	<<elseif _immigration < 60>>
+		. Furthermore, the high number of immigrants that reached the arcology this week complicates security protocols.<<set _secGrowth -= 0.5>>
+	<<elseif _immigration < 80>>
+		. Furthermore, the high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 1>>
+	<<else>>
+		. Furthermore, the extremely high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 2>>
+	<</if>>
+<<else>>
+	The extremely high number of residents makes their job a lot harder.<<set _secGrowth -= 2>>
+	<<if _immigration < 10>>
+		, but the limited number of immigrants that reached the arcology this week does not have any sensible impact.<<set _secGrowth += 0.5>>
+	<<elseif _immigration < 30>>
+		. Furthermore, the number of immigrants that reached the arcology this week is high enough to complicate security protocols.<<set _secGrowth -= 0.2>>
+	<<elseif _immigration < 60>>
+		. Furthermore, the high number of immigrants that reached the arcology this week complicates security protocols.<<set _secGrowth -= 0.5>>
+	<<elseif _immigration < 80>>
+		. Furthermore, the high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 1>>
+	<<else>>
+		. Furthermore, the extremely high number of immigrants that reached the arcology this week severely complicates security protocols.<<set _secGrowth -= 2>>
+	<</if>>
+<</if>>
+<<if $crime < 20>>
+	Crime is a distant problem in the arcology, which makes improving security easier.<<set _secGrowth += 1>>
+<<elseif $crime < 40>>
+	Crime is a minor problem in the arcology, not serious enough to disrupt security efforts.
+<<elseif $crime < 60>>
+	Crime is an issue in the arcology, which makes improving security harder.<<set _secGrowth -= 0.5>>
+<<elseif $crime < 80>>
+	Crime is a overbearing problem in the arcology, which makes improving security a lot harder.<<set _secGrowth -= 1>>
 <<else>>
-	The extremely high number of residents makes their job a lot harder.<<set _residentMod = -1>>
+	Crime is sovereign in the arcology, which makes improving security extremely difficult.<<set _secGrowth -= 2>>
+<</if>>
+<<if $authority < 5000>>
+	The low authority you hold on the arcology hampers the efforts of your security department.<<set _secGrowth -= 1>>
+<<elseif $authority < 7500>>
+	The limited authority you hold on the arcology hampers the efforts of your security department.<<set _secGrowth -= 0.5>>
+<<elseif $authority < 10000>>
+	The authority you hold on the arcology does not significantly impact the efforts of your security department.
+<<elseif $authority < 15000>>
+	The high authority you hold on the arcology facilitates the security department's work.<<set _secGrowth += 0.5>>
+<<else>>
+	The absolute authority you hold on the arcology makes the security department's work a lot easier.<<set _secGrowth += 1>>
 <</if>>
 <<if $lastAttackWeeks < 3>>
-	The recent attack has a negative effect on the security of the arcology.<<set _attackMod = -1>>
+	The recent attack has a negative effect on the security of the arcology.<<set _secGrowth -= 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>>
+	While some time has passed, the last attack still has a negative effect on the security of the arcology.<<set _secGrowth -= 0.5>>
 <<else>>
-	The arcology has not been attacked in a while, which has a positive effect on security.<<set _attackMod = 0.5>>
+	The arcology has not been attacked in a while, which has a positive effect on security.<<set _secGrowth += 0.5>>
 <</if>>
 
+<br>
 
+/* resting point */
+<<set _secRest = $secRestPoint * ($secHelots / $reqHelots)>>
+<<if _secRest < 0>>
+	<<set _secRest = 20>>
+<</if>>
+<<if _secRest < $secRestPoint>>
+	The limited staff assigned to the HQ hampers the improvements to security achieved this week.
+<</if>>
+<<if $security < _secRest>>
+	Your security level is below its resting point. There is enough infrastructure and staff in place to improve it beyond its current level.
+<<elseif $security == _secRest>>
+	Your security level is at its resting point. There is enough infrastructure and staff in place to maintain it at its current level.
+<<else>>
+	Your security level is above its resting point. There is not enough infrastructure or staff in place to maintain it at its current level.
+<</if>>
+<<set _restGrowth = (_secRest - $security) * 0.2>>
+<<set _newSec = $security + _secGrowth + _secRest>>
+<<if _newSec < $security>>
+	This week @@.red;security decreased@@.
+<<elseif _newSec = $security>>
+	This week @@.yellow;security did not change@@.
+<<else>>
+	This week @@.green;security improved@@.
+<</if>>
+<<set $security = _newSec>>
 
-$security  $secRestPoint
-
-
-
-
+<br>
+<br>
 
+/* crime modifiers */
+<<if $week < 30>>
+	Due to the deterioration of the old world countries, crime focuses more and more on the prosperous free cities, yours included.<<set _crimeGrowth += 0.5>>
+<<elseif $week < 60>>
+	Due to the deterioration of the old world countries, crime focuses more and more on the prosperous free cities, yours included.<<set _crimeGrowth += 1>>
+<<elseif $week < 90>>
+	Due to the deterioration of the old world countries, crime focuses more and more on the prosperous free cities, yours included.<<set _crimeGrowth += 1.5>>
+<<elseif $week < 120>>
+	Due to the deterioration of the old world countries, crime focuses more and more on the prosperous free cities, yours included.<<set _crimeGrowth += 2>>
+<<else>>
+	Due to the deterioration of the old world countries, crime focuses more and more on the prosperous free cities, yours included.<<set _crimeGrowth += 2.5>>
+<</if>>
+<<if $arcologies[0].prosperity < 50>>
+	The low prosperity of the arcology facilitates criminal activities.<<set _crimeGrowth += 2>>
+<<elseif $arcologies[0].prosperity < 80>>
+	The fairly low prosperity of the arcology facilitates criminal activities.<<set _crimeGrowth += 1>>
+<<elseif $arcologies[0].prosperity < 12>>
+	The prosperity of the arcology is not high or low enough to have significant effects on the crime level.
+<<elseif $arcologies[0].prosperity < 16>>
+	The prosperity of the arcology is high enough to provide its citizens a decent life, hampering criminal activities.<<set _crimeGrowth -= 0.5>>
+<<elseif $arcologies[0].prosperity < 18>>
+	The prosperity of the arcology is high enough to provide its citizens a decent life, significantly hampering criminal activities.<<set _crimeGrowth -= 1>>
+<<else>>
+	The prosperity of the arcology is high enough to provide its citizens a very good life, significantly hampering criminal activities.<<set _crimeGrowth -= 2>>
+<</if>>
+<<if $ASlaves < 1000>>
+	The low number of slaves in the arcology does not hinder the activity of law enforcement, limiting crime growth.<<set _crimeGrowth -= 1>>
+<<elseif $ASlaves < 2000>>
+	The fairly low number of slaves in the arcology does not hinder significantly the activity of law enforcement, limiting crime growth.<<set _crimeGrowth -= 0.5>>
+<<elseif $ASlaves < 3000>>
+	The number of slaves in the arcology is becoming an impediment for law enforcement, facilitating crime growth.<<set _crimeGrowth += 1>>
+<<else>>
+	The number of slaves in the arcology is becoming a a big issue for law enforcement, facilitating crime growth.<<set _crimeGrowth += 1.5>>
+<</if>>
+<<if $security <= 20>>
+	The security measures in place are not enough yet to effectively fight the current crime level, barely hindering its growth.
+<<elseif $security <= 50>>
+	The security measures in place are barely adequate to fight the current crime level, hardly hindering its growth.<<set _crimeGrowth -= 1>>
+<<elseif $security <= 75>>
+	The security measures in place are adequate to fight the current crime level, hindering its growth.<<set _crimeGrowth -= 2.5>>
+<<else>>
+	The security measures in place are more than adequate to fight the current crime level, considerably hindering its growth.<<set _crimeGrowth -= 5>>
+<</if>>
+<<if $authority < 5000>>
+	Your low authority allows crime to grow undisturbed.<<set _crimeGrowth += 1>>
+<<elseif $authority < 7500>>
+	Your relatively low authority facilitates criminal activities.<<set _crimeGrowth += 0.5>>
+<<elseif $authority < 10000>>
+	Your authority is not high enough to discourage criminal activity.
+<<elseif $authority < 15000>>
+	Your high authority is an effective tool against crime.<<set _crimeGrowth -= 1>>
+<<else>>
+	Your absolute authority is an extremely effective tool against crime.<<set _crimeGrowth -= 2>>
+<</if>>
 
-what influences security?
-	-number of people
-	-recent attacks
-	-authority
-	-reputation
-	
-what influences crime?
-	-security
-	-authority
-	-reputation
-	-prosperity
\ No newline at end of file
+/* crime cap */
+<<set _crimeCap = Math.clamp($crimeCap + $crimeCap * (($reqHelots - $secHelots) / $reqHelots),0,100)>>
+<<if _crimeCap < $crimeCap>>
+	The limited staff assigned to the HQ allows more space for criminals to act.
+<</if>>
+<<set _newCrime = $crime + _crimeGrowth>>
+<<if _newCrime > _crimeCap>>
+	<<set _newCrime = _crimeCap>>
+<</if>>
+<<if _newCrime > $crime>>
+	This week @@.red;crime increased@@.
+<<elseif _newCrime == $crime>>
+	This week @@.yellow;crime did not change@@.
+<<else>>
+	This week @@.green;crime decreased@@.
+<</if>>
+<<set $crime = _newCrime>>
\ No newline at end of file
diff --git a/src/uncategorized/arcmgmt.tw b/src/uncategorized/arcmgmt.tw
index 4c3c787482e..c63d31592eb 100644
--- a/src/uncategorized/arcmgmt.tw
+++ b/src/uncategorized/arcmgmt.tw
@@ -62,6 +62,7 @@ This week, <<if _flux > 0>>few to none<<else>>many<</if>> of $arcologies[0].name
 	<</if>>
 <</if>>
 
+<<set $oldACitizens = $ACitizens>> 
 <<if $ACitizens >= $ACitizenLimit>>
 	<<set $ACitizens = $ACitizenLimit>>
 	Your arcology is currently home to as many citizens as it can house; unless the living areas are reconfigured, the citizen population will not increase.
diff --git a/src/uncategorized/storyCaption.tw b/src/uncategorized/storyCaption.tw
index 54300f2a714..ceac329ef70 100644
--- a/src/uncategorized/storyCaption.tw
+++ b/src/uncategorized/storyCaption.tw
@@ -196,6 +196,60 @@
 <</if>>
 ($rep)
 </span>
+<br>@@.darkviolet;Auth@@ |
+<<set $authority = Math.clamp(Math.trunc($authority), 0, 20000)>>
+<span id="auth">
+<<if $authority > 19000>>
+	@@color:rgb(148,0,211);monarch@@
+<<elseif $authority > 18000>>
+	@@color:rgb(148,0,211);tyrant@@
+<<elseif $authority > 17000>>
+	@@color:rgb(148,0,211);dictator@@
+<<elseif $authority > 16000>>
+	@@color:rgb(148,0,211);prince@@
+<<elseif $authority > 15000>>
+	@@color:rgb(148,0,211);senator@@
+<<elseif $authority > 14000>>
+	@@color:rgb(148,0,211);director@@
+<<elseif $authority > 13000>>
+	@@color:rgb(148,0,211);superior@@
+<<elseif $authority > 12000>>
+	@@color:rgb(148,0,211);celebrated@@
+<<elseif $authority > 11000>>
+	@@color:rgb(148,0,211);honored@@
+<<elseif $authority > 10000>>
+	@@color:rgb(148,0,211);acclaimed@@
+<<elseif $authority > 9000>>
+	@@color:rgb(148,0,211);eminent@@
+<<elseif $authority > 8250>>
+	@@color:rgb(148,0,211);prominent@@
+<<elseif $authority > 7000>>
+	@@color:rgb(148,0,211);distinguished@@
+<<elseif $authority > 6750>>
+	@@color:rgb(148,0,211);admired@@
+<<elseif $authority > 6000>>
+	@@color:rgb(148,0,211);esteemed@@
+<<elseif $authority > 5250>>
+	@@color:rgb(148,0,211);respected@@
+<<elseif $authority > 4500>>
+	@@color:rgb(148,0,211);known@@
+<<elseif $authority > 3750>>
+	@@color:rgb(148,0,211);recognized@@
+<<elseif $authority > 3000>>
+	@@color:rgb(148,0,211);rumored@@
+<<elseif $authority > 2250>>
+	@@color:rgb(148,0,211);mostly harmless@@
+<<elseif $authority > 1500>>
+	@@color:rgb(148,0,211);harmless@@
+<<elseif $authority > 750>>
+	@@color:rgb(148,0,211);toothless@@
+<<else>>
+	@@color:rgb(210,0,211);powerless@@
+<</if>>
+(<<print $Authority>>)
+</span>
+<br>@@.deepskyblue;Security@@ | @@.deepskyblue;<<print Math.trunc($security)>>%@@
+<br>@@.orangered;Crime@@ | @@.orangered;<<print Math.trunc($crime)>>%@@
 <<if (_Pass == "Main")>>
 	<<if ($cheatMode) && ($cheatModeM)>>
 	<<set _TRep = $rep>>
-- 
GitLab