From ce23c0c87d83dd4dd5470c3be9ab402034259635 Mon Sep 17 00:00:00 2001
From: pregmodfan <pregmodfan@cock.li>
Date: Tue, 3 Apr 2018 22:50:45 +0300
Subject: [PATCH] fix for counting of reserved for incubator children

---
 src/js/pregJS.tw                      | 9 +++++++++
 src/pregmod/widgets/seBirthWidgets.tw | 4 +---
 src/uncategorized/seBirth.tw          | 2 ++
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/js/pregJS.tw b/src/js/pregJS.tw
index cae3d56e2bc..83990994dcc 100644
--- a/src/js/pregJS.tw
+++ b/src/js/pregJS.tw
@@ -139,4 +139,13 @@ window.setPregType = function(actor) {
 		}
 	}
 	return ovum;
+}
+
+window.getIncubatorReserved = function(slaves) {
+	var count = 0;
+	slaves.forEach(function(s){
+		if (s.reservedChildren > 0)
+			count += s.reservedChildren;
+		});
+	return count;
 }
\ No newline at end of file
diff --git a/src/pregmod/widgets/seBirthWidgets.tw b/src/pregmod/widgets/seBirthWidgets.tw
index c9cb9ea45d0..c30a052887b 100644
--- a/src/pregmod/widgets/seBirthWidgets.tw
+++ b/src/pregmod/widgets/seBirthWidgets.tw
@@ -755,7 +755,7 @@ All in all,
 <<if _origReserve > 0 && _curBabies > 0>> /*Do we need incubator checks?*/
 	<<if _curBabies >= _origReserve>>
 		/*adding normal*/
-		<<set _cToIncub = _origReserve>>
+		<<set _cToIncub = _origReserve, $slaves[$i].reservedChildren = 0>>
 	<<elseif _curBabies <  _origReserve && $slaves[$i].womb.length > 0>>
 		/*broodmother or partial birth, we will wait for next time to get remaining children*/
 		<<set $slaves[$i].reservedChildren -= _curBabies, _cToIncub = _curBabies>>
@@ -763,7 +763,6 @@ All in all,
 		/*Stillbirth or something other go wrong. Correcting children count.*/
 		<<set $slaves[$i].reservedChildren = 0, _cToIncub = _curBabies>>
 	<</if>>
-
 	<<set $mom = $slaves[$i]>>
 	<br><br>
 	Of $possessive _curBabies child<<if $slaves[$i].pregType > 1>>ren<</if>>; _cToIncub <<if $slaves[$i].reservedChildren > 1>>were<<else>>was<</if>> taken to $incubatorName.
@@ -772,7 +771,6 @@ All in all,
 		<<include "Incubator Workaround">>
 		<<set $slaves[$i].curBabies.shift()>> /*for now child generation metod for incubator not changed. But here children for incubator removed from array of birthed babies. If we decide later - we can use them for incubator as real objects here. For now they just discarded silently */
 	<</for>>
-	<<set $reservedChildren -= _cToIncub>>
 	<<set _curBabies = $slaves[$i].curBabies.length>>
 	<br><br>
 	<<if _curBabies > 0>>
diff --git a/src/uncategorized/seBirth.tw b/src/uncategorized/seBirth.tw
index dc783e56ed3..6a7b7216bf2 100644
--- a/src/uncategorized/seBirth.tw
+++ b/src/uncategorized/seBirth.tw
@@ -51,5 +51,7 @@ I need to break single passage to several widgets, as it's been overcomplicated
 	<</if>>
 <</for>>
 
+<<set $reservedChildren = getIncubatorReserved($slaves)>>
+
 <<set $birthee = 0>>
 <<set $birthed = 0>>
-- 
GitLab