Skip to content

Commit

Permalink
Use AI_DATA->abilities in more places (#4729)
Browse files Browse the repository at this point in the history
* use AI_DATA->abilities in more places

* Missed one

* restore the hack
  • Loading branch information
Sneed69 authored Jun 6, 2024
1 parent 8e15603 commit d0a8e9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/battle_ai_switch_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit d0a8e9f

Please sign in to comment.