From ff0a5f57dd7fa10fa047eccf9609db510c8398f3 Mon Sep 17 00:00:00 2001
From: kopareigns <kopareigns@gmail.com>
Date: Sat, 14 Apr 2018 23:56:21 -0400
Subject: [PATCH] Variable Cleanup

---
 src/uncategorized/BackwardsCompatibility.tw   |  6 ++
 .../freeRangeDairyAssignmentScene.tw          | 56 +++++++++----------
 src/uncategorized/nextWeek.tw                 |  2 +-
 src/uncategorized/randomIndividualEvent.tw    | 19 ++++---
 src/uncategorized/rieEligibilityCheck.tw      |  2 +-
 src/uncategorized/slaveInteract.tw            | 19 ++-----
 src/utility/miscWidgets.tw                    | 16 ------
 7 files changed, 51 insertions(+), 69 deletions(-)

diff --git a/src/uncategorized/BackwardsCompatibility.tw b/src/uncategorized/BackwardsCompatibility.tw
index f795a493043..7efd5afc912 100644
--- a/src/uncategorized/BackwardsCompatibility.tw
+++ b/src/uncategorized/BackwardsCompatibility.tw
@@ -142,6 +142,12 @@
 <<if def $place>>
 	<<unset $place>>
 <</if>>
+<<if def $assayedSlave>>
+	<<unset $assayedSlave>>
+<</if>>
+<<if def $assayedSlaveAvailable>>
+	<<unset $assayedSlaveAvailable>>
+<</if>>
 
 /* pregmod stuff */
 
diff --git a/src/uncategorized/freeRangeDairyAssignmentScene.tw b/src/uncategorized/freeRangeDairyAssignmentScene.tw
index 6280229e0af..89c79df7c7a 100644
--- a/src/uncategorized/freeRangeDairyAssignmentScene.tw
+++ b/src/uncategorized/freeRangeDairyAssignmentScene.tw
@@ -73,60 +73,60 @@ All this lewd display turns $activeSlave.slaveName on and she is almost overcome
 <br><br>
 /* GETTING IN */
 Eventually, $activeSlave.slaveName arrives at her designated milking stall.
-<<set $assayedSlaveAvailable = 0>>
+<<set _assayedSlaveAvailable = 0>>
 <<if $familyTesting == 1>>
 	<<if totalRelatives($activeSlave) > 0>>
 		<<set _relativeCattle = $slaves.filter(function(s) { return (areRelated(s, $activeSlave) && s.assignment == "work in the dairy") ; })>>
 		<<if _relativeCattle.length > 0>>
-			<<set $assayedSlave = _relativeCattle.random()>>
-			<<set $assayedSlaveAvailable = 1>>
-			<<if $activeSlave.mother == $assayedSlave.ID>>
-				<<set $assayType = "mother">>
-			<<elseif $assayedSlave.mother == $activeSlave.ID || $assayedSlave.father == $activeSlave.ID>>
-				<<set $assayType = "daughter">>
-			<<elseif $activeSlave.father == $assayedSlave.ID>>
-				<<set $assayType = "father">>
+			<<set _assayedSlave = _relativeCattle.random()>>
+			<<set _assayedSlaveAvailable = 1>>
+			<<if $activeSlave.mother == _assayedSlave.ID>>
+				<<set _assayType = "mother">>
+			<<elseif _assayedSlave.mother == $activeSlave.ID || _assayedSlave.father == $activeSlave.ID>>
+				<<set _assayType = "daughter">>
+			<<elseif $activeSlave.father == _assayedSlave.ID>>
+				<<set _assayType = "father">>
 			<<else>>
-				<<switch areSisters($activeSlave, $assayedSlave)>>
+				<<switch areSisters($activeSlave, _assayedSlave)>>
 				<<case 1>>
-					<<set $assayType = "twin">>
+					<<set _assayType = "twin">>
 				<<case 2>>
-					<<set $assayType = "sister">>
+					<<set _assayType = "sister">>
 				<<case 3>>
