From 6a394d5514413a160fa7e8875b24a9105774f4f0 Mon Sep 17 00:00:00 2001 From: pregmodfan <pregmodfan@cock.li> Date: Wed, 28 Nov 2018 15:21:53 +0200 Subject: [PATCH] new pregnancy size calculation, with debug output to compare with previous mechanic --- src/init/setupVars.tw | 7 ++++-- src/js/wombJS.tw | 55 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/init/setupVars.tw b/src/init/setupVars.tw index 9581c51ac3c..6874fe9f264 100644 --- a/src/init/setupVars.tw +++ b/src/init/setupVars.tw @@ -7,8 +7,11 @@ /*** pregmod exclusive start ***/ <<set setup.pregData = { -human: {type: "human", normalBirth: 40, minLiveBirth: 32, fetusWeek: [9, 20, 40, 52, 64, 80, 384, 99999], fetusSize: [3, 20, 51, 60, 67.5, 71.6, 129.5, 130], fetusPHI: 1.618, storedFat: 1}, -canine: {type: "canine", normalBirth: 9, minLiveBirth: 8, fetusWeek: [4, 6, 9, 32, 99999], fetusSize: [1, 5, 17.7, 70, 70], fetusPHI: 1.618, storedFat: 1} + +human: {type: "human", normalBirth: 40, minLiveBirth: 32, fetusWeek: [9, 20, 40, 52, 64, 80, 384, 99999], fetusSize: [3, 16, 51, 60, 67.5, 71.6, 129.5, 130], fetusCTR: [1, 1, 0.6513, 0.6459, 0.644, 0.6393, 0.58, 0.51], storedFat: 1}, + +canine: {type: "canine", normalBirth: 9, minLiveBirth: 8, fetusWeek: [4, 6, 9, 32, 99999], fetusSize: [1, 5, 17.7, 70, 70], fetusCTR: [1, 1, 1, 1], storedFat: 1} /*source data include CTR (not for head to toe), so CTR not apply.*/ + }>> <<set setup.filterRaces = ["Amerindian", "Asian", "Black", "Indo-Aryan", "Latina", "Malay", "Middle Eastern", "Mixed Race", "Pacific Islander", "Semitic", "Southern European", "White"]>> diff --git a/src/js/wombJS.tw b/src/js/wombJS.tw index 3d6942d6787..3e37834abeb 100644 --- a/src/js/wombJS.tw +++ b/src/js/wombJS.tw @@ -45,6 +45,13 @@ window.WombInit = function(actor) { actor.readyOva = 0; } + if ( actor.pregData == undefined) + { + //actor.pregData = deepCopy( setup.pregData.human ); + //Setup should be through deep copy, so in future, if we like, these values can be changed individually. Gameplay expansion posibilities. But for dev time to simplify debugging: + actor.pregData = setup.pregData.human; // any changes in setup pregData template will be applied immideatly to all. But can't be made seperate changes. + } + //backward compatibility setup. Fully accurate for normal pregnancy only. if (actor.womb.length > 0 && actor.womb[0].genetics == undefined) { var i=0 @@ -188,28 +195,68 @@ window.WombGetVolume = function(actor) { //most code from pregJS.tw with minor a var phi = 1.618; var targetLen; var wombSize = 0; + + function getCurLen(actor, age) + { + let i = 0; + let min, max, ageMin, ageMax, ctrMin, ctrMax, one, ctrOne, ctr, cage, csize; + 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]; + ctrMin = actor.pregData.fetusCTR[i]; + ctrMax = actor.pregData.fetusCTR[i+1]; + + cage = age - ageMin; + + one = (max - min) / (ageMax - ageMin); + ctrOne = (ctrMax - ctrMin) / (ageMax - ageMin); // CTR can have negative or positive progression, but we need absolute. + + ctr = ctrMin + (ctrOne * cage); + + csize = (min + (one * cage)); + console.log("min:"+min+" max:"+max+" ageMin:"+ageMin+" ageMax:"+ageMax+" one:"+one+" ctrOne:"+ctrOne+" cage:"+cage+" ctr:"+ctr+" csize:"+csize+" final size:"+csize*ctr); + + return csize*ctr; + //maybe not very effective code, but simple and easy to debug. May be optimized more in future. + } + try { actor.womb.forEach(ft => { gestastionWeek = ft.age; - if (gestastionWeek <= 32) { - targetLen = (0.00006396 * Math.pow(gestastionWeek, 4)) - + + //for debug only + let oldLen; + let oldVol; + if (gestastionWeek <= 32) { + oldLen = (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)) + + oldLen = (-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)) + + oldLen = (-0.00003266 * Math.pow(gestastionWeek,2)) + (0.076 * gestastionWeek) + 43.843; } + + targetLen = getCurLen(actor, ft.age); + ft.volume = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((targetLen / 2), 3))); wombSize += ft.volume; + + oldVol = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((oldLen / 2), 3))); //for debug + + console.log("fetus.age:" + ft.age + " oldLen:"+oldLen+" targetLen:"+targetLen+" ft.volume:"+ft.volume+ " old volume:"+oldVol ); }); } catch(err){ WombInit(actor); -- GitLab