From 26205beeb8a82bf4e0cdf488e2811e72a44fb0c9 Mon Sep 17 00:00:00 2001
From: lowercase-donkey <lowercasedonkey@gmail.com>
Date: Sun, 20 Jan 2019 21:41:13 -0500
Subject: [PATCH] House servant costBudget and EconomyJS fixes

---
 devNotes/twine JS.txt            | 14 +++++------
 src/endWeek/saServant.tw         |  8 +++----
 src/js/economyJS.tw              |  6 ++---
 src/uncategorized/costsBudget.tw | 40 ++++++++++++++------------------
 4 files changed, 32 insertions(+), 36 deletions(-)

diff --git a/devNotes/twine JS.txt b/devNotes/twine JS.txt
index 792e7a6c8ad..8a9d9ace212 100644
--- a/devNotes/twine JS.txt	
+++ b/devNotes/twine JS.txt	
@@ -2313,15 +2313,15 @@ window.getCost = function(array) {
 	cashX(forceNeg(getPCTrainingCosts()), "PCtraining");
 	cashX(forceNeg(getPCCosts()), "PCmedical");
 	getTotalSlaveCosts(array2);
-
-
+	
+	
 	//these two apply a multiplicative effect to all costs so far.
-	// Calculate what the deduced expenses would be, then subtract
+	// Calculate what the deduced expenses would be, then subtract 
 	costSoFar = (oldCash - State.variables.cash); //How much we have spent by this point; expected to be positive.
-	cashX(forceNeg(costSoFar - getEnvironmentCosts(costSoFar), "environment")); //getEnv takes total costs and makes it worse.  Figure out how much worse and record it
+	cashX(costSoFar - getEnvironmentCosts(costSoFar), "environment"); //getEnv takes total costs and makes it worse.  Figure out how much worse and record it
 
 	costSoFar = (oldCash - State.variables.cash);
-	cashX(forceNeg(costSoFar - getPCMultiplierCosts(costSoFar)), "PCskills");
+	cashX(costSoFar - getPCMultiplierCosts(costSoFar), "PCskills");
 
 	//in the old order these were applied after multiplication.  Not sure if deliberate, but I'm leaving it for now.
 	cashX(forceNeg(getSFCosts()), "specialForces");
@@ -2331,7 +2331,7 @@ window.getCost = function(array) {
 
 //slave expenses
 window.predictTotalSlaveCosts = function(array3) {
-	var loopCosts = 0;
+	var loopCosts = 0;	
 	//slave expenses
 	for (var slave of array3) {
 		loopCosts += getSlaveCost(slave);
@@ -2347,7 +2347,7 @@ window.getTotalSlaveCosts = function(array3) {
 		slaveCost = getSlaveCost(slave);
 		cashX(forceNeg(slaveCost), "slaveUpkeep", slave);
 		slaveCostMinor = getSlaveMinorCosts(slave);
-		cashX(forceNeg(slaveCostMinor), "slaveUpkeep", slave);
+		cashX(Math.abs(slaveCostMinor), "houseServant", slave);
 	}
 	//nothing to return, cashX already billed.
 };
diff --git a/src/endWeek/saServant.tw b/src/endWeek/saServant.tw
index 5f84d57b1e3..0034e8dfe3b 100644
--- a/src/endWeek/saServant.tw
+++ b/src/endWeek/saServant.tw
@@ -30,12 +30,12 @@ window.saServant = function saServant(slave) {
 				}
 				if (!(canHear(slave))) {
 					t += ` However, ${his} inability to hear often leaves ${him} oblivious to ${V.Stewardess.slaveName}'s orders, limiting their meaningful interactions.`;
-					cashX(V.stewardessBonus/4, "servantsQuarters", slave);
+					cashX(V.stewardessBonus/4, "houseServant", slave);
 				} else if ((slave.hears == -1 && slave.earwear != "hearing aids") || (slave.hears == 0 && slave.earwear == "muffling ear plugs")) {
 					t += ` However, ${he} often doesn't catch what ${V.Stewardess.slaveName} says, leading to frustration, confusion and less work done.`;
-					cashX(V.stewardessBonus/2, "servantsQuarters", slave);
+					cashX(V.stewardessBonus/2, "houseServant", slave);
 				} else {
-					cashX(V.stewardessBonus, "servantsQuarters", slave);
+					cashX(V.stewardessBonus, "houseServant", slave);
 				}
 			}
 		}
@@ -122,7 +122,7 @@ window.saServant = function saServant(slave) {
 			} else {
 				t += `an incident without lasting effect.`;
 			}
-			cashX(Math.trunc(V.FResult*_vignette.effect), "servantsQuarters", slave);
+			cashX(Math.trunc(V.FResult*_vignette.effect), "houseServant", slave);
 		} else if (_vignette.type == "devotion") {
 			if (_vignette.effect > 0) {
 				if (slave.devotion > 50) {
diff --git a/src/js/economyJS.tw b/src/js/economyJS.tw
index b4ee0cec07b..41086d9a6a9 100644
--- a/src/js/economyJS.tw
+++ b/src/js/economyJS.tw
@@ -97,10 +97,10 @@ window.getCost = function(array) {
 	//these two apply a multiplicative effect to all costs so far.
 	// Calculate what the deduced expenses would be, then subtract 
 	costSoFar = (oldCash - State.variables.cash); //How much we have spent by this point; expected to be positive.
-	cashX(forceNeg(costSoFar - getEnvironmentCosts(costSoFar), "environment")); //getEnv takes total costs and makes it worse.  Figure out how much worse and record it
+	cashX(costSoFar - getEnvironmentCosts(costSoFar), "environment"); //getEnv takes total costs and makes it worse.  Figure out how much worse and record it
 
 	costSoFar = (oldCash - State.variables.cash);
-	cashX(forceNeg(costSoFar - getPCMultiplierCosts(costSoFar)), "PCskills");
+	cashX(costSoFar - getPCMultiplierCosts(costSoFar), "PCskills");
 
 	//in the old order these were applied after multiplication.  Not sure if deliberate, but I'm leaving it for now.
 	cashX(forceNeg(getSFCosts()), "specialForces");
@@ -126,7 +126,7 @@ window.getTotalSlaveCosts = function(array3) {
 		slaveCost = getSlaveCost(slave);
 		cashX(forceNeg(slaveCost), "slaveUpkeep", slave);
 		slaveCostMinor = getSlaveMinorCosts(slave);
-		cashX(forceNeg(slaveCostMinor), "slaveUpkeep", slave);
+		cashX(Math.abs(slaveCostMinor), "houseServant", slave);
 	}
 	//nothing to return, cashX already billed.
 };
diff --git a/src/uncategorized/costsBudget.tw b/src/uncategorized/costsBudget.tw
index a510fb74aed..0c73efb93d1 100644
--- a/src/uncategorized/costsBudget.tw
+++ b/src/uncategorized/costsBudget.tw
@@ -356,7 +356,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 	//Slaves working in these buildings have their profits reported in "jobs".//
 	</tr>
 
-	<<if $brothel > 0>>
+	<<if $lastWeeksCashIncome.brothel || $lastWeeksCashExpenses.brothel>>
 		<tr>
 			<td>[[$brothelNameCaps|Brothel][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($brothelSlaves slaves)</td>
 			<td>
@@ -416,7 +416,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $club > 0>>
+	<<if $lastWeeksCashIncome.club || $lastWeeksCashExpenses.club>>
 		<tr>
 			<td>[[$clubNameCaps|Club][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($clubSlaves slaves)</td>
 			<td>
@@ -476,7 +476,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $arcade > 0>>
+	<<if $lastWeeksCashIncome.arcade || $lastWeeksCashExpenses.arcade>>
 	<tr>
 		<td>[[$arcadeNameCaps|Arcade][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($arcadeSlaves slaves)</td>
 		<td>
@@ -504,7 +504,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 	</tr>
 	<</if>>
 
-	<<if $dairy > 0>>
+	<<if $lastWeeksCashIncome.dairy || $lastWeeksCashExpenses.dairy>>
 		<tr>
 			<td>[[$dairyNameCaps|Dairy][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($dairySlaves slaves)</td>
 			<td>
@@ -534,7 +534,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if ($servantsQuarters > 0) && ($servantsQuartersUpgradeMonitoring > 0)>>
+	<<if $lastWeeksCashIncome.servantsQuarters || $lastWeeksCashExpenses.servantsQuarters>>
 		<tr>
 			<td>[[Servants' Quarters][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($servantsQuartersSlaves slaves)</td>
 			<td>
@@ -564,7 +564,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if ($masterSuiteUpgradePregnancy == 1)>>
+	<<if $lastWeeksCashIncome.masterSuite || $lastWeeksCashExpenses.masterSuite>>
 		<tr>
 			<td>[[Master Suite][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($masterSuiteSlaves slaves)</td>
 			<td>
@@ -594,7 +594,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $schoolroom>>
+	<<if $lastWeeksCashIncome.school || $lastWeeksCashExpenses.school>>
 		<tr>
 			<td>[[$schoolroomNameCaps|Schoolroom][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($schoolroomSlaves slaves)</td>
 			<td>
@@ -624,7 +624,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $spa>>
+	<<if $lastWeeksCashIncome.spa || $lastWeeksCashExpenses.spa>>
 		<tr>
 			<td>[[$spaNameCaps|Spa][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($spaSlaves slaves)</td>
 			<td>
@@ -654,7 +654,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $clinic>>
+	<<if $lastWeeksCashIncome.clinic || $lastWeeksCashExpenses.clinic>>
 		<tr>
 			<td>[[$clinicNameCaps|Clinic][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($clinicSlaves slaves)</td>
 			<td>
@@ -684,7 +684,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $cellblock>>
+	<<if $lastWeeksCashIncome.cellblock || $lastWeeksCashExpenses.cellblock>>
 		<tr>
 			<td>[[$cellblockNameCaps|Cellblock][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($cellblockSlaves slaves)</td>
 			<td>
@@ -714,7 +714,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $researchLab.built == "true">>
+	<<if $lastWeeksCashIncome.lab || $lastWeeksCashExpenses.lab>>
 		<tr>
 			<td>[[Research Lab][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] maintenance</td>
 			<td>
@@ -749,10 +749,10 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		<</if>>
 		<<if $researchLab.menials != 0>>
 			<tr>
-				<td><i>[[Research Lab][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($researchLab.menials menial Slaves)</i></td>
+				<td><i>[[Research Lab][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($researchLab.menials menial slaves)</i></td>
 				<td></td>
 				<td><i>@@.red;-+<<print cashFormat(Math.trunc(100*$researchLab.menials))>>@@</i></td>
-				<td><i>@@.red;-<<print cashFormat(Math.abs(Math.trunc(100*$researchLab.)menials))>>@@</i></td>
+				<td><i>@@.red;-<<print cashFormat(Math.abs(Math.trunc(100*$researchLab.menials))>>@@</i></td>
 			</tr>
 		<</if>>
 	<</if>>
@@ -790,7 +790,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $incubator>>
+	<<if $lastWeeksCashIncome.incubator || $lastWeeksCashExpenses.incubator>>
 		<tr>
 			<td>[[$incubatorNameCaps|Incubator][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($incubatorSlaves slaves)</td>
 			<td>
@@ -820,7 +820,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $nursery>>
+	<<if $lastWeeksCashIncome.nursery || $lastWeeksCashExpenses.nursery>>
 		<tr>
 			<td>[[$nurseryNameCaps|Nursery][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($nurserySlaves slaves)</td>
 			<td>
@@ -850,7 +850,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $farmyard>>
+	<<if $lastWeeksCashIncome.farmyard || $lastWeeksCashExpenses.farmyard>>
 		<tr>
 			<td>[[$farmyardNameCaps|Farmyard][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($farmyardSlaves slaves)</td>
 			<td>
@@ -880,7 +880,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-	<<if $pit>>
+	<<if $lastWeeksCashIncome.pit || $lastWeeksCashExpenses.pit>>
 		<tr>
 			<td>[[$pitNameCaps|Pit][$nextButton = "Back to Budget", $nextLink = "Costs Budget"]] ($fighterIDs.length slaves)</td>
 			<td>
@@ -1306,8 +1306,6 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-
-
 	<<if $lastWeeksCashIncome.porn || $lastWeeksCashExpenses.porn>>
 		<tr>
 			<td>Porn</td>
@@ -1368,8 +1366,6 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		</tr>
 	<</if>>
 
-
-
 	<<if $lastWeeksCashIncome.slaveTransfer || $lastWeeksCashExpenses.slaveTransfer>>
 		<tr>
 			<td>Buying/Selling Major Slaves</td>
@@ -1742,7 +1738,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 	<tr>
 		<td>
 			Your rents
-			<<if $lastWeeksCashExpenses.rents > 0>>
+			<<if $lastWeeksCashExpenses.rents < 0>>
 				and bribes
 			<</if>>
 		</td>
-- 
GitLab