From f0bbbe29938600df2e8f2cc28eb181121f94c268 Mon Sep 17 00:00:00 2001 From: h2o-DS Date: Sat, 26 Oct 2024 19:39:34 -0400 Subject: [PATCH] Cleaned up PokedexEncData Renamed ov21_021D57B4 to PokedexEncData Moved structs DungeonCoordinates, FieldCoordinates, and EncounterLocations to PokedexEncData.h Moved enum PokedexEncFileIndex to the c file. Created comment descriptions for PokedexEncData --- include/overlay021/ov21_021D57B4.h | 43 ---- include/overlay021/pokedexencdata.h | 155 +++++++++++++++ .../overlay021/struct_dungeoncoordinates.h | 11 -- include/overlay021/struct_fieldcoordinates.h | 12 -- include/overlay021/struct_ov21_021D5844.h | 9 - include/overlay021/struct_ov21_021E6B20.h | 4 +- platinum.us/main.lsf | 2 +- src/meson.build | 2 +- src/overlay021/ov21_021D57B4.c | 180 ----------------- src/overlay021/ov21_021DC9BC.c | 57 +++--- src/overlay021/pokedexencdata.c | 183 ++++++++++++++++++ 11 files changed, 370 insertions(+), 288 deletions(-) delete mode 100644 include/overlay021/ov21_021D57B4.h create mode 100644 include/overlay021/pokedexencdata.h delete mode 100644 include/overlay021/struct_dungeoncoordinates.h delete mode 100644 include/overlay021/struct_fieldcoordinates.h delete mode 100644 include/overlay021/struct_ov21_021D5844.h delete mode 100644 src/overlay021/ov21_021D57B4.c create mode 100644 src/overlay021/pokedexencdata.c diff --git a/include/overlay021/ov21_021D57B4.h b/include/overlay021/ov21_021D57B4.h deleted file mode 100644 index d957302ff1..0000000000 --- a/include/overlay021/ov21_021D57B4.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef POKEPLATINUM_OV21_021D57B4_H -#define POKEPLATINUM_OV21_021D57B4_H - -#include "overlay021/struct_dungeoncoordinates.h" -#include "overlay021/struct_fieldCoordinates.h" -#include "overlay021/struct_ov21_021D5844.h" - -#include "cell_actor.h" - -#define PEFI_DUNGEONMORNING 4 -#define PEFI_DUNGEONDAY (4 + MAX_SPECIES) -#define PEFI_DUNGEONNIGHT (4 + MAX_SPECIES * 2) -#define PEFI_DUNGEONSPECIAL (4 + MAX_SPECIES * 3) -#define PEFI_DUNGEONSPECIALNATDEX (4 + MAX_SPECIES * 4) -#define PEFI_FIELDMORNING (4 + MAX_SPECIES * 5) -#define PEFI_FIELDDAY (4 + MAX_SPECIES * 6) -#define PEFI_FIELDNIGHT (4 + MAX_SPECIES * 7) -#define PEFI_FIELDSPECIAL (4 + MAX_SPECIES * 8) -#define PEFI_FIELDSPECIALNATDEX (4 + MAX_SPECIES * 9) - -enum PokedexEncFileCatgegory { - PEFC_DUNGEONMORNING = 0, - PEFC_DUNGEONDAY = 1, - PEFC_DUNGEONNIGHT = 2, - PEFC_DUNGEONSPECIAL = 3, - PEFC_DUNGEONSPECIALNATDEX = 4, - PEFC_FIELDMORNING = 5, - PEFC_FIELDDAY = 6, - PEFC_FIELDNIGHT = 7, - PEFC_FIELDSPECIAL = 8, - PEFC_FIELDSPECIALNATDEX = 9, -}; - -void PokedexEncData_PopulateMapsEncounteredOn(mapsEncounteredOn *mapsEncOn, int species, int encounterCategory, int heapID); -void PokedexEncData_FreeMapsEncounteredOn(mapsEncounteredOn *mapsEncOn); -dungeonCoordinates *PokedexEncData_GetDungeonLocations(int heapID, int *numDungeons); -fieldCoordinates *PokedexEncData_GetFieldLocations(int heapID, int *numFields); -void ov21_021D58C0(u8 *param0, u8 param1, u8 param2, const fieldCoordinates *param3); -u32 ov21_021D5948(u8 *param0, int param1, int param2, const fieldCoordinates *param3, const mapsEncounteredOn *mapsEncOn, const u8 *param5, u32 param6); -void ov21_021D59D8(CellActor *param0, int param1, int param2, int param3, int param4, const dungeonCoordinates *param5, int param6, int param7); -int ov21_021D5A20(CellActor **param0, int param1, int param2, int param3, int param4, int param5, int param6, const dungeonCoordinates *param7, const mapsEncounteredOn *mapsEncOn, int param9, int param10, const u8 *param11, u32 param12, u32 *param13); - -#endif // POKEPLATINUM_OV21_021D57B4_H diff --git a/include/overlay021/pokedexencdata.h b/include/overlay021/pokedexencdata.h new file mode 100644 index 0000000000..692929c617 --- /dev/null +++ b/include/overlay021/pokedexencdata.h @@ -0,0 +1,155 @@ +#ifndef POKEPLATINUM_POKEDEXENCDATA_H +#define POKEPLATINUM_POKEDEXENCDATA_H + +#include "constants/species.h" + +#include "cell_actor.h" + +typedef struct { + int *locations; + int numLocations; +} EncounterLocations; + +typedef struct { + u8 x; + u8 y; + u8 isMtCoronet; + u8 unused; +} DungeonCoordinates; + +typedef struct { + u8 y; + u8 x; + u8 height; + u8 width; + u8 cellMatrix[32]; +} FieldCoordinates; + +enum PokedexEncFileCatgegory { + PEFC_DUNGEONMORNING = 0, + PEFC_DUNGEONDAY = 1, + PEFC_DUNGEONNIGHT = 2, + PEFC_DUNGEONSPECIAL = 3, + PEFC_DUNGEONSPECIALNATDEX = 4, + PEFC_FIELDMORNING = 5, + PEFC_FIELDDAY = 6, + PEFC_FIELDNIGHT = 7, + PEFC_FIELDSPECIAL = 8, + PEFC_FIELDSPECIALNATDEX = 9, +}; + +/** + * @brief Reads species encounter data from zukan_enc_platinum.narc + * + * encounterLocations is populated with the value and length of the file + * corresponding to the provided species and encounter. + * + * @param encounterLocations + * @param species + * @param encounterCategory + * @param heapID + */ +void PokedexEncData_PopulateEncounterLocations(EncounterLocations *encounterLocations, int species, int encounterCategory, int heapID); + +/** + * @brief Frees encounter data from the heap + * + * @param encounterLocations + */ +void PokedexEncData_FreeEncounterLocations(EncounterLocations *encounterLocations); + +/** + * @brief Reads dungeon coordinates data from zukan_enc_platinum.narc + * + * The first file in zukan_enc_platinum contains the location of each dungeon. + * numDungeons is only set if not passed as null. + * + * @param heapID + * @param numDungeons + * @return Array of coordinates for each dungeon + */ +DungeonCoordinates *PokedexEncData_GetDungeonCoordinates(int heapID, int *numDungeons); + +/** + * @brief Reads field coordinates data from zukan_enc_platinum.narc + * + * The third file in zukan_enc_platinum contains the location and shape of each field. + * numFields is only set if not passed as null. + * + * @param heapID + * @param numFields + * @return Array of coordinates for each field + */ +FieldCoordinates *PokedexEncData_GetFieldCoordinates(int heapID, int *numFields); + +/** + * @brief Updates fieldMap with the coordinates occupied by the field + * + * pokedexFieldMap is a 1D array treated like a 2D array for map purposes. + * Each coordinate occupied by the passed field will become 1 on the map. + * + * @param pokedexFieldMap + * @param mapHeight + * @param mapWidth + * @param fieldCoordinates + */ +void PokedexEncData_LocateFieldOnMap(u8 *pokedexFieldMap, u8 mapHeight, u8 mapWidth, const FieldCoordinates *fieldCoordinates); + +/** + * @brief Updates fieldMap with the coordinates occupied by visible fields + * + * Calls PokedexEncData_LocateFieldOnMap() for each field in encounterLocations not in invisibleFields. + * + * @param pokedexFieldMap + * @param mapHeight + * @param mapWidth + * @param fieldCoordinatesArray + * @param encounterLocations + * @param invisibleFields + * @param numInvisibleFields + * @return Number of visible fields + */ +u32 PokedexEncData_LocateVisibleFields(u8 *pokedexFieldMap, int mapHeight, int mapWidth, const FieldCoordinates *fieldCoordinatesArray, const EncounterLocations *encounterLocations, const u8 *invisibleFields, u32 numInvisibleFields); + +/** + * @brief Creates a CellActor with the coordinates occupied by the dungeon + * + * coronetAnimID is used for Mt Coronet, animID otherwise. + * + * @param cellActor + * @param xOffset + * @param yOffset + * @param xScale + * @param yScale + * @param dungeonCoordinates + * @param animID + * @param coronetAnimID + */ +void PokedexEncData_LocateDungeonOnMap(CellActor *cellActor, int xOffset, int yOffset, int xScale, int yScale, const DungeonCoordinates *dungeonCoordinates, int animID, int coronetAnimID); + +/** + * @brief Creates CellActors with the coordinates occupied by visible fields + * + * Calls PokedexEncData_LocateDungeonOnMap() for each dungeon in encounterLocations not in invisibleDungeons. + * cellActorsModified is set to the number of PokedexEncData_LocateDungeonOnMap() calls. + * The returned value = (cellActorsModified + initialNumVisibleDungeons) + * + * @param cellActorArray + * @param initialNumVisibleDungeons + * @param maxNumDungeons + * @param xOffset + * @param yOffset + * @param xScale + * @param yScale + * @param dungeonCoordinatesArray + * @param encounterLocations + * @param animID + * @param coronetAnimID + * @param invisibleDungeons + * @param numInvisibleDungeons + * @param cellActorsModified + * @return Number of visible dungeons + */ +int PokedexEncData_LocateVisibleDungeons(CellActor **cellActorArray, int initialNumVisibleDungeons, int maxNumDungeons, int xOffset, int yOffset, int xScale, int yScale, const DungeonCoordinates *dungeonCoordinatesArray, const EncounterLocations *encounterLocations, int animID, int coronetAnimID, const u8 *invisibleDungeons, u32 numInvisibleDungeons, u32 *cellActorsModified); + +#endif // POKEPLATINUM_POKEDEXENCDATA_H diff --git a/include/overlay021/struct_dungeoncoordinates.h b/include/overlay021/struct_dungeoncoordinates.h deleted file mode 100644 index 02b9851d21..0000000000 --- a/include/overlay021/struct_dungeoncoordinates.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_DUNGEONCOORDINATES_H -#define POKEPLATINUM_STRUCT_DUNGEONCOORDINATES_H - -typedef struct { - u8 xCoordinate; - u8 yCoordinate; - u8 isMtCoronet; - u8 unused; -} dungeonCoordinates; - -#endif // POKEPLATINUM_STRUCT_DUNGEONCOORDINATES_H diff --git a/include/overlay021/struct_fieldcoordinates.h b/include/overlay021/struct_fieldcoordinates.h deleted file mode 100644 index 215945648e..0000000000 --- a/include/overlay021/struct_fieldcoordinates.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_FIELDCOORDINATES_H -#define POKEPLATINUM_STRUCT_FIELDCOORDINATES_H - -typedef struct { - u8 yCoordinate; - u8 xCoordinate; - u8 height; - u8 width; - u8 cellMatrix[32]; -} fieldCoordinates; - -#endif // POKEPLATINUM_STRUCT_FIELDCOORDINATES_H diff --git a/include/overlay021/struct_ov21_021D5844.h b/include/overlay021/struct_ov21_021D5844.h deleted file mode 100644 index d70e3458e0..0000000000 --- a/include/overlay021/struct_ov21_021D5844.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV21_021D5844_H -#define POKEPLATINUM_STRUCT_OV21_021D5844_H - -typedef struct { - int *mapsEncounteredOnArray; - int numMapsEncounteredOn; -} mapsEncounteredOn; - -#endif // POKEPLATINUM_STRUCT_OV21_021D5844_H diff --git a/include/overlay021/struct_ov21_021E6B20.h b/include/overlay021/struct_ov21_021E6B20.h index c247a40f40..bd792f2669 100644 --- a/include/overlay021/struct_ov21_021E6B20.h +++ b/include/overlay021/struct_ov21_021E6B20.h @@ -1,9 +1,11 @@ #ifndef POKEPLATINUM_STRUCT_OV21_021E6B20_H #define POKEPLATINUM_STRUCT_OV21_021E6B20_H +#include "heap.h" + typedef struct { int unk_00; - int heapID; + enum HeapId heapID; void *unk_08; } UnkStruct_ov21_021E6B20; diff --git a/platinum.us/main.lsf b/platinum.us/main.lsf index e297dc0e23..967feeccac 100644 --- a/platinum.us/main.lsf +++ b/platinum.us/main.lsf @@ -794,7 +794,7 @@ Overlay overlay21 Object main.nef.p/src_overlay021_ov21_021D4EE4.c.o Object main.nef.p/src_overlay021_ov21_021D517C.c.o Object main.nef.p/src_overlay021_ov21_021D5600.c.o - Object main.nef.p/src_overlay021_ov21_021D57B4.c.o + Object main.nef.p/src_overlay021_pokedexencdata.c.o Object main.nef.p/src_overlay021_ov21_021D5AEC.c.o Object main.nef.p/src_overlay021_ov21_021D76B0.c.o Object main.nef.p/src_overlay021_ov21_021D85B0.c.o diff --git a/src/meson.build b/src/meson.build index 5fdcddea9f..638207dedb 100644 --- a/src/meson.build +++ b/src/meson.build @@ -605,7 +605,7 @@ pokeplatinum_c = files( 'overlay021/ov21_021D4EE4.c', 'overlay021/ov21_021D517C.c', 'overlay021/ov21_021D5600.c', - 'overlay021/ov21_021D57B4.c', + 'overlay021/pokedexencdata.c', 'overlay021/ov21_021D5AEC.c', 'overlay021/ov21_021D76B0.c', 'overlay021/ov21_021D85B0.c', diff --git a/src/overlay021/ov21_021D57B4.c b/src/overlay021/ov21_021D57B4.c deleted file mode 100644 index adb2bc30a0..0000000000 --- a/src/overlay021/ov21_021D57B4.c +++ /dev/null @@ -1,180 +0,0 @@ -#include "overlay021/ov21_021D57B4.h" - -#include -#include - -#include "constants/species.h" - -#include "overlay021/struct_dungeoncoordinates.h" -#include "overlay021/struct_fieldCoordinates.h" -#include "overlay021/struct_ov21_021D5844.h" - -#include "cell_actor.h" -#include "graphics.h" -#include "heap.h" -#include "narc.h" - -void PokedexEncData_PopulateMapsEncounteredOn(mapsEncounteredOn *mapsEncOn, int species, int encounterCategory, int heapID) -{ - int fileIndex; - u32 fileSize; - - switch (encounterCategory) { - case PEFC_DUNGEONMORNING: - fileIndex = PEFI_DUNGEONMORNING; - break; - case PEFC_DUNGEONDAY: - fileIndex = PEFI_DUNGEONDAY; - break; - case PEFC_DUNGEONNIGHT: - fileIndex = PEFI_DUNGEONNIGHT; - break; - case PEFC_DUNGEONSPECIAL: - fileIndex = PEFI_DUNGEONSPECIAL; - break; - case PEFC_DUNGEONSPECIALNATDEX: - fileIndex = PEFI_DUNGEONSPECIALNATDEX; - break; - case PEFC_FIELDMORNING: - fileIndex = PEFI_FIELDMORNING; - break; - case PEFC_FIELDDAY: - fileIndex = PEFI_FIELDDAY; - break; - case PEFC_FIELDNIGHT: - fileIndex = PEFI_FIELDNIGHT; - break; - case PEFC_FIELDSPECIAL: - fileIndex = PEFI_FIELDSPECIAL; - break; - case PEFC_FIELDSPECIALNATDEX: - fileIndex = PEFI_FIELDSPECIALNATDEX; - break; - } - - mapsEncOn->mapsEncounteredOnArray = (int *)LoadMemberFromNARC_OutFileSize(NARC_INDEX_APPLICATION__ZUKANLIST__ZKN_DATA__ZUKAN_ENC_PLATINUM, fileIndex + species, 0, heapID, 0, &fileSize); - mapsEncOn->numMapsEncounteredOn = fileSize / sizeof(int); -} - -void PokedexEncData_FreeMapsEncounteredOn(mapsEncounteredOn *mapsEncOn) -{ - GF_ASSERT(mapsEncOn); - GF_ASSERT(mapsEncOn->mapsEncounteredOnArray); - - Heap_FreeToHeap(mapsEncOn->mapsEncounteredOnArray); - - mapsEncOn->mapsEncounteredOnArray = NULL; - mapsEncOn->numMapsEncounteredOn = 0; -} - -dungeonCoordinates *PokedexEncData_GetDungeonLocations(int heapID, int *numDungeons) -{ - dungeonCoordinates *dungeonCoordinatesArray; - u32 fileSize; - - dungeonCoordinatesArray = (dungeonCoordinates *)LoadMemberFromNARC_OutFileSize(NARC_INDEX_APPLICATION__ZUKANLIST__ZKN_DATA__ZUKAN_ENC_PLATINUM, 0, 0, heapID, 0, &fileSize); - - if (numDungeons) { - *numDungeons = fileSize / sizeof(dungeonCoordinates); - } - - return dungeonCoordinatesArray; -} - -fieldCoordinates *PokedexEncData_GetFieldLocations(int heapID, int *numFields) -{ - fieldCoordinates *fieldCoordinatesArray; - u32 fileSize; - - fieldCoordinatesArray = (fieldCoordinates *)LoadMemberFromNARC_OutFileSize(NARC_INDEX_APPLICATION__ZUKANLIST__ZKN_DATA__ZUKAN_ENC_PLATINUM, 2, 0, heapID, 0, &fileSize); - - if (numFields) { - *numFields = fileSize / sizeof(fieldCoordinates); - } - - return fieldCoordinatesArray; -} - -void ov21_021D58C0(u8 *mapFieldCellMatrix, u8 mapHeight, u8 mapWidth, const fieldCoordinates *fieldCoords) -{ - int xCoord, yCoord; - - GF_ASSERT((fieldCoords->xCoordinate + fieldCoords->width) < mapWidth); // param 1 and 2 are 30 - GF_ASSERT((fieldCoords->yCoordinate + fieldCoords->height) < mapHeight); - - for (xCoord = fieldCoords->xCoordinate; xCoord < fieldCoords->xCoordinate + fieldCoords->width; xCoord++) { - for (yCoord = fieldCoords->yCoordinate; yCoord < fieldCoords->yCoordinate + fieldCoords->height; yCoord++) { - mapFieldCellMatrix[(xCoord * mapHeight) + yCoord] |= fieldCoords->cellMatrix[((xCoord - fieldCoords->xCoordinate) * fieldCoords->height) + (yCoord - fieldCoords->yCoordinate)]; - } - } -} - -u32 ov21_021D5948(u8 *mapFieldCellMatrix, int mapHeight, int mapWidth, const fieldCoordinates *fieldCoordArray, const mapsEncounteredOn *mapsEncOn, const u8 *fieldIDArray, u32 fieldIDArrayLength) -{ - int fieldIndex; - int fieldIDArrayIndex; - u32 v2 = 0; - - for (fieldIndex = 0; fieldIndex < mapsEncOn->numMapsEncounteredOn - 1; fieldIndex++) { - GF_ASSERT(mapsEncOn->mapsEncounteredOnArray[fieldIndex]); - - for (fieldIDArrayIndex = 0; fieldIDArrayIndex < fieldIDArrayLength; fieldIDArrayIndex++) { - if (mapsEncOn->mapsEncounteredOnArray[fieldIndex] == fieldIDArray[fieldIDArrayIndex]) { - break; - } - } - - if (fieldIDArrayIndex >= fieldIDArrayLength) { - ov21_021D58C0(mapFieldCellMatrix, mapHeight, mapWidth, &fieldCoordArray[mapsEncOn->mapsEncounteredOnArray[fieldIndex]]); - v2++; - } - } - - return v2; -} - -void ov21_021D59D8(CellActor *actor, int xOffset, int yOffset, int xScale, int yScale, const dungeonCoordinates *dungeonCoords, int animID_1, int animID_2) -{ - VecFx32 position; - - position.x = (dungeonCoords->xCoordinate * xScale) + xOffset; - position.y = (dungeonCoords->yCoordinate * yScale) + yOffset; - position.x <<= FX32_SHIFT; - position.y <<= FX32_SHIFT; - - CellActor_SetPosition(actor, &position); - - if (dungeonCoords->isMtCoronet) { - CellActor_SetAnim(actor, animID_2); - } else { - CellActor_SetAnim(actor, animID_1); - } -} - -int ov21_021D5A20(CellActor **cellActorArray, int initialNumDungeons, int maxNumDungeons, int xOffset, int yOffset, int xScale, int yScale, const dungeonCoordinates *dungeonCoordinatesArray, const mapsEncounteredOn *dungeonsEncounteredOn, int animID_1, int animID_2, const u8 *dungeonsToSkip, u32 numDungeonsToSkip, u32 *dungeonsModified) -{ - int dungeonIndex, dungeonsToSkipIndex; - int numDungeons = initialNumDungeons; - int DungeonCount = 0; - - for (dungeonIndex = 0; dungeonIndex < dungeonsEncounteredOn->numMapsEncounteredOn - 1; dungeonIndex++) { - GF_ASSERT(dungeonsEncounteredOn->mapsEncounteredOnArray[dungeonIndex]); - GF_ASSERT(numDungeons < maxNumDungeons); - - for (dungeonsToSkipIndex = 0; dungeonsToSkipIndex < numDungeonsToSkip; dungeonsToSkipIndex++) { - if (dungeonsEncounteredOn->mapsEncounteredOnArray[dungeonIndex] == dungeonsToSkip[dungeonsToSkipIndex]) { - break; - } - } - - if (dungeonsToSkipIndex >= numDungeonsToSkip) { - ov21_021D59D8(cellActorArray[numDungeons], xOffset, yOffset, xScale, yScale, &dungeonCoordinatesArray[dungeonsEncounteredOn->mapsEncounteredOnArray[dungeonIndex]], animID_1, animID_2); - numDungeons++; - DungeonCount++; - } - } - - *dungeonsModified = DungeonCount; - - return numDungeons; -} diff --git a/src/overlay021/ov21_021DC9BC.c b/src/overlay021/ov21_021DC9BC.c index 67634e7e9b..774639d608 100644 --- a/src/overlay021/ov21_021DC9BC.c +++ b/src/overlay021/ov21_021DC9BC.c @@ -9,17 +9,14 @@ #include "overlay021/ov21_021D1FA4.h" #include "overlay021/ov21_021D4C0C.h" #include "overlay021/ov21_021D517C.h" -#include "overlay021/ov21_021D57B4.h" #include "overlay021/ov21_021E29DC.h" #include "overlay021/pokedex_sort.h" -#include "overlay021/struct_dungeoncoordinates.h" -#include "overlay021/struct_fieldCoordinates.h" +#include "overlay021/pokedexencdata.h" #include "overlay021/struct_ov21_021D0F60_decl.h" #include "overlay021/struct_ov21_021D13FC.h" #include "overlay021/struct_ov21_021D2648.h" #include "overlay021/struct_ov21_021D4CA0.h" #include "overlay021/struct_ov21_021D4CB8.h" -#include "overlay021/struct_ov21_021D5844.h" #include "overlay021/struct_ov21_021E68F4.h" #include "overlay021/struct_ov21_021E6A68.h" #include "overlay021/struct_ov21_021E6B20.h" @@ -97,10 +94,10 @@ typedef struct { u8 *invisibleDungeons; u32 numInvisibleFields; u32 numInvisibleDungeons; - mapsEncounteredOn dungeonsEncounteredOn; - mapsEncounteredOn fieldsEncounteredOn; - mapsEncounteredOn dungeonSpecialEncounters; - mapsEncounteredOn fieldSpecialEncounters; + EncounterLocations dungeonsEncounteredOn; + EncounterLocations fieldsEncounteredOn; + EncounterLocations dungeonSpecialEncounters; + EncounterLocations fieldSpecialEncounters; } encounterCollection; typedef struct { @@ -118,8 +115,8 @@ typedef struct { NNSG2dCharacterData *unk_7F8; void *unk_7FC; NNSG2dCharacterData *unk_800; - dungeonCoordinates *dungeonCoordinatesArray; - fieldCoordinates *fieldCoordinatesArray; + DungeonCoordinates *dungeonCoordinatesArray; + FieldCoordinates *fieldCoordinatesArray; int unk_80C; int unk_810; UnkStruct_ov21_021D2648 unk_814; @@ -368,8 +365,8 @@ static int ov21_021DCBD8(void *param0, UnkStruct_ov21_021E6B20 *param1, const vo mapDisplay = param1->unk_08; mapDisplay->encounterTime = v0->encounterTime; - mapDisplay->dungeonCoordinatesArray = PokedexEncData_GetDungeonLocations(param1->heapID, NULL); - mapDisplay->fieldCoordinatesArray = PokedexEncData_GetFieldLocations(param1->heapID, NULL); + mapDisplay->dungeonCoordinatesArray = PokedexEncData_GetDungeonCoordinates(param1->heapID, NULL); + mapDisplay->fieldCoordinatesArray = PokedexEncData_GetFieldCoordinates(param1->heapID, NULL); param1->unk_00++; break; @@ -839,19 +836,19 @@ static void ov21_021DD710(PokedexMapDisplay *mapDisplay, const UnkStruct_ov21_02 ov21_021DD8B4(mapDisplay); - mapDisplay->numVisibleFields = ov21_021D5948(mapDisplay->mapFieldCellMatrix_1, POKEDEXMAPHEIGHT, POKEDEXMAPWIDTH, mapDisplay->fieldCoordinatesArray, &enCollection->fieldsEncounteredOn, enCollection->invisibleFields, enCollection->numInvisibleFields); - numCombinedMaps = (enCollection->fieldsEncounteredOn.numMapsEncounteredOn - 1) + enCollection->numInvisibleFields; + mapDisplay->numVisibleFields = PokedexEncData_LocateVisibleFields(mapDisplay->mapFieldCellMatrix_1, POKEDEXMAPHEIGHT, POKEDEXMAPWIDTH, mapDisplay->fieldCoordinatesArray, &enCollection->fieldsEncounteredOn, enCollection->invisibleFields, enCollection->numInvisibleFields); + numCombinedMaps = (enCollection->fieldsEncounteredOn.numLocations - 1) + enCollection->numInvisibleFields; combinedMapArray = Heap_AllocFromHeapAtEnd(heapID, numCombinedMaps); for (index = 0; index < numCombinedMaps; index++) { if (index < enCollection->numInvisibleFields) { combinedMapArray[index] = enCollection->invisibleFields[index]; } else { - combinedMapArray[index] = enCollection->fieldsEncounteredOn.mapsEncounteredOnArray[index - enCollection->numInvisibleFields]; + combinedMapArray[index] = enCollection->fieldsEncounteredOn.locations[index - enCollection->numInvisibleFields]; } } - mapDisplay->fieldsZero = ov21_021D5948(mapDisplay->mapFieldCellMatrix_2, POKEDEXMAPHEIGHT, POKEDEXMAPWIDTH, mapDisplay->fieldCoordinatesArray, &enCollection->fieldSpecialEncounters, combinedMapArray, numCombinedMaps); + mapDisplay->fieldsZero = PokedexEncData_LocateVisibleFields(mapDisplay->mapFieldCellMatrix_2, POKEDEXMAPHEIGHT, POKEDEXMAPWIDTH, mapDisplay->fieldCoordinatesArray, &enCollection->fieldSpecialEncounters, combinedMapArray, numCombinedMaps); Heap_FreeToHeap(combinedMapArray); MapFieldCellMatrix_SmoothCells(mapDisplay->mapFieldCellMatrix_1, POKEDEXMAPHEIGHT, POKEDEXMAPWIDTH); @@ -872,20 +869,20 @@ static void ov21_021DD710(PokedexMapDisplay *mapDisplay, const UnkStruct_ov21_02 } mapDisplay->numDungeons = 0; - mapDisplay->numDungeons = ov21_021D5A20(mapDisplay->cellActorArray, mapDisplay->numDungeons, (NUMDUNGEONS * 2), xOffset, yOffset, POKEDEXMAPXSCALE, POKEDEXMAPYSCALE, mapDisplay->dungeonCoordinatesArray, &enCollection->dungeonsEncounteredOn, 2, v2, enCollection->invisibleDungeons, enCollection->numInvisibleDungeons, &mapDisplay->numVisibleDungeons); + mapDisplay->numDungeons = PokedexEncData_LocateVisibleDungeons(mapDisplay->cellActorArray, mapDisplay->numDungeons, (NUMDUNGEONS * 2), xOffset, yOffset, POKEDEXMAPXSCALE, POKEDEXMAPYSCALE, mapDisplay->dungeonCoordinatesArray, &enCollection->dungeonsEncounteredOn, 2, v2, enCollection->invisibleDungeons, enCollection->numInvisibleDungeons, &mapDisplay->numVisibleDungeons); - numCombinedMaps = (enCollection->dungeonsEncounteredOn.numMapsEncounteredOn - 1) + enCollection->numInvisibleDungeons; + numCombinedMaps = (enCollection->dungeonsEncounteredOn.numLocations - 1) + enCollection->numInvisibleDungeons; combinedMapArray = Heap_AllocFromHeapAtEnd(heapID, numCombinedMaps); for (index = 0; index < numCombinedMaps; index++) { if (index < enCollection->numInvisibleDungeons) { combinedMapArray[index] = enCollection->invisibleDungeons[index]; } else { - combinedMapArray[index] = enCollection->dungeonsEncounteredOn.mapsEncounteredOnArray[index - enCollection->numInvisibleDungeons]; + combinedMapArray[index] = enCollection->dungeonsEncounteredOn.locations[index - enCollection->numInvisibleDungeons]; } } - mapDisplay->numDungeons = ov21_021D5A20(mapDisplay->cellActorArray, mapDisplay->numDungeons, (NUMDUNGEONS * 2), xOffset, yOffset, POKEDEXMAPXSCALE, POKEDEXMAPYSCALE, mapDisplay->dungeonCoordinatesArray, &enCollection->dungeonSpecialEncounters, 3, v3, combinedMapArray, numCombinedMaps, &mapDisplay->dungeonsZero); + mapDisplay->numDungeons = PokedexEncData_LocateVisibleDungeons(mapDisplay->cellActorArray, mapDisplay->numDungeons, (NUMDUNGEONS * 2), xOffset, yOffset, POKEDEXMAPXSCALE, POKEDEXMAPYSCALE, mapDisplay->dungeonCoordinatesArray, &enCollection->dungeonSpecialEncounters, 3, v3, combinedMapArray, numCombinedMaps, &mapDisplay->dungeonsZero); Heap_FreeToHeap(combinedMapArray); } @@ -1167,24 +1164,24 @@ static void PokedexEncounters_PopulateCategories(encounterCollection *enCollecti break; } - PokedexEncData_PopulateMapsEncounteredOn(&enCollection->dungeonsEncounteredOn, species, dungeonCategory, heapID); - PokedexEncData_PopulateMapsEncounteredOn(&enCollection->fieldsEncounteredOn, species, fieldCategory, heapID); + PokedexEncData_PopulateEncounterLocations(&enCollection->dungeonsEncounteredOn, species, dungeonCategory, heapID); + PokedexEncData_PopulateEncounterLocations(&enCollection->fieldsEncounteredOn, species, fieldCategory, heapID); if (Pokedex_Sort_PokedexUnlocked(param1->dexStatus) == 0) { - PokedexEncData_PopulateMapsEncounteredOn(&enCollection->dungeonSpecialEncounters, species, PEFC_DUNGEONSPECIAL, heapID); - PokedexEncData_PopulateMapsEncounteredOn(&enCollection->fieldSpecialEncounters, species, PEFC_FIELDSPECIAL, heapID); + PokedexEncData_PopulateEncounterLocations(&enCollection->dungeonSpecialEncounters, species, PEFC_DUNGEONSPECIAL, heapID); + PokedexEncData_PopulateEncounterLocations(&enCollection->fieldSpecialEncounters, species, PEFC_FIELDSPECIAL, heapID); } else { - PokedexEncData_PopulateMapsEncounteredOn(&enCollection->dungeonSpecialEncounters, species, PEFC_DUNGEONSPECIALNATDEX, heapID); - PokedexEncData_PopulateMapsEncounteredOn(&enCollection->fieldSpecialEncounters, species, PEFC_FIELDSPECIALNATDEX, heapID); + PokedexEncData_PopulateEncounterLocations(&enCollection->dungeonSpecialEncounters, species, PEFC_DUNGEONSPECIALNATDEX, heapID); + PokedexEncData_PopulateEncounterLocations(&enCollection->fieldSpecialEncounters, species, PEFC_FIELDSPECIALNATDEX, heapID); } } static void ov21_021DDB68(encounterCollection *enCollection) { - PokedexEncData_FreeMapsEncounteredOn(&enCollection->dungeonsEncounteredOn); - PokedexEncData_FreeMapsEncounteredOn(&enCollection->fieldsEncounteredOn); - PokedexEncData_FreeMapsEncounteredOn(&enCollection->dungeonSpecialEncounters); - PokedexEncData_FreeMapsEncounteredOn(&enCollection->fieldSpecialEncounters); + PokedexEncData_FreeEncounterLocations(&enCollection->dungeonsEncounteredOn); + PokedexEncData_FreeEncounterLocations(&enCollection->fieldsEncounteredOn); + PokedexEncData_FreeEncounterLocations(&enCollection->dungeonSpecialEncounters); + PokedexEncData_FreeEncounterLocations(&enCollection->fieldSpecialEncounters); } static void ov21_021DDB8C(PokedexMapDisplay *mapDisplay) diff --git a/src/overlay021/pokedexencdata.c b/src/overlay021/pokedexencdata.c new file mode 100644 index 0000000000..aed5b26c2d --- /dev/null +++ b/src/overlay021/pokedexencdata.c @@ -0,0 +1,183 @@ +#include "overlay021/pokedexencdata.h" + +#include +#include + +#include "cell_actor.h" +#include "graphics.h" +#include "heap.h" +#include "narc.h" + +enum PokedexEncFileIndex { + PEFI_DUNGEONMORNING = 4, + PEFI_DUNGEONDAY = (4 + MAX_SPECIES), + PEFI_DUNGEONNIGHT = (4 + MAX_SPECIES * 2), + PEFI_DUNGEONSPECIAL = (4 + MAX_SPECIES * 3), + PEFI_DUNGEONSPECIALNATDEX = (4 + MAX_SPECIES * 4), + PEFI_FIELDMORNING = (4 + MAX_SPECIES * 5), + PEFI_FIELDDAY = (4 + MAX_SPECIES * 6), + PEFI_FIELDNIGHT = (4 + MAX_SPECIES * 7), + PEFI_FIELDSPECIAL = (4 + MAX_SPECIES * 8), + PEFI_FIELDSPECIALNATDEX = (4 + MAX_SPECIES * 9), +}; + +void PokedexEncData_PopulateEncounterLocations(EncounterLocations *encounterLocations, int species, int encounterCategory, int heapID) +{ + int fileIndex; + u32 fileSize; + + switch (encounterCategory) { + case PEFC_DUNGEONMORNING: + fileIndex = PEFI_DUNGEONMORNING; + break; + case PEFC_DUNGEONDAY: + fileIndex = PEFI_DUNGEONDAY; + break; + case PEFC_DUNGEONNIGHT: + fileIndex = PEFI_DUNGEONNIGHT; + break; + case PEFC_DUNGEONSPECIAL: + fileIndex = PEFI_DUNGEONSPECIAL; + break; + case PEFC_DUNGEONSPECIALNATDEX: + fileIndex = PEFI_DUNGEONSPECIALNATDEX; + break; + case PEFC_FIELDMORNING: + fileIndex = PEFI_FIELDMORNING; + break; + case PEFC_FIELDDAY: + fileIndex = PEFI_FIELDDAY; + break; + case PEFC_FIELDNIGHT: + fileIndex = PEFI_FIELDNIGHT; + break; + case PEFC_FIELDSPECIAL: + fileIndex = PEFI_FIELDSPECIAL; + break; + case PEFC_FIELDSPECIALNATDEX: + fileIndex = PEFI_FIELDSPECIALNATDEX; + break; + } + + encounterLocations->locations = LoadMemberFromNARC_OutFileSize(NARC_INDEX_APPLICATION__ZUKANLIST__ZKN_DATA__ZUKAN_ENC_PLATINUM, fileIndex + species, 0, heapID, 0, &fileSize); + encounterLocations->numLocations = fileSize / sizeof(int); +} + +void PokedexEncData_FreeEncounterLocations(EncounterLocations *encounterLocations) +{ + GF_ASSERT(encounterLocations); + GF_ASSERT(encounterLocations->locations); + + Heap_FreeToHeap(encounterLocations->locations); + + encounterLocations->locations = NULL; + encounterLocations->numLocations = 0; +} + +DungeonCoordinates *PokedexEncData_GetDungeonCoordinates(int heapID, int *numDungeons) +{ + u32 fileSize; + + DungeonCoordinates *dungeonCoordinatesArray = LoadMemberFromNARC_OutFileSize(NARC_INDEX_APPLICATION__ZUKANLIST__ZKN_DATA__ZUKAN_ENC_PLATINUM, 0, 0, heapID, 0, &fileSize); + + if (numDungeons) { + *numDungeons = fileSize / sizeof(DungeonCoordinates); + } + + return dungeonCoordinatesArray; +} + +FieldCoordinates *PokedexEncData_GetFieldCoordinates(int heapID, int *numFields) +{ + u32 fileSize; + + FieldCoordinates *fieldCoordinatesArray = LoadMemberFromNARC_OutFileSize(NARC_INDEX_APPLICATION__ZUKANLIST__ZKN_DATA__ZUKAN_ENC_PLATINUM, 2, 0, heapID, 0, &fileSize); + + if (numFields) { + *numFields = fileSize / sizeof(FieldCoordinates); + } + + return fieldCoordinatesArray; +} + +void PokedexEncData_LocateFieldOnMap(u8 *pokedexFieldMap, u8 mapHeight, u8 mapWidth, const FieldCoordinates *fieldCoordinates) +{ + GF_ASSERT((fieldCoordinates->x + fieldCoordinates->width) < mapWidth); + GF_ASSERT((fieldCoordinates->y + fieldCoordinates->height) < mapHeight); + + for (int x = fieldCoordinates->x; x < fieldCoordinates->x + fieldCoordinates->width; x++) { + for (int y = fieldCoordinates->y; y < fieldCoordinates->y + fieldCoordinates->height; y++) { + pokedexFieldMap[(x * mapHeight) + y] |= fieldCoordinates->cellMatrix[((x - fieldCoordinates->x) * fieldCoordinates->height) + (y - fieldCoordinates->y)]; + } + } +} + +u32 PokedexEncData_LocateVisibleFields(u8 *pokedexFieldMap, int mapHeight, int mapWidth, const FieldCoordinates *fieldCoordinatesArray, const EncounterLocations *encounterLocations, const u8 *invisibleFields, u32 numInvisibleFields) +{ + int locationIndex; + int skipIndex; + u32 numVisibleFields = 0; + + for (locationIndex = 0; locationIndex < encounterLocations->numLocations - 1; locationIndex++) { + GF_ASSERT(encounterLocations->locations[locationIndex]); + + for (skipIndex = 0; skipIndex < numInvisibleFields; skipIndex++) { + if (encounterLocations->locations[locationIndex] == invisibleFields[skipIndex]) { + break; + } + } + + if (skipIndex >= numInvisibleFields) { + PokedexEncData_LocateFieldOnMap(pokedexFieldMap, mapHeight, mapWidth, &fieldCoordinatesArray[encounterLocations->locations[locationIndex]]); + numVisibleFields++; + } + } + + return numVisibleFields; +} + +void PokedexEncData_LocateDungeonOnMap(CellActor *cellActor, int xOffset, int yOffset, int xScale, int yScale, const DungeonCoordinates *dungeonCoordinates, int animID, int coronetAnimID) +{ + VecFx32 position; + + position.x = (dungeonCoordinates->x * xScale) + xOffset; + position.y = (dungeonCoordinates->y * yScale) + yOffset; + position.x <<= FX32_SHIFT; + position.y <<= FX32_SHIFT; + + CellActor_SetPosition(cellActor, &position); + + if (dungeonCoordinates->isMtCoronet) { + CellActor_SetAnim(cellActor, coronetAnimID); + } else { + CellActor_SetAnim(cellActor, animID); + } +} + +int PokedexEncData_LocateVisibleDungeons(CellActor **cellActorArray, int initialNumVisibleDungeons, int maxNumDungeons, int xOffset, int yOffset, int xScale, int yScale, const DungeonCoordinates *dungeonCoordinatesArray, const EncounterLocations *encounterLocations, int animID, int coronetAnimID, const u8 *invisibleDungeons, u32 numInvisibleDungeons, u32 *cellActorsModified) +{ + int locationIndex, skipIndex; + int numVisibleDungeons = initialNumVisibleDungeons; + int DungeonCount = 0; + + for (locationIndex = 0; locationIndex < encounterLocations->numLocations - 1; locationIndex++) { + GF_ASSERT(encounterLocations->locations[locationIndex]); + GF_ASSERT(numVisibleDungeons < maxNumDungeons); + + for (skipIndex = 0; skipIndex < numInvisibleDungeons; skipIndex++) { + if (encounterLocations->locations[locationIndex] == invisibleDungeons[skipIndex]) { + break; + } + } + + if (skipIndex >= numInvisibleDungeons) { + PokedexEncData_LocateDungeonOnMap(cellActorArray[numVisibleDungeons], xOffset, yOffset, xScale, yScale, &dungeonCoordinatesArray[encounterLocations->locations[locationIndex]], animID, coronetAnimID); + numVisibleDungeons++; + DungeonCount++; + } + } + + *cellActorsModified = DungeonCount; + + return numVisibleDungeons; +}