From 267900bdcbd2875ac1a73efa3642ceb4032a2ed4 Mon Sep 17 00:00:00 2001 From: ultima-soul Date: Thu, 24 Dec 2020 16:46:39 -0800 Subject: [PATCH] Add Form Species ID tables and functions to access them. --- include/pokemon.h | 4 + .../pokemon/form_species_table_pointers.h | 80 ++++ src/data/pokemon/form_species_tables.h | 386 ++++++++++++++++++ src/pokemon.c | 25 ++ 4 files changed, 495 insertions(+) create mode 100644 src/data/pokemon/form_species_table_pointers.h create mode 100644 src/data/pokemon/form_species_tables.h diff --git a/include/pokemon.h b/include/pokemon.h index a956b9c40..cbbb89d59 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -4,6 +4,8 @@ #include "constants/pokemon.h" #include "sprite.h" +#define GET_BASE_SPECIES_ID(speciesId) (GetFormSpeciesId(speciesId, 0)) + struct PokemonSubstruct0 { u16 species; @@ -416,5 +418,7 @@ bool8 HasTwoFramesAnimation(u16 species); struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1); void sub_806F47C(u8 id); u8 *sub_806F4F8(u8 id, u8 arg1); +u16 GetFormSpeciesId(u16 speciesId, u8 formId); +u8 GetFormIdFromFormSpeciesId(u16 formSpeciesId); #endif // GUARD_POKEMON_H diff --git a/src/data/pokemon/form_species_table_pointers.h b/src/data/pokemon/form_species_table_pointers.h new file mode 100644 index 000000000..22e32ae42 --- /dev/null +++ b/src/data/pokemon/form_species_table_pointers.h @@ -0,0 +1,80 @@ +const u16 *const gFormSpeciesIdTables[NUM_SPECIES] = +{ + [SPECIES_VENUSAUR] = sVenusaurFormSpeciesIdTable, + [SPECIES_CHARIZARD] = sCharizardFormSpeciesIdTable, + [SPECIES_BLASTOISE] = sBlastoiseFormSpeciesIdTable, + [SPECIES_BEEDRILL] = sBeedrillFormSpeciesIdTable, + [SPECIES_PIDGEOT] = sPidgeotFormSpeciesIdTable, + [SPECIES_RATTATA] = sRattataFormSpeciesIdTable, + [SPECIES_RATICATE] = sRaticateFormSpeciesIdTable, + [SPECIES_PIKACHU] = sPikachuFormSpeciesIdTable, + [SPECIES_RAICHU] = sRaichuFormSpeciesIdTable, + [SPECIES_SANDSHREW] = sSandshrewFormSpeciesIdTable, + [SPECIES_SANDSLASH] = sSandslashFormSpeciesIdTable, + [SPECIES_VULPIX] = sVulpixFormSpeciesIdTable, + [SPECIES_NINETALES] = sNinetalesFormSpeciesIdTable, + [SPECIES_DIGLETT] = sDiglettFormSpeciesIdTable, + [SPECIES_DUGTRIO] = sDugtrioFormSpeciesIdTable, + [SPECIES_MEOWTH] = sMeowthFormSpeciesIdTable, + [SPECIES_PERSIAN] = sPersianFormSpeciesIdTable, + [SPECIES_ALAKAZAM] = sAlakazamFormSpeciesIdTable, + [SPECIES_GEODUDE] = sGeodudeFormSpeciesIdTable, + [SPECIES_GRAVELER] = sGravelerFormSpeciesIdTable, + [SPECIES_GOLEM] = sGolemFormSpeciesIdTable, + [SPECIES_PONYTA] = sPonytaFormSpeciesIdTable, + [SPECIES_RAPIDASH] = sRapidashFormSpeciesIdTable, + [SPECIES_SLOWPOKE] = sSlowpokeFormSpeciesIdTable, + [SPECIES_SLOWBRO] = sSlowbroFormSpeciesIdTable, + [SPECIES_FARFETCHD] = sFarfetchdFormSpeciesIdTable, + [SPECIES_GRIMER] = sGrimerFormSpeciesIdTable, + [SPECIES_MUK] = sMukFormSpeciesIdTable, + [SPECIES_GENGAR] = sGengarFormSpeciesIdTable, + [SPECIES_EXEGGUTOR] = sExeggutorFormSpeciesIdTable, + [SPECIES_MAROWAK] = sMarowakFormSpeciesIdTable, + [SPECIES_WEEZING] = sWeezingFormSpeciesIdTable, + [SPECIES_KANGASKHAN] = sKangaskhanFormSpeciesIdTable, + [SPECIES_MR_MIME] = sMrMimeFormSpeciesIdTable, + [SPECIES_PINSIR] = sPinsirFormSpeciesIdTable, + [SPECIES_GYARADOS] = sGyaradosFormSpeciesIdTable, + [SPECIES_AERODACTYL] = sAerodactylFormSpeciesIdTable, + [SPECIES_ARTICUNO] = sArticunoFormSpeciesIdTable, + [SPECIES_ZAPDOS] = sZapdosFormSpeciesIdTable, + [SPECIES_MOLTRES] = sMoltresFormSpeciesIdTable, + [SPECIES_MEWTWO] = sMewtwoFormSpeciesIdTable, + [SPECIES_PICHU] = sPichuFormSpeciesIdTable, + [SPECIES_AMPHAROS] = sAmpharosFormSpeciesIdTable, + [SPECIES_SLOWKING] = sSlowkingFormSpeciesIdTable, + [SPECIES_UNOWN] = sUnownFormSpeciesIdTable, + [SPECIES_STEELIX] = sSteelixFormSpeciesIdTable, + [SPECIES_SCIZOR] = sScizorFormSpeciesIdTable, + [SPECIES_HERACROSS] = sHeracrossFormSpeciesIdTable, + [SPECIES_CORSOLA] = sCorsolaFormSpeciesIdTable, + [SPECIES_HOUNDOOM] = sHoundoomFormSpeciesIdTable, + [SPECIES_TYRANITAR] = sTyranitarFormSpeciesIdTable, + [SPECIES_SCEPTILE] = sSceptileFormSpeciesIdTable, + [SPECIES_BLAZIKEN] = sBlazikenFormSpeciesIdTable, + [SPECIES_SWAMPERT] = sSwampertFormSpeciesIdTable, + [SPECIES_ZIGZAGOON] = sZigzagoonFormSpeciesIdTable, + [SPECIES_LINOONE] = sLinooneFormSpeciesIdTable, + [SPECIES_GARDEVOIR] = sGardevoirFormSpeciesIdTable, + [SPECIES_SABLEYE] = sSableyeFormSpeciesIdTable, + [SPECIES_MAWILE] = sMawileFormSpeciesIdTable, + [SPECIES_AGGRON] = sAggronFormSpeciesIdTable, + [SPECIES_MEDICHAM] = sMedichamFormSpeciesIdTable, + [SPECIES_MANECTRIC] = sManectricFormSpeciesIdTable, + [SPECIES_SHARPEDO] = sSharpedoFormSpeciesIdTable, + [SPECIES_CAMERUPT] = sCameruptFormSpeciesIdTable, + [SPECIES_ALTARIA] = sAltariaFormSpeciesIdTable, + [SPECIES_CASTFORM] = sCastformFormSpeciesIdTable, + [SPECIES_BANETTE] = sBanetteFormSpeciesIdTable, + [SPECIES_ABSOL] = sAbsolFormSpeciesIdTable, + [SPECIES_GLALIE] = sGlalieFormSpeciesIdTable, + [SPECIES_SALAMENCE] = sSalamenceFormSpeciesIdTable, + [SPECIES_METAGROSS] = sMetagrossFormSpeciesIdTable, + [SPECIES_LATIAS] = sLatiasFormSpeciesIdTable, + [SPECIES_LATIOS] = sLatiosFormSpeciesIdTable, + [SPECIES_KYOGRE] = sKyogreFormSpeciesIdTable, + [SPECIES_GROUDON] = sGroudonFormSpeciesIdTable, + [SPECIES_RAYQUAZA] = sRayquazaFormSpeciesIdTable, + [SPECIES_DEOXYS] = sDeoxysFormSpeciesIdTable, +}; diff --git a/src/data/pokemon/form_species_tables.h b/src/data/pokemon/form_species_tables.h new file mode 100644 index 000000000..632bdd9be --- /dev/null +++ b/src/data/pokemon/form_species_tables.h @@ -0,0 +1,386 @@ +#define FORM_SPECIES_END (0xffff) + +static const u16 sVenusaurFormSpeciesIdTable[] = { + SPECIES_VENUSAUR, + FORM_SPECIES_END, +}; + +static const u16 sCharizardFormSpeciesIdTable[] = { + SPECIES_CHARIZARD, + FORM_SPECIES_END, +}; + +static const u16 sBlastoiseFormSpeciesIdTable[] = { + SPECIES_BLASTOISE, + FORM_SPECIES_END, +}; + +static const u16 sBeedrillFormSpeciesIdTable[] = { + SPECIES_BEEDRILL, + FORM_SPECIES_END, +}; + +static const u16 sPidgeotFormSpeciesIdTable[] = { + SPECIES_PIDGEOT, + FORM_SPECIES_END, +}; + +static const u16 sRattataFormSpeciesIdTable[] = { + SPECIES_RATTATA, + FORM_SPECIES_END, +}; + +static const u16 sRaticateFormSpeciesIdTable[] = { + SPECIES_RATICATE, + FORM_SPECIES_END, +}; + +static const u16 sPikachuFormSpeciesIdTable[] = { + SPECIES_PIKACHU, + FORM_SPECIES_END, +}; + +static const u16 sRaichuFormSpeciesIdTable[] = { + SPECIES_RAICHU, + FORM_SPECIES_END, +}; + +static const u16 sSandshrewFormSpeciesIdTable[] = { + SPECIES_SANDSHREW, + FORM_SPECIES_END, +}; + +static const u16 sSandslashFormSpeciesIdTable[] = { + SPECIES_SANDSLASH, + FORM_SPECIES_END, +}; + +static const u16 sVulpixFormSpeciesIdTable[] = { + SPECIES_VULPIX, + FORM_SPECIES_END, +}; + +static const u16 sNinetalesFormSpeciesIdTable[] = { + SPECIES_NINETALES, + FORM_SPECIES_END, +}; + +static const u16 sDiglettFormSpeciesIdTable[] = { + SPECIES_DIGLETT, + FORM_SPECIES_END, +}; + +static const u16 sDugtrioFormSpeciesIdTable[] = { + SPECIES_DUGTRIO, + FORM_SPECIES_END, +}; + +static const u16 sMeowthFormSpeciesIdTable[] = { + SPECIES_MEOWTH, + FORM_SPECIES_END, +}; + +static const u16 sPersianFormSpeciesIdTable[] = { + SPECIES_PERSIAN, + FORM_SPECIES_END, +}; + +static const u16 sAlakazamFormSpeciesIdTable[] = { + SPECIES_ALAKAZAM, + FORM_SPECIES_END, +}; + +static const u16 sGeodudeFormSpeciesIdTable[] = { + SPECIES_GEODUDE, + FORM_SPECIES_END, +}; + +static const u16 sGravelerFormSpeciesIdTable[] = { + SPECIES_GRAVELER, + FORM_SPECIES_END, +}; + +static const u16 sGolemFormSpeciesIdTable[] = { + SPECIES_GOLEM, + FORM_SPECIES_END, +}; + +static const u16 sPonytaFormSpeciesIdTable[] = { + SPECIES_PONYTA, + FORM_SPECIES_END, +}; + +static const u16 sRapidashFormSpeciesIdTable[] = { + SPECIES_RAPIDASH, + FORM_SPECIES_END, +}; + +static const u16 sSlowpokeFormSpeciesIdTable[] = { + SPECIES_SLOWPOKE, + FORM_SPECIES_END, +}; + +static const u16 sSlowbroFormSpeciesIdTable[] = { + SPECIES_SLOWBRO, + FORM_SPECIES_END, +}; + +static const u16 sFarfetchdFormSpeciesIdTable[] = { + SPECIES_FARFETCHD, + FORM_SPECIES_END, +}; + +static const u16 sGrimerFormSpeciesIdTable[] = { + SPECIES_GRIMER, + FORM_SPECIES_END, +}; + +static const u16 sMukFormSpeciesIdTable[] = { + SPECIES_MUK, + FORM_SPECIES_END, +}; + +static const u16 sGengarFormSpeciesIdTable[] = { + SPECIES_GENGAR, + FORM_SPECIES_END, +}; + +static const u16 sExeggutorFormSpeciesIdTable[] = { + SPECIES_EXEGGUTOR, + FORM_SPECIES_END, +}; + +static const u16 sMarowakFormSpeciesIdTable[] = { + SPECIES_MAROWAK, + FORM_SPECIES_END, +}; + +static const u16 sWeezingFormSpeciesIdTable[] = { + SPECIES_WEEZING, + FORM_SPECIES_END, +}; + +static const u16 sKangaskhanFormSpeciesIdTable[] = { + SPECIES_KANGASKHAN, + FORM_SPECIES_END, +}; + +static const u16 sMrMimeFormSpeciesIdTable[] = { + SPECIES_MR_MIME, + FORM_SPECIES_END, +}; + +static const u16 sPinsirFormSpeciesIdTable[] = { + SPECIES_PINSIR, + FORM_SPECIES_END, +}; + +static const u16 sGyaradosFormSpeciesIdTable[] = { + SPECIES_GYARADOS, + FORM_SPECIES_END, +}; + +static const u16 sAerodactylFormSpeciesIdTable[] = { + SPECIES_AERODACTYL, + FORM_SPECIES_END, +}; + +static const u16 sArticunoFormSpeciesIdTable[] = { + SPECIES_ARTICUNO, + FORM_SPECIES_END, +}; + +static const u16 sZapdosFormSpeciesIdTable[] = { + SPECIES_ZAPDOS, + FORM_SPECIES_END, +}; + +static const u16 sMoltresFormSpeciesIdTable[] = { + SPECIES_MOLTRES, + FORM_SPECIES_END, +}; + +static const u16 sMewtwoFormSpeciesIdTable[] = { + SPECIES_MEWTWO, + FORM_SPECIES_END, +}; + +static const u16 sPichuFormSpeciesIdTable[] = { + SPECIES_PICHU, + FORM_SPECIES_END, +}; + +static const u16 sAmpharosFormSpeciesIdTable[] = { + SPECIES_AMPHAROS, + FORM_SPECIES_END, +}; + +static const u16 sSlowkingFormSpeciesIdTable[] = { + SPECIES_SLOWKING, + FORM_SPECIES_END, +}; + +static const u16 sUnownFormSpeciesIdTable[] = { + SPECIES_UNOWN, + FORM_SPECIES_END, +}; + +static const u16 sSteelixFormSpeciesIdTable[] = { + SPECIES_STEELIX, + FORM_SPECIES_END, +}; + +static const u16 sScizorFormSpeciesIdTable[] = { + SPECIES_SCIZOR, + FORM_SPECIES_END, +}; + +static const u16 sHeracrossFormSpeciesIdTable[] = { + SPECIES_HERACROSS, + FORM_SPECIES_END, +}; + +static const u16 sCorsolaFormSpeciesIdTable[] = { + SPECIES_CORSOLA, + FORM_SPECIES_END, +}; + +static const u16 sHoundoomFormSpeciesIdTable[] = { + SPECIES_HOUNDOOM, + FORM_SPECIES_END, +}; + +static const u16 sTyranitarFormSpeciesIdTable[] = { + SPECIES_TYRANITAR, + FORM_SPECIES_END, +}; + +static const u16 sSceptileFormSpeciesIdTable[] = { + SPECIES_SCEPTILE, + FORM_SPECIES_END, +}; + +static const u16 sBlazikenFormSpeciesIdTable[] = { + SPECIES_BLAZIKEN, + FORM_SPECIES_END, +}; + +static const u16 sSwampertFormSpeciesIdTable[] = { + SPECIES_SWAMPERT, + FORM_SPECIES_END, +}; + +static const u16 sZigzagoonFormSpeciesIdTable[] = { + SPECIES_ZIGZAGOON, + FORM_SPECIES_END, +}; + +static const u16 sLinooneFormSpeciesIdTable[] = { + SPECIES_LINOONE, + FORM_SPECIES_END, +}; + +static const u16 sGardevoirFormSpeciesIdTable[] = { + SPECIES_GARDEVOIR, + FORM_SPECIES_END, +}; + +static const u16 sSableyeFormSpeciesIdTable[] = { + SPECIES_SABLEYE, + FORM_SPECIES_END, +}; + +static const u16 sMawileFormSpeciesIdTable[] = { + SPECIES_MAWILE, + FORM_SPECIES_END, +}; + +static const u16 sAggronFormSpeciesIdTable[] = { + SPECIES_AGGRON, + FORM_SPECIES_END, +}; + +static const u16 sMedichamFormSpeciesIdTable[] = { + SPECIES_MEDICHAM, + FORM_SPECIES_END, +}; + +static const u16 sManectricFormSpeciesIdTable[] = { + SPECIES_MANECTRIC, + FORM_SPECIES_END, +}; + +static const u16 sSharpedoFormSpeciesIdTable[] = { + SPECIES_SHARPEDO, + FORM_SPECIES_END, +}; + +static const u16 sCameruptFormSpeciesIdTable[] = { + SPECIES_CAMERUPT, + FORM_SPECIES_END, +}; + +static const u16 sAltariaFormSpeciesIdTable[] = { + SPECIES_ALTARIA, + FORM_SPECIES_END, +}; + +static const u16 sCastformFormSpeciesIdTable[] = { + SPECIES_CASTFORM, + FORM_SPECIES_END, +}; + +static const u16 sBanetteFormSpeciesIdTable[] = { + SPECIES_BANETTE, + FORM_SPECIES_END, +}; + +static const u16 sAbsolFormSpeciesIdTable[] = { + SPECIES_ABSOL, + FORM_SPECIES_END, +}; + +static const u16 sGlalieFormSpeciesIdTable[] = { + SPECIES_GLALIE, + FORM_SPECIES_END, +}; + +static const u16 sSalamenceFormSpeciesIdTable[] = { + SPECIES_SALAMENCE, + FORM_SPECIES_END, +}; + +static const u16 sMetagrossFormSpeciesIdTable[] = { + SPECIES_METAGROSS, + FORM_SPECIES_END, +}; + +static const u16 sLatiasFormSpeciesIdTable[] = { + SPECIES_LATIAS, + FORM_SPECIES_END, +}; + +static const u16 sLatiosFormSpeciesIdTable[] = { + SPECIES_LATIOS, + FORM_SPECIES_END, +}; + +static const u16 sKyogreFormSpeciesIdTable[] = { + SPECIES_KYOGRE, + FORM_SPECIES_END, +}; + +static const u16 sGroudonFormSpeciesIdTable[] = { + SPECIES_GROUDON, + FORM_SPECIES_END, +}; + +static const u16 sRayquazaFormSpeciesIdTable[] = { + SPECIES_RAYQUAZA, + FORM_SPECIES_END, +}; + +static const u16 sDeoxysFormSpeciesIdTable[] = { + SPECIES_DEOXYS, + FORM_SPECIES_END, +}; diff --git a/src/pokemon.c b/src/pokemon.c index 3621284d6..070f754c5 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -1386,6 +1386,8 @@ const s8 gNatureStatTable[NUM_NATURES][NUM_NATURE_STATS] = #include "data/pokemon/level_up_learnsets.h" #include "data/pokemon/evolution.h" #include "data/pokemon/level_up_learnset_pointers.h" +#include "data/pokemon/form_species_tables.h" +#include "data/pokemon/form_species_table_pointers.h" // SPECIES_NONE are ignored in the following two tables, so decrement before accessing these arrays to get the right result @@ -6982,3 +6984,26 @@ u8 *sub_806F4F8(u8 id, u8 arg1) return structPtr->byteArrays[arg1]; } } + +u16 GetFormSpeciesId(u16 speciesId, u8 formId) +{ + if (gFormSpeciesIdTables[speciesId] != NULL) + return gFormSpeciesIdTables[speciesId][formId]; + else + return speciesId; +} + +u8 GetFormIdFromFormSpeciesId(u16 formSpeciesId) +{ + u8 targetFormId = 0; + + if (gFormSpeciesIdTables[formSpeciesId] != NULL) + { + for (targetFormId = 0; gFormSpeciesIdTables[formSpeciesId][targetFormId] != FORM_SPECIES_END; targetFormId++) + { + if (formSpeciesId == gFormSpeciesIdTables[formSpeciesId][targetFormId]) + break; + } + } + return targetFormId; +}