-					<<set $assayType = "half-sister">>
+					<<set _assayType = "half-sister">>
 				<</switch>>
 			<</if>>
 		<</if>>
 	<</if>>
 <<else>>
 	<<if ($activeSlave.relation != 0)>>
-		<<set $assayedSlave = $slaves.find(function(s) { return s.ID == $activeSlave.relationTarget && s.assignment == "work in the dairy" ; })>>
-		<<if def $assayedSlave>>
-			<<set $assayedSlaveAvailable = 1>>
-			<<set $assayType = $activeSlave.relation>>
+		<<set _assayedSlave = getSlave($activeSlave.relationTarget)>>
+		<<if def _assayedSlave && _assayedSlave.assignment == "work in the dairy">>
+			<<set _assayedSlaveAvailable = 1>>
+			<<set _assayType = $activeSlave.relation>>
 		<</if>>
 	<</if>>
 <</if>> /*closes extended family mode */
-<<if $assayedSlaveAvailable == 0 && $activeSlave.relationship > 0>>
-	<<set $assayedSlave = $slaves.find(function(s) { return s.ID == $activeSlave.relationshipTarget && s.assignment == "work in the dairy" ; })>>
-	<<if def $assayedSlave>>
-		<<set $assayedSlaveAvailable = 1>>
+<<if _assayedSlaveAvailable == 0 && $activeSlave.relationship > 0>>
+	<<set _assayedSlave = getSlave($activeSlave.relationshipTarget)>>
+	<<if def _assayedSlave && _assayedSlave.assignment == "work in the dairy">>
+		<<set _assayedSlaveAvailable = 1>>
 		<<switch $activeSlave.relationship>>
 		<<case 1>>
-			<<set $assayType = "friend">>
+			<<set _assayType = "friend">>
 		<<case 2>>
-			<<set $assayType = "best friend">>
+			<<set _assayType = "best friend">>
 		<<case 3>>
-			<<set $assayType = "fuckbuddy">>
+			<<set _assayType = "fuckbuddy">>
 		<<case 4>>
-			<<set $assayType = "lover">>
+			<<set _assayType = "lover">>
 		<<case 5>>
-			<<set $assayType = "slave wife">>
+			<<set _assayType = "slave wife">>
 		<</switch>>
 	<</if>>
 <</if>>
-<<if $assayedSlaveAvailable == 1>>
-    Her $assayType $assayedSlave.slaveName is at the dairy, too. She is in the adjacent stall. The two of them are going to be milked right next to each other.
+<<if _assayedSlaveAvailable == 1>>
+    Her _assayType _assayedSlave.slaveName is at the dairy, too. She is in the adjacent stall. The two of them are going to be milked right next to each other.
 <</if>>
 
 The only "furniture" in the stall looks like a dentist's chair. It looks very medical, but it turns out to be quite comfortable actually. She <<if $activeSlave.devotion >90>>eagerly<<elseif $activeSlave.slaveName < 40>>hesitantly<</if>> gets into the chair.
diff --git a/src/uncategorized/nextWeek.tw b/src/uncategorized/nextWeek.tw
index 7e4394e915a..97edd400cd1 100644
--- a/src/uncategorized/nextWeek.tw
+++ b/src/uncategorized/nextWeek.tw
@@ -252,7 +252,7 @@
 <<set $activeSlave = 0, $eventSlave = 0, $slaveWithoutBonuses = 0, $subSlave = 0, $milfSlave = 0, $milkTap = 0, $relation = 0>>
 
 /% Slave Objects that never get zeroed so null them here. Second most memory eaten up. %/
-<<set $assayedSlave = null, $beforeGingering = null, $recruiterMother = null, $recruiterSister = null, $sibling = null, $recruiterSlave = null>>
+<<set $beforeGingering = null, $recruiterMother = null, $recruiterSister = null, $sibling = null, $recruiterSlave = null>>
 
 /% Slave Object Arrays. These can take up the most memory. %/
 <<set $eligibleSlaves = [], $slavesInLine = []>>
