From d55f15e57e6bcb5bb3c69a92288e2708a1bb907e Mon Sep 17 00:00:00 2001 From: cawtds Date: Sat, 25 May 2024 14:45:33 +0200 Subject: [PATCH] readded some key item field functions, pokedex refactoring --- data/maps/ViridianCity_Mart/scripts.inc | 13 ++++ include/config/item.h | 2 +- include/constants/pokedex.h | 5 +- include/pokedex.h | 2 - include/pokemon.h | 12 ++-- src/battle_interface.c | 2 +- src/battle_main.c | 2 +- src/battle_script_commands.c | 8 +-- src/battle_tower.c | 2 +- src/data/items.h | 10 +-- src/data/wild_encounters.json | 18 +++--- src/daycare.c | 2 +- src/easy_chat.c | 6 +- src/evolution_scene.c | 12 ++-- src/field_specials.c | 6 +- src/mystery_event_script.c | 2 +- src/pokedex.c | 60 ++++++------------ src/pokedex_screen.c | 60 +++++++++--------- src/pokemon.c | 81 ++++++++++++++----------- src/pokemon_size_record.c | 2 +- src/prof_pc.c | 2 +- src/script_pokemon_util.c | 2 +- src/trade_scene.c | 2 +- 23 files changed, 154 insertions(+), 159 deletions(-) diff --git a/data/maps/ViridianCity_Mart/scripts.inc b/data/maps/ViridianCity_Mart/scripts.inc index ac76d5d99..3ba3b35f4 100644 --- a/data/maps/ViridianCity_Mart/scripts.inc +++ b/data/maps/ViridianCity_Mart/scripts.inc @@ -90,7 +90,18 @@ ViridianCity_Mart_Items:: .2byte ITEM_EXP_CANDY_XL .2byte ITEM_THUNDER_STONE .2byte ITEM_FIRE_STONE + .2byte ITEM_LEAF_STONE + .2byte ITEM_WATER_STONE .2byte ITEM_ICE_STONE + .2byte ITEM_MOON_STONE + .2byte ITEM_SUN_STONE + .2byte ITEM_DRAGON_SCALE + .2byte ITEM_UPGRADE + .2byte ITEM_DUBIOUS_DISC + .2byte ITEM_KINGS_ROCK + .2byte ITEM_PROTECTOR + .2byte ITEM_ELECTIRIZER + .2byte ITEM_MAGMARIZER .2byte ITEM_LINKING_CORD .2byte ITEM_BLACK_AUGURITE .2byte ITEM_METAL_COAT @@ -107,6 +118,8 @@ ViridianCity_Mart_Items:: .2byte ITEM_VENUSAURITE .2byte ITEM_CHARIZARDITE_X .2byte ITEM_CHARIZARDITE_Y + .2byte ITEM_BLASTOISINITE + .2byte ITEM_PIDGEOTITE .2byte ITEM_SILPH_SCOPE .2byte ITEM_DYNAMAX_BAND .2byte ITEM_Z_POWER_RING diff --git a/include/config/item.h b/include/config/item.h index 64b37b4f2..42c0f4435 100644 --- a/include/config/item.h +++ b/include/config/item.h @@ -34,6 +34,6 @@ #define I_REPEL_LURE_MENU TRUE // If TRUE, the player is able to choose which Repel/Lure to use once the previous one runs out. Cursor position is saved by VAR_LAST_REPEL_LURE_USED if not 0. // Vs. Seeker -#define I_VS_SEEKER_CHARGING 0 // If this flag is assigned, the Vs Seeker functionality will be enabled. When the player has the Vs. Seeker, Match Call rematch functions will stop working. +#define I_VS_SEEKER_CHARGING TRUE // If this flag is assigned, the Vs Seeker functionality will be enabled. When the player has the Vs. Seeker, Match Call rematch functions will stop working. #endif // GUARD_CONFIG_ITEM_H diff --git a/include/constants/pokedex.h b/include/constants/pokedex.h index 0d71d50ea..8ab00bfe4 100644 --- a/include/constants/pokedex.h +++ b/include/constants/pokedex.h @@ -1546,12 +1546,13 @@ enum { HOENN_DEX_RAYQUAZA, HOENN_DEX_JIRACHI, HOENN_DEX_DEOXYS, - HOENN_DEX_COUNT, + HOENN_DEX_END, }; #define KANTO_DEX_START KANTO_DEX_BULBASAUR +#define HOENN_DEX_START HOENN_DEX_TREECKO + #define KANTO_DEX_COUNT KANTO_DEX_MEW -#define JOHTO_DEX_COUNT NATIONAL_DEX_CELEBI #define NATIONAL_DEX_START NATIONAL_DEX_BULBASAUR #if P_GEN_9_POKEMON == TRUE diff --git a/include/pokedex.h b/include/pokedex.h index 1095fa7a9..9210cd833 100644 --- a/include/pokedex.h +++ b/include/pokedex.h @@ -113,7 +113,6 @@ struct PokedexEntry /*0x20*/ u16 trainerOffset; }; /*size = 0x24*/ -u16 GetPokedexHeightWeight(u16 dexNum, u8 data); u16 GetNationalPokedexCount(u8); u16 GetKantoPokedexCount(u8); bool16 HasAllMons(void); @@ -124,7 +123,6 @@ bool16 HasAllKantoMons(void); bool16 HasAllMons(void); u8* ConvertMonHeightToString(u32 height); u8* ConvertMonWeightToString(u32 weight); - u8 DexScreen_RegisterMonToPokedex(u16 species); #endif // GUARD_POKEDEX_H diff --git a/include/pokemon.h b/include/pokemon.h index dd053a21e..175171715 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -753,13 +753,13 @@ u8 CanLearnTeachableMove(u16 species, u16 move); u8 GetNature(struct Pokemon *mon); u8 GetNatureFromPersonality(u32 personality); u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem, struct Pokemon *tradePartner); -u16 NationalPokedexNumToSpecies(u16 nationalNum); -u16 SpeciesToNationalPokedexNum(u16 species); +u16 NationalDexNumToSpecies(u16 nationalNum); +u16 SpeciesToNationalDexNum(u16 species); u16 SpeciesToKantoDexNum(u16 species); bool32 IsSpeciesInKantoDex(u16 species); -u16 KantoToNationalOrder(u16 kantoNum); -u16 NationalToKantoOrder(u16 nationalNum); -u16 HoennToNationalOrder(u16 hoennNum); +u16 KantoToNationalDexNum(u16 kantoNum); +u16 NationalToKantoDexNum(u16 nationalNum); +u16 HoennToNationalDexNum(u16 hoennNum); u16 SpeciesToCryId(u16 species); void DrawSpindaSpots(u32 species, u32 personality, u8 *dest, bool8 isFrontPic); void EvolutionRenameMon(struct Pokemon *mon, u16 oldSpecies, u16 newSpecies); @@ -824,5 +824,7 @@ u32 GetUnownSpeciesId(u32 personality); u8 CalculatePartyCount(struct Pokemon *party); u16 GetFirstPartnerMove(u16 species); const u8 *GetMoveName(u16 moveId); +u16 KantoNumToSpecies(u16 kantoNum); +u16 HoennNumToSpecies(u16 hoennNum); #endif // GUARD_POKEMON_H diff --git a/src/battle_interface.c b/src/battle_interface.c index e4d367c4f..68c399635 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1965,7 +1965,7 @@ void TryAddPokeballIconToHealthbox(u8 healthboxSpriteId, bool8 noStatus) return; if (CheckBattleTypeGhost(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId)) return; - if (!GetSetPokedexFlag(SpeciesToNationalPokedexNum(GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES)), FLAG_GET_CAUGHT)) + if (!GetSetPokedexFlag(SpeciesToNationalDexNum(GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES)), FLAG_GET_CAUGHT)) return; healthBarSpriteId = gSprites[healthboxSpriteId].sHealthBarSpriteId; diff --git a/src/battle_main.c b/src/battle_main.c index dcac76ddd..bd84e8ab7 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3161,7 +3161,7 @@ static void DoBattleIntro(void) | BATTLE_TYPE_LEGENDARY)) || ((gBattleTypeFlags & (BATTLE_TYPE_GHOST | BATTLE_TYPE_GHOST_UNVEILED)) && !IS_BATTLE_TYPE_GHOST_WITHOUT_SCOPE(gBattleTypeFlags)))) { - HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[battler].species), FLAG_SET_SEEN, gBattleMons[battler].personality); + HandleSetPokedexFlag(SpeciesToNationalDexNum(gBattleMons[battler].species), FLAG_SET_SEEN, gBattleMons[battler].personality); } } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index cf40ccfa7..7e406949d 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6442,7 +6442,7 @@ static void Cmd_switchinanim(void) | BATTLE_TYPE_POKEDUDE | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_GHOST))) - HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[battler].species), FLAG_SET_SEEN, gBattleMons[battler].personality); + HandleSetPokedexFlag(SpeciesToNationalDexNum(gBattleMons[battler].species), FLAG_SET_SEEN, gBattleMons[battler].personality); gAbsentBattlerFlags &= ~(gBitTable[battler]); @@ -14948,7 +14948,7 @@ static void Cmd_handleballthrow(void) } break; case ITEM_REPEAT_BALL: - if (GetSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gBattlerTarget].species), FLAG_GET_CAUGHT)) + if (GetSetPokedexFlag(SpeciesToNationalDexNum(gBattleMons[gBattlerTarget].species), FLAG_GET_CAUGHT)) ballMultiplier = (B_REPEAT_BALL_MODIFIER >= GEN_7 ? 350 : 300); break; case ITEM_TIMER_BALL: @@ -15207,13 +15207,13 @@ static void Cmd_trysetcaughtmondexflags(void) u32 species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[GetCatchingBattler()]], MON_DATA_SPECIES, NULL); u32 personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[GetCatchingBattler()]], MON_DATA_PERSONALITY, NULL); - if (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT)) + if (GetSetPokedexFlag(SpeciesToNationalDexNum(species), FLAG_GET_CAUGHT)) { gBattlescriptCurrInstr = cmd->failInstr; } else { - HandleSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_SET_CAUGHT, personality); + HandleSetPokedexFlag(SpeciesToNationalDexNum(species), FLAG_SET_CAUGHT, personality); gBattlescriptCurrInstr = cmd->nextInstr; } } diff --git a/src/battle_tower.c b/src/battle_tower.c index 1ac714c94..775d2ccef 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -715,7 +715,7 @@ static void FillBattleTowerTrainerParty(void) static u8 AppendBattleTowerBannedSpeciesName(u16 species, u8 count) { - if (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT)) + if (GetSetPokedexFlag(SpeciesToNationalDexNum(species), FLAG_GET_CAUGHT)) { if (count == 0) StringAppend(gStringVar1, gText_BattleTowerBan_Space); diff --git a/src/data/items.h b/src/data/items.h index 3be03ecda..35714f8b7 100644 --- a/src/data/items.h +++ b/src/data/items.h @@ -10949,7 +10949,7 @@ const struct Item gItemsInfo[] = .importance = 1, .pocket = POCKET_KEY_ITEMS, .type = ITEM_TYPE_FIELD, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, + .fieldUseFunc = ItemUseOutOfBattle_Bike, }, [ITEM_MACH_BIKE] = @@ -11052,7 +11052,7 @@ const struct Item gItemsInfo[] = .importance = 1, .pocket = POCKET_KEY_ITEMS, .type = ITEM_TYPE_BAG_MENU, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, + .fieldUseFunc = ItemUseOutOfBattle_TownMap, }, [ITEM_VS_SEEKER] = @@ -11067,7 +11067,7 @@ const struct Item gItemsInfo[] = .pocket = POCKET_KEY_ITEMS, .type = ITEM_TYPE_FIELD, #if I_VS_SEEKER_CHARGING != 0 - .fieldUseFunc = FieldUseFunc_VsSeeker, + .fieldUseFunc = ItemUseOutOfBattle_VsSeeker, #else .fieldUseFunc = ItemUseOutOfBattle_CannotUse, #endif @@ -11225,7 +11225,7 @@ const struct Item gItemsInfo[] = .importance = 1, .pocket = POCKET_KEY_ITEMS, .type = ITEM_TYPE_BAG_MENU, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, + .fieldUseFunc = ItemUseOutOfBattle_FameChecker, }, [ITEM_TEACHY_TV] = @@ -11239,7 +11239,7 @@ const struct Item gItemsInfo[] = .importance = 1, .pocket = POCKET_KEY_ITEMS, .type = ITEM_TYPE_FIELD, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, + .fieldUseFunc = ItemUseOutOfBattle_TeachyTv, }, // Story Key Items diff --git a/src/data/wild_encounters.json b/src/data/wild_encounters.json index 7e6268138..f900017af 100644 --- a/src/data/wild_encounters.json +++ b/src/data/wild_encounters.json @@ -3596,12 +3596,12 @@ { "min_level": 22, "max_level": 22, - "species": "SPECIES_VOLTORB" + "species": "SPECIES_ELEKID" }, { "min_level": 22, "max_level": 22, - "species": "SPECIES_MAGNEMITE" + "species": "SPECIES_ELEKID" }, { "min_level": 25, @@ -8263,27 +8263,27 @@ { "min_level": 3, "max_level": 3, - "species": "SPECIES_MEW" + "species": "SPECIES_PIDGEY" }, { "min_level": 3, "max_level": 3, - "species": "SPECIES_MEW" + "species": "SPECIES_PIDGEY" }, { "min_level": 3, "max_level": 3, - "species": "SPECIES_MEW" + "species": "SPECIES_PIDGEY" }, { "min_level": 3, "max_level": 3, - "species": "SPECIES_MEW" + "species": "SPECIES_PIDGEY" }, { "min_level": 2, "max_level": 2, - "species": "SPECIES_MEW" + "species": "SPECIES_PIDGEY" }, { "min_level": 2, @@ -13756,7 +13756,7 @@ { "min_level": 32, "max_level": 32, - "species": "SPECIES_RATICATE" + "species": "SPECIES_MAGBY" }, { "min_level": 30, @@ -13766,7 +13766,7 @@ { "min_level": 36, "max_level": 36, - "species": "SPECIES_RATICATE" + "species": "SPECIES_MAGBY" }, { "min_level": 30, diff --git a/src/daycare.c b/src/daycare.c index 457fafd8a..9d2367d2e 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -1656,7 +1656,7 @@ static void AddHatchedMonToParty(u8 id) StringCopy(name, GetSpeciesName(pokeNum)); SetMonData(mon, MON_DATA_NICKNAME, name); - pokeNum = SpeciesToNationalPokedexNum(pokeNum); + pokeNum = SpeciesToNationalDexNum(pokeNum); GetSetPokedexFlag(pokeNum, FLAG_SET_SEEN); GetSetPokedexFlag(pokeNum, FLAG_SET_CAUGHT); diff --git a/src/easy_chat.c b/src/easy_chat.c index 4c1fa5a93..d09003785 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -422,7 +422,7 @@ static u16 GetRandomECPokemon(void) numWords = sEasyChatGroups[EC_GROUP_POKEMON_2].numWords; for (i = 0; i < numWords; i++) { - u16 dexNum = SpeciesToNationalPokedexNum(*species); + u16 dexNum = SpeciesToNationalDexNum(*species); if (GetSetPokedexFlag(dexNum, FLAG_GET_SEEN)) { if (index) @@ -694,10 +694,10 @@ static bool8 UnlockedECMonOrMove(u16 wordIndex, u8 groupId) switch (groupId) { case EC_GROUP_POKEMON: - return GetSetPokedexFlag(SpeciesToNationalPokedexNum(wordIndex), FLAG_GET_SEEN); + return GetSetPokedexFlag(SpeciesToNationalDexNum(wordIndex), FLAG_GET_SEEN); case EC_GROUP_POKEMON_2: if (EC_IsDeoxys(wordIndex)) - return GetSetPokedexFlag(SpeciesToNationalPokedexNum(wordIndex), FLAG_GET_SEEN); + return GetSetPokedexFlag(SpeciesToNationalDexNum(wordIndex), FLAG_GET_SEEN); return TRUE; case EC_GROUP_MOVE_1: case EC_GROUP_MOVE_2: diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 0a4a5077a..ba62937c0 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -577,8 +577,8 @@ static void CreateShedinja(u16 preEvoSpecies, struct Pokemon* mon) CalculateMonStats(&gPlayerParty[gPlayerPartyCount]); CalculatePlayerPartyCount(); - GetSetPokedexFlag(SpeciesToNationalPokedexNum(evolutions[1].targetSpecies), FLAG_SET_SEEN); - GetSetPokedexFlag(SpeciesToNationalPokedexNum(evolutions[1].targetSpecies), FLAG_SET_CAUGHT); + GetSetPokedexFlag(SpeciesToNationalDexNum(evolutions[1].targetSpecies), FLAG_SET_SEEN); + GetSetPokedexFlag(SpeciesToNationalDexNum(evolutions[1].targetSpecies), FLAG_SET_CAUGHT); if (GetMonData(shedinja, MON_DATA_SPECIES) == SPECIES_SHEDINJA && GetMonData(shedinja, MON_DATA_LANGUAGE) == LANGUAGE_JAPANESE @@ -782,8 +782,8 @@ static void Task_EvolutionScene(u8 taskId) SetMonData(mon, MON_DATA_SPECIES, (void *)(&gTasks[taskId].tPostEvoSpecies)); CalculateMonStats(mon); EvolutionRenameMon(mon, gTasks[taskId].tPreEvoSpecies, gTasks[taskId].tPostEvoSpecies); - GetSetPokedexFlag(SpeciesToNationalPokedexNum(gTasks[taskId].tPostEvoSpecies), FLAG_SET_SEEN); - GetSetPokedexFlag(SpeciesToNationalPokedexNum(gTasks[taskId].tPostEvoSpecies), FLAG_SET_CAUGHT); + GetSetPokedexFlag(SpeciesToNationalDexNum(gTasks[taskId].tPostEvoSpecies), FLAG_SET_SEEN); + GetSetPokedexFlag(SpeciesToNationalDexNum(gTasks[taskId].tPostEvoSpecies), FLAG_SET_CAUGHT); IncrementGameStat(GAME_STAT_EVOLVED_POKEMON); } break; @@ -1216,8 +1216,8 @@ static void Task_TradeEvolutionScene(u8 taskId) SetMonData(mon, MON_DATA_SPECIES, (&gTasks[taskId].tPostEvoSpecies)); CalculateMonStats(mon); EvolutionRenameMon(mon, gTasks[taskId].tPreEvoSpecies, gTasks[taskId].tPostEvoSpecies); - GetSetPokedexFlag(SpeciesToNationalPokedexNum(gTasks[taskId].tPostEvoSpecies), FLAG_SET_SEEN); - GetSetPokedexFlag(SpeciesToNationalPokedexNum(gTasks[taskId].tPostEvoSpecies), FLAG_SET_CAUGHT); + GetSetPokedexFlag(SpeciesToNationalDexNum(gTasks[taskId].tPostEvoSpecies), FLAG_SET_SEEN); + GetSetPokedexFlag(SpeciesToNationalDexNum(gTasks[taskId].tPostEvoSpecies), FLAG_SET_CAUGHT); IncrementGameStat(GAME_STAT_EVOLVED_POKEMON); } break; diff --git a/src/field_specials.c b/src/field_specials.c index 63f882686..2ad3bf8ad 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -715,10 +715,10 @@ static u16 SampleResortGorgeousMon(void) for (i = 0; i < 100; i++) { species = (Random() % (NUM_SPECIES - 1)) + 1; - if (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), 0) == TRUE) + if (GetSetPokedexFlag(SpeciesToNationalDexNum(species), 0) == TRUE) return species; } - while (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), 0) != TRUE) + while (GetSetPokedexFlag(SpeciesToNationalDexNum(species), 0) != TRUE) { if (species == SPECIES_BULBASAUR) species = NUM_SPECIES - 1; @@ -1556,7 +1556,7 @@ u16 GetStarterSpecies(void) void SetSeenMon(void) { - GetSetPokedexFlag(SpeciesToNationalPokedexNum(gSpecialVar_0x8004), 2); + GetSetPokedexFlag(SpeciesToNationalDexNum(gSpecialVar_0x8004), 2); } void ResetContextNpcTextColor(void) diff --git a/src/mystery_event_script.c b/src/mystery_event_script.c index d50c09484..60ccf7a07 100644 --- a/src/mystery_event_script.c +++ b/src/mystery_event_script.c @@ -261,7 +261,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx) if (species != SPECIES_EGG) { - u16 pokedexNum = SpeciesToNationalPokedexNum(species); + u16 pokedexNum = SpeciesToNationalDexNum(species); GetSetPokedexFlag(pokedexNum, FLAG_SET_SEEN); GetSetPokedexFlag(pokedexNum, FLAG_SET_CAUGHT); } diff --git a/src/pokedex.c b/src/pokedex.c index 373dda969..634698eba 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -2,19 +2,6 @@ #include "pokedex.h" #include "pokedex_screen.h" -u16 GetPokedexHeightWeight(u16 dexNum, u8 data) -{ - switch (data) - { - case 0: // height - return gSpeciesInfo[dexNum].height; - case 1: // weight - return gSpeciesInfo[dexNum].weight; - default: - return 1; - } -} - s8 GetSetPokedexFlag(u16 nationalDexNo, u8 caseID) { return DexScreen_GetSetPokedexFlag(nationalDexNo, caseID, 0); @@ -25,16 +12,16 @@ u16 GetNationalPokedexCount(u8 caseID) u16 count = 0; u16 i; - for (i = 0; i < NATIONAL_DEX_COUNT; i++) + for (i = NATIONAL_DEX_START; i < NATIONAL_DEX_END; i++) { switch (caseID) { case FLAG_GET_SEEN: - if (GetSetPokedexFlag(i + 1, FLAG_GET_SEEN)) + if (GetSetPokedexFlag(i, FLAG_GET_SEEN)) count++; break; case FLAG_GET_CAUGHT: - if (GetSetPokedexFlag(i + 1, FLAG_GET_CAUGHT)) + if (GetSetPokedexFlag(i, FLAG_GET_CAUGHT)) count++; break; } @@ -48,9 +35,9 @@ u16 GetKantoPokedexCount(u8 caseID) u16 i; u16 nationalNum; - for (i = 1; i < KANTO_DEX_END; i++) + for (i = KANTO_DEX_START; i < KANTO_DEX_END; i++) { - nationalNum = KantoToNationalOrder(i); + nationalNum = KantoToNationalDexNum(i); switch (caseID) { case FLAG_GET_SEEN: @@ -68,25 +55,26 @@ u16 GetKantoPokedexCount(u8 caseID) bool16 HasAllHoennMons(void) { - u16 i; + u16 i, species; - // -2 excludes Jirachi and Deoxys - for (i = 0; i < HOENN_DEX_COUNT - 2; i++) + for (i = HOENN_DEX_START; i < HOENN_DEX_END; i++) { - if (!GetSetPokedexFlag(HoennToNationalOrder(i + 1), FLAG_GET_CAUGHT)) + species = HoennNumToSpecies(i); + if (!gSpeciesInfo[species].isMythical && !GetSetPokedexFlag(HoennToNationalDexNum(i), FLAG_GET_CAUGHT)) return FALSE; + } return TRUE; } bool16 HasAllKantoMons(void) { - u16 i; + u16 i, species; - // -1 excludes Mew for (i = KANTO_DEX_START; i < KANTO_DEX_END; i++) { - if (!GetSetPokedexFlag(KantoToNationalOrder(i), FLAG_GET_CAUGHT)) + species = KantoNumToSpecies(i); + if (!gSpeciesInfo[species].isMythical && !GetSetPokedexFlag(KantoToNationalDexNum(i), FLAG_GET_CAUGHT)) return FALSE; } return TRUE; @@ -94,26 +82,12 @@ bool16 HasAllKantoMons(void) bool16 HasAllMons(void) { - u16 i; + u16 i, species; - // -1 excludes Mew - for (i = 0; i < SPECIES_MEW - 1; i++) + for (i = NATIONAL_DEX_START; i < NATIONAL_DEX_END; i++) { - if (!GetSetPokedexFlag(i + 1, FLAG_GET_CAUGHT)) - return FALSE; - } - - // -3 excludes Lugia, Ho-Oh, and Celebi - for (i = SPECIES_MEW; i < JOHTO_DEX_COUNT - 3; i++) - { - if (!GetSetPokedexFlag(i + 1, FLAG_GET_CAUGHT)) - return FALSE; - } - - // -2 excludes Jirachi and Deoxys - for (i = JOHTO_DEX_COUNT; i < NATIONAL_DEX_COUNT - 2; i++) - { - if (!GetSetPokedexFlag(i + 1, FLAG_GET_CAUGHT)) + species = NationalDexNumToSpecies(i); + if (!gSpeciesInfo[species].isMythical && !GetSetPokedexFlag(i, FLAG_GET_CAUGHT)) return FALSE; } return TRUE; diff --git a/src/pokedex_screen.c b/src/pokedex_screen.c index c7ec5e9bf..bf3267307 100644 --- a/src/pokedex_screen.c +++ b/src/pokedex_screen.c @@ -1391,33 +1391,33 @@ static u16 DexScreen_CountMonsInOrderedList(u8 orderIdx) case DEX_ORDER_NUMERICAL_KANTO: for (i = 0; i < KANTO_DEX_COUNT; i++) { - natDexNum = KantoToNationalOrder(i + 1); + natDexNum = KantoToNationalDexNum(i + KANTO_DEX_START); seen = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_SEEN, FALSE); caught = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_CAUGHT, FALSE); if (seen) { - sPokedexScreenData->listItems[i].label = gSpeciesInfo[NationalPokedexNumToSpecies(natDexNum)].speciesName; + sPokedexScreenData->listItems[i].label = gSpeciesInfo[NationalDexNumToSpecies(natDexNum)].speciesName; ret = i + 1; } else { sPokedexScreenData->listItems[i].label = gText_5Dashes; } - sPokedexScreenData->listItems[i].index = (caught << 17) + (seen << 16) + NationalPokedexNumToSpecies(natDexNum); + sPokedexScreenData->listItems[i].index = (caught << 17) + (seen << 16) + NationalDexNumToSpecies(natDexNum); } break; case DEX_ORDER_ATOZ: for (i = 0; i < ARRAY_COUNT(gPokedexOrder_Alphabetical); i++) { natDexNum = gPokedexOrder_Alphabetical[i]; - if (NATIONAL_DEX_NONE < natDexNum && natDexNum <= NATIONAL_DEX_COUNT && (isNationalDex || NationalToKantoOrder(natDexNum) != KANTO_DEX_NONE)) + if (NATIONAL_DEX_NONE < natDexNum && natDexNum <= NATIONAL_DEX_COUNT && (isNationalDex || NationalToKantoDexNum(natDexNum) != KANTO_DEX_NONE)) { seen = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_SEEN, FALSE); caught = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_CAUGHT, FALSE); if (seen) { - sPokedexScreenData->listItems[ret].label = gSpeciesInfo[NationalPokedexNumToSpecies(natDexNum)].speciesName; - sPokedexScreenData->listItems[ret].index = (caught << 17) + (seen << 16) + NationalPokedexNumToSpecies(natDexNum); + sPokedexScreenData->listItems[ret].label = gSpeciesInfo[NationalDexNumToSpecies(natDexNum)].speciesName; + sPokedexScreenData->listItems[ret].index = (caught << 17) + (seen << 16) + NationalDexNumToSpecies(natDexNum); ret++; } } @@ -1426,15 +1426,15 @@ static u16 DexScreen_CountMonsInOrderedList(u8 orderIdx) case DEX_ORDER_TYPE: for (i = 0; i < ARRAY_COUNT(gPokedexOrder_Type); i++) { - natDexNum = SpeciesToNationalPokedexNum(gPokedexOrder_Type[i]); - if (NATIONAL_DEX_NONE < natDexNum && natDexNum <= NATIONAL_DEX_COUNT && (isNationalDex || NationalToKantoOrder(natDexNum) != KANTO_DEX_NONE)) + natDexNum = SpeciesToNationalDexNum(gPokedexOrder_Type[i]); + if (NATIONAL_DEX_NONE < natDexNum && natDexNum <= NATIONAL_DEX_COUNT && (isNationalDex || NationalToKantoDexNum(natDexNum) != KANTO_DEX_NONE)) { seen = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_SEEN, FALSE); caught = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_CAUGHT, FALSE); if (caught) { - sPokedexScreenData->listItems[ret].label = gSpeciesInfo[NationalPokedexNumToSpecies(natDexNum)].speciesName; - sPokedexScreenData->listItems[ret].index = (caught << 17) + (seen << 16) + NationalPokedexNumToSpecies(natDexNum); + sPokedexScreenData->listItems[ret].label = gSpeciesInfo[NationalDexNumToSpecies(natDexNum)].speciesName; + sPokedexScreenData->listItems[ret].index = (caught << 17) + (seen << 16) + NationalDexNumToSpecies(natDexNum); ret++; } } @@ -1444,14 +1444,14 @@ static u16 DexScreen_CountMonsInOrderedList(u8 orderIdx) for (i = 0; i < ARRAY_COUNT(gPokedexOrder_Weight); i++) { natDexNum = gPokedexOrder_Weight[i]; - if (NATIONAL_DEX_NONE < natDexNum && natDexNum <= NATIONAL_DEX_COUNT && (isNationalDex || NationalToKantoOrder(natDexNum) != KANTO_DEX_NONE)) + if (NATIONAL_DEX_NONE < natDexNum && natDexNum <= NATIONAL_DEX_COUNT && (isNationalDex || NationalToKantoDexNum(natDexNum) != KANTO_DEX_NONE)) { seen = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_SEEN, FALSE); caught = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_CAUGHT, FALSE); if (caught) { - sPokedexScreenData->listItems[ret].label = gSpeciesInfo[NationalPokedexNumToSpecies(natDexNum)].speciesName; - sPokedexScreenData->listItems[ret].index = (caught << 17) + (seen << 16) + NationalPokedexNumToSpecies(natDexNum); + sPokedexScreenData->listItems[ret].label = gSpeciesInfo[NationalDexNumToSpecies(natDexNum)].speciesName; + sPokedexScreenData->listItems[ret].index = (caught << 17) + (seen << 16) + NationalDexNumToSpecies(natDexNum); ret++; } } @@ -1461,14 +1461,14 @@ static u16 DexScreen_CountMonsInOrderedList(u8 orderIdx) for (i = 0; i < ARRAY_COUNT(gPokedexOrder_Height); i++) { natDexNum = gPokedexOrder_Height[i]; - if (NATIONAL_DEX_NONE < natDexNum && natDexNum <= NATIONAL_DEX_COUNT && (isNationalDex || NationalToKantoOrder(natDexNum) != KANTO_DEX_NONE)) + if (NATIONAL_DEX_NONE < natDexNum && natDexNum <= NATIONAL_DEX_COUNT && (isNationalDex || NationalToKantoDexNum(natDexNum) != KANTO_DEX_NONE)) { seen = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_SEEN, FALSE); caught = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_CAUGHT, FALSE); if (caught) { - sPokedexScreenData->listItems[ret].label = gSpeciesInfo[NationalPokedexNumToSpecies(natDexNum)].speciesName; - sPokedexScreenData->listItems[ret].index = (caught << 17) + (seen << 16) + NationalPokedexNumToSpecies(natDexNum); + sPokedexScreenData->listItems[ret].label = gSpeciesInfo[NationalDexNumToSpecies(natDexNum)].speciesName; + sPokedexScreenData->listItems[ret].index = (caught << 17) + (seen << 16) + NationalDexNumToSpecies(natDexNum); ret++; } } @@ -1482,14 +1482,14 @@ static u16 DexScreen_CountMonsInOrderedList(u8 orderIdx) caught = DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_CAUGHT, FALSE); if (seen) { - sPokedexScreenData->listItems[i].label = gSpeciesInfo[NationalPokedexNumToSpecies(natDexNum)].speciesName; + sPokedexScreenData->listItems[i].label = gSpeciesInfo[NationalDexNumToSpecies(natDexNum)].speciesName; ret = natDexNum; } else { sPokedexScreenData->listItems[i].label = gText_5Dashes; } - sPokedexScreenData->listItems[i].index = (caught << 17) + (seen << 16) + NationalPokedexNumToSpecies(natDexNum); + sPokedexScreenData->listItems[i].index = (caught << 17) + (seen << 16) + NationalDexNumToSpecies(natDexNum); } break; } @@ -2240,13 +2240,13 @@ static void DexScreen_PrintMonDexNo(u8 windowId, u8 fontId, u16 species, u8 x, u xNum = x + 9; if (isKantoNum) { - dexNum = NationalToKantoOrder(SpeciesToNationalPokedexNum(species)); + dexNum = NationalToKantoDexNum(SpeciesToNationalDexNum(species)); DexScreen_AddTextPrinterParameterized(windowId, fontId, gText_PokedexNo, x, y, 0); DexScreen_PrintNum3LeadingZeroes(windowId, fontId, dexNum, xNum, y, 0); } else { - dexNum = SpeciesToNationalPokedexNum(species); + dexNum = SpeciesToNationalDexNum(species); DexScreen_AddTextPrinterParameterized(windowId, fontId, gText_PokedexNo, x, y, 0); DexScreen_PrintNum4LeadingZeroes(windowId, fontId, dexNum, xNum, y, 0); } @@ -2260,7 +2260,7 @@ s8 DexScreen_GetSetPokedexFlag(u16 nationalDexNo, u8 caseId, bool8 indexIsSpecie s8 retVal; if (indexIsSpecies) - nationalDexNo = SpeciesToNationalPokedexNum(nationalDexNo); + nationalDexNo = SpeciesToNationalDexNum(nationalDexNo); nationalDexNo--; index = nationalDexNo / 8; @@ -2311,7 +2311,7 @@ static u16 DexScreen_GetDexCount(u8 caseId, bool8 whichDex) case 0: // Kanto for (i = KANTO_DEX_START; i < KANTO_DEX_END; i++) { - if (DexScreen_GetSetPokedexFlag(KantoToNationalOrder(i), caseId, FALSE)) + if (DexScreen_GetSetPokedexFlag(KantoToNationalDexNum(i), caseId, FALSE)) count++; } break; @@ -2703,7 +2703,7 @@ void DexScreen_PrintMonCategory(u8 windowId, u16 species, u8 x, u8 y) { u8 * categoryName; u8 index, categoryStr[12]; - u16 natDexNum = SpeciesToNationalPokedexNum(species); + u16 natDexNum = SpeciesToNationalDexNum(species); categoryName = (u8 *)gSpeciesInfo[species].categoryName; index = 0; @@ -2739,7 +2739,7 @@ void DexScreen_PrintMonHeight(u8 windowId, u16 species, u8 x, u8 y) { u8* heightString; - if (DexScreen_GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT, FALSE)) + if (DexScreen_GetSetPokedexFlag(SpeciesToNationalDexNum(species), FLAG_GET_CAUGHT, FALSE)) heightString = ConvertMonHeightToString(gSpeciesInfo[species].height); else heightString = GetUnknownMonHeightString(); @@ -2844,7 +2844,7 @@ void DexScreen_PrintMonWeight(u8 windowId, u16 species, u8 x, u8 y) { u8* weightString; - if (DexScreen_GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT, FALSE)) + if (DexScreen_GetSetPokedexFlag(SpeciesToNationalDexNum(species), FLAG_GET_CAUGHT, FALSE)) weightString = ConvertMonWeightToString(gSpeciesInfo[species].weight); else weightString = GetUnknownMonWeightString(); @@ -2973,7 +2973,7 @@ void DexScreen_PrintMonFlavorText(u8 windowId, u16 species, u8 x, u8 y) struct TextPrinterTemplate printerTemplate; u16 length; s32 xCenter; - u16 natDexNum = SpeciesToNationalPokedexNum(species); + u16 natDexNum = SpeciesToNationalDexNum(species); if (DexScreen_GetSetPokedexFlag(natDexNum, FLAG_GET_CAUGHT, FALSE)) { @@ -3105,7 +3105,7 @@ u8 DexScreen_DrawMonAreaPage(void) u16 kantoMapVoff; species = sPokedexScreenData->dexSpecies; - natDexNum = SpeciesToNationalPokedexNum(species); + natDexNum = SpeciesToNationalDexNum(species); monIsCaught = DexScreen_GetSetPokedexFlag(species, FLAG_GET_CAUGHT, TRUE); width = 28; height = 14; @@ -3282,7 +3282,7 @@ u8 DexScreen_DestroyAreaScreenResources(void) static bool32 DexScreen_MonHasCategoryEntry(u16 species) { u16 i, j, k; - u16 natDexNum = SpeciesToNationalPokedexNum(species); + u16 natDexNum = SpeciesToNationalDexNum(species); for (i = 0; i < NELEMS(gDexCategories); i++) { @@ -3291,7 +3291,7 @@ static bool32 DexScreen_MonHasCategoryEntry(u16 species) for (k = 0; k < gDexCategories[i].page[j].count; k++) { u16 pageSpecies = gDexCategories[i].page[j].species[k]; - if (SpeciesToNationalPokedexNum(pageSpecies) == natDexNum) + if (SpeciesToNationalDexNum(pageSpecies) == natDexNum) return TRUE; } } @@ -3402,7 +3402,7 @@ static u8 DexScreen_LookUpCategoryBySpecies(u16 species) for (k = 0, posInPage = 0; k < categoryPageCount; k++) { dexSpecies = gDexCategories[i].page[j].species[k]; - if (SpeciesToNationalPokedexNum(species) == SpeciesToNationalPokedexNum(dexSpecies)) + if (SpeciesToNationalDexNum(species) == SpeciesToNationalDexNum(dexSpecies)) { sPokedexScreenData->category = i; sPokedexScreenData->pageNum = j; diff --git a/src/pokemon.c b/src/pokemon.c index 51b1a8f1d..f9e5c8291 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4455,43 +4455,41 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, s return targetSpecies; } -u16 NationalPokedexNumToSpecies(u16 nationalNum) +u16 NationalDexNumToSpecies(u16 nationalNum) { u16 species; if (!nationalNum) - return 0; + return SPECIES_NONE; - species = 1; - - while (species < NUM_SPECIES && gSpeciesInfo[species].natDexNum != nationalNum) - species++; - - if (species == NUM_SPECIES) - return NATIONAL_DEX_NONE; - - return species; + for (species = 1; species < NUM_SPECIES; species++) + { + if (gSpeciesInfo[species].natDexNum == nationalNum) + return species; + } + return SPECIES_NONE; } -static u16 NationalToHoennOrder(u16 nationalNum) +static u16 NationalToHoennOrder(u16 natDexNum) { - u16 hoennNum; + u16 i; - if (!nationalNum) - return 0; + if (natDexNum == 0) + { + return HOENN_DEX_NONE; + } - hoennNum = 0; - - while (hoennNum < (HOENN_DEX_COUNT - 1) && sHoennToNationalOrder[hoennNum] != nationalNum) - hoennNum++; - - if (hoennNum >= HOENN_DEX_COUNT - 1) - return 0; - - return hoennNum + 1; + for (i = HOENN_DEX_START; i < HOENN_DEX_END; i++) + { + if (sHoennToNationalOrder[i] == natDexNum) + { + return i; + } + } + return HOENN_DEX_NONE; } -u16 SpeciesToNationalPokedexNum(u16 species) +u16 SpeciesToNationalDexNum(u16 species) { if (!species) return NATIONAL_DEX_NONE; @@ -4499,7 +4497,7 @@ u16 SpeciesToNationalPokedexNum(u16 species) return gSpeciesInfo[species].natDexNum; } -u16 NationalToKantoOrder(u16 natDexNum) +u16 NationalToKantoDexNum(u16 natDexNum) { u16 i; @@ -4520,7 +4518,7 @@ u16 NationalToKantoOrder(u16 natDexNum) u16 SpeciesToKantoDexNum(u16 species) { - return NationalToKantoOrder(SpeciesToNationalPokedexNum(species)); + return NationalToKantoDexNum(SpeciesToNationalDexNum(species)); } bool32 IsSpeciesInKantoDex(u16 species) @@ -4528,19 +4526,28 @@ bool32 IsSpeciesInKantoDex(u16 species) return SpeciesToKantoDexNum(species) != KANTO_DEX_NONE; } -u16 KantoToNationalOrder(u16 kantoNum) +u16 KantoToNationalDexNum(u16 kantoNum) { - if (KANTO_DEX_NONE < kantoNum && kantoNum < KANTO_DEX_END) + if (KANTO_DEX_START <= kantoNum && kantoNum < KANTO_DEX_END) return sKantoDexNumToNationalDexNum[kantoNum]; return NATIONAL_DEX_NONE; } -u16 HoennToNationalOrder(u16 hoennNum) +u16 KantoNumToSpecies(u16 kantoNum) { - if (!hoennNum || hoennNum >= HOENN_DEX_COUNT) - return 0; + return NationalDexNumToSpecies(KantoToNationalDexNum(kantoNum)); +} - return sHoennToNationalOrder[hoennNum - 1]; +u16 HoennToNationalDexNum(u16 hoennNum) +{ + if (HOENN_DEX_START <= hoennNum && hoennNum < HOENN_DEX_END) + return sHoennToNationalOrder[hoennNum]; + return NATIONAL_DEX_NONE; +} + +u16 HoennNumToSpecies(u16 hoennNum) +{ + return NationalDexNumToSpecies(HoennToNationalDexNum(hoennNum)); } u16 SpeciesToCryId(u16 species) @@ -5278,10 +5285,10 @@ u8 GetNumberOfRelearnableMoves(struct Pokemon *mon) u16 SpeciesToPokedexNum(u16 species) { - species = SpeciesToNationalPokedexNum(species); + species = SpeciesToNationalDexNum(species); if (!IsNationalPokedexEnabled()) { - species = NationalToKantoOrder(species); + species = NationalToKantoDexNum(species); } return species > 0 ? species : 0xFFFF; } @@ -5684,9 +5691,9 @@ void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality) if (!GetSetPokedexFlag(nationalNum, getFlagCaseId)) { GetSetPokedexFlag(nationalNum, caseId); - if (NationalPokedexNumToSpecies(nationalNum) == SPECIES_UNOWN) + if (NationalDexNumToSpecies(nationalNum) == SPECIES_UNOWN) gSaveBlock2Ptr->pokedex.unownPersonality = personality; - if (NationalPokedexNumToSpecies(nationalNum) == SPECIES_SPINDA) + if (NationalDexNumToSpecies(nationalNum) == SPECIES_SPINDA) gSaveBlock2Ptr->pokedex.spindaPersonality = personality; } } diff --git a/src/pokemon_size_record.c b/src/pokemon_size_record.c index 150a7fa4b..8dfc9ff6c 100644 --- a/src/pokemon_size_record.c +++ b/src/pokemon_size_record.c @@ -79,7 +79,7 @@ static u32 GetMonSize(u16 species, u16 b) u32 height; u32 var; - height = GetPokedexHeightWeight(SpeciesToNationalPokedexNum(species), 0); + height = GetSpeciesHeight(species); var = TranslateBigMonSizeTableIndex(b); unk0 = sBigMonSizeTable[var].unk0; unk2 = sBigMonSizeTable[var].unk2; diff --git a/src/prof_pc.c b/src/prof_pc.c index 93d8b97f2..148c6cd71 100644 --- a/src/prof_pc.c +++ b/src/prof_pc.c @@ -87,7 +87,7 @@ static const u8 *GetProfOaksRatingMessageByCount(u16 count) if (count == KANTO_DEX_COUNT - 1) { // Mew doesn't count for completing the pokedex - if (GetSetPokedexFlag(SpeciesToNationalPokedexNum(SPECIES_MEW), 1)) + if (GetSetPokedexFlag(SpeciesToNationalDexNum(SPECIES_MEW), 1)) return PokedexRating_Text_LessThan150; gSpecialVar_Result = TRUE; diff --git a/src/script_pokemon_util.c b/src/script_pokemon_util.c index bc11dc001..31cc39d3a 100644 --- a/src/script_pokemon_util.c +++ b/src/script_pokemon_util.c @@ -57,7 +57,7 @@ u8 ScriptGiveMon(u16 species, u8 level, u16 item, u32 unused1, u32 unused2, u8 u heldItem[1] = item >> 8; SetMonData(mon, MON_DATA_HELD_ITEM, heldItem); sentToPc = GiveMonToPlayer(mon); - nationalDexNum = SpeciesToNationalPokedexNum(species); + nationalDexNum = SpeciesToNationalDexNum(species); switch(sentToPc) { diff --git a/src/trade_scene.c b/src/trade_scene.c index 526c5db51..325a2c4c8 100644 --- a/src/trade_scene.c +++ b/src/trade_scene.c @@ -1033,7 +1033,7 @@ static void UpdatePokedexForReceivedMon(u8 partyIdx) { u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); - species = SpeciesToNationalPokedexNum(species); + species = SpeciesToNationalDexNum(species); GetSetPokedexFlag(species, FLAG_SET_SEEN); HandleSetPokedexFlag(species, FLAG_SET_CAUGHT, personality); }