From 61855cccbce59cdfd0d6cb6940a7813c2309ece9 Mon Sep 17 00:00:00 2001 From: Rachel Date: Fri, 3 Nov 2023 17:18:19 -0700 Subject: [PATCH] Clean-up and document pokemon_icon.c --- include/pokemon_icon.h | 115 +++++++++++++++-- src/pokemon_icon.c | 280 +++++++++++++++++++++-------------------- 2 files changed, 250 insertions(+), 145 deletions(-) diff --git a/include/pokemon_icon.h b/include/pokemon_icon.h index 000ede200c..d49c3b323d 100644 --- a/include/pokemon_icon.h +++ b/include/pokemon_icon.h @@ -3,19 +3,120 @@ #include "pokemon.h" -u32 BoxPokemon_IconSpriteIndex(const BoxPokemon * param0); -u32 Pokemon_IconSpriteIndex(Pokemon * param0); -u32 PokeIconSpriteIndex(u32 param0, u32 param1, u32 param2); -u16 BoxPokemon_IconFormOffset(const BoxPokemon * param0); -const u8 PokeIconPaletteIndex(u32 param0, u32 param1, u32 param2); -const u8 BoxPokemon_IconPaletteIndex(const BoxPokemon * param0); -const u8 Pokemon_IconPaletteIndex(Pokemon * param0); +/** + * @brief Get the index of the sprite-tiles file used for a given BoxPokemon. + * + * @param mon + * @return Index of the sprite-tiles file for this Pokemon in pl_poke_icon.narc + */ +u32 BoxPokemon_IconSpriteIndex(const BoxPokemon *mon); + +/** + * @brief Get the index of the sprite-tiles file used for a given Pokemon. + * + * @param mon + * @return Index of the sprite-tiles file for this Pokemon in pl_poke_icon.narc + */ +u32 Pokemon_IconSpriteIndex(Pokemon *mon); + +/** + * @brief Get the index of the sprite-tiles file used for a given combination + * of species+form and whether or not the Pokemon is in an egg. + * + * @param species + * @param isEgg + * @param form + * @return Index of the sprite-tiles file for the given tuple in pl_poke_icon.narc + */ +u32 PokeIconSpriteIndex(u32 species, u32 isEgg, u32 form); + +/** + * @brief Get the form offset for a given BoxPokemon's icon. + * + * In essence, this is just a nice wrapper around BoxPokemon_GetForm for species + * known to have alternate forms (visual or mechanical). + * + * @param mon + * @return Form offset + */ +u16 BoxPokemon_IconFormOffset(const BoxPokemon *mon); + +/** + * @brief Get the index of the palette used by a given combination of species+form + * and whether or not the Pokemon is in an egg. + * + * @param species + * @param form + * @param isEgg + * @return Index in the shared palette file for all Pokemon icons. + */ +const u8 PokeIconPaletteIndex(u32 species, u32 form, u32 isEgg); + +/** + * @brief Get the index of the palette used by a given BoxPokemon. + * + * @param mon + * @return Index in the shared palette file for all Pokemon icons. + */ +const u8 BoxPokemon_IconPaletteIndex(const BoxPokemon *mon); + +/** + * @brief Get the index of the palette used by a given Pokemon. + * + * @param mon + * @return Index in the shared palette file for all Pokemon icons. + */ +const u8 Pokemon_IconPaletteIndex(Pokemon *mon); + +/** + * @brief Get the file-index of the shared palettes file in pl_poke_icon.narc. + * + * @return File-index of the shared palettes file + */ u32 PokeIconPalettesFileIndex(void); + +/** + * @brief Get the file-index of the shared cells file in pl_poke_icon.narc. + * + * @return File-index of the shared cells file + */ u32 PokeIconCellsFileIndex(void); + +/** + * @brief Get the file-index of the shared 32K cells file in pl_poke_icon.narc. + * + * @return File-index of the shared cells file + */ u32 PokeIcon32KCellsFileIndex(void); + +/** + * @brief Get the file-index of the shared 64K cells file in pl_poke_icon.narc. + * + * @return File-index of the shared cells file + */ u32 PokeIcon64KCellsFileIndex(void); + +/** + * @brief Get the file-index of the shared animation file in pl_poke_icon.narc. + * + * @return File-index of the shared animation file + */ u32 PokeIconAnimationFileIndex(void); + +/** + * @brief Get the file-index of the shared 32K animation file in + * pl_poke_icon.narc. + * + * @return File-index of the shared 32K animation file + */ u32 PokeIcon32KAnimationFileIndex(void); + +/** + * @brief Get the file-index of the shared 64K animation file in + * pl_poke_icon.narc. + * + * @return File-index of the shared 64K animation file + */ u32 PokeIcon64KAnimationFileIndex(void); #endif // POKEPLATINUM_POKEMON_ICON_H diff --git a/src/pokemon_icon.c b/src/pokemon_icon.c index 7d6fdbc4ed..678f51460b 100644 --- a/src/pokemon_icon.c +++ b/src/pokemon_icon.c @@ -8,199 +8,203 @@ #include "data/pokeicon_palettes.h" -u32 BoxPokemon_IconSpriteIndex (const BoxPokemon * param0) +enum { + POKEICON_SHARED_PALETTES = 0, + POKEICON_SHARED_ANIMATION, + POKEICON_SHARED_CELLS, + POKEICON_SHARED_32K_ANIMATION, + POKEICON_SHARED_32K_CELLS, + POKEICON_SHARED_64K_ANIMATION, + POKEICON_SHARED_64K_CELLS, + + POKEICON_ICON_TILES_START, +}; + +static inline u32 IconTilesIndex(u32 icon) { - u32 v0; - u32 v1; - BOOL v2; - u32 v3; - u32 v4; - - v2 = BoxPokemon_EnterDecryptionContext((BoxPokemon *)param0); - v0 = BoxPokemon_GetValue((BoxPokemon *)param0, MON_DATA_SPECIES, NULL); - v4 = BoxPokemon_GetValue((BoxPokemon *)param0, MON_DATA_IS_EGG, NULL); - v3 = BoxPokemon_IconFormOffset((BoxPokemon *)param0); - v1 = PokeIconSpriteIndex(v0, v4, v3); - - BoxPokemon_ExitDecryptionContext((BoxPokemon *)param0, v2); - return v1; + return icon + POKEICON_ICON_TILES_START; } -u32 Pokemon_IconSpriteIndex (Pokemon * param0) +u32 BoxPokemon_IconSpriteIndex(const BoxPokemon *mon) { - return BoxPokemon_IconSpriteIndex((const BoxPokemon *)Pokemon_GetBoxPokemon(param0)); + BOOL ctx = BoxPokemon_EnterDecryptionContext((BoxPokemon *)mon); + + u32 species = BoxPokemon_GetValue((BoxPokemon *)mon, MON_DATA_SPECIES, NULL); + BOOL isEgg = BoxPokemon_GetValue((BoxPokemon *)mon, MON_DATA_IS_EGG, NULL); + u32 form = BoxPokemon_IconFormOffset((BoxPokemon *)mon); + u32 index = PokeIconSpriteIndex(species, isEgg, form); + + BoxPokemon_ExitDecryptionContext((BoxPokemon *)mon, ctx); + return index; } -u32 PokeIconSpriteIndex (u32 param0, u32 param1, u32 param2) +u32 Pokemon_IconSpriteIndex(Pokemon *mon) { - if (param1 == 1) { - if (param0 == 490) { - return 502; - } else { - return 501; + return BoxPokemon_IconSpriteIndex((const BoxPokemon *)Pokemon_GetBoxPokemon(mon)); +} + +u32 PokeIconSpriteIndex(u32 species, u32 isEgg, u32 form) +{ + if (isEgg == TRUE) { + if (species == SPECIES_MANAPHY) { + return IconTilesIndex(ICON_MANAPHY_EGG); + } + + return IconTilesIndex(ICON_EGG); + } + + form = Pokemon_SanitizeFormId(species, form); + + if (form != 0) { + if (species == SPECIES_DEOXYS) { + return IconTilesIndex(ICON_DEOXYS_ATTACK) + form - 1; + } + + if (species == SPECIES_UNOWN) { + return IconTilesIndex(ICON_UNOWN_B) + form - 1; + } + + if (species == SPECIES_BURMY) { + return IconTilesIndex(ICON_BURMY_SANDY) + form - 1; + } + + if (species == SPECIES_WORMADAM) { + return IconTilesIndex(ICON_WORMADAM_SANDY) + form - 1; + } + + if (species == SPECIES_SHELLOS) { + return IconTilesIndex(ICON_SHELLOS_EAST_SEA) + form - 1; + } + + if (species == SPECIES_GASTRODON) { + return IconTilesIndex(ICON_GASTRODON_EAST_SEA) + form - 1; + } + + if (species == SPECIES_GIRATINA) { + return IconTilesIndex(ICON_GIRATINA_ORIGIN) + form - 1; + } + + if (species == SPECIES_SHAYMIN) { + return IconTilesIndex(ICON_SHAYMIN_SKY) + form - 1; + } + + if (species == SPECIES_ROTOM) { + return IconTilesIndex(ICON_ROTOM_HEAT) + form - 1; } } - param2 = Pokemon_SanitizeFormId(param0, param2); - - if (param2 != 0) { - if (param0 == 386) { - return 503 + param2 - 1; - } - - if (param0 == 201) { - return 507 + param2 - 1; - } - - if (param0 == 412) { - return 534 + param2 - 1; - } - - if (param0 == 413) { - return 536 + param2 - 1; - } - - if (param0 == 422) { - return 538 + param2 - 1; - } - - if (param0 == 423) { - return 539 + param2 - 1; - } - - if (param0 == 487) { - return 540 + param2 - 1; - } - - if (param0 == 492) { - return 541 + param2 - 1; - } - - if (param0 == 479) { - return 542 + param2 - 1; - } + if (species > NATIONAL_DEX_COUNT) { + species = SPECIES_NONE; } - if (param0 > 493) { - param0 = 0; - } - - return 7 + param0; + return IconTilesIndex(species); } -u16 BoxPokemon_IconFormOffset (const BoxPokemon * param0) +u16 BoxPokemon_IconFormOffset(const BoxPokemon *mon) { - u32 v0; + u32 speciesOrEgg = BoxPokemon_GetValue((BoxPokemon *)mon, MON_DATA_SPECIES_EGG, NULL); - v0 = BoxPokemon_GetValue((BoxPokemon *)param0, MON_DATA_SPECIES_EGG, NULL); - - switch (v0) { - case 201: - return BoxPokemon_GetForm((BoxPokemon *)param0); - case 386: - case 412: - case 413: - case 422: - case 423: - case 487: - case 492: - case 479: - return BoxPokemon_GetValue((BoxPokemon *)param0, MON_DATA_FORM, NULL); - default: - return 0; + switch (speciesOrEgg) { + case SPECIES_UNOWN: + return BoxPokemon_GetForm((BoxPokemon *)mon); + case SPECIES_DEOXYS: + case SPECIES_BURMY: + case SPECIES_WORMADAM: + case SPECIES_SHELLOS: + case SPECIES_GASTRODON: + case SPECIES_GIRATINA: + case SPECIES_SHAYMIN: + case SPECIES_ROTOM: + return BoxPokemon_GetValue((BoxPokemon *)mon, MON_DATA_FORM, NULL); } return 0; } -const u8 PokeIconPaletteIndex (u32 param0, u32 param1, u32 param2) +const u8 PokeIconPaletteIndex(u32 species, u32 form, u32 isEgg) { - if (param2 == 1) { - if (param0 == 490) { - param0 = 495; + if (isEgg == TRUE) { + if (species == SPECIES_MANAPHY) { + species = ICON_MANAPHY_EGG; } else { - param0 = 494; + species = ICON_EGG; } - } else if (param0 > 493) { - param0 = 0; - } else if (param1 != 0) { - if (param0 == 386) { - param0 = 496 + param1 - 1; - } else if (param0 == 201) { - param0 = 499 + param1 - 1; - } else if (param0 == 412) { - param0 = 527 + param1 - 1; - } else if (param0 == 413) { - param0 = 529 + param1 - 1; - } else if (param0 == 422) { - param0 = 531 + param1 - 1; - } else if (param0 == 423) { - param0 = 532 + param1 - 1; - } else if (param0 == 487) { - param0 = 533 + param1 - 1; - } else if (param0 == 492) { - param0 = 534 + param1 - 1; - } else if (param0 == 479) { - param0 = 535 + param1 - 1; + } else if (species > NATIONAL_DEX_COUNT) { + species = SPECIES_NONE; + } else if (form != 0) { + if (species == SPECIES_DEOXYS) { + species = ICON_DEOXYS_ATTACK + form - 1; + } else if (species == SPECIES_UNOWN) { + species = ICON_UNOWN_A + form - 1; + } else if (species == SPECIES_BURMY) { + species = ICON_BURMY_SANDY + form - 1; + } else if (species == SPECIES_WORMADAM) { + species = ICON_WORMADAM_SANDY + form - 1; + } else if (species == SPECIES_SHELLOS) { + species = ICON_SHELLOS_EAST_SEA + form - 1; + } else if (species == SPECIES_GASTRODON) { + species = ICON_GASTRODON_EAST_SEA + form - 1; + } else if (species == SPECIES_GIRATINA) { + species = ICON_GIRATINA_ORIGIN + form - 1; + } else if (species == SPECIES_SHAYMIN) { + species = ICON_SHAYMIN_SKY + form - 1; + } else if (species == SPECIES_ROTOM) { + species = ICON_ROTOM_HEAT + form - 1; } } - return sPokemonIconPaletteIndex[param0]; + return sPokemonIconPaletteIndex[species]; } -const u8 BoxPokemon_IconPaletteIndex (const BoxPokemon * param0) +const u8 BoxPokemon_IconPaletteIndex(const BoxPokemon *mon) { - BOOL v0; - u32 v1; - u32 v2; - u32 v3; + BOOL ctx = BoxPokemon_EnterDecryptionContext((BoxPokemon *)mon); - v0 = BoxPokemon_EnterDecryptionContext((BoxPokemon *)param0); - v2 = BoxPokemon_IconFormOffset(param0); - v1 = BoxPokemon_GetValue((BoxPokemon *)param0, MON_DATA_SPECIES, NULL); - v3 = BoxPokemon_GetValue((BoxPokemon *)param0, MON_DATA_IS_EGG, NULL); + u32 form = BoxPokemon_IconFormOffset(mon); + u32 species = BoxPokemon_GetValue((BoxPokemon *)mon, MON_DATA_SPECIES, NULL); + u32 isEgg = BoxPokemon_GetValue((BoxPokemon *)mon, MON_DATA_IS_EGG, NULL); - BoxPokemon_ExitDecryptionContext((BoxPokemon *)param0, v0); + BoxPokemon_ExitDecryptionContext((BoxPokemon *)mon, ctx); - return PokeIconPaletteIndex(v1, v2, v3); + return PokeIconPaletteIndex(species, form, isEgg); } -const u8 Pokemon_IconPaletteIndex (Pokemon * param0) +const u8 Pokemon_IconPaletteIndex(Pokemon *mon) { - return BoxPokemon_IconPaletteIndex((const BoxPokemon *)Pokemon_GetBoxPokemon(param0)); + return BoxPokemon_IconPaletteIndex((const BoxPokemon *)Pokemon_GetBoxPokemon(mon)); } -u32 PokeIconPalettesFileIndex (void) +u32 PokeIconPalettesFileIndex(void) { - return 0; + return POKEICON_SHARED_PALETTES; } -u32 PokeIconCellsFileIndex (void) +u32 PokeIconCellsFileIndex(void) { - return 2; + return POKEICON_SHARED_CELLS; } -u32 PokeIcon32KCellsFileIndex (void) +u32 PokeIcon32KCellsFileIndex(void) { - return 4; + return POKEICON_SHARED_32K_CELLS; } -u32 PokeIcon64KCellsFileIndex (void) +u32 PokeIcon64KCellsFileIndex(void) { - return 6; + return POKEICON_SHARED_64K_CELLS; } -u32 PokeIconAnimationFileIndex (void) +u32 PokeIconAnimationFileIndex(void) { - return 1; + return POKEICON_SHARED_ANIMATION; } -u32 PokeIcon32KAnimationFileIndex (void) +u32 PokeIcon32KAnimationFileIndex(void) { - return 3; + return POKEICON_SHARED_32K_ANIMATION; } -u32 PokeIcon64KAnimationFileIndex (void) +u32 PokeIcon64KAnimationFileIndex(void) { - return 5; + return POKEICON_SHARED_64K_ANIMATION; }