From fb18ac3c0aa8fe01a2ee19c8ecc104ba155f9d4f Mon Sep 17 00:00:00 2001
From: kopareigns <kopareigns@gmail.com>
Date: Wed, 31 Oct 2018 23:13:08 -0400
Subject: [PATCH] Datatype and compatibility updates

---
 devNotes/twine JS.txt                         | 66 +++++++++++++++++++
 src/cheats/mod_EditArcologyCheat.tw           | 47 ++++++++-----
 .../mod_EditArcologyCheatDatatypeCleanup.tw   | 38 +----------
 src/events/intro/introSummary.tw              |  6 +-
 src/js/datatypeCleanupJS.tw                   | 66 +++++++++++++++++++
 src/uncategorized/BackwardsCompatibility.tw   | 55 +---------------
 src/uncategorized/persBusiness.tw             | 47 +++++--------
 7 files changed, 184 insertions(+), 141 deletions(-)

diff --git a/devNotes/twine JS.txt b/devNotes/twine JS.txt
index bbde3a95142..61ee520b3db 100644
--- a/devNotes/twine JS.txt	
+++ b/devNotes/twine JS.txt	
@@ -34701,3 +34701,69 @@ window.SlaveDatatypeCleanup = function SlaveDatatypeCleanup (slave) {
 	slave.missingLegs = Math.clamp(+slave.missingLegs, 0, 3) || 0;
 	generatePronouns(slave);
 };
