Skip to content

Commit

Permalink
Fix Entrainment AI scoring bug (#6056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawkkie authored Jan 20, 2025
1 parent 4bcb07a commit 6ec8470
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2952,7 +2952,7 @@ static s32 AI_DoubleBattle(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
case EFFECT_ENTRAINMENT:
if (partnerHasBadAbility && IsAbilityOfRating(aiData->abilities[battlerAtk], 0))
{
RETURN_SCORE_PLUS(WEAK_EFFECT);
RETURN_SCORE_PLUS(DECENT_EFFECT);
}
break;
case EFFECT_SOAK:
Expand Down Expand Up @@ -4061,9 +4061,13 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
case EFFECT_ENTRAINMENT:
if (GetActiveGimmick(battlerDef) == GIMMICK_DYNAMAX)
break;
else if ((IsAbilityOfRating(aiData->abilities[battlerDef], 5) || gAbilitiesInfo[aiData->abilities[battlerAtk]].aiRating <= 0)
&& (aiData->abilities[battlerDef] != aiData->abilities[battlerAtk] && !(gStatuses3[battlerDef] & STATUS3_GASTRO_ACID)))
ADJUST_SCORE(DECENT_EFFECT);
if (aiData->abilities[battlerDef] != aiData->abilities[battlerAtk] && !(gStatuses3[battlerDef] & STATUS3_GASTRO_ACID))
{
if (gAbilitiesInfo[aiData->abilities[battlerAtk]].aiRating <= 0)
ADJUST_SCORE(DECENT_EFFECT);
else if (IsAbilityOfRating(aiData->abilities[battlerDef], 5) && gAbilitiesInfo[aiData->abilities[battlerAtk]].aiRating <= 3)
ADJUST_SCORE(WEAK_EFFECT);
}
break;
case EFFECT_IMPRISON:
if (predictedMove != MOVE_NONE && HasMove(battlerAtk, predictedMove))
Expand Down
13 changes: 13 additions & 0 deletions test/battle/move_effect/entrainment.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#include "global.h"
#include "test/battle.h"

AI_DOUBLE_BATTLE_TEST("AI prefers Entrainment'ing good abilities onto partner with bad ability")
{
GIVEN {
AI_FLAGS(AI_FLAG_SMART_TRAINER);
PLAYER(SPECIES_QUAXWELL) { Level(18); Ability(ABILITY_TORRENT); Moves(MOVE_WATER_GUN); };
PLAYER(SPECIES_CORPHISH) { Level(18); Moves(MOVE_WATER_GUN); };
OPPONENT(SPECIES_SMEARGLE) { Level(17); Ability(ABILITY_TECHNICIAN); Moves(MOVE_AERIAL_ACE, MOVE_ENTRAINMENT, MOVE_FLAME_WHEEL, MOVE_MAGICAL_LEAF); }
OPPONENT(SPECIES_ARCHEN) { Level(17); Ability(ABILITY_DEFEATIST); Moves(MOVE_DUAL_WINGBEAT, MOVE_ROCK_TOMB); }
} WHEN {
TURN { EXPECT_MOVE(opponentLeft, MOVE_ENTRAINMENT); EXPECT_MOVE(opponentRight, MOVE_DUAL_WINGBEAT); MOVE(playerLeft, MOVE_WATER_GUN); MOVE(playerRight, MOVE_WATER_GUN); }
}
}

TO_DO_BATTLE_TEST("Entrainment changes the target's Ability to match the user's");
TO_DO_BATTLE_TEST("Entrainment fails if the user's ability has cantBeCopied flag");
TO_DO_BATTLE_TEST("Entrainment fails if the targets's ability has cantBeOverwritten flag");

0 comments on commit 6ec8470

Please sign in to comment.