Skip to content

Commit

Permalink
Fixed Steam Roller AI check affecting Terrain setting effects (#4498)
Browse files Browse the repository at this point in the history
* Fixed battle_ai_util.c whitespace

* Add arguments check

* Parenthesis

* Update src/battle_ai_util.c

Co-authored-by: Alex <[email protected]>

* Added AI tests by AlexOn1ine

---------

Co-authored-by: Alex <[email protected]>
  • Loading branch information
AsparagusEduardo and AlexOn1ine authored May 5, 2024
1 parent 41138f1 commit e20cb62
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ bool32 IsDamageMoveUnusable(u32 move, u32 battlerAtk, u32 battlerDef)
return TRUE;
break;
case EFFECT_HIT_SET_REMOVE_TERRAIN:
if (!(gFieldStatuses & STATUS_FIELD_TERRAIN_ANY))
return TRUE;
break;
if (!(gFieldStatuses & STATUS_FIELD_TERRAIN_ANY) && gMovesInfo[move].argument == ARG_TRY_REMOVE_TERRAIN_FAIL)
return TRUE;
break;
}

return FALSE;
Expand Down
42 changes: 42 additions & 0 deletions test/battle/move_effect/hit_set_remove_terrain.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,45 @@ SINGLE_BATTLE_TEST("Ice Spinner doesn't fail if there is no terrain on the field
NOT MESSAGE("But it failed!");
}
}

AI_SINGLE_BATTLE_TEST("Steel Roller will not be chosen by the AI if it might fail")
{
u32 move;

PARAMETRIZE { move = MOVE_ELECTRIC_TERRAIN; }
PARAMETRIZE { move = MOVE_NONE; }

GIVEN {
AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT);
PLAYER(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WOBBUFFET) { Moves(MOVE_STEEL_ROLLER, MOVE_ICE_SHARD); }
} WHEN {
if (move == MOVE_ELECTRIC_TERRAIN) {
TURN { MOVE(player, MOVE_ELECTRIC_TERRAIN); EXPECT_MOVE(opponent, MOVE_ICE_SHARD); }
TURN { EXPECT_MOVE(opponent, MOVE_STEEL_ROLLER); }
} else {
TURN { EXPECT_MOVE(opponent, MOVE_ICE_SHARD); }
}
}
}

AI_SINGLE_BATTLE_TEST("Ice Spinner can be chosen by the AI regardless if there is a terrain or not")
{
u32 move;

PARAMETRIZE { move = MOVE_ELECTRIC_TERRAIN; }
PARAMETRIZE { move = MOVE_NONE; }

GIVEN {
AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT);
PLAYER(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WOBBUFFET) { Moves(MOVE_ICE_SPINNER, MOVE_ICE_SHARD); }
} WHEN {
if (move == MOVE_ELECTRIC_TERRAIN) {
TURN { MOVE(player, MOVE_ELECTRIC_TERRAIN); EXPECT_MOVE(opponent, MOVE_ICE_SPINNER); }
TURN { EXPECT_MOVE(opponent, MOVE_ICE_SPINNER); }
} else {
TURN { EXPECT_MOVE(opponent, MOVE_ICE_SPINNER); }
}
}
}

0 comments on commit e20cb62

Please sign in to comment.