Skip to content

Commit

Permalink
Applied review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cfmnephrite committed Jan 24, 2024
1 parent 399881e commit ef159a8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion include/battle_ai_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool32 IsStatLoweringMoveEffect(u32 moveEffect);
bool32 IsMoveRedirectionPrevented(u32 move, u32 atkAbility);
bool32 IsMoveEncouragedToHit(u32 battlerAtk, u32 battlerDef, u32 move);
bool32 IsHazardMoveEffect(u32 moveEffect);
bool32 IsChargingMove(u32 battlerAtk, u32 move);
bool32 IsTwoTurnNotSemiInvulnerableMove(u32 battlerAtk, u32 move);
void ProtectChecks(u32 battlerAtk, u32 battlerDef, u32 move, u32 predictedMove, s32 *score);
bool32 ShouldSetSandstorm(u32 battler, u32 ability, u32 holdEffect);
bool32 ShouldSetHail(u32 battler, u32 ability, u32 holdEffect);
Expand Down
12 changes: 6 additions & 6 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
if (IsSemiInvulnerable(battlerDef, move) && moveEffect != EFFECT_SEMI_INVULNERABLE && AI_WhoStrikesFirst(battlerAtk, battlerDef, move) == AI_IS_FASTER)
RETURN_SCORE_MINUS(20); // if target off screen and we go first, don't use move

if (IsChargingMove(battlerAtk, move) && CanTargetFaintAi(battlerDef, battlerAtk))
if (IsTwoTurnNotSemiInvulnerableMove(battlerAtk, move) && CanTargetFaintAi(battlerDef, battlerAtk))
RETURN_SCORE_MINUS(10);

// check if negates type
Expand Down Expand Up @@ -3109,7 +3109,7 @@ static s32 AI_CompareDamagingMoves(u32 battlerAtk, u32 battlerDef, u32 currId)
s32 score = 0;
s32 leastHits = 1000;
u16 *moves = GetMovesArray(battlerAtk);
bool8 isChargingMoveEffect[MAX_MON_MOVES];
bool8 isTwoTurnNotSemiInvulnerableMove[MAX_MON_MOVES];

