remove gActiveBattler from battle_script_commands.c

This commit is contained in:
DizzyEggg 2023-08-30 09:40:15 +02:00
parent 0381ccdf32
commit 77dd5150f5

View File

@ -2831,15 +2831,15 @@ void SetMoveEffect(bool32 primary, u32 certain)
// check active uproar // check active uproar
if (battlerAbility != ABILITY_SOUNDPROOF) if (battlerAbility != ABILITY_SOUNDPROOF)
{ {
for (gActiveBattler = 0; for (i = 0; i < gBattlersCount && !(gBattleMons[i].status2 & STATUS2_UPROAR); i++)
gActiveBattler < gBattlersCount && !(gBattleMons[gActiveBattler].status2 & STATUS2_UPROAR);
gActiveBattler++)
; ;
} }
else else
gActiveBattler = gBattlersCount; {
i = gBattlersCount;
}
if (gActiveBattler != gBattlersCount) if (i != gBattlersCount)
break; break;
if (!CanSleep(gEffectBattler)) if (!CanSleep(gEffectBattler))
break; break;
@ -3741,12 +3741,12 @@ static void Cmd_clearstatusfromeffect(void)
{ {
CMD_ARGS(u8 battler); CMD_ARGS(u8 battler);
gActiveBattler = GetBattlerForBattleScript(cmd->battler); u32 battler = GetBattlerForBattleScript(cmd->battler);
if (gBattleScripting.moveEffect <= PRIMARY_STATUS_MOVE_EFFECT) if (gBattleScripting.moveEffect <= PRIMARY_STATUS_MOVE_EFFECT)
gBattleMons[gActiveBattler].status1 &= (~sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]); gBattleMons[battler].status1 &= (~sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]);
else else
gBattleMons[gActiveBattler].status2 &= (~sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]); gBattleMons[battler].status2 &= (~sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]);
gBattleScripting.moveEffect = 0; gBattleScripting.moveEffect = 0;
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
@ -3756,18 +3756,17 @@ static void Cmd_clearstatusfromeffect(void)
static void Cmd_tryfaintmon(void) static void Cmd_tryfaintmon(void)
{ {
CMD_ARGS(u8 battler, bool8 isSpikes, const u8 *instr); CMD_ARGS(u8 battler, bool8 isSpikes, const u8 *instr);
const u8 *instr; u32 battler, destinyBondBattler;
const u8 *faintScript;
battler = GetBattlerForBattleScript(cmd->battler);
if (cmd->isSpikes != 0) if (cmd->isSpikes != 0)
{ {
gActiveBattler = GetBattlerForBattleScript(cmd->battler); if (gHitMarker & HITMARKER_FAINTED(battler))
if (gHitMarker & HITMARKER_FAINTED(gActiveBattler))
{ {
instr = cmd->instr;
BattleScriptPop(); BattleScriptPop();
gBattlescriptCurrInstr = instr; gBattlescriptCurrInstr = cmd->instr;
gSideStatuses[GetBattlerSide(gActiveBattler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED); gSideStatuses[GetBattlerSide(battler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED);
} }
else else
{ {
@ -3776,46 +3775,42 @@ static void Cmd_tryfaintmon(void)
} }
else else
{ {
u8 battlerId;
if (cmd->battler == BS_ATTACKER) if (cmd->battler == BS_ATTACKER)
{ {
gActiveBattler = gBattlerAttacker; destinyBondBattler = gBattlerTarget;
battlerId = gBattlerTarget; faintScript = BattleScript_FaintAttacker;
instr = BattleScript_FaintAttacker;
} }
else else
{ {
gActiveBattler = gBattlerTarget; destinyBondBattler = gBattlerAttacker;
battlerId = gBattlerAttacker; faintScript = BattleScript_FaintTarget;
instr = BattleScript_FaintTarget;
} }
if (!(gAbsentBattlerFlags & gBitTable[gActiveBattler]) if (!(gAbsentBattlerFlags & gBitTable[battler])
&& gBattleMons[gActiveBattler].hp == 0) && gBattleMons[battler].hp == 0)
{ {
gHitMarker |= HITMARKER_FAINTED(gActiveBattler); gHitMarker |= HITMARKER_FAINTED(battler);
BattleScriptPush(cmd->nextInstr); BattleScriptPush(cmd->nextInstr);
gBattlescriptCurrInstr = instr; gBattlescriptCurrInstr = faintScript;
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) if (GetBattlerSide(battler) == B_SIDE_PLAYER)
{ {
gHitMarker |= HITMARKER_PLAYER_FAINTED; gHitMarker |= HITMARKER_PLAYER_FAINTED;
if (gBattleResults.playerFaintCounter < 255) if (gBattleResults.playerFaintCounter < 255)
gBattleResults.playerFaintCounter++; gBattleResults.playerFaintCounter++;
AdjustFriendshipOnBattleFaint(gActiveBattler); AdjustFriendshipOnBattleFaint(battler);
gSideTimers[B_SIDE_PLAYER].retaliateTimer = 2; gSideTimers[B_SIDE_PLAYER].retaliateTimer = 2;
} }
else else
{ {
if (gBattleResults.opponentFaintCounter < 255) if (gBattleResults.opponentFaintCounter < 255)
gBattleResults.opponentFaintCounter++; gBattleResults.opponentFaintCounter++;
gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES, NULL); gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL);
gSideTimers[B_SIDE_OPPONENT].retaliateTimer = 2; gSideTimers[B_SIDE_OPPONENT].retaliateTimer = 2;
} }
if ((gHitMarker & HITMARKER_DESTINYBOND) && gBattleMons[gBattlerAttacker].hp != 0) if ((gHitMarker & HITMARKER_DESTINYBOND) && gBattleMons[gBattlerAttacker].hp != 0)
{ {
gHitMarker &= ~HITMARKER_DESTINYBOND; gHitMarker &= ~HITMARKER_DESTINYBOND;
BattleScriptPush(gBattlescriptCurrInstr); BattleScriptPush(gBattlescriptCurrInstr);
gBattleMoveDamage = gBattleMons[battlerId].hp; gBattleMoveDamage = gBattleMons[destinyBondBattler].hp;
gBattlescriptCurrInstr = BattleScript_DestinyBondTakesLife; gBattlescriptCurrInstr = BattleScript_DestinyBondTakesLife;
} }
if ((gStatuses3[gBattlerTarget] & STATUS3_GRUDGE) if ((gStatuses3[gBattlerTarget] & STATUS3_GRUDGE)
@ -3989,24 +3984,18 @@ static void Cmd_jumpifstatus3condition(void)
{ {
CMD_ARGS(u8 battler, u32 flags, bool8 jumpIfTrue, const u8 *jumpInstr); CMD_ARGS(u8 battler, u32 flags, bool8 jumpIfTrue, const u8 *jumpInstr);
u32 flags; u32 battler = GetBattlerForBattleScript(cmd->battler);
const u8 *jumpInstr;
gActiveBattler = GetBattlerForBattleScript(cmd->battler);
flags = cmd->flags;
jumpInstr = cmd->jumpInstr;
if (cmd->jumpIfTrue) if (cmd->jumpIfTrue)
{ {
if ((gStatuses3[gActiveBattler] & flags) != 0) if ((gStatuses3[battler] & cmd->flags) != 0)
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
else else
gBattlescriptCurrInstr = jumpInstr; gBattlescriptCurrInstr = cmd->jumpInstr;
} }
else else
{ {
if ((gStatuses3[gActiveBattler] & flags) != 0) if ((gStatuses3[battler] & cmd->flags) != 0)
gBattlescriptCurrInstr = jumpInstr; gBattlescriptCurrInstr = cmd->jumpInstr;
else else
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
} }
@ -4277,20 +4266,20 @@ static void Cmd_getexp(void)
case 4: // lvl up if necessary case 4: // lvl up if necessary
if (gBattleControllerExecFlags == 0) if (gBattleControllerExecFlags == 0)
{ {
gActiveBattler = gBattleStruct->expGetterBattlerId; u32 expBattler = gBattleStruct->expGetterBattlerId;
if (gBattleResources->bufferB[gActiveBattler][0] == CONTROLLER_TWORETURNVALUES && gBattleResources->bufferB[gActiveBattler][1] == RET_VALUE_LEVELED_UP) if (gBattleResources->bufferB[expBattler][0] == CONTROLLER_TWORETURNVALUES && gBattleResources->bufferB[expBattler][1] == RET_VALUE_LEVELED_UP)
{ {
u16 temp, battlerId = 0xFF; u16 temp, battlerId = 0xFF;
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gBattlerPartyIndexes[gActiveBattler] == gBattleStruct->expGetterMonId) if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gBattlerPartyIndexes[expBattler] == gBattleStruct->expGetterMonId)
HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[expBattler]], expBattler);
PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, gActiveBattler, gBattleStruct->expGetterMonId); PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, expBattler, gBattleStruct->expGetterMonId);
PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff2, 3, GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_LEVEL)); PREPARE_BYTE_NUMBER_BUFFER(gBattleTextBuff2, 3, GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_LEVEL));
BattleScriptPushCursor(); BattleScriptPushCursor();
gLeveledUpInBattle |= gBitTable[gBattleStruct->expGetterMonId]; gLeveledUpInBattle |= gBitTable[gBattleStruct->expGetterMonId];
gBattlescriptCurrInstr = BattleScript_LevelUp; gBattlescriptCurrInstr = BattleScript_LevelUp;
gBattleMoveDamage = T1_READ_32(&gBattleResources->bufferB[gActiveBattler][2]); gBattleMoveDamage = T1_READ_32(&gBattleResources->bufferB[expBattler][2]);
AdjustFriendship(&gPlayerParty[gBattleStruct->expGetterMonId], FRIENDSHIP_EVENT_GROW_LEVEL); AdjustFriendship(&gPlayerParty[gBattleStruct->expGetterMonId], FRIENDSHIP_EVENT_GROW_LEVEL);
// update battle mon structure after level up // update battle mon structure after level up
@ -4868,7 +4857,6 @@ static void Cmd_end(void)
BattleArena_AddSkillPoints(gBattlerAttacker); BattleArena_AddSkillPoints(gBattlerAttacker);
gMoveResultFlags = 0; gMoveResultFlags = 0;
gActiveBattler = 0;
gCurrentActionFuncId = B_ACTION_TRY_FINISH; gCurrentActionFuncId = B_ACTION_TRY_FINISH;
} }
@ -4876,7 +4864,6 @@ static void Cmd_end2(void)
{ {
CMD_ARGS(); CMD_ARGS();
gActiveBattler = 0;
gCurrentActionFuncId = B_ACTION_TRY_FINISH; gCurrentActionFuncId = B_ACTION_TRY_FINISH;
} }
@ -5650,9 +5637,8 @@ static void Cmd_moveend(void)
if (gHitMarker & HITMARKER_SWAP_ATTACKER_TARGET) if (gHitMarker & HITMARKER_SWAP_ATTACKER_TARGET)
{ {
gActiveBattler = gBattlerAttacker; u8 temp;
gBattlerAttacker = gBattlerTarget; SWAP(gBattlerAttacker, gBattlerTarget, temp);
gBattlerTarget = gActiveBattler;
gHitMarker &= ~HITMARKER_SWAP_ATTACKER_TARGET; gHitMarker &= ~HITMARKER_SWAP_ATTACKER_TARGET;
} }
if (!gSpecialStatuses[gBattlerAttacker].dancerUsedMove) if (!gSpecialStatuses[gBattlerAttacker].dancerUsedMove)
@ -5877,7 +5863,7 @@ static void Cmd_moveend(void)
&& (gSpecialStatuses[battler].physicalDmg != 0 || gSpecialStatuses[battler].specialDmg != 0) && (gSpecialStatuses[battler].physicalDmg != 0 || gSpecialStatuses[battler].specialDmg != 0)
&& CountUsablePartyMons(battler) > 0) // Has mon to switch into && CountUsablePartyMons(battler) > 0) // Has mon to switch into
{ {
gActiveBattler = gBattleScripting.battler = battler; gBattleScripting.battler = battler;
gLastUsedItem = gBattleMons[battler].item; gLastUsedItem = gBattleMons[battler].item;
if (gBattleMoves[gCurrentMove].effect == EFFECT_HIT_ESCAPE) if (gBattleMoves[gCurrentMove].effect == EFFECT_HIT_ESCAPE)
gBattlescriptCurrInstr = BattleScript_MoveEnd; // Prevent user switch-in selection gBattlescriptCurrInstr = BattleScript_MoveEnd; // Prevent user switch-in selection
@ -5913,7 +5899,7 @@ static void Cmd_moveend(void)
&& CanBattlerSwitch(gBattlerAttacker)) && CanBattlerSwitch(gBattlerAttacker))
{ {
gLastUsedItem = gBattleMons[battler].item; gLastUsedItem = gBattleMons[battler].item;
gActiveBattler = gBattleStruct->savedBattlerTarget = gBattleScripting.battler = battler; // Battler with red card gBattleStruct->savedBattlerTarget = gBattleScripting.battler = battler; // Battler with red card
gEffectBattler = gBattlerAttacker; gEffectBattler = gBattlerAttacker;
if (gBattleMoves[gCurrentMove].effect == EFFECT_HIT_ESCAPE) if (gBattleMoves[gCurrentMove].effect == EFFECT_HIT_ESCAPE)
gBattlescriptCurrInstr = BattleScript_MoveEnd; // Prevent user switch-in selection gBattlescriptCurrInstr = BattleScript_MoveEnd; // Prevent user switch-in selection
@ -5941,7 +5927,7 @@ static void Cmd_moveend(void)
&& CountUsablePartyMons(battler) > 0) // Has mon to switch into && CountUsablePartyMons(battler) > 0) // Has mon to switch into
{ {
gProtectStructs[battler].statFell = FALSE; gProtectStructs[battler].statFell = FALSE;
gActiveBattler = gBattleScripting.battler = battler; gBattleScripting.battler = battler;
gLastUsedItem = gBattleMons[battler].item; gLastUsedItem = gBattleMons[battler].item;
BattleScriptPushCursor(); BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_EjectPackActivates; gBattlescriptCurrInstr = BattleScript_EjectPackActivates;
@ -6397,15 +6383,14 @@ static void Cmd_jumpifcantswitch(void)
{ {
CMD_ARGS(u8 battler:7, u8 ignoreEscapePrevention:1, const u8 *jumpInstr); CMD_ARGS(u8 battler:7, u8 ignoreEscapePrevention:1, const u8 *jumpInstr);
gActiveBattler = GetBattlerForBattleScript(cmd->battler); u32 battler = GetBattlerForBattleScript(cmd->battler);
if (!cmd->ignoreEscapePrevention && !CanBattlerEscape(battler))
if (!cmd->ignoreEscapePrevention && !CanBattlerEscape(gActiveBattler))
{ {
gBattlescriptCurrInstr = cmd->jumpInstr; gBattlescriptCurrInstr = cmd->jumpInstr;
} }
else else
{ {
if (CanBattlerSwitch(gActiveBattler)) if (CanBattlerSwitch(battler))
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
else else
gBattlescriptCurrInstr = cmd->jumpInstr; gBattlescriptCurrInstr = cmd->jumpInstr;
@ -7065,16 +7050,13 @@ static void Cmd_handlelearnnewmove(void)
{ {
CMD_ARGS(const u8 *learnedMovePtr, const u8 *nothingToLearnPtr, bool8 isFirstMove); CMD_ARGS(const u8 *learnedMovePtr, const u8 *nothingToLearnPtr, bool8 isFirstMove);
const u8 *learnedMovePtr = cmd->learnedMovePtr;
const u8 *nothingToLearnPtr = cmd->nothingToLearnPtr;
u16 learnMove = MonTryLearningNewMove(&gPlayerParty[gBattleStruct->expGetterMonId], cmd->isFirstMove); u16 learnMove = MonTryLearningNewMove(&gPlayerParty[gBattleStruct->expGetterMonId], cmd->isFirstMove);
while (learnMove == MON_ALREADY_KNOWS_MOVE) while (learnMove == MON_ALREADY_KNOWS_MOVE)
learnMove = MonTryLearningNewMove(&gPlayerParty[gBattleStruct->expGetterMonId], FALSE); learnMove = MonTryLearningNewMove(&gPlayerParty[gBattleStruct->expGetterMonId], FALSE);
if (learnMove == MOVE_NONE) if (learnMove == MOVE_NONE)
{ {
gBattlescriptCurrInstr = nothingToLearnPtr; gBattlescriptCurrInstr = cmd->nothingToLearnPtr;
} }
else if (learnMove == MON_HAS_MAX_MOVES) else if (learnMove == MON_HAS_MAX_MOVES)
{ {
@ -7082,24 +7064,24 @@ static void Cmd_handlelearnnewmove(void)
} }
else else
{ {
gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); u32 battler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT);
if (gBattlerPartyIndexes[gActiveBattler] == gBattleStruct->expGetterMonId if (gBattlerPartyIndexes[battler] == gBattleStruct->expGetterMonId
&& !(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED)) && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED))
{ {
GiveMoveToBattleMon(&gBattleMons[gActiveBattler], learnMove); GiveMoveToBattleMon(&gBattleMons[battler], learnMove);
} }
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
{ {
gActiveBattler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); battler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT);
if (gBattlerPartyIndexes[gActiveBattler] == gBattleStruct->expGetterMonId if (gBattlerPartyIndexes[battler] == gBattleStruct->expGetterMonId
&& !(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED)) && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED))
{ {
GiveMoveToBattleMon(&gBattleMons[gActiveBattler], learnMove); GiveMoveToBattleMon(&gBattleMons[battler], learnMove);
} }
} }
gBattlescriptCurrInstr = learnedMovePtr; gBattlescriptCurrInstr = cmd->learnedMovePtr;
} }
} }
@ -7107,8 +7089,6 @@ static void Cmd_yesnoboxlearnmove(void)
{ {
CMD_ARGS(const u8 *forgotMovePtr); CMD_ARGS(const u8 *forgotMovePtr);
gActiveBattler = 0;
switch (gBattleScripting.learnMoveState) switch (gBattleScripting.learnMoveState)
{ {
case 0: case 0:
@ -7180,7 +7160,7 @@ static void Cmd_yesnoboxlearnmove(void)
u16 moveId = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_MOVE1 + movePosition); u16 moveId = GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_MOVE1 + movePosition);
if (IsMoveHM(moveId)) if (IsMoveHM(moveId))
{ {
PrepareStringBattle(STRINGID_HMMOVESCANTBEFORGOTTEN, gActiveBattler); PrepareStringBattle(STRINGID_HMMOVESCANTBEFORGOTTEN, B_POSITION_PLAYER_LEFT);
gBattleScripting.learnMoveState = 6; gBattleScripting.learnMoveState = 6;
} }
else else
@ -7396,9 +7376,8 @@ static void Cmd_swapattackerwithtarget(void)
{ {
CMD_ARGS(); CMD_ARGS();
gActiveBattler = gBattlerAttacker; u8 temp;
gBattlerAttacker = gBattlerTarget; SWAP(gBattlerAttacker, gBattlerTarget, temp);
gBattlerTarget = gActiveBattler;
if (gHitMarker & HITMARKER_SWAP_ATTACKER_TARGET) if (gHitMarker & HITMARKER_SWAP_ATTACKER_TARGET)
gHitMarker &= ~HITMARKER_SWAP_ATTACKER_TARGET; gHitMarker &= ~HITMARKER_SWAP_ATTACKER_TARGET;
@ -8059,15 +8038,12 @@ static void Cmd_hpthresholds(void)
{ {
CMD_ARGS(u8 battler); CMD_ARGS(u8 battler);
u8 opposingBattler;
s32 result;
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{ {
gActiveBattler = GetBattlerForBattleScript(cmd->battler); u32 battler = GetBattlerForBattleScript(cmd->battler);
opposingBattler = BATTLE_OPPOSITE(gActiveBattler); u32 opposingBattler = BATTLE_OPPOSITE(battler);
result = gBattleMons[opposingBattler].hp * 100 / gBattleMons[opposingBattler].maxHP; s32 result = gBattleMons[opposingBattler].hp * 100 / gBattleMons[opposingBattler].maxHP;
if (result == 0) if (result == 0)
result = 1; result = 1;
@ -8088,16 +8064,12 @@ static void Cmd_hpthresholds2(void)
{ {
CMD_ARGS(u8 battler); CMD_ARGS(u8 battler);
u8 opposingBattler;
s32 result;
u8 hpSwitchout;
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{ {
gActiveBattler = GetBattlerForBattleScript(cmd->battler); u32 battler = GetBattlerForBattleScript(cmd->battler);
opposingBattler = BATTLE_OPPOSITE(gActiveBattler); u32 opposingBattler = BATTLE_OPPOSITE(battler);
hpSwitchout = *(gBattleStruct->hpOnSwitchout + GetBattlerSide(opposingBattler)); u8 hpSwitchout = *(gBattleStruct->hpOnSwitchout + GetBattlerSide(opposingBattler));
result = (hpSwitchout - gBattleMons[opposingBattler].hp) * 100 / hpSwitchout; s32 result = (hpSwitchout - gBattleMons[opposingBattler].hp) * 100 / hpSwitchout;
if (gBattleMons[opposingBattler].hp >= hpSwitchout) if (gBattleMons[opposingBattler].hp >= hpSwitchout)
gBattleStruct->hpScale = 0; gBattleStruct->hpScale = 0;
@ -11519,19 +11491,19 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
{ {
bool32 certain = FALSE; bool32 certain = FALSE;
bool32 notProtectAffected = FALSE; bool32 notProtectAffected = FALSE;
u32 index; u32 index, battler;
u16 activeBattlerAbility; u16 battlerAbility;
bool32 affectsUser = (flags & MOVE_EFFECT_AFFECTS_USER); bool32 affectsUser = (flags & MOVE_EFFECT_AFFECTS_USER);
bool32 mirrorArmored = (flags & STAT_CHANGE_MIRROR_ARMOR); bool32 mirrorArmored = (flags & STAT_CHANGE_MIRROR_ARMOR);
if (affectsUser) if (affectsUser)
gActiveBattler = gBattlerAttacker; battler = gBattlerAttacker;
else else
gActiveBattler = gBattlerTarget; battler = gBattlerTarget;
activeBattlerAbility = GetBattlerAbility(gActiveBattler); battlerAbility = GetBattlerAbility(battler);
gSpecialStatuses[gActiveBattler].changedStatsBattlerId = gBattlerAttacker; gSpecialStatuses[battler].changedStatsBattlerId = gBattlerAttacker;
flags &= ~(MOVE_EFFECT_AFFECTS_USER | STAT_CHANGE_MIRROR_ARMOR); flags &= ~(MOVE_EFFECT_AFFECTS_USER | STAT_CHANGE_MIRROR_ARMOR);
@ -11543,7 +11515,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
notProtectAffected++; notProtectAffected++;
flags &= ~STAT_CHANGE_NOT_PROTECT_AFFECTED; flags &= ~STAT_CHANGE_NOT_PROTECT_AFFECTED;
if (activeBattlerAbility == ABILITY_CONTRARY) if (battlerAbility == ABILITY_CONTRARY)
{ {
statValue ^= STAT_BUFF_NEGATIVE; statValue ^= STAT_BUFF_NEGATIVE;
gBattleScripting.statChanger ^= STAT_BUFF_NEGATIVE; gBattleScripting.statChanger ^= STAT_BUFF_NEGATIVE;
@ -11553,7 +11525,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
gBattleScripting.moveEffect = ReverseStatChangeMoveEffect(gBattleScripting.moveEffect); gBattleScripting.moveEffect = ReverseStatChangeMoveEffect(gBattleScripting.moveEffect);
} }
} }
else if (activeBattlerAbility == ABILITY_SIMPLE) else if (battlerAbility == ABILITY_SIMPLE)
{ {
statValue = (SET_STAT_BUFF_VALUE(GET_STAT_BUFF_VALUE(statValue) * 2)) | ((statValue <= -1) ? STAT_BUFF_NEGATIVE : 0); statValue = (SET_STAT_BUFF_VALUE(GET_STAT_BUFF_VALUE(statValue) * 2)) | ((statValue <= -1) ? STAT_BUFF_NEGATIVE : 0);
} }
@ -11562,22 +11534,22 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
if (statValue <= -1) // Stat decrease. if (statValue <= -1) // Stat decrease.
{ {
if (gSideTimers[GET_BATTLER_SIDE(gActiveBattler)].mistTimer if (gSideTimers[GET_BATTLER_SIDE(battler)].mistTimer
&& !certain && gCurrentMove != MOVE_CURSE && !certain && gCurrentMove != MOVE_CURSE
&& !(gActiveBattler == gBattlerTarget && GetBattlerAbility(gBattlerAttacker) == ABILITY_INFILTRATOR)) && !(battler == gBattlerTarget && GetBattlerAbility(gBattlerAttacker) == ABILITY_INFILTRATOR))
{ {
if (flags == STAT_CHANGE_ALLOW_PTR) if (flags == STAT_CHANGE_ALLOW_PTR)
{ {
if (gSpecialStatuses[gActiveBattler].statLowered) if (gSpecialStatuses[battler].statLowered)
{ {
gBattlescriptCurrInstr = BS_ptr; gBattlescriptCurrInstr = BS_ptr;
} }
else else
{ {
BattleScriptPush(BS_ptr); BattleScriptPush(BS_ptr);
gBattleScripting.battler = gActiveBattler; gBattleScripting.battler = battler;
gBattlescriptCurrInstr = BattleScript_MistProtected; gBattlescriptCurrInstr = BattleScript_MistProtected;
gSpecialStatuses[gActiveBattler].statLowered = TRUE; gSpecialStatuses[battler].statLowered = TRUE;
} }
} }
return STAT_CHANGE_DIDNT_WORK; return STAT_CHANGE_DIDNT_WORK;
@ -11588,108 +11560,108 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
gBattlescriptCurrInstr = BattleScript_ButItFailed; gBattlescriptCurrInstr = BattleScript_ButItFailed;
return STAT_CHANGE_DIDNT_WORK; return STAT_CHANGE_DIDNT_WORK;
} }
else if ((GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_CLEAR_AMULET else if ((GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET
|| activeBattlerAbility == ABILITY_CLEAR_BODY || battlerAbility == ABILITY_CLEAR_BODY
|| activeBattlerAbility == ABILITY_FULL_METAL_BODY || battlerAbility == ABILITY_FULL_METAL_BODY
|| activeBattlerAbility == ABILITY_WHITE_SMOKE) || battlerAbility == ABILITY_WHITE_SMOKE)
&& (!affectsUser || mirrorArmored) && !certain && gCurrentMove != MOVE_CURSE) && (!affectsUser || mirrorArmored) && !certain && gCurrentMove != MOVE_CURSE)
{ {
if (GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_CLEAR_AMULET) if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET)
{ {
RecordItemEffectBattle(gActiveBattler, HOLD_EFFECT_CLEAR_AMULET); RecordItemEffectBattle(battler, HOLD_EFFECT_CLEAR_AMULET);
} }
if (flags == STAT_CHANGE_ALLOW_PTR) if (flags == STAT_CHANGE_ALLOW_PTR)
{ {
if (gSpecialStatuses[gActiveBattler].statLowered) if (gSpecialStatuses[battler].statLowered)
{ {
gBattlescriptCurrInstr = BS_ptr; gBattlescriptCurrInstr = BS_ptr;
} }
else else
{ {
BattleScriptPush(BS_ptr); BattleScriptPush(BS_ptr);
gBattleScripting.battler = gActiveBattler; gBattleScripting.battler = battler;
if (GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_CLEAR_AMULET) if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET)
{ {
gBattlescriptCurrInstr = BattleScript_ItemNoStatLoss; gBattlescriptCurrInstr = BattleScript_ItemNoStatLoss;
} }
else else
{ {
gBattlerAbility = gActiveBattler; gBattlerAbility = battler;
gBattlescriptCurrInstr = BattleScript_AbilityNoStatLoss; gBattlescriptCurrInstr = BattleScript_AbilityNoStatLoss;
gLastUsedAbility = activeBattlerAbility; gLastUsedAbility = battlerAbility;
RecordAbilityBattle(gActiveBattler, gLastUsedAbility); RecordAbilityBattle(battler, gLastUsedAbility);
} }
gSpecialStatuses[gActiveBattler].statLowered = TRUE; gSpecialStatuses[battler].statLowered = TRUE;
} }
} }
return STAT_CHANGE_DIDNT_WORK; return STAT_CHANGE_DIDNT_WORK;
} }
else if ((index = IsFlowerVeilProtected(gActiveBattler)) && !certain) else if ((index = IsFlowerVeilProtected(battler)) && !certain)
{ {
if (flags == STAT_CHANGE_ALLOW_PTR) if (flags == STAT_CHANGE_ALLOW_PTR)
{ {
if (gSpecialStatuses[gActiveBattler].statLowered) if (gSpecialStatuses[battler].statLowered)
{ {
gBattlescriptCurrInstr = BS_ptr; gBattlescriptCurrInstr = BS_ptr;
} }
else else
{ {
BattleScriptPush(BS_ptr); BattleScriptPush(BS_ptr);
gBattleScripting.battler = gActiveBattler; gBattleScripting.battler = battler;
gBattlerAbility = index - 1; gBattlerAbility = index - 1;
gBattlescriptCurrInstr = BattleScript_FlowerVeilProtectsRet; gBattlescriptCurrInstr = BattleScript_FlowerVeilProtectsRet;
gLastUsedAbility = ABILITY_FLOWER_VEIL; gLastUsedAbility = ABILITY_FLOWER_VEIL;
gSpecialStatuses[gActiveBattler].statLowered = TRUE; gSpecialStatuses[battler].statLowered = TRUE;
} }
} }
return STAT_CHANGE_DIDNT_WORK; return STAT_CHANGE_DIDNT_WORK;
} }
else if (!certain else if (!certain
&& ((activeBattlerAbility == ABILITY_KEEN_EYE && statId == STAT_ACC) && ((battlerAbility == ABILITY_KEEN_EYE && statId == STAT_ACC)
|| (activeBattlerAbility == ABILITY_HYPER_CUTTER && statId == STAT_ATK) || (battlerAbility == ABILITY_HYPER_CUTTER && statId == STAT_ATK)
|| (activeBattlerAbility == ABILITY_BIG_PECKS && statId == STAT_DEF))) || (battlerAbility == ABILITY_BIG_PECKS && statId == STAT_DEF)))
{ {
if (flags == STAT_CHANGE_ALLOW_PTR) if (flags == STAT_CHANGE_ALLOW_PTR)
{ {
BattleScriptPush(BS_ptr); BattleScriptPush(BS_ptr);
gBattleScripting.battler = gActiveBattler; gBattleScripting.battler = battler;
gBattlerAbility = gActiveBattler; gBattlerAbility = battler;
gBattlescriptCurrInstr = BattleScript_AbilityNoSpecificStatLoss; gBattlescriptCurrInstr = BattleScript_AbilityNoSpecificStatLoss;
gLastUsedAbility = activeBattlerAbility; gLastUsedAbility = battlerAbility;
RecordAbilityBattle(gActiveBattler, gLastUsedAbility); RecordAbilityBattle(battler, gLastUsedAbility);
} }
return STAT_CHANGE_DIDNT_WORK; return STAT_CHANGE_DIDNT_WORK;
} }
else if (activeBattlerAbility == ABILITY_MIRROR_ARMOR && !affectsUser && !mirrorArmored && gBattlerAttacker != gBattlerTarget && gActiveBattler == gBattlerTarget) else if (battlerAbility == ABILITY_MIRROR_ARMOR && !affectsUser && !mirrorArmored && gBattlerAttacker != gBattlerTarget && battler == gBattlerTarget)
{ {
if (flags == STAT_CHANGE_ALLOW_PTR) if (flags == STAT_CHANGE_ALLOW_PTR)
{ {
SET_STATCHANGER(statId, GET_STAT_BUFF_VALUE(statValue) | STAT_BUFF_NEGATIVE, TRUE); SET_STATCHANGER(statId, GET_STAT_BUFF_VALUE(statValue) | STAT_BUFF_NEGATIVE, TRUE);
BattleScriptPush(BS_ptr); BattleScriptPush(BS_ptr);
gBattleScripting.battler = gActiveBattler; gBattleScripting.battler = battler;
gBattlerAbility = gActiveBattler; gBattlerAbility = battler;
gBattlescriptCurrInstr = BattleScript_MirrorArmorReflect; gBattlescriptCurrInstr = BattleScript_MirrorArmorReflect;
RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); RecordAbilityBattle(battler, gBattleMons[battler].ability);
} }
return STAT_CHANGE_DIDNT_WORK; return STAT_CHANGE_DIDNT_WORK;
} }
else if (activeBattlerAbility == ABILITY_SHIELD_DUST && flags == 0) else if (battlerAbility == ABILITY_SHIELD_DUST && flags == 0)
{ {
RecordAbilityBattle(gActiveBattler, ABILITY_SHIELD_DUST); RecordAbilityBattle(battler, ABILITY_SHIELD_DUST);
return STAT_CHANGE_DIDNT_WORK; return STAT_CHANGE_DIDNT_WORK;
} }
else if (flags == 0 && GetBattlerHoldEffect(gActiveBattler, TRUE) == HOLD_EFFECT_COVERT_CLOAK) else if (flags == 0 && GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_COVERT_CLOAK)
{ {
RecordItemEffectBattle(gActiveBattler, HOLD_EFFECT_COVERT_CLOAK); RecordItemEffectBattle(battler, HOLD_EFFECT_COVERT_CLOAK);
return STAT_CHANGE_DIDNT_WORK; return STAT_CHANGE_DIDNT_WORK;
} }
else // try to decrease else // try to decrease
{ {
statValue = -GET_STAT_BUFF_VALUE(statValue); statValue = -GET_STAT_BUFF_VALUE(statValue);
if (gBattleMons[gActiveBattler].statStages[statId] == 1) if (gBattleMons[battler].statStages[statId] == 1)
statValue = -1; statValue = -1;
else if (gBattleMons[gActiveBattler].statStages[statId] == 2 && statValue < -2) else if (gBattleMons[battler].statStages[statId] == 2 && statValue < -2)
statValue = -2; statValue = -2;
gBattleTextBuff2[0] = B_BUFF_PLACEHOLDER_BEGIN; gBattleTextBuff2[0] = B_BUFF_PLACEHOLDER_BEGIN;
index = 1; index = 1;
@ -11712,23 +11684,23 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
gBattleTextBuff2[index++] = STRINGID_STATFELL >> 8; gBattleTextBuff2[index++] = STRINGID_STATFELL >> 8;
gBattleTextBuff2[index] = B_BUFF_EOS; gBattleTextBuff2[index] = B_BUFF_EOS;
if (gBattleMons[gActiveBattler].statStages[statId] == MIN_STAT_STAGE) if (gBattleMons[battler].statStages[statId] == MIN_STAT_STAGE)
{ {
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STAT_WONT_DECREASE; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STAT_WONT_DECREASE;
} }
else else
{ {
gProtectStructs[gActiveBattler].statFell = TRUE; // Eject pack, lash out gProtectStructs[battler].statFell = TRUE; // Eject pack, lash out
gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == gActiveBattler); // B_MSG_ATTACKER_STAT_FELL or B_MSG_DEFENDER_STAT_FELL gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == battler); // B_MSG_ATTACKER_STAT_FELL or B_MSG_DEFENDER_STAT_FELL
} }
} }
} }
else // stat increase else // stat increase
{ {
statValue = GET_STAT_BUFF_VALUE(statValue); statValue = GET_STAT_BUFF_VALUE(statValue);
if (gBattleMons[gActiveBattler].statStages[statId] == 11) if (gBattleMons[battler].statStages[statId] == 11)
statValue = 1; statValue = 1;
else if (gBattleMons[gActiveBattler].statStages[statId] == 10 && statValue > 2) else if (gBattleMons[battler].statStages[statId] == 10 && statValue > 2)
statValue = 2; statValue = 2;
gBattleTextBuff2[0] = B_BUFF_PLACEHOLDER_BEGIN; gBattleTextBuff2[0] = B_BUFF_PLACEHOLDER_BEGIN;
index = 1; index = 1;
@ -11751,19 +11723,19 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
gBattleTextBuff2[index++] = STRINGID_STATROSE >> 8; gBattleTextBuff2[index++] = STRINGID_STATROSE >> 8;
gBattleTextBuff2[index] = B_BUFF_EOS; gBattleTextBuff2[index] = B_BUFF_EOS;
if (gBattleMons[gActiveBattler].statStages[statId] == MAX_STAT_STAGE) if (gBattleMons[battler].statStages[statId] == MAX_STAT_STAGE)
{ {
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STAT_WONT_INCREASE; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STAT_WONT_INCREASE;
} }
else else
{ {
gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == gActiveBattler); gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == battler);
gProtectStructs[gActiveBattler].statRaised = TRUE; gProtectStructs[battler].statRaised = TRUE;
// check mirror herb // check mirror herb
for (index = 0; index < gBattlersCount; index++) for (index = 0; index < gBattlersCount; index++)
{ {
if (GetBattlerSide(index) == GetBattlerSide(gActiveBattler)) if (GetBattlerSide(index) == GetBattlerSide(battler))
continue; // Only triggers on opposing side continue; // Only triggers on opposing side
if (GetBattlerHoldEffect(index, TRUE) == HOLD_EFFECT_MIRROR_HERB if (GetBattlerHoldEffect(index, TRUE) == HOLD_EFFECT_MIRROR_HERB
&& gBattleMons[index].statStages[statId] < MAX_STAT_STAGE) && gBattleMons[index].statStages[statId] < MAX_STAT_STAGE)
@ -11776,11 +11748,11 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
} }
} }
gBattleMons[gActiveBattler].statStages[statId] += statValue; gBattleMons[battler].statStages[statId] += statValue;
if (gBattleMons[gActiveBattler].statStages[statId] < MIN_STAT_STAGE) if (gBattleMons[battler].statStages[statId] < MIN_STAT_STAGE)
gBattleMons[gActiveBattler].statStages[statId] = MIN_STAT_STAGE; gBattleMons[battler].statStages[statId] = MIN_STAT_STAGE;
if (gBattleMons[gActiveBattler].statStages[statId] > MAX_STAT_STAGE) if (gBattleMons[battler].statStages[statId] > MAX_STAT_STAGE)
gBattleMons[gActiveBattler].statStages[statId] = MAX_STAT_STAGE; gBattleMons[battler].statStages[statId] = MAX_STAT_STAGE;
if (gBattleCommunication[MULTISTRING_CHOOSER] == B_MSG_STAT_WONT_INCREASE && flags & STAT_CHANGE_ALLOW_PTR) if (gBattleCommunication[MULTISTRING_CHOOSER] == B_MSG_STAT_WONT_INCREASE && flags & STAT_CHANGE_ALLOW_PTR)
gMoveResultFlags |= MOVE_RESULT_MISSED; gMoveResultFlags |= MOVE_RESULT_MISSED;
@ -13141,6 +13113,7 @@ static void Cmd_healpartystatus(void)
CMD_ARGS(); CMD_ARGS();
u32 zero = 0; u32 zero = 0;
u32 battler;
u8 toHeal = 0; u8 toHeal = 0;
if (gCurrentMove == MOVE_HEAL_BELL) if (gCurrentMove == MOVE_HEAL_BELL)
@ -13161,19 +13134,19 @@ static void Cmd_healpartystatus(void)
gBattleCommunication[MULTISTRING_CHOOSER] |= B_MSG_BELL_SOUNDPROOF_ATTACKER; gBattleCommunication[MULTISTRING_CHOOSER] |= B_MSG_BELL_SOUNDPROOF_ATTACKER;
} }
gActiveBattler = gBattleScripting.battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); battler = gBattleScripting.battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker)));
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE
&& !(gAbsentBattlerFlags & gBitTable[gActiveBattler])) && !(gAbsentBattlerFlags & gBitTable[battler]))
{ {
if (GetBattlerAbility(gActiveBattler) != ABILITY_SOUNDPROOF) if (GetBattlerAbility(battler) != ABILITY_SOUNDPROOF)
{ {
gBattleMons[gActiveBattler].status1 = 0; gBattleMons[battler].status1 = 0;
gBattleMons[gActiveBattler].status2 &= ~STATUS2_NIGHTMARE; gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE;
} }
else else
{ {
RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); RecordAbilityBattle(battler, gBattleMons[battler].ability);
gBattleCommunication[MULTISTRING_CHOOSER] |= B_MSG_BELL_SOUNDPROOF_PARTNER; gBattleCommunication[MULTISTRING_CHOOSER] |= B_MSG_BELL_SOUNDPROOF_PARTNER;
} }
} }
@ -13192,9 +13165,9 @@ static void Cmd_healpartystatus(void)
if (gBattlerPartyIndexes[gBattlerAttacker] == i) if (gBattlerPartyIndexes[gBattlerAttacker] == i)
ability = GetBattlerAbility(gBattlerAttacker); ability = GetBattlerAbility(gBattlerAttacker);
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE
&& gBattlerPartyIndexes[gActiveBattler] == i && gBattlerPartyIndexes[battler] == i
&& !(gAbsentBattlerFlags & gBitTable[gActiveBattler])) && !(gAbsentBattlerFlags & gBitTable[battler]))
ability = GetBattlerAbility(gActiveBattler); ability = GetBattlerAbility(battler);
else else
ability = GetAbilityBySpecies(species, abilityNum); ability = GetAbilityBySpecies(species, abilityNum);
@ -13211,12 +13184,12 @@ static void Cmd_healpartystatus(void)
gBattleMons[gBattlerAttacker].status1 = 0; gBattleMons[gBattlerAttacker].status1 = 0;
gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE; gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE;
gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker)));
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE
&& !(gAbsentBattlerFlags & gBitTable[gActiveBattler])) && !(gAbsentBattlerFlags & gBitTable[battler]))
{ {
gBattleMons[gActiveBattler].status1 = 0; gBattleMons[battler].status1 = 0;
gBattleMons[gActiveBattler].status2 &= ~STATUS2_NIGHTMARE; gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE;
} }
} }
@ -14589,9 +14562,9 @@ static void Cmd_jumpifhasnohp(void)
{ {
CMD_ARGS(u8 battler, const u8 *jumpInstr); CMD_ARGS(u8 battler, const u8 *jumpInstr);
gActiveBattler = GetBattlerForBattleScript(cmd->battler); u32 battler = GetBattlerForBattleScript(cmd->battler);
if (gBattleMons[gActiveBattler].hp == 0) if (gBattleMons[battler].hp == 0)
gBattlescriptCurrInstr = cmd->jumpInstr; gBattlescriptCurrInstr = cmd->jumpInstr;
else else
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
@ -14949,19 +14922,19 @@ static void Cmd_pursuitdoubles(void)
{ {
CMD_ARGS(const u8 *failInstr); CMD_ARGS(const u8 *failInstr);
gActiveBattler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); u32 battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker)));
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE
&& !(gAbsentBattlerFlags & gBitTable[gActiveBattler]) && !(gAbsentBattlerFlags & gBitTable[battler])
&& gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_MOVE && gChosenActionByBattler[battler] == B_ACTION_USE_MOVE
&& gBattleMoves[gChosenMoveByBattler[gActiveBattler]].effect == EFFECT_PURSUIT) && gBattleMoves[gChosenMoveByBattler[battler]].effect == EFFECT_PURSUIT)
{ {
gActionsByTurnOrder[gActiveBattler] = B_ACTION_TRY_FINISH; gActionsByTurnOrder[battler] = B_ACTION_TRY_FINISH;
gCurrentMove = gChosenMoveByBattler[gActiveBattler]; gCurrentMove = gChosenMoveByBattler[battler];
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
gBattleScripting.animTurn = 1; gBattleScripting.animTurn = 1;
gBattleScripting.savedBattler = gBattlerAttacker; gBattleScripting.savedBattler = gBattlerAttacker;
gBattlerAttacker = gActiveBattler; gBattlerAttacker = battler;
} }
else else
{ {
@ -15989,13 +15962,12 @@ void BS_TrySymbiosis(void)
{ {
NATIVE_ARGS(); NATIVE_ARGS();
//called by Bestow, Fling, and Bug Bite, which don't work with Cmd_removeitem. //called by Bestow, Fling, and Bug Bite, which don't work with Cmd_removeitem.
gActiveBattler = gBattlerAttacker; u32 partner = BATTLE_PARTNER(gBattlerAttacker);
if (SYMBIOSIS_CHECK(gBattlerAttacker, BATTLE_PARTNER(gActiveBattler))) if (SYMBIOSIS_CHECK(gBattlerAttacker, partner))
{ {
BestowItem(BATTLE_PARTNER(gActiveBattler), gActiveBattler); BestowItem(partner, gBattlerAttacker);
gLastUsedAbility = gBattleMons[BATTLE_PARTNER(gActiveBattler)].ability; gLastUsedAbility = gBattleMons[partner].ability;
gBattleScripting.battler = gBattlerAbility = BATTLE_PARTNER(gActiveBattler); gBattleScripting.battler = gBattlerAbility = partner;
gBattlerAttacker = gActiveBattler;
BattleScriptPushCursor(); BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_SymbiosisActivates; gBattlescriptCurrInstr = BattleScript_SymbiosisActivates;
return; return;