Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document pokedex_data #321

Merged
merged 10 commits into from
Jan 5, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 47 additions & 39 deletions src/pokedex_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,34 @@
#include "savedata.h"
#include "unk_020986CC.h"

#define DEX_SIZE_U32 ((int)((NATIONAL_DEX_COUNT - 1) / 32) + 1) // default 16
#define MAGIC_NUMBER 0xbeefcafe
#define NUM_MYTHICALS_NATIONAL 11
#define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_MYTHICALS_NATIONAL)
#define UNOWN_COUNT 28
#define DEOXYS_COUNT 4
#define ROTOM_COUNT 6
#define TERMINAL_4BITS 0x7
#define TERMINAL_BYTE 0xf
#define TERMINAL_U8 0xff
#define TERMINAL_U32 0xffffffff
static const u16 sExcludedMons_national[] = {
SPECIES_MEW,
SPECIES_LUGIA,
SPECIES_HO_OH,
SPECIES_CELEBI,
SPECIES_JIRACHI,
SPECIES_DEOXYS,
SPECIES_PHIONE,
SPECIES_MANAPHY,
SPECIES_DARKRAI,
SPECIES_SHAYMIN,
SPECIES_ARCEUS
};
static const u16 sExcludedMons_local[] = {};
h2o-DS marked this conversation as resolved.
Show resolved Hide resolved

#define DEX_SIZE_U32 ((int)((NATIONAL_DEX_COUNT - 1) / 32) + 1) // default 16
#define MAGIC_NUMBER 0xbeefcafe
#define NUM_EXCLUDED_NATIONAL ((int)(sizeof(sExcludedMons_national) / sizeof(u16)))
#define NUM_EXCLUDED_LOCAL 0 //((int)(sizeof(sExcludedMons_local) / sizeof(u16)))
h2o-DS marked this conversation as resolved.
Show resolved Hide resolved
#define NATIONAL_DEX_GOAL (NATIONAL_DEX_COUNT - NUM_EXCLUDED_NATIONAL)
#define LOCAL_DEX_GOAL (LOCAL_DEX_COUNT - NUM_EXCLUDED_LOCAL)
#define UNOWN_COUNT 28
#define DEOXYS_COUNT 4
#define ROTOM_COUNT 6
#define TERMINAL_4BITS 0x7
#define TERMINAL_BYTE 0xf
#define TERMINAL_U8 0xff
#define TERMINAL_U32 0xffffffff
h2o-DS marked this conversation as resolved.
Show resolved Hide resolved

typedef struct PokedexData {
u32 magic;
Expand Down Expand Up @@ -80,13 +97,13 @@ static BOOL SpeciesInvalid(u16 species)
static inline BOOL ReadBit_2Forms(const u8 *array, u16 bitIndex)
{
bitIndex--;
return 0 != (array[bitIndex >> 0x3] & (1 << (bitIndex & 0x7)));
return 0 != (array[bitIndex >> 3] & (1 << (bitIndex & 0x7)));
}

static inline void ActivateBit_2Forms(u8 *array, u16 bitIndex)
{
bitIndex--;
array[bitIndex >> 0x3] |= 1 << (bitIndex & 0x7);
array[bitIndex >> 3] |= 1 << (bitIndex & 0x7);
}

static inline void SetBit_2Forms(u8 *array, u8 value, u16 bitIndex)
Expand All @@ -95,8 +112,8 @@ static inline void SetBit_2Forms(u8 *array, u8 value, u16 bitIndex)

bitIndex--;

array[bitIndex >> 0x3] &= ~(1 << (bitIndex & 0x7));
array[bitIndex >> 0x3] |= value << (bitIndex & 0x7);
array[bitIndex >> 3] &= ~(1 << (bitIndex & 0x7));
array[bitIndex >> 3] |= value << (bitIndex & 0x7);
}

static inline u32 ReadBit_3Forms(const u8 *array, u16 bitIndex)
Expand Down Expand Up @@ -133,7 +150,7 @@ static void SetBit_Gender(PokedexData *pokedexData, u8 gender, u8 isSeen, u16 bi

static void UpdateGender(PokedexData *pokedexData, u8 gender, u8 isSeen, u16 bitIndex)
{
GF_ASSERT(gender <= 2);
GF_ASSERT(gender <= GENDER_NONE);

if (gender == GENDER_NONE) {
gender = GENDER_MALE;
Expand Down Expand Up @@ -587,8 +604,6 @@ static void UpdateForm(PokedexData *pokedexData, u16 species, Pokemon *pokemon)
form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL);
UpdateForms_Rotom(pokedexData, species, form);
break;
default:
break;
}
}

Expand Down Expand Up @@ -691,25 +706,10 @@ static int GetForm_3Forms(const PokedexData *pokedexData, u32 species, int formI
static BOOL CountsForDexCompletion_National(u16 species)
{
int i;
BOOL included;
static const u16 excludedMons[NUM_MYTHICALS_NATIONAL] = {
SPECIES_MEW,
SPECIES_LUGIA,
SPECIES_HO_OH,
SPECIES_CELEBI,
SPECIES_JIRACHI,
SPECIES_DEOXYS,
SPECIES_PHIONE,
SPECIES_MANAPHY,
SPECIES_DARKRAI,
SPECIES_SHAYMIN,
SPECIES_ARCEUS
};

included = TRUE;

for (i = 0; i < NUM_MYTHICALS_NATIONAL; i++) {
if (excludedMons[i] == species) {
BOOL included = TRUE;

for (i = 0; i < NUM_EXCLUDED_NATIONAL; i++) {
if (sExcludedMons_national[i] == species) {
included = FALSE;
}
}
Expand All @@ -719,7 +719,15 @@ static BOOL CountsForDexCompletion_National(u16 species)

static BOOL CountsForDexCompletion_Local(u16 species)
{
return TRUE;
BOOL included = TRUE;

for (int i = 0; i < NUM_EXCLUDED_LOCAL; i++) {
if (sExcludedMons_local[i] == species) {
included = FALSE;
}
}

return included;
}

void PokedexData_Init(PokedexData *pokedexData)
Expand Down Expand Up @@ -828,7 +836,7 @@ BOOL PokedexData_LocalDexCompleted(const PokedexData *pokedexData)
{
u16 numCaught = PokedexData_NumCaught_Local(pokedexData);

if (numCaught >= LOCAL_DEX_COUNT) {
if (numCaught >= LOCAL_DEX_GOAL) {
return TRUE;
}

Expand Down
Loading