for (i = 0; i < MAX_MON_MOVES; i++)
{
Expand All @@ -3121,13 +3121,13 @@ static s32 AI_CompareDamagingMoves(u32 battlerAtk, u32 battlerDef, u32 currId)
leastHits = noOfHits[i];
}
viableMoveScores[i] = AI_SCORE_DEFAULT;
isChargingMoveEffect[i] = IsChargingMove(battlerAtk, moves[i]);
isTwoTurnNotSemiInvulnerableMove[i] = IsTwoTurnNotSemiInvulnerableMove(battlerAtk, moves[i]);
}
else
{
noOfHits[i] = -1;
viableMoveScores[i] = 0;
isChargingMoveEffect[i] = FALSE;
isTwoTurnNotSemiInvulnerableMove[i] = FALSE;
}
/*
MgbaPrintf_("%S: required hits: %d Dmg: %d", gMoveNames[moves[i]], noOfHits[i], AI_DATA->simulatedDmg[battlerAtk][battlerDef][i]);
Expand All @@ -3151,9 +3151,9 @@ static s32 AI_CompareDamagingMoves(u32 battlerAtk, u32 battlerDef, u32 currId)
{
multipleBestMoves = TRUE;
// We need to make sure it's the current move which is objectively better.
if (isChargingMoveEffect[i] && !isChargingMoveEffect[currId])
if (isTwoTurnNotSemiInvulnerableMove[i] && !isTwoTurnNotSemiInvulnerableMove[currId])
viableMoveScores[i] -= 3;
else if (!isChargingMoveEffect[i] && isChargingMoveEffect[currId])
else if (!isTwoTurnNotSemiInvulnerableMove[i] && isTwoTurnNotSemiInvulnerableMove[currId])
viableMoveScores[currId] -= 3;

switch (CompareMoveAccuracies(battlerAtk, battlerDef, currId, i))
Expand Down
2 changes: 1 addition & 1 deletion src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ bool32 HasSnatchAffectedMove(u32 battler)
CHECK_MOVE_FLAG(snatchAffected);
}

bool32 IsChargingMove(u32 battlerAtk, u32 move)
bool32 IsTwoTurnNotSemiInvulnerableMove(u32 battlerAtk, u32 move)
{
switch (gBattleMoves[move].effect)
{
Expand Down
30 changes: 10 additions & 20 deletions test/battle/move_effect/two_turn_moves.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ SINGLE_BATTLE_TEST("Razor Wind doesn't need to charge with Power Herb")
} WHEN {
TURN { MOVE(player, MOVE_RAZOR_WIND); }
} SCENE {
if (B_UPDATED_MOVE_DATA >= GEN_5)
{
if (B_UPDATED_MOVE_DATA >= GEN_5) {
NOT MESSAGE("Wobbuffet whipped up a whirlwind!");
MESSAGE("Wobbuffet used Razor Wind!");
}
else
} else
ANIMATION(ANIM_TYPE_MOVE, MOVE_RAZOR_WIND, player);
if (B_UPDATED_MOVE_DATA < GEN_5)
MESSAGE("Wobbuffet whipped up a whirlwind!");
Expand All @@ -74,12 +72,10 @@ SINGLE_BATTLE_TEST("Skull Bash needs a charging turn")
TURN { SKIP_TURN(player); }
} SCENE {
// Charging turn
if (B_UPDATED_MOVE_DATA >= GEN_5)
{
if (B_UPDATED_MOVE_DATA >= GEN_5) {
NOT MESSAGE("Wobbuffet lowered its head!");
MESSAGE("Wobbuffet used Skull Bash!");
}
else
} else
ANIMATION(ANIM_TYPE_MOVE, MOVE_SKULL_BASH, player);
if (B_UPDATED_MOVE_DATA < GEN_5)
MESSAGE("Wobbuffet lowered its head!");
Expand All @@ -102,12 +98,10 @@ SINGLE_BATTLE_TEST("Skull Bash doesn't need to charge with Power Herb")
} WHEN {
TURN { MOVE(player, MOVE_SKULL_BASH); }
} SCENE {
if (B_UPDATED_MOVE_DATA >= GEN_5)
{
if (B_UPDATED_MOVE_DATA >= GEN_5) {
NOT MESSAGE("Wobbuffet lowered its head!");
MESSAGE("Wobbuffet used Skull Bash!");
}
else
} else
ANIMATION(ANIM_TYPE_MOVE, MOVE_SKULL_BASH, player);
if (B_UPDATED_MOVE_DATA < GEN_5)
MESSAGE("Wobbuffet lowered its head!");
Expand All @@ -134,15 +128,13 @@ SINGLE_BATTLE_TEST("Sky Attack needs a charging turn")
TURN { SKIP_TURN(player); }
} SCENE {
// Charging turn
if (B_UPDATED_MOVE_DATA >= GEN_5)
{
if (B_UPDATED_MOVE_DATA >= GEN_5) {
NONE_OF {
MESSAGE("Wobbuffet became cloaked in a harsh light!");
MESSAGE("Wobbuffet is glowing!");
}
MESSAGE("Wobbuffet used Sky Attack!");
}
else
} else
ANIMATION(ANIM_TYPE_MOVE, MOVE_SKY_ATTACK, player);
if (B_UPDATED_MOVE_DATA < GEN_4)
MESSAGE("Wobbuffet is glowing!");
Expand All @@ -165,15 +157,13 @@ SINGLE_BATTLE_TEST("Sky Attack doesn't need to charge with Power Herb")
} WHEN {
TURN { MOVE(player, MOVE_SKY_ATTACK); }
} SCENE {
if (B_UPDATED_MOVE_DATA >= GEN_5)
{
if (B_UPDATED_MOVE_DATA >= GEN_5) {
NONE_OF {
MESSAGE("Wobbuffet became cloaked in a harsh light!");
MESSAGE("Wobbuffet is glowing!");
}
MESSAGE("Wobbuffet used Sky Attack!");
}
else
} else
ANIMATION(ANIM_TYPE_MOVE, MOVE_SKY_ATTACK, player);
if (B_UPDATED_MOVE_DATA < GEN_4)
MESSAGE("Wobbuffet is glowing!");
Expand Down

0 comments on commit ef159a8

Please sign in to comment.