diff --git a/src/uncategorized/randomIndividualEvent.tw b/src/uncategorized/randomIndividualEvent.tw
index 239c04aa9fb..5a5b7f2057c 100644
--- a/src/uncategorized/randomIndividualEvent.tw
+++ b/src/uncategorized/randomIndividualEvent.tw
@@ -2,30 +2,33 @@
 
 <<set $showEncyclopedia = 0>>
 <<if $eventSlave == 0>>
-  <<set $eventSlave = $eligibleSlaves.random()>>
   <<if $cheatMode == 1>>
 	<<set $nextButton = "Refresh", $nextLink = "Random Individual Event", $returnTo = "Random Individual Event">>
 	''One of the following eligible slaves would have been selected for an individual random event:''
 	<br>
 	<<for $i = 0; $i < $eligibleSlaves.length; $i++>>
-		<<if $eligibleSlaves[$i].slaveSurname>>
+		<<capture $i>>
+		<<set $eventSlave = getSlave($eligibleSlaves[$i])>>
+		<<if $eventSlave.slaveSurname>>
 			<<if $surnameOrder != 1>>
-				<<switch $eligibleSlaves[$i].nationality>>
+				<<switch $eventSlave.nationality>>
 					<<case "Cambodian" "Chinese" "Hungarian" "Japanese" "Korean" "Mongolian" "Taiwanese" "Vietnamese">>
-						<<set _slaveName = $eligibleSlaves[$i].slaveSurname + " " + $eligibleSlaves[$i].slaveName>>
+						<<set _slaveName = $eventSlave.slaveSurname + " " + $eventSlave.slaveName>>
 					<<default>>
-						<<set _slaveName = $eligibleSlaves[$i].slaveName + " " + $eligibleSlaves[$i].slaveSurname>>
+						<<set _slaveName = $eventSlave.slaveName + " " + $eventSlave.slaveSurname>>
 				<</switch>>
 			<<else>>
-				<<set _slaveName = $eligibleSlaves[$i].slaveName + " " + $eligibleSlaves[$i].slaveSurname>>
+				<<set _slaveName = $eventSlave.slaveName + " " + $eventSlave.slaveSurname>>
 			<</if>>
 		<<else>>
-			<<set _slaveName = $eligibleSlaves[$i].slaveName>>
+			<<set _slaveName = $eventSlave.slaveName>>
 		<</if>>
-		<br><<print "[[_slaveName|Random Individual Event][$eventSlave = $eligibleSlaves[" + $i + "]]]">>
+		<br><<print "[[_slaveName|Random Individual Event][$eventSlave = getSlave($eligibleSlaves[$i])]]">>
+		<</capture>>
 	<</for>>
 	<br><br>[[Switch to Random Nonindividual Event|Random Nonindividual Event][$activeSlave = 0, $eventSlave = 0]]
   <<else>>
+	<<set $eventSlave = getSlave($eligibleSlaves.random())>>
 	<<goto "Random Individual Event">>
   <</if>>
 <<else>>
diff --git a/src/uncategorized/rieEligibilityCheck.tw b/src/uncategorized/rieEligibilityCheck.tw
index 913acf0a827..b6791290dbb 100644
--- a/src/uncategorized/rieEligibilityCheck.tw
+++ b/src/uncategorized/rieEligibilityCheck.tw
@@ -7,7 +7,7 @@
 <<for $i = 0; $i < $slaves.length; $i++>>
 	<<if $slaves[$i].assignmentVisible == 1 || $slaves[$i].assignment == "serve in the master suite" || $slaves[$i].assignment == "be your Concubine" || $slaves[$i].assignment == "be a servant">>
 	<<if $slaves[$i].fuckdoll == 0>>
-		<<set $eligibleSlaves.push($slaves[$i])>>
+		<<set $eligibleSlaves.push($slaves[$i].ID)>>
 	<</if>>
 	<</if>>
 <</for>>
