Skip to content

Commit

Permalink
Trace trapping switches
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawkkie committed Jan 20, 2025
1 parent 4825e52 commit 7af888a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/battle_ai_switch_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static bool32 ShouldSwitchIfTrapperInParty(u32 battler)

monAbility = GetMonAbility(&party[i]);

if (CanAbilityTrapOpponent(monAbility, opposingBattler))
if (CanAbilityTrapOpponent(monAbility, opposingBattler) || (CanAbilityTrapOpponent(gBattleMons[opposingBattler].ability, opposingBattler) && monAbility == ABILITY_TRACE))
{
// If mon in slot i is the most suitable switchin candidate, then it's a trapper than wins 1v1
if (i == AI_DATA->mostSuitableMonId[battler])
Expand Down Expand Up @@ -1915,7 +1915,8 @@ static u32 GetBestMonIntegrated(struct Pokemon *party, int firstId, int lastId,
}

// If mon can trap
if (CanAbilityTrapOpponent(AI_DATA->switchinCandidate.battleMon.ability, opposingBattler)
if ((CanAbilityTrapOpponent(AI_DATA->switchinCandidate.battleMon.ability, opposingBattler)
|| (CanAbilityTrapOpponent(gBattleMons[opposingBattler].ability, opposingBattler) && AI_DATA->switchinCandidate.battleMon.ability == ABILITY_TRACE))
&& CountUsablePartyMons(opposingBattler) > 0
&& canSwitchinWin1v1)
trapperId = i;
Expand Down
19 changes: 16 additions & 3 deletions test/battle/ai/ai_switching.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ AI_SINGLE_BATTLE_TEST("AI_FLAG_SMART_MON_CHOICES: AI will switch in trapping mon
u32 aiSmartMonChoicesFlag = 0; // Enables trapping behaviour after KOs
PARAMETRIZE { aiSmartMonChoicesFlag = 0; } // No trapping behaviour
PARAMETRIZE { aiSmartMonChoicesFlag = AI_FLAG_SMART_MON_CHOICES; } // Traps with mid battle switches
GIVEN{
GIVEN {
ASSUME(gSpeciesInfo[SPECIES_MAWILE].types[0] == TYPE_STEEL);
AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT | aiSmartMonChoicesFlag);
PLAYER(SPECIES_MAWILE) { Speed(2); Moves(MOVE_PROTECT, MOVE_TACKLE); }
Expand All @@ -443,15 +443,28 @@ AI_SINGLE_BATTLE_TEST("AI won't use trapping behaviour if player only has 1 mon
u32 aiSmartMonChoicesFlag = 0; // Enables trapping behaviour after KOs
PARAMETRIZE { aiSmartMonChoicesFlag = 0; } // No trapping behaviour
PARAMETRIZE { aiSmartMonChoicesFlag = AI_FLAG_SMART_MON_CHOICES; } // Traps with mid battle switches
GIVEN{
GIVEN {
ASSUME(gSpeciesInfo[SPECIES_MAWILE].types[0] == TYPE_STEEL);
AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT | aiSmartMonChoicesFlag);
PLAYER(SPECIES_MAWILE) { Speed(2); Moves(MOVE_PROTECT, MOVE_TACKLE); }
OPPONENT(SPECIES_SNORLAX) { Speed(3); Moves(MOVE_SELF_DESTRUCT); }
OPPONENT(SPECIES_MAGNEZONE) { Speed(1); Ability(ABILITY_MAGNET_PULL); Moves(MOVE_SHOCK_WAVE); }
OPPONENT(SPECIES_MEGANIUM) { Speed(3); Moves(MOVE_EARTH_POWER); }
} WHEN {
TURN{ MOVE(player, MOVE_PROTECT); EXPECT_MOVE(opponent, MOVE_SELF_DESTRUCT); EXPECT_SEND_OUT(opponent, 2); }
TURN{ MOVE(player, MOVE_PROTECT); EXPECT_MOVE(opponent, MOVE_SELF_DESTRUCT); EXPECT_SEND_OUT(opponent, 2); }
}
}

AI_SINGLE_BATTLE_TEST("AI will trap player using Trace if player has a trapper")
{
GIVEN {
AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT | AI_FLAG_OMNISCIENT | AI_FLAG_SMART_SWITCHING);
PLAYER(SPECIES_DUGTRIO) { Ability(ABILITY_ARENA_TRAP); Moves(MOVE_ROCK_TOMB); }
PLAYER(SPECIES_DUGTRIO);
OPPONENT(SPECIES_GENGAR);
OPPONENT(SPECIES_PORYGON2) { Ability(ABILITY_TRACE); Item(ITEM_EVIOLITE); Moves(MOVE_ICE_BEAM); }
} WHEN {
TURN { MOVE(player, MOVE_ROCK_TOMB); EXPECT_SWITCH(opponent, 1); }
}
}

Expand Down

0 comments on commit 7af888a

Please sign in to comment.