remove more of gActiveBattler

This commit is contained in:
DizzyEggg 2023-08-29 16:20:16 +02:00
parent 156aa59f18
commit 0381ccdf32
4 changed files with 178 additions and 179 deletions

View File

@ -53,10 +53,10 @@ void SpriteCB_TrainerThrowObject(struct Sprite *sprite);
void AnimSetCenterToCornerVecX(struct Sprite *sprite); void AnimSetCenterToCornerVecX(struct Sprite *sprite);
void BeginBattleIntroDummy(void); void BeginBattleIntroDummy(void);
void BeginBattleIntro(void); void BeginBattleIntro(void);
void SwitchInClearSetData(void); void SwitchInClearSetData(u32 battler);
void FaintClearSetData(void); void FaintClearSetData(u32 battler);
void BattleTurnPassed(void); void BattleTurnPassed(void);
u8 IsRunningFromBattleImpossible(void); u8 IsRunningFromBattleImpossible(u32 battler);
void SwitchPartyOrder(u8 battlerId); void SwitchPartyOrder(u8 battlerId);
void SwapTurnOrder(u8 id1, u8 id2); void SwapTurnOrder(u8 id1, u8 id2);
u32 GetBattlerTotalSpeedStat(u8 battlerId); u32 GetBattlerTotalSpeedStat(u8 battlerId);

View File