+
+window.ArcologyDatatypeCleanup = function ArcologyDatatypeCleanup () {
+	const V = State.variables;
+	
+	V.ACitizens = Math.max(+V.ACitizens, 0) || 0;
+	V.ACitizenLimit = Math.max(+V.ACitizenLimit, 0) || 0;
+	V.ASlaves = Math.max(+V.ASlaves, 0) || 0;
+	V.ASlaveLimit = Math.max(+V.ASlaveLimit, 0) || 0;
+	V.shelterAbuse = Math.max(+V.shelterAbuse, 0) || 0;
+	
+	V.economy = Math.max(+V.economy, 20) || 100;
+	V.difficultySwitch = Math.clamp(+V.difficultySwitch, 0, 1) || 0;
+	V.localEcon = Math.max(+V.localEcon, 20) || V.economy;
+	V.econRate = Math.clamp(V.econRate, 1, 4) || 2;
+	V.slaveCostFactor = Math.max(+V.slaveCostFactor, 0) || 1;
+	if (V.menialSupplyFactor !== 0) {
+		V.menialSupplyFactor = Math.clamp(V.menialSupplyFactor, -50000, 50000) || (1 - V.slaveCostFactor) * 400 * 1000 * 0.5; /* (1 - slaveCostFactor) * price elasticity * base price * 0.5 */
+	}
+	if (V.menialDemandFactor !== 0) {
+		V.menialDemandFactor = Math.clamp(V.menialDemandFactor, -50000, 50000) || -V.menialSupplyFactor;
+	}
+	V.slaveCostRandom = Math.clamp(V.slaveCostRandom, -3, 3) || 0;
+	V.demandTimer = Math.max(+V.demandTimer, 0) || 0;
+	V.elapsedDemandTimer = Math.max(+V.elapsedDemandTimer, 0) || 0;
+	V.supplyTimer = Math.max(+V.supplyTimer, 0) || 0;
+	V.elapsedSupplyTimer = Math.max(+V.elapsedSupplyTimer, 0) || 0;
+	V.deltaSupply = Math.clamp(+V.deltaSupply, -3000, 3000) || 0;
+	V.deltaDemand = Math.clamp(+V.deltaDemand, -3000, 3000) || 0;
+	V.econWeatherDamage = Math.max(+V.econWeatherDamage, 0) || 0;
+	V.disasterResponse = Math.clamp(V.disasterResponse, 0, 2) || 0;
+	
+	V.foodCost = Math.trunc(2500/V.economy);
+	V.drugsCost = Math.trunc(10000/V.economy);
+	V.rulesCost = Math.trunc(10000/V.economy);
+	V.modCost = Math.trunc(5000/V.economy);
+	V.surgeryCost = Math.trunc(30000/V.economy);
+	V.facilityCost = +V.facilityCost || 100;
+	V.policyCost = +V.policyCost || 5000;
+
+	V.TSS.studentsBought = Math.max(+V.TSS.studentsBought, 0) || 0;
+	V.TSS.schoolProsperity = Math.clamp(+V.TSS.schoolProsperity, -10, 10) || 0;
+	V.GRI.studentsBought = Math.max(+V.GRI.studentsBought, 0) || 0;
+	V.GRI.schoolProsperity = Math.clamp(+V.GRI.schoolProsperity, -10, 10) || 0;
+	V.SCP.studentsBought = Math.max(+V.SCP.studentsBought, 0) || 0;
+	V.SCP.schoolProsperity = Math.clamp(+V.SCP.schoolProsperity, -10, 10) || 0;
+	V.LDE.studentsBought = Math.max(+V.LDE.studentsBought, 0) || 0;
+	V.LDE.schoolProsperity = Math.clamp(+V.LDE.schoolProsperity, -10, 10) || 0;
+	V.TGA.studentsBought = Math.max(+V.TGA.studentsBought, 0) || 0;
+	V.TGA.schoolProsperity = Math.clamp(+V.TGA.schoolProsperity, -10, 10) || 0;
+	V.HA.studentsBought = Math.max(+V.HA.studentsBought, 0) || 0;
+	V.HA.schoolProsperity = Math.clamp(+V.HA.schoolProsperity, -10, 10) || 0;
+	V.TCR.studentsBought = Math.max(+V.TCR.studentsBought, 0) || 0;
+	V.TCR.schoolProsperity = Math.clamp(+V.TCR.schoolProsperity, -10, 10) || 0;
+	V.TFS.studentsBought = Math.max(+V.TFS.studentsBought, 0) || 0;
+	V.TFS.schoolProsperity = Math.clamp(+V.TFS.schoolProsperity, -10, 10) || 0;
+
+	V.arcologies[0].prosperity = Math.max(+V.arcologies[0].prosperity, 0) || 0;
+	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;
+
+	/* Will be moved when I get around to creating PCDatatypeCleanup */
+	V.PC.actualAge = Math.clamp(+V.PC.actualAge, 14, 80) || 35;
+	V.PC.physicalAge = Math.clamp(+V.PC.physicalAge, 14, 80) || V.PC.actualAge;
+	V.PC.visualAge = Math.clamp(+V.PC.visualAge, 14, 80) || V.PC.actualAge;
+};
diff --git a/src/cheats/mod_EditArcologyCheat.tw b/src/cheats/mod_EditArcologyCheat.tw
index ea0ec5f24a0..473019194eb 100644
--- a/src/cheats/mod_EditArcologyCheat.tw
+++ b/src/cheats/mod_EditArcologyCheat.tw
@@ -1,30 +1,43 @@
 :: MOD_Edit Arcology Cheat [nobr]
 
 <<set $nextButton = "Continue", $nextLink = "MOD_Edit Arcology Cheat Datatype Cleanup">>
-<<set $PC.actualAge = Math.clamp($PC.actualAge, 14, 80)>>
 
 ''Cheating Edit Arcology''
 
-<<if ($economy != 1) || ($seeDicks != 25) || ($continent != "North America") || ($internationalTrade != 1) || ($internationalVariety != 1) || ($seeRace != 1) || ($seeNationality != 1) || ($seeExtreme != 0) || ($plot != 1)>>
-	//[[restore defaults|MOD_Edit Arcology Cheat][$seeDicks = 25,$economy = 1,$continent = "North America",$internationalTrade = 1,$internationalVariety = 1,$seeRace = 1,$seeNationality = 1,$seeExtreme = 0,$plot = 1]]//
+<<if ($economy != 100) || ($seeDicks != 25) || ($continent != "North America") || ($internationalTrade != 1) || ($internationalVariety != 1) || ($seeRace != 1) || ($seeNationality != 1) || ($seeExtreme != 0) || ($plot != 1)>>
+	//[[restore defaults|MOD_Edit Arcology Cheat][$seeDicks = 25,$economy = 100,$continent = "North America",$internationalTrade = 1,$internationalVariety = 1,$seeRace = 1,$seeNationality = 1,$seeExtreme = 0,$plot = 1]]//
 <</if>>
 
