diff --git a/src/js/pregJS.js b/src/js/pregJS.js index c6d3a9a01acb6d4144f5de57eeca7cc7c110d68f..c7e0f29bc83fbe67bea9783ec1709da3ec98e161 100644 --- a/src/js/pregJS.js +++ b/src/js/pregJS.js @@ -381,10 +381,27 @@ window.setPregType = function(actor) { } } } + if (actor.geneticQuirks.superfetation === 2 && actor.womb.length > 0) { - ovum = Math.ceil(ovum / 4); + let ftvol = FetusGetPrediction(actor, actor.pregData.normalBirth); + let cmvol = ftvol * actor.womb.length; + let maxvol = actor.pregAdaptation*2000; + if (State.variables.seeHyperPreg == 0) + maxvol /= 10; //without hyperpreg enabled it's limited to be roughly ten times smaller. + let freevol = maxvol - cmvol; + let coeff = ((maxvol/actor.womb.length) / (freevol/ftvol)) / 2; // more divide to 2 is to balance for ensured 1 ova even if overlimit. + //console.log("ftvol:", ftvol, " cmvol:", cmvol, " maxvol:", maxvol, " freevol:", freevol, " coeff:", coeff); + if (ovum > coeff) + ovum = coeff; + /* for future, if mounthly cycle will be a thing to implement, this will be useful. + if (ovum < 0) + ovum = jsRandom(coeff/fertilityStack, 1); + */ + if (ovum < 1) + ovum = 1; } - return ovum; + + return Math.ceil(ovum);; }; /* diff --git a/src/js/slaveSummaryWidgets.js b/src/js/slaveSummaryWidgets.js index f0ef4175f96bc324424aef14355ca092b029b422..32ccb6f59751795f1861e721df02914bc2887dea 100644 --- a/src/js/slaveSummaryWidgets.js +++ b/src/js/slaveSummaryWidgets.js @@ -1038,8 +1038,6 @@ window.SlaveSummaryUncached = (function() { r += `On contraceptives.`; } else if (slave.preg === 0 && (slave.ovaries === 1 || slave.mpreg === 1)) { r += `Fertile.`; - } else if (((slave.preg < slave.pregData.normalBirth / 10) && (slave.preg > 0) && slave.pregKnown === 0) || slave.pregWeek === 1) { - r += `May be pregnant.`; } else if ((slave.preg >= 36) && (slave.broodmother > 0)) { r += `Permanently pregnant.`; } else if (swd.litters.length > 1) { @@ -1047,6 +1045,8 @@ window.SlaveSummaryUncached = (function() { r += `Mutipregnant, (` + swd.litters.length + ` sets).`; r+= ` Max:` + swd.litters[0] + ` / Min:` + swd.litters[swd.litters.length-1] + ` week(s).`; r += `</span> `; + } else if (((slave.preg < slave.pregData.normalBirth / 10) && (slave.preg > 0) && slave.pregKnown === 0) || slave.pregWeek === 1) { + r += `May be pregnant.`; } else if (slave.pregKnown === 1) { if (slave.pregType < 2 || slave.broodmother > 0) { r += `${slave.pregWeek} weeks pregnant.`; diff --git a/src/js/wombJS.js b/src/js/wombJS.js index ea8ae151fcb7ff42f9e129fd0e510dee4516210d..eded5f523ae8276b2134bec2ed355b9e5d27d8ad 100644 --- a/src/js/wombJS.js +++ b/src/js/wombJS.js @@ -117,6 +117,7 @@ window.WombImpregnate = function(actor, fCount, fatherID, age, surrogate) { } } MissingParentIDCorrection(actor); + WombUpdatePregVars(actor); }; window.WombSurrogate = function(actor, fCount, mother, fatherID, age) { @@ -184,6 +185,7 @@ window.WombImpregnateClone = function(actor, fCount, mother, motherOriginal, age alert("WombImpregnate warning - " + actor.slaveName + " " + err); } } + WombUpdatePregVars(actor); }; // Should be used to set biological age for fetus (ageToAdd), AND chronological (realAgeToAdd). Speed up or slow down gestation drugs should affect ONLY biological. @@ -373,6 +375,103 @@ window.WombGetVolume = function(actor) { // most legacy code from pregJS.tw with } }; +window.FetusGetPrediction = function (actor, age) { + let vol = 0.1; + if (actor.pregData.sizeType === 0) { + vol = getVolByLen(actor, age); + } else if (actor.pregData.sizeType === 1) { + vol = getVolByWeight(actor, age); + } else if (actor.pregData.sizeType === 2) { + vol = getVolByRaw(actor, age); + } + + if (vol === 0) + vol = 0.1; + + return vol; + + function getCurData(actor, age) { + let i = 0; + let min, max, ageMin, ageMax, rateMin, rateMax, one, rateOne, rate, cage, csize; + let data = {}; + + while (actor.pregData.fetusWeek[i + 1] < age && i < actor.pregData.fetusWeek.length - 1) { + i++; + } + + min = actor.pregData.fetusSize[i]; + max = actor.pregData.fetusSize[i + 1]; + ageMin = actor.pregData.fetusWeek[i]; + ageMax = actor.pregData.fetusWeek[i + 1]; + rateMin = actor.pregData.fetusRate[i]; + rateMax = actor.pregData.fetusRate[i + 1]; + + cage = age - ageMin; + + one = (max - min) / (ageMax - ageMin); + rateOne = (rateMax - rateMin) / (ageMax - ageMin); + + rate = rateMin + (rateOne * cage); + + csize = (min + (one * cage)); + // console.log("min:"+min+" max:"+max+" ageMin:"+ageMin+" ageMax:"+ageMax+" one:"+one+" rateOne:"+rateOne+" cage:"+cage+" rate:"+rate+" csize:"+csize+" final size:"+csize*rate); + + data.size = csize; + data.rate = rate; + + return data; // csize * rate; + // maybe not very effective code, but simple and easy to debug. May be optimized more in future. + } + + function getVolByLen(actor, age) { + let phi = 1.618; + let targetData, targetLen; + let volume = 0; + + targetData = getCurData(actor, age); + targetLen = targetData.size * targetData.rate; + + volume = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((targetLen / 2), 3))); + + if (volume < 0) { // catch for strange cases, to avoid messing with outside code. + volume = 0; + } + + return volume; + } + + function getVolByWeight(actor, age) { + let targetData; + let volume = 0; + + targetData = getCurData(actor, age); + + volume += targetData.size * targetData.rate; + + if (volume < 0) { // catch for strange cases, to avoid messing with outside code. + volume = 0; + } + + return volume; + } + + function getVolByRaw(actor) { + let targetData; + let volume = 0; + + targetData = getCurData(actor, age); + + volume += targetData.size; + + if (volume < 0) { // catch for strange cases, to avoid messing with outside code. + volume = 0; + } + + return volume; + } + +} + window.WombUpdatePregVars = function(actor) { WombSort(actor); if (actor.womb.length > 0) { @@ -381,6 +480,9 @@ window.WombUpdatePregVars = function(actor) { } actor.pregType = actor.womb.length; actor.bellyPreg = WombGetVolume(actor); + + if (actor.womb[0].age >= 10 && actor.pregKnown == 0) + actor.pregKnown = 1; } }; @@ -445,6 +547,9 @@ window.WombNormalizePreg = function(actor) { // console.log("advancing .preg"); } + if (actor.womb[0].age >= 10 && actor.pregKnown == 0) + actor.pregKnown = 1 + actor.pregType = actor.womb.length; actor.pregSource = actor.womb[0].fatherID; } else if (actor.womb.length === 0 && actor.broodmother < 1) {