From 9fdd6fffee4d06d56f610ff3265adcb4571dbc3c Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 15 Nov 2021 10:45:23 -0500 Subject: [PATCH] AI_GetAbility supports hidden abilities --- src/battle_ai_util.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index c90c9cdab4..499969ec33 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -1133,18 +1133,17 @@ s32 AI_GetAbility(u32 battlerId) || gBattleMons[battlerId].ability == ABILITY_MAGNET_PULL || gBattleMons[battlerId].ability == ABILITY_ARENA_TRAP) return gBattleMons[battlerId].ability; - + + // AI has no knowledge of opponent, so it guesses which ability. if (gBaseStats[gBattleMons[battlerId].species].abilities[0] != ABILITY_NONE) { - if (gBaseStats[gBattleMons[battlerId].species].abilities[1] != ABILITY_NONE) + u16 abilityGuess = ABILITY_NONE; + while (abilityGuess == ABILITY_NONE) { - // AI has no knowledge of opponent, so it guesses which ability. - return gBaseStats[gBattleMons[battlerId].species].abilities[Random() & 1]; - } - else - { - return gBaseStats[gBattleMons[battlerId].species].abilities[0]; // It's definitely ability 1. + abilityGuess = gBaseStats[gBattleMons[battlerId].species].abilities[Random() % NUM_ABILITY_SLOTS]; } + + return abilityGuess; } return ABILITY_NONE; // Unknown. }