-<br><br>The world economy is
-<<if $economy == 1>>
-	in ''doubtful'' shape.
-	[[Easier|MOD_Edit Arcology Cheat][$economy = 0.5]] | [[Harder|MOD_Edit Arcology Cheat][$economy = 1.5]]
-<<elseif $economy < 1>>
-	still in ''good'' shape.
-	[[Harder|MOD_Edit Arcology Cheat][$economy = 1]]
+<br><br>The economic situation is
+<<if $economy > 125>>
+	''not truly dire. Not yet.'' //Very Easy//
+	<br>[[Harder|MOD_Edit Arcology Cheat][$economy = 125]]
+<<elseif $economy > 100>>
+	''getting a touch dire.'' //Easy//
+	<br>[[Harder|MOD_Edit Arcology Cheat][$economy = 100]] | [[Easier|MOD_Edit Arcology Cheat][$economy = 200]]
+<<elseif $economy > 80>>
+	''serious risks.'' //Default Difficulty//
+	<br>[[Harder|MOD_Edit Arcology Cheat][$economy = 80]] | [[Easier|MOD_Edit Arcology Cheat][$economy = 125]]
+<<elseif $economy > 67>>
+	''ugly.'' //Hard//
+	<br>[[Harder|MOD_Edit Arcology Cheat][$economy = 67]] | [[Easier|MOD_Edit Arcology Cheat][$economy = 100]]
 <<else>>
-	in ''terrible'' shape.
-	[[Easier|MOD_Edit Arcology Cheat][$economy = 1]]
+	''this is the last dance.'' //Very Hard//
+	<br>[[Easier|MOD_Edit Arcology Cheat][$economy = 80]]
+<</if>>
+<br>The economy is forecasted to 
+<<if $difficultySwitch == 0>>
+	''remain fairly stable.''
+<<elseif $econRate == 1>>
+	''slowly decline''. //Easy//
+	<br>[[Harder|MOD_Edit Arcology Cheat][$econRate = 2]]
+<<elseif $econRate == 2>>
+	''noticeably deteriorate'' //Default Difficulty//
+	<br>[[Harder|MOD_Edit Arcology Cheat][$econRate = 4]] | [[Easier|MOD_Edit Arcology Cheat][$econRate = 1]]
+<<else>>
+	''go to hell in a handbasket''. //Hard//
+	<br>[[Easier|MOD_Edit Arcology Cheat][$econRate = 2]]
 <</if>>
-
-<<set $drugsCost = Math.trunc(100*$economy)>>
-<<set $rulesCost = Math.trunc(100*$economy)>>
-<<set $modCost = Math.trunc(50*$economy)>>
-<<set $surgeryCost = Math.trunc(300*$economy)>>
 
 <br>The arcology is located in ''$continent''.
 [[North America|MOD_Edit Arcology Cheat][$continent = "North America", $language = "English"]] | [[South America|MOD_Edit Arcology Cheat][$continent = "South America", $language = "Spanish"]] | [[Europe|MOD_Edit Arcology Cheat][$continent = "Europe", $language = "English"]] | [[the Middle East|MOD_Edit Arcology Cheat][$continent = "the Middle East", $language = "Arabic"]] | [[Africa|MOD_Edit Arcology Cheat][$continent = "Africa", $language = "Arabic"]] | [[Asia|MOD_Edit Arcology Cheat][$continent = "Asia", $language = "Chinese"]] | [[Australia|MOD_Edit Arcology Cheat][$continent = "Australia", $language = "English"]] | [[Japan|MOD_Edit Arcology Cheat][$continent = "Japan", $language = "Japanese"]]
