fix hit escape switching

This commit is contained in:
Pawkkie 2025-03-29 14:18:20 -04:00
parent c1364e14d4
commit 1c0e5bb0e1
5 changed files with 25 additions and 6 deletions

View File

@ -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
};

View File

@ -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

View File

@ -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;

View File

@ -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:

View File

@ -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); }
}
}