mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-13 15:13:42 +01:00
Fix switch-in abilities activating on empty field
This commit is contained in:
parent
380af442c3
commit
03915524c5
@ -644,6 +644,7 @@ struct BattleStruct
|
|||||||
struct StolenItem itemStolen[PARTY_SIZE]; // Player's team that had items stolen (two bytes per party member)
|
struct StolenItem itemStolen[PARTY_SIZE]; // Player's team that had items stolen (two bytes per party member)
|
||||||
u8 blunderPolicy:1; // should blunder policy activate
|
u8 blunderPolicy:1; // should blunder policy activate
|
||||||
u8 swapDamageCategory:1; // Photon Geyser, Shell Side Arm, Light That Burns the Sky
|
u8 swapDamageCategory:1; // Photon Geyser, Shell Side Arm, Light That Burns the Sky
|
||||||
|
u8 switchInAbilityPostponed:4; // To not activate against an empty field, each bit for battler
|
||||||
u8 ballSpriteIds[2]; // item gfx, window gfx
|
u8 ballSpriteIds[2]; // item gfx, window gfx
|
||||||
u8 stickyWebUser;
|
u8 stickyWebUser;
|
||||||
u8 appearedInBattle; // Bitfield to track which Pokemon appeared in battle. Used for Burmy's form change
|
u8 appearedInBattle; // Bitfield to track which Pokemon appeared in battle. Used for Burmy's form change
|
||||||
|
@ -44,6 +44,7 @@ u16 GetSecretPowerMoveEffect(void);
|
|||||||
void StealTargetItem(u8 battlerStealer, u8 battlerItem);
|
void StealTargetItem(u8 battlerStealer, u8 battlerItem);
|
||||||
u8 GetCatchingBattler(void);
|
u8 GetCatchingBattler(void);
|
||||||
u32 GetHighestStatId(u32 battlerId);
|
u32 GetHighestStatId(u32 battlerId);
|
||||||
|
bool32 DoSwitchInAbilitiesItems(u32 battlerId);
|
||||||
|
|
||||||
extern void (* const gBattleScriptingCommandsTable[])(void);
|
extern void (* const gBattleScriptingCommandsTable[])(void);
|
||||||
extern const u8 gBattlePalaceNatureToMoveGroupLikelihood[NUM_NATURES][4];
|
extern const u8 gBattlePalaceNatureToMoveGroupLikelihood[NUM_NATURES][4];
|
||||||
|
@ -6900,6 +6900,35 @@ static void SetDmgHazardsBattlescript(u8 battlerId, u8 multistringId)
|
|||||||
gBattlescriptCurrInstr = BattleScript_DmgHazardsOnFaintedBattler;
|
gBattlescriptCurrInstr = BattleScript_DmgHazardsOnFaintedBattler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool32 DoSwitchInAbilitiesItems(u32 battlerId)
|
||||||
|
{
|
||||||
|
return (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, battlerId, 0, 0, 0)
|
||||||
|
|| (gBattleWeather & B_WEATHER_ANY && WEATHER_HAS_EFFECT && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, battlerId, 0, 0, 0))
|
||||||
|
|| (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, battlerId, 0, 0, 0))
|
||||||
|
|| ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, battlerId, FALSE)
|
||||||
|
|| AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool32 ShouldPostponeSwitchInAbilities(u32 battlerId)
|
||||||
|
{
|
||||||
|
bool32 aliveOpposing1 = IsBattlerAlive(BATTLE_OPPOSITE(battlerId));
|
||||||
|
bool32 aliveOpposing2 = IsBattlerAlive(BATTLE_PARTNER(BATTLE_OPPOSITE(battlerId)));
|
||||||
|
// No pokemon on opposing side - postopone.
|
||||||
|
if (!aliveOpposing1 && !aliveOpposing2)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
// Checks for double battle, so abilities like Intimidate wait until all battlers are switched-in before activating.
|
||||||
|
if (IsDoubleBattle())
|
||||||
|
{
|
||||||
|
if (aliveOpposing1 && !aliveOpposing2 && !HasNoMonsToSwitch(BATTLE_OPPOSITE(battlerId), PARTY_SIZE, PARTY_SIZE))
|
||||||
|
return TRUE;
|
||||||
|
if (!aliveOpposing1 && aliveOpposing2 && !HasNoMonsToSwitch(BATTLE_PARTNER(BATTLE_OPPOSITE(battlerId)), PARTY_SIZE, PARTY_SIZE))
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void Cmd_switchineffects(void)
|
static void Cmd_switchineffects(void)
|
||||||
{
|
{
|
||||||
CMD_ARGS(u8 battler);
|
CMD_ARGS(u8 battler);
|
||||||
@ -7016,12 +7045,17 @@ static void Cmd_switchineffects(void)
|
|||||||
|
|
||||||
gDisableStructs[gActiveBattler].truantSwitchInHack = 0;
|
gDisableStructs[gActiveBattler].truantSwitchInHack = 0;
|
||||||
|
|
||||||
if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gActiveBattler, 0, 0, 0)
|
// Don't activate switch-in abilities if the opposing field is empty.
|
||||||
|| (gBattleWeather & B_WEATHER_ANY && WEATHER_HAS_EFFECT && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, gActiveBattler, 0, 0, 0))
|
// This could happen when a mon uses explosion and causes everyone to faint.
|
||||||
|| (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, gActiveBattler, 0, 0, 0))
|
if (ShouldPostponeSwitchInAbilities(gActiveBattler) || gBattleStruct->switchInAbilityPostponed)
|
||||||
|| ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gActiveBattler, FALSE)
|
{
|
||||||
|| AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0))
|
gBattleStruct->switchInAbilityPostponed |= gBitTable[gActiveBattler];
|
||||||
return;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (DoSwitchInAbilitiesItems(gActiveBattler))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
gSideStatuses[GetBattlerSide(gActiveBattler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED);
|
gSideStatuses[GetBattlerSide(gActiveBattler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED);
|
||||||
|
|
||||||
@ -11016,21 +11050,21 @@ static void Cmd_various(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case VARIOUS_JUMP_IF_NO_VALID_TARGETS:
|
case VARIOUS_JUMP_IF_NO_VALID_TARGETS:
|
||||||
{
|
{
|
||||||
VARIOUS_ARGS(const u8 *jumpInstr);
|
VARIOUS_ARGS(const u8 *jumpInstr);
|
||||||
u32 count = 0;
|
u32 count = 0;
|
||||||
|
|
||||||
for (i = 0; i < gBattlersCount; i++)
|
for (i = 0; i < gBattlersCount; i++)
|
||||||
{
|
{
|
||||||
if (GetBattlerSide(i) != GetBattlerSide(gBattlerAttacker) && IsBattlerAlive(i))
|
if (GetBattlerSide(i) != GetBattlerSide(gBattlerAttacker) && IsBattlerAlive(i))
|
||||||
count++;
|
count++;
|
||||||
}
|
|
||||||
if (count == 0)
|
|
||||||
gBattlescriptCurrInstr = cmd->jumpInstr;
|
|
||||||
else
|
|
||||||
gBattlescriptCurrInstr = cmd->nextInstr;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (count == 0)
|
||||||
|
gBattlescriptCurrInstr = cmd->jumpInstr;
|
||||||
|
else
|
||||||
|
gBattlescriptCurrInstr = cmd->nextInstr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
case VARIOUS_JUMP_IF_EMERGENCY_EXITED:
|
case VARIOUS_JUMP_IF_EMERGENCY_EXITED:
|
||||||
{
|
{
|
||||||
VARIOUS_ARGS(const u8 *jumpInstr);
|
VARIOUS_ARGS(const u8 *jumpInstr);
|
||||||
|
@ -3301,7 +3301,7 @@ bool8 HandleWishPerishSongOnTurnEnd(void)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FAINTED_ACTIONS_MAX_CASE 7
|
#define FAINTED_ACTIONS_MAX_CASE 8
|
||||||
|
|
||||||
bool8 HandleFaintedMonActions(void)
|
bool8 HandleFaintedMonActions(void)
|
||||||
{
|
{
|
||||||
@ -3386,7 +3386,19 @@ bool8 HandleFaintedMonActions(void)
|
|||||||
else
|
else
|
||||||
gBattleStruct->faintedActionsState = 4;
|
gBattleStruct->faintedActionsState = 4;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6: // All battlers switch-in abilities happen here to prevent them happening against an empty field.
|
||||||
|
for (i = 0; i < gBattlersCount; i++)
|
||||||
|
{
|
||||||
|
if (gBattleStruct->switchInAbilityPostponed & gBitTable[i])
|
||||||
|
{
|
||||||
|
if (DoSwitchInAbilitiesItems(i))
|
||||||
|
return TRUE;
|
||||||
|
gBattleStruct->switchInAbilityPostponed &= ~(gBitTable[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gBattleStruct->faintedActionsState++;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
if (ItemBattleEffects(ITEMEFFECT_NORMAL, 0, TRUE))
|
if (ItemBattleEffects(ITEMEFFECT_NORMAL, 0, TRUE))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
gBattleStruct->faintedActionsState++;
|
gBattleStruct->faintedActionsState++;
|
||||||
@ -4749,6 +4761,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
|
|||||||
case ABILITY_INTIMIDATE:
|
case ABILITY_INTIMIDATE:
|
||||||
if (!gSpecialStatuses[battler].switchInAbilityDone)
|
if (!gSpecialStatuses[battler].switchInAbilityDone)
|
||||||
{
|
{
|
||||||
|
gBattlerAttacker = battler;
|
||||||
gSpecialStatuses[battler].switchInAbilityDone = TRUE;
|
gSpecialStatuses[battler].switchInAbilityDone = TRUE;
|
||||||
SET_STATCHANGER(STAT_ATK, 1, TRUE);
|
SET_STATCHANGER(STAT_ATK, 1, TRUE);
|
||||||
BattleScriptPushCursorAndCallback(BattleScript_IntimidateActivates);
|
BattleScriptPushCursorAndCallback(BattleScript_IntimidateActivates);
|
||||||
|
@ -400,17 +400,17 @@ static const struct TrainerMonNoItemDefaultMoves sParty_Rose1[] = {
|
|||||||
{
|
{
|
||||||
.iv = 0,
|
.iv = 0,
|
||||||
.lvl = 14,
|
.lvl = 14,
|
||||||
.species = SPECIES_ROSELIA,
|
.species = SPECIES_PORYGON,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.iv = 0,
|
.iv = 0,
|
||||||
.lvl = 14,
|
.lvl = 14,
|
||||||
.species = SPECIES_SHROOMISH,
|
.species = SPECIES_PORYGON,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.iv = 0,
|
.iv = 0,
|
||||||
.lvl = 14,
|
.lvl = 14,
|
||||||
.species = SPECIES_ROSELIA,
|
.species = SPECIES_PORYGON,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -9631,17 +9631,17 @@ static const struct TrainerMonNoItemDefaultMoves sParty_Deandre[] = {
|
|||||||
{
|
{
|
||||||
.iv = 0,
|
.iv = 0,
|
||||||
.lvl = 14,
|
.lvl = 14,
|
||||||
.species = SPECIES_ZIGZAGOON,
|
.species = SPECIES_PORYGON,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.iv = 0,
|
.iv = 0,
|
||||||
.lvl = 14,
|
.lvl = 14,
|
||||||
.species = SPECIES_ARON,
|
.species = SPECIES_PORYGON,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.iv = 0,
|
.iv = 0,
|
||||||
.lvl = 14,
|
.lvl = 14,
|
||||||
.species = SPECIES_ELECTRIKE,
|
.species = SPECIES_PORYGON,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,13 +30,12 @@ SINGLE_BATTLE_TEST("Intimidate (opponent) lowers player's attack after switch ou
|
|||||||
SINGLE_BATTLE_TEST("Intimidate (opponent) lowers player's attack after KO", s16 damage)
|
SINGLE_BATTLE_TEST("Intimidate (opponent) lowers player's attack after KO", s16 damage)
|
||||||
{
|
{
|
||||||
u32 ability;
|
u32 ability;
|
||||||
KNOWN_FAILING;
|
|
||||||
PARAMETRIZE { ability = ABILITY_INTIMIDATE; }
|
PARAMETRIZE { ability = ABILITY_INTIMIDATE; }
|
||||||
PARAMETRIZE { ability = ABILITY_RECKLESS; }
|
PARAMETRIZE { ability = ABILITY_RECKLESS; }
|
||||||
GIVEN {
|
GIVEN {
|
||||||
PLAYER(SPECIES_WOBBUFFET) { Speed(2); };
|
PLAYER(SPECIES_WOBBUFFET) { Speed(2); Attack(120) ; };
|
||||||
OPPONENT(SPECIES_WOBBUFFET) { HP(1); Speed(1); };
|
OPPONENT(SPECIES_WOBBUFFET) { HP(1); Speed(1); };
|
||||||
OPPONENT(SPECIES_STARAPTOR) { Ability(ABILITY_INTIMIDATE); Speed(1); };
|
OPPONENT(SPECIES_STARAPTOR) { Ability(ability); Speed(1); };
|
||||||
} WHEN {
|
} WHEN {
|
||||||
TURN { MOVE(player, MOVE_TACKLE); SEND_OUT(opponent, 1); }
|
TURN { MOVE(player, MOVE_TACKLE); SEND_OUT(opponent, 1); }
|
||||||
TURN { MOVE(player, MOVE_TACKLE); }
|
TURN { MOVE(player, MOVE_TACKLE); }
|
||||||
@ -48,3 +47,48 @@ SINGLE_BATTLE_TEST("Intimidate (opponent) lowers player's attack after KO", s16
|
|||||||
EXPECT_MUL_EQ(results[0].damage, Q_4_12(1.5), results[1].damage);
|
EXPECT_MUL_EQ(results[0].damage, Q_4_12(1.5), results[1].damage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DOUBLE_BATTLE_TEST("Intimidate doesn't activate on an empty field in a double battle")
|
||||||
|
{
|
||||||
|
GIVEN {
|
||||||
|
ASSUME(gBattleMoves[MOVE_EXPLOSION].effect == EFFECT_EXPLOSION);
|
||||||
|
PLAYER(SPECIES_WOBBUFFET) { };
|
||||||
|
PLAYER(SPECIES_WOBBUFFET) { HP(1); };
|
||||||
|
PLAYER(SPECIES_STARAVIA) { Ability(ABILITY_INTIMIDATE); };
|
||||||
|
PLAYER(SPECIES_ABRA);
|
||||||
|
OPPONENT(SPECIES_WOBBUFFET) { HP(1); };
|
||||||
|
OPPONENT(SPECIES_WOBBUFFET) { HP(1); };
|
||||||
|
OPPONENT(SPECIES_STARAPTOR) { Ability(ABILITY_INTIMIDATE); };
|
||||||
|
OPPONENT(SPECIES_WYNAUT);
|
||||||
|
} WHEN {
|
||||||
|
TURN { MOVE(playerLeft, MOVE_EXPLOSION); SEND_OUT(playerLeft, 2); SEND_OUT(opponentLeft, 2); SEND_OUT(playerRight, 3); SEND_OUT(opponentRight, 3); }
|
||||||
|
TURN { MOVE(playerLeft, MOVE_CELEBRATE);}
|
||||||
|
} SCENE {
|
||||||
|
HP_BAR(playerLeft, hp: 0);
|
||||||
|
ANIMATION(ANIM_TYPE_MOVE, MOVE_EXPLOSION, playerLeft);
|
||||||
|
// Leaving these messages as they're not that important to the test, to not exceed MAX_QUEUED_EVENTS.
|
||||||
|
/*
|
||||||
|
MESSAGE("Foe Wobbuffet fainted!");
|
||||||
|
MESSAGE("Wobbuffet fainted!");
|
||||||
|
MESSAGE("Foe Wobbuffet fainted!");
|
||||||
|
MESSAGE("Wobbuffet fainted!");
|
||||||
|
*/
|
||||||
|
|
||||||
|
MESSAGE("Go! Staravia!");
|
||||||
|
MESSAGE("2 sent out Staraptor!");
|
||||||
|
MESSAGE("Go! Abra!");
|
||||||
|
MESSAGE("2 sent out Wynaut!");
|
||||||
|
|
||||||
|
ABILITY_POPUP(playerLeft, ABILITY_INTIMIDATE);
|
||||||
|
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponentLeft);
|
||||||
|
MESSAGE("Staravia's Intimidate cuts Foe Staraptor's ATTACK!");
|
||||||
|
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponentRight);
|
||||||
|
MESSAGE("Staravia's Intimidate cuts Foe Wynaut's ATTACK!");
|
||||||
|
|
||||||
|
ABILITY_POPUP(opponentLeft, ABILITY_INTIMIDATE);
|
||||||
|
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, playerLeft);
|
||||||
|
MESSAGE("Foe Staraptor's Intimidate cuts Staravia's ATTACK!");
|
||||||
|
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, playerRight);
|
||||||
|
MESSAGE("Foe Staraptor's Intimidate cuts Abra's ATTACK!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "test.h"
|
#include "test.h"
|
||||||
#include "test_runner.h"
|
#include "test_runner.h"
|
||||||
|
|
||||||
#define TIMEOUT_SECONDS 30
|
#define TIMEOUT_SECONDS 49
|
||||||
|
|
||||||
void CB2_TestRunner(void);
|
void CB2_TestRunner(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user