diff --git a/src/cheats/mod_EditArcologyCheatDatatypeCleanup.tw b/src/cheats/mod_EditArcologyCheatDatatypeCleanup.tw
index 86030bf4e5a..1d4b3759f3a 100644
--- a/src/cheats/mod_EditArcologyCheatDatatypeCleanup.tw
+++ b/src/cheats/mod_EditArcologyCheatDatatypeCleanup.tw
@@ -12,43 +12,7 @@
 <</if>>
 <<unset $customEvalCode>>
 
-<<set $ACitizens = Number($ACitizens) || 0>>
-<<set $ACitizenLimit = Number($ACitizenLimit) || 0>>
-<<set $ASlaves = Number($ASlaves) || 0>>
-<<set $ASlaveLimit = Number($ASlaveLimit) || 0>>
-<<set $arcologies[0].prosperity = Number($arcologies[0].prosperity) || 0>>
-<<set $AProsperityCap = Number($AProsperityCap) || 0>>
-<<set $shelterAbuse = Number($shelterAbuse) || 0>>
-
-<<set $TSS.studentsBought = Number($TSS.studentsBought) || 0>>
-<<set $TSS.schoolProsperity = Number($TSS.schoolProsperity) || 0>>
-
-<<set $GRI.studentsBought = Number($GRI.studentsBought) || 0>>
-<<set $GRI.schoolProsperity = Number($GRI.schoolProsperity) || 0>>
-
-<<set $SCP.studentsBought = Number($SCP.studentsBought) || 0>>
-<<set $SCP.schoolProsperity = Number($SCP.schoolProsperity) || 0>>
-
-<<set $LDE.studentsBought = Number($LDE.studentsBought) || 0>>
-<<set $LDE.schoolProsperity = Number($LDE.schoolProsperity) || 0>>
-
-<<set $TGA.studentsBought = Number($TGA.studentsBought) || 0>>
-<<set $TGA.schoolProsperity = Number($TGA.schoolProsperity) || 0>>
-
-<<set $HA.studentsBought = Number($HA.studentsBought) || 0>>
-<<set $HA.schoolProsperity = Number($HA.schoolProsperity) || 0>>
-
-<<set $TCR.studentsBought = Number($TCR.studentsBought) || 0>>
-<<set $TCR.schoolProsperity = Number($TCR.schoolProsperity) || 0>>
-
-<<set $TFS.studentsBought = Number($TFS.studentsBought) || 0>>
-<<set $TFS.schoolProsperity = Number($TFS.schoolProsperity) || 0>>
-
-<<set $arcologies[0].ownership = Number($arcologies[0].ownership) || 0>>
-<<set $arcologies[0].minority = Number($arcologies[0].minority) || 0>>
-
-<<set $PC.actualAge = Number($PC.actualAge) || 35>>
-<<set $PC.physicalAge = $PC.actualAge, $PC.visualAge = $PC.actualAge>>
+<<run ArcologyDatatypeCleanup()>>
 
 The chanting grows louder and louder, CHEAT! CHEAT! CHEAT!
 
diff --git a/src/events/intro/introSummary.tw b/src/events/intro/introSummary.tw
index 0953db6ad6d..296218fa4ae 100644
--- a/src/events/intro/introSummary.tw
+++ b/src/events/intro/introSummary.tw
@@ -52,7 +52,7 @@ __''World Settings''__
 	''slow decline''. //Easy//
 	<br>[[Harder|Intro Summary][$econRate = 2]] | [[Easier|Intro Summary][$difficultySwitch = 0]]
 <<elseif $econRate == 2>>
-	''noticable deterioration'' //Default Difficulty//
+	''noticeable deterioration'' //Default Difficulty//
 	<br>[[Harder|Intro Summary][$econRate = 4]] | [[Easier|Intro Summary][$econRate = 1]]
 <<else>>
 	''going to hell in a handbasket''. //Hard//
@@ -1138,8 +1138,8 @@ __''Mods''__
 	<<goto "init Nationalities">>
 <</link>>
 
