From 6461c3df098ab451991641a17d855dcf811e5957 Mon Sep 17 00:00:00 2001
From: pregmodfan <pregmodfan@cock.li>
Date: Tue, 20 Feb 2018 01:29:59 +0200
Subject: [PATCH] many improvement and fixes to birth start detection mainly

---
 src/pregmod/widgets/seBirthWidgets.tw       | 58 ++++++++++++++-------
 src/uncategorized/nextWeek.tw               |  4 +-
 src/uncategorized/saDrugs.tw                |  6 +--
 src/uncategorized/saLongTermEffects.tw      | 27 ++++++----
 src/uncategorized/seBirth.tw                |  2 +-
 src/uncategorized/slaveAssignmentsReport.tw |  4 ++
 6 files changed, 64 insertions(+), 37 deletions(-)

diff --git a/src/pregmod/widgets/seBirthWidgets.tw b/src/pregmod/widgets/seBirthWidgets.tw
index 4f32a3e1010..d383f16a1a1 100644
--- a/src/pregmod/widgets/seBirthWidgets.tw
+++ b/src/pregmod/widgets/seBirthWidgets.tw
@@ -284,6 +284,7 @@
 <<set $slaves[$i].curStillBirth = 0 >>
 
 <<set _curBabies = $slaves[$i].curBabies.length>> /*just to improve speed and usability here.*/
+/*<br>TEST curBabies:  _curBabies<br>*/
 
 <<set $slaves[$i].births += _curBabies>>
 <<set $slaves[$i].birthsTotal += _curBabies>>
@@ -330,7 +331,10 @@ This decriptions can be expanded with more outcomes later. But it's not practica
 */
 <<if $slaves[$i].assignment == "work in the dairy" && $dairyPregSetting > 0>> 
 	As a human cow, $pronoun @@.orange;gave birth@@<<if $diffSize < 1.15>> but $possessive overfilled womb barely lost any size. $possessiveCap body gave life <<elseif $diffSize < 1.3>> but $possessive stomach barely shrank at all. $possessiveCap body gave life <</if>>
-	<<if _curBabies <= 1>>
+
+	<<if _curBabies < 1>>
+		no live ones, but a stilbirth only.
+	<<elseif _curBabies == 1>>
 		to a single calf
 	<<elseif _curBabies >= 40>>
 		to a massive brood of _curBabies calves
@@ -371,7 +375,10 @@ This decriptions can be expanded with more outcomes later. But it's not practica
 	<<else>>	
 		$pronounCap @@.orange;gave birth@@<<if $diffSize < 1.15>>, but $possessive stomach barely shrank at all. $possessiveCap body gave life to <<elseif $diffSize < 1.3>>, but $possessive overfilled womb barely lost any size. $possessiveCap body gave life to <</if>>
 	<</if>>
-	<<if _curBabies <= 1>>
+	
+	<<if _curBabies < 1>>
+		no live ones, but a stilbirth only.
+	<<elseif _curBabies == 1>>
 		a single baby.
 	<<elseif _curBabies >= 40>>
 		a massive brood of _curBabies babies.
@@ -398,20 +405,22 @@ This decriptions can be expanded with more outcomes later. But it's not practica
 	<</if>>
 
 	Created by
-	<<if $slaves[$i].pregSource == -1>>
-		your magnificent dick,
-	<<elseif $slaves[$i].pregSource == -2>>
-		your arcology's eager citizens,
-	<<elseif $slaves[$i].pregSource == -3>>
-		the Societal Elite,
-	<<elseif $slaves[$i].pregSource == 0>>
-		an unknown father,
-	<<elseif $slaves[$i].ID == $daddy.ID>>
-		$possessive own curiosity over if $pronoun could fuck <<print $possessive>>self,
-	<<else>>
-		$daddy's virile cock and balls,
+	<<if _curBabies > 1>>
+		<<if $slaves[$i].pregSource == -1>>
+			your magnificent dick,
+		<<elseif $slaves[$i].pregSource == -2>>
+			your arcology's eager citizens,
+		<<elseif $slaves[$i].pregSource == -3>>
+			the Societal Elite,
+		<<elseif $slaves[$i].pregSource == 0>>
+			an unknown father,
+		<<elseif $slaves[$i].ID == $daddy.ID>>
+			$possessive own curiosity over if $pronoun could fuck <<print $possessive>>self,
+		<<else>>
+			$daddy's virile cock and balls,
+		<</if>>
+		<<if _curBabies > 1>>they<<else>>she<</if>> entered the world.
 	<</if>>
-	<<if _curBabies > 1>>they<<else>>she<</if>> entered the world.
 <</if>>
 
 /* ---- Postbirth reactions, body -------------------------------------------------------------------------------------------*/
@@ -738,19 +747,29 @@ All in all,
 		<<set _lostBabies = 1>>
 		Without time loss $possessive child<<if _curBabies > 1>>ren<</if>> collected by the Societal Elite to be raised into upstanding members of the new society.
 	<<elseif $Cash4Babies == 1>>
