diff --git a/src/data/backwardsCompatibility/backwardsCompatibility.js b/src/data/backwardsCompatibility/backwardsCompatibility.js index 31c1e94aec11e4012676c11d71682107d1e18bbb..8121e631682deca1160edd79d8e0852835c64f86 100644 --- a/src/data/backwardsCompatibility/backwardsCompatibility.js +++ b/src/data/backwardsCompatibility/backwardsCompatibility.js @@ -1281,15 +1281,17 @@ App.Update.slaveRecords = function(node) { }; App.Update.genePoolRecords = function(node) { - if (V.releaseID < 1075) { - Object.keys(V.missingTable).map(k => V.missingTable[k]).forEach(s => { + Object.values(V.missingTable).forEach(s => { + if (!jsDef(s.mother)) s.mother = 0; + if (!jsDef(s.father)) s.father = 0; + if (!jsDef(s.inbreedingCoeff)) s.inbreedingCoeff = 0; - }); - let ib_coeff = ibc.coeff_slaves(V.genePool); - V.genePool.forEach(g => {g.inbreedingCoefficient = ib_coeff[g.ID]}); - } + }); + + let ib_coeff = ibc.coeff_slaves(V.genePool); + V.genePool.forEach(g => {g.inbreedingCoeff = ib_coeff[g.ID]}); for (let bci = 0; bci < V.genePool.length; bci++) { App.Update.Slave(V.genePool[bci], true); diff --git a/src/data/backwardsCompatibility/updateSlaveObject.js b/src/data/backwardsCompatibility/updateSlaveObject.js index 1747ddfe272b9dab3fc2a48a7bba9c0650c17089..99edd8aba4176c3e2db7e1849226884a7d6b7709 100644 --- a/src/data/backwardsCompatibility/updateSlaveObject.js +++ b/src/data/backwardsCompatibility/updateSlaveObject.js @@ -1026,8 +1026,8 @@ App.Update.Slave = function(slave, genepool = false) { } } } - - if (V.releaseID < 1075) { + + if (!jsDef(slave.inbreedingCoeff)) { slave.inbreedingCoeff = ibc.coeff(slave); slave.womb.forEach(f => { // Use null as the ID, since fetuses are missing it diff --git a/src/data/newGamePlus.js b/src/data/newGamePlus.js index 506bf21159e86316b6769813f73eba7bc5dcd4d9..e6e70cd7ba963e6d9ece64fe859ecf45b80f3e4b 100644 --- a/src/data/newGamePlus.js +++ b/src/data/newGamePlus.js @@ -75,12 +75,13 @@ App.Data.NewGamePlus = (function() { .forEach(s => ([s.pregSource + NGPOffset, s.mother + NGPOffset, s.father + NGPOffset] .filter(i => (i in missingTable)) .forEach(i => { - if (needed.index(i) === -1) + if (needed.indexOf(i) === -1) needed.push(i); }))); while (needed.length > 0) { - let s = needed.shift(); + let i = needed.shift(); + let s = missingTable[i]; newTable[i - NGPOffset] = s; s.ID -= NGPOffset; if (s.mother in missingTable) { @@ -98,6 +99,30 @@ App.Data.NewGamePlus = (function() { return newTable; }; + if (typeof V.missingTable !== undefined && V.showMissingSlaves === true) { + let oldMissingParentID = Math.min(-10000, ...Object.keys(V.missingTable)) - 1; + V.slaves.filter(s => (s.assignment !== Job.IMPORTED)).forEach(s => { + V.missingTable[oldMissingParentID] = { + slaveName: s.slaveName, + slaveSurname: s.slaveSurname, + fullName: SlaveFullName(s), + dick: s.dick, + vagina: s.vagina, + ID: oldMissingParentID, + mother: s.mother, + father: s.father, + inbreedingCoeff: s.inbreedingCoeff + }; + Object.values(V.missingTable).concat(V.slaves).forEach(so => { + if (so.mother === s.ID) + so.mother = oldMissingParentID; + if (so.father === s.ID) + so.father = oldMissingParentID; + }); + oldMissingParentID--; + }); + } + V.slaves.deleteWith((s) => s.assignment !== Job.IMPORTED); for (let slave of V.slaves) { diff --git a/src/js/ibcJS.js b/src/js/ibcJS.js index 6148bc1c58cd824dd557e1892aafbdc546ea6b99..eb1ee4c7c1ac4539fdd097d1b777f2d979023fa5 100644 --- a/src/js/ibcJS.js +++ b/src/js/ibcJS.js @@ -183,8 +183,7 @@ globalThis.ibc = (() => { let total = Object.keys(nodes).length; let seen = []; let curid = 0; - Object.keys(nodes).forEach(s => { - let n = nodes[s]; + Object.values(nodes).forEach(n => { if (n.mother !== null || n.father !== null) return; n.nc.push([curid]); @@ -219,8 +218,7 @@ globalThis.ibc = (() => { } // Cache the string NodeCodes - Object.keys(nodes).forEach(s => { - let n = nodes[s]; + Object.values(nodes).forEach(n => { n.nc_s = n.nc.map(nc => nc.join(';')); }); }; @@ -273,14 +271,24 @@ globalThis.ibc = (() => { // Determine the coefficients of inbreeding of an array of slaves. Returns a mapping of their // ID to their coefficient of inbreeding let coeff_slaves = slaves => { - let nodes = nodes_slaves(slaves); - - // Compute coefficients let ret = {}; slaves.forEach(s => { - ret[s.ID] = coeff(nodes[s.ID]); + let sg = find_gp(s.ID); + if (sg !== null && "inbreedingCoeff" in sg && sg.inbreedingCoeff !== -1) { + ret[s.ID] = sg.inbreedingCoeff; + } }); + slaves = slaves.filter(s => (!(s.ID in ret))); + if (slaves.length > 0) { + let nodes = nodes_slaves(slaves); + + // Compute coefficients + slaves.forEach(s => { + ret[s.ID] = coeff(nodes[s.ID]); + }); + } + return ret; }; diff --git a/src/js/removeActiveSlave.js b/src/js/removeActiveSlave.js index ba16521d22c7584d6687e72b84a1fec1f4950fa4..eb32e2872f8dede7976205ae5c0deca11ca5f9c8 100644 --- a/src/js/removeActiveSlave.js +++ b/src/js/removeActiveSlave.js @@ -197,8 +197,7 @@ globalThis.removeActiveSlave = function() { V.genePool.deleteAt(_geneIndex); } } - Object.keys(V.missingTable).forEach(k => { - let s = V.missingTable[k]; + Object.values(V.missingTable).forEach(s => { if (s.mother === V.activeSlave.ID || s.father === V.activeSlave.ID) missing = true; }); @@ -220,8 +219,7 @@ globalThis.removeActiveSlave = function() { } else if (V.boomerangSlave.ID === V.activeSlave.ID) { V.boomerangSlave.missingParentTag = V.missingParentID; } - Object.keys(V.missingTable).forEach(k => { - let s = V.missingTable[k]; + Object.values(V.missingTable).forEach(s => { if (s.mother === V.activeSlave.ID) s.mother = V.missingParentID; if (s.father === V.activeSlave.ID) @@ -325,8 +323,7 @@ globalThis.removeNonNGPSlave = function(removedSlave) { V.genePool.deleteAt(_geneIndex); } } - Object.keys(V.missingTable).forEach(k => { - let s = V.missingTable[k]; + Object.values(V.missingTable).forEach(s => { if (s.mother == removedSlave.ID || s.father == removedSlave.ID) missing = true; }); @@ -342,8 +339,7 @@ globalThis.removeNonNGPSlave = function(removedSlave) { father: removedSlave.father, inbreedingCoeff: removedSlave.inbreedingCoeff }; - Object.keys(V.missingTable).forEach(k => { - let s = V.missingTable[k]; + Object.values(V.missingTable).forEach(s => { if (s.mother === removedSlave.ID) s.mother = V.missingParentID; if (s.father === removedSlave.ID) diff --git a/src/js/wombJS.js b/src/js/wombJS.js index e560f361fc5fd2203a9f1c90ca2f05c82b345c3d..2cdf98b6a0ff14da877cc76498f9ba6f798a83f0 100644 --- a/src/js/wombJS.js +++ b/src/js/wombJS.js @@ -94,6 +94,14 @@ globalThis.WombInit = function(actor) { WombImpregnate(actor, bLeft, actor.pregSource, i + 1); // setting up leftover of fetuses. } } + + actor.womb.forEach(f => { + if (!jsDef(f.genetics.inbreedingCoeff)) { + f.genetics.inbreedingCoeff = ibc.coeff( + {ID: null, mother: f.genetics.mother, father: f.genetics.father} + ); + } + }); }; globalThis.WombImpregnate = function(actor, fCount, fatherID, age, surrogate) {