From b7b60c9ba3d7106d70263df50116a43f5acf838d Mon Sep 17 00:00:00 2001
From: Blank_Alt <12406-Blank_Alt@users.noreply.gitgud.io>
Date: Tue, 31 Dec 2019 18:51:24 -0800
Subject: [PATCH] Redo arcology prosperity cleaning

---
 src/init/storyInit.tw                |  3 +-
 src/js/datatypeCleanupJS.js          |  8 ---
 src/js/economyJS.js                  | 31 ++++++++-
 src/uncategorized/buildingWidgets.tw | 46 --------------
 src/uncategorized/economics.tw       |  2 +-
 src/uncategorized/options.tw         | 94 ++++++++++++++--------------
 src/uncategorized/storyCaption.tw    |  2 +-
 7 files changed, 81 insertions(+), 105 deletions(-)

diff --git a/src/init/storyInit.tw b/src/init/storyInit.tw
index c6a19081ae4..8939b0ec0de 100644
--- a/src/init/storyInit.tw
+++ b/src/init/storyInit.tw
@@ -1160,7 +1160,7 @@ You should have received a copy of the GNU General Public License along with thi
 <<set $GDP = 278.6>>
 <<set $NPCSlaves = 900>>
 <<set $ASlaves = 900>>
-<<set $AProsperityCap = 120>>
+<<set $AProsperityCap = 0>>
 
 <<set $food = 50000>>
 <<set $foodLastWeek = 0>>
@@ -1484,7 +1484,6 @@ You should have received a copy of the GNU General Public License along with thi
 	$prosthetics[id] = {amount: 0, research: 0};
 })>>
 
-
 <<set $merchantFSWares = ["AssetExpansionistResearch", "GenderRadicalistResearch", "HedonisticDecadenceResearch", "SlaveProfessionalismResearch", "SlimnessEnthusiastResearch", "TransformationFetishistResearch", "YouthPreferentialistResearch"]>>
 <<set $merchantIllegalWares = ["asexualReproduction", "childhoodFertilityInducedNCS", "PGHack", "RapidCellGrowthFormula", "sympatheticOvaries", "UterineRestraintMesh"]>> /* "AnimalOrgans" for future use */
 <<set $RapidCellGrowthFormula = 0>>