-		<<set _lostBabies = 1>>
+		/*<<set _lostBabies = 1>>*/
 		<<set _babyCost = random(-12,12)>>
 		<<if ($slaves[$i].relationship == -3)>>
 			You make sure $possessive children are cared for, since $pronoun is your wife. $slaves[$i].slaveName is @@.hotpink;touched@@ by this @@.mediumaquamarine;act of kindness.@@
 			<<set $slaves[$i].trust += 3, $slaves[$i].devotion += 3>>
-			<<set _lostBabies = 0>>
+			<<set _lostBabies = 1>>
 		<<elseif ($slaves[$i].assignment == "serve in the master suite" || $slaves[$i].assignment == "be your Concubine")>>
 			$possessiveCap children are guaranteed to be treated well despite the laws you've passed since $pronoun is a member of your harem. $slaves[$i].slaveName is @@.hotpink;touched@@ by this @@.mediumaquamarine;act of kindness.@@
 			<<set $slaves[$i].trust += 3, $slaves[$i].devotion += 3>>
-			<<set _lostBabies = 0>>
+			<<set _lostBabies = 1>>
+		
 		<<else>>
+		/*
+		<<link 'Just sell them'>> 
+				<<replace `"#" + $dispositionId`>>
+					<<set _babyCost = random(-12,12)>>
+					$possessiveCap <<if _count > 1>>babies<<else>>baby<</if>> sold for a total of @@.yellowgreen;<<print cashFormat(_count*(50+_babyCost))>>.@@
+					<<set $cash += _curBabies*(50+_babyCost)>>
+				<</replace>>
+			<</link>> | 
 			$possessiveCap <<if _curBabies > 1>>babies<<else>>baby<</if>> sold for a total of @@.yellowgreen;<<print cashFormat(_curBabies*(50+_babyCost))>>.@@
 			<<set $cash += _curBabies*(50+_babyCost)>>
+		*/
 		<</if>>
 	<</if>>
 	<<if _lostBabies != 1>>
@@ -825,8 +844,7 @@ All in all,
 		<</link>> 
 		//Will cost <<print cashFormat(500)>> weekly//
 		<<if $Cash4Babies == 1>>
-			<br><br>
-			<<link 'Just sell them'>>
+			| <<link 'Just sell them'>>
 				<<replace `"#" + $dispositionId`>>
 					<<set _babyCost = random(-12,12)>>
 					$possessiveCap <<if _count > 1>>babies<<else>>baby<</if>> sold for a total of @@.yellowgreen;<<print cashFormat(_count*(50+_babyCost))>>.@@
diff --git a/src/uncategorized/nextWeek.tw b/src/uncategorized/nextWeek.tw
index dfa43ff31c4..56eb99a1751 100644
--- a/src/uncategorized/nextWeek.tw
+++ b/src/uncategorized/nextWeek.tw
@@ -114,9 +114,9 @@
 	<<set $HeadGirl = $slaves[_NewHG], $slaves[_NewHG].assignment = "be your Head Girl", $slaves[_NewHG].diet = "healthy">>
 <</if>>
 
-<<if $PC.preg >= 38 && random(1,100) > 50>>
+<<if WombBirthReady($PC, 38) > 0 && random(1,100) > 50>>
 	<<set $PC.labor = 1>>
-<<elseif $PC.preg >= 43>>
+<<elseif WombBirthReady($PC, 43) > 0>>
 	<<set $PC.labor = 1>>
 <</if>>
 
diff --git a/src/uncategorized/saDrugs.tw b/src/uncategorized/saDrugs.tw
index 63ace2b8fba..937769dc1ad 100644
--- a/src/uncategorized/saDrugs.tw
+++ b/src/uncategorized/saDrugs.tw
@@ -993,16 +993,16 @@
 	<</if>>
 <<case "labor supressors">>
 	<<set $slaves[$i].chem += 2>>
- 	<<if $slaves[$i].preg > 60>>
+ 	<<if WombBirthReady($slaves[$i], 60) > 0>>
 		<<set $slaves[$i].health -= 20>>
 		<<set $slaves[$i].labor = 1>>
 		<<set $slaves[$i].induce = 1>>
 		<<set $birthee = 1>>
 		$pronounCap has been ready to give birth for some time now. Supressing birth for so long @@.red;greatly affects $possessive health.@@ $pronounCap may @@.red;have trouble@@ giving birth to $possessive oversized child<<if $slaves[$i].pregType > 1>>ren<</if>>. $pronounCap seems to be in distress, $possessive body is @@.red;forcing $possessive child<<if $slaves[$i].pregType > 1>>ren<</if>> out!@@
- 	<<elseif $slaves[$i].preg > 50>>
+ 	<<elseif WombBirthReady($slaves[$i], 50) > 0>>
 		<<set $slaves[$i].health -= 20>>
 		$pronounCap has been ready to give birth for some time now. Supressing birth for so long @@.red;greatly affects $possessive health.@@ $pronounCap may @@.red;have trouble@@ giving birth to $possessive oversized child<<if $slaves[$i].pregType > 1>>ren<</if>>.
