diff --git a/include/constants/generational_changes.h b/include/constants/generational_changes.h index f80db1c1a7..e9653d26d5 100644 --- a/include/constants/generational_changes.h +++ b/include/constants/generational_changes.h @@ -11,6 +11,7 @@ enum GenConfigTag GEN_CONFIG_MULTI_HIT_CHANCE, GEN_CONFIG_GALE_WINGS, GEN_CONFIG_HEAL_BELL_SOUNDPROOF, + GEN_CONFIG_TELEPORT_BEHAVIOR, GEN_CONFIG_COUNT }; diff --git a/include/generational_changes.h b/include/generational_changes.h index 540b51e20b..1aad93f915 100644 --- a/include/generational_changes.h +++ b/include/generational_changes.h @@ -14,6 +14,7 @@ static const u8 sGenerationalChanges[GEN_CONFIG_COUNT] = [GEN_CONFIG_MULTI_HIT_CHANCE] = B_MULTI_HIT_CHANCE, [GEN_CONFIG_GALE_WINGS] = B_GALE_WINGS, [GEN_CONFIG_HEAL_BELL_SOUNDPROOF] = B_HEAL_BELL_SOUNDPROOF, + [GEN_CONFIG_TELEPORT_BEHAVIOR] = B_TELEPORT_BEHAVIOR, }; #if TESTING diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index f4b72c65b5..73a9b4505c 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -1852,7 +1852,7 @@ static inline bool32 IsFreeSwitch(enum SwitchType switchType, u32 battlerSwitchi // Switch out effects if (!IsDoubleBattle()) // Not handling doubles' additional complexity { - if (IsSwitchOutEffect(GetMoveEffect(gLastUsedMove)) && movedSecond) + if (IsSwitchOutEffect(GetMoveEffect(gCurrentMove)) && movedSecond) return TRUE; if (AI_DATA->ejectButtonSwitch) return TRUE; @@ -2066,7 +2066,7 @@ static u32 GetBestMonIntegrated(struct Pokemon *party, int firstId, int lastId, } // If ace mon is the last available Pokemon and U-Turn/Volt Switch or Eject Pack/Button was used - switch to the mon. if (aceMonId != PARTY_SIZE && CountUsablePartyMons(battler) <= aceMonCount - && (IsSwitchOutEffect(GetMoveEffect(gLastUsedMove)) || AI_DATA->ejectButtonSwitch || AI_DATA->ejectPackSwitch)) + && (IsSwitchOutEffect(GetMoveEffect(gCurrentMove)) || AI_DATA->ejectButtonSwitch || AI_DATA->ejectPackSwitch)) return aceMonId; return PARTY_SIZE; @@ -2183,7 +2183,7 @@ u32 GetMostSuitableMonToSwitchInto(u32 battler, enum SwitchType switchType) // If ace mon is the last available Pokemon and U-Turn/Volt Switch or Eject Pack/Button was used - switch to the mon. if (aceMonId != PARTY_SIZE && CountUsablePartyMons(battler) <= aceMonCount - && (IsSwitchOutEffect(GetMoveEffect(gLastUsedMove)) || AI_DATA->ejectButtonSwitch || AI_DATA->ejectPackSwitch)) + && (IsSwitchOutEffect(GetMoveEffect(gCurrentMove)) || AI_DATA->ejectButtonSwitch || AI_DATA->ejectPackSwitch)) return aceMonId; return PARTY_SIZE; diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 60b707808f..ca94655476 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -2407,6 +2407,9 @@ bool32 IsSwitchOutEffect(u32 effect) // Switch out effects like U-Turn, Volt Switch, etc. switch (effect) { + case EFFECT_TELEPORT: + if (B_TELEPORT_BEHAVIOR >= GEN_8) + return TRUE; case EFFECT_HIT_ESCAPE: case EFFECT_PARTING_SHOT: case EFFECT_BATON_PASS: diff --git a/test/battle/ai/ai_switching.c b/test/battle/ai/ai_switching.c index 367afbc0f1..5d7a61473a 100644 --- a/test/battle/ai/ai_switching.c +++ b/test/battle/ai/ai_switching.c @@ -106,16 +106,30 @@ AI_DOUBLE_BATTLE_TEST("AI will not try to switch for the same pokemon for 2 spot } } -AI_SINGLE_BATTLE_TEST("AI_FLAG_SMART_MON_CHOICES: U-Turn will send out Ace Mon if it's the only one remaining") +AI_SINGLE_BATTLE_TEST("AI_FLAG_SMART_MON_CHOICES: Switch effect moves will send out Ace Mon if it's the only one remaining") { + u32 aiMove = 0; + // Moves testing all effects in IsSwitchOutEffect + PARAMETRIZE { aiMove = MOVE_U_TURN; } + PARAMETRIZE { aiMove = MOVE_TELEPORT; } + PARAMETRIZE { aiMove = MOVE_PARTING_SHOT; } + PARAMETRIZE { aiMove = MOVE_BATON_PASS; } + PARAMETRIZE { aiMove = MOVE_CHILLY_RECEPTION; } + PARAMETRIZE { aiMove = MOVE_SHED_TAIL; } GIVEN { ASSUME(GetMoveEffect(MOVE_U_TURN) == EFFECT_HIT_ESCAPE); + ASSUME(GetMoveEffect(MOVE_TELEPORT) == EFFECT_TELEPORT); + ASSUME(GetMoveEffect(MOVE_PARTING_SHOT) == EFFECT_PARTING_SHOT); + ASSUME(GetMoveEffect(MOVE_BATON_PASS) == EFFECT_BATON_PASS); + ASSUME(GetMoveEffect(MOVE_CHILLY_RECEPTION) == EFFECT_CHILLY_RECEPTION); + ASSUME(GetMoveEffect(MOVE_SHED_TAIL) == EFFECT_SHED_TAIL); + WITH_CONFIG(GEN_CONFIG_TELEPORT_BEHAVIOR, GEN_8); AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SMART_MON_CHOICES | AI_FLAG_ACE_POKEMON); PLAYER(SPECIES_WOBBUFFET); - OPPONENT(SPECIES_WOBBUFFET) { Moves(MOVE_U_TURN); } + OPPONENT(SPECIES_WOBBUFFET) { Moves(aiMove); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { - TURN { EXPECT_MOVE(opponent, MOVE_U_TURN); EXPECT_SEND_OUT(opponent, 1); } + TURN { EXPECT_MOVE(opponent, aiMove); EXPECT_SEND_OUT(opponent, 1); } } }