-<<if ($economy != 100) || ($seeDicks != 50) || ($continent != "North America") || ($internationalTrade != 1) || ($internationalVariety != 1) || ($seeRace != 1) || ($seeNationality != 1) || ($seeExtreme != 0) || ($seeCircumcision != 1) || ($seeAge != 1) || ($plot != 1)>>
-	| [[restore defaults|Intro Summary][$seeDicks = 50,$economy = 100,$continent = "North America",$internationalTrade = 1,$internationalVariety = 1,$seeRace = 1,$seeNationality = 1,$seeExtreme = 0,$seeCircumcision = 1,$seeAge = 1,$plot = 1]]
+<<if ($economy != 100) || ($seeDicks != 25) || ($continent != "North America") || ($internationalTrade != 1) || ($internationalVariety != 1) || ($seeRace != 1) || ($seeNationality != 1) || ($seeExtreme != 0) || ($seeCircumcision != 1) || ($seeAge != 1) || ($plot != 1)>>
+	| [[restore defaults|Intro Summary][$seeDicks = 25,$economy = 100,$continent = "North America",$internationalTrade = 1,$internationalVariety = 1,$seeRace = 1,$seeNationality = 1,$seeExtreme = 0,$seeCircumcision = 1,$seeAge = 1,$plot = 1]]
 <</if>>
 
 <br><br>
diff --git a/src/js/datatypeCleanupJS.tw b/src/js/datatypeCleanupJS.tw
index 018f5961bc7..0a6ce740a78 100644
--- a/src/js/datatypeCleanupJS.tw
+++ b/src/js/datatypeCleanupJS.tw
@@ -507,3 +507,69 @@ window.SlaveDatatypeCleanup = function SlaveDatatypeCleanup (slave) {
 	slave.missingLegs = Math.clamp(+slave.missingLegs, 0, 3) || 0;
 	generatePronouns(slave);
 };
