diff --git a/src/dexnav.c b/src/dexnav.c index e821ac8542..6a5bacf2bd 100644 --- a/src/dexnav.c +++ b/src/dexnav.c @@ -1212,7 +1212,7 @@ static void DexNavUpdateSearchWindow(u8 proximity, u8 searchLevel) static void CreateDexNavWildMon(u16 species, u8 potential, u8 level, u8 abilityNum, u16 item, u16* moves) { struct Pokemon* mon = &gEnemyParty[0]; - u8 iv[3]; + u8 iv[3] = {NUM_STATS}; u8 i; u8 perfectIv = 31; @@ -1221,20 +1221,21 @@ static void CreateDexNavWildMon(u16 species, u8 potential, u8 level, u8 abilityN CreateWildMon(species, level); // shiny rate bonus handled in CreateBoxMon - //Pick potential unique ivs to set to 31 - iv[0] = Random() % 6; - do {iv[1] = Random() % 6;} while (iv[1] == iv[0]); - do {iv[2] = Random() % 6;} while (iv[2] == iv[0] || iv[2] == iv[1]); - if ((iv[0] != iv[1]) && (iv[0] != iv[2]) && (iv[1] != iv[2])) - { - if (potential > 2) - SetMonData(mon, MON_DATA_HP_IV + iv[2], &perfectIv); - else if (potential > 1) - SetMonData(mon, MON_DATA_HP_IV + iv[1], &perfectIv); - else if (potential) - SetMonData(mon, MON_DATA_HP_IV + iv[0], &perfectIv); - } - + // Pick random, unique IVs to set to 31. The number of perfect IVs that are assigned is equal to the potential + iv[0] = Random() % NUM_STATS; // choose 1st perfect stat + do { + iv[1] = Random() % NUM_STATS; + iv[2] = Random() % NUM_STATS; + } while ((iv[1] == iv[0]) // unique 2nd perfect stat + || (iv[2] == iv[0] || iv[2] == iv[1])); // unique 3rd perfect stat + + if (potential > 2 && iv[2] != NUM_STATS) + SetMonData(mon, MON_DATA_HP_IV + iv[2], &perfectIv); + if (potential > 1 && iv[1] != NUM_STATS) + SetMonData(mon, MON_DATA_HP_IV + iv[1], &perfectIv); + if (potential > 0 && iv[0] != NUM_STATS) + SetMonData(mon, MON_DATA_HP_IV + iv[0], &perfectIv); + //Set ability SetMonData(mon, MON_DATA_ABILITY_NUM, &abilityNum);