diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index dfd1a496f..cbec5bdb5 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -368,6 +368,8 @@ #define MON_PIC_SIZE (64 * 64 / 2) -#define NUM_ABILITY_SLOTS 3 +#define NUM_ABILITY_SLOTS (NUM_NORMAL_ABILITY_SLOTS + NUM_HIDDEN_ABILITY_SLOTS) +#define NUM_NORMAL_ABILITY_SLOTS 2 +#define NUM_HIDDEN_ABILITY_SLOTS 1 #endif // GUARD_CONSTANTS_POKEMON_H diff --git a/src/pokemon.c b/src/pokemon.c index baf408fce..e0e4f6b74 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5369,14 +5369,26 @@ u8 GetMonsStateToDoubles_2(void) u8 GetAbilityBySpecies(u16 species, u8 abilityNum) { + int i; + if (abilityNum < NUM_ABILITY_SLOTS) gLastUsedAbility = gBaseStats[species].abilities[abilityNum]; else - gLastUsedAbility = gBaseStats[species].abilities[0]; - - if (gLastUsedAbility == ABILITY_NONE) - gLastUsedAbility = gBaseStats[species].abilities[0]; - + gLastUsedAbility = ABILITY_NONE; + + if (abilityNum >= NUM_NORMAL_ABILITY_SLOTS) // if abilityNum is empty hidden ability, look for other hidden abilities + { + for (i = NUM_NORMAL_ABILITY_SLOTS; i < NUM_ABILITY_SLOTS && gLastUsedAbility == ABILITY_NONE; i++) + { + gLastUsedAbility = gBaseStats[species].abilities[i]; + } + } + + for (i = 0; i < NUM_ABILITY_SLOTS && gLastUsedAbility == ABILITY_NONE; i++) // look for any non-empty ability + { + gLastUsedAbility = gBaseStats[species].abilities[i]; + } + return gLastUsedAbility; }