diff --git a/src/uncategorized/slaveInteract.tw b/src/uncategorized/slaveInteract.tw
index e7037c8f540..766b0d19cc9 100644
--- a/src/uncategorized/slaveInteract.tw
+++ b/src/uncategorized/slaveInteract.tw
@@ -261,13 +261,8 @@
 		*/
 	<<else>>
 		<<if ($activeSlave.relation != 0)>>
-			<<for $i = 0; $i < _SL; $i++>>
-				<<if $slaves[$i].ID == $activeSlave.relationTarget>>
-					<<set $assayedSlave = $slaves[$i]>>
-					<<AssayedSlaveAvailable>>
-				<</if>>
-			<</for>>
-			<<if $assayedSlaveAvailable == 1>>
+			<<set _assayedSlave = getSlave($activeSlave.relationTarget)>>
+			<<if isSlaveAvailable(_assayedSlave)>>
 				<<if ($activeSlave.relation == "mother")>>
 					| <<link "Fuck her with her daughter">><<replace "#miniscene">><<set $partner = "relation">><<include "FRelation">><br>&nbsp;&nbsp;&nbsp;&nbsp;<</replace>><</link>>
 				<<elseif ($activeSlave.relation == "daughter")>>
@@ -278,18 +273,12 @@
 					| <<link "Fuck her with her twin">><<replace "#miniscene">><<set $partner = "relation">><<include "FRelation">><br>&nbsp;&nbsp;&nbsp;&nbsp;<</replace>><</link>>
 				<</if>>
 			<<else>>
-				//$assayedSlave.slaveName is unavailable//
+				//_assayedSlave.slaveName is unavailable//
 			<</if>>
 		<</if>>
 	<</if>>
 	<<if ($activeSlave.relationship > 0)>>
-		<<set _si = $slaves.findIndex(function(s) { return s.ID == $activeSlave.relationshipTarget; })>>
-		<<for _i = 0; _i < _SL; _i++>>
-			<<if $slaves[_i].ID == $activeSlave.relationshipTarget>>
-				<<set $assayedSlave = $slaves[_i]>>
-				<<AssayedSlaveAvailable>>
-			<</if>>
-		<</for>>
+		<<set _si = $slaveIndices[$activeSlave.relationshipTarget]>>
 		<<if isSlaveAvailable($slaves[_si])>>
 			<<if ($activeSlave.relationship == 1)>>
 				| <<link `"Fuck her with her friend <<SlaveFullName $slaves[_si]>>"`>><<replace "#miniscene">><<set $partner = "relationship">><<include "FRelation">><br>&nbsp;&nbsp;&nbsp;&nbsp;<</replace>><</link>>
diff --git a/src/utility/miscWidgets.tw b/src/utility/miscWidgets.tw
index b073b094a0d..ed5c39cc3df 100644
--- a/src/utility/miscWidgets.tw
+++ b/src/utility/miscWidgets.tw
@@ -18,22 +18,6 @@
 	<</replace>>
 <</widget>>
 
-/%
- Call as <<AssayedSlaveAvailable>>
- Checks $assayedSlave for availability, e.g. not strapped to a machine or distant.
-%/
-<<widget "AssayedSlaveAvailable">>
-<<if $assayedSlave.assignment == "be your agent">>
-	<<set $assayedSlaveAvailable = 0>>
-<<elseif $assayedSlave.assignment == "live with your agent">>
-	<<set $assayedSlaveAvailable = 0>>
-<<elseif ($assayedSlave.assignment == "work in the dairy") && ($dairyRestraintsSetting >= 2)>>
-	<<set $assayedSlaveAvailable = 0>>
-<<else>>
-	<<set $assayedSlaveAvailable = 1>>
-<</if>>
-<</widget>>
-
 /%
  Call as <<AnalVCheck 10>> or <<AnalVCheck>>
  $arg[0] is how many times to increment the Anal counts.
-- 
GitLab