From e26c91a81594ca85caa6cf3ca5278a8d193b1559 Mon Sep 17 00:00:00 2001
From: Empress Sela <empresssela@cock.li>
Date: Wed, 22 Jul 2020 23:36:04 -0400
Subject: [PATCH] Recalculate IBC later after cheat edit

- Was being recalculated before changed data was committed to V.slaves
---
 src/cheats/mod_EditChildCheatDatatypeCleanupNew.tw | 2 +-
 src/cheats/mod_EditSlaveCheatDatatypeCleanup.tw    | 2 +-
 src/cheats/mod_EditSlaveCheatDatatypeCleanupNew.tw | 2 +-
 src/js/ibcJS.js                                    | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/cheats/mod_EditChildCheatDatatypeCleanupNew.tw b/src/cheats/mod_EditChildCheatDatatypeCleanupNew.tw
index 57449fb187f..283f230b8ca 100644
--- a/src/cheats/mod_EditChildCheatDatatypeCleanupNew.tw
+++ b/src/cheats/mod_EditChildCheatDatatypeCleanupNew.tw
@@ -322,9 +322,9 @@ You perform the dark rituals, pray to the dark gods, and sell your soul for the
 <br><br>This slave has been changed forever and you have lost a bit of your soul, YOU CHEATER!
 
 <<set $activeSlave = clone($tempSlave)>>
-<<run ibc.recalculate_coeff_id($activeSlave.ID)>>
 <<unset $tempSlave>>
 <<set _escn = $cribs.findIndex(function(s) { s.ID === $activeSlave.ID; })>>
 <<if def _escn>>
 	<<set $cribs[_escn] = clone($activeSlave)>>
 <</if>>
+<<run ibc.recalculate_coeff_id($activeSlave.ID)>>
diff --git a/src/cheats/mod_EditSlaveCheatDatatypeCleanup.tw b/src/cheats/mod_EditSlaveCheatDatatypeCleanup.tw
index f07890401af..015bbf3689f 100644
--- a/src/cheats/mod_EditSlaveCheatDatatypeCleanup.tw
+++ b/src/cheats/mod_EditSlaveCheatDatatypeCleanup.tw
@@ -66,9 +66,9 @@ You perform the dark rituals, pray to the dark gods, and sell your soul for the
 <br><br>This slave has been changed forever and you have lost a bit of your soul, YOU CHEATER!
 
 <<set $activeSlave = clone($tempSlave)>>
-<<run ibc.recalculate_coeff_id($activeSlave.ID)>>
 <<unset $tempSlave>>
 <<set _escdc = $slaveIndices[$activeSlave.ID]>>
 <<if def _escdc>>
 	<<set $slaves[_escdc] = $activeSlave>>
 <</if>>
+<<run ibc.recalculate_coeff_id($activeSlave.ID)>>
diff --git a/src/cheats/mod_EditSlaveCheatDatatypeCleanupNew.tw b/src/cheats/mod_EditSlaveCheatDatatypeCleanupNew.tw
index 196caf23c02..043d863a43e 100644
--- a/src/cheats/mod_EditSlaveCheatDatatypeCleanupNew.tw
+++ b/src/cheats/mod_EditSlaveCheatDatatypeCleanupNew.tw
@@ -225,9 +225,9 @@ You perform the dark rituals, pray to the dark gods, and sell your soul for the
 <br><br>This slave has been changed forever and you have lost a bit of your soul, YOU CHEATER!
 
 <<set $activeSlave = clone($tempSlave)>>
-<<run ibc.recalculate_coeff_id($activeSlave.ID)>>
 <<unset $tempSlave>>
 <<set _escn = $slaveIndices[$activeSlave.ID]>>
 <<if def _escn>>
 	<<set $slaves[_escn] = clone($activeSlave)>>
 <</if>>
+<<run ibc.recalculate_coeff_id($activeSlave.ID)>>
diff --git a/src/js/ibcJS.js b/src/js/ibcJS.js
index fbd652e6f55..d1e916f4d49 100644
--- a/src/js/ibcJS.js
+++ b/src/js/ibcJS.js
@@ -338,7 +338,7 @@ globalThis.ibc = (() => {
         if (a === 0 || b === 0)
             return 0;
 
-        return kinship_one_many(a, [b], ignore_coeffs);
+        return kinship_one_many(a, [b], ignore_coeffs)[b.ID];
     };
 
     // Determine the coefficient of inbreeding of a single slave
@@ -350,7 +350,7 @@ globalThis.ibc = (() => {
         if (!ignore_coeffs && gp !== null && "inbreedingCoeff" in gp && gp.inbreedingCoeff !== -1)
             return gp.inbreedingCoeff;
 
-        return coeff_slaves([slave])[slave.ID];
+        return coeff_slaves([slave], ignore_coeffs)[slave.ID];
     };
 
     // Determine the kinship between one and many slaves. Returns an mapping from the ID of each of
-- 
GitLab