diff --git a/devNotes/twine JS.txt b/devNotes/twine JS.txt index 19271e7cc91f2abaa08b9b1c2fe6906bc052ddba..2edd894c164a16a3e6a54dec2642fe86c309bfb8 100644 --- a/devNotes/twine JS.txt +++ b/devNotes/twine JS.txt @@ -324,7 +324,7 @@ window.isFertile = function(slave) { if (slave.womb.length > 0 && slave.geneticQuirks.superfetation < 2 && slave.ovaImplant < 1) { /* currently pregnant without superfetation */ return false; } else if (slave.womb.length > 0) { /* temp failure condition to prevent current double preg bug */ - return false; + return false; } else if (slave.broodmother > 0) { /* currently broodmother */ return false; } else if (slave.preg < -1) { /* sterile */ @@ -988,16 +988,16 @@ window.SoftenSexualFlaw = function SoftenSexualFlaw(slave) { }; window.genUUID = function() { - var d = new Date().getTime(); - if(Date.now){ - d = Date.now(); //high-precision timer - } - var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - var r = (d + Math.random()*16)%16 | 0; - d = Math.floor(d/16); - return (c=='x' ? r : (r&0x3|0x8)).toString(16); - }); - return uuid; + var d = new Date().getTime(); + if(Date.now){ + d = Date.now(); //high-precision timer + } + var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = (d + Math.random()*16)%16 | 0; + d = Math.floor(d/16); + return (c=='x' ? r : (r&0x3|0x8)).toString(16); + }); + return uuid; }; /*:: itemAvailability [script]*/ @@ -10629,11 +10629,11 @@ window.generateChild = function(mother, ova, destination) { } else { child.slaveName = `Your and ${genes.fatherName}'s daughter`; } - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else { if (genes.father == -1) { child.slaveName = `${genes.motherName} and your daughter`; - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else if (genes.father > 0) { child.slaveName = `${genes.motherName} and ${genes.fatherName}'s daughter`; let currentMother = getSlave(genes.mother); @@ -10672,11 +10672,11 @@ window.generateChild = function(mother, ova, destination) { } else { child.slaveName = `Your and ${genes.fatherName}'s son`; } - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else { if (genes.father == -1) { child.slaveName = `${genes.motherName} and your son`; - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else if (genes.father > 0) { child.slaveName = `${genes.motherName} and ${genes.fatherName}'s son`; let currentMother = getSlave(genes.mother); @@ -10770,11 +10770,11 @@ window.generateChild = function(mother, ova, destination) { } else { child.slaveName = `Your and ${genes.fatherName}'s daughter`; } - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else { if (genes.father == -1) { child.slaveName = `${genes.motherName} and your daughter`; - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else if (genes.father > 0) { child.slaveName = `${genes.motherName} and ${genes.fatherName}'s daughter`; let currentMother = getSlave(genes.mother); @@ -10814,11 +10814,11 @@ window.generateChild = function(mother, ova, destination) { } else { child.slaveName = `Your and ${genes.fatherName}'s son`; } - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else { if (genes.father == -1) { child.slaveName = `${genes.motherName} and your son`; - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else if (genes.father > 0) { child.slaveName = `${genes.motherName} and ${genes.fatherName}'s son`; let currentMother = getSlave(genes.mother); @@ -11006,7 +11006,7 @@ $slave.bellyPreg = WombGetWolume($slave) - return double, with current womb volu //Init womb system. window.WombInit = function(actor) { - + if (!Array.isArray(actor.womb)) { //alert("creating new womb"); //debugging actor.womb = []; @@ -11025,10 +11025,10 @@ window.WombInit = function(actor) { //backward compatibility setup. Fully accurate for normal pregnancy only. if (actor.womb.length > 0 && actor.broodmother == 0 && actor.womb[0].genetics == undefined) { - var i=0 + var i=0 actor.womb.forEach(function(ft){ ft.genetics = generateGenetics(actor.ID, actor.pregSource, i); - i++; + i++; }); } else if (actor.womb.length == 0 && actor.pregType != 0 && actor.broodmother == 0) { WombImpregnate(actor, actor.pregType, actor.pregSource, actor.preg); @@ -11058,14 +11058,14 @@ window.WombImpregnate = function(actor, fCount, fatherID, age) { for (i=0; i<fCount; i++) { tf = {}; //new Object tf.age = age; //initial age - tf.motherID = actor.ID; //Initial biological mother ID setup. + tf.motherID = actor.ID; //Initial biological mother ID setup. tf.fatherID = fatherID; //We can store who is father too. tf.volume = 1; //Initial, to create property. Updated with actual data after WombGetVolume call. tf.reserve = ""; //Initial, to create property. Used later to mark if this child is to be kept. tf.identical = 0; //Initial, to create property. Updated with actual data during fetalSplit call. - tf.splitted = 0; //marker for already splitted fetus. + tf.splitted = 0; //marker for already splitted fetus. tf.genetics = generateGenetics(actor, fatherID, i+1); //Stored genetic information. - tf.ID = genUUID(); + tf.ID = genUUID(); try { if (actor.womb.length == 0) { @@ -11089,12 +11089,12 @@ window.WombSurrogate = function(actor, fCount, mother, fatherID, age) { for (i=0; i<fCount; i++) { tf = {}; //new Object tf.age = age; //initial age - tf.motherID = mother.ID; //Initial biological mother ID setup. + tf.motherID = mother.ID; //Initial biological mother ID setup. tf.fatherID = fatherID; //We can store who is father too. tf.volume = 1; //Initial, to create property. Updated with actual data after WombGetVolume call. tf.reserve = ""; //Initial, to create property. Used later to mark if this child is to be kept. tf.identical = 0; //Initial, to create property. Updated with actual data during fetalSplit call. - tf.splitted = 0; //marker for already splitted fetus. + tf.splitted = 0; //marker for already splitted fetus. tf.genetics = generateGenetics(mother, fatherID, i+1); //Stored genetic information. try { @@ -11309,7 +11309,7 @@ window.WombChangeGeneID = function(actor, fromID, toID) { actor.womb .filter(ft => ft.genetics.father === fromID) .forEach(ft => ft.genetics.father = toID); - actor.womb + actor.womb .filter(ft => ft.genetics.mother === fromID) .forEach(ft => ft.genetics.mother = toID); WombNormalizePreg(actor); @@ -11331,20 +11331,20 @@ window.fetalSplit = function(actor, chance) { nft = {}; nft.age = s.age; nft.fatherID = s.fatherID; - nft.motherID = s.motherID; + nft.motherID = s.motherID; nft.volume = s.volume; - nft.reserve = ""; //splitted fetus is new separate, reserve - it's not genetic to split. + nft.reserve = ""; //splitted fetus is new separate, reserve - it's not genetic to split. nft.genetics = deepCopy(s.genetics); - s.splitted = 1; //this is marker that this is already splitted fetus (to not split second time in loop), only source fetus needed it. - nft.identical = 1; //this is marker that this fetus has at least one twin. - s.identical = 1; //this is marker that this fetus has at least one twin. + s.splitted = 1; //this is marker that this is already splitted fetus (to not split second time in loop), only source fetus needed it. + nft.identical = 1; //this is marker that this fetus has at least one twin. + s.identical = 1; //this is marker that this fetus has at least one twin. - if (s.twinID == "" || s.twinID == undefined) - s.twinID = genUUID(); + if (s.twinID == "" || s.twinID == undefined) + s.twinID = genUUID(); - nft.twinID = s.twinID; + nft.twinID = s.twinID; - actor.womb.push(nft); + actor.womb.push(nft); } }); @@ -11354,54 +11354,54 @@ window.fetalSplit = function(actor, chance) { //safe alternative to .womb.length. window.WombFetusCount = function(actor) { - WombInit(actor); - return actor.womb.length; + WombInit(actor); + return actor.womb.length; } //give reference to fetus object, but not remove fetus, use for manupulation in the womb. window.WombGetFetus = function(actor, fetusNum) { - WombInit(actor); - if (actor.womb.length >= fetusNum) - return actor.womb[fetusNum]; - else - return null; + WombInit(actor); + if (actor.womb.length >= fetusNum) + return actor.womb[fetusNum]; + else + return null; } //give reference to fetus object, and remove it form the womb. window.WombRemoveFetus = function(actor, fetusNum) { - WombInit(actor); - if (actor.womb.length >= fetusNum){ - let ft = actor.womb[fetusNum]; - actor.womb.splice(fetusNum, 1); - WombSort(actor); - return ft; - } - else - return null; + WombInit(actor); + if (actor.womb.length >= fetusNum){ + let ft = actor.womb[fetusNum]; + actor.womb.splice(fetusNum, 1); + WombSort(actor); + return ft; + } + else + return null; } /*to add fetus object in the womb. Be warned - you can add one single fetus to many wombs, or even add it many times to one womb. It's will not show error, but behavior become strange, as fetus object will be the same - it's reference, not full copies. If this not desired - use deepCopy on fetus before adding.*/ window.WombAddFetus = function(actor, fetus) { - WombInit(actor); - actor.womb.push(fetus); - WombSort(actor); + WombInit(actor); + actor.womb.push(fetus); + WombSort(actor); } // change property for all fetuses. Like fetus.age = X. window.WombChangeFetus = function(actor, propName, newValue) { - WombInit(actor); - actor.womb.forEach(ft => ft[propName] = newValue); + WombInit(actor); + actor.womb.forEach(ft => ft[propName] = newValue); } // change genetic property of all fetuses. Like fetus.genetic.intelligence = X window.WombChangeGene = function(actor, geneName, newValue) { - WombInit(actor); - actor.womb.forEach(ft => ft.genetics[geneName] = newValue); + WombInit(actor); + actor.womb.forEach(ft => ft.genetics[geneName] = newValue); } // replaces untraceable fatherIDs with missingParentID. Required for concurrent pregancy to differentiate between siblings. @@ -11415,203 +11415,202 @@ window.MissingParentIDCorrection = function(actor) { window.WombCleanYYFetuses = function(actor) { - var reserved = []; + var reserved = []; - var i = actor.womb.length-1; - var ft; + var i = actor.womb.length-1; + var ft; - while (i >= 0) - { - ft = actor.womb[i]; + while (i >= 0) + { + ft = actor.womb[i]; - if (ft.genetics.gender == "YY") - { - reserved.push(ft); - actor.womb.splice(i, 1); - } + if (ft.genetics.gender == "YY") + { + reserved.push(ft); + actor.womb.splice(i, 1); + } - i--; - } + i--; + } - return reserved; + return reserved; } - window.FetusGlobalReserveCount = function(reserveType) { - var cnt = 0; - var SV = State.variables; + var cnt = 0; + var SV = State.variables; - if (typeof reserveType != 'string' ) - return 0; + if (typeof reserveType != 'string' ) + return 0; - SV.slaves.forEach(function(slave){ - slave.womb.forEach(function(ft){ - if (ft.reserve == reserveType) - cnt++; - }); - }); + SV.slaves.forEach(function(slave){ + slave.womb.forEach(function(ft){ + if (ft.reserve == reserveType) + cnt++; + }); + }); - SV.PC.womb.forEach(function(ft){ - if (ft.reserve == reserveType) - cnt++; - }); + SV.PC.womb.forEach(function(ft){ + if (ft.reserve == reserveType) + cnt++; + }); - return cnt; + return cnt; } window.WombSetGenericReserve = function(actor, type, count) { - //console.log ("actor: " + actor + " type: " + type + " typeof: " + typeof type + " count: " + count); - actor.womb.forEach(function(ft){ - //console.log (" type: " + ft.reserve + " typeof: " + typeof ft.reserve); - if ((ft.reserve == "" || ft.reserve == type) && count > 0) - { - //console.log ("!trigger"); - ft.reserve = type; - count--; - } - - }); + //console.log ("actor: " + actor + " type: " + type + " typeof: " + typeof type + " count: " + count); + actor.womb.forEach(function(ft){ + //console.log (" type: " + ft.reserve + " typeof: " + typeof ft.reserve); + if ((ft.reserve == "" || ft.reserve == type) && count > 0) + { + //console.log ("!trigger"); + ft.reserve = type; + count--; + } + + }); } window.WombAddToGenericReserve = function(actor, type, count) { - - WombSetGenericReserve(actor, type, (WombReserveCount(actor, type)+count)); + + WombSetGenericReserve(actor, type, (WombReserveCount(actor, type)+count)); } window.WombChangeReserveType = function(actor, oldType, newType) { - var count = 0; + var count = 0; - actor.womb.forEach(function(ft){ - if (ft.reserve == oldType) - { - ft.reserve = newType; - count++; - } - }); + actor.womb.forEach(function(ft){ + if (ft.reserve == oldType) + { + ft.reserve = newType; + count++; + } + }); - return count; + return count; } window.WombCleanGenericReserve = function(actor, type, count) { - actor.womb.forEach(function(ft){ + actor.womb.forEach(function(ft){ - if (ft.reserve == type && count > 0) - { - ft.reserve = ""; - count--; - } + if (ft.reserve == type && count > 0) + { + ft.reserve = ""; + count--; + } - }); + }); } window.WombReserveCount = function(actor, type) { - var cnt = 0; + var cnt = 0; - actor.womb.forEach(function(ft){ + actor.womb.forEach(function(ft){ - if (ft.reserve == type) - { - cnt++; - } + if (ft.reserve == type) + { + cnt++; + } - }); + }); - return cnt; + return cnt; } window.WombGetReservedFetuses = function(actor, type) { - var reserved = []; + var reserved = []; - actor.womb.forEach(function(ft){ + actor.womb.forEach(function(ft){ - if (ft.reserve == type) - { - reserved.push(ft); - } + if (ft.reserve == type) + { + reserved.push(ft); + } - }); + }); - return reserved; + return reserved; } window.WombRemoveReservedFetuses = function(actor, type) { - var reserved = []; + var reserved = []; - var i = actor.womb.length-1; - var ft; + var i = actor.womb.length-1; + var ft; - while (i >= 0) - { - ft = actor.womb[i]; + while (i >= 0) + { + ft = actor.womb[i]; - if (ft.reserve == type) - { - reserved.push(ft); - actor.womb.splice(i, 1); - } + if (ft.reserve == type) + { + reserved.push(ft); + actor.womb.splice(i, 1); + } - i--; - } + i--; + } - return reserved; + return reserved; } window.WombCleanAllReserve = function(actor) { - actor.womb.forEach(function(ft){ - ft.reserve = ""; - }); + actor.womb.forEach(function(ft){ + ft.reserve = ""; + }); } window.BCReserveInit = function() { - var SV = State.variables; - - SV.slaves.forEach(function(slave) - { - slave.womb.forEach(function(ft) - { - if (typeof ft.reserve != 'string') - ft.reserve = ""; - if (typeof ft.motherID != 'number') //setting missing biological mother ID for fetus. - ft.motherID = slave.ID; - - if (ft.ID == undefined) - ft.ID = genUUID(); - - try { - if (slave.reservedChildren > 0) - WombSetGenericReserve(slave, "incubator", reservedChildren); - - if (slave.reservedChildrenNursery > 0) - WombSetGenericReserve(slave, "nursery", reservedChildren); - } catch (err) { - - console.log (err + " slave ID: " + slave.ID + " slave name: " + slave.slaveName + " " + slave.slaveSurname); - slave.reservedChildren = 0; - } - }); - }); - - SV.PC.womb.forEach(function(ft){ - if (typeof ft.reserve != 'string') - ft.reserve = ""; - ft.motherID = SV.PC.ID; - }); + var SV = State.variables; + + SV.slaves.forEach(function(slave) + { + slave.womb.forEach(function(ft) + { + if (typeof ft.reserve != 'string') + ft.reserve = ""; + if (typeof ft.motherID != 'number') //setting missing biological mother ID for fetus. + ft.motherID = slave.ID; + + if (ft.ID == undefined) + ft.ID = genUUID(); + + try { + if (slave.reservedChildren > 0) + WombSetGenericReserve(slave, "incubator", reservedChildren); + + if (slave.reservedChildrenNursery > 0) + WombSetGenericReserve(slave, "nursery", reservedChildren); + } catch (err) { + + console.log (err + " slave ID: " + slave.ID + " slave name: " + slave.slaveName + " " + slave.slaveSurname); + slave.reservedChildren = 0; + } + }); + }); + + SV.PC.womb.forEach(function(ft){ + if (typeof ft.reserve != 'string') + ft.reserve = ""; + ft.motherID = SV.PC.ID; + }); } diff --git a/src/js/generateGenetics.tw b/src/js/generateGenetics.tw index 0ddae929c878aaeab2adccd4989febd706e609d8..3ccef28ab24e1605f12cbf25c68a3733d33dc52b 100644 --- a/src/js/generateGenetics.tw +++ b/src/js/generateGenetics.tw @@ -502,11 +502,11 @@ window.generateChild = function(mother, ova, destination) { } else { child.slaveName = `Your and ${genes.fatherName}'s daughter`; } - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else { if (genes.father == -1) { child.slaveName = `${genes.motherName} and your daughter`; - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else if (genes.father > 0) { child.slaveName = `${genes.motherName} and ${genes.fatherName}'s daughter`; let currentMother = getSlave(genes.mother); @@ -545,11 +545,11 @@ window.generateChild = function(mother, ova, destination) { } else { child.slaveName = `Your and ${genes.fatherName}'s son`; } - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else { if (genes.father == -1) { child.slaveName = `${genes.motherName} and your son`; - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else if (genes.father > 0) { child.slaveName = `${genes.motherName} and ${genes.fatherName}'s son`; let currentMother = getSlave(genes.mother); @@ -643,11 +643,11 @@ window.generateChild = function(mother, ova, destination) { } else { child.slaveName = `Your and ${genes.fatherName}'s daughter`; } - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else { if (genes.father == -1) { child.slaveName = `${genes.motherName} and your daughter`; - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else if (genes.father > 0) { child.slaveName = `${genes.motherName} and ${genes.fatherName}'s daughter`; let currentMother = getSlave(genes.mother); @@ -687,11 +687,11 @@ window.generateChild = function(mother, ova, destination) { } else { child.slaveName = `Your and ${genes.fatherName}'s son`; } - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else { if (genes.father == -1) { child.slaveName = `${genes.motherName} and your son`; - child.slaveSurname = V.PC.surname; + child.slaveSurname = V.PC.surname; } else if (genes.father > 0) { child.slaveName = `${genes.motherName} and ${genes.fatherName}'s son`; let currentMother = getSlave(genes.mother); diff --git a/src/js/wombJS.tw b/src/js/wombJS.tw index 2407abcb97bd203488d03cacb33ae7555eeb6788..0da9d2ca7d306d4f95ca424fec9b822996b8160e 100644 --- a/src/js/wombJS.tw +++ b/src/js/wombJS.tw @@ -28,7 +28,7 @@ $slave.bellyPreg = WombGetWolume($slave) - return double, with current womb volu //Init womb system. window.WombInit = function(actor) { - + if (!Array.isArray(actor.womb)) { //alert("creating new womb"); //debugging actor.womb = []; @@ -47,10 +47,10 @@ window.WombInit = function(actor) { //backward compatibility setup. Fully accurate for normal pregnancy only. if (actor.womb.length > 0 && actor.broodmother == 0 && actor.womb[0].genetics == undefined) { - var i=0 + var i=0 actor.womb.forEach(function(ft){ ft.genetics = generateGenetics(actor.ID, actor.pregSource, i); - i++; + i++; }); } else if (actor.womb.length == 0 && actor.pregType != 0 && actor.broodmother == 0) { WombImpregnate(actor, actor.pregType, actor.pregSource, actor.preg); @@ -80,14 +80,14 @@ window.WombImpregnate = function(actor, fCount, fatherID, age) { for (i=0; i<fCount; i++) { tf = {}; //new Object tf.age = age; //initial age - tf.motherID = actor.ID; //Initial biological mother ID setup. + tf.motherID = actor.ID; //Initial biological mother ID setup. tf.fatherID = fatherID; //We can store who is father too. tf.volume = 1; //Initial, to create property. Updated with actual data after WombGetVolume call. tf.reserve = ""; //Initial, to create property. Used later to mark if this child is to be kept. tf.identical = 0; //Initial, to create property. Updated with actual data during fetalSplit call. - tf.splitted = 0; //marker for already splitted fetus. + tf.splitted = 0; //marker for already splitted fetus. tf.genetics = generateGenetics(actor, fatherID, i+1); //Stored genetic information. - tf.ID = genUUID(); + tf.ID = genUUID(); try { if (actor.womb.length == 0) { @@ -111,12 +111,12 @@ window.WombSurrogate = function(actor, fCount, mother, fatherID, age) { for (i=0; i<fCount; i++) { tf = {}; //new Object tf.age = age; //initial age - tf.motherID = mother.ID; //Initial biological mother ID setup. + tf.motherID = mother.ID; //Initial biological mother ID setup. tf.fatherID = fatherID; //We can store who is father too. tf.volume = 1; //Initial, to create property. Updated with actual data after WombGetVolume call. tf.reserve = ""; //Initial, to create property. Used later to mark if this child is to be kept. tf.identical = 0; //Initial, to create property. Updated with actual data during fetalSplit call. - tf.splitted = 0; //marker for already splitted fetus. + tf.splitted = 0; //marker for already splitted fetus. tf.genetics = generateGenetics(mother, fatherID, i+1); //Stored genetic information. try { @@ -331,7 +331,7 @@ window.WombChangeGeneID = function(actor, fromID, toID) { actor.womb .filter(ft => ft.genetics.father === fromID) .forEach(ft => ft.genetics.father = toID); - actor.womb + actor.womb .filter(ft => ft.genetics.mother === fromID) .forEach(ft => ft.genetics.mother = toID); WombNormalizePreg(actor); @@ -353,20 +353,20 @@ window.fetalSplit = function(actor, chance) { nft = {}; nft.age = s.age; nft.fatherID = s.fatherID; - nft.motherID = s.motherID; + nft.motherID = s.motherID; nft.volume = s.volume; - nft.reserve = ""; //splitted fetus is new separate, reserve - it's not genetic to split. + nft.reserve = ""; //splitted fetus is new separate, reserve - it's not genetic to split. nft.genetics = deepCopy(s.genetics); - s.splitted = 1; //this is marker that this is already splitted fetus (to not split second time in loop), only source fetus needed it. - nft.identical = 1; //this is marker that this fetus has at least one twin. - s.identical = 1; //this is marker that this fetus has at least one twin. + s.splitted = 1; //this is marker that this is already splitted fetus (to not split second time in loop), only source fetus needed it. + nft.identical = 1; //this is marker that this fetus has at least one twin. + s.identical = 1; //this is marker that this fetus has at least one twin. - if (s.twinID == "" || s.twinID == undefined) - s.twinID = genUUID(); + if (s.twinID == "" || s.twinID == undefined) + s.twinID = genUUID(); - nft.twinID = s.twinID; + nft.twinID = s.twinID; - actor.womb.push(nft); + actor.womb.push(nft); } }); @@ -376,54 +376,54 @@ window.fetalSplit = function(actor, chance) { //safe alternative to .womb.length. window.WombFetusCount = function(actor) { - WombInit(actor); - return actor.womb.length; + WombInit(actor); + return actor.womb.length; } //give reference to fetus object, but not remove fetus, use for manupulation in the womb. window.WombGetFetus = function(actor, fetusNum) { - WombInit(actor); - if (actor.womb.length >= fetusNum) - return actor.womb[fetusNum]; - else - return null; + WombInit(actor); + if (actor.womb.length >= fetusNum) + return actor.womb[fetusNum]; + else + return null; } //give reference to fetus object, and remove it form the womb. window.WombRemoveFetus = function(actor, fetusNum) { - WombInit(actor); - if (actor.womb.length >= fetusNum){ - let ft = actor.womb[fetusNum]; - actor.womb.splice(fetusNum, 1); - WombSort(actor); - return ft; - } - else - return null; + WombInit(actor); + if (actor.womb.length >= fetusNum){ + let ft = actor.womb[fetusNum]; + actor.womb.splice(fetusNum, 1); + WombSort(actor); + return ft; + } + else + return null; } /*to add fetus object in the womb. Be warned - you can add one single fetus to many wombs, or even add it many times to one womb. It's will not show error, but behavior become strange, as fetus object will be the same - it's reference, not full copies. If this not desired - use deepCopy on fetus before adding.*/ window.WombAddFetus = function(actor, fetus) { - WombInit(actor); - actor.womb.push(fetus); - WombSort(actor); + WombInit(actor); + actor.womb.push(fetus); + WombSort(actor); } // change property for all fetuses. Like fetus.age = X. window.WombChangeFetus = function(actor, propName, newValue) { - WombInit(actor); - actor.womb.forEach(ft => ft[propName] = newValue); + WombInit(actor); + actor.womb.forEach(ft => ft[propName] = newValue); } // change genetic property of all fetuses. Like fetus.genetic.intelligence = X window.WombChangeGene = function(actor, geneName, newValue) { - WombInit(actor); - actor.womb.forEach(ft => ft.genetics[geneName] = newValue); + WombInit(actor); + actor.womb.forEach(ft => ft.genetics[geneName] = newValue); } // replaces untraceable fatherIDs with missingParentID. Required for concurrent pregancy to differentiate between siblings. @@ -437,203 +437,202 @@ window.MissingParentIDCorrection = function(actor) { window.WombCleanYYFetuses = function(actor) { - var reserved = []; + var reserved = []; - var i = actor.womb.length-1; - var ft; + var i = actor.womb.length-1; + var ft; - while (i >= 0) - { - ft = actor.womb[i]; + while (i >= 0) + { + ft = actor.womb[i]; - if (ft.genetics.gender == "YY") - { - reserved.push(ft); - actor.womb.splice(i, 1); - } + if (ft.genetics.gender == "YY") + { + reserved.push(ft); + actor.womb.splice(i, 1); + } - i--; - } + i--; + } - return reserved; + return reserved; } - window.FetusGlobalReserveCount = function(reserveType) { - var cnt = 0; - var SV = State.variables; + var cnt = 0; + var SV = State.variables; - if (typeof reserveType != 'string' ) - return 0; + if (typeof reserveType != 'string' ) + return 0; - SV.slaves.forEach(function(slave){ - slave.womb.forEach(function(ft){ - if (ft.reserve == reserveType) - cnt++; - }); - }); + SV.slaves.forEach(function(slave){ + slave.womb.forEach(function(ft){ + if (ft.reserve == reserveType) + cnt++; + }); + }); - SV.PC.womb.forEach(function(ft){ - if (ft.reserve == reserveType) - cnt++; - }); + SV.PC.womb.forEach(function(ft){ + if (ft.reserve == reserveType) + cnt++; + }); - return cnt; + return cnt; } window.WombSetGenericReserve = function(actor, type, count) { - //console.log ("actor: " + actor + " type: " + type + " typeof: " + typeof type + " count: " + count); - actor.womb.forEach(function(ft){ - //console.log (" type: " + ft.reserve + " typeof: " + typeof ft.reserve); - if ((ft.reserve == "" || ft.reserve == type) && count > 0) - { - //console.log ("!trigger"); - ft.reserve = type; - count--; - } - - }); + //console.log ("actor: " + actor + " type: " + type + " typeof: " + typeof type + " count: " + count); + actor.womb.forEach(function(ft){ + //console.log (" type: " + ft.reserve + " typeof: " + typeof ft.reserve); + if ((ft.reserve == "" || ft.reserve == type) && count > 0) + { + //console.log ("!trigger"); + ft.reserve = type; + count--; + } + + }); } window.WombAddToGenericReserve = function(actor, type, count) { - - WombSetGenericReserve(actor, type, (WombReserveCount(actor, type)+count)); + + WombSetGenericReserve(actor, type, (WombReserveCount(actor, type)+count)); } window.WombChangeReserveType = function(actor, oldType, newType) { - var count = 0; + var count = 0; - actor.womb.forEach(function(ft){ - if (ft.reserve == oldType) - { - ft.reserve = newType; - count++; - } - }); + actor.womb.forEach(function(ft){ + if (ft.reserve == oldType) + { + ft.reserve = newType; + count++; + } + }); - return count; + return count; } window.WombCleanGenericReserve = function(actor, type, count) { - actor.womb.forEach(function(ft){ + actor.womb.forEach(function(ft){ - if (ft.reserve == type && count > 0) - { - ft.reserve = ""; - count--; - } + if (ft.reserve == type && count > 0) + { + ft.reserve = ""; + count--; + } - }); + }); } window.WombReserveCount = function(actor, type) { - var cnt = 0; + var cnt = 0; - actor.womb.forEach(function(ft){ + actor.womb.forEach(function(ft){ - if (ft.reserve == type) - { - cnt++; - } + if (ft.reserve == type) + { + cnt++; + } - }); + }); - return cnt; + return cnt; } window.WombGetReservedFetuses = function(actor, type) { - var reserved = []; + var reserved = []; - actor.womb.forEach(function(ft){ + actor.womb.forEach(function(ft){ - if (ft.reserve == type) - { - reserved.push(ft); - } + if (ft.reserve == type) + { + reserved.push(ft); + } - }); + }); - return reserved; + return reserved; } window.WombRemoveReservedFetuses = function(actor, type) { - var reserved = []; + var reserved = []; - var i = actor.womb.length-1; - var ft; + var i = actor.womb.length-1; + var ft; - while (i >= 0) - { - ft = actor.womb[i]; + while (i >= 0) + { + ft = actor.womb[i]; - if (ft.reserve == type) - { - reserved.push(ft); - actor.womb.splice(i, 1); - } + if (ft.reserve == type) + { + reserved.push(ft); + actor.womb.splice(i, 1); + } - i--; - } + i--; + } - return reserved; + return reserved; } window.WombCleanAllReserve = function(actor) { - actor.womb.forEach(function(ft){ - ft.reserve = ""; - }); + actor.womb.forEach(function(ft){ + ft.reserve = ""; + }); } window.BCReserveInit = function() { - var SV = State.variables; - - SV.slaves.forEach(function(slave) - { - slave.womb.forEach(function(ft) - { - if (typeof ft.reserve != 'string') - ft.reserve = ""; - if (typeof ft.motherID != 'number') //setting missing biological mother ID for fetus. - ft.motherID = slave.ID; - - if (ft.ID == undefined) - ft.ID = genUUID(); - - try { - if (slave.reservedChildren > 0) - WombSetGenericReserve(slave, "incubator", reservedChildren); - - if (slave.reservedChildrenNursery > 0) - WombSetGenericReserve(slave, "nursery", reservedChildren); - } catch (err) { - - console.log (err + " slave ID: " + slave.ID + " slave name: " + slave.slaveName + " " + slave.slaveSurname); - slave.reservedChildren = 0; - } - }); - }); - - SV.PC.womb.forEach(function(ft){ - if (typeof ft.reserve != 'string') - ft.reserve = ""; - ft.motherID = SV.PC.ID; - }); + var SV = State.variables; + + SV.slaves.forEach(function(slave) + { + slave.womb.forEach(function(ft) + { + if (typeof ft.reserve != 'string') + ft.reserve = ""; + if (typeof ft.motherID != 'number') //setting missing biological mother ID for fetus. + ft.motherID = slave.ID; + + if (ft.ID == undefined) + ft.ID = genUUID(); + + try { + if (slave.reservedChildren > 0) + WombSetGenericReserve(slave, "incubator", reservedChildren); + + if (slave.reservedChildrenNursery > 0) + WombSetGenericReserve(slave, "nursery", reservedChildren); + } catch (err) { + + console.log (err + " slave ID: " + slave.ID + " slave name: " + slave.slaveName + " " + slave.slaveSurname); + slave.reservedChildren = 0; + } + }); + }); + + SV.PC.womb.forEach(function(ft){ + if (typeof ft.reserve != 'string') + ft.reserve = ""; + ft.motherID = SV.PC.ID; + }); }