-	<<elseif $slaves[$i].preg > 40>>
+	<<elseif WombBirthReady($slaves[$i], 40) > 0>>
 		<<set $slaves[$i].health -= 10>>
 		Labor suppressing agents @@.red;negatively affect $possessive health.@@
 	<</if>>
diff --git a/src/uncategorized/saLongTermEffects.tw b/src/uncategorized/saLongTermEffects.tw
index d71dc634d5f..2229959a4ea 100644
--- a/src/uncategorized/saLongTermEffects.tw
+++ b/src/uncategorized/saLongTermEffects.tw
@@ -7291,6 +7291,7 @@
 			<<set $slaves[$i].pregSource = 0>>
 			<<set $slaves[$i].pregWeek = 0>>
 			<<set $slaves[$i].pregKnown = 0>>
+			<<set WombFlush($slaves[$i])>>
 			<<SetBellySize $slaves[$i]>>
 			<<set $cash -= 100000>>
 			<<set $failedElite += 150>>
@@ -7304,17 +7305,21 @@
 	<</if>>
 <</if>>
 
-<<if ($slaves[$i].preg > 37) && ($slaves[$i].broodmother == 0) && (random(1,100) > 90) && $slaves[$i].pregControl != "labor supressors">>
-	<<set $slaves[$i].labor = 1>>
-	<<set $birthee = 1>>
-<<elseif ($slaves[$i].preg > 41) && ($slaves[$i].broodmother == 0) && $slaves[$i].pregControl != "labor supressors">>
-	<<set $slaves[$i].labor = 1>>
-	<<set $birthee = 1>>
-<<elseif ($slaves[$i].preg > 37) && ($slaves[$i].broodmother > 0) && ($slaves[$i].assignment != "labor in the production line")>>
-	<<set $slaves[$i].labor = 1>>
-	<<set $birthee = 1>>
-	<<if $slaves[$i].ovaryAge >= 47>>
-		<<set $slaves[$i].broodmotherCountDown = 37>>
+/*--------------- main labor triggers: -------- */
+
+<<if $slaves[$i].pregControl != "labor supressors" && $slaves[$i].assignment != "labor in the production line">>
+	<<if $slaves[$i].broodmother < 1>>
+		<<if WombBirthReady($slaves[$i], 43) > 0>> /*check for really ready fetuses - 43 weeks - max, overdue*/
+			<<set $slaves[$i].labor = 1, $birthee = 1>>
+		<<elseif WombBirthReady($slaves[$i], 40) > 0 && (random(1,100) > 50)>> /*check for really ready fetuses - 40 weeks - normal*/
+			<<set $slaves[$i].labor = 1, $birthee = 1>>
+		<<elseif WombBirthReady($slaves[$i], 36) > 0 && (random(1,100) > 90)>> /*check for really ready fetuses - 36 weeks minimum */
+			<<set $slaves[$i].labor = 1, $birthee = 1>>
+		<</if>>
+	<<else>> 
+		<<if WombBirthReady($slaves[$i], 37)>> /* broodmothers ready at 37 week always */
+			<<set $slaves[$i].labor = 1, $birthee = 1>>
+		<</if>>
 	<</if>>
 <</if>>
 
diff --git a/src/uncategorized/seBirth.tw b/src/uncategorized/seBirth.tw
index 086a518537a..f48e8fe31f4 100644
--- a/src/uncategorized/seBirth.tw
+++ b/src/uncategorized/seBirth.tw
@@ -24,7 +24,7 @@ I need to break single passage to several widgets, as it's been overcomplicated
 <<for $i to 0; $i < $slaves.length; $i++>>
 	<<if $slaves[$i].labor == 1>>
 		<<set $dispositionId = _.uniqueId('babyDisposition-')>>
-		Birth report: @@.coral;$slaves[$i].slaveName $slaves[$i].slaveSurname@@
+		Birth report: @@.coral;$slaves[$i].slaveName <<if $slaves[$i].slaveSurname != 0>>$slaves[$i].slaveSurname<</if>>@@
 		<br>
 		<<seBirthPreChek>>
 
diff --git a/src/uncategorized/slaveAssignmentsReport.tw b/src/uncategorized/slaveAssignmentsReport.tw
index 3791aaa698f..7f6548ddb54 100644
--- a/src/uncategorized/slaveAssignmentsReport.tw
+++ b/src/uncategorized/slaveAssignmentsReport.tw
@@ -334,6 +334,10 @@
 			/*one or more fetuses in one week*/
 			<<set WombImpregnate($slaves[$i], Math.floor($slaves[$i].broodmotherFetuses), $slaves[$i].pregSource, 0)>> /* really 0, it's will be advanced right few lines down.*/
 		<</if>>
+		<<if $slaves[$i].ovaryAge >= 47>>
+			<<set $slaves[$i].broodmotherOnHold = 1 >>
+			<<set $slaves[$i].broodmotherCountDown = 38-$slaves[$i].womb[$slaves[$i].womb.length-1].age>>
+		<</if>>
 	<</if>>
 
 	<<set WombProgress($slaves[$i], _pregSpeed)>>
-- 
GitLab