From 52f6e7450ded3d26ea2c151a04e5fb0dd76068dd Mon Sep 17 00:00:00 2001
From: pregmodfan <pregmodfan@cock.li>
Date: Sat, 10 Mar 2018 21:07:29 +0200
Subject: [PATCH] removeActiveSlave will now correctly clean another slaves
 fetuses father ID's

---
 slave variables documentation - Pregmod.txt |  7 ++++++-
 src/js/wombJS.tw                            | 14 ++++++++++++++
 src/npc/removeActiveSlave.tw                |  4 +---
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/slave variables documentation - Pregmod.txt b/slave variables documentation - Pregmod.txt
index 832a076880c..bb33da51189 100644
--- a/slave variables documentation - Pregmod.txt	
+++ b/slave variables documentation - Pregmod.txt	
@@ -2748,4 +2748,9 @@ WombUpdatePregVars($activeSlave) - automaticaly update $activeSlave.preg, $activ
 
 WombNormalizePreg($activeSlave) - automatialy correct all pregnancy related properties of given $activeSlave. Also it advance pregnancy if detected old .preg++ method used on slave and womb simulation is late. Can be called at any time without conditions checks - function do all needed checks by itself. Call of this function do NOT advance pregnancy by itself.
 
-P.S. All this womb system can be much more automated (.preg .pregType .pregSource .pregWeek may have to be done in a way, that they will have no need to be controlled manually anywhere at all. Just will be set fully automatially). But in this case many changes in present game code needed, to REMOVE legacy code.
+WombZeroID($activeSlave, _SlaveID) - automaticaly scan all fetuses and if their father ID matched - it will be replaced with zero. After it actor pregnancy related variables (like .pregSource) will be updated. Used mainly in process of removing slaves from game, to clean father's ID of unborn children of remaining slaves.
+
+All this womb system can be much more automated (.preg .pregType .pregSource .pregWeek may have to be done in a way, that they will have no need to be controlled manually anywhere at all. Just will be set fully automatially). But in this case many changes in present game code needed, to REMOVE legacy code.
+Right now they are set correctly, based on state of .womb object through pregnancy, but not outside. Also old style pregnancy initiation (setting only .preg to >0 and .pregType to >=1 ) working too - WombImpregnantion function for proper setup of .womb will be called on next SetBellySize call. Also old style pregnancy progression through using .preg++ is supported too, but can have minor issues with character descriptions in some cases, if SetBellySize widget not called before descriptions widgets.
+
+
diff --git a/src/js/wombJS.tw b/src/js/wombJS.tw
index 1ee59242690..7e357a75153 100644
--- a/src/js/wombJS.tw
+++ b/src/js/wombJS.tw
@@ -290,3 +290,17 @@ window.WombNormalizePreg = function(actor)
 
     actor.bellyPreg = WombGetVolume(actor);
 }
+
+window.WombZeroID = function(actor, id)
+{
+    WombInit(actor);
+    var i, ft;
+    for (i in actor.womb)
+    {
+        ft = actor.womb[i];
+        if (ft.fatherID == id)
+            ft.fatherID = 0;
+    }
+
+    WombNormalizePreg(actor);
+}
diff --git a/src/npc/removeActiveSlave.tw b/src/npc/removeActiveSlave.tw
index 91ed24b3beb..e232fd9798a 100644
--- a/src/npc/removeActiveSlave.tw
+++ b/src/npc/removeActiveSlave.tw
@@ -41,9 +41,7 @@
 		<</for>>
 	<</if>>
 	<<for _y = 0; _y < _SL; _y++>>
-		<<if _ID == $slaves[_y].pregSource>>
-			<<set $slaves[_y].pregSource = 0>>
-		<</if>>
+		<<set WombZeroID($slaves[_y], _ID)>> /* This check is complex, should be done in JS now, all needed will be done here. */
 		<<if $activeSlave.daughters > 0>>
 			<<if $slaves[_y].mother == _ID>>
 				<<set $slaves[_y].mother = $missingParentID>>
-- 
GitLab