From 78cb52151d3a392958304f07ba3671ceabe99bee Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Sun, 29 Dec 2019 19:14:31 -0800
Subject: [PATCH] Remove .tired member of slave objects and update or remove
 all uses thereof. Convert farmyard to use healthPenalty instead of .tired and
 .health.condition. Apply health penalty to Head Girl effectiveness.

---
 src/endWeek/saWorkTheFarm.js                  | 28 +++++++++++++++++--
 .../nursery/nurseryDatatypeCleanup.js         |  1 -
 src/facilities/nursery/nurseryWidgets.js      |  9 ------
 src/js/SlaveState.js                          |  5 ----
 src/js/datatypeCleanupJS.js                   |  5 ++--
 src/js/food.js                                | 21 ++------------
 src/js/slaveSummaryWidgets.js                 |  3 --
 src/js/vignettes.js                           |  4 +--
 src/npc/slaveStats.tw                         |  3 +-
 src/player/js/enslavePlayer.js                |  1 -
 src/uncategorized/hgApplication.tw            |  2 +-
 src/uncategorized/nextWeek.tw                 |  2 +-
 src/uncategorized/reRecruit.tw                |  4 +--
 src/uncategorized/recETS.tw                   |  5 +---
 src/uncategorized/saServeYourOtherSlaves.tw   |  6 ++--
 15 files changed, 39 insertions(+), 60 deletions(-)

diff --git a/src/endWeek/saWorkTheFarm.js b/src/endWeek/saWorkTheFarm.js
index a2b0eaccde3..2cb5e422167 100644
--- a/src/endWeek/saWorkTheFarm.js
+++ b/src/endWeek/saWorkTheFarm.js
@@ -85,9 +85,31 @@ window.saWorkTheFarm = function saWorkTheFarm(slave) {
 		}
 		t += `. `;
 	}