diff --git a/src/js/datatypeCleanupJS.js b/src/js/datatypeCleanupJS.js
index b8bf50fc764..617f7a04f7c 100644
--- a/src/js/datatypeCleanupJS.js
+++ b/src/js/datatypeCleanupJS.js
@@ -1792,14 +1792,8 @@ window.PCDatatypeCleanup = function PCDatatypeCleanup() {
 };
 
 window.EconomyDatatypeCleanup = function EconomyDatatypeCleanup() {
-	V.ACitizens = Math.max(+V.ACitizens, 0) || 0;
-	V.ASlaves = Math.max(+V.ASlaves, 0) || 0;
-	V.shelterAbuse = Math.max(+V.shelterAbuse, 0) || 0;
-
 	V.arcologies[0].prosperity = Math.clamp(+V.arcologies[0].prosperity, 1, V.AProsperityCap) || 1;
 	V.AProsperityCap = Math.max(+V.AProsperityCap, 0) || 0;
-	V.arcologies[0].ownership = Math.clamp(+V.arcologies[0].ownership, 0, 100) || 0;
-	V.arcologies[0].minority = Math.clamp(+V.arcologies[0].minority, 0, 100) || 0;
 
 	V.food = Math.max(+V.food, 0) || 0;
 
@@ -1921,8 +1915,6 @@ window.EconomyDatatypeCleanup = function EconomyDatatypeCleanup() {
 };
 
 window.ArcologyDatatypeCleanup = function ArcologyDatatypeCleanup() {
-	V.arcologies[0].prosperity = Math.clamp(+V.arcologies[0].prosperity, 1, 300) || 1;
-	V.AProsperityCap = Math.max(+V.AProsperityCap, 0) || 0;
 	V.arcologies[0].ownership = Math.clamp(+V.arcologies[0].ownership, 0, 100) || 0;
 	V.arcologies[0].minority = Math.clamp(+V.arcologies[0].minority, 0, 100) || 0;
 
diff --git a/src/js/economyJS.js b/src/js/economyJS.js
index 993941693bd..ac469bcb3f6 100644
--- a/src/js/economyJS.js
+++ b/src/js/economyJS.js
@@ -1643,7 +1643,8 @@ window.slaveJobValues = function(lowerClassSexDemandRef, middleClassSexDemandRef
 			s.effectiveWhoreClass = effectiveWhoreClass(s);
 			s.maxWhoreClass = s.effectiveWhoreClass;
 			income *= initialHealthPenalty;
-			
+
+
 
 			// Automatically changing effectiveWhoreClass
 			// what is the initial effective whore class? Are we providing more sex than overal demand? Is the ratio of supply/demand for this tier higher than the one below it?
@@ -1925,3 +1926,31 @@ window.forceNeg = function(x) {
 Number.prototype.toFixedHTML = function() {
 	return num(Number.prototype.toFixed.apply(this, arguments)).replace(/\.0+$/, '<span style="opacity: 0.3">$&</span>');
 };
+
+window.SectorCounts = function() {
+ V.Sweatshops = 0; // Ternaries: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
+ V.AProsperityCapModified = V.AProsperityCapModified > 0 ? V.AProsperityCapModified : 0;
+ const caps = [
+ {upgrade: "drones", cap: 10},
+ {upgrade: "hydro", cap: 30},
+ {upgrade: "apron", cap: 60},
+ {upgrade: "grid", cap: 100},
+ {upgrade: "spire", cap: 150}];
+
+ V.AProsperityCap = 0;
+ caps.forEach(cap => {
+		if (V.arcologyUpgrade[cap.upgrade] > 0) {
+			V.AProsperityCap = cap.cap;
+		}
+ });
+
+ for (let i = 0; i < V.sectors.length; i++) {
+		if (V.sectors[i].type.includes("Apartments")) {
+			V.AProsperityCap += V.sectors[i].type.includes("Luxury") ? 15 : 10;
+		} else if (V.sectors[i].type.includes("Sweatshops")) {
+			V.Sweatshops++;
+		}
+ }
+
+ V.AProsperityCap += V.AProsperityCapModified;
+};
diff --git a/src/uncategorized/buildingWidgets.tw b/src/uncategorized/buildingWidgets.tw
index 7ce4c195280..fa9763062ef 100644
--- a/src/uncategorized/buildingWidgets.tw
+++ b/src/uncategorized/buildingWidgets.tw
@@ -303,52 +303,6 @@ Selling this sector would relinquish a 4% interest in $arcologies[0].name. Such
 
 <</widget>>
 
-/%
-Call as <<SectorCounts>>
-Updates $AProsperityCap, $Sweatshops.
-%/
-<<widget "SectorCounts">>
-
-<<if $arcologyUpgrade.drones != 1>>
-	<<set $AProsperityCap = 0>>
-<<elseif $arcologyUpgrade.hydro != 1>>
-	<<set $AProsperityCap = 10>>
-<<elseif $arcologyUpgrade.apron != 1>>
-	<<set $AProsperityCap = 30>>
-<<elseif $arcologyUpgrade.grid != 1>>
-	<<set $AProsperityCap = 60>>
-<<elseif $arcologyUpgrade.spire != 1>>
-	<<set $AProsperityCap = 100>>
-<<else>>
-	<<set $AProsperityCap = 150>>
-<</if>>
-<<set $Sweatshops = 0>>
-<<if $arcologyUpgrade.spire == 1>>
-	<<for _i = 1; _i <= 4; _i++>>
-		<<if $sectors[_i].type == "DenseApartments">>
-			<<set $AProsperityCap += 10>>
-		<<elseif $sectors[_i].type == "LuxuryApartments">>
-			<<set $AProsperityCap += 15>>
-		<<else>>
-			<<set $AProsperityCap += 10>>
-		<</if>>
-	<</for>>
-<</if>>
-<<for _i = 8; _i <= 19; _i++>>
-	<<if $sectors[_i].type == "LuxuryApartments">>
-		<<set $AProsperityCap += 15>>
-	<<else>>
-		<<set $AProsperityCap += 10>>
-	<</if>>
-<</for>>
-<<for _i = 25; _i <= 29; _i++>>
-	<<if $sectors[_i].type == "Sweatshops">>
-		<<set $Sweatshops++>>
-	<</if>>
-<</for>>
-
-<</widget>>
-
 /%
 Call as <<UpdateOwnership>>
 Updates $arcologies[0].ownership.
diff --git a/src/uncategorized/economics.tw b/src/uncategorized/economics.tw
index 921c790d269..fd91fdd8e34 100644
--- a/src/uncategorized/economics.tw
+++ b/src/uncategorized/economics.tw
@@ -8,7 +8,7 @@
 	<<set $debtWarned = 0>>
 <</if>>
 
-<<SectorCounts>>
+<<= SectorCounts()>>
 <<UpdateOwnership>>
 
 <<include "Markets Report">>
diff --git a/src/uncategorized/options.tw b/src/uncategorized/options.tw
index 31e723d9ac0..70d5a5cb14c 100644
--- a/src/uncategorized/options.tw
+++ b/src/uncategorized/options.tw
@@ -859,29 +859,6 @@ This save was created using FC version $ver build $releaseID.
 			</td>
 			</tr>
 
-			<tr>
-			<td style="text-align:right">
-			<<link "Give menial slaves" "Options">>
-				<<set $menials = Math.clamp($menials + 30, 0, $PopCap)>>
-			<</link>>
-			| <<link "Remove menial slaves" "Options">>
-				<<set $menials = Math.clamp($menials - 30, 0, $PopCap)>>
-			<</link>>
-			</td>
-
-			<td style="text-align:left">
-			<<link "Add slaves" "Options">> /*Will work to a limited degree, minimums and maximums for slaves are set through population*/
-				<<set $NPCSlaves += 200>>
-			<</link>>
-			| <<link "Remove slaves" "Options">> /*Will work to a limited degree*/
-				<<set $NPCSlaves -= 200>>
-				<<if $NPCSlaves < 0>>
-					<<set $NPCSlaves = 0>>
-				<</if>>
-			<</link>>
-			</td>
-			</tr>
-
 			<tr>
 			<td style="text-align:right">
 			<<link "Give militia manpower" "Options">>
@@ -889,7 +866,7 @@ This save was created using FC version $ver build $releaseID.
 				<<recalcManpower>>
 			<</link>>
 			| <<link "Remove militia manpower" "Options">>
-				<<set $militiaFreeManpower = Math.clamp($militiaFreeManpower - 30, 0, $militiaFreeManpower)>>
+				<<set $militiaFreeManpower = Math.max($militiaFreeManpower - 30, 0)>>
 				<<recalcManpower>>
 			<</link>>
 			</td>
@@ -900,33 +877,12 @@ This save was created using FC version $ver build $releaseID.
 				<<recalcManpower>>
 			<</link>>
 			| <<link "Remove mercs manpower" "Options">>
-				<<set $mercFreeManpower = Math.clamp($mercFreeManpower - 30, 0, $mercFreeManpower)>>
+				<<set $mercFreeManpower = Math.max($mercFreeManpower - 30, 0)>>
 				<<recalcManpower>>
 			<</link>>
 			</td>
 			</tr>
 
-			<tr>
-			<td style="text-align:right">
-			<<link "Add citizens" "Options">> /*Will no longer work as intended due to population changes*/
-				<<set $lowerClass += 200>>
-			<</link>>
-			| <<link "Remove citizens" "Options">> /*also no longer properly functional*/
-				<<set $lowerClass -= 200>>
-				<<if $lowerClass < 0>>
-					<<set $lowerClass = 0>>
-				<</if>>
-			<</link>>
-			</td>
-
-			<td style="text-align:left">
-			<<link "Raise prosperity" "Options">>
-				<<set $arcologies[0].prosperity = Math.clamp($arcologies[0].prosperity + 10, 0, 1000)>>
-			<</link>>
-			| <<link "Lower prosperity" "Options">>
-				<<set $arcologies[0].prosperity = Math.clamp($arcologies[0].prosperity - 10, 0, 1000)>>
-			<</link>>
-			</td>
 			</tr>
 			</table>
 		<</if>> /* closes SecExp check*/
@@ -992,6 +948,52 @@ This save was created using FC version $ver build $releaseID.
 			<div class="scLink2">
 			[[Add 100000 money|Options][$cheater = 1, cashX(100000, "cheating")]] | [[Add 10000 rep|Options][$cheater = 1, repX(10000, "cheating")]] //Cheating will be flagged in your save//
 			</div>
+
+			<div class="scLink2">
+			<<= SectorCounts()>>
+			<<link "Raise prosperity cap" "Options">>
+				<<set $AProsperityCapModified += 10>>
+			<</link>>
+			| <<link "Lower prosperity cap" "Options">>
+				<<set $AProsperityCapModified -= 10>>
+			<</link>>
+
+			<br>
+			<<link "Raise prosperity" "Options">>
+				<<set $arcologies[0].prosperity = Math.clamp($arcologies[0].prosperity + 10, 0, $AProsperityCap)>>
+			<</link>>
+			| <<link "Lower prosperity" "Options">>
+				<<set $arcologies[0].prosperity = Math.clamp($arcologies[0].prosperity - 10, 0, $AProsperityCap)>>
+			<</link>>
+
+			<br>
+			<<link "Give menial slaves" "Options">>
+				<<set $menials = Math.clamp($menials + 30, 0, $PopCap)>>
+			<</link>>
+			| <<link "Remove menial slaves" "Options">>
+				<<set $menials = Math.clamp($menials - 30, 0, $PopCap)>>
+			<</link>>
+			</div>
+
+			/%
+			<br>Thanks for making this a right pain twine
+			<br>
+			<<link "Add citizens" "Options">> /*Will no longer work as intended due to population changes*/
+				<<set $lowerClass = Math.max($lowerClass + 200, 0)>>
+			<</link>>
+			| <<link "Remove citizens" "Options">> /*also no longer properly functional*/
+				<<set $lowerClass = Math.max($lowerClass - 200, 0)>>
+			<</link>>
+
+			<br>
+			<<link "Add slaves" "Options">> /*Will work to a limited degree, minimums and maximums for slaves are set through population*/
+				<<set $NPCSlaves = Math.max($NPCSlaves + 200, 0>>
+			<</link>>
+			| <<link "Remove slaves" "Options">> /*Will work to a limited degree*/
+				<<set $NPCSlaves = Math.max($NPCSlaves - 200, 0>>
+			<</link>>
+			%/
+
 			<<options $seeAge>>
 				<<option 2 "Slaves will celebrate birthdays, but not age.">>
 				<<option 1 "Enable slave aging">>
diff --git a/src/uncategorized/storyCaption.tw b/src/uncategorized/storyCaption.tw
index e1cfda14b95..194f846f75f 100644
--- a/src/uncategorized/storyCaption.tw
+++ b/src/uncategorized/storyCaption.tw
@@ -242,7 +242,7 @@
 	<<if _Pass != "Manage Penthouse">>
 		<<if $sideBarOptions.GSP > 0 && _Pass != "Neighbor Interact">> <br>
 			@@.yellowgreen;GSP@@ |
-			<<print Math.trunc(0.1*$arcologies[0].prosperity)>>m
+			<<= num(Math.trunc(0.1*$arcologies[0].prosperity))>>m
 			<<if $arcologies[0].ownership >= $arcologies[0].minority>>
 				<<if $arcologies[0].ownership >= $arcologies[0].minority+5>>
 					<<if $arcologies[0].ownership < 100>>
-- 
GitLab