@ -100,7 +100,7 @@ static void TryDoEventsBeforeFirstTurn(void);
static void HandleTurnActionSelectionState(void); static void HandleTurnActionSelectionState(void);
static void RunTurnActionsFunctions(void); static void RunTurnActionsFunctions(void);
static void SetActionsAndBattlersTurnOrder(void); static void SetActionsAndBattlersTurnOrder(void);
static void UpdateBattlerPartyOrdersOnSwitch(void); static void UpdateBattlerPartyOrdersOnSwitch(u32 battler);
static bool8 AllAtActionConfirmed(void); static bool8 AllAtActionConfirmed(void);
static void TryChangeTurnOrder(void); static void TryChangeTurnOrder(void);
static void CheckChosenMoveForEffectsBeforeTurnStarts(void); static void CheckChosenMoveForEffectsBeforeTurnStarts(void);
@ -3132,21 +3132,21 @@ static void BattleStartClearSetData(void)
gSelectedMonPartyId = PARTY_SIZE; // Revival Blessing gSelectedMonPartyId = PARTY_SIZE; // Revival Blessing
} }
void SwitchInClearSetData(void) void SwitchInClearSetData(u32 battler)
{ {
s32 i; s32 i;
struct DisableStruct disableStructCopy = gDisableStructs[gActiveBattler]; struct DisableStruct disableStructCopy = gDisableStructs[battler];
ClearIllusionMon(gActiveBattler); ClearIllusionMon(battler);
if (gBattleMoves[gCurrentMove].effect != EFFECT_BATON_PASS) if (gBattleMoves[gCurrentMove].effect != EFFECT_BATON_PASS)
{ {
for (i = 0; i < NUM_BATTLE_STATS; i++) for (i = 0; i < NUM_BATTLE_STATS; i++)
gBattleMons[gActiveBattler].statStages[i] = DEFAULT_STAT_STAGE; gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE;
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
if ((gBattleMons[i].status2 & STATUS2_ESCAPE_PREVENTION) && gDisableStructs[i].battlerPreventingEscape == gActiveBattler) if ((gBattleMons[i].status2 & STATUS2_ESCAPE_PREVENTION) && gDisableStructs[i].battlerPreventingEscape == battler)
gBattleMons[i].status2 &= ~STATUS2_ESCAPE_PREVENTION; gBattleMons[i].status2 &= ~STATUS2_ESCAPE_PREVENTION;
if ((gStatuses3[i] & STATUS3_ALWAYS_HITS) && gDisableStructs[i].battlerWithSureHit == gActiveBattler) if ((gStatuses3[i] & STATUS3_ALWAYS_HITS) && gDisableStructs[i].battlerWithSureHit == battler)
{ {
gStatuses3[i] &= ~STATUS3_ALWAYS_HITS; gStatuses3[i] &= ~STATUS3_ALWAYS_HITS;
gDisableStructs[i].battlerWithSureHit = 0; gDisableStructs[i].battlerWithSureHit = 0;
@ -3155,96 +3155,96 @@ void SwitchInClearSetData(void)
} }
if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS) if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS)
{ {
gBattleMons[gActiveBattler].status2 &= (STATUS2_CONFUSION | STATUS2_FOCUS_ENERGY | STATUS2_SUBSTITUTE | STATUS2_ESCAPE_PREVENTION | STATUS2_CURSED); gBattleMons[battler].status2 &= (STATUS2_CONFUSION | STATUS2_FOCUS_ENERGY | STATUS2_SUBSTITUTE | STATUS2_ESCAPE_PREVENTION | STATUS2_CURSED);
gStatuses3[gActiveBattler] &= (STATUS3_LEECHSEED_BATTLER | STATUS3_LEECHSEED | STATUS3_ALWAYS_HITS | STATUS3_PERISH_SONG | STATUS3_ROOTED gStatuses3[battler] &= (STATUS3_LEECHSEED_BATTLER | STATUS3_LEECHSEED | STATUS3_ALWAYS_HITS | STATUS3_PERISH_SONG | STATUS3_ROOTED
| STATUS3_GASTRO_ACID | STATUS3_EMBARGO | STATUS3_TELEKINESIS | STATUS3_MAGNET_RISE | STATUS3_HEAL_BLOCK | STATUS3_GASTRO_ACID | STATUS3_EMBARGO | STATUS3_TELEKINESIS | STATUS3_MAGNET_RISE | STATUS3_HEAL_BLOCK
| STATUS3_AQUA_RING | STATUS3_POWER_TRICK); | STATUS3_AQUA_RING | STATUS3_POWER_TRICK);
gStatuses4[gActiveBattler] &= (STATUS4_MUD_SPORT | STATUS4_WATER_SPORT | STATUS4_INFINITE_CONFUSION); gStatuses4[battler] &= (STATUS4_MUD_SPORT | STATUS4_WATER_SPORT | STATUS4_INFINITE_CONFUSION);
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
if (GetBattlerSide(gActiveBattler) != GetBattlerSide(i) if (GetBattlerSide(battler) != GetBattlerSide(i)
&& (gStatuses3[i] & STATUS3_ALWAYS_HITS) != 0 && (gStatuses3[i] & STATUS3_ALWAYS_HITS) != 0
&& (gDisableStructs[i].battlerWithSureHit == gActiveBattler)) && (gDisableStructs[i].battlerWithSureHit == battler))
{ {
gStatuses3[i] &= ~STATUS3_ALWAYS_HITS; gStatuses3[i] &= ~STATUS3_ALWAYS_HITS;
gStatuses3[i] |= STATUS3_ALWAYS_HITS_TURN(2); gStatuses3[i] |= STATUS3_ALWAYS_HITS_TURN(2);
} }
} }
if (gStatuses3[gActiveBattler] & STATUS3_POWER_TRICK) if (gStatuses3[battler] & STATUS3_POWER_TRICK)
SWAP(gBattleMons[gActiveBattler].attack, gBattleMons[gActiveBattler].defense, i); SWAP(gBattleMons[battler].attack, gBattleMons[battler].defense, i);
} }
else else
{ {
gBattleMons[gActiveBattler].status2 = 0; gBattleMons[battler].status2 = 0;
gStatuses3[gActiveBattler] = 0; gStatuses3[battler] = 0;
gStatuses4[gActiveBattler] = 0; gStatuses4[battler] = 0;
} }
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
if (gBattleMons[i].status2 & STATUS2_INFATUATED_WITH(gActiveBattler)) if (gBattleMons[i].status2 & STATUS2_INFATUATED_WITH(battler))
gBattleMons[i].status2 &= ~STATUS2_INFATUATED_WITH(gActiveBattler); gBattleMons[i].status2 &= ~STATUS2_INFATUATED_WITH(battler);
if ((gBattleMons[i].status2 & STATUS2_WRAPPED) && *(gBattleStruct->wrappedBy + i) == gActiveBattler) if ((gBattleMons[i].status2 & STATUS2_WRAPPED) && *(gBattleStruct->wrappedBy + i) == battler)
gBattleMons[i].status2 &= ~STATUS2_WRAPPED; gBattleMons[i].status2 &= ~STATUS2_WRAPPED;
} }
gActionSelectionCursor[gActiveBattler] = 0; gActionSelectionCursor[battler] = 0;
gMoveSelectionCursor[gActiveBattler] = 0; gMoveSelectionCursor[battler] = 0;
memset(&gDisableStructs[gActiveBattler], 0, sizeof(struct DisableStruct)); memset(&gDisableStructs[battler], 0, sizeof(struct DisableStruct));
if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS) if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS)
{ {
gDisableStructs[gActiveBattler].substituteHP = disableStructCopy.substituteHP; gDisableStructs[battler].substituteHP = disableStructCopy.substituteHP;
gDisableStructs[gActiveBattler].battlerWithSureHit = disableStructCopy.battlerWithSureHit; gDisableStructs[battler].battlerWithSureHit = disableStructCopy.battlerWithSureHit;
gDisableStructs[gActiveBattler].perishSongTimer = disableStructCopy.perishSongTimer; gDisableStructs[battler].perishSongTimer = disableStructCopy.perishSongTimer;
gDisableStructs[gActiveBattler].battlerPreventingEscape = disableStructCopy.battlerPreventingEscape; gDisableStructs[battler].battlerPreventingEscape = disableStructCopy.battlerPreventingEscape;
} }
gMoveResultFlags = 0; gMoveResultFlags = 0;
gDisableStructs[gActiveBattler].isFirstTurn = 2; gDisableStructs[battler].isFirstTurn = 2;
gDisableStructs[gActiveBattler].truantSwitchInHack = disableStructCopy.truantSwitchInHack; gDisableStructs[battler].truantSwitchInHack = disableStructCopy.truantSwitchInHack;
gLastMoves[gActiveBattler] = MOVE_NONE; gLastMoves[battler] = MOVE_NONE;
gLastLandedMoves[gActiveBattler] = MOVE_NONE; gLastLandedMoves[battler] = MOVE_NONE;
gLastHitByType[gActiveBattler] = 0; gLastHitByType[battler] = 0;
gLastResultingMoves[gActiveBattler] = MOVE_NONE; gLastResultingMoves[battler] = MOVE_NONE;
gLastPrintedMoves[gActiveBattler] = MOVE_NONE; gLastPrintedMoves[battler] = MOVE_NONE;
gLastHitBy[gActiveBattler] = 0xFF; gLastHitBy[battler] = 0xFF;
gBattleStruct->lastTakenMove[gActiveBattler] = 0; gBattleStruct->lastTakenMove[battler] = 0;
gBattleStruct->sameMoveTurns[gActiveBattler] = 0; gBattleStruct->sameMoveTurns[battler] = 0;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][0] = 0; gBattleStruct->lastTakenMoveFrom[battler][0] = 0;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][1] = 0; gBattleStruct->lastTakenMoveFrom[battler][1] = 0;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][2] = 0; gBattleStruct->lastTakenMoveFrom[battler][2] = 0;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0; gBattleStruct->lastTakenMoveFrom[battler][3] = 0;
gBattleStruct->lastMoveFailed &= ~(gBitTable[gActiveBattler]); gBattleStruct->lastMoveFailed &= ~(gBitTable[battler]);
gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]); gBattleStruct->palaceFlags &= ~(gBitTable[battler]);
for (i = 0; i < ARRAY_COUNT(gSideTimers); i++) for (i = 0; i < ARRAY_COUNT(gSideTimers); i++)
{ {
// Switched into sticky web user slot, so reset stored battler ID // Switched into sticky web user slot, so reset stored battler ID
if (gSideTimers[i].stickyWebBattlerId == gActiveBattler) if (gSideTimers[i].stickyWebBattlerId == battler)
gSideTimers[i].stickyWebBattlerId = 0xFF; gSideTimers[i].stickyWebBattlerId = 0xFF;
} }
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
if (i != gActiveBattler && GetBattlerSide(i) != GetBattlerSide(gActiveBattler)) if (i != battler && GetBattlerSide(i) != GetBattlerSide(battler))
gBattleStruct->lastTakenMove[i] = MOVE_NONE; gBattleStruct->lastTakenMove[i] = MOVE_NONE;
gBattleStruct->lastTakenMoveFrom[i][gActiveBattler] = 0; gBattleStruct->lastTakenMoveFrom[i][battler] = 0;
} }
gBattleStruct->choicedMove[gActiveBattler] = MOVE_NONE; gBattleStruct->choicedMove[battler] = MOVE_NONE;
gBattleResources->flags->flags[gActiveBattler] = 0; gBattleResources->flags->flags[battler] = 0;
gCurrentMove = MOVE_NONE; gCurrentMove = MOVE_NONE;
gBattleStruct->arenaTurnCounter = 0xFF; gBattleStruct->arenaTurnCounter = 0xFF;
// Reset damage to prevent things like red card activating if the switched-in mon is holding it // Reset damage to prevent things like red card activating if the switched-in mon is holding it
gSpecialStatuses[gActiveBattler].physicalDmg = 0; gSpecialStatuses[battler].physicalDmg = 0;
gSpecialStatuses[gActiveBattler].specialDmg = 0; gSpecialStatuses[battler].specialDmg = 0;
gBattleStruct->overwrittenAbilities[gActiveBattler] = ABILITY_NONE; gBattleStruct->overwrittenAbilities[battler] = ABILITY_NONE;
// Clear selected party ID so Revival Blessing doesn't get confused. // Clear selected party ID so Revival Blessing doesn't get confused.
gSelectedMonPartyId = PARTY_SIZE; gSelectedMonPartyId = PARTY_SIZE;
@ -3252,126 +3252,126 @@ void SwitchInClearSetData(void)
// Allow for illegal abilities within tests. // Allow for illegal abilities within tests.
if (gTestRunnerEnabled) if (gTestRunnerEnabled)
{ {
u32 side = GetBattlerSide(gActiveBattler); u32 side = GetBattlerSide(battler);
u32 partyIndex = gBattlerPartyIndexes[gActiveBattler]; u32 partyIndex = gBattlerPartyIndexes[battler];
if (TestRunner_Battle_GetForcedAbility(side, partyIndex)) if (TestRunner_Battle_GetForcedAbility(side, partyIndex))
gBattleMons[i].ability = gBattleStruct->overwrittenAbilities[i] = TestRunner_Battle_GetForcedAbility(side, partyIndex); gBattleMons[i].ability = gBattleStruct->overwrittenAbilities[i] = TestRunner_Battle_GetForcedAbility(side, partyIndex);
} }
Ai_UpdateSwitchInData(gActiveBattler); Ai_UpdateSwitchInData(battler);
} }
void FaintClearSetData(void) void FaintClearSetData(u32 battler)
{ {
s32 i; s32 i;
for (i = 0; i < NUM_BATTLE_STATS; i++) for (i = 0; i < NUM_BATTLE_STATS; i++)
gBattleMons[gActiveBattler].statStages[i] = DEFAULT_STAT_STAGE; gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE;
gBattleMons[gActiveBattler].status2 = 0; gBattleMons[battler].status2 = 0;
gStatuses3[gActiveBattler] = 0; gStatuses3[battler] = 0;
gStatuses4[gActiveBattler] = 0; gStatuses4[battler] = 0;
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
if ((gBattleMons[i].status2 & STATUS2_ESCAPE_PREVENTION) && gDisableStructs[i].battlerPreventingEscape == gActiveBattler) if ((gBattleMons[i].status2 & STATUS2_ESCAPE_PREVENTION) && gDisableStructs[i].battlerPreventingEscape == battler)
gBattleMons[i].status2 &= ~STATUS2_ESCAPE_PREVENTION; gBattleMons[i].status2 &= ~STATUS2_ESCAPE_PREVENTION;
if (gBattleMons[i].status2 & STATUS2_INFATUATED_WITH(gActiveBattler)) if (gBattleMons[i].status2 & STATUS2_INFATUATED_WITH(battler))
gBattleMons[i].status2 &= ~STATUS2_INFATUATED_WITH(gActiveBattler); gBattleMons[i].status2 &= ~STATUS2_INFATUATED_WITH(battler);
if ((gBattleMons[i].status2 & STATUS2_WRAPPED) && *(gBattleStruct->wrappedBy + i) == gActiveBattler) if ((gBattleMons[i].status2 & STATUS2_WRAPPED) && *(gBattleStruct->wrappedBy + i) == battler)
gBattleMons[i].status2 &= ~STATUS2_WRAPPED; gBattleMons[i].status2 &= ~STATUS2_WRAPPED;
} }
gActionSelectionCursor[gActiveBattler] = 0; gActionSelectionCursor[battler] = 0;
gMoveSelectionCursor[gActiveBattler] = 0; gMoveSelectionCursor[battler] = 0;
memset(&gDisableStructs[gActiveBattler], 0, sizeof(struct DisableStruct)); memset(&gDisableStructs[battler], 0, sizeof(struct DisableStruct));
gProtectStructs[gActiveBattler].protected = FALSE; gProtectStructs[battler].protected = FALSE;
gProtectStructs[gActiveBattler].spikyShielded = FALSE; gProtectStructs[battler].spikyShielded = FALSE;
gProtectStructs[gActiveBattler].kingsShielded = FALSE; gProtectStructs[battler].kingsShielded = FALSE;
gProtectStructs[gActiveBattler].banefulBunkered = FALSE; gProtectStructs[battler].banefulBunkered = FALSE;
gProtectStructs[gActiveBattler].quash = FALSE; gProtectStructs[battler].quash = FALSE;
gProtectStructs[gActiveBattler].obstructed = FALSE; gProtectStructs[battler].obstructed = FALSE;
gProtectStructs[gActiveBattler].silkTrapped = FALSE; gProtectStructs[battler].silkTrapped = FALSE;
gProtectStructs[gActiveBattler].endured = FALSE; gProtectStructs[battler].endured = FALSE;
gProtectStructs[gActiveBattler].noValidMoves = FALSE; gProtectStructs[battler].noValidMoves = FALSE;
gProtectStructs[gActiveBattler].helpingHand = FALSE; gProtectStructs[battler].helpingHand = FALSE;
gProtectStructs[gActiveBattler].bounceMove = FALSE; gProtectStructs[battler].bounceMove = FALSE;
gProtectStructs[gActiveBattler].stealMove = FALSE; gProtectStructs[battler].stealMove = FALSE;
gProtectStructs[gActiveBattler].prlzImmobility = FALSE; gProtectStructs[battler].prlzImmobility = FALSE;
gProtectStructs[gActiveBattler].confusionSelfDmg = FALSE; gProtectStructs[battler].confusionSelfDmg = FALSE;
gProtectStructs[gActiveBattler].targetAffected = FALSE; gProtectStructs[battler].targetAffected = FALSE;
gProtectStructs[gActiveBattler].chargingTurn = FALSE; gProtectStructs[battler].chargingTurn = FALSE;
gProtectStructs[gActiveBattler].fleeType = 0; gProtectStructs[battler].fleeType = 0;
gProtectStructs[gActiveBattler].usedImprisonedMove = FALSE; gProtectStructs[battler].usedImprisonedMove = FALSE;
gProtectStructs[gActiveBattler].loveImmobility = FALSE; gProtectStructs[battler].loveImmobility = FALSE;
gProtectStructs[gActiveBattler].usedDisabledMove = FALSE; gProtectStructs[battler].usedDisabledMove = FALSE;
gProtectStructs[gActiveBattler].usedTauntedMove = FALSE; gProtectStructs[battler].usedTauntedMove = FALSE;
gProtectStructs[gActiveBattler].flag2Unknown = FALSE; gProtectStructs[battler].flag2Unknown = FALSE;
gProtectStructs[gActiveBattler].flinchImmobility = FALSE; gProtectStructs[battler].flinchImmobility = FALSE;
gProtectStructs[gActiveBattler].notFirstStrike = FALSE; gProtectStructs[battler].notFirstStrike = FALSE;
gProtectStructs[gActiveBattler].usedHealBlockedMove = FALSE; gProtectStructs[battler].usedHealBlockedMove = FALSE;
gProtectStructs[gActiveBattler].usesBouncedMove = FALSE; gProtectStructs[battler].usesBouncedMove = FALSE;
gProtectStructs[gActiveBattler].usedGravityPreventedMove = FALSE; gProtectStructs[battler].usedGravityPreventedMove = FALSE;
gProtectStructs[gActiveBattler].usedThroatChopPreventedMove = FALSE; gProtectStructs[battler].usedThroatChopPreventedMove = FALSE;
gProtectStructs[gActiveBattler].statRaised = FALSE; gProtectStructs[battler].statRaised = FALSE;
gProtectStructs[gActiveBattler].statFell = FALSE; gProtectStructs[battler].statFell = FALSE;
gProtectStructs[gActiveBattler].pranksterElevated = FALSE; gProtectStructs[battler].pranksterElevated = FALSE;
gDisableStructs[gActiveBattler].isFirstTurn = 2; gDisableStructs[battler].isFirstTurn = 2;
gLastMoves[gActiveBattler] = MOVE_NONE; gLastMoves[battler] = MOVE_NONE;
gLastLandedMoves[gActiveBattler] = MOVE_NONE; gLastLandedMoves[battler] = MOVE_NONE;
gLastHitByType[gActiveBattler] = 0; gLastHitByType[battler] = 0;
gLastResultingMoves[gActiveBattler] = MOVE_NONE; gLastResultingMoves[battler] = MOVE_NONE;
gLastPrintedMoves[gActiveBattler] = MOVE_NONE; gLastPrintedMoves[battler] = MOVE_NONE;
gLastHitBy[gActiveBattler] = 0xFF; gLastHitBy[battler] = 0xFF;
gBattleStruct->choicedMove[gActiveBattler] = MOVE_NONE; gBattleStruct->choicedMove[battler] = MOVE_NONE;
gBattleStruct->sameMoveTurns[gActiveBattler] = 0; gBattleStruct->sameMoveTurns[battler] = 0;
gBattleStruct->lastTakenMove[gActiveBattler] = MOVE_NONE; gBattleStruct->lastTakenMove[battler] = MOVE_NONE;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][0] = 0; gBattleStruct->lastTakenMoveFrom[battler][0] = 0;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][1] = 0; gBattleStruct->lastTakenMoveFrom[battler][1] = 0;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][2] = 0; gBattleStruct->lastTakenMoveFrom[battler][2] = 0;
gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0; gBattleStruct->lastTakenMoveFrom[battler][3] = 0;
gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]); gBattleStruct->palaceFlags &= ~(gBitTable[battler]);
for (i = 0; i < ARRAY_COUNT(gSideTimers); i++) for (i = 0; i < ARRAY_COUNT(gSideTimers); i++)
{ {
// User of sticky web fainted, so reset the stored battler ID // User of sticky web fainted, so reset the stored battler ID
if (gSideTimers[i].stickyWebBattlerId == gActiveBattler) if (gSideTimers[i].stickyWebBattlerId == battler)
gSideTimers[i].stickyWebBattlerId = 0xFF; gSideTimers[i].stickyWebBattlerId = 0xFF;
} }
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)
{ {
if (i != gActiveBattler && GetBattlerSide(i) != GetBattlerSide(gActiveBattler)) if (i != battler && GetBattlerSide(i) != GetBattlerSide(battler))
gBattleStruct->lastTakenMove[i] = MOVE_NONE; gBattleStruct->lastTakenMove[i] = MOVE_NONE;
gBattleStruct->lastTakenMoveFrom[i][gActiveBattler] = 0; gBattleStruct->lastTakenMoveFrom[i][battler] = 0;
} }
gBattleResources->flags->flags[gActiveBattler] = 0; gBattleResources->flags->flags[battler] = 0;
gBattleMons[gActiveBattler].type1 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[0]; gBattleMons[battler].type1 = gSpeciesInfo[gBattleMons[battler].species].types[0];
gBattleMons[gActiveBattler].type2 = gSpeciesInfo[gBattleMons[gActiveBattler].species].types[1]; gBattleMons[battler].type2 = gSpeciesInfo[gBattleMons[battler].species].types[1];
gBattleMons[gActiveBattler].type3 = TYPE_MYSTERY; gBattleMons[battler].type3 = TYPE_MYSTERY;
Ai_UpdateFaintData(gActiveBattler); Ai_UpdateFaintData(battler);
TryBattleFormChange(gActiveBattler, FORM_CHANGE_FAINT); TryBattleFormChange(battler, FORM_CHANGE_FAINT);
gBattleStruct->overwrittenAbilities[gActiveBattler] = ABILITY_NONE; gBattleStruct->overwrittenAbilities[battler] = ABILITY_NONE;
// If the fainted mon was involved in a Sky Drop // If the fainted mon was involved in a Sky Drop
if (gBattleStruct->skyDropTargets[gActiveBattler] != 0xFF) if (gBattleStruct->skyDropTargets[battler] != 0xFF)
{ {
// Get battler id of the other Pokemon involved in this Sky Drop // Get battler id of the other Pokemon involved in this Sky Drop
u8 otherSkyDropper = gBattleStruct->skyDropTargets[gActiveBattler]; u8 otherSkyDropper = gBattleStruct->skyDropTargets[battler];
// Clear Sky Drop data // Clear Sky Drop data
gBattleStruct->skyDropTargets[gActiveBattler] = 0xFF; gBattleStruct->skyDropTargets[battler] = 0xFF;
gBattleStruct->skyDropTargets[otherSkyDropper] = 0xFF; gBattleStruct->skyDropTargets[otherSkyDropper] = 0xFF;
// If the other Pokemon involved in this Sky Drop was the target, not the attacker // If the other Pokemon involved in this Sky Drop was the target, not the attacker
@ -3405,7 +3405,7 @@ void FaintClearSetData(void)
// Clear Z-Move data // Clear Z-Move data
gBattleStruct->zmove.active = FALSE; gBattleStruct->zmove.active = FALSE;
gBattleStruct->zmove.toBeUsed[gActiveBattler] = MOVE_NONE; gBattleStruct->zmove.toBeUsed[battler] = MOVE_NONE;
gBattleStruct->zmove.effect = EFFECT_HIT; gBattleStruct->zmove.effect = EFFECT_HIT;
} }
@ -3975,23 +3975,23 @@ void BattleTurnPassed(void)
BattleScriptExecute(i == 1 ? BattleScript_TrainerASlideMsgEnd2 : BattleScript_TrainerBSlideMsgEnd2); BattleScriptExecute(i == 1 ? BattleScript_TrainerASlideMsgEnd2 : BattleScript_TrainerBSlideMsgEnd2);
} }
u8 IsRunningFromBattleImpossible(void) u8 IsRunningFromBattleImpossible(u32 battler)
{ {
u32 holdEffect, i; u32 holdEffect, i;
if (gBattleMons[gActiveBattler].item == ITEM_ENIGMA_BERRY_E_READER) if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY_E_READER)
holdEffect = gEnigmaBerries[gActiveBattler].holdEffect; holdEffect = gEnigmaBerries[battler].holdEffect;
else else
holdEffect = ItemId_GetHoldEffect(gBattleMons[gActiveBattler].item); holdEffect = ItemId_GetHoldEffect(gBattleMons[battler].item);
gPotentialItemEffectBattler = gActiveBattler; gPotentialItemEffectBattler = battler;
if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) // Cannot ever run from saving Birch's battle. if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) // Cannot ever run from saving Birch's battle.
{ {
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DONT_LEAVE_BIRCH; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DONT_LEAVE_BIRCH;
return BATTLE_RUN_FORBIDDEN; return BATTLE_RUN_FORBIDDEN;
} }
if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT && WILD_DOUBLE_BATTLE if (GetBattlerPosition(battler) == B_POSITION_PLAYER_RIGHT && WILD_DOUBLE_BATTLE
&& IsBattlerAlive(GetBattlerAtPosition(B_POSITION_PLAYER_LEFT))) // The second pokemon cannot run from a double wild battle, unless it's the only alive mon. && IsBattlerAlive(GetBattlerAtPosition(B_POSITION_PLAYER_LEFT))) // The second pokemon cannot run from a double wild battle, unless it's the only alive mon.
{ {
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_ESCAPE; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_ESCAPE;
@ -4001,15 +4001,15 @@ u8 IsRunningFromBattleImpossible(void)
if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN)
return BATTLE_RUN_SUCCESS; return BATTLE_RUN_SUCCESS;
#if B_GHOSTS_ESCAPE >= GEN_6 #if B_GHOSTS_ESCAPE >= GEN_6
if (IS_BATTLER_OF_TYPE(gActiveBattler, TYPE_GHOST)) if (IS_BATTLER_OF_TYPE(battler, TYPE_GHOST))
return BATTLE_RUN_SUCCESS; return BATTLE_RUN_SUCCESS;
#endif #endif
if (gBattleTypeFlags & BATTLE_TYPE_LINK) if (gBattleTypeFlags & BATTLE_TYPE_LINK)
return BATTLE_RUN_SUCCESS; return BATTLE_RUN_SUCCESS;
if (GetBattlerAbility(gActiveBattler) == ABILITY_RUN_AWAY) if (GetBattlerAbility(battler) == ABILITY_RUN_AWAY)
return BATTLE_RUN_SUCCESS; return BATTLE_RUN_SUCCESS;
if ((i = IsAbilityPreventingEscape(gActiveBattler))) if ((i = IsAbilityPreventingEscape(battler)))
{ {
gBattleScripting.battler = i - 1; gBattleScripting.battler = i - 1;
gLastUsedAbility = gBattleMons[i - 1].ability; gLastUsedAbility = gBattleMons[i - 1].ability;
@ -4017,7 +4017,7 @@ u8 IsRunningFromBattleImpossible(void)
return BATTLE_RUN_FAILURE; return BATTLE_RUN_FAILURE;
} }
if (!CanBattlerEscape(gActiveBattler)) if (!CanBattlerEscape(battler))
{ {
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_ESCAPE; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_ESCAPE;
return BATTLE_RUN_FORBIDDEN; return BATTLE_RUN_FORBIDDEN;
@ -4313,7 +4313,7 @@ static void HandleTurnActionSelectionState(void)
BattleScriptExecute(BattleScript_PrintCantRunFromTrainer); BattleScriptExecute(BattleScript_PrintCantRunFromTrainer);
gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN;
} }
else if (IsRunningFromBattleImpossible() != BATTLE_RUN_SUCCESS else if (IsRunningFromBattleImpossible(gActiveBattler) != BATTLE_RUN_SUCCESS
&& gBattleResources->bufferB[gActiveBattler][1] == B_ACTION_RUN) && gBattleResources->bufferB[gActiveBattler][1] == B_ACTION_RUN)
{ {
gSelectionBattleScripts[gActiveBattler] = BattleScript_PrintCantEscapeFromBattle; gSelectionBattleScripts[gActiveBattler] = BattleScript_PrintCantEscapeFromBattle;
@ -4347,7 +4347,7 @@ static void HandleTurnActionSelectionState(void)
return; return;
case 15: case 15:
gChosenActionByBattler[gActiveBattler] = B_ACTION_SWITCH; gChosenActionByBattler[gActiveBattler] = B_ACTION_SWITCH;
UpdateBattlerPartyOrdersOnSwitch(); UpdateBattlerPartyOrdersOnSwitch(gActiveBattler);
return; return;
default: default:
RecordedBattle_CheckMovesetChanges(B_RECORD_MODE_PLAYBACK); RecordedBattle_CheckMovesetChanges(B_RECORD_MODE_PLAYBACK);
@ -4403,7 +4403,7 @@ static void HandleTurnActionSelectionState(void)
} }
else else
{ {
UpdateBattlerPartyOrdersOnSwitch(); UpdateBattlerPartyOrdersOnSwitch(gActiveBattler);
gBattleCommunication[gActiveBattler]++; gBattleCommunication[gActiveBattler]++;
} }
break; break;
@ -4573,20 +4573,20 @@ static bool8 AllAtActionConfirmed(void)
return FALSE; return FALSE;
} }
static void UpdateBattlerPartyOrdersOnSwitch(void) static void UpdateBattlerPartyOrdersOnSwitch(u32 battler)
{ {
*(gBattleStruct->monToSwitchIntoId + gActiveBattler) = gBattleResources->bufferB[gActiveBattler][1]; gBattleStruct->monToSwitchIntoId[battler] = gBattleResources->bufferB[battler][1];
RecordedBattle_SetBattlerAction(gActiveBattler, gBattleResources->bufferB[gActiveBattler][1]); RecordedBattle_SetBattlerAction(battler, gBattleResources->bufferB[battler][1]);
if (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI) if (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI)
{ {
*(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= 0xF; *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= 0xF;
*(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[gActiveBattler][2] & 0xF0); *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[battler][2] & 0xF0);
*(gActiveBattler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 1) = gBattleResources->bufferB[gActiveBattler][3]; *(battler * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 1) = gBattleResources->bufferB[battler][3];
*((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0); *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) &= (0xF0);
*((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[gActiveBattler][2] & 0xF0) >> 4; *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 0) |= (gBattleResources->bufferB[battler][2] & 0xF0) >> 4;
*((BATTLE_PARTNER(gActiveBattler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleResources->bufferB[gActiveBattler][3]; *((BATTLE_PARTNER(battler)) * 3 + (u8 *)(gBattleStruct->battlerPartyOrders) + 2) = gBattleResources->bufferB[battler][3];
} }
} }
@ -4943,35 +4943,35 @@ static void TurnValuesCleanUp(bool8 var0)
{ {
s32 i; s32 i;
for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) for (i = 0; i < gBattlersCount; i++)
{ {
if (var0) if (var0)
{ {
gProtectStructs[gActiveBattler].protected = FALSE; gProtectStructs[i].protected = FALSE;
gProtectStructs[gActiveBattler].spikyShielded = FALSE; gProtectStructs[i].spikyShielded = FALSE;
gProtectStructs[gActiveBattler].kingsShielded = FALSE; gProtectStructs[i].kingsShielded = FALSE;
gProtectStructs[gActiveBattler].banefulBunkered = FALSE; gProtectStructs[i].banefulBunkered = FALSE;
gProtectStructs[gActiveBattler].quash = FALSE; gProtectStructs[i].quash = FALSE;
} }
else else
{ {
memset(&gProtectStructs[gActiveBattler], 0, sizeof(struct ProtectStruct)); memset(&gProtectStructs[i], 0, sizeof(struct ProtectStruct));
if (gDisableStructs[gActiveBattler].isFirstTurn) if (gDisableStructs[i].isFirstTurn)
gDisableStructs[gActiveBattler].isFirstTurn--; gDisableStructs[i].isFirstTurn--;
if (gDisableStructs[gActiveBattler].rechargeTimer) if (gDisableStructs[i].rechargeTimer)
{ {
gDisableStructs[gActiveBattler].rechargeTimer--; gDisableStructs[i].rechargeTimer--;
if (gDisableStructs[gActiveBattler].rechargeTimer == 0) if (gDisableStructs[i].rechargeTimer == 0)
gBattleMons[gActiveBattler].status2 &= ~STATUS2_RECHARGE; gBattleMons[i].status2 &= ~STATUS2_RECHARGE;
} }
} }
if (gDisableStructs[gActiveBattler].substituteHP == 0) if (gDisableStructs[i].substituteHP == 0)
gBattleMons[gActiveBattler].status2 &= ~STATUS2_SUBSTITUTE; gBattleMons[i].status2 &= ~STATUS2_SUBSTITUTE;
gSpecialStatuses[gActiveBattler].parentalBondState = PARENTAL_BOND_OFF; gSpecialStatuses[i].parentalBondState = PARENTAL_BOND_OFF;
} }
gSideStatuses[B_SIDE_PLAYER] &= ~(SIDE_STATUS_QUICK_GUARD | SIDE_STATUS_WIDE_GUARD | SIDE_STATUS_CRAFTY_SHIELD | SIDE_STATUS_MAT_BLOCK); gSideStatuses[B_SIDE_PLAYER] &= ~(SIDE_STATUS_QUICK_GUARD | SIDE_STATUS_WIDE_GUARD | SIDE_STATUS_CRAFTY_SHIELD | SIDE_STATUS_MAT_BLOCK);
@ -5327,7 +5327,7 @@ static void HandleEndTurn_MonFled(void)
static void HandleEndTurn_FinishBattle(void) static void HandleEndTurn_FinishBattle(void)
{ {
u32 i; u32 i, battler;
if (gCurrentActionFuncId == B_ACTION_TRY_FINISH || gCurrentActionFuncId == B_ACTION_FINISHED) if (gCurrentActionFuncId == B_ACTION_TRY_FINISH || gCurrentActionFuncId == B_ACTION_FINISHED)
{ {
@ -5339,19 +5339,19 @@ static void HandleEndTurn_FinishBattle(void)
| BATTLE_TYPE_WALLY_TUTORIAL | BATTLE_TYPE_WALLY_TUTORIAL
| BATTLE_TYPE_FRONTIER))) | BATTLE_TYPE_FRONTIER)))
{ {
for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) for (battler = 0; battler < gBattlersCount; battler++)
{ {
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) if (GetBattlerSide(battler) == B_SIDE_PLAYER)
{ {
if (gBattleResults.playerMon1Species == SPECIES_NONE) if (gBattleResults.playerMon1Species == SPECIES_NONE)
{ {
gBattleResults.playerMon1Species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL); gBattleResults.playerMon1Species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL);
GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_NICKNAME, gBattleResults.playerMon1Name); GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_NICKNAME, gBattleResults.playerMon1Name);
} }
else else
{ {
gBattleResults.playerMon2Species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL); gBattleResults.playerMon2Species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL);
GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_NICKNAME, gBattleResults.playerMon2Name); GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_NICKNAME, gBattleResults.playerMon2Name);
} }
} }
} }

