From c19100367f4a6b9b3406ec6e3e4d2c834d8fd575 Mon Sep 17 00:00:00 2001 From: Pregmodder <pregmodder@gmail.com> Date: Thu, 22 Feb 2018 17:41:57 -0500 Subject: [PATCH] fixes --- devNotes/VersionChangeLog-Premod+LoliMod.txt | 1 + devNotes/twine JS | 278 +++++++++++++++++++ src/js/wombJS.tw | 2 +- src/npc/acquisition.tw | 3 + src/pregmod/widgets/seBirthWidgets.tw | 1 + src/uncategorized/BackwardsCompatibility.tw | 2 +- src/uncategorized/slaveInteract.tw | 108 +++---- 7 files changed, 339 insertions(+), 56 deletions(-) diff --git a/devNotes/VersionChangeLog-Premod+LoliMod.txt b/devNotes/VersionChangeLog-Premod+LoliMod.txt index 083ce9b0887..04b8beaa85d 100644 --- a/devNotes/VersionChangeLog-Premod+LoliMod.txt +++ b/devNotes/VersionChangeLog-Premod+LoliMod.txt @@ -7,6 +7,7 @@ 364 -sidebar notification when you can start a new FS -pregmodfan's new pregnancy tracking system + -fixes to players being unable to manage HG, BG, rec 2/21/18 diff --git a/devNotes/twine JS b/devNotes/twine JS index fed40467405..03063268906 100644 --- a/devNotes/twine JS +++ b/devNotes/twine JS @@ -6817,6 +6817,284 @@ window.slimPass = function(slave) { return slimPass; } +/*:: wombJS [script]*/ + +/* +This is womb processor/simulator script. It's take care about calculation of belly sizes based on individual foetus sizes, +with full support of broodmothers implant random turning on and off possibility. Also this can be expanded to store more parents data in each individual fetus in future. +Design limitations: +- Mother can't gestate children with different speeds at same time. All speed changes apply to all fetuses. +- Sizes of inividual fetuses updated only on call of WombGetVolume - not every time as called WombProgress. This is for better overail code speed. +- For broodmothers we need actual "new ova release" code now. But it's possible to control how many children will be added each time, and so - how much children is ready to birth each time. + +Usage from sugarcube code (samples): + +WombInit($slave) - before first pregnancy, at slave creation, of as backward compatibility update. + +WombImpregnate($slave, $fetus_count, $fatherID, $initial_age) - should be added after normal impregnation code, with already calcualted fetus count. ID of father - can be used in future for prcess children from different fathers in one pregnancy. Initial age normally 1 (as .preg normally set to 1), but can be raised if needed. Also should be called at time as broodmother implant add another fetus(es), or if new fetuses added from other sources in future (transplanting maybe?) + +WombProgress($slave, $time_to_add_to_fetuses) - after code that update $slave.preg, time to add should be the same. + +$isReady = WombBirthReady($slave, $birth_ready_age) - how many children ready to be birthed if their time to be ready is $birth_ready_age (40 is for normal length pregnancy). Return int - count of ready to birth children, or 0 if no ready exists. + +$children = WombBirth($slave, $birth_ready_age) - for actual birth. Return array with fetuses objects that birthed (can be used in future) and remove them from womb array of $slave. Should be called at actual birth code in sugarcube. fetuses that not ready remained in womb (array). + +WombFlush($slave) - clean womb (array). Can be used at broodmother birthstorm or abortion situations in game. But birthstorm logicaly should use WombBirth($slave, 35) or so before - some children in this event is live capable, others is not. + +$slave.bellyPreg = WombGetWolume($slave) - return double, with current womb volume in CC - for updating $slave.bellyPreg, or if need to update individual fetuses sizes. +*/ + +window.WombInit = function(actor) //Init womb system. +{ + if (!Array.isArray(actor.womb)) + { + //alert("creating new womb"); //debugging + actor.womb = []; + } + + if (actor.womb.length == 0 && actor.pregType != 0 && actor.broodmother == 0) //backward compatibility setup. Fully accurate for normal pregnancy only. + { + WombImpregnate(actor, actor.pregType, actor.pregSource, actor.preg); + } + else if (actor.womb.length == 0 && actor.pregType != 0 && actor.broodmother > 0) //sorry but for already present broodmothers it's impossible to calculate fully, aproximation used. + { + var i, pw = actor.preg, bCount, bLeft; + if (pw > 40) + pw = 40; //to avoid disaster. + bCount = Math.floor(actor.pregType/pw); + bLeft = actor.pregType - (bCount*pw); + if (pw > actor.pregType) + { + pw = actor.pregType // low children count broodmothers not supported here. It's emergency/backward compatibility code, and they not in game anyway. So minimum is 1 fetus in week. + actor.preg = pw; // fixing initial pregnancy week. + } + for (i=0; i<pw; i++) + { + WombImpregnate(actor, bCount, actor.pregSource, i); // setting fetuses for every week, up to 40 week at max. + } + + if (bLeft > 0) + { + WombImpregnate(actor, bLeft, actor.pregSource, i+1); // setting up leftower of fetuses. + } + } +} + +window.WombImpregnate = function(actor, fCount, fatherID, age) +{ + var i; + var tf; + for (i=0; i<fCount; i++) + { + tf = {}; //new Object + tf.age = age; //initial age + tf.fatherID = fatherID; //We can store who is father too. + tf.sex = Math.round(Math.random())+1; // 1 = male, 2 = female. For possible future usage, just as concept now. + tf.volume = 1; //Initial, to create property. Updated with actual data after WombGetVolume call. + + try { + if (actor.womb.length == 0) + { + actor.pregWeek = age; + actor.preg = age; + } + + actor.womb.push(tf); + }catch(err){ + WombInit(actor); + actor.womb.push(tf); + alert("WombImpregnate warning - " + actor.slaveName+" "+err); + } + + } + +} + +window.WombProgress = function(actor, ageToAdd) +{ + var i, ft; + ageToAdd = Math.ceil(ageToAdd*10)/10; + try { + for (i in actor.womb) + { + ft = actor.womb[i]; + ft.age += ageToAdd; + } + }catch(err){ + WombInit(actor); + alert("WombProgress warning - " + actor.slaveName+" "+err); + } +} + +window.WombBirth = function(actor, readyAge) +{ + try{ + actor.womb.sort(function (a, b){return b.age - a.age}); //For normal processing fetuses that more old should be first. Now - they are. + }catch(err){ + WombInit(actor); + alert("WombBirth warning - " + actor.slaveName+" "+err); + } + + var birthed = []; + var ready = WombBirthReady(actor, readyAge); + var i; + + for (i=0; i<ready; i++) //here can't be used "for .. in .." syntax. + { + birthed.push(actor.womb.shift()); + } + + return birthed; +} + +window.WombFlush = function(actor) +{ + actor.womb = []; + +} + +window.WombBirthReady = function(actor, readyAge) +{ + + var i, ft; + var readyCnt = 0; + try { + for (i in actor.womb) + { + ft = actor.womb[i]; + if (ft.age >= readyAge) + readyCnt++; + } + }catch(err){ + WombInit(actor); + alert("WombBirthReady warning - " + actor.slaveName+" "+err); + + return 0; + } + + return readyCnt; +} + +window.WombGetVolume = function(actor) //most code from pregJS.tw with minor adaptation. +{ + var i, ft; + var gestastionWeek; + var phi = 1.618; + var targetLen; + var wombSize = 0; + + try{ + + for (i in actor.womb) + { + ft = actor.womb[i]; + gestastionWeek = ft.age; + + if (gestastionWeek <= 32) + { + targetLen = (0.00006396 * Math.pow(gestastionWeek, 4)) - (0.005501 * Math.pow(gestastionWeek, 3)) + (0.161 * Math.pow(gestastionWeek, 2)) - (0.76 * gestastionWeek) + 0.208; + } + else if (gestastionWeek <= 106) + { + targetLen = (-0.0000004675 * Math.pow(gestastionWeek, 4)) + (0.0001905 * Math.pow(gestastionWeek, 3)) - (0.029 * Math.pow(gestastionWeek, 2)) + (2.132 * gestastionWeek) - 16.575; + } + else + { + targetLen = (-0.00003266 * Math.pow(gestastionWeek,2)) + (0.076 * gestastionWeek) + 43.843; + } + + ft.volume = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((targetLen / 2), 3))); + + wombSize += ft.volume; + } + }catch(err){ + WombInit(actor); + alert("WombGetVolume warning - " + actor.slaveName + " " + err); + } + + if (wombSize < 0) //catch for strange cases, to avoid messing with outside code. + wombSize = 0; + + return wombSize; +} + +window.WombUpdatePregVars = function(actor) { + + actor.womb.sort(function (a, b){return b.age - a.age}); + if (actor.womb.length > 0) + { + if (actor.preg > 0 && actor.womb[0].age > 0) + { + actor.preg = actor.womb[0].age; + } + + actor.pregType = actor.womb.length; + + actor.bellyPreg = WombGetVolume(actor); + + } + +} + +window.WombMinPreg = function(actor) +{ + actor.womb.sort(function (a, b){return b.age - a.age}); + + if (actor.womb.length > 0) + return actor.womb[actor.womb.length-1].age; + else + return 0; +} + +window.WombMaxPreg = function(actor) +{ + actor.womb.sort(function (a, b){return b.age - a.age}); + if (actor.womb.length > 0) + return actor.womb[0].age; + else + return 0; +} + +window.WombNormalizePreg = function(actor) +{ + if (actor.womb.length > 1) + { + var max = WombMaxPreg(actor); + + if (actor.pregWeek < 1 ) + actor.pregWeek = 1 + + if (max < actor.preg) + { + WombProgress(actor, actor.preg - max); + } + else if ( max > actor.preg) + { + actor.preg = max; + } + + actor.pregType = actor.womb.length; + + actor.pregSource = actor.womb[0].fatherID; + + actor.bellyPreg = WombGetVolume(actor); + } + else if (actor.womb.length == 0 && actor.broodmother < 1) + { + actor.pregType = 0; + actor.pregKnown = 0; + + if (actor.preg > 0) + actor.preg = 0; + + if (actor.pregSource > 0) + actor.pregSource = 0; + + if (actor.pregWeek > 0) // We can't properly set postpartum here, but can normalize obvious error with forgotten property. + actor.pregWeek = 0; + } +} + /*:: DTreeJS [script]*/ /* This is the minified version of lodash, d3 and dTree */ ; diff --git a/src/js/wombJS.tw b/src/js/wombJS.tw index 04ec3ae4bad..3297207ea00 100644 --- a/src/js/wombJS.tw +++ b/src/js/wombJS.tw @@ -8,7 +8,7 @@ Design limitations: - Sizes of inividual fetuses updated only on call of WombGetVolume - not every time as called WombProgress. This is for better overail code speed. - For broodmothers we need actual "new ova release" code now. But it's possible to control how many children will be added each time, and so - how much children is ready to birth each time. -Usage form sugarcube code (samples): +Usage from sugarcube code (samples): WombInit($slave) - before first pregnancy, at slave creation, of as backward compatibility update. diff --git a/src/npc/acquisition.tw b/src/npc/acquisition.tw index 6752eb488ed..58b375301b2 100644 --- a/src/npc/acquisition.tw +++ b/src/npc/acquisition.tw @@ -48,6 +48,7 @@ <</if>> <<set $PC.pregKnown = 1>> <<set $PC.belly = getPregBellySize($PC)>> + <<set WombImpregnate($PC, $PC.pregType, $PC.pregSource, $PC.preg)>> <</if>> <</if>> <<set $PC.ovaryAge = $PC.physicalAge>> @@ -252,6 +253,7 @@ The previous owner seems to have left in something of a hurry. <<set $activeSlave.face = random(15,100)>> <<set $activeSlave.preg = random(1,40), $activeSlave.lactation = 1>> <<SetBellySize $activeSlave>> + <<set WombImpregnate($activeSlave, $activeSlave.pregType, $activeSlave.pregSource, $activeSlave.preg)>> <<if $activeSlave.vagina > -1>> <<if $activeSlave.vagina == 0>><<set $activeSlave.vagina++>><</if>> <<set $activeSlave.vaginalSkill = random(15,35)>> @@ -506,6 +508,7 @@ The previous owner seems to have left in something of a hurry. <<set $activeSlave.face = random(15,100)>> <<set $activeSlave.preg = random(10,40), $activeSlave.pregType = random(3,8), $activeSlave.lactation = 1>> <<SetBellySize $activeSlave>> + <<set WombImpregnate($activeSlave, $activeSlave.pregType, $activeSlave.pregSource, $activeSlave.preg)>> <<set $activeSlave.birthsTotal = 5>> <<set $activeSlave.bellySag = 20, $activeSlave.bellySagPreg = 20>> <<if $activeSlave.vagina > -1>> diff --git a/src/pregmod/widgets/seBirthWidgets.tw b/src/pregmod/widgets/seBirthWidgets.tw index 9542199f5a7..3602f767017 100644 --- a/src/pregmod/widgets/seBirthWidgets.tw +++ b/src/pregmod/widgets/seBirthWidgets.tw @@ -1,4 +1,5 @@ :: seBirthWidgets [widget nobr] + <<widget "seBirthPreChek">> <<SlavePronouns $slaves[$i]>> diff --git a/src/uncategorized/BackwardsCompatibility.tw b/src/uncategorized/BackwardsCompatibility.tw index b9ef7c54185..10f3b675fdb 100644 --- a/src/uncategorized/BackwardsCompatibility.tw +++ b/src/uncategorized/BackwardsCompatibility.tw @@ -2276,7 +2276,7 @@ Setting missing slave variables: <<PMODinit _Slave>> -<<set WombInit($PC)>> +<<set WombInit(_Slave)>> <<if ndef _Slave.publicCount>> <<set _Slave.publicCount = 0>> diff --git a/src/uncategorized/slaveInteract.tw b/src/uncategorized/slaveInteract.tw index a92531eaaa7..a3569b50f6e 100644 --- a/src/uncategorized/slaveInteract.tw +++ b/src/uncategorized/slaveInteract.tw @@ -1028,35 +1028,35 @@ Aphrodisiacs: <span id="aphrodisiacs"><strong><<if $activeSlave.aphrodisiacs > 1 <br> <span id="fertilityblock"> <<if $activeSlave.fuckdoll == 0 && ($activeSlave.ovaries == 1 || $activeSlave.mpreg == 1)>> -<<if ($activeSlave.preg < -1)>> - //She is sterile// -<<elseif ($activeSlave.pubertyXX == 0) && $activeSlave.preg < 1>> - //She is not yet fertile// -<<elseif $activeSlave.ovaryAge >= 47 && $activeSlave.preg < 1>> - //She is too old to become pregnant// - <<if $activeSlave.preg == -1>> - <<set $activeSlave.preg = 0>> - <<SetBellySize $activeSlave>> - <</if>> -<<elseif $activeSlave.broodmotherOnHold == 1>> - //Her pregnancy implant is turned off; she expected to be completely emptied of her remaining brood in $activeSlave.broodmotherCountDown week<<if $activeSlave.broodmotherCountDown > 1>>s<</if>>// - [[Turn on implant|Slave Interact][$activeSlave.broodmotherOnHold = 0, $activeSlave.broodmotherCountDown = 0]] -<<elseif $activeSlave.preg >= -1>> -Contraception: <span id="fertility"><strong><<if $activeSlave.preg == -1>><<print "using contraceptives">><<elseif $activeSlave.pregWeek < 0>><<print "postpartum">><<elseif $activeSlave.preg == 0>><<print "fertile">><<elseif $activeSlave.preg < 4>><<print "may be pregnant">><<else>><<print $activeSlave.preg>><<print " weeks pregnant">><</if>></strong></span>. -<<if ($activeSlave.preg == 0)>> - <<link "Use contraceptives">><<set $activeSlave.preg = -1>> - <<SlaveInteractFertility>> - <<SlaveInteractImpreg>> - <</link>> -<<elseif $activeSlave.preg == -1>> - <<link "Let her get pregnant">><<set $activeSlave.preg = 0>> - <<SlaveInteractFertility>> - <<SlaveInteractImpreg>> - <</link>> -<<elseif $activeSlave.induce == 1>> - //Hormones are being slipped into her food, she will give birth suddenly and rapidly this week// -<<elseif ($activeSlave.preg > 38) && ($activeSlave.broodmother == 0) && ($activeSlave.labor == 0)>> - [[Induce labor|Slave Interact][$activeSlave.labor = 1,$activeSlave.induce = 1,$birthee = 1]] + <<if ($activeSlave.preg < -1)>> + //She is sterile// + <<elseif ($activeSlave.pubertyXX == 0) && $activeSlave.preg < 1>> + //She is not yet fertile// + <<elseif $activeSlave.ovaryAge >= 47 && $activeSlave.preg < 1>> + //She is too old to become pregnant// + <<if $activeSlave.preg == -1>> + <<set $activeSlave.preg = 0>> + <<SetBellySize $activeSlave>> + <</if>> + <<elseif $activeSlave.broodmotherOnHold == 1>> + //Her pregnancy implant is turned off; she expected to be completely emptied of her remaining brood in $activeSlave.broodmotherCountDown week<<if $activeSlave.broodmotherCountDown > 1>>s<</if>>// + [[Turn on implant|Slave Interact][$activeSlave.broodmotherOnHold = 0, $activeSlave.broodmotherCountDown = 0]] + <<elseif $activeSlave.preg >= -1>> + Contraception: <span id="fertility"><strong><<if $activeSlave.preg == -1>><<print "using contraceptives">><<elseif $activeSlave.pregWeek < 0>><<print "postpartum">><<elseif $activeSlave.preg == 0>><<print "fertile">><<elseif $activeSlave.preg < 4>><<print "may be pregnant">><<else>><<print $activeSlave.preg>><<print " weeks pregnant">><</if>></strong></span>. + <<if ($activeSlave.preg == 0)>> + <<link "Use contraceptives">><<set $activeSlave.preg = -1>> + <<SlaveInteractFertility>> + <<SlaveInteractImpreg>> + <</link>> + <<elseif $activeSlave.preg == -1>> + <<link "Let her get pregnant">><<set $activeSlave.preg = 0>> + <<SlaveInteractFertility>> + <<SlaveInteractImpreg>> + <</link>> + <<elseif $activeSlave.induce == 1>> + //Hormones are being slipped into her food, she will give birth suddenly and rapidly this week// + <<elseif ($activeSlave.preg > 38) && ($activeSlave.broodmother == 0) && ($activeSlave.labor == 0)>> + [[Induce labor|Slave Interact][$activeSlave.labor = 1,$activeSlave.induce = 1,$birthee = 1]] | [[Give her a cesarean section|csec]] <<elseif ($activeSlave.broodmother > 0)>> <<if $activeSlave.broodmotherOnHold != 1>> @@ -1068,35 +1068,35 @@ Contraception: <span id="fertility"><strong><<if $activeSlave.preg == -1>><<prin <<elseif ($activeSlave.preg > 35)>> [[Give her a cesarean section|csec]] <<elseif ($activeSlave.preg > 0) && $activeSlave.breedingMark == 1 && $activeSlave.pregSource == -1>> - //You are forbidden from aborting an elite child// + //You are forbidden from aborting an elite child// <<elseif ($activeSlave.preg > 0)>> - [[Abort her pregnancy|Abort]] -<</if>> -<</if>> -<<elseif ($activeSlave.ovaries == 1 || $activeSlave.mpreg == 1)>> -<<if ($activeSlave.preg < -1)>> - //It is sterile// -<<elseif ($activeSlave.pubertyXX == 0)>> - //It is not yet fertile// -<<elseif $activeSlave.ovaryAge >= 47 && $activeSlave.preg < 1>> - //It is too old to become pregnant// - <<if $activeSlave.preg == -1>> - <<set $activeSlave.preg = 0>> - <<SetBellySize $activeSlave>> + [[Abort her pregnancy|Abort]] + <</if>> <</if>> +<<elseif ($activeSlave.ovaries == 1 || $activeSlave.mpreg == 1)>> + <<if ($activeSlave.preg < -1)>> + //It is sterile// + <<elseif ($activeSlave.pubertyXX == 0)>> + //It is not yet fertile// + <<elseif $activeSlave.ovaryAge >= 47 && $activeSlave.preg < 1>> + //It is too old to become pregnant// + <<if $activeSlave.preg == -1>> + <<set $activeSlave.preg = 0>> + <<SetBellySize $activeSlave>> + <</if>> <<elseif $activeSlave.broodmotherOnHold == 1>> //Its pregnancy implant is turned off; it expected to be completely emptied of its remaining brood in $activeSlave.broodmotherCountDown week<<if $activeSlave.broodmotherCountDown > 1>>s<</if>>// [[Turn on implant|Slave Interact][$activeSlave.broodmotherOnHold = 0, $activeSlave.broodmotherCountDown = 0]] -<<elseif ($activeSlave.preg >= -1)>> -__Contraception__: <span id="fertility"><strong><<if $activeSlave.preg == -1>><<print "using contraceptives">><<elseif $activeSlave.pregWeek < 0>><<print "postpartum">><<elseif $activeSlave.preg == 0>><<print "fertile">><<elseif $activeSlave.preg < 4>><<print "may be pregnant">><<else>><<print $activeSlave.preg>><<print " weeks pregnant">><</if>></strong></span>. -<<if ($activeSlave.preg == 0)>> - <<link "Use contraceptives">><<set $activeSlave.preg = -1>> - <<SlaveInteractFertility>> - <</link>> -<<elseif ($activeSlave.preg == -1)>> + <<elseif ($activeSlave.preg >= -1)>> + __Contraception__: <span id="fertility"><strong><<if $activeSlave.preg == -1>><<print "using contraceptives">><<elseif $activeSlave.pregWeek < 0>><<print "postpartum">><<elseif $activeSlave.preg == 0>><<print "fertile">><<elseif $activeSlave.preg < 4>><<print "may be pregnant">><<else>><<print $activeSlave.preg>><<print " weeks pregnant">><</if>></strong></span>. + <<if ($activeSlave.preg == 0)>> + <<link "Use contraceptives">><<set $activeSlave.preg = -1>> + <<SlaveInteractFertility>> + <</link>> + <<elseif ($activeSlave.preg == -1)>> <<link "Let it get pregnant">><<set $activeSlave.preg = 0>> - <<SlaveInteractFertility>> - <</link>> + <<SlaveInteractFertility>> + <</link>> <<elseif $activeSlave.induce == 1>> //Hormones are being slipped into its food, it will give birth suddenly and rapidly this week// <<elseif ($activeSlave.preg > 38) && ($activeSlave.broodmother == 0) && ($activeSlave.labor == 0)>> @@ -1115,8 +1115,8 @@ __Contraception__: <span id="fertility"><strong><<if $activeSlave.preg == -1>><< //You are forbidden from aborting an elite child// <<elseif ($activeSlave.preg > 0)>> [[Abort its pregnancy|Abort]] -<</if>> -<</if>> + <</if>> + <</if>> <</if>> <<if ($activeSlave.pregKnown == 1) && ($pregSpeedControl == 1) && ($activeSlave.breedingMark != 1) && ($activeSlave.indentureRestrictions < 1) && ($activeSlave.broodmother == 0) && $seePreg != 0>> <br> -- GitLab