+
+window.ArcologyDatatypeCleanup = function ArcologyDatatypeCleanup () {
+	const V = State.variables;
+	
+	V.ACitizens = Math.max(+V.ACitizens, 0) || 0;
+	V.ACitizenLimit = Math.max(+V.ACitizenLimit, 0) || 0;
+	V.ASlaves = Math.max(+V.ASlaves, 0) || 0;
+	V.ASlaveLimit = Math.max(+V.ASlaveLimit, 0) || 0;
+	V.shelterAbuse = Math.max(+V.shelterAbuse, 0) || 0;
+	
+	V.arcologies[0].prosperity = Math.max(+V.arcologies[0].prosperity, 0) || 0;
+	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.economy = Math.max(+V.economy, 20) || 100;
+	V.difficultySwitch = Math.clamp(+V.difficultySwitch, 0, 1) || 0;
+	V.localEcon = Math.max(+V.localEcon, 20) || V.economy;
+	V.econRate = Math.clamp(V.econRate, 1, 4) || 2;
+	V.slaveCostFactor = Math.max(+V.slaveCostFactor, 0) || 1;
+	if (V.menialSupplyFactor !== 0) {
+		V.menialSupplyFactor = Math.clamp(V.menialSupplyFactor, -50000, 50000) || (1 - V.slaveCostFactor) * 400 * 1000 * 0.5; /* (1 - slaveCostFactor) * price elasticity * base price * 0.5 */
+	}
+	if (V.menialDemandFactor !== 0) {
+		V.menialDemandFactor = Math.clamp(V.menialDemandFactor, -50000, 50000) || -V.menialSupplyFactor;
+	}
+	V.slaveCostRandom = Math.clamp(V.slaveCostRandom, -3, 3) || 0;
+	V.demandTimer = Math.max(+V.demandTimer, 0) || 0;
+	V.elapsedDemandTimer = Math.max(+V.elapsedDemandTimer, 0) || 0;
+	V.supplyTimer = Math.max(+V.supplyTimer, 0) || 0;
+	V.elapsedSupplyTimer = Math.max(+V.elapsedSupplyTimer, 0) || 0;
+	V.deltaSupply = Math.clamp(+V.deltaSupply, -3000, 3000) || 0;
+	V.deltaDemand = Math.clamp(+V.deltaDemand, -3000, 3000) || 0;
+	V.econWeatherDamage = Math.max(+V.econWeatherDamage, 0) || 0;
+	V.disasterResponse = Math.clamp(V.disasterResponse, 0, 2) || 0;
+	
+	V.foodCost = Math.trunc(2500/V.economy);
+	V.drugsCost = Math.trunc(10000/V.economy);
+	V.rulesCost = Math.trunc(10000/V.economy);
+	V.modCost = Math.trunc(5000/V.economy);
+	V.surgeryCost = Math.trunc(30000/V.economy);
+	V.facilityCost = +V.facilityCost || 100;
+	V.policyCost = +V.policyCost || 5000;
+
+	V.TSS.studentsBought = Math.max(+V.TSS.studentsBought, 0) || 0;
+	V.TSS.schoolProsperity = Math.clamp(+V.TSS.schoolProsperity, -10, 10) || 0;
+	V.GRI.studentsBought = Math.max(+V.GRI.studentsBought, 0) || 0;
+	V.GRI.schoolProsperity = Math.clamp(+V.GRI.schoolProsperity, -10, 10) || 0;
+	V.SCP.studentsBought = Math.max(+V.SCP.studentsBought, 0) || 0;
+	V.SCP.schoolProsperity = Math.clamp(+V.SCP.schoolProsperity, -10, 10) || 0;
+	V.LDE.studentsBought = Math.max(+V.LDE.studentsBought, 0) || 0;
+	V.LDE.schoolProsperity = Math.clamp(+V.LDE.schoolProsperity, -10, 10) || 0;
+	V.TGA.studentsBought = Math.max(+V.TGA.studentsBought, 0) || 0;
+	V.TGA.schoolProsperity = Math.clamp(+V.TGA.schoolProsperity, -10, 10) || 0;
+	V.HA.studentsBought = Math.max(+V.HA.studentsBought, 0) || 0;
+	V.HA.schoolProsperity = Math.clamp(+V.HA.schoolProsperity, -10, 10) || 0;
+	V.TCR.studentsBought = Math.max(+V.TCR.studentsBought, 0) || 0;
+	V.TCR.schoolProsperity = Math.clamp(+V.TCR.schoolProsperity, -10, 10) || 0;
+	V.TFS.studentsBought = Math.max(+V.TFS.studentsBought, 0) || 0;
+	V.TFS.schoolProsperity = Math.clamp(+V.TFS.schoolProsperity, -10, 10) || 0;
+
+	/* Will be moved when I get around to creating PCDatatypeCleanup */
+	V.PC.actualAge = Math.clamp(+V.PC.actualAge, 14, 80) || 35;
+	V.PC.physicalAge = Math.clamp(+V.PC.physicalAge, 14, 80) || V.PC.actualAge;
+	V.PC.visualAge = Math.clamp(+V.PC.visualAge, 14, 80) || V.PC.actualAge;
+};
diff --git a/src/uncategorized/BackwardsCompatibility.tw b/src/uncategorized/BackwardsCompatibility.tw
index 7b365de22ef..5815557a8e0 100644
--- a/src/uncategorized/BackwardsCompatibility.tw
+++ b/src/uncategorized/BackwardsCompatibility.tw
@@ -103,9 +103,6 @@
 <<if def $recruiters>>
 	<<unset $recruiters>>
 <</if>>
-<<if ndef $foodCost>>
-	<<set $foodCost = 25>>
-<</if>>
 <<if ndef $fixedNationality>>
 	<<set $fixedNationality = 0>>
 <</if>>
@@ -230,12 +227,6 @@
 		<<set $PC.actualAge = 50>>
 	<</if>>
 <</if>>
-<<if ndef $PC.visualAge>>
-	<<set $PC.visualAge = $PC.actualAge>>
-<</if>>
-<<if ndef $PC.physicalAge>>
-	<<set $PC.physicalAge = $PC.actualAge>>
-<</if>>
 <<if ndef $PC.birthWeek>>
 	<<set $PC.birthWeek = 0>>
 <</if>>
@@ -1698,9 +1689,6 @@ Setting missing global variables:
 	<<set $terrain = "rural">>
 <</if>>
 
-<<if ndef $menialDemandFactor>>
-	<<set $menialDemandFactor = 0>>
-<</if>>
 <<if ndef nicaeaAnnounceable>>
 	<<set $nicaeaAnnounceable = 0>>
 <</if>>