View File

@ -3870,7 +3870,7 @@ static void Cmd_cleareffectsonfaint(void)
MarkBattlerForControllerExec(battler); MarkBattlerForControllerExec(battler);
} }
FaintClearSetData(); // Effects like attractions, trapping, etc. FaintClearSetData(battler); // Effects like attractions, trapping, etc.
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
} }
} }
@ -6203,7 +6203,7 @@ static void Cmd_switchindataupdate(void)
gBattleMons[battler].status2 = oldData.status2; gBattleMons[battler].status2 = oldData.status2;
} }
SwitchInClearSetData(); SwitchInClearSetData(battler);
if (gBattleTypeFlags & BATTLE_TYPE_PALACE if (gBattleTypeFlags & BATTLE_TYPE_PALACE
&& gBattleMons[battler].maxHP / 2 >= gBattleMons[battler].hp && gBattleMons[battler].maxHP / 2 >= gBattleMons[battler].hp
@ -8873,7 +8873,7 @@ static void Cmd_various(void)
case VARIOUS_IS_RUNNING_IMPOSSIBLE: case VARIOUS_IS_RUNNING_IMPOSSIBLE:
{ {
VARIOUS_ARGS(); VARIOUS_ARGS();
gBattleCommunication[0] = IsRunningFromBattleImpossible(); gBattleCommunication[0] = IsRunningFromBattleImpossible(battler);
break; break;
} }
case VARIOUS_GET_MOVE_TARGET: case VARIOUS_GET_MOVE_TARGET:
@ -9096,7 +9096,7 @@ static void Cmd_various(void)
gBattleMons[battler].hp = 0; gBattleMons[battler].hp = 0;
SetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_HP, &gBattleMons[battler].hp); SetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_HP, &gBattleMons[battler].hp);
SetHealthboxSpriteInvisible(gHealthboxSpriteIds[battler]); SetHealthboxSpriteInvisible(gHealthboxSpriteIds[battler]);
FaintClearSetData(); FaintClearSetData(battler);
} }
else if (GetBattlerSide(battler) == B_SIDE_PLAYER) else if (GetBattlerSide(battler) == B_SIDE_PLAYER)
{ {

View File

@ -849,7 +849,6 @@ void HandleAction_ActionFinished(void)
gLastHitByType[gBattlerAttacker] = 0; gLastHitByType[gBattlerAttacker] = 0;
gBattleStruct->dynamicMoveType = 0; gBattleStruct->dynamicMoveType = 0;
gBattleScripting.moveendState = 0; gBattleScripting.moveendState = 0;
gBattleScripting.moveendState = 0;
gBattleCommunication[3] = 0; gBattleCommunication[3] = 0;
gBattleCommunication[4] = 0; gBattleCommunication[4] = 0;
gBattleScripting.multihitMoveEffect = 0; gBattleScripting.multihitMoveEffect = 0;