From 68ee9e5739c64c91a77a71a5b0260a1d99e36649 Mon Sep 17 00:00:00 2001 From: Jaizu Date: Mon, 30 Jan 2023 13:57:59 +0100 Subject: [PATCH] Restore bugfix Ooopsie! --- src/daycare.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/daycare.c b/src/daycare.c index ea44f1577..54a5e4c8f 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -558,8 +558,20 @@ static void InheritIVs(struct Pokemon *egg, struct DayCare *daycare, struct BoxP // Select which IVs that will be inherited. for (i = 0; i < howManyIVs; i++) { + // Randomly pick an IV from the available list and stop from being chosen again. + // BUG: Instead of removing the IV that was just picked, this + // removes position 0 (HP) then position 1 (DEF), then position 2. This is why HP and DEF + // have a lower chance to be inherited in Emerald and why the IV picked for inheritance can + // be repeated. Amusingly, FRLG and RS also got this wrong. They remove selectedIvs[i], which + // is not an index! This means that it can sometimes remove the wrong stat. + #ifndef BUGFIX selectedIvs[i] = availableIVs[Random() % (NUM_STATS - i)]; RemoveIVIndexFromList(availableIVs, i); + #else + u8 index = Random() % (NUM_STATS - i); + selectedIvs[i] = availableIVs[index]; + RemoveIVIndexFromList(availableIVs, index); + #endif } // Determine which parent each of the selected IVs should inherit from.