From 60987c0a403b7ecc1d4a96b47309aa7be1652bc5 Mon Sep 17 00:00:00 2001
From: Vasileios Pasialiokis <whiterocket@outlook.com>
Date: Thu, 12 Apr 2018 15:13:02 +0300
Subject: [PATCH] redo reverted changes

---
 src/init/storyInit.tw        | 3 ++-
 src/npc/removeActiveSlave.tw | 2 +-
 src/utility/miscWidgets.tw   | 6 +++---
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/init/storyInit.tw b/src/init/storyInit.tw
index 826336b85b7..d32802dc7fc 100644
--- a/src/init/storyInit.tw
+++ b/src/init/storyInit.tw
@@ -70,7 +70,7 @@ You should have received a copy of the GNU General Public License along with thi
 		<</if>>
 		<<set $slaves[_i].rivalry = 0, $slaves[_i].rivalryTarget = 0, $slaves[_i].subTarget = 0>>
 	<<else>>
-		<<set _dump = $slaves.deleteAt(_i), _i--, _SL-->>
+		<<set _dump = removeSlave(_i), _i--, _SL-->>
 	<</if>>
 	<</for>>
 	<<for _k = 0; _k < _SL; _k++>>
@@ -240,6 +240,7 @@ You should have received a copy of the GNU General Public License along with thi
 	<<set $genePool = []>>
 <</if>>
 
+<<set $slaveIndices = slaves2indices()>>
 <<set $organs = []>>
 <<set $ArcadeiIDs = [], $BrothiIDs = [], $CellBiIDs = [], $CliniciIDs = [], $ClubiIDs = [], $DairyiIDs = [], $HGSuiteiIDs = [], $MastSiIDs = [], $SchlRiIDs = [], $ServQiIDs = [], $SpaiIDs = [], $FacSupIDs = []>>
 
diff --git a/src/npc/removeActiveSlave.tw b/src/npc/removeActiveSlave.tw
index c7e2ee0387c..cf8ee8ab434 100644
--- a/src/npc/removeActiveSlave.tw
+++ b/src/npc/removeActiveSlave.tw
@@ -143,7 +143,7 @@
 		<<set $limbs.deleteAt(_o)>>
 	<</if>>
 	
-	<<set _dump = $slaves.deleteAt(_x), _SL--, $activeSlave = 0>>
+	<<set _dump = removeSlave(_x), _SL--, $activeSlave = 0>>
 	
 	<<if _missingID == 1>>
 		<<set $missingParentID-->>
diff --git a/src/utility/miscWidgets.tw b/src/utility/miscWidgets.tw
index 4d6a56df854..b073b094a0d 100644
--- a/src/utility/miscWidgets.tw
+++ b/src/utility/miscWidgets.tw
@@ -1737,7 +1737,7 @@
 	<<set $REReductionCheckinIDs.push($args[0].ID)>>
 <</if>>
 
-<<set $slaves.push($args[0])>>
+<<run addSlave($args[0])>>
 <<if $args[0].origin != "She was your slave, but you freed her, which she repaid by participating in a coup attempt against you. It failed, and she is again your chattel.">>
 	<<set $genePool.push($args[0])>>
 <<else>>
@@ -2059,9 +2059,9 @@ This experience
 			<<set $args[0] = $args[0].sort(function(a, b){return b.devotion-a.devotion})>>
 		<</if>>
 	<</switch>>
+	<<set $slaveIndices = slaves2indices()>>
 <<else>>
-	<<set $slaveIndices = {}>>
-	<<set $slaves.forEach(function(s, i) { $slaveIndices[s.ID] = i; })>>
+	<<set $slaveIndices = slaves2indices()>>
 	<<set filterInPlace($args[0], function(s) { return $slaveIndices[s] !== undefined; })>>
 	<<set $args[0].sort(function(a, b) { return $slaveIndices[a] - $slaveIndices[b]; })>>
 <</if>>
-- 
GitLab