@@ -1720,13 +1708,6 @@ Setting missing global variables:
 	<<set $nicaeaHeld = 0>>
 <</if>>
 
-<<if ndef $facilityCost>>
-<<set $facilityCost = 100>>
-<</if>>
-<<if ndef $policyCost>>
-	<<set $policyCost = 5000>>
-<</if>>
-
 <<if ndef $REFeminizationCheckinIDs>>
 	<<set $REFeminizationCheckinIDs = []>>
 <</if>>
@@ -2670,42 +2651,8 @@ Setting missing global variables:
 <<if $economy == 1.5>>
 	<<set $economy = 67>>
 <</if>>
-<<if ndef $difficultySwitch>>
-	<<set $difficultySwitch = 0>>
-<</if>>
-<<if ndef $menialSupplyFactor>>
-	/* (1 - slaveCostFactor) * price elasticity * base price * 0.5 */
-	<<set $menialSupplyFactor = (1 - $slaveCostFactor) * 400 * 1000 * 0.5>>
-	<<set $menialDemandFactor = (1 - $slaveCostFactor) * -400 * 1000 * 0.5>>
-<</if>>
-<<if ndef $slaveCostRandom>>
-	<<set $slaveCostRandom = 0>>
-<</if>>
-<<if ndef $demandTimer>>
-	<<set $demandTimer = 0>>
-<</if>>
-<<if ndef $elapsedDemandTimer>>
-	<<set $elapsedDemandTimer = 0>>
-<</if>>
-<<if ndef $supplyTimer>>
-	<<set $supplyTimer = 0>>
-<</if>>
-<<if ndef $elapsedSupplyTimer>>
-	<<set $elapsedSupplyTimer = 0>>
-<</if>>
-<<if ndef $deltaSupply>>
-	<<set $deltaSupply = 0>>
-<</if>>
-<<if ndef $deltaDemand>>
-	<<set $deltaDemand = 0>>
-<</if>>
 
-<<if ndef $econWeatherDamage>>
-	<<set $econWeatherDamage = 0>>
-<</if>>
-<<if ndef $disasterResponse>>
-	<<set $disasterResponse = 0>>
-<</if>>
+<<run ArcologyDatatypeCleanup()>>
 
 Done!
 
diff --git a/src/uncategorized/persBusiness.tw b/src/uncategorized/persBusiness.tw
index 83e582bcec2..d9bfbe90328 100644
--- a/src/uncategorized/persBusiness.tw
+++ b/src/uncategorized/persBusiness.tw
@@ -859,34 +859,27 @@ Routine upkeep of your demesne costs @@.yellow;<<print cashFormat($costs)>>.@@
 /*Without events triggering and a relatively average supply/demand situation, the best case scenario is an increase/decrease in the price of slaves of 10 in one week. Chance of these conditions happening are 1/25. For demand or supply to go from average to their maximum will take 25 weeks if rolling highest growth each time a roll is made and all other luck is average. Because of the properties of the market and how it develops the likely prices one will encounter are distributed in a bellshaped fashion, centered around 1000. Minimum possible price is 750, maximum 1250. At +/- 35000 chances of supply or demand getting even more extreme are reduced.*/
 <<set _demandSlaveVar = random(-10,10)*10>>
 <<set _supplySlaveVar = random(-10,10)*10>>
-<<set _randomSlaveCost = random(-3,3)>>
-<<set $slaveCostRandom = _randomSlaveCost>>
+<<set $slaveCostRandom = random(-3,3)>>
 <<if $menialDemandFactor <= -50000>>
-	<<set _demandDelta = random(1,3)>>
-	<<set $deltaDemand = _demandDelta * 1000>>
-	<<set _timerDemand = random(7,12)>>
-	<<set $demandTimer = _timerDemand>>
+	<<set $deltaDemand = random(1,3) * 1000>>
+	<<set $demandTimer = random(7,12)>>
 	<<set $elapsedDemandTimer = 1>>
 	<<set $menialDemandFactor += $deltaDemand + _demandSlaveVar>>
 <<elseif $menialDemandFactor >= 50000>>
