From a8a504ef253ca816f108382a13d661a6f7db583a Mon Sep 17 00:00:00 2001 From: Bassoonian Date: Thu, 11 Jan 2024 17:35:31 +0100 Subject: [PATCH] Refactor dex completion (again) (#3937) * Refactor dex completion * Incorporate Alex's requests * rename to dexForceRequired * Revert GetPokedexRatingText argument type * Apply suggestions from code review Co-authored-by: Eduardo Quezada D'Ottone * Revert "Revert GetPokedexRatingText argument type" This reverts commit a9b0c280409196ee0e6cfe170104f45d9e0168a7. * Fix HasAllMons * Fix oops --------- Co-authored-by: Eduardo Quezada D'Ottone --- include/birch_pc.h | 2 +- include/pokemon.h | 3 ++- src/birch_pc.c | 24 +++++++++++------------- src/pokedex.c | 15 ++++++++------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/birch_pc.h b/include/birch_pc.h index 5e0e8d9c16..d5b8cc7e85 100644 --- a/include/birch_pc.h +++ b/include/birch_pc.h @@ -1,6 +1,6 @@ #ifndef GUARD_BIRCH_PC_H #define GUARD_BIRCH_PC_H -const u8 *GetPokedexRatingText(u16 count); +const u8 *GetPokedexRatingText(u32 count); #endif // GUARD_BIRCH_PC_H diff --git a/include/pokemon.h b/include/pokemon.h index 4bfdd4b117..e86d710b37 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -394,7 +394,8 @@ struct SpeciesInfo /*0x8C*/ u32 isPaldeanForm:1; u32 cannotBeTraded:1; u32 allPerfectIVs:1; - u32 padding4:18; + u32 dexForceRequired:1; // This species will be taken into account for Pokédex ratings even if they have the "isMythical" flag set. + u32 padding4:17; // Move Data /* 0x80 */ const struct LevelUpMove *levelUpLearnset; /* 0x84 */ const u16 *teachableLearnset; diff --git a/src/birch_pc.c b/src/birch_pc.c index b656dd1de6..8a6af6bb44 100644 --- a/src/birch_pc.c +++ b/src/birch_pc.c @@ -20,13 +20,6 @@ bool16 ScriptGetPokedexInfo(void) return IsNationalPokedexEnabled(); } -// Species in this array are ignored in the progress towards a full regional dex -static const u16 sRegionalNotCountedList[] = { - SPECIES_JIRACHI, - SPECIES_DEOXYS, - SPECIES_NONE -}; - #define BIRCH_DEX_STRINGS 21 static const u8 *const sBirchDexRatingTexts[BIRCH_DEX_STRINGS] = @@ -55,15 +48,20 @@ static const u8 *const sBirchDexRatingTexts[BIRCH_DEX_STRINGS] = }; // This shows your Hoenn Pokedex rating and not your National Dex. -const u8 *GetPokedexRatingText(u16 count) +const u8 *GetPokedexRatingText(u32 count) { - u32 i; + u32 i, j; u16 maxDex = HOENN_DEX_COUNT - 1; - for(i = 0; sRegionalNotCountedList[i] != SPECIES_NONE; i++) + // doesNotCountForRegionalPokedex + for(i = 0; i < HOENN_DEX_COUNT; i++) { - if (GetSetPokedexFlag(SpeciesToNationalPokedexNum(sRegionalNotCountedList[i]), FLAG_GET_CAUGHT)) - count--; - maxDex--; + j = NationalPokedexNumToSpecies(HoennToNationalOrder(i + 1)); + if (gSpeciesInfo[j].isMythical && !gSpeciesInfo[j].dexForceRequired) + { + if (GetSetPokedexFlag(j, FLAG_GET_CAUGHT)) + count--; + maxDex--; + } } return sBirchDexRatingTexts[(count * (BIRCH_DEX_STRINGS - 1)) / maxDex]; } diff --git a/src/pokedex.c b/src/pokedex.c index 33b7dd02dd..238d418817 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -4379,12 +4379,12 @@ u16 GetKantoPokedexCount(u8 caseID) bool16 HasAllHoennMons(void) { - u16 i; + u32 i, j; - // -2 excludes Jirachi and Deoxys - for (i = 0; i < HOENN_DEX_COUNT - 2; i++) + for (i = 0; i < HOENN_DEX_COUNT; i++) { - if (!GetSetPokedexFlag(HoennToNationalOrder(i + 1), FLAG_GET_CAUGHT)) + j = HoennToNationalOrder(i + 1); + if (!(gSpeciesInfo[j].isMythical && !gSpeciesInfo[j].dexForceRequired) && !GetSetPokedexFlag(j, FLAG_GET_CAUGHT)) return FALSE; } return TRUE; @@ -4392,7 +4392,7 @@ bool16 HasAllHoennMons(void) bool8 HasAllKantoMons(void) { - u16 i; + u32 i; // -1 excludes Mew for (i = 0; i < KANTO_DEX_COUNT - 1; i++) @@ -4405,11 +4405,12 @@ bool8 HasAllKantoMons(void) bool16 HasAllMons(void) { - u16 i; + u32 i, j; for (i = 1; i < NATIONAL_DEX_COUNT + 1; i++) { - if (!(gSpeciesInfo[i].isMythical) && !GetSetPokedexFlag(i, FLAG_GET_CAUGHT)) + j = NationalPokedexNumToSpecies(i); + if (!(gSpeciesInfo[j].isMythical && !gSpeciesInfo[j].dexForceRequired) && !GetSetPokedexFlag(j, FLAG_GET_CAUGHT)) return FALSE; }