-	if (slave.tired === 1) {
-		t += `${He} is so tired that ${he} doesn't have the energy to work efficiently, impacting ${his} production. `;
+
+	if (slave.health.illness > 0 || slave.health.tired > 50) {
+		t += ` ${He} performed worse this week due to<span class="red">`;
+		if (slave.health.illness === 1) {
+			t += ` feeling under the weather`;
+		} else if (slave.health.illness === 2) {
+			t += ` a minor illness`;
+		} else if (slave.health.illness === 3) {
+			t += ` being sick`;
+		} else if (slave.health.illness === 4) {
+			t += ` being very sick`;
+		} else if (slave.health.illness === 5) {
+			t += ` a terrible illness`;
+		}
+		if (slave.health.illness > 0 && slave.health.tired > 50) {
+			t += ` and`;
+		}
+		if (slave.health.tired >= 80) {
+			t += ` exhaustion`;
+		} else if (slave.health.tired >= 50) {
+			t += ` being tired`;
+		}
+		t += `.</span> `;
 	}
+
 	t += `As a result, ${he} produces <span class="chocolate">${massFormat(food)}</span> of food over the week. `;
 
 	// Close Food Production
@@ -370,7 +392,7 @@ window.saWorkTheFarm = function saWorkTheFarm(slave) {
 		if (slave.preg > 10) {
 			// TODO: write this
 		}
-		if (slave.tired === 1) {
+		if (slave.health.tired > 50) {
 			t += `${He} is so tired that the energy in ${his} shows is basically nonexistent, affecting ${his} profits. `;
 		}
 		if (slave.chem > 10) {
diff --git a/src/facilities/nursery/nurseryDatatypeCleanup.js b/src/facilities/nursery/nurseryDatatypeCleanup.js
index 90443dad101..6ad295788e1 100644
--- a/src/facilities/nursery/nurseryDatatypeCleanup.js
+++ b/src/facilities/nursery/nurseryDatatypeCleanup.js
@@ -510,7 +510,6 @@ App.Facilities.Nursery.ChildDatatypeCleanup = function(child) {
 		child.intelligenceImplant = Math.clamp(+child.intelligenceImplant, 0, 30) || 0;
 		child.premature = Math.clamp(+child.premature, 0, 1) || 0;
 		child.training = Math.clamp(+child.training, 0, 150) || 0;
-		child.tired = Math.clamp(+child.tired, 0, 1) || 0;
 		child.hears = Math.clamp(+child.hears, -2, 0) || 0;
 		child.smells = Math.clamp(+child.smells, -1, 0) || 0;
 		child.tastes = Math.clamp(+child.tastes, -1, 0) || 0;
diff --git a/src/facilities/nursery/nurseryWidgets.js b/src/facilities/nursery/nurseryWidgets.js
index bf917c34212..e043169c8e8 100644
--- a/src/facilities/nursery/nurseryWidgets.js
+++ b/src/facilities/nursery/nurseryWidgets.js
@@ -2405,9 +2405,6 @@ App.Facilities.Nursery.ChildSummary = function(child) {
 				longRules(child);
 			}
 		}
-		if (child.tired !== 0) {
-			r += `Tired. `;
-		}
 		if (V.abbreviateDiet === 1) {
 			shortWeight(child);
 		} else if (V.abbreviateDiet === 2) {
@@ -15795,7 +15792,6 @@ App.Facilities.Nursery.infantToChild = function infantToChild(child) {
 	child.tailShape = "none",
 	child.tastes = 0,
 	child.teeth = "baby",
-	child.tired = 0,
 	child.tonguePiercing = 0,
 	child.training = 0,
 	child.trust = 0,	// TODO:
@@ -17795,11 +17791,6 @@ App.Facilities.Nursery.ChildState = class ChildState {
 		*
 		* 0: none; 1: supplemented; 2: nearly entirely */
 		this.dietMilk = 0;
-		/** Affects work performance, i.e. decreased pay for whoring
-		* caused by poor/overcrowded sleeping conditions
-		*
-		* 0: not tired; 1: tired */
-		this.tired = 0;
 		/**
 		* * -2: heavy male hormones
 		* * -1: male hormones
diff --git a/src/js/SlaveState.js b/src/js/SlaveState.js
index f8e7a5bb78a..5554f8c35af 100644
--- a/src/js/SlaveState.js
+++ b/src/js/SlaveState.js
@@ -1652,11 +1652,6 @@ App.Entity.SlaveState = class SlaveState {
 		 *
 		 * 0: none; 1: supplemented; 2: nearly entirely */
 		this.dietMilk = 0;
-		/** affects work performance, i.e. decreased pay for whoring
-		 * caused by poor/overcrowded sleeping conditions
-		 *
-		 * 0: not tired; 1: tired */
-		this.tired = 0;
 		/**
 		 * * -2: heavy male hormones
 		 * * -1: male hormones
diff --git a/src/js/datatypeCleanupJS.js b/src/js/datatypeCleanupJS.js
index 7593585eb24..ff4cf2c1bb8 100644
--- a/src/js/datatypeCleanupJS.js
+++ b/src/js/datatypeCleanupJS.js
@@ -27,6 +27,9 @@ App.Entity.Utils.SlaveDataSchemeCleanup = (function() {
 		if (slave.hasOwnProperty("assignmentVisible")) {
 			delete slave.assignmentVisible;
 		}
+		if (slave.hasOwnProperty("tired")) {
+			delete slave.tired;
+		}
 	}
 
 	/**
@@ -1094,7 +1097,6 @@ window.SlaveDatatypeCleanup = (function SlaveDatatypeCleanup() {
 			slave.indenture = Math.max(+slave.indenture, -1) || -1;
 		}
 		slave.indentureRestrictions = Math.clamp(+slave.indentureRestrictions, 0, 2) || 0;
-		slave.tired = Math.clamp(+slave.tired, 0, 1) || 0;
 		slave.hears = Math.clamp(+slave.hears, -2, 0) || 0;
 		slave.smells = Math.clamp(+slave.smells, -1, 0) || 0;
 		slave.tastes = Math.clamp(+slave.tastes, -1, 0) || 0;
@@ -1634,7 +1636,6 @@ window.childMiscellaneousDatatypeCleanup = function childMiscellaneousDatatypeCl
 	child.intelligenceImplant = Math.clamp(+child.intelligenceImplant, 0, 30) || 0;
 	child.premature = Math.clamp(+child.premature, 0, 1) || 0;
 	child.training = Math.clamp(+child.training, 0, 150) || 0;
-	child.tired = Math.clamp(+child.tired, 0, 1) || 0;
 	child.hears = Math.clamp(+child.hears, -2, 0) || 0;
 	child.smells = Math.clamp(+child.smells, -1, 0) || 0;
 	child.tastes = Math.clamp(+child.tastes, -1, 0) || 0;
diff --git a/src/js/food.js b/src/js/food.js
index 5f0207f2005..fecc4a67488 100644
--- a/src/js/food.js
+++ b/src/js/food.js
@@ -18,11 +18,6 @@ window.foodAmount = function(slave) {
 		} else if (slave.devotion < -50) {
 			food *= 0.8;
 		}
-		if (slave.health.condition > 50) {							// slave is extremely healthy or more
-			food *= 1.1;
-		} else if (slave.health.condition < -50) {					// slave is unhealthy or less
-			food *= 0.8;
-		}
 		if (slave.muscles > 30) {									// slave is muscular or more
 			food *= 1.1;
 		} else if (slave.muscles <= -6) {							// slave is weak or less
@@ -47,9 +42,7 @@ window.foodAmount = function(slave) {
 		} else if (slave.hears < -1) {								// slave is deaf
 			food *= 0.6;
 		}
-		if (slave.tired === 1) {									// slave is tired
-			food *= 0.8;
-		}
+		food *= healthPenalty(slave);
 		food = Math.trunc(food);
 		food = Math.clamp(food, 1, 1000000000000000000);
 		return food;
@@ -253,11 +246,6 @@ window.farmShowsIncome = function(slave) {
 		} else if (slave.porn.prestige === 3) { 						// slave is extremely prestigious from porn
 			cash *= 1.3;
 		} 															// TODO: add relationship checks
-		if (slave.health.condition > 20) { 							// slave is very healthy or more
-			cash *= 1.1;
-		} else if (slave.health.condition < -20) { 					// slave is less than unhealthy
-			cash *= 0.8;
-		}
 		if (slave.face > 40) {										// slave is beautiful or more
 			cash *= 1.3;
 		} else if (slave.face > 10) {								// slave is very pretty or more
@@ -302,12 +290,7 @@ window.farmShowsIncome = function(slave) {
 		if (slave.preg > 10) {										// slave is pregnant and showing
 			cash *= 0.8;											// TODO: not sure how to incorporate pregnancy
 		}															// TODO: incorporate skills
-		if (slave.tired === 1) {									// slave is tired
-			cash *= 0.9;
-		}
-		if (slave.chem > 10) {										// slave has high genetic damage
-			cash *= 0.9;
-		}
+		cash *= healthPenalty(slave);
 		if (slave.intelligence > 50) {								// slave is very smart or better
 			cash *= 1.1;
 		} else if (slave.intelligence < -50) {						// slave is very slow or less
diff --git a/src/js/slaveSummaryWidgets.js b/src/js/slaveSummaryWidgets.js
index 9bd7ce3e2d1..8d032ea8aa3 100644
--- a/src/js/slaveSummaryWidgets.js
+++ b/src/js/slaveSummaryWidgets.js
@@ -52,9 +52,6 @@ window.SlaveSummaryUncached = (function() {
 				long_rules(slave, para);
 			}
 		}
-		if (slave.tired !== 0) {
-			addText(para, `Tired.`);
-		}
 		if (V.abbreviateDiet === 1) {
 			short_weight(slave, para);
 		} else if (V.abbreviateDiet === 2) {
diff --git a/src/js/vignettes.js b/src/js/vignettes.js
index f3719926ec9..4bc85942a06 100644
--- a/src/js/vignettes.js
+++ b/src/js/vignettes.js
@@ -4094,7 +4094,7 @@ window.GetVignette = function GetVignette(slave) {
 				effect: 1,
 			});
 		}
-		if (slave.tired === 1) {
+		if (slave.health.tired > 50) {
 			vignettes.push({
 				text: `${he} was so exhausted that ${he} barely got any work done,`,
 				type: "cash",
@@ -4503,7 +4503,7 @@ window.GetVignette = function GetVignette(slave) {
 				effect: 0,
 			});
 		}
-		if (slave.tired === 1) {
+		if (slave.health.tired > 50) {
 			vignettes.push({
 				text: `${he} felt very tired and spent a lot of time napping,`,
 				type: "health",
diff --git a/src/npc/slaveStats.tw b/src/npc/slaveStats.tw
index 32dd435a338..63725a36825 100644
--- a/src/npc/slaveStats.tw
+++ b/src/npc/slaveStats.tw
@@ -131,8 +131,7 @@ Income: <<= num($activeSlave.lastWeeksRepIncome)>>
 		Flaw: $activeSlave.sexualFlaw,
 		Quirk: $activeSlave.sexualQuirk
 
-		<br>Energy: $activeSlave.energy,
-		Tired: $activeSlave.tired
+		<br>Energy: $activeSlave.energy
 		<br>Need: $activeSlave.need,
 		Cap: $activeSlave.needCap
 		<br>Addict: $activeSlave.addict
diff --git a/src/player/js/enslavePlayer.js b/src/player/js/enslavePlayer.js
index 2fba484bc00..6180a1cbd1f 100644
--- a/src/player/js/enslavePlayer.js
+++ b/src/player/js/enslavePlayer.js
@@ -86,7 +86,6 @@ window.convertPlayerToSlave = function(slave, badEnd = "boring") {
 	slave.useRulesAssistant = 1;
 	slave.dietCum = 0;
 	slave.dietMilk = 0;
-	slave.tired = 0;
 	slave.fuckdoll = 0;
 	slave.choosesOwnClothes = 0;
 	slave.clothes = "no clothing";
diff --git a/src/uncategorized/hgApplication.tw b/src/uncategorized/hgApplication.tw
index d99f9bd9c87..75e2994a24e 100644
--- a/src/uncategorized/hgApplication.tw
+++ b/src/uncategorized/hgApplication.tw
@@ -15,7 +15,7 @@
 <<if $HeadGirl.sexualFlaw == "abusive" && $HGSeverity >= 0>>
 	<<set _effectiveness += 10>>
 <</if>>
-<<set $activeSlave.tired = 1>>
+<<set _effectiveness *= healthPenalty($HeadGirl)>>
 
 &nbsp;&nbsp;&nbsp;&nbsp;''Your Head Girl __@@.pink;$HeadGirl.slaveName@@__'' notices that ''__@@.pink;$activeSlave.slaveName@@__''
 <<switch $HGtraining>>
diff --git a/src/uncategorized/nextWeek.tw b/src/uncategorized/nextWeek.tw
index 9115db254e2..7796fb5a1e5 100644
--- a/src/uncategorized/nextWeek.tw
+++ b/src/uncategorized/nextWeek.tw
@@ -153,7 +153,7 @@
 		<<set $slaves[_i].fertPeak = 0>>
 	<</if>>
 	<<set $slaves[_i].trust = Number($slaves[_i].trust.toFixed(1)), $slaves[_i].devotion = Number($slaves[_i].devotion.toFixed(1))>>
-	<<set $slaves[_i].oldDevotion = $slaves[_i].devotion, $slaves[_i].oldTrust = $slaves[_i].trust, $slaves[_i].tired = 0, $slaves[_i].minorInjury = 0>>
+	<<set $slaves[_i].oldDevotion = $slaves[_i].devotion, $slaves[_i].oldTrust = $slaves[_i].trust, $slaves[_i].minorInjury = 0>>
 	<<if $slaves[_i].sentence > 1>>
 		<<set $slaves[_i].sentence -= 1>>
 	<<elseif $slaves[_i].sentence == 1>>
diff --git a/src/uncategorized/reRecruit.tw b/src/uncategorized/reRecruit.tw
index 85a64350017..2651b631b82 100644
--- a/src/uncategorized/reRecruit.tw
+++ b/src/uncategorized/reRecruit.tw
@@ -1669,7 +1669,7 @@
 <<set $activeSlave = GenerateNewSlave("XX")>>
 <<set $activeSlave.origin = "$He sold $himself into slavery to feed $himself and $his growing brood.">>
 <<set $activeSlave.career = "a farm laborer">>
-<<run setHealth($activeSlave, jsRandom(-35, 10))>>
+<<run setHealth($activeSlave, jsRandom(-35, 10), -1, -1, -1, 50)>>
 <<set $activeSlave.devotion = random(35,45)>>
 <<set $activeSlave.trust = random(15,25)>>
 <<set $activeSlave.oldDevotion = $activeSlave.devotion>>
@@ -1694,7 +1694,6 @@
 <<set $activeSlave.lactationDuration = 2>>
 <<set $activeSlave.vaginaLube = 1>>
 <<set $activeSlave.butt = 3>>
-<<set $activeSlave.tired = 1>>
 <<set $activeSlave.sexualQuirk = "caring">>
 <<set $activeSlave.bellySag = 20>>
 <<set $activeSlave.bellySagPreg = 20>>
@@ -1730,7 +1729,6 @@
 <<set $activeSlave.fetishKnown = 0>>
 <<set $activeSlave.vaginaLube = 0>>
 <<set $activeSlave.collar = "shock punishment">>
-<<set $activeSlave.tired = 1>>
 <<set $activeSlave.energy = 0>>
 <<if $activeSlave.actualAge < 13>>
 	<<set $activeSlave.career = "a child soldier">>
diff --git a/src/uncategorized/recETS.tw b/src/uncategorized/recETS.tw
index 05eade3ae4d..69e81460262 100644
--- a/src/uncategorized/recETS.tw
+++ b/src/uncategorized/recETS.tw
@@ -691,7 +691,7 @@
 <<set $activeSlave = GenerateNewSlave("XX")>>
 <<set $activeSlave.origin = "$He begged to be enslaved in a desperate attempt to provide for $his many children.">>
 <<set $activeSlave.career = "homeless">>
-<<run setHealth($activeSlave, jsRandom(-45, -30))>>
+<<run setHealth($activeSlave, jsRandom(-45, -30), -1, -1, -1, 80)>>
 <<set $activeSlave.devotion = random(35,45)>>
 <<set $activeSlave.trust = random(15,25)>>
 <<set $activeSlave.oldDevotion = $activeSlave.devotion>>
@@ -723,7 +723,6 @@
 <<set $activeSlave.hips = 2>>
 <<set $activeSlave.vaginaLube = 1>>
 <<set $activeSlave.butt += 3>>
-<<set $activeSlave.tired = 1>>
 <<set $activeSlave.sexualQuirk = "caring">>
 <<set $activeSlave.bellySag = 20>>
 <<set $activeSlave.bellySagPreg = 20>>
@@ -1288,7 +1287,6 @@
 	<<set $activeSlave.waist = 0>>
 	<<set $activeSlave.vaginaLube = 0>>
 	<<set $activeSlave.butt = 0>>
-	<<set $activeSlave.tired = 1>>
 	<<set $activeSlave.fetish = "none">>
 	<<set $activeSlave.fetishStrength = 0>>
 	<<set $activeSlave.sexualFlaw = "none">>
@@ -1347,7 +1345,6 @@
 	<<set $activeSlave.waist = 0>>
 	<<set $activeSlave.vaginaLube = 0>>
 	<<set $activeSlave.butt = 0>>
-	<<set $activeSlave.tired = 1>>
 	<<set $activeSlave.fetish = "none">>
 	<<set $activeSlave.fetishStrength = 0>>
 	<<set $activeSlave.sexualFlaw = "none">>
diff --git a/src/uncategorized/saServeYourOtherSlaves.tw b/src/uncategorized/saServeYourOtherSlaves.tw
index a9e96f6705d..d53e34e24bb 100644
--- a/src/uncategorized/saServeYourOtherSlaves.tw
+++ b/src/uncategorized/saServeYourOtherSlaves.tw
@@ -64,7 +64,7 @@
 		With $his servicing sisters, $his workload is reasonable and $he isn't overworked.
 	<<elseif _load > .2>>
 		While $he may have support in servicing your stock, $he is overwhelmed by their collective need.
-		<<set $slaves[$i].tired = 1>>
+		<<set $slaves[$i].health.tired += 10>>
 		<<if $slaves[$i].sexualFlaw == "self hating">>
 			With so many other slaves taking advantage of $his body, $his life's purpose of @@.hotpink;being nothing more than a piece of meat@@ has come true.
 			<<set $slaves[$i].devotion += 5>>
@@ -84,7 +84,7 @@
 		<</if>>
 	<<else>>
 		Since <<if $subSlaves == 1>>$he is the only slave<<else>>there are so few other slaves<</if>> servicing your stock, $he is used to the @@.red;point of exhaustion.@@
-		<<set $slaves[$i].tired = 1>>
+		<<set $slaves[$i].health.tired += 30>>
 		<<run healthDamage($slaves[$i], 10)>>
 		<<if $averageDick > 5>>
 			<<if canDoVaginal($slaves[$i]) && $slaves[$i].vagina > 0 && $slaves[$i].vagina < 4>>
@@ -620,6 +620,4 @@ is serving ''$slaves[_dom].slaveName'' this week.
 	<</if>>
 <</if>>
 
-<<set $slaves[$i].tired = 1>> /* why was this applied to the dom slave? Seems like a good way to hinder them. */
-
 <</if>>
-- 
GitLab