-	<<set _demandDelta = random(-3,-1)>>
-	<<set $deltaDemand = _demandDelta * 1000>>
-	<<set _timerDemand = random(7,12)>>
-	<<set $demandTimer = _timerDemand>>
+	<<set $deltaDemand = random(-3,-1) * 1000>>
+	<<set $demandTimer = random(7,12)>>
 	<<set $elapsedDemandTimer = 1>>
 	<<set $menialDemandFactor += $deltaDemand + _demandSlaveVar>>
 <<elseif $demandTimer - $elapsedDemandTimer <= 0>>
-	<<set _timerDemand = random(7,12)>>
-	<<set $demandTimer = _timerDemand>>
+	<<set $demandTimer = random(7,12)>>
 	<<set $elapsedDemandTimer = 1>>
 	<<if $menialDemandFactor > 35000>>
-		<<set _demandDelta = random(-3,1)>>
+		<<set $deltaDemand = random(-3,1) * 1000>>
 	<<elseif $menialDemandFactor < -35000>>
-		<<set _demandDelta = random(-1,3)>>
+		<<set $deltaDemand = random(-1,3) * 1000>>
 	<<else>>
-		<<set _demandDelta = random(-2,2)>>
+		<<set $deltaDemand = random(-2,2) * 1000>>
 	<</if>>
-	<<set $deltaDemand = _demandDelta * 1000>>
 	<<set $menialDemandFactor += $deltaDemand + _demandSlaveVar>>
 	<<if $menialDemandFactor <= -35000>>
 		<br>Demand for slaves is approaching a @@.red;''historic low'',@@ forecasts predict
@@ -941,31 +934,25 @@ Routine upkeep of your demesne costs @@.yellow;<<print cashFormat($costs)>>.@@
 <</if>>
 
 <<if $menialSupplyFactor <= -50000>>
-	<<set _supplyDelta = random(1,3)>>
-	<<set $deltaSupply = _supplyDelta * 1000>>
-	<<set _timerSupply = random(7,12)>>
-	<<set $supplyTimer = _timerSupply>>
+	<<set $deltaSupply = random(1,3) * 1000>>
+	<<set $supplyTimer = random(7,12)>>
 	<<set $elapsedSupplyTimer = 1>>
 	<<set $menialSupplyFactor += $deltaSupply + _demandSlaveVar>>
 <<elseif $menialSupplyFactor >= 50000>>
-	<<set _supplyDelta = random(-3,-1)>>
-	<<set $deltaSupply = _supplyDelta * 1000>>
-	<<set _timerSupply = random(7,12)>>
-	<<set $supplyTimer = _timerSupply>>
+	<<set $deltaSupply = random(-3,-1) * 1000>>
+	<<set $supplyTimer = random(7,12)>>
 	<<set $elapsedSupplyTimer = 1>>
 	<<set $menialSupplyFactor += $deltaSupply + _demandSlaveVar>>
 <<elseif $supplyTimer - $elapsedSupplyTimer <= 0>>
-	<<set _timerSupply = random(7,12)>>
-	<<set $supplyTimer = _timerSupply>>
+	<<set $supplyTimer = random(7,12)>>
 	<<set $elapsedSupplyTimer = 1>>
 	<<if $menialSupplyFactor > 35000>>
-		<<set _supplyDelta = random(-3,1)>>
+		<<set $deltaSupply = random(-3,1) * 1000>>
 	<<elseif $menialSupplyFactor < -35000>>
-		<<set _supplyDelta = random(-1,3)>>
+		<<set $deltaSupply = random(-1,3) * 1000>>
 	<<else>>
-		<<set _supplyDelta = random(-2,2)>>
+		<<set $deltaSupply = random(-2,2) * 1000>>
 	<</if>>
-	<<set $deltaSupply = _supplyDelta * 1000>>
 	<<set $menialSupplyFactor += $deltaSupply + _supplySlaveVar>>
 	<<if $menialSupplyFactor <= -35000>>
 		<br>Supply of slaves is approaching a @@.green;''historic low'',@@ forecasts predict
-- 
GitLab