From d0a8e9fb31f33fe4ab055fa94c2729c51c12d757 Mon Sep 17 00:00:00 2001 From: sneed <56992013+Sneed69@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:27:07 +0300 Subject: [PATCH] Use AI_DATA->abilities in more places (#4729) * use AI_DATA->abilities in more places * Missed one * restore the hack --- src/battle_ai_main.c | 2 +- src/battle_ai_switch_items.c | 8 ++++---- src/battle_ai_util.c | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 10ad41d1fcc0..b25602b8b505 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -570,7 +570,7 @@ static bool32 AI_ShouldSwitchIfBadMoves(u32 battler, bool32 doubleBattle) // Consider switching if your mon with truant is bodied by Protect spam. // Or is using a double turn semi invulnerable move(such as Fly) and is faster. - if (GetBattlerAbility(battler) == ABILITY_TRUANT + if (AI_DATA->abilities[battler] == ABILITY_TRUANT && IsTruantMonVulnerable(battler, gBattlerTarget) && gDisableStructs[battler].truantCounter && gBattleMons[battler].hp >= gBattleMons[battler].maxHP / 2 diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 77552ccae980..63690220561a 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -73,7 +73,7 @@ static bool32 HasBadOdds(u32 battler, bool32 emitResult) //Variable initialization u8 opposingPosition, atkType1, atkType2, defType1, defType2, effectiveness; s32 i, damageDealt = 0, maxDamageDealt = 0, damageTaken = 0, maxDamageTaken = 0; - u32 aiMove, playerMove, aiBestMove = MOVE_NONE, aiAbility = GetBattlerAbility(battler), opposingBattler, weather = AI_GetWeather(AI_DATA); + u32 aiMove, playerMove, aiBestMove = MOVE_NONE, aiAbility = AI_DATA->abilities[battler], opposingBattler, weather = AI_GetWeather(AI_DATA); bool32 getsOneShot = FALSE, hasStatusMove = FALSE, hasSuperEffectiveMove = FALSE; u16 typeEffectiveness = UQ_4_12(1.0), aiMoveEffect; //baseline typing damage @@ -247,7 +247,7 @@ static bool32 ShouldSwitchIfWonderGuard(u32 battler, bool32 emitResult) opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(battler)); - if (GetBattlerAbility(GetBattlerAtPosition(opposingPosition)) != ABILITY_WONDER_GUARD) + if (AI_DATA->abilities[GetBattlerAtPosition(opposingPosition)] != ABILITY_WONDER_GUARD) return FALSE; // Check if Pokémon has a super effective move. @@ -837,7 +837,7 @@ static bool32 CanMonSurviveHazardSwitchin(u32 battler) { u32 battlerIn1, battlerIn2; u32 hazardDamage = 0, battlerHp = gBattleMons[battler].hp; - u32 ability = GetBattlerAbility(battler), aiMove; + u32 ability = AI_DATA->abilities[battler], aiMove; s32 firstId, lastId, i, j; struct Pokemon *party; @@ -1742,7 +1742,7 @@ static bool32 CanAbilityTrapOpponent(u16 ability, u32 opponent) return FALSE; else if (ability == ABILITY_SHADOW_TAG) { - if (B_SHADOW_TAG_ESCAPE >= GEN_4 && GetBattlerAbility(opponent) == ABILITY_SHADOW_TAG) // Check if ability exists in species + if (B_SHADOW_TAG_ESCAPE >= GEN_4 && AI_DATA->abilities[opponent] == ABILITY_SHADOW_TAG) // Check if ability exists in species return FALSE; else return TRUE; diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 7efee7ae05f5..0b6d7b3b9adf 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -33,6 +33,7 @@ return FALSE static u32 AI_GetEffectiveness(uq4_12_t multiplier); +u32 AI_GetBattlerAbility(u32); // Functions bool32 AI_IsFaster(u32 battlerAi, u32 battlerDef, u32 move) @@ -413,7 +414,7 @@ bool32 IsDamageMoveUnusable(u32 move, u32 battlerAtk, u32 battlerDef) // Battler doesn't see partners Ability for some reason. // This is a small hack to avoid the issue but should be investigated if (battlerDef == BATTLE_PARTNER(battlerAtk)) - battlerDefAbility = GetBattlerAbility(battlerDef); + battlerDefAbility = AI_GetBattlerAbility(battlerDef); switch (battlerDefAbility) {