From 40afae437c900c605d88bf29d2d36d66605fca53 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 11 Dec 2023 13:33:46 -0300 Subject: [PATCH 1/3] Added a GetSpeciesPreEvolution function and updated the value of EVO_NONE Credits to AsparagusEduardo. GetSpeciesPreEvolution is a new function that reads a species ID and returns the ID of its pre-evolution if there is one available. Otherwise it'll return SPECIES_NONE aka 0. Misc. Changes -Assigned a unique value to EVO_NONE to set it apart from EVOLUTIONS_END so this new GetSpeciesPreEvolution can work out smoothly. --- include/constants/pokemon.h | 5 ++--- include/pokemon.h | 1 + src/pokemon.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 0a41ebb6b882..7c96e25d7eef 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -253,7 +253,8 @@ #define F_SUMMARY_SCREEN_FLIP_SPRITE 0x80 // Evolution types -#define EVO_NONE 0xffff // Not an actual evolution, used to generate offspring that can't evolve into the specified species, like regional forms. +#define EVOLUTIONS_END 0xFFFF +#define EVO_NONE 0xFFFE // Not an actual evolution, used to generate offspring that can't evolve into the specified species, like regional forms. #define EVO_FRIENDSHIP 1 // Pokémon levels up with friendship ≥ 220 #define EVO_FRIENDSHIP_DAY 2 // Pokémon levels up during the day with friendship ≥ 220 #define EVO_FRIENDSHIP_NIGHT 3 // Pokémon levels up at night with friendship ≥ 220 @@ -301,8 +302,6 @@ #define EVO_LEVEL_FAMILY_OF_THREE 45 // Pokémon reaches the specified level with a personality value with a modulus of 0 #define EVO_LEVEL_FAMILY_OF_FOUR 46 // Pokémon reaches the specified level with a personality value with a modulus of 1-99 -#define EVOLUTIONS_END 0xFFFF - // Evolution 'modes,' for GetEvolutionTargetSpecies #define EVO_MODE_NORMAL 0 #define EVO_MODE_TRADE 1 diff --git a/include/pokemon.h b/include/pokemon.h index ac753301eaf5..dbf4c41c3bfb 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -709,5 +709,6 @@ u8 CalculatePartyCount(struct Pokemon *party); u16 SanitizeSpeciesId(u16 species); bool32 IsSpeciesEnabled(u16 species); u16 GetCryIdBySpecies(u16 species); +u16 GetSpeciesPreEvolution(u16 species); #endif // GUARD_POKEMON_H diff --git a/src/pokemon.c b/src/pokemon.c index 47b05ff90dc1..9605b1e4aab9 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -6092,3 +6092,22 @@ u16 GetCryIdBySpecies(u16 species) return 0; return gSpeciesInfo[species].cryId; } + +u16 GetSpeciesPreEvolution(u16 species) +{ + int i, j; + + for (i = SPECIES_BULBASAUR; i < NUM_SPECIES; i++) + { + const struct Evolution *evolutions = GetSpeciesEvolutions(i); + if (evolutions == NULL) + continue; + for (j = 0; evolutions[j].method != EVOLUTIONS_END; j++) + { + if (SanitizeSpeciesId(evolutions[j].targetSpecies) == species) + return i; + } + } + + return SPECIES_NONE; +} From 4972dfb86fcfb8f802e6c53fd1772a878664db06 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 11 Dec 2023 13:37:39 -0300 Subject: [PATCH 2/3] Added a comment explaining the purpose of EVOLUTIONS_END --- include/constants/pokemon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 7c96e25d7eef..d3e4076fd06e 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -253,7 +253,7 @@ #define F_SUMMARY_SCREEN_FLIP_SPRITE 0x80 // Evolution types -#define EVOLUTIONS_END 0xFFFF +#define EVOLUTIONS_END 0xFFFF // Not an actual evolution, used to mark the end of an evolution array. #define EVO_NONE 0xFFFE // Not an actual evolution, used to generate offspring that can't evolve into the specified species, like regional forms. #define EVO_FRIENDSHIP 1 // Pokémon levels up with friendship ≥ 220 #define EVO_FRIENDSHIP_DAY 2 // Pokémon levels up during the day with friendship ≥ 220 From ebc150b7f3f4eeef74be3f1cba0b1e49fbd77914 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 11 Dec 2023 13:38:41 -0300 Subject: [PATCH 3/3] Fixed spacing in the comment for EVOLUTIONS_END --- include/constants/pokemon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index d3e4076fd06e..724fe8c0b695 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -253,7 +253,7 @@ #define F_SUMMARY_SCREEN_FLIP_SPRITE 0x80 // Evolution types -#define EVOLUTIONS_END 0xFFFF // Not an actual evolution, used to mark the end of an evolution array. +#define EVOLUTIONS_END 0xFFFF // Not an actual evolution, used to mark the end of an evolution array. #define EVO_NONE 0xFFFE // Not an actual evolution, used to generate offspring that can't evolve into the specified species, like regional forms. #define EVO_FRIENDSHIP 1 // Pokémon levels up with friendship ≥ 220 #define EVO_FRIENDSHIP_DAY 2 // Pokémon levels up during the day with friendship ≥ 220